v0.8.15
Classes | Public Member Functions | Protected Member Functions | Private Types | Private Attributes | List of all members
MoFEM::UnknownInterface Struct Referenceabstract

base class for all interface classes More...

#include <src/interfaces/UnknownInterface.hpp>

Inheritance diagram for MoFEM::UnknownInterface:
[legend]

Classes

struct  HashMOFEMuuid
 
struct  NotKnownClass
 
struct  UIdTypeMap
 

Public Member Functions

virtual MoFEMErrorCode query_interface (const MOFEMuuid &uuid, UnknownInterface **iface) const =0
 
template<class IFACE >
MoFEMErrorCode registerInterface (const MOFEMuuid &uuid, bool error_if_registration_failed=true)
 Register interface. More...
 
template<class IFACE , bool VERIFY = false>
MoFEMErrorCode getInterface (const MOFEMuuid &uuid, IFACE *&iface) const
 Get interface by uuid and return reference to pointer of interface. More...
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE *&iface) const
 Get interface refernce to pointer of interface. More...
 
template<class IFACE >
MoFEMErrorCode getInterface (IFACE **const iface) const
 Get interface pointer to pointer of interface. More...
 
template<class IFACE , typename boost::enable_if< boost::is_pointer< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get interface pointer to pointer of interface. More...
 
template<class IFACE , typename boost::enable_if< boost::is_reference< IFACE >, int >::type = 0>
IFACE getInterface () const
 Get reference to interface. More...
 
template<class IFACE >
IFACE * getInterface () const
 Function returning pointer to interface. More...
 
virtual ~UnknownInterface ()
 
virtual MoFEMErrorCode getLibVersion (Version &version) const
 Get library version. More...
 
virtual const MoFEMErrorCode getFileVersion (moab::Interface &moab, Version &version) const
 Get database major version. More...
 
virtual MoFEMErrorCode getInterfaceVersion (Version &version) const
 Get database major version. More...
 
template<>
MoFEMErrorCode getInterface (const MOFEMuuid &uuid, UnknownInterface *&iface) const
 

Protected Member Functions

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...
 

Private Types

typedef multi_index_container< UIdTypeMap, indexed_by< hashed_unique< member< UIdTypeMap, MOFEMuuid, &UIdTypeMap::uID >, HashMOFEMuuid >, hashed_unique< member< UIdTypeMap, boost::typeindex::type_index, &UIdTypeMap::classIdx > > > > iFaceTypeMap_multiIndex
 Data structure for interfaces Id and class names. More...
 

Private Attributes

iFaceTypeMap_multiIndex iFaceTypeMap
 Maps MOFEMuuid to interface type name. More...
 

Detailed Description

base class for all interface classes

Examples:
forces_and_sources_testing_users_base.cpp.

Definition at line 75 of file UnknownInterface.hpp.

Member Typedef Documentation

◆ iFaceTypeMap_multiIndex

typedef multi_index_container< UIdTypeMap, indexed_by< hashed_unique< member<UIdTypeMap, MOFEMuuid, &UIdTypeMap::uID>, HashMOFEMuuid >, hashed_unique< member<UIdTypeMap, boost::typeindex::type_index, &UIdTypeMap::classIdx> > > > MoFEM::UnknownInterface::iFaceTypeMap_multiIndex
private

Data structure for interfaces Id and class names.

Definition at line 423 of file UnknownInterface.hpp.

Constructor & Destructor Documentation

◆ ~UnknownInterface()

virtual MoFEM::UnknownInterface::~UnknownInterface ( )
virtual

Definition at line 300 of file UnknownInterface.hpp.

300 {}

Member Function Documentation

◆ getClassIdx()

boost::typeindex::type_index MoFEM::UnknownInterface::getClassIdx ( const MOFEMuuid uid) const
protected

Get type name for interface Id.

Parameters
uidinterface Id
Returns
class name

Definition at line 373 of file UnknownInterface.hpp.

373  {
374  iFaceTypeMap_multiIndex::nth_index<0>::type::iterator it;
375  it = iFaceTypeMap.get<0>().find(uid);
376  if (it != iFaceTypeMap.get<0>().end()) {
377  return it->classIdx;
378  }
379  return boost::typeindex::type_id<NotKnownClass>();
380  }
iFaceTypeMap_multiIndex iFaceTypeMap
Maps MOFEMuuid to interface type name.

◆ getFileVersion()

virtual const MoFEMErrorCode MoFEM::UnknownInterface::getFileVersion ( moab::Interface &  moab,
Version version 
) const
virtual

Get database major version.

This is database version. MoFEM can read DataBase from file created by older version. Then library version and database version could be different.

Returns
error code

Definition at line 324 of file UnknownInterface.hpp.

325  {
327  const EntityHandle root_meshset = 0;
328  const int def_version[] = {-1, -1, -1};
329  Tag th;
330  rval = moab.tag_get_handle("MOFEM_VERSION", 3, MB_TYPE_INTEGER, th,
331  MB_TAG_CREAT | MB_TAG_MESH, &def_version);
332  int *version_ptr;
333  if (rval == MB_ALREADY_ALLOCATED) {
334  const void *tag_data[1];
335  CHKERR moab.tag_get_by_ptr(th, &root_meshset, 1, tag_data);
336  version_ptr = (int *)tag_data[0];
337  } else {
338  const void *tag_data[1];
339  CHKERR moab.tag_get_by_ptr(th, &root_meshset, 1, tag_data);
340  version_ptr = (int *)tag_data[0];
341  version_ptr[0] = MoFEM_VERSION_MAJOR;
342  version_ptr[1] = MoFEM_VERSION_MINOR;
343  version_ptr[2] = MoFEM_VERSION_BUILD;
344  }
345  version = Version(version_ptr);
347  }
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return() ...
Definition: definitions.h:459
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
Definition: Common.hpp:78
#define CHKERR
Inline error check.
Definition: definitions.h:578
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:403

◆ getInterface() [1/7]

template<class IFACE , bool VERIFY = false>
MoFEMErrorCode MoFEM::UnknownInterface::getInterface ( const MOFEMuuid uuid,
IFACE *&  iface 
) const

Get interface by uuid and return reference to pointer of interface.

Note
uuid of interface and interface are verified, if second template parameter is true. Function throw error if both do not match.
Do not use this function directly, it is called by other overload getInterface methods.
Parameters
uuid
ifacereference to a interface pointer
Returns
MoFEMErrorCode
Examples:
analytical_nonlinear_poisson.cpp, analytical_poisson.cpp, analytical_poisson_field_split.cpp, cubit_bc_test.cpp, elasticity.cpp, field_to_vertices.cpp, forces_and_sources_testing_edge_element.cpp, forces_and_sources_testing_users_base.cpp, hello_world.cpp, MagneticElement.hpp, mesh_cut.cpp, mesh_smoothing.cpp, minimal_surface_area.cpp, simple_elasticity.cpp, simple_interface.cpp, split_sideset.cpp, testing_jacobian_of_hook_element.cpp, unsaturated_transport.cpp, and UnsaturatedFlow.hpp.

Definition at line 122 of file UnknownInterface.hpp.

123  {
125  iface = NULL;
126  if (VERIFY) {
127  if (boost::typeindex::type_id<IFACE>()!=getClassIdx(uuid)) {
128  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
129  "Inconsistency between interface Id and type");
130  }
131  }
132  UnknownInterface *ptr;
133  ierr = getInterface<UnknownInterface, false>(uuid, ptr);
134  CHKERRG(ierr);
135  iface = static_cast<IFACE *>(ptr);
137  }
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:483
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:526
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return() ...
Definition: definitions.h:490
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Common.hpp:80
boost::typeindex::type_index getClassIdx(const MOFEMuuid &uid) const
Get type name for interface Id.

◆ getInterface() [2/7]

template<class IFACE >
MoFEMErrorCode MoFEM::UnknownInterface::getInterface ( IFACE *&  iface) const

Get interface refernce to pointer of interface.

// Create moab database
moab::Core mb_instance;
// Access moab database by interface
moab::Interface &moab = mb_instance;
// Create MoFEM database
// Acces MoFEM database by Interface
MoFEM::Interface &m_field = core;
// Get interface
// Get simple interface is simplified version enabling quick and
// easy construction of problem.
Simple *simple_interface;
// Query interface and get pointer to Simple interface
CHKERR m_field.getInterface(simple_interface);
Parameters
ifacereference to a interface pointer
Returns
MoFEMErrorCode

Definition at line 166 of file UnknownInterface.hpp.

166  {
167  return getInterface<IFACE, false>(
168  getUId(boost::typeindex::type_id<IFACE>()), iface);
169  }
MOFEMuuid getUId(const boost::typeindex::type_index &class_idx) const
Get interface Id for class name.

◆ getInterface() [3/7]

template<class IFACE >
MoFEMErrorCode MoFEM::UnknownInterface::getInterface ( IFACE **const  iface) const

Get interface pointer to pointer of interface.

// Create moab database
moab::Core mb_instance;
// Access moab database by interface
moab::Interface &moab = mb_instance;
// Create MoFEM database
// Acces MoFEM database by Interface
MoFEM::Interface &m_field = core;
// Get interface
// Get simple interface is simplified version enabling quick and
// easy construction of problem.
Simple *simple_interface;
// Query interface and get pointer to Simple interface
CHKERR m_field.getInterface(&simple_interface);
Parameters
ifaceconst pointer to a interface pointer
Returns
MoFEMErrorCode

Definition at line 199 of file UnknownInterface.hpp.

199  {
200  return getInterface<IFACE, false>(boost::typeindex::type_id<IFACE>(),
201  *iface);
202  }

◆ getInterface() [4/7]

template<class IFACE , typename boost::enable_if< boost::is_pointer< IFACE >, int >::type = 0>
IFACE MoFEM::UnknownInterface::getInterface ( ) const

Get interface pointer to pointer of interface.

// Create moab database
moab::Core mb_instance;
// Access moab database by interface
moab::Interface &moab = mb_instance;
// Create MoFEM database
// Acces MoFEM database by Interface
MoFEM::Interface &m_field = core;
// Get interface
// Get simple interface is simplified version enabling quick and
// easy construction of problem.
Simple *simple_interface = m_field.getInterface<Simple*,0>();
Returns
IFACE*

Definition at line 229 of file UnknownInterface.hpp.

229  {
230  typedef typename boost::remove_pointer<IFACE>::type IFaceType;
231  IFaceType* iface = NULL;
232  ierr = getInterface<IFaceType, false>(
233  getUId(boost::typeindex::type_id<IFaceType>()), iface);
234  CHKERRABORT(PETSC_COMM_SELF, ierr);
235  return iface;
236  }
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Common.hpp:80
MOFEMuuid getUId(const boost::typeindex::type_index &class_idx) const
Get interface Id for class name.

◆ getInterface() [5/7]

template<class IFACE , typename boost::enable_if< boost::is_reference< IFACE >, int >::type = 0>
IFACE MoFEM::UnknownInterface::getInterface ( ) const

Get reference to interface.

// Create moab database
moab::Core mb_instance;
// Access moab database by interface
moab::Interface &moab = mb_instance;
// Create MoFEM database
// Acces MoFEM database by Interface
MoFEM::Interface &m_field = core;
// Get interface
// Get simple interface is simplified version enabling quick and
// easy construction of problem.
Simple &simple_interface = m_field.getInterface<Simple&,0>();
Returns
IFACE&

Definition at line 263 of file UnknownInterface.hpp.

263  {
264  typedef typename boost::remove_reference<IFACE>::type IFaceType;
265  IFaceType* iface = NULL;
266  ierr = getInterface<IFaceType, false>(
267  getUId(boost::typeindex::type_id<IFaceType>()), iface);
268  CHKERRABORT(PETSC_COMM_SELF, ierr);
269  return *iface;
270  }
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Common.hpp:80
MOFEMuuid getUId(const boost::typeindex::type_index &class_idx) const
Get interface Id for class name.

◆ getInterface() [6/7]

template<class IFACE >
IFACE* MoFEM::UnknownInterface::getInterface ( ) const

Function returning pointer to interface.

// Create moab database
moab::Core mb_instance;
// Access moab database by interface
moab::Interface &moab = mb_instance;
// Create MoFEM database
// Acces MoFEM database by Interface
MoFEM::Interface &m_field = core;
// Get interface
// Get simple interface is simplified version enabling quick and
// easy construction of problem.
Simple *simple_interface = m_field.getInterface<Simple,0>();
Returns
IFACE*

Definition at line 296 of file UnknownInterface.hpp.

296  {
297  return getInterface<IFACE*,0>();
298  }

◆ getInterface() [7/7]

template<>
MoFEMErrorCode MoFEM::UnknownInterface::getInterface ( const MOFEMuuid uuid,
UnknownInterface *&  iface 
) const

Definition at line 430 of file UnknownInterface.hpp.

431  {
432  return query_interface(uuid, &iface);
433 }
virtual MoFEMErrorCode query_interface(const MOFEMuuid &uuid, UnknownInterface **iface) const =0

◆ getInterfaceVersion()

virtual MoFEMErrorCode MoFEM::UnknownInterface::getInterfaceVersion ( Version version) const
virtual

Get database major version.

Implementation of particular interface could be different than main lib. For example user could use older interface, to keep back compatibility.

Returns
error code

Definition at line 357 of file UnknownInterface.hpp.

357  {
359  version =
360  Version(MoFEM_VERSION_MAJOR, MoFEM_VERSION_MINOR, MoFEM_VERSION_BUILD);
362  }
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:483
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return() ...
Definition: definitions.h:490

◆ getLibVersion()

virtual MoFEMErrorCode MoFEM::UnknownInterface::getLibVersion ( Version version) const
virtual

Get library version.

This is library version.

Returns
error code

Definition at line 309 of file UnknownInterface.hpp.

309  {
311  version =
312  Version(MoFEM_VERSION_MAJOR, MoFEM_VERSION_MINOR, MoFEM_VERSION_BUILD);
314  }
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:483
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return() ...
Definition: definitions.h:490

◆ getUId()

MOFEMuuid MoFEM::UnknownInterface::getUId ( const boost::typeindex::type_index &  class_idx) const
protected

Get interface Id for class name.

Parameters
class_name
Returns
Id

Definition at line 387 of file UnknownInterface.hpp.

387  {
388  iFaceTypeMap_multiIndex::nth_index<1>::type::iterator it;
389  it = iFaceTypeMap.get<1>().find(class_idx);
390  if (it != iFaceTypeMap.get<1>().end()) {
391  return it->uID;
392  }
393  return IDD_MOFEMUnknown;
394  }
static const MOFEMuuid IDD_MOFEMUnknown
iFaceTypeMap_multiIndex iFaceTypeMap
Maps MOFEMuuid to interface type name.

◆ query_interface()

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

◆ registerInterface()

template<class IFACE >
MoFEMErrorCode MoFEM::UnknownInterface::registerInterface ( const MOFEMuuid uuid,
bool  error_if_registration_failed = true 
)

Register interface.

Example:

ierr = regSubInterface<Simple>(IDD_MOFEMSimple);
CHKERRABORT(PETSC_COMM_SELF, ierr);
Parameters
uuid
true
Returns
MoFEMErrorCode

Definition at line 94 of file UnknownInterface.hpp.

95  {
97  std::pair<iFaceTypeMap_multiIndex::iterator, bool> p;
98  p = iFaceTypeMap.insert(
99  UIdTypeMap(uuid, boost::typeindex::type_id<IFACE>()));
100  if (error_if_registration_failed && (!p.second)) {
101  SETERRQ1(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
102  "Registration of interface typeid(IFACE).name() = %s failed",
103  typeid(IFACE).name());
104  }
106  }
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:483
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return() ...
Definition: definitions.h:490
iFaceTypeMap_multiIndex iFaceTypeMap
Maps MOFEMuuid to interface type name.

Member Data Documentation

◆ iFaceTypeMap

iFaceTypeMap_multiIndex MoFEM::UnknownInterface::iFaceTypeMap
mutableprivate

Maps MOFEMuuid to interface type name.

Definition at line 426 of file UnknownInterface.hpp.


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