|
14 | 14 | # permissions and limitations under the License.
|
15 | 15 | ########################################################################
|
16 | 16 | """
|
17 |
| -date: 2022-01-20 |
| 17 | +date: 2022-12-19 |
18 | 18 | author: matz
|
19 |
| -Main DASSH calculation procedure |
| 19 | +Main DASSH calculation procedures |
20 | 20 | """
|
21 | 21 | ########################################################################
|
22 | 22 | import os
|
23 | 23 | import sys
|
24 |
| -import dassh |
| 24 | +import numpy as np |
25 | 25 | import argparse
|
26 | 26 | import cProfile
|
27 | 27 | import logging
|
| 28 | +import dassh |
28 | 29 | _log_info = 20 # logging levels must be int
|
29 | 30 |
|
30 | 31 |
|
@@ -216,6 +217,7 @@ def _run_dassh(dassh_inp, args, timestep, wdir, link=None):
|
216 | 217 | # Perform the sweep
|
217 | 218 | dassh_logger.log(_log_info, 'Performing temperature sweep...')
|
218 | 219 | reactor.temperature_sweep(verbose=args['verbose'])
|
| 220 | + reactor.postprocess() |
219 | 221 |
|
220 | 222 | # Post-processing: write output, save reactor if desired
|
221 | 223 | dassh_logger.log(_log_info, 'Temperature sweep complete')
|
@@ -278,5 +280,66 @@ def plot():
|
278 | 280 | dassh_logger.log(_log_info, 'DASSH_PLOT execution complete')
|
279 | 281 |
|
280 | 282 |
|
| 283 | +def integrate_pin_power(args=None): |
| 284 | + """Set up DASSH Reactor object, integrate pin power, and write to CSV""" |
| 285 | + # Get input file from command line arguments |
| 286 | + parser = argparse.ArgumentParser(description='Process DASSH cmd') |
| 287 | + parser.add_argument('inputfile', |
| 288 | + metavar='inputfile', |
| 289 | + help='The input file to run with DASSH') |
| 290 | + parser.add_argument('--save_reactor', |
| 291 | + action='store_true', |
| 292 | + help='Save DASSH Reactor object after sweep') |
| 293 | + args = parser.parse_args(args) |
| 294 | + |
| 295 | + # Initiate logger |
| 296 | + print(dassh._ascii._ascii_title) |
| 297 | + in_path = os.path.split(args.inputfile)[0] |
| 298 | + dassh_logger = dassh.logged_class.init_root_logger(in_path, 'dassh_power') |
| 299 | + |
| 300 | + # Pre-processing |
| 301 | + # Read input file and set up DASSH input object |
| 302 | + dassh_logger.log(_log_info, f'Reading input: {args.inputfile}') |
| 303 | + dassh_input = dassh.DASSHPower_Input(args.inputfile) |
| 304 | + |
| 305 | + # Initialize the Reactor object |
| 306 | + reactor = dassh.Reactor(dassh_input, write_output=False) |
| 307 | + |
| 308 | + # Generate pin power distributions |
| 309 | + dassh_logger.log(_log_info, 'Generating pin power distributions...') |
| 310 | + asm_ids = [] |
| 311 | + n_pins = [] |
| 312 | + integrated_pin_powers = [] |
| 313 | + for a in reactor.assemblies: |
| 314 | + if a.has_rodded: |
| 315 | + asm_ids.append(a.id) |
| 316 | + n_pins.append(a.rodded.n_pin) |
| 317 | + integrated_pin_powers.append( |
| 318 | + dassh.power._integrate_pin_power(a.power)) |
| 319 | + |
| 320 | + # Save reactor if desired |
| 321 | + dassh_logger.log(_log_info, 'Saving data') |
| 322 | + if args.save_reactor: |
| 323 | + if sys.version_info < (3, 7): |
| 324 | + handlers = dassh_logger.handlers[:] |
| 325 | + for handler in handlers: |
| 326 | + handler.close() |
| 327 | + dassh_logger.removeHandler(handler) |
| 328 | + reactor.save() |
| 329 | + if sys.version_info < (3, 7): |
| 330 | + dassh_logger = dassh.logged_class.init_root_logger( |
| 331 | + os.path.split(dassh_logger._root_logfile_path)[0], |
| 332 | + 'dassh', 'a+') |
| 333 | + |
| 334 | + # Write distributions to CSV |
| 335 | + arr_to_write = np.zeros((max(n_pins) + 1, len(asm_ids))) |
| 336 | + arr_to_write[0] = asm_ids |
| 337 | + for col in range(arr_to_write.shape[1]): |
| 338 | + arr_to_write[1:(n_pins[col] + 1), col] = integrated_pin_powers[col] |
| 339 | + outpath = os.path.join(dassh_input.path, 'total_pin_power.csv') |
| 340 | + np.savetxt(outpath, arr_to_write, delimiter=',') |
| 341 | + dassh_logger.log(_log_info, 'DASSH_POWER execution complete') |
| 342 | + |
| 343 | + |
281 | 344 | if __name__ == '__main__':
|
282 | 345 | main()
|
0 commit comments