12#ifndef DUMUX_SOLIDMECHANICS_HYPERELASTIC_LOCAL_RESIDUAL_HH
13#define DUMUX_SOLIDMECHANICS_HYPERELASTIC_LOCAL_RESIDUAL_HH
18#include <dune/common/fmatrix.hh>
19#include <dune/common/fvector.hh>
23#include <dumux/common/typetraits/localdofs_.hh>
56template<
class TypeTag>
64 using ElementDiscretization =
typename GridDiscretization::LocalView;
65 using GridView =
typename GridDiscretization::GridView;
66 using Element =
typename GridView::template Codim<0>::Entity;
68 using ElementVariables =
typename GridVariables::GridVariablesCache::LocalView;
70 using LocalDof = std::ranges::range_value_t<decltype(localDofs(std::declval<const ElementDiscretization&>()))>;
72 static constexpr int dim = GridView::dimension;
73 using Tensor = Dune::FieldMatrix<Scalar, dim, dim>;
74 using Vector = Dune::FieldVector<Scalar, dim>;
76 static constexpr bool hasInertia =
requires(
const Problem& p,
const ElementDiscretization& ed,
77 const ElementVariables& ev,
const LocalDof& localDof)
78 { p.acceleration(ed, ev, localDof); };
80 static constexpr bool hasVelocity =
requires(
const Problem& p,
const ElementDiscretization& ed,
81 const ElementVariables& ev,
const LocalDof& localDof)
82 { p.velocity(ed, ev, localDof); };
85 using ParentType::ParentType;
88 template<
class SubControlVolume>
89 NumEqVector
storageIntegral(
const ElementDiscretization&,
const ElementVariables&,
90 const SubControlVolume&,
bool)
const
94 template<
class SubControlVolume>
96 const ElementVariables& elemVars,
97 const SubControlVolume& scv)
const
99 const auto& problem = this->asImp().problem();
100 NumEqVector source(0.0);
103 const auto& ipData = qpData.ipData();
104 NumEqVector value = problem.source(elemDisc, elemVars, ipData);
105 if constexpr (hasInertia)
107 const LocalDof localDof(scv.localDofIndex(), scv.dofIndex(), scv.elementIndex());
108 value.axpy(-problem.solidDensity(elemDisc, ipData), problem.acceleration(elemDisc, elemVars, localDof));
110 source.axpy(qpData.weight(), value);
112 source *= elemVars[scv].extrusionFactor();
117 template<
class SubControlVolumeFace>
119 const ElementVariables& elemVars,
120 const SubControlVolumeFace& scvf)
const
122 const auto& problem = this->asImp().problem();
123 NumEqVector flux(0.0);
126 const auto& ipData = qpData.ipData();
127 const auto P = stress_(problem, elemDisc, elemVars, cache(elemVars, ipData), ipData);
129 P.mv(scvf.unitOuterNormal(), PN);
130 flux.axpy(-qpData.weight(), PN);
132 flux *= elemVars[elemDisc.scv(scvf.insideScvIdx())].extrusionFactor();
138 const Problem& problem,
139 const Element& element,
140 const ElementDiscretization& elemDisc,
141 const ElementVariables& elemVars)
const
143 if constexpr (Detail::LocalDofs::hasNonCVLocalDofsInterface<ElementDiscretization>())
145 if (std::ranges::empty(nonCVLocalDofs(elemDisc)))
150 const auto& ipData = qpData.ipData();
151 const auto& ipCache = cache(elemVars, ipData);
152 const auto P = stress_(problem, elemDisc, elemVars, ipCache, ipData);
153 const auto& shapeValues = ipCache.shapeValues();
155 NumEqVector bodyForce = problem.source(elemDisc, elemVars, ipData);
156 if constexpr (hasInertia)
158 const auto rho = problem.solidDensity(elemDisc, ipData);
159 for (
const auto& localDof :
localDofs(elemDisc))
160 bodyForce.axpy(-rho*shapeValues[localDof.index()][0], problem.acceleration(elemDisc, elemVars, localDof));
163 for (
const auto& localDof : nonCVLocalDofs(elemDisc))
165 const auto idx = localDof.index();
167 P.mv(ipCache.gradN(idx), value);
168 value.axpy(-shapeValues[idx][0], bodyForce);
169 residual[idx].axpy(qpData.weight(), value);
176 template<
class ShapeData,
class IpData>
177 Tensor stress_(
const Problem& problem,
178 const ElementDiscretization& elemDisc,
179 const ElementVariables& elemVars,
180 const ShapeData& shapeData,
181 const IpData& ipData)
const
184 for (
const auto& localDof :
localDofs(elemDisc))
185 for (
int i = 0; i < dim; ++i)
186 F[i].axpy(elemVars[localDof].displacement(i), shapeData.gradN(localDof.index()));
187 for (
int i = 0; i < dim; ++i)
190 if constexpr (hasVelocity)
193 for (
const auto& localDof :
localDofs(elemDisc))
195 const auto v = problem.velocity(elemDisc, elemVars, localDof);
196 for (
int i = 0; i < dim; ++i)
197 Fdot[i].axpy(v[i], shapeData.gradN(localDof.index()));
199 return problem.firstPiolaKirchhoffStressTensor(F, Fdot, elemDisc, ipData);
201 else if constexpr (
requires { problem.firstPiolaKirchhoffStressTensor(F, elemDisc, ipData); })
202 return problem.firstPiolaKirchhoffStressTensor(F, elemDisc, ipData);
204 return problem.firstPiolaKirchhoffStressTensor(F);
Local residual of the hyperelastic model.
Definition solidmechanics/hyperelastic/localresidual.hh:59
NumEqVector fluxIntegral(const ElementDiscretization &elemDisc, const ElementVariables &elemVars, const SubControlVolumeFace &scvf) const
Stress flux over a control volume face.
Definition solidmechanics/hyperelastic/localresidual.hh:118
NumEqVector sourceIntegral(const ElementDiscretization &elemDisc, const ElementVariables &elemVars, const SubControlVolume &scv) const
Body force minus inertia (lumped) over a control volume.
Definition solidmechanics/hyperelastic/localresidual.hh:95
typename ParentType::ElementResidualVector ElementResidualVector
Definition solidmechanics/hyperelastic/localresidual.hh:86
NumEqVector storageIntegral(const ElementDiscretization &, const ElementVariables &, const SubControlVolume &, bool) const
Definition solidmechanics/hyperelastic/localresidual.hh:89
void addToElementFluxAndSourceResidual(ElementResidualVector &residual, const Problem &problem, const Element &element, const ElementDiscretization &elemDisc, const ElementVariables &elemVars) const
Galerkin terms of the dofs without control volume.
Definition solidmechanics/hyperelastic/localresidual.hh:137
Defines all properties used in Dumux.
The default local operator than can be specialized for each discretization scheme.
typename NumEqVectorTraits< PrimaryVariables >::type NumEqVector
A vector with the same size as numbers of equations This is the default implementation and has to be ...
Definition numeqvector.hh:34
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition propertysystem.hh:296
auto quadratureRule(const FVElementGeometry &fvGeometry, const typename FVElementGeometry::SubControlVolume &scv, QuadratureRules::MidpointQuadrature)
Midpoint quadrature for scv.
Definition quadraturerules.hh:159
typename Detail::DiscretizationDefaultLocalOperator< TypeTag >::type DiscretizationDefaultLocalOperator
Definition defaultlocaloperator.hh:26
auto localDofs(const FVElementGeometry &fvGeometry)
range over local dofs
Definition localdof.hh:50
A helper to deduce a vector with the same size as numbers of equations.
Quadrature rules over sub-control volumes and sub-control volume faces.