proteus
1.9.0
C/C++/Fortran libraries
Toggle main menu visibility
Loading...
Searching...
No Matches
work
cekees
proteus
proteus
m_comp_co2
jet2.h
Go to the documentation of this file.
1
#ifndef JET2_H
2
#define JET2_H
3
// Second-order forward-mode AD in two independent variables (p, z). A Jet2
4
// carries (v, dp, dz, dpp, dpz, dzz) -- value plus exact first and second
5
// partials -- so threading it through the EOS/flash arithmetic yields
6
// machine-precision analytic derivatives with NO finite differencing.
7
//
8
// References:
9
// Griewank, A. and Walther, A., "Evaluating Derivatives: Principles and
10
// Techniques of Algorithmic Differentiation", 2nd ed., SIAM, Philadelphia,
11
// 2008 -- forward mode and the propagation of truncated Taylor (jet)
12
// coefficients that this struct implements for order 2 in two variables.
13
// Fike, J.A. and Alonso, J.J., "The Development of Hyper-Dual Numbers for
14
// Exact Second-Derivative Calculations", AIAA Paper 2011-886, 49th AIAA
15
// Aerospace Sciences Meeting, Orlando, 2011 -- the same second-order
16
// forward-mode idea, specialised to one independent variable.
17
#include <cmath>
18
19
namespace
m_comp_co2
{
20
21
struct
Jet2
{
22
double
v
,
dp
,
dz
,
dpp
,
dpz
,
dzz
;
23
Jet2
(
double
v_=0,
double
dp_=0,
double
dz_=0,
24
double
dpp_=0,
double
dpz_=0,
double
dzz_=0)
25
:
v
(v_),
dp
(dp_),
dz
(dz_),
dpp
(dpp_),
dpz
(dpz_),
dzz
(dzz_) {}
26
static
Jet2
cst
(
double
c
) {
return
Jet2
(
c
); }
27
static
Jet2
var_p
(
double
p) {
return
Jet2
(p, 1.0, 0.0); }
28
static
Jet2
var_z
(
double
z
) {
return
Jet2
(
z
, 0.0, 1.0); }
29
};
30
31
inline
Jet2
operator+
(
const
Jet2
& a,
const
Jet2
& b) {
32
return
Jet2
(a.
v
+b.
v
, a.
dp
+b.
dp
, a.
dz
+b.
dz
, a.
dpp
+b.
dpp
, a.
dpz
+b.
dpz
, a.
dzz
+b.
dzz
);
33
}
34
inline
Jet2
operator+
(
const
Jet2
& a,
double
c
) {
return
Jet2
(a.
v
+
c
, a.
dp
, a.
dz
, a.
dpp
, a.
dpz
, a.
dzz
); }
35
inline
Jet2
operator+
(
double
c
,
const
Jet2
& a) {
return
a +
c
; }
36
inline
Jet2
operator-
(
const
Jet2
& a) {
return
Jet2
(-a.
v
, -a.
dp
, -a.
dz
, -a.
dpp
, -a.
dpz
, -a.
dzz
); }
37
inline
Jet2
operator-
(
const
Jet2
& a,
const
Jet2
& b) {
return
a + (-b); }
38
inline
Jet2
operator-
(
const
Jet2
& a,
double
c
) {
return
Jet2
(a.
v
-
c
, a.
dp
, a.
dz
, a.
dpp
, a.
dpz
, a.
dzz
); }
39
inline
Jet2
operator-
(
double
c
,
const
Jet2
& a) {
return
Jet2
(
c
-a.
v
, -a.
dp
, -a.
dz
, -a.
dpp
, -a.
dpz
, -a.
dzz
); }
40
41
inline
Jet2
operator*
(
const
Jet2
& a,
const
Jet2
& b) {
42
return
Jet2
(a.
v
*b.
v
,
43
a.
dp
*b.
v
+ a.
v
*b.
dp
,
44
a.
dz
*b.
v
+ a.
v
*b.
dz
,
45
a.
dpp
*b.
v
+ 2.0*a.
dp
*b.
dp
+ a.
v
*b.
dpp
,
46
a.
dpz
*b.
v
+ a.
dp
*b.
dz
+ a.
dz
*b.
dp
+ a.
v
*b.
dpz
,
47
a.
dzz
*b.
v
+ 2.0*a.
dz
*b.
dz
+ a.
v
*b.
dzz
);
48
}
49
inline
Jet2
operator*
(
const
Jet2
& a,
double
c
) {
return
Jet2
(a.
v
*
c
, a.
dp
*
c
, a.
dz
*
c
, a.
dpp
*
c
, a.
dpz
*
c
, a.
dzz
*
c
); }
50
inline
Jet2
operator*
(
double
c
,
const
Jet2
& a) {
return
a*
c
; }
51
52
inline
Jet2
recip
(
const
Jet2
&
s
) {
53
double
b =
s
.v,
r
= 1.0/b, b2 = b*b, b3 = b2*b;
54
return
Jet2
(
r
, -
s
.dp/b2, -
s
.dz/b2,
55
(2.0*
s
.dp*
s
.dp - b*
s
.dpp)/b3,
56
(2.0*
s
.dp*
s
.dz - b*
s
.dpz)/b3,
57
(2.0*
s
.dz*
s
.dz - b*
s
.dzz)/b3);
58
}
59
inline
Jet2
operator/
(
const
Jet2
& a,
const
Jet2
& b) {
return
a*
recip
(b); }
60
inline
Jet2
operator/
(
const
Jet2
& a,
double
c
) {
return
Jet2
(a.
v
/
c
, a.
dp
/
c
, a.
dz
/
c
, a.
dpp
/
c
, a.
dpz
/
c
, a.
dzz
/
c
); }
61
inline
Jet2
operator/
(
double
c
,
const
Jet2
& a) {
return
Jet2::cst
(
c
)*
recip
(a); }
62
63
inline
Jet2
jsqrt
(
const
Jet2
&
s
) {
64
double
a =
s
.v, rt = std::sqrt(a), t2 = 2.0*rt, t3 = 4.0*rt*rt*rt;
65
return
Jet2
(rt,
s
.dp/t2,
s
.dz/t2,
66
s
.dpp/t2 -
s
.dp*
s
.dp/t3,
67
s
.dpz/t2 -
s
.dp*
s
.dz/t3,
68
s
.dzz/t2 -
s
.dz*
s
.dz/t3);
69
}
70
inline
Jet2
jexp
(
const
Jet2
&
s
) {
71
double
e = std::exp(
s
.v);
72
return
Jet2
(e, e*
s
.dp, e*
s
.dz,
73
e*(
s
.dpp +
s
.dp*
s
.dp),
74
e*(
s
.dpz +
s
.dp*
s
.dz),
75
e*(
s
.dzz +
s
.dz*
s
.dz));
76
}
77
inline
Jet2
jlog
(
const
Jet2
&
s
) {
78
double
a =
s
.v, a2 = a*a;
79
return
Jet2
(std::log(a),
s
.dp/a,
s
.dz/a,
80
s
.dpp/a -
s
.dp*
s
.dp/a2,
81
s
.dpz/a -
s
.dp*
s
.dz/a2,
82
s
.dzz/a -
s
.dz*
s
.dz/a2);
83
}
84
85
}
// namespace m_comp_co2
86
#endif
r
Double r
Definition
Headers.h:83
s
Double s
Definition
Headers.h:84
z
Double * z
Definition
Headers.h:49
c
#define c(i)
Definition
jf.h:21
m_comp_co2
Definition
co2_brine_eos.h:13
m_comp_co2::jsqrt
Jet2 jsqrt(const Jet2 &s)
Definition
jet2.h:63
m_comp_co2::operator*
Jet2 operator*(const Jet2 &a, const Jet2 &b)
Definition
jet2.h:41
m_comp_co2::recip
Jet2 recip(const Jet2 &s)
Definition
jet2.h:52
m_comp_co2::operator-
Jet2 operator-(const Jet2 &a)
Definition
jet2.h:36
m_comp_co2::jexp
Jet2 jexp(const Jet2 &s)
Definition
jet2.h:70
m_comp_co2::operator/
Jet2 operator/(const Jet2 &a, const Jet2 &b)
Definition
jet2.h:59
m_comp_co2::jlog
Jet2 jlog(const Jet2 &s)
Definition
jet2.h:77
m_comp_co2::operator+
Jet2 operator+(const Jet2 &a, const Jet2 &b)
Definition
jet2.h:31
m_comp_co2::Jet2
Definition
jet2.h:21
m_comp_co2::Jet2::dp
double dp
Definition
jet2.h:22
m_comp_co2::Jet2::dpp
double dpp
Definition
jet2.h:22
m_comp_co2::Jet2::var_z
static Jet2 var_z(double z)
Definition
jet2.h:28
m_comp_co2::Jet2::Jet2
Jet2(double v_=0, double dp_=0, double dz_=0, double dpp_=0, double dpz_=0, double dzz_=0)
Definition
jet2.h:23
m_comp_co2::Jet2::dz
double dz
Definition
jet2.h:22
m_comp_co2::Jet2::dpz
double dpz
Definition
jet2.h:22
m_comp_co2::Jet2::dzz
double dzz
Definition
jet2.h:22
m_comp_co2::Jet2::var_p
static Jet2 var_p(double p)
Definition
jet2.h:27
m_comp_co2::Jet2::cst
static Jet2 cst(double c)
Definition
jet2.h:26
m_comp_co2::Jet2::v
double v
Definition
jet2.h:22
Generated on
for proteus by
1.18.0