move advance out of Fields
This commit is contained in:
parent
946caf5e1b
commit
066c7619f7
|
@ -61,7 +61,7 @@ impl Universe {
|
||||||
|
|
||||||
/// Using artifical dissipation with the upwind operator
|
/// Using artifical dissipation with the upwind operator
|
||||||
pub fn advance_upwind(&mut self, dt: f32) {
|
pub fn advance_upwind(&mut self, dt: f32) {
|
||||||
Field::advance_upwind::<operators::Upwind4>(
|
maxwell::advance_upwind::<operators::Upwind4>(
|
||||||
&self.sys.0,
|
&self.sys.0,
|
||||||
&mut self.sys.1,
|
&mut self.sys.1,
|
||||||
dt,
|
dt,
|
||||||
|
@ -72,7 +72,7 @@ impl Universe {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn advance(&mut self, dt: f32) {
|
pub fn advance(&mut self, dt: f32) {
|
||||||
Field::advance::<operators::Upwind4>(
|
maxwell::advance::<operators::Upwind4>(
|
||||||
&self.sys.0,
|
&self.sys.0,
|
||||||
&mut self.sys.1,
|
&mut self.sys.1,
|
||||||
dt,
|
dt,
|
||||||
|
|
212
src/maxwell.rs
212
src/maxwell.rs
|
@ -68,124 +68,120 @@ impl Field {
|
||||||
ey.into_shape((ny, nx)).unwrap(),
|
ey.into_shape((ny, nx)).unwrap(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn advance_upwind<UO>(
|
pub(crate) fn advance_upwind<UO>(
|
||||||
&self,
|
prev: &Field,
|
||||||
fut: &mut Self,
|
fut: &mut Field,
|
||||||
dt: f32,
|
dt: f32,
|
||||||
grid: &Grid<UO>,
|
grid: &Grid<UO>,
|
||||||
work_buffers: Option<&mut WorkBuffers>,
|
work_buffers: Option<&mut WorkBuffers>,
|
||||||
) where
|
) where
|
||||||
UO: UpwindOperator,
|
UO: UpwindOperator,
|
||||||
{
|
{
|
||||||
assert_eq!(self.0.shape(), fut.0.shape());
|
assert_eq!(prev.0.shape(), fut.0.shape());
|
||||||
|
|
||||||
let mut wb: WorkBuffers;
|
let mut wb: WorkBuffers;
|
||||||
let (y, k, tmp) = if let Some(x) = work_buffers {
|
let (y, k, tmp) = if let Some(x) = work_buffers {
|
||||||
(&mut x.y, &mut x.buf, &mut x.tmp)
|
(&mut x.y, &mut x.buf, &mut x.tmp)
|
||||||
} else {
|
} else {
|
||||||
wb = WorkBuffers::new(self.nx(), self.ny());
|
wb = WorkBuffers::new(prev.nx(), prev.ny());
|
||||||
(&mut wb.y, &mut wb.buf, &mut wb.tmp)
|
(&mut wb.y, &mut wb.buf, &mut wb.tmp)
|
||||||
|
};
|
||||||
|
|
||||||
|
let boundaries = BoundaryTerms {
|
||||||
|
north: Boundary::This,
|
||||||
|
south: Boundary::This,
|
||||||
|
west: Boundary::This,
|
||||||
|
east: Boundary::This,
|
||||||
|
};
|
||||||
|
|
||||||
|
for i in 0..4 {
|
||||||
|
// y = y0 + c*kn
|
||||||
|
y.assign(&prev);
|
||||||
|
match i {
|
||||||
|
0 => {}
|
||||||
|
1 | 2 => {
|
||||||
|
y.scaled_add(1.0 / 2.0 * dt, &k[i - 1]);
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
y.scaled_add(dt, &k[i - 1]);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
unreachable!();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let boundaries = BoundaryTerms {
|
RHS_upwind(&mut k[i], &y, grid, &boundaries, tmp);
|
||||||
north: Boundary::This,
|
|
||||||
south: Boundary::This,
|
|
||||||
west: Boundary::This,
|
|
||||||
east: Boundary::This,
|
|
||||||
};
|
|
||||||
|
|
||||||
for i in 0..4 {
|
|
||||||
// y = y0 + c*kn
|
|
||||||
y.assign(&self);
|
|
||||||
match i {
|
|
||||||
0 => {}
|
|
||||||
1 | 2 => {
|
|
||||||
y.scaled_add(1.0 / 2.0 * dt, &k[i - 1]);
|
|
||||||
}
|
|
||||||
3 => {
|
|
||||||
y.scaled_add(dt, &k[i - 1]);
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
unreachable!();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
RHS_upwind(&mut k[i], &y, grid, &boundaries, tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
Zip::from(&mut fut.0)
|
|
||||||
.and(&self.0)
|
|
||||||
.and(&*k[0])
|
|
||||||
.and(&*k[1])
|
|
||||||
.and(&*k[2])
|
|
||||||
.and(&*k[3])
|
|
||||||
.apply(|y1, &y0, &k1, &k2, &k3, &k4| {
|
|
||||||
*y1 = y0 + dt / 6.0 * (k1 + 2.0 * k2 + 2.0 * k3 + k4)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Solving (Au)_x + (Bu)_y
|
Zip::from(&mut fut.0)
|
||||||
/// with:
|
.and(&prev.0)
|
||||||
/// A B
|
.and(&*k[0])
|
||||||
/// [ 0, 0, 0] [ 0, 1, 0]
|
.and(&*k[1])
|
||||||
/// [ 0, 0, -1] [ 1, 0, 0]
|
.and(&*k[2])
|
||||||
/// [ 0, -1, 0] [ 0, 0, 0]
|
.and(&*k[3])
|
||||||
pub(crate) fn advance<SBP>(
|
.apply(|y1, &y0, &k1, &k2, &k3, &k4| *y1 = y0 + dt / 6.0 * (k1 + 2.0 * k2 + 2.0 * k3 + k4));
|
||||||
&self,
|
}
|
||||||
fut: &mut Self,
|
|
||||||
dt: f32,
|
|
||||||
grid: &Grid<SBP>,
|
|
||||||
work_buffers: Option<&mut WorkBuffers>,
|
|
||||||
) where
|
|
||||||
SBP: SbpOperator,
|
|
||||||
{
|
|
||||||
assert_eq!(self.0.shape(), fut.0.shape());
|
|
||||||
|
|
||||||
let mut wb: WorkBuffers;
|
/// Solving (Au)_x + (Bu)_y
|
||||||
let (y, k, tmp) = if let Some(x) = work_buffers {
|
/// with:
|
||||||
(&mut x.y, &mut x.buf, &mut x.tmp)
|
/// A B
|
||||||
} else {
|
/// [ 0, 0, 0] [ 0, 1, 0]
|
||||||
wb = WorkBuffers::new(self.nx(), self.ny());
|
/// [ 0, 0, -1] [ 1, 0, 0]
|
||||||
(&mut wb.y, &mut wb.buf, &mut wb.tmp)
|
/// [ 0, -1, 0] [ 0, 0, 0]
|
||||||
|
pub(crate) fn advance<SBP>(
|
||||||
|
prev: &Field,
|
||||||
|
fut: &mut Field,
|
||||||
|
dt: f32,
|
||||||
|
grid: &Grid<SBP>,
|
||||||
|
work_buffers: Option<&mut WorkBuffers>,
|
||||||
|
) where
|
||||||
|
SBP: SbpOperator,
|
||||||
|
{
|
||||||
|
assert_eq!(prev.0.shape(), fut.0.shape());
|
||||||
|
|
||||||
|
let mut wb: WorkBuffers;
|
||||||
|
let (y, k, tmp) = if let Some(x) = work_buffers {
|
||||||
|
(&mut x.y, &mut x.buf, &mut x.tmp)
|
||||||
|
} else {
|
||||||
|
wb = WorkBuffers::new(prev.nx(), prev.ny());
|
||||||
|
(&mut wb.y, &mut wb.buf, &mut wb.tmp)
|
||||||
|
};
|
||||||
|
|
||||||
|
let boundaries = BoundaryTerms {
|
||||||
|
north: Boundary::This,
|
||||||
|
south: Boundary::This,
|
||||||
|
west: Boundary::This,
|
||||||
|
east: Boundary::This,
|
||||||
|
};
|
||||||
|
|
||||||
|
for i in 0..4 {
|
||||||
|
// y = y0 + c*kn
|
||||||
|
y.assign(&prev);
|
||||||
|
match i {
|
||||||
|
0 => {}
|
||||||
|
1 | 2 => {
|
||||||
|
y.scaled_add(1.0 / 2.0 * dt, &k[i - 1]);
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
y.scaled_add(dt, &k[i - 1]);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
unreachable!();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let boundaries = BoundaryTerms {
|
RHS(&mut k[i], &y, grid, &boundaries, tmp);
|
||||||
north: Boundary::This,
|
|
||||||
south: Boundary::This,
|
|
||||||
west: Boundary::This,
|
|
||||||
east: Boundary::This,
|
|
||||||
};
|
|
||||||
|
|
||||||
for i in 0..4 {
|
|
||||||
// y = y0 + c*kn
|
|
||||||
y.assign(&self);
|
|
||||||
match i {
|
|
||||||
0 => {}
|
|
||||||
1 | 2 => {
|
|
||||||
y.scaled_add(1.0 / 2.0 * dt, &k[i - 1]);
|
|
||||||
}
|
|
||||||
3 => {
|
|
||||||
y.scaled_add(dt, &k[i - 1]);
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
unreachable!();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
RHS(&mut k[i], &y, grid, &boundaries, tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
Zip::from(&mut fut.0)
|
|
||||||
.and(&self.0)
|
|
||||||
.and(&*k[0])
|
|
||||||
.and(&*k[1])
|
|
||||||
.and(&*k[2])
|
|
||||||
.and(&*k[3])
|
|
||||||
.apply(|y1, &y0, &k1, &k2, &k3, &k4| {
|
|
||||||
*y1 = y0 + dt / 6.0 * (k1 + 2.0 * k2 + 2.0 * k3 + k4)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Zip::from(&mut fut.0)
|
||||||
|
.and(&prev.0)
|
||||||
|
.and(&*k[0])
|
||||||
|
.and(&*k[1])
|
||||||
|
.and(&*k[2])
|
||||||
|
.and(&*k[3])
|
||||||
|
.apply(|y1, &y0, &k1, &k2, &k3, &k4| *y1 = y0 + dt / 6.0 * (k1 + 2.0 * k2 + 2.0 * k3 + k4));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
|
|
Loading…
Reference in New Issue