GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/io/plotpckrsw.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 19 19 100.0%
Functions: 6 9 66.7%
Branches: 8 22 36.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 InputOutput
10 * \brief Interface for plotting the two-phase fluid-matrix-interaction laws
11 */
12 #ifndef DUMUX_IO_PLOT_PC_KR_SW_HH
13 #define DUMUX_IO_PLOT_PC_KR_SW_HH
14
15 #include <string>
16 #include <tuple>
17 #include <algorithm>
18 #include <dumux/common/math.hh>
19
20 namespace Dumux {
21
22 namespace Detail {
23 template<class Function, class Range>
24 18 Range evalFunctionForRange(const Function& f, const Range& range)
25 {
26 18 Range result = range;
27 6072 std::transform(range.begin(), range.end(), result.begin(), [&](auto x){ return f(x); });
28 18 return result;
29 }
30 } // end namespace Detail
31
32 /*!
33 * \ingroup InputOutput
34 * \brief sample the pc-sw curve
35 */
36 template<class PcKrSw, class V>
37 auto samplePcSw(const PcKrSw& curve, const V& sw)
38 {
39
2/4
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
3003 return Detail::evalFunctionForRange([&](const auto s){ return curve.pc(s); }, sw);
40 }
41
42 /*!
43 * \ingroup InputOutput
44 * \brief sample the pc-sw curve derivative wrt sw
45 */
46 template<class PcKrSw, class V>
47 auto samplePcSwDerivative(const PcKrSw& curve, const V& sw)
48 {
49 return Detail::evalFunctionForRange([&](const auto s){ return curve.dpc_dsw(s); }, sw);
50 }
51
52 /*!
53 * \ingroup InputOutput
54 * \brief sample the sw-pc curve derivative wrt pc
55 */
56 template<class PcKrSw, class V>
57 auto samplePcSwInverseDerivative(const PcKrSw& curve, const V& pc)
58 {
59 return Detail::evalFunctionForRange([&](const auto p){ return curve.dsw_dpc(p); }, pc);
60 }
61
62 /*!
63 * \ingroup InputOutput
64 * \brief sample sw-pc curve but return the log10 of the capillary pressure
65 */
66 template<class PcKrSw, class V>
67 auto sampleLog10PcSw(const PcKrSw& curve, const V& sw)
68 {
69 return Detail::evalFunctionForRange([&](const auto s){ using std::log10; return log10(curve.pc(s)); }, sw);
70 }
71
72 /*!
73 * \ingroup InputOutput
74 * \brief sample krw-sw and krn-sw curves
75 */
76 template<class PcKrSw, class V>
77 3 auto sampleRelPerms(const PcKrSw& curve, const V& sw)
78 {
79 return std::make_tuple(
80 3000 Detail::evalFunctionForRange([&](const auto s){ return curve.krw(s); }, sw),
81 6000 Detail::evalFunctionForRange([&](const auto s){ return curve.krn(s); }, sw)
82
1/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3 );
83 }
84
85 /*!
86 * \ingroup InputOutput
87 * \brief sample the derivatives of the krw-sw and krn-sw curves
88 */
89 template<class PcKrSw, class V>
90 auto sampleRelPermDerivatives(const PcKrSw& curve, const V& sw)
91 {
92 return std::make_tuple(
93 Detail::evalFunctionForRange([&](const auto s){ return curve.dkrw_dsw(s); }, sw),
94 Detail::evalFunctionForRange([&](const auto s){ return curve.dkrn_dsw(s); }, sw)
95 );
96 }
97
98 // forward declaration
99 template<class S> class GnuplotInterface;
100
101 namespace Detail {
102 template<class S, class V>
103 9 void addDataSetToGnuplot(GnuplotInterface<S>& gnuplot,
104 const V& x, const V& y,
105 const std::string& curveName,
106 const std::string& curveOptions,
107 const std::string& xLabel,
108 const std::string& yLabel)
109 {
110 9 gnuplot.setXlabel(xLabel);
111 9 gnuplot.setYlabel(yLabel);
112 9 gnuplot.addDataSetToPlot(x, y, curveName, curveOptions);
113 9 }
114 } // end namespace Detail
115
116 /*!
117 * \ingroup InputOutput
118 * \brief Helper functions related to gnuplot
119 */
120 namespace Gnuplot {
121
122 /*!
123 * \ingroup InputOutput
124 * \brief Convenience function for adding material law quantities to gnuplot
125 */
126 template<class S, class V>
127 void addPcSw(GnuplotInterface<S>& gnuplot, const V& sw, const V& pc,
128 const std::string& curveName = "pc-sw",
129 const std::string& curveOptions = "w l",
130 const std::string& xLabel = "wetting phase saturation [-]",
131 const std::string& yLabel = "capillary pressure [Pa]")
132 {
133
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 Detail::addDataSetToGnuplot(gnuplot, sw, pc, curveName, curveOptions, xLabel, yLabel);
134 }
135
136 /*!
137 * \ingroup InputOutput
138 * \brief Convenience function for adding material law quantities to gnuplot
139 */
140 template<class S, class V>
141 void addPcSwDerivative(GnuplotInterface<S>& gnuplot, const V& sw, const V& dpc_dsw,
142 const std::string& curveName = "dpc-dsw",
143 const std::string& curveOptions = "w l",
144 const std::string& xLabel = "wetting phase saturation [-]",
145 const std::string& yLabel = "derivative of capillary pressure [Pa]")
146 {
147 Detail::addDataSetToGnuplot(gnuplot, sw, dpc_dsw, curveName, curveOptions, xLabel, yLabel);
148 }
149
150 /*!
151 * \ingroup InputOutput
152 * \brief Convenience function for adding material law quantities to gnuplot
153 */
154 template<class S, class V>
155 void addPcSwInverseDerivative(GnuplotInterface<S>& gnuplot, const V& sw, const V& dpc_dsw,
156 const std::string& curveName = "dsw-dpc",
157 const std::string& curveOptions = "w l",
158 const std::string& xLabel = "capillary pressure [Pa]",
159 const std::string& yLabel = "derivative of saturation [1/Pa]")
160 {
161 Detail::addDataSetToGnuplot(gnuplot, sw, dpc_dsw, curveName, curveOptions, xLabel, yLabel);
162 }
163
164 /*!
165 * \ingroup InputOutput
166 * \brief Convenience function for adding material law quantities to gnuplot
167 */
168 template<class S, class V>
169 void addLog10PcSw(GnuplotInterface<S>& gnuplot, const V& sw, const V& log10pc,
170 const std::string& curveName = "log10-pc-sw",
171 const std::string& curveOptions = "w l",
172 const std::string& xLabel = "wetting phase saturation [-]",
173 const std::string& yLabel = "log10 of capillary pressure [Pa]")
174 {
175 Detail::addDataSetToGnuplot(gnuplot, sw, log10pc, curveName, curveOptions, xLabel, yLabel);
176 }
177
178 /*!
179 * \ingroup InputOutput
180 * \brief Convenience function for adding material law quantities to gnuplot
181 */
182 template<class S, class V>
183 3 void addRelPerms(GnuplotInterface<S>& gnuplot, const V& sw, const V& krw, const V& krn,
184 const std::string& curveName = "relperm",
185 const std::string& curveOptions = "w l",
186 const std::string& xLabel = "wetting phase saturation [-]",
187 const std::string& yLabel = "relative permeability [-]")
188 {
189
2/6
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
3 Detail::addDataSetToGnuplot(gnuplot, sw, krw, curveName + "_krw", curveOptions, xLabel, yLabel);
190
2/6
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
3 Detail::addDataSetToGnuplot(gnuplot, sw, krn, curveName + "_krn", curveOptions, xLabel, yLabel);
191 3 }
192
193 /*!
194 * \ingroup InputOutput
195 * \brief Convenience function for adding material law quantities to gnuplot
196 */
197 template<class S, class V>
198 void addRelPermDerivatives(GnuplotInterface<S>& gnuplot, const V& sw, const V& krw, const V& krn,
199 const std::string& curveName = "relperm_dsw",
200 const std::string& curveOptions = "w l",
201 const std::string& xLabel = "wetting phase saturation [-]",
202 const std::string& yLabel = "derivative of the relative permeability [-]")
203 {
204 Detail::addDataSetToGnuplot(gnuplot, sw, krw, curveName + "_krw", curveOptions, xLabel, yLabel);
205 Detail::addDataSetToGnuplot(gnuplot, sw, krn, curveName + "_krn", curveOptions, xLabel, yLabel);
206 }
207
208 } // end namespace Gnuplot
209 } // end namespace Dumux
210
211 #endif
212