36 #include "ToroidalHoneycombVertexMeshGenerator.hpp" 39 unsigned numElementsUp,
40 double cellRearrangementThreshold,
44 assert(numElementsAcross > 1);
45 assert(numElementsUp > 1);
46 assert(numElementsAcross%2 == 0);
47 assert(numElementsUp%2 == 0);
49 assert(cellRearrangementThreshold > 0.0);
50 assert(t2Threshold > 0.0);
52 std::vector<Node<2>*> nodes;
53 std::vector<VertexElement<2,2>*> elements;
55 unsigned node_index = 0;
56 unsigned node_indices[6];
57 unsigned element_index;
60 for (
unsigned j=0; j<2*numElementsUp; j++)
62 for (
unsigned i=0; i<numElementsAcross; i++)
64 double x_coord = ((j%4 == 0)||(j%4 == 3)) ? i+0.5 : i;
65 double y_coord = (1.5*j - 0.5*(j%2))*0.5/sqrt(3.0);
67 Node<2>* p_node =
new Node<2>(node_index, false , x_coord, y_coord);
68 nodes.push_back(p_node);
77 for (
unsigned j=0; j<numElementsUp; j++)
79 for (
unsigned i=0; i<numElementsAcross; i++)
81 element_index = j*numElementsAcross + i;
83 node_indices[0] = 2*j*numElementsAcross + i + 1*(j%2==1);
84 node_indices[1] = node_indices[0] + numElementsAcross + 1*(j%2==0);
85 node_indices[2] = node_indices[0] + 2*numElementsAcross + 1*(j%2==0);
86 node_indices[3] = node_indices[0] + 3*numElementsAcross;
87 node_indices[4] = node_indices[0] + 2*numElementsAcross - 1*(j%2==1);
88 node_indices[5] = node_indices[0] + numElementsAcross - 1*(j%2==1);
90 if (i == numElementsAcross-1)
92 node_indices[0] -= numElementsAcross*(j%2==1);
93 node_indices[1] -= numElementsAcross;
94 node_indices[2] -= numElementsAcross;
95 node_indices[3] -= numElementsAcross*(j%2==1);
97 if (j == numElementsUp-1)
99 node_indices[2] -= 2*numElementsAcross*numElementsUp;
100 node_indices[3] -= 2*numElementsAcross*numElementsUp;
101 node_indices[4] -= 2*numElementsAcross*numElementsUp;
104 std::vector<Node<2>*> element_nodes;
105 for (
unsigned k=0; k<6; k++)
107 element_nodes.push_back(nodes[node_indices[k]]);
110 elements.push_back(p_element);
114 double mesh_width = numElementsAcross;
115 double mesh_height = 1.5*numElementsUp/sqrt(3.0);
122 EXCEPTION(
"A toroidal mesh was created but a normal mesh is being requested.");
MutableVertexMesh< 2, 2 > * GetMesh()
#define EXCEPTION(message)
MutableVertexMesh< 2, 2 > * mpMesh
ToroidalHoneycombVertexMeshGenerator(unsigned numElementsAcross, unsigned numElementsUp, double cellRearrangementThreshold=0.01, double t2Threshold=0.001)
Toroidal2dVertexMesh * GetToroidalMesh()