use crate::{
bins::BinningScheme,
convergence::Convergence,
diff::Mapping,
geom::Geom,
geom::Shape,
multiproblem::MultiProblem,
orientation::{Euler, EulerConvention, Orientation, Scheme},
problem::Problem,
result::Results,
settings::Settings,
zones::{Zone, ZoneConfig, ZoneType, Zones, ZonesIterator},
};
use pyo3::prelude::*;
#[cfg(feature = "stub-gen")]
use pyo3_stub_gen::{define_stub_info_gatherer, derive::*};
#[cfg_attr(feature = "stub-gen", gen_stub_pyfunction(module = "goad._goad"))]
#[pyfunction]
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
Ok((a + b).to_string())
}
#[cfg_attr(feature = "stub-gen", gen_stub_pyfunction(module = "goad._goad"))]
#[pyfunction]
fn uniform_orientation(num_orients: usize) -> PyResult<Scheme> {
Ok(Scheme::Uniform { num_orients })
}
#[cfg_attr(feature = "stub-gen", gen_stub_pyfunction(module = "goad._goad"))]
#[pyfunction]
fn discrete_orientation(eulers: Vec<Euler>) -> PyResult<Scheme> {
Ok(Scheme::Discrete { eulers })
}
#[cfg_attr(feature = "stub-gen", gen_stub_pyfunction(module = "goad._goad"))]
#[pyfunction]
fn sobol_orientation(num_orients: usize) -> PyResult<Scheme> {
Ok(Scheme::Sobol { num_orients })
}
#[cfg_attr(feature = "stub-gen", gen_stub_pyfunction(module = "goad._goad"))]
#[pyfunction]
fn halton_orientation(num_orients: usize) -> PyResult<Scheme> {
Ok(Scheme::Halton { num_orients })
}
#[cfg_attr(feature = "stub-gen", gen_stub_pyfunction(module = "goad._goad"))]
#[pyfunction]
#[pyo3(signature = (num_orients, euler_convention = None))]
fn create_uniform_orientation(
num_orients: usize,
euler_convention: Option<EulerConvention>,
) -> PyResult<Orientation> {
Ok(Orientation {
scheme: Scheme::Uniform { num_orients },
euler_convention: euler_convention.unwrap_or(EulerConvention::ZYZ),
})
}
#[cfg_attr(feature = "stub-gen", gen_stub_pyfunction(module = "goad._goad"))]
#[pyfunction]
#[pyo3(signature = (eulers, euler_convention = None))]
fn create_discrete_orientation(
eulers: Vec<Euler>,
euler_convention: Option<EulerConvention>,
) -> PyResult<Orientation> {
Ok(Orientation {
scheme: Scheme::Discrete { eulers },
euler_convention: euler_convention.unwrap_or(EulerConvention::ZYZ),
})
}
#[cfg_attr(feature = "stub-gen", gen_stub_pyfunction(module = "goad._goad"))]
#[pyfunction]
#[pyo3(signature = (num_orients, euler_convention = None))]
fn create_sobol_orientation(
num_orients: usize,
euler_convention: Option<EulerConvention>,
) -> PyResult<Orientation> {
Ok(Orientation {
scheme: Scheme::Sobol { num_orients },
euler_convention: euler_convention.unwrap_or(EulerConvention::ZYZ),
})
}
#[cfg_attr(feature = "stub-gen", gen_stub_pyfunction(module = "goad._goad"))]
#[pyfunction]
#[pyo3(signature = (num_orients, euler_convention = None))]
fn create_halton_orientation(
num_orients: usize,
euler_convention: Option<EulerConvention>,
) -> PyResult<Orientation> {
Ok(Orientation {
scheme: Scheme::Halton { num_orients },
euler_convention: euler_convention.unwrap_or(EulerConvention::ZYZ),
})
}
#[cfg(feature = "stub-gen")]
define_stub_info_gatherer!(stub_info);
#[pymodule]
#[pyo3(name = "_goad")]
fn _goad_py(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
m.add_class::<Shape>()?;
m.add_class::<Geom>()?;
m.add_class::<Settings>()?;
m.add_class::<Problem>()?;
m.add_class::<MultiProblem>()?;
m.add_class::<Results>()?;
m.add_class::<BinningScheme>()?;
m.add_class::<Euler>()?;
m.add_class::<EulerConvention>()?;
m.add_class::<Orientation>()?;
m.add_class::<Scheme>()?;
m.add_class::<Mapping>()?;
m.add_class::<crate::params::Param>()?;
m.add_class::<Convergence>()?;
m.add_class::<ZoneType>()?;
m.add_class::<ZoneConfig>()?;
m.add_class::<Zone>()?;
m.add_class::<Zones>()?;
m.add_class::<ZonesIterator>()?;
m.add_function(wrap_pyfunction!(uniform_orientation, m)?)?;
m.add_function(wrap_pyfunction!(discrete_orientation, m)?)?;
m.add_function(wrap_pyfunction!(sobol_orientation, m)?)?;
m.add_function(wrap_pyfunction!(halton_orientation, m)?)?;
m.add_function(wrap_pyfunction!(create_uniform_orientation, m)?)?;
m.add_function(wrap_pyfunction!(create_discrete_orientation, m)?)?;
m.add_function(wrap_pyfunction!(create_sobol_orientation, m)?)?;
m.add_function(wrap_pyfunction!(create_halton_orientation, m)?)?;
Ok(())
}