v0.14.0
Public Types | Public Member Functions | List of all members
MoFEM::SmartPetscObj< OBJ > Struct Template Reference

intrusive_ptr for managing petsc objects More...

#include <include/PetscSmartObj.hpp>

Inheritance diagram for MoFEM::SmartPetscObj< OBJ >:
[legend]
Collaboration diagram for MoFEM::SmartPetscObj< OBJ >:
[legend]

Public Types

using Derived = boost::intrusive_ptr< typename std::remove_pointer< OBJ >::type >
 

Public Member Functions

 SmartPetscObj (std::nullptr_t ptr)
 
 SmartPetscObj (OBJ o, bool add_ref=false)
 Construct a new Smart Petsc Obj object. More...
 
 operator OBJ ()
 
 operator PetscObject ()
 
int use_count () const
 

Detailed Description

template<typename OBJ>
struct MoFEM::SmartPetscObj< OBJ >

intrusive_ptr for managing petsc objects

It manages destruction, referencing and dereferencing petsc objects. It is similar how smart_ptr pointers works, but applied for petsc objects like Vec, DM, Mat, etc.

SmartPetscObj<Vec> smart_vec = createSmartGhostVector(...);
Template Parameters
OBJ
Examples
approx_sphere.cpp, dynamic_first_order_con_law.cpp, plastic.cpp, schur_test_diag_mat.cpp, shallow_wave.cpp, and test_broken_space.cpp.

Definition at line 82 of file PetscSmartObj.hpp.

Member Typedef Documentation

◆ Derived

template<typename OBJ >
using MoFEM::SmartPetscObj< OBJ >::Derived = boost::intrusive_ptr<typename std::remove_pointer<OBJ>::type>

Definition at line 85 of file PetscSmartObj.hpp.

Constructor & Destructor Documentation

◆ SmartPetscObj() [1/2]

template<typename OBJ >
MoFEM::SmartPetscObj< OBJ >::SmartPetscObj ( std::nullptr_t  ptr)
inline

Definition at line 89 of file PetscSmartObj.hpp.

89 : SmartPetscObj() {}

◆ SmartPetscObj() [2/2]

template<typename OBJ >
MoFEM::SmartPetscObj< OBJ >::SmartPetscObj ( OBJ  o,
bool  add_ref = false 
)
inlineexplicit

Construct a new Smart Petsc Obj object.

Note
If add_red is set to true, you have to destroy OBJ.
Parameters
o
add_ref// if false ownership of OBJ is taken by SmartPetscObj

Definition at line 99 of file PetscSmartObj.hpp.

Member Function Documentation

◆ operator OBJ()

template<typename OBJ >
MoFEM::SmartPetscObj< OBJ >::operator OBJ ( )
inline

Definition at line 104 of file PetscSmartObj.hpp.

104 { return this->get(); }

◆ operator PetscObject()

template<typename OBJ >
MoFEM::SmartPetscObj< OBJ >::operator PetscObject ( )
inlineexplicit

Definition at line 105 of file PetscSmartObj.hpp.

105  {
106  return reinterpret_cast<PetscObject>(this->get());
107  }

◆ use_count()

template<typename OBJ >
int MoFEM::SmartPetscObj< OBJ >::use_count ( ) const
inline

Definition at line 109 of file PetscSmartObj.hpp.

109  {
110  if (this->get()) {
111  int cnt;
112  ierr = PetscObjectGetReference(getPetscObject(this->get()), &cnt);
113  CHKERRABORT(PetscObjectComm(getPetscObject(this->get())), ierr);
114  return cnt;
115  } else
116  return 0;
117  }

The documentation for this struct was generated from the following file:
MoFEM::getPetscObject
PetscObject getPetscObject(T obj)
Definition: PetscSmartObj.hpp:9
convert.type
type
Definition: convert.py:64
MoFEM::createSmartGhostVector
DEPRECATED auto createSmartGhostVector(MPI_Comm comm, PetscInt n, PetscInt N, PetscInt nghost, const PetscInt ghosts[])
Definition: PetscSmartObj.hpp:188
MoFEM::Exceptions::ierr
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Exceptions.hpp:76
MoFEM::SmartPetscObj::SmartPetscObj
SmartPetscObj(std::nullptr_t ptr)
Definition: PetscSmartObj.hpp:89