follow nx/ny conventions
This commit is contained in:
		
							
								
								
									
										11
									
								
								src/grid.rs
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/grid.rs
									
									
									
									
									
								
							@@ -66,17 +66,6 @@ impl<SBP: super::operators::SbpOperator> Grid<SBP> {
 | 
			
		||||
            operator: std::marker::PhantomData,
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
    pub fn new_from_slice(
 | 
			
		||||
        ny: usize,
 | 
			
		||||
        nx: usize,
 | 
			
		||||
        x: &[f32],
 | 
			
		||||
        y: &[f32],
 | 
			
		||||
    ) -> Result<Self, ndarray::ShapeError> {
 | 
			
		||||
        let x = Array2::from_shape_vec((ny, nx), x.to_vec())?;
 | 
			
		||||
        let y = Array2::from_shape_vec((ny, nx), y.to_vec())?;
 | 
			
		||||
 | 
			
		||||
        Self::new(x, y)
 | 
			
		||||
    }
 | 
			
		||||
    pub fn nx(&self) -> usize {
 | 
			
		||||
        self.x.shape()[1]
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -23,8 +23,10 @@ pub struct MaxwellUniverse(maxwell::System<operators::Upwind4>);
 | 
			
		||||
#[wasm_bindgen]
 | 
			
		||||
impl MaxwellUniverse {
 | 
			
		||||
    #[wasm_bindgen(constructor)]
 | 
			
		||||
    pub fn new(width: usize, height: usize, x: &[f32], y: &[f32]) -> Self {
 | 
			
		||||
        Self(maxwell::System::new(width as usize, height as usize, x, y))
 | 
			
		||||
    pub fn new(height: usize, width: usize, x: &[f32], y: &[f32]) -> Self {
 | 
			
		||||
        let x = ndarray::Array2::from_shape_vec((height, width), x.to_vec()).unwrap();
 | 
			
		||||
        let y = ndarray::Array2::from_shape_vec((height, width), y.to_vec()).unwrap();
 | 
			
		||||
        Self(maxwell::System::new(x, y))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn init(&mut self, x0: f32, y0: f32) {
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,7 @@ impl std::ops::DerefMut for Field {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Field {
 | 
			
		||||
    pub fn new(width: usize, height: usize) -> Self {
 | 
			
		||||
    pub fn new(height: usize, width: usize) -> Self {
 | 
			
		||||
        let field = Array3::zeros((3, height, width));
 | 
			
		||||
 | 
			
		||||
        Self(field)
 | 
			
		||||
@@ -68,6 +68,7 @@ impl Field {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Clone)]
 | 
			
		||||
pub struct System<SBP: SbpOperator> {
 | 
			
		||||
    sys: (Field, Field),
 | 
			
		||||
    wb: WorkBuffers,
 | 
			
		||||
@@ -75,17 +76,17 @@ pub struct System<SBP: SbpOperator> {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<SBP: SbpOperator> System<SBP> {
 | 
			
		||||
    pub fn new(width: usize, height: usize, x: &[f32], y: &[f32]) -> Self {
 | 
			
		||||
        assert_eq!((width * height), x.len());
 | 
			
		||||
        assert_eq!((width * height), y.len());
 | 
			
		||||
    pub fn new(x: Array2<f32>, y: Array2<f32>) -> Self {
 | 
			
		||||
        assert_eq!(x.shape(), y.shape());
 | 
			
		||||
        let ny = x.shape()[0];
 | 
			
		||||
        let nx = x.shape()[1];
 | 
			
		||||
 | 
			
		||||
        let grid = Grid::new(x, y).unwrap();
 | 
			
		||||
 | 
			
		||||
        let grid = Grid::new_from_slice(height, width, x, y).expect(
 | 
			
		||||
            "Could not create grid. Different number of elements compared to width*height?",
 | 
			
		||||
        );
 | 
			
		||||
        Self {
 | 
			
		||||
            sys: (Field::new(width, height), Field::new(width, height)),
 | 
			
		||||
            sys: (Field::new(ny, nx), Field::new(ny, nx)),
 | 
			
		||||
            grid,
 | 
			
		||||
            wb: WorkBuffers::new(width, height),
 | 
			
		||||
            wb: WorkBuffers::new(ny, nx),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -556,15 +557,16 @@ fn SAT_characteristics<SBP: SbpOperator>(
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Clone, Debug)]
 | 
			
		||||
pub struct WorkBuffers {
 | 
			
		||||
    k: [Field; 4],
 | 
			
		||||
    tmp: (Array2<f32>, Array2<f32>, Array2<f32>, Array2<f32>),
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl WorkBuffers {
 | 
			
		||||
    pub fn new(nx: usize, ny: usize) -> Self {
 | 
			
		||||
    pub fn new(ny: usize, nx: usize) -> Self {
 | 
			
		||||
        let arr2 = Array2::zeros((ny, nx));
 | 
			
		||||
        let arr3 = Field::new(nx, ny);
 | 
			
		||||
        let arr3 = Field::new(ny, nx);
 | 
			
		||||
        Self {
 | 
			
		||||
            k: [arr3.clone(), arr3.clone(), arr3.clone(), arr3],
 | 
			
		||||
            tmp: (arr2.clone(), arr2.clone(), arr2.clone(), arr2),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user