Skip to content

Commit

Permalink
Use Application/* params in constructing the app
Browse files Browse the repository at this point in the history
  • Loading branch information
loganharbour committed Feb 7, 2024
1 parent bb2a44c commit 837cd99
Show file tree
Hide file tree
Showing 20 changed files with 2,653 additions and 2,363 deletions.
30 changes: 4 additions & 26 deletions framework/include/base/AppFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,6 @@ class AppFactory
virtual ~AppFactory();

static InputParameters validParams();
/**
* Helper function for creating a MooseApp from command-line arguments and a Parser.
*/
static MooseAppPtr createAppShared(const std::string & default_app_type,
int argc,
char ** argv,
std::unique_ptr<Parser> parser,
MPI_Comm comm_word = MPI_COMM_WORLD);

/**
* Deprecated helper function for creating a MooseApp for Apps haven't adapted to the new Parser
* and Builder changes. This function needed to be removed after the new Parser and Builder merged
*/
static MooseAppPtr createAppShared(const std::string & default_app_type,
int argc,
char ** argv,
MPI_Comm comm_word = MPI_COMM_WORLD);

/**
* Register a new object
Expand All @@ -97,16 +80,11 @@ class AppFactory
InputParameters getValidParams(const std::string & name);

/**
* Build an application object (must be registered)
* @param app_type Type of the application being constructed
* @param name Name for the object
* @param parameters Parameters this object should have
* @return The created object
* Creates an application with the parameters in \p parameters.
*
* @return The application
*/
MooseAppPtr createShared(const std::string & app_type,
const std::string & name,
InputParameters parameters,
MPI_Comm COMM_WORLD_IN);
MooseAppPtr createShared(InputParameters parameters);

/**
* Returns a reference to the map from names to AppFactoryBuildInfo pointers
Expand Down
23 changes: 19 additions & 4 deletions framework/include/base/MooseApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ class MooseApp : public ConsoleStreamInterface,

static InputParameters validParams();

/**
* Adds the app type parameters into \p params.
*
* This is separate because in MooseMain we will parse the type
* early to instantiate the correct app.
*/
static void addTypeParam(InputParameters & params);
/**
* Adds the input file parameter into \p params.
*
* This is separate because in MooseMain we will parse the input
* file from command-line early so that we can parse the input
* to parse Application/type.
*/
static void addInputFileParam(InputParameters & params);

virtual ~MooseApp();

TheWarehouse & theWarehouse() { return *_the_warehouse; }
Expand Down Expand Up @@ -130,7 +146,7 @@ class MooseApp : public ConsoleStreamInterface,
* MooseTestApp).
* @return The the type of the object
*/
const std::string & type() const;
const std::string & type() const { return _type; }

/**
* The RankMap is a useful object for determining how the processes
Expand Down Expand Up @@ -352,7 +368,8 @@ class MooseApp : public ConsoleStreamInterface,
* Deprecated helper function to link the new added Builder back to Parser. This function will be
*removed after new Parser and builder are merged
**/
Moose::Builder & parser();
Parser & parser();
const Parser & parser() const;

private:
/**
Expand Down Expand Up @@ -1050,8 +1067,6 @@ class MooseApp : public ConsoleStreamInterface,
template <class T>
const std::vector<T *> & getInterfaceObjects() const;

static void addAppParam(InputParameters & params);

protected:
/**
* Helper method for dynamic loading of objects
Expand Down
12 changes: 9 additions & 3 deletions framework/include/base/MooseServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#pragma once

#include "MooseApp.h"
#include "wasplsp/LSP.h"
#include "wasplsp/ServerImpl.h"
#include "wasplsp/Connection.h"
Expand All @@ -20,10 +19,17 @@
#include "wasphit/HITNodeView.h"
#include "waspsiren/SIRENInterpreter.h"
#include "waspsiren/SIRENResultSet.h"
#include "parse.h"

#include <string>
#include <memory>
#include <set>
#include <map>
#include <functional>

class MooseApp;
class Parser;
class InputParameters;

class MooseServer : public wasp::lsp::ServerImpl
{
Expand Down Expand Up @@ -315,9 +321,9 @@ class MooseServer : public wasp::lsp::ServerImpl
MooseApp & _moose_app;

/**
* @brief _check_app - application created to check input and access parser
* @brief _parser - parser passed to the application containing the hit root
*/
std::shared_ptr<MooseApp> _check_app;
std::shared_ptr<Parser> _parser;

/**
* @brief _connection - shared pointer to this server's read / write iostream
Expand Down
105 changes: 105 additions & 0 deletions framework/include/builder/AppBuilder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "BuilderBase.h"

namespace Moose
{

/**
* Helper for constructing an application.
*
* Enables:
* - Parsing --type and Application/type ASAP to determine an app type
* - Parsing and extracting Application/ parameters for the app
* - Doing basic hit sanity checking as early as possible (before app construction)
*/
class AppBuilder : public BuilderBase
{
public:
AppBuilder(std::shared_ptr<Parser> parser);

/**
* Build an application's parameters from command line arguments, with a
* not-yet-decided type.
*
* This is used for constructing an application in main, where we do not
* have a CommandLine object yet.
*
* The type is determined from either default_type or any of the command
* line and input options (Application/type=, --type, or --app (deprecated)).
* Once the type is determined, it starts with the valid parameters and
* then specifies (in the parameters):
* _argc - The arg count from \p argc
* _argv - The arg count from \p argv
* _command_line - The built CommandLine from the arguments
*
* See buildParamsFromCommandLine() for information on what else is set.
*
* @param default_type The default application type to build if one can't be parsed
* @param name The name of the application to build
* @param argc Argument count
* @param argv Argument vector
* @param comm_world_in The MPI communicator
* @return The built parameters
*/
InputParameters buildParams(const std::string & default_type,
const std::string & name,
int argc,
char ** argv,
MPI_Comm comm_world_in);

/**
* Builds an application's parameters in place with a type already set
* and CommandLine that is already filled in "_command_line".
*
* This is used for constructing applications not from main, such as a subapp,
* where the CommandLine is duplicated from the parent application.
*
* The following parameters are specified:
* _app_name - The \p name
* _comm - The setup communicator from \p comm_world_in
* _app_builder_state - The state from the AppBuilder needed in the Builder
*
* This will merge all of the CLI args from the CommandLine and do an initial walk of the hit tree
* to evaluate the brace expressions and look for duplicate variables. It will also populate
* Application/... from both input and command line.
*
* @param name The name of the application to build
* @param params The base parameters for the application
* @param comm_world_in The MPI communicator
*/
void buildParamsFromCommandLine(const std::string & name,
InputParameters & params,
MPI_Comm comm_world_in);

/**
* Helper struct for storing the state produced by build() that is needed
* by the Builder later on
*/
struct State
{
/// Root node for the parsed CLI hit arguments
std::unique_ptr<hit::Node> cli_root;
/// The variables that were extracted from Application/*
std::set<std::string> extracted_vars;
};

protected:
/**
* Performs the initial walk.
*
* Expands things and does some simple error checking
*/
void initialWalk();
};

}
Loading

0 comments on commit 837cd99

Please sign in to comment.