HoneycombVertexMeshGenerator.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 #include "HoneycombVertexMeshGenerator.hpp"
00030 
00031 HoneycombVertexMeshGenerator::HoneycombVertexMeshGenerator(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     // Create the nodes, row by row, from the bottom up
00050 
00051     // On the first row we have numElementsAcross nodes, all of which are boundary nodes
00052     for (unsigned i=0; i<numElementsAcross; i++)
00053     {
00054         Node<2>* p_node = new Node<2>(node_index, true, i+0.5, 0);
00055         nodes.push_back(p_node);
00056         node_index++;
00057     }
00058 
00059     /*
00060      * On each interior row we have numElementsAcross+1 nodes. On the second and penultimate
00061      * row all nodes are boundary nodes. On other rows the first and last nodes only
00062      * are boundary nodes.
00063      */
00064     for (unsigned j=1; j<2*numElementsUp+1; j++)
00065     {
00066         for (unsigned i=0; i<=numElementsAcross; i++)
00067         {
00068             double x_coord = ((j%4 == 0)||(j%4 == 3)) ? i+0.5 : i;
00069             double y_coord = (1.5*j - 0.5*(j%2))*0.5/sqrt(3);
00070             bool is_boundary_node = (j==1 || j==2*numElementsUp || i==0 || i==numElementsAcross) ? true : false;
00071 
00072             Node<2>* p_node = new Node<2>(node_index, is_boundary_node, x_coord, y_coord);
00073             nodes.push_back(p_node);
00074             node_index++;
00075         }
00076     }
00077 
00078     /*
00079      * On the last row we have numElementsAcross nodes, all of which are boundary nodes.
00080      */
00081     double y_coord = (1.5*(2*numElementsUp+1) - 0.5*((2*numElementsUp+1)%2))*0.5/sqrt(3);
00082     if (((2*numElementsUp+1)%4 == 0)||((2*numElementsUp+1)%4 == 3))
00083     {
00084         Node<2>* p_node = new Node<2>(node_index, true, 0.5, y_coord);
00085         nodes.push_back(p_node);
00086         node_index++;
00087     }
00088     for (unsigned i=1; i<numElementsAcross; i++)
00089     {
00090         double x_coord = (((2*numElementsUp+1)%4 == 0)||((2*numElementsUp+1)%4 == 3)) ? i+0.5 : i;
00091 
00092         Node<2>* p_node = new Node<2>(node_index, true, x_coord, y_coord);
00093         nodes.push_back(p_node);
00094         node_index++;
00095     }
00096     if (((2*numElementsUp+1)%4 == 1)||((2*numElementsUp+1)%4 == 2))
00097     {
00098         Node<2>* p_node = new Node<2>(node_index, true, numElementsAcross, y_coord);
00099         nodes.push_back(p_node);
00100         node_index++;
00101     }
00102 
00103     /*
00104      * Create the elements. The array node_indices contains the
00105      * global node indices from bottom, going anticlockwise.
00106      */
00107     for (unsigned j=0; j<numElementsUp; j++)
00108     {
00109         for (unsigned i=0; i<numElementsAcross; i++)
00110         {
00111             if (j==0)
00112             {
00113                 node_indices[0] = i;
00114             }
00115             else
00116             {
00117                 node_indices[0] = 2*j*(numElementsAcross+1) - 1*(j%2==0) + i; // different for even/odd rows
00118             }
00119             node_indices[1] = node_indices[0] + numElementsAcross + 1 + 1*(j%2==0 && j>0);
00120             node_indices[2] = node_indices[1] + numElementsAcross + 1;
00121             node_indices[3] = node_indices[2] + numElementsAcross + 1*(j%2==1 && j<numElementsUp-1);
00122             node_indices[4] = node_indices[2] - 1;
00123             node_indices[5] = node_indices[1] - 1;
00124 
00125             std::vector<Node<2>*> element_nodes;
00126             for (unsigned k=0; k<6; k++)
00127             {
00128                element_nodes.push_back(nodes[node_indices[k]]);
00129             }
00130 
00131             element_index = j*numElementsAcross + i;
00132             VertexElement<2,2>* p_element = new VertexElement<2,2>(element_index, element_nodes);
00133             elements.push_back(p_element);
00134         }
00135     }
00136 
00137     mpMesh = new MutableVertexMesh<2,2>(nodes, elements, cellRearrangementThreshold, t2Threshold);
00138 }
00139 
00140 HoneycombVertexMeshGenerator::~HoneycombVertexMeshGenerator()
00141 {
00142     delete mpMesh;
00143 }
00144 
00145 MutableVertexMesh<2,2>* HoneycombVertexMeshGenerator::GetMesh()
00146 {
00147     return mpMesh;
00148 }

Generated on Mon Apr 18 11:35:27 2011 for Chaste by  doxygen 1.5.5