-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathstatehd.rs
More file actions
176 lines (146 loc) · 4.54 KB
/
Copy pathstatehd.rs
File metadata and controls
176 lines (146 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
use crate::StateHD;
use ndarray::Array1;
use num_dual::python::{PyDual3Dual64, PyDual3_64, PyDual64, PyHyperDual64, PyHyperDualDual64};
use num_dual::{Dual, Dual3, Dual3_64, Dual64, DualVec64, HyperDual, HyperDual64};
use pyo3::prelude::*;
use std::convert::From;
#[pyclass(name = "StateF")]
#[derive(Clone)]
pub struct PyStateF(StateHD<f64>);
impl From<StateHD<f64>> for PyStateF {
fn from(s: StateHD<f64>) -> Self {
Self(s)
}
}
#[pyclass(name = "StateHD")]
#[derive(Clone)]
pub struct PyStateHD(StateHD<HyperDual64>);
impl From<StateHD<HyperDual64>> for PyStateHD {
fn from(s: StateHD<HyperDual64>) -> Self {
Self(s)
}
}
#[pyclass(name = "StateHDD")]
#[derive(Clone)]
pub struct PyStateHDD(StateHD<HyperDual<Dual64, f64>>);
impl From<StateHD<HyperDual<Dual64, f64>>> for PyStateHDD {
fn from(s: StateHD<HyperDual<Dual64, f64>>) -> Self {
Self(s)
}
}
#[pyclass(name = "StateHDDV2")]
#[derive(Clone)]
pub struct PyStateHDDV2(StateHD<HyperDual<DualVec64<2>, f64>>);
impl From<StateHD<HyperDual<DualVec64<2>, f64>>> for PyStateHDDV2 {
fn from(s: StateHD<HyperDual<DualVec64<2>, f64>>) -> Self {
Self(s)
}
}
#[pyclass(name = "StateHDDV3")]
#[derive(Clone)]
pub struct PyStateHDDV3(StateHD<HyperDual<DualVec64<3>, f64>>);
impl From<StateHD<HyperDual<DualVec64<3>, f64>>> for PyStateHDDV3 {
fn from(s: StateHD<HyperDual<DualVec64<3>, f64>>) -> Self {
Self(s)
}
}
#[pyclass(name = "StateD")]
#[derive(Clone)]
pub struct PyStateD(StateHD<Dual64>);
impl From<StateHD<Dual64>> for PyStateD {
fn from(s: StateHD<Dual64>) -> Self {
Self(s)
}
}
#[pyclass(name = "StateDDV3")]
#[derive(Clone)]
pub struct PyStateDDV3(StateHD<Dual<DualVec64<3>, f64>>);
impl From<StateHD<Dual<DualVec64<3>, f64>>> for PyStateDDV3 {
fn from(s: StateHD<Dual<DualVec64<3>, f64>>) -> Self {
Self(s)
}
}
#[pyclass(name = "StateD3")]
#[derive(Clone)]
pub struct PyStateD3(StateHD<Dual3_64>);
impl From<StateHD<Dual3_64>> for PyStateD3 {
fn from(s: StateHD<Dual3_64>) -> Self {
Self(s)
}
}
#[pyclass(name = "StateD3D")]
#[derive(Clone)]
pub struct PyStateD3D(StateHD<Dual3<Dual64, f64>>);
impl From<StateHD<Dual3<Dual64, f64>>> for PyStateD3D {
fn from(s: StateHD<Dual3<Dual64, f64>>) -> Self {
Self(s)
}
}
#[pyclass(name = "StateD3DV2")]
#[derive(Clone)]
pub struct PyStateD3DV2(StateHD<Dual3<DualVec64<2>, f64>>);
impl From<StateHD<Dual3<DualVec64<2>, f64>>> for PyStateD3DV2 {
fn from(s: StateHD<Dual3<DualVec64<2>, f64>>) -> Self {
Self(s)
}
}
#[pyclass(name = "StateD3DV3")]
#[derive(Clone)]
pub struct PyStateD3DV3(StateHD<Dual3<DualVec64<3>, f64>>);
impl From<StateHD<Dual3<DualVec64<3>, f64>>> for PyStateD3DV3 {
fn from(s: StateHD<Dual3<DualVec64<3>, f64>>) -> Self {
Self(s)
}
}
macro_rules! impl_state_hd {
($pystate:ty, $pyhd:ty, $state:ty, $hd:ty) => {
#[pymethods]
impl $pystate {
#[new]
pub fn new(temperature: $pyhd, volume: $pyhd, moles: Vec<$pyhd>) -> Self {
let m = Array1::from(moles).mapv(<$hd>::from);
Self(<$state>::new(temperature.into(), volume.into(), m))
}
#[getter]
pub fn get_temperature(&self) -> $pyhd {
<$pyhd>::from(self.0.temperature)
}
#[getter]
pub fn get_volume(&self) -> $pyhd {
<$pyhd>::from(self.0.volume)
}
#[getter]
pub fn get_moles(&self) -> Vec<$pyhd> {
self.0.moles.mapv(<$pyhd>::from).into_raw_vec()
}
#[getter]
pub fn get_partial_density(&self) -> Vec<$pyhd> {
self.0.partial_density.mapv(<$pyhd>::from).into_raw_vec()
}
#[getter]
pub fn get_molefracs(&self) -> Vec<$pyhd> {
self.0.molefracs.mapv(<$pyhd>::from).into_raw_vec()
}
#[getter]
pub fn get_density(&self) -> $pyhd {
<$pyhd>::from(self.0.partial_density.sum())
}
}
};
}
impl_state_hd!(PyStateF, f64, StateHD<f64>, f64);
impl_state_hd!(PyStateHD, PyHyperDual64, StateHD<HyperDual64>, HyperDual64);
impl_state_hd!(
PyStateHDD,
PyHyperDualDual64,
StateHD<HyperDual<Dual64, f64>>,
HyperDual<Dual64, f64>
);
impl_state_hd!(PyStateD, PyDual64, StateHD<Dual64>, Dual64);
impl_state_hd!(PyStateD3, PyDual3_64, StateHD<Dual3_64>, Dual3_64);
impl_state_hd!(
PyStateD3D,
PyDual3Dual64,
StateHD<Dual3<Dual64, f64>>,
Dual3<Dual64, f64>
);