v0.13.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 (boost::typeindex::type_index type_index, 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 (bool error_if_registration_failed=true)
 Register 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
 

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

- Static Public Member Functions inherited from MoFEM::UnknownInterface
static MoFEMErrorCode getLibVersion (Version &version)
 Get library version. More...
 
static MoFEMErrorCode getFileVersion (moab::Interface &moab, Version &version)
 Get database major version. More...
 
static MoFEMErrorCode setFileVersion (moab::Interface &moab, Version version=Version(MoFEM_VERSION_MAJOR, MoFEM_VERSION_MINOR, MoFEM_VERSION_BUILD))
 Get database major version. More...
 
static MoFEMErrorCode getInterfaceVersion (Version &version)
 Get database major version. More...
 

Detailed Description

Merge node by collapsing edge between them.

Definition at line 27 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 179 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 124 of file NodeMerger.hpp.

Constructor & Destructor Documentation

◆ NodeMergerInterface()

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

Definition at line 31 of file NodeMerger.cpp.

32  : cOre(const_cast<MoFEM::Core &>(core)), minQualityFunction(min_non_abs),
33  successMerge(false), errorIfNoCommonEdge(false) {}
static auto min_non_abs(const double a, const double b)
Definition: NodeMerger.cpp:27
Core (interface) class.
Definition: Core.hpp:92
bool successMerge
True if marge is success.
Definition: NodeMerger.hpp:136
boost::function< double(const double a, const double b)> minQualityFunction
Definition: NodeMerger.hpp:134
bool errorIfNoCommonEdge
Send error if no common edge.
Definition: NodeMerger.hpp:137

Member Function Documentation

◆ getParentChildMap()

ParentChildMap& MoFEM::NodeMergerInterface::getParentChildMap ( )

Get map of parent cand child.

Returns

Definition at line 130 of file NodeMerger.hpp.

130 { return parentChildMap; }
ParentChildMap parentChildMap
Definition: NodeMerger.hpp:167

◆ getSubInterfaceOptions()

MoFEMErrorCode MoFEM::NodeMergerInterface::getSubInterfaceOptions ( )

Definition at line 35 of file NodeMerger.cpp.

35  {
36  Interface &m_field = cOre;
38  ierr = PetscOptionsBegin(m_field.get_comm(), "node_merge",
39  "Node merge options", "none");
40  CHKERRQ(ierr);
41 
42  ierr = PetscOptionsEnd();
43  CHKERRQ(ierr);
44 
46 }
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Exceptions.hpp:87
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1965

◆ getSuccessMerge()

bool MoFEM::NodeMergerInterface::getSuccessMerge ( )

Return true if successful merge.

Returns
Error code

Definition at line 40 of file NodeMerger.hpp.

40 { return successMerge; }

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

416  {
417  Interface &m_field = cOre;
419 
420  EntityHandle conn[] = {father, mother};
421 
422  double coords[6];
423  if (th == NULL) {
424  CHKERR m_field.get_moab().get_coords(conn, 2, coords);
425  } else {
426  CHKERR m_field.get_moab().tag_get_data(th, conn, 2, coords);
427  }
428 
430  FTensor::Tensor1<double, 3> t_coords(coords[0], coords[1], coords[2]);
432  for (int nn = 0; nn != 3; nn++) {
433  t_delta(nn) = coords[3 + nn] - t_coords(nn);
434  }
435 
436  t_move(i) = t_coords(i);
437  double min_quality_i = 1;
438  CHKERR minQuality(check_tests, father, mother, &t_move(0), min_quality_i, th,
440 
441  t_move(i) = t_coords(i) + t_delta(i);
442  double min_quality_k = 1;
443  CHKERR minQuality(check_tests, father, mother, &t_move(0), min_quality_k, th,
445 
446  double alpha_i = 0;
447  double alpha_k = 1;
448 
449  for (int ii = 0; ii != line_search; ii++) {
450  double min_quality = 1;
451  double alpha = (alpha_i + alpha_k) * 0.5;
452  t_move(i) = t_coords(i) + alpha * t_delta(i);
453  CHKERR minQuality(check_tests, father, mother, &t_move(0), min_quality, th,
455  if (min_quality_i >= min_quality_k) {
456  min_quality_k = min_quality;
457  alpha_k = alpha;
458  } else {
459  min_quality_i = min_quality;
460  alpha_i = alpha;
461  }
462  }
463 
464  if (min_quality_i > min_quality_k) {
465  t_move(i) = t_coords(i) + alpha_i * t_delta(i);
466  } else {
467  t_move(i) = t_coords(i) + alpha_k * t_delta(i);
468  }
469 
471 }
constexpr double alpha
#define CHKERR
Inline error check.
Definition: definitions.h:548
FTensor::Index< 'i', SPACE_DIM > i
MoFEMErrorCode check_tests(int ss, int test_num, double &expected_energy, double &expected_contact_area, int &expected_nb_gauss_pts)
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:350

◆ mergeNodes() [1/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 485 of file NodeMerger.cpp.

488  {
489  Interface &m_field = cOre;
491  Range level_tets;
492  CHKERR m_field.getInterface<BitRefManager>()->getEntitiesByTypeAndRefLevel(
493  tets_from_bit_ref_level, BitRefLevel().set(), MBTET, level_tets);
494  CHKERR mergeNodes(father, mother, bit, &level_tets, only_if_improve_quality,
495  move, th);
497 }
auto bit
set bit
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:51
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:48

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

475  {
476  Interface &m_field = cOre;
478  Range out_tets;
479  CHKERR mergeNodes(father, mother, out_tets, tets_ptr, only_if_improve_quality,
480  move, 0, th);
481  CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevel(out_tets, bit);
483 }

◆ mergeNodes() [3/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 48 of file NodeMerger.cpp.

51  {
52  Interface &m_field = cOre;
55 
56  // Get edges adjacent to father and mother, i.e. mother is merged to father.
57  Range father_edges;
58  CHKERR m_field.get_moab().get_adjacencies(&father, 1, 1, false, father_edges);
59  Range mother_edges;
60  CHKERR m_field.get_moab().get_adjacencies(&mother, 1, 1, false, mother_edges);
61 
62  // Get tets adjacent to mother and father
63  Range father_tets;
64  CHKERR m_field.get_moab().get_adjacencies(&father, 1, 3, false, father_tets);
65  Range mother_tets;
66  CHKERR m_field.get_moab().get_adjacencies(&mother, 1, 3, false, mother_tets);
67  if (tets_ptr != NULL) {
68  mother_tets = intersect(mother_tets, *tets_ptr);
69  father_tets = intersect(father_tets, *tets_ptr);
70  }
71 
72  // Find common edge
73  Range common_edge;
74  common_edge = intersect(father_edges, mother_edges);
75  if (tets_ptr != NULL) {
76  Range tets = unite(father_tets, mother_tets);
77  Range tets_edges;
78  CHKERR m_field.get_moab().get_adjacencies(tets, 1, false, tets_edges,
79  moab::Interface::UNION);
80  common_edge = intersect(common_edge, tets_edges);
81  father_edges = intersect(father_edges, tets_edges);
82  mother_edges = intersect(mother_edges, tets_edges);
83  }
84 
85  // No common edge, merge no possible
86  if (errorIfNoCommonEdge && common_edge.empty()) {
87  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
88  "no common edge between nodes");
89  } else if (common_edge.empty()) {
90  Range seed_tets;
91  if (tets_ptr != NULL) {
92  seed_tets.merge(*tets_ptr);
93  }
94  out_tets = seed_tets;
95  successMerge = false;
97  }
98 
99  // Common edge tets, that tests will be squashed
100  Range edge_tets;
101  CHKERR m_field.get_moab().get_adjacencies(common_edge, 3, true, edge_tets);
102  // Intersect with ptr_tets (usually associated with some bit level)
103  if (tets_ptr != NULL) {
104  edge_tets = intersect(edge_tets, *tets_ptr);
105  }
106  // Mother tets, has only one mother vertex and no father vertex.
107  mother_tets = subtract(mother_tets, edge_tets);
108  father_tets = subtract(father_tets, edge_tets);
109 
110  auto get_coords = [&m_field](Tag th, const EntityHandle *conn,
111  const int num_nodes) {
112  VectorDouble coords(3 * num_nodes);
113  if (th == NULL) {
114  CHKERR m_field.get_moab().get_coords(conn, num_nodes, &coords[0]);
115  } else {
116  CHKERR m_field.get_moab().tag_get_data(th, conn, num_nodes, &coords[0]);
117  }
118  return coords;
119  };
120 
121  auto get_tensor = [](VectorDouble &coords, const int shift) {
123  &coords[shift], &coords[shift + 1], &coords[shift + 2]);
124  };
125 
126  // move father coord is move > 0
128  if (move > 0) {
129  EntityHandle conn[] = {father, mother};
130  VectorDouble coords = get_coords(th, conn, 2);
131  auto t_n0 = get_tensor(coords, 0);
132  auto t_n1 = get_tensor(coords, 3);
133  t_move(i) = t_n0(i) + move * (t_n1(i) - t_n0(i));
134  }
135 
136  if (line_search > 0) {
137  Range check_tests = unite(father_tets, mother_tets);
138  CHKERR lineSearch(check_tests, father, mother, line_search, t_move, th);
139  }
140 
141  if (only_if_improve_quality) {
142  Range check_tests = mother_tets;
143  // no need to check father tets since no change of quality for them
144  if (move > 0 || line_search) {
145  check_tests.merge(father_tets);
146  }
147 
148  double min_quality0 = 1;
149  CHKERR minQuality(edge_tets, 0, 0, NULL, min_quality0, th,
151  CHKERR minQuality(check_tests, 0, 0, NULL, min_quality0, th,
153  double min_quality = 1;
154  CHKERR minQuality(check_tests, father, mother,
155  ((move > 0) || line_search) ? &t_move(0) : NULL,
156  min_quality, th, minQualityFunction);
157  if (min_quality < min_quality0) {
158  if (tets_ptr != NULL) {
159  out_tets = *tets_ptr;
160  }
161  successMerge = false;
163  }
164  }
165 
166  // Move node
167  if (move > 0 || line_search) {
168  if (th == NULL) {
169  CHKERR m_field.get_moab().set_coords(&father, 1, &t_move(0));
170  } else {
171  CHKERR m_field.get_moab().tag_set_data(th, &father, 1, &t_move(0));
172  }
173  }
174 
175  auto get_conn = [&m_field](const EntityHandle ent,
176  int *ret_num_nodes = nullptr) {
177  int num_nodes;
178  const EntityHandle *conn;
179  CHKERR m_field.get_moab().get_connectivity(ent, conn, num_nodes, true);
180  if (ret_num_nodes)
181  *ret_num_nodes = num_nodes;
182  return conn;
183  };
184 
185  auto create_tet = [this, &m_field](const EntityHandle *new_conn,
186  const EntityHandle parent) {
187  EntityHandle tet;
188  Range tets;
189  CHKERR m_field.get_moab().get_adjacencies(new_conn, 4, 3, false, tets);
190  bool tet_found = false;
191  for (auto it_tet : tets) {
192  const EntityHandle *tet_conn;
193  int num_nodes;
194  CHKERR m_field.get_moab().get_connectivity(it_tet, tet_conn, num_nodes,
195  true);
196  const EntityHandle *p = std::find(tet_conn, &tet_conn[4], new_conn[0]);
197  if (p != tet_conn + 4) {
198  int s = std::distance(tet_conn, p);
199  int n = 0;
200  for (; n != 4; ++n) {
201  const int idx[] = {0, 1, 2, 3, 0, 1, 2, 3};
202  if (tet_conn[idx[s + n]] != new_conn[n])
203  break;
204  }
205  if (n == 4 && !tet_found) {
206  tet = it_tet;
207  tet_found = true;
208  } else if (n == 4) {
209  THROW_MESSAGE("More that one tet with the same connectivity");
210  }
211  }
212  }
213  if (!tet_found) {
214  // Create tet with new connectivity
215  CHKERR m_field.get_moab().create_element(MBTET, new_conn, 4, tet);
216  CHKERR m_field.get_moab().tag_set_data(cOre.get_th_RefParentHandle(),
217  &tet, 1, &parent);
218  parentChildMap.insert(ParentChild(parent, tet));
219  }
220  return tet;
221  };
222 
223  // clear map
224  parentChildMap.clear();
225 
226  Range created_tets;
227  for (auto m_tet : mother_tets) {
228  const EntityHandle *conn = get_conn(m_tet);
229  EntityHandle new_conn[4];
230  // Replace mother vertices by father vertices
231  int nb_mother_verts = 0;
232  for (int nn = 0; nn != 4; ++nn) {
233  if (conn[nn] == father) {
234  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
235  "Tet has father vertex, impossible but here it is");
236  }
237  if (conn[nn] == mother) {
238  new_conn[nn] = father;
239  nb_mother_verts++;
240  } else {
241  new_conn[nn] = conn[nn];
242  }
243  }
244  if (nb_mother_verts != 1) {
245  SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
246  "Tet should have only one vertex but have %d", nb_mother_verts);
247  }
248 
249  VectorDouble new_coords = get_coords(th, new_conn, 4);
250 
251  // add tet to range
252  created_tets.insert(create_tet(new_conn, m_tet));
253  }
254 
255  // Loop over mother adjacent entities to use them as parents
256  auto get_adj_ents = [&](const Range &ents, const bool create) {
257  Range adj;
258  for (int dd = 1; dd <= 2; dd++)
259  CHKERR m_field.get_moab().get_adjacencies(ents, dd, create, adj,
260  moab::Interface::UNION);
261  return adj;
262  };
263  auto adj_crated_ents = get_adj_ents(created_tets, true);
264  adj_crated_ents.erase(common_edge[0]);
265 
266  FaceMapIdx face_map;
267  for (auto ent : adj_crated_ents) {
268  int num_nodes;
269  const EntityHandle *conn = get_conn(ent, &num_nodes);
270  EntityHandle small_conn[num_nodes];
271  int ii = 0;
272  bool father_node = false;
273  for (int nn = 0; nn != num_nodes; nn++) {
274  if (conn[nn] == father)
275  father_node = true;
276  else
277  small_conn[ii++] = conn[nn];
278  }
279  if (father_node) {
280  if (ii > 1)
281  std::sort(&small_conn[0], &small_conn[ii]);
282  if (ii == 2)
283  face_map.insert(FaceMap(ent, small_conn[0], small_conn[1]));
284  else
285  face_map.insert(FaceMap(ent, small_conn[0], 0));
286  }
287  }
288 
289  auto adj_mother_ents = get_adj_ents(mother_tets, false);
290  adj_mother_ents.erase(common_edge[0]);
291  for (auto ent : adj_mother_ents) {
292  int num_nodes;
293  const EntityHandle *conn = get_conn(ent, &num_nodes);
294  EntityHandle small_conn[num_nodes];
295  int nb_new_node = 0;
296  int nn = 0;
297  int ii = 0;
298  for (; nn != num_nodes; ++nn) {
299  if (conn[nn] == mother) {
300  nb_new_node++;
301  } else {
302  small_conn[ii++] = conn[nn];
303  }
304  }
305  if (nb_new_node > 0) {
306  if (ii > 1)
307  std::sort(&small_conn[0], &small_conn[ii]);
308 
309  EntityHandle n0 = small_conn[0], n1 = 0;
310  if (ii == 2)
311  n1 = small_conn[1];
312 
313  FaceMapIdx::iterator fit = face_map.find(boost::make_tuple(n0, n1));
314  if (fit != face_map.end()) {
315  const EntityHandle child = fit->e;
316  const EntityHandle parent = ent;
317  if (m_field.get_moab().dimension_from_handle(parent) !=
318  m_field.get_moab().dimension_from_handle(child))
319  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
320  "Huston we have a problem!");
321 
322  // Set parent child relation
323  CHKERR m_field.get_moab().tag_set_data(cOre.get_th_RefParentHandle(),
324  &child, 1, &parent);
325  // Create map
326  parentChildMap.insert(ParentChild(parent, child));
327  }
328  }
329  }
330 
331  // Seed tets to given bit level
332  Range seed_tets;
333  if (tets_ptr != NULL) {
334  seed_tets.merge(*tets_ptr);
335  seed_tets = subtract(seed_tets, edge_tets);
336  seed_tets = subtract(seed_tets, mother_tets);
337  }
338  seed_tets.merge(created_tets);
339  out_tets.swap(seed_tets);
340 
341  successMerge = true;
342 
343  if (verb > VERY_VERBOSE)
344  std::cerr << "Nodes merged" << endl;
345 
347 }
static Index< 'n', 3 > n
static Index< 'p', 3 > p
@ VERY_VERBOSE
Definition: definitions.h:223
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:460
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:44
#define THROW_MESSAGE(msg)
Throw MoFEM exception.
Definition: definitions.h:574
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
UBlasVector< double > VectorDouble
Definition: Types.hpp:79
Tag get_th_RefParentHandle() const
Definition: Core.hpp:207
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:179
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:414

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

353  {
354  Interface &m_field = cOre;
355  double coords[12];
358  for (Range::iterator tit = check_tests.begin(); tit != check_tests.end();
359  tit++) {
360  const EntityHandle *conn;
361  int num_nodes;
362  CHKERR m_field.get_moab().get_connectivity(*tit, conn, num_nodes, true);
363  if (mother > 0) {
364  EntityHandle new_conn[4];
365  // Replace mother vertices by father vertices
366  int nb_mother_verts = 0;
367  int father_nn = 0;
368  for (int nn = 0; nn < 4; nn++) {
369  if (conn[nn] == father) {
370  father_nn = nn;
371  }
372  if (conn[nn] == mother) {
373  new_conn[nn] = father;
374  father_nn = nn;
375  nb_mother_verts++;
376  } else {
377  new_conn[nn] = conn[nn];
378  }
379  }
380  if (nb_mother_verts > 1) {
381  SETERRQ1(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
382  "Tet should have no more than one mother vertex but have %d",
383  nb_mother_verts);
384  }
385  if (th == NULL) {
386  CHKERR m_field.get_moab().get_coords(new_conn, num_nodes, coords);
387  } else {
388  CHKERR m_field.get_moab().tag_get_data(th, new_conn, num_nodes, coords);
389  }
390  if (coords_move) {
391  int shift = 3 * father_nn;
392  for (int nn = 0; nn != 3; nn++) {
393  coords[shift + nn] = coords_move[nn];
394  }
395  }
396  } else {
397  if (th == NULL) {
398  CHKERR m_field.get_moab().get_coords(conn, num_nodes, coords);
399  } else {
400  CHKERR m_field.get_moab().tag_get_data(th, conn, num_nodes, coords);
401  }
402  }
403  double quality = Tools::volumeLengthQuality(coords);
404  if (!std::isnormal(quality)) {
405  min_quality = 0;
407  }
408  min_quality = f(min_quality, quality);
409  }
411 };
static double volumeLengthQuality(const double *coords)
Calculate tetrahedron volume length quality.
Definition: Tools.cpp:28

◆ query_interface()

MoFEMErrorCode MoFEM::NodeMergerInterface::query_interface ( boost::typeindex::type_index  type_index,
UnknownInterface **  iface 
) const
virtual

Implements MoFEM::UnknownInterface.

Definition at line 21 of file NodeMerger.cpp.

22  {
23  *iface = const_cast<NodeMergerInterface *>(this);
24  return 0;
25 }
NodeMergerInterface(const MoFEM::Core &core)
Definition: NodeMerger.cpp:31

◆ 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 46 of file NodeMerger.hpp.

46  {
48  }

Member Data Documentation

◆ cOre

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

Definition at line 133 of file NodeMerger.hpp.

◆ errorIfNoCommonEdge

bool MoFEM::NodeMergerInterface::errorIfNoCommonEdge
private

Send error if no common edge.

Definition at line 137 of file NodeMerger.hpp.

◆ minQualityFunction

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

Definition at line 134 of file NodeMerger.hpp.

◆ parentChildMap

ParentChildMap MoFEM::NodeMergerInterface::parentChildMap
private

Definition at line 167 of file NodeMerger.hpp.

◆ successMerge

bool MoFEM::NodeMergerInterface::successMerge
private

True if marge is success.

Definition at line 136 of file NodeMerger.hpp.


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