55from SerpentCellCard import SerpentCellCard , write_serpent_cell
66from SerpentMaterialCard import SerpentMaterialCard , write_serpent_material
77
8+ import logging
9+ import re
10+
811class SerpentInput (InputDeck ):
912 """ SerpentInput class - does the actual processing
1013 """
@@ -13,12 +16,91 @@ class SerpentInput(InputDeck):
1316 def __init__ (self ,filename = "" ):
1417 InputDeck .__init__ (self ,filename )
1518
16- # def from_input(self,InputDeckClass):
17- # InputDeck.filename = InputDeckClass.filename
18- # InputDeck.title = InputDeckClass.title
19- # InputDeck.cell_list = InputDeckClass.cell_list
20- # InputDeck.surfcace_list = InputDeckClass.surface_list
21- # return
19+ # extract a material card from the start line until
20+ def __get_material_card (self , start_line , mat_num ):
21+ # we already know that the start line has an mat name
22+ idx = start_line
23+ tokens = self .file_lines [idx ].split ()
24+ mat_name = tokens [1 ]
25+ # set the material name
26+
27+ mat_density = float (tokens [2 ])
28+
29+ # build the first mat string
30+ material_string = ' '
31+ idx += 1
32+
33+ while True :
34+ # if at the end of the file
35+ if idx == len (self .file_lines ):
36+ break
37+ while True :
38+ # its possible that we will have advanced to the end of the
39+ # file
40+ if (idx == len (self .file_lines )):
41+ break
42+ if ('mat' == self .file_lines [idx ].split ()[0 ]):
43+ break
44+ line = self .file_lines [idx ]
45+ if '%' in line :
46+ pos = line .find ('%' )
47+ line = line [:pos ]
48+ material_string += line
49+ # increment the line that we are looking at
50+ idx += 1
51+ break
52+
53+ material = SerpentMaterialCard (mat_num , mat_name , mat_density , material_string )
54+
55+ self .material_list [material .material_number ] = material
56+
57+
58+ return
59+
60+ # get the material cards definitions
61+ def __get_material_cards (self ):
62+
63+ idx = 0
64+ mat_num = 1
65+ while True :
66+ if idx == len (self .file_lines ):
67+ break
68+
69+ # this crazy makes sure that we find an "mat " in the line
70+ if re .match (" *mat /*" ,self .file_lines [idx ]):
71+ logging .debug ("%s" , "material found on line " + str (idx ))
72+ self .__get_material_card (idx , mat_num )
73+ mat_num += 1
74+ idx += 1
75+ return
76+
77+
78+ # process the serpent input deck and read into a generic datastructure
79+ # that we can translate to other formats
80+ def process (self ):
81+
82+ # clear out the comment and white space cards
83+ idx = 0
84+ while True :
85+ if idx == len (self .file_lines ):
86+ break
87+ if self .file_lines [idx ].isspace ():
88+ del self .file_lines [idx ]
89+ elif self .file_lines [idx ].strip ().startswith ("%" ):
90+ del self .file_lines [idx ]
91+ else :
92+ idx += 1
93+
94+ if logging .getLogger ().isEnabledFor (logging .DEBUG ):
95+ logging .debug ("%s" , "Input Echo" )
96+ for idx ,line in enumerate (self .file_lines ):
97+ logging .debug ("%i %s" ,idx ,line )
98+
99+ self .__get_material_cards ()
100+
101+ # raise NotImplementedError('Serpent input files are not fully supported yet')
102+
103+ return
22104
23105 # Write the Serpent Cell definitions
24106 def __write_serpent_cells (self , filestream ):
0 commit comments