Working multithreaded version backup

This commit is contained in:
Jan Bergen 2024-09-12 16:03:23 +02:00
parent 45bca79eb6
commit 8ffbe252d1
26 changed files with 377 additions and 131 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 104 KiB

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

Binary file not shown.

125
bachelorarbeit/plotter.py Normal file
View File

@ -0,0 +1,125 @@
import numpy as np
import matplotlib.pyplot as plt
import scienceplots
i = 1
names = [
"omnes_integrand",
"omnes_integrand_zoom",
"omnes_integrand_tan",
"phi0_integrand",
"phi0_integrand_zoom",
"phi0_integrand_tan",
"delta",
"omnes",
"phi0",
"phi0_delta_rel_diff",
]
files = [open("exports/" + n + ".txt") for n in names]
export_filenames = ["figures/" + n + ".png" for n in names]
titles = [
r"$\frac{\delta_1^1(s') - \delta_1^1(s)}{s'(s'-s)}$, $\sqrt{s}=1$ GeV",
r"$\frac{\delta_1^1(s') - \delta_1^1(s)}{s'(s'-s)}$, $\sqrt{s}=1$ GeV",
r"$\frac{1}{\cos^2(u)}\frac{\delta_1^1(\tan{u}) - \delta_1^1(s)}{\tan{u}(\tan{u}-s)}$, $\sqrt{s}=1$ GeV",
r"$\frac{\ln{|\frac{F(s')}{F(s)}|^2}}{(x^2+s_0)(x^2+s_0-s)}$, $\sqrt{s}=1$ GeV",
r"$\frac{\ln{|\frac{F(s')}{F(s)}|^2}}{(x^2+s_0)(x^2+s_0-s)}$, $\sqrt{s}=1$ GeV",
r"$\frac{1}{\cos^2(u)}\frac{\ln{|\frac{F(\tan^2{u}+s_0)}{F(s)}|^2}}{(\tan^2{u}+s_0)(\tan^2{u}+s_0-s)}$, $\sqrt{s}=1$ GeV",
"",
"",
"",
"",
]
xlabels = [
r"$\sqrt{s}$ [GeV]",
r"$\sqrt{s}$ [GeV]",
r"$u$",
r"$x$",
r"$x$",
r"$u$",
r"$\sqrt{s}$ [GeV]",
r"$\sqrt{s}$ [GeV]",
r"$\sqrt{s}$ [GeV]",
r"$\sqrt{s}$ [GeV]",
]
ylabels = [
r"integrand",
r"integrand",
r"integrand",
r"integrand",
r"integrand",
r"integrand",
r"$\delta_1^1(s)$",
r"$|\Omega(s)|^2$",
r"$\phi_0(s)$",
r"$\frac{\phi_0(s)}{\delta_1^1(s)}$",
]
y_logarithmic = [
False,
False,
False,
False,
False,
False,
False,
True,
False,
False,
]
x_sqrt = [
True,
True,
False,
False,
False,
False,
True,
True,
True,
True,
]
for i in range(len(names)):
print(i)
plt.figure()
filecont = []
for line in files[i]:
filecont.append(line.split(','))
data = []
for curve in filecont:
curve_numbers = []
for val in curve:
try:
curve_numbers.append(float(val))
except ValueError:
continue
if x_sqrt[i]:
curve_numbers_paired = np.array([[x**0.5 for x in curve_numbers[0::2]], curve_numbers[1::2]])
else:
curve_numbers_paired = np.array([curve_numbers[0::2], curve_numbers[1::2]])
data.append(curve_numbers_paired)
# Plotting
plt.style.use(['science'])
plt.figure(figsize=(4,3))
plt.title(titles[i], fontsize = 15)
if y_logarithmic[i]:
plt.yscale('log')
for j in range(len(data)):
plt.plot(data[j][0], data[j][1])
plt.xlabel(xlabels[i], fontsize = 12)
plt.ylabel(ylabels[i], fontsize = 12)
plt.grid(which='major', color='#000000', linestyle='-', alpha = 0.3)
plt.grid(which='minor', color='#000000', linestyle='-', alpha=0.1)
plt.savefig(export_filenames[i], dpi=400)
plt.close()

View File

@ -13,18 +13,18 @@ use crate::gq_storage;
pub type Complex = num::complex::Complex<f64>; pub type Complex = num::complex::Complex<f64>;
const M_ROH: f64 = 0.7736; pub const M_ROH: f64 = 0.7736;
const M_PI: f64 = 0.13957; pub const M_PI: f64 = 0.13957;
pub const S0: f64 = 4.0 * M_PI * M_PI; pub const S0: f64 = 4.0 * M_PI * M_PI;
const M_K: f64 = 0.496; pub const M_K: f64 = 0.496;
const B0: f64 = 1.055; pub const B0: f64 = 1.055;
const B1: f64 = 0.15; pub const B1: f64 = 0.15;
const LAMBDA1: f64 = 1.57; pub const LAMBDA1: f64 = 1.57;
const LAMBDA2: f64 = -1.96; pub const LAMBDA2: f64 = -1.96;
const LAMBDA_HIGH: f64 = 10.0; pub const LAMBDA_HIGH: f64 = 10.0;
pub const EPSILON: f64 = 1e-15; pub const EPSILON: f64 = 1e-15;
const S_MID_CUTOFF: f64 = 1.42 * 1.42; pub const S_MID_CUTOFF: f64 = 1.42;
const INF: f64 = 1e6; pub const INF: f64 = 1e6;
#[derive(Default)] #[derive(Default)]
pub struct Cache { pub struct Cache {
@ -105,12 +105,8 @@ impl Cache {
// derivated values // derivated values
fn lambda_0() -> f64 { fn lambda_0(cache: &Cache) -> f64 {
delta((2.0 * M_K).powi(2)) delta_with_lut(cache, (2.0 * M_K).powi(2))
}
fn delta_mid_cutoff() -> f64 {
delta(S_MID_CUTOFF)
} }
fn atan_shift(x: f64) -> f64 { fn atan_shift(x: f64) -> f64 {
@ -133,7 +129,6 @@ fn integrate<G: Fn(f64) -> f64 + Send + Sync>(
if roots.len() != weights.len() { if roots.len() != weights.len() {
panic!("Error: roots and weights are of different length"); panic!("Error: roots and weights are of different length");
} }
println!("Calculating single integration: ");
let prog = indicatif::ProgressBar::new(roots.len() as u64); let prog = indicatif::ProgressBar::new(roots.len() as u64);
let prog_ = prog.clone(); let prog_ = prog.clone();
let sum:f64 = (weights.par_iter(), roots.par_iter()).into_par_iter().map(move |(weight,root)| { let sum:f64 = (weights.par_iter(), roots.par_iter()).into_par_iter().map(move |(weight,root)| {
@ -183,30 +178,69 @@ fn k(s: f64) -> f64 {
} }
pub fn delta_with_lut(cache: &Cache, s: f64) -> f64 { pub fn delta_with_lut(cache: &Cache, s: f64) -> f64 {
// println!("delta_with_lut");
match cache.delta_lut.get(&s.to_bits()) { match cache.delta_lut.get(&s.to_bits()) {
Some(val) => *val, Some(val) => *val,
None => { None => {
let val = delta(s); let val = delta(cache, s);
let _ = cache.delta_lut.insert(s.to_bits(), val); let _ = cache.delta_lut.insert(s.to_bits(), val);
val val
} }
} }
} }
pub fn delta(s: f64) -> f64 {
if s <= 2.0 * M_K {
const BLEND_RANGE: f64 = 0.1;
#[allow(unused)]
pub fn delta_low(cache: &Cache, s: f64) -> f64 {
atan_shift(
(s.sqrt() / (2.0 * k(s).powi(3))
* (M_ROH.powi(2) - s)
* ((2.0 * M_PI.powi(3)) / (M_ROH.powi(2) * s.sqrt()) + B0 + B1 * omega(s)))
.powi(-1),
)
}
#[allow(unused)]
pub fn delta_mid(cache: &Cache, s: f64) -> f64 {
let par = 0.5 * s.sqrt() / M_K - 1.0;
lambda_0(cache) + LAMBDA1 * par + LAMBDA2 * par.powi(2)
}
#[allow(unused)]
pub fn delta_high(cache: &Cache, s: f64) -> f64 {
PI + (delta(cache, S_MID_CUTOFF.powi(2)) - PI) * (LAMBDA_HIGH * LAMBDA_HIGH + S_MID_CUTOFF)
/ (LAMBDA_HIGH * LAMBDA_HIGH + s)
}
#[allow(unused)]
pub fn delta_blend(cache: &Cache, s: f64) -> f64 {
if (s - 4.0*M_K.powi(2)).abs() < BLEND_RANGE {
let t = (s - 4.0*M_K.powi(2) + BLEND_RANGE) / (2.0*BLEND_RANGE);
(1.0 - t) * delta_low(cache, s) + t * delta_mid(cache, s)
} else if (s - S_MID_CUTOFF.powi(2)).abs() < BLEND_RANGE {
let t = (s - S_MID_CUTOFF.powi(2) + BLEND_RANGE) / (2.0*BLEND_RANGE);
(1.0 - t) * delta_mid(cache, s) + t * delta_high(cache, s)
} else {
delta(cache, s)
}
}
fn delta(cache: &Cache, s: f64) -> f64 {
let s_sqrt = s.sqrt();
if s <= 4.0 * M_K.powi(2) {
atan_shift( atan_shift(
(s.sqrt() / (2.0 * k(s).powi(3)) (s_sqrt / (2.0 * k(s).powi(3))
* (M_ROH.powi(2) - s) * (M_ROH.powi(2) - s)
* ((2.0 * M_PI.powi(3)) / (M_ROH.powi(2) * s.sqrt()) + B0 + B1 * omega(s))) * ((2.0 * M_PI.powi(3)) / (M_ROH.powi(2) * s_sqrt) + B0 + B1 * omega(s)))
.powi(-1), .powi(-1),
) )
} else if s <= S_MID_CUTOFF { } else if s <= S_MID_CUTOFF.powi(2) {
let par = 0.5 * s.sqrt() / M_K - 1.0; let par = 0.5 * s_sqrt / M_K - 1.0;
lambda_0() + LAMBDA1 * par + LAMBDA2 * par.powi(2) lambda_0(cache) + LAMBDA1 * par + LAMBDA2 * par.powi(2)
} else { } else {
PI + (delta_mid_cutoff() - PI) * (LAMBDA_HIGH * LAMBDA_HIGH + S_MID_CUTOFF) PI + (delta_with_lut(cache, S_MID_CUTOFF.powi(2)) - PI) * (LAMBDA_HIGH * LAMBDA_HIGH + S_MID_CUTOFF)
/ (LAMBDA_HIGH * LAMBDA_HIGH + s) / (LAMBDA_HIGH * LAMBDA_HIGH + s)
} }
} }
@ -218,13 +252,11 @@ pub fn omnes_integrand_tan(cache: &Cache, s_tick: f64, s: f64) -> Complex {
} }
pub fn omnes_integrand_notan(cache: &Cache, s_tick: f64, s: f64) -> Complex { pub fn omnes_integrand_notan(cache: &Cache, s_tick: f64, s: f64) -> Complex {
// println!("omnes_integrand_notan");
(delta_with_lut(cache, s_tick) - delta_with_lut(cache, s)) (delta_with_lut(cache, s_tick) - delta_with_lut(cache, s))
/ (s_tick * (s_tick - s + Complex::new(0.0, EPSILON))) / (s_tick * (s_tick - s + Complex::new(0.0, EPSILON)))
} }
pub fn omnes(cache: &Cache, s: f64, n: u32, use_tan: bool) -> Complex { pub fn omnes(cache: &Cache, s: f64, n: u32, use_tan: bool) -> Complex {
// println!("Omnes");
if let Some(inner_lut) = cache.omnes_lut.get(&n) { if let Some(inner_lut) = cache.omnes_lut.get(&n) {
if let Some(res) = inner_lut.get(&s.to_bits()) { if let Some(res) = inner_lut.get(&s.to_bits()) {
return *res; return *res;
@ -236,24 +268,20 @@ pub fn omnes(cache: &Cache, s: f64, n: u32, use_tan: bool) -> Complex {
.insert(n, DashMap::with_hasher(Default::default())); .insert(n, DashMap::with_hasher(Default::default()));
} }
// println!("Retrieving roots and weights omnes");
let roots: Arc<[f64]>; let roots: Arc<[f64]>;
let weights: Arc<[f64]>; let weights: Arc<[f64]>;
match cache.gauss_quad_lut.get(&n) { match cache.gauss_quad_lut.get(&n) {
Some(gq_values) => { Some(gq_values) => {
// println!("Somobomo");
roots = Arc::clone(&gq_values.0); roots = Arc::clone(&gq_values.0);
weights = Arc::clone(&gq_values.1); weights = Arc::clone(&gq_values.1);
} }
None => { None => {
// println!("Nononono");
let gq_values = GaussLegendre::nodes_and_weights(n.try_into().unwrap()); let gq_values = GaussLegendre::nodes_and_weights(n.try_into().unwrap());
roots = Arc::from(gq_values.0.as_slice()); roots = Arc::from(gq_values.0.as_slice());
weights = Arc::from(gq_values.1.as_slice()); weights = Arc::from(gq_values.1.as_slice());
} }
} }
// println!("will maybe calc n_omnes");
if !cache.gauss_quad_lut.contains_key(&n) { if !cache.gauss_quad_lut.contains_key(&n) {
println!("n_omnes={} is not included in the lookup file. Consider generating a new lookup file via the appropriate function in gq_storage.rs", n); println!("n_omnes={} is not included in the lookup file. Consider generating a new lookup file via the appropriate function in gq_storage.rs", n);
let gq_values = GaussLegendre::nodes_and_weights(n.try_into().unwrap()); let gq_values = GaussLegendre::nodes_and_weights(n.try_into().unwrap());
@ -262,7 +290,6 @@ pub fn omnes(cache: &Cache, s: f64, n: u32, use_tan: bool) -> Complex {
.insert(n, (Arc::from(gq_values.0), Arc::from(gq_values.1))); .insert(n, (Arc::from(gq_values.0), Arc::from(gq_values.1)));
} }
// println!("Will calculate integrate complex");
let intgrl = if use_tan { let intgrl = if use_tan {
integrate_complex(&roots, &weights, S0.atan(), PI / 2.0, |s_tick| { integrate_complex(&roots, &weights, S0.atan(), PI / 2.0, |s_tick| {
omnes_integrand_tan(cache, s_tick, s) omnes_integrand_tan(cache, s_tick, s)
@ -297,21 +324,14 @@ pub fn phi0_integrand(
cutoff_s: f64, cutoff_s: f64,
cutoff_factor: Complex, cutoff_factor: Complex,
) -> f64 { ) -> f64 {
// println!("phi0_integrand");
let sub = match (use_tan_phi0, use_xsub) { let sub = match (use_tan_phi0, use_xsub) {
(true, true) => s_tick.tan().powi(2) + S0, (true, true) => s_tick.tan().powi(2) + S0,
(true, false) => s_tick.tan(), (true, false) => s_tick.tan(),
(false, true) => s_tick.powi(2) + S0, (false, true) => s_tick.powi(2) + S0,
(false, false) => s_tick, (false, false) => s_tick,
}; };
// let omnes_s = if use_cutoff && s >= cutoff_s {
// cutoff_factor * s.powf(cutoff_power)
// } else {
// omnes(cache, s, n_omnes, use_tan_omnes)
// };
let omnes_sub = if use_cutoff && sub >= cutoff_s { let omnes_sub = if use_cutoff && sub >= cutoff_s {
cutoff_factor * sub.powf(cutoff_power) cutoff_factor * sub.powf(cutoff_power)
// Complex::new((0.00002f64).powf(cutoff_power), 0.0)
} else { } else {
omnes(cache, sub, n_omnes, use_tan_omnes) omnes(cache, sub, n_omnes, use_tan_omnes)
}; };
@ -340,7 +360,6 @@ pub fn phi0(
cutoff_power: f64, cutoff_power: f64,
cutoff_s: f64 cutoff_s: f64
) -> f64 { ) -> f64 {
// println!("phi0");
if !cache.gauss_quad_lut.contains_key(&n_phi0) { if !cache.gauss_quad_lut.contains_key(&n_phi0) {
let gq_values = GaussLegendre::nodes_and_weights(n_phi0.try_into().unwrap()); let gq_values = GaussLegendre::nodes_and_weights(n_phi0.try_into().unwrap());
let _ = cache let _ = cache
@ -353,14 +372,13 @@ pub fn phi0(
(Arc::clone(&ent.0), Arc::clone(&ent.1)) (Arc::clone(&ent.0), Arc::clone(&ent.1))
}; };
// println!("Will run omnes");
let analyt = if use_reduced_integrand { let analyt = if use_reduced_integrand {
omnes(cache, s, n_omnes, use_tan_omnes).norm().ln() / S0.sqrt()
} else {
(omnes(cache, s, n_omnes, use_tan_omnes) / omnes(cache, S0, n_omnes, use_tan_omnes)) (omnes(cache, s, n_omnes, use_tan_omnes) / omnes(cache, S0, n_omnes, use_tan_omnes))
.norm() .norm()
.ln() .ln()
/ (s * (s - S0).powf(1.5)) / (s * (s - S0).powf(1.5))
} else {
omnes(cache, s, n_omnes, use_tan_omnes).norm().ln() / S0.sqrt()
}; };
let cutoff_factor = omnes(cache, cutoff_s, n_omnes, use_tan_omnes) * cutoff_s.powf(-cutoff_power); let cutoff_factor = omnes(cache, cutoff_s, n_omnes, use_tan_omnes) * cutoff_s.powf(-cutoff_power);

View File

@ -4,10 +4,12 @@
use indicatif; use indicatif;
use std::time::Instant; use std::time::Instant;
use std::fs;
use core::f64::consts::PI;
use egui_plot::{log_grid_spacer, AxisHints, GridInput, GridMark, Legend, Line, Plot}; use egui_plot::{log_grid_spacer, AxisHints, GridInput, GridMark, Legend, Line, Plot};
use num::{complex::ComplexFloat, Float}; use num::{complex::ComplexFloat, Float};
use eframe::Theme;
// use scc::HashMap; // use scc::HashMap;
mod calc; mod calc;
@ -15,7 +17,7 @@ mod gq_storage;
struct App { struct App {
plot_data: Vec<PlotCurve>, plot_data: Vec<PlotCurve>,
plots_available: [String; 7], plots_available: [String; 9],
calc_cache: calc::Cache, calc_cache: calc::Cache,
scaling_type: ScalingType, scaling_type: ScalingType,
a: f64, a: f64,
@ -30,6 +32,7 @@ struct App {
use_cutoff: bool, use_cutoff: bool,
cutoff_power: f64, cutoff_power: f64,
cutoff_s: f64, cutoff_s: f64,
export_filename: String,
} }
#[derive(Clone)] #[derive(Clone)]
@ -48,27 +51,31 @@ impl Default for App {
"Phi0".to_string(), "Phi0".to_string(),
"Phi0 / delta".to_string(), "Phi0 / delta".to_string(),
"s^cutoff_power".to_string(), "s^cutoff_power".to_string(),
"Omnes integrand".to_string(),
"phi0 integrand".to_string(), "phi0 integrand".to_string(),
"Phi0_cut / Phi0".to_string(), "Phi0_cut / Phi0".to_string(),
"Phi0 / delta".to_string(),
], ],
calc_cache: calc::Cache::default(), calc_cache: calc::Cache::default(),
scaling_type: ScalingType::default(), scaling_type: ScalingType::default(),
a: calc::S0, a: calc::S0,
b: 9.0, b: 9.0,
n_points: 500, n_points:2500,
n_omnes: 500, n_omnes:2500,
n_phi0: 500, n_phi0:2500,
// Substitutions params // Substitutions params
use_tan_omnes: true, use_tan_omnes: true,
use_tan_phi0: true, use_tan_phi0: true,
use_xsub_phi0: true, use_xsub_phi0: true,
use_reduced_integrand: true, use_reduced_integrand: false,
// Cutoff params // Cutoff params
use_cutoff: false, use_cutoff: false,
cutoff_power: -1.0, cutoff_power: -1.0,
cutoff_s: 100.0, cutoff_s: 100.0,
export_filename: "plot_data".to_string(),
} }
} }
} }
@ -83,6 +90,7 @@ enum ScalingType {
impl eframe::App for App { impl eframe::App for App {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| { egui::CentralPanel::default().show(ctx, |ui| {
ui.set_min_width(ui.available_width());
let cur_scaling_type = self.scaling_type; let cur_scaling_type = self.scaling_type;
ui.vertical(|ui| { ui.vertical(|ui| {
@ -97,12 +105,20 @@ impl eframe::App for App {
"the lower bound of the interval that functions are calculated in", "the lower bound of the interval that functions are calculated in",
); );
float_text_edit_singleline(ui, &mut self.a, true); float_text_edit_singleline(ui, &mut self.a, true);
let seta_pi2 = ui.button("S0");
if seta_pi2.clicked() {
self.a = calc::S0;
}
ui.end_row(); ui.end_row();
ui.label("calc interval end:").on_hover_text( ui.label("calc interval end:").on_hover_text(
"the upper bound of the interval that functions are calculated in", "the upper bound of the interval that functions are calculated in",
); );
float_text_edit_singleline(ui, &mut self.b, true); float_text_edit_singleline(ui, &mut self.b, true);
let setb_pi2 = ui.button("pi/2");
if setb_pi2.clicked() {
self.b = 1.5707963268;
}
ui.end_row(); ui.end_row();
ui.label("N for omnes:").on_hover_text( ui.label("N for omnes:").on_hover_text(
@ -180,6 +196,25 @@ impl eframe::App for App {
float_text_edit_singleline(ui, &mut self.cutoff_s, true); float_text_edit_singleline(ui, &mut self.cutoff_s, true);
ui.end_row(); ui.end_row();
}); });
let textedit = egui::TextEdit::singleline(&mut self.export_filename);
ui.add(textedit);
let button_export = ui.button("Export data");
if button_export.clicked() {
let mut plot_data_str = String::new();
for curve in &mut self.plot_data {
for point in &mut curve.points {
plot_data_str.push_str(&point[0].to_string());
plot_data_str.push_str(",");
plot_data_str.push_str(&point[1].to_string());
plot_data_str.push_str(",");
}
plot_data_str.push_str("\n");
}
let mut filename = "./exports/".to_owned();
filename.push_str(&self.export_filename);
filename.push_str(".txt");
fs::write(filename, plot_data_str).expect("Unable to write file");
}
}) })
}); });
@ -199,76 +234,52 @@ impl eframe::App for App {
.collect(); .collect();
match i { match i {
0 => { 0 => {
let y_values_delta: Vec<f64> = if self.scaling_type let y_values: Vec<f64> = x_values.iter().map(|&x| {
== ScalingType::Linear let val = calc::delta_with_lut(&mut self.calc_cache, x);
{ match self.scaling_type {
x_values ScalingType::Linear => {
.iter() val
.map(|&x| calc::delta_with_lut(&mut self.calc_cache, x)) }
.collect() ScalingType::Logarithmic => {
} else { val.log10()
x_values }
.iter() }
.map(|&x| { }).collect();
calc::delta_with_lut(&mut self.calc_cache, x)
.log10()
})
.collect()
};
self.plot_data.push(PlotCurve { self.plot_data.push(PlotCurve {
points: x_values points: x_values
.iter() .iter()
.zip(y_values_delta.iter()) .zip(y_values.iter())
.map(|(&x, &y)| [x.powf(0.5), y]) .map(|(&x, &y)| [x, y])
.collect(), .collect(),
name: format!("(#{}) Delta", self.plot_data.len() + 1), name: format!("(#{}) Delta", self.plot_data.len() + 1),
}) });
} }
1 => { 1 => {
let y_values_omnes: Vec<f64> = if self.scaling_type let cutoff_factor = calc::omnes(&mut self.calc_cache, self.cutoff_s, self.n_omnes, self.use_tan_omnes) * self.cutoff_s;
== ScalingType::Linear
{ let y_values: Vec<f64> = x_values.iter().map(|&x| {
print!("Calculating all plot points: "); let val = calc::omnes(
let bar = &mut self.calc_cache,
indicatif::ProgressBar::new(u64::from(self.n_points)); x,
let res = x_values self.n_omnes,
.iter() self.use_tan_omnes,
.map(|&x| { ).abs().powi(2);
bar.inc(1); match self.scaling_type {
calc::omnes( ScalingType::Linear => {
&mut self.calc_cache, val
x, }
self.n_omnes, ScalingType::Logarithmic => {
self.use_tan_omnes, val.log10()
) }
.abs() }
.powi(2) }).collect();
})
.collect();
bar.finish();
res
} else {
x_values
.iter()
.map(|&x| {
calc::omnes(
&mut self.calc_cache,
x,
self.n_omnes,
self.use_tan_omnes,
)
.abs()
.powi(2)
.log10()
})
.collect()
};
self.plot_data.push(PlotCurve { self.plot_data.push(PlotCurve {
points: x_values points: x_values
.iter() .iter()
.zip(y_values_omnes.iter()) .zip(y_values.iter())
.map(|(&x, &y)| [x.powf(0.5), y]) .map(|(&x, &y)| [x, y])
.collect(), .collect(),
name: format!( name: format!(
"(#{}) Omnes, {} ot, n_o={}", "(#{}) Omnes, {} ot, n_o={}",
@ -318,7 +329,7 @@ impl eframe::App for App {
points: x_values points: x_values
.iter() .iter()
.zip(y_values_phi0.iter()) .zip(y_values_phi0.iter())
.map(|(&x, &y)| [x.powf(0.5), y]) .map(|(&x, &y)| [x, y])
.collect(), .collect(),
name: format!( name: format!(
"(#{}) phi0, {} ot, {} pt, {} ss, n_o={}, n_p={}", "(#{}) phi0, {} ot, {} pt, {} ss, n_o={}, n_p={}",
@ -333,10 +344,13 @@ impl eframe::App for App {
} }
3 => { 3 => {
let y_values_phi0: Vec<f64> = { let y_values_phi0: Vec<f64> = {
let bar =
indicatif::ProgressBar::new(u64::from(self.n_points));
let t0 = Instant::now();
x_values x_values
.iter() .iter()
.map(|&x| { .map(|&x| {
let val = calc::phi0( let val = calc::phi0(
&mut self.calc_cache, &mut self.calc_cache,
x, x,
self.n_omnes, self.n_omnes,
@ -352,7 +366,7 @@ impl eframe::App for App {
) / calc::delta_with_lut( ) / calc::delta_with_lut(
&mut self.calc_cache, &mut self.calc_cache,
x, x,
); ) - 1.0;
match self.scaling_type { match self.scaling_type {
ScalingType::Linear => { ScalingType::Linear => {
val val
@ -368,7 +382,7 @@ impl eframe::App for App {
points: x_values points: x_values
.iter() .iter()
.zip(y_values_phi0.iter()) .zip(y_values_phi0.iter())
.map(|(&x, &y)| [x.powf(0.5), y]) .map(|(&x, &y)| [x, y])
.collect(), .collect(),
name: format!( name: format!(
"(#{}) phi0 / delta, {} ot, {} pt, {} ss, n_o={}, n_p={}", "(#{}) phi0 / delta, {} ot, {} pt, {} ss, n_o={}, n_p={}",
@ -400,21 +414,52 @@ impl eframe::App for App {
points: x_values points: x_values
.iter() .iter()
.zip(y_values_func.iter()) .zip(y_values_func.iter())
.map(|(&x, &y)| [x.powf(0.5), y]) .map(|(&x, &y)| [x, y])
.collect(), .collect(),
name:"cont. polynomial".to_string() name:"cont. polynomial".to_string()
}); });
} }
5 => { 5 => {
let cutoff_factor = calc::omnes(&mut self.calc_cache, self.cutoff_s, self.n_omnes, self.use_tan_omnes) * self.cutoff_s;
println!("{:?}", cutoff_factor);
let y_values_func: Vec<f64> = x_values let y_values_func: Vec<f64> = x_values
.iter() .iter()
.map(|&x| { .map(|&x| {
let val = if self.use_tan_omnes {
calc::omnes_integrand_tan(&self.calc_cache, x, 1.2).abs()
} else {
calc::omnes_integrand_notan(&self.calc_cache, x, 1.2).abs()
};
match self.scaling_type {
ScalingType::Linear => {
val
}
ScalingType::Logarithmic => {
val.log10()
}
}
}).collect();
self.plot_data.push(PlotCurve {
points: x_values
.iter()
.zip(y_values_func.iter())
.map(|(&x, &y)| [x, y])
.collect(),
name: format!(
"(#{}) omnes integrand",
self.plot_data.len() + 1,
),
})
}
6 => {
let bar = indicatif::ProgressBar::new(u64::from(self.n_points));
let cutoff_factor = calc::omnes(&mut self.calc_cache, self.cutoff_s, self.n_omnes, self.use_tan_omnes) * self.cutoff_s;
let y_values_func: Vec<f64> = x_values
.iter()
.map(|&x| {
bar.inc(1);
let val = calc::phi0_integrand( let val = calc::phi0_integrand(
&mut self.calc_cache, &mut self.calc_cache,
x, x,
2.0, 1.0,
self.n_omnes, self.n_omnes,
self.use_tan_omnes, self.use_tan_omnes,
self.use_tan_phi0, self.use_tan_phi0,
@ -438,7 +483,7 @@ impl eframe::App for App {
points: x_values points: x_values
.iter() .iter()
.zip(y_values_func.iter()) .zip(y_values_func.iter())
.map(|(&x, &y)| [x.powf(0.5), y]) .map(|(&x, &y)| [x, y])
.collect(), .collect(),
name: format!( name: format!(
"(#{}) phi0 integrand", "(#{}) phi0 integrand",
@ -446,7 +491,7 @@ impl eframe::App for App {
), ),
}) })
} }
6 => { 7 => {
let bar = indicatif::ProgressBar::new(u64::from(self.n_points)); let bar = indicatif::ProgressBar::new(u64::from(self.n_points));
let y_values: Vec<f64> = let y_values: Vec<f64> =
x_values.iter().map(|&x| { x_values.iter().map(|&x| {
@ -492,7 +537,7 @@ impl eframe::App for App {
points: x_values points: x_values
.iter() .iter()
.zip(y_values.iter()) .zip(y_values.iter())
.map(|(&x, &y)| [x.powf(0.5), y]) .map(|(&x, &y)| [x, y])
.collect(), .collect(),
name: format!( name: format!(
"(#{}) phi0_cut / phi0, cutoff power: {}", "(#{}) phi0_cut / phi0, cutoff power: {}",
@ -501,7 +546,43 @@ impl eframe::App for App {
), ),
}); });
} }
7_usize.. => { 8 => {
let bar = indicatif::ProgressBar::new(u64::from(self.n_points));
let y_values_func: Vec<f64> = x_values.iter().map(|&x| {
bar.inc(1);
let val = calc::phi0(
&mut self.calc_cache,
x,
self.n_omnes,
self.n_phi0,
self.use_tan_omnes,
self.use_tan_phi0,
self.use_xsub_phi0,
self.use_reduced_integrand,
x == self.a,
self.use_cutoff,
self.cutoff_power,
self.cutoff_s
) / calc::delta_with_lut(&mut self.calc_cache, x);
match self.scaling_type {
ScalingType::Linear => {
val
}
ScalingType::Logarithmic => {
val.log10()
}
}
}).collect();
self.plot_data.push(PlotCurve {
points: x_values
.iter()
.zip(y_values_func.iter())
.map(|(&x, &y)| [x, y])
.collect(),
name:"cont. polynomial".to_string()
});
}
9_usize.. => {
panic!("This button has no assigned purpose!"); panic!("This button has no assigned purpose!");
} }
} }
@ -524,7 +605,7 @@ impl eframe::App for App {
let plot = Plot::new("my_plot") let plot = Plot::new("my_plot")
.grid_spacing(5.0f32..=300.0f32) .grid_spacing(5.0f32..=300.0f32)
.x_axis_label("sqrt(s) [GeV]") .x_axis_label("s [GeV^2]")
.legend(Legend::default()); .legend(Legend::default());
let plot = match self.scaling_type { let plot = match self.scaling_type {
@ -545,7 +626,7 @@ impl eframe::App for App {
if v.value - v.value.floor() < 0.9 { if v.value - v.value.floor() < 0.9 {
log_gridmarks.push(GridMark { log_gridmarks.push(GridMark {
value: log_map(v.value), value: log_map(v.value),
step_size: v.step_size / 1.14, step_size: v.step_size / 1.14, // This value just looks best
}); });
} }
} }
@ -563,7 +644,7 @@ impl eframe::App for App {
plot_ui.line( plot_ui.line(
Line::new(self.plot_data[i].points.clone()) Line::new(self.plot_data[i].points.clone())
.name(self.plot_data[i].name.clone()), .name(self.plot_data[i].name.clone()),
); // is clone necessary? );
} }
}); });
}); });
@ -574,6 +655,7 @@ impl eframe::App for App {
fn main() { fn main() {
let mut app = App::default(); let mut app = App::default();
app.calc_cache = calc::Cache::from_file("./gauss_quad_lut.morello").unwrap(); app.calc_cache = calc::Cache::from_file("./gauss_quad_lut.morello").unwrap();
println!("{}", (2.0 * calc::M_K).powi(2));
// let x_values: Vec<f64> = (0..app.n_points) // let x_values: Vec<f64> = (0..app.n_points)
// .map(|x| -> f64 { f64::from(x) * ((app.b - app.a) / f64::from(app.n_points)) + app.a }) // .map(|x| -> f64 { f64::from(x) * ((app.b - app.a) / f64::from(app.n_points)) + app.a })
@ -603,19 +685,30 @@ fn main() {
// for (o,n_o) in accuracies.iter().enumerate() { // for (o,n_o) in accuracies.iter().enumerate() {
// println!("{:?}", n_o); // println!("{:?}", n_o);
// for (p,n_p) in accuracies.iter().enumerate() { // for (p,n_p) in accuracies.iter().enumerate() {
// let phi0 = calc::phi0(&mut app.calc_cache, 10000.0, *n_o, *n_p , true, true, true, true, true, false, 0.0, 0.0); // let phi0 = calc::phi0(&mut app.calc_cache, 10000.0, *n_o, *n_p , true, true, true, false, true, false, 0.0, 0.0);
// results[o][p] = phi0 / calc::delta(10000.0) - 1.0; // results[o][p] = phi0 / calc::delta(10000.0) - 1.0;
// } // }
// } // }
// println!("{:#?}", results); // println!("{:#?}", results);
let phi0 = calc::phi0(&mut app.calc_cache, 10000.0, 1000, 1000, true, true, true, true, true, false, 0.0, 0.0); let phi0 = calc::phi0(&mut app.calc_cache, 2.0158, 100, 100, true, true, true, false, true, false, 0.0, 0.0);
println!("relative difference: {:e}", phi0 / calc::delta(10000.0) - 1.0); println!("relative difference: {:e}", phi0 / calc::delta_with_lut(&mut app.calc_cache, 2.0158) - 1.0);
// let A = 1.42;
// let numerator = 4.0*A*A*calc::M_K * (calc::delta_with_lut(&mut app.calc_cache, A*A) - PI);
// let denominator = calc::LAMBDA1 + 2.0*calc::LAMBDA2 * (0.5*A/calc::M_K - 1.0);
// println!("{:?}", - numerator / denominator - A*A);
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([1500 as f32, 1000 as f32]),
default_theme: Theme::Dark,
..Default::default()
};
// eframe::run_native( // eframe::run_native(
// "Omnes Calculator", // "Omnes Calculator",
// eframe::NativeOptions::default(), // options,
// Box::new(|_cc| Box::new(app)), // Box::new(|_cc| Box::new(app)),
// ) // )
// .unwrap(); // .unwrap();