diff --git a/pypact/input/inputdata.py b/pypact/input/inputdata.py index 7971506..8e00f59 100644 --- a/pypact/input/inputdata.py +++ b/pypact/input/inputdata.py @@ -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.") \ No newline at end of file diff --git a/reference/test.i b/reference/test.i new file mode 100644 index 0000000..48d4c39 --- /dev/null +++ b/reference/test.i @@ -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 diff --git a/tests/input/inputfiletest.py b/tests/input/inputfiletest.py new file mode 100644 index 0000000..7dc92db --- /dev/null +++ b/tests/input/inputfiletest.py @@ -0,0 +1,30 @@ +import pypact as pp + +from tests.testerbase import Tester + + +class InputFileTest(Tester): + + def test_reading_in_mass(self): + 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}" \ No newline at end of file diff --git a/tests/testsuite.py b/tests/testsuite.py index 99f2cda..8391c46 100644 --- a/tests/testsuite.py +++ b/tests/testsuite.py @@ -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