ABLATE Source Documentation  0.12.34
rhsAccessor.hpp
1 #ifndef ABLATELIBRARY_RHSACCESSOR_HPP
2 #define ABLATELIBRARY_RHSACCESSOR_HPP
3 
4 #include <petsc.h>
5 #include <map>
6 #include "accessor.hpp"
7 #include "particles/field.hpp"
8 #include "utilities/petscUtilities.hpp"
9 
10 namespace ablate::particles::accessors {
14 class RhsAccessor : public Accessor<PetscReal> {
15  private:
17  const std::map<std::string, Field>& fieldsMap;
18 
20  Vec rhsVec;
21 
23  PetscScalar* rhsValues{};
24 
25  public:
26  RhsAccessor(bool cachePointData, const std::map<std::string, Field>& fieldsMap, Vec rhsVec) : Accessor(cachePointData), fieldsMap(fieldsMap), rhsVec(rhsVec) {
27  // extract the array from the vector
28  VecGetArray(rhsVec, &rhsValues) >> utilities::PetscUtilities::checkError;
29  }
30 
34  ~RhsAccessor() override { VecRestoreArray(rhsVec, &rhsValues) >> utilities::PetscUtilities::checkError; }
35 
41  PointData CreateData(const std::string& fieldName) override {
42  try {
43  const auto& field = fieldsMap.at(fieldName);
44  if (field.location == domain::FieldLocation::SOL) {
45  return {rhsValues, field};
46  } else {
47  throw std::invalid_argument("The field " + std::string(fieldName) + " is not a solution variable");
48  }
49  } catch (std::exception& exception) {
50  throw std::invalid_argument("Unable to locate particle field " + fieldName);
51  }
52  }
53 
57  RhsAccessor(const RhsAccessor&) = delete;
58 };
59 } // namespace ablate::particles::accessors
60 #endif // ABLATELIBRARY_RHSACCESSOR_HPP
Definition: accessor.hpp:17
Definition: rhsAccessor.hpp:14
RhsAccessor(const RhsAccessor &)=delete
~RhsAccessor() override
Definition: rhsAccessor.hpp:34
PointData CreateData(const std::string &fieldName) override
Definition: rhsAccessor.hpp:41
static utilities::PetscUtilities::ErrorChecker checkError
Definition: petscUtilities.hpp:46
Definition: pointData.hpp:14