Skip to content

Commit

Permalink
feat: deco model default
Browse files Browse the repository at this point in the history
  • Loading branch information
KG32 committed Jul 2, 2024
1 parent d3fd828 commit ce414e6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ use dive_deco::{ BuehlmannConfig, BuehlmannModel, DecoModel };

fn main() {
// model with default config (GF 100/100)
let default_config = BuehlmannConfig::default();
let model = BuehlmannModel::new(default_config);
let model = BuehlmannModel::default();
println!("{:?}", model.config()); // BuehlmannConfig { gf: (100, 100) }
}
```
Expand Down
8 changes: 5 additions & 3 deletions src/buehlmann/buehlmann_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,24 @@ impl BuehlmannState {
impl DecoModel for BuehlmannModel {
type ConfigType = BuehlmannConfig;

// initialize with default config
fn default() -> Self {
Self::new(BuehlmannConfig::default())
}

/// initialize new Buehlmann (ZH-L16C) model with gradient factors
fn new(config: BuehlmannConfig) -> Self {
// validate config
if let Err(e) = config.validate() {
panic!("Config error [{}]: {}", e.field, e.reason);
}

// air as a default init gas
let initial_model_state = BuehlmannState::initial();

let mut model = Self {
config,
compartments: vec![],
state: initial_model_state,
};

model.create_compartments(ZHL_16C_N2_16A_HE_VALUES, config);

model
Expand Down
9 changes: 6 additions & 3 deletions src/common/deco_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ pub struct DiveState {
pub trait DecoModel {
type ConfigType: DecoModelConfig;

// default
fn default() -> Self;

/// model init
fn new(config: Self::ConfigType) -> Self;

/// get model config
fn config(&self) -> Self::ConfigType;

/// get model dive state
fn dive_state(&self) -> DiveState;

/// model init
fn new(config: Self::ConfigType) -> Self;

/// register step (depth: meters, time: seconds)
fn step(&mut self, depth: Depth, time: Seconds, gas: &Gas);

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use dive_deco::{ BuehlmannModel, BuehlmannConfig, DecoModel, Gas, GradientFactors };

pub fn model_default() -> BuehlmannModel {
BuehlmannModel::new(BuehlmannConfig::default())
BuehlmannModel::default()
}

pub fn model_gf(gf: GradientFactors) -> BuehlmannModel {
Expand Down

0 comments on commit ce414e6

Please sign in to comment.