From d826359a551024976257fbacd2dbf92ede96b753 Mon Sep 17 00:00:00 2001 From: Steven Bradnam Date: Mon, 25 Nov 2024 15:09:22 +0000 Subject: [PATCH] Added OpenMCTallyFactors data class --- jade/openmc.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/jade/openmc.py b/jade/openmc.py index 54f82665..047bde9e 100644 --- a/jade/openmc.py +++ b/jade/openmc.py @@ -4,16 +4,71 @@ import os import re from typing import TYPE_CHECKING +from dataclasses import dataclass import openmc import numpy as np import pandas as pd +import yaml if TYPE_CHECKING: from f4enix.input.libmanager import LibManager from f4enix.input.materials import Material, SubMaterial, Zaid +@dataclass +class OpenMCTallyFactors: + """Configuration for a computational benchmark. + + Attributes + ---------- + tally_factors : dict[int, TallyFactors] + Options for the Excel benchmark. + """ + tally_factors : dict[int, TallyFactors] + + @classmethod + def from_yaml(cls, file: str | os.PathLike) -> OpenMCTallyFactors: + """Build the configuration for a computational benchmark from a yaml file. + + Parameters + ---------- + file : str | os.PathLike + path to the yaml file. + + Returns + ------- + OpenMCTallyFactors + The tally factors for the OpenMC benchmark. + """ + with open(file) as f: + cfg = yaml.safe_load(f) + + tally_factors = {} + for key, value in cfg.items(): + tally_factors[int(key)] = TallyFactors(**value) + return cls(tally_factors=tally_factors) + +@dataclass +class TallyFactors: + """Data class storing tally factors + + Attributes + ---------- + identifier : int + Identifier of the tally. + normalisation : float + Nomrlaisation factor for the tally. + volume : bool + True if volume divisor is needed, False if not. + mass : BinningType | list[BinningType] + True if mass divisor is needed, False if not. + """ + identifier : int + normalisation : float + volume : bool + mass : bool + class OpenMCInputFiles: def __init__(self, path: str, name=None) -> None: """Class to handle the OpenMC input file generation