geode/
model.rs

1#![allow(unused)]
2//! The `model` module contains the core definitions for geoscience physics modeling.
3//!
4//! - `Physics`: Represents different types of physical models.
5//! - `CompositionalPhysics`: A specific model for compositional systems.
6
7pub mod domain;
8pub mod material;
9pub use material::Material;
10use schemars::JsonSchema;
11
12use std::{collections::HashMap, str::FromStr};
13
14use self::domain::Domain;
15use compositional::CompositionalPhysics;
16use serde::{Deserialize, Serialize};
17
18mod compositional {
19    use crate::parse::quantity::*;
20    use std::collections::HashMap;
21
22    use schemars::JsonSchema;
23    use serde::{Deserialize, Serialize};
24
25    /// Represents a component in a compositional physics model, such as a
26    /// molecule or chemical species.
27    #[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Deserialize, JsonSchema)]
28    pub struct Component {
29        pub mass: MolarMass,
30    }
31
32    /// # Compositional Physics
33    ///
34    /// Describe compositional physics YEAH
35    #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
36    pub struct CompositionalPhysics {
37        pub components: HashMap<String, Component>,
38        pub phases: Vec<String>,
39    }
40}
41
42/// Hello Lyss, you're such a bg.
43#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
44pub struct Physics {
45    compositional: CompositionalPhysics,
46}
47
48#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
49pub struct GeoscienceModel {
50    pub physics: Physics,
51    pub domain: Domain,
52    #[serde(default)]
53    pub materials: HashMap<String, Option<Material>>,
54}
55
56impl FromStr for GeoscienceModel {
57    type Err = serde_yaml::Error;
58
59    /// Converts a YAML formatted string into a `GeoscienceModel`.
60    /// This allows the use of the `FromStr` trait to parse YAML strings
61    /// directly into the model, with graceful error handling.
62    fn from_str(s: &str) -> Result<Self, Self::Err> {
63        Self::from_yaml(s)
64    }
65}
66
67impl GeoscienceModel {
68    /// Constructs a `GeoscienceModel` from a YAML string input using Serde.
69    /// It attempts to deserialize the input and returns a Result with either
70    /// a `GeoscienceModel` instance on success, or a `serde_yaml::Error` on failure.
71    fn from_yaml(s: &str) -> Result<Self, serde_yaml::Error> {
72        Ok(serde_yaml::from_str(s)?)
73    }
74}