diff --git a/src/pg_rad/simulator/__init__.py b/src/pg_rad/simulator/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/pg_rad/simulator/engine.py b/src/pg_rad/simulator/engine.py new file mode 100644 index 0000000..8de7e98 --- /dev/null +++ b/src/pg_rad/simulator/engine.py @@ -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 diff --git a/src/pg_rad/simulator/outputs.py b/src/pg_rad/simulator/outputs.py new file mode 100644 index 0000000..395317f --- /dev/null +++ b/src/pg_rad/simulator/outputs.py @@ -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]