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