[关闭]
@BravoWA 2015-09-10T06:17:26.000000Z 字数 2036 阅读 1224

S-FEM++中CNode和CElem类的测试

S-FEM C++ 测试 CNode类 CElem类


调试Main函数

  1. #include <iostream>
  2. #include <vector>
  3. #include <armadillo>
  4. #include "node.hpp"
  5. #include "elem.hpp"
  6. using namespace std;
  7. using namespace arma;
  8. int main()
  9. {
  10. /* Geometry: two triangular
  11. 2 (0,2)
  12. /|\
  13. / | \
  14. / | \
  15. (-1,1)3 II| I 1 (1,1)
  16. \ | /
  17. \ | /
  18. \|/
  19. 0(0,0)
  20. */
  21. unsigned long nNode=4;
  22. unsigned long nElem = 2;
  23. vector<CNode*> Nodes;
  24. vector<double> n_coords(2);
  25. vector<unsigned long> ele;
  26. // initial nodes
  27. CNode node0;
  28. node0.SetCoords(0.0, 0.0);
  29. node0.AddElem(0);
  30. node0.AddElem(1);
  31. node0.SetGlobalID(0);
  32. Nodes.push_back(&node0);
  33. cout << "node0.coords = " << Nodes[0]->GetX() << ", " << Nodes[0]->GetY() << endl;
  34. cout << "node0.Elems = " << Nodes[0]->GetElems()[0] << endl;
  35. CNode node1;
  36. node1.SetCoords(1.0, 1.0);
  37. node1.AddElem(0);
  38. node1.SetGlobalID(1);
  39. Nodes.push_back(&node1);
  40. cout << "node1.coords = " << Nodes[1]->GetX() << ", " << Nodes[1]->GetY() << endl;
  41. cout << "node1.Elems = " << Nodes[1]->GetElems()[0] << endl;
  42. CNode node2;
  43. node2.SetCoords(0.0, 2.0);
  44. node2.AddElem(0);
  45. node2.AddElem(1);
  46. node2.SetGlobalID(1);
  47. Nodes.push_back(&node2);
  48. cout << "node2.coords = " << Nodes[2]->GetX() << ", " << Nodes[2]->GetY() << endl;
  49. cout << "node2.Elems = " << Nodes[2]->GetElems()[0] << endl;
  50. CNode node3;
  51. node3.SetCoords(-1.0, 1.0);
  52. node3.AddElem(0);
  53. node3.SetGlobalID(1);
  54. Nodes.push_back(&node3);
  55. cout << "node1.coords = " << Nodes[3]->GetX() << ", " << Nodes[3]->GetY() << endl;
  56. cout << "node1.Elems = " << Nodes[3]->GetElems()[0] << endl;
  57. //creat element
  58. vector<CElem*> Ele;
  59. CElemTRI3 ele0(0,1,2,0,2);
  60. vector<double> n0_xyz, n1_xyz, n2_xyz;
  61. n0_xyz = Nodes[0]->GetCoords(); n1_xyz = Nodes[1]->GetCoords(); n2_xyz = Nodes[2]->GetCoords();
  62. ele0.SetCG(n0_xyz, n1_xyz, n2_xyz);
  63. ele0.SetVol(n0_xyz, n1_xyz, n2_xyz);
  64. // CElemTRI3 ele1(2,3,0,1,2);
  65. // ele1.SetCG(Nodes[2]->GetCoords(), Nodes[3]->GetCoords(), Nodes[0]->GetCoords());
  66. // ele1.SetVol(Nodes[2]->GetCoords(), Nodes[3]->GetCoords(), Nodes[0]->GetCoords());
  67. Ele.push_back(&ele0);
  68. // Ele.push_back(&ele1);
  69. //
  70. Ele[0]->Display();
  71. // Ele[1]->Display();
  72. return 0;
  73. }

Output

  1. node0.coords = 0, 0
  2. node0.Elems = 0
  3. node1.coords = 1, 1
  4. node1.Elems = 0
  5. node2.coords = 0, 2
  6. node2.Elems = 0
  7. node1.coords = -1, 1
  8. node1.Elems = 0
  9. Element No. 0 's vars:
  10. Type: 5
  11. nNodes: 3
  12. Nodes: 0, 1, 2,
  13. CG: 0.333333, 1,
  14. nDim: 2
  15. nFaces: 3
  16. nNodesFace: 2
  17. Vol: 1
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注