ToroidalHoneycombVertexMeshGenerator.cpp

00001 /*
00002 
00003 Copyright (c) 2005-2015, 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 "ToroidalHoneycombVertexMeshGenerator.hpp"
00037 
00038 ToroidalHoneycombVertexMeshGenerator::ToroidalHoneycombVertexMeshGenerator(unsigned numElementsAcross,
00039    unsigned numElementsUp,
00040    double cellRearrangementThreshold,
00041    double t2Threshold)
00042 {
00043     // numElementsAcross and numElementsUp must be even for toroidal meshes
00044     assert(numElementsAcross > 1);
00045     assert(numElementsUp > 1);
00046     assert(numElementsAcross%2 == 0);
00047     assert(numElementsUp%2 == 0);
00048 
00049     assert(cellRearrangementThreshold > 0.0);
00050     assert(t2Threshold > 0.0);
00051 
00052     std::vector<Node<2>*> nodes;
00053     std::vector<VertexElement<2,2>*>  elements;
00054 
00055     unsigned node_index = 0;
00056     unsigned node_indices[6];
00057     unsigned element_index;
00058 
00059     // Create the nodes
00060     for (unsigned j=0; j<2*numElementsUp; 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.0);
00066 
00067             Node<2>* p_node = new Node<2>(node_index, false , x_coord, y_coord);
00068             nodes.push_back(p_node);
00069             node_index++;
00070         }
00071     }
00072 
00073     /*
00074      * Create the elements. The array node_indices contains the
00075      * global node indices from bottom, going anticlockwise.
00076      */
00077     for (unsigned j=0; j<numElementsUp; j++)
00078     {
00079         for (unsigned i=0; i<numElementsAcross; i++)
00080         {
00081             element_index = j*numElementsAcross + i;
00082 
00083             node_indices[0] = 2*j*numElementsAcross + i + 1*(j%2==1);
00084             node_indices[1] = node_indices[0] + numElementsAcross + 1*(j%2==0);
00085             node_indices[2] = node_indices[0] + 2*numElementsAcross + 1*(j%2==0);
00086             node_indices[3] = node_indices[0] + 3*numElementsAcross;
00087             node_indices[4] = node_indices[0] + 2*numElementsAcross - 1*(j%2==1);
00088             node_indices[5] = node_indices[0] + numElementsAcross - 1*(j%2==1);
00089 
00090             if (i == numElementsAcross-1) // on far right
00091             {
00092                 node_indices[0] -= numElementsAcross*(j%2==1);
00093                 node_indices[1] -= numElementsAcross;
00094                 node_indices[2] -= numElementsAcross;
00095                 node_indices[3] -= numElementsAcross*(j%2==1);
00096             }
00097             if (j == numElementsUp-1) // on far top
00098             {
00099                 node_indices[2] -= 2*numElementsAcross*numElementsUp;
00100                 node_indices[3] -= 2*numElementsAcross*numElementsUp;
00101                 node_indices[4] -= 2*numElementsAcross*numElementsUp;
00102             }
00103 
00104             std::vector<Node<2>*> element_nodes;
00105             for (unsigned k=0; k<6; k++)
00106             {
00107                element_nodes.push_back(nodes[node_indices[k]]);
00108             }
00109             VertexElement<2,2>* p_element = new VertexElement<2,2>(element_index, element_nodes);
00110             elements.push_back(p_element);
00111         }
00112     }
00113 
00114     double mesh_width = numElementsAcross;
00115     double mesh_height = 1.5*numElementsUp/sqrt(3.0);
00116 
00117     mpMesh = new Toroidal2dVertexMesh(mesh_width, mesh_height, nodes, elements, cellRearrangementThreshold, t2Threshold);
00118 }
00119 
00120 MutableVertexMesh<2,2>* ToroidalHoneycombVertexMeshGenerator::GetMesh()
00121 {
00122     EXCEPTION("A toroidal mesh was created but a normal mesh is being requested.");
00123     return mpMesh; // Not really
00124 }
00125 
00126 Toroidal2dVertexMesh* ToroidalHoneycombVertexMeshGenerator::GetToroidalMesh()
00127 {
00128     return (Toroidal2dVertexMesh*) mpMesh;
00129 }

Generated by  doxygen 1.6.2