Karol,
So I expect, that you rather like to do,
// That get a smart pointer, if you go out of the scope, dM is dereferenced, if the reference count is zero object is destroyed.
SmartPetscObj<DM> dM = simple->getDM();
// No bump reference, and cas SmartPetscObj<DM> to PetscObject,
PetscObjectReference(getPetscObject(dM.get()));
DM dm = dM;
// do somthing
// Now you have to remember to destroy DM.
DMDestroy(dm);
However, I do not know exactly what you like to do, why you need to do that? Why SmartPestcObj is not good for you, and you need to work with raw DM object?
One comment, that
DM *dm = dM.get();
makes no big sense, since PetscObject, in this case, DM is a pointer to structure. That would make only sense, in the case like that,
auto get_dm = [simple](DM *dm) {
MoFEMFunctionBegin;
dM = simple->getDM();
CHKERR PetscObjectReference(getPetscObject(dM.get()));
DM *dm = dM.get();
MoFEMFunctionReturn(0);
};
DM dm;
CHKERR get_dm(&dm);
// Do something
CHKERR DMDestroy(&dm);
Kind regards,
Lukasz
MoFEMErrorCode MortarInterface::addContactElements(DM dm) {
MoFEMFunctionBeginHot;
dmPtr = &dm;
CHKERR DMMoFEMAddElement(*dmPtr, "CONTACT_ELEM");
CHKERR DMMoFEMAddElement(*dmPtr, "CONTACT_POST_PROC");
auto simple = mField.getInterface<Simple>();
simple->getOtherFiniteElements().push_back("CONTACT_ELEM");
simple->getOtherFiniteElements().push_back("CONTACT_POST_PROC");
MoFEMFunctionReturnHot(0);
}
MoFEMErrorCode MortarInterface::addContactElements(SmartPetscObj<DM> dm) {
MoFEMFunctionBeginHot;
CHKERR PetscObjectReference(getPetscObject(dm.get()));
*dmPtr = dm.get();
CHKERR addContactElements(*dmPtr);
MoFEMFunctionReturnHot(0);
}
template <typename T>
MoFEMErrorCode MortarInterface::setupSolver(bool is_quasi_static) {
MoFEMFunctionBegin;
if (!dmPtr)
SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
"DM not defined, addContactElements first");
...