Dune::Copasi 2.1.0-git79717215+dune.gitlab.629933
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages Concepts
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,
37 SpeciesBlocked>;
38
39template<class Model, std::size_t Order, bool SpeciesBlocked, bool CompartmentBlocked>
40using MultiCompartmentTraits = ModelMultiCompartmentPkTraits<
41 SingleCompartmentTraits<Model, Order, SpeciesBlocked>,
42 CompartmentBlocked>;
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 } else {
68 return std::index_sequence<1>{};
69 }
70 }();
71
72 auto config_fem_order = config.get("order", std::size_t{ 1 });
73
74 auto field_blocked = config.get("blocked_layout.scalar_fields", false);
75 auto compartments_blocked = config.get("blocked_layout.compartments", false);
76
77 std::set<std::string> compartments;
78 for (const auto& component : config.sub("scalar_field").getSubKeys()) {
79 compartments.insert(config[fmt::format("scalar_field.{}.compartment", component)]);
80 }
81
82 // default case when order is unknown
83 auto not_know_order = [config_fem_order]() {
84 throw format_exception(
85 IOError{}, "Polynomail degree '{}' not available for this simulation", config_fem_order);
86 };
87
88 std::unique_ptr<Model> model;
89
90 if (compartments.size() == 1) {
91 // unroll static switch case for dynamic order case
92 Dune::Hybrid::switchCases(
93 fem_orders,
94 config_fem_order,
95 [&](auto fem_order) {
96 if (field_blocked) {
97 model = std::make_unique<
99 functor_factory, cell_data);
100 } else {
101 model = std::make_unique<
103 functor_factory, cell_data);
104 }
105 },
106 not_know_order);
107 } else {
108 // unroll static switch case for dynamic order case
109 Dune::Hybrid::switchCases(
110 fem_orders,
111 config_fem_order,
112 [&](auto fem_order) {
113 if (compartments_blocked) {
114 if (field_blocked) {
115 model = std::make_unique<ModelMultiCompartment<
117 } else {
118 model = std::make_unique<ModelMultiCompartment<
120 }
121 } else {
122 if (field_blocked) {
123 model = std::make_unique<ModelMultiCompartment<
125 } else {
126 model = std::make_unique<ModelMultiCompartment<
128 }
129 }
130 },
131 not_know_order);
132 }
133
134 assert(model); // this should not be reachable if parameters are invalid
135 return model;
136}
137
138} // namespace Dune::Copasi
139
140#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
Definition: model_single_compartment_traits.hh:19
Definition: model_multi_compartment_traits.hh:20
GridView_ GridView
Definition: model.hh:32
TimeQuantity_ TimeQuantity
Definition: model.hh:33
Grid_ Grid
Definition: model.hh:31
RangeQuatinty_ RangeQuatinty
Definition: model.hh:34