GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/test/geomechanics/hyperelastic/problem.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 40 43 93.0%
Functions: 5 7 71.4%
Branches: 40 50 80.0%

Line Branch Exec Source
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-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7 #ifndef DUMUX_HYPERELASTICITY_TEST_PROBLEM_HH
8 #define DUMUX_HYPERELASTICITY_TEST_PROBLEM_HH
9
10 #include <dumux/common/boundarytypes.hh>
11 #include <dumux/common/fvproblemwithspatialparams.hh>
12 #include <dumux/common/numeqvector.hh>
13 #include <dumux/common/parameters.hh>
14 #include <dumux/common/properties.hh>
15 #include <dumux/common/math.hh>
16
17 namespace Dumux {
18
19 // This test case is adapted from
20 // https://fenicsproject.org/olddocs/dolfin/1.6.0/python/demo/documented/hyperelasticity/python/documentation.html
21 // using a slightly different material law and finite volumes
22 template<class TypeTag>
23 1 class HyperelasticityProblem : public FVProblemWithSpatialParams<TypeTag>
24 {
25 using ParentType = FVProblemWithSpatialParams<TypeTag>;
26 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
27 using FVElementGeometry = typename GridGeometry::LocalView;
28 using SubControlVolume = typename GridGeometry::SubControlVolume;
29 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
30 using GridView = typename GridGeometry::GridView;
31 using Element = typename GridView::template Codim<0>::Entity;
32 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
33 using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
34 using NumEqVector = Dumux::NumEqVector<PrimaryVariables>;
35 using BoundaryTypes = Dumux::BoundaryTypes<GetPropType<TypeTag, Properties::ModelTraits>::numEq()>;
36 static constexpr int dimWorld = GridView::dimensionworld;
37 static constexpr int dim = GridView::dimension;
38 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
39 using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices;
40 using Tensor = Dune::FieldMatrix<Scalar, dim, dim>;
41
42 public:
43 1 HyperelasticityProblem(std::shared_ptr<const GridGeometry> gridGeometry)
44
5/14
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
3 : ParentType(gridGeometry)
45 1 {}
46
47 62016 BoundaryTypes boundaryTypesAtPos(const GlobalPosition &globalPos) const
48 {
49 62016 BoundaryTypes values;
50
20/20
✓ Branch 0 taken 53824 times.
✓ Branch 1 taken 8192 times.
✓ Branch 2 taken 53824 times.
✓ Branch 3 taken 8192 times.
✓ Branch 4 taken 53824 times.
✓ Branch 5 taken 8192 times.
✓ Branch 6 taken 53824 times.
✓ Branch 7 taken 8192 times.
✓ Branch 8 taken 53824 times.
✓ Branch 9 taken 8192 times.
✓ Branch 10 taken 8192 times.
✓ Branch 11 taken 45632 times.
✓ Branch 12 taken 8192 times.
✓ Branch 13 taken 45632 times.
✓ Branch 14 taken 8192 times.
✓ Branch 15 taken 45632 times.
✓ Branch 16 taken 8192 times.
✓ Branch 17 taken 45632 times.
✓ Branch 18 taken 8192 times.
✓ Branch 19 taken 45632 times.
310080 if (globalPos[0] < this->gridGeometry().bBoxMin()[0] + eps_ || globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_)
51 values.setAllDirichlet();
52 62016 return values;
53 }
54
55 template<class ElementVolumeVariables, class ElementFluxVariablesCache>
56 NumEqVector neumann(const Element& element,
57 const FVElementGeometry& fvGeometry,
58 const ElementVolumeVariables& elemVolVars,
59 const ElementFluxVariablesCache& elemFluxVarsCache,
60 const SubControlVolumeFace& scvf) const
61 {
62 return {0.1, 0.0, 0.0};
63 }
64
65 16384 PrimaryVariables dirichletAtPos(const GlobalPosition& globalPos) const
66 {
67
10/10
✓ Branch 0 taken 8192 times.
✓ Branch 1 taken 8192 times.
✓ Branch 2 taken 8192 times.
✓ Branch 3 taken 8192 times.
✓ Branch 4 taken 8192 times.
✓ Branch 5 taken 8192 times.
✓ Branch 6 taken 8192 times.
✓ Branch 7 taken 8192 times.
✓ Branch 8 taken 8192 times.
✓ Branch 9 taken 8192 times.
81920 if (globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_)
68 8192 return {0.0, 0.0, 0.0};
69
70 8192 PrimaryVariables values(0.0);
71 8192 const auto y = globalPos[1];
72 8192 const auto z = globalPos[2];
73 8192 values[0] = 0.0;
74 8192 values[1] = 0.5*(0.5 + (y-0.5)*std::cos(M_PI/3.0) - (z-0.5)*std::sin(M_PI/3.0) - y);
75 8192 values[2] = 0.5*(0.5 + (y-0.5)*std::sin(M_PI/3.0) + (z-0.5)*std::cos(M_PI/3.0) - z);
76 8192 return values;
77 }
78
79 NumEqVector sourceAtPos(const GlobalPosition& globalPos) const
80 9830400 { return {0.0, -0.5, 0.0}; }
81
82 // Some Neo-Hookean material
83 // from Simo and Armero, 1992 (https://doi.org/10.1002/nme.1620330705) Eq. 77/78
84 // ψ = K(0.5(J*J - 1) - ln J) + 0.5µ (J^(-2/3) tr(C) - 3)
85 // P = 2F∂ψ/∂C = µ J^(-2/3) (F - 1/3*tr(C)*F^-T) + K*(J*J - 1)F^-T
86 14745600 Tensor firstPiolaKirchhoffStressTensor(Tensor F) const
87 {
88 // invariants
89 14745600 const auto J = F.determinant();
90 14745600 const auto Jm23 = std::pow(J, -2.0/3.0);
91 14745600 auto trC = 0.0;
92
2/2
✓ Branch 0 taken 44236800 times.
✓ Branch 1 taken 14745600 times.
58982400 for (int i = 0; i < dimWorld; ++i)
93
2/2
✓ Branch 0 taken 132710400 times.
✓ Branch 1 taken 44236800 times.
176947200 for (int j = 0; j < dimWorld; ++j)
94 663552000 trC += F[i][j]*F[i][j];
95
96 // inverse transpose of deformation gradient
97 14745600 const auto invFT = [&](){
98 14745600 auto invFT = F;
99
1/2
✓ Branch 0 taken 14745600 times.
✗ Branch 1 not taken.
14745600 if (J != 0.0)
100 14745600 invFT.invert();
101 14745600 return transpose(invFT);
102 14745600 }();
103
104 // material parameters
105 14745600 const auto mu = this->spatialParams().shearModulus();
106 14745600 const auto K = this->spatialParams().bulkModulus();
107
108 // assemble 1st Piola Kirchhoff stress tensor
109 14745600 Tensor P(0.0);
110 14745600 P.axpy(K*(J*J - 1), invFT);
111 14745600 auto& FTerm = F;
112 14745600 FTerm.axpy(-1.0/3.0*trC, invFT);
113 14745600 P.axpy(mu*Jm23, FTerm);
114 14745600 return P;
115 }
116
117 private:
118 static constexpr Scalar eps_ = 1e-7;
119 };
120
121 } // end namespace Dumux
122
123 #endif
124