-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added protype accessors to the domain * adding missing header * version bump * added missing header to cmake
- Loading branch information
Showing
12 changed files
with
550 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#ifndef ABLATELIBRARY_ACCESSOR_HPP | ||
#define ABLATELIBRARY_ACCESSOR_HPP | ||
|
||
#include <petsc.h> | ||
#include "field.hpp" | ||
|
||
namespace ablate::domain { | ||
/** | ||
* Class responsible for computing point data locations for dm plex integration | ||
*/ | ||
template <class DataType, bool isLocal = true> | ||
class Accessor { | ||
private: | ||
/** | ||
* The petsc vector used to hold the data | ||
*/ | ||
Vec dataVector; | ||
|
||
/** | ||
* The extracted data from the vector | ||
*/ | ||
PetscScalar* dataArray; | ||
|
||
/** | ||
* Store the DM for the vector to find memory locations | ||
*/ | ||
DM dataDM; | ||
|
||
public: | ||
Accessor(Vec dataVectorIn, DM dm = nullptr) : dataVector(dataVectorIn), dataDM(dm) { | ||
// Get read/write access to the vector | ||
VecGetArray(dataVector, &dataArray) >> ablate::utilities::PetscUtilities::checkError; | ||
|
||
// Get the dm from the vector if not specified | ||
if (!dataDM) { | ||
VecGetDM(dataVector, &dataDM) >> ablate::utilities::PetscUtilities::checkError; | ||
} | ||
} | ||
|
||
~Accessor() { | ||
// Put back the vector | ||
VecRestoreArray(dataVector, &dataArray) >> ablate::utilities::PetscUtilities::checkError; | ||
}; | ||
|
||
//! Inline function to compute the memory address at this point | ||
template <class IndexType> | ||
inline DataType* operator[](IndexType point) { | ||
DataType* field; | ||
if constexpr (isLocal) { | ||
DMPlexPointLocalRef(dataDM, point, dataArray, &field) >> ablate::utilities::PetscUtilities::checkError; | ||
} else { | ||
DMPlexPointGlobalRef(dataDM, point, dataArray, &field) >> ablate::utilities::PetscUtilities::checkError; | ||
} | ||
return field; | ||
} | ||
|
||
//! Inline function to compute the memory address at this point using PETSC style return error | ||
template <class IndexType> | ||
inline PetscErrorCode operator()(IndexType point, DataType** field) { | ||
PetscFunctionBeginHot; | ||
if constexpr (isLocal) { | ||
PetscCall(DMPlexPointLocalRef(dataDM, point, dataArray, field)); | ||
} else { | ||
PetscCall(DMPlexPointGlobalRef(dataDM, point, dataArray, field)); | ||
} | ||
PetscFunctionReturn(PETSC_SUCCESS); | ||
} | ||
|
||
/** | ||
* prevent copy of this class | ||
*/ | ||
Accessor(const Accessor&) = delete; | ||
}; | ||
} // namespace ablate::domain | ||
#endif // ABLATELIBRARY_FIELDACCESSOR_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#ifndef ABLATELIBRARY_CONSTACCESSOR_HPP | ||
#define ABLATELIBRARY_CONSTACCESSOR_HPP | ||
|
||
#include <petsc.h> | ||
#include "field.hpp" | ||
|
||
namespace ablate::domain { | ||
/** | ||
* Class responsible for computing point data locations for dm plex integration | ||
*/ | ||
template <class DataType, bool isLocal = true> | ||
class ConstAccessor { | ||
private: | ||
/** | ||
* The petsc vector used to hold the data | ||
*/ | ||
Vec dataVector; | ||
|
||
/** | ||
* The extracted data from the vector | ||
*/ | ||
const PetscScalar* dataArray; | ||
|
||
/** | ||
* Store the DM for the vector to find memory locations | ||
*/ | ||
DM dataDM; | ||
|
||
public: | ||
explicit ConstAccessor(Vec dataVectorIn, DM dm = nullptr) : dataVector(dataVectorIn), dataDM(dm) { | ||
// Get read/write access to the vector | ||
VecGetArrayRead(dataVector, &dataArray) >> ablate::utilities::PetscUtilities::checkError; | ||
|
||
// Get the dm from the vector if not specified | ||
if (!dataDM) { | ||
VecGetDM(dataVector, &dataDM) >> ablate::utilities::PetscUtilities::checkError; | ||
} | ||
} | ||
|
||
~ConstAccessor() { | ||
// Put back the vector | ||
VecRestoreArrayRead(dataVector, &dataArray) >> ablate::utilities::PetscUtilities::checkError; | ||
}; | ||
|
||
//! Inline function to compute the memory address at this point | ||
template <class IndexType> | ||
inline const DataType* operator[](IndexType point) const { | ||
const DataType* field; | ||
if constexpr (isLocal) { | ||
DMPlexPointLocalRead(dataDM, point, dataArray, &field) >> ablate::utilities::PetscUtilities::checkError; | ||
} else { | ||
DMPlexPointGlobalRead(dataDM, point, dataArray, &field) >> ablate::utilities::PetscUtilities::checkError; | ||
} | ||
return field; | ||
} | ||
|
||
//! Inline function to compute the memory address at this point using PETSC style return error | ||
template <class IndexType> | ||
inline PetscErrorCode operator()(IndexType point, const DataType** field) const { | ||
PetscFunctionBeginHot; | ||
if constexpr (isLocal) { | ||
PetscCall(DMPlexPointLocalRead(dataDM, point, dataArray, field)); | ||
} else { | ||
PetscCall(DMPlexPointGlobalRead(dataDM, point, dataArray, field)); | ||
} | ||
PetscFunctionReturn(PETSC_SUCCESS); | ||
} | ||
|
||
/** | ||
* prevent copy of this class | ||
*/ | ||
ConstAccessor(const ConstAccessor&) = delete; | ||
}; | ||
} // namespace ablate::domain | ||
#endif // ABLATELIBRARY_FIELDACCESSOR_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#ifndef ABLATELIBRARY_CONSTFIELDACCESSOR_HPP | ||
#define ABLATELIBRARY_CONSTFIELDACCESSOR_HPP | ||
|
||
#include <petsc.h> | ||
#include "field.hpp" | ||
|
||
namespace ablate::domain { | ||
/** | ||
* Class responsible for computing const point data locations for dm plex integration | ||
*/ | ||
template <class DataType, bool isLocal = true> | ||
class ConstFieldAccessor { | ||
private: | ||
/** | ||
* The petsc vector used to hold the data | ||
*/ | ||
Vec dataVector; | ||
|
||
/** | ||
* The field information needed to extract the data | ||
*/ | ||
const Field& dataField; | ||
|
||
/** | ||
* The extracted data from the vector | ||
*/ | ||
const PetscScalar* dataArray{}; | ||
|
||
/** | ||
* Store the DM for the vector to find memory locations | ||
*/ | ||
DM dataDM; | ||
|
||
public: | ||
ConstFieldAccessor(Vec dataVectorIn, const Field& dataFieldIn, DM dm = nullptr) : dataVector(dataVectorIn), dataField(dataFieldIn), dataDM(dm) { | ||
// Get read/write access to the vector | ||
VecGetArrayRead(dataVector, &dataArray) >> ablate::utilities::PetscUtilities::checkError; | ||
|
||
// Get the dm from the vector if not specified | ||
if (!dataDM) { | ||
VecGetDM(dataVector, &dataDM) >> ablate::utilities::PetscUtilities::checkError; | ||
} | ||
} | ||
|
||
~ConstFieldAccessor() { | ||
// Put back the vector | ||
VecRestoreArrayRead(dataVector, &dataArray) >> ablate::utilities::PetscUtilities::checkError; | ||
}; | ||
|
||
//! provide easy access to the field information | ||
[[nodiscard]] inline const Field& GetField() const { return dataField; } | ||
|
||
//! Inline function to compute the memory address at this point | ||
template <class IndexType> | ||
inline const DataType* operator[](IndexType point) const { | ||
const DataType* field; | ||
if constexpr (isLocal) { | ||
DMPlexPointLocalFieldRead(dataDM, point, dataField.id, dataArray, &field) >> ablate::utilities::PetscUtilities::checkError; | ||
} else { | ||
DMPlexPointGlobalFieldRead(dataDM, point, dataField.id, dataArray, &field) >> ablate::utilities::PetscUtilities::checkError; | ||
} | ||
return field; | ||
} | ||
|
||
//! Inline function to compute the memory address at this point using PETSC style return error | ||
template <class IndexType> | ||
inline PetscErrorCode operator()(IndexType point, const DataType** field) const { | ||
PetscFunctionBeginHot; | ||
if constexpr (isLocal) { | ||
PetscCall(DMPlexPointLocalFieldRead(dataDM, point, dataField.id, dataArray, field)); | ||
} else { | ||
PetscCall(DMPlexPointGlobalFieldRead(dataDM, point, dataField.id, dataArray, field)); | ||
} | ||
PetscFunctionReturn(PETSC_SUCCESS); | ||
} | ||
|
||
/** | ||
* prevent copy of this class | ||
*/ | ||
ConstFieldAccessor(const ConstFieldAccessor&) = delete; | ||
}; | ||
} // namespace ablate::domain | ||
#endif // ABLATELIBRARY_CONSTFIELDACCESSOR_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.