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

Work on integration of spectrum into analysis.

Not working yet....
parent c13bbbe9
No related branches found
No related tags found
No related merge requests found
...@@ -43,7 +43,7 @@ mod test { ...@@ -43,7 +43,7 @@ mod test {
let light = Light::new("test1", "test2"); let light = Light::new("test1", "test2");
assert_eq!(light.src_port, "test1"); assert_eq!(light.src_port, "test1");
assert_eq!(light.target_port, "test2"); assert_eq!(light.target_port, "test2");
assert_eq!(light.data, None); assert!(light.data.is_none());
} }
#[test] #[test]
fn src_port() { fn src_port() {
......
use std::fmt::Display; use std::fmt::Display;
use uom::si::{f64::Energy, energy::joule};
use uom::fmt::DisplayStyle::Abbreviation; use uom::fmt::DisplayStyle::Abbreviation;
use uom::si::{energy::joule, f64::Energy};
#[derive(Debug, PartialEq, Clone)] use crate::spectrum::Spectrum;
#[derive(Debug, Clone)]
pub enum LightData { pub enum LightData {
Energy(DataEnergy), Energy(DataEnergy),
Geometric(DataGeometric), Geometric(DataGeometric),
...@@ -12,21 +14,24 @@ pub enum LightData { ...@@ -12,21 +14,24 @@ pub enum LightData {
impl Display for LightData { impl Display for LightData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
LightData::Energy(e) => { LightData::Energy(e) => {
let ef = Energy::format_args(joule, Abbreviation); let ef = Energy::format_args(joule, Abbreviation);
write!(f, "Energy: {}", ef.with(e.energy)) write!(
} , f,
"Energy: {}",
ef.with(Energy::new::<joule>(e.spectrum.total_energy()))
)
}
_ => write!(f, "No display defined for this type of LightData"), _ => write!(f, "No display defined for this type of LightData"),
} }
} }
} }
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, Clone)]
pub struct DataEnergy { pub struct DataEnergy {
pub energy: Energy, pub spectrum: Spectrum,
} }
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, Clone)]
pub struct DataGeometric { pub struct DataGeometric {
ray: i32, ray: i32,
} }
use crate::analyzer::AnalyzerType; use crate::analyzer::AnalyzerType;
use crate::error::OpossumError; use crate::error::OpossumError;
use crate::lightdata::{LightData, DataEnergy}; use crate::lightdata::{DataEnergy, LightData};
use crate::optic_node::{Dottable, LightResult, Optical}; use crate::optic_node::{Dottable, LightResult, Optical};
use crate::optic_ports::OpticPorts; use crate::optic_ports::OpticPorts;
use std::collections::HashMap; use std::collections::HashMap;
use uom::num_traits::Zero;
use uom::si::f64::Energy;
type Result<T> = std::result::Result<T, OpossumError>; type Result<T> = std::result::Result<T, OpossumError>;
#[derive(Debug)] #[derive(Debug)]
/// An ideal filter with given transmission or optical density. /// An ideal filter with given transmission or optical density.
pub struct IdealFilter { pub struct IdealFilter {
transmission: f64 transmission: f64,
} }
impl IdealFilter { impl IdealFilter {
...@@ -64,19 +62,21 @@ impl IdealFilter { ...@@ -64,19 +62,21 @@ impl IdealFilter {
} }
fn analyze_energy(&mut self, incoming_data: LightResult) -> Result<LightResult> { fn analyze_energy(&mut self, incoming_data: LightResult) -> Result<LightResult> {
let input = incoming_data.get("front"); let input = incoming_data.get("front");
let mut input_energy = Energy::zero();
if let Some(Some(input)) = input { if let Some(Some(input)) = input {
match input { match input {
LightData::Energy(e) => input_energy = e.energy, LightData::Energy(e) => {
let mut out_spec=e.spectrum.clone();
if out_spec.scale_vertical(self.transmission).is_ok() {
let light_data = Some(LightData::Energy(DataEnergy {
spectrum: out_spec,
}));
return Ok(HashMap::from([("rear".into(), light_data)]));
}
}
_ => return Err(OpossumError::Analysis("expected energy value".into())), _ => return Err(OpossumError::Analysis("expected energy value".into())),
} }
} }
let output_energy = Some(LightData::Energy(DataEnergy { Err(OpossumError::Analysis("error in analysis".into()))
energy: input_energy * self.transmission,
}));
Ok(HashMap::from([("rear".into(), output_energy)]))
} }
} }
......
use std::collections::HashMap; use std::collections::HashMap;
use uom::{si::f64::Energy, num_traits::Zero}; use uom::{num_traits::Zero, si::f64::Energy};
use crate::{ use crate::{
analyzer::AnalyzerType, analyzer::AnalyzerType,
error::OpossumError, error::OpossumError,
lightdata::{LightData, DataEnergy}, lightdata::{DataEnergy, LightData},
optic_node::{Dottable, LightResult, Optical}, optic_node::{Dottable, LightResult, Optical},
optic_ports::OpticPorts, optic_ports::OpticPorts,
spectrum::Spectrum,
}; };
type Result<T> = std::result::Result<T, OpossumError>; type Result<T> = std::result::Result<T, OpossumError>;
...@@ -36,30 +37,30 @@ impl BeamSplitter { ...@@ -36,30 +37,30 @@ impl BeamSplitter {
let in1 = incoming_data.get("input1"); let in1 = incoming_data.get("input1");
let in2 = incoming_data.get("input2"); let in2 = incoming_data.get("input2");
let mut in1_energy = Energy::zero(); let mut in1_spectrum: Option<Spectrum> = None;
let mut in2_energy = Energy::zero(); let mut in2_spectrum: Option<Spectrum> = None;
if let Some(Some(in1)) = in1 { if let Some(Some(in1)) = in1 {
match in1 { match in1 {
LightData::Energy(e) => in1_energy = e.energy, LightData::Energy(e) => in1_spectrum = Some(e.spectrum.clone()),
_ => return Err(OpossumError::Analysis("expected energy value".into())), _ => return Err(OpossumError::Analysis("expected DataEnergy value".into())),
} }
} }
if let Some(Some(in2)) = in2 { if let Some(Some(in2)) = in2 {
match in2 { match in2 {
LightData::Energy(e) => in2_energy = e.energy, LightData::Energy(e) => in2_spectrum = Some(e.spectrum.clone()),
_ => return Err(OpossumError::Analysis("expected energy value".into())), _ => return Err(OpossumError::Analysis("expected DataEnergy value".into())),
} }
} }
let out1_energy = Some(LightData::Energy(DataEnergy { // let out1_energy = Some(LightData::Energy(DataEnergy {
energy: in1_energy * self.ratio + in2_energy * (1.0 - self.ratio), // energy: in1_energy * self.ratio + in2_energy * (1.0 - self.ratio),
})); // }));
let out2_energy = Some(LightData::Energy(DataEnergy { // let out2_energy = Some(LightData::Energy(DataEnergy {
energy: in1_energy * (1.0 - self.ratio) + in2_energy * self.ratio, // energy: in1_energy * (1.0 - self.ratio) + in2_energy * self.ratio,
})); // }));
Ok(HashMap::from([ Ok(HashMap::from([
("out1_trans1_refl2".into(), out1_energy), ("out1_trans1_refl2".into(), None), //out1_energy),
("out2_trans2_refl1".into(), out2_energy), ("out2_trans2_refl1".into(), None), //out2_energy),
])) ]))
} }
} }
......
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