15 #ifndef ALLIUM_LA_PETSC_OBJECT_PTR_HPP
16 #define ALLIUM_LA_PETSC_OBJECT_PTR_HPP
18 #include <allium/config.hpp>
20 #ifdef ALLIUM_USE_PETSC
40 struct is_petsc_object : std::false_type {};
42 template<>
struct is_petsc_object<Mat> : std::true_type {};
43 template<>
struct is_petsc_object<Vec> : std::true_type {};
44 template<>
struct is_petsc_object<KSP> : std::true_type {};
45 template<>
struct is_petsc_object<PC> : std::true_type {};
46 template<>
struct is_petsc_object<TS> : std::true_type {};
47 template<>
struct is_petsc_object<DM> : std::true_type {};
49 template<>
struct is_petsc_object<EPS> : std::true_type {};
53 std::enable_if_t<is_petsc_object<T>::value, PetscObject>
54 petsc_object_cast(T value) {
55 return reinterpret_cast<PetscObject
>(value);
68 static_assert(is_petsc_object<T>::value,
69 "PetscObjectPtr can only hold PETSc objects.");
76 PetscObjectReference(petsc_object_cast(other.value));
77 this->value = other.value;
81 this->value = other.value;
82 other.value =
nullptr;
87 set(new_value, adopt);
99 set(other.value,
false);
106 if (value !=
nullptr) {
107 PetscObjectDereference(petsc_object_cast(value));
120 void set(T new_value,
bool adopt) {
124 PetscObjectReference(petsc_object_cast(new_value));
144 friend void swap(PetscObjectPtr<T> &a, PetscObjectPtr<T> &b){
PETSc wrapper object for memory management.
Definition: petsc_object_ptr.hpp:66
void release()
Definition: petsc_object_ptr.hpp:105
T * writable_ptr()
Definition: petsc_object_ptr.hpp:135
T abandon()
Definition: petsc_object_ptr.hpp:114