diff --git a/bachelorarbeit/Cargo.lock b/bachelorarbeit/Cargo.lock index fdbf0b3..1257949 100644 --- a/bachelorarbeit/Cargo.lock +++ b/bachelorarbeit/Cargo.lock @@ -455,6 +455,7 @@ checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" name = "bachelorarbeit" version = "0.1.0" dependencies = [ + "ahash", "eframe", "egui", "egui_extras", diff --git a/bachelorarbeit/Cargo.toml b/bachelorarbeit/Cargo.toml index c0910d2..366c249 100644 --- a/bachelorarbeit/Cargo.toml +++ b/bachelorarbeit/Cargo.toml @@ -14,6 +14,7 @@ eframe = "0.27.2" egui_plot = "0.27.2" indicatif = "0.17.8" nohash-hasher = "0.2.0" +ahash = "0.8.11" [target.'cfg(target_arch = "wasm32")'.dependencies] wasm-bindgen-futures = "0.4" @@ -21,9 +22,9 @@ gloo-net = "0.5.0" [profile.release] debug = true -# lto = "fat" -# codegen-units = 1 +lto = "fat" +codegen-units = 1 [profile.webrelease] inherits = "release" -opt-level = "s" \ No newline at end of file +opt-level = "s" diff --git a/bachelorarbeit/flamegraph.png b/bachelorarbeit/flamegraph.png new file mode 100644 index 0000000..0ffb936 Binary files /dev/null and b/bachelorarbeit/flamegraph.png differ diff --git a/bachelorarbeit/src/calc.rs b/bachelorarbeit/src/calc.rs index 2de2bd7..08d9e53 100644 --- a/bachelorarbeit/src/calc.rs +++ b/bachelorarbeit/src/calc.rs @@ -4,6 +4,8 @@ use std::collections::HashMap; use std::io; use std::rc::Rc; +use ahash::{AHasher, RandomState}; + use std::{fs::File, io::BufReader}; use crate::gq_storage; @@ -34,6 +36,22 @@ pub struct Cache { >, // First key is n, second is s } +// pub struct Cache { +// pub gauss_quad_lut: HashMap, Rc<[f64]>), RandomState>, +// pub delta_lut: HashMap, +// pub omnes_lut: HashMap< +// u32, +// HashMap, +// RandomState, +// >, // First key is n, second is s +// } + +// pub struct Cache { +// pub gauss_quad_lut: HashMap, Rc<[f64]>)>, +// pub delta_lut: HashMap, +// pub omnes_lut: HashMap> // First key is n, second is s +// } + impl Cache { pub fn from_file(filepath: &str) -> io::Result { let file = File::open(filepath)?; @@ -194,9 +212,6 @@ pub fn omnes_integrand_notan(cache: &mut Cache, s_tick: f64, s: f64) -> Complex } pub fn omnes(cache: &mut Cache, s: f64, n: u32, use_tan: bool) -> Complex { - let roots: Rc<[f64]>; - let weights: Rc<[f64]>; - if let Some(inner_lut) = cache.omnes_lut.get(&n) { if let Some(res) = inner_lut.get(&s.to_bits()) { return *res; @@ -209,6 +224,8 @@ pub fn omnes(cache: &mut Cache, s: f64, n: u32, use_tan: bool) -> Complex { .insert(n, HashMap::with_hasher(Default::default())); } + let roots: Rc<[f64]>; + let weights: Rc<[f64]>; match cache.gauss_quad_lut.get_mut(&n) { Some(gq_values) => { roots = Rc::clone(&gq_values.0); @@ -335,6 +352,8 @@ pub fn phi0( -(s - S0).sqrt() * (intgrl - analyt) } + + #[allow(unused)] pub fn bit_pattern_randomness_tester(a: f64, b: f64, n_points: u64) -> Vec { let mut modulos = vec![0.0; n_points as usize]; diff --git a/bachelorarbeit/src/main.rs b/bachelorarbeit/src/main.rs index 3ad4f9c..22c61e6 100644 --- a/bachelorarbeit/src/main.rs +++ b/bachelorarbeit/src/main.rs @@ -3,7 +3,7 @@ // - Reduziertes Integral aus Paper zu numerisch berechenbarer Form umformen use indicatif; -use std::collections::HashMap; +use std::{collections::HashMap, time::Instant}; use egui_plot::{log_grid_spacer, AxisHints, GridInput, GridMark, Legend, Line, Plot}; use num::complex::ComplexFloat; @@ -25,6 +25,9 @@ struct App { use_tan_phi0: bool, use_xsub_phi0: bool, use_reduced_integrand: bool, + use_cutoff: bool, + cutoff_s: f64, + cont_power: f64, } #[derive(Clone)] @@ -50,10 +53,17 @@ impl Default for App { n_points: 500, n_omnes: 500, n_phi0: 500, + + // Substitutions params use_tan_omnes: true, use_tan_phi0: true, use_xsub_phi0: true, use_reduced_integrand: true, + + // Cutoff params + use_cutoff: false, + cutoff_s: 100.0, + cont_power: -1.0, } } } @@ -78,39 +88,39 @@ impl eframe::App for App { ui.label("calc interval start:").on_hover_text( "the lower bound of the interval that functions are calculated in", ); - float_text_edit_singleline(ui, &mut self.a); + float_text_edit_singleline(ui, &mut self.a, true); ui.end_row(); ui.label("calc interval end:").on_hover_text( "the upper bound of the interval that functions are calculated in", ); - float_text_edit_singleline(ui, &mut self.b); + float_text_edit_singleline(ui, &mut self.b, true); ui.end_row(); ui.label("N for omnes:").on_hover_text( "the number of points used in calculation of omnes function", ); - int_text_edit_singleline(ui, &mut self.n_omnes); + int_text_edit_singleline(ui, &mut self.n_omnes, true); ui.end_row(); ui.label("N for phi0:").on_hover_text( "the number of points used in calculation of phi0 function", ); - int_text_edit_singleline(ui, &mut self.n_phi0); + int_text_edit_singleline(ui, &mut self.n_phi0, true); ui.end_row(); ui.label("number of plotpoints:") .on_hover_text("the number of points shown in the plot"); - int_text_edit_singleline(ui, &mut self.n_points); + int_text_edit_singleline(ui, &mut self.n_points, true); ui.end_row(); }); ui.separator(); ui.vertical(|ui| { - let omnes_cb = + let omnes_tan_cb = ui.checkbox(&mut self.use_tan_omnes, "Use tan()-subst. for Omnes ('ot')"); - if omnes_cb.clicked() { + if omnes_tan_cb.clicked() { self.calc_cache.omnes_lut = HashMap::with_hasher(Default::default()); // TODO split omnes_lut so that this is no longer necessary } ui.checkbox(&mut self.use_tan_phi0, "Use tan()-subst. for phi0 ('pt')"); @@ -142,6 +152,24 @@ impl eframe::App for App { egui::widgets::global_dark_light_mode_switch(ui); }); }); + + ui.separator(); + + ui.vertical(|ui| { + ui.label("Omnes Continuation with polynomial").on_hover_text( + "If activated, from a user chosen cutoff value, the Omnes function will be replaced with s to a user chosen power, starting at the last Omnes value of the numerically calculated values", + ); + ui.checkbox(&mut self.use_cutoff, "Use cutoff"); + egui::Grid::new("grid2").min_col_width(125.0).show(ui, |ui| { + ui.label("Power for continuation").on_hover_text("Omnes will be replaced with s^{this power}."); + float_text_edit_singleline(ui, &mut self.cont_power, self.use_cutoff); + ui.end_row(); + + ui.label("Cutoff point").on_hover_text("Omnes will be replaced from this s-value onward."); + float_text_edit_singleline(ui, &mut self.cutoff_s, self.use_cutoff); + ui.end_row(); + }); + }) }); ui.separator(); @@ -204,7 +232,7 @@ impl eframe::App for App { self.use_tan_omnes, ) .abs() - //.powi(2) + .powi(2) }) .collect(); bar.finish(); @@ -244,7 +272,8 @@ impl eframe::App for App { if self.scaling_type == ScalingType::Linear { let bar = indicatif::ProgressBar::new(u64::from(self.n_points)); - x_values + let t0 = Instant::now(); + let values = x_values .iter() .map(|&x| { bar.inc(1); @@ -260,7 +289,9 @@ impl eframe::App for App { x == self.a, ) }) - .collect() + .collect(); + println!("{:?}", t0.elapsed()); + values } else { x_values .iter() @@ -432,23 +463,35 @@ impl eframe::App for App { fn main() { let mut app = App::default(); app.calc_cache = calc::Cache::from_file("./gauss_quad_lut.morello").unwrap(); - // let x_values: Vec = (0..app.n_points) - // .map(|x| -> f64 { f64::from(x) * ((app.b - app.a) / f64::from(app.n_points)) + app.a }) - // .collect(); - // let t0 = Instant::now(); - // let y_values_phi0: Vec = x_values - // .iter() - // .map(|&x| calc::phi0(&mut app.calc_cache, x, app.n_omnes, app.n_phi0)) - // .collect(); - // std::hint::black_box(&y_values_phi0); - // println!("{:?}", t0.elapsed()); - eframe::run_native( - "Titel", - eframe::NativeOptions::default(), - Box::new(|_cc| Box::new(app)), - ) - .unwrap(); + let x_values: Vec = (0..app.n_points) + .map(|x| -> f64 { f64::from(x) * ((app.b - app.a) / f64::from(app.n_points)) + app.a }) + .collect(); + let bar = indicatif::ProgressBar::new(u64::from(app.n_points)); + let values: Vec = x_values + .iter() + .map(|&x| { + bar.inc(1); + calc::phi0( + &mut app.calc_cache, + x, + 1000, + 1000, + app.use_tan_omnes, + app.use_tan_phi0, + app.use_xsub_phi0, + app.use_reduced_integrand, + x == app.a, + ) + }) + .collect(); + + // eframe::run_native( + // "Titel", + // eframe::NativeOptions::default(), + // Box::new(|_cc| Box::new(app)), + // ) + // .unwrap(); } #[cfg(target_arch = "wasm32")] @@ -503,9 +546,10 @@ fn scientific_notation(x: f64, log: bool) -> String { } } -fn int_text_edit_singleline(ui: &mut egui::Ui, value: &mut u32) -> egui::Response { +fn int_text_edit_singleline(ui: &mut egui::Ui, value: &mut u32, enabled: bool) -> egui::Response { let mut tmp_value = format!("{}", value); - let res = ui.text_edit_singleline(&mut tmp_value); + let textedit = egui::TextEdit::singleline(&mut tmp_value); + let res = ui.add_enabled(enabled, textedit); if let Ok(result) = tmp_value.parse::() { *value = result; } else if tmp_value == "" { @@ -514,9 +558,10 @@ fn int_text_edit_singleline(ui: &mut egui::Ui, value: &mut u32) -> egui::Respons res } -fn float_text_edit_singleline(ui: &mut egui::Ui, value: &mut f64) -> egui::Response { +fn float_text_edit_singleline(ui: &mut egui::Ui, value: &mut f64, enabled: bool) -> egui::Response { let mut tmp_value = format!("{}", value); - let res = ui.text_edit_singleline(&mut tmp_value); + let textedit = egui::TextEdit::singleline(&mut tmp_value); + let res = ui.add_enabled(enabled, textedit); if let Ok(result) = tmp_value.parse::() { *value = result; } else if tmp_value == "" { diff --git a/calc.py b/calc.py index 67d639b..919dc97 100644 --- a/calc.py +++ b/calc.py @@ -34,8 +34,9 @@ import random # print(v_z_end/v_x) # print(1.492+0.1492) -sum = 0 -for i in range(18): - sum += random.randint(1,4) +# sum = 0 +# for i in range(18): +# sum += random.randint(1,4) -print(sum) \ No newline at end of file +# print(sum) +