From 1bfd37b1644c12ec5a98df5b420b8c015fe795cb Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Tue, 17 Aug 2021 12:35:05 +0000 Subject: [PATCH] Fixup max dt --- multigrid/src/system.rs | 49 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/multigrid/src/system.rs b/multigrid/src/system.rs index bcc14dd..dd8bcb7 100644 --- a/multigrid/src/system.rs +++ b/multigrid/src/system.rs @@ -318,8 +318,6 @@ impl BaseSystem { wb_ew: Array2::zeros((4, ny)), }; - // init and send maxdt - // receive maxdt sys.run(); }) .unwrap(), @@ -688,7 +686,10 @@ impl DistributedSystemPart { loop { match self.recv.recv().unwrap() { MsgFromHost::DtSet(dt) => self.dt = dt, - MsgFromHost::DtRequest => todo!(), + MsgFromHost::DtRequest => { + let dt = self.max_dt(); + self.send.send((self.id, MsgToHost::MaxDt(dt))).unwrap(); + } MsgFromHost::Advance(ntime) => self.advance(ntime), MsgFromHost::Output(ntime) => self.output(ntime), MsgFromHost::Stop => return, @@ -696,6 +697,48 @@ impl DistributedSystemPart { } } + fn max_dt(&self) -> Float { + let nx = self.current.nx(); + let ny = self.current.ny(); + + let (rho, rhou, rhov, _e) = self.current.components(); + + let mut max_u: Float = 0.0; + let mut max_v: Float = 0.0; + + for ((((((rho, rhou), rhov), detj_dxi_dx), detj_dxi_dy), detj_deta_dx), detj_deta_dy) in rho + .iter() + .zip(rhou.iter()) + .zip(rhov.iter()) + .zip(self.grid.1.detj_dxi_dx()) + .zip(self.grid.1.detj_dxi_dy()) + .zip(self.grid.1.detj_deta_dx()) + .zip(self.grid.1.detj_deta_dy()) + { + let u = rhou / rho; + let v = rhov / rho; + + let uhat: Float = detj_dxi_dx * u + detj_dxi_dy * v; + let vhat: Float = detj_deta_dx * u + detj_deta_dy * v; + + max_u = max_u.max(uhat.abs()); + max_v = max_v.max(vhat.abs()); + } + + let dx = 1.0 / nx as Float; + let dy = 1.0 / ny as Float; + + let c_dt = Float::max(max_u / dx, max_v / dy); + + let c_max = if self.sbp.is_h2xi() || self.sbp.is_h2eta() { + 0.5 + } else { + 1.0 + }; + + c_max / c_dt + } + fn output(&mut self, _ntime: u64) { let (ny, nx) = (self.current.ny(), self.current.nx()); let rhods = self.output.dataset("rho").unwrap();