fispact / pypact

A Python package for parsing FISPACT-II output
https://pypact.readthedocs.io/en/latest/
Apache License 2.0
25 stars 13 forks source link

Digit of fuel entries #34

Closed zxkjack123 closed 3 years ago

zxkjack123 commented 3 years ago

An simple fispact-II input was generated via pypact. The material composition are calculated form as set as below:

<< set the target via FUEL >>
FUEL 2
H1 5.974010803153376e+26
H2 6.870902577422786e+22

However, fispact cannot deal with it and here is the error message:

ERROR in INPUT file
 Detected at argument   3 on line  29 of keyword FUEL on line  28.
 Argument value is 5.974010803153376e+26. Expected argument type is floating-point number.
 Abbreviated keyword 5.974010803153376e+26 matches** keywords
 when argument 3 from previous keyword FUEL expected

 ERROR in INPUT file
 Expecting a keyword, but token 5.974010803153376e+26 is too long
 Detected on line number =  29
 Skipping to next keyword

I think the digit of float should be controled when writing input file to avoid running error. For example:

diff --git a/pypact/input/inputdata.py b/pypact/input/inputdata.py
index 16b4991..c3955e0 100644
--- a/pypact/input/inputdata.py
+++ b/pypact/input/inputdata.py
@@ -41,7 +41,10 @@ class FuelInventory(InventoryType):
     def __str__(self):
         strrep = "{} {}".format('FUEL', len(self.entries))
         for i in self.entries:
-            strrep += "\n{} {}".format(i[0], i[1])
+            if len("{}".format(i[1]) > 20:
+                strrep += "\n{} {:.14E}".format(i[0], i[1])
+            else:
+                strrep += "\n{} {}".format(i[0], i[1])
thomasms commented 3 years ago

Yes - good spot!

If I remember correctly, FISPACT-II takes a maximum of 13 or 14 decimal places, otherwise you get this not so useful error message, so indeed this needs to be taken into account.

This code is a bit old now and we would be better off using f-strings now anyway. I would just vote to always dump to 10 decimal places anyway, since this is plenty of accuracy and most of them are just noise.

Something like:

     def __str__(self):
         strrep = f"FUEL {len(self.entries)}"
         for i in self.entries:
             strrep += f"\n{i[0]} {i[1]:.10E}")

By all means do a pull request and we can fix this.