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 MaterialTests | ||
10 | * \brief Test for the 2p van Genuchten material law | ||
11 | */ | ||
12 | |||
13 | #ifndef DUMUX_TEST_MATERIALLAW_FUNCTIONS_HH | ||
14 | #define DUMUX_TEST_MATERIALLAW_FUNCTIONS_HH | ||
15 | |||
16 | #include <iomanip> | ||
17 | |||
18 | #include <dune/common/float_cmp.hh> | ||
19 | #include <dumux/common/math.hh> | ||
20 | #include <dumux/common/numericdifferentiation.hh> | ||
21 | |||
22 | namespace Dumux::Test { | ||
23 | |||
24 | template<class F, class D> | ||
25 | 16 | void testDerivatives(std::string_view derivName, | |
26 | const std::vector<double>& values, | ||
27 | const F& f, const D& deriv) | ||
28 | { | ||
29 | static constexpr double eps = 1.0e-1; | ||
30 | static constexpr double numEps = 1e-8; | ||
31 |
4/4✓ Branch 0 taken 800 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 800 times.
✓ Branch 3 taken 8 times.
|
1648 | for (auto val : values) |
32 | { | ||
33 | 3200 | double analyticDeriv = deriv(val); | |
34 | |||
35 | 1600 | double numericDeriv = 0.0; | |
36 | 1600 | Dumux::NumericDifferentiation::partialDerivative(f, val, | |
37 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
1600 | numericDeriv, f(val), numEps, 0 /*central differences*/); |
38 | |||
39 |
3/4✓ Branch 0 taken 487 times.
✓ Branch 1 taken 313 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 800 times.
|
2574 | if (Dune::FloatCmp::ne(analyticDeriv, numericDeriv, eps)) |
40 | ✗ | DUNE_THROW(Dune::Exception, "Analytic derivative for " << derivName | |
41 | << " doesn't match numerical derivative: " | ||
42 | << std::setprecision(10) << analyticDeriv << " != " << numericDeriv | ||
43 | << " evaluated at " << val); | ||
44 | } | ||
45 | 16 | } | |
46 | |||
47 | template<class F, class G> | ||
48 | 36 | void testValueEqualRange(std::string_view testName, | |
49 | const std::vector<double>& values, | ||
50 | const F& f, const G& g) | ||
51 | { | ||
52 | static constexpr double eps = 1e-7; | ||
53 |
4/4✓ Branch 0 taken 1800 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 1800 times.
✓ Branch 3 taken 18 times.
|
3708 | for (auto val : values) |
54 | { | ||
55 | 4000 | const auto a = f(val); | |
56 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
6800 | const auto b = g(val); |
57 | |||
58 |
3/4✓ Branch 0 taken 94 times.
✓ Branch 1 taken 1706 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 600 times.
|
3788 | if (Dune::FloatCmp::ne(a, b, eps)) |
59 | ✗ | DUNE_THROW(Dune::Exception, "Test: " << testName << ": Function values do not match: " | |
60 | << a << " != " << b << " evaluated at " << val << "\n"); | ||
61 | |||
62 | } | ||
63 | 36 | } | |
64 | |||
65 | |||
66 | template<class Law, class RegLaw> | ||
67 | 2 | void runMaterialLawTest(const std::string& name, | |
68 | const Law& law, | ||
69 | const RegLaw& regLaw, | ||
70 | const std::vector<typename Law::Scalar>& sw, | ||
71 | const std::vector<typename Law::Scalar>& swNonReg) | ||
72 | { | ||
73 | 4 | const auto pc = [&](){ auto pc = sw; | |
74 |
4/4✓ Branch 0 taken 200 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 200 times.
✓ Branch 3 taken 2 times.
|
404 | for (int i = 0; i < sw.size(); ++i) |
75 | 400 | pc[i] = regLaw.pc(sw[i]); | |
76 | 6 | return pc; | |
77 | }(); | ||
78 | |||
79 |
1/2✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
602 | testDerivatives("dpc_dsw", sw, [&](auto sw){ return regLaw.pc(sw); }, [&](auto sw){ return regLaw.dpc_dsw(sw); }); |
80 |
1/2✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
602 | testDerivatives("dkrw_dsw", sw, [&](auto sw){ return regLaw.krw(sw); }, [&](auto sw){ return regLaw.dkrw_dsw(sw); }); |
81 |
1/2✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
602 | testDerivatives("dkrn_dsw", sw, [&](auto sw){ return regLaw.krn(sw); }, [&](auto sw){ return regLaw.dkrn_dsw(sw); }); |
82 |
3/6✓ Branch 3 taken 100 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 101 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
|
602 | testDerivatives("dsw_dpc", pc, [&](auto pc){ return regLaw.sw(pc); }, [&](auto pc){ return regLaw.dsw_dpc(pc); }); |
83 |
3/6✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
202 | testValueEqualRange("Checking sw == sw(pc(sw))", sw, [](auto sw){ return sw; }, [&](auto sw) { return regLaw.sw(regLaw.pc(sw)); }); |
84 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
402 | testValueEqualRange("Checking 1.0 == dsw_dpc*dpc_dsw^-1", sw, [](auto sw){ return 1.0; }, [&](auto sw) { return regLaw.dpc_dsw(sw)*regLaw.dsw_dpc(regLaw.pc(sw)); }); |
85 | |||
86 | // check that regularized and unregularized are the same in the region without regularization | ||
87 |
1/2✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
202 | testValueEqualRange("Checking NoReg::pc == Reg::pc", swNonReg, [&](auto sw){ return law.pc(sw); }, [&](auto sw) { return regLaw.pc(sw); }); |
88 | |||
89 | // test pc-sw curve against some precomputed values | ||
90 |
6/18✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
4 | writeContainerToFile(pc, "test_pcsw_" + name + ".dat", 100); |
91 | 2 | } | |
92 | |||
93 | |||
94 | template<class FluidMatrix> | ||
95 | 8 | void runEffToAbsTest(const std::string& name, const FluidMatrix& fmLaw, | |
96 | const std::vector<typename FluidMatrix::Scalar>& sw) | ||
97 | |||
98 | { | ||
99 | using EffToAbs = typename FluidMatrix::EffToAbs; | ||
100 | 8 | const auto params = fmLaw.effToAbsParams(); | |
101 | |||
102 |
4/8✗ Branch 0 not taken.
✓ Branch 1 taken 200 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 200 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 200 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 200 times.
|
808 | testValueEqualRange("Checking 1.0 == Abs::swToSwe(1-snr)", sw, [](auto sw){ return 1.0; }, [&](auto sw) { return EffToAbs::swToSwe(1-params.snr(), params); }); |
103 |
4/8✗ Branch 0 not taken.
✓ Branch 1 taken 200 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 200 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 200 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 200 times.
|
808 | testValueEqualRange("Checking 0.0 == Abs::swToSwe(snr)", sw, [](auto sw){ return 0.0; }, [&](auto sw) { return EffToAbs::swToSwe(params.snr(), params); }); |
104 |
12/12✓ Branch 0 taken 8 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 192 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 192 times.
✓ Branch 6 taken 8 times.
✓ Branch 7 taken 192 times.
✓ Branch 8 taken 8 times.
✓ Branch 9 taken 192 times.
✓ Branch 10 taken 8 times.
✓ Branch 11 taken 192 times.
|
1208 | testValueEqualRange("Checking sw == sweToSw(swToSwe(sw))", sw, [](auto sw){ return sw; }, [&](auto sw) { return EffToAbs::sweToSw(EffToAbs::swToSwe(sw, params), params); }); |
105 | 8 | } | |
106 | |||
107 | } // end namespace Dumux | ||
108 | |||
109 | #endif | ||
110 |