1 #ifndef ABLATELIBRARY_CONSTFIELDACCESSOR_HPP
2 #define ABLATELIBRARY_CONSTFIELDACCESSOR_HPP
7 namespace ablate::domain {
11 template <
class DataType,
bool isLocal = true>
22 const Field& dataField;
27 const PetscScalar* dataArray{};
35 ConstFieldAccessor(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>
55 inline const DataType*
operator[](IndexType point)
const {
56 const DataType* field;
57 if constexpr (isLocal) {
66 template <
class IndexType>
67 inline PetscErrorCode
operator()(IndexType point,
const DataType** field)
const {
68 PetscFunctionBeginHot;
69 if constexpr (isLocal) {
70 PetscCall(DMPlexPointLocalFieldRead(dataDM, point, dataField.id, dataArray, field));
72 PetscCall(DMPlexPointGlobalFieldRead(dataDM, point, dataField.id, dataArray, field));
74 PetscFunctionReturn(PETSC_SUCCESS);
Definition: constFieldAccessor.hpp:12
ConstFieldAccessor(const ConstFieldAccessor &)=delete
const DataType * operator[](IndexType point) const
Inline function to compute the memory address at this point.
Definition: constFieldAccessor.hpp:55
const Field & GetField() const
provide easy access to the field information
Definition: constFieldAccessor.hpp:51
PetscErrorCode operator()(IndexType point, const DataType **field) const
Inline function to compute the memory address at this point using PETSC style return error.
Definition: constFieldAccessor.hpp:67
static utilities::PetscUtilities::ErrorChecker checkError
Definition: petscUtilities.hpp:46