49 mMeshFilename(
"mesh"),
50 mDomainWidth(numNodesAlongWidth*scaleFactor),
51 mNumCellWidth(numNodesAlongWidth),
52 mNumCellLength(numNodesAlongLength)
58 assert(scaleFactor > 0.0);
61 std::stringstream pid;
63 OutputFileHandler output_file_handler(
"2D_temporary_honeycomb_mesh_" + pid.str());
69 double vertical_spacing = (sqrt(3.0)/2)*horizontal_spacing;
75 num_nodes_along_width += 2*ghosts;
76 num_nodes_along_length += 2*ghosts;
78 unsigned num_nodes = num_nodes_along_width*num_nodes_along_length;
79 unsigned num_elem_along_width = num_nodes_along_width-1;
80 unsigned num_elem_along_length = num_nodes_along_length-1;
81 unsigned num_elem = 2*num_elem_along_width*num_elem_along_length;
82 unsigned num_edges = 3*num_elem_along_width*num_elem_along_length + num_elem_along_width + num_elem_along_length;
84 double x0 = -horizontal_spacing*ghosts;
85 double y0 = -vertical_spacing*ghosts;
87 mBottom = -vertical_spacing*ghosts;
88 mTop =
mBottom + vertical_spacing*(num_nodes_along_length-1);
92 (*p_node_file) << std::scientific;
93 (*p_node_file) << std::setprecision(20);
94 (*p_node_file) << num_nodes <<
"\t2\t0\t1" << std::endl;
97 for (
unsigned i=0; i<num_nodes_along_length; i++)
99 for (
unsigned j=0; j<num_nodes_along_width; j++)
109 unsigned boundary = 0;
110 if (i==0 || i==num_nodes_along_length-1 || j==0 || j==num_nodes_along_width-1)
115 const double adjustment = i % 2 != 0 ? 0.5 : 0.0;
116 double x = x0 + horizontal_spacing*((
double)j + adjustment);
117 double y = y0 + vertical_spacing*(
double)i;
120 if ((y<0.0) && (y>-1e-12))
128 (*p_node_file) << node++ <<
"\t" << x <<
"\t" << y <<
"\t" << boundary << std::endl;
131 p_node_file->close();
135 (*p_elem_file) << std::scientific;
138 (*p_node_file) << std::scientific;
140 (*p_elem_file) << num_elem <<
"\t3\t0" << std::endl;
141 (*p_edge_file) << num_edges <<
"\t1" << std::endl;
145 for (
unsigned i=0; i<num_elem_along_length; i++)
147 for (
unsigned j=0; j < num_elem_along_width; j++)
149 unsigned node0 = i*num_nodes_along_width + j;
150 unsigned node1 = i*num_nodes_along_width + j+1;
151 unsigned node2 = (i+1)*num_nodes_along_width + j;
158 (*p_elem_file) << elem++ <<
"\t" << node0 <<
"\t" << node1 <<
"\t" << node2 << std::endl;
160 unsigned horizontal_edge_is_boundary_edge = 0;
161 unsigned vertical_edge_is_boundary_edge = 0;
164 horizontal_edge_is_boundary_edge = 1;
168 vertical_edge_is_boundary_edge = 1;
171 (*p_edge_file) << edge++ <<
"\t" << node0 <<
"\t" << node1 <<
"\t" << horizontal_edge_is_boundary_edge << std::endl;
172 (*p_edge_file) << edge++ <<
"\t" << node1 <<
"\t" << node2 <<
"\t" << 0 << std::endl;
173 (*p_edge_file) << edge++ <<
"\t" << node2 <<
"\t" << node0 <<
"\t" << vertical_edge_is_boundary_edge << std::endl;
175 node0 = i*num_nodes_along_width + j + 1;
181 node1 = (i+1)*num_nodes_along_width + j+1;
182 node2 = (i+1)*num_nodes_along_width + j;
184 (*p_elem_file) << elem++ <<
"\t" << node0 <<
"\t" << node1 <<
"\t" << node2 << std::endl;
188 for (
unsigned i=0; i<num_elem_along_length; i++)
190 unsigned node0, node1;
194 node0 = (i+1)*num_nodes_along_width - 1;
195 node1 = (i+2)*num_nodes_along_width - 1;
199 node0 = (i+1)*num_nodes_along_width;
200 node1 = (i)*num_nodes_along_width;
202 (*p_edge_file) << edge++ <<
"\t" << node0 <<
"\t" << node1 <<
"\t" << 1 << std::endl;
205 for (
unsigned j=0; j<num_elem_along_width; j++)
207 unsigned node0 = num_nodes_along_width*(num_nodes_along_length-1) + j;
208 unsigned node1 = num_nodes_along_width*(num_nodes_along_length-1) + j+1;
209 (*p_edge_file) << edge++ <<
"\t" << node1 <<
"\t" << node0 <<
"\t" << 1 << std::endl;
212 p_elem_file->close();
213 p_edge_file->close();
219 mpMesh = boost::make_shared<MutableMesh<2,2> >();
220 mpMesh->ConstructFromMeshReader(mesh_reader);
227 mpMesh->SetMeshHasChangedSinceLoading();
253 EXCEPTION(
"Cannot call GetCircularMesh on a HoneycombMesh with ghost nodes");
257 c_vector<double,2> centre = zero_vector<double>(2);
258 for (
unsigned i=0; i<
mpMesh->GetNumNodes(); i++)
260 centre +=
mpMesh->GetNode(i)->rGetLocation();
264 mpMesh->Translate(-centre[0], -centre[1]);
267 for (
unsigned i=0; i<
mpMesh->GetNumAllNodes(); i++)
269 if (norm_2(
mpMesh->GetNode(i)->rGetLocation()) >= radius)
271 mpMesh->DeleteNodePriorToReMesh(i);
276 c_vector<double,2>& r_location =
mpMesh->GetNode(i)->rGetModifiableLocation();
277 c_vector<double,2> shift;
279 double max_jiggle = radius*5e-6;
280 shift[0] = max_jiggle*(p_gen->
ranf()-0.5);
281 shift[1] = max_jiggle*(p_gen->
ranf()-0.5);