15#include <dune/vtk/gridfunctions/vtkfunctionwrapper.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];
55template <
typename AS,
template <
typename,
int,
int>
class RT,
typename UserFunction = Impl::DefaultUserFunction>
56requires(Concepts::FlatAssembler<AS> and Concepts::ResultType<RT>)
64 using FiniteElement =
typename std::remove_cvref_t<FEContainer>::value_type;
66 using ctype =
typename GridView::ctype;
67 constexpr static int griddim = GridView::dimension;
68 using Entity =
typename GridView::template Codim<0>::Entity;
81 const auto index = gridView().indexSet().index(e);
82 return evaluateComponent(index, local, comp);
92 [[nodiscard]]
int ncomps()
const override {
93 if constexpr (std::is_same_v<UserFunction, Impl::DefaultUserFunction>) {
95 auto sigma = finiteElements().at(0).template calculateAt<RT>(requirement(), val).asVec();
96 return static_cast<int>(sigma.size());
98 return userFunction_.ncomps();
108 [[nodiscard]]
constexpr std::string
name()
const override {
109 if constexpr (
requires { userFunction_.name(); })
110 return userFunction_.name();
112 return toString<RT>();
123 Dune::VTK::Precision
precision()
const override {
return prec_; }
135 template <
typename UF = UserFunction>
136 ResultFunction(std::shared_ptr<Assembler> assembler, Dune::VTK::Precision prec = Dune::VTK::Precision::float64,
137 UF&& userFunction = {})
138 : assembler_(assembler),
140 userFunction_{std::forward<UF>(userFunction)} {}
144 const auto& fe = finiteElements().at(eleID);
145 auto result = fe.template calculateAt<RT>(requirement(), local).asVec();
147 return userFunction_(result, local, fe, comp);
150 const FEContainer& finiteElements()
const {
return assembler_->finiteElements(); }
151 const FERequirementType& requirement()
const {
return assembler_->requirement(); }
152 const GridView& gridView()
const {
return assembler_->gridView(); }
154 std::shared_ptr<Assembler> assembler_;
156 Dune::VTK::Precision prec_;
157 UserFunction userFunction_;
173template <
template <
typename,
int,
int>
class RT,
typename UserFunction = Impl::DefaultUserFunction,
174 Concepts::FlatAssembler AS>
175auto makeResultFunction(std::shared_ptr<AS> assembler, Dune::VTK::Precision prec = Dune::VTK::Precision::float64,
176 UserFunction&& userFunction = {}) {
177 return std::make_shared<ResultFunction<AS, RT, UserFunction>>(assembler, prec,
178 std::forward<UserFunction>(userFunction));
191template <
template <
typename,
int,
int>
class RT,
typename UserFunction, Concepts::FlatAssembler AS>
193 return makeResultFunction<RT>(assembler, Dune::VTK::Precision::float64, std::forward<UserFunction>(userFunction));
212template <
template <
typename,
int,
int>
class RT,
typename UserFunction = Impl::DefaultUserFunction,
213 Concepts::FlatAssembler AS>
215 return Dune::Vtk::VTKFunctionWrapper<typename AS::GridView>(std::make_shared<ResultFunction<AS, RT, UserFunction>>(
216 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:175
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:214
Wrapper to evaluate results for a vtkwriter. Works both out-of-the-box with Dune::VTK and Dune::Vtk.
Definition: resultfunction.hh:58
typename Assembler::FERequirement FERequirementType
Definition: resultfunction.hh:62
int ncomps() const override
Get the number of components.
Definition: resultfunction.hh:92
typename Assembler::FEContainer FEContainer
Definition: resultfunction.hh:63
typename GridView::template Codim< 0 >::Entity Entity
Definition: resultfunction.hh:68
typename std::remove_cvref_t< FEContainer >::value_type FiniteElement
Definition: resultfunction.hh:64
typename GridView::ctype ctype
Definition: resultfunction.hh:66
Dune::VTK::Precision precision() const override
Get the precision used for this result.
Definition: resultfunction.hh:123
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:136
constexpr std::string name() const override
Get the name of the result type.
Definition: resultfunction.hh:108
AS Assembler
Definition: resultfunction.hh:60
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:80
typename Assembler::GridView GridView
Definition: resultfunction.hh:61
Definition: utils/dirichletvalues.hh:34