Chaste Release::3.1
|
00001 /* 00002 00003 Copyright (c) 2005-2012, University of Oxford. 00004 All rights reserved. 00005 00006 University of Oxford means the Chancellor, Masters and Scholars of the 00007 University of Oxford, having an administrative office at Wellington 00008 Square, Oxford OX1 2JD, UK. 00009 00010 This file is part of Chaste. 00011 00012 Redistribution and use in source and binary forms, with or without 00013 modification, are permitted provided that the following conditions are met: 00014 * Redistributions of source code must retain the above copyright notice, 00015 this list of conditions and the following disclaimer. 00016 * Redistributions in binary form must reproduce the above copyright notice, 00017 this list of conditions and the following disclaimer in the documentation 00018 and/or other materials provided with the distribution. 00019 * Neither the name of the University of Oxford nor the names of its 00020 contributors may be used to endorse or promote products derived from this 00021 software without specific prior written permission. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 00034 */ 00035 00036 #include "HoneycombVertexMeshGenerator.hpp" 00037 00038 HoneycombVertexMeshGenerator::HoneycombVertexMeshGenerator(unsigned numElementsAcross, 00039 unsigned numElementsUp, 00040 bool isFlatBottom, 00041 double cellRearrangementThreshold, 00042 double t2Threshold) 00043 { 00044 assert(numElementsAcross > 0); 00045 assert(numElementsUp > 0); 00046 assert(cellRearrangementThreshold > 0.0); 00047 assert(t2Threshold > 0.0); 00048 00049 std::vector<Node<2>*> nodes; 00050 std::vector<VertexElement<2,2>*> elements; 00051 00052 unsigned node_index = 0; 00053 unsigned node_indices[6]; 00054 unsigned element_index; 00055 00056 // Create the nodes, row by row, from the bottom up 00057 00058 // On the first row we have numElementsAcross nodes, all of which are boundary nodes 00059 for (unsigned i=0; i<numElementsAcross; i++) 00060 { 00061 Node<2>* p_node = new Node<2>(node_index, true, i+0.5, 0); 00062 nodes.push_back(p_node); 00063 node_index++; 00064 } 00065 00066 /* 00067 * On each interior row we have numElementsAcross+1 nodes. On the second and penultimate 00068 * row all nodes are boundary nodes. On other rows the first and last nodes only 00069 * are boundary nodes. 00070 */ 00071 for (unsigned j=1; j<2*numElementsUp+1; j++) 00072 { 00073 for (unsigned i=0; i<=numElementsAcross; i++) 00074 { 00075 double x_coord = ((j%4 == 0)||(j%4 == 3)) ? i+0.5 : i; 00076 double y_coord = (1.5*j - 0.5*(j%2))*0.5/sqrt(3); 00077 bool is_boundary_node = (j==1 || j==2*numElementsUp || i==0 || i==numElementsAcross) ? true : false; 00078 00079 Node<2>* p_node = new Node<2>(node_index, is_boundary_node, x_coord, y_coord); 00080 nodes.push_back(p_node); 00081 node_index++; 00082 } 00083 } 00084 00085 /* 00086 * On the last row we have numElementsAcross nodes, all of which are boundary nodes. 00087 */ 00088 double y_coord = (1.5*(2*numElementsUp+1) - 0.5*((2*numElementsUp+1)%2))*0.5/sqrt(3); 00089 if (((2*numElementsUp+1)%4 == 0)||((2*numElementsUp+1)%4 == 3)) 00090 { 00091 Node<2>* p_node = new Node<2>(node_index, true, 0.5, y_coord); 00092 nodes.push_back(p_node); 00093 node_index++; 00094 } 00095 for (unsigned i=1; i<numElementsAcross; i++) 00096 { 00097 double x_coord = (((2*numElementsUp+1)%4 == 0)||((2*numElementsUp+1)%4 == 3)) ? i+0.5 : i; 00098 00099 Node<2>* p_node = new Node<2>(node_index, true, x_coord, y_coord); 00100 nodes.push_back(p_node); 00101 node_index++; 00102 } 00103 if (((2*numElementsUp+1)%4 == 1)||((2*numElementsUp+1)%4 == 2)) 00104 { 00105 Node<2>* p_node = new Node<2>(node_index, true, numElementsAcross, y_coord); 00106 nodes.push_back(p_node); 00107 node_index++; 00108 } 00109 00110 /* 00111 * Create the elements. The array node_indices contains the 00112 * global node indices from bottom, going anticlockwise. 00113 */ 00114 for (unsigned j=0; j<numElementsUp; j++) 00115 { 00116 for (unsigned i=0; i<numElementsAcross; i++) 00117 { 00118 if (j==0) 00119 { 00120 node_indices[0] = i; 00121 } 00122 else 00123 { 00124 node_indices[0] = 2*j*(numElementsAcross+1) - 1*(j%2==0) + i; // different for even/odd rows 00125 } 00126 node_indices[1] = node_indices[0] + numElementsAcross + 1 + 1*(j%2==0 && j>0); 00127 node_indices[2] = node_indices[1] + numElementsAcross + 1; 00128 node_indices[3] = node_indices[2] + numElementsAcross + 1*(j%2==1 && j<numElementsUp-1); 00129 node_indices[4] = node_indices[2] - 1; 00130 node_indices[5] = node_indices[1] - 1; 00131 00132 std::vector<Node<2>*> element_nodes; 00133 for (unsigned k=0; k<6; k++) 00134 { 00135 element_nodes.push_back(nodes[node_indices[k]]); 00136 } 00137 00138 element_index = j*numElementsAcross + i; 00139 VertexElement<2,2>* p_element = new VertexElement<2,2>(element_index, element_nodes); 00140 elements.push_back(p_element); 00141 } 00142 } 00143 00144 mpMesh = new MutableVertexMesh<2,2>(nodes, elements, cellRearrangementThreshold, t2Threshold); 00145 } 00146 00147 HoneycombVertexMeshGenerator::~HoneycombVertexMeshGenerator() 00148 { 00149 delete mpMesh; 00150 } 00151 00152 MutableVertexMesh<2,2>* HoneycombVertexMeshGenerator::GetMesh() 00153 { 00154 return mpMesh; 00155 }