dvcompute_branch/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#[cfg(feature="dist_mode")]
11#[repr(C)]
12#[derive(Clone)]
13pub struct Point<'a> {
14
15    /// The current simulation run.
16    pub run: &'a Run<'a>,
17
18    /// The current simulation time.
19    pub time: f64,
20
21    /// The current simulation time priority.
22    pub priority: isize,
23
24    /// The minimal priority to cancel less important processes.
25    pub minimal_priority: isize,
26
27    /// The current integration iteration.
28    pub iteration: usize,
29
30    /// The integration iteration phase.
31    pub phase: i32
32}
33
34#[cfg(feature="dist_mode")]
35impl<'a> Point<'a> {
36
37    /// Return the integration time point by the specified iteration number.
38    #[inline]
39    pub fn with_iteration(&self, n: usize) -> Self {
40        let run = &self.run;
41        let specs = &run.specs;
42        let t0 = specs.start_time;
43        let t2 = specs.stop_time;
44        let dt = specs.dt;
45        let n2 = ((t2 - t0) / dt).floor() as usize;
46        let t  = if n == n2 { t2 } else { t0 + (n as f64) * dt };
47        Point {
48            run: run,
49            time: t,
50            priority: self.priority,
51            minimal_priority: self.minimal_priority,
52            iteration: n,
53            phase: -1
54        }
55    }
56
57    /// Trace by displaying the specified message.
58    pub fn trace(&self, msg: &str) {
59        println!("t={}: {}", self.time, msg);
60    }
61}
62
63
64/// The modeling point.
65#[cfg(any(feature="branch_mode", feature="branch_wasm_mode"))]
66#[repr(C)]
67#[derive(Clone)]
68pub struct Point<'a> {
69
70    /// The current simulation run.
71    pub run: &'a Run,
72
73    /// The current simulation time.
74    pub time: f64,
75
76    /// The current simulation time priority.
77    pub priority: isize,
78
79    /// The minimal priority to cancel less important processes.
80    pub minimal_priority: isize,
81
82    /// The current integration iteration.
83    pub iteration: usize,
84
85    /// The integration iteration phase.
86    pub phase: i32
87}
88
89#[cfg(any(feature="branch_mode", feature="branch_wasm_mode"))]
90impl<'a> Point<'a> {
91
92    /// Return the integration time point by the specified iteration number.
93    #[inline]
94    pub fn with_iteration(&self, n: usize) -> Self {
95        let run = &self.run;
96        let specs = &run.specs;
97        let t0 = specs.start_time;
98        let t2 = specs.stop_time;
99        let dt = specs.dt;
100        let n2 = ((t2 - t0) / dt).floor() as usize;
101        let t  = if n == n2 { t2 } else { t0 + (n as f64) * dt };
102        Point {
103            run: run,
104            time: t,
105            priority: self.priority,
106            minimal_priority: self.minimal_priority,
107            iteration: n,
108            phase: -1
109        }
110    }
111
112    /// Trace by displaying the specified message.
113    pub fn trace(&self, msg: &str) {
114        println!("t={}: {}", self.time, msg);
115    }
116}