24#ifndef DUMUX_DISCRETIZATION_EVAL_SOLUTION_HH
25#define DUMUX_DISCRETIZATION_EVAL_SOLUTION_HH
32#include <dune/localfunctions/lagrange/pqkfactory.hh>
45template<
class ElementSolution>
49 auto firstState = elemSol[0].state();
50 for (std::size_t i = 1; i < elemSol.size(); ++i)
51 if (elemSol[i].state() != firstState)
58template<
class ElementSolution>
65template<
class Geometry,
class ElementSolution>
66auto minDistVertexSol(
const Geometry& geometry,
const typename Geometry::GlobalCoordinate& globalPos,
67 const ElementSolution& elemSol)
70 std::vector<typename Geometry::ctype> distances(geometry.corners());
71 for (
int i = 0; i < geometry.corners(); ++i)
72 distances[i] = (geometry.corner(i) - globalPos).two_norm2();
75 auto minDistanceIt = std::min_element(distances.begin(), distances.end());
76 return elemSol[
std::distance(distances.begin(), minDistanceIt)];
94template<
class Element,
class FVElementGeometry,
class PrimaryVariables>
96 const typename Element::Geometry& geometry,
97 const typename FVElementGeometry::GridGeometry& gridGeometry,
99 const typename Element::Geometry::GlobalCoordinate& globalPos,
100 bool ignoreState =
false)
108 using Scalar =
typename PrimaryVariables::value_type;
111 const auto& localBasis = gridGeometry.feCache().get(geometry.type()).localBasis();
114 const auto localPos = geometry.local(globalPos);
115 std::vector< Dune::FieldVector<Scalar, 1> > shapeValues;
116 localBasis.evaluateFunction(localPos, shapeValues);
118 PrimaryVariables result(0.0);
119 for (
int i = 0; i < geometry.corners(); ++i)
121 auto value = elemSol[i];
122 value *= shapeValues[i][0];
127 if constexpr (HasState{})
129 result.setState(elemSol[0].state());
135 static bool warnedAboutUsingMinDist =
false;
136 if (!warnedAboutUsingMinDist)
138 std::cout <<
"Warning: Using nearest-neighbor interpolation in evalSolution"
139 <<
"\nbecause not all states are equal and ignoreState is false!"
141 warnedAboutUsingMinDist =
true;
162template<
class Element,
class FVElementGeometry,
class PrimaryVariables>
164 const typename Element::Geometry& geometry,
166 const typename Element::Geometry::GlobalCoordinate& globalPos,
167 bool ignoreState =
false)
175 using Scalar =
typename PrimaryVariables::value_type;
176 using CoordScalar =
typename Element::Geometry::GlobalCoordinate::value_type;
177 static constexpr int dim = Element::Geometry::mydimension;
180 using FEFactory = Dune::PQkLocalFiniteElementFactory<CoordScalar, Scalar, dim, 1>;
181 using FiniteElement =
typename FEFactory::FiniteElementType;
182 std::unique_ptr<FiniteElement> fe(FEFactory::create(geometry.type()));
183 const auto& localBasis = fe->localBasis();
186 const auto localPos = geometry.local(globalPos);
187 using ShapeValue =
typename FiniteElement::Traits::LocalBasisType::Traits::RangeType;
188 std::vector< ShapeValue > shapeValues;
189 localBasis.evaluateFunction(localPos, shapeValues);
191 PrimaryVariables result(0.0);
192 for (
int i = 0; i < geometry.corners(); ++i)
194 auto value = elemSol[i];
195 value *= shapeValues[i][0];
200 if constexpr (HasState{})
202 result.setState(elemSol[0].state());
208 static bool warnedAboutUsingMinDist =
false;
209 if (!warnedAboutUsingMinDist)
211 std::cout <<
"Warning: Using nearest-neighbor interpolation in evalSolution"
212 <<
"\nbecause not all states are equal and ignoreState is false!"
214 warnedAboutUsingMinDist =
true;
233template<
class Element,
class FVElementGeometry,
class PrimaryVariables>
235 const typename Element::Geometry& geometry,
236 const typename FVElementGeometry::GridGeometry& gridGeometry,
238 const typename Element::Geometry::GlobalCoordinate& globalPos,
239 bool ignoreState =
false)
257template<
class Element,
class FVElementGeometry,
class PrimaryVariables>
259 const typename Element::Geometry& geometry,
261 const typename Element::Geometry::GlobalCoordinate& globalPos,
262 bool ignoreState =
false)
Type traits to be used with matrix types.
A helper function for class member function introspection.
static ctype distance(const Dune::FieldVector< ctype, dimWorld > &a, const Dune::FieldVector< ctype, dimWorld > &b)
Compute the shortest distance between two points.
Definition: distance.hh:292
PrimaryVariables evalSolution(const Element &element, const typename Element::Geometry &geometry, const typename FVElementGeometry::GridGeometry &gridGeometry, const BoxElementSolution< FVElementGeometry, PrimaryVariables > &elemSol, const typename Element::Geometry::GlobalCoordinate &globalPos, bool ignoreState=false)
Interpolates a given box element solution at a given global position. Uses the finite element cache o...
Definition: evalsolution.hh:95
constexpr auto isValid(const Expression &t)
A function that creates a test functor to do class member introspection at compile time.
Definition: isvalid.hh:93
auto minDistVertexSol(const Geometry &geometry, const typename Geometry::GlobalCoordinate &globalPos, const ElementSolution &elemSol)
return the solution at the closest dof
Definition: evalsolution.hh:66
bool allStatesEqual(const ElementSolution &elemSol, std::true_type hasState)
returns true if all states in an element solution are the same
Definition: evalsolution.hh:46
bool allStatesEqual(const ElementSolution &elemSol, std::false_type hasState)
overload if the solution is stateless
Definition: evalsolution.hh:59
helper struct detecting if a PrimaryVariables object has a state() function
Definition: state.hh:32
The element solution vector.
Definition: box/elementsolution.hh:39
The element solution vector.
Definition: cellcentered/elementsolution.hh:40
The local element solution class for the box method.
The local element solution class for cell-centered methods.