12#if HAVE_DUNE_LOCALFEFUNCTIONS
13 #include <dune/fufem/boundarypatch.hh>
14 #include <dune/geometry/quadraturerules.hh>
15 #include <dune/geometry/type.hh>
16 #include <dune/localfefunctions/cachedlocalBasis/cachedlocalBasis.hh>
17 #include <dune/localfefunctions/expressions/greenLagrangeStrains.hh>
18 #include <dune/localfefunctions/impl/standardLocalFunction.hh>
19 #include <dune/localfefunctions/manifolds/realTuple.hh>
33template <
typename PreFE,
typename FE,
typename PRE>
34class NonLinearElastic;
40template <
typename MAT>
46 template <
typename PreFE,
typename FE>
59template <
typename PreFE,
typename FE,
typename PRE>
75 using LocalBasisType =
decltype(std::declval<LocalView>().tree().child(0).finiteElement().localBasis());
92 const auto& localView = underlying().localView();
93 const auto& element = localView.element();
94 auto& firstChild = localView.tree().child(0);
95 const auto& fe = firstChild.finiteElement();
96 geo_ = std::make_shared<const Geometry>(element.geometry());
97 numberOfNodes_ = fe.size();
98 order_ = 2 * (fe.localBasis().order());
99 localBasis_ = Dune::CachedLocalBasis(fe.localBasis());
100 if constexpr (
requires { element.impl().getQuadratureRule(order_); })
101 if (element.impl().isTrimmed())
102 localBasis_.bind(element.impl().getQuadratureRule(order_), Dune::bindDerivatives(0, 1));
104 localBasis_.bind(Dune::QuadratureRules<double, myDim>::rule(element.type(), order_),
105 Dune::bindDerivatives(0, 1));
107 localBasis_.bind(Dune::QuadratureRules<double, myDim>::rule(element.type(), order_), Dune::bindDerivatives(0, 1));
119 template <
typename ScalarType =
double>
122 const std::optional<std::reference_wrapper<
const Eigen::VectorX<ScalarType>>>& dx = std::nullopt)
const {
124 auto disp = Ikarus::FEHelper::localSolutionBlockVector<Traits>(d, underlying().localView(), dx);
125 Dune::StandardLocalFunction uFunction(localBasis_, disp, geo_);
137 template <
typename ScalarType =
double>
140 const std::optional<std::reference_wrapper<
const Eigen::VectorX<ScalarType>>>& dx = std::nullopt)
const {
153 template <
typename ScalarType,
int strainDim,
bool voigt = true>
155 return material<ScalarType>().template tangentModuli<strainType, voigt>(strain);
166 template <
typename ScalarType,
int strainDim>
168 return material<ScalarType>().template storedEnergy<strainType>(strain);
180 template <
typename ScalarType,
int strainDim,
bool voigt = true>
181 auto getStress(
const Eigen::Vector<ScalarType, strainDim>& strain)
const {
182 return material<ScalarType>().template stresses<strainType, voigt>(strain);
187 [[nodiscard]]
int order()
const {
return order_; }
189 template <
typename ScalarType =
double>
192 return mat_.template rebind<ScalarType>();
207 template <
template <
typename,
int,
int>
class RT>
208 requires(supportsResultType<RT>())
210 Dune::PriorityTag<1>)
const {
211 using namespace Dune::DerivativeDirections;
214 if constexpr (isSameResultType<RT, ResultTypes::PK2Stress> or isSameResultType<RT, ResultTypes::PK2StressFull>) {
216 const auto H = uFunction.evaluateDerivative(local, Dune::wrt(spatialAll), Dune::on(gridElement));
217 const auto E = (0.5 * (H.transpose() + H + H.transpose() * H)).eval();
219 decltype(
auto) mat = [&]() {
220 if constexpr (isSameResultType<RT, ResultTypes::PK2StressFull> and
requires { mat_.underlying(); })
221 return mat_.underlying();
225 return RTWrapper{mat.template stresses<StrainTags::greenLagrangian>(enlargeIfReduced<Material>(
toVoigt(E)))};
231 const auto& underlying()
const {
return static_cast<const FE&
>(*this); }
232 auto& underlying() {
return static_cast<FE&
>(*this); }
233 std::shared_ptr<const Geometry> geo_;
234 Dune::CachedLocalBasis<std::remove_cvref_t<LocalBasisType>> localBasis_;
236 size_t numberOfNodes_{0};
247 template <
typename ScalarType>
250 const std::optional<std::reference_wrapper<
const Eigen::VectorX<ScalarType>>>& dx = std::nullopt)
const {
251 using namespace Dune::DerivativeDirections;
252 using namespace Dune;
255 for (
const auto& [gpIndex, gp] : eps.viewOverIntegrationPoints()) {
256 const double intElement = geo_->integrationElement(gp.position()) * gp.weight();
257 const auto EVoigt = (eps.evaluate(gpIndex, on(gridElement))).eval();
258 const auto u = (uFunction.evaluate(gpIndex, on(gridElement))).eval();
262 for (
size_t i = 0; i < numberOfNodes_; ++i) {
263 const auto bopI = eps.evaluateDerivative(gpIndex, wrt(coeff(i)), on(gridElement));
264 for (
size_t j = 0; j < numberOfNodes_; ++j) {
265 const auto bopJ = eps.evaluateDerivative(gpIndex, wrt(coeff(j)), on(gridElement));
266 const auto kgIJ = eps.evaluateDerivative(gpIndex, wrt(coeff(i, j)), along(stresses), on(gridElement));
267 K.template block<myDim, myDim>(i *
myDim, j *
myDim) += (bopI.transpose() * C * bopJ + kgIJ) * intElement;
273 template <
typename ScalarType>
275 const std::optional<std::reference_wrapper<
const Eigen::VectorX<ScalarType>>>& dx =
276 std::nullopt)
const -> ScalarType {
277 using namespace Dune::DerivativeDirections;
278 using namespace Dune;
281 const auto& lambda = par.parameter();
282 ScalarType energy = 0.0;
284 for (
const auto& [gpIndex, gp] : eps.viewOverIntegrationPoints()) {
285 const auto EVoigt = (eps.evaluate(gpIndex, on(gridElement))).eval();
287 energy += internalEnergy * geo_->integrationElement(gp.position()) * gp.weight();
293 template <
typename ScalarType>
296 const std::optional<std::reference_wrapper<
const Eigen::VectorX<ScalarType>>>& dx = std::nullopt)
const {
297 using namespace Dune::DerivativeDirections;
298 using namespace Dune;
302 for (
const auto& [gpIndex, gp] : eps.viewOverIntegrationPoints()) {
303 const double intElement = geo_->integrationElement(gp.position()) * gp.weight();
304 const auto EVoigt = (eps.evaluate(gpIndex, on(gridElement))).eval();
306 for (
size_t i = 0; i < numberOfNodes_; ++i) {
307 const auto bopI = eps.evaluateDerivative(gpIndex, wrt(coeff(i)), on(gridElement));
308 force.template segment<myDim>(
myDim * i) += bopI.transpose() * stresses * intElement;
320template <
typename MAT>
330 #error NonLinearElastic depends on dune-localfefunctions, which is not included
Helper for transform between Dune linear algebra types and Eigen.
Collection of fallback default functions.
Helper for the autodiff library.
Header file for types of loads in Ikarus finite element mechanics.
Definition of several material related enums.
Contains the FE class, which is used as a base class for all finite elements. It provides information...
Definition of the LinearElastic class for finite element mechanics computations.
Material property functions and conversion utilities.
constexpr Eigen::Index toVoigt(Eigen::Index i, Eigen::Index j) noexcept
Converts 2D indices to Voigt notation index.
Definition: tensorutils.hh:166
Definition: assemblermanipulatorbuildingblocks.hh:22
MatrixAffordance
A strongly typed enum class representing the matrix affordance.
Definition: ferequirements.hh:63
auto nonLinearElastic(const MAT &mat)
A helper function to create a non-linear elastic pre finite element.
Definition: nonlinearelastic.hh:321
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
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: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
std::conditional_t< useFlat, FlatBasis, UntouchedBasis > Basis
Type of the basis version.
Definition: fetraits.hh:39
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
NonLinearElastic class represents a non-linear elastic finite element.
Definition: nonlinearelastic.hh:61
auto getInternalEnergy(const Eigen::Vector< ScalarType, strainDim > &strain) const
Get the internal energy for the given strain.
Definition: nonlinearelastic.hh:167
typename Traits::Basis Basis
Definition: nonlinearelastic.hh:64
typename Traits::Geometry Geometry
Definition: nonlinearelastic.hh:69
auto calculateScalarImpl(const Requirement &par, ScalarAffordance affordance, const std::optional< std::reference_wrapper< const Eigen::VectorX< ScalarType > > > &dx=std::nullopt) const -> ScalarType
Definition: nonlinearelastic.hh:274
typename Traits::FlatBasis FlatBasis
Definition: nonlinearelastic.hh:65
auto strainFunction(const Requirement &par, const std::optional< std::reference_wrapper< const Eigen::VectorX< ScalarType > > > &dx=std::nullopt) const
The strain function for the given Requirement.
Definition: nonlinearelastic.hh:138
PRE::Material Material
Definition: nonlinearelastic.hh:72
typename Traits::GridView GridView
Definition: nonlinearelastic.hh:70
void bindImpl()
A helper function to bind the local view to the element.
Definition: nonlinearelastic.hh:91
const Geometry & geometry() const
Definition: nonlinearelastic.hh:185
static constexpr int myDim
Definition: nonlinearelastic.hh:77
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: nonlinearelastic.hh:294
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: nonlinearelastic.hh:209
decltype(auto) material() const
Definition: nonlinearelastic.hh:190
NonLinearElastic(const Pre &pre)
Constructor for the NonLinearElastic class.
Definition: nonlinearelastic.hh:84
typename Traits::Element Element
Definition: nonlinearelastic.hh:71
PRE Pre
Definition: nonlinearelastic.hh:73
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
Calculate the matrix associated with the given Requirement.
Definition: nonlinearelastic.hh:248
auto materialTangent(const Eigen::Vector< ScalarType, strainDim > &strain) const
Get the material tangent for the given strain.
Definition: nonlinearelastic.hh:154
auto displacementFunction(const Requirement &par, const std::optional< std::reference_wrapper< const Eigen::VectorX< ScalarType > > > &dx=std::nullopt) const
Get the displacement function for the given Requirement.
Definition: nonlinearelastic.hh:120
static constexpr auto strainType
Definition: nonlinearelastic.hh:78
typename Traits::LocalView LocalView
Definition: nonlinearelastic.hh:68
int order() const
Definition: nonlinearelastic.hh:187
decltype(std::declval< LocalView >().tree().child(0).finiteElement().localBasis()) LocalBasisType
Definition: nonlinearelastic.hh:75
auto getStress(const Eigen::Vector< ScalarType, strainDim > &strain) const
Get the stress for the given strain.
Definition: nonlinearelastic.hh:181
size_t numberOfNodes() const
Definition: nonlinearelastic.hh:186
A PreFE struct for non-linear elastic elements.
Definition: nonlinearelastic.hh:42
MAT Material
Definition: nonlinearelastic.hh:43
MAT material
Definition: nonlinearelastic.hh:44
Definition: utils/dirichletvalues.hh:32
Concept to check if the underlying scalar type is a dual type.
Definition: concepts.hh:608