Skip to content

Commit 8c49f63

Browse files
committed
inp: fixed cell parser bugs
1 parent 36e3a0e commit 8c49f63

Some content is hidden

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

100 files changed

+4796
-127
lines changed

scripts/inp_data.py

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,22 @@ def __init__(
306306
name='number',
307307
type='types.Integer',
308308
description='Cell universe number',
309-
restriction='number >= -9 and number <= 99_999_999',
309+
restriction='number == 10000000000 or (number >= -9 and number <= 99_999_999)',
310310
),
311311
),
312312
),
313313
ElementScheme(
314314
name='trcl_0',
315315
mnemonic='trcl',
316+
regex='([*])?trcl( {types.Integer._REGEX.pattern[2:-2]})',
316317
attributes=(
318+
AttributeScheme(
319+
name='prefix',
320+
type='types.String',
321+
description='Star prefix',
322+
restriction='prefix in {"*"}',
323+
optional=True,
324+
),
317325
AttributeScheme(
318326
name='transformation',
319327
type='types.Integer',
@@ -325,7 +333,15 @@ def __init__(
325333
ElementScheme(
326334
name='trcl_1',
327335
mnemonic='trcl',
336+
regex='([*])?trcl( {types.Transformation_0._REGEX.pattern[2:-2]})',
328337
attributes=[
338+
AttributeScheme(
339+
name='prefix',
340+
type='types.String',
341+
description='Star prefix',
342+
restriction='prefix in {"*"}',
343+
optional=True,
344+
),
329345
AttributeScheme(
330346
name='transformation',
331347
type='types.Transformation_0',
@@ -336,7 +352,15 @@ def __init__(
336352
ElementScheme(
337353
name='trcl_2',
338354
mnemonic='trcl',
355+
regex='([*])?trcl( {types.Transformation_1._REGEX.pattern[2:-2]})',
339356
attributes=[
357+
AttributeScheme(
358+
name='prefix',
359+
type='types.String',
360+
description='Star prefix',
361+
restriction='prefix in {"*"}',
362+
optional=True,
363+
),
340364
AttributeScheme(
341365
name='transformation',
342366
type='types.Transformation_1',
@@ -347,7 +371,15 @@ def __init__(
347371
ElementScheme(
348372
name='trcl_3',
349373
mnemonic='trcl',
374+
regex='([*])?trcl( {types.Transformation_2._REGEX.pattern[2:-2]})',
350375
attributes=[
376+
AttributeScheme(
377+
name='prefix',
378+
type='types.String',
379+
description='Star prefix',
380+
restriction='prefix in {"*"}',
381+
optional=True,
382+
),
351383
AttributeScheme(
352384
name='transformation',
353385
type='types.Transformation_2',
@@ -358,7 +390,15 @@ def __init__(
358390
ElementScheme(
359391
name='trcl_4',
360392
mnemonic='trcl',
393+
regex='([*])?trcl( {types.Transformation_3._REGEX.pattern[2:-2]})',
361394
attributes=[
395+
AttributeScheme(
396+
name='prefix',
397+
type='types.String',
398+
description='Star prefix',
399+
restriction='prefix in {"*"}',
400+
optional=True,
401+
),
362402
AttributeScheme(
363403
name='transformation',
364404
type='types.Transformation_3',
@@ -369,7 +409,15 @@ def __init__(
369409
ElementScheme(
370410
name='trcl_5',
371411
mnemonic='trcl',
412+
regex='([*])?trcl( {types.Transformation_4._REGEX.pattern[2:-2]})',
372413
attributes=[
414+
AttributeScheme(
415+
name='prefix',
416+
type='types.String',
417+
description='Star prefix',
418+
restriction='prefix in {"*"}',
419+
optional=True,
420+
),
373421
AttributeScheme(
374422
name='transformation',
375423
type='types.Transformation_4',
@@ -447,7 +495,7 @@ def __init__(
447495
name='universe',
448496
type='types.Integer',
449497
description='Cell fill universe number',
450-
restriction='universe >= 0 and universe <= 99_999_999',
498+
restriction='universe == 10000000000 or (universe >= 0 and universe <= 99_999_999)',
451499
),
452500
AttributeScheme(
453501
name='transformation',
@@ -474,7 +522,7 @@ def __init__(
474522
name='universe',
475523
type='types.Integer',
476524
description='Cell fill universe number',
477-
restriction='universe >= 0 and universe <= 99_999_999',
525+
restriction='universe == 10000000000 or (universe >= 0 and universe <= 99_999_999)',
478526
),
479527
AttributeScheme(
480528
name='transformation',
@@ -501,7 +549,7 @@ def __init__(
501549
name='universe',
502550
type='types.Integer',
503551
description='Cell fill universe number',
504-
restriction='universe >= 0 and universe <= 99_999_999',
552+
restriction='universe == 10000000000 or (universe >= 0 and universe <= 99_999_999)',
505553
),
506554
AttributeScheme(
507555
name='transformation',
@@ -528,7 +576,7 @@ def __init__(
528576
name='universe',
529577
type='types.Integer',
530578
description='Cell fill universe number',
531-
restriction='universe >= 0 and universe <= 99_999_999',
579+
restriction='universe == 10000000000 or (universe >= 0 and universe <= 99_999_999)',
532580
),
533581
AttributeScheme(
534582
name='transformation',
@@ -555,7 +603,7 @@ def __init__(
555603
name='universe',
556604
type='types.Integer',
557605
description='Cell fill universe number',
558-
restriction='universe >= 0 and universe <= 99_999_999',
606+
restriction='universe == 10000000000 or (universe >= 0 and universe <= 99_999_999)',
559607
),
560608
AttributeScheme(
561609
name='transformation',
@@ -582,7 +630,7 @@ def __init__(
582630
name='universe',
583631
type='types.Integer',
584632
description='Cell fill universe number',
585-
restriction='universe >= 0 and universe <= 99_999_999',
633+
restriction='universe == 10000000000 or (universe >= 0 and universe <= 99_999_999)',
586634
),
587635
AttributeScheme(
588636
name='transformation',

src/pymcnp/Inp.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ def from_mcnp(source: str):
130130
try:
131131
cells.append(inp.Like.from_mcnp(line))
132132
continue
133-
except errors.InpError as err:
134-
print(err)
133+
except errors.InpError:
135134
pass
136135

137136
cells.append(inp.Cell.from_mcnp(line))

src/pymcnp/inp/Cell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Cell(Card):
3030
'options': types.Tuple[cell.CellOption],
3131
}
3232

33-
_REGEX = re.compile(rf'\A(\S+)( \S+)((?<! 0) \S+|(?<= 0))( [^a-z]+)( ({cell.CellOption._REGEX.pattern[2:-2]}))*\Z')
33+
_REGEX = re.compile(rf'\A(\S+)( \S+)((?<! 0) \S+|(?<= 0))( [^a-z]+)((?: (?:{cell.CellOption._REGEX.pattern[2:-2]}))+?)?\Z')
3434

3535
def __init__(
3636
self,

src/pymcnp/inp/Like.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import dataclasses
44

55

6-
from . import cell
6+
from . import like
77
from ._card import Card
88
from ..utils import types
99
from ..utils import errors
@@ -23,16 +23,16 @@ class Like(Card):
2323
_ATTRS = {
2424
'number': types.Integer,
2525
'original': types.Integer,
26-
'options': types.Tuple[cell.CellOption],
26+
'options': types.Tuple[like.LikeOption],
2727
}
2828

29-
_REGEX = re.compile(rf'\A(\S+) like (\S+) but( ({cell.CellOption._REGEX.pattern[2:-2]}))*\Z')
29+
_REGEX = re.compile(rf'\A(\S+) like (\S+) but((?: (?:{like.LikeOption._REGEX.pattern[2:-2]}))+?)?\Z')
3030

3131
def __init__(
3232
self,
3333
number: types.Integer,
3434
original: types.Integer,
35-
options: types.Tuple[cell.CellOption] = None,
35+
options: types.Tuple[like.LikeOption] = None,
3636
):
3737
"""
3838
Initializes ``Like``.
@@ -50,12 +50,10 @@ def __init__(
5050
raise errors.InpError(errors.InpCode.SEMANTICS_CARD, number)
5151
if original is None or not (1 <= original <= 99_999_999):
5252
raise errors.InpError(errors.InpCode.SEMANTICS_CARD, original)
53-
if options is not None and None in options:
54-
raise errors.InpError(errors.InpCode.SEMANTICS_CARD, options)
5553

5654
self.number: types.Integer = number
5755
self.original: types.Integer = original
58-
self.options: types.Tuple[cell.CellOption] = options
56+
self.options: types.Tuple[like.LikeOption] = options
5957

6058
def to_mcnp(self):
6159
"""
@@ -85,7 +83,7 @@ class LikeBuilder:
8583

8684
number: str | int | types.Integer
8785
original: str | int | types.Integer
88-
options: list[str] | list[cell.CellOption] | list[cell.CellOptionBuilder] = None
86+
options: list[str] | list[like.LikeOption] | list[like.LikeOptionBuilder] = None
8987

9088
def build(self):
9189
"""
@@ -114,11 +112,11 @@ def build(self):
114112
if self.options:
115113
options = []
116114
for item in self.options:
117-
if isinstance(item, cell.CellOption):
115+
if isinstance(item, like.LikeOption):
118116
options.append(item)
119117
elif isinstance(item, str):
120-
options.append(cell.CellOption.from_mcnp(item))
121-
elif isinstance(item, cell.CellOptionBuilder):
118+
options.append(like.LikeOption.from_mcnp(item))
119+
elif isinstance(item, like.LikeOptionBuilder):
122120
options.append(item.build())
123121
options = types.Tuple(options)
124122
else:

src/pymcnp/inp/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from ._card import Card
22
from ._option import Option
33
from . import cell
4+
from . import like
45
from . import surface
56
from . import data
67
from .Cell import Cell
@@ -18,6 +19,7 @@
1819
'Card',
1920
'Option',
2021
'cell',
22+
'like',
2123
'surface',
2224
'data',
2325
'Cell',

src/pymcnp/inp/cell/Fill_1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self, universe: types.Integer, prefix: types.String = None, transfo
4444

4545
if prefix is not None and prefix not in {'*'}:
4646
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, prefix)
47-
if universe is None or not (universe >= 0 and universe <= 99_999_999):
47+
if universe is None or not (universe == 10000000000 or (universe >= 0 and universe <= 99_999_999)):
4848
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, universe)
4949

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

src/pymcnp/inp/cell/Fill_2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self, universe: types.Integer, prefix: types.String = None, transfo
4444

4545
if prefix is not None and prefix not in {'*'}:
4646
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, prefix)
47-
if universe is None or not (universe >= 0 and universe <= 99_999_999):
47+
if universe is None or not (universe == 10000000000 or (universe >= 0 and universe <= 99_999_999)):
4848
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, universe)
4949

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

src/pymcnp/inp/cell/Fill_3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self, universe: types.Integer, prefix: types.String = None, transfo
4444

4545
if prefix is not None and prefix not in {'*'}:
4646
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, prefix)
47-
if universe is None or not (universe >= 0 and universe <= 99_999_999):
47+
if universe is None or not (universe == 10000000000 or (universe >= 0 and universe <= 99_999_999)):
4848
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, universe)
4949

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

src/pymcnp/inp/cell/Fill_4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self, universe: types.Integer, prefix: types.String = None, transfo
4444

4545
if prefix is not None and prefix not in {'*'}:
4646
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, prefix)
47-
if universe is None or not (universe >= 0 and universe <= 99_999_999):
47+
if universe is None or not (universe == 10000000000 or (universe >= 0 and universe <= 99_999_999)):
4848
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, universe)
4949

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

src/pymcnp/inp/cell/Fill_5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self, universe: types.Integer, prefix: types.String = None, transfo
4444

4545
if prefix is not None and prefix not in {'*'}:
4646
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, prefix)
47-
if universe is None or not (universe >= 0 and universe <= 99_999_999):
47+
if universe is None or not (universe == 10000000000 or (universe >= 0 and universe <= 99_999_999)):
4848
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, universe)
4949

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

0 commit comments

Comments
 (0)