dvcompute/simulation/point.rs
1// Copyright (c) 2020-2022 David Sorokin <davsor@mail.ru>, based in Yoshkar-Ola, Russia
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
7use crate::simulation::Run;
8
9/// The modeling point.
10#[repr(C)]
11pub struct Point<'a> {
12
13 /// The current simulation run.
14 #[cfg(any(feature="seq_mode", feature="wasm_mode"))]
15 pub run: &'a Run,
16
17 /// The current simulation run.
18 #[cfg(feature="cons_mode")]
19 pub run: &'a Run<'a>,
20
21 /// The current simulation time.
22 pub time: f64,
23
24 /// The current simulation time priority.
25 pub priority: isize,
26
27 /// The minimal priority to cancel less important processes.
28 pub minimal_priority: isize,
29
30 /// The current integration iteration.
31 pub iteration: usize,
32
33 /// The integration iteration phase.
34 pub phase: i32
35}
36
37impl<'a> Point<'a> {
38
39 /// Return the integration time point by the specified iteration number.
40 #[inline]
41 pub fn with_iteration(&self, n: usize) -> Self {
42 let run = &self.run;
43 let specs = &run.specs;
44 let t0 = specs.start_time;
45 let t2 = specs.stop_time;
46 let dt = specs.dt;
47 let n2 = ((t2 - t0) / dt).floor() as usize;
48 let t = if n == n2 { t2 } else { t0 + (n as f64) * dt };
49 Point {
50 run: run,
51 time: t,
52 priority: self.priority,
53 minimal_priority: self.minimal_priority,
54 iteration: n,
55 phase: -1
56 }
57 }
58
59 /// Trace by displaying the specified message.
60 pub fn trace(&self, msg: &str) {
61 println!("t={}: {}", self.time, msg);
62 }
63}