Chaste  Release::2018.1
VertexElement.cpp
1 /*
2 
3 Copyright (c) 2005-2018, 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 #include "VertexElement.hpp"
36 #include <cassert>
37 
38 
39 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
41  const std::vector<VertexElement<ELEMENT_DIM-1,SPACE_DIM>*>& rFaces,
42  const std::vector<bool>& rOrientations,
43  const std::vector<Node<SPACE_DIM>*>& rNodes)
44  : MutableElement<ELEMENT_DIM, SPACE_DIM>(index, rNodes),
45  mFaces(rFaces),
46  mOrientations(rOrientations)
47 {
48  // This constructor should only be used in 3D
49  assert(SPACE_DIM == 3); // LCOV_EXCL_LINE - code will be removed at compile time
50 
51  // Each face must have an associated orientation
52  assert(mFaces.size() == mOrientations.size());
53 
54  if (SPACE_DIM == ELEMENT_DIM)
55  {
56  // Register element with nodes
57  this->RegisterWithNodes();
58  }
59 }
60 
61 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
63  const std::vector<VertexElement<ELEMENT_DIM-1,SPACE_DIM>*>& rFaces,
64  const std::vector<bool>& rOrientations)
65  : MutableElement<ELEMENT_DIM, SPACE_DIM>(index),
66  mFaces(rFaces),
67  mOrientations(rOrientations)
68 {
69  // Each face must have an associated orientation
70  assert(mFaces.size() == mOrientations.size());
71 
72  // Make a set of nodes with mFaces
73  std::set<Node<SPACE_DIM>* > nodes_set;
74  for (unsigned face_index=0; face_index<mFaces.size(); face_index++)
75  {
76  for (unsigned node_index=0; node_index<mFaces[face_index]->GetNumNodes(); node_index++)
77  {
78  nodes_set.insert(mFaces[face_index]->GetNode(node_index));
79  }
80  }
81 
82  // Populate mNodes
83  for (typename std::set< Node<SPACE_DIM>* >::iterator node_iter = nodes_set.begin();
84  node_iter != nodes_set.end();
85  ++node_iter)
86  {
87  this->mNodes.push_back(*node_iter);
88  }
89 
90  // Register element with nodes
91  this->RegisterWithNodes();
92 }
93 
94 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
96  : MutableElement<ELEMENT_DIM, SPACE_DIM>(index)
97 {
98 }
99 
100 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
102  const std::vector<Node<SPACE_DIM>*>& rNodes)
103  : MutableElement<ELEMENT_DIM, SPACE_DIM>(index, rNodes)
104 {
105 }
106 
107 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
109 {
110 }
111 
112 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
114 {
115  return mFaces.size();
116 }
117 
118 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
120 {
121  // Add pFace to the end of mFaces
122  this->mFaces.push_back(pFace);
123 
124  // Create a set of indices of nodes currently owned by this element
125  std::set<unsigned> node_indices;
126  for (unsigned local_index=0; local_index<this->GetNumNodes(); local_index++)
127  {
128  node_indices.insert(this->GetNodeGlobalIndex(local_index));
129  }
130 
131  // Loop over nodes owned by pFace
132  unsigned end_index = this->GetNumNodes()-1;
133  for (unsigned local_index=0; local_index<pFace->GetNumNodes(); local_index++)
134  {
135  // If this node is not already owned by this element...
136  unsigned global_index = pFace->GetNodeGlobalIndex(local_index);
137  if (node_indices.find(global_index) == node_indices.end())
138  {
139  // ... then add it to the element (and vice versa)
140  this->AddNode(pFace->GetNode(local_index), end_index);
141  end_index++;
142  }
143  }
144 }
145 
146 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
147 VertexElement<ELEMENT_DIM-1, SPACE_DIM>* VertexElement<ELEMENT_DIM, SPACE_DIM>::GetFace(unsigned index) const
148 {
149  assert(index < mFaces.size());
150  return mFaces[index];
151 }
152 
153 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
155 {
156  assert(index < mOrientations.size());
157  return mOrientations[index];
158 }
159 
161 // Specialization for 1d elements //
162 // //
163 // 1d elements are just edges (lines) //
165 
170 template<unsigned SPACE_DIM>
171 VertexElement<1, SPACE_DIM>::VertexElement(unsigned index, const std::vector<Node<SPACE_DIM>*>& rNodes)
172  : MutableElement<1, SPACE_DIM>(index, rNodes)
173 {
174 }
175 
176 template<unsigned SPACE_DIM>
178 {
179  return 0;
180 }
181 
182 template<unsigned SPACE_DIM>
184 {
185  return nullptr;
186 }
187 
188 template<unsigned SPACE_DIM>
190 {
191  return false;
192 }
193 
194 
195 // Explicit instantiation
196 template class VertexElement<1,1>;
197 template class VertexElement<1,2>;
198 template class VertexElement<1,3>;
199 template class VertexElement<2,2>;
200 template class VertexElement<2,3>;
201 template class VertexElement<3,3>;
VertexElement(unsigned index, const std::vector< VertexElement< ELEMENT_DIM-1, SPACE_DIM > * > &rFaces, const std::vector< bool > &rOrientations)
Definition: Node.hpp:58
unsigned GetNodeGlobalIndex(unsigned localIndex) const
bool FaceIsOrientatedClockwise(unsigned index) const
std::vector< VertexElement< ELEMENT_DIM-1, SPACE_DIM > * > mFaces
unsigned GetNumFaces() const
std::vector< bool > mOrientations
Node< SPACE_DIM > * GetNode(unsigned localIndex) const
std::vector< Node< SPACE_DIM > * > mNodes
VertexElement< ELEMENT_DIM-1, SPACE_DIM > * GetFace(unsigned index) const
unsigned GetNumNodes() const
void AddFace(VertexElement< ELEMENT_DIM-1, SPACE_DIM > *pFace)
void RegisterWithNodes()