Chaste Commit::f2ff7ee04e70ac9d06c57344df8d017dbb12b97b
VertexElement.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#include "VertexElement.hpp"
36#include <cassert>
37
38
39template<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
61template<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
94template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
96 : MutableElement<ELEMENT_DIM, SPACE_DIM>(index)
97{
98}
99
100template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
102 const std::vector<Node<SPACE_DIM>*>& rNodes)
103 : MutableElement<ELEMENT_DIM, SPACE_DIM>(index, rNodes)
105}
106
107template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
111
112template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
114{
115 return mFaces.size();
116}
118template<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())
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
146template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
147VertexElement<ELEMENT_DIM-1, SPACE_DIM>* VertexElement<ELEMENT_DIM, SPACE_DIM>::GetFace(unsigned index) const
148{
149 assert(index < mFaces.size());
150 return mFaces[index];
152
153template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
155{
156 assert(index < mOrientations.size());
157 return mOrientations[index];
159
161// Specialization for 1d elements //
162// //
163// 1d elements are just edges (lines) //
170template<unsigned SPACE_DIM>
171VertexElement<1, SPACE_DIM>::VertexElement(unsigned index, const std::vector<Node<SPACE_DIM>*>& rNodes)
172 : MutableElement<1, SPACE_DIM>(index, rNodes)
173{
174}
175
176template<unsigned SPACE_DIM>
178{
179 return 0;
180}
181
182template<unsigned SPACE_DIM>
184{
185 return nullptr;
186}
187
188template<unsigned SPACE_DIM>
190{
191 return false;
192}
193
194
195// Explicit instantiation
196template class VertexElement<1,1>;
197template class VertexElement<1,2>;
198template class VertexElement<1,3>;
199template class VertexElement<2,2>;
200template class VertexElement<2,3>;
201template class VertexElement<3,3>;
Node< SPACE_DIM > * GetNode(unsigned localIndex) const
unsigned GetNumNodes() const
unsigned GetNodeGlobalIndex(unsigned localIndex) const
std::vector< Node< SPACE_DIM > * > mNodes
Definition Node.hpp:59
VertexElement< ELEMENT_DIM-1, SPACE_DIM > * GetFace(unsigned index) const
std::vector< bool > mOrientations
void AddFace(VertexElement< ELEMENT_DIM-1, SPACE_DIM > *pFace)
VertexElement(unsigned index, const std::vector< VertexElement< ELEMENT_DIM-1, SPACE_DIM > * > &rFaces, const std::vector< bool > &rOrientations)
std::vector< VertexElement< ELEMENT_DIM-1, SPACE_DIM > * > mFaces
bool FaceIsOrientatedClockwise(unsigned index) const
unsigned GetNumFaces() const