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