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

Doc work.

Add splitting ratio to Beamsplitter (not used yet).
parent 21fe28ce
No related branches found
No related tags found
No related merge requests found
......@@ -11,8 +11,8 @@ fn main() {
let in1 = scenery.add_node(OpticNode::new("Input", NodeDummy));
let out1 = scenery.add_node(OpticNode::new("Output", NodeDummy));
let bs1 = scenery.add_node(OpticNode::new("Beamsplitter 1", NodeBeamSplitter));
let bs2 = scenery.add_node(OpticNode::new("Beamsplitter 2", NodeBeamSplitter));
let bs1 = scenery.add_node(OpticNode::new("Beamsplitter 1", NodeBeamSplitter::default()));
let bs2 = scenery.add_node(OpticNode::new("Beamsplitter 2", NodeBeamSplitter::default()));
let m1 = scenery.add_node(OpticNode::new("Mirror 1", NodeDummy));
let m2 = scenery.add_node(OpticNode::new("Mirror 2", NodeDummy));
......
......@@ -20,7 +20,7 @@ fn main() {
let pump_main_amplifier_node = scenery.add_element("Pump Main-Amplifier", NodeDummy);
let pump_compressor_node = scenery.add_element("Pump Compressor", NodeDummy);
let pump_shg_node = scenery.add_element("Pump SHG", NodeDummy);
let pump_splitter_node = scenery.add_element("Pump Beam Splitter", NodeBeamSplitter);
let pump_splitter_node = scenery.add_element("Pump Beam Splitter", NodeBeamSplitter::default());
scenery
.connect_nodes(pulse_generation_split_node, "rear", u_opa_1_node, "front")
......
use crate::{optic_node::{Optical, Dottable}, optic_ports::OpticPorts};
use crate::{
optic_node::{Dottable, Optical},
optic_ports::OpticPorts,
};
#[derive(Debug)]
pub struct NodeBeamSplitter;
/// An ideal beamsplitter node with a given splitting ratio.
pub struct NodeBeamSplitter {
ratio: f32,
}
impl NodeBeamSplitter {
/// Creates a new [`NodeBeamSplitter`] with a given splitting ratio.
pub fn new(ratio: f32) -> Self {
Self { ratio }
}
/// Returns the splitting ratio of this [`NodeBeamSplitter`].
pub fn ratio(&self) -> f32 {
self.ratio
}
/// Sets the splitting ratio of this [`NodeBeamSplitter`].
pub fn set_ratio(&mut self, ratio: f32) {
self.ratio = ratio;
}
}
impl Default for NodeBeamSplitter {
/// Create a 50:50 beamsplitter.
fn default() -> Self {
Self { ratio: 0.5 }
}
}
impl Optical for NodeBeamSplitter {
fn node_type(&self) -> &str {
"ideal beam splitter"
}
fn ports(&self) -> OpticPorts {
let mut ports=OpticPorts::new();
ports.add_input("input1").unwrap();
ports.add_input("input2").unwrap();
ports.add_output("out1_trans1_refl2").unwrap();
ports.add_output("out2_trans2_refl1").unwrap();
ports
}
fn node_type(&self) -> &str {
"ideal beam splitter"
}
fn ports(&self) -> OpticPorts {
let mut ports = OpticPorts::new();
ports.add_input("input1").unwrap();
ports.add_input("input2").unwrap();
ports.add_output("out1_trans1_refl2").unwrap();
ports.add_output("out2_trans2_refl1").unwrap();
ports
}
}
impl Dottable for NodeBeamSplitter{
fn node_color(&self) -> &str {
"lightpink"
}
impl Dottable for NodeBeamSplitter {
fn node_color(&self) -> &str {
"lightpink"
}
}
......@@ -2,6 +2,7 @@ use crate::{optic_node::{Optical, Dottable, LightResult}, optic_ports::OpticPort
use crate::lightdata::LightData;
#[derive(Debug, Default)]
/// This node rerpresents an universal detector. Any [`LightData`] coming in will be stored internally for later display / export. So far it only has one input (in1).
pub struct NodeDetector {
light_data: Option<LightData>
}
......
use crate::error::OpossumError;
use crate::light::Light;
use crate::optic_node::Dottable;
use crate::{optic_node::{OpticNode, Optical}, optic_ports::OpticPorts};
use crate::{
optic_node::{OpticNode, Optical},
optic_ports::OpticPorts,
};
use petgraph::algo::*;
use petgraph::prelude::{DiGraph, EdgeIndex, NodeIndex};
use crate::light::Light;
type Result<T> = std::result::Result<T, OpossumError>;
#[derive(Default, Debug)]
/// A node that represents a group of other [`OpticNode`]s. These subnodes are arranged in its own subgraph. All unconnected input and output ports of this subgraph form the ports of this [`NodeGroup`].
pub struct NodeGroup {
g: DiGraph<OpticNode, Light>,
}
......@@ -16,7 +20,7 @@ impl NodeGroup {
pub fn new() -> Self {
Self::default()
}
/// Add a given [`OpticNode`] to the graph of this [`NodeGroup`].
/// Add a given [`OpticNode`] to the (sub-)graph of this [`NodeGroup`].
///
/// This command just adds an [`OpticNode`] but does not connect it to existing nodes in the (sub-)graph. The given node is
/// consumed (owned) by the [`NodeGroup`].
......@@ -101,7 +105,7 @@ impl Optical for NodeGroup {
}
}
impl Dottable for NodeGroup{
impl Dottable for NodeGroup {
fn to_dot(&self, node_index: &str, name: &str, inverted: bool, _ports: &OpticPorts) -> String {
let inv_string = if inverted { "(inv)" } else { "" };
let mut dot_string = format!(
......@@ -127,10 +131,9 @@ impl Dottable for NodeGroup{
}
dot_string += "}";
dot_string
}
fn node_color(&self) -> &str {
"yellow"
}
}
}
......@@ -17,7 +17,6 @@ impl NodeReference {
}
}
impl Optical for NodeReference {
fn node_type(&self) -> &str {
"reference"
......
......@@ -4,22 +4,26 @@ use crate::{
optic_ports::OpticPorts,
};
/// This node represents a source of light. Hence it has only one output port (out1) and no input ports. Source nodes usually are the first nodes of an optic scenery.
#[derive(Debug, Default)]
pub struct NodeSource {
light_data: Option<LightData>,
}
impl NodeSource {
/// Creates a new [`NodeSource`].
pub fn new(light: LightData) -> Self {
NodeSource {
light_data: Some(light),
}
}
/// Returns the light data of this [`NodeSource`].
pub fn light_data(&self) -> Option<&LightData> {
self.light_data.as_ref()
}
/// Sets the light data of this [`NodeSource`]. The [`LightData`] provided here represents the input data of an `OpticScenery`.
pub fn set_light_data(&mut self, light_data: LightData) {
self.light_data = Some(light_data);
}
......
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