1#ifndef DUNE_COPASI_MODEL_INTERPOLATE_HH
2#define DUNE_COPASI_MODEL_INTERPOLATE_HH
6#include <dune/pdelab/common/local_container.hh>
7#include <dune/pdelab/concepts/basis.hh>
9#include <dune/typetree/treecontainer.hh>
11#include <spdlog/spdlog.h>
15#include <unordered_map>
19template<PDELab::Concept::Basis Basis,
class Gr
idFunction>
20 requires Concept::LocalBasisTree<typename Basis::LocalView::Tree>
22interpolate(
const Basis& basis,
24 const std::unordered_map<std::string, GridFunction>& initial)
26 spdlog::info(
"Set initial state from grid functions");
28 if (basis.entitySet().size(0) == 0) {
32 auto lspace = basis.localView();
34 PDELab::LocalContainerBuffer lcontainer{ basis, &coefficients };
35 std::vector<double> buff;
38 lspace.bind(*basis.entitySet().template begin<0>());
39 using LocalFunction =
decltype(localFunction(std::declval<GridFunction>()));
40 auto lfuncs = TypeTree::makeTreeContainer(
41 lspace.tree(), [&](
const auto& lbasis_node) -> std::optional<LocalFunction> {
42 const auto& compartment_basis = basis.subSpace(pop_back(lbasis_node.orderingViewPath()));
43 const auto& component_basis = basis.subSpace(lbasis_node.orderingViewPath());
45 initial.find(fmt::format(
"{}.{}", compartment_basis.name(), component_basis.name()));
46 if (it != end(initial)) {
47 return localFunction(it->second);
54 for (
const auto& entity : elements(basis.entitySet())) {
57 lcontainer.clear(lspace);
60 forEachLeafNode(lspace.tree(), [&](
const auto& lbasis_node,
auto path) {
61 auto& lfunc = lfuncs[path];
62 if (lbasis_node.size() == 0 or not lfunc) {
65 lfunc->bind(lbasis_node.element());
66 const auto& fe = lbasis_node.finiteElement();
67 buff.assign(fe.size(), 0.);
68 fe.localInterpolation().interpolate(*lfunc, buff);
69 for (std::size_t dof = 0; dof != lbasis_node.size(); ++dof) {
70 lcontainer.accumulate(lbasis_node, dof, buff[dof]);
75 lcontainer.store(lspace);
Definition: axis_names.hh:7