HoneycombMutableVertexMeshGenerator.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
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 "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     // Create the nodes, row by row, from the bottom up
00051 
00052     // On the first row we have numElementsAcross nodes, all of which are boundary nodes
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      * On each interior row we have numElementsAcross+1 nodes. On the second and penultimate
00062      * row all nodes are boundary nodes. On other rows the first and last nodes only
00063      * are boundary nodes.
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      * On the last row we have numElementsAcross nodes, all of which are boundary nodes.
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      * Create the elements. The array node_indices contains the
00106      * global node indices from bottom, going anticlockwise.
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; // different for even/odd rows
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; //Not really
00146 }
00147 
00148 MutableVertexMesh<2,2>* HoneycombMutableVertexMeshGenerator::GetMutableMesh()
00149 {
00150     return (MutableVertexMesh<2,2>*) mpMesh;
00151 }
00152 
00153 

Generated on Mon Nov 1 12:35:23 2010 for Chaste by  doxygen 1.5.5