Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cstdlib>
- #include <vector>
- #include <sstream>
- using namespace std;
- struct Node
- {
- int condition;
- int nodeID;
- int xValue;
- };
- struct Element
- {
- int* nodeID1;
- int* nodeID2;
- int lElement;
- float kElement=1;
- float sElement=1;
- };
- float localMatrix[1][1];
- static int elements;
- static int nodes;
- static float L;
- static float k;
- static float S;
- static float alfa;
- static float q;
- vector <Node> nodeNet;
- vector <Element> elementNet;
- vector <int> xVector;
- void ReadFromFile()
- {
- fstream file;
- file.open("input",ios::in);
- if (file.is_open())
- {
- cout<<"Plik został otwarty!"<<endl;
- string line;
- getline(file,line);
- line=line.substr(line.find_first_of('"')+1,line.find_last_of('"')-(line.find_first_of('"')+1));
- elements=atoi (line.c_str());
- cout<<endl<<"Liczba elemntow: "<<elements<<endl;
- getline(file,line);
- line=line.substr(line.find_first_of('"')+1,line.find_last_of('"')-(line.find_first_of('"')+1));
- nodes=atoi (line.c_str());
- cout<<endl<<"Liczba wezlow: "<<nodes<<endl;
- getline(file,line);
- line=line.substr(line.find_first_of('"')+1,line.find_last_of('"')-(line.find_first_of('"')+1));
- L=atof (line.c_str());
- cout<<endl<<"Dlugosc L: "<<L<<endl;
- getline(file,line);
- line=line.substr(line.find_first_of('"')+1,line.find_last_of('"')-(line.find_first_of('"')+1));
- k=atof (line.c_str());
- cout<<endl<<"Stala k: "<<k<<endl;
- getline(file,line);
- line=line.substr(line.find_first_of('"')+1,line.find_last_of('"')-(line.find_first_of('"')+1));
- S=atof (line.c_str());
- cout<<endl<<"Powierzchnia S: "<<S<<endl;
- getline(file,line);
- line=line.substr(line.find_first_of('"')+1,line.find_last_of('"')-(line.find_first_of('"')+1));
- alfa=atof (line.c_str());
- cout<<endl<<"Wspolczynnik alfa: "<<alfa<<endl;
- getline(file,line);
- line=line.substr(line.find_first_of('"')+1,line.find_last_of('"')-(line.find_first_of('"')+1));
- q=atof (line.c_str());
- cout<<endl<<"Strumien ciepla q: "<<q<<endl;
- getline(file,line);
- line=line.substr(line.find_first_of('"')+1,line.find_last_of('"')-(line.find_first_of('"')+1));
- stringstream stream(line);
- int n;
- while(stream >> n)
- {
- xVector.push_back(n);
- }
- // for(int i=0;i<xVector.size();i++)
- // cout<<endl<<"Element numer "<<i<<"rowna sie "<<xVector[i]<<endl;
- //
- file.close();
- }
- else
- {
- cout<<"ERROR! Sprawdz dane wejsciowe i pamietaj by umieścic je między znakami \"\"";
- }
- }
- void CreateNets()
- {
- for (int i=1; i<=nodes; ++i)
- {
- Node node;
- node.nodeID=i;
- if(i==1 )
- node.condition=1;
- else if(i==nodes)
- node.condition=2;
- else
- node.condition=0;
- node.xValue=xVector[i-1];
- nodeNet.push_back(node);
- }
- //for(int i=0;i<nodeNet.size();i++)
- //cout<<endl<<"Element numer "<<i<<"rowna sie "<<nodeNet[i].xValue<<endl;
- for (int i=1; i<=elements; ++i)
- {
- Element element;
- element.lElement=(nodeNet[i].xValue - nodeNet[i-1].xValue);
- elementNet.push_back(element);
- }
- }
- void CreateLocalMatrix(Element element)
- {
- float c;
- c=(element.sElement*element.kElement)/element.lElement;
- localMatrix[0][0]= c;
- localMatrix[0][1]= c*(-1);
- localMatrix[1][0]= c*(-1);
- localMatrix[1][1]= c;
- cout<<"\t\t C jest rowne: \t"<<c<<endl;
- }
- void CreateGlobalMatrix()
- {
- float** globalMatrix = new float*[elements+1];
- for(int i = 0; i < elements+1; ++i)
- globalMatrix[i] = new float[elements+1];
- for(int i=0; i<elements+1; ++i)
- for(int j=0; j<elements+1; ++j)
- globalMatrix[i][j]=0;
- //CREATING LOCAL MATRIX
- int k=0;
- for(int i=0; i<elementNet.size(); ++i)
- {
- CreateLocalMatrix(elementNet[i]);
- cout<<"Macierz lokalna wynosi"<<endl;
- for(int i=0; i<2; ++i)
- {
- {
- for(int j=0; j<2; ++j)
- cout<<localMatrix[i][j]<<" ";
- }
- cout<<endl;
- }
- globalMatrix[i][k]+=localMatrix[0][0];
- globalMatrix[i][k+1]+=localMatrix[0][1];
- globalMatrix[i+1][k]+=localMatrix[1][0];
- globalMatrix[i+1][k+1]+=localMatrix[1][1];
- k++;
- }
- cout<<"Macierz globalna jest rowna: "<<endl;
- for(int i=0; i<elements+1; ++i)
- {
- {
- for(int j=0; j<elements+1; ++j)
- cout<<globalMatrix[i][j]<<" \t";
- }
- cout<<endl<<endl;
- }
- }
- int main()
- {
- ReadFromFile();
- CreateNets();
- CreateGlobalMatrix();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement