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

intrusive_ptr for managing petsc objects More...

#include <src/petsc/AuxPETSc.hpp>

Inherits intrusive_ptr< std::remove_pointer< OBJ >::type >.

Public Member Functions

 SmartPetscObj ()
 
 SmartPetscObj (OBJ o)
 
 operator OBJ ()
 
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
reaction_diffusion_equation.cpp.

Definition at line 124 of file AuxPETSc.hpp.

Constructor & Destructor Documentation

◆ SmartPetscObj() [1/2]

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

Definition at line 127 of file AuxPETSc.hpp.

128  : boost::intrusive_ptr<typename std::remove_pointer<OBJ>::type>() {}

◆ SmartPetscObj() [2/2]

template<typename OBJ>
MoFEM::SmartPetscObj< OBJ >::SmartPetscObj ( OBJ  o)

Definition at line 129 of file AuxPETSc.hpp.

130  : boost::intrusive_ptr<typename std::remove_pointer<OBJ>::type>(o,
131  false) {}

Member Function Documentation

◆ operator OBJ()

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

Definition at line 132 of file AuxPETSc.hpp.

132 { return this->get(); }

◆ use_count()

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

Definition at line 134 of file AuxPETSc.hpp.

134  {
135  if (this->get()) {
136  int cnt;
137  ierr = PetscObjectGetReference(getPetscObject(this->get()), &cnt);
138  CHKERRABORT(PetscObjectComm(getPetscObject(this->get())), ierr);
139  return cnt;
140  } else
141  return 0;
142  }
PetscObject getPetscObject(T obj)
Definition: AuxPETSc.hpp:23

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