Skip to content

Commit 0dad1eb

Browse files
committed
Add skip_evals option to Terminator UserObject for problems. Closes #30343
1 parent 5e63aaa commit 0dad1eb

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

framework/doc/content/source/userobjects/Terminator.md

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ The message output by the `Terminator` when the condition for termination is met
2626
- an information message, to indicate that while the `Terminator` is acting on the solve, the conditions
2727
met are expected or normal. This can be used to make the `Terminator` stop the simulation but accept the result.
2828

29+
An additional constraint may be added with the [!param](/UserObjects/Terminator/skip_evals) parameter,
30+
which temporarily disables the terminator for the first `n` evaluations (usually the same as timesteps,
31+
but when executed on `INITIAL`, this will change the count).
32+
2933

3034
## Example input syntax
3135

framework/include/userobjects/Terminator.h

+3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ class Terminator : public GeneralUserObject
7474

7575
/// Fparser parameter buffer
7676
std::vector<Real> _params;
77+
78+
unsigned int _n_evals;
79+
const unsigned int _skip_evals;
7780
};
7881

7982
#endif // LIBMESH_HAVE_FPARSER

framework/src/userobjects/Terminator.C

+9-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ Terminator::validParams()
4949
errorLevel,
5050
"The error level for the message. A level of ERROR will always lead to a hard "
5151
"termination of the entire simulation.");
52+
params.addParam<unsigned int>("skip_evals",
53+
0,
54+
"Number of evaluations to skip, useful for avoiding"
55+
"errors due to initialization problems");
5256
return params;
5357
}
5458

@@ -59,7 +63,8 @@ Terminator::Terminator(const InputParameters & parameters)
5963
_pp_names(),
6064
_pp_values(),
6165
_expression(getParam<std::string>("expression")),
62-
_fp()
66+
_fp(),
67+
_skip_evals(getParam<unsigned int>("skip_evals"))
6368
{
6469
// sanity check the parameters
6570
if (_msg_type == MessageType::ERROR && _fail_mode != FailMode::HARD)
@@ -87,6 +92,7 @@ Terminator::Terminator(const InputParameters & parameters)
8792
_pp_values[i] = &getPostprocessorValueByName(_pp_names[i]);
8893

8994
_params.resize(_pp_num);
95+
_n_evals = 0;
9096
}
9197

9298
void
@@ -150,8 +156,9 @@ Terminator::execute()
150156
for (unsigned int i = 0; i < _pp_num; ++i)
151157
_params[i] = *(_pp_values[i]);
152158

159+
++_n_evals;
153160
// request termination of the run or timestep in case the expression evaluates to true
154-
if (_fp.Eval(_params.data()) != 0)
161+
if ((_fp.Eval(_params.data()) != 0) && (_skip_evals < _n_evals))
155162
{
156163
handleMessage();
157164
if (_fail_mode == FailMode::HARD)
Binary file not shown.

test/tests/userobjects/Terminator/tests

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
requirement = "The system shall terminate the execution of a solve based on post-processing "
1010
"calculations performed within the simulation."
1111
[]
12+
[terminator_skip_evals]
13+
type = 'Exodiff'
14+
input = 'terminator.i'
15+
exodiff = 'terminator_out_long.e'
16+
issues = '#30343'
17+
cli_args = "UserObjects/arnold/skip_evals=4
18+
Outputs/file_base=terminator_out_long"
19+
requirement = "The system shall terminate the execution of a solve based on post-processing "
20+
"calculations performed within the simulation, and skip termination if user "
21+
"specified override criteria are met."
22+
[]
1223
[terminator_soft_step_fail]
1324
type = 'CSVDiff'
1425
input = 'terminator_soft.i'

0 commit comments

Comments
 (0)