3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
co2tablereader.hh
Go to the documentation of this file.
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
25#ifndef DUMUX_TABULATED_CO2_HH
26#define DUMUX_TABULATED_CO2_HH
27
28#include <dune/common/float_cmp.hh>
30#warning "This header is deprecated and will be removed after release 3.5. Use generated tables (bin/util/make_co2_tables.py), see test/porousmediumflow/co2/"
31
32namespace Dumux {
38template <class Traits>
40{
41 using Scalar = typename Traits::Scalar;
42 enum { numTempSteps = Traits::numTempSteps, numPressSteps = Traits::numPressSteps };
43
44public:
45 // user default constructor (we can't use "= default" here to satisfy older clang compilers since this class is used as a static data member)
47
48 Scalar minTemp() const
49 { return Traits::minTemp; }
50
51 Scalar maxTemp() const
52 { return Traits::maxTemp; }
53
54 Scalar minPress() const
55 { return Traits::minPress; }
56
57 Scalar maxPress() const
58 { return Traits::maxPress; }
59
60 bool applies(Scalar temperature, Scalar pressure) const
61 {
62 return minTemp() <= temperature && temperature <= maxTemp() &&
64 }
65
66 Scalar at(Scalar temperature, Scalar pressure) const
67 {
69 {
70 if (temperature<minTemp())
74 if(pressure<minPress())
76 if(pressure>maxPress())
78 }
79
81 int j = findPressIdx_(pressure);
82
83 Scalar tempAtI = temperatureAt_(i);
84 Scalar tempAtI1 = temperatureAt_(i + 1);
85 Scalar pressAtI = pressureAt_(j);
86 Scalar pressAtI1 = pressureAt_(j + 1);
87
88 Scalar alpha = (temperature - tempAtI)/(tempAtI1 - tempAtI);
89 Scalar beta = (pressure - pressAtI)/(pressAtI1 - pressAtI);
90
91 // bi-linear interpolation
92 Scalar lowresValue =
93 (1-alpha)*(1-beta)*val(i, j) +
94 (1-alpha)*( beta)*val(i, j + 1) +
95 ( alpha)*(1-beta)*val(i + 1, j) +
96 ( alpha)*( beta)*val(i + 1, j + 1);
97
98 // return the weighted sum of the low- and high-resolution
99 // values
100 return lowresValue;
101 }
102
103 Scalar val(int i, int j) const
104 {
105#if !defined NDEBUG
106 if (i < 0 || i >= Traits::numTempSteps ||
107 j < 0 || j >= Traits::numPressSteps) {
108 DUNE_THROW(NumericalProblem,
109 "Attempt to access element ("
110 << i << ", " << j
111 << ") on a " << Traits::name << " table of size ("
112 << Traits::numTempSteps << ", " << Traits::numPressSteps
113 << ")\n");
114 }
115#endif
116 return Traits::vals[i][j];
117 }
118
119protected:
120 int findTempIdx_(Scalar temperature) const
121 {
122 if (Dune::FloatCmp::eq<Scalar>(temperature, maxTemp()))
123 return numTempSteps - 2;
124 const int result = static_cast<int>((temperature - minTemp())/(maxTemp() - minTemp())*(numTempSteps - 1));
125
126 using std::min;
127 using std::max;
128 return max(0, min(result, numTempSteps - 2));
129 }
130
131 int findPressIdx_(Scalar pressure) const
132 {
133 if (Dune::FloatCmp::eq<Scalar>(pressure, maxPress()))
134 return numPressSteps - 2;
135 const int result = static_cast<int>((pressure - minPress())/(maxPress() - minPress())*(numPressSteps - 1));
136
137 using std::min;
138 using std::max;
139 return max(0, min(result, numPressSteps - 2));
140 }
141
142 Scalar temperatureAt_(int i) const
143 { return i*(maxTemp() - minTemp())/(numTempSteps - 1) + minTemp(); }
144 Scalar pressureAt_(int j) const
145 { return j*(maxPress() - minPress())/(numPressSteps - 1) + minPress(); }
146};
147} // end namespace Dumux
148
149#endif
Some exceptions thrown in DuMux
Definition: adapt.hh:29
std::string temperature() noexcept
I/O name of temperature for equilibrium models.
Definition: name.hh:51
std::string pressure(int phaseIdx) noexcept
I/O name of pressure for multiphase systems.
Definition: name.hh:34
Exception thrown if a fixable numerical problem occurs.
Definition: exceptions.hh:39
A generic template for tabulated material laws that depend on two parameters.
Definition: co2tablereader.hh:40
Scalar temperatureAt_(int i) const
Definition: co2tablereader.hh:142
int findTempIdx_(Scalar temperature) const
Definition: co2tablereader.hh:120
Scalar at(Scalar temperature, Scalar pressure) const
Definition: co2tablereader.hh:66
Scalar maxPress() const
Definition: co2tablereader.hh:57
bool applies(Scalar temperature, Scalar pressure) const
Definition: co2tablereader.hh:60
TabulatedCO2Properties()
Definition: co2tablereader.hh:46
Scalar minTemp() const
Definition: co2tablereader.hh:48
Scalar minPress() const
Definition: co2tablereader.hh:54
int findPressIdx_(Scalar pressure) const
Definition: co2tablereader.hh:131
Scalar maxTemp() const
Definition: co2tablereader.hh:51
Scalar pressureAt_(int j) const
Definition: co2tablereader.hh:144
Scalar val(int i, int j) const
Definition: co2tablereader.hh:103