1212
1313from saltproc import SerpentDepcode , OpenMCDepcode , Simulation , Reactor
1414from saltproc import Process , Sparger , Separator , Materialflow
15- from . _schema_default import DefaultValidatingValidator
15+ from _schema_default import DefaultValidatingValidator
1616
1717
18+ _codename_map = {'serpent' : SerpentDepcode ,
19+ 'openmc' : OpenMCDepcode }
20+
1821def run ():
1922 """ Inititializes main run"""
2023 nodes , cores , saltproc_input = parse_arguments ()
@@ -152,42 +155,40 @@ def read_main_input(main_inp_file):
152155
153156 input_schema = (Path (__file__ ).parents [0 ] / 'input_schema.json' )
154157 with open (main_inp_file ) as f :
155- obj = json .load (f )
158+ input_parameters = json .load (f )
156159 with open (input_schema ) as s :
157160 schema = json .load (s )
158161 try :
159- DefaultValidatingValidator (schema ).validate (obj )
162+ DefaultValidatingValidator (schema ).validate (input_parameters )
160163 #jsonschema.validate(instance=j, schema=v)
161164 except jsonschema .exceptions .ValidationError :
162165 print ("Your input file is improperly structured.\
163166 Please see saltproc/tests/test.json for an example." )
164167
165- j = obj
166- print (j ['reactor' ]['timestep_type' ])
167168 # Global input path
168169 input_path = (Path .cwd () / Path (f .name ).parents [0 ])
169170
170171 # Saltproc settings
171172 process_file = str ((input_path /
172- j ['proc_input_file' ]).resolve ())
173+ input_parameters ['proc_input_file' ]).resolve ())
173174 dot_file = str ((
174175 input_path /
175- j ['dot_input_file' ]).resolve ())
176- output_path = j ['output_path' ]
177- n_depletion_steps = j ['n_depletion_steps' ]
176+ input_parameters ['dot_input_file' ]).resolve ())
177+ output_path = input_parameters ['output_path' ]
178+ n_depletion_steps = input_parameters ['n_depletion_steps' ]
178179
179180 # Global output path
180181 output_path = (input_path / output_path )
181- j ['output_path' ] = output_path .resolve ()
182+ input_parameters ['output_path' ] = output_path .resolve ()
182183
183184 # Create output directoy if it doesn't exist
184- if not Path (j ['output_path' ]).exists ():
185- Path (j ['output_path' ]).mkdir (parents = True )
185+ if not Path (input_parameters ['output_path' ]).exists ():
186+ Path (input_parameters ['output_path' ]).mkdir (parents = True )
186187
187188 # Class settings
188- depcode_input = j ['depcode' ]
189- simulation_input = j ['simulation' ]
190- reactor_input = j ['reactor' ]
189+ depcode_input = input_parameters ['depcode' ]
190+ simulation_input = input_parameters ['simulation' ]
191+ reactor_input = input_parameters ['reactor' ]
191192
192193 depcode_input ['codename' ] = depcode_input ['codename' ].lower ()
193194 if depcode_input ['codename' ] == 'serpent' :
@@ -243,21 +244,12 @@ def _print_simulation_input_info(simulation_input, depcode_input):
243244def _create_depcode_object (depcode_input ):
244245 """Helper function for `run()` """
245246 codename = depcode_input .pop ('codename' )
246- if codename == 'serpent' :
247- depcode = SerpentDepcode
248- elif codename == 'openmc' :
249- depcode = OpenMCDepcode
250- chain_file_path = depcode_input .pop ('chain_file_path' )
251- depletion_settings = depcode_input .pop ('depletion_settings' )
252- else :
253- raise ValueError (
254- f'{ codename } is not a supported depletion code.'
255- 'Accepts: "serpent" or "openmc".' )
247+ depcode = _codename_map [codename ]
256248
257249 depcode = depcode (** depcode_input )
258250 if codename == 'openmc' :
259- depcode .chain_file_path = chain_file_path
260- depcode .depletion_settings = depletion_settings
251+ depcode .chain_file_path = depcode_input . pop ( ' chain_file_path' )
252+ depcode .depletion_settings = depcode_input . pop ( ' depletion_settings' )
261253
262254 depcode_input ['codename' ] = codename
263255
@@ -298,11 +290,10 @@ def _process_main_input_reactor_params(reactor_input, n_depletion_steps, codenam
298290 raise ValueError ('There must be a positive integer number'
299291 ' of depletion steps. Provided'
300292 f' n_depletion_steps: { n_depletion_steps } ' )
301- else :
302- if len (depletion_timesteps ) == 1 :
303- depletion_timesteps = depletion_timesteps * n_depletion_steps
304- if len (power_levels ) == 1 :
305- power_levels = power_levels * n_depletion_steps
293+ if len (depletion_timesteps ) == 1 :
294+ depletion_timesteps = depletion_timesteps * n_depletion_steps
295+ if len (power_levels ) == 1 :
296+ power_levels = power_levels * n_depletion_steps
306297
307298 if len (depletion_timesteps ) != len (power_levels ):
308299 raise ValueError ('depletion_timesteps and power_levels length mismatch:'
@@ -323,7 +314,7 @@ def _process_main_input_reactor_params(reactor_input, n_depletion_steps, codenam
323314 depletion_timesteps /= 60 * 24
324315 elif timestep_units in ('h' , 'hr' , 'hour' ):
325316 depletion_timesteps /= 24
326- elif timestep_units in ('a' , 'year' ):
317+ elif timestep_units in ('a' , 'year' , 'yr' ):
327318 depletion_timesteps *= 365.25
328319 else :
329320 raise IOError (f'Unrecognized time unit: { timestep_units } ' )
0 commit comments