HoneycombVertexMeshGenerator.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 "HoneycombVertexMeshGenerator.hpp"
00037
00038 HoneycombVertexMeshGenerator::HoneycombVertexMeshGenerator(unsigned numElementsAcross,
00039 unsigned numElementsUp,
00040 bool isFlatBottom,
00041 double cellRearrangementThreshold,
00042 double t2Threshold)
00043 {
00044 assert(numElementsAcross > 0);
00045 assert(numElementsUp > 0);
00046 assert(cellRearrangementThreshold > 0.0);
00047 assert(t2Threshold > 0.0);
00048
00049 std::vector<Node<2>*> nodes;
00050 std::vector<VertexElement<2,2>*> elements;
00051
00052 unsigned node_index = 0;
00053 unsigned node_indices[6];
00054 unsigned element_index;
00055
00056
00057
00058
00059 for (unsigned i=0; i<numElementsAcross; i++)
00060 {
00061 Node<2>* p_node = new Node<2>(node_index, true, i+0.5, 0);
00062 nodes.push_back(p_node);
00063 node_index++;
00064 }
00065
00066
00067
00068
00069
00070
00071 for (unsigned j=1; j<2*numElementsUp+1; j++)
00072 {
00073 for (unsigned i=0; i<=numElementsAcross; i++)
00074 {
00075 double x_coord = ((j%4 == 0)||(j%4 == 3)) ? i+0.5 : i;
00076 double y_coord = (1.5*j - 0.5*(j%2))*0.5/sqrt(3.0);
00077 bool is_boundary_node = (j==1 || j==2*numElementsUp || i==0 || i==numElementsAcross) ? true : false;
00078
00079 Node<2>* p_node = new Node<2>(node_index, is_boundary_node, x_coord, y_coord);
00080 nodes.push_back(p_node);
00081 node_index++;
00082 }
00083 }
00084
00085
00086
00087
00088 double y_coord = (1.5*(2*numElementsUp+1) - 0.5*((2*numElementsUp+1)%2))*0.5/sqrt(3.0);
00089 if (((2*numElementsUp+1)%4 == 0)||((2*numElementsUp+1)%4 == 3))
00090 {
00091 Node<2>* p_node = new Node<2>(node_index, true, 0.5, y_coord);
00092 nodes.push_back(p_node);
00093 node_index++;
00094 }
00095 for (unsigned i=1; i<numElementsAcross; i++)
00096 {
00097 double x_coord = (((2*numElementsUp+1)%4 == 0)||((2*numElementsUp+1)%4 == 3)) ? i+0.5 : i;
00098
00099 Node<2>* p_node = new Node<2>(node_index, true, x_coord, y_coord);
00100 nodes.push_back(p_node);
00101 node_index++;
00102 }
00103 if (((2*numElementsUp+1)%4 == 1)||((2*numElementsUp+1)%4 == 2))
00104 {
00105 Node<2>* p_node = new Node<2>(node_index, true, numElementsAcross, y_coord);
00106 nodes.push_back(p_node);
00107 node_index++;
00108 }
00109
00110
00111
00112
00113
00114 for (unsigned j=0; j<numElementsUp; j++)
00115 {
00116 for (unsigned i=0; i<numElementsAcross; i++)
00117 {
00118 if (j==0)
00119 {
00120 node_indices[0] = i;
00121 }
00122 else
00123 {
00124 node_indices[0] = 2*j*(numElementsAcross+1) - 1*(j%2==0) + i;
00125 }
00126 node_indices[1] = node_indices[0] + numElementsAcross + 1 + 1*(j%2==0 && j>0);
00127 node_indices[2] = node_indices[1] + numElementsAcross + 1;
00128 node_indices[3] = node_indices[2] + numElementsAcross + 1*(j%2==1 && j<numElementsUp-1);
00129 node_indices[4] = node_indices[2] - 1;
00130 node_indices[5] = node_indices[1] - 1;
00131
00132 std::vector<Node<2>*> element_nodes;
00133 for (unsigned k=0; k<6; k++)
00134 {
00135 element_nodes.push_back(nodes[node_indices[k]]);
00136 }
00137
00138 element_index = j*numElementsAcross + i;
00139 VertexElement<2,2>* p_element = new VertexElement<2,2>(element_index, element_nodes);
00140 elements.push_back(p_element);
00141 }
00142 }
00143
00144 mpMesh = new MutableVertexMesh<2,2>(nodes, elements, cellRearrangementThreshold, t2Threshold);
00145 }
00146
00147 HoneycombVertexMeshGenerator::~HoneycombVertexMeshGenerator()
00148 {
00149 delete mpMesh;
00150 }
00151
00152 MutableVertexMesh<2,2>* HoneycombVertexMeshGenerator::GetMesh()
00153 {
00154 return mpMesh;
00155 }