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