Mentions légales du service

Skip to content
Snippets Groups Projects
Commit b1472edb authored by Arthur Carcano's avatar Arthur Carcano
Browse files

a few rename

parent 78fda7a2
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ use cvode_5_sys::{
};
mod nvector;
use nvector::NVectorSerial;
use nvector::NVectorSerialHeapAlloced;
pub type Realtype = realtype;
pub type CVector = cvode::N_Vector;
......@@ -61,7 +61,7 @@ impl From<NonNull<CvodeMemoryBlock>> for CvodeMemoryBlockNonNullPtr {
/// See [crate-level](`crate`) documentation for more.
pub struct Solver<UserData, const N: usize> {
mem: CvodeMemoryBlockNonNullPtr,
y0: NVectorSerial<N>,
y0: NVectorSerialHeapAlloced<N>,
sunmatrix: SUNMatrix,
linsolver: SUNLinearSolver,
atol: AbsTolerance<N>,
......@@ -138,7 +138,7 @@ fn check_flag_is_succes(flag: c_int, func_id: &'static str) -> Result<()> {
pub enum AbsTolerance<const SIZE: usize> {
Scalar(Realtype),
Vector(NVectorSerial<SIZE>),
Vector(NVectorSerialHeapAlloced<SIZE>),
}
impl<const SIZE: usize> AbsTolerance<SIZE> {
......@@ -147,7 +147,7 @@ impl<const SIZE: usize> AbsTolerance<SIZE> {
}
pub fn vector(atol: &[Realtype; SIZE]) -> Self {
let atol = NVectorSerial::new_from(atol);
let atol = NVectorSerialHeapAlloced::new_from(atol);
AbsTolerance::Vector(atol)
}
}
......@@ -167,7 +167,7 @@ impl<UserData, const N: usize> Solver<UserData, N> {
let mem_maybenull = unsafe { cvode::CVodeCreate(method as c_int) };
check_non_null(mem_maybenull as *mut CvodeMemoryBlock, "CVodeCreate")?.into()
};
let y0 = NVectorSerial::new_from(y0);
let y0 = NVectorSerialHeapAlloced::new_from(y0);
let matrix = {
let matrix = unsafe {
cvode_5_sys::sunmatrix_dense::SUNDenseMatrix(
......@@ -244,7 +244,7 @@ impl<UserData, const N: usize> Solver<UserData, N> {
)
};
check_flag_is_succes(flag, "CVode")?;
Ok((tret, self.y0.as_ref()))
Ok((tret, self.y0.as_slice()))
}
}
......
......@@ -2,13 +2,14 @@ use std::{convert::TryInto, intrinsics::transmute, ops::Deref, ptr::NonNull};
use cvode_5_sys::{cvode::realtype, nvector_serial};
#[repr(transparent)]
#[derive(Debug)]
pub struct NVectorSerial<const SIZE: usize> {
pub struct NVectorSerialHeapAlloced<const SIZE: usize> {
inner: NonNull<nvector_serial::_generic_N_Vector>,
}
impl<const SIZE: usize> Deref for NVectorSerial<SIZE> {
impl<const SIZE: usize> Deref for NVectorSerialHeapAlloced<SIZE> {
type Target = nvector_serial::_generic_N_Vector;
fn deref(&self) -> &Self::Target {
......@@ -16,12 +17,12 @@ impl<const SIZE: usize> Deref for NVectorSerial<SIZE> {
}
}
impl<const SIZE: usize> NVectorSerial<SIZE> {
pub fn as_ref(&self) -> &[realtype; SIZE] {
impl<const SIZE: usize> NVectorSerialHeapAlloced<SIZE> {
pub fn as_slice(&self) -> &[realtype; SIZE] {
unsafe { transmute(nvector_serial::N_VGetArrayPointer_Serial(self.as_raw())) }
}
pub fn as_mut(&mut self) -> &mut [realtype; SIZE] {
pub fn as_slice_mut(&mut self) -> &mut [realtype; SIZE] {
unsafe { transmute(nvector_serial::N_VGetArrayPointer_Serial(self.as_raw())) }
}
......@@ -34,7 +35,7 @@ impl<const SIZE: usize> NVectorSerial<SIZE> {
pub fn new_from(data: &[realtype; SIZE]) -> Self {
let mut res = Self::new();
res.as_mut().copy_from_slice(data);
res.as_slice_mut().copy_from_slice(data);
res
}
......@@ -43,7 +44,7 @@ impl<const SIZE: usize> NVectorSerial<SIZE> {
}
}
impl<const SIZE: usize> Drop for NVectorSerial<SIZE> {
impl<const SIZE: usize> Drop for NVectorSerialHeapAlloced<SIZE> {
fn drop(&mut self) {
unsafe { nvector_serial::N_VDestroy(self.as_raw()) }
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment