12#ifndef DUMUX_DISCRETIZATION_CVFE_INTERPOLATE_HH
13#define DUMUX_DISCRETIZATION_CVFE_INTERPOLATE_HH
20#include <dune/grid/common/rangegenerators.hh>
24#include <dumux/common/concepts/ipdata_.hh>
53template<
class ElementDiscretization,
class Function,
class ValueType>
55 const ElementDiscretization& eDisc,
56 const std::ranges::range_value_t<
decltype(
localDofs(eDisc))>& ld,
61 v = f(eDisc, ipData(eDisc, ld));
64template<
class ElementDiscretization,
class Function,
class ValueType>
66 typename ElementDiscretization::Element::Geometry::GlobalCoordinate globalPos,
71template<
class ElementDiscretization,
class Function,
class ValueType>
73 ElementDiscretization& eDisc,
74 typename ElementDiscretization::Element::Geometry::GlobalCoordinate globalPos,
77{ v = f(eDisc, globalPos); };
86template<
class Gr
idDiscretization,
class Function>
89 using ElementDiscretization =
typename GridDiscretization::LocalView;
90 using Element =
typename ElementDiscretization::Element;
91 using LocalCoord =
typename Element::Geometry::LocalCoordinate;
92 using GlobalPos =
typename Element::Geometry::GlobalCoordinate;
96 : function_(std::move(f))
100 void bind(
const Element& element)
102 element_.emplace(element);
103 elemDisc_.bind(element);
108 const GlobalPos globalPos = elemDisc_.elementGeometry().global(localCoord);
109 if constexpr (
requires(ElementDiscretization& elemDisc , GlobalPos g, std::decay_t<Function>& f){ f(elemDisc, g); })
110 return function_(elemDisc_, globalPos);
112 return function_(globalPos);
117 ElementDiscretization elemDisc_;
118 std::optional<Element> element_;
121template<
class Gr
idDiscretization,
class Function>
125 gridDisc, std::forward<Function>(f));
136template<
class Gr
idDiscretization,
class CoefficientVector,
class Function>
138 CoefficientVector& coeffs,
141requires (Detail::InterpolatableAtElemDiscIpData<typename GridDiscretization::LocalView, Function, typename CoefficientVector::value_type>
142 || Detail::InterpolatableAtElemDiscGlobalPos<typename GridDiscretization::LocalView, Function, typename CoefficientVector::value_type>
143 || Detail::InterpolatableAtGlobalPos<typename GridDiscretization::LocalView, Function, typename CoefficientVector::value_type>)
145 using LocalView =
typename GridDiscretization::LocalView;
146 using ValueType =
typename CoefficientVector::value_type;
148 for (
const auto& element : elements(gridDisc.gridView()))
150 elemDisc.bind(element);
151 for (
const auto& localDof :
localDofs(elemDisc))
153 if constexpr (Detail::InterpolatableAtElemDiscIpData<LocalView, Function, ValueType>)
154 coeffs[localDof.dofIndex()] = function(elemDisc, ipData(elemDisc, localDof));
155 else if constexpr (Detail::InterpolatableAtElemDiscGlobalPos<LocalView, Function, ValueType>)
156 coeffs[localDof.dofIndex()] = function(elemDisc, ipData(elemDisc, localDof).global());
158 coeffs[localDof.dofIndex()] = function(ipData(elemDisc, localDof).global());
170template<
class Gr
idDiscretization,
class CoefficientVector,
class Function>
172 CoefficientVector& coeffs,
179 const Basis basis(gridDisc);
182 typename L2Proj::Params params;
183 params.maxIterations = policy.maxIterations;
184 params.residualReduction = policy.residualReduction;
185 params.verbosity = policy.verbosity;
189 const auto result =
projection.project(localFunction, params);
190 assert(coeffs.size() == result.size());
191 using ResultValue =
typename decltype(result)::value_type;
192 constexpr int numEq = ResultValue::dimension;
193 for (std::size_t i = 0; i < result.size(); ++i)
194 if constexpr (numEq == 1)
195 coeffs[i] = result[i][0];
197 coeffs[i] = result[i];
Wraps a function callable as f(globalPos) or f(elemDisc, globalPos) into a local-function interface: ...
Definition: interpolate.hh:88
LocalFunctionAdapter(const GridDiscretization &gridDisc, Function f)
Definition: interpolate.hh:95
void bind(const Element &element)
Definition: interpolate.hh:100
auto operator()(const LocalCoord &localCoord)
Definition: interpolate.hh:106
Wraps a CVFE grid discretization to expose the FE basis interface expected by L2Projection.
Definition: l2_projection.hh:81
Definition: l2_projection.hh:136
Definition: interpolate.hh:72
Definition: interpolate.hh:54
Definition: interpolate.hh:65
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:26
void interpolate(const GridDiscretization &gridDisc, CoefficientVector &coeffs, Function &&function, InterpolationPolicy::DofPositionEvaluation={})
Interpolate a function into a coefficient vector by evaluating it at the dof positions.
Definition: interpolate.hh:137
L2-projections of analytic functions into a given function space.
Class representing dofs on elements for control-volume finite element schemes.
Free function to get the local view of a grid cache object.
Dumux::CVFE::LocalDofInterpolationPointData< typename GridView::template Codim< 0 >::Entity::Geometry::LocalCoordinate, typename GridView::template Codim< 0 >::Entity::Geometry::GlobalCoordinate, typename IndexTraits< GridView >::LocalIndex > LocalDofIpData
Default LocalDofInterpolationPointData type.
Definition: quadraturerules.hh:146
auto makeLocalFunctionAdapter(const GridDiscretization &gridDisc, Function &&f)
Definition: interpolate.hh:122
Definition: interpolate.hh:27
Definition: interpolate.hh:27
constexpr Projection projection
Definition: couplingmanager1d3d_projection.hh:263
auto localDofs(const FVElementGeometry &fvGeometry)
range over local dofs
Definition: localdof.hh:50
Interpolation policy that evaluates a function at the dof positions.
Definition: interpolate.hh:33
Interpolation policy that uses an L2 projection.
Definition: interpolate.hh:40
int verbosity
Definition: interpolate.hh:43
double residualReduction
Definition: interpolate.hh:42
std::size_t maxIterations
Definition: interpolate.hh:41
Helper class to create (named and comparable) tagged types Tags any given type. The tagged type is eq...
Definition: tag.hh:30
Helper class to create (named and comparable) tagged types.