-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from zhieejhia93/compare-results-example
Demonstration on how to extract results from multiple runs and save in one CSV file
- Loading branch information
Showing
4 changed files
with
446 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Example1d - MOOSE/SAM Plugin | ||
|
||
## Purpose | ||
|
||
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. | ||
|
||
## Code(s) | ||
|
||
- SAM | ||
|
||
## Keywords | ||
|
||
- Parametric study | ||
- Results extraction | ||
- Post-processing | ||
|
||
## File descriptions | ||
|
||
- [__example1d.py__](example1d.py): WATTS workflow for this example. This is the file to execute to run the problem described above. | ||
- [__sam_template__](sam_template): SAM templated input file. | ||
- [__results.csv__](results.csv): An example of CSV file that will be generated through running this example. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# SPDX-FileCopyrightText: 2022 UChicago Argonne, LLC | ||
# SPDX-License-Identifier: MIT | ||
|
||
""" | ||
This example demonstrates how to use WATTS to perform | ||
multiple runs and extract selected results from the runs. | ||
The demonstration includes an approach to save selected | ||
results from different runs into a single CSV file for | ||
ease of comparison, visualization, and post-processing. | ||
This demonstration uses SAM with a single PbCoreChannel | ||
with inlet and outlet boundary conditions. The input | ||
power of the channel is varied. The simulation is run | ||
as transient where the end time is varied to artificially | ||
create results of different lengths to show that the | ||
output CSV file can accept columns of different lengths. | ||
""" | ||
|
||
from math import cos, pi | ||
import os | ||
import watts | ||
import pandas as pd | ||
from astropy.units import Quantity | ||
|
||
|
||
params = watts.Parameters() | ||
|
||
# Input parameters to template file | ||
|
||
params['He_inlet_temp'] = Quantity(600, "Celsius") # 873.15 K | ||
params['He_outlet_temp'] = Quantity(850, "Celsius") # 1123.15 K | ||
params['He_cp'] = Quantity(4.9184126, "BTU/(kg*K)") # 5189.2 J/kg-K | ||
params['He_K'] = 0.32802 # W/m-K | ||
params['He_density'] = 3.8815 # kg/m3 | ||
params['He_viscosity'] = 4.16e-5 # Pa.s | ||
params['He_Pressure'] = Quantity(1015.264164, "psi") # 7e6 Pa | ||
params['num_cool_pins'] = 1*6 + 2*6 + 6*2/2 | ||
params['num_fuel_pins'] = 6 + 6 + 6 + 3*6 + 2*6/2 + 6/3 | ||
params['Height_FC'] = Quantity(2000, "mm") # Automatically converts to 'm' for MOOSE and 'cm' for openmc | ||
params['Lattice_pitch'] = 2.0 | ||
params['FuelPin_rad'] = 0.90 # cm | ||
params['cool_hole_rad'] = 0.60 # cm | ||
params['Coolant_channel_diam'] = (params['cool_hole_rad'] * 2)/100 # in m | ||
params['Graphite_thickness'] = (params['Lattice_pitch'] - params['FuelPin_rad'] - params['cool_hole_rad']) # cm | ||
|
||
params.show_summary(show_metadata=False, sort_by='key') | ||
|
||
# MOOSE Workflow | ||
moose_app_type = "SAM" | ||
app_dir = os.environ[moose_app_type.upper() + "_DIR"] | ||
|
||
power = [100_000, 250_000, 300_000, 400_000, 500_000] # Watts | ||
endtime = [50, 100, 100, 50, 50] # End time is varied to artificially create results of different lengths. | ||
results_dict = {} # Create empty dictionary | ||
for i in range(len(power)): | ||
params['Tot_assembly_power'] = power[i] | ||
params['endtime'] = endtime[i] | ||
|
||
# Execute WATTS | ||
moose_plugin = watts.PluginMOOSE(moose_app_type.lower() + '_template') # show all the output | ||
moose_plugin.moose_exec = app_dir + "/" + moose_app_type.lower() + "-opt" | ||
moose_result = moose_plugin(params) | ||
|
||
# Add items to dictionary. | ||
results_dict[f'time_{i+1}'] = moose_result.csv_data['time'] | ||
results_dict[f'max_Tcoolant_{i+1}'] = moose_result.csv_data['max_Tcoolant'] | ||
results_dict[f'max_Tw_{i+1}'] = moose_result.csv_data['max_Tw'] | ||
|
||
# Store dictionary items as dataframe. Columns of unequal lengths are padded with NaN. | ||
df = pd.DataFrame({k: pd.Series(v) for k, v in results_dict.items()}) | ||
|
||
# Sort column names alphabetically and save as CSV file | ||
df.sort_index(axis=1).to_csv('results.csv') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
,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 | ||
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 | ||
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 | ||
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 | ||
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 | ||
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 | ||
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 | ||
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 | ||
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 | ||
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 | ||
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 | ||
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 | ||
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 | ||
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 | ||
13,,901.13250000791,904.11762199167,,,,908.19431753527,912.88091825956,,,,68.759576141834,68.759576141834,, | ||
14,,905.73962467973,908.73622781101,,,,914.73933284292,919.70515198246,,,,86.949470177293,86.949470177293,, | ||
15,,908.48960529517,911.3980152664,,,,918.79654965452,923.80513538894,,,,100.0,100.0,, |
Oops, something went wrong.