GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/examples/1ptracer/problem_tracer.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 17 25 68.0%
Functions: 2 4 50.0%
Branches: 32 68 47.1%

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
8 #ifndef DUMUX_TRACER_TEST_PROBLEM_HH
9 #define DUMUX_TRACER_TEST_PROBLEM_HH
10
11 // ## Initial and boundary conditions (`problem_tracer.hh`)
12 //
13 // This file contains the __problem class__ which defines the initial and boundary
14 // conditions for the tracer transport simulation.
15 //
16 // [[content]]
17 //
18 // ### Include files
19 // Include the `PorousMediumFlowProblem` class, the base
20 // class from which we will derive.
21 #include <dumux/porousmediumflow/problem.hh>
22 // Include the `BoundaryTypes` class which specifies the boundary types set in this problem.
23 #include <dumux/common/boundarytypes.hh>
24 // Include the `NumEqVector` class which specifies a field vector with size number of equations in this problem.
25 #include <dumux/common/numeqvector.hh>
26
27 // ### The problem class
28 //
29 // We enter the problem class where all necessary boundary conditions and initial
30 // conditions are set for our simulation. As we are solving a problem related to
31 // flow in porous media, we inherit from the base class `PorousMediumFlowProblem`.
32 // [[codeblock]]
33 namespace Dumux {
34
35 template <class TypeTag>
36 1 class TracerTestProblem : public PorousMediumFlowProblem<TypeTag>
37 {
38 // A few convenience aliases used throughout this class.
39 using ParentType = PorousMediumFlowProblem<TypeTag>;
40 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
41 using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices;
42 using GridView = typename GetPropType<TypeTag, Properties::GridGeometry>::GridView;
43 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
44 using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
45 using BoundaryTypes = Dumux::BoundaryTypes<PrimaryVariables::size()>;
46 using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
47 using SpatialParams = GetPropType<TypeTag, Properties::SpatialParams>;
48 using Element = typename GridGeometry::GridView::template Codim<0>::Entity;
49 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
50 using NumEqVector = Dumux::NumEqVector<PrimaryVariables>;
51 using GridVariables = GetPropType<TypeTag, Properties::GridVariables>;
52 using ElementVolumeVariables = typename GridVariables::GridVolumeVariables::LocalView;
53 using ElementFluxVariablesCache = typename GridVariables::GridFluxVariablesCache::LocalView;
54 using FVElementGeometry = typename GetPropType<TypeTag, Properties::GridGeometry>::LocalView;
55 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
56 // We create a convenience bool stating whether mole or mass fractions are used
57 static constexpr bool useMoles = getPropValue<TypeTag, Properties::UseMoles>();
58 // We create additional convenience integers to make dimWorld and numComponents available in the problem
59 static constexpr int dimWorld = GridView::dimensionworld;
60 static const int numComponents = FluidSystem::numComponents;
61
62 public:
63 // This is the constructor of our problem class:
64 1 TracerTestProblem(std::shared_ptr<const GridGeometry> gridGeometry)
65
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 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
3 : ParentType(gridGeometry)
66 {
67 // We print to the terminal whether mole or mass fractions are used
68 if(useMoles)
69 std::cout<<"problem uses mole fractions" << '\n';
70 else
71
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 std::cout<<"problem uses mass fractions" << '\n';
72 1 }
73 // [[/codeblock]]
74
75 // #### Boundary conditions
76 //
77 // We define the __type of boundary conditions__ depending on the location.
78 // All boundaries are set to a neumann-type flow boundary condition.
79 // [[codeblock]]
80 BoundaryTypes boundaryTypesAtPos(const GlobalPosition& globalPos) const
81 {
82
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 2200 times.
✓ Branch 2 taken 2200 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 100000 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 202400 times.
306800 BoundaryTypes values;
83
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 2200 times.
✓ Branch 2 taken 2200 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 100000 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 202400 times.
306800 values.setAllNeumann();
84 return values;
85 }
86 // [[/codeblock]]
87
88 // In the following function we implement the __Neumann boundary conditions__.
89 // Here, we define an outflow boundary on the top of the domain and prescribe zero-flux
90 // Neumann boundary conditions on all other boundaries.
91 // [[codeblock]]
92 100000 NumEqVector neumann(const Element& element,
93 const FVElementGeometry& fvGeometry,
94 const ElementVolumeVariables& elemVolVars,
95 const ElementFluxVariablesCache& elemFluxVarsCache,
96 const SubControlVolumeFace& scvf) const
97 {
98 100000 NumEqVector values(0.0);
99 200000 const auto& volVars = elemVolVars[scvf.insideScvIdx()];
100
2/2
✓ Branch 0 taken 25000 times.
✓ Branch 1 taken 75000 times.
100000 const auto& globalPos = scvf.center();
101
102 // This is the outflow boundary, where tracer is transported by advection with the given flux field.
103
10/10
✓ Branch 0 taken 25000 times.
✓ Branch 1 taken 75000 times.
✓ Branch 2 taken 25000 times.
✓ Branch 3 taken 75000 times.
✓ Branch 4 taken 25000 times.
✓ Branch 5 taken 75000 times.
✓ Branch 6 taken 25000 times.
✓ Branch 7 taken 75000 times.
✓ Branch 8 taken 25000 times.
✓ Branch 9 taken 75000 times.
500000 if (globalPos[dimWorld-1] > this->gridGeometry().bBoxMax()[dimWorld-1] - eps_)
104 {
105
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25000 times.
25000 values = this->spatialParams().volumeFlux(element, fvGeometry, elemVolVars, scvf)
106
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 25000 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 25000 times.
50000 * volVars.massFraction(0, 0) * volVars.density(0)
107
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25000 times.
25000 / scvf.area();
108
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 25000 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 25000 times.
50000 assert(values>=0.0 && "Volume flux at outflow boundary is expected to have a positive sign");
109 }
110
111 // Prescribe zero-flux Neumann boundary conditions elsewhere
112 else
113 values = 0.0;
114
115 100000 return values;
116 }
117 // [[/codeblock]]
118
119 // #### Initial conditions
120 //
121 // We specify the initial conditions for the primary variable (tracer mass fraction) depending
122 // on the location. Here, we set zero mass fractions everywhere in the domain except for a strip
123 // at the bottom of the domain where we set an initial mole fraction of $`10^{-9}`$.
124 // [[codeblock]]
125 PrimaryVariables initialAtPos(const GlobalPosition& globalPos) const
126 {
127 // initialize the mole fraction to zero
128 PrimaryVariables initialValues(0.0);
129
130 // The initial contamination is located at the bottom of the domain
131 if (globalPos[1] < 0.1 + eps_)
132 {
133 // We chose a mole fraction of 1e-9, but in case the mass fractions
134 // are used by the model, we have to convert this value:
135 if (useMoles)
136 initialValues = 1e-9;
137 else
138 initialValues = 1e-9*FluidSystem::molarMass(0)
139 /this->spatialParams().fluidMolarMassAtPos(globalPos);
140 }
141
142 return initialValues;
143 }
144 // [[/codeblock]]
145 //
146 // The remainder of the class contains an epsilon value used for floating point comparisons.
147 // [[codeblock]]
148 private:
149 // We assign a private global variable for the epsilon:
150 static constexpr Scalar eps_ = 1e-6;
151
152 }; // end class definition TracerTestProblem
153 } // end namespace Dumux
154 // [[/codeblock]]
155 // [[/content]]
156 #endif
157