Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
CylindricalHoneycombVertexMeshGenerator.cpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met:
14 * Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19 * Neither the name of the University of Oxford nor the names of its
20 contributors may be used to endorse or promote products derived from this
21 software without specific prior written permission.
22
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
36#include "CylindricalHoneycombVertexMeshGenerator.hpp"
37#include <boost/make_shared.hpp>
38#include <boost/shared_ptr.hpp>
39
41 unsigned numElementsUp,
42 bool isFlatBottom,
43 double cellRearrangementThreshold,
44 double t2Threshold)
45{
46 // numElementsAcross must be even for cylindrical meshes
48 assert(numElementsAcross > 1);
49 assert(numElementsAcross%2 == 0);
50
51 assert(numElementsUp > 0);
52 assert(cellRearrangementThreshold > 0.0);
53 assert(t2Threshold > 0.0);
54
55 std::vector<Node<2>*> nodes;
56 std::vector<VertexElement<2,2>*> elements;
57
58 unsigned node_index = 0;
59 unsigned node_indices[6];
60 unsigned element_index;
61
62 // Create the nodes
63 for (unsigned j=0; j<=2*numElementsUp+1; j++)
64 {
65 if (isFlatBottom && (j==1))
66 {
67 // Flat bottom to cylindrical mesh
68 for (unsigned i=0; i<=numElementsAcross-1; i++)
69 {
70 Node<2>* p_node = new Node<2>(node_index, true, i, 0.0);
71 nodes.push_back(p_node);
72 node_index++;
73 }
74 }
75 /*
76 * On each interior row we have numElementsAcross+1 nodes. All nodes on the first, second,
77 * penultimate and last rows are boundary nodes. On other rows no nodes are boundary nodes.
78 */
79 else
80 {
81 for (unsigned i=0; i<=numElementsAcross-1; i++)
82 {
83 double x_coord = ((j%4 == 0)||(j%4 == 3)) ? i+0.5 : i;
84 double y_coord = (1.5*j - 0.5*(j%2))*0.5/sqrt(3.0);
85 bool is_boundary_node = (j==0 || j==1 || j==2*numElementsUp || j==2*numElementsUp+1) ? true : false;
86
87 Node<2>* p_node = new Node<2>(node_index, is_boundary_node , x_coord, y_coord);
88 nodes.push_back(p_node);
89 node_index++;
90 }
91 }
92 }
93
94 /*
95 * Create the elements. The array node_indices contains the
96 * global node indices from bottom, going anticlockwise.
97 */
98 for (unsigned j=0; j<numElementsUp; j++)
99 {
100 for (unsigned i=0; i<numElementsAcross; i++)
101 {
102 element_index = j*numElementsAcross + i;
103
104 node_indices[0] = 2*j*numElementsAcross + i + 1*(j%2==1);
105 node_indices[1] = node_indices[0] + numElementsAcross + 1*(j%2==0);
106 node_indices[2] = node_indices[0] + 2*numElementsAcross + 1*(j%2==0);
107 node_indices[3] = node_indices[0] + 3*numElementsAcross;
108 node_indices[4] = node_indices[0] + 2*numElementsAcross - 1*(j%2==1);
109 node_indices[5] = node_indices[0] + numElementsAcross - 1*(j%2==1);
110
111 if (i==numElementsAcross-1) // on far right
112 {
113 node_indices[0] -= numElementsAcross*(j%2==1);
114 node_indices[1] -= numElementsAcross;
115 node_indices[2] -= numElementsAcross;
116 node_indices[3] -= numElementsAcross*(j%2==1);
117 }
118
119 std::vector<Node<2>*> element_nodes;
120 for (unsigned k=0; k<6; k++)
121 {
122 element_nodes.push_back(nodes[node_indices[k]]);
123 }
124 VertexElement<2,2>* p_element = new VertexElement<2,2>(element_index, element_nodes);
125 elements.push_back(p_element);
126 }
127 }
128
129 // If imposing a flat bottom, delete unnecessary nodes from the mesh
130 if (isFlatBottom)
131 {
132 for (unsigned i=0; i<numElementsAcross; i++)
133 {
134 nodes[i]->SetPoint(nodes[i+numElementsAcross]->GetPoint());
135 }
136 }
137 mpMesh = boost::make_shared<Cylindrical2dVertexMesh>(numElementsAcross, nodes, elements, cellRearrangementThreshold, t2Threshold);
138}
139
140boost::shared_ptr<MutableVertexMesh<2,2> > CylindricalHoneycombVertexMeshGenerator::GetMesh()
141{
142 EXCEPTION("A cylindrical mesh was created but a normal mesh is being requested.");
143 return mpMesh; // Not really
144}
145
146boost::shared_ptr<Cylindrical2dVertexMesh> CylindricalHoneycombVertexMeshGenerator::GetCylindricalMesh()
147{
148 return boost::static_pointer_cast<Cylindrical2dVertexMesh>(mpMesh);
149}
#define EXCEPTION(message)
boost::shared_ptr< Cylindrical2dVertexMesh > GetCylindricalMesh()
CylindricalHoneycombVertexMeshGenerator(unsigned numElementsAcross, unsigned numElementsUp, bool isFlatBottom=false, double cellRearrangementThreshold=0.01, double t2Threshold=0.001)
boost::shared_ptr< MutableVertexMesh< 2, 2 > > GetMesh()
boost::shared_ptr< MutableVertexMesh< 2, 2 > > mpMesh
Definition Node.hpp:59