36 #include "CylindricalHoneycombMeshGenerator.hpp"
38 #include <boost/foreach.hpp>
39 #include "RandomNumberGenerator.hpp"
55 assert(scaleFactor > 0.0);
58 std::stringstream pid;
66 double vertical_spacing = (sqrt(3.0)/2)*horizontal_spacing;
72 num_nodes_along_length += 2*ghosts;
74 unsigned num_nodes = num_nodes_along_width*num_nodes_along_length;
75 unsigned num_elem_along_width = num_nodes_along_width-1;
76 unsigned num_elem_along_length = num_nodes_along_length-1;
77 unsigned num_elem = 2*num_elem_along_width*num_elem_along_length;
78 unsigned num_edges = 3*num_elem_along_width*num_elem_along_length + num_elem_along_width + num_elem_along_length;
81 double y0 = -vertical_spacing*ghosts;
83 mBottom = -vertical_spacing*ghosts;
84 mTop =
mBottom + vertical_spacing*(num_nodes_along_length-1);
87 out_stream p_node_file = output_file_handler.OpenOutputFile(
mMeshFilename+
".node");
88 (*p_node_file) << std::scientific;
90 (*p_node_file) << num_nodes <<
"\t2\t0\t1" << std::endl;
93 for (
unsigned i=0; i<num_nodes_along_length; i++)
95 for (
unsigned j=0; j<num_nodes_along_width; j++)
101 unsigned boundary = 0;
102 if ((i==0) || (i==num_nodes_along_length-1))
107 double x = x0 + horizontal_spacing*((
double)j + 0.25*(1.0+
SmallPow(-1.0,i+1)));
108 double y = y0 + vertical_spacing*(
double)i;
111 if ( (y<0.0) && (y>-1e-12) )
114 #define COVERAGE_IGNORE
116 #undef COVERAGE_IGNORE
119 (*p_node_file) << node++ <<
"\t" << x <<
"\t" << y <<
"\t" << boundary << std::endl;
122 p_node_file->close();
125 out_stream p_elem_file = output_file_handler.OpenOutputFile(
mMeshFilename+
".ele");
126 (*p_elem_file) << std::scientific;
128 out_stream p_edge_file = output_file_handler.OpenOutputFile(
mMeshFilename+
".edge");
129 (*p_node_file) << std::scientific;
131 (*p_elem_file) << num_elem <<
"\t3\t0" << std::endl;
132 (*p_edge_file) << num_edges <<
"\t1" << std::endl;
136 for (
unsigned i=0; i<num_elem_along_length; i++)
138 for (
unsigned j=0; j < num_elem_along_width; j++)
140 unsigned node0 = i*num_nodes_along_width + j;
141 unsigned node1 = i*num_nodes_along_width + j+1;
142 unsigned node2 = (i+1)*num_nodes_along_width + j;
149 (*p_elem_file) << elem++ <<
"\t" << node0 <<
"\t" << node1 <<
"\t" << node2 << std::endl;
151 unsigned horizontal_edge_is_boundary_edge = 0;
152 unsigned vertical_edge_is_boundary_edge = 0;
155 horizontal_edge_is_boundary_edge = 1;
158 (*p_edge_file) << edge++ <<
"\t" << node0 <<
"\t" << node1 <<
"\t" << horizontal_edge_is_boundary_edge << std::endl;
159 (*p_edge_file) << edge++ <<
"\t" << node1 <<
"\t" << node2 <<
"\t" << 0 << std::endl;
160 (*p_edge_file) << edge++ <<
"\t" << node2 <<
"\t" << node0 <<
"\t" << vertical_edge_is_boundary_edge << std::endl;
162 node0 = i*num_nodes_along_width + j + 1;
168 node1 = (i+1)*num_nodes_along_width + j+1;
169 node2 = (i+1)*num_nodes_along_width + j;
171 (*p_elem_file) << elem++ <<
"\t" << node0 <<
"\t" << node1 <<
"\t" << node2 << std::endl;
175 for (
unsigned i=0; i<num_elem_along_length; i++)
177 unsigned node0, node1;
181 node0 = (i+1)*num_nodes_along_width - 1;
182 node1 = (i+2)*num_nodes_along_width - 1;
186 node0 = (i+1)*num_nodes_along_width;
187 node1 = (i)*num_nodes_along_width;
189 (*p_edge_file) << edge++ <<
"\t" << node0 <<
"\t" << node1 <<
"\t" << 1 << std::endl;
192 for (
unsigned j=0; j<num_elem_along_width; j++)
194 unsigned node0 = num_nodes_along_width*(num_nodes_along_length-1) + j;
195 unsigned node1 = num_nodes_along_width*(num_nodes_along_length-1) + j+1;
196 (*p_edge_file) << edge++ <<
"\t" << node1 <<
"\t" << node0 <<
"\t" << 1 << std::endl;
199 p_elem_file->close();
200 p_edge_file->close();
207 mpMesh->ConstructFromMeshReader(mesh_reader);
214 output_file_handler.FindFile(
"").Remove();
222 EXCEPTION(
"A cylindrical mesh was created but a normal mesh is being requested.");
std::string mMeshFilename
double SmallPow(double x, unsigned exponent)
#define EXCEPTION(message)
CylindricalHoneycombMeshGenerator(unsigned numNodesAlongWidth, unsigned numNodesAlongLength, unsigned ghosts=3, double scaleFactor=1.0)
std::set< unsigned > mGhostNodeIndices
virtual void ReMesh(NodeMap &map)
MutableMesh< 2, 2 > * GetMesh()
void SetMeshHasChangedSinceLoading()
MutableMesh< 2, 2 > * mpMesh
Cylindrical2dMesh * GetCylindricalMesh()