diff --git a/Cargo.lock b/Cargo.lock index 203ce8e..db5a28b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1678,6 +1678,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "oscps-lib" version = "0.1.0" +dependencies = [ + "uom", +] [[package]] name = "overload" @@ -3077,6 +3080,16 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" +[[package]] +name = "uom" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffd36e5350a65d112584053ee91843955826bf9e56ec0d1351214e01f6d7cd9c" +dependencies = [ + "num-traits", + "typenum", +] + [[package]] name = "url" version = "2.5.2" diff --git a/Cargo.toml b/Cargo.toml index 043f4ff..ee0796e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] +resolver = "2" members = [ "oscps-lib", diff --git a/oscps-lib/Cargo.toml b/oscps-lib/Cargo.toml index aa25f17..797037d 100644 --- a/oscps-lib/Cargo.toml +++ b/oscps-lib/Cargo.toml @@ -4,3 +4,4 @@ version = "0.1.0" edition = "2021" [dependencies] +uom = "0.36.0" diff --git a/oscps-lib/src/blocks.rs b/oscps-lib/src/blocks.rs new file mode 100644 index 0000000..6f92d08 --- /dev/null +++ b/oscps-lib/src/blocks.rs @@ -0,0 +1,36 @@ +//! # Blocks +//! +//! This file contains traits which describe the traits that will be +//! implemented by various structs to represent different unit operations. +//! +//! For example, if a block is a simple mixer, then it will implement the +//! MassBalance trait but not th +//! + +// use crate::connector; + +// trait MassBalance { +// fn overall_massive_balance() {} +// } + +// trait EnergyBalance { +// fn energy_balance(){} +// } + +// trait ElementBalance { +// fn element_balance(){} +// } + +// pub struct Mixer{ +// pub block_id: String, +// pub input_stream: Vec, +// pub output_stream: connector::Mconnector +// } + +// impl MassBalance for Mixer{ + +// } + +// impl EnergyBalance for Mixer{ + +// } diff --git a/oscps-lib/src/component.rs b/oscps-lib/src/component.rs new file mode 100644 index 0000000..7f64572 --- /dev/null +++ b/oscps-lib/src/component.rs @@ -0,0 +1,72 @@ +//! # Component + +extern crate uom; + +use uom::si::f64::ThermodynamicTemperature; + +/// A struct to store information regarding the chemical properties of a particular substance. +struct Chemical { + /// The (PubChem)[https://pubchem.ncbi.nlm.nih.gov/] CID of a compound. + component_id: u64, + /// The IUPAC name of a compound + iupac_name: String, + /// The chemical formula of a compound + chemical_formula: String, + /// The chemical properties of a compound + properties: ChemicalProperties +} + +impl Chemical { + /// Create a Chemical struct + /// + /// TODO: Finish this documentation comment + /// + pub fn new(component_id: u64, iupac_name: &str, chemical_formula: &str, properties: ChemicalProperties) -> Chemical { + Chemical { + component_id, + iupac_name: iupac_name.to_string(), + chemical_formula: chemical_formula.to_string(), + properties: properties, + } + } +} + +/// A struct for storing chemical properties of a chemical. +/// +/// This struct allows OSCPS access to the data needed to predict the various +/// physical properties of a substance using thermodynamic correlations, including melting and +/// boiling point, heat capacity, solubility, and many other properites. +struct ChemicalProperties { + /// The melting point of a substance at atmospheric pressure in Kelvin + normal_melting_point: ThermodynamicTemperature, + /// The normal boiling point of a substance at atmospheric pressure in Kelvin + normal_boiling_point: ThermodynamicTemperature, +} + +impl ChemicalProperties { + /// Create a ChemicalProperties struct + /// + pub fn new( + normal_melting_point: ThermodynamicTemperature, + normal_boiling_point: ThermodynamicTemperature + ) -> ChemicalProperties { + ChemicalProperties { + normal_melting_point, + normal_boiling_point, + } + } +} + +use std::io; +use uom::si::thermodynamic_temperature::kelvin; + +#[test] +fn test_chemical_properties_constructor() -> io::Result<()> { + // Test using water + let water_melting_point = ThermodynamicTemperature::new::(273.15); + let water_boiling_point = ThermodynamicTemperature::new::(373.15); + let water_properties = ChemicalProperties::new(water_melting_point, water_boiling_point); + assert_eq!(water_properties.normal_melting_point, water_melting_point); + assert_eq!(water_properties.normal_boiling_point, water_boiling_point); + Ok(()) +} diff --git a/oscps-lib/src/connector.rs b/oscps-lib/src/connector.rs new file mode 100644 index 0000000..3de38ab --- /dev/null +++ b/oscps-lib/src/connector.rs @@ -0,0 +1,11 @@ +//here we will have 2 connector structs + //- Mass Streams + //- Energy Streams +// pub struct Mconnector{ +// m_conn_id: String +// } + +// pub struct Econnector{ +// e_conn_id: String +// } + diff --git a/oscps-lib/src/lib.rs b/oscps-lib/src/lib.rs index 0502ad2..da483b2 100644 --- a/oscps-lib/src/lib.rs +++ b/oscps-lib/src/lib.rs @@ -1,18 +1,8 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right -} - -pub fn hello() -> String { - "Hello from Rust!".to_string() -} - -#[cfg(test)] -mod tests { - use super::*; +mod blocks; +mod connector; +mod component; +mod simulation; - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } +pub fn hello() -> String { + "Hello, world!".to_string() } diff --git a/oscps-lib/src/simulation.rs b/oscps-lib/src/simulation.rs new file mode 100644 index 0000000..78b5c97 --- /dev/null +++ b/oscps-lib/src/simulation.rs @@ -0,0 +1,69 @@ +// use std::collections::HashMap; + +// #[derive(Debug, Clone)] +// struct Settings { +// // Add fields as needed +// } + +// #[derive(Debug, Clone)] +// struct SimulationState { +// // Add fields as needed +// } + +// #[derive(Debug)] +// enum Err { +// BlockNotFound, +// ConnectorNotFound, +// BlockExists, +// ConnectorExists, +// Other(String), +// } + +// struct Simulation { +// blocks: HashMap, +// connectors: HashMap, +// settings: Settings, +// state: SimulationState, +// } + +// impl Simulation { +// pub fn new(settings: Settings, state: SimulationState) -> Self { +// Self { +// blocks: HashMap::new(), +// connectors: HashMap::new(), +// settings, +// state, +// } +// } + +// pub fn add_block(&mut self, block_id: i32, block: Block) -> Result<(), Err> { +// if self.blocks.contains_key(&block_id) { +// return Err(Err::BlockExists); +// } +// self.blocks.insert(block_id, block); +// Ok(()) +// } + +// pub fn add_connector(&mut self, connector_id: i32, connector: Connector) -> Result<(), Err> { +// if self.connectors.contains_key(&connector_id) { +// return Err(Err::ConnectorExists); +// } +// self.connectors.insert(connector_id, connector); +// Ok(()) +// } + +// pub fn remove_block(&mut self, block_id: i32) -> Result<(), Err> { +// if self.blocks.remove(&block_id).is_none() { +// return Err(Err::BlockNotFound); +// } +// Ok(()) +// } + +// pub fn remove_connector(&mut self, connector_id: i32) -> Result<(), Err> { +// if self.connectors.remove(&connector_id).is_none() { +// return Err(Err::ConnectorNotFound); +// } +// Ok(()) +// } + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..de49555 --- /dev/null +++ b/package.json @@ -0,0 +1,7 @@ +{ + "dependencies": { "@tauri-apps/api": "^1.6.0" }, + "devDependencies": { + "@sveltejs/adapter-static": "^3.0.2", + "@tauri-apps/cli": "^1.6.0" + } +} \ No newline at end of file