ABLATE Source Documentation  0.12.34
region.hpp
1 #ifndef ABLATELIBRARY_REGION_HPP
2 #define ABLATELIBRARY_REGION_HPP
3 
4 #include <petsc.h>
5 #include <memory>
6 #include <string>
7 #include <utilities/petscUtilities.hpp>
8 #include <vector>
9 namespace ablate::domain {
10 
11 class Region {
12  public:
13  inline const static std::shared_ptr<Region> ENTIREDOMAIN = {};
14 
15  private:
16  const std::string name;
17  const PetscInt value;
18  std::size_t id;
19 
20  public:
26  explicit Region(const std::string& name = {}, int value = 1);
27 
28  [[nodiscard]] inline const std::size_t& GetId() const { return id; }
29 
30  [[nodiscard]] inline const std::string& GetName() const { return name; }
31 
32  [[nodiscard]] inline const PetscInt& GetValue() const { return value; }
33 
34  [[nodiscard]] inline std::string ToString() const { return name + ":" + std::to_string(value); };
35 
43  void CreateLabel(DM dm, DMLabel& regionLabel, PetscInt& regionValue) const;
44 
52  static void GetLabel(const std::shared_ptr<Region>& region, DM dm, DMLabel& regionLabel, PetscInt& regionValue);
53 
60  void GetLabel(DM dm, DMLabel& regionLabel, PetscInt& regionValue);
61 
69  static bool InRegion(const std::shared_ptr<Region>& region, DM dm, PetscInt point);
70 
77  inline bool InRegion(DM dm, PetscInt point) const {
78  PetscInt ptValue;
79  DMGetLabelValue(dm, name.c_str(), point, &ptValue) >> utilities::PetscUtilities::checkError;
80  return ptValue == value;
81  }
82 
88  void CheckForLabel(DM dm) const;
89 
95  void CheckForLabel(DM dm, MPI_Comm comm) const;
96 
101  inline bool operator==(const Region& otherRegion) const { return id == otherRegion.id; }
102 
108  inline bool operator<(const Region& otherRegion) const { return id < otherRegion.id; }
109 };
110 
111 std::ostream& operator<<(std::ostream& os, const Region& region);
112 
113 std::ostream& operator<<(std::ostream& os, const std::shared_ptr<Region>& region);
114 
115 } // namespace ablate::domain
116 #endif // ABLATELIBRARY_REGION_HPP
Definition: region.hpp:11
bool operator<(const Region &otherRegion) const
Definition: region.hpp:108
static void GetLabel(const std::shared_ptr< Region > &region, DM dm, DMLabel &regionLabel, PetscInt &regionValue)
Definition: region.cpp:18
bool InRegion(DM dm, PetscInt point) const
Definition: region.hpp:77
void CreateLabel(DM dm, DMLabel &regionLabel, PetscInt &regionValue) const
Definition: region.cpp:12
void CheckForLabel(DM dm) const
Definition: region.cpp:32
Region(const std::string &name={}, int value=1)
Definition: region.cpp:6
static bool InRegion(const std::shared_ptr< Region > &region, DM dm, PetscInt point)
Definition: region.cpp:55
bool operator==(const Region &otherRegion) const
Definition: region.hpp:101
static utilities::PetscUtilities::ErrorChecker checkError
Definition: petscUtilities.hpp:46