www.mooseframework.org
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
Parser Class Reference

Class for parsing input files. More...

#include <Parser.h>

Inheritance diagram for Parser:
[legend]

Public Types

enum  SyntaxFormatterType { INPUT_FILE, YAML }
 

Public Member Functions

 Parser (MooseApp &app, ActionWarehouse &action_wh)
 
virtual ~Parser ()
 
std::string getFileName (bool stripLeadingPath=true) const
 Return the filename that was parsed. More...
 
void parse (const std::string &input_filename)
 Parse an input file consisting of hit syntax and setup objects in the MOOSE derived application. More...
 
void extractParams (const std::string &prefix, InputParameters &p)
 This function attempts to extract values from the input file based on the contents of the passed parameters objects. More...
 
void initSyntaxFormatter (SyntaxFormatterType type, bool dump_mode)
 Creates a syntax formatter for printing. More...
 
void buildFullTree (const std::string &search_string)
 Use MOOSE Factories to construct a full parse tree for documentation or echoing input. More...
 
void buildJsonSyntaxTree (JsonSyntaxTree &tree) const
 Use MOOSE Factories to construct a parameter tree for documentation or echoing input. More...
 
void walk (const std::string &fullpath, const std::string &nodepath, hit::Node *n)
 
void errorCheck (const Parallel::Communicator &comm, bool warn_unused, bool err_unused)
 
std::vector< std::string > listValidParams (std::string &section_name)
 

Public Attributes

const ConsoleStream _console
 An instance of helper class to write streams to the Console objects. More...
 

Protected Member Functions

template<typename T , typename Base >
void setScalarParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< T > *param, bool in_global, GlobalParamsAction *global_block)
 Helper functions for setting parameters of arbitrary types - bodies are in the .C file since they are called only from this Object. More...
 
template<typename T , typename UP_T , typename Base >
void setScalarValueTypeParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< T > *param, bool in_global, GlobalParamsAction *global_block)
 
template<typename T , typename Base >
void setVectorParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< std::vector< T >> *param, bool in_global, GlobalParamsAction *global_block)
 Template method for setting any vector type parameter read from the input file or command line. More...
 
template<typename T >
void setFilePathParam (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< T > *param, InputParameters &params, bool in_global, GlobalParamsAction *global_block)
 Sets an input parameter representing a file path using input file data. More...
 
template<typename T >
void setVectorFilePathParam (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< std::vector< T >> *param, InputParameters &params, bool in_global, GlobalParamsAction *global_block)
 Sets an input parameter representing a vector of file paths using input file data. More...
 
template<typename T >
void setDoubleIndexParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< std::vector< std::vector< T >>> *param, bool in_global, GlobalParamsAction *global_block)
 Template method for setting any double indexed type parameter read from the input file or command line. More...
 
template<typename T >
void setScalarComponentParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< T > *param, bool in_global, GlobalParamsAction *global_block)
 Template method for setting any multivalue "scalar" type parameter read from the input file or command line. More...
 
template<typename T >
void setVectorComponentParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< std::vector< T >> *param, bool in_global, GlobalParamsAction *global_block)
 Template method for setting several multivalue "scalar" type parameter read from the input file or command line. More...
 
template<>
void setScalarParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< RealVectorValue > *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setScalarParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< Point > *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setScalarParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< PostprocessorName > *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setScalarParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< MooseEnum > *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setScalarParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< MultiMooseEnum > *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setScalarParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< ExecFlagEnum > *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setScalarParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< RealTensorValue > *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setVectorParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< std::vector< RealVectorValue >> *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setVectorParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< std::vector< Point >> *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setVectorParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< std::vector< MooseEnum >> *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setVectorParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< std::vector< VariableName >> *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setScalarParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< RealVectorValue > *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setScalarParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< Point > *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setScalarParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< MooseEnum > *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setScalarParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< MultiMooseEnum > *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setScalarParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< ExecFlagEnum > *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setScalarParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< RealTensorValue > *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setScalarParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< PostprocessorName > *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setVectorParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< std::vector< RealVectorValue >> *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setVectorParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< std::vector< Point >> *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setVectorParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< std::vector< MooseEnum >> *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setVectorParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< std::vector< VariableName >> *param, bool, GlobalParamsAction *)
 Specialization for coupling vectors. More...
 

Protected Attributes

std::unique_ptr< hit::Node > _cli_root = nullptr
 
std::unique_ptr< hit::Node > _root = nullptr
 
std::vector< std::string > _secs_need_first
 
MooseApp_app
 The MooseApp this Parser is part of. More...
 
Factory_factory
 The Factory associated with that MooseApp. More...
 
ActionWarehouse_action_wh
 Action warehouse that will be filled by actions. More...
 
ActionFactory_action_factory
 The Factory that builds actions. More...
 
Syntax_syntax
 Reference to an object that defines input file syntax. More...
 
std::unique_ptr< SyntaxTree_syntax_formatter
 Object for holding the syntax parse tree. More...
 
std::string _input_filename
 The input file name that is used for parameter extraction. More...
 
std::set< std::string > _extracted_vars
 The set of all variables extracted from the input file. More...
 
bool _sections_read
 Boolean to indicate whether parsing has started (sections have been extracted) More...
 
InputParameters_current_params
 The current parameter object for which parameters are being extracted. More...
 
std::ostringstream * _current_error_stream
 The current stream object used for capturing errors during extraction. More...
 

Private Member Functions

std::string hitCLIFilter (std::string appname, int argc, char *argv[])
 
void walkRaw (std::string fullpath, std::string nodepath, hit::Node *n)
 

Private Attributes

std::string _errmsg
 
std::string _warnmsg
 

Detailed Description

Class for parsing input files.

This class utilizes the GetPot library for actually tokenizing and parsing files. It is not currently designed for extensibility. If you wish to build your own parser, please contact the MOOSE team for guidance.

Definition at line 115 of file Parser.h.

Member Enumeration Documentation

◆ SyntaxFormatterType

Enumerator
INPUT_FILE 
YAML 

Definition at line 118 of file Parser.h.

119  {
120  INPUT_FILE,
121  YAML
122  };

Constructor & Destructor Documentation

◆ Parser()

Parser::Parser ( MooseApp app,
ActionWarehouse action_wh 
)

Definition at line 51 of file Parser.C.

53  _app(app),
54  _factory(app.getFactory()),
55  _action_wh(action_wh),
58  _syntax_formatter(nullptr),
59  _sections_read(false),
60  _current_params(nullptr),
61  _current_error_stream(nullptr)
62 {
63 }
MooseApp & _app
The MooseApp this Parser is part of.
Definition: Parser.h:256
bool _sections_read
Boolean to indicate whether parsing has started (sections have been extracted)
Definition: Parser.h:276
Syntax & _syntax
Reference to an object that defines input file syntax.
Definition: Parser.h:264
ActionFactory & getActionFactory()
Retrieve the ActionFactory associated with this App.
Definition: MooseApp.h:286
Factory & getFactory()
Retrieve the Factory associated with this App.
Definition: MooseApp.h:279
ConsoleStreamInterface(MooseApp &app)
A class for providing a helper stream object for writting message to all the Output objects...
std::unique_ptr< SyntaxTree > _syntax_formatter
Object for holding the syntax parse tree.
Definition: Parser.h:267
ActionWarehouse & _action_wh
Action warehouse that will be filled by actions.
Definition: Parser.h:260
std::ostringstream * _current_error_stream
The current stream object used for capturing errors during extraction.
Definition: Parser.h:282
InputParameters * _current_params
The current parameter object for which parameters are being extracted.
Definition: Parser.h:279
Factory & _factory
The Factory associated with that MooseApp.
Definition: Parser.h:258
ActionFactory & _action_factory
The Factory that builds actions.
Definition: Parser.h:262

◆ ~Parser()

Parser::~Parser ( )
virtual

Definition at line 65 of file Parser.C.

65 {}

Member Function Documentation

◆ buildFullTree()

void Parser::buildFullTree ( const std::string &  search_string)

Use MOOSE Factories to construct a full parse tree for documentation or echoing input.

If the task is nullptr that means we need to figure out which task goes with this syntax for the purpose of building the Moose Object part of the tree. We will figure this out by asking the ActionFactory for the registration info.

We need to see if this action is inherited from MooseObjectAction. If it is, then we will loop over all the Objects in MOOSE's Factory object to print them out if they have associated bases matching the current task.

Now that we know that this is a MooseObjectAction we need to see if it has been restricted in any way by the user.

Definition at line 767 of file Parser.C.

Referenced by MooseApp::setupOptions().

768 {
769  std::vector<std::pair<std::string, Syntax::ActionInfo>> all_names;
770 
771  for (const auto & iter : _syntax.getAssociatedActions())
772  {
773  Syntax::ActionInfo act_info = iter.second;
779  if (act_info._task == "")
780  act_info._task = _action_factory.getTaskName(act_info._action);
781 
782  all_names.push_back(std::pair<std::string, Syntax::ActionInfo>(iter.first, act_info));
783  }
784 
785  for (const auto & act_names : all_names)
786  {
787  InputParameters action_obj_params = _action_factory.getValidParams(act_names.second._action);
788  _syntax_formatter->insertNode(
789  act_names.first, act_names.second._action, true, &action_obj_params);
790 
791  const std::string & task = act_names.second._task;
792  std::string act_name = act_names.first;
793 
799  if (action_obj_params.have_parameter<bool>("isObjectAction") &&
800  action_obj_params.get<bool>("isObjectAction"))
801  {
803  moose_obj != _factory.registeredObjectsEnd();
804  ++moose_obj)
805  {
806  InputParameters moose_obj_params = (moose_obj->second)();
811  const std::vector<std::string> & buildable_types = action_obj_params.getBuildableTypes();
812 
813  // See if the current Moose Object syntax belongs under this Action's block
814  if ((buildable_types.empty() || // Not restricted
815  std::find(buildable_types.begin(), buildable_types.end(), moose_obj->first) !=
816  buildable_types.end()) && // Restricted but found
817  moose_obj_params.have_parameter<std::string>("_moose_base") && // Has a registered base
818  _syntax.verifyMooseObjectTask(moose_obj_params.get<std::string>("_moose_base"),
819  task) && // and that base is associated
820  action_obj_params.mooseObjectSyntaxVisibility()) // and the Action says it's visible
821  {
822  std::string name;
823  size_t pos = 0;
824  bool is_action_params = false;
825  if (act_name[act_name.size() - 1] == '*')
826  {
827  pos = act_name.size();
828 
829  if (!action_obj_params.collapseSyntaxNesting())
830  name = act_name.substr(0, pos - 1) + moose_obj->first;
831  else
832  {
833  name = act_name.substr(0, pos - 1) + "/<type>/" + moose_obj->first;
834  is_action_params = true;
835  }
836  }
837  else
838  {
839  name = act_name + "/<type>/" + moose_obj->first;
840  }
841 
842  moose_obj_params.set<std::string>("type") = moose_obj->first;
843 
844  _syntax_formatter->insertNode(
845  name, moose_obj->first, is_action_params, &moose_obj_params);
846  }
847  }
848  }
849  }
850 
851  // Do not change to _console, we need this printed to the stdout in all cases
852  Moose::out << _syntax_formatter->print(search_string) << std::flush;
853 }
const std::multimap< std::string, ActionInfo > & getAssociatedActions() const
Return all Syntax to Action associations.
Definition: Syntax.C:301
registeredMooseObjectIterator registeredObjectsEnd()
Access to registered object iterator (end)
Definition: Factory.h:339
void mooseObjectSyntaxVisibility(bool visibility)
Mutators for controlling whether or not the outermost level of syntax will be collapsed when printed...
InputParameters getValidParams(const std::string &name)
Definition: ActionFactory.C:70
const std::vector< std::string > & getBuildableTypes() const
Returns the list of buildable types as a std::vector<std::string>
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Syntax & _syntax
Reference to an object that defines input file syntax.
Definition: Parser.h:264
std::map< std::string, paramsPtr >::iterator registeredMooseObjectIterator
alias for registered Object iterator
Definition: Factory.h:139
std::string _action
Definition: Syntax.h:26
std::unique_ptr< SyntaxTree > _syntax_formatter
Object for holding the syntax parse tree.
Definition: Parser.h:267
registeredMooseObjectIterator registeredObjectsBegin()
Access to registered object iterator (begin)
Definition: Factory.h:334
std::string getTaskName(const std::string &action)
Definition: ActionFactory.C:90
std::string _task
Definition: Syntax.h:27
bool verifyMooseObjectTask(const std::string &base, const std::string &task) const
Returns a Boolean indicating whether a task is associated with on of the MOOSE pluggable systems (BAS...
Definition: Syntax.C:277
void collapseSyntaxNesting(bool collapse)
Mutators for controlling whether or not the outermost level of syntax will be collapsed when printed...
Factory & _factory
The Factory associated with that MooseApp.
Definition: Parser.h:258
ActionFactory & _action_factory
The Factory that builds actions.
Definition: Parser.h:262

◆ buildJsonSyntaxTree()

void Parser::buildJsonSyntaxTree ( JsonSyntaxTree tree) const

Use MOOSE Factories to construct a parameter tree for documentation or echoing input.

If the task is nullptr that means we need to figure out which task goes with this syntax for the purpose of building the Moose Object part of the tree. We will figure this out by asking the ActionFactory for the registration info.

We need to see if this action is inherited from MooseObjectAction. If it is, then we will loop over all the Objects in MOOSE's Factory object to print them out if they have associated bases matching the current task.

Definition at line 651 of file Parser.C.

Referenced by MooseApp::setupOptions().

652 {
653  std::vector<std::pair<std::string, Syntax::ActionInfo>> all_names;
654 
655  for (const auto & iter : _syntax.getAssociatedTypes())
656  root.addSyntaxType(iter.first, iter.second);
657 
658  for (const auto & iter : _syntax.getAssociatedActions())
659  {
660  Syntax::ActionInfo act_info = iter.second;
666  if (act_info._task == "")
667  act_info._task = _action_factory.getTaskName(act_info._action);
668 
669  all_names.push_back(std::make_pair(iter.first, act_info));
670  }
671 
672  for (const auto & act_names : all_names)
673  {
674  const auto & act_info = act_names.second;
675  const std::string & action = act_info._action;
676  const std::string & task = act_info._task;
677  const std::string act_name = act_names.first;
678  InputParameters action_obj_params = _action_factory.getValidParams(action);
679  bool params_added = root.addParameters("",
680  act_name,
681  false,
682  action,
683  true,
684  &action_obj_params,
685  _syntax.getLineInfo(act_name, action, ""),
686  "");
687 
688  if (params_added)
689  {
690  auto tasks = _action_factory.getTasksByAction(action);
691  for (auto & t : tasks)
692  {
693  auto info = _action_factory.getLineInfo(action, t);
694  root.addActionTask(act_name, action, t, info);
695  }
696  }
697 
703  if (action_obj_params.have_parameter<bool>("isObjectAction") &&
704  action_obj_params.get<bool>("isObjectAction"))
705  {
707  moose_obj != _factory.registeredObjectsEnd();
708  ++moose_obj)
709  {
710  InputParameters moose_obj_params = (moose_obj->second)();
711  // Now that we know that this is a MooseObjectAction we need to see if it has been
712  // restricted
713  // in any way by the user.
714  const std::vector<std::string> & buildable_types = action_obj_params.getBuildableTypes();
715 
716  // See if the current Moose Object syntax belongs under this Action's block
717  if ((buildable_types.empty() || // Not restricted
718  std::find(buildable_types.begin(), buildable_types.end(), moose_obj->first) !=
719  buildable_types.end()) && // Restricted but found
720  moose_obj_params.have_parameter<std::string>("_moose_base") && // Has a registered base
721  _syntax.verifyMooseObjectTask(moose_obj_params.get<std::string>("_moose_base"),
722  task) && // and that base is associated
723  action_obj_params.mooseObjectSyntaxVisibility()) // and the Action says it's visible
724  {
725  std::string name;
726  size_t pos = 0;
727  bool is_action_params = false;
728  bool is_type = false;
729  if (act_name[act_name.size() - 1] == '*')
730  {
731  pos = act_name.size();
732 
733  if (!action_obj_params.collapseSyntaxNesting())
734  name = act_name.substr(0, pos - 1) + moose_obj->first;
735  else
736  {
737  name = act_name.substr(0, pos - 1) + "/<type>/" + moose_obj->first;
738  is_action_params = true;
739  }
740  }
741  else
742  {
743  name = act_name + "/<type>/" + moose_obj->first;
744  is_type = true;
745  }
746 
747  moose_obj_params.set<std::string>("type") = moose_obj->first;
748 
749  auto lineinfo = _factory.getLineInfo(moose_obj->first);
750  std::string classname = _factory.associatedClassName(moose_obj->first);
751  root.addParameters(act_name,
752  name,
753  is_type,
754  moose_obj->first,
755  is_action_params,
756  &moose_obj_params,
757  lineinfo,
758  classname);
759  }
760  }
761  }
762  }
763  root.addGlobal();
764 }
const std::multimap< std::string, std::string > & getAssociatedTypes() const
Get a multimap of registered associations of syntax with type.
Definition: Syntax.C:295
const std::multimap< std::string, ActionInfo > & getAssociatedActions() const
Return all Syntax to Action associations.
Definition: Syntax.C:301
registeredMooseObjectIterator registeredObjectsEnd()
Access to registered object iterator (end)
Definition: Factory.h:339
void mooseObjectSyntaxVisibility(bool visibility)
Mutators for controlling whether or not the outermost level of syntax will be collapsed when printed...
InputParameters getValidParams(const std::string &name)
Definition: ActionFactory.C:70
std::string associatedClassName(const std::string &name) const
Get the associated class name for an object name.
Definition: Factory.C:298
std::set< std::string > getTasksByAction(const std::string &action) const
const std::vector< std::string > & getBuildableTypes() const
Returns the list of buildable types as a std::vector<std::string>
FileLineInfo getLineInfo(const std::string &syntax, const std::string &action, const std::string &task) const
Gets the file and line where the syntax/action/task combo was registered.
Definition: Syntax.C:307
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
FileLineInfo getLineInfo(const std::string &name, const std::string &task) const
Gets file and line information where an action was registered.
Syntax & _syntax
Reference to an object that defines input file syntax.
Definition: Parser.h:264
std::map< std::string, paramsPtr >::iterator registeredMooseObjectIterator
alias for registered Object iterator
Definition: Factory.h:139
std::string _action
Definition: Syntax.h:26
FileLineInfo getLineInfo(const std::string &name) const
Gets file and line information where an object was initially registered.
Definition: Factory.C:286
registeredMooseObjectIterator registeredObjectsBegin()
Access to registered object iterator (begin)
Definition: Factory.h:334
std::string getTaskName(const std::string &action)
Definition: ActionFactory.C:90
std::string _task
Definition: Syntax.h:27
bool verifyMooseObjectTask(const std::string &base, const std::string &task) const
Returns a Boolean indicating whether a task is associated with on of the MOOSE pluggable systems (BAS...
Definition: Syntax.C:277
void collapseSyntaxNesting(bool collapse)
Mutators for controlling whether or not the outermost level of syntax will be collapsed when printed...
Factory & _factory
The Factory associated with that MooseApp.
Definition: Parser.h:258
ActionFactory & _action_factory
The Factory that builds actions.
Definition: Parser.h:262

◆ errorCheck()

void Parser::errorCheck ( const Parallel::Communicator &  comm,
bool  warn_unused,
bool  err_unused 
)

Definition at line 590 of file Parser.C.

Referenced by MooseApp::errorCheck().

591 {
592  // this if guard is important in case the simulation was not configured via parsed input text -
593  // e.g. configured programatically.
594  if (!_root || !_cli_root)
595  return;
596 
598  UnusedWalker uwcli("CLI_ARG", _extracted_vars, *this);
599 
600  _root->walk(&uw);
601  _cli_root->walk(&uwcli);
602 
603  auto cli = _app.commandLine();
604  if (warn_unused)
605  {
606  for (auto arg : cli->unused(comm))
607  _warnmsg +=
608  errormsg("CLI_ARG", nullptr, "unused command line parameter '", cli->argv()[arg], "'") +
609  "\n";
610  for (auto & msg : uwcli.errors)
611  _warnmsg += msg + "\n";
612  for (auto & msg : uw.errors)
613  _warnmsg += msg + "\n";
614  }
615  else if (err_unused)
616  {
617  for (auto arg : cli->unused(comm))
618  _errmsg +=
619  errormsg("CLI_ARG", nullptr, "unused command line parameter '", cli->argv()[arg], "'") +
620  "\n";
621  for (auto & msg : uwcli.errors)
622  _errmsg += msg + "\n";
623  for (auto & msg : uw.errors)
624  _errmsg += msg + "\n";
625  }
626 
627  if (_warnmsg.size() > 0)
629  if (_errmsg.size() > 0)
631 }
MooseApp & _app
The MooseApp this Parser is part of.
Definition: Parser.h:256
std::string _warnmsg
Definition: Parser.h:286
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
std::shared_ptr< CommandLine > commandLine() const
Get the command line.
Definition: MooseApp.h:293
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:270
std::unique_ptr< hit::Node > _cli_root
Definition: Parser.h:251
void mooseUnused(Args &&... args)
Warning message used to notify the users of unused parts of their input files Really used internally ...
Definition: MooseError.h:229
std::string _errmsg
Definition: Parser.h:285
std::set< std::string > _extracted_vars
The set of all variables extracted from the input file.
Definition: Parser.h:273
std::string errormsg(std::string, hit::Node *)
Definition: Parser.h:34
std::unique_ptr< hit::Node > _root
Definition: Parser.h:252
MPI_Comm comm

◆ extractParams()

void Parser::extractParams ( const std::string &  prefix,
InputParameters p 
)

This function attempts to extract values from the input file based on the contents of the passed parameters objects.

It handles a number of various types with dynamic casting including vector types

Special case handling if the parameter wasn't found in the input file or the cli object the logic in this branch will execute

Scalar types

Definition at line 951 of file Parser.C.

Referenced by walkRaw().

952 {
953  std::ostringstream error_stream;
954  static const std::string global_params_task = "set_global_params";
955  static const std::string global_params_block_name =
956  _syntax.getSyntaxByAction("GlobalParamsAction").front();
957 
958  ActionIterator act_iter = _action_wh.actionBlocksWithActionBegin(global_params_task);
959  GlobalParamsAction * global_params_block = nullptr;
960 
961  // We are grabbing only the first
962  if (act_iter != _action_wh.actionBlocksWithActionEnd(global_params_task))
963  global_params_block = dynamic_cast<GlobalParamsAction *>(*act_iter);
964 
965  // Set a pointer to the current InputParameters object being parsed so that it can be referred
966  // to
967  // in the extraction routines
968  _current_params = &p;
969  _current_error_stream = &error_stream;
970  for (const auto & it : p)
971  {
972  bool found = false;
973  bool in_global = false;
974  std::string orig_name = prefix + "/" + it.first;
975  std::string full_name = orig_name;
976 
977  // Mark parameters appearing in the input file or command line
978  if (_root->find(full_name) && _root->find(full_name)->type() == hit::NodeType::Field)
979  {
980  p.set_attributes(it.first, false);
981  _extracted_vars.insert(
982  full_name); // Keep track of all variables extracted from the input file
983  found = true;
984  p.inputLocation(it.first) =
985  _input_filename + ":" + std::to_string(_root->find(full_name)->line());
986  p.paramFullpath(it.first) = full_name;
987  }
988  // Wait! Check the GlobalParams section
989  else if (global_params_block)
990  {
991  full_name = global_params_block_name + "/" + it.first;
992  if (_root->find(full_name))
993  {
994  p.set_attributes(it.first, false);
995  _extracted_vars.insert(
996  full_name); // Keep track of all variables extracted from the input file
997  found = true;
998  in_global = true;
999  p.inputLocation(it.first) =
1000  _input_filename + ":" + std::to_string(_root->find(full_name)->line());
1001  p.paramFullpath(it.first) = full_name;
1002  }
1003  }
1004 
1005  if (!found)
1006  {
1013  // In the case where we have OutFileName but it wasn't actually found in the input filename,
1014  // we will populate it with the actual parsed filename which is available here in the
1015  // parser.
1016 
1017  InputParameters::Parameter<OutFileBase> * scalar_p =
1018  dynamic_cast<InputParameters::Parameter<OutFileBase> *>(it.second);
1019  if (scalar_p)
1020  {
1021  std::string input_file_name = getFileName();
1022  mooseAssert(input_file_name != "", "Input Filename is nullptr");
1023  size_t pos = input_file_name.find_last_of('.');
1024  mooseAssert(pos != std::string::npos, "Unable to determine suffix of input file name");
1025  scalar_p->set() = input_file_name.substr(0, pos) + "_out";
1026  p.set_attributes(it.first, false);
1027  }
1028  }
1029  else
1030  {
1031  if (p.isPrivate(it.first))
1032  mooseError("The parameter '",
1033  full_name,
1034  "' is a private parameter and should not be used in an input file.");
1035 
1036  auto par = it.second;
1037  auto short_name = it.first;
1038 
1039 #define setscalarvaltype(ptype, base, range) \
1040  else if (par->type() == demangle(typeid(ptype).name())) \
1041  setScalarValueTypeParameter<ptype, range, base>( \
1042  full_name, \
1043  short_name, \
1044  dynamic_cast<InputParameters::Parameter<ptype> *>(par), \
1045  in_global, \
1046  global_params_block)
1047 #define setscalar(ptype, base) \
1048  else if (par->type() == demangle(typeid(ptype).name())) \
1049  setScalarParameter<ptype, base>(full_name, \
1050  short_name, \
1051  dynamic_cast<InputParameters::Parameter<ptype> *>(par), \
1052  in_global, \
1053  global_params_block)
1054 #define setfpath(ptype) \
1055  else if (par->type() == demangle(typeid(ptype).name())) \
1056  setFilePathParam<ptype>(full_name, \
1057  short_name, \
1058  dynamic_cast<InputParameters::Parameter<ptype> *>(par), \
1059  p, \
1060  in_global, \
1061  global_params_block)
1062 #define setvector(ptype, base) \
1063  else if (par->type() == demangle(typeid(std::vector<ptype>).name())) \
1064  setVectorParameter<ptype, base>( \
1065  full_name, \
1066  short_name, \
1067  dynamic_cast<InputParameters::Parameter<std::vector<ptype>> *>(par), \
1068  in_global, \
1069  global_params_block)
1070 #define setvectorfpath(ptype) \
1071  else if (par->type() == demangle(typeid(std::vector<ptype>).name())) \
1072  setVectorFilePathParam<ptype>( \
1073  full_name, \
1074  short_name, \
1075  dynamic_cast<InputParameters::Parameter<std::vector<ptype>> *>(par), \
1076  p, \
1077  in_global, \
1078  global_params_block)
1079 #define setvectorvector(ptype) \
1080  else if (par->type() == demangle(typeid(std::vector<std::vector<ptype>>).name())) \
1081  setDoubleIndexParameter<ptype>( \
1082  full_name, \
1083  short_name, \
1084  dynamic_cast<InputParameters::Parameter<std::vector<std::vector<ptype>>> *>(par), \
1085  in_global, \
1086  global_params_block)
1087 
1091  // built-ins
1092  // NOTE: Similar dynamic casting is done in InputParameters.C, please update appropriately
1093  if (false)
1094  ;
1095  setscalarvaltype(Real, double, Real);
1096  setscalarvaltype(int, int, long);
1097  setscalarvaltype(unsigned short, unsigned int, long);
1098  setscalarvaltype(long, int, long);
1099  setscalarvaltype(unsigned int, unsigned int, long);
1100  setscalarvaltype(unsigned long, unsigned int, long);
1101  setscalarvaltype(long int, int64_t, long);
1102  setscalarvaltype(unsigned long long, unsigned int, long);
1103 
1104  setscalar(bool, bool);
1105  setscalar(SubdomainID, int);
1106  setscalar(BoundaryID, int);
1107 
1108  // string and string-subclass types
1109  setscalar(string, string);
1110  setscalar(SubdomainName, string);
1111  setscalar(BoundaryName, string);
1112  setfpath(FileName);
1113  setfpath(MeshFileName);
1114  setfpath(FileNameNoExtension);
1115  setscalar(OutFileBase, string);
1116  setscalar(VariableName, string);
1117  setscalar(NonlinearVariableName, string);
1118  setscalar(AuxVariableName, string);
1119  setscalar(FunctionName, string);
1120  setscalar(UserObjectName, string);
1121  setscalar(VectorPostprocessorName, string);
1122  setscalar(IndicatorName, string);
1123  setscalar(MarkerName, string);
1124  setscalar(MultiAppName, string);
1125  setscalar(OutputName, string);
1126  setscalar(MaterialPropertyName, string);
1127  setscalar(MaterialName, string);
1128  setscalar(DistributionName, string);
1129  setscalar(SamplerName, string);
1130  setscalar(TagName, string);
1131  setscalar(MeshGeneratorName, string);
1132 
1133  setscalar(PostprocessorName, PostprocessorName);
1134 
1135  // Moose Compound Scalars
1136  setscalar(RealVectorValue, RealVectorValue);
1137  setscalar(Point, Point);
1138  setscalar(MooseEnum, MooseEnum);
1139  setscalar(MultiMooseEnum, MultiMooseEnum);
1140  setscalar(RealTensorValue, RealTensorValue);
1141  setscalar(ExecFlagEnum, ExecFlagEnum);
1142 
1143  // vector types
1144  setvector(Real, double);
1145  setvector(int, int);
1146  setvector(long, int);
1147  setvector(unsigned int, int);
1148 
1149 // We need to be able to parse 8-byte unsigned types when
1150 // libmesh is configured --with-dof-id-bytes=8. Officially,
1151 // libmesh uses uint64_t in that scenario, which is usually
1152 // equivalent to 'unsigned long long'. Note that 'long long'
1153 // has been around since C99 so most C++ compilers support it,
1154 // but presumably uint64_t is the "most standard" way to get a
1155 // 64-bit unsigned type, so we'll stick with that here.
1156 #if LIBMESH_DOF_ID_BYTES == 8
1157  setvector(uint64_t, int);
1158 #endif
1159 
1160  setvector(SubdomainID, int);
1161  setvector(BoundaryID, int);
1162  setvector(RealVectorValue, double);
1163  setvector(Point, Point);
1164  setvector(MooseEnum, MooseEnum);
1165 
1166  setvector(string, string);
1167  setvectorfpath(FileName);
1168  setvectorfpath(FileNameNoExtension);
1169  setvectorfpath(MeshFileName);
1170  setvector(SubdomainName, string);
1171  setvector(BoundaryName, string);
1172  setvector(NonlinearVariableName, string);
1173  setvector(AuxVariableName, string);
1174  setvector(FunctionName, string);
1175  setvector(UserObjectName, string);
1176  setvector(IndicatorName, string);
1177  setvector(MarkerName, string);
1178  setvector(MultiAppName, string);
1179  setvector(PostprocessorName, string);
1180  setvector(VectorPostprocessorName, string);
1181  setvector(OutputName, string);
1182  setvector(MaterialPropertyName, string);
1183  setvector(MaterialName, string);
1184  setvector(DistributionName, string);
1185  setvector(SamplerName, string);
1186  setvector(TagName, string);
1187  setvector(VariableName, VariableName);
1188  setvector(MeshGeneratorName, string);
1189 
1190  // Double indexed types
1191  setvectorvector(Real);
1192  setvectorvector(int);
1193  setvectorvector(long);
1194  setvectorvector(unsigned int);
1195  setvectorvector(unsigned long long);
1196 
1197 // See vector type explanation
1198 #if LIBMESH_DOF_ID_BYTES == 8
1199  setvectorvector(uint64_t);
1200 #endif
1201 
1202  setvectorvector(SubdomainID);
1203  setvectorvector(BoundaryID);
1204  setvectorvector(string);
1205  setvectorvector(FileName);
1206  setvectorvector(FileNameNoExtension);
1207  setvectorvector(MeshFileName);
1208  setvectorvector(SubdomainName);
1209  setvectorvector(BoundaryName);
1210  setvectorvector(VariableName);
1211  setvectorvector(NonlinearVariableName);
1212  setvectorvector(AuxVariableName);
1213  setvectorvector(FunctionName);
1214  setvectorvector(UserObjectName);
1215  setvectorvector(IndicatorName);
1216  setvectorvector(MarkerName);
1217  setvectorvector(MultiAppName);
1218  setvectorvector(PostprocessorName);
1219  setvectorvector(VectorPostprocessorName);
1220  setvectorvector(MarkerName);
1221  setvectorvector(OutputName);
1222  setvectorvector(MaterialPropertyName);
1223  setvectorvector(MaterialName);
1224  setvectorvector(DistributionName);
1225  setvectorvector(SamplerName);
1226  else
1227  {
1228  mooseError("unsupported type '", par->type(), "' for input parameter '", full_name, "'");
1229  }
1230 
1231 #undef setscalarValueType
1232 #undef setscalar
1233 #undef setvector
1234 #undef setvectorvector
1235  }
1236  }
1237 
1238  // All of the parameters for this object have been extracted. See if there are any errors
1239  if (!error_stream.str().empty())
1240  mooseError(error_stream.str());
1241 
1242  // Here we will see if there are any auto build vectors that need to be created
1243  std::map<std::string, std::pair<std::string, std::string>> auto_build_vectors =
1244  p.getAutoBuildVectors();
1245  for (const auto & it : auto_build_vectors)
1246  {
1247  // We'll autogenerate values iff the requested vector is not valid but both the base and
1248  // number
1249  // are valid
1250  const std::string & base_name = it.second.first;
1251  const std::string & num_repeat = it.second.second;
1252 
1253  if (!p.isParamValid(it.first) && p.isParamValid(base_name) && p.isParamValid(num_repeat))
1254  {
1255  unsigned int vec_size = p.get<unsigned int>(num_repeat);
1256  const std::string & name = p.get<std::string>(base_name);
1257 
1258  std::vector<VariableName> variable_names(vec_size);
1259  for (unsigned int i = 0; i < vec_size; ++i)
1260  {
1261  std::ostringstream oss;
1262  oss << name << i;
1263  variable_names[i] = oss.str();
1264  }
1265 
1266  // Finally set the autogenerated vector into the InputParameters object
1267  p.set<std::vector<VariableName>>(it.first) = variable_names;
1268  }
1269  }
1270 }
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:25
std::list< Action * >::iterator ActionIterator
alias to hide implementation details
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
subdomain_id_type SubdomainID
Definition: MooseTypes.h:95
Syntax & _syntax
Reference to an object that defines input file syntax.
Definition: Parser.h:264
std::vector< std::string > getSyntaxByAction(const std::string &action, const std::string &task="")
Retrieve the syntax associated with the passed in action type string.
Definition: Syntax.C:183
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:270
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:32
std::set< std::string > _extracted_vars
The set of all variables extracted from the input file.
Definition: Parser.h:273
ActionWarehouse & _action_wh
Action warehouse that will be filled by actions.
Definition: Parser.h:260
std::ostringstream * _current_error_stream
The current stream object used for capturing errors during extraction.
Definition: Parser.h:282
std::unique_ptr< hit::Node > _root
Definition: Parser.h:252
std::string getFileName(bool stripLeadingPath=true) const
Return the filename that was parsed.
Definition: Parser.C:289
ActionIterator actionBlocksWithActionEnd(const std::string &task)
InputParameters * _current_params
The current parameter object for which parameters are being extracted.
Definition: Parser.h:279
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
ActionIterator actionBlocksWithActionBegin(const std::string &task)
Iterators to the Actions in the warehouse.
boundary_id_type BoundaryID
Definition: MooseTypes.h:93

◆ getFileName()

std::string Parser::getFileName ( bool  stripLeadingPath = true) const

Return the filename that was parsed.

Definition at line 289 of file Parser.C.

Referenced by MeshOnlyAction::act(), extractParams(), MooseApp::getFileName(), and walkRaw().

290 {
291  if (!stripLeadingPath)
292  return _input_filename;
293 
294  std::string filename;
295  size_t pos = _input_filename.find_last_of('/');
296  if (pos != std::string::npos)
297  filename = _input_filename.substr(pos + 1);
298  else
299  filename = _input_filename;
300 
301  return filename;
302 }
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:270

◆ hitCLIFilter()

std::string Parser::hitCLIFilter ( std::string  appname,
int  argc,
char *  argv[] 
)
private

Definition at line 406 of file Parser.C.

Referenced by parse().

407 {
408  std::string hit_text;
409  bool afterDoubleDash = false;
410  for (int i = 1; i < argc; i++)
411  {
412  std::string arg(argv[i]);
413 
414  // all args after a "--" are hit parameters
415  if (arg == "--")
416  {
417  afterDoubleDash = true;
418  continue;
419  } // otherwise try to guess if a hit params have started by looking for "=" and "/"
420  else if (arg.find("=", 0) != std::string::npos)
421  afterDoubleDash = true;
422 
423  // skip arguments with no equals sign
424  if (arg.find("=", 0) == std::string::npos)
425  continue;
426  // skip cli flags (i.e. start with dash)
427  else if (arg.find("-", 0) == 0)
428  continue;
429  // skip over args that don't look like or are before hit parameters
430  else if (!afterDoubleDash)
431  continue;
432  else if (appname == "main")
433  {
434  auto pos = arg.find(":", 0);
435  if (pos == 0) // trim leading colon
436  arg = arg.substr(pos + 1, arg.size() - pos - 1);
437  else if (pos != std::string::npos && pos < arg.find("=", 0)) // param is for non-main subapp
438  continue;
439  }
440  else if (appname != "main") // app we are loading is a multiapp subapp
441  {
442  std::string name;
443  std::string num;
444  pcrecpp::RE("(.*?)" // Match the multiapp name
445  "(\\d+)" // math the multiapp number
446  )
447  .FullMatch(appname, &name, &num);
448  auto pos = arg.find(":", 0);
449  if (pos == 0)
450  ; // cli param is ":" prefixed meaning global for all main+subapps
451  else if (pos == std::string::npos) // param is for main app - skip
452  continue;
453  else if (arg.substr(0, pos) != appname &&
454  arg.substr(0, pos) != name) // param is for different multiapp - skip
455  {
456  _app.commandLine()->markHitParam(i);
457  continue;
458  }
459  arg = arg.substr(pos + 1, arg.size() - pos - 1); // trim off subapp name prefix
460  }
461 
462  try
463  {
464  hit::check("CLI_ARG", arg);
465  hit_text += " " + arg;
466  // handle case where bash ate quotes around an empty string after the "="
467  if (arg.find("=", 0) == arg.size() - 1)
468  hit_text += "''";
469  _app.commandLine()->markHitParamUsed(i);
470  }
471  catch (hit::ParseError & err)
472  {
473  // bash might have eaten quotes around a hit string value or vector
474  // so try quoting after the "=" and reparse
475  auto quoted = arg;
476  auto pos = quoted.find("=", 0);
477  if (pos != std::string::npos)
478  quoted = arg.substr(0, pos + 1) + "'" + arg.substr(pos + 1, quoted.size() - pos) + "'";
479  try
480  {
481  hit::check("CLI_ARG", quoted);
482  hit_text += " " + quoted;
483  _app.commandLine()->markHitParamUsed(i);
484  }
485  catch (hit::ParseError & err)
486  {
487  mooseError("invalid hit in arg '", arg, "': ", err.what());
488  }
489  }
490  }
491  return hit_text;
492 }
MooseApp & _app
The MooseApp this Parser is part of.
Definition: Parser.h:256
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
std::shared_ptr< CommandLine > commandLine() const
Get the command line.
Definition: MooseApp.h:293

◆ initSyntaxFormatter()

void Parser::initSyntaxFormatter ( SyntaxFormatterType  type,
bool  dump_mode 
)

Creates a syntax formatter for printing.

Definition at line 634 of file Parser.C.

Referenced by MooseApp::setupOptions().

635 {
636  switch (type)
637  {
638  case INPUT_FILE:
639  _syntax_formatter = libmesh_make_unique<InputFileFormatter>(dump_mode);
640  break;
641  case YAML:
642  _syntax_formatter = libmesh_make_unique<YAMLFormatter>(dump_mode);
643  break;
644  default:
645  mooseError("Unrecognized Syntax Formatter requested");
646  break;
647  }
648 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
std::unique_ptr< SyntaxTree > _syntax_formatter
Object for holding the syntax parse tree.
Definition: Parser.h:267
MatType type

◆ listValidParams()

std::vector< std::string > Parser::listValidParams ( std::string &  section_name)

Definition at line 161 of file Parser.C.

Referenced by UnusedWalker::walk().

162 {
163  bool dummy;
164  std::string registered_identifier = _syntax.isAssociated(section_name, &dummy);
165  auto iters = _syntax.getActions(registered_identifier);
166 
167  std::vector<std::string> paramlist;
168  for (auto it = iters.first; it != iters.second; ++it)
169  {
170  auto params = _action_factory.getValidParams(it->second._action);
171  for (const auto & it : params)
172  paramlist.push_back(it.first);
173  }
174  return paramlist;
175 }
std::pair< std::multimap< std::string, ActionInfo >::const_iterator, std::multimap< std::string, ActionInfo >::const_iterator > getActions(const std::string &syntax) const
Returns a pair of multimap iterators to all the ActionInfo objects associated with a given piece of s...
Definition: Syntax.C:271
InputParameters getValidParams(const std::string &name)
Definition: ActionFactory.C:70
Syntax & _syntax
Reference to an object that defines input file syntax.
Definition: Parser.h:264
std::string isAssociated(const std::string &real_id, bool *is_parent) const
Method for determining whether a piece of syntax is associated with an Action TODO: I need a better n...
Definition: Syntax.C:209
ActionFactory & _action_factory
The Factory that builds actions.
Definition: Parser.h:262

◆ parse()

void Parser::parse ( const std::string &  input_filename)

Parse an input file consisting of hit syntax and setup objects in the MOOSE derived application.

Definition at line 495 of file Parser.C.

Referenced by MooseApp::setupOptions().

496 {
497  // Save the filename
498  char abspath[PATH_MAX + 1];
499  realpath(input_filename.c_str(), abspath);
500  _input_filename = std::string(abspath);
501 
502  // vector for initializing active blocks
503  std::vector<std::string> all = {"__all__"};
504 
506 
507  std::ifstream f(_input_filename);
508  std::string input((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
509 
510  try
511  {
512  _root.reset(hit::parse(_input_filename, input));
513 
514  int argc = _app.commandLine()->argc();
515  char ** argv = _app.commandLine()->argv();
516  auto cli_input = hitCLIFilter(_app.name(), argc, argv);
517 
518  _cli_root.reset(hit::parse("CLI_ARGS", cli_input));
519  hit::explode(_cli_root.get());
520  hit::explode(_root.get());
521  hit::merge(_cli_root.get(), _root.get());
522  }
523  catch (hit::ParseError & err)
524  {
525  mooseError(err.what());
526  }
527 
528  // expand ${bla} parameter values and mark/include variables used in expansions as "used". This
529  // MUST occur before parameter extraction - otherwise parameters will get wrong values.
531  _root->walk(&exw);
532  for (auto & var : exw.used)
533  _extracted_vars.insert(var);
534  for (auto & msg : exw.errors)
535  _errmsg += msg + "\n";
536 
537  // do as much error checking as early as possible so that errors are more useful instead
538  // of surprising and disconnected from what caused them.
541  _root->walk(&dw, hit::NodeType::Field);
542  _root->walk(&bw, hit::NodeType::Section);
543  for (auto & msg : dw.errors)
544  _errmsg += msg + "\n";
545  for (auto & msg : bw.errors)
546  _errmsg += msg + "\n";
547 
548  // There are a few order dependent actions that have to be built first in
549  // order for the parser and application to function properly:
550  //
551  // SetupDebugAction: This action can contain an option for monitoring the parser progress. It must
552  // be parsed first to capture all of the parsing output.
553  //
554  // GlobalParamsAction: This action is checked during the parameter extraction routines of all
555  // subsequent blocks. It must be parsed early since it must exist during
556  // subsequent parameter extraction.
557  //
558  // DynamicObjectRegistration: This action must be built before any MooseObjectActions are built.
559  // This is because we retrieve valid parameters from the Factory
560  // during parse time. Objects must be registered before
561  // validParameters can be retrieved.
562  auto syntax = _syntax.getSyntaxByAction("SetupDebugAction");
563  std::copy(syntax.begin(), syntax.end(), std::back_inserter(_secs_need_first));
564 
565  syntax = _syntax.getSyntaxByAction("GlobalParamsAction");
566  std::copy(syntax.begin(), syntax.end(), std::back_inserter(_secs_need_first));
567 
568  syntax = _syntax.getSyntaxByAction("DynamicObjectRegistrationAction");
569  std::copy(syntax.begin(), syntax.end(), std::back_inserter(_secs_need_first));
570 
571  // walk all the sections extracting paramters from each into InputParameters objects
572  for (auto & sec : _secs_need_first)
573  {
574  auto n = _root->find(sec);
575  if (n)
576  walkRaw(n->parent()->fullpath(), n->path(), n);
577  }
578  _root->walk(this, hit::NodeType::Section);
579 
580  if (_errmsg.size() > 0)
582 }
const std::string & name() const
Get the name of the object.
Definition: MooseApp.h:72
MooseApp & _app
The MooseApp this Parser is part of.
Definition: Parser.h:256
void walkRaw(std::string fullpath, std::string nodepath, hit::Node *n)
Definition: Parser.C:305
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
std::shared_ptr< CommandLine > commandLine() const
Get the command line.
Definition: MooseApp.h:293
std::vector< std::string > _secs_need_first
Definition: Parser.h:253
Syntax & _syntax
Reference to an object that defines input file syntax.
Definition: Parser.h:264
std::vector< std::string > getSyntaxByAction(const std::string &action, const std::string &task="")
Retrieve the syntax associated with the passed in action type string.
Definition: Syntax.C:183
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:270
bool checkFileReadable(const std::string &filename, bool check_line_endings=false, bool throw_on_unreadable=true)
Checks to see if a file is readable (exists and permissions)
Definition: MooseUtils.C:145
std::unique_ptr< hit::Node > _cli_root
Definition: Parser.h:251
std::string hitCLIFilter(std::string appname, int argc, char *argv[])
Definition: Parser.C:406
std::string _errmsg
Definition: Parser.h:285
std::set< std::string > _extracted_vars
The set of all variables extracted from the input file.
Definition: Parser.h:273
PetscInt n
std::unique_ptr< hit::Node > _root
Definition: Parser.h:252

◆ setDoubleIndexParameter()

template<typename T >
void Parser::setDoubleIndexParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< std::vector< std::vector< T >>> *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

Template method for setting any double indexed type parameter read from the input file or command line.

Definition at line 1466 of file Parser.C.

1471 {
1472  // Get the full string assigned to the variable full_name
1473  std::string buffer = _root->param<std::string>(full_name);
1474 
1475  // split vector at delim ;
1476  // NOTE: the substrings are _not_ of type T yet
1477  std::vector<std::string> first_tokenized_vector;
1478  MooseUtils::tokenize(buffer, first_tokenized_vector, 1, ";");
1479  param->set().resize(first_tokenized_vector.size());
1480 
1481  for (unsigned j = 0; j < first_tokenized_vector.size(); ++j)
1482  if (!MooseUtils::tokenizeAndConvert<T>(first_tokenized_vector[j], param->set()[j]))
1483  {
1484  _errmsg += errormsg(
1485  _input_filename, _root->find(full_name), "invalid format for parameter ", full_name);
1486  return;
1487  }
1488 
1489  if (in_global)
1490  {
1491  global_block->remove(short_name);
1492  global_block->setDoubleIndexParam<T>(short_name).resize(first_tokenized_vector.size());
1493  for (unsigned j = 0; j < first_tokenized_vector.size(); ++j)
1494  {
1495  global_block->setDoubleIndexParam<T>(short_name)[j].resize(param->get()[j].size());
1496  for (unsigned int i = 0; i < param->get()[j].size(); ++i)
1497  global_block->setDoubleIndexParam<T>(short_name)[j][i] = param->get()[j][i];
1498  }
1499  }
1500 }
void tokenize(const std::string &str, std::vector< T > &elements, unsigned int min_len=1, const std::string &delims="/")
This function will split the passed in string on a set of delimiters appending the substrings to the ...
Definition: MooseUtils.h:377
std::vector< std::vector< T > > & setDoubleIndexParam(const std::string &name)
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:270
std::string _errmsg
Definition: Parser.h:285
std::string errormsg(std::string, hit::Node *)
Definition: Parser.h:34
std::unique_ptr< hit::Node > _root
Definition: Parser.h:252
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...

◆ setFilePathParam()

template<typename T >
void Parser::setFilePathParam ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< T > *  param,
InputParameters params,
bool  in_global,
GlobalParamsAction global_block 
)
protected

Sets an input parameter representing a file path using input file data.

The file path is modified to be relative to the directory this application's input file is in.

Definition at line 1351 of file Parser.C.

1357 {
1358  std::string prefix;
1359  std::string postfix = _root->param<std::string>(full_name);
1360  size_t pos = _input_filename.find_last_of('/');
1361  if (pos != std::string::npos && postfix[0] != '/' && !postfix.empty())
1362  prefix = _input_filename.substr(0, pos + 1);
1363 
1364  params.rawParamVal(short_name) = postfix;
1365  param->set() = prefix + postfix;
1366 
1367  if (in_global)
1368  {
1369  global_block->remove(short_name);
1370  global_block->setScalarParam<T>(short_name) = param->get();
1371  }
1372 }
std::string & rawParamVal(const std::string &param)
Get/set a string representing the raw, unmodified token text for the given param. ...
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:270
T & setScalarParam(const std::string &name)
std::unique_ptr< hit::Node > _root
Definition: Parser.h:252
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...

◆ setScalarComponentParameter()

template<typename T >
void Parser::setScalarComponentParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< T > *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

Template method for setting any multivalue "scalar" type parameter read from the input file or command line.

Examples include "Point" and "RealVectorValue".

Definition at line 1504 of file Parser.C.

1509 {
1510  std::vector<double> vec;
1511  try
1512  {
1513  vec = _root->param<std::vector<double>>(full_name);
1514  }
1515  catch (hit::Error & err)
1516  {
1517  _errmsg += errormsg(_input_filename, _root->find(full_name), err.what());
1518  return;
1519  }
1520 
1521  if (vec.size() != LIBMESH_DIM)
1522  {
1524  _root->find(full_name),
1525  "wrong number of values in scalar component parameter ",
1526  full_name,
1527  ": size ",
1528  vec.size(),
1529  " is not a multiple of ",
1530  LIBMESH_DIM);
1531  return;
1532  }
1533 
1534  T value;
1535  for (unsigned int i = 0; i < vec.size(); ++i)
1536  value(i) = Real(vec[i]);
1537 
1538  param->set() = value;
1539  if (in_global)
1540  {
1541  global_block->remove(short_name);
1542  global_block->setScalarParam<T>(short_name) = value;
1543  }
1544 }
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:270
T & setScalarParam(const std::string &name)
std::string _errmsg
Definition: Parser.h:285
std::string errormsg(std::string, hit::Node *)
Definition: Parser.h:34
std::unique_ptr< hit::Node > _root
Definition: Parser.h:252
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...

◆ setScalarParameter() [1/15]

template<typename T , typename Base >
void Parser::setScalarParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< T > *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

Helper functions for setting parameters of arbitrary types - bodies are in the .C file since they are called only from this Object.

Template method for setting any scalar type parameter read from the input file or command line

Definition at line 1288 of file Parser.C.

1293 {
1294 
1295  try
1296  {
1297  param->set() = _root->param<Base>(full_name);
1298  }
1299  catch (hit::Error & err)
1300  {
1301  auto strval = _root->param<std::string>(full_name);
1302 
1303  // handle the case where the user put a number inside quotes
1304  auto & t = typeid(T);
1305  if (t == typeid(int) || t == typeid(unsigned int) || t == typeid(SubdomainID) ||
1306  t == typeid(BoundaryID) || t == typeid(double))
1307  {
1308  try
1309  {
1310  param->set() = MooseUtils::convert<T>(strval, true);
1311  }
1312  catch (std::invalid_argument & /*e*/)
1313  {
1314  const std::string format_type = (t == typeid(double)) ? "float" : "integer";
1316  _root->find(full_name),
1317  "invalid ",
1318  format_type,
1319  " syntax for parameter: ",
1320  full_name,
1321  "=",
1322  strval) +
1323  "\n";
1324  }
1325  }
1326  else if (t == typeid(bool))
1327  {
1328  bool isbool = toBool(strval, param->set());
1329  if (!isbool)
1331  _root->find(full_name),
1332  "invalid boolean syntax for parameter: ",
1333  full_name,
1334  "=",
1335  strval) +
1336  "\n";
1337  }
1338  else
1339  throw;
1340  }
1341 
1342  if (in_global)
1343  {
1344  global_block->remove(short_name);
1345  global_block->setScalarParam<T>(short_name) = param->get();
1346  }
1347 }
subdomain_id_type SubdomainID
Definition: MooseTypes.h:95
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:270
T & setScalarParam(const std::string &name)
std::string _errmsg
Definition: Parser.h:285
std::string errormsg(std::string, hit::Node *)
Definition: Parser.h:34
std::unique_ptr< hit::Node > _root
Definition: Parser.h:252
bool toBool(const std::string &, T &)
Definition: Parser.C:1274
boundary_id_type BoundaryID
Definition: MooseTypes.h:93
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...

◆ setScalarParameter() [2/15]

template<>
void Parser::setScalarParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< RealVectorValue > *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

◆ setScalarParameter() [3/15]

template<>
void Parser::setScalarParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< Point > *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

◆ setScalarParameter() [4/15]

template<>
void Parser::setScalarParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< PostprocessorName > *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

◆ setScalarParameter() [5/15]

template<>
void Parser::setScalarParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< MooseEnum > *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

◆ setScalarParameter() [6/15]

template<>
void Parser::setScalarParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< MultiMooseEnum > *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

◆ setScalarParameter() [7/15]

template<>
void Parser::setScalarParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< ExecFlagEnum > *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

◆ setScalarParameter() [8/15]

template<>
void Parser::setScalarParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< RealTensorValue > *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

◆ setScalarParameter() [9/15]

template<>
void Parser::setScalarParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< RealVectorValue > *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

Definition at line 1600 of file Parser.C.

1606 {
1607  setScalarComponentParameter(full_name, short_name, param, in_global, global_block);
1608 }
void setScalarComponentParameter(const std::string &full_name, const std::string &short_name, InputParameters::Parameter< T > *param, bool in_global, GlobalParamsAction *global_block)
Template method for setting any multivalue "scalar" type parameter read from the input file or comman...
Definition: Parser.C:1504

◆ setScalarParameter() [10/15]

template<>
void Parser::setScalarParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< Point > *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

Definition at line 1612 of file Parser.C.

1617 {
1618  setScalarComponentParameter(full_name, short_name, param, in_global, global_block);
1619 }
void setScalarComponentParameter(const std::string &full_name, const std::string &short_name, InputParameters::Parameter< T > *param, bool in_global, GlobalParamsAction *global_block)
Template method for setting any multivalue "scalar" type parameter read from the input file or comman...
Definition: Parser.C:1504

◆ setScalarParameter() [11/15]

template<>
void Parser::setScalarParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< MooseEnum > *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

Definition at line 1623 of file Parser.C.

1628 {
1629  MooseEnum current_param = param->get();
1630 
1631  std::string value = _root->param<std::string>(full_name);
1632 
1633  param->set() = value;
1634  if (in_global)
1635  {
1636  global_block->remove(short_name);
1637  global_block->setScalarParam<MooseEnum>(short_name) = current_param;
1638  }
1639 }
T & setScalarParam(const std::string &name)
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:32
std::unique_ptr< hit::Node > _root
Definition: Parser.h:252
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...

◆ setScalarParameter() [12/15]

template<>
void Parser::setScalarParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< MultiMooseEnum > *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

Definition at line 1643 of file Parser.C.

1649 {
1650  MultiMooseEnum current_param = param->get();
1651 
1652  auto vec = _root->param<std::vector<std::string>>(full_name);
1653 
1654  std::string raw_values;
1655  for (unsigned int i = 0; i < vec.size(); ++i)
1656  raw_values += ' ' + vec[i];
1657 
1658  param->set() = raw_values;
1659 
1660  if (in_global)
1661  {
1662  global_block->remove(short_name);
1663  global_block->setScalarParam<MultiMooseEnum>(short_name) = current_param;
1664  }
1665 }
T & setScalarParam(const std::string &name)
unsigned int get(unsigned int i) const
Indexing operator Operator to retrieve an item from the MultiMooseEnum.
std::unique_ptr< hit::Node > _root
Definition: Parser.h:252
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...

◆ setScalarParameter() [13/15]

template<>
void Parser::setScalarParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< ExecFlagEnum > *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

Definition at line 1669 of file Parser.C.

1675 {
1676  ExecFlagEnum current_param = param->get();
1677  auto vec = _root->param<std::vector<std::string>>(full_name);
1678 
1679  std::string raw_values;
1680  for (unsigned int i = 0; i < vec.size(); ++i)
1681  raw_values += ' ' + vec[i];
1682 
1683  param->set() = raw_values;
1684 
1685  if (in_global)
1686  {
1687  global_block->remove(short_name);
1688  global_block->setScalarParam<ExecFlagEnum>(short_name) = current_param;
1689  }
1690 }
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:25
T & setScalarParam(const std::string &name)
unsigned int get(unsigned int i) const
Indexing operator Operator to retrieve an item from the MultiMooseEnum.
std::unique_ptr< hit::Node > _root
Definition: Parser.h:252
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...

◆ setScalarParameter() [14/15]

template<>
void Parser::setScalarParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< RealTensorValue > *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

Definition at line 1694 of file Parser.C.

1700 {
1701  auto vec = _root->param<std::vector<double>>(full_name);
1702  if (vec.size() != LIBMESH_DIM * LIBMESH_DIM)
1703  {
1705  _root->find(full_name),
1706  "invalid RealTensorValue parameter ",
1707  full_name,
1708  ": size is ",
1709  vec.size(),
1710  " but should be ",
1711  LIBMESH_DIM * LIBMESH_DIM);
1712  return;
1713  }
1714 
1715  RealTensorValue value;
1716  for (int i = 0; i < LIBMESH_DIM; ++i)
1717  for (int j = 0; j < LIBMESH_DIM; ++j)
1718  value(i, j) = Real(vec[i * LIBMESH_DIM + j]);
1719 
1720  param->set() = value;
1721  if (in_global)
1722  {
1723  global_block->remove(short_name);
1724  global_block->setScalarParam<RealTensorValue>(short_name) = value;
1725  }
1726 }
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:270
T & setScalarParam(const std::string &name)
std::string _errmsg
Definition: Parser.h:285
std::string errormsg(std::string, hit::Node *)
Definition: Parser.h:34
std::unique_ptr< hit::Node > _root
Definition: Parser.h:252
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...

◆ setScalarParameter() [15/15]

template<>
void Parser::setScalarParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< PostprocessorName > *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

Definition at line 1731 of file Parser.C.

1737 {
1738  PostprocessorName pps_name = _root->param<std::string>(full_name);
1739  param->set() = pps_name;
1740 
1741  Real real_value = -std::numeric_limits<Real>::max();
1742  std::istringstream ss(pps_name);
1743 
1744  if (ss >> real_value && ss.eof())
1745  _current_params->setDefaultPostprocessorValue(short_name, real_value);
1746 
1747  if (in_global)
1748  {
1749  global_block->remove(short_name);
1750  global_block->setScalarParam<PostprocessorName>(short_name) = pps_name;
1751  }
1752 }
void setDefaultPostprocessorValue(const std::string &name, const PostprocessorValue &value)
Set the default value for a postprocessor added with addPostprocessor.
T & setScalarParam(const std::string &name)
std::unique_ptr< hit::Node > _root
Definition: Parser.h:252
InputParameters * _current_params
The current parameter object for which parameters are being extracted.
Definition: Parser.h:279
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...

◆ setScalarValueTypeParameter()

template<typename T , typename UP_T , typename Base >
void Parser::setScalarValueTypeParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< T > *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

Definition at line 1376 of file Parser.C.

1381 {
1382  setScalarParameter<T, Base>(full_name, short_name, param, in_global, global_block);
1383 
1384  // If this is a range checked param, we need to make sure that the value falls within the
1385  // requested range
1386  mooseAssert(_current_params, "Current params is nullptr");
1387 
1388  _current_params->rangeCheck<T, UP_T>(full_name, short_name, param, *_current_error_stream);
1389 }
void rangeCheck(const std::string &full_name, const std::string &short_name, InputParameters::Parameter< T > *param, std::ostream &oss=Moose::out)
Runs a range on the supplied parameter if it exists and throws an error if that check fails...
std::ostringstream * _current_error_stream
The current stream object used for capturing errors during extraction.
Definition: Parser.h:282
InputParameters * _current_params
The current parameter object for which parameters are being extracted.
Definition: Parser.h:279

◆ setVectorComponentParameter()

template<typename T >
void Parser::setVectorComponentParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< std::vector< T >> *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

Template method for setting several multivalue "scalar" type parameter read from the input file or command line.

Examples include "Point" and "RealVectorValue".

Definition at line 1548 of file Parser.C.

1553 {
1554  std::vector<double> vec;
1555  try
1556  {
1557  vec = _root->param<std::vector<double>>(full_name);
1558  }
1559  catch (hit::Error & err)
1560  {
1561  _errmsg += errormsg(_input_filename, _root->find(full_name), err.what());
1562  return;
1563  }
1564 
1565  if (vec.size() % LIBMESH_DIM)
1566  {
1568  _root->find(full_name),
1569  "wrong number of values in vector component parameter ",
1570  full_name,
1571  ": size ",
1572  vec.size(),
1573  " is not a multiple of ",
1574  LIBMESH_DIM);
1575  return;
1576  }
1577 
1578  std::vector<T> values;
1579  for (unsigned int i = 0; i < vec.size() / LIBMESH_DIM; ++i)
1580  {
1581  T value;
1582  for (int j = 0; j < LIBMESH_DIM; ++j)
1583  value(j) = Real(vec[i * LIBMESH_DIM + j]);
1584  values.push_back(value);
1585  }
1586 
1587  param->set() = values;
1588 
1589  if (in_global)
1590  {
1591  global_block->remove(short_name);
1592  global_block->setVectorParam<T>(short_name).resize(vec.size(), values[0]);
1593  for (unsigned int i = 0; i < vec.size() / LIBMESH_DIM; ++i)
1594  global_block->setVectorParam<T>(short_name)[i] = values[0];
1595  }
1596 }
std::vector< T > & setVectorParam(const std::string &name)
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:270
std::string _errmsg
Definition: Parser.h:285
std::string errormsg(std::string, hit::Node *)
Definition: Parser.h:34
std::unique_ptr< hit::Node > _root
Definition: Parser.h:252
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...

◆ setVectorFilePathParam()

template<typename T >
void Parser::setVectorFilePathParam ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< std::vector< T >> *  param,
InputParameters params,
bool  in_global,
GlobalParamsAction global_block 
)
protected

Sets an input parameter representing a vector of file paths using input file data.

The file paths are modified to be relative to the directory this application's input file is in.

Definition at line 1428 of file Parser.C.

1434 {
1435  std::vector<T> vec;
1436  std::vector<std::string> rawvec;
1437  if (_root->find(full_name))
1438  {
1439  auto tmp = _root->param<std::vector<std::string>>(full_name);
1440  params.rawParamVal(short_name) = _root->param<std::string>(full_name);
1441  for (auto val : tmp)
1442  {
1443  std::string prefix;
1444  std::string postfix = val;
1445  size_t pos = _input_filename.find_last_of('/');
1446  if (pos != std::string::npos && postfix[0] != '/')
1447  prefix = _input_filename.substr(0, pos + 1);
1448  rawvec.push_back(postfix);
1449  vec.push_back(prefix + postfix);
1450  }
1451  }
1452 
1453  param->set() = vec;
1454 
1455  if (in_global)
1456  {
1457  global_block->remove(short_name);
1458  global_block->setVectorParam<T>(short_name).resize(param->get().size());
1459  for (unsigned int i = 0; i < vec.size(); ++i)
1460  global_block->setVectorParam<T>(short_name)[i] = param->get()[i];
1461  }
1462 }
std::string & rawParamVal(const std::string &param)
Get/set a string representing the raw, unmodified token text for the given param. ...
std::vector< T > & setVectorParam(const std::string &name)
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:270
std::unique_ptr< hit::Node > _root
Definition: Parser.h:252
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...

◆ setVectorParameter() [1/9]

template<typename T , typename Base >
void Parser::setVectorParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< std::vector< T >> *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

Template method for setting any vector type parameter read from the input file or command line.

Definition at line 1393 of file Parser.C.

1398 {
1399  std::vector<T> vec;
1400  if (_root->find(full_name))
1401  {
1402  try
1403  {
1404  auto tmp = _root->param<std::vector<Base>>(full_name);
1405  for (auto val : tmp)
1406  vec.push_back(val);
1407  }
1408  catch (hit::Error & err)
1409  {
1410  _errmsg += errormsg(_input_filename, _root->find(full_name), err.what());
1411  return;
1412  }
1413  }
1414 
1415  param->set() = vec;
1416 
1417  if (in_global)
1418  {
1419  global_block->remove(short_name);
1420  global_block->setVectorParam<T>(short_name).resize(param->get().size());
1421  for (unsigned int i = 0; i < vec.size(); ++i)
1422  global_block->setVectorParam<T>(short_name)[i] = param->get()[i];
1423  }
1424 }
std::vector< T > & setVectorParam(const std::string &name)
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:270
std::string _errmsg
Definition: Parser.h:285
std::string errormsg(std::string, hit::Node *)
Definition: Parser.h:34
std::unique_ptr< hit::Node > _root
Definition: Parser.h:252
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...

◆ setVectorParameter() [2/9]

template<>
void Parser::setVectorParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< std::vector< RealVectorValue >> *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

◆ setVectorParameter() [3/9]

template<>
void Parser::setVectorParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< std::vector< Point >> *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

◆ setVectorParameter() [4/9]

template<>
void Parser::setVectorParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< std::vector< MooseEnum >> *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

◆ setVectorParameter() [5/9]

template<>
void Parser::setVectorParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< std::vector< VariableName >> *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

◆ setVectorParameter() [6/9]

template<>
void Parser::setVectorParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< std::vector< RealVectorValue >> *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

Definition at line 1756 of file Parser.C.

1762 {
1763  setVectorComponentParameter(full_name, short_name, param, in_global, global_block);
1764 }
void setVectorComponentParameter(const std::string &full_name, const std::string &short_name, InputParameters::Parameter< std::vector< T >> *param, bool in_global, GlobalParamsAction *global_block)
Template method for setting several multivalue "scalar" type parameter read from the input file or co...
Definition: Parser.C:1548

◆ setVectorParameter() [7/9]

template<>
void Parser::setVectorParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< std::vector< Point >> *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

Definition at line 1768 of file Parser.C.

1773 {
1774  setVectorComponentParameter(full_name, short_name, param, in_global, global_block);
1775 }
void setVectorComponentParameter(const std::string &full_name, const std::string &short_name, InputParameters::Parameter< std::vector< T >> *param, bool in_global, GlobalParamsAction *global_block)
Template method for setting several multivalue "scalar" type parameter read from the input file or co...
Definition: Parser.C:1548

◆ setVectorParameter() [8/9]

template<>
void Parser::setVectorParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< std::vector< MooseEnum >> *  param,
bool  in_global,
GlobalParamsAction global_block 
)
protected

With MOOSE Enums we need a default object so it should have been passed in the param pointer. We are only going to use the first item in the vector (values[0]) and ignore the rest.

Definition at line 1779 of file Parser.C.

1785 {
1786  std::vector<MooseEnum> enum_values = param->get();
1787  std::vector<std::string> values(enum_values.size());
1788  for (unsigned int i = 0; i < values.size(); ++i)
1789  values[i] = static_cast<std::string>(enum_values[i]);
1790 
1795  std::vector<std::string> vec;
1796  if (_root->find(full_name))
1797  {
1798  vec = _root->param<std::vector<std::string>>(full_name);
1799  param->set().resize(vec.size(), enum_values[0]);
1800  }
1801 
1802  for (unsigned int i = 0; i < vec.size(); ++i)
1803  param->set()[i] = vec[i];
1804 
1805  if (in_global)
1806  {
1807  global_block->remove(short_name);
1808  global_block->setVectorParam<MooseEnum>(short_name).resize(vec.size(), enum_values[0]);
1809  for (unsigned int i = 0; i < vec.size(); ++i)
1810  global_block->setVectorParam<MooseEnum>(short_name)[i] = values[0];
1811  }
1812 }
std::vector< T > & setVectorParam(const std::string &name)
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:32
std::unique_ptr< hit::Node > _root
Definition: Parser.h:252
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...

◆ setVectorParameter() [9/9]

template<>
void Parser::setVectorParameter ( const std::string &  full_name,
const std::string &  short_name,
InputParameters::Parameter< std::vector< VariableName >> *  param,
bool  ,
GlobalParamsAction  
)
protected

Specialization for coupling vectors.

This routine handles default values and auto generated VariableValue vectors.

Definition at line 1820 of file Parser.C.

1826 {
1827  auto vec = _root->param<std::vector<std::string>>(full_name);
1828  auto strval = _root->param<std::string>(full_name);
1829  std::vector<VariableName> var_names(vec.size());
1830 
1831  bool has_var_names = false;
1832  for (unsigned int i = 0; i < vec.size(); ++i)
1833  {
1834  VariableName var_name = vec[i];
1835 
1836  Real real_value;
1837  std::istringstream ss(var_name);
1838 
1839  // If we are able to convert this value into a Real, then set a default coupled value
1840  // NOTE: parameter must be either all default or no defaults
1841  if (ss >> real_value && ss.eof())
1842  _current_params->defaultCoupledValue(short_name, real_value, i);
1843  else
1844  {
1845  var_names[i] = var_name;
1846  has_var_names = true;
1847  }
1848  }
1849 
1850  if (has_var_names)
1851  {
1852  param->set().resize(vec.size());
1853 
1854  for (unsigned int i = 0; i < vec.size(); ++i)
1855  if (var_names[i] == "")
1856  {
1857  _errmsg += errormsg(
1859  _root->find(full_name),
1860  "invalid value for ",
1861  full_name,
1862  ":\n"
1863  " MOOSE does not currently support a coupled vector where some parameters are ",
1864  "reals and others are variables");
1865  return;
1866  }
1867  else
1868  param->set()[i] = var_names[i];
1869  }
1870 }
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:270
Real defaultCoupledValue(const std::string &coupling_name, unsigned int i=0) const
Get the default value for an optionally coupled variable.
std::string _errmsg
Definition: Parser.h:285
std::string errormsg(std::string, hit::Node *)
Definition: Parser.h:34
std::unique_ptr< hit::Node > _root
Definition: Parser.h:252
InputParameters * _current_params
The current parameter object for which parameters are being extracted.
Definition: Parser.h:279

◆ walk()

void Parser::walk ( const std::string &  fullpath,
const std::string &  nodepath,
hit::Node *  n 
)

Definition at line 396 of file Parser.C.

397 {
398  // skip sections that were manually processed first.
399  for (auto & sec : _secs_need_first)
400  if (nodepath == sec)
401  return;
402  walkRaw(fullpath, nodepath, n);
403 }
void walkRaw(std::string fullpath, std::string nodepath, hit::Node *n)
Definition: Parser.C:305
std::vector< std::string > _secs_need_first
Definition: Parser.h:253
PetscInt n

◆ walkRaw()

void Parser::walkRaw ( std::string  fullpath,
std::string  nodepath,
hit::Node *  n 
)
private

Definition at line 305 of file Parser.C.

Referenced by parse(), and walk().

306 {
307  InputParameters active_list_params = validParams<Action>();
309 
310  std::string section_name = n->fullpath();
311  std::string curr_identifier = n->fullpath();
312 
313  // Before we retrieve any actions or build any objects, make sure that the section they are in
314  // is active
315  if (!isSectionActive(curr_identifier, _root.get()))
316  return;
317 
318  // Extract the block parameters before constructing the action
319  // There may be more than one Action registered for a given section in which case we need to
320  // build them all
321  bool is_parent;
322  std::string registered_identifier = _syntax.isAssociated(section_name, &is_parent);
323 
324  // We need to retrieve a list of Actions associated with the current identifier
325  auto iters = _syntax.getActions(registered_identifier);
326  if (iters.first == iters.second)
327  {
329  n,
330  "section '",
331  curr_identifier,
332  "' does not have an associated \"Action\".\nDid you misspell it?");
333  return;
334  }
335 
336  for (auto it = iters.first; it != iters.second; ++it)
337  {
338  if (is_parent)
339  continue;
340  if (_syntax.isDeprecatedSyntax(registered_identifier))
342  errormsg(getFileName(), n, _syntax.deprecatedActionSyntaxMessage(registered_identifier)));
343 
344  params = _action_factory.getValidParams(it->second._action);
345 
346  params.set<ActionWarehouse *>("awh") = &_action_wh;
347 
348  extractParams(curr_identifier, params);
349 
350  // Add the parsed syntax to the parameters object for consumption by the Action
351  params.set<std::string>("task") = it->second._task;
352  params.set<std::string>("registered_identifier") = registered_identifier;
353  params.blockLocation() = _input_filename + ":" + std::to_string(n->line());
354  params.blockFullpath() = n->fullpath();
355 
356  // Create the Action
357  std::shared_ptr<Action> action_obj =
358  _action_factory.create(it->second._action, MooseUtils::shortName(curr_identifier), params);
359 
360  {
361  // extract the MooseObject params if necessary
362  std::shared_ptr<MooseObjectAction> object_action =
364  if (object_action)
365  {
366  object_action->getObjectParams().blockLocation() = params.blockLocation();
367  object_action->getObjectParams().blockFullpath() = params.blockFullpath();
368  extractParams(curr_identifier, object_action->getObjectParams());
369  object_action->getObjectParams()
370  .set<std::vector<std::string>>("control_tags")
371  .push_back(MooseUtils::baseName(curr_identifier));
372  }
373  }
374 
375  {
376  // extract the MooseObject params if necessary
377  std::shared_ptr<MooseADObjectAction> object_action =
379  if (object_action)
380  {
381  object_action->getObjectParams().blockLocation() = params.blockLocation();
382  object_action->getObjectParams().blockFullpath() = params.blockFullpath();
383  extractParams(curr_identifier, object_action->getObjectParams());
384  object_action->getObjectParams()
385  .set<std::vector<std::string>>("control_tags")
386  .push_back(MooseUtils::baseName(curr_identifier));
387  }
388  }
389 
390  // add it to the warehouse
391  _action_wh.addActionBlock(action_obj);
392  }
393 }
std::pair< std::multimap< std::string, ActionInfo >::const_iterator, std::multimap< std::string, ActionInfo >::const_iterator > getActions(const std::string &syntax) const
Returns a pair of multimap iterators to all the ActionInfo objects associated with a given piece of s...
Definition: Syntax.C:271
InputParameters validParams< EmptyAction >()
Definition: EmptyAction.C:20
InputParameters getValidParams(const std::string &name)
Definition: ActionFactory.C:70
InputParameters & getObjectParams()
Retreive the parameters of the object to be created by this action.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
Storage for action instances.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void addActionBlock(std::shared_ptr< Action > blk)
This method add an Action instance to the warehouse.
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
void extractParams(const std::string &prefix, InputParameters &p)
This function attempts to extract values from the input file based on the contents of the passed para...
Definition: Parser.C:951
Syntax & _syntax
Reference to an object that defines input file syntax.
Definition: Parser.h:264
bool isSectionActive(std::string path, hit::Node *root)
Definition: Parser.C:68
std::string shortName(const std::string &name)
Function for stripping name after the file / in parser block.
Definition: MooseUtils.C:360
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:270
bool isDeprecatedSyntax(const std::string &syntax) const
Returns a Boolean indicating whether the syntax has been deprecated through a call to deprecateAction...
Definition: Syntax.C:177
std::string isAssociated(const std::string &real_id, bool *is_parent) const
Method for determining whether a piece of syntax is associated with an Action TODO: I need a better n...
Definition: Syntax.C:209
InputParameters & getObjectParams()
Retreive the parameters of the object to be created by this action.
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition: MooseError.h:237
std::string _errmsg
Definition: Parser.h:285
ActionWarehouse & _action_wh
Action warehouse that will be filled by actions.
Definition: Parser.h:260
std::string baseName(const std::string &name)
Function for string the information before the final / in a parser block.
Definition: MooseUtils.C:366
PetscInt n
std::string errormsg(std::string, hit::Node *)
Definition: Parser.h:34
std::unique_ptr< hit::Node > _root
Definition: Parser.h:252
std::string getFileName(bool stripLeadingPath=true) const
Return the filename that was parsed.
Definition: Parser.C:289
std::shared_ptr< Action > create(const std::string &action, const std::string &action_name, InputParameters parameters)
Definition: ActionFactory.C:41
std::string deprecatedActionSyntaxMessage(const std::string syntax)
Returns the deprecation message for a given syntax that has been deprecated by deprecateActionSyntax...
Definition: Syntax.C:166
ActionFactory & _action_factory
The Factory that builds actions.
Definition: Parser.h:262
std::string & blockLocation()
Get/set a string representing the location (i.e.
InputParameters validParams< Action >()
Definition: Action.C:19

Member Data Documentation

◆ _action_factory

ActionFactory& Parser::_action_factory
protected

The Factory that builds actions.

Definition at line 262 of file Parser.h.

Referenced by buildFullTree(), buildJsonSyntaxTree(), listValidParams(), and walkRaw().

◆ _action_wh

ActionWarehouse& Parser::_action_wh
protected

Action warehouse that will be filled by actions.

Definition at line 260 of file Parser.h.

Referenced by extractParams(), and walkRaw().

◆ _app

MooseApp& Parser::_app
protected

The MooseApp this Parser is part of.

Definition at line 256 of file Parser.h.

Referenced by errorCheck(), hitCLIFilter(), and parse().

◆ _cli_root

std::unique_ptr<hit::Node> Parser::_cli_root = nullptr
protected

Definition at line 251 of file Parser.h.

Referenced by errorCheck(), and parse().

◆ _console

const ConsoleStream ConsoleStreamInterface::_console
inherited

An instance of helper class to write streams to the Console objects.

Definition at line 32 of file ConsoleStreamInterface.h.

Referenced by IterationAdaptiveDT::acceptStep(), SetupRecoverFileBaseAction::act(), Adaptivity::adaptMesh(), FEProblemBase::adaptMesh(), SimplePredictor::apply(), FEProblemBase::backupMultiApps(), FEProblemBase::checkProblemIntegrity(), IterationAdaptiveDT::computeAdaptiveDT(), Transient::computeConstrainedDT(), NonlinearSystemBase::computeDamping(), IterationAdaptiveDT::computeDT(), IterationAdaptiveDT::computeFailedDT(), IterationAdaptiveDT::computeInterpolationDT(), FEProblemBase::computeResidualTags(), IterationAdaptiveDT::constrainStep(), TimeStepper::constrainStep(), AB2PredictorCorrector::converged(), FEProblemBase::execMultiApps(), FEProblemBase::execMultiAppTransfers(), MultiAppPostprocessorTransfer::execute(), MultiAppPostprocessorInterpolationTransfer::execute(), MultiAppVariableValueSamplePostprocessorTransfer::execute(), MultiAppNearestNodeTransfer::execute(), MultiAppPostprocessorToAuxScalarTransfer::execute(), MultiAppScalarToAuxScalarTransfer::execute(), MultiAppVariableValueSampleTransfer::execute(), MultiAppInterpolationTransfer::execute(), MultiAppMeshFunctionTransfer::execute(), MultiAppUserObjectTransfer::execute(), MultiAppProjectionTransfer::execute(), MultiAppVectorPostprocessorTransfer::execute(), MultiAppCopyTransfer::execute(), Steady::execute(), MultiAppDTKUserObjectTransfer::execute(), ActionWarehouse::executeActionsWithAction(), ActionWarehouse::executeAllActions(), FEProblemBase::FEProblemBase(), ElementQualityChecker::finalize(), FEProblemBase::finishMultiAppStep(), MultiApp::globalAppToLocal(), InversePowerMethod::init(), NonlinearEigen::init(), Steady::init(), FEProblemBase::initialAdaptMesh(), FEProblemBase::initialSetup(), EigenExecutionerBase::inversePowerIteration(), Transient::keepGoing(), IterationAdaptiveDT::limitDTByFunction(), IterationAdaptiveDT::limitDTToPostprocessorValue(), EigenExecutionerBase::makeBXConsistent(), Console::meshChanged(), MooseObject::mooseDeprecated(), MooseObject::mooseInfo(), MooseObject::mooseWarning(), PerfGraphOutput::output(), DOFMapOutput::output(), VariableResidualNormsDebugOutput::output(), Console::output(), ControlOutput::outputActiveObjects(), ControlOutput::outputChangedControls(), ControlOutput::outputControls(), Console::outputInput(), Console::outputPostprocessors(), Console::outputScalarVariables(), Console::outputSystemInformation(), FEProblemBase::possiblyRebuildGeomSearchPatches(), EigenExecutionerBase::postExecute(), ActionWarehouse::printActionDependencySets(), EigenExecutionerBase::printEigenvalue(), MaterialPropertyDebugOutput::printMaterialMap(), SolutionTimeAdaptiveDT::rejectStep(), DT2::rejectStep(), FEProblemBase::restoreMultiApps(), SimplePredictor::shouldApply(), NonlinearSystem::solve(), LStableDirk2::solve(), LStableDirk3::solve(), ImplicitMidpoint::solve(), ExplicitTVDRK2::solve(), AStableDirk4::solve(), LStableDirk4::solve(), ExplicitRK2::solve(), TransientMultiApp::solveStep(), Transient::solveStep(), DT2::step(), AB2PredictorCorrector::step(), NonlinearEigen::takeStep(), Console::writeTimestepInformation(), Console::writeVariableNorms(), and FEProblemBase::~FEProblemBase().

◆ _current_error_stream

std::ostringstream* Parser::_current_error_stream
protected

The current stream object used for capturing errors during extraction.

Definition at line 282 of file Parser.h.

Referenced by extractParams(), and setScalarValueTypeParameter().

◆ _current_params

InputParameters* Parser::_current_params
protected

The current parameter object for which parameters are being extracted.

Definition at line 279 of file Parser.h.

Referenced by extractParams(), and setScalarValueTypeParameter().

◆ _errmsg

std::string Parser::_errmsg
private

◆ _extracted_vars

std::set<std::string> Parser::_extracted_vars
protected

The set of all variables extracted from the input file.

Definition at line 273 of file Parser.h.

Referenced by errorCheck(), extractParams(), and parse().

◆ _factory

Factory& Parser::_factory
protected

The Factory associated with that MooseApp.

Definition at line 258 of file Parser.h.

Referenced by buildFullTree(), and buildJsonSyntaxTree().

◆ _input_filename

std::string Parser::_input_filename
protected

◆ _root

std::unique_ptr<hit::Node> Parser::_root = nullptr
protected

◆ _secs_need_first

std::vector<std::string> Parser::_secs_need_first
protected

Definition at line 253 of file Parser.h.

Referenced by parse(), and walk().

◆ _sections_read

bool Parser::_sections_read
protected

Boolean to indicate whether parsing has started (sections have been extracted)

Definition at line 276 of file Parser.h.

◆ _syntax

Syntax& Parser::_syntax
protected

Reference to an object that defines input file syntax.

Definition at line 264 of file Parser.h.

Referenced by buildFullTree(), buildJsonSyntaxTree(), extractParams(), listValidParams(), parse(), and walkRaw().

◆ _syntax_formatter

std::unique_ptr<SyntaxTree> Parser::_syntax_formatter
protected

Object for holding the syntax parse tree.

Definition at line 267 of file Parser.h.

Referenced by buildFullTree(), and initSyntaxFormatter().

◆ _warnmsg

std::string Parser::_warnmsg
private

Definition at line 286 of file Parser.h.

Referenced by errorCheck().


The documentation for this class was generated from the following files: