www.mooseframework.org
EFAEdge.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
8 #include "EFAEdge.h"
9 
10 #include "EFANode.h"
11 #include "EFAError.h"
12 #include "XFEMFuncs.h"
13 
14 EFAEdge::EFAEdge(EFANode * node1, EFANode * node2) : _edge_node1(node1), _edge_node2(node2)
15 {
16  _embedded_nodes.clear();
17  _intersection_x.clear();
18  _edge_interior_node = NULL;
20 }
21 
22 EFAEdge::EFAEdge(const EFAEdge & other_edge)
23 {
24  _edge_node1 = other_edge._edge_node1;
25  _edge_node2 = other_edge._edge_node2;
26  _intersection_x = other_edge._intersection_x;
27  _embedded_nodes = other_edge._embedded_nodes;
29 }
30 
31 EFAEdge::~EFAEdge() // do not delete edge node - they will be deleted
32 { // in EFAelement's destructor
33 }
34 
35 bool
36 EFAEdge::equivalent(const EFAEdge & other) const
37 {
38  bool isEqual = false;
39  if (other._edge_node1 == _edge_node1 && other._edge_node2 == _edge_node2)
40  isEqual = true;
41  else if (other._edge_node2 == _edge_node1 && other._edge_node1 == _edge_node2)
42  isEqual = true;
43 
44  // For cut along the edge case
45  if (isEqual)
46  {
49  isEqual = false;
50  }
51  return isEqual;
52 }
53 
54 bool
55 EFAEdge::isPartialOverlap(const EFAEdge & other) const
56 {
57  return containsEdge(other) || other.containsEdge(*this);
58 }
59 
60 bool
61 EFAEdge::containsEdge(const EFAEdge & other) const
62 {
63  return containsNode(other._edge_node1) && containsNode(other._edge_node2);
64 }
65 
66 bool
68  std::vector<EFANode *> & master_nodes,
69  std::vector<double> & master_weights) const
70 {
71  master_nodes.clear();
72  master_weights.clear();
73  bool masters_found = false;
74  if (_edge_node1 == node || _edge_node2 == node)
75  {
76  master_nodes.push_back(node);
77  master_weights.push_back(1.0);
78  masters_found = true;
79  }
80  else
81  {
82  for (unsigned int i = 0; i < _embedded_nodes.size(); ++i)
83  {
84  if (_embedded_nodes[i] == node)
85  {
86  master_nodes.push_back(_edge_node1);
87  master_nodes.push_back(_edge_node2);
88  master_weights.push_back(1.0 - _intersection_x[i]);
89  master_weights.push_back(_intersection_x[i]);
90  masters_found = true;
91  break;
92  }
93  }
94  }
95  return masters_found;
96 }
97 
98 // TODO: Saving because I don't want to throw it away, but it needs more work to be used.
99 // bool
100 // EFAEdge::operator < (const edge_t & other) const
101 //{
102 // node_t * this_min_node;
103 // node_t * this_max_node;
104 // node_t * other_min_node;
105 // node_t * other_max_node;
106 //
107 // int this_node1_unique_index = ((int) edge_node1->category + 1) * edge_node1->id;
108 // int this_node2_unique_index = ((int) edge_node2->category + 1) * edge_node2->id;
109 // int other_node1_unique_index = ((int) other.edge_node1->category + 1) * edge_node1->id;
110 // int other_node2_unique_index = ((int) other.edge_node2->category + 1) * edge_node2->id;
111 // int this_min_index = std::min(this_node1_unique_index, this_node2_unique_index);
112 // int other_min_index = std::min(other_node1_unique_index, other_node2_unique_index);
113 //
114 // if (this_min_index < other_min_index)
115 // return true;
116 // else if (this_min_index == other_min_index)
117 // {
118 // int this_max_index = std::max(this_node1_unique_index, this_node2_unique_index);
119 // int other_max_index = std::max(other_node1_unique_index, other_node2_unique_index);
120 //
121 // if (this_max_index < other_max_index)
122 // return true;
123 // }
124 // return false;
125 //}
126 
127 void
128 EFAEdge::addIntersection(double position, EFANode * embedded_node_tmp, EFANode * from_node)
129 {
130  _embedded_nodes.push_back(embedded_node_tmp);
131  if (from_node == _edge_node1)
132  _intersection_x.push_back(position);
133  else if (from_node == _edge_node2)
134  _intersection_x.push_back(1.0 - position);
135  else
136  EFAError("In addIntersection from_node does not exist on edge");
137 }
138 
139 void
140 EFAEdge::resetIntersection(double position, EFANode * embedded_node_tmp, EFANode * from_node)
141 {
142  for (unsigned int i = 0; i < _embedded_nodes.size(); ++i)
143  {
144  if (_embedded_nodes[i] == embedded_node_tmp)
145  {
146  if (from_node == _edge_node1)
147  _intersection_x[i] = position;
148  else if (from_node == _edge_node2)
149  _intersection_x[i] = 1.0 - position;
150  else
151  EFAError("In resetIntersection from_node does not exist on edge");
152  break;
153  }
154  }
155 }
156 
157 void
158 EFAEdge::copyIntersection(const EFAEdge & other, unsigned int from_node_id)
159 {
160  _embedded_nodes.clear();
161  _intersection_x.clear();
163  if (from_node_id == 0)
165  else if (from_node_id == 1)
166  {
167  for (unsigned int i = 0; i < other.numEmbeddedNodes(); ++i)
168  _intersection_x.push_back(1.0 - other._intersection_x[i]);
169  }
170  else
171  EFAError("from_node_id out of bounds");
172  if (_embedded_nodes.size() != _intersection_x.size())
173  EFAError("in copyIntersection num emb_nodes must == num of inters_x");
174 }
175 
176 EFANode *
177 EFAEdge::getNode(unsigned int index) const
178 {
179  if (index == 0)
180  return _edge_node1;
181  else if (index == 1)
182  return _edge_node2;
183  else
184  EFAError("In getNode index out of bounds");
185 }
186 
187 void
189 {
190  std::swap(_edge_node1, _edge_node2);
191  for (unsigned int i = 0; i < _embedded_nodes.size(); ++i)
192  _intersection_x[i] = 1.0 - _intersection_x[i];
193 }
194 
195 bool
197 {
198  bool has = false;
199  if (_edge_node1->parent() != NULL)
201 
202  if (_edge_node2->parent() != NULL)
204 
205  return has || _embedded_nodes.size() > 0;
206 }
207 
208 bool
209 EFAEdge::hasIntersectionAtPosition(double position, EFANode * from_node) const
210 {
211  bool has_int = false;
212  if (hasIntersection())
213  {
214  double tmp_intersection_x = -1.0;
215  if (from_node == _edge_node1)
216  tmp_intersection_x = position;
217  else if (from_node == _edge_node2)
218  tmp_intersection_x = 1.0 - position;
219  else
220  EFAError("In hasIntersectionAtPosition from_node does not exist on edge");
221 
222  for (unsigned int i = 0; i < _embedded_nodes.size(); ++i)
223  {
224  if (std::abs(tmp_intersection_x - _intersection_x[i]) < Xfem::tol)
225  {
226  has_int = true;
227  break;
228  }
229  }
230  }
231  return has_int;
232 }
233 
234 double
235 EFAEdge::getIntersection(unsigned int emb_id, EFANode * from_node) const
236 {
237  if (from_node == _edge_node1)
238  return _intersection_x[emb_id];
239  else if (from_node == _edge_node2)
240  return 1.0 - _intersection_x[emb_id];
241  else
242  EFAError("In getIntersection node not in edge");
243 }
244 
245 double
247 {
248  double xi = -100.0;
249  if (_edge_node1 == node)
250  xi = 0.0;
251  else if (_edge_node2 == node)
252  xi = 1.0;
253  else if (isEmbeddedNode(node))
254  {
255  unsigned int embedded_node_id = getEmbeddedNodeIndex(node);
256  xi = _intersection_x[embedded_node_id];
257  }
258  else
259  EFAError("the given node is not found in the current edge");
260  return xi;
261 }
262 
263 bool
264 EFAEdge::isEmbeddedNode(const EFANode * node) const
265 {
266  bool is_emb = false;
267  for (unsigned int i = 0; i < _embedded_nodes.size(); ++i)
268  {
269  if (_embedded_nodes[i] == node)
270  {
271  is_emb = true;
272  break;
273  }
274  }
275  return is_emb;
276 }
277 
278 unsigned int
280 {
281  unsigned int index;
282  bool have_index = false;
283  for (unsigned int i = 0; i < _embedded_nodes.size(); ++i)
284  {
285  if (_embedded_nodes[i] == node)
286  {
287  have_index = true;
288  index = i;
289  break;
290  }
291  }
292  if (!have_index)
293  EFAError("In getEmbeddedNodeIndex, could not find index");
294  return index;
295 }
296 
297 unsigned int
298 EFAEdge::getEmbeddedNodeIndex(double position, EFANode * from_node) const
299 {
300  bool have_index = false;
301  unsigned int index;
302  if (hasIntersection())
303  {
304  double tmp_intersection_x = -1.0; // dist from edge_node1
305  if (from_node == _edge_node1)
306  tmp_intersection_x = position;
307  else if (from_node == _edge_node2)
308  tmp_intersection_x = 1.0 - position;
309  else
310  EFAError("In getEmbeddedNodeIndex, from_node does not exist on edge");
311 
312  for (unsigned int i = 0; i < _embedded_nodes.size(); ++i)
313  {
314  if (std::abs(tmp_intersection_x - _intersection_x[i]) < Xfem::tol)
315  {
316  have_index = true;
317  index = i;
318  break;
319  }
320  }
321  }
322  if (!have_index)
323  EFAError("In getEmbeddedNodeIndex, could not find index");
324  return index;
325 }
326 
327 EFANode *
328 EFAEdge::getEmbeddedNode(unsigned int index) const
329 {
330  if (index < _embedded_nodes.size())
331  return _embedded_nodes[index];
332  else
333  EFAError("in getEmbeddedNode index out of bounds");
334 }
335 
336 unsigned int
338 {
339  return _embedded_nodes.size();
340 }
341 
342 void
344 {
345  bool consistent = true;
349  consistent = false;
353  consistent = false;
354  if (!consistent)
355  EFAError("In consistencyCheck nodes on edge are not consistent");
356  if (_embedded_nodes.size() != _intersection_x.size())
357  EFAError("In consistencyCheck num of emb_nodes must be = num of inters_x");
358 }
359 
360 void
361 EFAEdge::switchNode(EFANode * new_node, EFANode * old_node)
362 {
363  if (_edge_node1 == old_node)
364  _edge_node1 = new_node;
365  else if (_edge_node2 == old_node)
366  _edge_node2 = new_node;
367  else if (isEmbeddedNode(old_node))
368  {
369  unsigned int id = getEmbeddedNodeIndex(old_node);
370  _embedded_nodes[id] = new_node;
371  }
372 }
373 
374 bool
375 EFAEdge::containsNode(const EFANode * node) const
376 {
377  return _edge_node1 == node || _edge_node2 == node || isEmbeddedNode(node);
378 }
379 
380 void
382 {
383  _embedded_nodes.clear();
384  _intersection_x.clear();
385 }
386 
387 void
389 {
390  unsigned int index = 0;
391  bool node_found = false;
392  for (unsigned int i = 0; i < _embedded_nodes.size(); ++i)
393  {
394  if (_embedded_nodes[i] == node)
395  {
396  index = i;
397  node_found = true;
398  break;
399  }
400  }
401  if (node_found)
402  {
403  _embedded_nodes.erase(_embedded_nodes.begin() + index);
404  _intersection_x.erase(_intersection_x.begin() + index);
405  }
406 }
EFANode * getEmbeddedNode(unsigned int index) const
Definition: EFAEdge.C:328
void reverseNodes()
Definition: EFAEdge.C:188
bool containsEdge(const EFAEdge &other) const
Definition: EFAEdge.C:61
EFANode * parent() const
Definition: EFANode.C:46
void switchNode(EFANode *new_node, EFANode *old_node)
Definition: EFAEdge.C:361
std::vector< double > _intersection_x
Definition: EFAEdge.h:28
void consistencyCheck()
Definition: EFAEdge.C:343
bool containsNode(const EFANode *node) const
Definition: EFAEdge.C:375
double distanceFromNode1(EFANode *node) const
Definition: EFAEdge.C:246
bool hasIntersectionAtPosition(double position, EFANode *from_node) const
Definition: EFAEdge.C:209
unsigned int numEmbeddedNodes() const
Definition: EFAEdge.C:337
bool getNodeMasters(EFANode *node, std::vector< EFANode * > &master_nodes, std::vector< double > &master_weights) const
Definition: EFAEdge.C:67
std::vector< EFANode * > _embedded_nodes
Definition: EFAEdge.h:27
EFAEdge(EFANode *node1, EFANode *node2)
Definition: EFAEdge.C:14
N_CATEGORY category() const
Definition: EFANode.C:40
~EFAEdge()
Definition: EFAEdge.C:31
void resetIntersection(double position, EFANode *embedded_node_tmp, EFANode *from_node)
Definition: EFAEdge.C:140
EFANode * _edge_node1
Definition: EFAEdge.h:24
EFANode * _edge_interior_node
Definition: EFAEdge.h:26
static const double tol
Definition: XFEMFuncs.h:26
void copyIntersection(const EFAEdge &other, unsigned int from_node_id)
Definition: EFAEdge.C:158
EFANode * getNode(unsigned int index) const
Definition: EFAEdge.C:177
bool isEmbeddedNode(const EFANode *node) const
Definition: EFAEdge.C:264
void removeEmbeddedNodes()
Definition: EFAEdge.C:381
bool hasIntersection() const
Definition: EFAEdge.C:196
EFANode * _edge_node2
Definition: EFAEdge.h:25
bool isPartialOverlap(const EFAEdge &other) const
Definition: EFAEdge.C:55
unsigned int getEmbeddedNodeIndex(EFANode *node) const
Definition: EFAEdge.C:279
bool equivalent(const EFAEdge &other) const
Definition: EFAEdge.C:36
double getIntersection(unsigned int emb_id, EFANode *from_node) const
Definition: EFAEdge.C:235
void addIntersection(double position, EFANode *embedded_node_tmp, EFANode *from_node)
Definition: EFAEdge.C:128
void removeEmbeddedNode(EFANode *node)
Definition: EFAEdge.C:388