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

Add first try for implementation of AnalyzerEnergy

parent 49048bb9
No related branches found
No related tags found
No related merge requests found
use opossum::nodes::{NodeDummy, NodeGroup, NodeReference};
use opossum::optic_node::OpticNode;
use opossum::optic_scenery::OpticScenery;
use opossum::analyzer::AnalyzerEnergy;
use std::fs::File;
use std::io::Write;
......@@ -43,4 +43,7 @@ fn main() {
let path = "graph.dot";
let mut output = File::create(path).unwrap();
write!(output, "{}", scenery.to_dot()).unwrap();
let analyzer=AnalyzerEnergy::new(&scenery);
analyzer.analyze();
}
use opossum::analyzer::AnalyzerEnergy;
use opossum::nodes::{NodeBeamSplitter, NodeDummy};
use opossum::optic_scenery::OpticScenery;
......@@ -155,4 +156,7 @@ fn main() {
let path = "uOPA_PreAmp.dot";
let mut output = File::create(path).unwrap();
write!(output, "{}", scenery_2.to_dot()).unwrap();
let analyzer=AnalyzerEnergy::new(&scenery);
analyzer.analyze();
}
use crate::optic_scenery::OpticScenery;
#[derive(Debug)]
pub struct AnalyzerEnergy {
scene: OpticScenery
}
impl AnalyzerEnergy {
pub fn new(scenery: &OpticScenery) -> Self {
Self { scene: (*scenery).to_owned()}
}
pub fn analyze(&self) {
for node in self.scene.nodes_topological().unwrap() {
println!("Node: {}", node.name())
}
}
}
\ No newline at end of file
......@@ -11,4 +11,6 @@ pub mod optic_ports;
pub mod nodes;
pub mod analyzer;
pub mod error;
\ No newline at end of file
use crate::lightdata::LightData;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Light {
src_port: String,
target_port: String,
......
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum LightData {
Energy(LightDataEnergy),
Geometric(LightDataGeometric),
Fourier
Energy(LightDataEnergy),
Geometric(LightDataGeometric),
Fourier,
}
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct LightDataEnergy {
energy: f32
energy: f32,
}
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct LightDataGeometric {
ray: i32
}
\ No newline at end of file
ray: i32,
}
......@@ -5,12 +5,13 @@ use crate::light::Light;
use crate::optic_node::{OpticNode, Optical};
use petgraph::algo::*;
use petgraph::prelude::{DiGraph, EdgeIndex, NodeIndex};
use petgraph::algo::toposort;
type Result<T> = std::result::Result<T, OpossumError>;
/// [`OpticScenery`] represents the overall optical model and additional metatdata. All optical elements ([`OpticNode`]s) have
/// to be added to this structure in order to be considered for an analysis.
#[derive(Default, Debug)]
#[derive(Default, Debug, Clone)]
pub struct OpticScenery {
g: DiGraph<Rc<OpticNode>, Light>,
description: String,
......@@ -145,10 +146,6 @@ impl OpticScenery {
dot_string += "}";
dot_string
}
/// Analyze this [`OpticScenery`] using a given OpticAnalyzer.
pub fn analyze(&self) {
todo!();
}
/// Sets the description of this [`OpticScenery`].
pub fn set_description(&mut self, description: String) {
self.description = description;
......@@ -157,6 +154,23 @@ impl OpticScenery {
pub fn description(&self) -> &str {
self.description.as_ref()
}
pub fn nodes_topological(&self) -> Result<Vec<Rc<OpticNode>>> {
let sorted=toposort(&self.g, None);
if let Ok(sorted) = sorted {
let node=sorted.into_iter()
.map(|idx| self.g.node_weight(idx).unwrap().to_owned()).collect();
Ok(node)
} else {
Err(OpossumError::OpticScenery("Analyis: topological sort failed".into()))
}
}
pub fn nodes_unordered(&self) -> Vec<NodeIndex> {
self.g.node_indices().collect::<Vec<NodeIndex>>()
}
pub fn incoming_edges(&self, idx: NodeIndex) -> Vec<Light> {
let edges= self.g.edges_directed(idx, petgraph::Direction::Incoming);
edges.into_iter().map(|e| e.weight().to_owned()).collect::<Vec<Light>>()
}
}
#[cfg(test)]
......
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