Skip to content

Commit c7becbb

Browse files
committed
inp: added support for vertical data cards
1 parent 0e08e9d commit c7becbb

7 files changed

Lines changed: 117 additions & 93 deletions

File tree

files/inp/example_00.inp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ c source cards
6262
c ============================================================
6363
mode n p
6464
nps 1e6
65-
c rand seed = 71129329235055
65+
rand seed = 71129329235055
6666
c source definition
6767
sdef par=n erg=14.05
6868
c tally information

files/inp/example_01.inp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ c source cards
6262
c ============================================================
6363
mode n p
6464
nps 1e7
65-
c rand seed = 71129329235055
65+
rand seed = 71129329235055
6666
c source definition
6767
sdef par=n erg=14.05
6868
c tally information

files/inp/example_03.inp

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -43,72 +43,72 @@ c burst packets=32
4343
c capture gate=380 us
4444
c sigma packets=3
4545
c sdef par=n erg=14 TME=D1<D2
46-
c # SI1 SP1
47-
c 0 0
48-
c 10e2 1
49-
c 35e2 0
50-
c 45e2 1
51-
c 70e2 0
52-
c 80e2 1
53-
c 105e2 0
54-
c 115e2 1
55-
c 140e2 0
56-
c 150e2 1
57-
c 175e2 0
58-
c 185e2 1
59-
c 210e2 0
60-
c 220e2 1
61-
c 245e2 0
62-
c 255e2 1
63-
c 280e2 0
64-
c 290e2 1
65-
c 315e2 0
66-
c 325e2 1
67-
c 350e2 0
68-
c 360e2 1
69-
c 385e2 0
70-
c 395e2 1
71-
c 420e2 0
72-
c 430e2 1
73-
c 455e2 0
74-
c 465e2 1
75-
c 490e2 0
76-
c 500e2 1
77-
c 525e2 0
78-
c 535e2 1
79-
c 560e2 0
80-
c 570e2 1
81-
c 595e2 0
82-
c 605e2 1
83-
c 630e2 0
84-
c 640e2 1
85-
c 665e2 0
86-
c 675e2 1
87-
c 700e2 0
88-
c 710e2 1
89-
c 735e2 0
90-
c 745e2 1
91-
c 770e2 0
92-
c 780e2 1
93-
c 805e2 0
94-
c 815e2 1
95-
c 840e2 0
96-
c 850e2 1
97-
c 875e2 0
98-
c 885e2 1
99-
c 910e2 0
100-
c 920e2 1
101-
c 945e2 0
102-
c 955e2 1
103-
c 980e2 0
104-
c 990e2 1
105-
c 1015e2 0
106-
c 1025e2 1
107-
c 1050e2 0
108-
c 1060e2 1
109-
c 1085e2 0
110-
c 1095e2 1
111-
c 1500e2 0
46+
# SI1 SP1
47+
0 0
48+
10e2 1
49+
35e2 0
50+
45e2 1
51+
70e2 0
52+
80e2 1
53+
105e2 0
54+
115e2 1
55+
140e2 0
56+
150e2 1
57+
175e2 0
58+
185e2 1
59+
210e2 0
60+
220e2 1
61+
245e2 0
62+
255e2 1
63+
280e2 0
64+
290e2 1
65+
315e2 0
66+
325e2 1
67+
350e2 0
68+
360e2 1
69+
385e2 0
70+
395e2 1
71+
420e2 0
72+
430e2 1
73+
455e2 0
74+
465e2 1
75+
490e2 0
76+
500e2 1
77+
525e2 0
78+
535e2 1
79+
560e2 0
80+
570e2 1
81+
595e2 0
82+
605e2 1
83+
630e2 0
84+
640e2 1
85+
665e2 0
86+
675e2 1
87+
700e2 0
88+
710e2 1
89+
735e2 0
90+
745e2 1
91+
770e2 0
92+
780e2 1
93+
805e2 0
94+
815e2 1
95+
840e2 0
96+
850e2 1
97+
875e2 0
98+
885e2 1
99+
910e2 0
100+
920e2 1
101+
945e2 0
102+
955e2 1
103+
980e2 0
104+
990e2 1
105+
1015e2 0
106+
1025e2 1
107+
1050e2 0
108+
1060e2 1
109+
1085e2 0
110+
1095e2 1
111+
1500e2 0
112112
SI2 0 4500e2
113113
SP2 0 1
114114
c ===============================================================

files/inp/valid_10.inp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ lattice example 18
3030
12 cz 0.1
3131

3232
c sdef erg=d1 cel=d2:d3:0 rad=d5 ext=d6 axs=0 0 1 pos=d7
33-
c # si1 sp1 sb1
34-
c 1 0 0
35-
c 3 0.22 0.05
36-
c 4 0.08 0.05
37-
c 5 0.25 0.1
38-
c 6 0.18 0.1
39-
c 7 0.07 0.2
40-
c 8 0.1 0.2
41-
c 9 0.05 0.1
42-
c 11 0.05 0.2
33+
# si1 sp1 sb1
34+
1 0 0
35+
3 0.22 0.05
36+
4 0.08 0.05
37+
5 0.25 0.1
38+
6 0.18 0.1
39+
7 0.07 0.2
40+
8 0.1 0.2
41+
9 0.05 0.1
42+
11 0.05 0.2
4343
si2 L 2 3 4 5 6
4444
sp2 1 1 1 1 1
4545
si3 L 8 9 10

files/inp/valid_36.inp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ rand seed = 71129329235055
5858
c source definition
5959
c
6060
c sdef par=n erg=14 TME=D1<D2
61-
c # SI1 SP1
62-
c 0 0
63-
c 1000 1
64-
c 20000 0
65-
c # SI2 SP2
66-
c 0 0
67-
c 20000 1
61+
# SI1 SP1
62+
0 0
63+
1000 1
64+
20000 0
65+
# SI2 SP2
66+
0 0
67+
20000 1
6868
F4:n 200
6969
T4 0 99i 20000
7070
c end of file

files/inp/valid_37.inp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ rand seed = 71129329235055
5858
c source definition
5959
c
6060
c sdef par=n erg=14 TME=D1<D2
61-
c # SI1 SP1
62-
c 0 0
63-
c 1000 1
64-
c 20000 0
65-
c # SI2 SP2
66-
c 0 0
67-
c 20000 1
61+
# SI1 SP1
62+
0 0
63+
1000 1
64+
20000 0
65+
# SI2 SP2
66+
0 0
67+
20000 1
6868
F4:n 200
6969
T4 0 99i 20000
7070
E4 0 5 14

src/pymcnp/utils/_parser.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,36 @@
55
""" Preprocessing Functions """
66

77

8+
def _preprocess_vertical(string: str):
9+
""" """
10+
11+
tokens = re.split(r'\n(#(?: \S+)+\n(?: *\d\S*(?: +\S+)+\n)+)', string)
12+
13+
string = ''
14+
for token in tokens:
15+
if (match := re.match(r'#((?: \S+)+)\n((?: *\d\S*(?: +\S+)+\n)+)', token)):
16+
cards = re.split(r'\s+', match[1])[1:]
17+
rows = [[card] for card in cards]
18+
19+
lines = match[2].split('\n')[:-1]
20+
for line in lines:
21+
parameters = re.split(r'\s+', line)
22+
for parameter, row in zip(parameters, rows):
23+
row.append(parameter)
24+
25+
string += '\n' + '\n'.join([' '.join(row) for row in rows]) + '\n'
26+
else:
27+
string += token
28+
29+
return string
30+
831
def _preprocess_horizontal(string: str):
932
""" """
1033

1134
tokens = re.split(r'( \d+j)', string)
1235

1336
string = ''
14-
for i, token in enumerate(tokens):
37+
for token in tokens:
1538
if match := re.match(r'( \d+)j', token):
1639
string += int(match[1]) * ' j'
1740
else:
@@ -71,6 +94,7 @@ def _preprocess_comments(string: str):
7194
def preprocess_inp(string: str):
7295
""" """
7396

97+
string = _preprocess_vertical(string)
7498
string, comments = _preprocess_comments(string)
7599
string = _preprocess_case(string)
76100
string = _preprocess_whitespace(string)

0 commit comments

Comments
 (0)