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