version 0.4.1
truss.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
10#pragma once
11
12#include <optional>
13
14#include <dune/localfefunctions/eigenDuneTransformations.hh>
15
18
19namespace Ikarus {
20
21template <typename PreFE, typename FE>
22class Truss;
23
28{
29 double E; // Young's modulus
30 double A; // Cross-section area
31
32 template <typename PreFE, typename FE>
34};
35
44template <typename PreFE, typename FE>
45class Truss
46 : public ResultTypeBase<ResultTypes::cauchyAxialForce, ResultTypes::PK2AxialForce, ResultTypes::linearAxialForce>
47{
48public:
51 using FlatBasis = typename Traits::FlatBasis;
54 using LocalView = typename Traits::LocalView;
55 using Geometry = typename Traits::Geometry;
56 using GridView = typename Traits::GridView;
57 using Element = typename Traits::Element;
58 using Pre = TrussPre;
59
60 static constexpr int myDim = Traits::mydim;
61 static constexpr int worldDim = Traits::worlddim;
62 static_assert(myDim == 1, "Truss elements should have myDim == 1");
63
72 template <typename ST>
74 {
75 double L;
76 ST l;
77 ST Elin;
78 ST Egl;
79 Eigen::VectorX<ST> dEdu;
80 Eigen::MatrixX<ST> ddEddu;
81 };
82
87 explicit Truss(const Pre& pre)
88 : E{pre.E},
89 A{pre.A} {}
90
99 template <typename ST = double>
100 auto displacement(const Requirement& par,
101 const std::optional<std::reference_wrapper<const Eigen::VectorX<ST>>>& dx = std::nullopt) const {
102 const auto& d = par.globalSolution();
103 auto disp = Ikarus::FEHelper::localSolutionBlockVector<Traits>(d, underlying().localView(), dx);
104 return disp;
105 }
106
116 template <class ST = double>
118 const Requirement& par,
119 const std::optional<std::reference_wrapper<const Eigen::VectorX<ST>>>& dx = std::nullopt) const {
121 const auto& localView = underlying().localView();
122 const auto& tree = localView.tree();
123 const auto numberOfNodes = tree.child(0).finiteElement().size();
124 auto& ele = localView.element();
125 const auto X1 = Dune::toEigen(ele.geometry().corner(0));
126 const auto X2 = Dune::toEigen(ele.geometry().corner(1));
127 const auto u = Dune::viewAsEigenMatrixAsDynFixed(displacement(par, dx)).transpose().eval();
128 const auto A1 = X2 - X1;
129 const auto ud1 = u.col(1) - u.col(0);
130
131 const Eigen::Vector<ST, worldDim> x1 = X1 + u.col(0);
132 const Eigen::Vector<ST, worldDim> x2 = X2 + u.col(1);
133
134 const double Lsquared = A1.squaredNorm();
135 const ST lsquared = (x2 - x1).squaredNorm();
136
137 kin.L = sqrt(Lsquared);
138 kin.l = sqrt(lsquared);
139
140 // Linear strain
141 kin.Elin = (kin.l - kin.L) / kin.L;
142
143 // Green-Lagrange strains
144 kin.Egl = 0.5 * (lsquared - Lsquared) / Lsquared;
145
146 // First derivative of Egl w.r.t displacements
147 kin.dEdu.setZero(worldDim * numberOfNodes);
148 kin.dEdu << -A1 - ud1, A1 + ud1;
149 kin.dEdu /= Lsquared;
150
151 // Second derivative of Egl w.r.t displacements
152 kin.ddEddu.setIdentity(worldDim * numberOfNodes, worldDim * numberOfNodes);
153 kin.ddEddu.template topRightCorner<worldDim, worldDim>() = -Eigen::Matrix<ST, worldDim, worldDim>::Identity();
154 kin.ddEddu.template bottomLeftCorner<worldDim, worldDim>() = -Eigen::Matrix<ST, worldDim, worldDim>::Identity();
155 kin.ddEddu /= Lsquared;
156
157 return kin;
158 }
159
160public:
171 template <template <typename, int, int> class RT>
172 requires(supportsResultType<RT>())
173 auto calculateAtImpl(const Requirement& req, [[maybe_unused]] const Dune::FieldVector<double, Traits::mydim>& local,
174 Dune::PriorityTag<0>) const {
176 const auto [L, l, Elin, Egl, dEdu, ddEddu] = computeStrain(req);
177 if constexpr (isSameResultType<RT, ResultTypes::cauchyAxialForce>) {
178 auto N = Eigen::Vector<double, 1>{E * A * Egl * l / L}; // Axial force in deformed configuration
179 return RTWrapper{N};
180 }
181 if constexpr (isSameResultType<RT, ResultTypes::PK2AxialForce>) {
182 auto N = Eigen::Vector<double, 1>{E * A * Egl}; // Axial force in undeformed configuration
183 return RTWrapper{N};
184 }
185 if constexpr (isSameResultType<RT, ResultTypes::linearAxialForce>) {
186 auto N = Eigen::Vector<double, 1>{E * A * Elin};
187 return RTWrapper{N};
188 }
189 }
190
191private:
192 //> CRTP
193 const auto& underlying() const { return static_cast<const FE&>(*this); }
194 auto& underlying() { return static_cast<FE&>(*this); }
195
196 double E;
197 double A;
198
199protected:
200 template <typename ScalarType>
202 const Requirement& par, const MatrixAffordance& affordance, typename Traits::template MatrixType<> K,
203 const std::optional<std::reference_wrapper<const Eigen::VectorX<ScalarType>>>& dx = std::nullopt) const {
204 const auto [L, l, Elin, Egl, dEdu, ddEddu] = computeStrain(par, dx);
205 K += E * A * L * (dEdu * dEdu.transpose() + ddEddu * Egl);
206 }
207
208 template <typename ScalarType>
210 const std::optional<std::reference_wrapper<const Eigen::VectorX<ScalarType>>>& dx =
211 std::nullopt) const -> ScalarType {
212 const auto [L, l, Elin, Egl, dEdu, ddEddu] = computeStrain(par, dx);
213 return 0.5 * E * A * L * Egl * Egl;
214 }
215
216 template <typename ScalarType>
218 const Requirement& par, VectorAffordance affordance, typename Traits::template VectorType<ScalarType> force,
219 const std::optional<std::reference_wrapper<const Eigen::VectorX<ScalarType>>>& dx = std::nullopt) const {
220 const auto [L, l, Elin, Egl, dEdu, ddEddu] = computeStrain(par, dx);
221 force += E * A * Egl * L * dEdu;
222 }
223};
224
231inline auto truss(const double E, const double A) {
232 TrussPre pre(E, A);
233
234 return pre;
235}
236} // namespace Ikarus
Definition of the LinearElastic class for finite element mechanics computations.
auto viewAsEigenMatrixAsDynFixed(Dune::BlockVector< ValueType > &blockedVector)
View Dune::BlockVector as an Eigen::Matrix with dynamic rows and fixed columns depending on the size ...
Definition: linearalgebrahelper.hh:88
Definition: assemblermanipulatorbuildingblocks.hh:22
auto truss(const double E, const double A)
A helper function to create a truss pre finite element.
Definition: truss.hh:231
MatrixAffordance
A strongly typed enum class representing the matrix affordance.
Definition: ferequirements.hh:63
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
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
SolutionVectorReturnType globalSolution()
Get the global solution vector.
Definition: ferequirements.hh:308
Container that is used for FE Results. It gives access to the stored value, but can also be used to a...
Definition: feresulttypes.hh:159
Base class for element definitions that provides common functionality for ResultTypes.
Definition: feresulttypes.hh:272
Traits for handling finite elements.
Definition: fetraits.hh:25
typename Basis::LocalView LocalView
Type of the local view.
Definition: fetraits.hh:42
typename Element::Geometry Geometry
Type of the element geometry.
Definition: fetraits.hh:51
BH BasisHandler
Type of the basis of the finite element.
Definition: fetraits.hh:27
typename Basis::GridView GridView
Type of the grid view.
Definition: fetraits.hh:45
static constexpr int worlddim
Dimension of the world space.
Definition: fetraits.hh:60
typename BasisHandler::FlatBasis FlatBasis
Type of the flat basis.
Definition: fetraits.hh:33
typename LocalView::Element Element
Type of the grid element.
Definition: fetraits.hh:48
static constexpr int mydim
Dimension of the geometry.
Definition: fetraits.hh:63
Truss class represents a truss finite element.
Definition: truss.hh:47
void calculateVectorImpl(const Requirement &par, VectorAffordance affordance, typename Traits::template VectorType< ScalarType > force, const std::optional< std::reference_wrapper< const Eigen::VectorX< ScalarType > > > &dx=std::nullopt) const
Definition: truss.hh:217
auto calculateAtImpl(const Requirement &req, const Dune::FieldVector< double, Traits::mydim > &local, Dune::PriorityTag< 0 >) const
Calculates a requested result at a specific local position.
Definition: truss.hh:173
typename Traits::LocalView LocalView
Definition: truss.hh:54
Truss(const Pre &pre)
Constructor for the Truss class.
Definition: truss.hh:87
static constexpr int worldDim
Definition: truss.hh:61
void calculateMatrixImpl(const Requirement &par, const MatrixAffordance &affordance, typename Traits::template MatrixType<> K, const std::optional< std::reference_wrapper< const Eigen::VectorX< ScalarType > > > &dx=std::nullopt) const
Definition: truss.hh:201
typename Traits::Geometry Geometry
Definition: truss.hh:55
typename Traits::FlatBasis FlatBasis
Definition: truss.hh:51
typename Traits::GridView GridView
Definition: truss.hh:56
typename Traits::BasisHandler BasisHandler
Definition: truss.hh:50
static constexpr int myDim
Definition: truss.hh:60
auto calculateScalarImpl(const Requirement &par, ScalarAffordance affordance, const std::optional< std::reference_wrapper< const Eigen::VectorX< ScalarType > > > &dx=std::nullopt) const -> ScalarType
Definition: truss.hh:209
typename Traits::Element Element
Definition: truss.hh:57
KinematicVariables< ST > computeStrain(const Requirement &par, const std::optional< std::reference_wrapper< const Eigen::VectorX< ST > > > &dx=std::nullopt) const
Gets the strain for the given Requirement and optional displacement vector.
Definition: truss.hh:117
auto displacement(const Requirement &par, const std::optional< std::reference_wrapper< const Eigen::VectorX< ST > > > &dx=std::nullopt) const
Gets the displacement for the given Requirement and optional displacement vector.
Definition: truss.hh:100
A PreFE struct for truss elements.
Definition: truss.hh:28
double E
Definition: truss.hh:29
double A
Definition: truss.hh:30
A structure representing kinematic variables.
Definition: truss.hh:74
double L
Length of the reference geometry.
Definition: truss.hh:75
Eigen::MatrixX< ST > ddEddu
second derivative of Egl w.r.t displacements
Definition: truss.hh:80
ST l
Length of the deformed geometry.
Definition: truss.hh:76
ST Egl
Green-Lagrange strain.
Definition: truss.hh:78
ST Elin
Linear strain.
Definition: truss.hh:77
Eigen::VectorX< ST > dEdu
first derivative of Egl w.r.t displacements
Definition: truss.hh:79
Definition: utils/dirichletvalues.hh:32