version 0.4
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
8
9namespace Ikarus {
10
19 template <typename DisplacementBasedElement, typename Traits>
20 class Volume {
21 public:
22 using FERequirementType = typename Traits::FERequirementType;
23 using LocalView = typename Traits::LocalView;
24 static constexpr int worldDim = Traits::worlddim;
25
33 template <typename VolumeLoad>
34 explicit Volume(VolumeLoad p_volumeLoad = {}) {
35 if constexpr (!std::is_same_v<VolumeLoad, utils::LoadDefault>) volumeLoad = p_volumeLoad;
36 }
37
46 double calculateScalar(const FERequirementType& req) const { return calculateScalarImpl<double>(req); }
47
55 void calculateVector(const FERequirementType& req, typename Traits::template VectorType<> force) const {
56 calculateVectorImpl<double>(req, force);
57 }
65 void calculateMatrix(const FERequirementType& req, typename Traits::template MatrixType<> K) const {
66 calculateMatrixImpl<double>(req, K);
67 }
68
69 protected:
70 template <typename ScalarType>
71 auto calculateScalarImpl(const FERequirementType& par, const std::optional<const Eigen::VectorX<ScalarType>>& dx
72 = std::nullopt) const -> ScalarType {
73 if (not volumeLoad) return 0.0;
74 ScalarType energy = 0.0;
75 const auto uFunction = dbElement().displacementFunction(par, dx);
76 const auto geo = dbElement().geometry();
77 const auto& lambda = par.getParameter(Ikarus::FEParameter::loadfactor);
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 ScalarType>
88 void calculateVectorImpl(const FERequirementType& par, typename Traits::template VectorType<ScalarType> force,
89 const std::optional<const Eigen::VectorX<ScalarType>>& dx = std::nullopt) const {
90 if (not volumeLoad) return;
91 using namespace Dune::DerivativeDirections;
92 using namespace Dune;
93 const auto uFunction = dbElement().displacementFunction(par, dx);
94 const auto geo = dbElement().geometry();
95 const auto& lambda = par.getParameter(Ikarus::FEParameter::loadfactor);
96
97 for (const auto& [gpIndex, gp] : uFunction.viewOverIntegrationPoints()) {
98 const Eigen::Vector<double, worldDim> fext = volumeLoad(geo.global(gp.position()), lambda);
99 const double intElement = geo.integrationElement(gp.position()) * gp.weight();
100 for (size_t i = 0; i < dbElement().numberOfNodes(); ++i) {
101 const auto udCi = uFunction.evaluateDerivative(gpIndex, wrt(coeff(i)));
102 force.template segment<worldDim>(worldDim * i) -= udCi * fext * intElement;
103 }
104 }
105 }
106
107 template <typename ScalarType>
108 void calculateMatrixImpl(const FERequirementType& par, typename Traits::template MatrixType<> K,
109 const std::optional<const Eigen::VectorX<ScalarType>>& dx = std::nullopt) const {}
110
111 private:
112 std::function<Eigen::Vector<double, worldDim>(const Dune::FieldVector<double, worldDim>&, const double&)>
113 volumeLoad;
114
120 constexpr const DisplacementBasedElement& dbElement() const {
121 return static_cast<DisplacementBasedElement const&>(*this);
122 }
123 };
124} // namespace Ikarus
Collection of fallback default functions.
Definition of the LinearElastic class for finite element mechanics computations.
Definition: simpleassemblers.hh:21
Definition: resultevaluators.hh:17
Volume class represents distributed volume load that can be applied.
Definition: volume.hh:20
typename Traits::FERequirementType FERequirementType
Definition: volume.hh:22
typename Traits::LocalView LocalView
Definition: volume.hh:23
double calculateScalar(const FERequirementType &req) const
Calculate the scalar value.
Definition: volume.hh:46
auto calculateScalarImpl(const FERequirementType &par, const std::optional< const Eigen::VectorX< ScalarType > > &dx=std::nullopt) const -> ScalarType
Definition: volume.hh:71
Volume(VolumeLoad p_volumeLoad={})
Constructor for the Loads class.
Definition: volume.hh:34
void calculateMatrixImpl(const FERequirementType &par, typename Traits::template MatrixType<> K, const std::optional< const Eigen::VectorX< ScalarType > > &dx=std::nullopt) const
Definition: volume.hh:108
static constexpr int worldDim
Definition: volume.hh:24
void calculateMatrix(const FERequirementType &req, typename Traits::template MatrixType<> K) const
Calculate the matrix associated with the given FERequirementType.
Definition: volume.hh:65
void calculateVector(const FERequirementType &req, typename Traits::template VectorType<> force) const
Calculate the vector associated with the given FERequirementType.
Definition: volume.hh:55
void calculateVectorImpl(const FERequirementType &par, typename Traits::template VectorType< ScalarType > force, const std::optional< const Eigen::VectorX< ScalarType > > &dx=std::nullopt) const
Definition: volume.hh:88
Definition: resultevaluators.hh:20