Skip to content

Commit

Permalink
Re-added binary thermal routines
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoireHENRY committed Apr 18, 2024
1 parent dbeb53b commit 462e1ed
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 19 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.2"
version = "0.5.3"
authors = ["Grégoire Henry <gregoire.henry@oma.be>"]
edition = "2021"
description = "Thermophysical Model for Binary Asteroids"
Expand Down
20 changes: 18 additions & 2 deletions src/config/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,19 @@ pub struct CfgSimulation {
pub file: Option<FileSetup>,

#[serde(default)]
pub read_file_data_only: bool,
pub read_file_data_only: Option<bool>,

#[serde(default)]
pub self_shadowing: Option<bool>,

#[serde(default)]
pub mutual_shadowing: Option<bool>,

#[serde(default)]
pub self_heating: Option<bool>,

#[serde(default)]
pub mutual_heating: Option<bool>,
}

impl Default for CfgSimulation {
Expand All @@ -65,7 +77,11 @@ impl Default for CfgSimulation {
export: CfgTimeExport::default(),
pause_first_it: None,
file: None,
read_file_data_only: false,
read_file_data_only: None,
self_shadowing: None,
mutual_shadowing: None,
self_heating: None,
mutual_heating: None,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/simu/routines/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub trait Routines: DowncastSync {
time_elapsed = time_elapsed % last;
}

if config.simulation.read_file_data_only {
if let Some(true) = config.simulation.read_file_data_only.as_ref() {
time.file_row = Some(time.iteration);
found = true;
}
Expand Down
77 changes: 63 additions & 14 deletions src/simu/routines/thermal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use itertools::Itertools;
use polars::prelude::{
df, CsvReader, CsvWriter, DataFrame, NamedFrom, SerReader, SerWriter, Series,
};
use std::fs;
use std::{collections::HashSet, fs};

pub struct ThermalBodyData {
pub depth_size: usize,
Expand Down Expand Up @@ -278,21 +278,71 @@ impl Routines for RoutinesThermalDefault {
let mut fluxes_solar =
self.fn_compute_solar_flux(&bodies[body], &bodies_data[body], &self.data[body], sun);

let other_bodies = (0..bodies.len()).collect_vec();
let mut other_bodies_shadowing = HashSet::new();

if config.window.shadows {
let mut shadows: Vec<usize> = vec![];
if let Some(true) = config.simulation.mutual_shadowing.as_ref() {
other_bodies_shadowing.extend(0..bodies.len());
}

for other_body in other_bodies {
shadows = crate::body::shadows(sun, &bodies[body], &bodies[other_body]);
match config.simulation.self_shadowing.as_ref() {
None | Some(false) => {
other_bodies_shadowing.remove(&body);
}
_ => {}
};

let mut other_bodies_heating = HashSet::new();

for &index in &shadows {
fluxes_solar[index] = 0.0;
if let Some(true) = config.simulation.mutual_heating.as_ref() {
other_bodies_heating.extend(0..bodies.len());
}

match config.simulation.self_heating.as_ref() {
None | Some(false) => {
other_bodies_heating.remove(&body);
}
_ => {}
};

let mut shadows = HashSet::new();

for other_body in other_bodies_shadowing {
let shadows_mutual = crate::shadows(sun, &bodies[body], &bodies[other_body]);
shadows.extend(shadows_mutual);
}

for index in shadows {
fluxes_solar[index] = 0.0;
}

let fluxes = fluxes_solar.clone();
self.data[body].fluxes_solar = fluxes_solar.clone();

let mut fluxes = fluxes_solar;

for other_body in other_bodies_heating {
// maybe mut
let vfs = crate::view_factor(&bodies[body], &bodies[other_body], true);

// Pas sûr...
// for (mut vf, face) in izip!(vfs.column_iter_mut(), &b1.surface.faces) {
// vf *= face.area;
// }
// let vfmax = vfs.max();

let diffuse = crate::diffuse_solar_radiation(
&vfs,
&self.data[other_body].fluxes_solar,
&self.data[other_body].albedos,
);

let direct = crate::direct_thermal_heating(
&vfs,
&self.data[other_body].tmp.row(0).clone_owned(),
&self.data[other_body].emissivities,
);

fluxes += diffuse + direct;
}

let temperatures_surface =
self.fn_compute_surface_temperatures(&bodies[body], &self.data[body], &fluxes);
Expand All @@ -317,10 +367,10 @@ impl Routines for RoutinesThermalDefault {
println!(
"Update: {:.0} SF: {:.1}±({:.1})/{:.1}/{:.1} | T: {:.1}±({:.1})/{:.1}/{:.1}",
time.elapsed_seconds(),
fluxes_solar.mean(),
fluxes_solar.variance().sqrt(),
fluxes_solar.max(),
fluxes_solar.min(),
self.data[body].fluxes_solar.mean(),
self.data[body].fluxes_solar.variance().sqrt(),
self.data[body].fluxes_solar.max(),
self.data[body].fluxes_solar.min(),
temperatures_surface.mean(),
temperatures_surface.variance().sqrt(),
temperatures_surface.max(),
Expand All @@ -344,7 +394,6 @@ impl Routines for RoutinesThermalDefault {
}

self.data[body].fluxes = fluxes;
self.data[body].fluxes_solar = fluxes_solar;
}

fn fn_update_body_colormap(
Expand Down

0 comments on commit 462e1ed

Please sign in to comment.