1 #ifndef ABLATELIBRARY_FIELDACCESSOR_HPP
2 #define ABLATELIBRARY_FIELDACCESSOR_HPP
7 namespace ablate::domain {
11 template <
class DataType,
bool isLocal = true>
22 const Field& dataField;
27 PetscScalar* dataArray{};
35 FieldAccessor(Vec dataVectorIn,
const Field& dataFieldIn, DM dm =
nullptr) : dataVector(dataVectorIn), dataField(dataFieldIn), dataDM(dm) {
51 [[nodiscard]]
inline const Field&
GetField()
const {
return dataField; }
54 template <
class IndexType>
57 if constexpr (isLocal) {
66 template <
class IndexType>
67 inline PetscErrorCode
operator()(IndexType point, DataType** field) {
68 PetscFunctionBeginHot;
69 if constexpr (isLocal) {
70 PetscCall(DMPlexPointLocalFieldRef(dataDM, point, dataField.id, dataArray, field));
72 PetscCall(DMPlexPointGlobalFieldRef(dataDM, point, dataField.id, dataArray, field));
74 PetscFunctionReturn(PETSC_SUCCESS);
Definition: fieldAccessor.hpp:12
FieldAccessor(const FieldAccessor &)=delete
PetscErrorCode operator()(IndexType point, DataType **field)
Inline function to compute the memory address at this point using PETSC style return error.
Definition: fieldAccessor.hpp:67
const Field & GetField() const
provide easy access to the field information
Definition: fieldAccessor.hpp:51
DataType * operator[](IndexType point)
Inline function to compute the memory address at this point.
Definition: fieldAccessor.hpp:55
static utilities::PetscUtilities::ErrorChecker checkError
Definition: petscUtilities.hpp:46