1#ifndef DUNE_COPASI_MODEL_DIFFUSION_REACTION_MULTI_COMPARTMENT_IMPL_HH
2#define DUNE_COPASI_MODEL_DIFFUSION_REACTION_MULTI_COMPARTMENT_IMPL_HH
12#include <dune/pdelab/basis/backend/istl.hh>
13#include <dune/pdelab/basis/basis.hh>
14#include <dune/pdelab/basis/discrete_global_function.hh>
15#include <dune/pdelab/common/trace.hh>
16#include <dune/pdelab/common/partition/identity.hh>
17#include <dune/pdelab/concepts/multiindex.hh>
19#include <dune/grid/io/file/vtk.hh>
21#include <spdlog/spdlog.h>
25#ifdef DUNE_COPASI_PRECOMPILED_MODE
26#warning "Including this file in pre-compiled mode may defeat the purpose of pre-compilation"
35 const std::unordered_map<std::string, GridFunction>&
initial)
const
38 PDELab::Basis<PDELab::EntitySetPartitioner::Identity<MultiCompartmentEntitySet>,
MultiCompartmentPreBasis, TypeTree::HybridTreePath<>>;
43 PDELab::Basis<PDELab::EntitySetPartitioner::Identity<MultiCompartmentEntitySet>,
MultiCompartmentPreBasis, TypeTree::HybridTreePath<>>;
50 Dune::Copasi::interpolate(basis, coefficients,
initial);
61 spdlog::info(
"Setup basis functions");
86 spdlog::info(
"Setup of multi-compartment grid function space");
97ModelMultiCompartment<Traits>::setup_coefficient_vector(State&
state)
100 PDELab::Basis<PDELab::EntitySetPartitioner::Identity<MultiCompartmentEntitySet>, MultiCompartmentPreBasis, TypeTree::HybridTreePath<>>;
104 spdlog::info(
"Setup coefficient vector");
109template<
class Traits>
113 -> std::unique_ptr<State>
115 auto state_ptr = std::make_unique<State>();
117 make_multi_compartment_pre_basis(*grid,
config, _functor_factory));
124template<
class Traits>
127 const std::shared_ptr<const State>&
state,
131 PDELab::Basis<PDELab::EntitySetPartitioner::Identity<MultiCompartmentEntitySet>,
MultiCompartmentPreBasis, TypeTree::HybridTreePath<>>;
153template<
class Traits>
157 -> std::unordered_map<std::string, GridFunction>
162template<
class Traits>
165 -> std::map<std::string, double>
168 PDELab::Basis<PDELab::EntitySetPartitioner::Identity<MultiCompartmentEntitySet>,
MultiCompartmentPreBasis, TypeTree::HybridTreePath<>>;
176 return Dune::Copasi::DiffusionReaction::reduce(PDELab::Execution::seq, basis,
coeff,
state.time,
config, _functor_factory);
179template<
class Traits>
186 PDELab::Basis<PDELab::EntitySetPartitioner::Identity<MultiCompartmentEntitySet>,
MultiCompartmentPreBasis, TypeTree::HybridTreePath<>>;
191 using LocalBasisTraits =
typename ScalarFiniteElementMap::Traits::FiniteElement::Traits::LocalBasisType::Traits;
194 std::shared_ptr
one_step = DiffusionReaction::make_step_operator<LocalBasisTraits, Coefficients, Residual, ResidualQuantity, TimeQuantity>(
config, basis, 2, _functor_factory, _cell_data);
201 static_cast<PDELab::PropertyTree&
>(*one_step) =
202 static_cast<const PDELab::PropertyTree&
>(
self);
209 static_cast<PDELab::PropertyTree&
>(*type_erased_one_step) =
210 static_cast<const PDELab::PropertyTree&
>(*one_step);
218template<
class Traits>
221 const std::filesystem::path& path,
225 PDELab::Basis<PDELab::EntitySetPartitioner::Identity<MultiCompartmentEntitySet>,
MultiCompartmentPreBasis, TypeTree::HybridTreePath<>>;
233 std::shared_ptr<const Coefficients>
coeff_ptr = Dune::stackobject_to_shared_ptr(
coeff);
236 auto path_entry = std::filesystem::directory_entry{ path };
238 spdlog::info(
"Creating output directory '{}'",
path_entry.path().string());
239 std::error_code
ec{ 0, std::generic_category() };
240 std::filesystem::create_directories(
path_entry.path(),
ec);
246 ec.category().name(),
251 spdlog::info(
"Writing solution for {:.2f}s time stamp",
state.time);
255 auto&
timesteps = _writer_timesteps[path.string()];
262 std::string name = fmt::format(
"{}-{}", path.filename().string(),
compartment_basis.name());
265 spdlog::info(
"Creating a time sequence file: '{}.pvd'", name);
267 spdlog::info(
"Overriding time sequence file: '{}.pvd'", name);
272 Dune::VTK::conforming);
282 VTK::FieldInfo{
species_basis.name(), VTK::FieldInfo::Type::scalar, 1 });
284 spdlog::info(
"Writing vtu file: '{0}/{0}-{1:0>5}.vtu'", name,
timesteps.size());
297 "Fake shared pointer from coefficient vector may have been leaked outsie of this function!");
Definition model_multi_compartment.hh:28
void write_vtk(const State &, const std::filesystem::path &, bool) const override
Definition model_multi_compartment.impl.hh:220
GridFunction make_compartment_function(const std::shared_ptr< const State > &, std::string_view) const override
Definition model_multi_compartment.impl.hh:126
typename Base::State State
Definition model_multi_compartment.hh:35
void interpolate(State &, const std::unordered_map< std::string, GridFunction > &) const override
Definition model_multi_compartment.impl.hh:33
PDELab::PreBasisVector< MultiCompartmentMergingStrategy, CompartmentPreBasis > MultiCompartmentPreBasis
Definition model_multi_compartment.hh:51
std::unordered_map< std::string, GridFunction > make_initial(const Grid &, const ParameterTree &) const override
Definition model_multi_compartment.impl.hh:155
typename Traits::Grid Grid
Definition model_multi_compartment.hh:36
typename Base::GridFunction GridFunction
Definition model_multi_compartment.hh:56
typename Traits::TimeQuantity TimeQuantity
Definition model_multi_compartment.hh:37
std::unique_ptr< State > make_state(const std::shared_ptr< const Grid > &, const ParameterTree &) const override
Definition model_multi_compartment.impl.hh:111
std::unique_ptr< PDELab::OneStep< State > > make_step_operator(const State &, const ParameterTree &) const override
Definition model_multi_compartment.impl.hh:181
std::map< std::string, double > reduce(const State &, const ParameterTree &) const override
Definition model_multi_compartment.impl.hh:164
static CompartmentPreBasis make_compartment_pre_basis(const CompartmentEntitySet &, std::string_view, const std::vector< std::string > &, const ParameterTree &={}, std::shared_ptr< const FunctorFactory< Grid::dimensionworld > >=nullptr)
Definition model_single_compartment.impl.hh:82
Definition functor_factory.hh:24
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
auto ostream2spdlog()
Standard output redirection to spdlog.
Definition ostream_to_spdlog.hh:20