version 0.4.1
volume.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2024 The Ikarus Developers mueller@ibb.uni-stuttgart.de
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4#pragma once
5
6#include <dune/localfefunctions/derivativetransformators.hh>
7#include <dune/localfefunctions/meta.hh>
8
12
13namespace Ikarus {
14
15template <typename PreFE, typename FE>
16class VolumeLoad;
17
22template <int wd>
24{
25 static constexpr int worldDim = wd;
26 std::function<Eigen::Vector<double, worldDim>(const Dune::FieldVector<double, worldDim>&, const double&)> volumeLoad;
27
28 template <typename PreFE, typename FE>
30};
31
32// Deduction guide
33template <class F>
35
44template <typename PreFE, typename FE>
46{
47public:
51 static constexpr int worldDim = Traits::worlddim;
53
59 explicit VolumeLoad(const Pre& pre = {})
60 : volumeLoad_{pre.volumeLoad} {}
61
62protected:
63 template <template <typename, int, int> class RT>
64 requires Dune::AlwaysFalse<RT<double, 1, 1>>::value
66 Dune::PriorityTag<0>) const {}
67
68 template <typename ST>
70 const Requirement& par, ScalarAffordance affordance,
71 const std::optional<std::reference_wrapper<const Eigen::VectorX<ST>>>& dx = std::nullopt) const -> ST {
72 if (not volumeLoad_)
73 return 0.0;
74 ST energy = 0.0;
75 const auto uFunction = underlying().displacementFunction(par, dx);
76 const auto geo = underlying().geometry();
77 const auto& lambda = par.parameter();
78
79 for (const auto& [gpIndex, gp] : uFunction.viewOverIntegrationPoints()) {
80 const auto uVal = uFunction.evaluate(gpIndex);
81 Eigen::Vector<double, worldDim> fext = volumeLoad_(geo.global(gp.position()), lambda);
82 energy -= uVal.dot(fext) * geo.integrationElement(gp.position()) * gp.weight();
83 }
84 return energy;
85 }
86
87 template <typename ST>
89 const Requirement& par, VectorAffordance affordance, typename Traits::template VectorType<ST> force,
90 const std::optional<std::reference_wrapper<const Eigen::VectorX<ST>>>& dx = std::nullopt) const {
91 if (not volumeLoad_)
92 return;
93 using namespace Dune::DerivativeDirections;
94 using namespace Dune;
95 const auto uFunction = underlying().displacementFunction(par, dx);
96 const auto geo = underlying().geometry();
97 const auto& lambda = par.parameter();
98
99 for (const auto& [gpIndex, gp] : uFunction.viewOverIntegrationPoints()) {
100 const Eigen::Vector<double, worldDim> fext = volumeLoad_(geo.global(gp.position()), lambda);
101 const double intElement = geo.integrationElement(gp.position()) * gp.weight();
102 for (size_t i = 0; i < underlying().numberOfNodes(); ++i) {
103 const auto udCi = uFunction.evaluateDerivative(gpIndex, wrt(coeff(i)));
104 force.template segment<worldDim>(worldDim * i) -= udCi * fext * intElement;
105 }
106 }
107 }
108
109 template <typename ST>
111 const Requirement& par, MatrixAffordance, typename Traits::template MatrixType<> K,
112 const std::optional<std::reference_wrapper<const Eigen::VectorX<ST>>>& dx = std::nullopt) const {}
113
114private:
115 std::function<Eigen::Vector<double, worldDim>(const Dune::FieldVector<double, worldDim>&, const double&)> volumeLoad_;
116 //> CRTP
117 const auto& underlying() const { return static_cast<const FE&>(*this); }
118 auto& underlying() { return static_cast<FE&>(*this); }
119};
120
127template <int worldDim>
128auto volumeLoad(const std::function<Eigen::Vector<double, worldDim>(const Dune::FieldVector<double, worldDim>&,
129 const double&)>& f) {
130 VolumeLoadPre pre(f);
131 return pre;
132}
133
139template <typename F>
140auto volumeLoad(F&& f) {
141 VolumeLoadPre pre(f);
142 return pre;
143}
144
145} // namespace Ikarus
Contains stl-like type traits.
Several concepts.
Definition of the LinearElastic class for finite element mechanics computations.
Definition: assemblermanipulatorbuildingblocks.hh:22
auto volumeLoad(const std::function< Eigen::Vector< double, worldDim >(const Dune::FieldVector< double, worldDim > &, const double &)> &f)
A helper function to create a volume load skill.
Definition: volume.hh:128
MatrixAffordance
A strongly typed enum class representing the matrix affordance.
Definition: ferequirements.hh:63
VolumeLoadPre(F f) -> VolumeLoadPre< traits::FunctionTraits< F >::return_type::RowsAtCompileTime >
VectorAffordance
A strongly typed enum class representing the vector affordance.
Definition: ferequirements.hh:48
ScalarAffordance
A strongly typed enum class representing the scalar affordance.
Definition: ferequirements.hh:37
Definition: utils/dirichletvalues.hh:30
FE class is a base class for all finite elements.
Definition: febase.hh:79
FETraits< BH, useEigenRef, useFlat > Traits
Definition: febase.hh:38
Class representing the requirements for finite element calculations.
Definition: ferequirements.hh:252
PMHelper::ConstReturnType parameter() const
Get the parameter value.
Definition: ferequirements.hh:325
Traits for handling finite elements.
Definition: fetraits.hh:25
static constexpr int worlddim
Dimension of the world space.
Definition: fetraits.hh:60
VolumeLoad class represents distributed volume load that can be applied.
Definition: volume.hh:46
VolumeLoad(const Pre &pre={})
Constructor for the Loads class.
Definition: volume.hh:59
static constexpr int worldDim
Definition: volume.hh:51
auto calculateScalarImpl(const Requirement &par, ScalarAffordance affordance, const std::optional< std::reference_wrapper< const Eigen::VectorX< ST > > > &dx=std::nullopt) const -> ST
Definition: volume.hh:69
::value auto calculateAtImpl(const Requirement &req, const Dune::FieldVector< double, Traits::mydim > &local, Dune::PriorityTag< 0 >) const
Definition: volume.hh:65
void calculateVectorImpl(const Requirement &par, VectorAffordance affordance, typename Traits::template VectorType< ST > force, const std::optional< std::reference_wrapper< const Eigen::VectorX< ST > > > &dx=std::nullopt) const
Definition: volume.hh:88
void calculateMatrixImpl(const Requirement &par, MatrixAffordance, typename Traits::template MatrixType<> K, const std::optional< std::reference_wrapper< const Eigen::VectorX< ST > > > &dx=std::nullopt) const
Definition: volume.hh:110
A PreFE struct for volume load skill.
Definition: volume.hh:24
std::function< Eigen::Vector< double, worldDim >(const Dune::FieldVector< double, worldDim > &, const double &)> volumeLoad
Definition: volume.hh:26
static constexpr int worldDim
Definition: volume.hh:25
Definition: utils/dirichletvalues.hh:32