@BravoWA
2015-09-10T06:17:26.000000Z
字数 2036
阅读 1224
S-FEM
C++
测试
CNode类
CElem类
#include <iostream>
#include <vector>
#include <armadillo>
#include "node.hpp"
#include "elem.hpp"
using namespace std;
using namespace arma;
int main()
{
/* Geometry: two triangular
2 (0,2)
/|\
/ | \
/ | \
(-1,1)3 II| I 1 (1,1)
\ | /
\ | /
\|/
0(0,0)
*/
unsigned long nNode=4;
unsigned long nElem = 2;
vector<CNode*> Nodes;
vector<double> n_coords(2);
vector<unsigned long> ele;
// initial nodes
CNode node0;
node0.SetCoords(0.0, 0.0);
node0.AddElem(0);
node0.AddElem(1);
node0.SetGlobalID(0);
Nodes.push_back(&node0);
cout << "node0.coords = " << Nodes[0]->GetX() << ", " << Nodes[0]->GetY() << endl;
cout << "node0.Elems = " << Nodes[0]->GetElems()[0] << endl;
CNode node1;
node1.SetCoords(1.0, 1.0);
node1.AddElem(0);
node1.SetGlobalID(1);
Nodes.push_back(&node1);
cout << "node1.coords = " << Nodes[1]->GetX() << ", " << Nodes[1]->GetY() << endl;
cout << "node1.Elems = " << Nodes[1]->GetElems()[0] << endl;
CNode node2;
node2.SetCoords(0.0, 2.0);
node2.AddElem(0);
node2.AddElem(1);
node2.SetGlobalID(1);
Nodes.push_back(&node2);
cout << "node2.coords = " << Nodes[2]->GetX() << ", " << Nodes[2]->GetY() << endl;
cout << "node2.Elems = " << Nodes[2]->GetElems()[0] << endl;
CNode node3;
node3.SetCoords(-1.0, 1.0);
node3.AddElem(0);
node3.SetGlobalID(1);
Nodes.push_back(&node3);
cout << "node1.coords = " << Nodes[3]->GetX() << ", " << Nodes[3]->GetY() << endl;
cout << "node1.Elems = " << Nodes[3]->GetElems()[0] << endl;
//creat element
vector<CElem*> Ele;
CElemTRI3 ele0(0,1,2,0,2);
vector<double> n0_xyz, n1_xyz, n2_xyz;
n0_xyz = Nodes[0]->GetCoords(); n1_xyz = Nodes[1]->GetCoords(); n2_xyz = Nodes[2]->GetCoords();
ele0.SetCG(n0_xyz, n1_xyz, n2_xyz);
ele0.SetVol(n0_xyz, n1_xyz, n2_xyz);
// CElemTRI3 ele1(2,3,0,1,2);
// ele1.SetCG(Nodes[2]->GetCoords(), Nodes[3]->GetCoords(), Nodes[0]->GetCoords());
// ele1.SetVol(Nodes[2]->GetCoords(), Nodes[3]->GetCoords(), Nodes[0]->GetCoords());
Ele.push_back(&ele0);
// Ele.push_back(&ele1);
//
Ele[0]->Display();
// Ele[1]->Display();
return 0;
}
node0.coords = 0, 0
node0.Elems = 0
node1.coords = 1, 1
node1.Elems = 0
node2.coords = 0, 2
node2.Elems = 0
node1.coords = -1, 1
node1.Elems = 0
Element No. 0 's vars:
Type: 5
nNodes: 3
Nodes: 0, 1, 2,
CG: 0.333333, 1,
nDim: 2
nFaces: 3
nNodesFace: 2
Vol: 1