add SimulationEngine and SimulationOutputs to compute results and pass standardized objects on to plotter

This commit is contained in:
Pim Nelissen
2026-02-25 14:21:59 +01:00
parent 9944c06466
commit ae0a038948
3 changed files with 88 additions and 0 deletions

View File

View File

@ -0,0 +1,63 @@
from typing import List
from pg_rad.landscape.landscape import Landscape
from pg_rad.simulator.outputs import (
CountRateOutput,
SimulationOutput,
SourceOutput
)
from pg_rad.physics.fluence import calculate_fluence_along_path
from pg_rad.utils.projection import minimal_distance_to_path
from pg_rad.inputparser.specs import RuntimeSpec, SimulationOptionsSpec
class SimulationEngine:
"""Takes a fully built landscape and produces results."""
def __init__(
self,
landscape: Landscape,
runtime_spec=RuntimeSpec,
sim_spec=SimulationOptionsSpec
):
self.landscape = landscape
self.runtime_spec = runtime_spec
self.sim_spec = sim_spec
def simulate(self) -> SimulationOutput:
"""Compute everything and return structured output."""
count_rate_results = self._calculate_count_rate_along_path()
source_results = self._calculate_point_source_distance_to_path()
return SimulationOutput(
name=self.landscape.name,
count_rate=count_rate_results,
sources=source_results
)
def _calculate_count_rate_along_path(self) -> CountRateOutput:
arc_length, phi = calculate_fluence_along_path(self.landscape)
return CountRateOutput(arc_length, phi)
def _calculate_point_source_distance_to_path(self) -> List[SourceOutput]:
path = self.landscape.path
source_output = []
for s in self.landscape.point_sources:
dist_to_path = minimal_distance_to_path(
path.x_list,
path.y_list,
path.z,
s.pos)
source_output.append(
SourceOutput(
s.name,
s.isotope.name,
s.activity,
s.pos,
dist_to_path)
)
return source_output

View File

@ -0,0 +1,25 @@
from typing import List, Tuple
from dataclasses import dataclass
@dataclass
class CountRateOutput:
arc_length: List[float]
count_rate: List[float]
@dataclass
class SourceOutput:
name: str
isotope: str
activity: float
position: Tuple[float, float, float]
dist_from_path: float
@dataclass
class SimulationOutput:
name: str
count_rate: CountRateOutput
sources: List[SourceOutput]