12#if HAVE_DUNE_LOCALFEFUNCTIONS
16# include <type_traits>
18# include <dune/fufem/boundarypatch.hh>
19# include <dune/geometry/quadraturerules.hh>
20# include <dune/localfefunctions/expressions/linearStrainsExpr.hh>
21# include <dune/localfefunctions/impl/standardLocalFunction.hh>
22# include <dune/localfefunctions/manifolds/realTuple.hh>
43 template <
typename Basis_,
typename FERequirements_ = FERequirements<>,
bool useEigenRef = false>
52 using Element =
typename LocalView::Element;
58 using LocalBasisType =
decltype(std::declval<LocalView>().tree().child(0).finiteElement().localBasis());
73 template <
typename VolumeLoad = utils::LoadDefault,
typename NeumannBoundaryLoad = utils::LoadDefault>
74 LinearElastic(
const Basis& globalBasis,
const typename LocalView::Element& element,
double emod,
double nu,
75 VolumeLoad p_volumeLoad = {},
const BoundaryPatch<GridView>* p_neumannBoundary =
nullptr,
76 NeumannBoundaryLoad p_neumannBoundaryLoad = {})
79 auto& first_child = this->
localView().tree().child(0);
80 const auto& fe = first_child.finiteElement();
81 geo_ = std::make_shared<const Geometry>(this->
localView().element().geometry());
83 order = 2 * (fe.localBasis().order());
84 localBasis = Dune::CachedLocalBasis(fe.localBasis());
85 if constexpr (
requires { this->
localView().element().impl().getQuadratureRule(
order); })
86 if (this->
localView().element().impl().isTrimmed())
87 localBasis.bind(this->localView().element().impl().getQuadratureRule(
order), Dune::bindDerivatives(0, 1));
90 Dune::bindDerivatives(0, 1));
93 Dune::bindDerivatives(0, 1));
95 if constexpr (!std::is_same_v<VolumeLoad, utils::LoadDefault>)
volumeLoad = p_volumeLoad;
96 if constexpr (!std::is_same_v<NeumannBoundaryLoad, utils::LoadDefault>)
100 &&
"If you pass a Neumann boundary you should also pass the function for the Neumann load!");
110 template <
typename ScalarType =
double>
112 const std::optional<
const Eigen::VectorX<ScalarType>>& dx = std::nullopt)
const {
114 auto disp = Ikarus::FEHelper::localSolutionBlockVector<FERequirementType>(d, this->
localView(), dx);
126 template <
class ScalarType =
double>
128 const std::optional<
const Eigen::VectorX<ScalarType>>& dx = std::nullopt)
const {
138 if constexpr (
myDim == 2)
140 else if constexpr (
myDim == 3)
169 calculateVectorImpl<double>(par, force);
180 using namespace Dune::DerivativeDirections;
181 using namespace Dune;
184 for (
const auto& [gpIndex, gp] : eps.viewOverIntegrationPoints()) {
185 const double intElement =
geo_->integrationElement(gp.position()) * gp.weight();
187 const auto bopI = eps.evaluateDerivative(gpIndex, wrt(coeff(i)), on(
gridElement));
189 const auto bopJ = eps.evaluateDerivative(gpIndex, wrt(coeff(j)), on(
gridElement));
190 K.template block<myDim, myDim>(i *
myDim, j *
myDim) += bopI.transpose() * C * bopJ * intElement;
205 using namespace Dune::Indices;
206 using namespace Dune::DerivativeDirections;
207 using namespace Dune;
211 auto epsVoigt = eps.evaluate(local, on(
gridElement));
218 DUNE_THROW(Dune::NotImplemented,
"The requested result type is NOT implemented.");
221 std::shared_ptr<const Geometry>
geo_;
222 Dune::CachedLocalBasis<std::remove_cvref_t<LocalBasisType>>
localBasis;
234 template <
typename ScalarType>
236 = std::nullopt)
const -> ScalarType {
240 using namespace Dune::DerivativeDirections;
241 using namespace Dune;
245 ScalarType energy = 0.0;
246 for (
const auto& [gpIndex, gp] : eps.viewOverIntegrationPoints()) {
247 const auto EVoigt = eps.evaluate(gpIndex, on(
gridElement));
249 energy += (0.5 * EVoigt.dot(C * EVoigt)) *
geo_->integrationElement(gp.position()) * gp.weight();
254 for (
const auto& [gpIndex, gp] : eps.viewOverIntegrationPoints()) {
255 const auto uVal = uFunction.evaluate(gpIndex);
256 Eigen::Vector<double, Traits::worlddim> fext =
volumeLoad(
geo_->global(gp.position()), lambda);
257 energy -= uVal.dot(fext) *
geo_->integrationElement(gp.position()) * gp.weight();
264 auto element = this->
localView().element();
265 for (
auto&& intersection : intersections(
neumannBoundary->gridView(), element)) {
268 const auto& quadLine = Dune::QuadratureRules<double, myDim - 1>::rule(intersection.type(),
order);
270 for (
const auto& curQuad : quadLine) {
274 const double integrationElement = intersection.geometry().integrationElement(curQuad.position());
277 const auto uVal = uFunction.evaluate(quadPos);
280 auto neumannValue =
neumannBoundaryLoad(intersection.geometry().global(curQuad.position()), lambda);
282 energy -= neumannValue.dot(uVal) * curQuad.weight() * integrationElement;
288 template <
typename ScalarType>
290 const std::optional<
const Eigen::VectorX<ScalarType>>& dx = std::nullopt)
const {
294 using namespace Dune::DerivativeDirections;
295 using namespace Dune;
300 for (
const auto& [gpIndex, gp] : eps.viewOverIntegrationPoints()) {
301 const double intElement =
geo_->integrationElement(gp.position()) * gp.weight();
302 auto stresses = (C * eps.evaluate(gpIndex, on(
gridElement))).eval();
304 const auto bopI = eps.evaluateDerivative(gpIndex, wrt(coeff(i)), on(
gridElement));
305 force.template segment<myDim>(
myDim * i) += bopI.transpose() * stresses * intElement;
311 for (
const auto& [gpIndex, gp] : uFunction.viewOverIntegrationPoints()) {
312 Eigen::Vector<double, Traits::worlddim> fext =
volumeLoad(
geo_->global(gp.position()), lambda);
314 const auto udCi = uFunction.evaluateDerivative(gpIndex, wrt(coeff(i)));
315 force.template segment<myDim>(
myDim * i)
316 -= udCi * fext *
geo_->integrationElement(gp.position()) * gp.weight();
323 auto element = this->
localView().element();
324 for (
auto&& intersection : intersections(
neumannBoundary->gridView(), element)) {
328 const auto& quadLine = Dune::QuadratureRules<double, myDim - 1>::rule(intersection.type(),
order);
330 for (
const auto& curQuad : quadLine) {
333 const double integrationElement = intersection.geometry().integrationElement(curQuad.position());
337 const auto udCi = uFunction.evaluateDerivative(quadPos, wrt(coeff(i)));
340 auto neumannValue =
neumannBoundaryLoad(intersection.geometry().global(curQuad.position()), lambda);
341 force.template segment<myDim>(
myDim * i) -= udCi * neumannValue * curQuad.weight() * integrationElement;
350# error LinearElastic depends on dune-localfefunctions, which is not included
Collection of fallback default functions.
Helper for the autodiff library.
Contains the PowerBasisFE class, which works with a power basis in FlatInterLeaved elements.
Material property functions and conversion utilities.
Definition of the LinearElastic class for finite element mechanics computations.
Header file for material models in Ikarus finite element mechanics.
Definition: simpleassemblers.hh:21
Eigen::Matrix3d planeStressLinearElasticMaterialTangent(double E, double nu)
Computes the plane stress linear elastic material tangent matrix.
Definition: physicshelper.hh:27
Eigen::Matrix< double, 6, 6 > linearElasticMaterialTangent3D(double E, double nu)
Computes the 3D linear elastic material tangent matrix.
Definition: physicshelper.hh:48
Definition: resultevaluators.hh:17
PowerBasisFE class for working with a power basis in FlatInterLeaved elements.
Definition: powerbasisfe.hh:23
const GridElement & gridElement() const
Get the grid element associated with the local view.
Definition: powerbasisfe.hh:78
const LocalView & localView() const
Get the const reference to the local view.
Definition: powerbasisfe.hh:84
Class representing a map of result types to result arrays.
Definition: ferequirements.hh:342
void insertOrAssignResult(ResultType &&resultType, const ResultArray &resultArray)
Insert or assign a result to the map.
Definition: ferequirements.hh:354
Class representing the requirements for obtaining specific results.
Definition: ferequirements.hh:405
const FERequirements & getFERequirements() const
Get the associated finite element requirements.
Definition: ferequirements.hh:535
bool isResultRequested(ResultType &&key) const
Check if a specific result type is requested.
Definition: ferequirements.hh:446
LinearElastic class represents a linear elastic finite element.
Definition: finiteelements/mechanics/linearelastic.hh:44
typename FlatBasis::GridView GridView
Definition: finiteelements/mechanics/linearelastic.hh:55
decltype(std::declval< LocalView >().tree().child(0).finiteElement().localBasis()) LocalBasisType
Definition: finiteelements/mechanics/linearelastic.hh:58
static constexpr int myDim
Definition: finiteelements/mechanics/linearelastic.hh:56
auto materialTangentFunction(const FERequirementType &par) const
Gets the material tangent function for the given FERequirementType.
Definition: finiteelements/mechanics/linearelastic.hh:150
auto calculateScalarImpl(const FERequirementType &par, const std::optional< const Eigen::VectorX< ScalarType > > &dx=std::nullopt) const -> ScalarType
Definition: finiteelements/mechanics/linearelastic.hh:235
FERequirements_ FERequirementType
Definition: finiteelements/mechanics/linearelastic.hh:49
double nu_
Definition: finiteelements/mechanics/linearelastic.hh:229
typename LocalView::Element Element
Definition: finiteelements/mechanics/linearelastic.hh:52
void calculateVector(const FERequirementType &par, typename Traits::template VectorType<> force) const
Calculates the vector force for the given FERequirementType.
Definition: finiteelements/mechanics/linearelastic.hh:168
void calculateVectorImpl(const FERequirementType &par, typename Traits::template VectorType< ScalarType > force, const std::optional< const Eigen::VectorX< ScalarType > > &dx=std::nullopt) const
Definition: finiteelements/mechanics/linearelastic.hh:289
PowerBasisFE< FlatBasis > BaseDisp
Definition: finiteelements/mechanics/linearelastic.hh:48
const BoundaryPatch< GridView > * neumannBoundary
Definition: finiteelements/mechanics/linearelastic.hh:227
void calculateAt(const ResultRequirementsType &req, const Dune::FieldVector< double, Traits::mydim > &local, ResultTypeMap< double > &result) const
Calculates results at a specific local position.
Definition: finiteelements/mechanics/linearelastic.hh:203
Basis_ Basis
Definition: finiteelements/mechanics/linearelastic.hh:46
typename Element::Geometry Geometry
Definition: finiteelements/mechanics/linearelastic.hh:54
static constexpr int worldDim
Definition: finiteelements/mechanics/linearelastic.hh:57
auto displacementFunction(const FERequirementType &par, const std::optional< const Eigen::VectorX< ScalarType > > &dx=std::nullopt) const
Gets the displacement function for the given FERequirementType and optional displacement vector.
Definition: finiteelements/mechanics/linearelastic.hh:111
auto strainFunction(const FERequirementType &par, const std::optional< const Eigen::VectorX< ScalarType > > &dx=std::nullopt) const
Gets the strain function for the given FERequirementType and optional displacement vector.
Definition: finiteelements/mechanics/linearelastic.hh:127
std::function< Eigen::Vector< double, worldDim >(const Dune::FieldVector< double, worldDim > &, const double &)> neumannBoundaryLoad
Definition: finiteelements/mechanics/linearelastic.hh:226
LinearElastic(const Basis &globalBasis, const typename LocalView::Element &element, double emod, double nu, VolumeLoad p_volumeLoad={}, const BoundaryPatch< GridView > *p_neumannBoundary=nullptr, NeumannBoundaryLoad p_neumannBoundaryLoad={})
Constructor for the LinearElastic class.
Definition: finiteelements/mechanics/linearelastic.hh:74
void calculateMatrix(const FERequirementType &par, typename Traits::template MatrixType<> K) const
Calculates the matrix stiffness for the given FERequirementType.
Definition: finiteelements/mechanics/linearelastic.hh:178
int order
Definition: finiteelements/mechanics/linearelastic.hh:231
size_t numberOfNodes
Definition: finiteelements/mechanics/linearelastic.hh:230
Dune::CachedLocalBasis< std::remove_cvref_t< LocalBasisType > > localBasis
Definition: finiteelements/mechanics/linearelastic.hh:222
typename Basis::FlatBasis FlatBasis
Definition: finiteelements/mechanics/linearelastic.hh:47
typename FlatBasis::LocalView LocalView
Definition: finiteelements/mechanics/linearelastic.hh:51
auto materialTangent() const
Gets the material tangent matrix for the linear elastic material.
Definition: finiteelements/mechanics/linearelastic.hh:137
double emod_
Definition: finiteelements/mechanics/linearelastic.hh:228
std::function< Eigen::Vector< double, worldDim >(const Dune::FieldVector< double, worldDim > &, const double &)> volumeLoad
Definition: finiteelements/mechanics/linearelastic.hh:224
std::shared_ptr< const Geometry > geo_
Definition: finiteelements/mechanics/linearelastic.hh:221
double calculateScalar(const FERequirementType &par) const
Calculates the scalar energy for the given FERequirementType.
Definition: finiteelements/mechanics/linearelastic.hh:160
Traits for handling local views.see https://en.wikipedia.org/wiki/Lam%C3%A9_parameters.
Definition: physicshelper.hh:65
static constexpr int worlddim
Dimension of the world space.
Definition: physicshelper.hh:68
static constexpr int mydim
Dimension of the geometry.
Definition: physicshelper.hh:71
Definition: resultevaluators.hh:20
decltype(Dune::Functions::DefaultGlobalBasis(Ikarus::flatPreBasis(std::declval< PreBasis >()))) FlatBasis
The type of the flattened basis.
Definition: utils/basis.hh:36