Dune::Copasi
Loading...
Searching...
No Matches
factory.hh
Go to the documentation of this file.
1#ifndef DUNE_COPASI_MODEL_FACTORY_HH
2#define DUNE_COPASI_MODEL_FACTORY_HH
3
5
12
14
15// comma separated list of fem orders to compile for each dimension
16#ifndef DUNE_COPASI_1D_DIFFUSION_REACTION_FEM_ORDERS
17#define DUNE_COPASI_1D_DIFFUSION_REACTION_FEM_ORDERS 1
18#endif
19
20#ifndef DUNE_COPASI_2D_DIFFUSION_REACTION_FEM_ORDERS
21#define DUNE_COPASI_2D_DIFFUSION_REACTION_FEM_ORDERS 1
22#endif
23
24#ifndef DUNE_COPASI_3D_DIFFUSION_REACTION_FEM_ORDERS
25#define DUNE_COPASI_3D_DIFFUSION_REACTION_FEM_ORDERS 1
26#endif
27
29
30namespace Impl {
31template<class Model, std::size_t Order, bool SpeciesBlocked>
32using SingleCompartmentTraits = ModelSingleCompartmentPkTraits<typename Model::Grid,
33 typename Model::GridView,
34 Order,
35 typename Model::RangeQuatinty,
36 typename Model::TimeQuantity,
38
39template<class Model, std::size_t Order, bool SpeciesBlocked, bool CompartmentBlocked>
40using MultiCompartmentTraits = ModelMultiCompartmentPkTraits<
43}
44
45// multi-domaingrid case!
46template<class Model>
49std::unique_ptr<Model>
51 const ParameterTree& config,
52 std::shared_ptr<const FunctorFactory<Model::Grid::dimensionworld>> functor_factory = nullptr,
54)
55{
56 if (not functor_factory) {
57 functor_factory = std::make_shared<FunctorFactoryParser<Model::Grid::dimensionworld>>();
58 }
59
60 const auto fem_orders = []() {
61 if constexpr (Model::Grid::dimensionworld == 1) {
62 return std::index_sequence<DUNE_COPASI_1D_DIFFUSION_REACTION_FEM_ORDERS>{};
63 } else if constexpr (Model::Grid::dimensionworld == 2) {
64 return std::index_sequence<DUNE_COPASI_2D_DIFFUSION_REACTION_FEM_ORDERS>{};
65 } else if constexpr (Model::Grid::dimensionworld == 3) {
66 return std::index_sequence<DUNE_COPASI_3D_DIFFUSION_REACTION_FEM_ORDERS>{};
67 }
68 return std::index_sequence<1>{};
69 }();
70
71 auto config_fem_order = config.get("order", std::size_t{ 1 });
72
73 auto field_blocked = config.get("blocked_layout.scalar_fields", false);
74 auto compartments_blocked = config.get("blocked_layout.compartments", false);
75
76 std::set<std::string> compartments;
77 for (const auto& component : config.sub("scalar_field").getSubKeys()) {
78 compartments.insert(config[fmt::format("scalar_field.{}.compartment", component)]);
79 }
80
81 // default case when order is unknown
83 throw format_exception(
84 IOError{}, "Polynomail degree '{}' not available for this simulation", config_fem_order);
85 };
86
87 std::unique_ptr<Model> model;
88
89 if (compartments.size() == 1) {
90 // unroll static switch case for dynamic order case
91 Dune::Hybrid::switchCases(
94 [&](auto fem_order) {
95 if (field_blocked) {
96 model = std::make_unique<
99 } else {
100 model = std::make_unique<
103 }
104 },
106 } else {
107 // unroll static switch case for dynamic order case
108 Dune::Hybrid::switchCases(
111 [&](auto fem_order) {
113 if (field_blocked) {
114 model = std::make_unique<ModelMultiCompartment<
116 } else {
117 model = std::make_unique<ModelMultiCompartment<
119 }
120 } else {
121 if (field_blocked) {
122 model = std::make_unique<ModelMultiCompartment<
124 } else {
125 model = std::make_unique<ModelMultiCompartment<
127 }
128 }
129 },
131 }
132
133 assert(model); // this should not be reachable if parameters are invalid
134 return model;
135}
136
137} // namespace Dune::Copasi
138
139#endif // DUNE_COPASI_MODEL_FACTORY_HH
Container for cell data of a grid view.
Definition cell_data.hh:25
Definition model_multi_compartment.hh:28
Definition model_single_compartment.hh:26
Definition functor_factory.hh:24
Concept for dune multidomain grids.
Definition grid.hh:51
Concept for dune subdomain grids of multidomain grids.
Definition grid.hh:31
Definition factory.hh:28
std::unique_ptr< Model > make_model(const ParameterTree &config, std::shared_ptr< const FunctorFactory< Model::Grid::dimensionworld > > functor_factory=nullptr, std::shared_ptr< const CellData< typename Model::Grid::LeafGridView, typename Model::RangeQuatinty > > cell_data=nullptr)
Definition factory.hh:50
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_single_compartment_traits.hh:19
GridView_ GridView
Definition model.hh:32
TimeQuantity_ TimeQuantity
Definition model.hh:33
Grid_ Grid
Definition model.hh:31
RangeQuatinty_ RangeQuatinty
Definition model.hh:34
Definition model_multi_compartment_traits.hh:20