Skip to content

Commit 3f8b812

Browse files
authored
Merge pull request #28 from zhieejhia93/compare-results-example
Demonstration on how to extract results from multiple runs and save in one CSV file
2 parents fb9dc17 + 6aa2180 commit 3f8b812

4 files changed

Lines changed: 446 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Example1d - MOOSE/SAM Plugin
2+
3+
## Purpose
4+
5+
This example provides a demonstration on how to use WATTS to perform multiple runs and save selected outputs from all runs to a single '.csv' file for ease of comparison, post-processing, and visualization.
6+
7+
## Code(s)
8+
9+
- SAM
10+
11+
## Keywords
12+
13+
- Parametric study
14+
- Results extraction
15+
- Post-processing
16+
17+
## File descriptions
18+
19+
- [__example1d.py__](example1d.py): WATTS workflow for this example. This is the file to execute to run the problem described above.
20+
- [__sam_template__](sam_template): SAM templated input file.
21+
- [__results.csv__](results.csv): An example of CSV file that will be generated through running this example.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# SPDX-FileCopyrightText: 2022 UChicago Argonne, LLC
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
This example demonstrates how to use WATTS to perform
6+
multiple runs and extract selected results from the runs.
7+
The demonstration includes an approach to save selected
8+
results from different runs into a single CSV file for
9+
ease of comparison, visualization, and post-processing.
10+
This demonstration uses SAM with a single PbCoreChannel
11+
with inlet and outlet boundary conditions. The input
12+
power of the channel is varied. The simulation is run
13+
as transient where the end time is varied to artificially
14+
create results of different lengths to show that the
15+
output CSV file can accept columns of different lengths.
16+
"""
17+
18+
from math import cos, pi
19+
import os
20+
import watts
21+
import pandas as pd
22+
from astropy.units import Quantity
23+
24+
25+
params = watts.Parameters()
26+
27+
# Input parameters to template file
28+
29+
params['He_inlet_temp'] = Quantity(600, "Celsius") # 873.15 K
30+
params['He_outlet_temp'] = Quantity(850, "Celsius") # 1123.15 K
31+
params['He_cp'] = Quantity(4.9184126, "BTU/(kg*K)") # 5189.2 J/kg-K
32+
params['He_K'] = 0.32802 # W/m-K
33+
params['He_density'] = 3.8815 # kg/m3
34+
params['He_viscosity'] = 4.16e-5 # Pa.s
35+
params['He_Pressure'] = Quantity(1015.264164, "psi") # 7e6 Pa
36+
params['num_cool_pins'] = 1*6 + 2*6 + 6*2/2
37+
params['num_fuel_pins'] = 6 + 6 + 6 + 3*6 + 2*6/2 + 6/3
38+
params['Height_FC'] = Quantity(2000, "mm") # Automatically converts to 'm' for MOOSE and 'cm' for openmc
39+
params['Lattice_pitch'] = 2.0
40+
params['FuelPin_rad'] = 0.90 # cm
41+
params['cool_hole_rad'] = 0.60 # cm
42+
params['Coolant_channel_diam'] = (params['cool_hole_rad'] * 2)/100 # in m
43+
params['Graphite_thickness'] = (params['Lattice_pitch'] - params['FuelPin_rad'] - params['cool_hole_rad']) # cm
44+
45+
params.show_summary(show_metadata=False, sort_by='key')
46+
47+
# MOOSE Workflow
48+
moose_app_type = "SAM"
49+
app_dir = os.environ[moose_app_type.upper() + "_DIR"]
50+
51+
power = [100_000, 250_000, 300_000, 400_000, 500_000] # Watts
52+
endtime = [50, 100, 100, 50, 50] # End time is varied to artificially create results of different lengths.
53+
results_dict = {} # Create empty dictionary
54+
for i in range(len(power)):
55+
params['Tot_assembly_power'] = power[i]
56+
params['endtime'] = endtime[i]
57+
58+
# Execute WATTS
59+
moose_plugin = watts.PluginMOOSE(moose_app_type.lower() + '_template') # show all the output
60+
moose_plugin.moose_exec = app_dir + "/" + moose_app_type.lower() + "-opt"
61+
moose_result = moose_plugin(params)
62+
63+
# Add items to dictionary.
64+
results_dict[f'time_{i+1}'] = moose_result.csv_data['time']
65+
results_dict[f'max_Tcoolant_{i+1}'] = moose_result.csv_data['max_Tcoolant']
66+
results_dict[f'max_Tw_{i+1}'] = moose_result.csv_data['max_Tw']
67+
68+
# Store dictionary items as dataframe. Columns of unequal lengths are padded with NaN.
69+
df = pd.DataFrame({k: pd.Series(v) for k, v in results_dict.items()})
70+
71+
# Sort column names alphabetically and save as CSV file
72+
df.sort_index(axis=1).to_csv('results.csv')
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
,max_Tcoolant_1,max_Tcoolant_2,max_Tcoolant_3,max_Tcoolant_4,max_Tcoolant_5,max_Tw_1,max_Tw_2,max_Tw_3,max_Tw_4,max_Tw_5,time_1,time_2,time_3,time_4,time_5
2+
0,873.15,873.15,873.15,873.15,873.15,873.15,873.15,873.15,873.15,873.15,0.0,0.0,0.0,0.0,0.0
3+
1,873.27104921286,873.43810086872,873.49065886366,873.59190621014,873.68855640385,873.28161009639,873.47591550168,873.53971354419,873.6657615605,873.7896951253,1.0,1.0,1.0,1.0,1.0
4+
2,873.48915321747,873.9513668803,874.09593841533,874.37324679071,874.63647787688,873.51686111721,874.05654234752,874.23313339839,874.58105473883,874.92183964822,2.25,2.25,2.25,2.25,2.25
5+
3,873.82194978879,874.72504661291,875.00506845726,875.5387550794,876.04104528075,873.87516282324,874.93590423349,875.28112249024,875.95831774038,876.61762676121,3.8125,3.8125,3.8125,3.8125,3.8125
6+
4,874.27343475392,875.76106198183,876.21726964285,877.07976558,877.88289449909,874.36231506049,876.12245829945,876.69120874201,877.80054902349,878.87213773414,5.765625,5.765625,5.765625,5.765625,5.765625
7+
5,874.8538848479,877.072824014,877.74430707176,879.00161116296,880.15757781373,874.9909666925,877.63884368919,878.48680672732,880.12907283705,881.70016989853,8.20703125,8.20703125,8.20703125,8.20703125,8.20703125
8+
6,875.58194423382,878.68797653503,879.6130093482,881.3253473059,882.87623449571,875.78317170824,879.52634436555,880.71180351804,882.9878448061,885.13979476113,11.2587890625,11.2587890625,11.2587890625,11.2587890625,11.2587890625
9+
7,876.48369397379,880.64317642372,881.85817511776,884.07669579887,886.05063536445,876.76999121326,881.84077515653,883.42452242952,886.43296758297,889.23702430754,15.073486328125,15.073486328125,15.073486328125,15.073486328125,15.073486328125
10+
8,877.5927620808,882.97994877943,884.51660469873,887.27655011714,889.68059765118,877.99223601368,884.64955696936,886.69273029612,890.52305326699,894.03146484253,19.841857910156,19.841857910156,19.841857910156,19.841857910156,19.841857910156
11+
9,878.95013382982,885.73874050643,887.61906534972,890.92940430644,893.73981639644,879.50107263029,888.02652607666,890.58562219037,895.30551850243,899.53698863573,25.802322387695,25.802322387695,25.802322387695,25.802322387695,25.802322387695
12+
10,880.60272774206,888.94902754307,891.17792354183,895.00734023247,898.15881886507,881.35755047396,892.04158649905,895.15952401279,900.79445261705,905.71548203674,33.252902984619,33.252902984619,33.252902984619,33.252902984619,33.252902984619
13+
11,882.600872861,892.61628293266,895.17176620727,899.43319984754,902.81105744982,883.63123864771,896.74533494383,900.43727507456,906.94441899222,912.45034622658,42.566128730774,42.566128730774,42.566128730774,42.566128730774,42.566128730774
14+
12,884.14251784475,896.70680642053,899.52935202219,902.48897213256,905.92375655658,885.40785598488,902.14783346776,906.38370510318,911.32509412447,917.11376520378,50.0,54.207660913467,54.207660913467,50.0,50.0
15+
13,,901.13250000791,904.11762199167,,,,908.19431753527,912.88091825956,,,,68.759576141834,68.759576141834,,
16+
14,,905.73962467973,908.73622781101,,,,914.73933284292,919.70515198246,,,,86.949470177293,86.949470177293,,
17+
15,,908.48960529517,911.3980152664,,,,918.79654965452,923.80513538894,,,,100.0,100.0,,

0 commit comments

Comments
 (0)