diff --git a/opossum/examples/apodization.rs b/opossum/examples/apodization.rs index 47e26e21c751038d56bb6708aa6ab387ff4cf5e6..7a59764b8bc1001cf640b4c9306f01f692f0b391 100644 --- a/opossum/examples/apodization.rs +++ b/opossum/examples/apodization.rs @@ -2,7 +2,7 @@ use std::path::Path; use opossum::{ analyzers::{AnalyzerType, RayTraceConfig}, - aperture::{Aperture, PolygonConfig, RectangleConfig}, + aperture::{Aperture, RectangleConfig}, error::OpmResult, joule, millimeter, nodes::{round_collimated_ray_source, Dummy, NodeGroup, SpotDiagram}, @@ -19,13 +19,6 @@ fn main() -> OpmResult<()> { joule!(1.0), 25, )?)?; - let poly = PolygonConfig::new(vec![ - millimeter!(-1.0, 0.0), - millimeter!(0.0, 0.5), - millimeter!(1.0, 0.0), - millimeter!(0.0, 1.0), - ]) - .unwrap(); let mut dummy = Dummy::default(); let rect_config = diff --git a/opossum/examples/grating_examples/folded_martinez.rs b/opossum/examples/grating_examples/folded_martinez.rs index 4bd5e91e5e8219ff53a8f2b965a8407888616948..d648c4f8052998cc95a35041357d59b0fc41e0a9 100644 --- a/opossum/examples/grating_examples/folded_martinez.rs +++ b/opossum/examples/grating_examples/folded_martinez.rs @@ -2,7 +2,7 @@ use opossum::{ centimeter, degree, error::OpmResult, millimeter, - nodes::{Dummy, Lens, NodeGroup, NodeReference, ReflectiveGrating, ThinMirror}, + nodes::{Lens, NodeGroup, NodeReference, ReflectiveGrating, ThinMirror}, num_per_mm, optic_node::{Alignable, OpticNode}, refractive_index::RefractiveIndex, diff --git a/opossum/files_for_testing/dot/to_dot_empty_LR.dot b/opossum/files_for_testing/dot/to_dot_empty_LR.dot index 44ce92d3e5ce5c28f53d995597f6efcad5b87746..4a699f313d0d1e2b06339c47064cd63ae9b609dc 100644 --- a/opossum/files_for_testing/dot/to_dot_empty_LR.dot +++ b/opossum/files_for_testing/dot/to_dot_empty_LR.dot @@ -1,10 +1,10 @@ digraph { - fontsize = 8; + fontsize = 10; compound = true; rankdir = "LR"; label="Test" fontname="Courier-monospace" - node [fontname="Courier-monospace" fontsize = 8] - edge [fontname="Courier-monospace"] + node [fontname="Courier-monospace" fontsize = 10] + edge [fontname="Courier-monospace" fontsize = 10] } diff --git a/opossum/files_for_testing/dot/to_dot_empty_TB.dot b/opossum/files_for_testing/dot/to_dot_empty_TB.dot index abb744d6ea6891fc6cc20681f884d8c8a6450d77..385ab3cbec0d23571966560c407abb88753cedfe 100644 --- a/opossum/files_for_testing/dot/to_dot_empty_TB.dot +++ b/opossum/files_for_testing/dot/to_dot_empty_TB.dot @@ -1,10 +1,10 @@ digraph { - fontsize = 8; + fontsize = 10; compound = true; rankdir = "TB"; label="Test" fontname="Courier-monospace" - node [fontname="Courier-monospace" fontsize = 8] - edge [fontname="Courier-monospace"] + node [fontname="Courier-monospace" fontsize = 10] + edge [fontname="Courier-monospace" fontsize = 10] } diff --git a/opossum/files_for_testing/opm/optic_ref.opm b/opossum/files_for_testing/opm/optic_ref.opm index 1e8c410c7effc626e51e06385963b9debf1d6cb3..dbb0d44e8a646fe3e73075136c3ac4bcd24d4a78 100644 --- a/opossum/files_for_testing/opm/optic_ref.opm +++ b/opossum/files_for_testing/opm/optic_ref.opm @@ -1,5 +1,4 @@ type: dummy -id: 587ee70f-6f52-4420-89f6-e1618ff4dbdb attributes: alignment: null isometry: null diff --git a/opossum/files_for_testing/opm/opticscenery.opm b/opossum/files_for_testing/opm/opticscenery.opm index f843d66a371b82f71d984f5ba11ffa9f09045281..7a3b3f0bb7110991dffe207c43feec2f9c3e3c9e 100644 --- a/opossum/files_for_testing/opm/opticscenery.opm +++ b/opossum/files_for_testing/opm/opticscenery.opm @@ -5,21 +5,18 @@ scenery: ports: inputs: {} outputs: {} - uuid: b8cb049b-4eb9-4db8-8842-2fc7c70c27ba - lidt: 10000. + uuid: 7743e13b-7c3f-44fe-90f7-61e0ba6fa4d3 + lidt: 10000.0 props: expand view: !Bool false graph: !OpticGraph nodes: - type: dummy - id: 180328fe-7ad4-4568-b501-183b88c4daee attributes: name: dummy1 - uuid: 180328fe-7ad4-4568-b501-183b88c4daee - lidt: 10000. ports: inputs: - front: + input_1: geo_surface: !Flat s: isometry: @@ -45,14 +42,14 @@ scenery: - 0.0 aperture: None coating: IdealAR - lidt: 10000. + lidt: 10000.0 backward_rays_cache: [] forward_rays_cache: [] hit_map: hit_map: [] critical_fluence: {} outputs: - rear: + output_1: geo_surface: !Flat s: isometry: @@ -78,23 +75,22 @@ scenery: - 0.0 aperture: None coating: IdealAR - lidt: 10000. + lidt: 10000.0 backward_rays_cache: [] forward_rays_cache: [] hit_map: hit_map: [] critical_fluence: {} + uuid: d8c43481-43b7-4bad-8305-7246a62e4016 + lidt: 10000.0 props: {} inverted: false - type: dummy - id: 642ce76e-b071-43c0-a77e-1bdbb99b40d8 attributes: name: dummy2 - uuid: 642ce76e-b071-43c0-a77e-1bdbb99b40d8 - lidt: 10000. ports: inputs: - front: + input_1: geo_surface: !Flat s: isometry: @@ -120,14 +116,14 @@ scenery: - 0.0 aperture: None coating: IdealAR - lidt: 10000. + lidt: 10000.0 backward_rays_cache: [] forward_rays_cache: [] hit_map: hit_map: [] critical_fluence: {} outputs: - rear: + output_1: geo_surface: !Flat s: isometry: @@ -153,23 +149,30 @@ scenery: - 0.0 aperture: None coating: IdealAR - lidt: 10000. + lidt: 10000.0 backward_rays_cache: [] forward_rays_cache: [] hit_map: hit_map: [] critical_fluence: {} + uuid: e6729ff1-e14a-468d-a08f-d0b9dd131dab + lidt: 10000.0 props: {} inverted: false edges: - - - 180328fe-7ad4-4568-b501-183b88c4daee - - 642ce76e-b071-43c0-a77e-1bdbb99b40d8 - - rear - - front + - - d8c43481-43b7-4bad-8305-7246a62e4016 + - e6729ff1-e14a-468d-a08f-d0b9dd131dab + - output_1 + - input_1 - 0.0 input_map: {} output_map: {} inverted: false - input_port_distances: {} +global: + ambient_refr_index: !Const + refractive_index: 1.0 analyzers: -- Energy +- !RayTrace + min_energy_per_ray: 1e-12 + max_number_of_bounces: 1000 + max_number_of_refractions: 1000 diff --git a/opossum/src/nodes/mod.rs b/opossum/src/nodes/mod.rs index e8a6ea55d3f41ccdc9417b9450dd0ee1b0105065..81fe2608c67a796bd411445a26ba20d85cd2912d 100644 --- a/opossum/src/nodes/mod.rs +++ b/opossum/src/nodes/mod.rs @@ -53,7 +53,6 @@ use crate::{ error::{OpmResult, OpossumError}, optic_ref::OpticRef, }; -use uuid::Uuid; /// Factory function creating a new reference of an optical node of the given type. /// /// If a uuid is given, the optical node is created using this id. Otherwise a new (random) id is generated. This @@ -63,101 +62,73 @@ use uuid::Uuid; /// /// This function will return an [`OpossumError`] if there is no node with the given type. #[allow(clippy::too_many_lines)] -pub fn create_node_ref(node_type: &str, uuid: Option<Uuid>) -> OpmResult<OpticRef> { +pub fn create_node_ref(node_type: &str) -> OpmResult<OpticRef> { match node_type { - "dummy" => Ok(OpticRef::new( - Rc::new(RefCell::new(Dummy::default())), - uuid, - None, - )), + "dummy" => Ok(OpticRef::new(Rc::new(RefCell::new(Dummy::default())), None)), "beam splitter" => Ok(OpticRef::new( Rc::new(RefCell::new(BeamSplitter::default())), - uuid, None, )), "energy meter" => Ok(OpticRef::new( Rc::new(RefCell::new(EnergyMeter::default())), - uuid, None, )), "group" => Ok(OpticRef::new( Rc::new(RefCell::new(NodeGroup::default())), - uuid, None, )), "ideal filter" => Ok(OpticRef::new( Rc::new(RefCell::new(IdealFilter::default())), - uuid, None, )), "reflective grating" => Ok(OpticRef::new( Rc::new(RefCell::new(ReflectiveGrating::default())), - uuid, None, )), "reference" => Ok(OpticRef::new( Rc::new(RefCell::new(NodeReference::default())), - uuid, - None, - )), - "lens" => Ok(OpticRef::new( - Rc::new(RefCell::new(Lens::default())), - uuid, None, )), + "lens" => Ok(OpticRef::new(Rc::new(RefCell::new(Lens::default())), None)), "cylindric lens" => Ok(OpticRef::new( Rc::new(RefCell::new(CylindricLens::default())), - uuid, None, )), "source" => Ok(OpticRef::new( Rc::new(RefCell::new(Source::default())), - uuid, None, )), "spectrometer" => Ok(OpticRef::new( Rc::new(RefCell::new(Spectrometer::default())), - uuid, None, )), "spot diagram" => Ok(OpticRef::new( Rc::new(RefCell::new(SpotDiagram::default())), - uuid, None, )), "wavefront monitor" => Ok(OpticRef::new( Rc::new(RefCell::new(WaveFront::default())), - uuid, None, )), "paraxial surface" => Ok(OpticRef::new( Rc::new(RefCell::new(ParaxialSurface::default())), - uuid, None, )), "ray propagation" => Ok(OpticRef::new( Rc::new(RefCell::new(RayPropagationVisualizer::default())), - uuid, None, )), "fluence detector" => Ok(OpticRef::new( Rc::new(RefCell::new(FluenceDetector::default())), - uuid, - None, - )), - "wedge" => Ok(OpticRef::new( - Rc::new(RefCell::new(Wedge::default())), - uuid, None, )), + "wedge" => Ok(OpticRef::new(Rc::new(RefCell::new(Wedge::default())), None)), "mirror" => Ok(OpticRef::new( Rc::new(RefCell::new(ThinMirror::default())), - uuid, None, )), "parabolic mirror" => Ok(OpticRef::new( Rc::new(RefCell::new(ParabolicMirror::default())), - uuid, None, )), _ => Err(OpossumError::Other(format!( @@ -170,15 +141,6 @@ mod test { use super::*; #[test] fn create_node_ref_error() { - assert!(create_node_ref("test", None).is_err()); - } - #[test] - fn create_dummy() { - assert!(create_node_ref("dummy", None).is_ok()); - let id = Uuid::new_v4(); - let node = create_node_ref("dummy", Some(id)); - assert!(node.is_ok()); - let node = node.unwrap(); - assert_eq!(node.uuid(), id); + assert!(create_node_ref("test").is_err()); } } diff --git a/opossum/src/nodes/node_group/optic_graph.rs b/opossum/src/nodes/node_group/optic_graph.rs index 79dbc6e64c6c98dce95a4891cc4e83f175c9250f..556857cd618f93ac06ba5f80c2b4f3ebc6e25d3b 100644 --- a/opossum/src/nodes/node_group/optic_graph.rs +++ b/opossum/src/nodes/node_group/optic_graph.rs @@ -62,11 +62,8 @@ impl OpticGraph { "cannot add nodes if group is set as inverted".into(), )); } - let uuid = *node.node_attr().uuid(); - let idx = self.g.add_node(OpticRef::new( Rc::new(RefCell::new(node)), - Some(uuid), self.global_confg.clone(), )); @@ -682,11 +679,14 @@ impl OpticGraph { .ok_or_else(|| OpossumError::Other("could not get edge_endpoints".into()))?; let dist = self.distance_from_predecessor(end_nodes.1, light.target_port())?; - + let src_edge_str = self.create_node_edge_str(end_nodes.0, light.src_port())?; let target_edge_str = self.create_node_edge_str(end_nodes.1, light.target_port())?; - dot_string.push_str(&format!(" {src_edge_str} -> {target_edge_str} [label=\"{}\"]\n", format_quantity(meter, dist))); + dot_string.push_str(&format!( + " {src_edge_str} -> {target_edge_str} [label=\"{}\"]\n", + format_quantity(meter, dist) + )); } dot_string.push_str("}\n"); Ok(dot_string) diff --git a/opossum/src/nodes/reference.rs b/opossum/src/nodes/reference.rs index 8fcec30c894138b65991d3ef9f09f9fee2e0fde3..7d05a7c01edbf62b277a24ee65048fc3200703ef 100644 --- a/opossum/src/nodes/reference.rs +++ b/opossum/src/nodes/reference.rs @@ -15,6 +15,7 @@ use crate::{ optic_node::{OpticNode, LIDT}, optic_ports::OpticPorts, optic_ref::OpticRef, + properties::Proptype, utils::geom_transformation::Isometry, }; @@ -70,7 +71,10 @@ impl NodeReference { pub fn from_node(node: &OpticRef) -> Self { let mut refr = Self::default(); refr.node_attr - .set_property("reference id", node.uuid().into()) + .set_property( + "reference id", + Proptype::Uuid(*node.optical_ref.borrow().node_attr().uuid()), + ) .unwrap(); let ref_name = format!("ref ({})", node.optical_ref.borrow().name()); refr.node_attr.set_name(&ref_name); diff --git a/opossum/src/opm_document.rs b/opossum/src/opm_document.rs index 8cfa5f576d38f11ba00a328d624485538ce91e49..ad0d0b5a48245a5f8b5855fa63ccd751c98c30a1 100644 --- a/opossum/src/opm_document.rs +++ b/opossum/src/opm_document.rs @@ -169,11 +169,11 @@ mod test { let node1 = document.scenery.node(NodeIndex::from(0)).unwrap(); let node2 = document.scenery.node(NodeIndex::from(1)).unwrap(); assert_eq!( - "180328fe-7ad4-4568-b501-183b88c4daee", + "d8c43481-43b7-4bad-8305-7246a62e4016", node1.uuid().to_string() ); assert_eq!( - "642ce76e-b071-43c0-a77e-1bdbb99b40d8", + "e6729ff1-e14a-468d-a08f-d0b9dd131dab", node2.uuid().to_string() ); } diff --git a/opossum/src/optic_ref.rs b/opossum/src/optic_ref.rs index be50fa712df7a2c7446091b8baf7f64dd9548e51..13c4c5ac1018f97b148677d03caa696d66bbd1fa 100644 --- a/opossum/src/optic_ref.rs +++ b/opossum/src/optic_ref.rs @@ -19,32 +19,24 @@ use crate::{ /// /// This structure stores a reference to an optical node (a structure implementing the /// [`OpticNode`](crate::optic_node::OpticNode) trait). This [`OpticRef`] is then stored -/// as a node in a `NodeGroup`)[`crate::nodes::NodeGroup`]. In addition, it contains a -/// unique id ([`Uuid`]) in order to unambiguously identify a node within a scene. +/// as a node in a `NodeGroup`)[`crate::nodes::NodeGroup`]. pub struct OpticRef { /// The underlying optical reference. pub optical_ref: Rc<RefCell<dyn Analyzable>>, - uuid: Uuid, } impl OpticRef { /// Creates a new [`OpticRef`]. - /// - /// You can either assign a given [`Uuid`] using `Some(uuid!(...))` or provide `None`, where a new unique id is generated. pub fn new( node: Rc<RefCell<dyn Analyzable>>, - uuid: Option<Uuid>, global_conf: Option<Rc<RefCell<SceneryResources>>>, ) -> Self { node.borrow_mut().set_global_conf(global_conf); - Self { - optical_ref: node, - uuid: uuid.unwrap_or_else(Uuid::new_v4), - } + Self { optical_ref: node } } - /// Returns the [`Uuid`] of this [`OpticRef`]. + /// Returns the [`Uuid`] of the node, reference to by this [`OpticRef`]. #[must_use] - pub const fn uuid(&self) -> Uuid { - self.uuid + pub fn uuid(&self) -> Uuid { + *self.optical_ref.borrow().node_attr().uuid() } /// Update the reference to the global configuration. /// **Note**: This functions is normally only called from `OpticGraph`. @@ -59,7 +51,6 @@ impl Serialize for OpticRef { { let mut node = serializer.serialize_struct("node", 3)?; node.serialize_field("type", &self.optical_ref.borrow().node_type())?; - node.serialize_field("id", &self.uuid)?; node.serialize_field("attributes", &self.optical_ref.borrow().node_attr())?; node.end() } @@ -74,9 +65,8 @@ impl<'de> Deserialize<'de> for OpticRef { enum Field { NodeType, Attributes, - Id, } - const FIELDS: &[&str] = &["type", "attributes", "id"]; + const FIELDS: &[&str] = &["type", "attributes"]; impl<'de> Deserialize<'de> for Field { fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error> @@ -92,7 +82,7 @@ impl<'de> Deserialize<'de> for OpticRef { &self, formatter: &mut std::fmt::Formatter<'_>, ) -> std::fmt::Result { - formatter.write_str("`type`, `attributes`, or `id`") + formatter.write_str("`type`, or `attributes`") } fn visit_str<E>(self, value: &str) -> std::result::Result<Field, E> where @@ -101,7 +91,6 @@ impl<'de> Deserialize<'de> for OpticRef { match value { "type" => Ok(Field::NodeType), "attributes" => Ok(Field::Attributes), - "id" => Ok(Field::Id), _ => Err(de::Error::unknown_field(value, FIELDS)), } } @@ -129,8 +118,8 @@ impl<'de> Deserialize<'de> for OpticRef { let properties = seq .next_element()? .ok_or_else(|| de::Error::invalid_length(1, &self))?; - let node = create_node_ref(node_type, None) - .map_err(|e| de::Error::custom(e.to_string()))?; + let node = + create_node_ref(node_type).map_err(|e| de::Error::custom(e.to_string()))?; node.optical_ref .borrow_mut() .set_properties(properties) @@ -144,7 +133,6 @@ impl<'de> Deserialize<'de> for OpticRef { { let mut node_type = None; let mut node_attributes = None; - let mut id: Option<Uuid> = None; while let Some(key) = map.next_key()? { match key { Field::NodeType => { @@ -159,20 +147,13 @@ impl<'de> Deserialize<'de> for OpticRef { } node_attributes = Some(map.next_value::<NodeAttr>()?); } - Field::Id => { - if id.is_some() { - return Err(de::Error::duplicate_field("id")); - } - id = Some(map.next_value()?); - } } } let node_type = node_type.ok_or_else(|| de::Error::missing_field("type"))?; let node_attributes = node_attributes.ok_or_else(|| de::Error::missing_field("attributes"))?; - let id = id.ok_or_else(|| de::Error::missing_field("id"))?; - let node = create_node_ref(node_type, Some(id)) - .map_err(|e| de::Error::custom(e.to_string()))?; + let node = + create_node_ref(node_type).map_err(|e| de::Error::custom(e.to_string()))?; node.optical_ref.borrow_mut().set_node_attr(node_attributes); // group node: assign props to graph node.optical_ref @@ -189,28 +170,21 @@ impl<'de> Deserialize<'de> for OpticRef { mod test { use super::*; use crate::nodes::Dummy; + use crate::optic_node::OpticNode; use std::io::Read; use std::{fs::File, path::PathBuf}; use uuid::uuid; #[test] fn new() { let uuid = Uuid::new_v4(); - let optic_ref = OpticRef::new(Rc::new(RefCell::new(Dummy::default())), Some(uuid), None); - assert_eq!(optic_ref.uuid, uuid); - } - #[test] - fn uuid() { - let uuid = Uuid::new_v4(); - let optic_ref = OpticRef::new(Rc::new(RefCell::new(Dummy::default())), Some(uuid), None); + let mut dummy = Dummy::default(); + dummy.node_attr_mut().set_uuid(&uuid); + let optic_ref = OpticRef::new(Rc::new(RefCell::new(dummy)), None); assert_eq!(optic_ref.uuid(), uuid); } #[test] fn serialize() { - let optic_ref = OpticRef::new( - Rc::new(RefCell::new(Dummy::default())), - Some(uuid!("587ee70f-6f52-4420-89f6-e1618ff4dbdb")), - None, - ); + let optic_ref = OpticRef::new(Rc::new(RefCell::new(Dummy::default())), None); let serialized = serde_yaml::to_string(&optic_ref); assert!(serialized.is_ok()); } @@ -236,12 +210,9 @@ mod test { assert_eq!( format!( "{:?}", - OpticRef::new( - Rc::new(RefCell::new(Dummy::default())), - Some(uuid!("587ee70f-6f52-4420-89f6-e1618ff4dbdb")), None - ) + OpticRef::new(Rc::new(RefCell::new(Dummy::default())), None) ), - "OpticRef { optical_ref: RefCell { value: 'dummy' (dummy) }, uuid: 587ee70f-6f52-4420-89f6-e1618ff4dbdb }" + "OpticRef { optical_ref: RefCell { value: 'dummy' (dummy) } }" ); } } diff --git a/opossum/src/properties/proptype.rs b/opossum/src/properties/proptype.rs index deadbe64f37c91f6b790c6d9e582339f5468a403..7e3a2182321b01b2babb07bcb94ff9a327073eb1 100644 --- a/opossum/src/properties/proptype.rs +++ b/opossum/src/properties/proptype.rs @@ -266,6 +266,10 @@ pub fn format_value_with_prefix(value: f64) -> String { format!("{:8.3} {prefix}", value / f64::powi(10.0, exponent)) } +///Formats a uom quantity +/// +/// # Panics +/// This function panics if the coversion from the quantity value to f64 fails pub fn format_quantity<D, U, V, N>(_: N, q: Quantity<D, U, V>) -> String where D: Dimension + ?Sized,