15#include <dune/vtk/function.hh>
16#include <dune/vtk/vtkwriter.hh>
23 struct DefaultUserFunction
32 template <
typename R,
typename FiniteElement,
int dim>
34 const int comp)
const {
35 return resultArray[comp];
60template <
typename AS,
template <
typename,
int,
int>
class RT,
typename UserFunction = Impl::DefaultUserFunction>
61requires(Concepts::FlatAssembler<AS> and Concepts::ResultType<RT>)
69 using FiniteElement =
typename std::remove_cvref_t<FEContainer>::value_type;
71 using ctype =
typename GridView::ctype;
72 constexpr static int griddim = GridView::dimension;
73 using Entity =
typename GridView::template Codim<0>::Entity;
86 const auto index = gridView().indexSet().index(e);
87 return evaluateComponent(index, local, comp);
97 [[nodiscard]]
int ncomps()
const override {
98 if constexpr (std::is_same_v<UserFunction, Impl::DefaultUserFunction>) {
100 auto sigma = finiteElements().at(0).template calculateAt<RT>(requirement(), val).asVec();
101 return static_cast<int>(sigma.size());
103 return userFunction_.ncomps();
113 [[nodiscard]]
constexpr std::string
name()
const override {
114 if constexpr (
requires { userFunction_.name(); })
115 return userFunction_.name();
117 return toString<RT>();
128 Dune::VTK::Precision
precision()
const override {
return prec_; }
140 template <
typename UF = UserFunction>
141 ResultFunction(std::shared_ptr<Assembler> assembler, Dune::VTK::Precision prec = Dune::VTK::Precision::float64,
142 UF&& userFunction = {})
143 : assembler_(assembler),
145 userFunction_{std::forward<UF>(userFunction)} {}
149 const auto& fe = finiteElements().at(eleID);
150 auto result = fe.template calculateAt<RT>(requirement(), local).asVec();
152 return userFunction_(result, local, fe, comp);
155 const FEContainer& finiteElements()
const {
return assembler_->finiteElements(); }
156 const FERequirementType& requirement()
const {
return assembler_->requirement(); }
157 const GridView& gridView()
const {
return assembler_->gridView(); }
159 std::shared_ptr<Assembler> assembler_;
161 Dune::VTK::Precision prec_;
162 UserFunction userFunction_;
178template <
template <
typename,
int,
int>
class RT,
typename UserFunction = Impl::DefaultUserFunction,
179 Concepts::FlatAssembler AS>
180auto makeResultFunction(std::shared_ptr<AS> assembler, Dune::VTK::Precision prec = Dune::VTK::Precision::float64,
181 UserFunction&& userFunction = {}) {
182 return std::make_shared<ResultFunction<AS, RT, UserFunction>>(assembler, prec,
183 std::forward<UserFunction>(userFunction));
196template <
template <
typename,
int,
int>
class RT,
typename UserFunction, Concepts::FlatAssembler AS>
198 return makeResultFunction<RT>(assembler, Dune::VTK::Precision::float64, std::forward<UserFunction>(userFunction));
217template <
template <
typename,
int,
int>
class RT,
typename UserFunction = Impl::DefaultUserFunction,
218 Concepts::FlatAssembler AS>
220 return Dune::Vtk::Function<typename AS::GridView>(std::make_shared<ResultFunction<AS, RT, UserFunction>>(
221 assembler, Dune::VTK::Precision::float64, std::forward<UserFunction>(userFunction)));
Definition of the LinearElastic class for finite element mechanics computations.
Definition: assemblermanipulatorbuildingblocks.hh:22
auto makeResultFunction(std::shared_ptr< AS > assembler, Dune::VTK::Precision prec=Dune::VTK::Precision::float64, UserFunction &&userFunction={})
Function to create a ResultFunction as a shared_ptr.
Definition: resultfunction.hh:180
auto makeResultVtkFunction(std::shared_ptr< AS > assembler, UserFunction &&userFunction={})
Function to create a ResultFunction as a gridfunction that can be used with dune-vtk.
Definition: resultfunction.hh:219
Wrapper to evaluate results for a vtkwriter.
Definition: resultfunction.hh:63
typename Assembler::FERequirement FERequirementType
Definition: resultfunction.hh:67
int ncomps() const override
Get the number of components.
Definition: resultfunction.hh:97
typename Assembler::FEContainer FEContainer
Definition: resultfunction.hh:68
typename GridView::template Codim< 0 >::Entity Entity
Definition: resultfunction.hh:73
typename std::remove_cvref_t< FEContainer >::value_type FiniteElement
Definition: resultfunction.hh:69
typename GridView::ctype ctype
Definition: resultfunction.hh:71
Dune::VTK::Precision precision() const override
Get the precision used for this result.
Definition: resultfunction.hh:128
ResultFunction(std::shared_ptr< Assembler > assembler, Dune::VTK::Precision prec=Dune::VTK::Precision::float64, UF &&userFunction={})
Construct a new Result Function object.
Definition: resultfunction.hh:141
constexpr std::string name() const override
Get the name of the result type.
Definition: resultfunction.hh:113
AS Assembler
Definition: resultfunction.hh:65
double evaluate(int comp, const Entity &e, const Dune::FieldVector< ctype, griddim > &local) const override
Evaluate the component at a given entity and local coordinates.
Definition: resultfunction.hh:85
typename Assembler::GridView GridView
Definition: resultfunction.hh:66
Definition: utils/dirichletvalues.hh:32