v0.8.23
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< hashed_unique< member< ParentChild, EntityHandle, &ParentChild::pArent > >, hashed_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 getSucessMerge ()
 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 ()
 
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<hashed_unique< member<ParentChild, EntityHandle, &ParentChild::pArent> >, hashed_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:476
CHKERRQ(ierr)
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:406

◆ getSucessMerge()

bool MoFEM::NodeMergerInterface::getSucessMerge ( )

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 463 of file NodeMerger.cpp.

465  {
466  Interface &m_field = cOre;
468 
469  EntityHandle conn[] = {father, mother};
470 
471  double coords[6];
472  if (th == NULL) {
473  CHKERR m_field.get_moab().get_coords(conn, 2, coords);
474  } else {
475  CHKERR m_field.get_moab().tag_get_data(th, conn, 2, coords);
476  }
477 
479  FTensor::Tensor1<double, 3> t_coords(coords[0], coords[1], coords[2]);
481  for (int nn = 0; nn != 3; nn++) {
482  t_delta(nn) = coords[3 + nn] - t_coords(nn);
483  }
484 
485  t_move(i) = t_coords(i);
486  double min_quality_i = 1;
487  CHKERR minQuality(check_tests, father, mother, &t_move(0), min_quality_i, th,
489 
490  t_move(i) = t_coords(i) + t_delta(i);
491  double min_quality_k = 1;
492  CHKERR minQuality(check_tests, father, mother, &t_move(0), min_quality_k, th,
494 
495  double alpha_i = 0;
496  double alpha_k = 1;
497 
498  for (int ii = 0; ii != line_search; ii++) {
499  double min_quality = 1;
500  double alpha = (alpha_i + alpha_k) * 0.5;
501  t_move(i) = t_coords(i) + alpha * t_delta(i);
502  CHKERR minQuality(check_tests, father, mother, &t_move(0), min_quality, th,
504  if (min_quality_i >= min_quality_k) {
505  min_quality_k = min_quality;
506  alpha_k = alpha;
507  } else {
508  min_quality_i = min_quality;
509  alpha_i = alpha;
510  }
511  }
512 
513  if (min_quality_i > min_quality_k) {
514  t_move(i) = t_coords(i) + alpha_i * t_delta(i);
515  } else {
516  t_move(i) = t_coords(i) + alpha_k * t_delta(i);
517  }
518 
520 }
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:476
#define CHKERR
Inline error check.
Definition: definitions.h:595
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:406
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:399

◆ 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
tetrahedraafter merge
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 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  Range adj_father_ents;
298  for (int dd = 1; dd <= 2; dd++) {
299  CHKERR m_field.get_moab().get_adjacencies(
300  created_tets, dd, true, adj_father_ents, moab::Interface::UNION);
301  }
302  FaceMapIdx face_map;
303  for (auto ent : adj_father_ents) {
304  int num_nodes;
305  const EntityHandle *conn = get_conn(ent, &num_nodes);
306  EntityHandle small_conn[num_nodes];
307  int ii = 0;
308  int nn = 0;
309  bool father_node = false;
310  for (; nn != num_nodes; nn++) {
311  if (conn[nn] == father) {
312  father_node = true;
313  } else {
314  small_conn[ii++] = conn[nn];
315  }
316  }
317  if (father_node) {
318  if (ii > 1) {
319  std::sort(&small_conn[0], &small_conn[ii]);
320  }
321  if (ii == 2) {
322  face_map.insert(FaceMap(ent, small_conn[0], small_conn[1]));
323  } else {
324  face_map.insert(FaceMap(ent, small_conn[0], 0));
325  }
326  }
327  }
328 
329  Range adj_mother_ents;
330  for (int dd = 1; dd <= 2; ++dd) {
331  CHKERR m_field.get_moab().get_adjacencies(
332  mother_tets, dd, false, adj_mother_ents, moab::Interface::UNION);
333  }
334 
335  adj_mother_ents.erase(common_edge[0]);
336  for (auto ent : adj_mother_ents) {
337  int num_nodes;
338  const EntityHandle *conn = get_conn(ent, &num_nodes);
339  // EntityHandle new_conn[num_nodes];
340  EntityHandle small_conn[num_nodes];
341  int nb_new_node = 0;
342  int nn = 0;
343  int ii = 0;
344  for (; nn != num_nodes; ++nn) {
345  if (conn[nn] == mother) {
346  // new_conn[nn] = father;
347  nb_new_node++;
348  } else {
349  // new_conn[nn] = conn[nn];
350  small_conn[ii++] = conn[nn];
351  }
352  }
353  if (nb_new_node > 0) {
354  if (ii > 1) {
355  std::sort(&small_conn[0], &small_conn[ii]);
356  }
357  EntityHandle n0 = small_conn[0], n1 = 0;
358  if (ii == 2) {
359  n1 = small_conn[1];
360  }
361  FaceMapIdx::iterator fit = face_map.find(boost::make_tuple(n0, n1));
362  if (fit == face_map.end()) {
363  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Entity not found");
364  }
365  const EntityHandle child = fit->e;
366  const EntityHandle parent = ent;
367  if (m_field.get_moab().dimension_from_handle(parent) !=
368  m_field.get_moab().dimension_from_handle(child)) {
369  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
370  "Huston we have a problem!");
371  }
372  CHKERR m_field.get_moab().tag_set_data(cOre.get_th_RefParentHandle(),
373  &parent, 1, &child);
374  // create map
375  parentChildMap.insert(ParentChild(parent, child));
376  }
377  }
378 
379  // Seed tets to given bit level
380  Range seed_tets;
381  if (tets_ptr != NULL) {
382  seed_tets.merge(*tets_ptr);
383  seed_tets = subtract(seed_tets, edge_tets);
384  seed_tets = subtract(seed_tets, mother_tets);
385  }
386  seed_tets.merge(created_tets);
387  out_tets.swap(seed_tets);
388 
389  successMerge = true;
390 
391  if (verb > VERY_VERBOSE) {
392  std::cout << "nodes merged" << endl;
393  }
394 
396 }
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:476
#define THROW_MESSAGE(a)
Throw MoFEM exception.
Definition: definitions.h:619
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:507
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:595
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:463
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:406
ublas::vector< double, DoubleAllocator > VectorDouble
Definition: Types.hpp:76
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:399

◆ 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 522 of file NodeMerger.cpp.

524  {
525  Interface &m_field = cOre;
527  Range out_tets;
528  CHKERR mergeNodes(father, mother, out_tets, tets_ptr, only_if_improve_quality,
529  move, 0, th);
530  CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevel(out_tets, bit);
532 }
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:476
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:595
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:406

◆ 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 534 of file NodeMerger.cpp.

537  {
538  Interface &m_field = cOre;
540  Range level_tets;
541  CHKERR m_field.getInterface<BitRefManager>()->getEntitiesByTypeAndRefLevel(
542  tets_from_bit_ref_level, BitRefLevel().set(), MBTET, level_tets);
543  CHKERR mergeNodes(father, mother, bit, &level_tets, only_if_improve_quality,
544  move, th);
546 }
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:476
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:595
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:406

◆ 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 399 of file NodeMerger.cpp.

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

◆ 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:500
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:507

◆ 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: