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
114 const auto& pointSources = problem.pointSources();
115 if (!pointSources.empty())
116 for (const auto& context : pointSources.contexts(elemDisc, scv))
117 source += pointSources.eval(elemDisc, elemVars, context);
118
119 return source;
120 }
121
123 template<class SubControlVolumeFace>
124 NumEqVector fluxIntegral(const ElementDiscretization& elemDisc,
125 const ElementVariables& elemVars,
126 const SubControlVolumeFace& scvf) const
127 {
128 const auto& problem = this->asImp().problem();
129 NumEqVector flux(0.0);
130 for (const auto& qpData : CVFE::quadratureRule(elemDisc, scvf))
131 {
132 const auto& ipData = qpData.ipData();
133 const auto P = stress_(problem, elemDisc, elemVars, cache(elemVars, ipData), ipData);
134 Vector PN;
135 P.mv(scvf.unitOuterNormal(), PN);
136 flux.axpy(-qpData.weight(), PN);
137 }
138 flux *= elemVars[elemDisc.scv(scvf.insideScvIdx())].extrusionFactor();
139 return flux;
140 }
141
144 const Problem& problem,
145 const Element& element,
146 const ElementDiscretization& elemDisc,
147 const ElementVariables& elemVars) const
148 {
149 if constexpr (Detail::LocalDofs::hasNonCVLocalDofsInterface<ElementDiscretization>())
150 {
151 if (std::ranges::empty(nonCVLocalDofs(elemDisc)))
152 return;
153
154 for (const auto& qpData : CVFE::quadratureRule(elemDisc, element))
155 {
156 const auto& ipData = qpData.ipData();
157 const auto& ipCache = cache(elemVars, ipData);
158 const auto P = stress_(problem, elemDisc, elemVars, ipCache, ipData);
159 const auto& shapeValues = ipCache.shapeValues();
160
161 NumEqVector bodyForce = problem.source(elemDisc, elemVars, ipData);
162 if constexpr (hasInertia)
163 {
164 const auto rho = problem.solidDensity(elemDisc, ipData);
165 for (const auto& localDof : localDofs(elemDisc))
166 bodyForce.axpy(-rho*shapeValues[localDof.index()][0], problem.acceleration(elemDisc, elemVars, localDof));
167 }
168
169 for (const auto& localDof : nonCVLocalDofs(elemDisc))
170 {
171 const auto idx = localDof.index();
172 Vector value;
173 P.mv(ipCache.gradN(idx), value);
174 value.axpy(-shapeValues[idx][0], bodyForce);
175 residual[idx].axpy(qpData.weight(), value);
176 }
177 }
178 }
179 }
180
181private:
182 template<class ShapeData, class IpData>
183 Tensor stress_(const Problem& problem,
184 const ElementDiscretization& elemDisc,
185 const ElementVariables& elemVars,
186 const ShapeData& shapeData,
187 const IpData& ipData) const
188 {
189 Tensor F(0.0);
190 for (const auto& localDof : localDofs(elemDisc))
191 for (int i = 0; i < dim; ++i)
192 F[i].axpy(elemVars[localDof].displacement(i), shapeData.gradN(localDof.index()));
193 for (int i = 0; i < dim; ++i)
194 F[i][i] += 1.0;
195
196 if constexpr (hasVelocity)
197 {
198 Tensor Fdot(0.0);
199 for (const auto& localDof : localDofs(elemDisc))
200 {
201 const auto v = problem.velocity(elemDisc, elemVars, localDof);
202 for (int i = 0; i < dim; ++i)
203 Fdot[i].axpy(v[i], shapeData.gradN(localDof.index()));
204 }
205 return problem.firstPiolaKirchhoffStressTensor(F, Fdot, elemDisc, ipData);
206 }
207 else if constexpr (requires { problem.firstPiolaKirchhoffStressTensor(F, elemDisc, ipData); })
208 return problem.firstPiolaKirchhoffStressTensor(F, elemDisc, ipData);
209 else
210 return problem.firstPiolaKirchhoffStressTensor(F);
211 }
212};
213
214} // end namespace Dumux
215
216#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:124
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:143
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:171
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.