Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions pypact/input/inputdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,30 @@ def _deserialize(self, f):
The deserialization method
f: file object
"""
pass


self.reset()

lines = f.readlines()
in_mass_section = False

for line in lines:
line = line.strip()
if line.startswith("MASS"):
# Parse the MASS line
parts = line.split()
if len(parts) != 3:
raise PypactInvalidOptionException("Invalid MASS line format.")
self.setMass(float(parts[1]))
num_elements = int(parts[2])
in_mass_section = True
continue

if in_mass_section:
# Parse the elements following the MASS line
if len(line.split()) == 2:
element, percentage = line.split()
self.addElement(element, float(percentage))
num_elements -= 1
if num_elements == 0:
in_mass_section = False
else:
raise PypactInvalidOptionException("Invalid element line format in MASS section.")
63 changes: 63 additions & 0 deletions reference/test.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<< CONTROL PHASE >>
<< enable JSON output >>
JSON
<< overwrite existing output files of same name >>
CLOBBER
<< read gamma groups from file, specify ggbins in files file >>
READGG
<< monitor FISPACT-II progress >>
MONITOR 1
<< the minimum cross section (barns) for inclusion in pathways analysis >>
XSTHRESHOLD 1e-12
<< perform collapse >>
GETXS 1 709
<< get decay data >>
GETDECAY 1
<< enable logging at level 1 >>
LOGLEVEL 1
<< approximate spectra when not available >>
SPEK
<< end control >>
FISPACT
* test

<< INITIALIZATION PHASE >>
<< output half life values >>
HALF
<< output ingestion and inhalation values >>
HAZARDS
<< set the target via MASS >>
MASS 1.0 3
Ti 80.0
Fe 14.8
Cr 5.2
<< set the target density >>
DENSITY 19.5
<< set the threshold for atoms in the inventory >>
MIND 100000.0
<< output the initial inventory >>
ATOMS

<< INVENTORY PHASE >>
<< irradiation schedule >>
FLUX 1100000000000000.0
TIME 300.0 SECS
ATOMS
<< end of irradiation >>
FLUX 0.0
ZERO
TIME 10.0 SECS
ATOMS
TIME 100.0 SECS
ATOMS
TIME 1000.0 SECS
ATOMS
TIME 10000.0 SECS
ATOMS
TIME 100000.0 SECS
ATOMS
<< end of cooling >>

<< end of input >>
END
* end
30 changes: 30 additions & 0 deletions tests/input/inputfiletest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pypact as pp

from tests.testerbase import Tester


class InputFileTest(Tester):

def test_reading_in_mass():
ff = pp.InputData()
pp.from_file(ff, 'reference/test.i')

# Assert that the inventory is set to mass mode
assert ff._inventoryismass is True, "Inventory should be set to mass mode"
assert ff._inventoryisfuel is False, "Inventory should not be set to fuel mode"

# Assert the total mass
assert ff._inventorymass.totalMass == 1.0, "Total mass should be 1.0"

# Assert the number of elements
assert len(ff._inventorymass.entries) == 3, "There should be 3 elements in the inventory"

# Assert the elements and their percentages
expected_elements = [
("Ti", 80.0),
("Fe", 14.8),
("Cr", 5.2)
]
for i, (element, percentage) in enumerate(expected_elements):
assert ff._inventorymass.entries[i][0] == element, f"Element {i} should be {element}"
assert ff._inventorymass.entries[i][1] == percentage, f"Percentage of {element} should be {percentage}"
1 change: 1 addition & 0 deletions tests/testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from tests.input.groupconverttest import GroupConvertUnitTest
from tests.input.groupstructurestest import GroupStructuresUnitTest
from tests.input.projectilestest import ProjectilesUnitTest
from tests.input.inputfiletest import InputFileTest

from tests.library.nuclidelibtest import NuclideLibUnitTest
from tests.library.reactionlibtest import ReactionLibUnitTest
Expand Down