Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
TimeStepError.hpp
Go to the documentation of this file.
1 // Copyright (c) 2019 Maikel Nadolski
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 
21 #ifndef FUB_TIME_STEP_ERROR_HPP
22 #define FUB_TIME_STEP_ERROR_HPP
23 
24 #include "fub/Duration.hpp"
25 
26 #include <string>
27 #include <system_error>
28 
29 namespace fub {
30 enum class TimeStepErrc { success = 0, time_step_too_large = 1 };
31 }
32 
33 namespace std {
34 // Tell the C++ 11 STL metaprogramming that enum TimeStepErrc
35 // is registered with the standard error code system
36 template <> struct is_error_code_enum<::fub::TimeStepErrc> : true_type {};
37 } // namespace std
38 
39 namespace fub {
40 
41 // Define a custom error code category derived from std::error_category
42 class TimeStepErrcCategory : public std::error_category {
43 public:
44  // Return a short descriptive name for the category
45  virtual const char* name() const noexcept override final {
46  return "TimeStepError";
47  }
48 
49  // Return what each enum means in text
50  virtual std::string message(int c) const override final {
51  switch (static_cast<TimeStepErrc>(c)) {
53  return "time step successful";
55  return "time step size too large";
56  default:
57  return "unknown";
58  }
59  }
60 };
61 
63  static TimeStepErrcCategory c{};
64  return c;
65 }
66 
67 inline std::error_code make_error_code(TimeStepErrc error) {
68  return {static_cast<int>(error), TimeStepErrc_category()};
69 }
70 
73  int level;
74 };
75 
76 inline std::error_code make_error_code(const TimeStepTooLarge&) {
78 }
79 
80 } // namespace fub
81 
82 #endif
Definition: TimeStepError.hpp:42
virtual const char * name() const noexcept override final
Definition: TimeStepError.hpp:45
virtual std::string message(int c) const override final
Definition: TimeStepError.hpp:50
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
TimeStepErrc
Definition: TimeStepError.hpp:30
std::chrono::duration< double > Duration
Definition: Duration.hpp:31
const TimeStepErrcCategory & TimeStepErrc_category()
Definition: TimeStepError.hpp:62
std::error_code make_error_code(TimeStepErrc error)
Definition: TimeStepError.hpp:67
Definition: TimeStepError.hpp:71
Duration dt
Definition: TimeStepError.hpp:72
int level
Definition: TimeStepError.hpp:73