Dune::Copasi
Loading...
Searching...
No Matches
model.hh
Go to the documentation of this file.
1#ifndef DUNE_COPASI_MODEL_MODEL_HH
2#define DUNE_COPASI_MODEL_MODEL_HH
3
5
6#include <dune/pdelab/operator/operator.hh>
7
8#include <dune/functions/gridfunctions/gridviewfunction.hh>
9
10#include <dune/grid/concepts/grid.hh>
11#include <dune/grid/concepts/gridview.hh>
12
13#include <dune/common/parametertree.hh>
14
15#include <any>
16#include <filesystem>
17#include <map>
18#include <memory>
19#include <string>
20#include <unordered_map>
21
22namespace Dune::Copasi {
23
24template<Dune::Concept::Grid Grid_,
25 Dune::Concept::GridView GridView_ = typename Grid_::LeafGridView,
26 class RangeQuatinty_ = double,
27 class TimeQuantity_ = double>
28struct Model
29{
30
31 using Grid = Grid_;
35
36 struct State
37 {
38 std::shared_ptr<const Grid> grid;
40 std::any coefficients = nullptr;
41 std::any basis = nullptr;
42 };
43
44 using GridFunction = Dune::Functions::GridViewFunction<
45 RangeQuatinty(typename GridView::template Codim<0>::Geometry::GlobalCoordinate),
46 GridView>;
47
48 Model() = default;
49 Model(const Model&) = delete;
50 Model(Model&&) = delete;
51
52 Model& operator=(const Model&) = delete;
53 Model& operator=(Model&&) = delete;
54
55 virtual ~Model() = default;
56
57 [[nodiscard]] virtual std::unique_ptr<State> make_state(const std::shared_ptr<const Grid>&,
58 const ParameterTree&) const = 0;
59
60 virtual void interpolate(State&, const std::unordered_map<std::string, GridFunction>&) const = 0;
61
62 [[nodiscard]] virtual std::unordered_map<std::string, GridFunction> make_initial(
63 const Grid&,
64 const ParameterTree&) const = 0;
65
66 // copies the state into the grid function
68 std::string_view name) const
69 {
70 return make_compartment_function(std::make_shared<State>(state), name);
71 }
72
73 // shares the state with the grid function
74 [[nodiscard]] virtual GridFunction make_compartment_function(const std::shared_ptr<const State>&,
75 std::string_view) const = 0;
76
77 virtual std::nullptr_t make_membrane_function(const State&, std::string_view) const
78 {
79 throw format_exception(NotImplemented{}, "Model has no membrane functions");
80 }
81
82 virtual std::nullptr_t make_membrane_function(const std::shared_ptr<const State>&,
83 std::string_view) const
84 {
85 throw format_exception(NotImplemented{}, "Model has no membrane functions");
86 }
87
88 virtual void write_vtk(const State&, const std::filesystem::path&, bool) const
89 {
90 throw format_exception(NotImplemented{}, "Model write has not been implemented");
91 }
92
93 [[nodiscard]] virtual std::unique_ptr<PDELab::OneStep<State>> make_step_operator(
94 const State&,
95 const ParameterTree&) const = 0;
96
97 virtual std::map<std::string, double> reduce(const State&, const ParameterTree&) const
98 {
99 throw format_exception(NotImplemented{}, "Model reduce has not been implemented");
100 }
101};
102
103} // namespace Dune::Copasi
104
105#endif // DUNE_COPASI_MODEL_MODEL_HH
Definition axis_names.hh:7
auto format_exception(Exception &&e, fmt::format_string< Args... > format, Args &&... args)
Definition exceptions.hh:23
constexpr bool is_bitflags_v
Alias for Bitflag indicator.
Definition bit_flags.hh:24
Definition model.hh:37
std::any coefficients
Definition model.hh:40
TimeQuantity time
Definition model.hh:39
std::any basis
Definition model.hh:41
std::shared_ptr< const Grid > grid
Definition model.hh:38
Definition model.hh:29
virtual std::unique_ptr< PDELab::OneStep< State > > make_step_operator(const State &, const ParameterTree &) const =0
GridView_ GridView
Definition model.hh:32
Model(const Model &)=delete
virtual std::nullptr_t make_membrane_function(const State &, std::string_view) const
Definition model.hh:77
Model & operator=(const Model &)=delete
virtual GridFunction make_compartment_function(const std::shared_ptr< const State > &, std::string_view) const =0
Model(Model &&)=delete
TimeQuantity_ TimeQuantity
Definition model.hh:33
virtual std::nullptr_t make_membrane_function(const std::shared_ptr< const State > &, std::string_view) const
Definition model.hh:82
Grid_ Grid
Definition model.hh:31
Model & operator=(Model &&)=delete
Dune::Functions::GridViewFunction< RangeQuatinty(typename GridView::template Codim< 0 >::Geometry::GlobalCoordinate), GridView > GridFunction
Definition model.hh:44
virtual void interpolate(State &, const std::unordered_map< std::string, GridFunction > &) const =0
virtual std::map< std::string, double > reduce(const State &, const ParameterTree &) const
Definition model.hh:97
virtual std::unordered_map< std::string, GridFunction > make_initial(const Grid &, const ParameterTree &) const =0
virtual std::unique_ptr< State > make_state(const std::shared_ptr< const Grid > &, const ParameterTree &) const =0
virtual ~Model()=default
GridFunction make_compartment_function(const State &state, std::string_view name) const
Definition model.hh:67
virtual void write_vtk(const State &, const std::filesystem::path &, bool) const
Definition model.hh:88
RangeQuatinty_ RangeQuatinty
Definition model.hh:34