Skip to content

Commit

Permalink
Dont allow checkpoint/exodus restart and initial conditions at the sa…
Browse files Browse the repository at this point in the history
…me time

Unless user says it s fine
 refs idaholab#21423
  • Loading branch information
GiudGiud committed Sep 5, 2023
1 parent 9539914 commit 400fe18
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
1 change: 1 addition & 0 deletions framework/include/problems/FEProblemBase.h
Expand Up @@ -2473,6 +2473,7 @@ class FEProblemBase : public SubProblem, public Restartable
bool _ignore_zeros_in_jacobian;
const bool _force_restart;
const bool _skip_additional_restart_data;
const bool _allow_ics_during_restart;
const bool _skip_nl_system_check;
bool _fail_next_nonlinear_convergence_check;
const bool & _allow_invalid_solution;
Expand Down
24 changes: 23 additions & 1 deletion framework/src/problems/FEProblemBase.C
Expand Up @@ -174,6 +174,10 @@ FEProblemBase::validParams()
false,
"True to skip the NonlinearSystem check for work to do (e.g. Make sure "
"that there are variables to solve for).");
params.addParam<bool>("allow_initial_conditions_with_restart",
false,
"True to allow the user to specify initial conditions when restarting. "
"Initial conditions can override any restarted field");

/// One entry of coord system per block, the size of _blocks and _coord_sys has to match, except:
/// 1. _blocks.size() == 0, then there needs to be just one entry in _coord_sys, which will
Expand Down Expand Up @@ -282,7 +286,8 @@ FEProblemBase::validParams()
params.addParamNamesToGroup("use_nonlinear previous_nl_solution_required nl_sys_names "
"ignore_zeros_in_jacobian",
"Nonlinear system(s)");
params.addParamNamesToGroup("restart_file_base force_restart skip_additional_restart_data",
params.addParamNamesToGroup("restart_file_base force_restart skip_additional_restart_data "
"allow_initial_conditions_with_restart",
"Restart");
params.addParamNamesToGroup("verbose_multiapps parallel_barrier_messaging", "Verbosity");
params.addParamNamesToGroup(
Expand Down Expand Up @@ -379,6 +384,7 @@ FEProblemBase::FEProblemBase(const InputParameters & parameters)
_ignore_zeros_in_jacobian(getParam<bool>("ignore_zeros_in_jacobian")),
_force_restart(getParam<bool>("force_restart")),
_skip_additional_restart_data(getParam<bool>("skip_additional_restart_data")),
_allow_ics_during_restart(getParam<bool>("allow_initial_conditions_with_restart")),
_skip_nl_system_check(getParam<bool>("skip_nl_system_check")),
_fail_next_nonlinear_convergence_check(false),
_allow_invalid_solution(getParam<bool>("allow_invalid_solution")),
Expand Down Expand Up @@ -3000,6 +3006,22 @@ FEProblemBase::addInitialCondition(const std::string & ic_name,
{
parallel_object_only();

// Forbid initial conditions on a restarted problem, as they would override the restart
if (!_allow_ics_during_restart)
{
std::string restart_method = "";
if (_app.isRestarting())
restart_method = "a checkpoint restart";
else if (_app.getExReaderForRestart())
restart_method = "an Exodus restart";
if (!restart_method.empty())
mooseError(
"Initial condition has been specified during ",
restart_method,
".\nThis is only allowed if you specify 'allow_initial_conditions_with_restart' to "
"the [Problem], as initial conditions can override restarted fields");
}

// before we start to mess with the initial condition, we need to check parameters for errors.
parameters.checkParams(name);

Expand Down
@@ -1,47 +1,47 @@
[Mesh]
[./square]
[square]
type = GeneratedMeshGenerator
nx = 2
ny = 2
dim = 2
[../]
[]
uniform_refine = 2
[]

[Variables]
active = 'u'

[./u]
[u]
order = FIRST
family = LAGRANGE
[../]
[]
[]

[Kernels]
active = 'diff'

[./diff]
[diff]
type = Diffusion
variable = u
[../]
[]
[]

[BCs]
active = 'left right'

[./left]
[left]
type = DirichletBC
variable = u
boundary = 3
value = 0
[../]
[]

[./right]
[right]
type = DirichletBC
variable = u
boundary = 1
value = 1
[../]
[]
[]

[Executioner]
Expand Down
13 changes: 11 additions & 2 deletions test/tests/restart/restart_diffusion/tests
Expand Up @@ -91,8 +91,7 @@
[restart_use_end_error_check]
type = 'RunException'
input = 'restart_diffusion_from_end_part2.i'
expect_err = 'Invalid value passed as "initial_from_file_timestep". Expected "LATEST" or a valid '
'integer between \d+ and \d+ inclusive, received \d+'
expect_err = 'Invalid value passed as "initial_from_file_timestep". Expected "LATEST" or a valid integer between \d+ and \d+ inclusive, received \d+'

cli_args = 'Variables/u/initial_from_file_timestep=8'
prereq = 'restart_use_end_part2'
Expand All @@ -101,4 +100,14 @@
requirement = "The system shall issue a useful error message stating the valid options when a "
"user requests an invalid time step number or keyword."
[]

[restart_error_with_ics]
type = 'RunException'
input = 'exodus_refined_restart_2_test.i'
expect_err = 'Initial condition has been specified during an Exodus restart'
cli_args = 'Variables/u/initial_condition=3'
issues = "#21423"
requirement = "The system shall issue a useful error message stating that initial conditions "
"should not be used when restarting."
[]
[]

0 comments on commit 400fe18

Please sign in to comment.