ABLATE Source Documentation  0.12.34
petscUtilities.hpp
1 #ifndef ABLATELIBRARY_PETSCUTILITIES_HPP
2 #define ABLATELIBRARY_PETSCUTILITIES_HPP
3 #include <petsc.h>
4 #include <map>
5 #include <string>
6 namespace ablate::utilities {
7 
9  public:
13  class ErrorChecker {
14  public:
15  struct PetscError : public std::runtime_error {
16  private:
17  static std::string GetMessage(PetscErrorCode ierr) {
18  const char* text;
19  char* specific;
20 
21  PetscErrorMessage(ierr, &text, &specific);
22 
23  return std::string(text) + ": " + std::string(specific);
24  }
25 
26  public:
27  explicit PetscError(PetscErrorCode ierr) : std::runtime_error(GetMessage(ierr)) {}
28  };
29 
30  inline friend void operator>>(PetscErrorCode ierr, const ErrorChecker&) {
31  if (ierr != 0) {
32  throw PetscError(ierr);
33  }
34  }
35  };
36 
37  public:
41  static void Initialize(const char[] = nullptr);
42 
47 
54  static void Set(const std::string& prefix, const std::map<std::string, std::string>& options, bool override = true);
55 
61  static void Set(const std::map<std::string, std::string>& options);
62 
68  static void Set(PetscOptions petscOptions, const std::map<std::string, std::string>& options);
69 
77  static void Set(PetscOptions petscOptions, const char name[], const char value[], bool override = true);
78 
84  static void PetscOptionsDestroyAndCheck(const std::string& name, PetscOptions* options);
85 
86  // keep this class static
87  PetscUtilities() = delete;
88 };
89 
96 std::istream& operator>>(std::istream& is, PetscDataType& v);
97 
104 std::ostream& operator<<(std::ostream& os, const PetscDataType& dt);
105 
106 } // namespace ablate::utilities
107 #endif // ABLATELIBRARY_PETSCUTILITIES_HPP
Definition: petscUtilities.hpp:13
Definition: petscUtilities.hpp:8
static void PetscOptionsDestroyAndCheck(const std::string &name, PetscOptions *options)
Definition: petscUtilities.cpp:41
static void Set(const std::string &prefix, const std::map< std::string, std::string > &options, bool override=true)
Definition: petscUtilities.cpp:11
static void Initialize(const char[]=nullptr)
Definition: petscUtilities.cpp:4
static utilities::PetscUtilities::ErrorChecker checkError
Definition: petscUtilities.hpp:46
static void Set(PetscOptions petscOptions, const char name[], const char value[], bool override=true)