GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/porenetwork/common/velocityoutput.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 26 27 96.3%
Functions: 76 85 89.4%
Branches: 9 10 90.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 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 719 std::string phaseName(int phaseIdx) const override { return FluidSystem::phaseName(phaseIdx); }
44
45 //! Returns the number of phases.
46 137684 int numFluidPhases() const override { return VolumeVariables::numFluidPhases(); }
47
48 //! Constructor.
49 21 VelocityOutput(const GridVariables& gridVariables)
50 21 : gridVariables_(gridVariables)
51 {
52 21 velocityOutput_ = getParamFromGroup<bool>(problem_().paramGroup(), "Vtk.AddVelocity");
53 }
54
55 //! Returns true if velocity output is enabled.
56 246800 bool enableOutput() const override
57 246800 { 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 83068 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 83068 times.
83068 if (!velocityOutput_)
69 return;
70
71 83068 const auto geometry = element.geometry();
72
73 249132 auto tmpVelocity = (geometry.corner(1) - geometry.corner(0));
74 166136 tmpVelocity /= tmpVelocity.two_norm();
75
76 83068 const auto eIdxGlobal = fvGeometry.gridGeometry().elementMapper().index(element);
77 166136 velocity[eIdxGlobal] = 0.0;
78
79
2/2
✓ Branch 0 taken 83068 times.
✓ Branch 1 taken 83068 times.
166136 for (auto&& scvf : scvfs(fvGeometry))
80 {
81 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 83068 const Scalar flux = getFlux_(element, fvGeometry, scvf, elemVolVars, elemFluxVarsCache, phaseIdx);
88
89 83068 tmpVelocity *= flux;
90 83068 velocity[eIdxGlobal] = tmpVelocity;
91 }
92 }
93
94 private:
95
96
2/2
✓ Branch 0 taken 54267 times.
✓ Branch 1 taken 28801 times.
83068 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
2/2
✓ Branch 0 taken 54267 times.
✓ Branch 1 taken 28801 times.
83068 const Scalar localArea = elemFluxVarsCache[scvf].throatCrossSectionalArea(phaseIdx);
104
105 // make sure the phase is actually present (2p)
106
2/2
✓ Branch 0 taken 54267 times.
✓ Branch 1 taken 28801 times.
83068 if (localArea > 0.0)
107 {
108 // instantiate the flux variables
109 54267 FluxVariables fluxVars;
110 54267 fluxVars.init(problem_(), element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache);
111
112 // the upwind term to be used for the volume flux evaluation
113 54267 auto upwindTerm = [phaseIdx](const auto& volVars) { return volVars.mobility(phaseIdx); };
114 54267 return fluxVars.advectiveFlux(phaseIdx, upwindTerm) / localArea;
115 }
116 else
117 return 0.0;
118 }
119
120 54288 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