3.2-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
31namespace Dumux {
37template <class Traits>
39{
40 using Scalar = typename Traits::Scalar;
41 enum { numTempSteps = Traits::numTempSteps, numPressSteps = Traits::numPressSteps };
42
43public:
44 // user default constructor (we can't use "= default" here to satisfy older clang compilers since this class is used as a static data member)
46
47 Scalar minTemp() const
48 { return Traits::minTemp; }
49
50 Scalar maxTemp() const
51 { return Traits::maxTemp; }
52
53 Scalar minPress() const
54 { return Traits::minPress; }
55
56 Scalar maxPress() const
57 { return Traits::maxPress; }
58
59 bool applies(Scalar temperature, Scalar pressure) const
60 {
61 return minTemp() <= temperature && temperature <= maxTemp() &&
63 }
64
65 Scalar at(Scalar temperature, Scalar pressure) const
66 {
68 {
69 if (temperature<minTemp())
73 if(pressure<minPress())
75 if(pressure>maxPress())
77 }
78
80 int j = findPressIdx_(pressure);
81
82 Scalar tempAtI = temperatureAt_(i);
83 Scalar tempAtI1 = temperatureAt_(i + 1);
84 Scalar pressAtI = pressureAt_(j);
85 Scalar pressAtI1 = pressureAt_(j + 1);
86
87 Scalar alpha = (temperature - tempAtI)/(tempAtI1 - tempAtI);
88 Scalar beta = (pressure - pressAtI)/(pressAtI1 - pressAtI);
89
90 // bi-linear interpolation
91 Scalar lowresValue =
92 (1-alpha)*(1-beta)*val(i, j) +
93 (1-alpha)*( beta)*val(i, j + 1) +
94 ( alpha)*(1-beta)*val(i + 1, j) +
95 ( alpha)*( beta)*val(i + 1, j + 1);
96
97 // return the weighted sum of the low- and high-resolution
98 // values
99 return lowresValue;
100 }
101
102 Scalar val(int i, int j) const
103 {
104#if !defined NDEBUG
105 if (i < 0 || i >= Traits::numTempSteps ||
106 j < 0 || j >= Traits::numPressSteps) {
107 DUNE_THROW(NumericalProblem,
108 "Attempt to access element ("
109 << i << ", " << j
110 << ") on a " << Traits::name << " table of size ("
111 << Traits::numTempSteps << ", " << Traits::numPressSteps
112 << ")\n");
113 }
114#endif
115 return Traits::vals[i][j];
116 }
117
118protected:
119 int findTempIdx_(Scalar temperature) const
120 {
121 if (Dune::FloatCmp::eq<Scalar>(temperature, maxTemp()))
122 return numTempSteps - 2;
123 const int result = static_cast<int>((temperature - minTemp())/(maxTemp() - minTemp())*(numTempSteps - 1));
124
125 using std::min;
126 using std::max;
127 return max(0, min(result, numTempSteps - 2));
128 }
129
130 int findPressIdx_(Scalar pressure) const
131 {
132 if (Dune::FloatCmp::eq<Scalar>(pressure, maxPress()))
133 return numPressSteps - 2;
134 const int result = static_cast<int>((pressure - minPress())/(maxPress() - minPress())*(numPressSteps - 1));
135
136 using std::min;
137 using std::max;
138 return max(0, min(result, numPressSteps - 2));
139 }
140
141 Scalar temperatureAt_(int i) const
142 { return i*(maxTemp() - minTemp())/(numTempSteps - 1) + minTemp(); }
143 Scalar pressureAt_(int j) const
144 { return j*(maxPress() - minPress())/(numPressSteps - 1) + minPress(); }
145};
146} // end namespace Dumux
147
148#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:39
Scalar temperatureAt_(int i) const
Definition: co2tablereader.hh:141
int findTempIdx_(Scalar temperature) const
Definition: co2tablereader.hh:119
Scalar at(Scalar temperature, Scalar pressure) const
Definition: co2tablereader.hh:65
Scalar maxPress() const
Definition: co2tablereader.hh:56
bool applies(Scalar temperature, Scalar pressure) const
Definition: co2tablereader.hh:59
TabulatedCO2Properties()
Definition: co2tablereader.hh:45
Scalar minTemp() const
Definition: co2tablereader.hh:47
Scalar minPress() const
Definition: co2tablereader.hh:53
int findPressIdx_(Scalar pressure) const
Definition: co2tablereader.hh:130
Scalar maxTemp() const
Definition: co2tablereader.hh:50
Scalar pressureAt_(int j) const
Definition: co2tablereader.hh:143
Scalar val(int i, int j) const
Definition: co2tablereader.hh:102