|
7 | 7 | # * |
8 | 8 | # * Licensed under LGPL 2.1, please see LICENSE for details |
9 | 9 | # * https://www.gnu.org/licenses/lgpl-2.1.html |
10 | | -import numpy as np |
11 | | -import sys |
| 10 | +""" |
| 11 | +This should be called by the test harness with sub.i input file. |
| 12 | +
|
| 13 | +The purpose is to test StochasticControl for perturbing input parameters and |
| 14 | +gathering results on-the-fly using the MOOSE WebServerControl for VPP style outputs. |
| 15 | +
|
| 16 | +It works by checking predefined matrices and running the STM with some |
| 17 | + benchmark problems. There is no |
| 18 | +"gold" file in this sense, it instead checks for syntax correctness. |
| 19 | +""" |
| 20 | + |
12 | 21 | import os |
13 | | -import importlib |
14 | | -import importlib.util |
15 | | -import argparse |
| 22 | +import sys |
16 | 23 | import shutil |
| 24 | +import numpy as np |
| 25 | +import argparse |
| 26 | +import importlib.util |
| 27 | +import importlib |
17 | 28 |
|
18 | 29 | StochasticControl = None |
19 | 30 | StochasticRunOptions = None |
@@ -62,46 +73,48 @@ def test_options(): |
62 | 73 | if __name__ == "__main__": |
63 | 74 | options = { |
64 | 75 | 'input_name':'stochastic_run.i', |
65 | | - 'ignore_solve_not_converge':False |
66 | 76 | } |
67 | 77 | cmd = os.environ.get("RUNAPP_COMMAND") |
68 | 78 | if cmd is None: |
69 | 79 | sys.exit("Missing expected command variable RUNAPP_COMMAND") |
70 | 80 | cmd = cmd.split() |
71 | | - |
| 81 | + # Gather MPI options if running with MPI |
72 | 82 | if "-n" in cmd: |
73 | | - mpi_index = cmd.index("-n")-1 |
| 83 | + mpi_index = cmd.index("-n") - 1 |
74 | 84 | options["mpi_command"] = cmd[mpi_index] |
75 | | - options["num_procs"] = int(cmd[mpi_index+2]) |
76 | | - exec_index = cmd.index("-i")-1 |
| 85 | + options["num_procs"] = int(cmd[mpi_index + 2]) |
| 86 | + # Get executable and input file based on position of '-i' argument |
| 87 | + exec_index = cmd.index("-i") - 1 |
77 | 88 | executable = cmd[exec_index] |
78 | | - input_file = cmd[exec_index+2] |
79 | | - options["cli_args"] = cmd[(exec_index + 3):] |
| 89 | + input_file = cmd[exec_index + 2] |
| 90 | + # Everything after the input is cli_args |
| 91 | + options["cli_args"] = cmd[(exec_index + 3) :] |
80 | 92 |
|
81 | 93 | if StochasticControl is None: |
82 | | - _exec_dir = os.path.dirname(os.path.abspatch(shutil.which(executable))) |
| 94 | + _exec_dir = os.path.dirname(os.path.abspath(shutil.which(executable))) |
83 | 95 | _share_dir = os.path.abspath(os.path.join(_exec_dir, "..", "share")) |
84 | | - _moose_stm_python = os.path.join(_share_dir, "stochastic_tools","python") |
| 96 | + _moose_stm_python = os.path.join(_share_dir, "stochastic_tools", "python") |
85 | 97 | _moose_python = os.path.join(_moose_stm_python,'..','..','..','python') |
86 | 98 | if not (tryImportStochasticControl(_moose_python) and tryImportStochasticControl(_moose_stm_python)): |
87 | 99 | raise ModuleNotFoundError("Could not find MOOSE stochastic tools module python utilities.") |
88 | 100 |
|
89 | 101 | if StochasticRunOptions.MultiAppMode.BATCH_RESET is not None: |
90 | | - options['multiapp_mode'] = StochasticRunOptions.MultiAppMode.BATCH_RESET, |
| 102 | + options['multiapp_mode'] = StochasticRunOptions.MultiAppMode.BATCH_RESET |
91 | 103 | cli_args = test_options() |
92 | | - input_file_name = 'main_runner.i' |
| 104 | + parameters = ['capsule1:Postprocessors/frequency_factor/value', |
| 105 | + 'capsule1:Postprocessors/activation_energy/value', |
| 106 | + 'capsule1:BCs/heat_DRV_outer/value', |
| 107 | + 'capsule1:mesh_specified' |
| 108 | + ] |
| 109 | + qois = ['capsule_01/x', 'capsule_01/temp'] |
93 | 110 | input_file = 'vpp_test_runner.i' |
94 | | - command_possibilities = [] |
95 | | - with StochasticControl(executable=executable, |
96 | | - physics_input=input_file, |
97 | | - options=StochasticRunOptions(**options), |
98 | | - parameters=['capsule1:Postprocessors/frequency_factor/value', |
99 | | - 'capsule1:Postprocessors/activation_energy/value', |
100 | | - 'capsule1:BCs/heat_DRV_outer/value', |
101 | | - 'capsule1:mesh_specified'], |
102 | | - quantities_of_interest=['capsule_01/x', |
103 | | - 'capsule_01/temp', |
104 | | - ]) as runner: |
| 111 | + with StochasticControl( |
| 112 | + executable=executable, |
| 113 | + physics_input=input_file, |
| 114 | + parameters=parameters, |
| 115 | + quantities_of_interest=qois, |
| 116 | + options=StochasticRunOptions(**options), |
| 117 | + ) as runner: |
105 | 118 | if cmd[exec_index+3]==0: |
106 | 119 | runner.configCache(tol=[1,1e-10,1e-14,1e-14]) |
107 | 120 | elif cmd[exec_index+3]==1: |
|
0 commit comments