Chaste Commit::ca8ccdedf819b6e02855bc0e8e6f50bdecbc5208
Edge.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 "Edge.hpp"
37
38template <unsigned SPACE_DIM>
39Edge<SPACE_DIM>::Edge(unsigned index)
40 : mIndex(index),
41 mIsDeleted(false)
42{
43}
44
45template <unsigned SPACE_DIM>
46Edge<SPACE_DIM>::Edge(unsigned index,
47 Node<SPACE_DIM>* pNodeA,
48 Node<SPACE_DIM>* pNodeB)
49 : mIndex(index),
50 mIsDeleted(false)
51{
52 this->SetNodes(pNodeA, pNodeB);
53}
54
55template <unsigned SPACE_DIM>
56std::pair<unsigned, unsigned> Edge<SPACE_DIM>::GenerateMapIndex(unsigned indexA,
57 unsigned indexB)
58{
59 return std::make_pair(std::min(indexA, indexB), std::max(indexA, indexB));
60}
61
62template<unsigned SPACE_DIM>
64{
65 mIsDeleted = true;
66}
67
68template<unsigned SPACE_DIM>
70{
71 return mIsDeleted;
72}
73
74template<unsigned SPACE_DIM>
75void Edge<SPACE_DIM>::SetIndex(unsigned index)
76{
77 mIndex = index;
78}
79
80template<unsigned SPACE_DIM>
82{
83 return mIndex;
84}
85
86template<unsigned SPACE_DIM>
87std::pair<unsigned ,unsigned> Edge<SPACE_DIM>::GetMapIndex()
88{
89 assert(mNodes.size() == 2);
90 const unsigned index0 = mNodes[0]->GetIndex();
91 const unsigned index1 = mNodes[1]->GetIndex();
92 return Edge<SPACE_DIM>::GenerateMapIndex(index0, index1);
93}
94
95template<unsigned SPACE_DIM>
97{
98 mNodes.clear();
99}
100
101template<unsigned SPACE_DIM>
103 Node<SPACE_DIM>* pNodeB)
104{
105 // Clear the nodes first
106 this->RemoveNodes();
107
108 // Add nodes
109 this->mNodes.push_back(pNodeA);
110 this->mNodes.push_back(pNodeB);
111}
112
113template<unsigned SPACE_DIM>
115 Node<SPACE_DIM>* pNewNode)
116{
117 for (unsigned i = 0; i < 2; i++)
118 {
119 if (this->mNodes[i] == pOldNode)
120 {
121 this->mNodes[i] = pNewNode;
122 return;
123 }
124 }
125}
126
127template<unsigned SPACE_DIM>
129{
130 return mNodes[index];
131}
132
133template<unsigned SPACE_DIM>
135{
136 return mNodes.size();
137}
138
139template<unsigned SPACE_DIM>
141{
142 for (auto p_node : mNodes)
143 {
144 if (p_node->GetIndex() == pNode->GetIndex())
145 {
146 return true;
147 }
148 }
149 return false;
150}
151
152template<unsigned SPACE_DIM>
153c_vector<double, SPACE_DIM> Edge<SPACE_DIM>::rGetCentreLocation()
154{
155 assert(mNodes.size() == 2);
156 return 0.5*(mNodes[0]->rGetLocation() + mNodes[1]->rGetLocation());
157}
158
159template<unsigned SPACE_DIM>
161{
162 assert(mNodes.size() == 2);
163 return norm_2(mNodes[0]->rGetLocation() - mNodes[1]->rGetLocation());
164}
165
166template<unsigned SPACE_DIM>
167std::set<unsigned> Edge<SPACE_DIM>::GetOtherElements(unsigned elementIndex)
168{
169 std::set<unsigned> otherElements;
170 for (unsigned elem: mElementIndices)
171 {
172 if (elem != elementIndex)
173 {
174 otherElements.insert(elem);
175 }
176 }
177 return otherElements;
178}
179
180template<unsigned SPACE_DIM>
181void Edge<SPACE_DIM>::AddElement(unsigned elementIndex)
182{
183 mElementIndices.insert(elementIndex);
184}
185
186template<unsigned SPACE_DIM>
187void Edge<SPACE_DIM>::RemoveElement(unsigned elementIndex)
188{
189 mElementIndices.erase(elementIndex);
190}
191
192template<unsigned SPACE_DIM>
194{
195 std::set<unsigned> neighbouring_element_indices;
196
197 auto elem_indices0 = mNodes[0]->rGetContainingElementIndices();
198 auto elem_indices1 = mNodes[1]->rGetContainingElementIndices();
199
200 std::set_intersection(elem_indices0.begin(), elem_indices0.end(),
201 elem_indices1.begin(), elem_indices1.end(),
202 std::inserter(neighbouring_element_indices, neighbouring_element_indices.begin()));
203
204 return neighbouring_element_indices;
205}
206
207template<unsigned SPACE_DIM>
209{
210 return mElementIndices.size();
211}
212
213template<unsigned SPACE_DIM>
215{
216 return mElementIndices.size()<=1;
217}
218
219template <unsigned SPACE_DIM>
221{
222 return this->ContainsNode(rEdge.GetNode(0)) && this->ContainsNode(rEdge.GetNode(1));
223}
224
225// Explicit instantiation
226template class Edge<1>;
227template class Edge<2>;
228template class Edge<3>;
Definition Edge.hpp:52
bool ContainsNode(Node< SPACE_DIM > *pNode) const
Definition Edge.cpp:140
void SetNodes(Node< SPACE_DIM > *pNodeA, Node< SPACE_DIM > *pNodeB)
Definition Edge.cpp:102
void RemoveElement(unsigned elementIndex)
Definition Edge.cpp:187
c_vector< double, SPACE_DIM > rGetCentreLocation()
Definition Edge.cpp:153
std::set< unsigned > GetNeighbouringElementIndices()
Definition Edge.cpp:193
unsigned GetIndex() const
Definition Edge.cpp:81
double rGetLength()
Definition Edge.cpp:160
Node< SPACE_DIM > * GetNode(unsigned index) const
Definition Edge.cpp:128
Edge(unsigned index)
Definition Edge.cpp:39
static std::pair< unsigned, unsigned > GenerateMapIndex(unsigned index1, unsigned index2)
Definition Edge.cpp:56
std::set< unsigned > GetOtherElements(unsigned elementIndex)
Definition Edge.cpp:167
bool IsDeleted()
Definition Edge.cpp:69
void MarkAsDeleted()
Definition Edge.cpp:63
bool operator==(const Edge< SPACE_DIM > &rEdge) const
Definition Edge.cpp:220
unsigned GetNumNodes()
Definition Edge.cpp:134
void ReplaceNode(Node< SPACE_DIM > *pOldNode, Node< SPACE_DIM > *pNewNode)
Definition Edge.cpp:114
void SetIndex(unsigned index)
Definition Edge.cpp:75
void RemoveNodes()
Definition Edge.cpp:96
unsigned GetNumElements()
Definition Edge.cpp:208
bool IsBoundaryEdge() const
Definition Edge.cpp:214
void AddElement(unsigned elementIndex)
Definition Edge.cpp:181
std::pair< unsigned, unsigned > GetMapIndex()
Definition Edge.cpp:87
Definition Node.hpp:59
unsigned GetIndex() const
Definition Node.cpp:158