Skip to content

Additional features #9

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 7 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"

members = [
"oscps-lib",
Expand Down
1 change: 1 addition & 0 deletions oscps-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ version = "0.1.0"
edition = "2021"

[dependencies]
uom = "0.36.0"
36 changes: 36 additions & 0 deletions oscps-lib/src/blocks.rs
Original file line number Diff line number Diff line change
@@ -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<connector::Mconnector>,
// pub output_stream: connector::Mconnector
// }

// impl MassBalance for Mixer{

// }

// impl EnergyBalance for Mixer{

// }
72 changes: 72 additions & 0 deletions oscps-lib/src/component.rs
Original file line number Diff line number Diff line change
@@ -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::<kelvin>(273.15);
let water_boiling_point = ThermodynamicTemperature::new::<kelvin>(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(())
}
11 changes: 11 additions & 0 deletions oscps-lib/src/connector.rs
Original file line number Diff line number Diff line change
@@ -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
// }

22 changes: 6 additions & 16 deletions oscps-lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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()
}
69 changes: 69 additions & 0 deletions oscps-lib/src/simulation.rs
Original file line number Diff line number Diff line change
@@ -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<i32, Block>,
// connectors: HashMap<i32, Connector>,
// 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(())
// }


7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"dependencies": { "@tauri-apps/api": "^1.6.0" },
"devDependencies": {
"@sveltejs/adapter-static": "^3.0.2",
"@tauri-apps/cli": "^1.6.0"
}
}