Skip to main content

cmtool_assemble/
data.rs

1// SPDX-License-Identifier: GPL-3.0-or-later
2
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6#[derive(Debug, PartialEq)]
7pub enum FlowDirection {
8    In,
9    Out,
10}
11
12///Required information to describe a feed
13#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
14pub struct FeedFlow {
15    pub flow: f64,
16    pub position: usize,
17    pub output_position: Option<usize>,
18}
19
20///Set of feed for each phase and their id
21#[derive(Default, Clone, Serialize, Deserialize)]
22pub struct ParsedFeeds {
23    pub liq: HashMap<String, FeedFlow>,
24    pub gas: HashMap<String, FeedFlow>,
25}
26
27///Basic about domain
28//TODO: clean what's should be private or not
29#[derive(Default, Clone, Serialize, Deserialize)]
30pub struct DomainInfo {
31    ///Compartment index offset for given reactor (e.g compartment_cumsum[reactor_id]==10)
32    pub(crate) compartment_cumsum: HashMap<String, usize>,
33    pub(crate) total_number_compartment: usize,
34    ///Reactor id of pfr names, needed to ensure global mass balance
35    pub(crate) pfr_names: Vec<String>,
36    pub(crate) is_two_phase_flow: bool,
37}
38impl DomainInfo {
39    pub fn get_relative_compartment_number(
40        &self,
41        reactor_id: &str,
42        relative_index: usize,
43    ) -> Option<usize> {
44        self.compartment_cumsum
45            .get(reactor_id)
46            .map(|cum_sum| relative_index + *cum_sum)
47    }
48
49    pub fn get_total_number_compartment(&self) -> usize {
50        self.total_number_compartment
51    }
52}
53
54///Details about generated domain
55//TODO: clean what's should be private or not
56#[derive(Clone, Serialize, Deserialize, Default)]
57pub struct DomainData {
58    ///connections between partial flowmaps
59    pub(crate) info: DomainInfo,
60    ///Information about feed of the resulting merged domain
61    pub(crate) feeds: Option<ParsedFeeds>,
62    pub(crate) case_path: String,
63    pub run_id: String,
64}
65
66impl DomainData {
67    pub fn feeds(&self) -> &Option<ParsedFeeds> {
68        &self.feeds
69    }
70
71    pub fn info(&self) -> &DomainInfo {
72        &self.info
73    }
74
75    pub fn get_case_path(&self) -> impl AsRef<std::path::Path> {
76        &self.case_path
77    }
78}