version 3.11-dev
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 <dune/common/fvector.hh>
16#include <dune/common/fmatrix.hh>
17#include <dune/common/std/type_traits.hh>
18#include <dune/common/exceptions.hh>
19
20#include <dumux/common/math.hh>
25
26namespace Dumux {
27
28#ifndef DOXYGEN
29namespace Detail::Hyperelastic {
30// helper struct detecting if the user-defined problem class has a solidDensity method
31template <typename T, typename ...Ts>
32using SolidDensityDetector = decltype(std::declval<T>().solidDensity(std::declval<Ts>()...));
33
34template<class T, typename ...Args>
35static constexpr bool hasSolidDensity()
36{ return Dune::Std::is_detected<SolidDensityDetector, T, Args...>::value; }
37
38// helper struct detecting if the user-defined problem class has a acceleration method
39template <typename T, typename ...Ts>
40using AccelerationDetector = decltype(std::declval<T>().acceleration(std::declval<Ts>()...));
41
42template<class T, typename ...Args>
43static constexpr bool hasAcceleration()
44{ return Dune::Std::is_detected<AccelerationDetector, T, Args...>::value; }
45} // end namespace Detail::Hyperelastic
46#endif
47
52template<class TypeTag>
55{
61 using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView;
62 using ElementFluxVariablesCache = typename GetPropType<TypeTag, Properties::GridFluxVariablesCache>::LocalView;
64 using FVElementGeometry = typename GridGeometry::LocalView;
65 using SubControlVolume = typename GridGeometry::SubControlVolume;
66 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
67 using GridView = typename GridGeometry::GridView;
68 using Element = typename GridView::template Codim<0>::Entity;
69 using Extrusion = Extrusion_t<GridGeometry>;
71 using Indices = typename ModelTraits::Indices;
72 static constexpr int dimWorld = GridView::dimensionworld;
73public:
74 using ParentType::ParentType;
75 using ElementResidualVector = typename ParentType::ElementResidualVector;
76
77 using ParentType::evalStorage;
78
83 const Problem& problem,
84 const Element& element,
85 const FVElementGeometry& fvGeometry,
86 const ElementVolumeVariables& prevElemVolVars,
87 const ElementVolumeVariables& curElemVolVars,
88 const SubControlVolume& scv) const
89 {
90 const auto& curVolVars = curElemVolVars[scv];
91
92 if constexpr (Detail::Hyperelastic::hasSolidDensity<Problem, const Element&, const SubControlVolume&>()
93 && Detail::Hyperelastic::hasAcceleration<Problem, const Element&, const SubControlVolume&, Scalar, decltype(curVolVars.displacement())>())
94 {
95 const auto& curVolVars = curElemVolVars[scv];
96 NumEqVector storage = problem.solidDensity(element, scv)*problem.acceleration(
97 element, scv, this->timeLoop().timeStepSize(), curVolVars.displacement()
98 );
99 storage *= curVolVars.extrusionFactor()*Extrusion::volume(fvGeometry, scv);
100 residual[scv.localDofIndex()] += storage;
101 }
102 else
103 DUNE_THROW(Dune::InvalidStateException,
104 "Problem class must implement solidDensity and acceleration"
105 " methods to evaluate storage term"
106 );
107 }
108
113 NumEqVector computeFlux(const Problem& problem,
114 const Element& element,
115 const FVElementGeometry& fvGeometry,
116 const ElementVolumeVariables& elemVolVars,
117 const SubControlVolumeFace& scvf,
118 const ElementFluxVariablesCache& elemFluxVarsCache) const
119 {
120 // the deformation gradient F = grad(d) + I
121 const auto F = [&]()
122 {
123 const auto& fluxVarCache = elemFluxVarsCache[scvf];
124 Dune::FieldMatrix<Scalar, dimWorld, dimWorld> F(0.0);
125 for (const auto& scv : scvs(fvGeometry))
126 {
127 const auto& volVars = elemVolVars[scv];
128 for (int dir = 0; dir < dimWorld; ++dir)
129 F[dir].axpy(volVars.displacement(dir), fluxVarCache.gradN(scv.indexInElement()));
130 }
131
132 for (int dir = 0; dir < dimWorld; ++dir)
133 F[dir][dir] += 1;
134
135 return F;
136 }();
137
138 // numerical flux ==> -P*n*dA
139 NumEqVector flux(0.0);
140
141 // problem implements the constitutive law P=P(F)
142 const auto P = problem.firstPiolaKirchhoffStressTensor(F);
143 P.mv(scvf.unitOuterNormal(), flux);
144 flux *= -scvf.area();
145 return flux;
146 }
147
148 NumEqVector computeSource(const Problem& problem,
149 const Element& element,
150 const FVElementGeometry& fvGeometry,
151 const ElementVolumeVariables& elemVolVars,
152 const SubControlVolume& scv) const
153 {
154 // loading and body forces are implemented in the problem
155 return ParentType::computeSource(problem, element, fvGeometry, elemVolVars, scv);
156 }
157};
158
159} // end namespace Dumux
160
161#endif
Local residual for the hyperelastic model.
Definition: solidmechanics/hyperelastic/localresidual.hh:55
typename ParentType::ElementResidualVector ElementResidualVector
Definition: solidmechanics/hyperelastic/localresidual.hh:75
NumEqVector computeSource(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolume &scv) const
Definition: solidmechanics/hyperelastic/localresidual.hh:148
void evalStorage(ElementResidualVector &residual, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &prevElemVolVars, const ElementVolumeVariables &curElemVolVars, const SubControlVolume &scv) const
Evaluate the storage contribution to the residual: rho*d^2u/dt^2.
Definition: solidmechanics/hyperelastic/localresidual.hh:82
NumEqVector computeFlux(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolumeFace &scvf, const ElementFluxVariablesCache &elemFluxVarsCache) const
Evaluate the fluxes over a face of a sub control volume flux: -div(P) where P is the 1st Piola-Kircho...
Definition: solidmechanics/hyperelastic/localresidual.hh:113
Defines all properties used in Dumux.
The default local operator than can be specialized for each discretization scheme.
Helper classes to compute the integration elements.
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
auto volume(const Geometry &geo, unsigned int integrationOrder=4)
The volume of a given geometry.
Definition: volume.hh:159
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:296
Define some often used mathematical functions.
Definition: adapt.hh:17
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:166
typename Detail::DiscretizationDefaultLocalOperator< TypeTag >::type DiscretizationDefaultLocalOperator
Definition: defaultlocaloperator.hh:27
A helper to deduce a vector with the same size as numbers of equations.