Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
dumux-repositories
dumux
Commits
3a209ad7
Commit
3a209ad7
authored
Mar 27, 2019
by
Timo Koch
Browse files
[test] Fix tabulation test to actually test something
parent
221952c5
Changes
1
Hide whitespace changes
Inline
Side-by-side
test/material/tabulation/test_tabulation.cc
View file @
3a209ad7
...
...
@@ -28,87 +28,104 @@
#include
<config.h>
#include
<dune/common/float_cmp.hh>
#include
<dumux/material/components/air.hh>
#include
<dumux/material/components/benzene.hh>
#include
<dumux/material/components/brine.hh>
#include
<dumux/material/components/calcite.hh>
#include
<dumux/material/components/calciumion.hh>
#include
<dumux/material/components/cao.hh>
#include
<dumux/material/components/cao2h2.hh>
#include
<dumux/material/components/carbonateion.hh>
#include
<dumux/material/components/ch4.hh>
#include
<dumux/material/components/co2.hh>
#include
<dumux/material/components/granite.hh>
#include
<dumux/material/components/h2.hh>
#include
<dumux/material/components/h2o.hh>
#include
<dumux/material/components/heavyoil.hh>
#include
<dumux/material/components/mesitylene.hh>
#include
<dumux/material/components/n2.hh>
#include
<dumux/material/components/nacl.hh>
#include
<dumux/material/components/o2.hh>
#include
<dumux/material/components/simpleh2o.hh>
#include
<dumux/material/components/trichloroethene.hh>
#include
<dumux/material/components/xylene.hh>
#include
<dumux/material/components/tabulatedcomponent.hh>
#include
<dumux/material/components/componenttraits.hh>
bool
success
;
template
<
class
Scalar
>
void
isSame
(
const
char
*
str
,
Scalar
v
,
Scalar
vRef
,
Scalar
tol
=
1e-3
)
template
<
class
Scalar
>
void
checkEquality
(
const
std
::
string
&
name
,
Scalar
tab
,
Scalar
real
,
Scalar
eps
)
{
using
std
::
abs
;
if
(
abs
(
(
v
-
vRef
)
/
vRef
)
>
tol
)
{
std
::
cout
<<
"error for
\"
"
<<
str
<<
"
\"
: "
<<
(
v
-
vRef
)
/
vRef
*
100
<<
"% difference (tolerance: "
<<
tol
*
100
<<
"%)
\n
"
;
success
=
false
;
//exit(1);
}
if
(
!
Dune
::
FloatCmp
::
eq
(
tab
,
real
,
eps
))
DUNE_THROW
(
Dune
::
InvalidStateException
,
"Tabulated and computed value for "
<<
name
<<
" differs by more than "
<<
eps
*
100
<<
"% "
<<
"(tabulated: "
<<
tab
<<
", "
<<
"actual value: "
<<
real
<<
")"
);
}
int
main
()
int
main
(
int
argc
,
char
*
argv
[]
)
{
using
namespace
Dumux
;
using
Scalar
=
double
;
using
IapwsH2O
=
Dumux
::
Components
::
H2O
<
Scalar
>
;
using
TabulatedH2O
=
Dumux
::
Components
::
TabulatedComponent
<
IapwsH2O
>
;
Scalar
tempMin
=
274.15
;
Scalar
tempMax
=
622.15
;
int
nTemp
=
static_cast
<
int
>
(
tempMax
-
tempMin
)
*
6
/
8
;
Scalar
pMin
=
10.00
;
Scalar
pMax
=
IapwsH2O
::
vaporPressure
(
tempMax
*
1.1
);
int
nPress
=
200
;
// test IapwsH2O in detail
{
using
IapwsH2O
=
Components
::
H2O
<
Scalar
>
;
using
TabulatedH2O
=
Components
::
TabulatedComponent
<
IapwsH2O
>
;
std
::
cout
<<
"Creating tabulation with "
<<
nTemp
*
nPress
<<
" entries per quantity
\n
"
;
TabulatedH2O
::
init
(
tempMin
,
tempMax
,
nTemp
,
pMin
,
pMax
,
nPress
);
// tabulation min/max
const
Scalar
tempMin
=
274.15
;
const
Scalar
tempMax
=
622.15
;
const
int
nTemp
=
800
;
std
::
cout
<<
"Checking tabulation
\n
"
;
success
=
true
;
int
m
=
nTemp
*
3
;
int
n
=
nPress
*
3
;
for
(
int
i
=
0
;
i
<
m
;
++
i
)
{
Scalar
T
=
tempMin
+
(
tempMax
-
tempMin
)
*
Scalar
(
i
)
/
m
;
using
std
::
max
;
if
(
i
%
max
(
1
,
m
/
1000
)
==
0
)
{
std
::
cout
<<
Scalar
(
i
)
/
m
*
100
<<
"% done
\r
"
;
std
::
cout
.
flush
();
}
const
Scalar
pMin
=
1e4
;
const
Scalar
pMax
=
IapwsH2O
::
vaporPressure
(
tempMax
*
1.1
);
const
int
nPress
=
200
;
isSame
(
"vaporPressure"
,
TabulatedH2O
::
vaporPressure
(
T
),
IapwsH2O
::
vaporPressure
(
T
),
1e-3
);
for
(
int
j
=
0
;
j
<
n
;
++
j
)
{
Scalar
p
=
pMin
+
(
pMax
-
pMin
)
*
Scalar
(
j
)
/
n
;
if
(
p
<
IapwsH2O
::
vaporPressure
(
T
)
*
1.001
)
{
Scalar
tol
=
1e-3
;
if
(
p
>
IapwsH2O
::
vaporPressure
(
T
))
tol
=
1e-2
;
Scalar
rho
=
IapwsH2O
::
gasDensity
(
T
,
p
);
//isSame("Iapws::gasPressure", IapwsH2O::gasPressure(T,rho), p, 1e-6);
//isSame("gasPressure", TabulatedH2O::gasPressure(T,rho), p, 2e-2);
isSame
(
"gasEnthalpy"
,
TabulatedH2O
::
gasEnthalpy
(
T
,
p
),
IapwsH2O
::
gasEnthalpy
(
T
,
p
),
tol
);
isSame
(
"gasInternalEnergy"
,
TabulatedH2O
::
gasInternalEnergy
(
T
,
p
),
IapwsH2O
::
gasInternalEnergy
(
T
,
p
),
tol
);
isSame
(
"gasDensity"
,
TabulatedH2O
::
gasDensity
(
T
,
p
),
rho
,
tol
);
isSame
(
"gasViscosity"
,
TabulatedH2O
::
gasViscosity
(
T
,
p
),
IapwsH2O
::
gasViscosity
(
T
,
p
),
tol
);
}
std
::
cout
<<
"Creating tabulation with "
<<
nTemp
*
nPress
<<
" entries per quantity
\n
"
;
TabulatedH2O
::
init
(
tempMin
,
tempMax
,
nTemp
,
pMin
,
pMax
,
nPress
);
constexpr
Scalar
eps
=
1e-1
;
std
::
cout
<<
"Checking tabulation
\n
"
;
const
int
m
=
nTemp
*
3
;
const
int
n
=
nPress
*
3
;
for
(
int
i
=
0
;
i
<
m
;
++
i
)
{
const
Scalar
T
=
tempMin
+
(
tempMax
-
tempMin
)
*
Scalar
(
i
)
/
Scalar
(
m
-
1
);
checkEquality
(
"vaporPressure"
,
TabulatedH2O
::
vaporPressure
(
T
),
IapwsH2O
::
vaporPressure
(
T
),
eps
);
if
(
p
>
IapwsH2O
::
vaporPressure
(
T
)
/
1.001
)
{
Scalar
tol
=
1e-3
;
if
(
p
<
IapwsH2O
::
vaporPressure
(
T
))
tol
=
1e-2
;
Scalar
rho
=
IapwsH2O
::
liquidDensity
(
T
,
p
);
//isSame("Iapws::liquidPressure", IapwsH2O::liquidPressure(T,rho), p, 1e-6);
//isSame("liquidPressure", TabulatedH2O::liquidPressure(T,rho), p, 2e-2);
isSame
(
"liquidEnthalpy"
,
TabulatedH2O
::
liquidEnthalpy
(
T
,
p
),
IapwsH2O
::
liquidEnthalpy
(
T
,
p
),
tol
);
isSame
(
"liquidInternalEnergy"
,
TabulatedH2O
::
liquidInternalEnergy
(
T
,
p
),
IapwsH2O
::
liquidInternalEnergy
(
T
,
p
),
tol
);
isSame
(
"liquidDensity"
,
TabulatedH2O
::
liquidDensity
(
T
,
p
),
rho
,
tol
);
isSame
(
"liquidViscosity"
,
TabulatedH2O
::
liquidViscosity
(
T
,
p
),
IapwsH2O
::
liquidViscosity
(
T
,
p
),
tol
);
for
(
int
j
=
0
;
j
<
n
;
++
j
)
{
const
Scalar
p
=
pMin
+
(
pMax
-
pMin
)
*
Scalar
(
j
)
/
Scalar
(
n
-
1
);
checkEquality
(
"gasEnthalpy"
,
TabulatedH2O
::
gasEnthalpy
(
T
,
p
),
IapwsH2O
::
gasEnthalpy
(
T
,
p
),
eps
);
checkEquality
(
"gasInternalEnergy"
,
TabulatedH2O
::
gasInternalEnergy
(
T
,
p
),
IapwsH2O
::
gasInternalEnergy
(
T
,
p
),
eps
);
checkEquality
(
"gasDensity"
,
TabulatedH2O
::
gasDensity
(
T
,
p
),
IapwsH2O
::
gasDensity
(
T
,
p
),
eps
);
checkEquality
(
"gasViscosity"
,
TabulatedH2O
::
gasViscosity
(
T
,
p
),
IapwsH2O
::
gasViscosity
(
T
,
p
),
eps
);
}
}
//std::cerr << "\n";
}
if
(
success
)
std
::
cout
<<
"
\n
success
\n
"
;
// test if other components can be tabulated
{
Components
::
TabulatedComponent
<
Components
::
Air
<
Scalar
>>::
init
(
273
,
275
,
3
,
1e5
,
1e6
,
3
);
Components
::
TabulatedComponent
<
Components
::
Benzene
<
Scalar
>>::
init
(
273
,
275
,
3
,
1e5
,
1e6
,
3
);
Components
::
TabulatedComponent
<
Components
::
Calcite
<
Scalar
>>::
init
(
273
,
275
,
3
,
1e5
,
1e6
,
3
);
Components
::
TabulatedComponent
<
Components
::
CalciumIon
<
Scalar
>>::
init
(
273
,
275
,
3
,
1e5
,
1e6
,
3
);
Components
::
TabulatedComponent
<
Components
::
CaO
<
Scalar
>>::
init
(
273
,
275
,
3
,
1e5
,
1e6
,
3
);
Components
::
TabulatedComponent
<
Components
::
CaO2H2
<
Scalar
>>::
init
(
273
,
275
,
3
,
1e5
,
1e6
,
3
);
Components
::
TabulatedComponent
<
Components
::
CarbonateIon
<
Scalar
>>::
init
(
273
,
275
,
3
,
1e5
,
1e6
,
3
);
Components
::
TabulatedComponent
<
Components
::
CH4
<
Scalar
>>::
init
(
273
,
275
,
3
,
1e5
,
1e6
,
3
);
Components
::
TabulatedComponent
<
Components
::
Granite
<
Scalar
>>::
init
(
273
,
275
,
3
,
1e5
,
1e6
,
3
);
Components
::
TabulatedComponent
<
Components
::
H2O
<
Scalar
>>::
init
(
273
,
275
,
3
,
1e5
,
1e6
,
3
);
Components
::
TabulatedComponent
<
Components
::
HeavyOil
<
Scalar
>>::
init
(
273
,
275
,
3
,
1e5
,
1e6
,
3
);
Components
::
TabulatedComponent
<
Components
::
Mesitylene
<
Scalar
>>::
init
(
273
,
275
,
3
,
1e5
,
1e6
,
3
);
Components
::
TabulatedComponent
<
Components
::
N2
<
Scalar
>>::
init
(
273
,
275
,
3
,
1e5
,
1e6
,
3
);
Components
::
TabulatedComponent
<
Components
::
NaCl
<
Scalar
>>::
init
(
273
,
275
,
3
,
1e5
,
1e6
,
3
);
Components
::
TabulatedComponent
<
Components
::
O2
<
Scalar
>>::
init
(
273
,
275
,
3
,
1e5
,
1e6
,
3
);
Components
::
TabulatedComponent
<
Components
::
SimpleH2O
<
Scalar
>>::
init
(
273
,
275
,
3
,
1e5
,
1e6
,
3
);
Components
::
TabulatedComponent
<
Components
::
Trichloroethene
<
Scalar
>>::
init
(
273
,
275
,
3
,
1e5
,
1e6
,
3
);
Components
::
TabulatedComponent
<
Components
::
Xylene
<
Scalar
>>::
init
(
273
,
275
,
3
,
1e5
,
1e6
,
3
);
}
return
0
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment