This commit is contained in:
Jan Bergen 2024-08-03 17:11:38 +02:00
parent 1dbfafc999
commit 3285ae0b74
6 changed files with 28 additions and 9 deletions

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Binary file not shown.

View File

@ -32,6 +32,7 @@ pub struct Cache {
HashMap<u64, Complex, nohash_hasher::BuildNoHashHasher<u64>>,
nohash_hasher::BuildNoHashHasher<u32>,
>, // First key is n, second is s
pub tan_lut: HashMap<u64, f64, nohash_hasher::BuildNoHashHasher<u64>>
}
// pub struct Cache {
@ -67,6 +68,7 @@ impl Cache {
.collect(),
delta_lut: HashMap::with_hasher(Default::default()),
omnes_lut: HashMap::with_hasher(Default::default()),
tan_lut: HashMap::with_hasher(Default::default()),
};
Ok(me)
}
@ -86,6 +88,7 @@ impl Cache {
.collect(),
delta_lut: HashMap::with_hasher(Default::default()),
omnes_lut: HashMap::with_hasher(Default::default()),
tan_lut: HashMap::with_hasher(Default::default()),
};
Ok(me)
}
@ -101,6 +104,21 @@ fn delta_mid_cutoff() -> f64 {
delta(S_MID_CUTOFF)
}
fn tan_with_lut(cache: &mut Cache, s: f64) -> f64 {
// match cache.tan_lut.get(&s.to_bits()) {
// Some(val) => {
// println!("tan reused");
// *val
// }
// None => {
// let val = s.tan();
// cache.tan_lut.insert(s.to_bits(), val);
// val
// }
// }
s.tan()
}
fn atan_shift(x: f64) -> f64 {
let atan_std: f64 = x.atan();
if atan_std < 0.0 {
@ -199,7 +217,7 @@ pub fn delta(s: f64) -> f64 {
}
pub fn omnes_integrand_tan(cache: &mut Cache, s_tick: f64, s: f64) -> Complex {
let sub = s_tick.tan();
let sub = tan_with_lut(cache, s_tick);
(delta_with_lut(cache, sub) - delta_with_lut(cache, s))
/ (sub * (sub - s + Complex::new(0.0, EPSILON)) * s_tick.cos().powi(2))
}
@ -278,8 +296,8 @@ pub fn phi0_integrand(
cutoff_factor: Complex,
) -> f64 {
let sub = match (use_tan_phi0, use_xsub) {
(true, true) => s_tick.tan().powi(2) + S0,
(true, false) => s_tick.tan(),
(true, true) => tan_with_lut(cache, s_tick).powi(2) + S0,
(true, false) => tan_with_lut(cache, s_tick),
(false, true) => s_tick.powi(2) + S0,
(false, false) => s_tick,
};

View File

@ -595,8 +595,9 @@ fn main() {
// })
// .collect();
let phi0 = calc::phi0(&mut app.calc_cache, 10000.0, 10000, 10000, true, true, true, true, true, false, 0.0, 0.0);
let phi0 = calc::phi0(&mut app.calc_cache, 10000.0, 15000, 15000, true, true, true, true, true, false, 0.0, 0.0);
println!("relative difference: {}", phi0 / calc::delta(10000.0) - 1.0);
println!("{:?}", app.calc_cache.tan_lut.len());
// eframe::run_native(
// "Omnes Calculator",

View File

@ -195,7 +195,7 @@ def phi0(s, a=0, inf = 100000, optimized = True, n = gl_n_phi0):
c = np.pi / (s * np.sqrt(s_0)) * np.log(cmath.polar(omnes(s))[0]**2)
if optimized == True:
integral = integral_gl_tan_reparam(phi0_integrand, s, a, inf, n, False)
integral = integral_gl_tan_reparam(phi0_integrand, s, a, inf, n, True)
else:
integral = integral_gl(phi0_integrand, s, a, inf, n)
return -s * np.sqrt(s-s_0) / (2*np.pi) * (integral - c)
@ -269,7 +269,7 @@ ax.plot(x, y_delta, label = r"$\delta$")
# print(time() - t0)
t0 = time()
print(phi0(10000, n=100))
print(phi0(10000, n=15000) / delta(10000))
print(time() - t0)
# ax.legend()
@ -277,4 +277,4 @@ print(time() - t0)
# ax.grid(which='major', color='#A4A4A4', linewidth=1)
# ax.grid(which='minor', color='#B5B5B5', linestyle=':', linewidth=0.5)
# ax.minorticks_on()
# plt.show()
# plt.show()