v0.13.0
RefEntsMultiIndices.hpp
Go to the documentation of this file.
1 /** \file RefEntsMultiIndices.hpp
2  * \brief Multi-index contains, for mofem entities data structures and other
3  * low-level functions
4  */
5 
6 /*
7  * MoFEM is free software: you can redistribute it and/or modify it under
8  * the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * MoFEM is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15  * License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>
19  */
20 
21 #ifndef __REF_ENTSMULTIINDICES_HPP__
22 #define __REF_ENTSMULTIINDICES_HPP__
23 
24 namespace MoFEM {
25 
26 template <EntityType TYPE> inline EntityHandle get_id_for_max_type() {
27  return (static_cast<EntityHandle>(TYPE) << MB_ID_WIDTH) |
28  (~static_cast<EntityHandle>(MB_TYPE_MASK));
29 };
30 
31 template <EntityType TYPE> inline EntityHandle get_id_for_min_type() {
32  return (static_cast<EntityHandle>(TYPE) << MB_ID_WIDTH);
33 };
34 
35 inline EntityHandle get_id_for_max_type(const EntityType type) {
36  return (static_cast<EntityHandle>(type) << MB_ID_WIDTH) |
37  (~static_cast<EntityHandle>(MB_TYPE_MASK));
38 };
39 
40 inline EntityHandle get_id_for_min_type(const EntityType type) {
41  return (static_cast<EntityHandle>(type) << MB_ID_WIDTH);
42 };
43 
44 /**
45  * @brief Get the tag ptr object
46  *
47  * @param moab
48  * @param th
49  * @param ent
50  * @param tag_size
51  * @return void*
52  */
53 inline void *get_tag_ptr(moab::Interface &moab, Tag th, EntityHandle ent,
54  int *tag_size) {
55  void *ret_val;
56  rval = moab.tag_get_by_ptr(th, &ent, 1, (const void **)&ret_val, tag_size);
57  if (rval != MB_SUCCESS) {
58  if (tag_size)
59  *tag_size = 0;
60  return NULL;
61  } else {
62  return ret_val;
63  }
64 }
65 
66 /**
67  * \brief keeps information about side number for the finite element
68  * \ingroup ent_multi_indices
69  */
70 struct /*__attribute__((__packed__))*/ SideNumber {
73  char sense;
74  char offset;
76 
77  inline EntityType getEntType() const {
78  return static_cast<EntityType>((ent & MB_TYPE_MASK) >> MB_ID_WIDTH);
79  }
80 
81  inline int getEntDimension() const {
82  return moab::CN::Dimension(getEntType());
83  }
84 
85  inline const char *getEntTypeName() const {
86  return moab::CN::EntityTypeName(getEntType());
87  }
88 
91  brother_side_number(-1) {}
92 };
93 
94 /**
95  * @relates multi_index_container
96  * \brief SideNumber_multiIndex for SideNumber
97  * \ingroup ent_multi_indices
98  *
99  */
100 typedef multi_index_container<
101  boost::shared_ptr<SideNumber>,
102  indexed_by<
103  ordered_unique<member<SideNumber, EntityHandle, &SideNumber::ent>>,
104  ordered_non_unique<
105 
106  composite_key<
107  SideNumber,
108  const_mem_fun<SideNumber, EntityType, &SideNumber::getEntType>,
109  member<SideNumber, char, &SideNumber::side_number>
110 
111  >>
112 
113  >>
115 
116 /**
117  * \brief PipelineManager data. like access to moab interface and basic tag
118  * handlers.
119  */
122  int pcommID;
126  BasicEntityData(const moab::Interface &mfield,
127  const int pcomm_id = MYPCOMM_INDEX);
128  virtual ~BasicEntityData() = default;
129 };
130 
131 template <int N> struct RefEntityTmp : public RefEntityTmp<N - 1> {
132 
133  using RefEntityTmp<N - 1>::RefEntityTmp;
134 
135  virtual const boost::shared_ptr<BasicEntityData> getBasicDataPtr() const {
136  if (auto ptr = basicDataPtr.lock())
137  return ptr;
138  else
139  return nullptr;
140  }
141 
142  static boost::weak_ptr<BasicEntityData> basicDataPtr;
143 };
144 
145 template <int N> boost::weak_ptr<BasicEntityData> RefEntityTmp<N>::basicDataPtr;
146 
147 struct RefElement;
148 
149 /**
150 * \brief Struct keeps handle to refined handle.
151 * \ingroup ent_multi_indices
152 
153 \todo th_RefType "_RefType" is set as two integers, need to be fixed, it is
154 waste of space.
155 
156 */
157 template <> struct RefEntityTmp<0> {
158 
159  RefEntityTmp(const boost::shared_ptr<BasicEntityData> &basic_data_ptr,
160  const EntityHandle ent);
161 
162  RefEntityTmp(const boost::shared_ptr<BasicEntityData> &basic_data_ptr,
163  const EntityHandle ent, EntityHandle *ent_parent_tag_ptr);
164 
165  virtual ~RefEntityTmp() = default;
166 
167  /**
168  * @brief Get pointer to basic data struture
169  *
170  * @return const boost::shared_ptr<BasicEntityData>
171  */
172  virtual const boost::shared_ptr<BasicEntityData> getBasicDataPtr() const {
173  if (auto ptr = basicDataPtr.lock())
174  return ptr;
175  else
176  return nullptr;
177  }
178 
179  int getSideNumber() const;
180 
181  /**
182  * @brief Get the Side number
183  *
184  * @return int
185  */
186  boost::shared_ptr<SideNumber> getSideNumberPtr() const;
187 
188  /**
189  * @brief Get the entity handle
190  *
191  * @return EntityHandle
192  */
193  inline EntityHandle getEnt() const { return this->ent; }
194 
195  /** \brief Get entity type
196  */
197  inline EntityType getEntType() const {
198  return (EntityType)((this->ent & MB_TYPE_MASK) >> MB_ID_WIDTH);
199  }
200 
201  /**
202  * @brief Get the Ent Dimension
203  *
204  * @return int
205  */
206  inline int getEntDimension() const {
207  return moab::CN::Dimension(getEntType());
208  }
209 
210  /**
211  * @brief Get the Ent Type Name
212  *
213  * @return const char*
214  */
215  inline const char *getEntTypeName() const {
216  return moab::CN::EntityTypeName(getEntType());
217  }
218 
219  /** \brief get entity id
220  */
221  inline EntityID getEntId() const {
222  return (EntityID)(this->ent & MB_ID_MASK);
223  };
224 
225  static inline EntityHandle
227  boost::shared_ptr<BasicEntityData> basic_ent_data) {
228  auto *pcomm =
229  ParallelComm::get_pcomm(&basic_ent_data->moab, basic_ent_data->pcommID);
230 
231  auto get_owner_ent = [&](auto tag) {
232  if (auto owner_ent_ptr = static_cast<EntityHandle *>(
233  MoFEM::get_tag_ptr(basic_ent_data->moab, tag, ent, NULL))) {
234  return owner_ent_ptr[0];
235  } else {
236  return ent;
237  }
238  };
239 
240  if (auto pstat_ptr = static_cast<unsigned char *>(MoFEM::get_tag_ptr(
241  basic_ent_data->moab, pcomm->pstatus_tag(), ent, NULL))) {
242  if (!(*pstat_ptr & PSTATUS_NOT_OWNED)) {
243  return ent;
244  } else if (*pstat_ptr & PSTATUS_MULTISHARED) {
245  return get_owner_ent(pcomm->sharedhs_tag());
246  } else if (*pstat_ptr & PSTATUS_SHARED) {
247  return get_owner_ent(pcomm->sharedh_tag());
248  } else {
249  return ent;
250  }
251  } else {
252  return ent;
253  }
254  }
255 
256  /** \brief Owner handle on this or other processors
257  */
258  inline EntityHandle getOwnerEnt() const {
259  return getOwnerEnt(this->ent, this->getBasicDataPtr());
260  }
261 
262  static inline int
264  boost::shared_ptr<BasicEntityData> basic_ent_data) {
265  auto *pcomm =
266  ParallelComm::get_pcomm(&basic_ent_data->moab, basic_ent_data->pcommID);
267 
268  auto get_owner_proc = [&](auto tag) {
269  if (auto owner_proc = static_cast<int *>(
270  MoFEM::get_tag_ptr(basic_ent_data->moab, tag, ent, NULL))) {
271  return owner_proc[0];
272  } else {
273  return 0;
274  }
275  };
276 
277  if (auto pstat_ptr = static_cast<unsigned char *>(MoFEM::get_tag_ptr(
278  basic_ent_data->moab, pcomm->pstatus_tag(), ent, NULL))) {
279  if (!(*pstat_ptr & PSTATUS_NOT_OWNED)) {
280  return pcomm->rank();
281  } else if (*pstat_ptr & PSTATUS_MULTISHARED) {
282  return get_owner_proc(pcomm->sharedps_tag());
283  } else if (*pstat_ptr & PSTATUS_SHARED) {
284  return get_owner_proc(pcomm->sharedp_tag());
285  } else {
286  return 0;
287  }
288  } else {
289  return 0;
290  }
291  }
292 
293  inline int getOwnerProc() const {
294  return getOwnerProc(this->ent, this->getBasicDataPtr());
295  }
296 
297  static inline int
298  getPartProc(const EntityHandle ent, const Tag th,
299  const boost::shared_ptr<BasicEntityData> &basic_ptr) {
300  if (auto part_ptr = static_cast<int *>(
301  MoFEM::get_tag_ptr(basic_ptr->moab, th, ent, NULL))) {
302  return *part_ptr >= 0 ? *part_ptr : 0;
303  } else
304  return 0;
305  };
306 
307  /** \brief Get processor
308  */
309  inline int getPartProc() const {
310  if (PetscUnlikely(getEntType() == MBENTITYSET)) {
311  return getPartProc(ent, this->getBasicDataPtr()->th_MeshsetPart,
312  this->getBasicDataPtr());
313  } else {
314  auto *pcomm = ParallelComm::get_pcomm(&this->getBasicDataPtr()->moab,
315  this->getBasicDataPtr()->pcommID);
316  return getPartProc(ent, pcomm->partition_tag(), this->getBasicDataPtr());
317  }
318  }
319 
320  /**
321  * @brief Get pointer to partition tag
322  *
323  * @return int*
324  */
325  inline int *getPartProcPtr() const {
326  if (PetscUnlikely(getEntType() == MBENTITYSET)) {
327  return static_cast<int *>(MoFEM::get_tag_ptr(
328  this->getBasicDataPtr()->moab,
329  this->getBasicDataPtr()->th_MeshsetPart, ent, NULL));
330  } else {
331  auto *pcomm = ParallelComm::get_pcomm(&this->getBasicDataPtr()->moab,
332  this->getBasicDataPtr()->pcommID);
333  return static_cast<int *>(MoFEM::get_tag_ptr(
334  this->getBasicDataPtr()->moab, pcomm->partition_tag(), ent, NULL));
335  }
336  }
337 
338  /** \brief get pstatus
339  * This tag stores various aspects of parallel status in bits; see also
340  * define following, to be used in bit mask operations. If an entity is
341  * not shared with any other processors, the pstatus is 0, otherwise it's >
342  * 0
343  *
344  * bit 0: !owned (0=owned, 1=not owned)
345  * bit 1: shared (0=not shared, 1=shared)
346  * bit 2: multishared (shared by > 2 procs; 0=not shared, 1=shared)
347  * bit 3: interface (0=not interface, 1=interface)
348  * bit 4: ghost (0=not ghost, 1=ghost)
349  *
350  */
351  inline unsigned char getPStatus() const {
352  auto *pcomm = ParallelComm::get_pcomm(&this->getBasicDataPtr()->moab,
353  this->getBasicDataPtr()->pcommID);
354  if (auto pstat_ptr = static_cast<unsigned char *>(MoFEM::get_tag_ptr(
355  this->getBasicDataPtr()->moab, pcomm->pstatus_tag(), ent, NULL))) {
356  return *pstat_ptr;
357  } else {
358  return 0;
359  }
360  }
361 
362  /** \brief get shared processors
363 
364  Returning list to shared processors. Lists end with -1. Returns NULL if not
365  sharing processors.
366 
367  DO NOT MODIFY LIST.
368 
369  \code
370  BasicEntity *ent_ptr = BasicEntity(moab,entity_handle);
371  for(int proc = 0; proc<MAX_SHARING_PROCS && -1 !=
372  ent_ptr->getSharingProcsPtr[proc]; proc++) {
373  if(ent_ptr->getSharingProcsPtr[proc] == -1) {
374  // End of the list
375  break;
376  }
377  int sharing_proc = ent_ptr->getSharingProcsPtr[proc];
378  EntityHandle sharing_ent = ent_ptr->getSharingHandlersPtr[proc];
379  if(!(ent_ptr->getPStatus()&PSTATUS_MULTISHARED)) {
380  break;
381  }
382  }
383  \endcode
384 
385  */
386  int *getSharingProcsPtr() const {
387  auto &moab = this->getBasicDataPtr()->moab;
388  int *sharing_procs_ptr = NULL;
389  ParallelComm *pcomm =
390  ParallelComm::get_pcomm(&moab, this->getBasicDataPtr()->pcommID);
391  if (getPStatus() & PSTATUS_MULTISHARED) {
392  // entity is multi shared
393  rval = moab.tag_get_by_ptr(pcomm->sharedps_tag(), &this->ent, 1,
394  (const void **)&sharing_procs_ptr);
395  MOAB_THROW(rval);
396  } else if (getPStatus() & PSTATUS_SHARED) {
397  // shared
398  rval = moab.tag_get_by_ptr(pcomm->sharedp_tag(), &this->ent, 1,
399  (const void **)&sharing_procs_ptr);
400  MOAB_THROW(rval);
401  }
402  return sharing_procs_ptr;
403  }
404 
405  /** \brief get sharid entity handlers
406 
407  Returning list to shared entity handlers. Use it with getSharingProcsPtr()
408 
409  DO NOT MODIFY LIST.
410 
411  \code
412  BasicEntity *ent_ptr = BasicEntity(moab,entity_handle);
413  for(int proc = 0; proc<MAX_SHARING_PROCS && -1 !=
414  ent_ptr->getSharingProcsPtr[proc]; proc++) {
415  if(ent_ptr->getSharingProcsPtr[proc] == -1) {
416  // End of the list
417  break;
418  }
419  int sharing_proc = ent_ptr->getSharingProcsPtr[proc];
420  EntityHandle sharing_ent = ent_ptr->getSharingHandlersPtr[proc];
421  if(!(ent_ptr->getPStatus()&PSTATUS_MULTISHARED)) {
422  break;
423  }
424  }
425  \endcode
426 
427  */
429  EntityHandle *sharing_handlers_ptr = NULL;
430  auto &moab = this->getBasicDataPtr()->moab;
431  ParallelComm *pcomm =
432  ParallelComm::get_pcomm(&moab, this->getBasicDataPtr()->pcommID);
433  if (getPStatus() & PSTATUS_MULTISHARED) {
434  // entity is multi shared
435  rval = moab.tag_get_by_ptr(pcomm->sharedhs_tag(), &this->ent, 1,
436  (const void **)&sharing_handlers_ptr);
437  MOAB_THROW(rval);
438  } else if (getPStatus() & PSTATUS_SHARED) {
439  // shared
440  rval = moab.tag_get_by_ptr(pcomm->sharedh_tag(), &this->ent, 1,
441  (const void **)&sharing_handlers_ptr);
442  MOAB_THROW(rval);
443  }
444  return sharing_handlers_ptr;
445  }
446 
447  static MoFEMErrorCode getParentEnt(Interface &moab, Range ents,
448  std::vector<EntityHandle> vec_patent_ent);
449 
450  static MoFEMErrorCode
451  getBitRefLevel(Interface &moab, Range ents,
452  std::vector<BitRefLevel> &vec_bit_ref_level) {
454  Tag th_ref_bit_level;
455  CHKERR moab.tag_get_handle("_RefBitLevel", th_ref_bit_level);
456  vec_bit_ref_level.resize(ents.size());
457  CHKERR moab.tag_get_data(th_ref_bit_level, ents,
458  &*vec_bit_ref_level.begin());
460  }
461 
462  static MoFEMErrorCode
463  getBitRefLevel(Interface &moab, Range ents,
464  std::vector<const BitRefLevel *> &vec_ptr_bit_ref_level) {
466  Tag th_ref_bit_level;
467  CHKERR moab.tag_get_handle("_RefBitLevel", th_ref_bit_level);
468  vec_ptr_bit_ref_level.resize(ents.size());
469  CHKERR moab.tag_get_by_ptr(
470  th_ref_bit_level, ents,
471  reinterpret_cast<const void **>(&*vec_ptr_bit_ref_level.begin()));
473  }
474 
475  /**
476  * \brief Get pointer to parent entity tag.
477  *
478  * Each refined entity has his parent. Such information is stored on tags.
479  * This function get pinter to tag.
480  *
481  * @return Pointer to tag on entity
482  */
483  inline EntityHandle *getParentEntPtr() const { return entParentTagPtr; }
484 
485  /**
486  * \brief Get pointer to bit ref level tag
487 
488  * Every entity belongs to some refinement level or levels. Each level is
489  marked
490  * by bit set in BitRefLevel() (bitset) structure.
491  *
492  * See \ref mix_mesh_refinement for explanation.
493 
494  * @return Return pointer to tag.
495  */
497  return static_cast<BitRefLevel *>(
498  get_tag_ptr(this->getBasicDataPtr()->moab,
499  this->getBasicDataPtr()->th_RefBitLevel, this->ent, NULL));
500  }
501 
502  /** \brief Get patent entity
503  */
504  inline EntityType getParentEntType() const {
505  return (EntityType)((getParentEnt() & MB_TYPE_MASK) >> MB_ID_WIDTH);
506  }
507 
508  /** \brief Get parent entity, i.e. entity form one refinement level up
509  */
510  inline EntityHandle getParentEnt() const { return *(getParentEntPtr()); }
511 
512  /** \brief Get entity ref bit refinement signature
513  */
514  inline const BitRefLevel &getBitRefLevel() const {
515  return *getBitRefLevelPtr();
516  }
517 
518  /** \brief Get entity ref bit refinement as ulong
519  */
520  inline unsigned long int getBitRefLevelULong() const {
521  return getBitRefLevel().to_ulong();
522  }
523 
524  friend std::ostream &operator<<(std::ostream &os, const RefEntityTmp &e);
525 
527  static boost::weak_ptr<BasicEntityData> basicDataPtr;
528 
529 private:
530  friend struct EntFiniteElement;
531  friend struct NumeredEntFiniteElement;
532 
533  /**
534  * @brief Get the pointer to reference element
535  *
536  * @return const boost::shared_ptr<RefElement>
537  */
538  inline const boost::shared_ptr<RefElement> getRefElementPtr() const {
539  if (auto ptr = refElementPtr.lock())
540  return ptr;
541  else
542  return nullptr;
543  }
544 
545  static boost::weak_ptr<RefElement> refElementPtr;
546  EntityHandle *entParentTagPtr; ///< Tag ptr to parent entity handle
547 };
548 
549 template <> struct RefEntityTmp<-1> : public RefEntityTmp<0> {
550 
551  RefEntityTmp(const boost::shared_ptr<BasicEntityData> &basic_data_ptr,
552  const EntityHandle ent)
553  : RefEntityTmp<0>(basic_data_ptr, ent), basicDataPtr(basic_data_ptr) {}
554 
555  RefEntityTmp(const boost::shared_ptr<BasicEntityData> &basic_data_ptr,
556  const EntityHandle ent, EntityHandle *ent_parent_tag_ptr)
557  : RefEntityTmp<0>(basic_data_ptr, ent, ent_parent_tag_ptr),
558  basicDataPtr(basic_data_ptr) {}
559 
560  virtual const boost::shared_ptr<BasicEntityData> getBasicDataPtr() const {
561  if (auto ptr = basicDataPtr.lock())
562  return ptr;
563  else
564  return nullptr;
565  }
566 
567 private:
568  mutable boost::weak_ptr<BasicEntityData> basicDataPtr;
569 };
570 
572 
573 /**
574  * \brief interface to RefEntity
575  * \ingroup ent_multi_indices
576  */
577 template <typename T> struct interface_RefEntity {
578 
579  interface_RefEntity(const boost::shared_ptr<T> &sptr) : sPtr(sptr) {}
580 
582  : sPtr(interface.getRefEntityPtr()) {}
583 
584  virtual ~interface_RefEntity() = default;
585 
586  /**
587  * @copydoc MoFEM::RefEntityTmp<0>::getSideNumber
588  */
589  inline int getSideNumber() const { return this->sPtr->getSideNumber(); }
590 
591  /**
592  * @copydoc MoFEM::RefEntityTmp<0>::getSideNumberPtr
593  */
594  inline boost::shared_ptr<SideNumber> getSideNumberPtr() const {
595  return this->sPtr->getSideNumberPtr();
596  }
597 
598  /**
599  * @copydoc MoFEM::RefEntityTmp<0>::getBasicDataPtr
600  */
601  inline const boost::shared_ptr<BasicEntityData> getBasicDataPtr() const {
602  return this->sPtr->getBasicDataPtr();
603  }
604 
605  /**
606  * @copydoc MoFEM::RefEntityTmp<0>::getEnt
607  */
608  inline EntityHandle getEnt() const { return this->sPtr->getEnt(); }
609 
610  /**
611  * @copydoc MoFEM::RefEntityTmp<0>::getParentEntType
612  */
613  inline EntityType getParentEntType() const {
614  return this->sPtr->getParentEntType();
615  };
616 
617  /**
618  * @copydoc MoFEM::RefEntityTmp<0>::getParentEnt
619  */
620  inline EntityHandle getParentEnt() const {
621  return this->sPtr->getParentEnt();
622  }
623 
624  /**
625  * @copydoc MoFEM::RefEntityTmp<0>::getBitRefLevelPtr
626  */
627  inline BitRefLevel *getBitRefLevelPtr() const {
628  return this->sPtr->getBitRefLevelPtr();
629  }
630 
631  /**
632  * @copydoc MoFEM::RefEntityTmp<0>::getBitRefLevel
633  */
634  inline const BitRefLevel &getBitRefLevel() const {
635  return this->sPtr->getBitRefLevel();
636  }
637 
638  /**
639  * @copydoc MoFEM::RefEntityTmp<0>::getBitRefLevelULong
640  */
641  inline unsigned long int getBitRefLevelULong() const {
642  return this->sPtr->getBitRefLevelULong();
643  }
644 
645  /**
646  * @copydoc MoFEM::RefEntityTmp<0>::getEntType
647  */
648  inline EntityType getEntType() const { return this->sPtr->getEntType(); };
649 
650  /**
651  * @copydoc MoFEM::RefEntityTmp<0>::getEntDimension
652  */
653  inline int getEntDimension() const { return this->sPtr->getEntDimension(); }
654 
655  /**
656  * @copydoc MoFEM::RefEntityTmp<0>::getEntTypeName
657  */
658  inline const char *getEntTypeName() const {
659  return this->sPtr->getEntTypeName();
660  }
661 
662  /**
663  * @copydoc MoFEM::RefEntityTmp<0>::getEntId
664  */
665  inline EntityID getEntId() const { return this->sPtr->getEntId(); };
666 
667  /**
668  * @copydoc MoFEM::RefEntityTmp<0>::getOwnerEnt
669  */
670  inline EntityHandle getOwnerEnt() const { return this->sPtr->getOwnerEnt(); }
671 
672  /**
673  * @copydoc MoFEM::RefEntityTmp<0>::getOwnerEnt
674  */
675  inline EntityHandle &getOwnerEnt() { return this->sPtr->getOwnerEnt(); }
676 
677  /**
678  * @copydoc MoFEM::RefEntityTmp<0>::getOwnerProc
679  */
680  inline int getOwnerProc() const { return this->sPtr->getOwnerProc(); }
681 
682  /**
683  * @copydoc MoFEM::RefEntityTmp<0>::getPartProc
684  */
685  inline int getPartProc() const { return this->sPtr->getPartProc(); }
686 
687  /**
688  * @copydoc MoFEM::RefEntityTmp<0>::getPartProcPtr
689  */
690  inline int *getPartProcPtr() const { return this->sPtr->getPartProcPtr(); }
691 
692  /**
693  * @copydoc MoFEM::RefEntityTmp<0>::getPartProc
694  */
695  inline unsigned char getPStatus() const { return this->sPtr->getPStatus(); }
696 
697  /**
698  * @copydoc MoFEM::RefEntityTmp<0>::getSharingProcsPtr
699  */
700  inline int *getSharingProcsPtr() const {
701  return this->sPtr->getSharingProcsPtr();
702  }
703 
704  /**
705  * @copydoc MoFEM::RefEntityTmp<0>::getSharingHandlersPtr
706  */
708  return this->sPtr->getSharingHandlersPtr();
709  }
710 
711  /**
712  * @copydoc MoFEM::RefEntityTmp<0>::getRefEntityPtr
713  */
714  inline boost::shared_ptr<T> &getRefEntityPtr() const { return this->sPtr; }
715 
716  mutable boost::shared_ptr<T> sPtr;
717 };
718 
719 /**
720  * \typedef RefEntity_multiIndex
721  * type multiIndex container for RefEntity
722  * \ingroup ent_multi_indices
723  *
724  * \param hashed_unique Ent_mi_tag
725  * \param ordered_non_unique Ent_Ent_mi_tag
726  * \param ordered_non_unique Composite_EntType_And_ParentEntType_mi_tag
727  * \param ordered_non_unique Composite_ParentEnt_And_EntType_mi_tag
728  */
729 using RefEntity_multiIndex = multi_index_container<
730  boost::shared_ptr<RefEntity>,
731  indexed_by<ordered_unique<
732 
733  tag<Ent_mi_tag>,
734  const_mem_fun<RefEntity, EntityHandle, &RefEntity::getEnt>
735 
736  >,
737 
738  ordered_non_unique<
739 
740  tag<Ent_Ent_mi_tag>, const_mem_fun<RefEntity, EntityHandle,
742 
743  >,
744 
745  ordered_non_unique<
746  tag<Composite_EntType_and_ParentEntType_mi_tag>,
747  composite_key<RefEntity,
748  const_mem_fun<RefEntity, EntityType,
750  const_mem_fun<RefEntity, EntityType,
752 
753  >,
754 
755  ordered_non_unique<
756  tag<Composite_ParentEnt_And_EntType_mi_tag>,
757  composite_key<RefEntity,
758  const_mem_fun<RefEntity, EntityType,
760  const_mem_fun<RefEntity, EntityHandle,
762 
763  >>
764 
765  >;
766 
767 /** \brief multi-index view of RefEntity by parent entity
768 \ingroup ent_multi_indices
769 */
771  boost::shared_ptr<RefEntity>,
772  indexed_by<
773  hashed_non_unique<
774  const_mem_fun<RefEntity, EntityHandle, &RefEntity::getParentEnt>>,
775  hashed_unique<tag<Composite_EntType_and_ParentEntType_mi_tag>,
776  composite_key<boost::shared_ptr<RefEntity>,
777  const_mem_fun<RefEntity, EntityHandle,
779  const_mem_fun<RefEntity, EntityHandle,
781 
782  >;
783 
785  multi_index_container<
786  boost::shared_ptr<RefEntity>,
787  indexed_by<ordered_non_unique<const_mem_fun<RefEntity, EntityHandle,
789  hashed_unique<
790  tag<Composite_EntType_and_ParentEntType_mi_tag>,
791  composite_key<boost::shared_ptr<RefEntity>,
792  const_mem_fun<RefEntity, EntityHandle,
794  const_mem_fun<RefEntity, EntityHandle,
796 
797  >;
798 
800  boost::shared_ptr<RefEntity>,
801  indexed_by<
802  sequenced<>,
803  ordered_unique<tag<Ent_mi_tag>, const_mem_fun<RefEntity, EntityHandle,
804  &RefEntity::getEnt>>>>;
805 
806 /** \brief change parent
807 * \ingroup ent_multi_indices
808 *
809 * Use this function with care. Some other multi-indices can deponent on
810 this.
811 
812 Known dependent multi-indices (verify if that list is full):
813 - RefEntity_multiIndex
814 - RefElement_multiIndex
815 
816 */
820  inline void operator()(boost::shared_ptr<RefEntity> &e) {
821  rval = e->getBasicDataPtr()->moab.tag_set_data(
822  e->getBasicDataPtr()->th_RefParentHandle, &e->ent, 1, &pArent);
823  MOAB_THROW(rval);
824  }
825 };
826 
827 /** \brief ref mofem entity, left shift
828  * \ingroup ent_multi_indices
829  */
831  int shift;
833  RefEntity_change_left_shift(const int _shift,
834  const BitRefLevel _mask = BitRefLevel().set())
835  : shift(_shift), mask(_mask) {}
836  inline void operator()(boost::shared_ptr<RefEntity> &e) {
837  BitRefLevel bit = *(e->getBitRefLevelPtr());
838  (*e->getBitRefLevelPtr()) = ((bit & mask) << shift) | (bit & ~mask);
839  };
840 };
841 
842 /** \brief ref mofem entity, right shift
843  * \ingroup ent_multi_indices
844  */
846  int shift;
849  const BitRefLevel _mask = BitRefLevel().set())
850  : shift(_shift), mask(_mask) {}
851  inline void operator()(boost::shared_ptr<RefEntity> &e) {
852  BitRefLevel bit = *(e->getBitRefLevelPtr());
853  *(e->getBitRefLevelPtr()) = ((bit & mask) >> shift) | (bit & ~mask);
854  };
855 };
856 } // namespace MoFEM
857 
858 #endif // __REF_ENTSMULTIINDICES_HPP__
859 
860 /**
861  * \defgroup ent_multi_indices Entities structures and multi-indices
862  * \ingroup mofem
863  **/
#define MB_ID_MASK
Definition: definitions.h:247
#define MOAB_THROW(err)
Check error code of MoAB function and throw MoFEM exception.
Definition: definitions.h:554
#define MYPCOMM_INDEX
default communicator number PCOMM
Definition: definitions.h:228
#define MB_ID_WIDTH
Definition: definitions.h:240
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
#define MB_TYPE_MASK
Definition: definitions.h:241
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
#define CHKERR
Inline error check.
Definition: definitions.h:548
multi_index_container< boost::shared_ptr< RefEntity >, indexed_by< hashed_non_unique< const_mem_fun< RefEntity, EntityHandle, &RefEntity::getParentEnt > >, hashed_unique< tag< Composite_EntType_and_ParentEntType_mi_tag >, composite_key< boost::shared_ptr< RefEntity >, const_mem_fun< RefEntity, EntityHandle, &RefEntity::getEnt >, const_mem_fun< RefEntity, EntityHandle, &RefEntity::getParentEnt > >> > > RefEntity_multiIndex_view_by_hashed_parent_entity
multi-index view of RefEntity by parent entity
multi_index_container< boost::shared_ptr< RefEntity >, indexed_by< ordered_unique< tag< Ent_mi_tag >, const_mem_fun< RefEntity, EntityHandle, &RefEntity::getEnt > >, ordered_non_unique< tag< Ent_Ent_mi_tag >, const_mem_fun< RefEntity, EntityHandle, &RefEntity::getParentEnt > >, ordered_non_unique< tag< Composite_EntType_and_ParentEntType_mi_tag >, composite_key< RefEntity, const_mem_fun< RefEntity, EntityType, &RefEntity::getEntType >, const_mem_fun< RefEntity, EntityType, &RefEntity::getParentEntType > > >, ordered_non_unique< tag< Composite_ParentEnt_And_EntType_mi_tag >, composite_key< RefEntity, const_mem_fun< RefEntity, EntityType, &RefEntity::getEntType >, const_mem_fun< RefEntity, EntityHandle, &RefEntity::getParentEnt > > > > > RefEntity_multiIndex
multi_index_container< boost::shared_ptr< SideNumber >, indexed_by< ordered_unique< member< SideNumber, EntityHandle, &SideNumber::ent > >, ordered_non_unique< composite_key< SideNumber, const_mem_fun< SideNumber, EntityType, &SideNumber::getEntType >, member< SideNumber, char, &SideNumber::side_number > > > > > SideNumber_multiIndex
SideNumber_multiIndex for SideNumber.
auto bit
set bit
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
Definition: Exceptions.hpp:85
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:67
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:51
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
EntityHandle get_id_for_max_type()
EntityHandle get_id_for_min_type()
RefEntityTmp< 0 > RefEntity
void * get_tag_ptr(moab::Interface &moab, Tag th, EntityHandle ent, int *tag_size)
Get the tag ptr object.
multi_index_container< boost::shared_ptr< RefEntity >, indexed_by< sequenced<>, ordered_unique< tag< Ent_mi_tag >, const_mem_fun< RefEntity, EntityHandle, &RefEntity::getEnt > >> > RefEntity_multiIndex_view_sequence_ordered_view
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1965
multi_index_container< boost::shared_ptr< RefEntity >, indexed_by< ordered_non_unique< const_mem_fun< RefEntity, EntityHandle, &RefEntity::getParentEnt > >, hashed_unique< tag< Composite_EntType_and_ParentEntType_mi_tag >, composite_key< boost::shared_ptr< RefEntity >, const_mem_fun< RefEntity, EntityHandle, &RefEntity::getEnt >, const_mem_fun< RefEntity, EntityHandle, &RefEntity::getParentEnt > >> > > RefEntity_multiIndex_view_by_ordered_parent_entity
const int N
Definition: speed_test.cpp:3
PipelineManager data. like access to moab interface and basic tag handlers.
virtual ~BasicEntityData()=default
BasicEntityData(const moab::Interface &mfield, const int pcomm_id=MYPCOMM_INDEX)
Deprecated interface functions.
Finite element data for entity.
Partitioned (Indexed) Finite Element in Problem.
keeps data about abstract refined finite element
RefEntity_change_left_shift(const int _shift, const BitRefLevel _mask=BitRefLevel().set())
void operator()(boost::shared_ptr< RefEntity > &e)
RefEntity_change_parent(EntityHandle parent)
void operator()(boost::shared_ptr< RefEntity > &e)
void operator()(boost::shared_ptr< RefEntity > &e)
RefEntity_change_right_shift(const int _shift, const BitRefLevel _mask=BitRefLevel().set())
boost::weak_ptr< BasicEntityData > basicDataPtr
RefEntityTmp(const boost::shared_ptr< BasicEntityData > &basic_data_ptr, const EntityHandle ent)
virtual const boost::shared_ptr< BasicEntityData > getBasicDataPtr() const
Get pointer to basic data struture.
RefEntityTmp(const boost::shared_ptr< BasicEntityData > &basic_data_ptr, const EntityHandle ent, EntityHandle *ent_parent_tag_ptr)
Struct keeps handle to refined handle.
EntityHandle * getParentEntPtr() const
Get pointer to parent entity tag.
static int getPartProc(const EntityHandle ent, const Tag th, const boost::shared_ptr< BasicEntityData > &basic_ptr)
static MoFEMErrorCode getBitRefLevel(Interface &moab, Range ents, std::vector< const BitRefLevel * > &vec_ptr_bit_ref_level)
virtual ~RefEntityTmp()=default
EntityType getParentEntType() const
Get patent entity.
int getPartProc() const
Get processor.
static boost::weak_ptr< RefElement > refElementPtr
int * getSharingProcsPtr() const
get shared processors
virtual const boost::shared_ptr< BasicEntityData > getBasicDataPtr() const
Get pointer to basic data struture.
BitRefLevel * getBitRefLevelPtr() const
Get pointer to bit ref level tag.
EntityID getEntId() const
get entity id
unsigned char getPStatus() const
get pstatus This tag stores various aspects of parallel status in bits; see also define following,...
const char * getEntTypeName() const
Get the Ent Type Name.
const BitRefLevel & getBitRefLevel() const
Get entity ref bit refinement signature.
EntityHandle * getSharingHandlersPtr() const
get sharid entity handlers
unsigned long int getBitRefLevelULong() const
Get entity ref bit refinement as ulong.
EntityType getEntType() const
Get entity type.
static MoFEMErrorCode getBitRefLevel(Interface &moab, Range ents, std::vector< BitRefLevel > &vec_bit_ref_level)
EntityHandle getParentEnt() const
Get parent entity, i.e. entity form one refinement level up.
int * getPartProcPtr() const
Get pointer to partition tag.
EntityHandle * entParentTagPtr
Tag ptr to parent entity handle.
friend std::ostream & operator<<(std::ostream &os, const RefEntityTmp &e)
int getEntDimension() const
Get the Ent Dimension.
static boost::weak_ptr< BasicEntityData > basicDataPtr
static EntityHandle getOwnerEnt(const EntityHandle ent, boost::shared_ptr< BasicEntityData > basic_ent_data)
EntityHandle getOwnerEnt() const
Owner handle on this or other processors.
EntityHandle getEnt() const
Get the entity handle.
static int getOwnerProc(const EntityHandle ent, boost::shared_ptr< BasicEntityData > basic_ent_data)
static MoFEMErrorCode getParentEnt(Interface &moab, Range ents, std::vector< EntityHandle > vec_patent_ent)
const boost::shared_ptr< RefElement > getRefElementPtr() const
Get the pointer to reference element.
virtual const boost::shared_ptr< BasicEntityData > getBasicDataPtr() const
static boost::weak_ptr< BasicEntityData > basicDataPtr
keeps information about side number for the finite element
const char * getEntTypeName() const
EntityType getEntType() const
SideNumber(EntityHandle ent, int side_number, int sense, int offset)
virtual ~interface_RefEntity()=default
EntityType getParentEntType() const
Get patent entity.
boost::shared_ptr< SideNumber > getSideNumberPtr() const
Get the Side number.
interface_RefEntity(const interface_RefEntity< T > &interface)
int * getPartProcPtr() const
Get pointer to partition tag.
EntityHandle getParentEnt() const
EntityHandle getOwnerEnt() const
const char * getEntTypeName() const
Get the Ent Type Name.
EntityHandle * getSharingHandlersPtr() const
get sharid entity handlers
const BitRefLevel & getBitRefLevel() const
boost::shared_ptr< T > & getRefEntityPtr() const
int getEntDimension() const
Get the Ent Dimension.
EntityType getEntType() const
Get entity type.
BitRefLevel * getBitRefLevelPtr() const
Get pointer to bit ref level tag.
const boost::shared_ptr< BasicEntityData > getBasicDataPtr() const
Get pointer to basic data struture.
unsigned char getPStatus() const
EntityID getEntId() const
get entity id
unsigned long int getBitRefLevelULong() const
Get entity ref bit refinement as ulong.
interface_RefEntity(const boost::shared_ptr< T > &sptr)
EntityHandle getEnt() const
Get the entity handle.
int * getSharingProcsPtr() const
get shared processors
@ TYPE
Definition: inflate.h:32