Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
LoopNode.h
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MoDELib is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_LoopNode_H_
9#define model_LoopNode_H_
10
11#include <iostream>
12#include <set>
13#include <memory>
14#include <assert.h>
15#include <tuple>
16#include <limits.h>
17
18#include <StaticID.h>
19#include <CRTP.h>
20
21#include <LoopLink.h>
22#include <NetworkNode.h>
23#include <NetworkBase.h>
24
25
26
27#ifndef NDEBUG
28#define VerboseLoopNode(N,x) if(verboseLevel>=N){std::cout<<greenColor<<x<<defaultColor;}
29#else
30#define VerboseLoopNode(N,x)
31#endif
32
33namespace model
34{
35
36 template<typename Derived>
37 class LoopNode : public StaticID<Derived>
38 /* */,public CRTP<Derived>
39 /* */,public NetworkBase<Derived,size_t>
40 {
41
42 public:
43
44 typedef Derived LoopNodeType;
50
51
52 private:
53
54
55
56 std::shared_ptr<LoopType> _loop;
57
58
59 public:
60
61 std::shared_ptr<NetworkNodeType> networkNode;
62 std::pair<LoopNodeType*,LoopLinkType*> prev;
63 std::pair<LoopNodeType*,LoopLinkType*> next;
64
65
66 static int verboseLevel;
67
68
69
70
71 /**********************************************************************/
72 LoopNode(LoopNetworkType* const loopNetwork_in,
73 const std::shared_ptr<LoopType>& loop_in,
74 const std::shared_ptr<NetworkNodeType>& networkNode_in) :
75 /* init */ NetworkBaseType(loopNetwork_in,&loopNetwork_in->loopNodes(),this->sID)
76 /* init */,_loop(loop_in)
77 /* init */,networkNode(networkNode_in)
78 /* init */,prev(nullptr,nullptr)
79 /* init */,next(nullptr,nullptr)
80 {
81 VerboseLoopNode(1,"Constructing LoopNode "<<tag()<<std::endl);
82
83 networkNode->addLoopNode(this->p_derived());
84 }
85
86 /**********************************************************************/
88 {
89 VerboseLoopNode(1,"Destroying LoopNode "<<tag()<<std::endl);
90
91 assert(prev.first==nullptr && "~LoopNode prev.first!=nullptr");
92 assert(prev.second==nullptr && "~LoopNode prev.second!=nullptr");
93 assert(next.first==nullptr && "~LoopNode next.first!=nullptr");
94 assert(next.second==nullptr && "~LoopNode next.second!=nullptr");
95
96 networkNode->removeLoopNode(this->p_derived());
97 }
98
99// size_t networkID() const
100// {
101// return std::distance(this->network().loopNodes().begin(),this->network().loopNodes().find(this->key));
102// }
103
104 /**********************************************************************/
105 void resetLoop(const std::shared_ptr<LoopType>& newLoop)
106 {
107 VerboseLoopNode(1,"LoopNode "<<tag()<<" resetLoop to "<<newLoop->tag()<<std::endl);
108 assert((isIsolated() || _loop==newLoop) && "Trying to change loop of LoopNode connected to LoopLinks");
109 if(isIsolated() && _loop!=newLoop)
110 {
111 _loop=newLoop;
112 }
113 }
114
115 /**********************************************************************/
116 bool isIsolated() const
117 {
118 return prev.first==nullptr && next.first==nullptr;
119 }
120
121 /**********************************************************************/
122 const std::shared_ptr<LoopType>& loop() const
123 {
124 return _loop;
125 }
126
127 /**********************************************************************/
128 bool isContractableTo(const Derived* const other) const
129 {
130 return loop()==other->loop();
131 }
132
133 /**********************************************************************/
134 size_t gID() const
135 {
138 return this->network().globalNodeID(this->sID);
139 }
140
141 /**********************************************************************/
142 void addLoopLink(LoopLinkType* const pL)
143 {
144 VerboseLoopNode(2,"LoopNode "<<tag()<<" addLoopLink "<<pL->tag()<<std::endl);
145 VerboseLoopNode(3,"LoopNode "<<tag()<<" loop()= "<<loop()->tag()<<std::endl);
146 VerboseLoopNode(3,"LoopLink "<<pL->tag()<<" loop= "<<pL->loop->tag()<<std::endl);
147
148 assert(pL->loop==_loop && "LoopNode and LoopLink in different loops");
149
150 if(pL->source.get()==this)
151 {// outlink (next)
152 assert((next.first==nullptr || next.first==pL->sink.get()) && "LoopNode::addLoopLink wrong next node ");
153 assert((next.second==nullptr || next.second==pL) && "LoopNode::addLoopLink wrong next link");
154 next.first=pL->sink.get();
155 next.second=pL;
156
157 assert((pL->prev==nullptr || pL->prev==prev.second));
158 pL->prev=prev.second;
159 if(prev.second)
160 {
161 assert(prev.second->loop==pL->loop && "links in different loops");
162 prev.second->next=pL;
163 }
164 }
165 else if(pL->sink.get()==this)
166 {// inlink (prev)
167 assert((prev.first==nullptr || prev.first==pL->source.get()) && "LoopNode::addLoopLink wrong prev node ");
168 assert((prev.second==nullptr || prev.second==pL) && "LoopNode::addLoopLink wrong prev link");
169 prev.first=pL->source.get();
170 prev.second=pL;
171
172 assert((pL->next==nullptr || pL->next==next.second));
173 pL->next=next.second;
174 if(next.second)
175 {
176 assert(next.second->loop==pL->loop && "links in different loops");
177 next.second->prev=pL;
178 }
179 }
180 else
181 {
182 assert(false && "LoopLink connected to wrong node.");
183 }
184 }
185
186 /**********************************************************************/
188 {
189 VerboseLoopNode(2,"LoopNode "<<tag()<<" removeLoopLink "<<pL->tag()<<std::endl);
190 assert(pL->loop==_loop && "LoopNode and LoopLink in different loops");
191
192
193 if(pL->source.get()==this)
194 {// outlink (next)
195 VerboseLoopNode(3,"LoopNode "<<tag()<<" removeLoopLink (next) "<<pL->tag()<<std::endl);
196
197 assert((next.first==nullptr || next.first==pL->sink.get()) && "LoopNode::addLoopLink wrong next node ");
198 assert((next.second==nullptr || next.second==pL) && "LoopNode::addLoopLink wrong next link");
199 next.first=nullptr;
200 next.second=nullptr;
201
202 assert((pL->prev==nullptr || pL->prev==prev.second));
203 if(prev.second)
204 {
205 prev.second->next=nullptr;
206 }
207 }
208 else if(pL->sink.get()==this)
209 {// inlink (prev)
210 VerboseLoopNode(3,"LoopNode "<<tag()<<" removeLoopLink (prev) "<<pL->tag()<<std::endl);
211
212 assert((prev.first==nullptr || prev.first==pL->source.get()) && "LoopNode::addLoopLink wrong prev node ");
213 assert((prev.second==nullptr || prev.second==pL) && "LoopNode::addLoopLink wrong prev link");
214 prev.first=nullptr;
215 prev.second=nullptr;
216
217 assert((pL->next==nullptr || pL->next==next.second));
218 if(next.second)
219 {
220 next.second->prev=nullptr;
221 }
222 }
223 else
224 {
225 assert(false && "LoopLink connected to wrong node.");
226 }
227
228 }
229
230 /**********************************************************************/
231 // void updateConfinedGeometry()
232 // {
233 // //This will change the confinement for the loop node in the derived layer
234 // //Added by Yash
235 // }
236 /**********************************************************************/
237 std::string tag() const
238 {
240 return std::to_string(this->sID) + "[" + (networkNode? networkNode->tag() : "?") + "]";
241 }
242
243 };
244
245 template<typename Derived>
247
248
249
250}
251#endif
Derived * p_derived()
A pointer to the derived object.
Definition CRTP.h:27
CRTP()
The default constructor.
Definition CRTP.h:37
LoopNode(LoopNetworkType *const loopNetwork_in, const std::shared_ptr< LoopType > &loop_in, const std::shared_ptr< NetworkNodeType > &networkNode_in)
Definition LoopNode.h:72
TypeTraits< Derived >::NetworkNodeType NetworkNodeType
Definition LoopNode.h:47
TypeTraits< Derived >::LoopType LoopType
Definition LoopNode.h:46
void addLoopLink(LoopLinkType *const pL)
Definition LoopNode.h:142
bool isIsolated() const
Definition LoopNode.h:116
void resetLoop(const std::shared_ptr< LoopType > &newLoop)
Definition LoopNode.h:105
std::shared_ptr< NetworkNodeType > networkNode
Definition LoopNode.h:61
const std::shared_ptr< LoopType > & loop() const
Definition LoopNode.h:122
static int verboseLevel
Definition LoopNode.h:66
std::string tag() const
Definition LoopNode.h:237
void removeLoopLink(LoopLinkType *const pL)
Definition LoopNode.h:187
std::pair< LoopNodeType *, LoopLinkType * > prev
Definition LoopNode.h:62
Derived LoopNodeType
Definition LoopNode.h:44
NetworkBase< Derived, size_t > NetworkBaseType
Definition LoopNode.h:49
TypeTraits< Derived >::LoopLinkType LoopLinkType
Definition LoopNode.h:45
bool isContractableTo(const Derived *const other) const
Definition LoopNode.h:128
size_t gID() const
Definition LoopNode.h:134
std::pair< LoopNodeType *, LoopLinkType * > next
Definition LoopNode.h:63
TypeTraits< Derived >::LoopNetworkType LoopNetworkType
Definition LoopNode.h:48
const LoopNetworkType & network() const
Definition NetworkBase.h:57
NetworkBase(const NetworkBase< LoopNetworkType, KeyType > &)=delete
const size_t sID
The static ID of this.
Definition StaticID.h:41