Skip to content

Commit

Permalink
add output of total luminosity
Browse files Browse the repository at this point in the history
  • Loading branch information
Tehforsch committed Sep 18, 2023
1 parent 226d42f commit d7b4e9c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/io/time_series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@ pub fn output_time_series_system<T: TimeSeries>(
val: ev.clone(),
})
.collect();
let f = OpenOptions::new()
.append(true)
.open(&path)
.unwrap_or_else(|e| panic!("Failed to open time series file. {}", e));
serde_yaml::to_writer(&f, &entries)
.unwrap_or_else(|e| panic!("Failed to write to time series file: {}", e));
if entries.len() > 0 {
let f = OpenOptions::new()
.append(true)
.open(&path)
.unwrap_or_else(|e| panic!("Failed to open time series file. {}", e));
serde_yaml::to_writer(&f, &entries)
.unwrap_or_else(|e| panic!("Failed to write to time series file: {}", e));
}
}

fn get_time_series_filename<T: TimeSeries>(
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ use subsweep::components::IonizedHydrogenFraction;
use subsweep::components::Position;
use subsweep::cosmology::Cosmology;
use subsweep::io::input::DatasetInputPlugin;
use subsweep::io::time_series::TimeSeriesPlugin;
use subsweep::io::DatasetDescriptor;
use subsweep::io::DatasetShape;
use subsweep::io::InputDatasetDescriptor;
use subsweep::prelude::*;
use subsweep::simulation_plugin::remove_components_system;
use subsweep::source_systems::set_source_terms_system;
use subsweep::source_systems::Sources;
use subsweep::source_systems::TotalLuminosity;
use subsweep::units::Dimensionless;
use subsweep::units::PhotonRate;
use subsweep::units::SourceRate;
Expand Down Expand Up @@ -104,6 +106,7 @@ fn main() {
StartupStages::InsertGrid,
remove_components_system::<ElectronAbundance>,
)
.add_plugin(TimeSeriesPlugin::<TotalLuminosity>::default())
.add_plugin(DatasetInputPlugin::<Position>::from_descriptor(
InputDatasetDescriptor::<Position>::new(
DatasetDescriptor {
Expand Down
9 changes: 9 additions & 0 deletions src/source_systems.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use bevy_ecs::event::EventWriter;
use bevy_ecs::prelude::Res;
use bevy_ecs::prelude::Resource;
use derive_custom::Named;
use log::debug;
use mpi::traits::Equivalence;
use ordered_float::OrderedFloat;
use serde::Serialize;

use crate::communication::MpiWorld;
use crate::components;
Expand All @@ -16,6 +19,10 @@ use crate::units::Length;
use crate::units::SourceRate;
use crate::units::VecLength;

#[derive(Debug, Clone, Equivalence, Named, Serialize)]
#[name = "total_luminosity"]
pub struct TotalLuminosity(pub SourceRate);

#[derive(Debug, Equivalence, Clone, PartialOrd, PartialEq)]
pub struct DistanceToSourceData(Length);

Expand All @@ -36,6 +43,7 @@ pub fn set_source_terms_system(
decomposition: Res<DecompositionState>,
box_: Res<SimulationBox>,
world_rank: Res<WorldRank>,
mut writer: EventWriter<TotalLuminosity>,
) {
let mut source_comm = MpiWorld::<Source>::new();
let all_sources = source_comm.all_gather_varcount(&sources.sources);
Expand All @@ -55,5 +63,6 @@ pub fn set_source_terms_system(
}
}
let total: SourceRate = all_sources.iter().map(|source| source.rate).sum();
writer.send(TotalLuminosity(total));
debug!("Total luminosity: {:+.2e}", total.in_photons_per_second());
}
2 changes: 0 additions & 2 deletions src/sweep/time_series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ use crate::units::Volume;

#[derive(Component, Debug, Clone, Equivalence, Deref, DerefMut, From, Named, Serialize)]
#[name = "hydrogen_ionization_mass_average"]
#[repr(transparent)]
pub struct HydrogenIonizationMassAverage(pub Dimensionless);

#[derive(Component, Debug, Clone, Equivalence, Deref, DerefMut, From, Named, Serialize)]
#[name = "hydrogen_ionization_volume_average"]
#[repr(transparent)]
pub struct HydrogenIonizationVolumeAverage(pub Dimensionless);

#[derive(Serialize, Clone, Named)]
Expand Down

0 comments on commit d7b4e9c

Please sign in to comment.