Skip to content

Commit 5dd29cd

Browse files
committed
pymcnp/inp: added data cards
1 parent 3138ad7 commit 5dd29cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+4170
-1097
lines changed

src/pymcnp/_data.py

Lines changed: 1158 additions & 1045 deletions
Large diffs are not rendered by default.

src/pymcnp/inp/cell/Fill_2.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import re
2+
import typing
3+
4+
5+
from .option_ import CellOption_
6+
from ...utils import types
7+
from ...utils import errors
8+
9+
10+
class Fill_2(CellOption_, keyword='fill'):
11+
"""
12+
Represents INP fill_2 elements.
13+
14+
Attributes:
15+
InpError: SEMANTICS_OPTION_VALUE.
16+
"""
17+
18+
_ATTRS = {
19+
'i': types.IndexEntry,
20+
'j': types.IndexEntry,
21+
'k': types.IndexEntry,
22+
'universes': types.Tuple[types.Integer],
23+
}
24+
25+
_REGEX = re.compile(
26+
rf'fill( {types.IndexEntry._REGEX.pattern})( {types.IndexEntry._REGEX.pattern})( {types.IndexEntry._REGEX.pattern})(( \S+)+)'
27+
)
28+
29+
def __init__(
30+
self,
31+
i: types.IndexEntry,
32+
j: types.IndexEntry,
33+
k: types.IndexEntry,
34+
universes: types.Tuple[types.Integer],
35+
):
36+
"""
37+
Initializes ``Fill_2``.
38+
39+
Parameters:
40+
i: Lattice parameter #1.
41+
j: Lattice parameter #2.
42+
k: Lattice parameter #3.
43+
universes: Fill universe numbers.
44+
45+
Raises:
46+
InpError: SEMANTICS_OPTION_VALUE.
47+
"""
48+
49+
if i is None:
50+
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION_VALUE, i)
51+
if j is None:
52+
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION_VALUE, j)
53+
if k is None:
54+
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION_VALUE, k)
55+
if universes is None or not (
56+
len(universes) == (i.upper - i.lower) * (j.upper - j.lower) * (k.upper - k.lower)
57+
):
58+
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION_VALUE, universes)
59+
60+
self.value: typing.Final[types.Tuple] = types.Tuple(
61+
[
62+
i,
63+
j,
64+
k,
65+
universes,
66+
]
67+
)
68+
69+
self.i: typing.Final[types.IndexEntry] = i
70+
self.j: typing.Final[types.IndexEntry] = j
71+
self.k: typing.Final[types.IndexEntry] = k
72+
self.universes: typing.Final[types.Tuple[types.Integer]] = universes

src/pymcnp/inp/cell/Tmp_0.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import re
2+
import typing
3+
4+
5+
from .option_ import CellOption_
6+
from ...utils import types
7+
from ...utils import errors
8+
9+
10+
class Tmp_0(CellOption_, keyword='tmp'):
11+
"""
12+
Represents INP tmp_0 elements.
13+
14+
Attributes:
15+
InpError: SEMANTICS_OPTION_VALUE.
16+
"""
17+
18+
_ATTRS = {
19+
'suffix': types.Integer,
20+
'temperature': tuple[types.Real],
21+
}
22+
23+
_REGEX = re.compile(r'tmp(\S+)( \S+)')
24+
25+
def __init__(self, suffix: types.Integer, temperature: tuple[types.Real]):
26+
"""
27+
Initializes ``Tmp_0``.
28+
29+
Parameters:
30+
suffix: Thermal time index.
31+
temperature: Temperature at time index.
32+
33+
Raises:
34+
InpError: SEMANTICS_OPTION_VALUE.
35+
"""
36+
37+
if suffix is None:
38+
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION_VALUE, suffix)
39+
if temperature is None or not (min(temperature) > 0):
40+
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION_VALUE, temperature)
41+
42+
self.value: typing.Final[types.Tuple] = types.Tuple(
43+
[
44+
temperature,
45+
]
46+
)
47+
48+
self.suffix: typing.Final[types.Integer] = suffix
49+
self.temperature: typing.Final[tuple[types.Real]] = temperature

src/pymcnp/inp/cell/Tmp_1.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import re
2+
import typing
3+
4+
5+
from .option_ import CellOption_
6+
from ...utils import types
7+
from ...utils import errors
8+
9+
10+
class Tmp_1(CellOption_, keyword='tmp'):
11+
"""
12+
Represents INP tmp_1 elements.
13+
14+
Attributes:
15+
InpError: SEMANTICS_OPTION_VALUE.
16+
"""
17+
18+
_ATTRS = {
19+
'temperature': tuple[types.Real],
20+
}
21+
22+
_REGEX = re.compile(r'tmp( \S+)')
23+
24+
def __init__(self, temperature: tuple[types.Real]):
25+
"""
26+
Initializes ``Tmp_1``.
27+
28+
Parameters:
29+
temperature: Temperature at time index.
30+
31+
Raises:
32+
InpError: SEMANTICS_OPTION_VALUE.
33+
"""
34+
35+
if temperature is None or not (min(temperature) > 0):
36+
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION_VALUE, temperature)
37+
38+
self.value: typing.Final[types.Tuple] = types.Tuple(
39+
[
40+
temperature,
41+
]
42+
)
43+
44+
self.temperature: typing.Final[tuple[types.Real]] = temperature

src/pymcnp/inp/cell/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
from .Lat import Lat
1717
from .Fill_0 import Fill_0
1818
from .Fill_1 import Fill_1
19+
from .Fill_2 import Fill_2
1920
from .Elpt import Elpt
21+
from .Tmp_0 import Tmp_0
22+
from .Tmp_1 import Tmp_1
2023
from .Cosy import Cosy
2124
from .Bflcl import Bflcl
2225
from .Unc import Unc
@@ -39,7 +42,10 @@
3942
'Lat',
4043
'Fill_0',
4144
'Fill_1',
45+
'Fill_2',
4246
'Elpt',
47+
'Tmp_0',
48+
'Tmp_1',
4349
'Cosy',
4450
'Bflcl',
4551
'Unc',

src/pymcnp/inp/cell/option_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class CellOption_(Option_):
1414
_KEYWORD = ''
1515
_SUBCLASSES = {}
1616
_REGEX = re.compile(
17-
rf'bflcl( \S+)|nonu( \S+)|trcl( \S+)|trcl( {types.TransformationEntry._REGEX.pattern})|fill( \S+)( \S+)?|fill( \S+)( {types.TransformationEntry._REGEX.pattern})?|elpt:(\S+)( \S+)|cosy( \S+)|imp:(\S+)( \S+)|vol( \S+)|pwt( \S+)|ext:(\S+)( \S+)|fcl:(\S+)( \S+)|wwn(\S+):(\S+)( \S+)|dxc(\S+):(\S+)( \S+)|tmp(\S+)( \S+)|lat( \S+)|unc:(\S+)( \S+)|pd(\S+)( \S+)|u( \S+)'
17+
rf'bflcl( \S+)|nonu( \S+)|trcl( \S+)|trcl( {types.TransformationEntry._REGEX.pattern})|fill( \S+)( \S+)?|fill( \S+)( {types.TransformationEntry._REGEX.pattern})?|fill( {types.IndexEntry._REGEX.pattern})( {types.IndexEntry._REGEX.pattern})( {types.IndexEntry._REGEX.pattern})(( \S+)+)|elpt:(\S+)( \S+)|cosy( \S+)|imp:(\S+)( \S+)|vol( \S+)|pwt( \S+)|ext:(\S+)( \S+)|fcl:(\S+)( \S+)|wwn(\S+):(\S+)( \S+)|dxc(\S+):(\S+)( \S+)|tmp(\S+)( \S+)|lat( \S+)|tmp(\S+)( \S+)|tmp( \S+)|unc:(\S+)( \S+)|pd(\S+)( \S+)|u( \S+)'
1818
)
1919

2020
def __init_subclass__(cls, keyword: str):

src/pymcnp/inp/data/C_0.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import re
2+
import typing
3+
4+
5+
from .option_ import DataOption_
6+
from ...utils import types
7+
from ...utils import errors
8+
9+
10+
class C_0(DataOption_, keyword='c'):
11+
"""
12+
Represents INP c_0 elements.
13+
14+
Attributes:
15+
InpError: SEMANTICS_OPTION_VALUE.
16+
"""
17+
18+
_ATTRS = {
19+
'suffix': types.Integer,
20+
'bounds': types.Tuple[types.Real],
21+
't': types.String,
22+
'c': types.String,
23+
}
24+
25+
_REGEX = re.compile(r'c(\S+)(( \S+)+)( \S+)?( \S+)?')
26+
27+
def __init__(
28+
self,
29+
suffix: types.Integer,
30+
bounds: types.Tuple[types.Real],
31+
t: types.String = None,
32+
c: types.String = None,
33+
):
34+
"""
35+
Initializes ``C_0``.
36+
37+
Parameters:
38+
suffix: Data card option suffix.
39+
bounds: Upper cosine bounds for bin.
40+
t: Notation to provide totals.
41+
c: Notation to make bin values cumulative.
42+
43+
Raises:
44+
InpError: SEMANTICS_OPTION_VALUE.
45+
"""
46+
47+
if suffix is None:
48+
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION_VALUE, suffix)
49+
if bounds is None:
50+
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION_VALUE, bounds)
51+
52+
self.value: typing.Final[types.Tuple] = types.Tuple(
53+
[
54+
bounds,
55+
t,
56+
c,
57+
]
58+
)
59+
60+
self.suffix: typing.Final[types.Integer] = suffix
61+
self.bounds: typing.Final[types.Tuple[types.Real]] = bounds
62+
self.t: typing.Final[types.String] = t
63+
self.c: typing.Final[types.String] = c

src/pymcnp/inp/data/C_1.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import re
2+
import typing
3+
4+
5+
from .option_ import DataOption_
6+
from ...utils import types
7+
from ...utils import errors
8+
9+
10+
class C_1(DataOption_, keyword='[*]c'):
11+
"""
12+
Represents INP c_1 elements.
13+
14+
Attributes:
15+
InpError: SEMANTICS_OPTION_VALUE.
16+
"""
17+
18+
_ATTRS = {
19+
'suffix': types.Integer,
20+
'bounds': types.Tuple[types.Real],
21+
't': types.String,
22+
'c': types.String,
23+
}
24+
25+
_REGEX = re.compile(r'[*]c(\S+)(( \S+)+)( \S+)?( \S+)?')
26+
27+
def __init__(
28+
self,
29+
suffix: types.Integer,
30+
bounds: types.Tuple[types.Real],
31+
t: types.String = None,
32+
c: types.String = None,
33+
):
34+
"""
35+
Initializes ``C_1``.
36+
37+
Parameters:
38+
suffix: Data card option suffix.
39+
bounds: Upper angle limit for bin.
40+
t: Notation to provide totals.
41+
c: Notation to make bin values cumulative.
42+
43+
Raises:
44+
InpError: SEMANTICS_OPTION_VALUE.
45+
"""
46+
47+
if suffix is None:
48+
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION_VALUE, suffix)
49+
if bounds is None or not (bounds[-1] == 0 and max(bounds) <= 180):
50+
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION_VALUE, bounds)
51+
52+
self.value: typing.Final[types.Tuple] = types.Tuple(
53+
[
54+
bounds,
55+
t,
56+
c,
57+
]
58+
)
59+
60+
self.suffix: typing.Final[types.Integer] = suffix
61+
self.bounds: typing.Final[types.Tuple[types.Real]] = bounds
62+
self.t: typing.Final[types.String] = t
63+
self.c: typing.Final[types.String] = c
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from ...utils import errors
88

99

10-
class Df(DataOption_, keyword='df'):
10+
class Df_0(DataOption_, keyword='df'):
1111
"""
12-
Represents INP df elements.
12+
Represents INP df_0 elements.
1313
1414
Attributes:
1515
InpError: SEMANTICS_OPTION_VALUE.
@@ -27,7 +27,7 @@ def __init__(
2727
self, suffix: types.Integer, method: types.String, values: types.Tuple[types.Real]
2828
):
2929
"""
30-
Initializes ``Df``.
30+
Initializes ``Df_0``.
3131
3232
Parameters:
3333
suffix: Data card option suffix.

src/pymcnp/inp/data/Df_1.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import re
2+
import typing
3+
4+
5+
from . import df_1
6+
from .option_ import DataOption_
7+
from ...utils import types
8+
from ...utils import errors
9+
10+
11+
class Df_1(DataOption_, keyword='df'):
12+
"""
13+
Represents INP df_1 elements.
14+
15+
Attributes:
16+
InpError: SEMANTICS_OPTION_VALUE.
17+
"""
18+
19+
_ATTRS = {
20+
'suffix': types.Integer,
21+
'options': types.Tuple[df_1.Df_1Option_],
22+
}
23+
24+
_REGEX = re.compile(rf'df(\S+)(( ({df_1.Df_1Option_._REGEX.pattern}))+)')
25+
26+
def __init__(self, suffix: types.Integer, options: types.Tuple[df_1.Df_1Option_]):
27+
"""
28+
Initializes ``Df_1``.
29+
30+
Parameters:
31+
suffix: Data card option suffix.
32+
options: Dictionary of options.
33+
34+
Raises:
35+
InpError: SEMANTICS_OPTION_VALUE.
36+
"""
37+
38+
if suffix is None or not (suffix <= 99_999_999):
39+
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION_VALUE, suffix)
40+
if options is None:
41+
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION_VALUE, options)
42+
43+
self.value: typing.Final[types.Tuple] = types.Tuple(
44+
[
45+
options,
46+
]
47+
)
48+
49+
self.suffix: typing.Final[types.Integer] = suffix
50+
self.options: typing.Final[types.Tuple[df_1.Df_1Option_]] = options

0 commit comments

Comments
 (0)