v0.13.1
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]

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.

auto createSmartGhostVector(MPI_Comm comm, PetscInt n, PetscInt N, PetscInt nghost, const PetscInt ghosts[])
Create smart ghost vector.
Template Parameters
OBJ
Examples
contact.cpp, plastic.cpp, and thermo_plastic.cpp.

Definition at line 91 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 94 of file PetscSmartObj.hpp.

Constructor & Destructor Documentation

◆ SmartPetscObj() [1/2]

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

Definition at line 98 of file PetscSmartObj.hpp.

98: SmartPetscObj() {}
SmartPetscObj(std::nullptr_t ptr)

◆ SmartPetscObj() [2/2]

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

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 108 of file PetscSmartObj.hpp.

110 add_ref) {
111 }
static Index< 'o', 3 > o

Member Function Documentation

◆ operator OBJ()

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

Definition at line 113 of file PetscSmartObj.hpp.

113{ return this->get(); }

◆ operator PetscObject()

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

Definition at line 114 of file PetscSmartObj.hpp.

114 {
115 return reinterpret_cast<PetscObject>(this->get());
116 }

◆ use_count()

template<typename OBJ >
int MoFEM::SmartPetscObj< OBJ >::use_count ( ) const
Examples
petsc_smart_ptr_objects.cpp.

Definition at line 118 of file PetscSmartObj.hpp.

118 {
119 if (this->get()) {
120 int cnt;
121 ierr = PetscObjectGetReference(getPetscObject(this->get()), &cnt);
122 CHKERRABORT(PetscObjectComm(getPetscObject(this->get())), ierr);
123 return cnt;
124 } else
125 return 0;
126 }
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Exceptions.hpp:87
PetscObject getPetscObject(T obj)

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