12#if HAVE_DUNE_LOCALFEFUNCTIONS
15 #include <type_traits>
17 #include <dune/geometry/quadraturerules.hh>
18 #include <dune/localfefunctions/expressions/linearStrainsExpr.hh>
19 #include <dune/localfefunctions/impl/standardLocalFunction.hh>
32template <
typename PreFE,
typename FE,
typename PRE>
39template <Concepts::GeometricallyLinearMaterial MAT>
45 template <
typename PreFE,
typename FE>
57template <
typename PreFE,
typename FE,
typename PRE>
72 using LocalBasisType =
decltype(std::declval<LocalView>().tree().child(0).finiteElement().localBasis());
74 template <
typename ST>
75 using VectorXOptRef = std::optional<std::reference_wrapper<const Eigen::VectorX<ST>>>;
82 template <
template <
typename,
int,
int>
class RT>
85 template <
typename ST =
double>
88 template <
typename ST =
double>
89 using BopType = Eigen::Matrix<ST, strainDim, myDim>;
91 template <
typename ST =
double>
92 using KgType = Eigen::Matrix<ST, myDim, myDim>;
106 const auto& localView = underlying().localView();
107 const auto& element = localView.element();
108 auto& firstChild = localView.tree().child(0);
109 const auto& fe = firstChild.finiteElement();
110 geo_ = std::make_shared<const Geometry>(element.geometry());
111 numberOfNodes_ = fe.size();
112 order_ = fe.localBasis().order();
113 localBasis_ = Dune::CachedLocalBasis(fe.localBasis());
114 if (underlying().quadratureRule())
115 localBasis_.bind(underlying().quadratureRule().value(), Dune::bindDerivatives(0, 1));
117 localBasis_.bind(defaultQuadratureRule<myDim>(element, 2 * order_), Dune::bindDerivatives(0, 1));
129 template <
typename ScalarType =
double>
132 auto disp = Ikarus::FEHelper::localSolutionBlockVector<Traits>(d, underlying().localView(), dx);
133 Dune::StandardLocalFunction uFunction(localBasis_, disp, geo_);
145 template <
class ScalarType =
double>
158 template <
typename ScalarType,
int strainDim>
160 const auto C = materialTangent<ScalarType, strainDim>(strain);
161 return (0.5 * strain.dot(C * strain));
173 template <
typename ScalarType,
int strainDim,
bool voigt = true>
174 auto stress(
const Eigen::Vector<ScalarType, strainDim>& strain)
const {
175 const auto C = materialTangent<ScalarType, strainDim, voigt>(strain);
176 return (C * strain).eval();
188 template <
typename ScalarType,
int strainDim,
bool voigt = true>
190 const Eigen::Vector<ScalarType, strainDim>& strain = Eigen::Vector<ScalarType, strainDim>::Zero())
const {
192 return material<ScalarType>().template tangentModuli<strainType, voigt>(strain);
197 [[nodiscard]]
int order()
const {
return order_; }
198 const Dune::CachedLocalBasis<std::remove_cvref_t<LocalBasisType>>&
localBasis()
const {
return localBasis_; }
200 template <
typename ScalarType =
double>
203 return mat_.template rebind<ScalarType>();
214 template <
template <
typename,
int,
int>
class RT>
215 requires(LinearElastic::template supportsResultType<RT>())
217 return [&](
const Eigen::Vector<double, strainDim>& strainInVoigt) {
218 if constexpr (isSameResultType<RT, ResultTypes::linearStress> or
219 isSameResultType<RT, ResultTypes::linearStressFull>) {
220 decltype(
auto) mat = [&]() {
221 if constexpr (isSameResultType<RT, ResultTypes::linearStressFull> and
requires { mat_.underlying(); })
222 return mat_.underlying();
226 return RTWrapperType<RT>{mat.template stresses<StrainTags::linear>(enlargeIfReduced<Material>(strainInVoigt))};
239 template <
template <
typename,
int,
int>
class RT>
240 requires(LinearElastic::template supportsResultType<RT>())
242 Dune::PriorityTag<1>)
const {
245 if constexpr (isSameResultType<RT, ResultTypes::linearStress> or
246 isSameResultType<RT, ResultTypes::linearStressFull>) {
247 const auto rFunction = resultFunction<RT>();
249 auto epsVoigt = eps.evaluate(local, Dune::on(Dune::DerivativeDirections::gridElement));
250 return rFunction(epsVoigt);
256 const auto& underlying()
const {
return static_cast<const FE&
>(*this); }
257 auto& underlying() {
return static_cast<FE&
>(*this); }
259 std::shared_ptr<const Geometry> geo_;
260 Dune::CachedLocalBasis<std::remove_cvref_t<LocalBasisType>> localBasis_;
262 size_t numberOfNodes_{0};
277 template <
typename ST>
280 return [&](
const FE::template
KgType<ST>& kgIJ,
const int I,
const int J,
const auto& gp) {
281 const auto geo = underlying().localView().element().geometry();
282 const double intElement = geo.integrationElement(gp.position()) * gp.weight();
283 K.template block<FE::myDim, FE::myDim>(I *
FE::myDim, J *
FE::myDim) += kgIJ * intElement;
296 template <
typename ST>
302 const double intElement = geo_->integrationElement(gp.position()) * gp.weight();
303 K.template block<myDim, myDim>(I *
myDim, J *
myDim) += (bopI.transpose() * C * bopJ) * intElement;
318 template <
typename ST>
322 const double intElement = geo_->integrationElement(gp.position()) * gp.weight();
323 force.template segment<myDim>(
myDim * I) += bopI.transpose() * stresses * intElement;
335 template <
typename ScalarType>
337 return [&]() -> ScalarType {
338 using namespace Dune::DerivativeDirections;
339 using namespace Dune;
340 ScalarType energy = 0.0;
342 for (
const auto& [gpIndex, gp] : eps.viewOverIntegrationPoints()) {
343 const auto epsVoigt = eps.evaluate(gpIndex, on(gridElement));
344 energy +=
internalEnergy(epsVoigt) * geo_->integrationElement(gp.position()) * gp.weight();
351 template <
typename ScalarType>
353 typename Traits::template MatrixType<> K,
358 using namespace Dune::DerivativeDirections;
359 using namespace Dune;
361 const auto kFunction = materialStiffnessMatrixFunction<ScalarType>(par, K, dx);
363 for (
const auto& [gpIndex, gp] : eps.viewOverIntegrationPoints()) {
364 const auto epsVoigt = eps.evaluate(gpIndex, on(gridElement));
365 for (
size_t i = 0; i < numberOfNodes_; ++i) {
366 const auto bopI = eps.evaluateDerivative(gpIndex, wrt(coeff(i)), on(gridElement));
367 for (
size_t j = 0; j < numberOfNodes_; ++j) {
368 const auto bopJ = eps.evaluateDerivative(gpIndex, wrt(coeff(j)), on(gridElement));
369 kFunction(epsVoigt, bopI, bopJ, i, j, gp);
375 template <
typename ScalarType>
379 return ScalarType{0.0};
383 template <
typename ScalarType>
385 typename Traits::template VectorType<ScalarType> force,
389 using namespace Dune::DerivativeDirections;
390 using namespace Dune;
392 const auto fIntFunction = internalForcesFunction<ScalarType>(par, force, dx);
395 for (
const auto& [gpIndex, gp] : eps.viewOverIntegrationPoints()) {
396 const auto epsVoigt = eps.evaluate(gpIndex, on(gridElement));
397 const auto stresses =
stress(epsVoigt);
398 for (
size_t i = 0; i < numberOfNodes_; ++i) {
399 const auto bopI = eps.evaluateDerivative(gpIndex, wrt(coeff(i)), on(gridElement));
400 fIntFunction(stresses, bopI, i, gp);
412template <Concepts::GeometricallyLinearMaterial MAT>
421 #error LinearElastic depends on dune-localfefunctions, which is not included
Free function for creating a tensor product quadrature rule and other Dune::Quadrature rule utils.
Header file for various EAS functions.
Definition of several material related enums.
Definitions of ResultTypes used for finite element results.
Material property functions and conversion utilities.
Definition of the LinearElastic class for finite element mechanics computations.
Definition: assemblermanipulatorbuildingblocks.hh:22
MatrixAffordance
A strongly typed enum class representing the matrix affordance.
Definition: ferequirements.hh:65
VectorAffordance
A strongly typed enum class representing the vector affordance.
Definition: ferequirements.hh:50
ScalarAffordance
A strongly typed enum class representing the scalar affordance.
Definition: ferequirements.hh:39
auto linearElastic(const MAT &mat)
A helper function to create a linear elastic pre finite element.
Definition: linearelastic.hh:413
Definition: utils/dirichletvalues.hh:35
FE class is a base class for all finite elements.
Definition: febase.hh:79
static constexpr int myDim
Definition: febase.hh:95
FETraits< BH, useEigenRef, useFlat > Traits
Definition: febase.hh:38
Class representing the requirements for finite element calculations.
Definition: ferequirements.hh:224
const SolutionVectorType & globalSolution() const
Get the global solution vector.
Definition: ferequirements.hh:314
Container that is used for FE Results. It gives access to the stored value, but can also be used to a...
Definition: feresulttypes.hh:164
Base class for element definitions that provides common functionality for ResultTypes.
Definition: feresulttypes.hh:277
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
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
LinearElastic class represents a linear elastic finite element.
Definition: linearelastic.hh:59
void bindImpl()
A helper function to bind the local view to the element.
Definition: linearelastic.hh:105
auto internalForcesFunction(const Requirement &par, typename Traits::template VectorType< ST > &force, const VectorXOptRef< ST > &dx=std::nullopt) const
Get a lambda function that evaluates the internal force vector for a given strain,...
Definition: linearelastic.hh:319
auto energyFunction(const Requirement &par, const VectorXOptRef< ScalarType > &dx=std::nullopt) const
Get a lambda function that evaluates the internal energy at a given integration point and its index.
Definition: linearelastic.hh:336
static constexpr int myDim
Definition: linearelastic.hh:77
Eigen::Vector< ST, strainDim > StrainType
Definition: linearelastic.hh:86
Eigen::Matrix< ST, strainDim, myDim > BopType
Definition: linearelastic.hh:89
void calculateMatrixImpl(const Requirement &par, const MatrixAffordance &affordance, typename Traits::template MatrixType<> K, const VectorXOptRef< ScalarType > &dx=std::nullopt) const
Definition: linearelastic.hh:352
Eigen::Matrix< ST, myDim, myDim > KgType
Definition: linearelastic.hh:92
typename Traits::Element Element
Definition: linearelastic.hh:68
auto resultFunction() const
Get a lambda function that evaluates the requested result type for a given strain (in Voigt notation)...
Definition: linearelastic.hh:216
static constexpr auto strainType
Definition: linearelastic.hh:79
PRE Pre
Definition: linearelastic.hh:70
static constexpr auto stressType
Definition: linearelastic.hh:80
auto calculateScalarImpl(const Requirement &par, ScalarAffordance affordance, const VectorXOptRef< ScalarType > &dx=std::nullopt) const -> ScalarType
Definition: linearelastic.hh:376
size_t numberOfNodes() const
Definition: linearelastic.hh:196
int order() const
Definition: linearelastic.hh:197
auto materialStiffnessMatrixFunction(const Requirement &par, typename Traits::template MatrixType< ST > &K, const VectorXOptRef< ST > &dx=std::nullopt) const
Get a lambda function that evaluates the elastic stiffness matrix for a given strain,...
Definition: linearelastic.hh:297
auto materialTangent(const Eigen::Vector< ScalarType, strainDim > &strain=Eigen::Vector< ScalarType, strainDim >::Zero()) const
Get the linear elastic material tangent for the given strain for the given Requirement.
Definition: linearelastic.hh:189
auto calculateAtImpl(const Requirement &req, const Dune::FieldVector< double, Traits::mydim > &local, Dune::PriorityTag< 1 >) const
Calculates a requested result at a specific local position.
Definition: linearelastic.hh:241
auto geometricStiffnessMatrixFunction(const Requirement &par, typename Traits::template MatrixType< ST > &K, const VectorXOptRef< ST > &dx=std::nullopt) const
Get a lambda function that evaluates the geometric part of the stiffness matrix (Kg) for a given inte...
Definition: linearelastic.hh:278
typename Traits::GridView GridView
Definition: linearelastic.hh:67
typename Traits::BasisHandler BasisHandler
Definition: linearelastic.hh:62
typename Traits::LocalView LocalView
Definition: linearelastic.hh:65
std::optional< std::reference_wrapper< const Eigen::VectorX< ST > > > VectorXOptRef
Definition: linearelastic.hh:75
typename Traits::FlatBasis FlatBasis
Definition: linearelastic.hh:63
auto displacementFunction(const Requirement &par, const VectorXOptRef< ScalarType > &dx=std::nullopt) const
Gets the displacement function for the given Requirement and optional displacement vector.
Definition: linearelastic.hh:130
LinearElastic(const Pre &pre)
Constructor for the LinearElastic class.
Definition: linearelastic.hh:98
PRE::Material Material
Definition: linearelastic.hh:69
static constexpr int strainDim
Definition: linearelastic.hh:78
decltype(std::declval< LocalView >().tree().child(0).finiteElement().localBasis()) LocalBasisType
Definition: linearelastic.hh:72
decltype(auto) material() const
Definition: linearelastic.hh:201
typename Traits::Geometry Geometry
Definition: linearelastic.hh:66
auto internalEnergy(const Eigen::Vector< ScalarType, strainDim > &strain) const
Get the internal energy for the given strain.
Definition: linearelastic.hh:159
const Dune::CachedLocalBasis< std::remove_cvref_t< LocalBasisType > > & localBasis() const
Definition: linearelastic.hh:198
auto strainFunction(const Requirement &par, const VectorXOptRef< ScalarType > &dx=std::nullopt) const
Gets the strain function for the given Requirement and optional di splacement vector.
Definition: linearelastic.hh:146
const Geometry & geometry() const
Definition: linearelastic.hh:195
void calculateVectorImpl(const Requirement &par, VectorAffordance affordance, typename Traits::template VectorType< ScalarType > force, const VectorXOptRef< ScalarType > &dx=std::nullopt) const
Definition: linearelastic.hh:384
auto stress(const Eigen::Vector< ScalarType, strainDim > &strain) const
Get the stress for the given strain.
Definition: linearelastic.hh:174
A PreFE struct for linear elastic elements.
Definition: linearelastic.hh:41
MAT Material
Definition: linearelastic.hh:42
MAT material
Definition: linearelastic.hh:43
static constexpr bool isMixed()
Definition: mixin.hh:110
Definition: utils/dirichletvalues.hh:37
Concept to check if the underlying scalar type is a dual type.
Definition: utils/concepts.hh:625
Header file for material models in Ikarus finite element mechanics.