GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/test/multidomain/embedded/1d3d/root_soil_benchmark/plot.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 34 35 97.1%
Functions: 2 2 100.0%
Branches: 24 48 50.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 * \author Timo Koch <timokoch@uio.no>
10 * \brief Plotting tools for root soil benchmark
11 */
12 #ifndef DUMUX_TEST_ROOT_SOIL_BENCHMARK_PLOT_HH
13 #define DUMUX_TEST_ROOT_SOIL_BENCHMARK_PLOT_HH
14
15 #include <vector>
16 #include <algorithm>
17 #include <tuple>
18 #include <utility>
19 #include <memory>
20
21 #include <dumux/common/parameters.hh>
22 #include <dumux/io/gnuplotinterface.hh>
23
24 namespace Dumux::RootSoil {
25
26 /*!
27 * \brief plot the transpiration curves
28 * \tparam Problem the problem type
29 */
30 template<class Problem>
31 class TranspirationPlot
32 {
33 public:
34 2 TranspirationPlot(std::shared_ptr<const Problem> problem)
35
2/4
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
2 : problem_(problem)
36 {
37
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 const std::string outputDir = getParam<std::string>("Output.GnuplotOutputDirectory", "");
38
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 filenamePrefix_ = getParam<std::string>("Output.GnuplotOutputFilenamePrefix", "");
39
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 const bool openGnuPlot = getParam<bool>("Output.GnuplotShow", true);
40
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 gnuplot_.setOpenPlotWindow(openGnuPlot);
41
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (outputDir != "")
42 gnuplot_.setOutputDirectory(outputDir);
43 2 }
44
45 /*!
46 * \brief add a data point to the transpiration plot
47 * \param curSol the current solution vector (root)
48 * \param curGridVars the current grid variables (root)
49 * \param t the time at the end of the current time step
50 * \param dt the time step size of the current time step
51 */
52 template<class SolutionVector, class GridVariables>
53 434 void addDataPoint(const SolutionVector& curSol, const GridVariables& curGridVars, double t, double dt)
54 {
55 434 gnuplot_.resetPlot();
56
57 868 gnuplot_.setXlabel("time [day]");
58 868 gnuplot_.setYlabel("transpiration rate [g/day]");
59
1/2
✓ Branch 2 taken 434 times.
✗ Branch 3 not taken.
434 gnuplot_.setOption("set y2label \"cumulative transpiration [g]\"");
60
61 434 const auto conversion = 86400.0*1000.0; // convert to g/day
62 434 const auto tAct = problem_->computeActualTranspirationRate(curSol, curGridVars)*conversion;
63
64 434 tActPlot_.push_back(tAct);
65
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 432 times.
434 if (tCumulPlot_.empty())
66 2 tCumulPlot_.push_back(tAct*dt/86400.0);
67 else
68 432 tCumulPlot_.push_back(tCumulPlot_.back() + tAct*dt/86400.0);
69 434 timePlot_.push_back(t/86400.0);
70
2/4
✓ Branch 2 taken 434 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 434 times.
✗ Branch 6 not taken.
868 gnuplot_.addDataSetToPlot(timePlot_, tActPlot_, filenamePrefix_ + "actualtranspiration.out", "with lines axes x1y1 lw 3");
71
2/4
✓ Branch 2 taken 434 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 434 times.
✗ Branch 6 not taken.
868 gnuplot_.addDataSetToPlot(timePlot_, tCumulPlot_, filenamePrefix_ + "cumulativetranspiration.out", "with lines axes x1y2 lw 3");
72
73
1/2
✓ Branch 0 taken 434 times.
✗ Branch 1 not taken.
434 if (problem_->bcType() != Problem::BCType::constCollarPressure)
74 {
75 434 const auto tPot = problem_->potentialTranspirationRate()*conversion;
76 434 tPotPlot_.push_back(tPot);
77
2/4
✓ Branch 2 taken 434 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 434 times.
✗ Branch 6 not taken.
868 gnuplot_.addDataSetToPlot(timePlot_, tPotPlot_, filenamePrefix_ + "potentialtranspiration.out", "with lines axes x1y1 lw 2 lc rgb 'black'");
78 }
79
80
1/2
✓ Branch 2 taken 434 times.
✗ Branch 3 not taken.
434 gnuplot_.setOption("set ytics nomirror");
81
1/2
✓ Branch 2 taken 434 times.
✗ Branch 3 not taken.
434 gnuplot_.setOption("set y2tics");
82
83
1/2
✓ Branch 2 taken 434 times.
✗ Branch 3 not taken.
434 gnuplot_.setOption("set autoscale x");
84
1/2
✓ Branch 2 taken 434 times.
✗ Branch 3 not taken.
434 gnuplot_.setOption("set autoscale y");
85
1/2
✓ Branch 2 taken 434 times.
✗ Branch 3 not taken.
434 gnuplot_.setOption("set autoscale y2");
86
87
1/2
✓ Branch 2 taken 434 times.
✗ Branch 3 not taken.
434 gnuplot_.setOption("set title \"Plant transpiration\"");
88
1/2
✓ Branch 2 taken 434 times.
✗ Branch 3 not taken.
434 gnuplot_.plot(filenamePrefix_ + "transpiration");
89 434 }
90
91 private:
92 std::shared_ptr<const Problem> problem_;
93 GnuplotInterface<double> gnuplot_;
94 std::string filenamePrefix_;
95
96 // the cached data vectors (they are updated on each call to addDataPoint)
97 std::vector<double> tPotPlot_, tActPlot_, tCumulPlot_, timePlot_;
98 };
99
100 } // end namespace Dumux::RootSoil
101
102 #endif
103