From da8f3f08cbcfdf02ccbf737e0fb28c531b850bcf Mon Sep 17 00:00:00 2001 From: Udo Eisenbarth <u.eisenbarth@gsi.de> Date: Fri, 11 Oct 2024 15:46:28 +0200 Subject: [PATCH] Fixed switched axis labels for HitMap. Fixed some missing statements in ghost focus analysis for Wedge. Add Wedge to ghot_focus example. --- opossum/examples/ghost_focus.rs | 23 +++++++++++++++++++---- opossum/src/nodes/lens/mod.rs | 1 - opossum/src/nodes/wedge/mod.rs | 20 +++++++++++++++++--- opossum/src/surface/hit_map.rs | 4 ++-- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/opossum/examples/ghost_focus.rs b/opossum/examples/ghost_focus.rs index ca439816..dd856e5f 100644 --- a/opossum/examples/ghost_focus.rs +++ b/opossum/examples/ghost_focus.rs @@ -1,11 +1,13 @@ use opossum::{ analyzers::{AnalyzerType, GhostFocusConfig}, coatings::CoatingType, + degree, error::OpmResult, joule, millimeter, - nodes::{round_collimated_ray_source, Lens, NodeGroup, SpotDiagram}, - optic_node::OpticNode, + nodes::{round_collimated_ray_source, Lens, NodeGroup, SpotDiagram, Wedge}, + optic_node::{Alignable, OpticNode}, optic_ports::PortType, + refractive_index::RefrIndexConst, OpmDocument, }; use std::path::Path; @@ -33,14 +35,27 @@ fn main() -> OpmResult<()> { lens.set_coating(&PortType::Input, "front", &CoatingType::Fresnel)?; lens.set_coating(&PortType::Output, "rear", &CoatingType::Fresnel)?; let i_l = scenery.add_node(lens)?; + + let mut wedge = Wedge::new( + "wedge", + millimeter!(20.0), + degree!(10.0), + &RefrIndexConst::new(1.5)?, + )? + .with_tilt(degree!(0.0, 5.0, 0.0))?; + wedge.set_coating(&PortType::Input, "front", &CoatingType::Fresnel)?; + wedge.set_coating(&PortType::Input, "front", &CoatingType::Fresnel)?; + let i_w=scenery.add_node(wedge)?; + let i_sd2 = scenery.add_node(SpotDiagram::default())?; scenery.connect_nodes(i_src, "out1", i_sd, "in1", millimeter!(20.0))?; scenery.connect_nodes(i_sd, "out1", i_l, "front", millimeter!(80.0))?; - scenery.connect_nodes(i_l, "rear", i_sd2, "in1", millimeter!(70.0))?; + scenery.connect_nodes(i_l, "rear", i_w, "front", millimeter!(70.0))?; + scenery.connect_nodes(i_w, "rear", i_sd2, "in1", millimeter!(70.0))?; let mut doc = OpmDocument::new(scenery); let mut config = GhostFocusConfig::default(); - config.set_max_bounces(2); + config.set_max_bounces(1); doc.add_analyzer(AnalyzerType::GhostFocus(config)); doc.save_to_file(Path::new("./opossum/playground/ghost_focus.opm")) } diff --git a/opossum/src/nodes/lens/mod.rs b/opossum/src/nodes/lens/mod.rs index 06895c81..899a0759 100644 --- a/opossum/src/nodes/lens/mod.rs +++ b/opossum/src/nodes/lens/mod.rs @@ -358,7 +358,6 @@ impl Lens { let reflected_front = rays.refract_on_surface(&mut self.front_surf, Some(&ambient_idx))?; self.front_surf.set_forward_rays_cache(reflected_front); rays.merge(self.front_surf.backwards_rays_cache()); - if let Some(aperture) = self.ports().aperture(&PortType::Input, "rear") { rays.apodize(aperture)?; if let AnalyzerType::RayTrace(config) = analyzer_type { diff --git a/opossum/src/nodes/wedge/mod.rs b/opossum/src/nodes/wedge/mod.rs index 5468f82a..996d708d 100644 --- a/opossum/src/nodes/wedge/mod.rs +++ b/opossum/src/nodes/wedge/mod.rs @@ -72,6 +72,7 @@ impl Default for Wedge { .create_property("wedge", "wedge angle", None, Angle::zero().into()) .unwrap(); let mut ports = OpticPorts::new(); + ports.add(&PortType::Input, "front").unwrap(); ports.add(&PortType::Output, "rear").unwrap(); node_attr.set_ports(ports); @@ -192,6 +193,13 @@ impl Wedge { let ambient_idx = self.ambient_idx(); let mut rays = incoming_rays; self.front_surf.set_isometry(iso); + self.front_surf.set_coating( + self.node_attr() + .ports() + .coating(&PortType::Input, "front") + .unwrap() + .clone(), + ); let thickness_iso = Isometry::new_along_z(thickness)?; let wedge_iso = Isometry::new( Point3::origin(), @@ -199,7 +207,14 @@ impl Wedge { )?; let isometry = iso.append(&thickness_iso).append(&wedge_iso); self.rear_surf.set_isometry(&isometry); - if let Some(aperture) = self.ports().aperture(&PortType::Input, "rear") { + self.rear_surf.set_coating( + self.node_attr() + .ports() + .coating(&PortType::Output, "rear") + .unwrap() + .clone(), + ); + if let Some(aperture) = self.ports().aperture(&PortType::Output, "front") { rays.apodize(aperture)?; if let AnalyzerType::RayTrace(config) = analyzer_type { rays.invalidate_by_threshold_energy(config.min_energy_per_ray())?; @@ -211,11 +226,10 @@ impl Wedge { self.rear_surf.set_forward_rays_cache(reflected_rear); rays.merge(self.rear_surf.backwards_rays_cache()); rays.set_refractive_index(refri)?; - let reflected_front = rays.refract_on_surface(&mut self.front_surf, Some(&ambient_idx))?; self.front_surf.set_forward_rays_cache(reflected_front); rays.merge(self.front_surf.backwards_rays_cache()); - if let Some(aperture) = self.ports().aperture(&PortType::Output, "front") { + if let Some(aperture) = self.ports().aperture(&PortType::Input, "rear") { rays.apodize(aperture)?; if let AnalyzerType::RayTrace(config) = analyzer_type { rays.invalidate_by_threshold_energy(config.min_energy_per_ray())?; diff --git a/opossum/src/surface/hit_map.rs b/opossum/src/surface/hit_map.rs index 6e9ce2aa..b889f555 100644 --- a/opossum/src/surface/hit_map.rs +++ b/opossum/src/surface/hit_map.rs @@ -82,8 +82,8 @@ impl Plottable for HitMap { let y_prefix = get_prefix_for_base_unit(y_max); let x_prefix = get_prefix_for_base_unit(x_max); - plt_type.set_plot_param(&PlotArgs::YLabel(format!("x position ({y_prefix}m)")))?; - plt_type.set_plot_param(&PlotArgs::XLabel(format!("y position ({x_prefix}m)")))?; + plt_type.set_plot_param(&PlotArgs::XLabel(format!("x position ({y_prefix}m)")))?; + plt_type.set_plot_param(&PlotArgs::YLabel(format!("y position ({x_prefix}m)")))?; let mut plt_series = Vec::<PlotSeries>::with_capacity(1); let x_vals = xy_pos -- GitLab