ABLATE Source Documentation  0.12.34
eulerianSourceAccessor.hpp
1 #ifndef ABLATELIBRARY_EULERIANSOURCEACCESSOR_HPP
2 #define ABLATELIBRARY_EULERIANSOURCEACCESSOR_HPP
3 
4 #include <petsc.h>
5 #include <map>
6 #include "accessor.hpp"
7 #include "domain/subDomain.hpp"
8 #include "particles/field.hpp"
9 #include "swarmAccessor.hpp"
10 #include "utilities/petscUtilities.hpp"
11 
12 namespace ablate::particles::accessors {
17 class EulerianSourceAccessor : public Accessor<PetscReal> {
18  public:
19  // A string to hold the coupled source terms name
20  inline static const char CoupledSourceTermPostfix[] = "_CoupledSourceTerm";
21 
22  private:
24  const DM& swarmDm;
25 
27  const std::map<std::string, Field>& fieldsMap;
28 
29  public:
30  EulerianSourceAccessor(bool cachePointData, const DM& swarmDm, const std::map<std::string, Field>& fieldsMap) : Accessor(cachePointData), swarmDm(swarmDm), fieldsMap(fieldsMap) {}
31 
37  PointData CreateData(const std::string& fieldName) override {
38  const auto& field = fieldsMap.at(fieldName + CoupledSourceTermPostfix);
39  if (field.location == domain::FieldLocation::SOL) {
40  throw std::invalid_argument("Eulerian Source Fields should not be SOL fields");
41  } else {
42  // get the field from the dm
43  PetscScalar* values;
44  DMSwarmGetField(swarmDm, field.name.c_str(), nullptr, nullptr, (void**)&values) >> utilities::PetscUtilities::checkError;
45 
46  // Register the cleanup
48  const std::string name = field.name;
49  DMSwarmRestoreField(swarmDm, name.c_str(), nullptr, nullptr, (void**)&values) >> utilities::PetscUtilities::checkError;
50  });
51 
52  return {values, field};
53  }
54  }
55 
60 };
61 } // namespace ablate::particles::accessors
62 #endif // ABLATELIBRARY_EULERIANSOURCEACCESSOR_HPP
Definition: accessor.hpp:17
void RegisterCleanupFunction(const std::function< void()> &function)
Definition: accessor.hpp:78
Definition: eulerianSourceAccessor.hpp:17
PointData CreateData(const std::string &fieldName) override
Definition: eulerianSourceAccessor.hpp:37
EulerianSourceAccessor(const EulerianSourceAccessor &)=delete
static utilities::PetscUtilities::ErrorChecker checkError
Definition: petscUtilities.hpp:46
Definition: pointData.hpp:14