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