goad-py 1.3.0__tar.gz → 1.3.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {goad_py-1.3.0 → goad_py-1.3.3}/Cargo.lock +1 -1
- {goad_py-1.3.0 → goad_py-1.3.3}/Cargo.toml +1 -1
- {goad_py-1.3.0 → goad_py-1.3.3}/PKG-INFO +1 -1
- {goad_py-1.3.0 → goad_py-1.3.3}/pyproject.toml +1 -1
- {goad_py-1.3.0 → goad_py-1.3.3}/src/beam.rs +2 -32
- {goad_py-1.3.0 → goad_py-1.3.3}/src/convergence/python.rs +3 -1
- {goad_py-1.3.0 → goad_py-1.3.3}/src/convergence.rs +39 -2
- {goad_py-1.3.0 → goad_py-1.3.3}/src/diff2.rs +178 -143
- {goad_py-1.3.0 → goad_py-1.3.3}/src/lib.rs +1 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/multiproblem.rs +42 -6
- {goad_py-1.3.0 → goad_py-1.3.3}/src/output.rs +60 -17
- {goad_py-1.3.0 → goad_py-1.3.3}/src/problem.rs +154 -98
- goad_py-1.3.3/src/timing.rs +227 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/.github/workflows/CI.yml +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/.gitignore +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/LICENSE +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/README.md +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/config/default.toml +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/config_editor.sh +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/backscattering/generate_ensemble.py +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/backscattering/generate_plate.py +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/backscattering/generate_roughness_sweep.py +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/backscattering/main.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/backscattering/plate-render.png +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/backscattering/plot_roughness_sweep.py +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/backscattering/results.json +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/backscattering/roughened_edge15.0_sigma0p1_merge1p0_hexagonal_column_l5.0_r25.0_6904c8.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/backscattering/run_ensemble.py +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/backscattering/run_individual.py +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/backscattering/run_roughness_sweep.py +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/backscattering/run_simulation.py +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/backscattering/settings.json +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/capture_vertices.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/convergence.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/8col.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/clip_test.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/concave1.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/concave2.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/cone.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/cube.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/cube2.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/cube_inside_cube.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/cube_inside_hex.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/cube_inside_ico.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/cubes.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/hex.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/hex2.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/hex3.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/hex4.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/hex5.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/hex6.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/hex7.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/hex_20_30_30.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/hex_distort.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/hex_hollow.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/hex_indented.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/icosphere1.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/multiple.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/multiple2.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/multiple3.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/octo.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/octo2.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/para.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/para_rough1.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/plane_xy.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/plane_xy_rect.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/plane_xy_rect_split.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/plane_yz.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/plate.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/data/plate_distort.obj +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/diffraction_plot.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/distortion.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/field_at_initial_beam.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/lidar_batch_test.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/lidar_convergence_test.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/multiproblem.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/problem-diff.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/problem1.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/regen_mueller_refs/main.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/schematic_field_dump.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/simplify.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/examples/tmp_dump_recording.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/mkdocs.yml +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/python/goad/__init__.py +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/python/goad/_goad.pyi +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/python/goad/bar.py +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/python/goad/py.typed +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/setup.sh +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/_quickstart.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/bin/stub_gen.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/bins.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/cancel.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/clip.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/containment.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/convergence/convergeable.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/convergence/progress.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/diff.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/distortion.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/field.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/filelog.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/fresnel.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/geom.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/main.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/orientation.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/params.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/powers.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/python.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/recording.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/result/component.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/result/integrate.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/result/mueller.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/result/python.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/result/results.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/result/scatt_result.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/result.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/settings/cli.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/settings/constants.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/settings/loading.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/settings/validation.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/settings.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/snell.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/src/zones.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/template/custom_bins.toml +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/template/goad_pbs.sh +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/tests/common/cases.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/tests/compare_solvers.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/tests/convergence_merge_tests.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/tests/diffraction_tests.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/tests/helpers.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/tests/mueller_regression_tests.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/tests/optical_theorem_tests.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/tests/orientation_sampling_tests.rs +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/tests/test_basic.py +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/tests/test_data/fixed_hex_30_20_20_mueller_scatgrid +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/tests/test_data/fixed_hex_30_30_30_mueller_scatgrid +0 -0
- {goad_py-1.3.0 → goad_py-1.3.3}/tests/test_data/hex.obj +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "goad"
|
|
3
|
-
version = "1.3.
|
|
3
|
+
version = "1.3.3"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
license = "GPL-3.0"
|
|
6
6
|
description = "Compute the single scattering properties of particles much larger than the wavelength of light with geometric optics and aperture diffraction theory."
|
|
@@ -5,13 +5,11 @@ use std::sync::atomic::{AtomicU64, Ordering};
|
|
|
5
5
|
use nalgebra::{Complex, Matrix4, Vector3};
|
|
6
6
|
|
|
7
7
|
use crate::{
|
|
8
|
-
bins::SolidAngleBin,
|
|
9
8
|
clip::Clipping,
|
|
10
|
-
|
|
11
|
-
field::{Ampl, Field},
|
|
9
|
+
field::Field,
|
|
12
10
|
fresnel,
|
|
13
11
|
geom::{Face, Geom},
|
|
14
|
-
settings
|
|
12
|
+
settings,
|
|
15
13
|
snell::get_theta_t,
|
|
16
14
|
};
|
|
17
15
|
|
|
@@ -557,34 +555,6 @@ impl Beam {
|
|
|
557
555
|
})
|
|
558
556
|
}
|
|
559
557
|
|
|
560
|
-
pub fn diffract(
|
|
561
|
-
&self,
|
|
562
|
-
bins: &[SolidAngleBin],
|
|
563
|
-
fov_factor: Option<f32>,
|
|
564
|
-
// incidence_beam: Option<&IncidentBeam>,
|
|
565
|
-
) -> Vec<(usize, Ampl)> {
|
|
566
|
-
match &self.face {
|
|
567
|
-
Face::Simple(..) => {
|
|
568
|
-
// TODO: remove match statement
|
|
569
|
-
let result = diff2::n2f_aperture_diffraction(
|
|
570
|
-
&self,
|
|
571
|
-
bins,
|
|
572
|
-
// reference,
|
|
573
|
-
&IncidentBeam {
|
|
574
|
-
e_perp: default_e_perp(), // to match basic_initial_beam
|
|
575
|
-
prop: default_prop(),
|
|
576
|
-
},
|
|
577
|
-
fov_factor,
|
|
578
|
-
)
|
|
579
|
-
.unwrap_or_default();
|
|
580
|
-
result.into_iter().collect()
|
|
581
|
-
}
|
|
582
|
-
Face::Complex { interiors, .. } => {
|
|
583
|
-
log::warn!("face with {} holes not supported yet", interiors.len());
|
|
584
|
-
vec![]
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
558
|
}
|
|
589
559
|
|
|
590
560
|
#[derive(Debug, Clone, PartialEq)]
|
|
@@ -61,6 +61,7 @@ impl Convergence {
|
|
|
61
61
|
sampler,
|
|
62
62
|
rng,
|
|
63
63
|
log_file: None,
|
|
64
|
+
timings: crate::timing::Timings::default(),
|
|
64
65
|
})
|
|
65
66
|
}
|
|
66
67
|
|
|
@@ -148,7 +149,8 @@ impl Convergence {
|
|
|
148
149
|
self.settings.clone()
|
|
149
150
|
};
|
|
150
151
|
|
|
151
|
-
let output_manager =
|
|
152
|
+
let output_manager =
|
|
153
|
+
crate::output::OutputManager::new(&settings, &result).with_timings(&self.timings);
|
|
152
154
|
output_manager.write_all().map_err(|e| {
|
|
153
155
|
pyo3::exceptions::PyIOError::new_err(format!("Failed to save results: {}", e))
|
|
154
156
|
})?;
|
|
@@ -26,6 +26,7 @@ use crate::{
|
|
|
26
26
|
problem::Problem,
|
|
27
27
|
result::{GOComponent, Results},
|
|
28
28
|
settings::Settings,
|
|
29
|
+
timing::{TimingAccumulator, Timings},
|
|
29
30
|
};
|
|
30
31
|
use progress::ConvergenceProgress;
|
|
31
32
|
use pyo3::pyclass;
|
|
@@ -84,11 +85,14 @@ pub struct Convergence {
|
|
|
84
85
|
rng: StdRng,
|
|
85
86
|
/// Optional path to log file for mean values during convergence
|
|
86
87
|
pub log_file: Option<PathBuf>,
|
|
88
|
+
/// Wall-time breakdown of the last solve
|
|
89
|
+
pub timings: Timings,
|
|
87
90
|
}
|
|
88
91
|
|
|
89
92
|
impl Convergence {
|
|
90
93
|
/// Creates a new Convergence solver from geometries and settings.
|
|
91
94
|
pub fn new(geoms: Vec<Geom>, settings: Option<Settings>) -> anyhow::Result<Self> {
|
|
95
|
+
let init_start = Instant::now();
|
|
92
96
|
let settings = load_settings_or_default(settings);
|
|
93
97
|
|
|
94
98
|
// Initialize file-based logging early so geometry load warnings are captured
|
|
@@ -112,6 +116,9 @@ impl Convergence {
|
|
|
112
116
|
Scheme::Halton { .. } => OrientationSampler::halton(),
|
|
113
117
|
};
|
|
114
118
|
|
|
119
|
+
let mut timings = Timings::default();
|
|
120
|
+
timings.wall.init = init_start.elapsed().as_secs_f64();
|
|
121
|
+
|
|
115
122
|
Ok(Self {
|
|
116
123
|
geoms,
|
|
117
124
|
settings,
|
|
@@ -121,6 +128,7 @@ impl Convergence {
|
|
|
121
128
|
sampler,
|
|
122
129
|
rng,
|
|
123
130
|
log_file: None,
|
|
131
|
+
timings,
|
|
124
132
|
})
|
|
125
133
|
}
|
|
126
134
|
|
|
@@ -161,11 +169,25 @@ impl Convergence {
|
|
|
161
169
|
pub fn writeup(&self) {
|
|
162
170
|
let mut result = self.mean();
|
|
163
171
|
// Recompute params from averaged Mueller matrices
|
|
172
|
+
let post_start = Instant::now();
|
|
164
173
|
result.mueller_to_1d();
|
|
165
174
|
let _ = result.compute_params(self.settings.wavelength);
|
|
166
|
-
|
|
167
|
-
let
|
|
175
|
+
|
|
176
|
+
let mut timings = self.timings.clone();
|
|
177
|
+
timings.wall.post_process += post_start.elapsed().as_secs_f64();
|
|
178
|
+
|
|
179
|
+
let output_manager =
|
|
180
|
+
output::OutputManager::new(&self.settings, &result).with_timings(&timings);
|
|
181
|
+
let io_elapsed = output_manager.write_all();
|
|
168
182
|
info!("Output written to {}", self.settings.directory.display());
|
|
183
|
+
|
|
184
|
+
if !self.settings.quiet {
|
|
185
|
+
if let Ok(elapsed) = io_elapsed {
|
|
186
|
+
timings.wall.file_io = elapsed.as_secs_f64();
|
|
187
|
+
}
|
|
188
|
+
println!();
|
|
189
|
+
timings.print();
|
|
190
|
+
}
|
|
169
191
|
}
|
|
170
192
|
|
|
171
193
|
/// Check if all convergence targets are satisfied.
|
|
@@ -361,9 +383,11 @@ impl Convergence {
|
|
|
361
383
|
});
|
|
362
384
|
|
|
363
385
|
// Run prognosis to determine optimal batch size based on actual timing
|
|
386
|
+
let prognosis_start = Instant::now();
|
|
364
387
|
let batch_size = self
|
|
365
388
|
.run_prognosis(&problems_base, num_workers)
|
|
366
389
|
.min(self.max_orientations);
|
|
390
|
+
self.timings.wall.prognosis = Some(prognosis_start.elapsed().as_secs_f64());
|
|
367
391
|
let injector: Injector<OrientationTask> = Injector::new();
|
|
368
392
|
|
|
369
393
|
// Template for workers to create their local trackers
|
|
@@ -382,10 +406,15 @@ impl Convergence {
|
|
|
382
406
|
// Cancellation token shared with workers (tripped on convergence/interrupt).
|
|
383
407
|
let cancel = CancelToken::new();
|
|
384
408
|
|
|
409
|
+
let stage_acc = TimingAccumulator::default();
|
|
410
|
+
|
|
385
411
|
let injector_ref = &injector;
|
|
386
412
|
let problems_ref = &problems_base;
|
|
387
413
|
let template_ref = &result_template;
|
|
388
414
|
let cancel_ref = &cancel;
|
|
415
|
+
let stage_acc_ref = &stage_acc;
|
|
416
|
+
|
|
417
|
+
let solve_start = Instant::now();
|
|
389
418
|
|
|
390
419
|
thread::scope(|s| {
|
|
391
420
|
// Spawn workers
|
|
@@ -399,6 +428,7 @@ impl Convergence {
|
|
|
399
428
|
batch_size,
|
|
400
429
|
tx,
|
|
401
430
|
cancel_ref,
|
|
431
|
+
stage_acc_ref,
|
|
402
432
|
);
|
|
403
433
|
});
|
|
404
434
|
}
|
|
@@ -440,6 +470,10 @@ impl Convergence {
|
|
|
440
470
|
progress.set_finalising();
|
|
441
471
|
});
|
|
442
472
|
|
|
473
|
+
self.timings.wall.solve = solve_start.elapsed().as_secs_f64();
|
|
474
|
+
self.timings.worker = stage_acc.snapshot();
|
|
475
|
+
self.timings.threads = num_workers;
|
|
476
|
+
|
|
443
477
|
progress.finish();
|
|
444
478
|
}
|
|
445
479
|
|
|
@@ -570,6 +604,7 @@ impl Convergence {
|
|
|
570
604
|
batch_size: usize,
|
|
571
605
|
tx: Sender<ConvergenceTracker<Results>>,
|
|
572
606
|
cancel: &CancelToken,
|
|
607
|
+
stage_acc: &TimingAccumulator,
|
|
573
608
|
) -> Result<()> {
|
|
574
609
|
loop {
|
|
575
610
|
let tasks = Self::steal_batch(injector, batch_size, cancel)?;
|
|
@@ -578,11 +613,13 @@ impl Convergence {
|
|
|
578
613
|
for task in tasks {
|
|
579
614
|
cancel.check()?;
|
|
580
615
|
let mut problem = problems_base[task.problem_idx].clone();
|
|
616
|
+
let run_start = Instant::now();
|
|
581
617
|
if let Err(err) = problem.run(Some(&task.euler), cancel) {
|
|
582
618
|
cancel.check()?;
|
|
583
619
|
error!("Error running problem (will skip this iteration): {}", err);
|
|
584
620
|
continue;
|
|
585
621
|
}
|
|
622
|
+
stage_acc.add(&problem.timings, run_start.elapsed());
|
|
586
623
|
local_tracker.update(&problem.result);
|
|
587
624
|
}
|
|
588
625
|
|
|
@@ -9,6 +9,7 @@ use crate::field::Ampl;
|
|
|
9
9
|
#[cfg(debug_assertions)]
|
|
10
10
|
use crate::geom::Face;
|
|
11
11
|
use crate::geom::{self};
|
|
12
|
+
#[cfg(debug_assertions)]
|
|
12
13
|
use crate::settings::constants::COLINEAR_THRESHOLD;
|
|
13
14
|
#[cfg(debug_assertions)]
|
|
14
15
|
use crate::settings::constants::PLANARITY_TOLERANCE;
|
|
@@ -425,137 +426,161 @@ pub fn get_rotation_matrix(verts: &[Vector3<f32>]) -> Matrix3<f32> {
|
|
|
425
426
|
}
|
|
426
427
|
|
|
427
428
|
// =============================================================================
|
|
428
|
-
// Main
|
|
429
|
+
// Main API
|
|
429
430
|
// =============================================================================
|
|
430
431
|
|
|
431
|
-
///
|
|
432
|
-
///
|
|
433
|
-
/// # Arguments
|
|
434
|
-
/// * `beam` - The beam to diffract
|
|
435
|
-
/// * `bins` - List of solid angle bins to compute diffraction for
|
|
436
|
-
/// * `incident` - Incident beam parameters (e_perp and prop of original illumination)
|
|
437
|
-
/// * `fov_factor` - Optional field of view factor for filtering
|
|
432
|
+
/// Per-beam diffraction context.
|
|
438
433
|
///
|
|
439
|
-
///
|
|
440
|
-
///
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
let e_perp = beam.field.e_perp();
|
|
461
|
-
let normal = beam.face.data().normal;
|
|
462
|
-
if beam.field.prop().dot(&beam.face.data().normal) < 0.0 {
|
|
463
|
-
log::warn!("prop should be pointing away from the face but the dot product with face normal is {}",
|
|
464
|
-
beam.field.prop().dot(&beam.face.data().normal)
|
|
465
|
-
);
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
assert_face_simple(&beam.face);
|
|
469
|
-
assert_face_planar(verts);
|
|
470
|
-
// assert_clockwise_winding(verts, prop);
|
|
471
|
-
assert_e_perp_perpendicular_to_prop(e_perp, prop);
|
|
472
|
-
assert_e_perp_perpendicular_to_normal(e_perp, normal);
|
|
473
|
-
}
|
|
434
|
+
/// Holds everything that can be computed once per beam, independent of the
|
|
435
|
+
/// observation direction: the aperture-frame transforms, pre-computed edge
|
|
436
|
+
/// data for the Fraunhofer integral, and the scaled amplitude matrix.
|
|
437
|
+
/// Build once with [`DiffractionContext::new`], then evaluate per bin with
|
|
438
|
+
/// [`DiffractionContext::contribution`]. This split lets callers iterate
|
|
439
|
+
/// bin-major (accumulating many beams into each output bin) without paying
|
|
440
|
+
/// the per-beam setup cost inside the bin loop.
|
|
441
|
+
pub struct DiffractionContext {
|
|
442
|
+
rot3: Matrix3<f32>,
|
|
443
|
+
edge_data: EdgeData,
|
|
444
|
+
/// FOV cosine threshold; `None` disables filtering.
|
|
445
|
+
cos_fov: Option<f32>,
|
|
446
|
+
kinc_xy: [f32; 2],
|
|
447
|
+
inv_denom: Complex<f32>,
|
|
448
|
+
ampl: Ampl,
|
|
449
|
+
prop_aperture: Vector3<f32>,
|
|
450
|
+
wavenumber: f32,
|
|
451
|
+
r_offset: Vector3<f32>,
|
|
452
|
+
incident_e_perp: Vector3<f32>,
|
|
453
|
+
incident_prop: Vector3<f32>,
|
|
454
|
+
}
|
|
474
455
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
456
|
+
impl DiffractionContext {
|
|
457
|
+
/// Pre-compute the aperture-frame quantities for a beam.
|
|
458
|
+
///
|
|
459
|
+
/// # Arguments
|
|
460
|
+
/// * `beam` - The beam to diffract
|
|
461
|
+
/// * `incident` - Incident beam parameters (e_perp and prop of original illumination)
|
|
462
|
+
/// * `fov_factor` - Optional field of view factor for filtering
|
|
463
|
+
pub fn new(beam: &Beam, incident: &IncidentBeam, fov_factor: Option<f32>) -> Result<Self> {
|
|
464
|
+
let verts = &beam.face.data().exterior;
|
|
465
|
+
|
|
466
|
+
#[cfg(debug_assertions)]
|
|
467
|
+
{
|
|
468
|
+
// Apply small perturbation to prop to reduce numerical errors (matches original diff.rs)
|
|
469
|
+
let prop = (beam.field.prop()
|
|
470
|
+
+ Vector3::new(
|
|
471
|
+
settings::constants::PROP_PERTURBATION,
|
|
472
|
+
settings::constants::PROP_PERTURBATION,
|
|
473
|
+
settings::constants::PROP_PERTURBATION,
|
|
474
|
+
))
|
|
475
|
+
.normalize();
|
|
476
|
+
|
|
477
|
+
let e_perp = beam.field.e_perp();
|
|
478
|
+
let normal = beam.face.data().normal;
|
|
479
|
+
if beam.field.prop().dot(&beam.face.data().normal) < 0.0 {
|
|
480
|
+
log::warn!("prop should be pointing away from the face but the dot product with face normal is {}",
|
|
481
|
+
beam.field.prop().dot(&beam.face.data().normal)
|
|
482
|
+
);
|
|
483
|
+
};
|
|
478
484
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
485
|
+
assert_face_simple(&beam.face);
|
|
486
|
+
assert_face_planar(verts);
|
|
487
|
+
// assert_clockwise_winding(verts, prop);
|
|
488
|
+
assert_e_perp_perpendicular_to_prop(e_perp, prop);
|
|
489
|
+
assert_e_perp_perpendicular_to_normal(e_perp, normal);
|
|
490
|
+
}
|
|
482
491
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
492
|
+
// Step 1: Translate beam so face is centered at origin
|
|
493
|
+
let center_of_mass = geom::calculate_center_of_mass(verts);
|
|
494
|
+
let beam_centered = beam.transformed(&translation_to_origin(¢er_of_mass))?;
|
|
495
|
+
|
|
496
|
+
// Step 2: Rotate beam into xy plane (vertices are now centered at origin)
|
|
497
|
+
let rot_to_xy = rotation_to_xy_plane(&beam_centered);
|
|
498
|
+
let beam_xy = beam_centered.transformed(&rot_to_xy)?;
|
|
499
|
+
|
|
500
|
+
// Step 3: Rotate around z-axis to put e_perp along +y (aperture system)
|
|
501
|
+
// This also ensures prop lies in the xz plane since e_perp ⊥ prop
|
|
502
|
+
let rot_e_perp_to_y = rotation_e_perp_to_y(&beam_xy);
|
|
503
|
+
let beam_aperture = beam_xy.transformed(&rot_e_perp_to_y)?;
|
|
504
|
+
|
|
505
|
+
// Combined rotation matrix (3x3) for rotating vectors from original to aperture frame
|
|
506
|
+
let rot3_to_xy: Matrix3<f32> = rot_to_xy.fixed_view::<3, 3>(0, 0).into_owned();
|
|
507
|
+
let rot3_e_perp_to_y: Matrix3<f32> = rot_e_perp_to_y.fixed_view::<3, 3>(0, 0).into_owned();
|
|
508
|
+
let rot3 = rot3_e_perp_to_y * rot3_to_xy;
|
|
509
|
+
|
|
510
|
+
#[cfg(debug_assertions)]
|
|
511
|
+
{
|
|
512
|
+
let aperture_verts = &beam_aperture.face.data().exterior;
|
|
513
|
+
let aperture_prop = beam_aperture.field.prop();
|
|
514
|
+
let aperture_e_perp = beam_aperture.field.e_perp();
|
|
515
|
+
let aperture_normal = beam_aperture.face.data().normal;
|
|
516
|
+
|
|
517
|
+
assert_face_simple(&beam_aperture.face);
|
|
518
|
+
assert_face_planar(aperture_verts);
|
|
519
|
+
// assert_clockwise_winding(aperture_verts, aperture_prop);
|
|
520
|
+
assert_e_perp_perpendicular_to_prop(aperture_e_perp, aperture_prop);
|
|
521
|
+
assert_e_perp_perpendicular_to_normal(aperture_e_perp, aperture_normal);
|
|
522
|
+
}
|
|
487
523
|
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
524
|
+
// Get wavenumber from beam and scale amplitude matrix
|
|
525
|
+
let wavenumber = beam_aperture.wavenumber();
|
|
526
|
+
let mut ampl = beam_aperture.field.ampl();
|
|
527
|
+
ampl *= Complex::new(wavenumber, 0.0);
|
|
492
528
|
|
|
493
|
-
|
|
494
|
-
{
|
|
529
|
+
// Get aperture vertices and prop in aperture system
|
|
495
530
|
let aperture_verts = &beam_aperture.face.data().exterior;
|
|
496
|
-
let
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
531
|
+
let prop_aperture = beam_aperture.field.prop();
|
|
532
|
+
|
|
533
|
+
// Pre-compute edge data for Fraunhofer integral
|
|
534
|
+
let edge_data = EdgeData::from_vertices(aperture_verts);
|
|
535
|
+
|
|
536
|
+
// Calculate field of view cosine for filtering
|
|
537
|
+
let cos_fov =
|
|
538
|
+
fov_factor.map(|_| calculate_fov_cosine(aperture_verts, wavenumber, fov_factor));
|
|
539
|
+
|
|
540
|
+
// Incident wave vector in aperture frame
|
|
541
|
+
let kinc = prop_aperture * wavenumber;
|
|
542
|
+
|
|
543
|
+
Ok(Self {
|
|
544
|
+
rot3,
|
|
545
|
+
edge_data,
|
|
546
|
+
cos_fov,
|
|
547
|
+
kinc_xy: [kinc.x, kinc.y],
|
|
548
|
+
inv_denom: Complex::new(wavenumber / (2.0 * PI), 0.0),
|
|
549
|
+
ampl,
|
|
550
|
+
prop_aperture,
|
|
551
|
+
wavenumber,
|
|
552
|
+
// Phase offset vector: uses ORIGINAL center of mass (before transforms)
|
|
553
|
+
// This is the displacement from aperture center to far-field reference
|
|
554
|
+
r_offset: -center_of_mass.coords,
|
|
555
|
+
incident_e_perp: incident.e_perp,
|
|
556
|
+
incident_prop: incident.prop,
|
|
557
|
+
})
|
|
505
558
|
}
|
|
506
559
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
// Get aperture vertices and prop in aperture system
|
|
513
|
-
let aperture_verts = &beam_aperture.face.data().exterior;
|
|
514
|
-
let prop_aperture = beam_aperture.field.prop();
|
|
515
|
-
|
|
516
|
-
// Pre-compute edge data for Fraunhofer integral
|
|
517
|
-
let edge_data = EdgeData::from_vertices(aperture_verts);
|
|
518
|
-
|
|
519
|
-
// Calculate field of view cosine for filtering
|
|
520
|
-
let cos_fov = calculate_fov_cosine(aperture_verts, wavenumber, fov_factor);
|
|
521
|
-
|
|
522
|
-
// Incident wave vector in aperture frame
|
|
523
|
-
let kinc = prop_aperture * wavenumber;
|
|
524
|
-
|
|
525
|
-
// Pre-calculate constant for Fraunhofer integral
|
|
526
|
-
let inv_denom = Complex::new(wavenumber / (2.0 * PI), 0.0);
|
|
527
|
-
|
|
528
|
-
// Output amplitude for each bin
|
|
529
|
-
let mut ampl_cs = vec![Ampl::zeros(); bins.len()];
|
|
530
|
-
|
|
531
|
-
// Phase offset vector: uses ORIGINAL center of mass (before transforms)
|
|
532
|
-
// This is the displacement from aperture center to far-field reference
|
|
533
|
-
let r_offset = -center_of_mass.coords;
|
|
534
|
-
|
|
535
|
-
// Main loop over scattering bins
|
|
536
|
-
for (index, bin) in bins.iter().enumerate() {
|
|
560
|
+
/// Far-field amplitude contribution of this beam to a single bin.
|
|
561
|
+
///
|
|
562
|
+
/// Returns zeros for bins outside the field-of-view cone (when enabled).
|
|
563
|
+
pub fn contribution(&self, bin: &SolidAngleBin) -> Ampl {
|
|
537
564
|
// Calculate observation direction in the original (lab) frame
|
|
538
565
|
// Uses inverted z-axis convention: theta=0 is forward (along -z)
|
|
539
566
|
let k_obs = bin.unit_vector();
|
|
540
567
|
|
|
541
568
|
// Rotate observation direction into aperture frame
|
|
542
|
-
let k = rot3 * k_obs;
|
|
543
|
-
|
|
544
|
-
// Phase calculation: path difference times wavenumber
|
|
545
|
-
// Uses k_obs (original frame) with r_offset (original center of mass)
|
|
546
|
-
let path_difference = k_obs.dot(&r_offset);
|
|
547
|
-
let bvsk = path_difference * wavenumber;
|
|
569
|
+
let k = self.rot3 * k_obs;
|
|
548
570
|
|
|
549
571
|
// Field of view filtering: skip bins outside the valid scattering cone
|
|
550
|
-
if
|
|
551
|
-
|
|
572
|
+
if let Some(cos_fov) = self.cos_fov {
|
|
573
|
+
if k.dot(&self.prop_aperture) < cos_fov {
|
|
574
|
+
return Ampl::zeros();
|
|
575
|
+
}
|
|
552
576
|
}
|
|
553
577
|
|
|
554
|
-
//
|
|
555
|
-
|
|
578
|
+
// Phase calculation: path difference times wavenumber
|
|
579
|
+
// Uses k_obs (original frame) with r_offset (original center of mass)
|
|
580
|
+
let bvsk = k_obs.dot(&self.r_offset) * self.wavenumber;
|
|
556
581
|
|
|
557
582
|
// Compute Karczewski polarisation matrix and scattering plane normal
|
|
558
|
-
let (karczewski_matrix, karczewski_e_perp) = karczewski(&prop_aperture, &k);
|
|
583
|
+
let (karczewski_matrix, karczewski_e_perp) = karczewski(&self.prop_aperture, &k);
|
|
559
584
|
|
|
560
585
|
// Precompute sin/cos phi for rotation matrices
|
|
561
586
|
let (sin_phi, cos_phi) = bin.phi.center.to_radians().sin_cos();
|
|
@@ -563,46 +588,38 @@ pub fn n2f_aperture_diffraction(
|
|
|
563
588
|
// rot4: rotation from Karczewski scattering plane to aperture system scattering plane
|
|
564
589
|
// hc is the vector perpendicular to the scattering plane, rotated into aperture system
|
|
565
590
|
let scattering_e_perp = Vector3::new(-sin_phi, cos_phi, 0.0);
|
|
566
|
-
let hc = rot3 * scattering_e_perp;
|
|
591
|
+
let hc = self.rot3 * scattering_e_perp;
|
|
567
592
|
let rot4 = crate::field::Field::rotation_matrix(karczewski_e_perp, hc, k);
|
|
568
593
|
|
|
569
594
|
// prerotation: rotation of initial incidence reference frame
|
|
570
595
|
// Uses the incident beam's e_perp and prop to define the reference frame
|
|
571
|
-
let prerotation =
|
|
572
|
-
|
|
573
|
-
|
|
596
|
+
let prerotation = crate::field::Field::rotation_matrix(
|
|
597
|
+
self.incident_e_perp,
|
|
598
|
+
scattering_e_perp,
|
|
599
|
+
self.incident_prop,
|
|
600
|
+
)
|
|
601
|
+
.transpose();
|
|
574
602
|
|
|
575
603
|
// Compute amplitude: rot4 * karczewski * ampl * prerotation
|
|
576
|
-
let
|
|
604
|
+
let ampl_bin = rot4.map(Complex::from)
|
|
577
605
|
* karczewski_matrix.map(Complex::from)
|
|
578
|
-
* ampl
|
|
606
|
+
* self.ampl
|
|
579
607
|
* prerotation.map(Complex::from);
|
|
580
608
|
|
|
581
|
-
*ampl_far_field = ampl_temp;
|
|
582
|
-
|
|
583
609
|
// Calculate Fraunhofer factor for this direction
|
|
584
610
|
let mut fraunhofer_sum = Complex::new(0.0, 0.0);
|
|
585
611
|
|
|
586
|
-
let (kxx, kyy) = calculate_kxx_kyy(
|
|
587
|
-
&kinc
|
|
588
|
-
.fixed_rows::<2>(0)
|
|
589
|
-
.into_owned()
|
|
590
|
-
.as_slice()
|
|
591
|
-
.try_into()
|
|
592
|
-
.unwrap(),
|
|
593
|
-
&k,
|
|
594
|
-
wavenumber,
|
|
595
|
-
);
|
|
612
|
+
let (kxx, kyy) = calculate_kxx_kyy(&self.kinc_xy, &k, self.wavenumber);
|
|
596
613
|
|
|
597
614
|
// Loop over aperture edges
|
|
598
|
-
let nv = edge_data.x.len();
|
|
615
|
+
let nv = self.edge_data.x.len();
|
|
599
616
|
for j in 0..nv {
|
|
600
|
-
let xj = edge_data.x[j];
|
|
601
|
-
let yj = edge_data.y[j];
|
|
602
|
-
let dx = edge_data.dx[j];
|
|
603
|
-
let dy = edge_data.dy[j];
|
|
604
|
-
let mj = edge_data.m_adj[j];
|
|
605
|
-
let nj = edge_data.n_adj[j];
|
|
617
|
+
let xj = self.edge_data.x[j];
|
|
618
|
+
let yj = self.edge_data.y[j];
|
|
619
|
+
let dx = self.edge_data.dx[j];
|
|
620
|
+
let dy = self.edge_data.dy[j];
|
|
621
|
+
let mj = self.edge_data.m_adj[j];
|
|
622
|
+
let nj = self.edge_data.n_adj[j];
|
|
606
623
|
|
|
607
624
|
let (delta, delta1, delta2) = calculate_deltas(kxx, kyy, xj, yj, mj, nj);
|
|
608
625
|
let (omega1, omega2) = calculate_omegas(dx, dy, delta1, delta2);
|
|
@@ -613,7 +630,8 @@ pub fn n2f_aperture_diffraction(
|
|
|
613
630
|
continue;
|
|
614
631
|
}
|
|
615
632
|
|
|
616
|
-
let summand =
|
|
633
|
+
let summand =
|
|
634
|
+
calculate_summand(bvsk, delta, omega1, omega2, alpha, beta, self.inv_denom);
|
|
617
635
|
|
|
618
636
|
// Final check
|
|
619
637
|
if summand.is_nan() {
|
|
@@ -623,17 +641,34 @@ pub fn n2f_aperture_diffraction(
|
|
|
623
641
|
fraunhofer_sum += summand;
|
|
624
642
|
}
|
|
625
643
|
|
|
626
|
-
*
|
|
644
|
+
ampl_bin * fraunhofer_sum
|
|
627
645
|
}
|
|
646
|
+
}
|
|
628
647
|
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
648
|
+
/// Perform near-to-far field aperture diffraction for a single beam over all bins.
|
|
649
|
+
///
|
|
650
|
+
/// Beam-major convenience wrapper around [`DiffractionContext`]. For hot
|
|
651
|
+
/// paths that accumulate many beams into the same bins, build the contexts
|
|
652
|
+
/// once and iterate bin-major instead.
|
|
653
|
+
///
|
|
654
|
+
/// # Returns
|
|
655
|
+
/// Vector of (bin_index, amplitude_matrix) pairs, with zero-amplitude bins omitted
|
|
656
|
+
pub fn n2f_aperture_diffraction(
|
|
657
|
+
beam: &Beam,
|
|
658
|
+
bins: &[SolidAngleBin],
|
|
659
|
+
incident: &IncidentBeam,
|
|
660
|
+
fov_factor: Option<f32>,
|
|
661
|
+
) -> Result<Vec<(usize, Ampl)>> {
|
|
662
|
+
let context = DiffractionContext::new(beam, incident, fov_factor)?;
|
|
635
663
|
|
|
636
|
-
Ok(
|
|
664
|
+
Ok(bins
|
|
665
|
+
.iter()
|
|
666
|
+
.enumerate()
|
|
667
|
+
.filter_map(|(index, bin)| {
|
|
668
|
+
let ampl = context.contribution(bin);
|
|
669
|
+
ampl.iter().any(|c| c.norm() > 0.0).then_some((index, ampl))
|
|
670
|
+
})
|
|
671
|
+
.collect())
|
|
637
672
|
}
|
|
638
673
|
|
|
639
674
|
#[cfg(test)]
|