Skip to content

Commit 36d961b

Browse files
committed
utils: refactored types & errors
1 parent 2fc2004 commit 36d961b

1,233 files changed

Lines changed: 31225 additions & 30759 deletions

File tree

Some content is hidden

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

examples/create_inp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
RADIUS_LEAD: float = 1
1010

1111
# Creating cell geometries.
12-
geometry_air = pymcnp.utils.types.Geometry('11')
13-
geometry_shield = pymcnp.utils.types.Geometry('12')
14-
geometry_lead = pymcnp.utils.types.Geometry('13')
15-
geometry_world = pymcnp.utils.types.Geometry('14')
12+
geometry_air = pymcnp.inp.cell.Geometry('11')
13+
geometry_shield = pymcnp.inp.cell.Geometry('12')
14+
geometry_lead = pymcnp.inp.cell.Geometry('13')
15+
geometry_world = pymcnp.inp.cell.Geometry('14')
1616

1717
# Creating cells.
1818
cell_air = pymcnp.inp.Cell(number=1, material=21, density=0.5, geometry=geometry_air)

scripts/inp_data.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def __init__(
141141
),
142142
AttributeScheme(
143143
name='geometry',
144-
type='types.Geometry',
144+
type='cell.Geometry',
145145
description='cell geometry',
146146
restriction='# TODO #',
147147
),
@@ -6182,7 +6182,7 @@ def from_formula(number: int, formulas: dict[str, float], is_weight: bool = True
61826182
attributes=[
61836183
AttributeScheme(
61846184
name='energy',
6185-
type='types.DistributionNumber',
6185+
type='types.Distribution',
61866186
description='Kinetic energy',
61876187
),
61886188
],
@@ -6204,7 +6204,7 @@ def from_formula(number: int, formulas: dict[str, float], is_weight: bool = True
62046204
attributes=[
62056205
AttributeScheme(
62066206
name='time',
6207-
type='types.EmbeddedDistributionNumber',
6207+
type='types.EmbeddedDistribution',
62086208
description='Time in shakes',
62096209
),
62106210
],
@@ -6227,7 +6227,7 @@ def from_formula(number: int, formulas: dict[str, float], is_weight: bool = True
62276227
attributes=[
62286228
AttributeScheme(
62296229
name='cosine',
6230-
type='types.DistributionNumber',
6230+
type='types.Distribution',
62316231
description='Cosine of the angle between VEC and particle',
62326232
optional=True,
62336233
),
@@ -6293,7 +6293,7 @@ def from_formula(number: int, formulas: dict[str, float], is_weight: bool = True
62936293
attributes=[
62946294
AttributeScheme(
62956295
name='radial_distance',
6296-
type='types.DistributionNumber',
6296+
type='types.Distribution',
62976297
description='Radial distance fo the position from POS or AXS',
62986298
),
62996299
],
@@ -6551,7 +6551,7 @@ def from_formula(number: int, formulas: dict[str, float], is_weight: bool = True
65516551
),
65526552
AttributeScheme(
65536553
name='information',
6554-
type='types.Tuple[types.DistributionNumber]',
6554+
type='types.Tuple[types.Distribution]',
65556555
description='Particle source information',
65566556
),
65576557
],
@@ -6977,7 +6977,7 @@ def to_mcnp(self):
69776977
attributes=[
69786978
AttributeScheme(
69796979
name='number',
6980-
type='types.DistributionNumber',
6980+
type='types.Distribution',
69816981
description='Particle weight',
69826982
),
69836983
],
@@ -7022,7 +7022,7 @@ def to_mcnp(self):
70227022
attributes=[
70237023
AttributeScheme(
70247024
name='number',
7025-
type='types.DistributionNumber',
7025+
type='types.Distribution',
70267026
description='Distribution number for baising sampling',
70277027
),
70287028
],

scripts/inp_tests.py

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

src/pymcnp/Inp.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import re
22

33
from . import inp
4-
from .utils import types
5-
from .utils import errors
4+
from . import types
5+
from . import errors
66
from .utils import _parser
77
from .utils import _object
88
from .utils import _visualization
@@ -61,14 +61,14 @@ def from_mcnp(source: str):
6161
``Inp``.
6262
6363
Raises:
64-
InpError: SYNTAX_INP.
64+
InpError: SYNTAX_FILE.
6565
"""
6666

6767
source, comments = _parser.preprocess_inp(source)
6868
tokens = Inp._REGEX.match(source)
6969

7070
if not tokens:
71-
raise errors.InpError(errors.InpCode.SYNTAX_INP, source)
71+
raise errors.InpError(errors.InpCode.SYNTAX_FILE, source)
7272

7373
message = types.String.from_mcnp(tokens[1]) if tokens[1] else None
7474
title = types.String.from_mcnp(tokens[2])
@@ -192,7 +192,7 @@ def title(self, title: str | types.String) -> None:
192192
title = types.String.from_mcnp(title)
193193

194194
if title is None or not len(title) < 80:
195-
raise errors.InpError(errors.InpCode.SEMANTICS_INP, title)
195+
raise errors.InpError(errors.InpCode.SEMANTICS_FILE, title)
196196

197197
self._title: types.Integer = title
198198

@@ -245,7 +245,7 @@ def cells(self, cells: list[str] | list[inp.Cell | inp.Like | inp.Comment]) -> N
245245
cells = types.Tuple(array)
246246

247247
if cells is None or None in cells:
248-
raise errors.InpError(errors.InpCode.SEMANTICS_INP, cells)
248+
raise errors.InpError(errors.InpCode.SEMANTICS_FILE, cells)
249249

250250
self._cells: types.Integer = cells
251251

@@ -292,7 +292,7 @@ def surfaces(self, surfaces: list[str] | list[inp.Surface | inp.Comment]) -> Non
292292
surfaces = types.Tuple(array)
293293

294294
if surfaces is None or None in surfaces:
295-
raise errors.InpError(errors.InpCode.SEMANTICS_INP, surfaces)
295+
raise errors.InpError(errors.InpCode.SEMANTICS_FILE, surfaces)
296296

297297
self._surfaces: types.Integer = surfaces
298298

@@ -340,7 +340,7 @@ def data(self, data: list[str] | list[inp.Data | inp.Comment]) -> None:
340340
data = types.Tuple(array)
341341

342342
if data is None or None in data:
343-
raise errors.InpError(errors.InpCode.SEMANTICS_INP, data)
343+
raise errors.InpError(errors.InpCode.SEMANTICS_FILE, data)
344344

345345
self._data: types.Integer = data
346346

src/pymcnp/Meshtal.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import typing
33

44
from . import meshtal
5-
from .utils import errors
5+
from . import errors
66
from .utils import _object
77

88

@@ -29,15 +29,15 @@ def __init__(self, header: meshtal.Header, tallies: typing.Generator[meshtal.Tal
2929
``Meshtal``.
3030
3131
Raises:
32-
MeshtalError: SEMANTICS_MESHTAL_HEADER.
33-
MeshtalError: SEMANTICS_MESHTAL_TALLIES.
32+
MeshtalError: SEMANTICS_FILE_HEADER.
33+
MeshtalError: SEMANTICS_FILE_TALLIES.
3434
"""
3535

3636
if header is None:
37-
raise errors.MeshtalError(errors.MeshtalCode.SEMANTICS_MESHTAL)
37+
raise errors.MeshtalError(errors.MeshtalCode.SEMANTICS_FILE)
3838

3939
if tallies is None:
40-
raise errors.MeshtalError(errors.MeshtalCode.SEMANTICS_MESHTAL)
40+
raise errors.MeshtalError(errors.MeshtalCode.SEMANTICS_FILE)
4141

4242
self.header: typing.Final[meshtal.Header] = header
4343
self.tallies: typing.Final[typing.Generator[typing.Generator[meshtal.Tally, None, None]]] = tallies
@@ -57,7 +57,7 @@ def from_mcnp(source: str):
5757
tokens = Meshtal._REGEX.match(source)
5858

5959
if not tokens:
60-
raise errors.MeshtalError(errors.MeshtalCode.SYNTAX_MESHTAL, source)
60+
raise errors.MeshtalError(errors.MeshtalCode.SYNTAX_FILE, source)
6161

6262
header = meshtal.Header.from_mcnp(tokens[1])
6363
tallies = (meshtal.Tally.from_mcnp(match[0], header) for match in meshtal.Tally._REGEX.finditer(tokens[12]))

src/pymcnp/Outp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44

55
from . import outp
6-
from .utils import types
7-
from .utils import errors
6+
from . import types
7+
from . import errors
88
from .utils import _object
99

1010

@@ -38,10 +38,10 @@ def __init__(
3838
"""
3939

4040
if header is None:
41-
raise errors.OutpError(errors.OutpCode.SEMANTICS_TABLE, header)
41+
raise errors.OutpError(errors.OutpCode.SEMANTICS_FILE, header)
4242

4343
if blocks is None or None in blocks:
44-
raise errors.OutpError(errors.OutpCode.SEMANTICS_TABLE, blocks)
44+
raise errors.OutpError(errors.OutpCode.SEMANTICS_FILE, blocks)
4545

4646
self.header: typing.Final[outp.Header] = header
4747
self.blocks: typing.Final[types.Tuple[outp.Block]] = blocks
@@ -107,6 +107,6 @@ def to_dataframe(self):
107107

108108
for block in self.blocks:
109109
if hasattr(block, 'to_dataframe'):
110-
tallies[block.number.strip()] = block.to_dataframe()
110+
tallies[block.number.value.strip()] = block.to_dataframe()
111111

112112
return tallies

src/pymcnp/Ptrac.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import typing
33

44
from . import ptrac
5-
from .utils import types
6-
from .utils import errors
5+
from . import types
6+
from . import errors
77
from .utils import _object
88

99

@@ -30,14 +30,14 @@ def __init__(self, header: ptrac.Header, histories: typing.Generator[ptrac.Histo
3030
``Ptrac``.
3131
3232
Raises:
33-
PtracError: SEMANTICS_PTRAC.
33+
PtracError: SEMANTICS_FILE.
3434
"""
3535

3636
if header is None:
37-
raise errors.PtracError(errors.PtracCode.SEMANTICS_PTRAC, header)
37+
raise errors.PtracError(errors.PtracCode.SEMANTICS_FILE, header)
3838

3939
if histories is None:
40-
raise errors.PtracError(errors.PtracCode.SEMANTICS_PTRAC, histories)
40+
raise errors.PtracError(errors.PtracCode.SEMANTICS_FILE, histories)
4141

4242
self.header: typing.Final[ptrac.Header] = header
4343
self.histories: typing.Final[typing.Generator[ptrac.History, None, None]] = histories
@@ -54,13 +54,13 @@ def from_mcnp(source: str):
5454
``Ptrac``.
5555
5656
Raises:
57-
PtracError: SYNTAX_PTRAC.
57+
PtracError: SYNTAX_FILE.
5858
"""
5959

6060
tokens = Ptrac._REGEX.match(source)
6161

6262
if not tokens:
63-
raise errors.PtracError(errors.PtracCode.SYNTAX_PTRAC, source)
63+
raise errors.PtracError(errors.PtracCode.SYNTAX_FILE, source)
6464

6565
header = ptrac.Header.from_mcnp(tokens[1])
6666
histories = types.Tuple(ptrac.History.from_mcnp(match[0], header) for match in re.finditer(ptrac.History._REGEX.pattern[2:-2], tokens[10]))

src/pymcnp/__init__.py

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,33 @@
1-
# UTILS
2-
from .utils import types
3-
from .utils import errors
4-
5-
from .cli.run import Run
1+
from . import cli
2+
from . import errors
63
from . import inp
7-
from .Inp import Inp
4+
from . import meshtal
5+
from . import outp
86
from . import ptrac
7+
from . import types
8+
from .Inp import Inp
9+
from .Meshtal import Meshtal
10+
from .Outp import Outp
911
from .Ptrac import Ptrac
1012
from .PtracFiltered import PtracFiltered
1113
from .PtracProcessed import PtracProcessed
12-
from . import meshtal
13-
from .Meshtal import Meshtal
1414
from .MeshtalFiltered import MeshtalFiltered
1515
from .MeshtalProcessed import MeshtalProcessed
1616

17-
from . import outp
18-
from .Outp import Outp
19-
20-
read_input = Inp.from_file
21-
read_ptrac = Ptrac.from_file
22-
read_meshtal = Meshtal.from_file
23-
read_output = Outp.from_file
24-
2517
__all__ = [
26-
'types',
18+
'cli',
2719
'errors',
28-
'Run',
2920
'inp',
30-
'Inp',
21+
'meshtal',
22+
'outp',
3123
'ptrac',
24+
'types',
25+
'Inp',
26+
'Meshtal',
27+
'Outp',
3228
'Ptrac',
3329
'PtracFiltered',
3430
'PtracProcessed',
35-
'meshtal',
36-
'Meshtal',
3731
'MeshtalFiltered',
3832
'MeshtalProcessed',
39-
'outp',
40-
'Outp',
41-
'read_input',
42-
'read_ptrac',
43-
'read_meshtal',
44-
'read_output',
4533
]

src/pymcnp/cli/__init__.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
from .run import Run
2-
from .check import Check
3-
from .convert import Convert
4-
from .plot import Plot
5-
from .visualize import Visualize
1+
from . import Run as run
2+
from . import Check as check
3+
from . import Convert as convert
4+
from . import Plot as plot
5+
from . import Visualize as visualize
6+
from .Run import Run
7+
from .Check import Check
8+
from .Convert import Convert
9+
from .Plot import Plot
10+
from .Visualize import Visualize
611

7-
__all__ = ['Run', 'Check', 'Convert', 'Plot', 'Visualize']
12+
__all__ = ['run', 'check', 'convert', 'plot', 'visualize', 'Run', 'Check', 'Convert', 'Plot', 'Visualize']

src/pymcnp/cli/_doer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Doer:
2+
"""
3+
Represents cli backend classes.
4+
"""
5+
6+
pass

0 commit comments

Comments
 (0)