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