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