Skip to content

Commit

Permalink
Add option for specifying specific application for input run
Browse files Browse the repository at this point in the history
  • Loading branch information
lindsayad committed Jan 19, 2022
1 parent 267ec14 commit c36faa0
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 4 deletions.
2 changes: 1 addition & 1 deletion framework/include/base/AppFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class AppFactory
/**
* Helper function for creating a MooseApp from command-line arguments.
*/
static MooseAppPtr createAppShared(const std::string & app_type,
static MooseAppPtr createAppShared(const std::string & default_app_type,
int argc,
char ** argv,
MPI_Comm comm_word = MPI_COMM_WORLD);
Expand Down
2 changes: 2 additions & 0 deletions framework/include/base/MooseApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,8 @@ class MooseApp : public ConsoleStreamInterface,
template <class T>
const std::vector<T *> & getInterfaceObjects() const;

static void addAppParam(InputParameters & params);

protected:
/**
* Whether or not this MooseApp has cached a Backup to use for restart / recovery
Expand Down
10 changes: 9 additions & 1 deletion framework/src/base/AppFactory.C
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "AppFactory.h"
#include "CommandLine.h"
#include "InputParameters.h"
#include "MooseApp.h"

AppFactory AppFactory::_instance = AppFactory();

Expand All @@ -32,12 +33,19 @@ AppFactory::getValidParams(const std::string & name)
}

MooseAppPtr
AppFactory::createAppShared(const std::string & app_type,
AppFactory::createAppShared(const std::string & default_app_type,
int argc,
char ** argv,
MPI_Comm comm_world_in)
{
auto command_line = std::make_shared<CommandLine>(argc, argv);
auto which_app_param = emptyInputParameters();
MooseApp::addAppParam(which_app_param);
command_line->addCommandLineOptionsFromParams(which_app_param);
std::string app_type;
if (!command_line->search("app_to_run", app_type))
app_type = default_app_type;

auto app_params = AppFactory::instance().getValidParams(app_type);

app_params.set<int>("_argc") = argc;
Expand Down
13 changes: 13 additions & 0 deletions framework/src/base/MooseApp.C
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@

defineLegacyParams(MooseApp);

void
MooseApp::addAppParam(InputParameters & params)
{
params.addCommandLineParam<std::string>(
"app_to_run",
"--app <AppName>",
"Specify the application that should be used to run the input file. This must match an "
"application name registered to the application factory. Note that this option is "
"case-sensitive.");
}

InputParameters
MooseApp::validParams()
{
Expand Down Expand Up @@ -303,6 +314,8 @@ MooseApp::validParams()
true,
"Set false to allow material properties to be output on INITIAL, not just TIMESTEP_END.");

MooseApp::addAppParam(params);

return params;
}

Expand Down
4 changes: 2 additions & 2 deletions test/tests/kernels/simple_diffusion/tests
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[Tests]
[./test]
[test]
type = 'Exodiff'
input = 'simple_diffusion.i'
exodiff = 'simple_diffusion_out.e'

issues = '#1493'
design = 'kernels/Diffusion.md'
requirement = 'The system shall run a simple 2D linear diffusion problem with Dirichlet boundary conditions on a regular mesh.'
[../]
[]
[]
Binary file not shown.
44 changes: 44 additions & 0 deletions test/tests/misc/app_name/simple-diffusion.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[Mesh]
type = GeneratedMesh
dim = 2
nx = 10
ny = 10
[]

[Variables]
[u]
[]
[]

[Kernels]
[diff]
type = Diffusion
variable = u
[]
[]

[BCs]
[left]
type = DirichletBC
variable = u
boundary = left
value = 0
[]
[right]
type = DirichletBC
variable = u
boundary = right
value = 1
[]
[]

[Executioner]
type = Steady
solve_type = 'PJFNK'
petsc_options_iname = '-pc_type -pc_hypre_type'
petsc_options_value = 'hypre boomeramg'
[]

[Outputs]
exodus = true
[]
9 changes: 9 additions & 0 deletions test/tests/misc/app_name/tests
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@
design = MooseApp.md
requirement = "The compiled application shall be capable of returning the name used for registering objects."
[../]
[specified_app]
type = 'Exodiff'
input = 'simple-diffusion.i'
exodiff = 'simple-diffusion_out.e'
issues = '#20062'
design = 'MooseApp.md'
cli_args = '--app MooseTestApp'
requirement = 'The system shall be able to run a specific application by passing a command line option.'
[]
[]

0 comments on commit c36faa0

Please sign in to comment.