From e6be134f6297ad6ae1fa6b509b09f86e8fe18504 Mon Sep 17 00:00:00 2001 From: Daniel Yankura Date: Thu, 9 Jan 2025 17:41:25 -0700 Subject: [PATCH] New error when two different ICs are specified -Error thrown if an initial_condition parameter is provided along with an initial_from_file_var parameter for the same variable. closes #20944 --- framework/src/actions/AddVariableAction.C | 7 ++++ test/tests/restart/scalar-var/part3.i | 50 +++++++++++++++++++++++ test/tests/restart/scalar-var/tests | 6 +++ 3 files changed, 63 insertions(+) create mode 100644 test/tests/restart/scalar-var/part3.i diff --git a/framework/src/actions/AddVariableAction.C b/framework/src/actions/AddVariableAction.C index d3f098d62574..b1ff72afa4a1 100644 --- a/framework/src/actions/AddVariableAction.C +++ b/framework/src/actions/AddVariableAction.C @@ -56,6 +56,7 @@ AddVariableAction::validParams() "Specifies a scaling factor to apply to this variable"); params.addParam>("initial_condition", "Specifies a constant initial condition for this variable"); + params.addParam("initial_from_file_var", "Initial from file"); return params; } @@ -132,6 +133,12 @@ AddVariableAction::init() "`scaling` parameter set, and they are different values. I don't know how you " "achieved this, but you need to rectify it."); + if (_pars.isParamSetByUser("initial_condition") && + _pars.isParamSetByUser("initial_from_file_var")) + mooseError("Two initial conditions have been provided for the variable ", + name(), + ". One from the user and one from the restart input file."); + _moose_object_pars.applySpecificParameters(_pars, {"order", "family", "scaling"}); // Determine the MooseVariable type diff --git a/test/tests/restart/scalar-var/part3.i b/test/tests/restart/scalar-var/part3.i new file mode 100644 index 000000000000..48b22a60229d --- /dev/null +++ b/test/tests/restart/scalar-var/part3.i @@ -0,0 +1,50 @@ +[Mesh] + [fmg] + type = FileMeshGenerator + file = part1_out.e + use_for_exodus_restart = true + [] +[] + +[Variables] + [v] + family = MONOMIAL + order = CONSTANT + fv = true + initial_from_file_var = v + initial_condition = 0 + [] + [lambda] + family = SCALAR + order = FIRST + initial_from_file_var = lambda + [] +[] + +[FVKernels] + [advection] + type = FVElementalAdvection + variable = v + velocity = '1 0 0' + [] + [lambda] + type = FVScalarLagrangeMultiplier + variable = v + lambda = lambda + phi0 = 1 + [] +[] + +[Executioner] + type = Steady + petsc_options_iname = '-snes_max_it' + petsc_options_value = '0' + nl_abs_tol = 1e-10 +[] + +[Outputs] + [out] + type = Exodus + execute_on = 'final' + [] +[] diff --git a/test/tests/restart/scalar-var/tests b/test/tests/restart/scalar-var/tests index edb7ade68ea0..58ff0a1f56e4 100644 --- a/test/tests/restart/scalar-var/tests +++ b/test/tests/restart/scalar-var/tests @@ -16,5 +16,11 @@ exodiff = part2_out.e detail = 'run restart input' [] + [part3] + prereq = 'restarting/part1' + type = 'RunException' + input = part3.i + expect_err = 'Two initial conditions have been provided for the variable v. One from the user and one from the restart input file.' + [] [] []