Skip to content

Commit

Permalink
module / macro / coords / spice / routines
Browse files Browse the repository at this point in the history
- renamed modules for more explicit name, more will be added and
  refactored soon
- initialized pro macros sub folder for derive trait of body / routines
- more work on equatorial coordinates, angle, and conversion to xyz
- example with spice for DART impact
- reworked and rearranged routines
  • Loading branch information
GregoireHENRY committed Nov 30, 2023
1 parent fb49210 commit 94c6e10
Show file tree
Hide file tree
Showing 34 changed files with 872 additions and 787 deletions.
10 changes: 10 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
Expand Up @@ -52,6 +52,7 @@ lazy_static = "1.0"
dunce = "1.0"
uom = "0.35"
regex = "1.10"
kalast_macros = { path = "macros", version = "0.4.0-beta" }

[dev-dependencies]
rstest = "0.18"
Expand Down
26 changes: 26 additions & 0 deletions examples/ground-based-lightcurve-didymos-spice/cfg/cfg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
window:
export_frames: true

simulation:
start: 2022-09-26
step: 60
duration: 8136
export:
step: 60
duration: 8136

scene:
spice: true
camera:
!earth 2.0

bodies:
- id: Didymos
mesh:
shape: sphere
factor: [0.4095, 0.4005, 0.3035]
smooth: true
material:
albedo: 0.1
spin:
period: 8136
105 changes: 11 additions & 94 deletions examples/viewer-picker/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use kalast::{
routines_viewer_default, simu::Scene, util::*, Asteroid, Body, CfgBody, CfgColormap, ColorMode,
FoldersRun, Result, Routines, RoutinesViewerDefault, Scenario, Time, Window,
simu::Scene, util::*, AirlessBody, ColorMode, Result, Routines, RoutinesViewer, Scenario, Time,
Window,
};

fn main() -> Result<()> {
Expand Down Expand Up @@ -29,12 +29,12 @@ fn main() -> Result<()> {

fn update_surf_face(
routines: &mut RoutinesViewerCustom,
bodies: &mut [Body],
bodies: &mut [AirlessBody],
win: &Window,
faces: &[usize],
ii_body: usize,
) {
let surf = &mut bodies[ii_body].asteroid.surface;
let surf = &mut bodies[ii_body].surface;

for &ii_face in faces {
if !routines.faces.contains(&ii_face) {
Expand All @@ -55,95 +55,19 @@ fn update_surf_face(
}

pub struct RoutinesViewerCustom {
pub default: RoutinesViewerDefault,
pub faces: Vec<usize>,
}

impl Routines for RoutinesViewerCustom {
fn fn_setup_body(&mut self, asteroid: Asteroid, cb: &CfgBody, scene: &Scene) -> Body {
self.default.fn_setup_body(asteroid, cb, scene)
}
fn fn_update_matrix_model(
&self,
ii_body: usize,
ii_other_bodies: &[usize],
cb: &CfgBody,
other_cbs: &[&CfgBody],
bodies: &mut [Body],
time: &Time,
scene: &mut Scene,
) {
self.default.fn_update_matrix_model(
ii_body,
ii_other_bodies,
cb,
other_cbs,
bodies,
time,
scene,
)
}

fn fn_iteration_body(
&mut self,
ii_body: usize,
ii_other_bodies: &[usize],
cb: &CfgBody,
other_cbs: &[&CfgBody],
bodies: &mut [Body],
scene: &Scene,
time: &Time,
) {
self.default
.fn_iteration_body(ii_body, ii_other_bodies, cb, other_cbs, bodies, scene, time)
}

fn fn_update_colormap(
&self,
win: &Window,
cmap: &CfgColormap,
ii_body: usize,
body: &mut Body,
scene: &Scene,
) {
self.default
.fn_update_colormap(win, cmap, ii_body, body, scene)
}

fn fn_export_iteration(
&self,
cb: &CfgBody,
ii_body: usize,
time: &Time,
folders: &FoldersRun,
is_first_it: bool,
) {
self.default
.fn_export_iteration(cb, ii_body, time, folders, is_first_it)
}

fn fn_export_iteration_period(
&self,
cb: &CfgBody,
body: &Body,
ii_body: usize,
folders: &FoldersRun,
exporting_started_elapsed: i64,
is_first_it_export: bool,
) {
self.default.fn_export_iteration_period(
cb,
body,
ii_body,
folders,
exporting_started_elapsed,
is_first_it_export,
)
impl RoutinesViewerCustom {
pub fn new() -> Self {
Self { faces: vec![] }
}
}

impl Routines for RoutinesViewerCustom {
fn fn_end_of_iteration(
&mut self,
bodies: &mut [Body],
bodies: &mut [AirlessBody],
_time: &Time,
_scene: &Scene,
win: &Window,
Expand All @@ -154,11 +78,4 @@ impl Routines for RoutinesViewerCustom {
}
}

impl RoutinesViewerCustom {
pub fn new() -> Self {
Self {
default: routines_viewer_default(),
faces: vec![],
}
}
}
impl RoutinesViewer for RoutinesViewerCustom {}
47 changes: 47 additions & 0 deletions macros/Cargo.lock

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

14 changes: 14 additions & 0 deletions macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "kalast_macros"
version = "0.4.0-beta"
description = "Kalast Macros"
edition = "2021"
license = "Apache-2.0"

[lib]
proc-macro = true

[dependencies]
syn = "2.0"
quote = "1.0"
proc-macro2 = "1.0"
Empty file added macros/src/lib.rs
Empty file.
Empty file added preferences.yaml
Empty file.
4 changes: 2 additions & 2 deletions src/ast/asteroid.rs → src/body/asteroid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use polars::prelude::{CsvReader, SerReader};
use std::path::Path;

#[derive(Debug, Clone)]
pub struct Asteroid {
pub struct AirlessBody {
pub surface: Surface,
pub interior: Option<Interior>,
pub matrix_model: Mat4,
}

impl Asteroid {
impl AirlessBody {
pub fn new(surface: Surface) -> Self {
Self {
surface,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/ast/mesh.rs → src/body/mesh.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{intersect_surface, util::*, vec3_to_4_one, Asteroid, FaceData};
use crate::{intersect_surface, util::*, vec3_to_4_one, AirlessBody, FaceData};

use itertools::{iproduct, izip};

Expand Down Expand Up @@ -49,7 +49,7 @@ where $a_i$ is the area of the facet $i$, $\Theta_x$ the angle between the cente
facets $i$ and $j$ and the normal of the facet $x$, and $r$ is the distance between the
facets.
*/
pub fn view_factor(b1: &Asteroid, b2: &Asteroid, shadows: bool) -> DMatrix<Float> {
pub fn view_factor(b1: &AirlessBody, b2: &AirlessBody, shadows: bool) -> DMatrix<Float> {
assert!(!b1.surface.is_smooth());
assert!(!b2.surface.is_smooth());

Expand Down
File renamed without changes.
35 changes: 29 additions & 6 deletions src/ast/orbit.rs → src/body/orbit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use crate::{util::*, NEWTON_METHOD_THRESHOLD, NUMBER_ITERATION_FAIL};
use regex::Regex;
use serde::{Deserialize, Serialize};
use snafu::{prelude::*, Location};
use std::str::FromStr;
use std::{
ops::{Deref, DerefMut},
str::FromStr,
};
use uom::{
si::{angle::radian, f64::Angle},
str::ParseQuantityError,
Expand Down Expand Up @@ -64,13 +67,11 @@ pub enum AstronomicalAngleOptions {
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(try_from = "AstronomicalAngleStr")]
#[serde(into = "AstronomicalAngleStr")]
pub struct AstronomicalAngle {
pub angle: Angle,
}
pub struct AstronomicalAngle(Angle);

impl AstronomicalAngle {
pub fn new(angle: Angle) -> Self {
Self { angle }
Self(angle)
}

pub fn parse(s: &str) -> OrbitResult<Self> {
Expand Down Expand Up @@ -179,6 +180,19 @@ impl FromStr for AstronomicalAngle {
}
}

impl Deref for AstronomicalAngle {
type Target = Angle;
fn deref(&self) -> &Self::Target {
&self.0
}
}

impl DerefMut for AstronomicalAngle {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

#[derive(Serialize, Deserialize)]
struct AstronomicalAngleStr(String);

Expand All @@ -192,7 +206,7 @@ impl TryFrom<AstronomicalAngleStr> for AstronomicalAngle {

impl From<AstronomicalAngle> for AstronomicalAngleStr {
fn from(value: AstronomicalAngle) -> Self {
Self(value.angle.value.to_string())
Self(value.value.to_string())
}
}

Expand Down Expand Up @@ -221,6 +235,15 @@ impl Equatorial {
pub fn new(ra: AstronomicalAngle, dec: AstronomicalAngle) -> Self {
Self { ra, dec }
}

pub fn xyz(&self, distance: Float) -> Vec3 {
distance
* vec3(
(self.ra.cos() * self.dec.cos()).value,
(self.ra.sin() * self.dec.cos()).value,
self.dec.sin().value,
)
}
}

pub fn mean_angular_motion(gravitational_parameter: Float, semi_major_axis: Float) -> Float {
Expand Down
12 changes: 8 additions & 4 deletions src/ast/ray.rs → src/body/ray.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{util::*, vec3_to_4_one, Asteroid};
use crate::{util::*, vec3_to_4_one, AirlessBody};

use itertools::izip;

Expand Down Expand Up @@ -71,11 +71,11 @@ pub fn intersect_surface(
pub fn intersect_asteroids(
raystart_world: &Vec3,
raydir_world: &Vec3,
asteroids: &[&Asteroid],
asteroids: &[AirlessBody],
) -> Option<(Vec3, usize, usize)> {
let mut best_intersect: Option<(Vec3, usize, usize)> = None;

for (surface_index, &asteroid) in asteroids.iter().enumerate() {
for (surface_index, asteroid) in asteroids.iter().enumerate() {
let raystart =
(glm::inverse(&asteroid.matrix_model) * vec3_to_4_one(&raystart_world)).xyz();

Expand Down Expand Up @@ -114,7 +114,11 @@ pub fn intersect_asteroids(
}

/// asteroid1 is shadowed by asteroid2.
pub fn shadows(lightpos_world: &Vec3, asteroid1: &Asteroid, asteroid2: &Asteroid) -> Vec<usize> {
pub fn shadows(
lightpos_world: &Vec3,
asteroid1: &AirlessBody,
asteroid2: &AirlessBody,
) -> Vec<usize> {
if asteroid1.surface.is_smooth() || asteroid2.surface.is_smooth() {
unimplemented!("Shadowing by ray-casting is only implemented for flat surface.");
}
Expand Down
File renamed without changes.
Loading

0 comments on commit 94c6e10

Please sign in to comment.