Skip to content
Snippets Groups Projects
Commit d5895a03 authored by Udo Eisenbarth's avatar Udo Eisenbarth :speech_balloon:
Browse files

Reenable lens_test example

parent 73df6085
No related branches found
No related tags found
No related merge requests found
// use opossum::{Detector, use opossum::nodes::{RealLens, Source};
// optic_scenery::OpticScenery use opossum::{nodes::Detector, optic_scenery::OpticScenery};
// }; use std::fs::File;
// use std::io::Write; use std::io::Write;
use opossum::error::OpossumError; use opossum::error::OpossumError;
fn main() -> Result<(), OpossumError> { fn main() -> Result<(), OpossumError> {
// let mut scenery = OpticScenery::new(); let mut scenery = OpticScenery::new();
// scenery.set_description("Lens Ray-trace test".into()); scenery.set_description("Lens Ray-trace test".into());
// let src = scenery.add_element("Source", Source::default()); let src = scenery.add_element("Source", Source::default());
// let l1 = scenery.add_element("Lens 1", RealLens::default()); let l1 = scenery.add_element("Lens 1", RealLens::default());
// let l2 = scenery.add_element("Lens 2", RealLens::default()); let l2 = scenery.add_element("Lens 2", RealLens::default());
// let det=scenery.add_element("Detector", Detector::default()); let det = scenery.add_element("Detector", Detector::default());
// scenery.connect_nodes(src, "out1", l1, "in1")?; scenery.connect_nodes(src, "out1", l1, "in1")?;
// scenery.connect_nodes(l1, "out1", l2, "in1")?; scenery.connect_nodes(l1, "out1", l2, "in1")?;
// scenery.connect_nodes(l2, "out1", det, "in1")?; scenery.connect_nodes(l2, "out1", det, "in1")?;
// let path = "lens_system.dot"; let path = "lens_system.dot";
// let mut output = File::create(path).unwrap(); let mut output = File::create(path).unwrap();
// write!(output, "{}", scenery.to_dot()).unwrap(); write!(output, "{}", scenery.to_dot()).unwrap();
Ok(()) Ok(())
} }
...@@ -19,4 +19,5 @@ impl AnalyzerEnergy { ...@@ -19,4 +19,5 @@ impl AnalyzerEnergy {
pub enum AnalyzerType { pub enum AnalyzerType {
Energy, Energy,
ParAxialRayTrace,
} }
...@@ -114,6 +114,11 @@ impl Optical for BeamSplitter { ...@@ -114,6 +114,11 @@ impl Optical for BeamSplitter {
) -> Result<LightResult> { ) -> Result<LightResult> {
match analyzer_type { match analyzer_type {
AnalyzerType::Energy => self.analyze_energy(incoming_data), AnalyzerType::Energy => self.analyze_energy(incoming_data),
_ => {
return Err(OpossumError::Analysis(
"analysis type not yet implemented".into(),
))
}
} }
} }
} }
......
...@@ -128,6 +128,11 @@ impl Optical for IdealFilter { ...@@ -128,6 +128,11 @@ impl Optical for IdealFilter {
) -> Result<crate::optic_node::LightResult> { ) -> Result<crate::optic_node::LightResult> {
match analyzer_type { match analyzer_type {
AnalyzerType::Energy => self.analyze_energy(incoming_data), AnalyzerType::Energy => self.analyze_energy(incoming_data),
_ => {
return Err(OpossumError::Analysis(
"analysis type not yet implemented".into(),
))
}
} }
} }
} }
......
use std::collections::HashMap;
use uom::{si::f64::{Energy, Length}, si::length::meter, num_traits::Zero};
use ndarray::{Array1, Array2, array};
type Result<T> = std::result::Result<T, OpossumError>;
use crate::{ use crate::{
analyzer::AnalyzerType, analyzer::AnalyzerType,
error::OpossumError, error::OpossumError,
lightdata::{LightData, DataEnergy, RayDataParaxial}, lightdata::LightData,
optic_node::{Dottable, LightResult, Optical}, optic_node::{Dottable, LightResult, Optical},
optic_ports::OpticPorts, optic_ports::OpticPorts,
}; };
use ndarray::{array, Array1};
use uom::{si::f64::Length, si::length::meter};
type Result<T> = std::result::Result<T, OpossumError>;
pub struct IdealLens;
pub struct IdealLens {
focal_length: f64,
aperture: f64
}
#[derive(Debug)] #[derive(Debug)]
pub struct RealLens { pub struct RealLens {
aperture: Length, aperture: Length,
curvatures: Array1<Length>, curvatures: Array1<Length>,
center_thickness: Length, center_thickness: Length,
z_pos: Length, z_pos: Length,
refractive_index: f64, refractive_index: f64,
} }
impl RealLens { impl RealLens {
pub fn new(aperture: Length, front_curvature: Length, rear_curvature: Length, center_thickness: Length, z_pos: Length, refractive_index: f64) -> Self { pub fn new(
Self{ aperture: aperture, aperture: Length,
curvatures: array![front_curvature,rear_curvature], front_curvature: Length,
center_thickness: center_thickness, rear_curvature: Length,
z_pos: z_pos, center_thickness: Length,
refractive_index: refractive_index, z_pos: Length,
refractive_index: f64,
) -> Self {
Self {
aperture: aperture,
curvatures: array![front_curvature, rear_curvature],
center_thickness: center_thickness,
z_pos: z_pos,
refractive_index: refractive_index,
} }
} }
pub fn get_aperture(&self) -> Length{ pub fn get_aperture(&self) -> Length {
self.aperture self.aperture
} }
...@@ -45,15 +46,18 @@ impl RealLens { ...@@ -45,15 +46,18 @@ impl RealLens {
self.aperture = Length::new::<meter>(aperture); self.aperture = Length::new::<meter>(aperture);
} }
pub fn get_curvatures(&self) -> &Array1<Length>{ pub fn get_curvatures(&self) -> &Array1<Length> {
&self.curvatures &self.curvatures
} }
pub fn set_curvatures(&mut self, curvature_1: f64, curvature_2: f64) { pub fn set_curvatures(&mut self, curvature_1: f64, curvature_2: f64) {
self.curvatures = array![Length::new::<meter>(curvature_1),Length::new::<meter>(curvature_2)]; self.curvatures = array![
Length::new::<meter>(curvature_1),
Length::new::<meter>(curvature_2)
];
} }
pub fn get_thickness(&self) -> Length{ pub fn get_thickness(&self) -> Length {
self.center_thickness self.center_thickness
} }
...@@ -61,7 +65,7 @@ impl RealLens { ...@@ -61,7 +65,7 @@ impl RealLens {
self.center_thickness = Length::new::<meter>(thickness); self.center_thickness = Length::new::<meter>(thickness);
} }
pub fn get_position(&self) -> Length{ pub fn get_position(&self) -> Length {
self.z_pos self.z_pos
} }
...@@ -69,7 +73,7 @@ impl RealLens { ...@@ -69,7 +73,7 @@ impl RealLens {
self.z_pos = Length::new::<meter>(position); self.z_pos = Length::new::<meter>(position);
} }
pub fn get_refractve_index(&self) -> f64{ pub fn get_refractve_index(&self) -> f64 {
self.refractive_index self.refractive_index
} }
...@@ -78,7 +82,7 @@ impl RealLens { ...@@ -78,7 +82,7 @@ impl RealLens {
} }
fn analyze_ray_trace(&mut self, incoming_data: LightResult) -> Result<LightResult> { fn analyze_ray_trace(&mut self, incoming_data: LightResult) -> Result<LightResult> {
let in1: Option<&Option<LightData>> = incoming_data.get("in1"); let _in1: Option<&Option<LightData>> = incoming_data.get("in1");
Ok(incoming_data) Ok(incoming_data)
// let mut in_rays: Vec<RayDataParaxial> = Vec::new(); // let mut in_rays: Vec<RayDataParaxial> = Vec::new();
...@@ -112,17 +116,21 @@ impl RealLens { ...@@ -112,17 +116,21 @@ impl RealLens {
// bounce_lvl: usize, // bounce_lvl: usize,
// max_bounces: usize, // max_bounces: usize,
// } // }
} }
impl Default for RealLens { impl Default for RealLens {
/// Create a 100mm focal lengths lens. LA1251-B from thorlabs. refractive inde hardcoded for n-bk7 at 1054 nm /// Create a 100mm focal lengths lens. LA1251-B from thorlabs. refractive inde hardcoded for n-bk7 at 1054 nm
fn default() -> Self { fn default() -> Self {
Self { aperture: Length::new::<meter>(25e-3), Self {
curvatures: array![Length::new::<meter>(51.5e-3),Length::new::<meter>(f64::INFINITY)], aperture: Length::new::<meter>(25e-3),
center_thickness: Length::new::<meter>(3.6e-3), curvatures: array![
z_pos: Length::new::<meter>(0.0), Length::new::<meter>(51.5e-3),
refractive_index: 1.5068} Length::new::<meter>(f64::INFINITY)
],
center_thickness: Length::new::<meter>(3.6e-3),
z_pos: Length::new::<meter>(0.0),
refractive_index: 1.5068,
}
} }
} }
...@@ -137,15 +145,20 @@ impl Optical for RealLens { ...@@ -137,15 +145,20 @@ impl Optical for RealLens {
ports ports
} }
fn analyze(&mut self, incoming_data: LightResult, analyzer_type: &AnalyzerType) -> Result<LightResult> { fn analyze(
&mut self,
incoming_data: LightResult,
analyzer_type: &AnalyzerType,
) -> Result<LightResult> {
match analyzer_type { match analyzer_type {
AnalyzerType::Energy => Err(OpossumError::Analysis("Energy Analysis is not yet implemented for Lens Nodes".into())), AnalyzerType::Energy => Err(OpossumError::Analysis(
"Energy Analysis is not yet implemented for Lens Nodes".into(),
)),
AnalyzerType::ParAxialRayTrace => self.analyze_ray_trace(incoming_data), AnalyzerType::ParAxialRayTrace => self.analyze_ray_trace(incoming_data),
} }
} }
} }
impl Dottable for RealLens { impl Dottable for RealLens {
fn node_color(&self) -> &str { fn node_color(&self) -> &str {
"blue" "blue"
......
...@@ -4,6 +4,7 @@ mod detector; ...@@ -4,6 +4,7 @@ mod detector;
mod dummy; mod dummy;
mod group; mod group;
mod ideal_filter; mod ideal_filter;
mod lens;
mod reference; mod reference;
mod source; mod source;
...@@ -11,7 +12,7 @@ pub use beam_splitter::BeamSplitter; ...@@ -11,7 +12,7 @@ pub use beam_splitter::BeamSplitter;
pub use detector::Detector; pub use detector::Detector;
pub use dummy::Dummy; pub use dummy::Dummy;
pub use group::NodeGroup; pub use group::NodeGroup;
pub use ideal_filter::FilterType; pub use ideal_filter::{FilterType, IdealFilter};
pub use ideal_filter::IdealFilter; pub use lens::{IdealLens, RealLens};
pub use reference::NodeReference; pub use reference::NodeReference;
pub use source::Source; pub use source::Source;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment