Skip to content

Commit 7f93f2e

Browse files
committed
tests: added examples from manual 1
1 parent 92fef08 commit 7f93f2e

Some content is hidden

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

54 files changed

+1922
-240
lines changed

scripts/inp_data.py

Lines changed: 46 additions & 38 deletions
Large diffs are not rendered by default.

src/pymcnp/Inp.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,25 @@ class InpBuilder:
250250
message: str = ''
251251
other: str = ''
252252

253+
def from_mcnp(source: str):
254+
"""
255+
Initiailizes ``InpBuilder`` from MCNP.
256+
257+
Attributes:
258+
source: MCNP for ``Inp``.
259+
"""
260+
261+
ast = Inp.from_mcnp(source)
262+
263+
return InpBuilder(
264+
title=ast.title,
265+
cells={cell.number.value: cell for cell in ast.cells},
266+
surfaces={surface.number.value: surface for surface in ast.surfaces},
267+
data={},
268+
message=ast.message,
269+
other=ast.other,
270+
)
271+
253272
def build(self):
254273
"""
255274
Builds ``InpBuilder`` into ``Inp``.

src/pymcnp/inp/_option.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ def from_mcnp(cls, source: str):
4747
for i, (name, attr) in enumerate(subclass._ATTRS.items()):
4848
if isinstance(attr, types.GenericAlias):
4949
attrs[name] = (
50-
attr.from_mcnp(tokens[i + 1], attr.__args__[0]) if tokens[i + 1] else None
50+
attr.from_mcnp(tokens[i + 1].strip(), attr.__args__[0])
51+
if tokens[i + 1]
52+
else None
5153
)
5254
else:
53-
attrs[name] = attr.from_mcnp(tokens[i + 1]) if tokens[i + 1] else None
55+
attrs[name] = attr.from_mcnp(tokens[i + 1].strip()) if tokens[i + 1] else None
5456

5557
return subclass(**attrs)
5658

src/pymcnp/inp/cell/Trcl_0.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, transformation: types.Integer):
3333
InpError: SEMANTICS_OPTION.
3434
"""
3535

36-
if transformation is None or not (1 <= transformation.value <= 999):
36+
if transformation is None or not (0 <= transformation.value <= 999):
3737
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, transformation)
3838

3939
self.value: typing.Final[types.Tuple] = types.Tuple(

src/pymcnp/inp/data/Mt.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,41 @@ class Mt(DataOption):
1414
1515
Attributes:
1616
suffix: Data card option suffix.
17-
identifier: Corresponding S(α,β) identifier.
17+
identifiers: Corresponding S(α,β) identifier.
1818
"""
1919

2020
_ATTRS = {
2121
'suffix': types.Integer,
22-
'identifier': types.String,
22+
'identifiers': types.Tuple[types.String],
2323
}
2424

25-
_REGEX = re.compile(rf'\Amt(\d+)( {types.String._REGEX.pattern})\Z')
25+
_REGEX = re.compile(rf'\Amt(\d+)((?: {types.String._REGEX.pattern})+?)\Z')
2626

27-
def __init__(self, suffix: types.Integer, identifier: types.String):
27+
def __init__(self, suffix: types.Integer, identifiers: types.Tuple[types.String]):
2828
"""
2929
Initializes ``Mt``.
3030
3131
Parameters:
3232
suffix: Data card option suffix.
33-
identifier: Corresponding S(α,β) identifier.
33+
identifiers: Corresponding S(α,β) identifier.
3434
3535
Raises:
3636
InpError: SEMANTICS_OPTION.
3737
"""
3838

3939
if suffix is None:
4040
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, suffix)
41-
if identifier is None:
42-
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, identifier)
41+
if identifiers is None:
42+
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, identifiers)
4343

4444
self.value: typing.Final[types.Tuple] = types.Tuple(
4545
[
46-
identifier,
46+
identifiers,
4747
]
4848
)
4949

5050
self.suffix: typing.Final[types.Integer] = suffix
51-
self.identifier: typing.Final[types.String] = identifier
51+
self.identifiers: typing.Final[types.Tuple[types.String]] = identifiers
5252

5353

5454
@dataclasses.dataclass
@@ -58,11 +58,11 @@ class MtBuilder:
5858
5959
Attributes:
6060
suffix: Data card option suffix.
61-
identifier: Corresponding S(α,β) identifier.
61+
identifiers: Corresponding S(α,β) identifier.
6262
"""
6363

6464
suffix: str | int | types.Integer
65-
identifier: str | types.String
65+
identifiers: list[str] | list[types.String]
6666

6767
def build(self):
6868
"""
@@ -80,13 +80,20 @@ def build(self):
8080
elif isinstance(self.suffix, str):
8181
suffix = types.Integer.from_mcnp(self.suffix)
8282

83-
identifier = self.identifier
84-
if isinstance(self.identifier, types.String):
85-
identifier = self.identifier
86-
elif isinstance(self.identifier, str):
87-
identifier = types.String.from_mcnp(self.identifier)
83+
if self.identifiers:
84+
identifiers = []
85+
for item in self.identifiers:
86+
if isinstance(item, types.String):
87+
identifiers.append(item)
88+
elif isinstance(item, str):
89+
identifiers.append(types.String.from_mcnp(item))
90+
else:
91+
identifiers.append(item.build())
92+
identifiers = types.Tuple(identifiers)
93+
else:
94+
identifiers = None
8895

8996
return Mt(
9097
suffix=suffix,
91-
identifier=identifier,
98+
identifiers=identifiers,
9299
)

src/pymcnp/inp/data/Phys_0.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ def __init__(
6666
InpError: SEMANTICS_OPTION.
6767
"""
6868

69-
if iunr is not None and not (isinstance(iunr, types.Jump) or iunr.value in {0, 1}):
69+
if iunr is not None and not (isinstance(iunr.value, types.Jump) or iunr.value in {0, 1}):
7070
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, iunr)
71-
if ngam is not None and not (isinstance(ngam, types.Jump) or ngam.value in {0, 1, 2}):
71+
if ngam is not None and not (isinstance(ngam.value, types.Jump) or ngam.value in {0, 1, 2}):
7272
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, ngam)
7373
if i_int_model is not None and not (
74-
isinstance(i_int_model, types.Jump) or i_int_model.value in {-1, 0, 1, 2}
74+
isinstance(i_int_model.value, types.Jump) or i_int_model.value in {-1, 0, 1, 2, 3}
7575
):
7676
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, i_int_model)
7777
if i_els_model is not None and not (
78-
isinstance(i_els_model, types.Jump) or i_els_model.value in {-1, 0}
78+
isinstance(i_els_model.value, types.Jump) or i_els_model.value in {-1, 0, 1}
7979
):
8080
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, i_els_model)
8181

src/pymcnp/inp/data/Phys_2.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,29 +90,33 @@ def __init__(
9090
InpError: SEMANTICS_OPTION.
9191
"""
9292

93-
if ides is not None and not (isinstance(ides, types.Jump) or ides.value in {0, 1}):
93+
if ides is not None and not (isinstance(ides.value, types.Jump) or ides.value in {0, 1}):
9494
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, ides)
95-
if iphot is not None and not (isinstance(iphot, types.Jump) or iphot.value in {0, 1}):
95+
if iphot is not None and not (isinstance(iphot.value, types.Jump) or iphot.value in {0, 1}):
9696
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, iphot)
97-
if ibad is not None and not (isinstance(ibad, types.Jump) or ibad.value in {0, 1}):
97+
if ibad is not None and not (isinstance(ibad.value, types.Jump) or ibad.value in {0, 1}):
9898
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, ibad)
99-
if istrg is not None and not (isinstance(istrg, types.Jump) or istrg.value in {0, 1}):
99+
if istrg is not None and not (isinstance(istrg.value, types.Jump) or istrg.value in {0, 1}):
100100
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, istrg)
101-
if xnum is not None and not (isinstance(xnum, types.Jump) or xnum.value >= 0):
101+
if xnum is not None and not (isinstance(xnum.value, types.Jump) or xnum.value >= 0):
102102
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, xnum)
103-
if rnok is not None and not (isinstance(rnok, types.Jump) or rnok.value >= 0):
103+
if rnok is not None and not (isinstance(rnok.value, types.Jump) or rnok.value >= 0):
104104
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, rnok)
105-
if enum is not None and not (isinstance(enum, types.Jump) or enum.value >= 0):
105+
if enum is not None and not (isinstance(enum.value, types.Jump) or enum.value >= 0):
106106
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, enum)
107-
if numb is not None and not (isinstance(numb, types.Jump) or numb.value >= 0):
107+
if numb is not None and not (isinstance(numb.value, types.Jump) or numb.value >= 0):
108108
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, numb)
109109
if i_mcs_model is not None and not (
110-
isinstance(i_mcs_model, types.Jump) or i_mcs_model.value in {-1, 0}
110+
isinstance(i_mcs_model.value, types.Jump) or i_mcs_model.value in {-1, 0}
111111
):
112112
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, i_mcs_model)
113-
if efac is not None and not (isinstance(efac, types.Jump) or 0.8 <= efac.value <= 0.99):
113+
if efac is not None and not (
114+
isinstance(efac.value, types.Jump) or 0.8 <= efac.value <= 0.99
115+
):
114116
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, efac)
115-
if ckvnum is not None and not (isinstance(ckvnum, types.Jump) or 0 <= ckvnum.value < 1):
117+
if ckvnum is not None and not (
118+
isinstance(ckvnum.value, types.Jump) or 0 <= ckvnum.value < 1
119+
):
116120
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, ckvnum)
117121

118122
self.value: typing.Final[types.Tuple] = types.Tuple(

src/pymcnp/inp/data/Phys_3.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,31 +79,35 @@ def __init__(
7979
"""
8080

8181
if tabl is not None and not (
82-
isinstance(tabl, types.Jump) or tabl.value == -1 or tabl.value >= 0
82+
isinstance(tabl.value, types.Jump) or tabl.value == -1 or tabl.value >= 0
8383
):
8484
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, tabl)
85-
if istrg is not None and not (isinstance(istrg, types.Jump) or istrg.value in {0, 1}):
85+
if istrg is not None and not (isinstance(istrg.value, types.Jump) or istrg.value in {0, 1}):
8686
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, istrg)
87-
if recl is not None and not (isinstance(recl, types.Jump) or 0 <= recl.value <= 1):
87+
if recl is not None and not (isinstance(recl.value, types.Jump) or 0 <= recl.value <= 1):
8888
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, recl)
8989
if i_mcs_model is not None and not (
90-
isinstance(i_mcs_model, types.Jump) or i_mcs_model.value in {-1, 0, 1, 2}
90+
isinstance(i_mcs_model.value, types.Jump) or i_mcs_model.value in {-1, 0, 1, 2}
9191
):
9292
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, i_mcs_model)
9393
if i_int_model is not None and not (
94-
isinstance(i_int_model, types.Jump) or i_int_model.value in {-1, 0, 1, 2}
94+
isinstance(i_int_model.value, types.Jump) or i_int_model.value in {-1, 0, 1, 2}
9595
):
9696
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, i_int_model)
9797
if i_els_model is not None and not (
98-
isinstance(i_els_model, types.Jump) or i_els_model.value in {-1, 0}
98+
isinstance(i_els_model.value, types.Jump) or i_els_model.value in {-1, 0}
9999
):
100100
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, i_els_model)
101-
if efac is not None and not (isinstance(efac, types.Jump) or 0.8 <= efac.value <= 0.99):
101+
if efac is not None and not (
102+
isinstance(efac.value, types.Jump) or 0.8 <= efac.value <= 0.99
103+
):
102104
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, efac)
103-
if ckvnum is not None and not (isinstance(ckvnum, types.Jump) or 0 <= ckvnum.value < 1):
105+
if ckvnum is not None and not (
106+
isinstance(ckvnum.value, types.Jump) or 0 <= ckvnum.value < 1
107+
):
104108
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, ckvnum)
105109
if drp is not None and not (
106-
isinstance(drp, types.Jump) or drp.value >= 0 or drp.value == -1
110+
isinstance(drp.value, types.Jump) or drp.value >= 0 or drp.value == -1
107111
):
108112
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, drp)
109113

src/pymcnp/inp/data/Phys_4.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,34 @@ def __init__(
8080

8181
if designator is None:
8282
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, designator)
83-
if istrg is not None and not (isinstance(istrg, types.Jump) or istrg.value in {0, 1}):
83+
if istrg is not None and not (isinstance(istrg.value, types.Jump) or istrg.value in {0, 1}):
8484
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, istrg)
85-
if xmunum is not None and not (isinstance(xmunum, types.Jump) or xmunum.value in {-1, 1}):
85+
if xmunum is not None and not (
86+
isinstance(xmunum.value, types.Jump) or xmunum.value in {-1, 1}
87+
):
8688
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, xmunum)
8789
if i_mcs_model is not None and not (
88-
isinstance(i_mcs_model, types.Jump) or i_mcs_model.value in {-1, 0, 1, 2}
90+
isinstance(i_mcs_model.value, types.Jump) or i_mcs_model.value in {-1, 0, 1, 2}
8991
):
9092
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, i_mcs_model)
9193
if i_int_model is not None and not (
92-
isinstance(i_int_model, types.Jump) or i_int_model.value in {-1, 0, 1, 2}
94+
isinstance(i_int_model.value, types.Jump) or i_int_model.value in {-1, 0, 1, 2}
9395
):
9496
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, i_int_model)
9597
if i_els_model is not None and not (
96-
isinstance(i_els_model, types.Jump) or i_els_model.value in {-1, 0}
98+
isinstance(i_els_model.value, types.Jump) or i_els_model.value in {-1, 0}
9799
):
98100
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, i_els_model)
99-
if efac is not None and not (isinstance(efac, types.Jump) or 0.8 <= efac.value <= 0.99):
101+
if efac is not None and not (
102+
isinstance(efac.value, types.Jump) or 0.8 <= efac.value <= 0.99
103+
):
100104
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, efac)
101-
if ckvnum is not None and not (isinstance(ckvnum, types.Jump) or 0 <= ckvnum.value < 1):
105+
if ckvnum is not None and not (
106+
isinstance(ckvnum.value, types.Jump) or 0 <= ckvnum.value < 1
107+
):
102108
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, ckvnum)
103109
if drp is not None and not (
104-
isinstance(drp, types.Jump) or drp.value >= 0 or drp.value == -1
110+
isinstance(drp.value, types.Jump) or drp.value >= 0 or drp.value == -1
105111
):
106112
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, drp)
107113

src/pymcnp/inp/data/df_1/Fac.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self, normalization: types.Integer):
3434
"""
3535

3636
if normalization is None or not (
37-
isinstance(normalization, types.Jump) or normalization.value >= -3
37+
isinstance(normalization.value, types.Jump) or normalization.value >= -3
3838
):
3939
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, normalization)
4040

0 commit comments

Comments
 (0)