GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/test/porousmediumflow/1p/convergence/discretesolution/problem.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 31 31 100.0%
Functions: 6 6 100.0%
Branches: 18 30 60.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-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7 /*!
8 * \file
9 * \ingroup OnePTests
10 * \brief The properties & problem setup for the convergence test
11 */
12 #ifndef DUMUX_INCOMPRESSIBLE_ONEP_CONVERGENCETEST_PROBLEM_HH
13 #define DUMUX_INCOMPRESSIBLE_ONEP_CONVERGENCETEST_PROBLEM_HH
14
15 #include <cmath>
16
17 #include <dune/geometry/quadraturerules.hh>
18
19 #include <dumux/common/properties.hh>
20 #include <dumux/common/parameters.hh>
21
22 #include <dumux/common/boundarytypes.hh>
23 #include <dumux/common/numeqvector.hh>
24 #include <dumux/porousmediumflow/problem.hh>
25
26 namespace Dumux {
27
28 /*!
29 * \ingroup OnePTests
30 * \brief problem setup for the convergence test
31 */
32 template <class TypeTag>
33 16 class OnePTestProblem : public PorousMediumFlowProblem<TypeTag>
34 {
35 using ParentType = PorousMediumFlowProblem<TypeTag>;
36
37 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
38 using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
39 using NumEqVector = Dumux::NumEqVector<PrimaryVariables>;
40 using BoundaryTypes = Dumux::BoundaryTypes<GetPropType<TypeTag, Properties::ModelTraits>::numEq()>;
41
42 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
43 using FVElementGeometry = typename GridGeometry::LocalView;
44 using SubControlVolume = typename GridGeometry::SubControlVolume;
45 using GridView = typename GridGeometry::GridView;
46 using Element = typename GridView::template Codim<0>::Entity;
47 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
48
49 public:
50 /*!
51 * \brief The constructor.
52 * \param gridGeometry The finite-volume grid geometry
53 */
54 16 OnePTestProblem(std::shared_ptr<const GridGeometry> gridGeometry)
55
2/4
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
48 : ParentType(gridGeometry)
56 {
57
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 periodLength_ = getParam<Scalar>("Problem.ExactSolPeriodLength");
58
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 sourceIntegrationOrder_ = getParam<Scalar>("Problem.SourceIntegrationOrder");
59 16 }
60
61 /*!
62 * \brief Specifies which kind of boundary condition should be
63 * used for which equation on a given boundary control volume.
64 * \param globalPos The position of the center of the finite volume
65 */
66
4/6
✓ Branch 0 taken 2368 times.
✓ Branch 1 taken 1200 times.
✓ Branch 2 taken 1200 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1200 times.
✗ Branch 5 not taken.
5968 BoundaryTypes boundaryTypesAtPos(const GlobalPosition &globalPos) const
67 {
68
4/6
✓ Branch 0 taken 2368 times.
✓ Branch 1 taken 1200 times.
✓ Branch 2 taken 1200 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1200 times.
✗ Branch 5 not taken.
5968 BoundaryTypes values;
69 values.setAllDirichlet();
70 return values;
71 }
72
73 /*!
74 * \brief Evaluates the boundary conditions for a Dirichlet control volume.
75 * \param globalPos The center of the finite volume for which it is to be set.
76 */
77 3568 PrimaryVariables dirichletAtPos(const GlobalPosition &globalPos) const
78 {
79
1/2
✓ Branch 1 taken 1200 times.
✗ Branch 2 not taken.
3568 return exact(globalPos, periodLength_);
80 }
81
82 /*!
83 * \brief Evaluates the source term within a sub-control volume.
84 * \param element The finite element
85 * \param fvGeometry The element finite-volume geometry
86 * \param elemVolVars The element volume variables
87 * \param scv The sub-control volume for which the source term is evaluated
88 */
89 template <class ElementVolumeVariables>
90 85000 NumEqVector source(const Element &element,
91 const FVElementGeometry &fvGeometry,
92 const ElementVolumeVariables &elemVolVars,
93 const SubControlVolume &scv) const
94 {
95
1/2
✓ Branch 1 taken 85000 times.
✗ Branch 2 not taken.
85000 const auto &k = this->spatialParams().permeabilityAtPos(scv.center());
96
97 using std::cos;
98 using std::sin;
99
100 85000 const auto eg = element.geometry();
101
2/4
✓ Branch 1 taken 85000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 85000 times.
✗ Branch 5 not taken.
85000 const auto rule = Dune::QuadratureRules<Scalar, GridView::dimension>::rule(eg.type(), sourceIntegrationOrder_);
102
103 85000 Scalar source = 0.0;
104
2/2
✓ Branch 0 taken 340000 times.
✓ Branch 1 taken 85000 times.
425000 for (auto qp : rule)
105 {
106 680000 const auto p = eg.global(qp.position());
107 340000 const auto x = p[0];
108 340000 const auto y = p[1];
109
110 340000 const auto sineTerm = sin(periodLength_*x);
111 340000 const auto cosTerm = cos(periodLength_*y);
112 340000 const auto secondDeriv = -1.0*periodLength_*periodLength_*sineTerm*cosTerm;
113
114 // derivative in x and y are identical
115 680000 source -= 2.0*k*secondDeriv*qp.weight()*eg.integrationElement(qp.position());
116 }
117
118 85000 source /= eg.volume();
119 85000 return NumEqVector(source);
120 85000 }
121
122 /*!
123 * \brief Returns the exact solution at a position.
124 * \param globalPos The center of the finite volume for which it is to be set.
125 */
126 224568 static PrimaryVariables exact(const GlobalPosition& globalPos, const Scalar periodLength)
127 {
128 224568 const auto x = globalPos[0];
129 224568 const auto y = globalPos[1];
130
131 using std::cos;
132 using std::sin;
133
134 224568 const auto u = sin(periodLength*x)*cos(periodLength*y);
135 224568 return PrimaryVariables(u);
136 }
137
138 private:
139 Scalar periodLength_;
140 Scalar sourceIntegrationOrder_;
141 };
142
143 } // end namespace Dumux
144
145 #endif
146