ToroidalHoneycombVertexMeshGenerator.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "ToroidalHoneycombVertexMeshGenerator.hpp"
00037
00038 ToroidalHoneycombVertexMeshGenerator::ToroidalHoneycombVertexMeshGenerator(unsigned numElementsAcross,
00039 unsigned numElementsUp,
00040 double cellRearrangementThreshold,
00041 double t2Threshold)
00042 {
00043
00044 assert(numElementsAcross > 1);
00045 assert(numElementsUp > 1);
00046 assert(numElementsAcross%2 == 0);
00047 assert(numElementsUp%2 == 0);
00048
00049 assert(cellRearrangementThreshold > 0.0);
00050 assert(t2Threshold > 0.0);
00051
00052 std::vector<Node<2>*> nodes;
00053 std::vector<VertexElement<2,2>*> elements;
00054
00055 unsigned node_index = 0;
00056 unsigned node_indices[6];
00057 unsigned element_index;
00058
00059
00060 for (unsigned j=0; j<2*numElementsUp; j++)
00061 {
00062 for (unsigned i=0; i<numElementsAcross; i++)
00063 {
00064 double x_coord = ((j%4 == 0)||(j%4 == 3)) ? i+0.5 : i;
00065 double y_coord = (1.5*j - 0.5*(j%2))*0.5/sqrt(3.0);
00066
00067 Node<2>* p_node = new Node<2>(node_index, false , x_coord, y_coord);
00068 nodes.push_back(p_node);
00069 node_index++;
00070 }
00071 }
00072
00073
00074
00075
00076
00077 for (unsigned j=0; j<numElementsUp; j++)
00078 {
00079 for (unsigned i=0; i<numElementsAcross; i++)
00080 {
00081 element_index = j*numElementsAcross + i;
00082
00083 node_indices[0] = 2*j*numElementsAcross + i + 1*(j%2==1);
00084 node_indices[1] = node_indices[0] + numElementsAcross + 1*(j%2==0);
00085 node_indices[2] = node_indices[0] + 2*numElementsAcross + 1*(j%2==0);
00086 node_indices[3] = node_indices[0] + 3*numElementsAcross;
00087 node_indices[4] = node_indices[0] + 2*numElementsAcross - 1*(j%2==1);
00088 node_indices[5] = node_indices[0] + numElementsAcross - 1*(j%2==1);
00089
00090 if (i == numElementsAcross-1)
00091 {
00092 node_indices[0] -= numElementsAcross*(j%2==1);
00093 node_indices[1] -= numElementsAcross;
00094 node_indices[2] -= numElementsAcross;
00095 node_indices[3] -= numElementsAcross*(j%2==1);
00096 }
00097 if (j == numElementsUp-1)
00098 {
00099 node_indices[2] -= 2*numElementsAcross*numElementsUp;
00100 node_indices[3] -= 2*numElementsAcross*numElementsUp;
00101 node_indices[4] -= 2*numElementsAcross*numElementsUp;
00102 }
00103
00104 std::vector<Node<2>*> element_nodes;
00105 for (unsigned k=0; k<6; k++)
00106 {
00107 element_nodes.push_back(nodes[node_indices[k]]);
00108 }
00109 VertexElement<2,2>* p_element = new VertexElement<2,2>(element_index, element_nodes);
00110 elements.push_back(p_element);
00111 }
00112 }
00113
00114 double mesh_width = numElementsAcross;
00115 double mesh_height = 1.5*numElementsUp/sqrt(3.0);
00116
00117 mpMesh = new Toroidal2dVertexMesh(mesh_width, mesh_height, nodes, elements, cellRearrangementThreshold, t2Threshold);
00118 }
00119
00120 MutableVertexMesh<2,2>* ToroidalHoneycombVertexMeshGenerator::GetMesh()
00121 {
00122 EXCEPTION("A toroidal mesh was created but a normal mesh is being requested.");
00123 return mpMesh;
00124 }
00125
00126 Toroidal2dVertexMesh* ToroidalHoneycombVertexMeshGenerator::GetToroidalMesh()
00127 {
00128 return (Toroidal2dVertexMesh*) mpMesh;
00129 }