bcore/datamodel/
main_file.rs

1//! Main file descriptor.
2//!
3//! Provides objects and methods to read the simulation's main file.
4//! The object hierarchy mimics the file's structure:
5
6use super::{tallies::Tallies, Dim, ResultGroup, Weight};
7use std::collections::HashMap;
8///File's mics section
9#[derive(Debug)]
10pub struct Misc {
11    pub n_node_thread: u64,
12    pub n_rank: u64,
13}
14
15
16
17///Time dependent scalar records
18#[derive(Debug)]
19pub struct MainRecords {
20    pub concentration_liquid: Vec<f64>,
21    pub volume_liquid: Vec<f64>,
22    pub concentration_gas: Option<Vec<f64>>,
23    pub volume_gas: Option<Vec<f64>>,
24    pub mtr: Option<Vec<f64>>,
25    pub tallies: Option<Tallies>,
26    pub dim: Dim,
27    pub time: Vec<f64>,
28}
29
30///Initial information
31#[derive(Debug)]
32pub struct MainInitial {
33    pub delta_time: f64,
34    pub final_time: f64,
35    pub initial_biomass_concentration: f64,
36    pub initial_weight: f64,
37    pub n_map: usize,
38    pub number_compartment: usize,
39    pub number_particles: u64,
40    pub t_per_flow_map: f64,
41}
42
43///Final information
44#[derive(Debug)]
45pub struct MainFInal {
46    pub events: Option<HashMap<String, u64>>,
47    pub number_particles: u64,
48}
49
50///Object that stores data main file
51#[derive(Debug)]
52pub struct MainResult {
53    pub records: MainRecords,
54    pub initial: MainInitial,
55    pub cfinal: Option<MainFInal>, //TODO Add runtime parameter to throw error or not when missing
56    pub misc: Misc,
57    pub weight: Weight,
58}
59
60impl MainResult {
61    pub fn read(name: &str) -> hdf5::Result<MainResult> {
62        let file = hdf5::File::open_as(name, hdf5::file::OpenMode::Read)?;
63
64        let m_ds = file.group("initial_parameters")?;
65        let initial = ResultGroup::<MainInitial>::read_g(&m_ds)?;
66
67        let m_ds = file.group("misc")?;
68        let misc = ResultGroup::<Misc>::read_g(&m_ds)?;
69
70        let m_ds = file.group("records")?;
71        let records = ResultGroup::<MainRecords>::read_g(&m_ds)?;
72
73        let mut cfinal = None;
74        if let Ok(m_ds) = file.group("final_result")
75        {
76            cfinal= Some(ResultGroup::<MainFInal>::read_g(&m_ds)?);
77        }
78
79        let weight = Weight::Single(initial.initial_weight); //TODO switch between single and multi weight
80
81        Ok(MainResult {
82            records,
83            initial,
84            cfinal,
85            misc,
86            weight,
87        })
88    }
89
90    pub fn time(&self) -> &[f64] {
91        &self.records.time
92    }
93}