GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/porenetwork/common/velocityoutput.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 27 28 96.4%
Functions: 61 96 63.5%
Branches: 18 38 47.4%

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 * \file
9 * \ingroup PoreNetworkModels
10 * \copydoc Dumux::PoreNetwork::VelocityOutput
11 */
12 #ifndef DUMUX_PNM_VELOCITYOUTPUT_HH
13 #define DUMUX_PNM_VELOCITYOUTPUT_HH
14
15 #include <string>
16 #include <dumux/io/velocityoutput.hh>
17
18 namespace Dumux::PoreNetwork {
19
20 /*!
21 * \ingroup PoreNetworkModels
22 * \brief Velocity output for pore-network models
23 */
24 template<class GridVariables, class FluxVariables>
25 class VelocityOutput : public Dumux::VelocityOutput<GridVariables>
26 {
27 using ParentType = Dumux::VelocityOutput<GridVariables>;
28 using Scalar = typename GridVariables::Scalar;
29 using GridGeometry = typename GridVariables::GridGeometry;
30 using ElementVolumeVariables = typename GridVariables::GridVolumeVariables::LocalView;
31 using VolumeVariables = typename GridVariables::VolumeVariables;
32 using FluidSystem = typename VolumeVariables::FluidSystem;
33 using ElementFluxVariablesCache = typename GridVariables::GridFluxVariablesCache::LocalView;
34 using FVElementGeometry = typename GridGeometry::LocalView;
35 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
36 using Element = typename GridGeometry::GridView::template Codim<0>::Entity;
37
38 public:
39 //! Export the velocity vector type.
40 using VelocityVector = typename ParentType::VelocityVector;
41
42 //! Returns the phase name of a given phase index.
43 649 std::string phaseName(int phaseIdx) const override { return FluidSystem::phaseName(phaseIdx); }
44
45 //! Returns the number of phases.
46 137194 int numFluidPhases() const override { return VolumeVariables::numFluidPhases(); }
47
48 //! Constructor.
49 17 VelocityOutput(const GridVariables& gridVariables)
50 17 : gridVariables_(gridVariables)
51 {
52
3/9
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 15 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
17 velocityOutput_ = getParamFromGroup<bool>(problem_().paramGroup(), "Vtk.AddVelocity");
53 }
54
55 //! Returns true if velocity output is enabled.
56 246520 bool enableOutput() const override
57 246520 { return velocityOutput_; }
58
59 //! Calculate the velocities for the scvs in the element
60 //! We assume the local containers to be bound to the complete stencil
61 82998 void calculateVelocity(VelocityVector& velocity,
62 const Element& element,
63 const FVElementGeometry& fvGeometry,
64 const ElementVolumeVariables& elemVolVars,
65 const ElementFluxVariablesCache& elemFluxVarsCache,
66 int phaseIdx) const override
67 {
68
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82998 times.
82998 if (!velocityOutput_)
69 return;
70
71 82998 const auto geometry = element.geometry();
72
73 248990 auto tmpVelocity = (geometry.corner(1) - geometry.corner(0));
74 165996 tmpVelocity /= tmpVelocity.two_norm();
75
76 165996 const auto eIdxGlobal = fvGeometry.gridGeometry().elementMapper().index(element);
77 165996 velocity[eIdxGlobal] = 0.0;
78
79
2/2
✓ Branch 0 taken 82998 times.
✓ Branch 1 taken 82998 times.
248994 for (auto&& scvf : scvfs(fvGeometry))
80 {
81 82998 if (scvf.boundary())
82 continue;
83
84 // get the volume flux divided by the area of the
85 // subcontrolvolume face in the reference element
86 // TODO: Divide by extrusion factor!!?
87 82998 const Scalar flux = getFlux_(element, fvGeometry, scvf, elemVolVars, elemFluxVarsCache, phaseIdx);
88
89 82998 tmpVelocity *= flux;
90 165996 velocity[eIdxGlobal] = tmpVelocity;
91 }
92 }
93
94 private:
95
96 82998 Scalar getFlux_(const Element& element,
97 const FVElementGeometry& fvGeometry,
98 const SubControlVolumeFace& scvf,
99 const ElementVolumeVariables& elemVolVars,
100 const ElementFluxVariablesCache& elemFluxVarsCache,
101 const int phaseIdx) const
102 {
103
4/4
✓ Branch 0 taken 54197 times.
✓ Branch 1 taken 28801 times.
✓ Branch 2 taken 33903 times.
✓ Branch 3 taken 28801 times.
145702 const Scalar localArea = elemFluxVarsCache[scvf].throatCrossSectionalArea(phaseIdx);
104
105 // make sure the phase is actually present (2p)
106
2/2
✓ Branch 0 taken 54197 times.
✓ Branch 1 taken 28801 times.
82998 if (localArea > 0.0)
107 {
108 // instantiate the flux variables
109 54197 FluxVariables fluxVars;
110 162591 fluxVars.init(problem_(), element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache);
111
112 // the upwind term to be used for the volume flux evaluation
113 216788 auto upwindTerm = [phaseIdx](const auto& volVars) { return volVars.mobility(phaseIdx); };
114 54197 return fluxVars.advectiveFlux(phaseIdx, upwindTerm) / localArea;
115 }
116 else
117 return 0.0;
118 }
119
120
6/19
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 11 taken 15 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 15 times.
✗ Branch 15 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 1 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
108428 const auto& problem_() const { return gridVariables_.curGridVolVars().problem(); }
121
122 bool velocityOutput_;
123
124 const GridVariables& gridVariables_;
125 };
126
127 } // end namespace Dumux::PoreNetwork
128
129 #endif
130