Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
32 changes: 29 additions & 3 deletions pypact/input/inputdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,32 @@ 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._inventoryismass = True
self._inventorymass.totalMass = float(parts[1])
num_elements = int(parts[2])
self._inventorymass.entries = []
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._inventorymass.entries.append((element, float(percentage)))
num_elements -= 1
if num_elements == 0:
in_mass_section = False
else:
raise PypactInvalidOptionException("Invalid element line format in MASS section.")
26 changes: 26 additions & 0 deletions tests/input/inputfiletest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pypact as pp


def test_reading_in_mass():
ff = pp.InputData()
pp.from_file(ff, 'examples/files/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}"
Loading