1#ifndef DUNE_COPASI_MODEL_DIFFUSION_REACTION_SINGLE_COMPARTMENT_IMPL_HH
2#define DUNE_COPASI_MODEL_DIFFUSION_REACTION_SINGLE_COMPARTMENT_IMPL_HH
17#include <dune/pdelab/basis/backend/istl.hh>
18#include <dune/pdelab/basis/basis.hh>
19#include <dune/pdelab/basis/discrete_global_function.hh>
20#include <dune/pdelab/common/partition/identity.hh>
21#include <dune/pdelab/common/trace.hh>
22#include <dune/pdelab/concepts/multiindex.hh>
24#include <dune/grid/io/file/vtk.hh>
26#include <spdlog/spdlog.h>
28#ifdef DUNE_COPASI_PRECOMPILED_MODE
29#warning "Including this file in pre-compiled mode may defeat the purpose of pre-compilation"
36ModelSingleCompartment<Traits>::get_entity_set(
const Grid& grid, std::size_t
subdomain)
37 -> CompartmentEntitySet
39 if constexpr (std::same_as<typename Grid::LeafGridView, CompartmentEntitySet>) {
40 return grid.leafGridView();
41 }
else if constexpr (Concept::SubDomainGrid<typename CompartmentEntitySet::Grid>) {
42 static_assert(std::same_as<typename Grid::SubDomainGrid::LeafGridView, CompartmentEntitySet>);
43 return grid.subDomain(
subdomain).leafGridView();
52 const std::unordered_map<std::string, GridFunction>&
initial)
const
60 Dune::Copasi::interpolate(basis, coefficients,
initial);
67 std::string_view name,
71 spdlog::info(
"Setup basis functions for component '{}'", name);
73 ScalarPreBasis{ ScalarMergingStrategy{
entity_set },
74 std::make_shared<ScalarFiniteElementMap>(
entity_set),
89 spdlog::info(
"Setup compartment basis functions for compartment '{}'",
compartment_name);
104 spdlog::info(
"No. of components on '{}' compartment: {}",
111template<
class Traits>
119 using CompartmentBasis = PDELab::Basis<PDELab::EntitySetPartitioner::Identity<CompartmentEntitySet>, CompartmentPreBasis>;
140template<
class Traits>
142ModelSingleCompartment<Traits>::setup_coefficient_vector(State&
state)
144 spdlog::info(
"Setup coefficient vector");
145 using CompartmentBasis = PDELab::Basis<PDELab::EntitySetPartitioner::Identity<CompartmentEntitySet>, CompartmentPreBasis>;
152template<
class Traits>
156 -> std::unique_ptr<State>
158 auto state_ptr = std::make_unique<State>();
166template<
class Traits>
169 std::string_view name)
const
187template<
class Traits>
190 -> std::unordered_map<std::string, GridFunction>
195template<
class Traits>
199 -> std::unique_ptr<PDELab::OneStep<State>>
206 using LocalBasisTraits =
typename ScalarFiniteElementMap::Traits::FiniteElement::Traits::LocalBasisType::Traits;
210 std::shared_ptr
one_step = DiffusionReaction::make_step_operator<LocalBasisTraits, Coefficients, Residual, ResidualQuantity, TimeQuantity>(
config, basis, 1, _functor_factory, _cell_data);
217 static_cast<PDELab::PropertyTree&
>(*one_step) =
218 static_cast<const PDELab::PropertyTree&
>(
self);
225 static_cast<PDELab::PropertyTree&
>(*type_erased_one_step) =
226 static_cast<const PDELab::PropertyTree&
>(*one_step);
234template<
class Traits>
237 -> std::map<std::string, double>
247 return Dune::Copasi::DiffusionReaction::reduce(PDELab::Execution::seq, basis,
coeff,
state.time,
config, _functor_factory);
250template<
class Traits>
253 const std::filesystem::path& path,
264 std::shared_ptr<const Coefficients>
const coeff_ptr = Dune::stackobject_to_shared_ptr(
coeff);
267 auto path_entry = std::filesystem::directory_entry{ path };
269 spdlog::info(
"Creating output directory '{}'",
path_entry.path().string());
270 std::error_code
ec{ 0, std::generic_category() };
271 std::filesystem::create_directories(
path_entry.path(),
ec);
274 "\n Category: {}\nValue: {}\nMessage: {}\n",
275 ec.category().name(),
282 auto&
timesteps = _writer_timesteps[path.string()];
283 std::string name = fmt::format(
"{}-{}", path.filename().string(), basis.name());
286 spdlog::info(
"Creating a time sequence file: '{}.pvd'", name);
288 spdlog::info(
"Overriding time sequence file: '{}.pvd'", name);
293 std::make_shared<VTKWriter<CompartmentEntitySet>>(basis.entitySet(), Dune::VTK::conforming);
300 basis.subSpace(TypeTree::treePath(std::size_t{
component }));
303 VTK::FieldInfo{
component_basis.name(), VTK::FieldInfo::Type::scalar, 1 });
306 spdlog::info(
"Writing solution for {:.2f}s time stamp",
state.time);
307 spdlog::info(
"Writing vtu file: '{0}/{0}-{1:0>5}.vtu'", name,
timesteps.size());
316 "Fake shared pointer from coefficient vector may have been leaked outside of this"
Mapper of boundary entities.
Definition boundary_entity_mapper.hh:26
Constraints parser and operator for a leaf basis.
Definition constraints.hh:29
Definition model_single_compartment.hh:26
std::unique_ptr< State > make_state(const std::shared_ptr< const Grid > &, const ParameterTree &) const override
Definition model_single_compartment.impl.hh:154
typename Traits::CompartmentEntitySet CompartmentEntitySet
Definition model_single_compartment.hh:37
typename Traits::CompartmentMergingStrategy CompartmentMergingStrategy
Definition model_single_compartment.hh:42
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
typename Traits::Grid Grid
Definition model_single_compartment.hh:34
typename Base::State State
Definition model_single_compartment.hh:33
GridFunction make_compartment_function(const std::shared_ptr< const State > &, std::string_view) const override
Definition model_single_compartment.impl.hh:168
std::map< std::string, double > reduce(const State &, const ParameterTree &) const override
Definition model_single_compartment.impl.hh:236
PDELab::PreBasisVector< CompartmentMergingStrategy, ScalarPreBasis > CompartmentPreBasis
Definition model_single_compartment.hh:43
typename Base::GridFunction GridFunction
Definition model_single_compartment.hh:46
void interpolate(State &, const std::unordered_map< std::string, GridFunction > &) const override
Definition model_single_compartment.impl.hh:50
void write_vtk(const State &, const std::filesystem::path &, bool=true) const override
Definition model_single_compartment.impl.hh:252
typename Traits::TimeQuantity TimeQuantity
Definition model_single_compartment.hh:35
std::unordered_map< std::string, GridFunction > make_initial(const Grid &, const ParameterTree &) const override
Definition model_single_compartment.impl.hh:189
std::unique_ptr< PDELab::OneStep< State > > make_step_operator(const State &, const ParameterTree &) const override
Definition model_single_compartment.impl.hh:197
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