Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make all DFT struct Sync + Send and remove unsendable attribute
  • Loading branch information
prehner authored and g-bauer committed Oct 17, 2022
commit 10d07c2770027244128b5a70a5ba99dbec7076ef
4 changes: 2 additions & 2 deletions feos-core/src/python/cubic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::convert::{TryFrom, TryInto};
use std::sync::Arc;

/// A pure substance parameter for the Peng-Robinson equation of state.
#[pyclass(name = "PengRobinsonRecord", unsendable)]
#[pyclass(name = "PengRobinsonRecord")]
#[derive(Clone)]
pub struct PyPengRobinsonRecord(PengRobinsonRecord);

Expand Down Expand Up @@ -59,7 +59,7 @@ impl_binary_record!();
/// Returns
/// -------
/// PengRobinsonParameters
#[pyclass(name = "PengRobinsonParameters", unsendable)]
#[pyclass(name = "PengRobinsonParameters")]
#[derive(Clone)]
pub struct PyPengRobinsonParameters(pub Arc<PengRobinsonParameters>);

Expand Down
8 changes: 4 additions & 4 deletions feos-core/src/python/phase_equilibria.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
macro_rules! impl_phase_equilibrium {
($eos:ty, $py_eos:ty) => {
/// A thermodynamic two phase equilibrium state.
#[pyclass(name = "PhaseEquilibrium", unsendable)]
#[pyclass(name = "PhaseEquilibrium")]
#[derive(Clone)]
pub struct PyPhaseEquilibrium(PhaseEquilibrium<SIUnit, $eos, 2>);

Expand Down Expand Up @@ -328,7 +328,7 @@ macro_rules! impl_phase_equilibrium {
}

/// A thermodynamic three phase equilibrium state.
#[pyclass(name = "ThreePhaseEquilibrium", unsendable)]
#[pyclass(name = "ThreePhaseEquilibrium")]
#[derive(Clone)]
struct PyThreePhaseEquilibrium(PhaseEquilibrium<SIUnit, $eos, 3>);

Expand Down Expand Up @@ -463,7 +463,7 @@ macro_rules! impl_phase_equilibrium {
}

/// Phase diagram for a pure component or a binary mixture.
#[pyclass(name = "PhaseDiagram", unsendable)]
#[pyclass(name = "PhaseDiagram")]
pub struct PyPhaseDiagram(PhaseDiagram<SIUnit, $eos>);

#[pymethods]
Expand Down Expand Up @@ -871,7 +871,7 @@ macro_rules! impl_phase_equilibrium {
}

/// Phase diagram for a binary mixture exhibiting a heteroazeotrope.
#[pyclass(name = "PhaseDiagramHetero", unsendable)]
#[pyclass(name = "PhaseDiagramHetero")]
pub struct PyPhaseDiagramHetero(PhaseDiagramHetero<SIUnit, $eos>);

#[pymethods]
Expand Down
4 changes: 2 additions & 2 deletions feos-core/src/python/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ macro_rules! impl_state {
/// ------
/// Error
/// When the state cannot be created using the combination of input.
#[pyclass(name = "State", unsendable)]
#[pyclass(name = "State")]
#[derive(Clone)]
#[pyo3(text_signature = "(eos, temperature=None, volume=None, density=None, partial_density=None, total_moles=None, moles=None, molefracs=None, pressure=None, molar_enthalpy=None, molar_entropy=None, molar_internal_energy=None, density_initialization=None, initial_temperature=None)")]
pub struct PyState(pub State<SIUnit, $eos>);
Expand Down Expand Up @@ -1012,7 +1012,7 @@ macro_rules! impl_state {
}


#[pyclass(name = "StateVec", unsendable)]
#[pyclass(name = "StateVec")]
pub struct PyStateVec(Vec<State<SIUnit, $eos>>);

impl From<StateVec<'_, SIUnit, $eos>> for PyStateVec {
Expand Down
22 changes: 11 additions & 11 deletions feos-dft/src/convolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ndarray::{Axis as Axis_nd, RemoveAxis, ScalarOperand, Slice};
use num_dual::*;
use rustdct::DctNum;
use std::ops::{AddAssign, MulAssign, SubAssign};
use std::rc::Rc;
use std::sync::Arc;

mod periodic_convolver;
mod transform;
Expand All @@ -19,7 +19,7 @@ use transform::*;
/// Helmholtz energy functional.
///
/// Parametrized over data types `T` and dimension of the problem `D`.
pub trait Convolver<T, D: Dimension> {
pub trait Convolver<T, D: Dimension>: Sync + Send {
/// Convolve the profile with the given weight function.
fn convolve(&self, profile: Array<T, D>, weight_function: &WeightFunction<T>) -> Array<T, D>;

Expand Down Expand Up @@ -79,9 +79,9 @@ pub struct ConvolverFFT<T, D: Dimension> {
/// Lanczos sigma factor
lanczos_sigma: Option<Array<f64, D>>,
/// Possibly curvilinear Fourier transform in the first dimension
transform: Rc<dyn FourierTransform<T>>,
transform: Arc<dyn FourierTransform<T>>,
/// Vector of additional cartesian Fourier transforms in the other dimensions
cartesian_transforms: Vec<Rc<CartesianTransform<T>>>,
cartesian_transforms: Vec<Arc<CartesianTransform<T>>>,
}

impl<T, D: Dimension + RemoveAxis + 'static> ConvolverFFT<T, D>
Expand All @@ -96,7 +96,7 @@ where
grid: &Grid,
weight_functions: &[WeightFunctionInfo<T>],
lanczos: Option<i32>,
) -> Rc<dyn Convolver<T, D>> {
) -> Arc<dyn Convolver<T, D>> {
match grid {
Grid::Polar(r) => CurvilinearConvolver::new(r, &[], weight_functions, lanczos),
Grid::Spherical(r) => CurvilinearConvolver::new(r, &[], weight_functions, lanczos),
Expand Down Expand Up @@ -125,7 +125,7 @@ where
cartesian_axes: &[&Axis],
weight_functions: &[WeightFunctionInfo<T>],
lanczos: Option<i32>,
) -> Rc<dyn Convolver<T, D>> {
) -> Arc<dyn Convolver<T, D>> {
// initialize the Fourier transform
let mut cartesian_transforms = Vec::with_capacity(cartesian_axes.len());
let mut k_vec = Vec::with_capacity(cartesian_axes.len() + 1);
Expand Down Expand Up @@ -222,7 +222,7 @@ where
}

// Return `FFTConvolver<T, D>`
Rc::new(Self {
Arc::new(Self {
k_abs,
weight_functions: fft_weight_functions,
lanczos_sigma,
Expand Down Expand Up @@ -506,8 +506,8 @@ where
/// The curvilinear convolver accounts for the shift that has to be performed
/// for spherical and polar transforms.
struct CurvilinearConvolver<T, D> {
convolver: Rc<dyn Convolver<T, D>>,
convolver_boundary: Rc<dyn Convolver<T, D>>,
convolver: Arc<dyn Convolver<T, D>>,
convolver_boundary: Arc<dyn Convolver<T, D>>,
}

impl<T, D: Dimension + RemoveAxis + 'static> CurvilinearConvolver<T, D>
Expand All @@ -522,8 +522,8 @@ where
z: &[&Axis],
weight_functions: &[WeightFunctionInfo<T>],
lanczos: Option<i32>,
) -> Rc<dyn Convolver<T, D>> {
Rc::new(Self {
) -> Arc<dyn Convolver<T, D>> {
Arc::new(Self {
convolver: ConvolverFFT::new(Some(r), z, weight_functions, lanczos),
convolver_boundary: ConvolverFFT::new(None, z, weight_functions, lanczos),
})
Expand Down
5 changes: 2 additions & 3 deletions feos-dft/src/convolver/periodic_convolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use rustfft::num_complex::Complex;
use rustfft::{Fft, FftDirection, FftNum, FftPlanner};
use std::f64::consts::PI;
use std::ops::AddAssign;
use std::rc::Rc;
use std::sync::Arc;

#[derive(Clone)]
Expand All @@ -35,7 +34,7 @@ where
axes: &[&Axis],
weight_functions: &[WeightFunctionInfo<T>],
lanczos: Option<i32>,
) -> Rc<dyn Convolver<T, D>> {
) -> Arc<dyn Convolver<T, D>> {
// initialize the Fourier transform
let mut planner = FftPlanner::new();
let mut forward_transforms = Vec::with_capacity(axes.len());
Expand Down Expand Up @@ -130,7 +129,7 @@ where
});
}

Rc::new(Self {
Arc::new(Self {
k_abs,
weight_functions: fft_weight_functions,
lanczos_sigma,
Expand Down
23 changes: 11 additions & 12 deletions feos-dft/src/convolver/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use rustdct::{DctNum, DctPlanner, TransformType2And3};
use rustfft::{num_complex::Complex, Fft, FftPlanner};
use std::f64::consts::PI;
use std::ops::{DivAssign, SubAssign};
use std::rc::Rc;
use std::sync::Arc;

#[derive(Clone, Copy)]
Expand All @@ -26,7 +25,7 @@ impl SinCosTransform {
}
}

pub(super) trait FourierTransform<T: DualNum<f64>> {
pub(super) trait FourierTransform<T: DualNum<f64>>: Sync + Send {
fn forward_transform(&self, f_r: ArrayView1<T>, f_k: ArrayViewMut1<T>, scalar: bool);

fn back_transform(&self, f_k: ArrayViewMut1<T>, f_r: ArrayViewMut1<T>, scalar: bool);
Expand All @@ -37,14 +36,14 @@ pub(super) struct CartesianTransform<T> {
}

impl<T: DualNum<f64> + DctNum + ScalarOperand> CartesianTransform<T> {
pub(super) fn new(axis: &Axis) -> (Rc<dyn FourierTransform<T>>, Array1<f64>) {
pub(super) fn new(axis: &Axis) -> (Arc<dyn FourierTransform<T>>, Array1<f64>) {
let (s, k) = Self::init(axis);
(Rc::new(s), k)
(Arc::new(s), k)
}

pub(super) fn new_cartesian(axis: &Axis) -> (Rc<Self>, Array1<f64>) {
pub(super) fn new_cartesian(axis: &Axis) -> (Arc<Self>, Array1<f64>) {
let (s, k) = Self::init(axis);
(Rc::new(s), k)
(Arc::new(s), k)
}

fn init(axis: &Axis) -> (Self, Array1<f64>) {
Expand Down Expand Up @@ -130,12 +129,12 @@ pub(super) struct SphericalTransform<T> {
}

impl<T: DualNum<f64> + DctNum + ScalarOperand> SphericalTransform<T> {
pub(super) fn new(axis: &Axis) -> (Rc<dyn FourierTransform<T>>, Array1<f64>) {
pub(super) fn new(axis: &Axis) -> (Arc<dyn FourierTransform<T>>, Array1<f64>) {
let points = axis.grid.len();
let length = axis.length();
let k_grid: Array1<_> = (0..=points).map(|v| PI * v as f64 / length).collect();
(
Rc::new(Self {
Arc::new(Self {
r_grid: axis.grid.clone(),
k_grid: k_grid.clone(),
dct: DctPlanner::new().plan_dct2(points),
Expand Down Expand Up @@ -224,7 +223,7 @@ pub(super) struct PolarTransform<T: DctNum> {
}

impl<T: DualNum<f64> + DctNum + ScalarOperand> PolarTransform<T> {
pub(super) fn new(axis: &Axis) -> (Rc<dyn FourierTransform<T>>, Array1<f64>) {
pub(super) fn new(axis: &Axis) -> (Arc<dyn FourierTransform<T>>, Array1<f64>) {
let points = axis.grid.len();

let mut alpha = 0.002_f64;
Expand Down Expand Up @@ -263,7 +262,7 @@ impl<T: DualNum<f64> + DctNum + ScalarOperand> PolarTransform<T> {
ifft.process(jv.as_slice_mut().unwrap());

(
Rc::new(Self {
Arc::new(Self {
r_grid: axis.grid.clone(),
k_grid: k_grid.clone(),
fft,
Expand Down Expand Up @@ -329,8 +328,8 @@ impl<T: DualNum<f64> + DctNum + ScalarOperand> FourierTransform<T> for PolarTran
pub(super) struct NoTransform();

impl NoTransform {
pub(super) fn new<T: DualNum<f64>>() -> (Rc<dyn FourierTransform<T>>, Array1<f64>) {
(Rc::new(Self()), arr1(&[0.0]))
pub(super) fn new<T: DualNum<f64>>() -> (Arc<dyn FourierTransform<T>>, Array1<f64>) {
(Arc::new(Self()), arr1(&[0.0]))
}
}

Expand Down
16 changes: 8 additions & 8 deletions feos-dft/src/functional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use quantity::{QuantityArray, QuantityArray1, QuantityScalar};
use std::borrow::Cow;
use std::fmt;
use std::ops::{AddAssign, Deref, MulAssign};
use std::rc::Rc;
use std::sync::Arc;

/// Wrapper struct for the [HelmholtzEnergyFunctional] trait.
///
Expand Down Expand Up @@ -203,7 +203,7 @@ impl<T: HelmholtzEnergyFunctional> DFT<T> {
&self,
temperature: QuantityScalar<U>,
density: &QuantityArray<U, D::Larger>,
convolver: &Rc<dyn Convolver<f64, D>>,
convolver: &Arc<dyn Convolver<f64, D>>,
) -> EosResult<QuantityArray<U, D>>
where
U: EosUnit,
Expand Down Expand Up @@ -275,7 +275,7 @@ impl<T: HelmholtzEnergyFunctional> DFT<T> {
&self,
temperature: N,
density: &Array<f64, D::Larger>,
convolver: &Rc<dyn Convolver<N, D>>,
convolver: &Arc<dyn Convolver<N, D>>,
) -> EosResult<Array<N, D>>
where
N: DualNum<f64> + ScalarOperand,
Expand Down Expand Up @@ -311,7 +311,7 @@ impl<T: HelmholtzEnergyFunctional> DFT<T> {
&self,
temperature: f64,
density: &Array<f64, D::Larger>,
convolver: &Rc<dyn Convolver<Dual64, D>>,
convolver: &Arc<dyn Convolver<Dual64, D>>,
contributions: Contributions,
) -> EosResult<Array<f64, D>>
where
Expand All @@ -338,7 +338,7 @@ impl<T: HelmholtzEnergyFunctional> DFT<T> {
&self,
temperature: f64,
density: &Array<f64, D::Larger>,
convolver: &Rc<dyn Convolver<Dual64, D>>,
convolver: &Arc<dyn Convolver<Dual64, D>>,
) -> EosResult<Vec<Array<f64, D>>>
where
D: Dimension,
Expand Down Expand Up @@ -382,7 +382,7 @@ impl<T: HelmholtzEnergyFunctional> DFT<T> {
temperature: f64,
density: &Array<f64, D::Larger>,
external_potential: &Array<f64, D::Larger>,
convolver: &Rc<dyn Convolver<Dual64, D>>,
convolver: &Arc<dyn Convolver<Dual64, D>>,
contributions: Contributions,
) -> EosResult<Array<f64, D>>
where
Expand Down Expand Up @@ -411,7 +411,7 @@ impl<T: HelmholtzEnergyFunctional> DFT<T> {
&self,
temperature: f64,
density: &Array<f64, D::Larger>,
convolver: &Rc<dyn Convolver<f64, D>>,
convolver: &Arc<dyn Convolver<f64, D>>,
) -> EosResult<(Array<f64, D>, Array<f64, D::Larger>)>
where
D: Dimension,
Expand Down Expand Up @@ -446,7 +446,7 @@ impl<T: HelmholtzEnergyFunctional> DFT<T> {
&self,
temperature: f64,
functional_derivative: &Array<f64, D::Larger>,
convolver: &Rc<dyn Convolver<f64, D>>,
convolver: &Arc<dyn Convolver<f64, D>>,
) -> Array<f64, D::Larger>
where
D: Dimension,
Expand Down
Loading