v0.14.0
Functions | Variables
petsc_smart_ptr_objects.cpp File Reference
#include <MoFEM.hpp>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Variables

static char help [] = "...\n\n"
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)
Examples
petsc_smart_ptr_objects.cpp.

Definition at line 14 of file petsc_smart_ptr_objects.cpp.

14  {
15 
16  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
17 
18  try {
19 
20  SmartPetscObj<Mat> m_ptr;
21 
22  // check is count is correct
23  auto check = [&](const int expected) {
25  if (m_ptr.use_count() != expected)
26  SETERRQ2(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
27  "use count should be %d but is %d", expected,
28  m_ptr.use_count());
30  };
31 
32  // check copy constructor
33  {
34  Mat m;
35  CHKERR MatCreate(PETSC_COMM_SELF, &m);
36  m_ptr = SmartPetscObj<Mat>(m);
37  }
38 
39  // Check casting on PetscObject
40  { std::ignore = static_cast<PetscObject>(m_ptr); }
41 
42  {
43  SmartPetscObj<Mat> n_ptr(m_ptr);
44  CHKERR check(2);
45  }
46 
47  CHKERR check(1);
48 
49  // check if casting works well
50  CHKERR MatSetSizes(m_ptr, 2, 2, 2, 2);
51 
52  {
53  // nesting once
54  SmartPetscObj<Mat> n_ptr = m_ptr;
55  CHKERR check(2);
56  {
57  // again
58  SmartPetscObj<Mat> i_ptr = m_ptr;
59  CHKERR check(3);
60  }
61  CHKERR check(2);
62  }
63 
64 
65  {
66  // nesting again
67  SmartPetscObj<Mat> n_ptr = m_ptr;
68  CHKERR check(2);
69  }
70 
71  // only one now
72  CHKERR check(1);
73 
74  // reset, i.e. delete matrix
75  m_ptr.reset();
76 
77  // counts should be zero now
78  CHKERR check(0);
79 
80  {
82  }
83 
84  }
86 
88  return 0;
89 }

Variable Documentation

◆ help

char help[] = "...\n\n"
static
Examples
petsc_smart_ptr_objects.cpp.

Definition at line 12 of file petsc_smart_ptr_objects.cpp.

help
static char help[]
Definition: petsc_smart_ptr_objects.cpp:12
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEM::SmartPetscObj::use_count
int use_count() const
Definition: PetscSmartObj.hpp:105
MoFEM::CoreTmp< 0 >::Initialize
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:72
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
m
FTensor::Index< 'm', 3 > m
Definition: shallow_wave.cpp:80
MoFEM::SmartPetscObj< Mat >
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346