Skip to content

Commit

Permalink
Merge branch 'dev' into fix-voronoi-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Tehforsch committed Nov 7, 2023
2 parents 48f4b80 + b3d4cbb commit efa31b8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 34 deletions.
2 changes: 1 addition & 1 deletion examples/sweep_1d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn add_source(sim: &mut Simulation, params: &Params) {
if sim.on_main_rank() {
sim.insert_resource(Sources {
sources: vec![Source {
position: VecLength::new(params.source_pos, Length::zero(), Length::zero()),
pos: VecLength::new(params.source_pos, Length::zero(), Length::zero()),
rate: params.photon_flux * area,
}],
});
Expand Down
4 changes: 2 additions & 2 deletions src/arepo_postprocess/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::path::PathBuf;

use derive_custom::subsweep_parameters;
use subsweep::source_systems::Source;
use subsweep::units::Dimensionless;
use subsweep::units::SourceRate;

pub mod bpass;
pub mod read_grid;
Expand Down Expand Up @@ -31,7 +31,7 @@ pub enum GridParameters {
#[subsweep_parameters]
pub enum SourceType {
FromIcs(FromIcs),
SingleSource(SourceRate),
Explicit(Vec<Source>),
}

impl SourceType {
Expand Down
20 changes: 1 addition & 19 deletions src/arepo_postprocess/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use subsweep::impl_to_dataset;
use subsweep::io::input::Reader;
use subsweep::io::DatasetShape;
use subsweep::parameters::InputParameters;
use subsweep::prelude::SimulationBox;
use subsweep::source_systems::Source;
use subsweep::source_systems::Sources;
use subsweep::units;
Expand All @@ -28,7 +27,6 @@ use super::unit_reader::make_descriptor;
use super::unit_reader::read_vec;
use super::unit_reader::ArepoUnitReader;
use super::Parameters;
use super::SourceType;

#[derive(H5Type, Component, Debug, Clone, Equivalence, Deref, DerefMut, From, Named)]
#[name = "metallicity"]
Expand All @@ -44,22 +42,6 @@ pub struct StellarFormationTime(pub Dimensionless);
impl_to_dataset!(StellarFormationTime, units::Dimensionless, true);
impl_to_dataset!(Metallicity, units::Dimensionless, true);

pub fn add_single_source_system(
box_size: Res<SimulationBox>,
parameters: Res<Parameters>,
mut commands: Commands,
) {
let center = box_size.center;
if let SourceType::SingleSource(rate) = parameters.sources {
commands.insert_resource(Sources {
sources: vec![Source {
position: center,
rate,
}],
})
}
}

pub fn read_sources_system(
mut commands: Commands,
parameters: Res<InputParameters>,
Expand All @@ -82,7 +64,7 @@ fn new_bpass_source(
) -> Source {
let age = formation_scale_factor_to_age(cosmology, formation_scale_factor);
Source {
position,
pos: position,
rate: bpass_lookup(age, metallicity, mass) * escape_fraction,
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mod arepo_postprocess;

use arepo_postprocess::read_grid::ReadSweepGridPlugin;
use arepo_postprocess::remap::remap_abundances_and_energies_system;
use arepo_postprocess::sources::add_single_source_system;
use arepo_postprocess::sources::read_sources_system;
use arepo_postprocess::unit_reader::read_vec;
use arepo_postprocess::unit_reader::ArepoUnitReader;
Expand Down Expand Up @@ -57,9 +56,9 @@ fn main() {
SourceType::FromIcs(_) => {
sim.add_startup_system(read_sources_system);
}
SourceType::SingleSource(_) => {
SourceType::Explicit(sources) => {
if rank.is_main() {
sim.add_startup_system(add_single_source_system);
sim.insert_resource(Sources { sources });
} else {
sim.insert_resource(Sources::default());
}
Expand Down
14 changes: 8 additions & 6 deletions src/source_systems.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy_ecs::event::EventWriter;
use bevy_ecs::prelude::Res;
use bevy_ecs::prelude::Resource;
use derive_custom::subsweep_parameters;
use derive_custom::Named;
use kiddo::distance::squared_euclidean;
use kiddo::KdTree;
Expand Down Expand Up @@ -32,13 +32,15 @@ pub struct TotalLuminosity(pub SourceRate);
#[derive(Debug, Equivalence, Clone, PartialOrd, PartialEq)]
pub struct DistanceToSourceData(Length);

#[derive(Clone, Debug, Equivalence)]
#[derive(Debug, Equivalence)]
#[subsweep_parameters]
pub struct Source {
pub position: VecLength,
pub pos: VecLength,
pub rate: SourceRate,
}

#[derive(Resource, Default, Debug)]
#[derive(Default, Debug)]
#[subsweep_parameters]
pub struct Sources {
pub sources: Vec<Source>,
}
Expand All @@ -60,10 +62,10 @@ fn set_source_terms_system(
.collect::<Vec<_>>())
.into();
for s in all_sources.iter() {
let key = s.position.into_key(&*box_);
let key = s.pos.into_key(&*box_);
let rank = decomposition.get_owning_rank(key);
if rank == **world_rank {
let (_, index) = tree.nearest_one(&pos_to_tree_coord(&s.position), &squared_euclidean);
let (_, index) = tree.nearest_one(&pos_to_tree_coord(&s.pos), &squared_euclidean);
let (_, ref mut source_term) = &mut particles[index];
***source_term += s.rate;
}
Expand Down
6 changes: 3 additions & 3 deletions src/units/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ unit_system!(
constant PROTON_MASS = 1.67262192369e-27 * kilograms,
constant SPEED_OF_LIGHT = 299792458.0 * meters_per_second,
constant GAMMA = 5.0 / 3.0,
constant NUMBER_WEIGHTED_AVERAGE_CROSS_SECTION = 1.6437820340825549e-18 * centimeters_squared,
constant ENERGY_WEIGHTED_AVERAGE_CROSS_SECTION = 1.180171754359821e-18 * centimeters_squared,
constant PHOTON_AVERAGE_ENERGY = 100.6910475508583 * electron_volts,
constant NUMBER_WEIGHTED_AVERAGE_CROSS_SECTION = 2.9580524545305314e-18 * centimeters_squared,
constant ENERGY_WEIGHTED_AVERAGE_CROSS_SECTION = 2.7352520425024469e-18 * centimeters_squared,
constant PHOTON_AVERAGE_ENERGY = 18.028356312818811 * electron_volts,
constant RYDBERG_CONSTANT = 13.65693 * electron_volts,
]
);
Expand Down

0 comments on commit efa31b8

Please sign in to comment.