41 unsigned numElementsUp,
43 double cellRearrangementThreshold,
47 assert(numElementsAcross > 0);
48 assert(numElementsUp > 0);
49 assert(cellRearrangementThreshold > 0.0);
50 assert(t2Threshold > 0.0);
51 assert(elementArea > 0.0);
53 std::vector<Node<2>*> nodes;
54 std::vector<VertexElement<2,2>*> elements;
56 unsigned node_index = 0;
57 unsigned node_indices[6];
58 unsigned element_index;
67 for (
unsigned i = 0; i < numElementsAcross; i++)
70 nodes.push_back(p_node);
80 for (
unsigned j = 1; j < 2*numElementsUp + 1; j++)
82 if ((j == 1) && isFlatBottom)
84 for (
unsigned i = 0; i <= numElementsAcross; i++)
86 double x_coord = ((j%4 == 0)||(j%4 == 3)) ? i + 0.5 : i;
90 nodes.push_back(p_node);
96 for (
unsigned i = 0; i <= numElementsAcross; i++)
98 double x_coord = ((j%4 == 0)||(j%4 == 3)) ? i + 0.5 : i;
99 double y_coord = (1.5*j - 0.5*(j%2))*0.5/sqrt(3.0);
100 bool is_boundary_node = (j==1 || j==2*numElementsUp || i==0 || i==numElementsAcross) ?
true :
false;
102 Node<2>* p_node =
new Node<2>(node_index, is_boundary_node, x_coord, y_coord);
103 nodes.push_back(p_node);
112 double y_coord = (1.5*(2*numElementsUp+1) - 0.5*((2*numElementsUp+1)%2))*0.5/sqrt(3.0);
113 if (((2*numElementsUp+1)%4 == 0)||((2*numElementsUp+1)%4 == 3))
116 nodes.push_back(p_node);
119 for (
unsigned i=1; i<numElementsAcross; i++)
121 double x_coord = (((2*numElementsUp+1)%4 == 0)||((2*numElementsUp+1)%4 == 3)) ? i+0.5 : i;
123 Node<2>* p_node =
new Node<2>(node_index,
true, x_coord, y_coord);
124 nodes.push_back(p_node);
127 if (((2*numElementsUp+1)%4 == 1)||((2*numElementsUp+1)%4 == 2))
129 Node<2>* p_node =
new Node<2>(node_index,
true, numElementsAcross, y_coord);
130 nodes.push_back(p_node);
138 for (
unsigned j = 0; j < numElementsUp; j++)
140 if (j == 0 && isFlatBottom)
142 unsigned short_node_indices[5];
143 for (
unsigned i = 0; i < numElementsAcross; i++)
145 short_node_indices[0] = i;
146 short_node_indices[1] = i + 1;
147 short_node_indices[2] = short_node_indices[1] + numElementsAcross + 1;
148 short_node_indices[3] = short_node_indices[2] + numElementsAcross;
149 short_node_indices[4] = short_node_indices[2] - 1;
151 std::vector<Node<2>*> element_nodes;
152 for (
unsigned k = 0; k < 5; k++)
154 element_nodes.push_back(nodes[short_node_indices[k]]);
157 element_index = j*numElementsAcross + i;
159 elements.push_back(p_element);
164 for (
unsigned i = 0; i < numElementsAcross; i++)
172 unsigned first_index;
175 first_index = 2*j*(numElementsAcross+1) - 1*(j%2==0) + i - numElementsAcross;
179 first_index = 2*j*(numElementsAcross+1) - 1*(j%2==0) + i;
181 node_indices[0] = first_index;
183 node_indices[1] = node_indices[0] + numElementsAcross + 1 + 1*(j%2==0 && j>0);
184 node_indices[2] = node_indices[1] + numElementsAcross + 1;
185 node_indices[3] = node_indices[2] + numElementsAcross + 1*(j%2==1 && j<numElementsUp-1);
186 node_indices[4] = node_indices[2] - 1;
187 node_indices[5] = node_indices[1] - 1;
189 std::vector<Node<2>*> element_nodes;
190 for (
unsigned k = 0; k < 6; k++)
192 element_nodes.push_back(nodes[node_indices[k]]);
195 element_index = j*numElementsAcross + i;
197 elements.push_back(p_element);
202 mpMesh = boost::make_shared<MutableVertexMesh<2,2> >(nodes, elements, cellRearrangementThreshold, t2Threshold);
206 mpMesh->Scale(sqrt(elementArea*2.0/sqrt(3.0)), sqrt(elementArea*2.0/sqrt(3.0)));