Skip to content

Commit

Permalink
Allow executable to be specified in PluginMOOSE constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
paulromano committed Nov 4, 2022
1 parent d7ed191 commit 14f0424
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 51 deletions.
17 changes: 10 additions & 7 deletions examples/1App_BISON_MetalFuel/watts_exec.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# SPDX-FileCopyrightText: 2022 UChicago Argonne, LLC
# SPDX-License-Identifier: MIT

from math import cos, pi
from pathlib import Path
import os

import watts

params = watts.Parameters()
Expand Down Expand Up @@ -38,12 +39,14 @@
params.show_summary(show_metadata=False, sort_by='key')

# MOOSE Workflow
# set your BISON directorate as BISON_DIR

moose_app_type = "bison"
app_dir = os.environ[moose_app_type.upper() + "_DIR"]
moose_plugin = watts.PluginMOOSE('bison_template', show_stdout=True) # show all the output
moose_plugin.executable = app_dir + "/" + moose_app_type.lower() + "-opt"
# set your BISON directory as BISON_DIR

app_dir = Path(os.environ["BISON_DIR"])
moose_plugin = watts.PluginMOOSE(
'bison_template',
executable=app_dir / 'bison-opt',
show_stdout=True
)
moose_result = moose_plugin(params, mpi_args=['mpiexec', '-n', '2'])
for key in moose_result.csv_data:
print(key, moose_result.csv_data[key])
Expand Down
18 changes: 11 additions & 7 deletions examples/1App_MOOSE-MultiApp_Simple/watts_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
# SPDX-License-Identifier: MIT

"""
This example provides a demonstration on how to use WATTS to perform a simple simulation leveraging MOOSE's MultiApps system.
This example provides a demonstration on how to use WATTS to perform a simple
simulation leveraging MOOSE's MultiApps system.
"""

from math import cos, pi
from pathlib import Path
import os

import watts

params = watts.Parameters()
Expand All @@ -18,12 +20,14 @@
params.show_summary(show_metadata=False, sort_by='key')

# MOOSE Workflow
# set your BISON directorate as BISON_DIR
# set your BISON directory as BISON_DIR

moose_app_type = "bison"
app_dir = os.environ[moose_app_type.upper() + "_DIR"]
moose_plugin = watts.PluginMOOSE('main.tmpl', extra_inputs=['main_in.e', 'sub.i'])
moose_plugin.executable = app_dir + "/" + moose_app_type.lower() + "-opt"
app_dir = Path(os.environ["BISON_DIR"])
moose_plugin = watts.PluginMOOSE(
'main.tmpl',
executable=app_dir / 'bison-opt',
extra_inputs=['main_in.e', 'sub.i']
)
moose_result = moose_plugin(params)
for key in moose_result.csv_data:
print(key, moose_result.csv_data[key])
Expand Down
10 changes: 5 additions & 5 deletions examples/1App_SAM_VHTR/watts_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

from math import cos, pi
import os
from pathlib import Path

import watts
from astropy.units import Quantity

Expand Down Expand Up @@ -52,12 +54,10 @@
params.show_summary(show_metadata=False, sort_by='key')

# MOOSE Workflow
# set your SAM directorate as SAM_DIR
# set your SAM directory as SAM_DIR

moose_app_type = "SAM"
app_dir = os.environ[moose_app_type.upper() + "_DIR"]
moose_plugin = watts.PluginMOOSE(moose_app_type.lower() + '_template') # show all the output
moose_plugin.executable = app_dir + "/" + moose_app_type.lower() + "-opt"
app_dir = Path(os.environ["SAM_DIR"])
moose_plugin = watts.PluginMOOSE('sam_template', executable=app_dir / 'sam-opt')
moose_result = moose_plugin(params)
for key in moose_result.csv_data:
print(key, moose_result.csv_data[key])
Expand Down
15 changes: 9 additions & 6 deletions examples/Main_SAM-OpenMC_VHTR/watts_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
sensitivity analyses.
"""

from pathlib import Path
from math import cos, pi
import os
import watts
from statistics import mean, stdev
from statistics import mean
from openmc_template import build_openmc_model

params = watts.Parameters()
Expand Down Expand Up @@ -64,11 +65,13 @@ def calc_workflow(X):
print("FuelPin_rad / cool_hole_rad", X[0], X[1])

# MOOSE Workflow
# set your SAM directorate as SAM_DIR
moose_app_type = "SAM"
app_dir = os.environ[moose_app_type.upper() + "_DIR"]
sam_plugin = watts.PluginMOOSE('../1App_SAM_VHTR/sam_template', show_stderr=False) # does not show anything
sam_plugin.executable = app_dir + "/" + moose_app_type.lower() + "-opt"
# set your SAM directory as SAM_DIR
app_dir = Path(os.environ["SAM_DIR"])
sam_plugin = watts.PluginMOOSE(
'../1App_SAM_VHTR/sam_template',
executable=app_dir / 'sam-opt',
show_stderr=False
)
sam_result = sam_plugin(params)
max_Tf = max(sam_result.csv_data[f'max_Tf_{i}'][-1] for i in range(1, 6))
avg_Tf = mean(sam_result.csv_data[f'avg_Tf_{i}'][-1] for i in range(1, 6))
Expand Down
15 changes: 9 additions & 6 deletions examples/MultiApp_SAM-OpenMC_VHTR/watts_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
in the params database.
"""

from pathlib import Path
from math import cos, pi
import os
import watts
Expand Down Expand Up @@ -70,12 +71,14 @@


# MOOSE Workflow
# set your SAM directorate as SAM_DIR

moose_app_type = "SAM"
app_dir = os.environ[moose_app_type.upper() + "_DIR"]
moose_plugin = watts.PluginMOOSE('../1App_SAM_VHTR/sam_template', show_stderr=True) # show only error
moose_plugin.executable = app_dir + "/" + moose_app_type.lower() + "-opt"
# set your SAM directory as SAM_DIR

app_dir = Path(os.environ["SAM_DIR"])
moose_plugin = watts.PluginMOOSE(
'../1App_SAM_VHTR/sam_template',
executable=app_dir / 'sam-opt',
show_stderr=True
)
moose_result = moose_plugin(params)
for key in moose_result.csv_data:
print(key, moose_result.csv_data[key])
Expand Down
30 changes: 21 additions & 9 deletions examples/MultiStep_Griffin-BISON-Sockeye_MR/watts_exec.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-FileCopyrightText: 2022 UChicago Argonne, LLC
# SPDX-License-Identifier: MIT

from pathlib import Path
import os
import watts

Expand All @@ -11,15 +12,15 @@
Third step is a real transient simulation induced by loss of cooling capacity
"""

# set your SuperMoose directory as SUPER_MOOSE
# set your SuperMoose directory as SUPER_MOOSE_DIR
# As Sockeye is run through dynamic linking
# set your Sockeye directory as SOCKEYE_DIR

if not os.getenv("SOCKEYE_DIR"):
raise RuntimeError("SOCKEYE_DIR must be set to enable this example.")
# MOOSE app type to run
moose_app_type = "super_moose"
app_dir = os.environ[moose_app_type.upper() + "_DIR"]
app_dir = Path(os.enrivon["SUPER_MOOSE_DIR"])
moose_exec = app_dir / "super_moose-opt"

# Steady State Parameters
params_ss = watts.Parameters()
Expand All @@ -42,8 +43,11 @@
# MOOSE Workflow for steady state
print("Steady-state calculation")
mpi_args = ['mpiexec', '-n', '40']
moose_plugin_ss = watts.PluginMOOSE('MP_ss_griffin.tmpl', extra_inputs=['MP_ss_moose.i', 'MP_ss_sockeye.i', '3D_unit_cell_FY21_level-1_bison.e', '3D_unit_cell_FY21_supersimple.e', 'unitcell_nogap_hom_xml_G11_df_MP.xml'])
moose_plugin_ss.executable = app_dir + "/" + moose_app_type.lower() + "-opt"
moose_plugin_ss = watts.PluginMOOSE(
'MP_ss_griffin.tmpl',
executable=moose_exec,
extra_inputs=['MP_ss_moose.i', 'MP_ss_sockeye.i', '3D_unit_cell_FY21_level-1_bison.e', '3D_unit_cell_FY21_supersimple.e', 'unitcell_nogap_hom_xml_G11_df_MP.xml']
)
moose_result_ss = moose_plugin_ss(params_ss, mpi_args=mpi_args)
for key in moose_result_ss.csv_data:
print(key, moose_result_ss.csv_data[key])
Expand All @@ -58,8 +62,12 @@

# MOOSE Workflow for Null transient
print("Null transient calculation")
moose_plugin_trN = watts.PluginMOOSE('MP_trN_griffin.tmpl', show_stdout=False, extra_inputs=['MP_trN_moose.i', 'MP_trN_sockeye.i', 'unitcell_nogap_hom_xml_G11_df_MP.xml'])
moose_plugin_trN.executable = app_dir + "/" + moose_app_type.lower() + "-opt"
moose_plugin_trN = watts.PluginMOOSE(
'MP_trN_griffin.tmpl',
executable=moose_exec,
show_stdout=False,
extra_inputs=['MP_trN_moose.i', 'MP_trN_sockeye.i', 'unitcell_nogap_hom_xml_G11_df_MP.xml']
)
moose_result_trN = moose_plugin_trN(params_trN, mpi_args=mpi_args)
for key in moose_result_trN.csv_data:
print(key, moose_result_trN.csv_data[key])
Expand All @@ -78,8 +86,12 @@

# MOOSE Workflow for transient
print("Transient calculation")
moose_plugin_tr = watts.PluginMOOSE('MP_tr_griffin.tmpl', show_stdout=True, extra_inputs=['MP_tr_moose.i', 'MP_tr_sockeye.i', 'unitcell_nogap_hom_xml_G11_df_MP.xml'])
moose_plugin_tr.executable = app_dir + "/" + moose_app_type.lower() + "-opt"
moose_plugin_tr = watts.PluginMOOSE(
'MP_tr_griffin.tmpl',
executable=moose_exec,
show_stdout=True,
extra_inputs=['MP_tr_moose.i', 'MP_tr_sockeye.i', 'unitcell_nogap_hom_xml_G11_df_MP.xml']
)
moose_result_tr = moose_plugin_tr(params_tr, mpi_args=mpi_args)
for key in moose_result_tr.csv_data:
print(key, moose_result_tr.csv_data[key])
Expand Down
9 changes: 4 additions & 5 deletions examples/ParamStudy_SAM_VHTR/watts_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
output CSV file can accept columns of different lengths.
"""

from math import cos, pi
from pathlib import Path
import os

import watts
import pandas as pd
from astropy.units import Quantity
Expand Down Expand Up @@ -45,8 +46,7 @@
params.show_summary(show_metadata=False, sort_by='key')

# MOOSE Workflow
moose_app_type = "SAM"
app_dir = os.environ[moose_app_type.upper() + "_DIR"]
app_dir = Path(os.environ["SAM_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.
Expand All @@ -56,8 +56,7 @@
params['endtime'] = endtime[i]

# Execute WATTS
moose_plugin = watts.PluginMOOSE(moose_app_type.lower() + '_template') # show all the output
moose_plugin.executable = app_dir + "/" + moose_app_type.lower() + "-opt"
moose_plugin = watts.PluginMOOSE('sam_template', executable=app_dir / 'sam-opt')
moose_result = moose_plugin(params)

# Add items to dictionary.
Expand Down
11 changes: 7 additions & 4 deletions examples/PicardIterations_SAM-OpenMC_VHTR/watts_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
model with 1 coolant channel surrounded by graphite and fuel.
"""

from pathlib import Path
from math import cos, pi
import os
import watts
Expand Down Expand Up @@ -64,13 +65,15 @@
nmax_it = 5
conv_criteria = 1e-4

app_dir = Path(os.environ["SAM_DIR"])
list_keff = []
while conv_it:
# MOOSE Workflow
moose_app_type = "SAM"
app_dir = os.environ[moose_app_type.upper() + "_DIR"]
sam_plugin = watts.PluginMOOSE('../1App_SAM_VHTR/sam_template', show_stderr=True) # show only error
sam_plugin.executable = app_dir + "/" + moose_app_type.lower() + "-opt"
sam_plugin = watts.PluginMOOSE(
'../1App_SAM_VHTR/sam_template',
executable=app_dir / "sam-opt",
show_stderr=True
)
sam_result = sam_plugin(params)

# get temperature from SAM results
Expand Down
5 changes: 3 additions & 2 deletions src/watts/plugin_moose.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# SPDX-License-Identifier: MIT

from datetime import datetime
from pathlib import Path
from typing import List, Optional

import numpy as np
Expand Down Expand Up @@ -84,6 +83,8 @@ class PluginMOOSE(PluginGeneric):
----------
template_file
Templated MOOSE input
executable
Path to MOOSE executable
extra_inputs
List of extra (non-templated) input files that are needed
extra_template_inputs
Expand All @@ -103,10 +104,10 @@ class PluginMOOSE(PluginGeneric):
"""

def __init__(self, template_file: str,
executable: PathLike = 'moose-opt',
extra_inputs: Optional[List[str]] = None,
extra_template_inputs: Optional[List[PathLike]] = None,
show_stdout: bool = False, show_stderr: bool = False):
executable = 'moose-opt'
execute_command = ['{self.executable}', '-i', '{self.input_name}']
super().__init__(
executable, execute_command, template_file, extra_inputs,
Expand Down

0 comments on commit 14f0424

Please sign in to comment.