v0.9.0
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
MoFEM::NodeMergerInterface Struct Reference

Merge node by collapsing edge between them. More...

#include <src/interfaces/NodeMerger.hpp>

Inheritance diagram for MoFEM::NodeMergerInterface:
[legend]
Collaboration diagram for MoFEM::NodeMergerInterface:
[legend]

Classes

struct  FaceMap
 
struct  ParentChild
 

Public Types

typedef multi_index_container< ParentChild, indexed_by< ordered_unique< member< ParentChild, EntityHandle, &ParentChild::pArent > >, ordered_non_unique< member< ParentChild, EntityHandle, &ParentChild::cHild > > > > ParentChildMap
 

Public Member Functions

MoFEMErrorCode query_interface (const MOFEMuuid &uuid, UnknownInterface **iface) const
 
 NodeMergerInterface (const MoFEM::Core &core)
 
MoFEMErrorCode getSubInterfaceOptions ()
 
bool getSuccessMerge ()
 Return true if successful merge. More...
 
void setErrorIfNoCommonEdge (const bool b=true)
 Set error if no common edge. More...
 
MoFEMErrorCode mergeNodes (EntityHandle father, EntityHandle mother, Range &out_tets, Range *tets_ptr=NULL, const bool only_if_improve_quality=false, const double move=0, const int line_search=0, Tag th=NULL, const int verb=0)
 merge nodes which sharing edge More...
 
MoFEMErrorCode mergeNodes (EntityHandle father, EntityHandle mother, BitRefLevel bit, Range *tets_ptr=NULL, const bool only_if_improve_quality=false, const double move=0, Tag th=NULL)
 merge nodes which sharing edge More...
 
MoFEMErrorCode mergeNodes (EntityHandle father, EntityHandle mother, BitRefLevel bit, BitRefLevel tets_from_bit_ref_level, const bool only_if_improve_quality=false, const double move=0, Tag th=NULL)
 merge nodes which sharing edge More...
 
ParentChildMapgetParentChildMap ()
 Get map of parent cand child. More...
 
- Public Member Functions inherited from MoFEM::UnknownInterface
template<class IFACE >
MoFEMErrorCode registerInterface (const MOFEMuuid &uuid, bool error_if_registration_failed=true)
 Register interface. More...
 
template<class IFACE , bool VERIFY = false>
MoFEMErrorCode getInterface (const MOFEMuuid &uuid, IFACE *&iface) const
 Get interface by uuid and return reference to pointer of interface. More...
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE *&iface) const
 Get interface refernce to pointer of interface. More...
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE **const iface) const
 Get interface pointer to pointer of interface. More...
 
template<class IFACE , typename boost::enable_if< boost::is_pointer< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get interface pointer to pointer of interface. More...
 
template<class IFACE , typename boost::enable_if< boost::is_reference< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get reference to interface. More...
 
template<class IFACE >
IFACE * getInterface () const
 Function returning pointer to interface. More...
 
virtual ~UnknownInterface ()=default
 
virtual MoFEMErrorCode getLibVersion (Version &version) const
 Get library version. More...
 
virtual const MoFEMErrorCode getFileVersion (moab::Interface &moab, Version &version) const
 Get database major version. More...
 
virtual MoFEMErrorCode getInterfaceVersion (Version &version) const
 Get database major version. More...
 
template<>
MoFEMErrorCode getInterface (const MOFEMuuid &uuid, UnknownInterface *&iface) const
 

Private Types

typedef multi_index_container< FaceMap, indexed_by< hashed_unique< composite_key< FaceMap, member< FaceMap, EntityHandle, &FaceMap::n0 >, member< FaceMap, EntityHandle, &FaceMap::n1 > > > > > FaceMapIdx
 

Private Member Functions

MoFEMErrorCode minQuality (Range &check_tests, EntityHandle father, EntityHandle mother, double *coords_move, double &min_quality, Tag th=NULL, boost::function< double(double, double)> f=[](double a, double b) -> double { return std::min(a, b);})
 Calualte quality if nodes merged. More...
 
MoFEMErrorCode lineSearch (Range &check_tests, EntityHandle father, EntityHandle mother, int line_search, FTensor::Tensor1< double, 3 > &t_move, Tag th=NULL)
 Use bisection method to find point of edge collapse. More...
 

Private Attributes

MoFEM::CorecOre
 
boost::function< double(const double a, const double b)> minQualityFunction
 
bool successMerge
 True if marge is success. More...
 
bool errorIfNoCommonEdge
 Send error if no common edge. More...
 
ParentChildMap parentChildMap
 

Additional Inherited Members

- Protected Member Functions inherited from MoFEM::UnknownInterface
boost::typeindex::type_index getClassIdx (const MOFEMuuid &uid) const
 Get type name for interface Id. More...
 
MOFEMuuid getUId (const boost::typeindex::type_index &class_idx) const
 Get interface Id for class name. More...
 

Detailed Description

Merge node by collapsing edge between them.

Definition at line 30 of file NodeMerger.hpp.

Member Typedef Documentation

◆ FaceMapIdx

typedef multi_index_container< FaceMap, indexed_by<hashed_unique<composite_key< FaceMap, member<FaceMap, EntityHandle, &FaceMap::n0>, member<FaceMap, EntityHandle, &FaceMap::n1> > > > > MoFEM::NodeMergerInterface::FaceMapIdx
private

Definition at line 183 of file NodeMerger.hpp.

◆ ParentChildMap

typedef multi_index_container< ParentChild, indexed_by<ordered_unique< member<ParentChild, EntityHandle, &ParentChild::pArent> >, ordered_non_unique< member<ParentChild, EntityHandle, &ParentChild::cHild> > > > MoFEM::NodeMergerInterface::ParentChildMap

Definition at line 128 of file NodeMerger.hpp.

Constructor & Destructor Documentation

◆ NodeMergerInterface()

MoFEM::NodeMergerInterface::NodeMergerInterface ( const MoFEM::Core core)

Definition at line 72 of file NodeMerger.cpp.

73  : cOre(const_cast<MoFEM::Core &>(core)), minQualityFunction(min_non_abs),
74  successMerge(false), errorIfNoCommonEdge(false) {}
boost::function< double(const double a, const double b)> minQualityFunction
Definition: NodeMerger.hpp:138
static auto min_non_abs(const double a, const double b)
Definition: NodeMerger.cpp:68
bool successMerge
True if marge is success.
Definition: NodeMerger.hpp:140
bool errorIfNoCommonEdge
Send error if no common edge.
Definition: NodeMerger.hpp:141

Member Function Documentation

◆ getParentChildMap()

ParentChildMap& MoFEM::NodeMergerInterface::getParentChildMap ( )

Get map of parent cand child.

Returns

Definition at line 134 of file NodeMerger.hpp.

134 { return parentChildMap; }
ParentChildMap parentChildMap
Definition: NodeMerger.hpp:171

◆ getSubInterfaceOptions()

MoFEMErrorCode MoFEM::NodeMergerInterface::getSubInterfaceOptions ( )

Definition at line 76 of file NodeMerger.cpp.

76  {
77  Interface &m_field = cOre;
79  ierr = PetscOptionsBegin(m_field.get_comm(), "node_merge",
80  "Node merge options", "none");
81  CHKERRQ(ierr);
82 
83  ierr = PetscOptionsEnd();
84  CHKERRQ(ierr);
85 
87 }
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:477
CHKERRQ(ierr)
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:407

◆ getSuccessMerge()

bool MoFEM::NodeMergerInterface::getSuccessMerge ( )

Return true if successful merge.

Returns
Error code

Definition at line 44 of file NodeMerger.hpp.

44 { return successMerge; }
bool successMerge
True if marge is success.
Definition: NodeMerger.hpp:140

◆ lineSearch()

MoFEMErrorCode MoFEM::NodeMergerInterface::lineSearch ( Range &  check_tests,
EntityHandle  father,
EntityHandle  mother,
int  line_search,
FTensor::Tensor1< double, 3 > &  t_move,
Tag  th = NULL 
)
private

Use bisection method to find point of edge collapse.

Parameters
check_testsrange of tets to check quality
fatherfirst node of the edge
mothersecond node of the edge
line_searchnumber of iterations
coords_movenode to move
Returns
error code

Definition at line 455 of file NodeMerger.cpp.

457  {
458  Interface &m_field = cOre;
460 
461  EntityHandle conn[] = {father, mother};
462 
463  double coords[6];
464  if (th == NULL) {
465  CHKERR m_field.get_moab().get_coords(conn, 2, coords);
466  } else {
467  CHKERR m_field.get_moab().tag_get_data(th, conn, 2, coords);
468  }
469 
471  FTensor::Tensor1<double, 3> t_coords(coords[0], coords[1], coords[2]);
473  for (int nn = 0; nn != 3; nn++) {
474  t_delta(nn) = coords[3 + nn] - t_coords(nn);
475  }
476 
477  t_move(i) = t_coords(i);
478  double min_quality_i = 1;
479  CHKERR minQuality(check_tests, father, mother, &t_move(0), min_quality_i, th,
481 
482  t_move(i) = t_coords(i) + t_delta(i);
483  double min_quality_k = 1;
484  CHKERR minQuality(check_tests, father, mother, &t_move(0), min_quality_k, th,
486 
487  double alpha_i = 0;
488  double alpha_k = 1;
489 
490  for (int ii = 0; ii != line_search; ii++) {
491  double min_quality = 1;
492  double alpha = (alpha_i + alpha_k) * 0.5;
493  t_move(i) = t_coords(i) + alpha * t_delta(i);
494  CHKERR minQuality(check_tests, father, mother, &t_move(0), min_quality, th,
496  if (min_quality_i >= min_quality_k) {
497  min_quality_k = min_quality;
498  alpha_k = alpha;
499  } else {
500  min_quality_i = min_quality;
501  alpha_i = alpha;
502  }
503  }
504 
505  if (min_quality_i > min_quality_k) {
506  t_move(i) = t_coords(i) + alpha_i * t_delta(i);
507  } else {
508  t_move(i) = t_coords(i) + alpha_k * t_delta(i);
509  }
510 
512 }
boost::function< double(const double a, const double b)> minQualityFunction
Definition: NodeMerger.hpp:138
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:477
#define CHKERR
Inline error check.
Definition: definitions.h:596
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:407
MoFEMErrorCode minQuality(Range &check_tests, EntityHandle father, EntityHandle mother, double *coords_move, double &min_quality, Tag th=NULL, boost::function< double(double, double)> f=[](double a, double b) -> double { return std::min(a, b);})
Calualte quality if nodes merged.
Definition: NodeMerger.cpp:391

◆ mergeNodes() [1/3]

MoFEMErrorCode MoFEM::NodeMergerInterface::mergeNodes ( EntityHandle  father,
EntityHandle  mother,
Range &  out_tets,
Range *  tets_ptr = NULL,
const bool  only_if_improve_quality = false,
const double  move = 0,
const int  line_search = 0,
Tag  th = NULL,
const int  verb = 0 
)

merge nodes which sharing edge

Father is sties, mother is merged.

Parameters
fathernode to which mother is merged to.
mothermerged node
out_tetstetrahedra after merge
tets_ptrtest only tets_ptr from range are changed
only_if_improve_qualityDo merge if that improve quality
movefather by fraction of edge length move=[0,1]

Move node on the edge, 0 not move, 1 move to mother side, 0.5 will be in the middle.

Definition at line 89 of file NodeMerger.cpp.

92  {
93  Interface &m_field = cOre;
96 
97  // Get edges adjacent to father and mother, i.e. mother is merged to father.
98  Range father_edges;
99  CHKERR m_field.get_moab().get_adjacencies(&father, 1, 1, false, father_edges);
100  Range mother_edges;
101  CHKERR m_field.get_moab().get_adjacencies(&mother, 1, 1, false, mother_edges);
102 
103  // Get tets adjacent to mother and father
104  Range father_tets;
105  CHKERR m_field.get_moab().get_adjacencies(&father, 1, 3, false, father_tets);
106  Range mother_tets;
107  CHKERR m_field.get_moab().get_adjacencies(&mother, 1, 3, false, mother_tets);
108  if (tets_ptr != NULL) {
109  mother_tets = intersect(mother_tets, *tets_ptr);
110  father_tets = intersect(father_tets, *tets_ptr);
111  }
112 
113  // Find common edge
114  Range common_edge;
115  common_edge = intersect(father_edges, mother_edges);
116  if (tets_ptr != NULL) {
117  Range tets = unite(father_tets, mother_tets);
118  Range tets_edges;
119  CHKERR m_field.get_moab().get_adjacencies(tets, 1, false, tets_edges,
120  moab::Interface::UNION);
121  common_edge = intersect(common_edge, tets_edges);
122  father_edges = intersect(father_edges, tets_edges);
123  mother_edges = intersect(mother_edges, tets_edges);
124  }
125 
126  // No common edge, merge no possible
127  if (errorIfNoCommonEdge && common_edge.empty()) {
128  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
129  "no common edge between nodes");
130  } else if (common_edge.empty()) {
131  Range seed_tets;
132  if (tets_ptr != NULL) {
133  seed_tets.merge(*tets_ptr);
134  }
135  out_tets = seed_tets;
136  successMerge = false;
138  }
139 
140  // Common edge tets, that tests will be squashed
141  Range edge_tets;
142  CHKERR m_field.get_moab().get_adjacencies(common_edge, 3, true, edge_tets);
143  // Intersect with ptr_tets (usually associated with some bit level)
144  if (tets_ptr != NULL) {
145  edge_tets = intersect(edge_tets, *tets_ptr);
146  }
147  // Mother tets, has only one mother vertex and no father vertex.
148  mother_tets = subtract(mother_tets, edge_tets);
149  father_tets = subtract(father_tets, edge_tets);
150 
151  auto get_coords = [&m_field](Tag th, const EntityHandle *conn,
152  const int num_nodes) {
153  VectorDouble coords(3 * num_nodes);
154  if (th == NULL) {
155  CHKERR m_field.get_moab().get_coords(conn, num_nodes, &coords[0]);
156  } else {
157  CHKERR m_field.get_moab().tag_get_data(th, conn, num_nodes, &coords[0]);
158  }
159  return coords;
160  };
161 
162  auto get_tensor = [](VectorDouble &coords, const int shift) {
164  &coords[shift], &coords[shift + 1], &coords[shift + 2]);
165  };
166 
167  // move father coord is move > 0
169  if (move > 0) {
170  EntityHandle conn[] = {father, mother};
171  VectorDouble coords = get_coords(th, conn, 2);
172  auto t_n0 = get_tensor(coords, 0);
173  auto t_n1 = get_tensor(coords, 3);
174  t_move(i) = t_n0(i) + move * (t_n1(i) - t_n0(i));
175  }
176 
177  if (line_search > 0) {
178  Range check_tests = unite(father_tets, mother_tets);
179  CHKERR lineSearch(check_tests, father, mother, line_search, t_move, th);
180  }
181 
182  if (only_if_improve_quality) {
183  Range check_tests = mother_tets;
184  // no need to check father tets since no change of quality for them
185  if (move > 0 || line_search) {
186  check_tests.merge(father_tets);
187  }
188 
189  double min_quality0 = 1;
190  CHKERR minQuality(edge_tets, 0, 0, NULL, min_quality0, th,
192  CHKERR minQuality(check_tests, 0, 0, NULL, min_quality0, th,
194  double min_quality = 1;
195  CHKERR minQuality(check_tests, father, mother,
196  ((move > 0) || line_search) ? &t_move(0) : NULL,
197  min_quality, th, minQualityFunction);
198  if (min_quality < min_quality0) {
199  if (tets_ptr != NULL) {
200  out_tets = *tets_ptr;
201  }
202  successMerge = false;
204  }
205  }
206 
207  // Move node
208  if (move > 0 || line_search) {
209  if (th == NULL) {
210  CHKERR m_field.get_moab().set_coords(&father, 1, &t_move(0));
211  } else {
212  CHKERR m_field.get_moab().tag_set_data(th, &father, 1, &t_move(0));
213  }
214  }
215 
216  auto get_conn = [&m_field](const EntityHandle ent,
217  int *ret_num_nodes = nullptr) {
218  int num_nodes;
219  const EntityHandle *conn;
220  CHKERR m_field.get_moab().get_connectivity(ent, conn, num_nodes, true);
221  if (ret_num_nodes)
222  *ret_num_nodes = num_nodes;
223  return conn;
224  };
225 
226  auto create_tet = [this, &m_field](const EntityHandle *new_conn,
227  const EntityHandle parent) {
228  EntityHandle tet;
229  Range tets;
230  CHKERR m_field.get_moab().get_adjacencies(new_conn, 4, 3, false, tets);
231  bool tet_found = false;
232  for (auto it_tet : tets) {
233  const EntityHandle *tet_conn;
234  int num_nodes;
235  CHKERR m_field.get_moab().get_connectivity(it_tet, tet_conn, num_nodes,
236  true);
237  const EntityHandle *p = std::find(tet_conn, &tet_conn[4], new_conn[0]);
238  if (p != tet_conn + 4) {
239  int s = std::distance(tet_conn, p);
240  int n = 0;
241  for (; n != 4; ++n) {
242  const int idx[] = {0, 1, 2, 3, 0, 1, 2, 3};
243  if (tet_conn[idx[s + n]] != new_conn[n])
244  break;
245  }
246  if (n == 4 && !tet_found) {
247  tet = it_tet;
248  tet_found = true;
249  } else if (n == 4) {
250  THROW_MESSAGE("More that one tet with the same connectivity");
251  }
252  }
253  }
254  if (!tet_found) {
255  // Create tet with new connectivity
256  CHKERR m_field.get_moab().create_element(MBTET, new_conn, 4, tet);
257  CHKERR m_field.get_moab().tag_set_data(cOre.get_th_RefParentHandle(),
258  &tet, 1, &parent);
259  parentChildMap.insert(ParentChild(parent, tet));
260  }
261  return tet;
262  };
263 
264  // clear map
265  parentChildMap.clear();
266 
267  Range created_tets;
268  for (auto m_tet : mother_tets) {
269  const EntityHandle *conn = get_conn(m_tet);
270  EntityHandle new_conn[4];
271  // Replace mother vertices by father vertices
272  int nb_mother_verts = 0;
273  for (int nn = 0; nn != 4; ++nn) {
274  if (conn[nn] == father) {
275  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
276  "Tet has father vertex, impossible but here it is");
277  }
278  if (conn[nn] == mother) {
279  new_conn[nn] = father;
280  nb_mother_verts++;
281  } else {
282  new_conn[nn] = conn[nn];
283  }
284  }
285  if (nb_mother_verts != 1) {
286  SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
287  "Tet should have only one vertex but have %d", nb_mother_verts);
288  }
289 
290  VectorDouble new_coords = get_coords(th, new_conn, 4);
291 
292  // add tet to range
293  created_tets.insert(create_tet(new_conn, m_tet));
294  }
295 
296  // Loop over mother adjacent entities to use them as parents
297  auto get_adj_ents = [&](const Range &ents, const bool create) {
298  Range adj;
299  for (int dd = 1; dd <= 2; dd++)
300  CHKERR m_field.get_moab().get_adjacencies(ents, dd, create, adj,
301  moab::Interface::UNION);
302  return adj;
303  };
304  auto adj_crated_ents = get_adj_ents(created_tets, true);
305  adj_crated_ents.erase(common_edge[0]);
306 
307  FaceMapIdx face_map;
308  for (auto ent : adj_crated_ents) {
309  int num_nodes;
310  const EntityHandle *conn = get_conn(ent, &num_nodes);
311  EntityHandle small_conn[num_nodes];
312  int ii = 0;
313  bool father_node = false;
314  for (int nn = 0; nn != num_nodes; nn++) {
315  if (conn[nn] == father)
316  father_node = true;
317  else
318  small_conn[ii++] = conn[nn];
319  }
320  if (father_node) {
321  if (ii > 1)
322  std::sort(&small_conn[0], &small_conn[ii]);
323  if (ii == 2)
324  face_map.insert(FaceMap(ent, small_conn[0], small_conn[1]));
325  else
326  face_map.insert(FaceMap(ent, small_conn[0], 0));
327  }
328  }
329 
330  auto adj_mother_ents = get_adj_ents(mother_tets, false);
331  adj_mother_ents.erase(common_edge[0]);
332  for (auto ent : adj_mother_ents) {
333  int num_nodes;
334  const EntityHandle *conn = get_conn(ent, &num_nodes);
335  EntityHandle small_conn[num_nodes];
336  int nb_new_node = 0;
337  int nn = 0;
338  int ii = 0;
339  for (; nn != num_nodes; ++nn) {
340  if (conn[nn] == mother) {
341  nb_new_node++;
342  } else {
343  small_conn[ii++] = conn[nn];
344  }
345  }
346  if (nb_new_node > 0) {
347  if (ii > 1)
348  std::sort(&small_conn[0], &small_conn[ii]);
349 
350  EntityHandle n0 = small_conn[0], n1 = 0;
351  if (ii == 2)
352  n1 = small_conn[1];
353 
354  FaceMapIdx::iterator fit = face_map.find(boost::make_tuple(n0, n1));
355  if (fit != face_map.end()) {
356  const EntityHandle child = fit->e;
357  const EntityHandle parent = ent;
358  if (m_field.get_moab().dimension_from_handle(parent) !=
359  m_field.get_moab().dimension_from_handle(child))
360  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
361  "Huston we have a problem!");
362 
363  // Set parent child relation
364  CHKERR m_field.get_moab().tag_set_data(cOre.get_th_RefParentHandle(),
365  &child, 1, &parent);
366  // Create map
367  parentChildMap.insert(ParentChild(parent, child));
368  }
369  }
370  }
371 
372  // Seed tets to given bit level
373  Range seed_tets;
374  if (tets_ptr != NULL) {
375  seed_tets.merge(*tets_ptr);
376  seed_tets = subtract(seed_tets, edge_tets);
377  seed_tets = subtract(seed_tets, mother_tets);
378  }
379  seed_tets.merge(created_tets);
380  out_tets.swap(seed_tets);
381 
382  successMerge = true;
383 
384  if (verb > VERY_VERBOSE)
385  std::cerr << "Nodes merged" << endl;
386 
388 }
boost::function< double(const double a, const double b)> minQualityFunction
Definition: NodeMerger.hpp:138
Tag get_th_RefParentHandle() const
Definition: Core.hpp:150
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:477
#define THROW_MESSAGE(a)
Throw MoFEM exception.
Definition: definitions.h:620
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:508
bool successMerge
True if marge is success.
Definition: NodeMerger.hpp:140
const Tensor2_symmetric_Expr< const ddTensor0< T, Dim, i, j >, typename promote< T, double >::V, Dim, i, j > dd(const Tensor0< T * > &a, const Index< i, Dim > index1, const Index< j, Dim > index2, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
Definition: ddTensor0.hpp:33
ParentChildMap parentChildMap
Definition: NodeMerger.hpp:171
bool errorIfNoCommonEdge
Send error if no common edge.
Definition: NodeMerger.hpp:141
#define CHKERR
Inline error check.
Definition: definitions.h:596
MoFEMErrorCode lineSearch(Range &check_tests, EntityHandle father, EntityHandle mother, int line_search, FTensor::Tensor1< double, 3 > &t_move, Tag th=NULL)
Use bisection method to find point of edge collapse.
Definition: NodeMerger.cpp:455
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:407
ublas::vector< double, DoubleAllocator > VectorDouble
Definition: Types.hpp:72
multi_index_container< FaceMap, indexed_by< hashed_unique< composite_key< FaceMap, member< FaceMap, EntityHandle, &FaceMap::n0 >, member< FaceMap, EntityHandle, &FaceMap::n1 > > > > > FaceMapIdx
Definition: NodeMerger.hpp:183
MoFEMErrorCode minQuality(Range &check_tests, EntityHandle father, EntityHandle mother, double *coords_move, double &min_quality, Tag th=NULL, boost::function< double(double, double)> f=[](double a, double b) -> double { return std::min(a, b);})
Calualte quality if nodes merged.
Definition: NodeMerger.cpp:391

◆ mergeNodes() [2/3]

MoFEMErrorCode MoFEM::NodeMergerInterface::mergeNodes ( EntityHandle  father,
EntityHandle  mother,
BitRefLevel  bit,
Range *  tets_ptr = NULL,
const bool  only_if_improve_quality = false,
const double  move = 0,
Tag  th = NULL 
)

merge nodes which sharing edge

Father is sties, mother is merged.

Parameters
fathernode to which mother is merged to.
mothermerged node
bitlevel of mesh merged nodes mesh
testonly tets_ptr from range are changed
only_if_improve_qualityDo merge if that improve quality
movefather by fraction of edge length move=[0,1]

Move node on the edge, 0 not move, 1 move to mother side, 0.5 will be in the middle.

Definition at line 514 of file NodeMerger.cpp.

516  {
517  Interface &m_field = cOre;
519  Range out_tets;
520  CHKERR mergeNodes(father, mother, out_tets, tets_ptr, only_if_improve_quality,
521  move, 0, th);
522  CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevel(out_tets, bit);
524 }
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:477
MoFEMErrorCode mergeNodes(EntityHandle father, EntityHandle mother, Range &out_tets, Range *tets_ptr=NULL, const bool only_if_improve_quality=false, const double move=0, const int line_search=0, Tag th=NULL, const int verb=0)
merge nodes which sharing edge
Definition: NodeMerger.cpp:89
#define CHKERR
Inline error check.
Definition: definitions.h:596
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:407

◆ mergeNodes() [3/3]

MoFEMErrorCode MoFEM::NodeMergerInterface::mergeNodes ( EntityHandle  father,
EntityHandle  mother,
BitRefLevel  bit,
BitRefLevel  tets_from_bit_ref_level,
const bool  only_if_improve_quality = false,
const double  move = 0,
Tag  th = NULL 
)

merge nodes which sharing edge

Father is sties, mother is merged.

Parameters
fathernode to which mother is merged to.
mothermerged node
tets_from_bit_ref_levelonly tetrahedrons from bit level are changed
only_if_improve_qualityDo merge if that improve quality
movefather by fraction of edge length move=[0,1]

Move node on the edge, 0 not move, 1 move to mother side, 0.5 will be in the middle.

Definition at line 526 of file NodeMerger.cpp.

529  {
530  Interface &m_field = cOre;
532  Range level_tets;
533  CHKERR m_field.getInterface<BitRefManager>()->getEntitiesByTypeAndRefLevel(
534  tets_from_bit_ref_level, BitRefLevel().set(), MBTET, level_tets);
535  CHKERR mergeNodes(father, mother, bit, &level_tets, only_if_improve_quality,
536  move, th);
538 }
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:477
MoFEMErrorCode mergeNodes(EntityHandle father, EntityHandle mother, Range &out_tets, Range *tets_ptr=NULL, const bool only_if_improve_quality=false, const double move=0, const int line_search=0, Tag th=NULL, const int verb=0)
merge nodes which sharing edge
Definition: NodeMerger.cpp:89
#define CHKERR
Inline error check.
Definition: definitions.h:596
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:51
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:407

◆ minQuality()

MoFEMErrorCode MoFEM::NodeMergerInterface::minQuality ( Range &  check_tests,
EntityHandle  father,
EntityHandle  mother,
double coords_move,
double min_quality,
Tag  th = NULL,
boost::function< double(double, double)>  f = [](double a, double b) -> double { return std::min(a, b); } 
)
private

Calualte quality if nodes merged.

Parameters
check_teststets to check
fatherfirst node of the edge
mothersecond node of the edge
coords_movemoved father node
min_qualitycalculated quality
Returns
error code

Definition at line 391 of file NodeMerger.cpp.

394  {
395  Interface &m_field = cOre;
396  double coords[12];
399  for (Range::iterator tit = check_tests.begin(); tit != check_tests.end();
400  tit++) {
401  const EntityHandle *conn;
402  int num_nodes;
403  CHKERR m_field.get_moab().get_connectivity(*tit, conn, num_nodes, true);
404  if (mother > 0) {
405  EntityHandle new_conn[4];
406  // Replace mother vertices by father vertices
407  int nb_mother_verts = 0;
408  int father_nn = 0;
409  for (int nn = 0; nn < 4; nn++) {
410  if (conn[nn] == father) {
411  father_nn = nn;
412  }
413  if (conn[nn] == mother) {
414  new_conn[nn] = father;
415  father_nn = nn;
416  nb_mother_verts++;
417  } else {
418  new_conn[nn] = conn[nn];
419  }
420  }
421  if (nb_mother_verts > 1) {
422  SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
423  "Tet should have no more than one mother vertex but have %d",
424  nb_mother_verts);
425  }
426  if (th == NULL) {
427  CHKERR m_field.get_moab().get_coords(new_conn, num_nodes, coords);
428  } else {
429  CHKERR m_field.get_moab().tag_get_data(th, new_conn, num_nodes, coords);
430  }
431  if (coords_move) {
432  int shift = 3 * father_nn;
433  for (int nn = 0; nn != 3; nn++) {
434  coords[shift + nn] = coords_move[nn];
435  }
436  }
437  } else {
438  if (th == NULL) {
439  CHKERR m_field.get_moab().get_coords(conn, num_nodes, coords);
440  } else {
441  CHKERR m_field.get_moab().tag_get_data(th, conn, num_nodes, coords);
442  }
443  }
444  double quality = Tools::volumeLengthQuality(coords);
445  if (!std::isnormal(quality)) {
446  min_quality = 0;
448  }
449  min_quality = f(min_quality, quality);
450  }
452 };
static double volumeLengthQuality(const double *coords)
Calculate tetrahedron volume length quality.
Definition: Tools.cpp:34
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:477
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:508
#define CHKERR
Inline error check.
Definition: definitions.h:596
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:407

◆ query_interface()

MoFEMErrorCode MoFEM::NodeMergerInterface::query_interface ( const MOFEMuuid uuid,
UnknownInterface **  iface 
) const
virtual

Implements MoFEM::UnknownInterface.

Definition at line 56 of file NodeMerger.cpp.

57  {
59  *iface = NULL;
60  if (uuid == IDD_MOFEMNodeMerger) {
61  *iface = const_cast<NodeMergerInterface *>(this);
63  }
64  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "unknown interface");
66 }
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:501
static const MOFEMuuid IDD_MOFEMNodeMerger
Definition: NodeMerger.hpp:23
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:508

◆ setErrorIfNoCommonEdge()

void MoFEM::NodeMergerInterface::setErrorIfNoCommonEdge ( const bool  b = true)

Set error if no common edge.

Parameters
bIf true send error if false no error

Definition at line 50 of file NodeMerger.hpp.

50  {
52  }
bool errorIfNoCommonEdge
Send error if no common edge.
Definition: NodeMerger.hpp:141

Member Data Documentation

◆ cOre

MoFEM::Core& MoFEM::NodeMergerInterface::cOre
private

Definition at line 137 of file NodeMerger.hpp.

◆ errorIfNoCommonEdge

bool MoFEM::NodeMergerInterface::errorIfNoCommonEdge
private

Send error if no common edge.

Definition at line 141 of file NodeMerger.hpp.

◆ minQualityFunction

boost::function<double(const double a, const double b)> MoFEM::NodeMergerInterface::minQualityFunction
private

Definition at line 138 of file NodeMerger.hpp.

◆ parentChildMap

ParentChildMap MoFEM::NodeMergerInterface::parentChildMap
private

Definition at line 171 of file NodeMerger.hpp.

◆ successMerge

bool MoFEM::NodeMergerInterface::successMerge
private

True if marge is success.

Definition at line 140 of file NodeMerger.hpp.


The documentation for this struct was generated from the following files: