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