version 3.11-dev
Loading...
Searching...
No Matches
solidmechanics/hyperelastic/localresidual.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_SOLIDMECHANICS_HYPERELASTIC_LOCAL_RESIDUAL_HH
13#define DUMUX_SOLIDMECHANICS_HYPERELASTIC_LOCAL_RESIDUAL_HH
14
15#include <ranges>
16#include <utility>
17
18#include <dune/common/fmatrix.hh>
19#include <dune/common/fvector.hh>
20
23#include <dumux/common/typetraits/localdofs_.hh>
26
27namespace Dumux {
28
56template<class TypeTag>
59{
63 using GridDiscretization = GetPropType<TypeTag, Properties::GridGeometry>;
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&>()))>;
71
72 static constexpr int dim = GridView::dimension;
73 using Tensor = Dune::FieldMatrix<Scalar, dim, dim>;
74 using Vector = Dune::FieldVector<Scalar, dim>;
75
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); };
79
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); };
83
84public:
85 using ParentType::ParentType;
86 using ElementResidualVector = typename ParentType::ElementResidualVector;
87
88 template<class SubControlVolume>
89 NumEqVector storageIntegral(const ElementDiscretization&, const ElementVariables&,
90 const SubControlVolume&, bool) const
91 { return NumEqVector(0.0); }
92
94 template<class SubControlVolume>
95 NumEqVector sourceIntegral(const ElementDiscretization& elemDisc,
96 const ElementVariables& elemVars,
97 const SubControlVolume& scv) const
98 {
99 const auto& problem = this->asImp().problem();
100 NumEqVector source(0.0);
101 for (const auto& qpData : CVFE::quadratureRule(elemDisc, scv))
102 {
103 const auto& ipData = qpData.ipData();
104 NumEqVector value = problem.source(elemDisc, elemVars, ipData);
105 if constexpr (hasInertia)
106 {
107 const LocalDof localDof(scv.localDofIndex(), scv.dofIndex(), scv.elementIndex());
108 value.axpy(-problem.solidDensity(elemDisc, ipData), problem.acceleration(elemDisc, elemVars, localDof));
109 }
110 source.axpy(qpData.weight(), value);
111 }
112 source *= elemVars[scv].extrusionFactor();
113 return source;
114 }
115
117 template<class SubControlVolumeFace>
118 NumEqVector fluxIntegral(const ElementDiscretization& elemDisc,
119 const ElementVariables& elemVars,
120 const SubControlVolumeFace& scvf) const
121 {
122 const auto& problem = this->asImp().problem();
123 NumEqVector flux(0.0);
124 for (const auto& qpData : CVFE::quadratureRule(elemDisc, scvf))
125 {
126 const auto& ipData = qpData.ipData();
127 const auto P = stress_(problem, elemDisc, elemVars, cache(elemVars, ipData), ipData);
128 Vector PN;
129 P.mv(scvf.unitOuterNormal(), PN);
130 flux.axpy(-qpData.weight(), PN);
131 }
132 flux *= elemVars[elemDisc.scv(scvf.insideScvIdx())].extrusionFactor();
133 return flux;
134 }
135
138 const Problem& problem,
139 const Element& element,
140 const ElementDiscretization& elemDisc,
141 const ElementVariables& elemVars) const
142 {
143 if constexpr (Detail::LocalDofs::hasNonCVLocalDofsInterface<ElementDiscretization>())
144 {
145 if (std::ranges::empty(nonCVLocalDofs(elemDisc)))
146 return;
147
148 for (const auto& qpData : CVFE::quadratureRule(elemDisc, element))
149 {
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();
154
155 NumEqVector bodyForce = problem.source(elemDisc, elemVars, ipData);
156 if constexpr (hasInertia)
157 {
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));
161 }
162
163 for (const auto& localDof : nonCVLocalDofs(elemDisc))
164 {
165 const auto idx = localDof.index();
166 Vector value;
167 P.mv(ipCache.gradN(idx), value);
168 value.axpy(-shapeValues[idx][0], bodyForce);
169 residual[idx].axpy(qpData.weight(), value);
170 }
171 }
172 }
173 }
174
175private:
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
182 {
183 Tensor F(0.0);
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)
188 F[i][i] += 1.0;
189
190 if constexpr (hasVelocity)
191 {
192 Tensor Fdot(0.0);
193 for (const auto& localDof : localDofs(elemDisc))
194 {
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()));
198 }
199 return problem.firstPiolaKirchhoffStressTensor(F, Fdot, elemDisc, ipData);
200 }
201 else if constexpr (requires { problem.firstPiolaKirchhoffStressTensor(F, elemDisc, ipData); })
202 return problem.firstPiolaKirchhoffStressTensor(F, elemDisc, ipData);
203 else
204 return problem.firstPiolaKirchhoffStressTensor(F);
205 }
206};
207
208} // end namespace Dumux
209
210#endif
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
Definition adapt.hh:17
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.