plotmateriallaw.hh 14.1 KB
Newer Older
Thomas Fetzer's avatar
Thomas Fetzer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*****************************************************************************
 *   See the file COPYING for full copying permissions.                      *
 *                                                                           *
 *   This program is free software: you can redistribute it and/or modify    *
 *   it under the terms of the GNU General Public License as published by    *
 *   the Free Software Foundation, either version 2 of the License, or       *
 *   (at your option) any later version.                                     *
 *                                                                           *
 *   This program is distributed in the hope that it will be useful,         *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
 *   GNU General Public License for more details.                            *
 *                                                                           *
 *   You should have received a copy of the GNU General Public License       *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
 *****************************************************************************/
/*!
 * \file
21
 * \ingroup InputOutput
Thomas Fetzer's avatar
Thomas Fetzer committed
22
23
24
25
26
 * \brief Interface for plotting the two-phase fluid-matrix-interaction laws
 */
#ifndef DUMUX_PLOT_FLUID_MATRIX_LAW_HH
#define DUMUX_PLOT_FLUID_MATRIX_LAW_HH

Timo Koch's avatar
Timo Koch committed
27
28
29
30
31
32
#include <cmath>
#include <vector>
#include <string>

namespace Dumux {

33
34
// forward declaration
template<class Scalar> class GnuplotInterface;
Thomas Fetzer's avatar
Thomas Fetzer committed
35
36

/*!
37
 * \ingroup InputOutput
Thomas Fetzer's avatar
Thomas Fetzer committed
38
39
 *\brief Interface for plotting the two-phase fluid-matrix-interaction laws
 */
40
template<class Scalar, class MaterialLaw>
Thomas Fetzer's avatar
Thomas Fetzer committed
41
42
class PlotMaterialLaw
{
43
    using MaterialLawParams = typename MaterialLaw::Params;
Thomas Fetzer's avatar
Thomas Fetzer committed
44
45

public:
46
47
48
49
50
    //! Constructor
    PlotMaterialLaw()
    : numIntervals_(1000)
    { }

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
    /*!
     * \brief Add a capillary pressure-saturation data set to the plot
     *
     * \param gnuplot The gnuplot interface
     * \param params The material law parameters
     * \param lowerSat Minimum x-value for data set
     * \param upperSat Maximum x-value for data set
     * \param curveName Name of the data set
     * \param curveOptions Plotting options associated with that data set
     */
    void addpcswcurve(GnuplotInterface<Scalar> &gnuplot,
                      const MaterialLawParams &params,
                      Scalar lowerSat = 0.0,
                      Scalar upperSat = 1.0,
                      std::string curveName = "pc-Sw",
                      std::string curveOptions = "w l")
    {
        std::vector<Scalar> sw(numIntervals_+1);
        std::vector<Scalar> pc(numIntervals_+1);
        Scalar satInterval = upperSat - lowerSat;

        for (int i = 0; i <= numIntervals_; i++)
        {
            sw[i] = lowerSat + satInterval * Scalar(i) / Scalar(numIntervals_);
            pc[i] = MaterialLaw::pc(params, sw[i]);
        }

        gnuplot.setXlabel("wetting phase saturation [-]");
        gnuplot.setYlabel("capillary pressure [Pa]");
        gnuplot.addDataSetToPlot(sw, pc, curveName, curveOptions);
    }

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
    /*!
     * \brief Add a capillary pressure-saturation data set to the plot
     *
     * \param gnuplot The gnuplot interface
     * \param params The material law parameters
     * \param lowerSat Minimum x-value for data set
     * \param upperSat Maximum x-value for data set
     * \param curveName Name of the data set
     * \param curveOptions Plotting options associated with that data set
     */
    void addLog10PcSwCurve(GnuplotInterface<Scalar> &gnuplot,
                           const MaterialLawParams &params,
                           Scalar lowerSat = 0.0,
                           Scalar upperSat = 1.0,
                           std::string curveName = "log10_pc-Sw.dat",
                           std::string curveOptions = "w l")
    {
        std::vector<Scalar> sw(numIntervals_+1);
        std::vector<Scalar> log10pc(numIntervals_+1);
        Scalar satInterval = upperSat - lowerSat;

        for (int i = 0; i <= numIntervals_; i++)
        {
            sw[i] = lowerSat + satInterval * Scalar(i) / Scalar(numIntervals_);
            const Scalar pc = std::log10(MaterialLaw::pc(params, sw[i]));
            log10pc[i] = std::isnan(pc) ? 0.0 : pc;
        }

        gnuplot.setXlabel("wetting phase saturation [-]");
        gnuplot.setYlabel("log10 of capillary pressure [Pa]");
        gnuplot.addDataSetToPlot(sw, log10pc, curveName, curveOptions);
    }

Thomas Fetzer's avatar
Thomas Fetzer committed
116
    /*!
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
     * \brief Add a saturation-capillary pressure data set to the plot
     *
     * \param gnuplot The gnuplot interface
     * \param params The material law parameters
     * \param lowerpc Minimum x-value for data set
     * \param upperpc Maximum x-value for data set
     * \param curveName Name of the data set
     * \param curveOptions Plotting options associated with that data set
     */
    void addswpccurve(GnuplotInterface<Scalar> &gnuplot,
                      const MaterialLawParams &params,
                      Scalar lowerpc = 0.0,
                      Scalar upperpc = 5000.0,
                      std::string curveName = "Sw-pc",
                      std::string curveOptions = "w l")
    {
        std::vector<Scalar> sw;
        std::vector<Scalar> pc;
        Scalar pcInterval = upperpc - lowerpc;

        Scalar pcTemp, swTemp = 0.0;
        for (int i = 0; i <= numIntervals_; i++)
        {
            pcTemp = lowerpc + pcInterval * Scalar(i) / Scalar(numIntervals_);
            swTemp = MaterialLaw::sw(params, pcTemp);
            if (checkValues_(pcTemp, swTemp))
            {
                pc.push_back(pcTemp);
                sw.push_back(swTemp);
            }
        }

        gnuplot.setXlabel("capillary pressure [Pa]");
        gnuplot.setYlabel("wetting phase saturation [-]");
        gnuplot.addDataSetToPlot(pc, sw, curveName, curveOptions);
    }

154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
    /*!
     * \brief Add a saturation-capillary pressure data set to the plot
     *
     * \param gnuplot The gnuplot interface
     * \param params The material law parameters
     * \param lowerpc Minimum x-value for data set
     * \param upperpc Maximum x-value for data set
     * \param curveName Name of the data set
     * \param curveOptions Plotting options associated with that data set
     */
    void addSwLog10PcCurve(GnuplotInterface<Scalar> &gnuplot,
                           const MaterialLawParams &params,
                           Scalar lowerpc = 1,
                           Scalar upperpc = 1e9,
                           std::string curveName = "Sw-pc",
                           std::string curveOptions = "w l")
    {
        std::vector<Scalar> sw;
        std::vector<Scalar> pc;
        Scalar pcInterval = std::log10(upperpc) - std::log10(lowerpc);

        Scalar pcTemp, swTemp = 0.0;
        for (int i = 0; i <= numIntervals_; i++)
        {
            pcTemp = std::log10(lowerpc) + pcInterval * Scalar(i) / Scalar(numIntervals_);
            swTemp = MaterialLaw::sw(params, std::pow(10, pcTemp));
            pc.push_back(pcTemp);
            sw.push_back(swTemp);
        }

        gnuplot.setXlabel("log10 capillary pressure [Pa]");
        gnuplot.setYlabel("wetting phase saturation [-]");
        gnuplot.addDataSetToPlot(pc, sw, curveName, curveOptions);
    }

189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
    /*!
     * \brief Add a capillary pressure-saturation gradient data set to the plot
     *
     * \param gnuplot The gnuplot interface
     * \param params The material law parameters
     * \param lowerSat Minimum x-value for data set
     * \param upperSat Maximum x-value for data set
     * \param curveName Name of the data set
     * \param curveOptions Plotting options associated with that data set
     */
    void adddpcdswcurve(GnuplotInterface<Scalar> &gnuplot,
                        const MaterialLawParams &params,
                        Scalar lowerSat = 0.0,
                        Scalar upperSat = 1.0,
                        std::string curveName = "dpcdsw",
                        std::string curveOptions = "w l")
    {
        std::vector<Scalar> sw;
        std::vector<Scalar> dpcdsw;
        Scalar satInterval = upperSat - lowerSat;

        Scalar swTemp, dpcdswTemp = 0.0;
        for (int i = 0; i <= numIntervals_; i++)
        {
            swTemp = lowerSat + satInterval * Scalar(i) / Scalar(numIntervals_);
            dpcdswTemp = MaterialLaw::dpc_dsw(params, swTemp);
            if (checkValues_(swTemp, dpcdsw))
            {
                sw.push_back(swTemp);
                dpcdsw.push_back(dpcdswTemp);
            }
        }

        gnuplot.setXlabel("wetting phase saturation [-]");
        gnuplot.setYlabel("gradient of the pc-Sw curve [Pa]");
        gnuplot.addDataSetToPlot(sw, dpcdsw, curveName, curveOptions);
    }

    /*!
     * \brief Add a saturation-capillary pressure gradient data set to the plot
     *
     * \param gnuplot The gnuplot interface
     * \param params The material law parameters
     * \param lowerpc Minimum x-value for data set
     * \param upperpc Maximum x-value for data set
     * \param curveName Name of the data set
     * \param curveOptions Plotting options associated with that data set
     */
    void adddswdpccurve(GnuplotInterface<Scalar> &gnuplot,
                        const MaterialLawParams &params,
                        Scalar lowerpc = 0.0,
                        Scalar upperpc = 5000.0,
                        std::string curveName = "dswdpc",
                        std::string curveOptions = "w l")
    {
        std::vector<Scalar> pc;
        std::vector<Scalar> dswdpc;
        Scalar pcInterval = upperpc - lowerpc;

        Scalar dswdpcTemp, pcTemp = 0.0;
        for (int i = 0; i <= numIntervals_; i++)
        {
            pcTemp = lowerpc + pcInterval * Scalar(i) / Scalar(numIntervals_);
            dswdpcTemp = MaterialLaw::dsw_dpc(params, pcTemp);
            if (checkValues_(pcTemp, dswdpcTemp))
            {
                pc.push_back(pcTemp);
                dswdpc.push_back(dswdpcTemp);
            }
        }

        gnuplot.setXlabel("capillary pressure [Pa]");
        gnuplot.setYlabel("gradient of the Sw-pc curve [1/Pa]");
        gnuplot.addDataSetToPlot(pc, dswdpc, curveName, curveOptions);
    }

    /*!
     * \brief Add relative permeabilities data sets to the plot
     *
     * \param gnuplot The gnuplot interface
     * \param params The material law parameters
     * \param lowerSat Minimum x-value for data set
     * \param upperSat Maximum x-value for data set
     * \param curveName Name of the data set
     * \param curveOptions Plotting options associated with that data set
     */
    void addkrcurves(GnuplotInterface<Scalar> &gnuplot,
                      const MaterialLawParams &params,
                      Scalar lowerSat = 0.0,
                      Scalar upperSat = 1.0,
                      std::string curveName = "kr",
                      std::string curveOptions = "w l")
    {
        std::vector<Scalar> sw;
        std::vector<Scalar> krw;
        std::vector<Scalar> krn;
        Scalar satInterval = upperSat - lowerSat;

        Scalar swTemp, krwTemp, krnTemp = 0.0;
        for (int i = 0; i <= numIntervals_; i++)
        {
            swTemp = lowerSat + satInterval * Scalar(i) / Scalar(numIntervals_);
            krwTemp = MaterialLaw::krw(params, swTemp);
            krnTemp = MaterialLaw::krn(params, swTemp);
            if (checkValues_(swTemp, krwTemp) && checkValues_(swTemp, krnTemp))
            {
                sw.push_back(swTemp);
                krw.push_back(krwTemp);
                krn.push_back(krnTemp);
            }
        }

        gnuplot.setXlabel("wetting phase saturation [-]");
        gnuplot.setYlabel("relative permeability [-]");
        gnuplot.addDataSetToPlot(sw, krw, curveName + "_krw", curveOptions);
304
        gnuplot.addDataSetToPlot(sw, krn, curveName + "_krn", curveOptions);
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
    }

    /*!
     * \brief Add relative permeabilities gradients data sets to the plot
     *
     * \param gnuplot The gnuplot interface
     * \param params The material law parameters
     * \param lowerSat Minimum x-value for data set
     * \param upperSat Maximum x-value for data set
     * \param curveName Name of the data set
     * \param curveOptions Plotting options associated with that data set
     */
    void adddkrdswcurves(GnuplotInterface<Scalar> &gnuplot,
                         const MaterialLawParams &params,
                         Scalar lowerSat = 0.0,
                         Scalar upperSat = 1.0,
                         std::string curveName = "dkrndsw",
                         std::string curveOptions = "w l")
    {
        std::vector<Scalar> sw;
        std::vector<Scalar> dkrw_dsw;
        std::vector<Scalar> dkrn_dsw;
        Scalar satInterval = upperSat - lowerSat;

        Scalar swTemp, dkrwdswTemp, dkrndswTemp = 0.0;
        for (int i = 0; i <= numIntervals_; i++)
        {
            swTemp = lowerSat + satInterval * Scalar(i) / Scalar(numIntervals_);
            dkrwdswTemp = MaterialLaw::dkrw_dsw(params, swTemp);
            dkrndswTemp = MaterialLaw::dkrn_dsw(params, swTemp);
            if (checkValues_(swTemp, dkrwdswTemp) && checkValues_(swTemp, dkrndswTemp))
            {
                sw.push_back(swTemp);
                dkrw_dsw.push_back(dkrwdswTemp);
                dkrn_dsw.push_back(dkrndswTemp);
            }
        }

        gnuplot.setXlabel("wetting phase saturation [-]");
        gnuplot.setYlabel("gradient of the kr-Sw function [-]");
        gnuplot.addDataSetToPlot(sw, dkrw_dsw, curveName + "_dkrw_dsw", curveOptions);
        gnuplot.addDataSetToPlot(sw, dkrn_dsw, curveName + "_dkrn_dsw", curveOptions);
    }

349
private:
350
351
352
353
354
355
    /*!
     * \brief Check the values for occurrences of nan and inf
     *
     * \param value1 A data point value
     * \param value2 An other data point value
     */
356
    bool checkValues_(Scalar value1, Scalar value2)
357
    {
358
359
360
361
        using std::isnan;
        using std::isinf;
        return !isnan(value1) && !isinf(value1)
               && !isnan(value2) && !isinf(value2);
362
363
    }

Thomas Fetzer's avatar
Thomas Fetzer committed
364
365
    int numIntervals_;
};
366
367

} // end namespace Dumux
Thomas Fetzer's avatar
Thomas Fetzer committed
368
369

#endif // DUMUX_PLOT_FLUID_MATRIX_LAW_HH