Skip to content

Commit 0cfccdb

Browse files
authored
Fix the sign of vector weighted densities in cartesian and cylindrical geometry (#120)
* Fix the sign of vector weighted densities in cartesian and cylindrical geometry * add changelog entry
1 parent fc6729a commit 0cfccdb

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

feos-dft/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Renamed the parameter `beta` of the Picard iteration and Anderson mixing solvers to `damping_coefficient`. [#75](https://github.com/feos-org/feos/pull/75)
1818
- Removed generics for units in all structs and traits in favor of static SI units. [#115](https://github.com/feos-org/feos/pull/115)
1919

20+
### Fixed
21+
- Fixed the sign of vector weighted densities in Cartesian and cylindrical geometries. The wrong sign had no effects on the Helmholtz energy and thus on density profiles. [#120](https://github.com/feos-org/feos/pull/120)
22+
2023
## [0.3.2] - 2022-10-13
2124
### Changed
2225
- The 3D DFT functionalities (3D pores, solvation free energy, free-energy-averaged potentials) are hidden behind the new `3d_dft` feature. For the Python package, the feature is always enabled. [#51](https://github.com/feos-org/feos/pull/51)

feos-dft/src/convolver/transform.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use num_dual::*;
55
use rustdct::{DctNum, DctPlanner, TransformType2And3};
66
use rustfft::{num_complex::Complex, Fft, FftPlanner};
77
use std::f64::consts::PI;
8-
use std::ops::{DivAssign, SubAssign};
8+
use std::ops::DivAssign;
99
use std::sync::Arc;
1010

1111
#[derive(Clone, Copy)]
@@ -189,10 +189,10 @@ impl<T: DualNum<f64> + DctNum + ScalarOperand> FourierTransform<T> for Spherical
189189
if scalar {
190190
self.sine_transform(&f_r * &self.r_grid, f_k.view_mut(), false);
191191
} else {
192-
self.cosine_transform(&f_r * &self.r_grid, f_k.view_mut(), false);
193192
let mut f_aux = Array::zeros(f_k.raw_dim());
194-
self.sine_transform(f_r, f_aux.view_mut(), false);
195-
f_k.sub_assign(&(&f_aux / &self.k_grid));
193+
self.cosine_transform(&f_r * &self.r_grid, f_aux.view_mut(), false);
194+
self.sine_transform(f_r, f_k.view_mut(), false);
195+
f_k.assign(&(&f_k / &self.k_grid - &f_aux));
196196
}
197197
f_k.assign(&(&f_k / &self.k_grid));
198198
f_k[0] = T::zero();
@@ -202,10 +202,10 @@ impl<T: DualNum<f64> + DctNum + ScalarOperand> FourierTransform<T> for Spherical
202202
if scalar {
203203
self.sine_transform(&f_k * &self.k_grid, f_r.view_mut(), true);
204204
} else {
205-
self.cosine_transform(&f_k * &self.k_grid, f_r.view_mut(), true);
206205
let mut f_aux = Array::zeros(f_r.raw_dim());
207-
self.sine_transform(f_k, f_aux.view_mut(), true);
208-
f_r.sub_assign(&(&f_aux / &self.r_grid));
206+
self.cosine_transform(&f_k * &self.k_grid, f_aux.view_mut(), true);
207+
self.sine_transform(f_k, f_r.view_mut(), true);
208+
f_r.assign(&(&f_r / &self.r_grid - &f_aux));
209209
}
210210
f_r.assign(&(&f_r / &self.r_grid));
211211
}

feos-dft/src/weight_functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<T: DualNum<f64>> WeightFunction<T> {
116116
w_i.assign(&match self.shape {
117117
WeightFunctionShape::DeltaVec => {
118118
&rik.mapv(|rik| {
119-
(rik.sph_j0() + rik.sph_j2()) * (-radius.powi(3) * 4.0 * FRAC_PI_3 * p)
119+
(rik.sph_j0() + rik.sph_j2()) * (radius.powi(3) * 4.0 * FRAC_PI_3 * p)
120120
}) * &k_x
121121
}
122122
_ => unreachable!(),

0 commit comments

Comments
 (0)