diff --git a/framework/include/problems/FEProblemBase.h b/framework/include/problems/FEProblemBase.h index 964ba318550f..1b1d053f387e 100644 --- a/framework/include/problems/FEProblemBase.h +++ b/framework/include/problems/FEProblemBase.h @@ -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; diff --git a/framework/src/problems/FEProblemBase.C b/framework/src/problems/FEProblemBase.C index bb5266d24167..df2aaeb07973 100644 --- a/framework/src/problems/FEProblemBase.C +++ b/framework/src/problems/FEProblemBase.C @@ -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("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 @@ -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( @@ -379,6 +384,7 @@ FEProblemBase::FEProblemBase(const InputParameters & parameters) _ignore_zeros_in_jacobian(getParam("ignore_zeros_in_jacobian")), _force_restart(getParam("force_restart")), _skip_additional_restart_data(getParam("skip_additional_restart_data")), + _allow_ics_during_restart(getParam("allow_initial_conditions_with_restart")), _skip_nl_system_check(getParam("skip_nl_system_check")), _fail_next_nonlinear_convergence_check(false), _allow_invalid_solution(getParam("allow_invalid_solution")), @@ -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); diff --git a/test/tests/restart/restart_diffusion/exodus_refined_restart_1_test.i b/test/tests/restart/restart_diffusion/exodus_refined_restart_1_test.i index 1e0f6bdfce9c..711e35ba76d9 100644 --- a/test/tests/restart/restart_diffusion/exodus_refined_restart_1_test.i +++ b/test/tests/restart/restart_diffusion/exodus_refined_restart_1_test.i @@ -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] diff --git a/test/tests/restart/restart_diffusion/tests b/test/tests/restart/restart_diffusion/tests index e5c8b92abbca..9d5453756d6a 100644 --- a/test/tests/restart/restart_diffusion/tests +++ b/test/tests/restart/restart_diffusion/tests @@ -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' @@ -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." + [] []