CylindricalHoneycombVertexMeshGenerator.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 "CylindricalHoneycombVertexMeshGenerator.hpp"
00037 
00038 CylindricalHoneycombVertexMeshGenerator::CylindricalHoneycombVertexMeshGenerator(unsigned numElementsAcross,
00039                                                            unsigned numElementsUp,
00040                                                            bool isFlatBottom,
00041                                                            double cellRearrangementThreshold,
00042                                                            double t2Threshold)
00043 {
00044     // numElementsAcross must be even for cylindrical meshes
00046     assert(numElementsAcross > 1);
00047     assert(numElementsAcross%2 == 0);
00048 
00049     assert(numElementsUp > 0);
00050     assert(cellRearrangementThreshold > 0.0);
00051     assert(t2Threshold > 0.0);
00052 
00053     std::vector<Node<2>*> nodes;
00054     std::vector<VertexElement<2,2>*>  elements;
00055 
00056     unsigned node_index = 0;
00057     unsigned node_indices[6];
00058     unsigned element_index;
00059 
00060     // Create the nodes
00061     for (unsigned j=0; j<=2*numElementsUp+1; j++)
00062     {
00063         if (isFlatBottom && (j==1))
00064         {
00065             // Flat bottom to cylindrical mesh
00066             for (unsigned i=0; i<=numElementsAcross-1; i++)
00067             {
00068                 Node<2>* p_node = new Node<2>(node_index, true, i, 0.0);
00069                 nodes.push_back(p_node);
00070                 node_index++;
00071             }
00072         }
00073         /*
00074          * On each interior row we have numElementsAcross+1 nodes. All nodes on the first, second,
00075          * penultimate and last rows are boundary nodes. On other rows no nodes are boundary nodes.
00076          */
00077         else
00078         {
00079             for (unsigned i=0; i<=numElementsAcross-1; i++)
00080             {
00081                 double x_coord = ((j%4 == 0)||(j%4 == 3)) ? i+0.5 : i;
00082                 double y_coord = (1.5*j - 0.5*(j%2))*0.5/sqrt(3.0);
00083                 bool is_boundary_node = (j==0 || j==1 || j==2*numElementsUp || j==2*numElementsUp+1) ? true : false;
00084 
00085                 Node<2>* p_node = new Node<2>(node_index, is_boundary_node , x_coord, y_coord);
00086                 nodes.push_back(p_node);
00087                 node_index++;
00088             }
00089         }
00090     }
00091 
00092     /*
00093      * Create the elements. The array node_indices contains the
00094      * global node indices from bottom, going anticlockwise.
00095      */
00096     for (unsigned j=0; j<numElementsUp; j++)
00097     {
00098         for (unsigned i=0; i<numElementsAcross; i++)
00099         {
00100             element_index = j*numElementsAcross + i;
00101 
00102             node_indices[0] = 2*j*numElementsAcross + i + 1*(j%2==1);
00103             node_indices[1] = node_indices[0] + numElementsAcross + 1*(j%2==0);
00104             node_indices[2] = node_indices[0] + 2*numElementsAcross + 1*(j%2==0);
00105             node_indices[3] = node_indices[0] + 3*numElementsAcross;
00106             node_indices[4] = node_indices[0] + 2*numElementsAcross - 1*(j%2==1);
00107             node_indices[5] = node_indices[0] + numElementsAcross - 1*(j%2==1);
00108 
00109             if (i==numElementsAcross-1) // on far right
00110             {
00111                 node_indices[0] -= numElementsAcross*(j%2==1);
00112                 node_indices[1] -= numElementsAcross;
00113                 node_indices[2] -= numElementsAcross;
00114                 node_indices[3] -= numElementsAcross*(j%2==1);
00115             }
00116 
00117             std::vector<Node<2>*> element_nodes;
00118             for (unsigned k=0; k<6; k++)
00119             {
00120                element_nodes.push_back(nodes[node_indices[k]]);
00121             }
00122             VertexElement<2,2>* p_element = new VertexElement<2,2>(element_index, element_nodes);
00123             elements.push_back(p_element);
00124         }
00125     }
00126 
00127     // If imposing a flat bottom, delete unnecessary nodes from the mesh
00128     if (isFlatBottom)
00129     {
00130         for (unsigned i=0; i<numElementsAcross; i++)
00131         {
00132             nodes[i]->SetPoint(nodes[i+numElementsAcross]->GetPoint());
00133         }
00134     }
00135     mpMesh = new Cylindrical2dVertexMesh(numElementsAcross, nodes, elements, cellRearrangementThreshold, t2Threshold);
00136 }
00137 
00138 MutableVertexMesh<2,2>* CylindricalHoneycombVertexMeshGenerator::GetMesh()
00139 {
00140     EXCEPTION("A cylindrical mesh was created but a normal mesh is being requested.");
00141     return mpMesh; // Not really
00142 }
00143 
00144 Cylindrical2dVertexMesh* CylindricalHoneycombVertexMeshGenerator::GetCylindricalMesh()
00145 {
00146     return (Cylindrical2dVertexMesh*) mpMesh;
00147 }

Generated by  doxygen 1.6.2