Skip to main content

cmtool_core/ensight_gold/
mod.rs

1// SPDX-License-Identifier: GPL-3.0-or-later
2
3mod reader;
4use std::{path::Path, sync::Arc};
5mod geo;
6pub mod types;
7pub use crate::{ensight_gold::reader::Reader, utils};
8pub mod scalar;
9pub mod vectors;
10pub use geo::Geometry;
11pub use geo::Part;
12pub mod case;
13pub mod variable;
14
15pub trait RawField: Sized {
16    fn init(geometry: Arc<Geometry>, path: impl AsRef<Path>) -> std::io::Result<Self>;
17}
18
19// impl super::CfdCase for Case {
20//     fn get_root(&self) -> String {
21//         self.root.clone()
22//     }
23
24//     fn get_geometry_relative_path(&self) -> String {
25//         self.geometry_file_path.clone()
26//     }
27// }
28
29#[cfg(test)]
30mod test {
31    use crate::ensight_gold::case::{Case, VariableInfo};
32
33    use std::env;
34    use std::fs::File;
35    use std::io::Write;
36    #[test]
37    fn test_read() {
38        let reference = "FORMAT
39type: ensight gold
40GEOMETRY
41model: test.geo
42VARIABLE
43scalar per element: velocity_magnitude test.scl1
44scalar per element: x_velocity test.scl2
45scalar per element: y_velocity test.scl3
46scalar per element: z_velocity test.scl4
47scalar per element: turb_kinetic_energy test.scl5
48vector per element: velocity test.vel
49SCRIPTS
50metadata: \"test.xml\"
51";
52
53        let mut temp_file_path = env::temp_dir();
54        temp_file_path.push("temp_test_file.encas");
55
56        let mut file = File::create(&temp_file_path).expect("Failed to create temporary file");
57        write!(file, "{}", reference).expect("Failed to write to temporary file");
58
59        let case = Case::read(&temp_file_path).expect("Failed to read temporary file");
60
61        let reference_case = Case {
62            geometry_file_path: "test.geo".to_string(),
63            paths: vec![
64                VariableInfo {
65                    var_type: "scalar".to_string(),
66                    name: "velocity_magnitude".to_string(),
67                    filepath: "test.scl1".to_string(),
68                },
69                VariableInfo {
70                    var_type: "scalar".to_string(),
71                    name: "x_velocity".to_string(),
72                    filepath: "test.scl2".to_string(),
73                },
74                VariableInfo {
75                    var_type: "scalar".to_string(),
76                    name: "y_velocity".to_string(),
77                    filepath: "test.scl3".to_string(),
78                },
79                VariableInfo {
80                    var_type: "scalar".to_string(),
81                    name: "z_velocity".to_string(),
82                    filepath: "test.scl4".to_string(),
83                },
84                VariableInfo {
85                    var_type: "scalar".to_string(),
86                    name: "turb_kinetic_energy".to_string(),
87                    filepath: "test.scl5".to_string(),
88                },
89                VariableInfo {
90                    var_type: "vector".to_string(),
91                    name: "velocity".to_string(),
92                    filepath: "test.vel".to_string(),
93                },
94            ],
95            root: String::new(),
96        };
97
98        assert_eq!(case.geometry_file_path, reference_case.geometry_file_path);
99        assert_eq!(case.paths.len(), reference_case.paths.len());
100
101        for (i, path) in case.paths.iter().enumerate() {
102            let reference_path = &reference_case.paths[i];
103            assert_eq!(path.var_type, reference_path.var_type);
104            assert_eq!(path.name, reference_path.name);
105            assert_eq!(path.filepath, reference_path.filepath);
106        }
107        std::fs::remove_file(&temp_file_path).expect("Failed to remove temporary file");
108    }
109}