Skip to content

Commit aa7b237

Browse files
committed
rebase
1 parent 5d5aa63 commit aa7b237

File tree

2 files changed

+36
-45
lines changed

2 files changed

+36
-45
lines changed

src/association/mod.rs

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct AssociationSite<A> {
2323
parameters: A,
2424
}
2525

26-
impl<A> AssociationSite<A> {
26+
impl<A: Clone + Default> AssociationSite<A> {
2727
fn new(assoc_comp: usize, site_index: usize, n: f64, parameters: A) -> Self {
2828
Self {
2929
assoc_comp,
@@ -53,7 +53,7 @@ pub struct AssociationRecord<A> {
5353
pub nc: f64,
5454
}
5555

56-
impl<A> AssociationRecord<A> {
56+
impl<A: Clone + Default> AssociationRecord<A> {
5757
pub fn new(parameters: A, na: f64, nb: f64, nc: f64) -> Self {
5858
Self {
5959
parameters,
@@ -81,29 +81,22 @@ impl<A: fmt::Display> fmt::Display for AssociationRecord<A> {
8181
}
8282

8383
#[derive(Clone, Serialize, Deserialize, Default)]
84-
#[serde(from = "AssociationRecordsSerde")]
85-
#[serde(into = "AssociationRecordsSerde")]
86-
pub struct AssociationRecords(Vec<AssociationRecord>);
84+
#[serde(from = "AssociationRecordsSerde<A>")]
85+
#[serde(into = "AssociationRecordsSerde<A>")]
86+
pub struct AssociationRecords<A: Clone + Default>(Vec<AssociationRecord<A>>);
8787

88-
impl AssociationRecords {
88+
impl<A: Clone + Default> AssociationRecords<A> {
8989
pub fn new(
90-
kappa_ab: Option<f64>,
91-
epsilon_k_ab: Option<f64>,
90+
parameters: Option<A>,
9291
na: Option<f64>,
9392
nb: Option<f64>,
9493
nc: Option<f64>,
95-
association_records: Option<Vec<AssociationRecord>>,
94+
association_records: Option<Vec<AssociationRecord<A>>>,
9695
) -> Self {
9796
let mut association_records = association_records.unwrap_or_default();
98-
if kappa_ab.is_some()
99-
|| epsilon_k_ab.is_some()
100-
|| na.is_some()
101-
|| nb.is_some()
102-
|| nc.is_some()
103-
{
97+
if let Some(parameters) = parameters {
10498
association_records.push(AssociationRecord::new(
105-
kappa_ab.unwrap_or_default(),
106-
epsilon_k_ab.unwrap_or_default(),
99+
parameters,
107100
na.unwrap_or_default(),
108101
nb.unwrap_or_default(),
109102
nc.unwrap_or_default(),
@@ -113,27 +106,27 @@ impl AssociationRecords {
113106
}
114107
}
115108

116-
impl Deref for AssociationRecords {
117-
type Target = Vec<AssociationRecord>;
109+
impl<A: Clone + Default> Deref for AssociationRecords<A> {
110+
type Target = Vec<AssociationRecord<A>>;
118111

119-
fn deref(&self) -> &Vec<AssociationRecord> {
112+
fn deref(&self) -> &Vec<AssociationRecord<A>> {
120113
&self.0
121114
}
122115
}
123116

124-
impl DerefMut for AssociationRecords {
125-
fn deref_mut(&mut self) -> &mut Vec<AssociationRecord> {
117+
impl<A: Clone + Default> DerefMut for AssociationRecords<A> {
118+
fn deref_mut(&mut self) -> &mut Vec<AssociationRecord<A>> {
126119
&mut self.0
127120
}
128121
}
129122

130-
impl FromIterator<AssociationRecord> for AssociationRecords {
131-
fn from_iter<T: IntoIterator<Item = AssociationRecord>>(iter: T) -> Self {
123+
impl<A: Clone + Default> FromIterator<AssociationRecord<A>> for AssociationRecords<A> {
124+
fn from_iter<T: IntoIterator<Item = AssociationRecord<A>>>(iter: T) -> Self {
132125
Self(Vec::from_iter(iter))
133126
}
134127
}
135128

136-
impl fmt::Display for AssociationRecords {
129+
impl<A: Clone + Default + fmt::Display> fmt::Display for AssociationRecords<A> {
137130
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
138131
write!(f, "[")?;
139132
for (i, record) in self.0.iter().enumerate() {
@@ -147,16 +140,16 @@ impl fmt::Display for AssociationRecords {
147140
}
148141

149142
#[derive(Serialize, Deserialize)]
150-
struct AssociationRecordsSerde {
143+
struct AssociationRecordsSerde<A> {
151144
#[serde(flatten)]
152-
single: Option<AssociationRecord>,
145+
single: Option<AssociationRecord<A>>,
153146
#[serde(default)]
154147
#[serde(skip_serializing_if = "Vec::is_empty")]
155-
association_records: Vec<AssociationRecord>,
148+
association_records: Vec<AssociationRecord<A>>,
156149
}
157150

158-
impl From<AssociationRecordsSerde> for AssociationRecords {
159-
fn from(value: AssociationRecordsSerde) -> Self {
151+
impl<A: Clone + Default> From<AssociationRecordsSerde<A>> for AssociationRecords<A> {
152+
fn from(value: AssociationRecordsSerde<A>) -> Self {
160153
let mut association_records = value.association_records;
161154
if let Some(record) = value.single {
162155
association_records.push(record);
@@ -165,8 +158,8 @@ impl From<AssociationRecordsSerde> for AssociationRecords {
165158
}
166159
}
167160

168-
impl From<AssociationRecords> for AssociationRecordsSerde {
169-
fn from(value: AssociationRecords) -> Self {
161+
impl<A: Clone + Default> From<AssociationRecords<A>> for AssociationRecordsSerde<A> {
162+
fn from(value: AssociationRecords<A>) -> Self {
170163
let mut association_records = value.0;
171164
let single = if association_records.len() == 1 {
172165
association_records.pop()
@@ -336,7 +329,7 @@ impl<P: AssociationStrength> Association<P> {
336329
}
337330

338331
pub trait AssociationStrength: HardSphereProperties {
339-
type Record: Copy;
332+
type Record: Copy + Default;
340333
type BinaryRecord: Copy;
341334

342335
fn association_strength<D: DualNum<f64> + Copy>(

src/pcsaft/parameters.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ impl FromSegments<f64> for PcSaftRecord {
7070
.flat_map(|(s, n)| {
7171
s.association_records.iter().map(move |record| {
7272
AssociationRecord::new(
73-
record.parameters.kappa_ab,
74-
record.parameters.epsilon_k_ab,
73+
record.parameters,
7574
record.na * n,
7675
record.nb * n,
7776
record.nc * n,
@@ -216,18 +215,17 @@ impl PcSaftRecord {
216215
na: Option<f64>,
217216
nb: Option<f64>,
218217
nc: Option<f64>,
219-
association_records: Option<Vec<AssociationRecord>>,
218+
association_records: Option<Vec<AssociationRecord<PcSaftAssociationRecord>>>,
220219
viscosity: Option<[f64; 4]>,
221220
diffusion: Option<[f64; 5]>,
222221
thermal_conductivity: Option<[f64; 4]>,
223222
) -> PcSaftRecord {
224-
let association_records = AssociationRecords::new(
225-
PcSaftAssociationRecord::new(kappa_ab, epsilon_k_ab),
226-
na,
227-
nb,
228-
nc,
229-
association_records,
230-
);
223+
let assoc = if let (Some(kappa_ab), Some(epsilon_k_ab)) = (kappa_ab, epsilon_k_ab) {
224+
Some(PcSaftAssociationRecord::new(kappa_ab, epsilon_k_ab))
225+
} else {
226+
None
227+
};
228+
let association_records = AssociationRecords::new(assoc, na, nb, nc, association_records);
231229
PcSaftRecord {
232230
m,
233231
sigma,
@@ -614,8 +612,8 @@ impl PcSaftParameters {
614612
o,
615613
"\n|{}|{}|{}|{}|{}|{}|",
616614
component,
617-
association.kappa_ab,
618-
association.epsilon_k_ab,
615+
association.parameters.kappa_ab,
616+
association.parameters.epsilon_k_ab,
619617
association.na,
620618
association.nb,
621619
association.nc

0 commit comments

Comments
 (0)