mirror of
https://github.com/pim-n/pg-rad
synced 2026-03-23 21:58:12 +01:00
add SimulationEngine and SimulationOutputs to compute results and pass standardized objects on to plotter
This commit is contained in:
0
src/pg_rad/simulator/__init__.py
Normal file
0
src/pg_rad/simulator/__init__.py
Normal file
63
src/pg_rad/simulator/engine.py
Normal file
63
src/pg_rad/simulator/engine.py
Normal 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
|
||||
25
src/pg_rad/simulator/outputs.py
Normal file
25
src/pg_rad/simulator/outputs.py
Normal 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]
|
||||
Reference in New Issue
Block a user