Skip to content

Commit

Permalink
Complete task 3/3 of #4 and #5
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoireHENRY committed Apr 20, 2024
1 parent 3b8ce8d commit 3b26da1
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 193 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kalast"
version = "0.5.3"
version = "0.5.4"
authors = ["Grégoire Henry <gregoire.henry@oma.be>"]
edition = "2021"
description = "Thermophysical Model for Binary Asteroids"
Expand Down
9 changes: 4 additions & 5 deletions cfg/cfg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ mutual_shadowing = true
[simulation.export]
step = 60
duration = 429120
period = 66528000
cooldown_start = 66441600

# 769 * 86400 = 66441600
Expand All @@ -37,8 +36,8 @@ camera.projection.perspective = 3
[[bodies]]
name = "Didymos"
# mesh.shape.path = "/Users/gregoireh/data/spice/hera/kernels/dsk/g_01165mm_spc_obj_didy_0000n00000_v003.obj"
mesh.shape.path = "/Users/gregoireh/data/DART/meshes/didymos-model-v002/9740mm/g_09740mm_spc_obj_didy_0000n00000_v002.obj"
# mesh = { shape.shape = "sphere_m1", factor = [0.4095, 0.4005, 0.3035] }
# mesh.shape.path = "/Users/gregoireh/data/DART/meshes/didymos-model-v002/9740mm/g_09740mm_spc_obj_didy_0000n00000_v002.obj"
mesh = { shape.shape = "sphere_m1", factor = [0.4095, 0.4005, 0.3035] }
mesh_low = { shape.shape = "sphere_m1", factor = [0.4095, 0.4005, 0.3035] }
interior.grid1d.linear = { size = 40, a = 2e-2 }
spin = { period = 8136, obliquity = 162 }
Expand All @@ -51,8 +50,8 @@ record = { rows = [0], columns = [0], mesh = true, depth = true }
[[bodies]]
name = "Dimorphos"
# mesh.shape.path = "/Users/gregoireh/data/spice/hera/kernels/dsk/g_00243mm_spc_obj_dimo_0000n00000_v004.obj"
mesh.shape.path = "/Users/gregoireh/data/DART/meshes/dimorphos-model-v003/1960mm/g_01960mm_spc_obj_dimo_0000n00000_v003.obj"
# mesh = { shape.shape = "sphere_m1", factor = [0.0895165, 0.0825, 0.0575] }
# mesh.shape.path = "/Users/gregoireh/data/DART/meshes/dimorphos-model-v003/1960mm/g_01960mm_spc_obj_dimo_0000n00000_v003.obj"
mesh = { shape.shape = "sphere_m1", factor = [0.0895165, 0.0825, 0.0575] }
mesh_low = { shape.shape = "sphere_m1", factor = [0.0895165, 0.0825, 0.0575] }
interior.grid1d.linear = { size = 40, a = 2e-2 }
spin = { period = 42912 }
Expand Down
70 changes: 57 additions & 13 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,29 +158,57 @@ impl Config {
// and apply restart settings later.
// Depth TODO

// New restart parameters.
// Restart parameters that are already in main config without restart.

if let Some(factor) = restart.time_step_factor {
config.simulation.step = (config.simulation.step as Float * factor) as usize;
if let Some(elapsed) = new.simulation.elapsed {
config.simulation.elapsed = Some(elapsed);
}

if let Some(factor) = restart.time_step_export_factor {
config.simulation.export.step =
(config.simulation.export.step as Float * factor) as usize;
if let Some(step) = new.simulation.step {
config.simulation.step = Some(step);
}

// Restart parameters that are already in main config without restart.

if let Some(elapsed) = new.simulation.elapsed {
config.simulation.elapsed = Some(elapsed);
if let Some(duration) = new.simulation.duration {
config.simulation.duration = Some(duration);
}

if let Some(pause) = new.simulation.pause_first_it {
config.simulation.pause_first_it = Some(pause);
}

if let Some(cooldown) = new.simulation.export.cooldown_start {
config.simulation.export.cooldown_start = Some(cooldown);
if let Some(shadow) = new.simulation.self_shadowing {
config.simulation.self_shadowing = Some(shadow);
}

if let Some(shadow) = new.simulation.mutual_shadowing {
config.simulation.mutual_shadowing = Some(shadow);
}

if let Some(heating) = new.simulation.self_heating {
config.simulation.self_heating = Some(heating);
}

if let Some(heating) = new.simulation.mutual_heating {
config.simulation.mutual_heating = Some(heating);
}

if let Some(new_export) = new.simulation.export {
if let Some(export) = config.simulation.export.as_mut() {
if let Some(step) = new_export.step {
export.step = Some(step);
}
if let Some(duration) = new_export.duration {
export.duration = Some(duration);
}
if let Some(period) = new_export.period {
export.period = Some(period);
}
if let Some(cooldown) = new_export.cooldown_start {
export.cooldown_start = Some(cooldown);
}
} else {
config.simulation.export = Some(new_export);
}
}

if let Some(p) = new.scene.camera.position.clone() {
Expand Down Expand Up @@ -220,7 +248,23 @@ impl Config {
// Restart parameters to be applied at the end.

if let Some(duration_more) = restart.duration_more {
config.simulation.duration += duration_more;
if let Some(duration) = config.simulation.duration.as_mut() {
*duration += duration_more;
}
}

if let Some(factor) = restart.time_step_factor {
if let Some(step) = config.simulation.step.as_mut() {
*step = (*step as Float * factor) as usize;
}
}

if let Some(factor) = restart.time_step_export_factor {
if let Some(export) = config.simulation.export.as_mut() {
if let Some(step) = export.step.as_mut() {
*step = (*step as Float * factor) as usize;
}
}
}

config.restart = Some(restart);
Expand Down
54 changes: 11 additions & 43 deletions src/config/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ impl From<Error> for CfgSimulationError {
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct CfgSimulation {
#[serde(default)]
pub routines: CfgRoutines,
pub routines: Option<CfgRoutines>,

// In seconds.
#[serde(default)]
pub start: TimeOption,
pub start: Option<TimeOption>,

// In seconds.
#[serde(default)]
pub start_offset: isize,
pub start_offset: Option<isize>,

// In seconds.
#[serde(default)]
pub elapsed: Option<usize>,

#[serde(default)]
pub step: usize,
pub step: Option<usize>,

#[serde(default)]
pub duration: usize,
pub duration: Option<usize>,

#[serde(default)]
pub export: CfgTimeExport,
pub export: Option<CfgTimeExport>,

#[serde(default)]
pub pause_first_it: Option<bool>,
Expand All @@ -65,27 +65,6 @@ pub struct CfgSimulation {
pub mutual_heating: Option<bool>,
}

impl Default for CfgSimulation {
fn default() -> Self {
Self {
routines: CfgRoutines::default(),
start: TimeOption::default(),
start_offset: 0,
elapsed: None,
step: 0,
duration: 0,
export: CfgTimeExport::default(),
pause_first_it: None,
file: None,
read_file_data_only: None,
self_shadowing: None,
mutual_shadowing: None,
self_heating: None,
mutual_heating: None,
}
}
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
// #[serde(tag = "type", content = "args")]
Expand Down Expand Up @@ -132,28 +111,17 @@ impl Default for CfgRoutines {
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct CfgTimeExport {
#[serde(default)]
pub step: usize,
pub step: Option<usize>,

#[serde(default)]
pub duration: usize,
pub duration: Option<usize>,

#[serde(default)]
pub period: usize,
pub period: Option<usize>,

#[serde(default)]
pub cooldown_start: Option<usize>,
}

impl Default for CfgTimeExport {
fn default() -> Self {
Self {
step: 0,
duration: 0,
period: 0,
cooldown_start: None,
}
}
}
18 changes: 13 additions & 5 deletions src/simu/converge.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use crate::{config::Body, config::CfgTimeExport, util::*, AirlessBody, ThermalBodyData};
/*
use crate::{
config::Body, config::CfgTimeExport, config::Config, util::*, AirlessBody, ThermalBodyData,
};
use itertools::izip;
use notify_rust::Notification;
Expand All @@ -13,7 +17,7 @@ pub fn check<P: AsRef<Path>>(
cb: &Body,
info: &mut ThermalBodyData,
path: P,
ct: &CfgTimeExport,
config: &Config,
) -> bool {
let path = path.as_ref();
Expand All @@ -37,9 +41,11 @@ pub fn check<P: AsRef<Path>>(
let zdepth = &asteroid.interior.as_ref().unwrap().as_grid().depth;
let len_time = (ct.duration / ct.step) as usize + 1;
let len_spin = (cb.spin.period / ct.step as Float).ceil() as usize + 1;
let n_spins = (ct.duration as Float / cb.spin.period).floor() as usize;
let export_step = export.step.unwrap_or(default)
let len_time = (export.duration / export.step) as usize + 1;
let len_spin = (cb.spin.period / export.step as Float).ceil() as usize + 1;
let n_spins = (export.duration as Float / cb.spin.period).floor() as usize;
let n_spins_elapsed = time_elapsed / cb.spin.period;
let c0_ii = cb.record.columns[0];
Expand Down Expand Up @@ -202,3 +208,5 @@ pub fn check_all<P: AsRef<Path>>(
converged_all
}
*/
Loading

0 comments on commit 3b26da1

Please sign in to comment.