v0.9.1
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
MoFEM::BitLevelCoupler Struct Reference

Interface set parent for vertices, edges, triangles and tetrahedrons.FIXME: Not tested, slow, bugs. More...

#include <src/interfaces/BitLevelCoupler.hpp>

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

Public Member Functions

MoFEMErrorCode query_interface (const MOFEMuuid &uuid, UnknownInterface **iface) const
 
 BitLevelCoupler (const MoFEM::Core &core)
 
MoFEMErrorCode buildTree (const BitRefLevel &parent_level, int verb=0)
 build adaptive kd-tree More...
 
MoFEMErrorCode resetTree (const BitRefLevel &parent_level, int verb=0)
 reset adaptive kd-tree More...
 
MoFEMErrorCode getParent (const double *coords, EntityHandle &parent, bool tet_only=false, const double iter_tol=1.0e-10, const double inside_tol=1.0e-6, int verb=0)
 get parent entity More...
 
MoFEMErrorCode buildAdjacenciesVerticesOnTets (const BitRefLevel &parent_level, Range &children, bool vertex_elements=false, const double iter_tol=1.0e-10, const double inside_tol=1.0e-6, bool throw_error=true, int verb=0)
 finding parents for vertices More...
 
MoFEMErrorCode buildAdjacenciesEdgesFacesVolumes (const BitRefLevel &parent_level, Range &children, bool elements=true, int verb=0)
 finding parents for edegs, faces and tets More...
 
MoFEMErrorCode resetParents (Range &children, bool elements=true, int verb=0)
 reset parent entities More...
 
MoFEMErrorCode copyFieldDataFromParentToChildren (const std::vector< EntityHandle > &parents, const std::vector< EntityHandle > &children, const bool verify=true)
 copy data from parents More...
 
MoFEMErrorCode copyFieldDataFromParentToChildren (const BitRefLevel bit, const BitRefLevel mask, const bool verify=true)
 copy data from parents 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
 

Public Attributes

MoFEM::CorecOre
 
bool vErify
 by default is switched off, with it on to verify if existing parent is equal to parent set by interface More...
 

Private Member Functions

MoFEMErrorCode chanegParent (RefEntity_multiIndex::iterator it, EntityHandle parent)
 
MoFEMErrorCode verifyParent (RefEntity_multiIndex::iterator it, EntityHandle parent)
 
MoFEMErrorCode getLocCoordsOnTet (EntityHandle tet, const double *glob_coords, int verb=0)
 

Private Attributes

double cOords [12+3]
 
double diffN [12]
 
double N [4]
 
double locCoords [3]
 
const EntityHandlecOnn
 
boost::scoped_ptr< AdaptiveKDTree > treePtr
 

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

Interface set parent for vertices, edges, triangles and tetrahedrons.

FIXME: Not tested, slow, bugs.

Definition at line 32 of file BitLevelCoupler.hpp.

Constructor & Destructor Documentation

◆ BitLevelCoupler()

MoFEM::BitLevelCoupler::BitLevelCoupler ( const MoFEM::Core core)

Definition at line 39 of file BitLevelCoupler.hpp.

39  :
40  cOre(const_cast<MoFEM::Core&>(core)),
41  vErify(false) {}
bool vErify
by default is switched off, with it on to verify if existing parent is equal to parent set by interfa...

Member Function Documentation

◆ buildAdjacenciesEdgesFacesVolumes()

MoFEMErrorCode MoFEM::BitLevelCoupler::buildAdjacenciesEdgesFacesVolumes ( const BitRefLevel parent_level,
Range &  children,
bool  elements = true,
int  verb = 0 
)

finding parents for edegs, faces and tets

It assumes that parents for vertices are known. Run buildAdjacenciesVerticesOnTets if parents for vertices are not set.

Parameters
parent_levelbit level of parents
childrenlist of entities for which parents are being set
vertex_elementsif true algorithm assumes that vertices elements are used. IF NOT SET AND SUCH ELEMENTS EXIST IT WILL RESULT IN UNPREDICTABLE BEHAVIOR.
iter_toltolerance for convergence of point search
inside_toltolerance for inside element calculation
throw_errorif parent can not be found
verboselevel

Definition at line 283 of file BitLevelCoupler.cpp.

284  {
285  Interface &m_field = cOre;
286  auto refined_ptr = m_field.get_ref_ents();
288 
289  if (verb > 2)
290  std::cout << children << std::endl;
291 
292  std::vector<EntityHandle> conn_parents;
293 
294  Range::iterator eit, hi_eit;
295  eit = children.begin();
296  hi_eit = children.end();
297  for (; eit != hi_eit; eit++) {
298 
299  // check entity type
300  EntityType type;
301  type = m_field.get_moab().type_from_handle(*eit);
302  switch (type) {
303  case MBEDGE:
304  case MBTRI:
305  case MBTET:
306  break;
307  default:
308  continue;
309  }
310 
311  // get ref entity iterator
312  RefEntity_multiIndex::index<Ent_mi_tag>::type::iterator it;
313  it = refined_ptr->get<Ent_mi_tag>().find(*eit);
314  // that entity is on parent bit level, no need to process
315  if (((*it)->getBitRefLevel() & parent_level).any()) {
316  continue;
317  }
318 
319  if (verb > 1) {
320  std::cout << "before: " << **it << std::endl;
321  }
322 
323  // check if entity has a parent and parent is on parent bit level
324  EntityHandle parent_ent;
325  parent_ent = (*it)->getParentEnt();
326  const RefEntity ref_parent_ent(m_field.get_basic_entity_data_ptr(),
327  parent_ent);
328  if ((ref_parent_ent.getBitRefLevel() & parent_level).any()) {
329  if (!vErify)
330  continue;
331  }
332 
333  // connectivity
334  int max_dim = m_field.get_moab().dimension_from_handle(*eit);
335  const EntityHandle *conn;
336  int num_nodes;
337  ierr = m_field.get_moab().get_connectivity(*eit, conn, num_nodes);
338  CHKERRG(ierr);
339  conn_parents.resize(num_nodes);
340  for (int nn = 0; nn < num_nodes; nn++) {
341  const RefEntity ent(m_field.get_basic_entity_data_ptr(), conn[nn]);
342  conn_parents[nn] = ent.getParentEnt();
343  RefEntity_multiIndex::index<Ent_mi_tag>::type::iterator cit;
344  cit = refined_ptr->get<Ent_mi_tag>().find(conn_parents[nn]);
345  if (cit == refined_ptr->end()) {
346  conn_parents[nn] = conn[nn];
347  cit = refined_ptr->get<Ent_mi_tag>().find(conn_parents[nn]);
348  }
349  if (((*cit)->getBitRefLevel() & parent_level).none()) {
350  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
351  "parent of vertex is not on parent bit level");
352  }
353  int ent_dim = m_field.get_moab().dimension_from_handle(conn_parents[nn]);
354  max_dim = ent_dim > max_dim ? ent_dim : max_dim;
355  }
356 
357  if (verb > 1)
358  std::cout << "max_dim " << max_dim << std::endl;
359 
360  if (max_dim > 0) {
361 
362  for (; max_dim <= 3; max_dim++) {
363  Range parent_ents;
364  rval = m_field.get_moab().get_adjacencies(
365  &*conn_parents.begin(), num_nodes, max_dim, false, parent_ents);
367  parent_ents.erase((*it)->getRefEnt());
368  if (!parent_ents.empty()) {
369  ierr = chanegParent(refined_ptr->project<0>(it), *parent_ents.begin());
370  CHKERRG(ierr);
371  if (verb > 1) {
372  std::cout << "after: " << **it << std::endl << std::endl;
373  }
374  break;
375  }
376  }
377 
378  if (!vErify && max_dim > 3) {
379  ierr = chanegParent(refined_ptr->project<0>(it), 0);
380  CHKERRG(ierr);
381  if (verb > 1) {
382  std::cout << "parent not found\n";
383  }
384  }
385  }
386  }
387 
389 }
#define CHKERRQ_MOAB(a)
check error code of MoAB function
Definition: definitions.h:521
bool vErify
by default is switched off, with it on to verify if existing parent is equal to parent set by interfa...
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:507
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:550
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:514
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
Definition: Exceptions.hpp:85
MoFEMErrorCode get_ref_ents(const RefEntity_multiIndex **refined_entities_ptr) const
Get ref entities multi-index from database.
Definition: Core.cpp:746
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1879
MoFEMErrorCode chanegParent(RefEntity_multiIndex::iterator it, EntityHandle parent)

◆ buildAdjacenciesVerticesOnTets()

MoFEMErrorCode MoFEM::BitLevelCoupler::buildAdjacenciesVerticesOnTets ( const BitRefLevel parent_level,
Range &  children,
bool  vertex_elements = false,
const double  iter_tol = 1.0e-10,
const double  inside_tol = 1.0e-6,
bool  throw_error = true,
int  verb = 0 
)

finding parents for vertices

Use kd-tree to find tetrahedral or other volume element.

Parameters
parent_levelbit level of parents
childrenlist of vertices for which parents are being set
vertex_elementsif true algorithm assumes that vertices elements are used. IF NOT SET AND SUCH ELEMENTS EXIST IT WILL RESULT IN UNPREDICTABLE BEHAVIOUR.
iter_toltolerance for convergence of point search
inside_toltolerance for inside element calculation
throw_errorif parent can not be found
verboselevel

Definition at line 213 of file BitLevelCoupler.cpp.

216  {
217  Interface &m_field = cOre;
218  auto refined_ptr = m_field.get_ref_ents();
220  // build Tree
221  bool init_tree = false;
222 
223  // find parents of all nodes, if node has no parent then tetrahedral
224  // containing that node is searched node on tetrahedra my by part of face or
225  // edge on that tetrahedral, this need to be verified
226  RefEntity_multiIndex::index<EntType_mi_tag>::type::iterator it, hi_it;
227  it = refined_ptr->get<EntType_mi_tag>().lower_bound(MBVERTEX);
228  hi_it = refined_ptr->get<EntType_mi_tag>().upper_bound(MBVERTEX);
229 
230  for (; it != hi_it; it++) {
231 
232  // entity on parent level, can be parent to yourself
233  if (((*it)->getBitRefLevel() & parent_level).any())
234  continue;
235 
236  if (verb > 1) {
237  std::cout << *it << " " << (*it)->getBitRefLevel() << std::endl;
238  }
239 
240  // that vertex is on parent bit level, no need to process
241  // check if vertex has a parent and parent is on parent bit level
242  EntityHandle parent_ent;
243  parent_ent = (*it)->getParentEnt();
244  const RefEntity ref_parent_ent(m_field.get_basic_entity_data_ptr(),
245  parent_ent);
246  if ((ref_parent_ent.getBitRefLevel() & parent_level).any()) {
247  continue;
248  }
249 
250  // check if vertex is on child entities set
251  EntityHandle node = (*it)->getRefEnt();
252  if (children.find(node) == children.end()) {
253  continue;
254  }
255 
256  // build a boundary volume Tree
257  // if(!treePtr) {
258  ierr = buildTree(parent_level, verb);
259  CHKERRG(ierr);
260  init_tree = true;
261  //}
262 
263  double coords[3];
264  rval = m_field.get_moab().get_coords(&node, 1, coords);
266  EntityHandle parent = 0;
267  ierr = getParent(coords, parent, false, iter_tol, inside_tol, verb);
268  CHKERRG(ierr);
269  ierr = chanegParent(refined_ptr->project<0>(it), parent);
270  CHKERRG(ierr);
271  if (throw_error && parent == 0) {
272  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
273  "tets or any other entity for node not found");
274  }
275  }
276 
277  if (init_tree) {
278  treePtr->reset_tree();
279  }
281 }
#define CHKERRQ_MOAB(a)
check error code of MoAB function
Definition: definitions.h:521
boost::scoped_ptr< AdaptiveKDTree > treePtr
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:507
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:550
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:514
MoFEMErrorCode buildTree(const BitRefLevel &parent_level, int verb=0)
build adaptive kd-tree
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
Definition: Exceptions.hpp:85
MoFEMErrorCode getParent(const double *coords, EntityHandle &parent, bool tet_only=false, const double iter_tol=1.0e-10, const double inside_tol=1.0e-6, int verb=0)
get parent entity
MoFEMErrorCode get_ref_ents(const RefEntity_multiIndex **refined_entities_ptr) const
Get ref entities multi-index from database.
Definition: Core.cpp:746
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1879
MoFEMErrorCode chanegParent(RefEntity_multiIndex::iterator it, EntityHandle parent)

◆ buildTree()

MoFEMErrorCode MoFEM::BitLevelCoupler::buildTree ( const BitRefLevel parent_level,
int  verb = 0 
)

build adaptive kd-tree

Definition at line 29 of file BitLevelCoupler.cpp.

30  {
32  Interface &m_field = cOre;
33  treePtr.reset(new AdaptiveKDTree(&m_field.get_moab()));
34  Range tets;
35  ierr = m_field.getInterface<BitRefManager>()->getEntitiesByTypeAndRefLevel(
36  parent_level, BitRefLevel().set(), MBTET, tets);
37  CHKERRG(ierr);
38  rval = treePtr->build_tree(tets);
40  if (verb > 2) {
41  rval = treePtr->print();
43  }
45 }
#define CHKERRQ_MOAB(a)
check error code of MoAB function
Definition: definitions.h:521
boost::scoped_ptr< AdaptiveKDTree > treePtr
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:507
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:550
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:514
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
Definition: Exceptions.hpp:85
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:50
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1879

◆ chanegParent()

MoFEMErrorCode MoFEM::BitLevelCoupler::chanegParent ( RefEntity_multiIndex::iterator  it,
EntityHandle  parent 
)
private

Definition at line 391 of file BitLevelCoupler.cpp.

392  {
393  Interface &m_field = cOre;
394  auto refined_ptr = m_field.get_ref_ents();
396 
397 
398  if (vErify) {
399  ierr = verifyParent(it, parent);
400  CHKERRG(ierr);
401  }
402 
403  RefEntity_change_parent modifier(parent);
404  bool success =
405  const_cast<RefEntity_multiIndex *>(refined_ptr)->modify(it, modifier);
406  if (!success) {
407  SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
408  "unsuccessful operation");
409  }
410 
412 }
MoFEMErrorCode verifyParent(RefEntity_multiIndex::iterator it, EntityHandle parent)
bool vErify
by default is switched off, with it on to verify if existing parent is equal to parent set by interfa...
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:507
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:550
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:514
MoFEMErrorCode get_ref_ents(const RefEntity_multiIndex **refined_entities_ptr) const
Get ref entities multi-index from database.
Definition: Core.cpp:746
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1879

◆ copyFieldDataFromParentToChildren() [1/2]

MoFEMErrorCode MoFEM::BitLevelCoupler::copyFieldDataFromParentToChildren ( const std::vector< EntityHandle > &  parents,
const std::vector< EntityHandle > &  children,
const bool  verify = true 
)

copy data from parents

This not approximate date from, simply copy DOFs values from one mesh to another. This is useful for special case of refinement, e.g. insertion of interface, where entities on the interface are doubled to create displacement jump. In general case use this function could lead to wrong results.

Note
Move data only if type of child and parent is the same.
Parameters
parentpointer to array of parent entities
childrenpointer to array of children entities
verifyif true verifi consistency with database
Returns
error code

Definition at line 489 of file BitLevelCoupler.cpp.

491  {
492  Interface &m_field = cOre;
493  moab::Interface &moab = m_field.get_moab();
494  auto fields_ptr = m_field.get_fields();
496 
497  if (parents.size() != children.size()) {
498  SETERRQ2(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
499  "parents adn children vectors has to have the same size %d != %d",
500  parents.size(), children.size());
501  }
502 
503  const int nb_elems = parents.size();
504  std::vector<double *> data(nb_elems);
505  std::vector<int> data_size(nb_elems);
506 
507  for (auto fit = fields_ptr->begin(); fit != fields_ptr->end(); fit++) {
508 
509  // Verify consistency with database
510  if (verify) {
511  // Get pointer to multi-index with field entities
512  auto *field_ents = m_field.get_field_ents();
513 
514  auto get_ents_max_order = [&](const std::vector<EntityHandle> &ents) {
515  boost::shared_ptr<std::vector<const void *>> ents_max_order(
516  new std::vector<const void *>());
517  ents_max_order->resize(ents.size());
518  CHKERR moab.tag_get_by_ptr((*fit)->th_AppOrder, &*ents.begin(),
519  ents.size(), &*ents_max_order->begin());
520  return ents_max_order;
521  };
522 
523  auto max_order_parents = get_ents_max_order(parents);
524  auto max_order_children = get_ents_max_order(children);
525 
526  auto pit = parents.begin();
527  auto cit = children.begin();
528  auto vit_parent_max_order = max_order_parents->begin();
529  auto vit_child_max_order = max_order_children->begin();
530 
531  for (; pit != parents.end();
532  ++pit, ++cit, ++vit_parent_max_order, ++vit_child_max_order) {
533  // verify entity type
534  if (moab.type_from_handle(*pit) != moab.type_from_handle(*cit)) {
535  SETERRQ(m_field.get_comm(), MOFEM_DATA_INCONSISTENCY,
536  "inconsistent type");
537  }
538  // ref ent pointers
539  auto ref_parent_ptr = boost::make_shared<RefEntity>(
540  m_field.get_basic_entity_data_ptr(), *pit);
541  auto ref_child_ptr = boost::make_shared<RefEntity>(
542  m_field.get_basic_entity_data_ptr(), *cit);
543  // create mofem entity objects
544  boost::shared_ptr<FieldEntity> mofem_ent_parent(new FieldEntity(
545  *fit, ref_parent_ptr,
546  FieldEntity::makeSharedFieldDataAdaptorPtr(*fit, ref_parent_ptr),
547  boost::shared_ptr<const int>(
548  max_order_parents,
549  static_cast<const int *>(*vit_parent_max_order))));
550  boost::shared_ptr<FieldEntity> mofem_ent_child(new FieldEntity(
551  *fit, ref_child_ptr,
552  FieldEntity::makeSharedFieldDataAdaptorPtr(*fit, ref_child_ptr),
553  boost::shared_ptr<const int>(
554  max_order_children,
555  static_cast<const int *>(*vit_child_max_order))));
556  // check approximation order
557  if (mofem_ent_parent->getMaxOrder() == mofem_ent_child->getMaxOrder()) {
558  // approximation order is equal, simply copy data
559  for (unsigned int dd = 0;
560  dd != mofem_ent_child->getEntFieldData().size(); dd++) {
561  mofem_ent_child->getEntFieldData()[dd] =
562  mofem_ent_parent->getEntFieldData()[dd];
563  }
564  } else {
565  // approximation orders is different
566  FieldEntity_multiIndex::iterator fcit =
567  field_ents->find(mofem_ent_child->getGlobalUniqueId());
568  if (fcit == field_ents->end()) {
569  // entity not in database, set order and copy data
570  (FieldEntity_change_order(mofem_ent_parent->getMaxOrder()))(
571  mofem_ent_child);
572  for (unsigned int dd = 0;
573  dd != mofem_ent_child->getEntFieldData().size(); dd++) {
574  mofem_ent_child->getEntFieldData()[dd] =
575  mofem_ent_parent->getEntFieldData()[dd];
576  }
577  } else {
578  int parent_nb_dofs = mofem_ent_parent->getEntFieldData().size();
579  int child_nb_dofs = mofem_ent_child->getEntFieldData().size();
580  for (int dd = 0; dd != child_nb_dofs; dd++) {
581  if (dd < parent_nb_dofs) {
582  mofem_ent_child->getEntFieldData()[dd] =
583  mofem_ent_parent->getEntFieldData()[dd];
584  } else {
585  mofem_ent_child->getEntFieldData()[dd] = 0;
586  }
587  }
588  }
589  }
590  }
591  } else {
592 
593  auto copy_tag_data = [this, &moab, &data, &data_size](auto th, auto &p,
594  auto &c) {
596  // Get pointer and size of field values tag
597  CHKERR moab.tag_get_by_ptr(th, p, (const void **)&data.front(),
598  &data_size.front());
599  // Set data
600  CHKERR moab.tag_set_by_ptr(th, c, (void *const *)&data.front(),
601  &data_size.front());
603  };
604 
605  Range p, c;
606  p.insert_list(parents.begin(), parents.end());
607  c.insert_list(children.begin(), children.end());
608 
609  Range parents_verts = p.subset_by_type(MBTET);
610  Range children_verts = c.subset_by_type(MBTET);
611  Range parents_without_verts = subtract(p, parents_verts);
612  Range children_without_verts = subtract(c, children_verts);
613 
614  CHKERR copy_tag_data(fit->get()->th_FieldDataVerts, parents_verts,
615  children_verts);
616  CHKERR copy_tag_data(fit->get()->th_FieldData, parents_verts,
617  children_verts);
618 
619  }
620  }
621 
623 }
virtual moab::Interface & get_moab()=0
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:483
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
#define CHKERR
Inline error check.
Definition: definitions.h:602
static boost::shared_ptr< FieldData *const > makeSharedFieldDataAdaptorPtr(const boost::shared_ptr< Field > &field_ptr, const boost::shared_ptr< RefEntity > &ref_ents_ptr)
Return shared pointer to entity field data vector adaptor.
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1879
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:413

◆ copyFieldDataFromParentToChildren() [2/2]

MoFEMErrorCode MoFEM::BitLevelCoupler::copyFieldDataFromParentToChildren ( const BitRefLevel  bit,
const BitRefLevel  mask,
const bool  verify = true 
)

copy data from parents

This not approximate date from, simply copy DOFs values from one mesh to another. This is useful for special case of refinement, e.g. insertion of interface, where entities on the interface are doubled to create displacement jump.

In general case use this function could lead to wrong results.

Note
Move data only if type of child and parent is the same.
Parameters
bitbit ref level
verifyif true verifi consistency with database
Returns
error code

Definition at line 625 of file BitLevelCoupler.cpp.

626  {
627  Interface &m_field = cOre;
628  // moab::Interface& moab = m_field.get_moab();
630  Range ents;
631  ierr = m_field.getInterface<BitRefManager>()->getEntitiesByRefLevel(bit, mask,
632  ents);
633  CHKERRG(ierr);
634  std::vector<EntityHandle> parents;
635  std::vector<EntityHandle> children;
636  for (Range::iterator eit = ents.begin(); eit != ents.end(); eit++) {
637  RefEntity ref_ent(m_field.get_basic_entity_data_ptr(), *eit);
638  if (ref_ent.getParentEntType() == ref_ent.getEntType()) {
639  children.push_back(*eit);
640  parents.push_back(ref_ent.getParentEnt());
641  }
642  }
643  ierr = copyFieldDataFromParentToChildren(parents, children, verify);
644  CHKERRG(ierr);
646 }
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:507
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:550
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:514
MoFEMErrorCode copyFieldDataFromParentToChildren(const std::vector< EntityHandle > &parents, const std::vector< EntityHandle > &children, const bool verify=true)
copy data from parents
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1879

◆ getLocCoordsOnTet()

MoFEMErrorCode MoFEM::BitLevelCoupler::getLocCoordsOnTet ( EntityHandle  tet,
const double glob_coords,
int  verb = 0 
)
private

Definition at line 451 of file BitLevelCoupler.cpp.

453  {
454  Interface &m_field = cOre;
456 
457  int num_nodes;
458  rval = m_field.get_moab().get_connectivity(tet, cOnn, num_nodes, true);
460  rval = m_field.get_moab().get_coords(cOnn, num_nodes, cOords);
462  double shifted_glob_coors[3];
463  cblas_dcopy(3, glob_coords, 1, shifted_glob_coors, 1);
464  for (int nn = 1; nn < 4; nn++) {
465  cblas_daxpy(3, -1, cOords, 1, &cOords[nn * 3], 1);
466  }
467  cblas_daxpy(3, -1, cOords, 1, shifted_glob_coors, 1);
468  for (int dd = 0; dd < 3; dd++) {
469  cOords[dd] = 0;
470  }
472  CHKERRG(ierr);
473  locCoords[0] = locCoords[1] = locCoords[2] = 0;
474  ierr = ShapeMBTET(N, &locCoords[0], &locCoords[1], &locCoords[2], 1);
475  CHKERRG(ierr);
476  ierr = ShapeMBTET_inverse(N, diffN, cOords, shifted_glob_coors, locCoords);
477  CHKERRG(ierr);
478  ierr = ShapeMBTET(N, &locCoords[0], &locCoords[1], &locCoords[2], 1);
479  CHKERRG(ierr);
480 
481  if (verb > 1) {
482  std::cout << "N " << N[0] << " " << N[1] << " " << N[2] << " " << N[3]
483  << std::endl;
484  }
485 
487 }
#define CHKERRQ_MOAB(a)
check error code of MoAB function
Definition: definitions.h:521
PetscErrorCode ShapeMBTET(double *N, const double *G_X, const double *G_Y, const double *G_Z, int DIM)
calculate shape functions
Definition: fem_tools.c:318
void cblas_daxpy(const int N, const double alpha, const double *X, const int incX, double *Y, const int incY)
Definition: cblas_daxpy.c:11
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:507
void cblas_dcopy(const int N, const double *X, const int incX, double *Y, const int incY)
Definition: cblas_dcopy.c:11
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:550
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:514
PetscErrorCode ShapeMBTET_inverse(double *N, double *diffN, const double *elem_coords, const double *glob_coords, double *loc_coords)
calculate local coordinates for given global coordinates
Definition: fem_tools.c:347
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
Definition: Exceptions.hpp:85
PetscErrorCode ShapeDiffMBTET(double *diffN)
calculate derivatives of shape functions
Definition: fem_tools.c:331
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
const EntityHandle * cOnn
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1879

◆ getParent()

MoFEMErrorCode MoFEM::BitLevelCoupler::getParent ( const double coords,
EntityHandle parent,
bool  tet_only = false,
const double  iter_tol = 1.0e-10,
const double  inside_tol = 1.0e-6,
int  verb = 0 
)

get parent entity

Use kd-tree to find tetrahedral or other volume element.

Parameters
coordinate
parentreturned parent entity
iter_toltolerance for convergence of point search
inside_toltolerance for inside element calculation
throw_errorif parent can not be found
verboselevel

Definition at line 55 of file BitLevelCoupler.cpp.

58  {
60  Interface &m_field = cOre;
61  EntityHandle leaf_out;
62  rval = treePtr->point_search(coords, leaf_out, iter_tol, inside_tol);
64  bool is_in;
65  Range tets;
66  ierr = m_field.get_moab().get_entities_by_type(leaf_out, MBTET, tets);
67  CHKERRG(ierr);
68  Range::iterator tit = tets.begin();
69  for (; tit != tets.end(); tit++) {
70  ierr = getLocCoordsOnTet(*tit, coords, verb);
71  CHKERRG(ierr);
72  is_in = true;
73  for (int nn = 0; nn < 4; nn++) {
74  if (N[nn] < -inside_tol || N[nn] > 1 + inside_tol) {
75  is_in = false;
76  break;
77  }
78  if (!is_in)
79  break;
80  }
81  parent = 0;
82  if (is_in) {
83  if (!tet_only) {
84  // vertices
85  if (fabs(N[0] - 1) < inside_tol && fabs(N[1]) < inside_tol &&
86  fabs(N[2]) < inside_tol && fabs(N[3]) < inside_tol) {
87  if (verb > 1)
88  std::cout << "node 0 found " << std::endl;
89  rval = m_field.get_moab().side_element(*tit, 0, 0, parent);
92  }
93  if (fabs(N[0]) < inside_tol && fabs(N[1] - 1) < inside_tol &&
94  fabs(N[2]) < inside_tol && fabs(N[3]) < inside_tol) {
95  if (verb > 1)
96  std::cout << "node 1 found " << std::endl;
97  rval = m_field.get_moab().side_element(*tit, 0, 1, parent);
100  }
101  if (fabs(N[0]) < inside_tol && fabs(N[1]) < inside_tol &&
102  fabs(N[2] - 2) < inside_tol && fabs(N[3]) < inside_tol) {
103  if (verb > 1)
104  std::cout << "node 2 found " << std::endl;
105  rval = m_field.get_moab().side_element(*tit, 0, 2, parent);
108  }
109  if (fabs(N[0]) < inside_tol && fabs(N[1]) < inside_tol &&
110  fabs(N[2]) < inside_tol && fabs(N[3] - 1) < inside_tol) {
111  if (verb > 1)
112  std::cout << "node 3 found " << std::endl;
113  rval = m_field.get_moab().side_element(*tit, 0, 3, parent);
116  }
117  // edges
118  if (fabs(N[0]) > inside_tol && fabs(N[1]) > inside_tol &&
119  fabs(N[2]) < inside_tol && fabs(N[3]) < inside_tol) {
120  if (verb > 1)
121  std::cout << "edge 0 found " << std::endl;
122  rval = m_field.get_moab().side_element(*tit, 1, 0, parent);
125  }
126  if (fabs(N[0]) < inside_tol && fabs(N[1]) > inside_tol &&
127  fabs(N[2]) > inside_tol && fabs(N[3]) < inside_tol) {
128  if (verb > 1)
129  std::cout << "edge 1 found " << std::endl;
130  rval = m_field.get_moab().side_element(*tit, 1, 1, parent);
133  }
134  if (fabs(N[0]) > inside_tol && fabs(N[1]) < inside_tol &&
135  fabs(N[2]) > inside_tol && fabs(N[3]) < inside_tol) {
136  if (verb > 1)
137  std::cout << "edge 2 found " << std::endl;
138  rval = m_field.get_moab().side_element(*tit, 1, 2, parent);
141  }
142  if (fabs(N[0]) > inside_tol && fabs(N[1]) < inside_tol &&
143  fabs(N[2]) < inside_tol && fabs(N[3]) > inside_tol) {
144  if (verb > 1)
145  std::cout << "edge 3 found " << std::endl;
146  rval = m_field.get_moab().side_element(*tit, 1, 3, parent);
149  }
150  if (fabs(N[0]) < inside_tol && fabs(N[1]) > inside_tol &&
151  fabs(N[2]) < inside_tol && fabs(N[3]) > inside_tol) {
152  if (verb > 1)
153  std::cout << "edge 4 found " << std::endl;
154  rval = m_field.get_moab().side_element(*tit, 1, 4, parent);
157  }
158  if (fabs(N[0]) < inside_tol && fabs(N[1]) < inside_tol &&
159  fabs(N[2]) > inside_tol && fabs(N[3]) > inside_tol) {
160  if (verb > 1)
161  std::cout << "edge 5 found " << std::endl;
162  rval = m_field.get_moab().side_element(*tit, 1, 5, parent);
165  }
166  // faces
167  if (fabs(N[0]) > inside_tol && fabs(N[1]) > inside_tol &&
168  fabs(N[2]) < inside_tol && fabs(N[3]) > inside_tol) {
169  if (verb > 1)
170  std::cout << "face 0 found " << std::endl;
171  rval = m_field.get_moab().side_element(*tit, 2, 0, parent);
174  }
175  if (fabs(N[0]) < inside_tol && fabs(N[1]) > inside_tol &&
176  fabs(N[2]) > inside_tol && fabs(N[3]) > inside_tol) {
177  if (verb > 1)
178  std::cout << "face 1 found " << std::endl;
179  rval = m_field.get_moab().side_element(*tit, 2, 1, parent);
182  }
183  if (fabs(N[0]) > inside_tol && fabs(N[1]) < inside_tol &&
184  fabs(N[2]) > inside_tol && fabs(N[3]) > inside_tol) {
185  if (verb > 1)
186  std::cout << "face 2 found " << std::endl;
187  rval = m_field.get_moab().side_element(*tit, 2, 2, parent);
190  }
191  if (fabs(N[0]) > inside_tol && fabs(N[1]) > inside_tol &&
192  fabs(N[2]) > inside_tol && fabs(N[3]) < inside_tol) {
193  if (verb > 1)
194  std::cout << "face 3 found " << std::endl;
195  rval = m_field.get_moab().side_element(*tit, 2, 2, parent);
198  }
199  // set parent
200  if (parent != 0) {
201  break;
202  }
203  }
204  if (verb > 1)
205  std::cout << "tet found " << std::endl;
206  parent = *tit;
207  break;
208  }
209  }
211 }
#define CHKERRQ_MOAB(a)
check error code of MoAB function
Definition: definitions.h:521
boost::scoped_ptr< AdaptiveKDTree > treePtr
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:507
MoFEMErrorCode getLocCoordsOnTet(EntityHandle tet, const double *glob_coords, int verb=0)
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:550
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:514
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
Definition: Exceptions.hpp:85
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1879

◆ query_interface()

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

Implements MoFEM::UnknownInterface.

Definition at line 17 of file BitLevelCoupler.cpp.

18  {
20  *iface = NULL;
21  if (uuid == IDD_MOFEMBitLevelCoupler) {
22  *iface = const_cast<BitLevelCoupler *>(this);
24  }
25  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "unknown interface");
27 }
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:507
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:514
static const MOFEMuuid IDD_MOFEMBitLevelCoupler

◆ resetParents()

MoFEMErrorCode MoFEM::BitLevelCoupler::resetParents ( Range &  children,
bool  elements = true,
int  verb = 0 
)

reset parent entities

This is needed for testing.

Definition at line 414 of file BitLevelCoupler.cpp.

415  {
416  Interface &m_field = cOre;
417  auto refined_ptr = m_field.get_ref_ents();
419 
420  // access to ref dofs multi-index
421  Range::iterator eit, hi_eit;
422  eit = children.begin();
423  hi_eit = children.end();
424  for (; eit != hi_eit; eit++) {
425 
426  // get ref entity iterator
427  RefEntity_multiIndex::index<Ent_mi_tag>::type::iterator it;
428  it = refined_ptr->get<Ent_mi_tag>().find(*eit);
429 
430  // resent entity parent
431  ierr = chanegParent(refined_ptr->project<0>(it), 0);
432  CHKERRG(ierr);
433  }
434 
436 }
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:507
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:550
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:514
MoFEMErrorCode get_ref_ents(const RefEntity_multiIndex **refined_entities_ptr) const
Get ref entities multi-index from database.
Definition: Core.cpp:746
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1879
MoFEMErrorCode chanegParent(RefEntity_multiIndex::iterator it, EntityHandle parent)

◆ resetTree()

MoFEMErrorCode MoFEM::BitLevelCoupler::resetTree ( const BitRefLevel parent_level,
int  verb = 0 
)

reset adaptive kd-tree

Definition at line 47 of file BitLevelCoupler.cpp.

48  {
50  treePtr->reset_tree();
51  treePtr.reset();
53 }
boost::scoped_ptr< AdaptiveKDTree > treePtr
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:507
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:514

◆ verifyParent()

MoFEMErrorCode MoFEM::BitLevelCoupler::verifyParent ( RefEntity_multiIndex::iterator  it,
EntityHandle  parent 
)
private

Definition at line 438 of file BitLevelCoupler.cpp.

439  {
441 
442  if (parent != (*it)->getParentEnt()) {
443  SETERRQ3(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
444  "data inconsistency %lu != %lu for ent %lu", parent,
445  (*it)->getParentEnt(), (*it)->getRefEnt());
446  }
447 
449 }
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:507
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:514

Member Data Documentation

◆ cOnn

const EntityHandle* MoFEM::BitLevelCoupler::cOnn
private

Definition at line 190 of file BitLevelCoupler.hpp.

◆ cOords

double MoFEM::BitLevelCoupler::cOords[12+3]
private

Definition at line 187 of file BitLevelCoupler.hpp.

◆ cOre

MoFEM::Core& MoFEM::BitLevelCoupler::cOre

Definition at line 36 of file BitLevelCoupler.hpp.

◆ diffN

double MoFEM::BitLevelCoupler::diffN[12]
private

Definition at line 188 of file BitLevelCoupler.hpp.

◆ locCoords

double MoFEM::BitLevelCoupler::locCoords[3]
private

Definition at line 189 of file BitLevelCoupler.hpp.

◆ N

double MoFEM::BitLevelCoupler::N[4]
private

Definition at line 188 of file BitLevelCoupler.hpp.

◆ treePtr

boost::scoped_ptr<AdaptiveKDTree> MoFEM::BitLevelCoupler::treePtr
private

Definition at line 194 of file BitLevelCoupler.hpp.

◆ vErify

bool MoFEM::BitLevelCoupler::vErify

by default is switched off, with it on to verify if existing parent is equal to parent set by interface

Definition at line 37 of file BitLevelCoupler.hpp.


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