16#include <dune/vtk/function.hh>
17#include <dune/vtk/vtkwriter.hh>
23 struct DefaultUserFunction
48template <
typename FE,
template <
typename,
int,
int>
class RT,
typename UserFunction = Impl::DefaultUserFunction>
55 using ctype =
typename GridView::ctype;
56 constexpr static int griddim = GridView::dimension;
57 using Entity =
typename GridView::template Codim<0>::Entity;
70 auto index = gridView_.indexSet().index(e);
71 return evaluateComponent(index, local, comp);
81 [[nodiscard]]
int ncomps()
const override {
82 if constexpr (std::is_same_v<UserFunction, Impl::DefaultUserFunction>) {
84 auto sigma = fes_->at(0).template calculateAt<RT>(feRequirements_, val).asVec();
85 return static_cast<int>(sigma.size());
87 return userFunction_.ncomps();
97 [[nodiscard]]
constexpr std::string
name()
const override {
98 if constexpr (
requires { userFunction_.name(); })
99 return userFunction_.name();
101 return toString<RT>();
113 : gridView_{fes->at(0).localView().globalBasis().gridView()},
114 feRequirements_{req},
116 userFunction_{UserFunction{}} {}
120 auto result = fes_->at(eleID).template calculateAt<RT>(feRequirements_, local).asVec();
122 if constexpr (!std::is_same_v<UserFunction, Impl::DefaultUserFunction>)
123 return userFunction_(result, comp);
130 std::vector<FiniteElement>* fes_;
131 [[no_unique_address]] std::string name_{};
132 UserFunction userFunction_;
147template <
template <
typename,
int,
int>
class RT,
typename UserFunction = Impl::DefaultUserFunction,
typename FE>
149 return std::make_shared<ResultFunction<FE, RT, UserFunction>>(fes, req);
168template <
template <
typename,
int,
int>
class RT,
typename UserFunction = Impl::DefaultUserFunction,
typename FE>
Definition of the LinearElastic class for finite element mechanics computations.
Definition: simpleassemblers.hh:22
auto makeResultVtkFunction(std::vector< FE > *fes, const typename FE::FERequirementType &req)
Function to create a ResultFunction as a gridfunction that can be used with dune-vtk.
Definition: resultfunction.hh:169
auto makeResultFunction(std::vector< FE > *fes, const typename FE::FERequirementType &req)
Function to create a ResultFunction as a shared_ptr.
Definition: resultfunction.hh:148
FE class is a base class for all finite elements.
Definition: febase.hh:81
typename Traits::GridView GridView
Type of the global view.
Definition: febase.hh:92
typename Traits::FERequirementType FERequirementType
Definition: febase.hh:95
Wrapper to evaluate results for a vtkwriter.
Definition: resultfunction.hh:50
typename FiniteElement::FERequirementType FERequirementType
Definition: resultfunction.hh:53
constexpr std::string name() const override
Get the name of the result type.
Definition: resultfunction.hh:97
int ncomps() const override
Get the number of components.
Definition: resultfunction.hh:81
typename GridView::ctype ctype
Definition: resultfunction.hh:55
static constexpr int griddim
Definition: resultfunction.hh:56
typename FiniteElement::GridView GridView
Definition: resultfunction.hh:54
ResultFunction(std::vector< FiniteElement > *fes, const FERequirementType &req)
Constructor for ResultFunction.
Definition: resultfunction.hh:112
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:69
typename GridView::template Codim< 0 >::Entity Entity
Definition: resultfunction.hh:57
Definition: utils/dirichletvalues.hh:30