Skip to content

Commit

Permalink
Do smarter control over header
Browse files Browse the repository at this point in the history
Closes #29662
  • Loading branch information
tophmatthews committed Jan 29, 2025
1 parent e193a3d commit 87ce983
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 7 deletions.
13 changes: 6 additions & 7 deletions framework/src/base/MooseApp.C
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ MooseApp::validParams()
"Continue the calculation. Without <file base>, the most recent recovery file will be used");
params.setGlobalCommandLineParam("recover");

params.addCommandLineParam<bool>(
"suppress_header", "--suppress-header", false, "Flag to print the App header");
params.setGlobalCommandLineParam("suppress_header");

params.addCommandLineParam<bool>(
"test_checkpoint_half_transient",
"--test-checkpoint-half-transient",
Expand Down Expand Up @@ -730,13 +734,8 @@ MooseApp::setupOptions()
TIME_SECTION("setupOptions", 5, "Setting Up Options");

// Print the header, this is as early as possible
auto hdr = header();
if (hdr.length() != 0)
{
if (multiAppLevel() > 0)
MooseUtils::indentMessage(_name, hdr);
Moose::out << hdr << std::endl;
}
if (header().length() && !getParam<bool>("suppress_header"))
_console << header() << std::endl;

if (getParam<bool>("error_unused"))
setCheckUnusedFlag(true);
Expand Down
2 changes: 2 additions & 0 deletions test/include/base/MooseTestApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ class MooseTestApp : public MooseApp

static void registerAll(Factory & f, ActionFactory & af, Syntax & s, bool use_test_objs = false);
static void registerApps();

virtual std::string header() const override;
};
9 changes: 9 additions & 0 deletions test/src/base/MooseTestApp.C
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ MooseTestApp::validParams()
"--test-check-legacy-params",
"Check for legacy parameter construction with CheckLegacyParamsAction; for testing");

params.addCommandLineParam<std::string>(
"append_header", "--append-header <header>", "", "String to print at top of console output");

params.set<bool>("automatic_automatic_scaling") = false;
params.set<bool>("use_legacy_material_output") = false;
params.set<bool>("use_legacy_initial_residual_evaluation_behavior") = false;
Expand Down Expand Up @@ -141,6 +144,12 @@ MooseTestApp::registerApps()
registerApp(MooseTestApp);
}

std::string
MooseTestApp::header() const
{
return getParam<std::string>("append_header");
}

extern "C" void
MooseTestApp__registerAll(Factory & f, ActionFactory & af, Syntax & s)
{
Expand Down
26 changes: 26 additions & 0 deletions test/tests/misc/header/parent.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[Mesh]
type = GeneratedMesh
dim = 1
[]

[Problem]
solve = false
[]

[Executioner]
type = Transient
num_steps = 0
[]

[Outputs]
color = false
[]

[MultiApps]
[sub]
type = TransientMultiApp
app_type = MooseTestApp
input_files = sub.i
cli_args = --append-header=sub
[]
[]
26 changes: 26 additions & 0 deletions test/tests/misc/header/sub.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[Mesh]
type = GeneratedMesh
dim = 1
[]

[Problem]
solve = false
[]

[Executioner]
type = Transient
num_steps = 0
[]

[Outputs]
color = false
[]

[MultiApps]
[sub]
type = TransientMultiApp
app_type = MooseTestApp
input_files = subsub.i
cli_args = --append-header=subsub
[]
[]
17 changes: 17 additions & 0 deletions test/tests/misc/header/subsub.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Mesh]
type = GeneratedMesh
dim = 1
[]

[Problem]
solve = false
[]

[Executioner]
type = Transient
num_steps = 0
[]

[Outputs]
color = false
[]
23 changes: 23 additions & 0 deletions test/tests/misc/header/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[Tests]
issues = '#1832'
design = 'syntax/MultiApps/index.md'

[g]
requirement = "The system shall be able to print a header for multi-level sub-applications:"
[header_on]
type = 'RunApp'
input = 'parent.i'
expect_out = 'parent\nsub0: sub\nsub0_sub0: subsub'
detail = "custom for each parent and sub-applications;"
cli_args = '--append-header=parent'
[]
[header_off]
type = 'RunApp'
input = 'parent.i'
prereq = g/header_on
cli_args = '--append-header=parent --suppress-header'
absent_out = 'parent\nsub0: sub\nsub0_sub0: subsub'
detail = "and suppress the all parent and sub-applications."
[]
[]
[]

0 comments on commit 87ce983

Please sign in to comment.