15#include <dune/vtk/function.hh>
16#include <dune/vtk/vtkwriter.hh>
23 struct DefaultUserFunction
48template <
typename AS,
template <
typename,
int,
int>
class RT,
typename UserFunction = Impl::DefaultUserFunction>
49requires(Concepts::FlatAssembler<AS> and Concepts::ResultType<RT>)
57 using FiniteElement =
typename std::remove_cvref_t<FEContainer>::value_type;
59 using ctype =
typename GridView::ctype;
60 constexpr static int griddim = GridView::dimension;
61 using Entity =
typename GridView::template Codim<0>::Entity;
74 const auto index = gridView().indexSet().index(e);
75 return evaluateComponent(index, local, comp);
85 [[nodiscard]]
int ncomps()
const override {
86 if constexpr (std::is_same_v<UserFunction, Impl::DefaultUserFunction>) {
88 auto sigma = finiteElements().at(0).template calculateAt<RT>(requirement(), val).asVec();
89 return static_cast<int>(sigma.size());
91 return userFunction_.ncomps();
101 [[nodiscard]]
constexpr std::string
name()
const override {
102 if constexpr (
requires { userFunction_.name(); })
103 return userFunction_.name();
105 return toString<RT>();
116 Dune::VTK::Precision
precision()
const override {
return prec_; }
128 ResultFunction(std::shared_ptr<Assembler> assembler, Dune::VTK::Precision prec = Dune::VTK::Precision::float64)
129 : assembler_(assembler),
131 userFunction_{UserFunction{}} {}
135 auto result = finiteElements().at(eleID).template calculateAt<RT>(requirement(), local).asVec();
137 if constexpr (!std::is_same_v<UserFunction, Impl::DefaultUserFunction>)
138 return userFunction_(result, comp);
143 const FEContainer& finiteElements()
const {
return assembler_->finiteElements(); }
144 const FERequirementType& requirement()
const {
return assembler_->requirement(); }
145 const GridView& gridView()
const {
return assembler_->gridView(); }
147 std::shared_ptr<Assembler> assembler_;
149 Dune::VTK::Precision prec_;
150 [[no_unique_address]] std::string name_{};
151 UserFunction userFunction_;
166template <
template <
typename,
int,
int>
class RT,
typename UserFunction = Impl::DefaultUserFunction,
typename AS>
167auto makeResultFunction(std::shared_ptr<AS> assembler, Dune::VTK::Precision prec = Dune::VTK::Precision::float64) {
168 return std::make_shared<ResultFunction<AS, RT, UserFunction>>(assembler, prec);
186template <
template <
typename,
int,
int>
class RT,
typename UserFunction = Impl::DefaultUserFunction,
typename AS>
Definition of the LinearElastic class for finite element mechanics computations.
Definition: assemblermanipulatorbuildingblocks.hh:22
auto makeResultVtkFunction(std::shared_ptr< AS > assembler)
Function to create a ResultFunction as a gridfunction that can be used with dune-vtk.
Definition: resultfunction.hh:187
auto makeResultFunction(std::shared_ptr< AS > assembler, Dune::VTK::Precision prec=Dune::VTK::Precision::float64)
Function to create a ResultFunction as a shared_ptr.
Definition: resultfunction.hh:167
Wrapper to evaluate results for a vtkwriter.
Definition: resultfunction.hh:51
typename Assembler::FERequirement FERequirementType
Definition: resultfunction.hh:55
int ncomps() const override
Get the number of components.
Definition: resultfunction.hh:85
typename Assembler::FEContainer FEContainer
Definition: resultfunction.hh:56
typename GridView::template Codim< 0 >::Entity Entity
Definition: resultfunction.hh:61
typename std::remove_cvref_t< FEContainer >::value_type FiniteElement
Definition: resultfunction.hh:57
typename GridView::ctype ctype
Definition: resultfunction.hh:59
Dune::VTK::Precision precision() const override
Get the precision used for this result.
Definition: resultfunction.hh:116
constexpr std::string name() const override
Get the name of the result type.
Definition: resultfunction.hh:101
AS Assembler
Definition: resultfunction.hh:53
ResultFunction(std::shared_ptr< Assembler > assembler, Dune::VTK::Precision prec=Dune::VTK::Precision::float64)
Constructor for ResultFunction.
Definition: resultfunction.hh:128
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:73
typename Assembler::GridView GridView
Definition: resultfunction.hh:54
Definition: utils/dirichletvalues.hh:32