version 3.11-dev
Loading...
Searching...
No Matches
solidmechanics/elastic/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//
13#ifndef DUMUX_SOLIDMECHANICS_ELASTIC_LOCAL_RESIDUAL_HH
14#define DUMUX_SOLIDMECHANICS_ELASTIC_LOCAL_RESIDUAL_HH
15
16#include <ranges>
17
18#include <dune/common/fmatrix.hh>
19
23#include <dumux/common/typetraits/localdofs_.hh>
26
27namespace Dumux {
28
43template<class TypeTag>
46{
49
50 using GridView = typename GridGeometry::GridView;
51 using Element = typename GridView::template Codim<0>::Entity;
52
55 using FVElementGeometry = typename GridGeometry::LocalView;
57
58 // class assembling the stress tensor
60
61 static constexpr int dim = GridView::dimension;
62 static constexpr int dimWorld = GridView::dimensionworld;
64 using Tensor = Dune::FieldMatrix<Scalar, dim, dimWorld>;
65
66public:
67 using ParentType::ParentType;
68
77 template<class SubControlVolume, class VolumeVariables>
78 NumEqVector computeStorage(const Problem& problem,
79 const SubControlVolume& scv,
80 const VolumeVariables& volVars) const
81 {
82 return NumEqVector(0.0);
83 }
84
96 template<class ElementVolumeVariables, class SubControlVolumeFace, class ElementFluxVariablesCache>
97 NumEqVector computeFlux(const Problem& problem,
98 const Element& element,
99 const FVElementGeometry& fvGeometry,
100 const ElementVolumeVariables& elemVolVars,
101 const SubControlVolumeFace& scvf,
102 const ElementFluxVariablesCache& elemFluxVarsCache) const
103 {
104 // obtain force on the face from stress type
105 return StressType::force(problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache);
106 }
107
121 template<class ElementVolumeVariables, class SubControlVolume>
122 NumEqVector computeSource(const Problem& problem,
123 const Element& element,
124 const FVElementGeometry& fvGeometry,
125 const ElementVolumeVariables& elemVolVars,
126 const SubControlVolume &scv) const
127 {
128 NumEqVector source(0.0);
129
130 // add contributions from volume flux sources
131 source += problem.source(element, fvGeometry, elemVolVars, scv);
132
133 // add contribution from possible point sources
134 source += problem.scvPointSources(element, fvGeometry, elemVolVars, scv);
135
136 // maybe add gravitational acceleration
137 static const bool gravity = getParamFromGroup<bool>(problem.paramGroup(), "Problem.EnableGravity");
138 if (gravity)
139 {
140 const auto& g = problem.spatialParams().gravity(scv.center());
141 for (int dir = 0; dir < GridView::dimensionworld; ++dir)
142 source[Indices::momentum(dir)] += elemVolVars[scv].solidDensity()*g[dir];
143 }
144
145 return source;
146 }
147
148 template<class ElementDiscretization, class ElementVariables, class Scv>
149 NumEqVector storageIntegral(const ElementDiscretization&, const ElementVariables&, const Scv&, bool) const
150 { return NumEqVector(0.0); }
151
153 template<class ElementDiscretization, class ElementVariables, class Scv>
154 NumEqVector sourceIntegral(const ElementDiscretization& elemDisc,
155 const ElementVariables& elemVars,
156 const Scv& scv) const
157 {
158 const auto& problem = this->asImp().problem();
159 NumEqVector source(0.0);
160 for (const auto& qpData : CVFE::quadratureRule(elemDisc, scv))
161 source.axpy(qpData.weight(), problem.source(elemDisc, elemVars, qpData.ipData()));
162 source *= elemVars[scv].extrusionFactor();
163
164 const auto& pointSources = problem.pointSources();
165 if (!pointSources.empty())
166 for (const auto& context : pointSources.contexts(elemDisc, scv))
167 source += pointSources.eval(elemDisc, elemVars, context);
168
169 return source;
170 }
171
173 template<class ElementDiscretization, class ElementVariables, class Scvf>
174 NumEqVector fluxIntegral(const ElementDiscretization& elemDisc,
175 const ElementVariables& elemVars,
176 const Scvf& scvf) const
177 {
178 const auto& problem = this->asImp().problem();
179 NumEqVector flux(0.0);
180 for (const auto& qpData : CVFE::quadratureRule(elemDisc, scvf))
181 {
182 const auto& ipData = qpData.ipData();
183 const auto sigma = stressTensor_(problem, elemDisc, elemVars, ipData);
184 for (int dir = 0; dir < dim; ++dir)
185 flux[Indices::momentum(dir)] -= qpData.weight()*(sigma[dir]*scvf.unitOuterNormal());
186 }
187 flux *= elemVars[elemDisc.scv(scvf.insideScvIdx())].extrusionFactor();
188 return flux;
189 }
190
195 template<class ElementResidualVector, class ElementDiscretization, class ElementVariables>
196 void addToElementFluxAndSourceResidual(ElementResidualVector& residual,
197 const Problem& problem,
198 const Element& element,
199 const ElementDiscretization& elemDisc,
200 const ElementVariables& elemVars) const
201 {
202 if constexpr (Detail::LocalDofs::hasNonCVLocalDofsInterface<ElementDiscretization>())
203 {
204 if (std::ranges::empty(nonCVLocalDofs(elemDisc)))
205 return;
206
207 for (const auto& qpData : CVFE::quadratureRule(elemDisc, element))
208 {
209 const auto& ipData = qpData.ipData();
210 const auto& ipCache = cache(elemVars, ipData);
211 const auto sigma = stressTensor_(problem, elemDisc, elemVars, ipData);
212 const auto bodyForce = problem.source(elemDisc, elemVars, ipData);
213 const auto& shapeValues = ipCache.shapeValues();
214 for (const auto& localDof : nonCVLocalDofs(elemDisc))
215 {
216 const auto idx = localDof.index();
217 for (int dir = 0; dir < dim; ++dir)
218 {
219 const auto eqIdx = Indices::momentum(dir);
220 residual[idx][eqIdx] += qpData.weight()*(sigma[dir]*ipCache.gradN(idx)
221 - shapeValues[idx][0]*bodyForce[eqIdx]);
222 }
223 }
224 }
225 }
226 }
227
228private:
230 template<class ElementDiscretization, class ElementVariables, class IpData>
231 Tensor stressTensor_(const Problem& problem,
232 const ElementDiscretization& elemDisc,
233 const ElementVariables& elemVars,
234 const IpData& ipData) const
235 {
236 const auto& ipCache = cache(elemVars, ipData);
237 Tensor gradU(0.0);
238 for (const auto& localDof : localDofs(elemDisc))
239 for (int dir = 0; dir < dim; ++dir)
240 gradU[dir].axpy(elemVars[localDof].displacement(dir), ipCache.gradN(localDof.index()));
241
242 const auto& lame = problem.spatialParams().lameParams(elemDisc, ipData);
243 Tensor sigma(0.0);
244 Scalar trace = 0.0;
245 for (int i = 0; i < dim; ++i)
246 trace += gradU[i][i];
247 for (int i = 0; i < dim; ++i)
248 {
249 for (int j = 0; j < dimWorld; ++j)
250 sigma[i][j] = lame.mu()*(gradU[i][j] + gradU[j][i]);
251 sigma[i][i] += lame.lambda()*trace;
252 }
253 return sigma;
254 }
255};
256
257} // end namespace Dumux
258
259#endif
Element-wise calculation of the local residual for problems using the elastic model considering linea...
Definition solidmechanics/elastic/localresidual.hh:46
NumEqVector storageIntegral(const ElementDiscretization &, const ElementVariables &, const Scv &, bool) const
The storage term is zero for quasi-static elasticity (assembly with local degrees of freedom).
Definition solidmechanics/elastic/localresidual.hh:149
NumEqVector sourceIntegral(const ElementDiscretization &elemDisc, const ElementVariables &elemVars, const Scv &scv) const
The body force over a control volume (assembly with local degrees of freedom).
Definition solidmechanics/elastic/localresidual.hh:154
NumEqVector computeStorage(const Problem &problem, const SubControlVolume &scv, const VolumeVariables &volVars) const
For the elastic model the storage term is zero since we neglect inertia forces.
Definition solidmechanics/elastic/localresidual.hh:78
NumEqVector computeSource(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolume &scv) const
Calculate the source term of the equation.
Definition solidmechanics/elastic/localresidual.hh:122
NumEqVector fluxIntegral(const ElementDiscretization &elemDisc, const ElementVariables &elemVars, const Scvf &scvf) const
The stress flux over a control volume face (assembly with local degrees of freedom).
Definition solidmechanics/elastic/localresidual.hh:174
NumEqVector computeFlux(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolumeFace &scvf, const ElementFluxVariablesCache &elemFluxVarsCache) const
Evaluates the force in all grid directions acting on a face of a sub-control volume.
Definition solidmechanics/elastic/localresidual.hh:97
void addToElementFluxAndSourceResidual(ElementResidualVector &residual, const Problem &problem, const Element &element, const ElementDiscretization &elemDisc, const ElementVariables &elemVars) const
The Galerkin terms of the degrees of freedom without control volume (assembly with local degrees of ...
Definition solidmechanics/elastic/localresidual.hh:196
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
Dune::DenseMatrix< MatrixType >::field_type trace(const Dune::DenseMatrix< MatrixType > &M)
Trace of a dense matrix.
Definition math.hh:800
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition parameters.hh:168
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.
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
Quadrature rules over sub-control volumes and sub-control volume faces.