Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
trappitsch committed Mar 15, 2024
1 parent 4ec2927 commit 2e45d8a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
15 changes: 5 additions & 10 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub struct XtalCalculatorApp {
crystal: String,
angle: f32,
walkoff: f32,

}

impl Default for XtalCalculatorApp {
Expand Down Expand Up @@ -63,7 +62,9 @@ impl eframe::App for XtalCalculatorApp {

egui::CentralPanel::default().show(ctx, |ui| {
// The central panel the region left after adding TopPanel's and SidePanel's
ui.heading(RichText::new("Ti:Sapphire Harmonic Generation Crystal Calculator").strong());
ui.heading(
RichText::new("Ti:Sapphire Harmonic Generation Crystal Calculator").strong(),
);
ui.add_space(VERTICAL_SPACE);

ui.label(INTRO_MESSAGE);
Expand All @@ -87,7 +88,6 @@ impl eframe::App for XtalCalculatorApp {

ui.label("Select Harmonic: ");


ui.horizontal(|ui| {
ui.radio_value(&mut self.harmonic, Harmonic::Second, "Second");
ui.radio_value(&mut self.harmonic, Harmonic::Third, "Third");
Expand Down Expand Up @@ -115,12 +115,9 @@ impl eframe::App for XtalCalculatorApp {
ui.label(format!("{:.2}mrad", self.walkoff));
});


ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
powered_by_egui_and_eframe(ui);
ui.hyperlink_to("Source code.",
"https://github.com/RIMS-Code/crystal_angle",
);
ui.hyperlink_to("Source code.", "https://github.com/RIMS-Code/crystal_angle");
egui::warn_if_debug_build(ui);
});
});
Expand All @@ -132,7 +129,6 @@ impl eframe::App for XtalCalculatorApp {
}
}


fn powered_by_egui_and_eframe(ui: &mut egui::Ui) {
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 0.0;
Expand Down Expand Up @@ -161,10 +157,9 @@ Next select from the radio buttons if you want to generate a second or third har

const VERTICAL_SPACE: f32 = 12.0;


fn which_crystal(harmonic: &Harmonic) -> &'static str {
match harmonic {
Harmonic::Second => "LBO",
Harmonic::Third => "BBO",
}
}
}
55 changes: 36 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,58 +7,75 @@ pub use app::XtalCalculatorApp;
use enterpolation::linear::Linear;
use enterpolation::Generator;

#[derive(PartialEq)]
#[derive(serde::Deserialize, serde::Serialize)]
pub enum Harmonic { Second, Third }
#[derive(PartialEq, serde::Deserialize, serde::Serialize)]
pub enum Harmonic {
Second,
Third,
}

struct CrystalData {
wavelengths: Vec<f32>,
angles: Vec<f32>,
walkoffs: Vec<f32>,
}




pub fn calculate_angle_walkoff(wavelength: f32, harmonic: &Harmonic) -> (f32, f32) {

let second_harmonic_lbo: CrystalData = CrystalData {
wavelengths: vec![
700.0, 710.0, 720.0, 730.0, 740.0, 750.0, 760.0, 770.0, 780.0, 790.0, 800.0, 810.0, 820.0, 830.0, 840.0, 850.0, 860.0, 870.0, 880.0, 890.0, 900.0, 910.0, 920.0, 930.0, 940.0, 950.0, 960.0, 970.0, 980.0, 990.0, 1000.0,
700.0, 710.0, 720.0, 730.0, 740.0, 750.0, 760.0, 770.0, 780.0, 790.0, 800.0, 810.0,
820.0, 830.0, 840.0, 850.0, 860.0, 870.0, 880.0, 890.0, 900.0, 910.0, 920.0, 930.0,
940.0, 950.0, 960.0, 970.0, 980.0, 990.0, 1000.0,
],
angles: vec![
43.4, 42.0, 40.7, 39.4, 38.2, 37.0, 35.9, 34.7, 33.7, 32.6, 31.6, 30.7, 29.7, 28.8, 27.9, 27.0, 26.1, 25.3, 24.4, 23.6, 22.8, 22.0, 21.3, 20.5, 19.8, 19.0, 18.3, 17.6, 16.9, 16.2, 15.6,
43.4, 42.0, 40.7, 39.4, 38.2, 37.0, 35.9, 34.7, 33.7, 32.6, 31.6, 30.7, 29.7, 28.8,
27.9, 27.0, 26.1, 25.3, 24.4, 23.6, 22.8, 22.0, 21.3, 20.5, 19.8, 19.0, 18.3, 17.6,
16.9, 16.2, 15.6,
],
walkoffs: vec![
18.83, 18.71, 18.55, 18.36, 18.15, 17.91, 17.66, 17.38, 17.1, 16.79, 16.48, 16.16, 15.83, 15.49, 15.15, 14.8, 14.44, 14.08, 13.72, 13.36, 12.99, 12.62, 12.25, 11.88, 11.51, 11.14, 10.77, 10.39, 10.02, 9.65, 9.27,
18.83, 18.71, 18.55, 18.36, 18.15, 17.91, 17.66, 17.38, 17.1, 16.79, 16.48, 16.16,
15.83, 15.49, 15.15, 14.8, 14.44, 14.08, 13.72, 13.36, 12.99, 12.62, 12.25, 11.88,
11.51, 11.14, 10.77, 10.39, 10.02, 9.65, 9.27,
],
};

let third_harmonic_bbo: CrystalData = CrystalData {
wavelengths: vec![
700.0, 710.0, 720.0, 730.0, 740.0, 750.0, 760.0, 770.0, 780.0, 790.0, 800.0, 810.0, 820.0, 830.0, 840.0, 850.0, 860.0, 870.0, 880.0, 890.0, 900.0, 910.0, 920.0, 930.0, 940.0, 950.0, 960.0, 970.0, 980.0, 990.0, 1000.0,
700.0, 710.0, 720.0, 730.0, 740.0, 750.0, 760.0, 770.0, 780.0, 790.0, 800.0, 810.0,
820.0, 830.0, 840.0, 850.0, 860.0, 870.0, 880.0, 890.0, 900.0, 910.0, 920.0, 930.0,
940.0, 950.0, 960.0, 970.0, 980.0, 990.0, 1000.0,
],
angles: vec![
53.3, 53.0, 51.8, 50.7, 49.6, 48.6, 47.7, 46.8, 45.9, 45.1, 44.3, 43.5, 42.8, 42.1, 41.5, 40.8, 40.2, 39.6, 39.1, 38.5, 38.0, 37.5, 37.0, 36.5, 36.0, 35.6, 35.2, 34.7, 34.3, 33.9, 33.5
53.3, 53.0, 51.8, 50.7, 49.6, 48.6, 47.7, 46.8, 45.9, 45.1, 44.3, 43.5, 42.8, 42.1,
41.5, 40.8, 40.2, 39.6, 39.1, 38.5, 38.0, 37.5, 37.0, 36.5, 36.0, 35.6, 35.2, 34.7,
34.3, 33.9, 33.5,
],
walkoffs: vec![
85.81, 86.52, 87.01, 87.32, 87.48, 87.52, 87.45, 87.3, 87.06, 86.77, 86.42, 86.03, 85.6, 85.14, 84.66, 84.15, 83.62, 83.09, 82.54, 81.98, 81.41, 80.84, 80.27, 79.7, 79.12, 78.55, 77.98, 77.41, 76.85, 76.29, 75.73
85.81, 86.52, 87.01, 87.32, 87.48, 87.52, 87.45, 87.3, 87.06, 86.77, 86.42, 86.03,
85.6, 85.14, 84.66, 84.15, 83.62, 83.09, 82.54, 81.98, 81.41, 80.84, 80.27, 79.7,
79.12, 78.55, 77.98, 77.41, 76.85, 76.29, 75.73,
],
};

let (wl_dat, ang_dat, wo_dat) = match harmonic {
Harmonic::Second => (second_harmonic_lbo.wavelengths, second_harmonic_lbo.angles, second_harmonic_lbo.walkoffs),
Harmonic::Third => (third_harmonic_bbo.wavelengths, third_harmonic_bbo.angles, third_harmonic_bbo.walkoffs),
Harmonic::Second => (
second_harmonic_lbo.wavelengths,
second_harmonic_lbo.angles,
second_harmonic_lbo.walkoffs,
),
Harmonic::Third => (
third_harmonic_bbo.wavelengths,
third_harmonic_bbo.angles,
third_harmonic_bbo.walkoffs,
),
};


let angle = interpolate(wl_dat.clone(), ang_dat, vec![wavelength])[0];
let walkoff = interpolate(wl_dat, wo_dat, vec![wavelength])[0];

(angle, walkoff)
}

fn interpolate(xs: Vec<f32>, ys: Vec<f32>, out_xs: Vec<f32>) -> Vec<f32> {
let linear = Linear::builder().elements(ys).knots(xs).build().unwrap();
linear.sample(out_xs).collect()
}
}

0 comments on commit 2e45d8a

Please sign in to comment.