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, const std::vector< std::string > &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 96 of file Parser.h.

Member Enumeration Documentation

◆ SyntaxFormatterType

Enumerator
INPUT_FILE 
YAML 

Definition at line 99 of file Parser.h.

100  {
101  INPUT_FILE,
102  YAML
103  };

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:237
bool _sections_read
Boolean to indicate whether parsing has started (sections have been extracted)
Definition: Parser.h:257
Syntax & _syntax
Reference to an object that defines input file syntax.
Definition: Parser.h:245
ActionFactory & getActionFactory()
Retrieve the ActionFactory associated with this App.
Definition: MooseApp.h:287
Factory & getFactory()
Retrieve the Factory associated with this App.
Definition: MooseApp.h:280
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:248
ActionWarehouse & _action_wh
Action warehouse that will be filled by actions.
Definition: Parser.h:241
std::ostringstream * _current_error_stream
The current stream object used for capturing errors during extraction.
Definition: Parser.h:263
InputParameters * _current_params
The current parameter object for which parameters are being extracted.
Definition: Parser.h:260
Factory & _factory
The Factory associated with that MooseApp.
Definition: Parser.h:239
ActionFactory & _action_factory
The Factory that builds actions.
Definition: Parser.h:243

◆ ~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  moose_obj->first.find("<JACOBIAN>") ==
822  std::string::npos) // And it is not a Jacobian templated AD object
823  {
824  std::string name;
825  size_t pos = 0;
826  bool is_action_params = false;
827  if (act_name[act_name.size() - 1] == '*')
828  {
829  pos = act_name.size();
830 
831  // Remove <RESIDUAL> append for AD objects
832  std::string obj_name = moose_obj->first;
833  removeSubstring(obj_name, "<RESIDUAL>");
834 
835  if (!action_obj_params.collapseSyntaxNesting())
836  name = act_name.substr(0, pos - 1) + obj_name;
837  else
838  {
839  name = act_name.substr(0, pos - 1) + "/<type>/" + moose_obj->first;
840  is_action_params = true;
841  }
842  }
843  else
844  {
845  name = act_name + "/<type>/" + moose_obj->first;
846  }
847 
848  moose_obj_params.set<std::string>("type") = moose_obj->first;
849 
850  _syntax_formatter->insertNode(
851  name, moose_obj->first, is_action_params, &moose_obj_params);
852  }
853  }
854  }
855  }
856 
857  // Do not change to _console, we need this printed to the stdout in all cases
858  Moose::out << _syntax_formatter->print(search_string) << std::flush;
859 }
const std::multimap< std::string, ActionInfo > & getAssociatedActions() const
Return all Syntax to Action associations.
Definition: Syntax.C:310
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:245
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:248
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
void removeSubstring(std::string &main, const std::string &sub)
find, erase, length algorithm for removing a substring from a string
Definition: MooseUtils.C:915
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:286
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:239
ActionFactory & _action_factory
The Factory that builds actions.
Definition: Parser.h:243

◆ 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 649 of file Parser.C.

Referenced by MooseApp::setupOptions().

650 {
651  std::vector<std::pair<std::string, Syntax::ActionInfo>> all_names;
652 
653  for (const auto & iter : _syntax.getAssociatedTypes())
654  root.addSyntaxType(iter.first, iter.second);
655 
656  for (const auto & iter : _syntax.getAssociatedActions())
657  {
658  Syntax::ActionInfo act_info = iter.second;
664  if (act_info._task == "")
665  act_info._task = _action_factory.getTaskName(act_info._action);
666 
667  all_names.push_back(std::make_pair(iter.first, act_info));
668  }
669 
670  for (const auto & act_names : all_names)
671  {
672  const auto & act_info = act_names.second;
673  const std::string & action = act_info._action;
674  const std::string & task = act_info._task;
675  const std::string act_name = act_names.first;
676  InputParameters action_obj_params = _action_factory.getValidParams(action);
677  bool params_added = root.addParameters("",
678  act_name,
679  false,
680  action,
681  true,
682  &action_obj_params,
683  _syntax.getLineInfo(act_name, action, ""),
684  "");
685 
686  if (params_added)
687  {
688  auto tasks = _action_factory.getTasksByAction(action);
689  for (auto & t : tasks)
690  {
691  auto info = _action_factory.getLineInfo(action, t);
692  root.addActionTask(act_name, action, t, info);
693  }
694  }
695 
701  if (action_obj_params.have_parameter<bool>("isObjectAction") &&
702  action_obj_params.get<bool>("isObjectAction"))
703  {
705  moose_obj != _factory.registeredObjectsEnd();
706  ++moose_obj)
707  {
708  InputParameters moose_obj_params = (moose_obj->second)();
709  // Now that we know that this is a MooseObjectAction we need to see if it has been
710  // restricted
711  // in any way by the user.
712  const std::vector<std::string> & buildable_types = action_obj_params.getBuildableTypes();
713 
714  // See if the current Moose Object syntax belongs under this Action's block
715  if ((buildable_types.empty() || // Not restricted
716  std::find(buildable_types.begin(), buildable_types.end(), moose_obj->first) !=
717  buildable_types.end()) && // Restricted but found
718  moose_obj_params.have_parameter<std::string>("_moose_base") && // Has a registered base
719  _syntax.verifyMooseObjectTask(moose_obj_params.get<std::string>("_moose_base"),
720  task) && // and that base is associated
721  action_obj_params.mooseObjectSyntaxVisibility() && // and the Action says it's visible
722  moose_obj->first.find("<JACOBIAN>") ==
723  std::string::npos) // And it is not a Jacobian templated AD object
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:304
const std::multimap< std::string, ActionInfo > & getAssociatedActions() const
Return all Syntax to Action associations.
Definition: Syntax.C:310
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:316
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:245
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:286
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:239
ActionFactory & _action_factory
The Factory that builds actions.
Definition: Parser.h:243

◆ errorCheck()

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

Definition at line 582 of file Parser.C.

Referenced by MooseApp::errorCheck().

583 {
584  // this if guard is important in case the simulation was not configured via parsed input text -
585  // e.g. configured programatically.
586  if (!_root || !_cli_root)
587  return;
588 
590  UnusedWalker uwcli("CLI_ARG", _extracted_vars, *this);
591 
592  _root->walk(&uw);
593  _cli_root->walk(&uwcli);
594 
595  auto cli = _app.commandLine();
596  if (warn_unused)
597  {
598  for (auto arg : cli->unused(comm))
599  _warnmsg += hit::errormsg("CLI_ARG",
600  nullptr,
601  "unused command line parameter '",
602  cli->getArguments()[arg],
603  "'") +
604  "\n";
605  for (auto & msg : uwcli.errors)
606  _warnmsg += msg + "\n";
607  for (auto & msg : uw.errors)
608  _warnmsg += msg + "\n";
609  }
610  else if (err_unused)
611  {
612  for (auto arg : cli->unused(comm))
613  _errmsg += hit::errormsg("CLI_ARG",
614  nullptr,
615  "unused command line parameter '",
616  cli->getArguments()[arg],
617  "'") +
618  "\n";
619  for (auto & msg : uwcli.errors)
620  _errmsg += msg + "\n";
621  for (auto & msg : uw.errors)
622  _errmsg += msg + "\n";
623  }
624 
625  if (_warnmsg.size() > 0)
627  if (_errmsg.size() > 0)
629 }
MooseApp & _app
The MooseApp this Parser is part of.
Definition: Parser.h:237
std::string _warnmsg
Definition: Parser.h:267
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:294
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:251
std::unique_ptr< hit::Node > _cli_root
Definition: Parser.h:232
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:266
std::set< std::string > _extracted_vars
The set of all variables extracted from the input file.
Definition: Parser.h:254
std::unique_ptr< hit::Node > _root
Definition: Parser.h:233
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 957 of file Parser.C.

Referenced by walkRaw().

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

◆ getFileName()

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

Return the filename that was parsed.

Definition at line 290 of file Parser.C.

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

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

◆ hitCLIFilter()

std::string Parser::hitCLIFilter ( std::string  appname,
const std::vector< std::string > &  argv 
)
private

Definition at line 393 of file Parser.C.

Referenced by parse().

394 {
395  std::string hit_text;
396  bool afterDoubleDash = false;
397  for (std::size_t i = 1; i < argv.size(); i++)
398  {
399  std::string arg(argv[i]);
400 
401  // all args after a "--" are hit parameters
402  if (arg == "--")
403  {
404  afterDoubleDash = true;
405  continue;
406  } // otherwise try to guess if a hit params have started by looking for "=" and "/"
407  else if (arg.find("=", 0) != std::string::npos)
408  afterDoubleDash = true;
409 
410  // skip arguments with no equals sign
411  if (arg.find("=", 0) == std::string::npos)
412  continue;
413  // skip cli flags (i.e. start with dash)
414  else if (arg.find("-", 0) == 0)
415  continue;
416  // skip over args that don't look like or are before hit parameters
417  else if (!afterDoubleDash)
418  continue;
419  else if (appname == "main")
420  {
421  auto pos = arg.find(":", 0);
422  if (pos == 0) // trim leading colon
423  arg = arg.substr(pos + 1, arg.size() - pos - 1);
424  else if (pos != std::string::npos && pos < arg.find("=", 0)) // param is for non-main subapp
425  continue;
426  }
427  else if (appname != "main") // app we are loading is a multiapp subapp
428  {
429  std::string name;
430  std::string num;
431  pcrecpp::RE("(.*?)" // Match the multiapp name
432  "(\\d+)" // math the multiapp number
433  )
434  .FullMatch(appname, &name, &num);
435  auto pos = arg.find(":", 0);
436  if (pos == 0)
437  ; // cli param is ":" prefixed meaning global for all main+subapps
438  else if (pos == std::string::npos) // param is for main app - skip
439  continue;
440  else if (arg.substr(0, pos) != appname &&
441  arg.substr(0, pos) != name) // param is for different multiapp - skip
442  {
443  _app.commandLine()->markHitParam(i);
444  continue;
445  }
446  arg = arg.substr(pos + 1, arg.size() - pos - 1); // trim off subapp name prefix
447  }
448 
449  try
450  {
451  hit::check("CLI_ARG", arg);
452  hit_text += " " + arg;
453  // handle case where bash ate quotes around an empty string after the "="
454  if (arg.find("=", 0) == arg.size() - 1)
455  hit_text += "''";
456  _app.commandLine()->markHitParamUsed(i);
457  }
458  catch (hit::ParseError & err)
459  {
460  // bash might have eaten quotes around a hit string value or vector
461  // so try quoting after the "=" and reparse
462  auto quoted = arg;
463  auto pos = quoted.find("=", 0);
464  if (pos != std::string::npos)
465  quoted = arg.substr(0, pos + 1) + "'" + arg.substr(pos + 1, quoted.size() - pos) + "'";
466  try
467  {
468  hit::check("CLI_ARG", quoted);
469  hit_text += " " + quoted;
470  _app.commandLine()->markHitParamUsed(i);
471  }
472  catch (hit::ParseError & err)
473  {
474  mooseError("invalid hit in arg '", arg, "': ", err.what());
475  }
476  }
477  }
478  return hit_text;
479 }
MooseApp & _app
The MooseApp this Parser is part of.
Definition: Parser.h:237
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:294

◆ initSyntaxFormatter()

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

Creates a syntax formatter for printing.

Definition at line 632 of file Parser.C.

Referenced by MooseApp::setupOptions().

633 {
634  switch (type)
635  {
636  case INPUT_FILE:
637  _syntax_formatter = libmesh_make_unique<InputFileFormatter>(dump_mode);
638  break;
639  case YAML:
640  _syntax_formatter = libmesh_make_unique<YAMLFormatter>(dump_mode);
641  break;
642  default:
643  mooseError("Unrecognized Syntax Formatter requested");
644  break;
645  }
646 }
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:248
MatType type

◆ listValidParams()

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

Definition at line 162 of file Parser.C.

Referenced by UnusedWalker::walk().

163 {
164  bool dummy;
165  std::string registered_identifier = _syntax.isAssociated(section_name, &dummy);
166  auto iters = _syntax.getActions(registered_identifier);
167 
168  std::vector<std::string> paramlist;
169  for (auto it = iters.first; it != iters.second; ++it)
170  {
171  auto params = _action_factory.getValidParams(it->second._action);
172  for (const auto & it : params)
173  paramlist.push_back(it.first);
174  }
175  return paramlist;
176 }
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:280
InputParameters getValidParams(const std::string &name)
Definition: ActionFactory.C:70
Syntax & _syntax
Reference to an object that defines input file syntax.
Definition: Parser.h:245
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:218
ActionFactory & _action_factory
The Factory that builds actions.
Definition: Parser.h:243

◆ 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 482 of file Parser.C.

Referenced by MooseApp::setupOptions().

483 {
484  // Save the filename
485  char abspath[PATH_MAX + 1];
486  realpath(input_filename.c_str(), abspath);
487  _input_filename = std::string(abspath);
488 
489  // vector for initializing active blocks
490  std::vector<std::string> all = {"__all__"};
491 
493 
494  std::ifstream f(_input_filename);
495  std::string input((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
496 
497  try
498  {
499  _root.reset(hit::parse(_input_filename, input));
500  auto cli_input = hitCLIFilter(_app.name(), _app.commandLine()->getArguments());
501 
502  _cli_root.reset(hit::parse("CLI_ARGS", cli_input));
503  hit::explode(_cli_root.get());
504  hit::explode(_root.get());
505  hit::merge(_cli_root.get(), _root.get());
506  }
507  catch (hit::ParseError & err)
508  {
509  mooseError(err.what());
510  }
511 
512  // expand ${bla} parameter values and mark/include variables used in expansions as "used". This
513  // MUST occur before parameter extraction - otherwise parameters will get wrong values.
514  hit::RawEvaler raw;
515  hit::EnvEvaler env;
516  hit::ReplaceEvaler repl;
517  FuncParseEvaler fparse_ev;
518  hit::BraceExpander exw(_input_filename);
519  exw.registerEvaler("raw", raw);
520  exw.registerEvaler("env", env);
521  exw.registerEvaler("fparse", fparse_ev);
522  exw.registerEvaler("replace", repl);
523  _root->walk(&exw);
524  for (auto & var : exw.used)
525  _extracted_vars.insert(var);
526  for (auto & msg : exw.errors)
527  _errmsg += msg + "\n";
528 
529  // do as much error checking as early as possible so that errors are more useful instead
530  // of surprising and disconnected from what caused them.
533  _root->walk(&dw, hit::NodeType::Field);
534  _root->walk(&bw, hit::NodeType::Section);
535  for (auto & msg : dw.errors)
536  _errmsg += msg + "\n";
537  for (auto & msg : bw.errors)
538  _errmsg += msg + "\n";
539 
540  // There are a few order dependent actions that have to be built first in
541  // order for the parser and application to function properly:
542  //
543  // SetupDebugAction: This action can contain an option for monitoring the parser progress. It must
544  // be parsed first to capture all of the parsing output.
545  //
546  // GlobalParamsAction: This action is checked during the parameter extraction routines of all
547  // subsequent blocks. It must be parsed early since it must exist during
548  // subsequent parameter extraction.
549  //
550  // DynamicObjectRegistration: This action must be built before any MooseObjectActions are built.
551  // This is because we retrieve valid parameters from the Factory
552  // during parse time. Objects must be registered before
553  // validParameters can be retrieved.
554  auto syntax = _syntax.getSyntaxByAction("SetupDebugAction");
555  std::copy(syntax.begin(), syntax.end(), std::back_inserter(_secs_need_first));
556 
557  syntax = _syntax.getSyntaxByAction("GlobalParamsAction");
558  std::copy(syntax.begin(), syntax.end(), std::back_inserter(_secs_need_first));
559 
560  syntax = _syntax.getSyntaxByAction("DynamicObjectRegistrationAction");
561  std::copy(syntax.begin(), syntax.end(), std::back_inserter(_secs_need_first));
562 
563  // walk all the sections extracting paramters from each into InputParameters objects
564  for (auto & sec : _secs_need_first)
565  {
566  auto n = _root->find(sec);
567  if (n)
568  walkRaw(n->parent()->fullpath(), n->path(), n);
569  }
570  _root->walk(this, hit::NodeType::Section);
571 
572  if (_errmsg.size() > 0)
574 }
const std::string & name() const
Get the name of the object.
Definition: MooseApp.h:73
MooseApp & _app
The MooseApp this Parser is part of.
Definition: Parser.h:237
void walkRaw(std::string fullpath, std::string nodepath, hit::Node *n)
Definition: Parser.C:306
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:294
std::vector< std::string > _secs_need_first
Definition: Parser.h:234
Syntax & _syntax
Reference to an object that defines input file syntax.
Definition: Parser.h:245
std::string hitCLIFilter(std::string appname, const std::vector< std::string > &argv)
Definition: Parser.C:393
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:192
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:251
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:146
std::unique_ptr< hit::Node > _cli_root
Definition: Parser.h:232
std::string _errmsg
Definition: Parser.h:266
std::set< std::string > _extracted_vars
The set of all variables extracted from the input file.
Definition: Parser.h:254
PetscInt n
std::unique_ptr< hit::Node > _root
Definition: Parser.h:233

◆ 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 1472 of file Parser.C.

1477 {
1478  // Get the full string assigned to the variable full_name
1479  std::string buffer = _root->param<std::string>(full_name);
1480 
1481  // split vector at delim ;
1482  // NOTE: the substrings are _not_ of type T yet
1483  std::vector<std::string> first_tokenized_vector;
1484  MooseUtils::tokenize(buffer, first_tokenized_vector, 1, ";");
1485  param->set().resize(first_tokenized_vector.size());
1486 
1487  for (unsigned j = 0; j < first_tokenized_vector.size(); ++j)
1488  if (!MooseUtils::tokenizeAndConvert<T>(first_tokenized_vector[j], param->set()[j]))
1489  {
1490  _errmsg +=
1491  hit::errormsg(
1492  _input_filename, _root->find(full_name), "invalid format for parameter ", full_name) +
1493  "\n";
1494  return;
1495  }
1496 
1497  if (in_global)
1498  {
1499  global_block->remove(short_name);
1500  global_block->setDoubleIndexParam<T>(short_name).resize(first_tokenized_vector.size());
1501  for (unsigned j = 0; j < first_tokenized_vector.size(); ++j)
1502  {
1503  global_block->setDoubleIndexParam<T>(short_name)[j].resize(param->get()[j].size());
1504  for (unsigned int i = 0; i < param->get()[j].size(); ++i)
1505  global_block->setDoubleIndexParam<T>(short_name)[j][i] = param->get()[j][i];
1506  }
1507  }
1508 }
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:429
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:251
std::string _errmsg
Definition: Parser.h:266
std::unique_ptr< hit::Node > _root
Definition: Parser.h:233
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 1357 of file Parser.C.

1363 {
1364  std::string prefix;
1365  std::string postfix = _root->param<std::string>(full_name);
1366  size_t pos = _input_filename.find_last_of('/');
1367  if (pos != std::string::npos && postfix[0] != '/' && !postfix.empty())
1368  prefix = _input_filename.substr(0, pos + 1);
1369 
1370  params.rawParamVal(short_name) = postfix;
1371  param->set() = prefix + postfix;
1372 
1373  if (in_global)
1374  {
1375  global_block->remove(short_name);
1376  global_block->setScalarParam<T>(short_name) = param->get();
1377  }
1378 }
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:251
T & setScalarParam(const std::string &name)
std::unique_ptr< hit::Node > _root
Definition: Parser.h:233
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 1512 of file Parser.C.

1517 {
1518  std::vector<double> vec;
1519  try
1520  {
1521  vec = _root->param<std::vector<double>>(full_name);
1522  }
1523  catch (hit::Error & err)
1524  {
1525  _errmsg += hit::errormsg(_input_filename, _root->find(full_name), err.what()) + "\n";
1526  return;
1527  }
1528 
1529  if (vec.size() != LIBMESH_DIM)
1530  {
1531  _errmsg += hit::errormsg(_input_filename,
1532  _root->find(full_name),
1533  "wrong number of values in scalar component parameter ",
1534  full_name,
1535  ": size ",
1536  vec.size(),
1537  " is not a multiple of ",
1538  LIBMESH_DIM) +
1539  "\n";
1540  return;
1541  }
1542 
1543  T value;
1544  for (unsigned int i = 0; i < vec.size(); ++i)
1545  value(i) = Real(vec[i]);
1546 
1547  param->set() = value;
1548  if (in_global)
1549  {
1550  global_block->remove(short_name);
1551  global_block->setScalarParam<T>(short_name) = value;
1552  }
1553 }
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:251
T & setScalarParam(const std::string &name)
std::string _errmsg
Definition: Parser.h:266
std::unique_ptr< hit::Node > _root
Definition: Parser.h:233
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 1294 of file Parser.C.

1299 {
1300 
1301  try
1302  {
1303  param->set() = _root->param<Base>(full_name);
1304  }
1305  catch (hit::Error & err)
1306  {
1307  auto strval = _root->param<std::string>(full_name);
1308 
1309  // handle the case where the user put a number inside quotes
1310  auto & t = typeid(T);
1311  if (t == typeid(int) || t == typeid(unsigned int) || t == typeid(SubdomainID) ||
1312  t == typeid(BoundaryID) || t == typeid(double))
1313  {
1314  try
1315  {
1316  param->set() = MooseUtils::convert<T>(strval, true);
1317  }
1318  catch (std::invalid_argument & /*e*/)
1319  {
1320  const std::string format_type = (t == typeid(double)) ? "float" : "integer";
1321  _errmsg += hit::errormsg(_input_filename,
1322  _root->find(full_name),
1323  "invalid ",
1324  format_type,
1325  " syntax for parameter: ",
1326  full_name,
1327  "=",
1328  strval) +
1329  "\n";
1330  }
1331  }
1332  else if (t == typeid(bool))
1333  {
1334  bool isbool = toBool(strval, param->set());
1335  if (!isbool)
1336  _errmsg += hit::errormsg(_input_filename,
1337  _root->find(full_name),
1338  "invalid boolean syntax for parameter: ",
1339  full_name,
1340  "=",
1341  strval) +
1342  "\n";
1343  }
1344  else
1345  throw;
1346  }
1347 
1348  if (in_global)
1349  {
1350  global_block->remove(short_name);
1351  global_block->setScalarParam<T>(short_name) = param->get();
1352  }
1353 }
subdomain_id_type SubdomainID
Definition: MooseTypes.h:160
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:251
T & setScalarParam(const std::string &name)
std::string _errmsg
Definition: Parser.h:266
std::unique_ptr< hit::Node > _root
Definition: Parser.h:233
bool toBool(const std::string &, T &)
Definition: Parser.C:1280
boundary_id_type BoundaryID
Definition: MooseTypes.h:158
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 1610 of file Parser.C.

1616 {
1617  setScalarComponentParameter(full_name, short_name, param, in_global, global_block);
1618 }
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:1512

◆ 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 1622 of file Parser.C.

1627 {
1628  setScalarComponentParameter(full_name, short_name, param, in_global, global_block);
1629 }
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:1512

◆ 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 1633 of file Parser.C.

1638 {
1639  MooseEnum current_param = param->get();
1640 
1641  std::string value = _root->param<std::string>(full_name);
1642 
1643  param->set() = value;
1644  if (in_global)
1645  {
1646  global_block->remove(short_name);
1647  global_block->setScalarParam<MooseEnum>(short_name) = current_param;
1648  }
1649 }
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:233
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 1653 of file Parser.C.

1659 {
1660  MultiMooseEnum current_param = param->get();
1661 
1662  auto vec = _root->param<std::vector<std::string>>(full_name);
1663 
1664  std::string raw_values;
1665  for (unsigned int i = 0; i < vec.size(); ++i)
1666  raw_values += ' ' + vec[i];
1667 
1668  param->set() = raw_values;
1669 
1670  if (in_global)
1671  {
1672  global_block->remove(short_name);
1673  global_block->setScalarParam<MultiMooseEnum>(short_name) = current_param;
1674  }
1675 }
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:233
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 1679 of file Parser.C.

1685 {
1686  ExecFlagEnum current_param = param->get();
1687  auto vec = _root->param<std::vector<std::string>>(full_name);
1688 
1689  std::string raw_values;
1690  for (unsigned int i = 0; i < vec.size(); ++i)
1691  raw_values += ' ' + vec[i];
1692 
1693  param->set() = raw_values;
1694 
1695  if (in_global)
1696  {
1697  global_block->remove(short_name);
1698  global_block->setScalarParam<ExecFlagEnum>(short_name) = current_param;
1699  }
1700 }
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:233
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 1704 of file Parser.C.

1710 {
1711  auto vec = _root->param<std::vector<double>>(full_name);
1712  if (vec.size() != LIBMESH_DIM * LIBMESH_DIM)
1713  {
1714  _errmsg += hit::errormsg(_input_filename,
1715  _root->find(full_name),
1716  "invalid RealTensorValue parameter ",
1717  full_name,
1718  ": size is ",
1719  vec.size(),
1720  " but should be ",
1721  LIBMESH_DIM * LIBMESH_DIM) +
1722  "\n";
1723  return;
1724  }
1725 
1726  RealTensorValue value;
1727  for (int i = 0; i < LIBMESH_DIM; ++i)
1728  for (int j = 0; j < LIBMESH_DIM; ++j)
1729  value(i, j) = Real(vec[i * LIBMESH_DIM + j]);
1730 
1731  param->set() = value;
1732  if (in_global)
1733  {
1734  global_block->remove(short_name);
1735  global_block->setScalarParam<RealTensorValue>(short_name) = value;
1736  }
1737 }
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:251
T & setScalarParam(const std::string &name)
std::string _errmsg
Definition: Parser.h:266
std::unique_ptr< hit::Node > _root
Definition: Parser.h:233
TensorValue< Real > RealTensorValue
Definition: MooseTypes.h:133
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 1742 of file Parser.C.

1748 {
1749  PostprocessorName pps_name = _root->param<std::string>(full_name);
1750  param->set() = pps_name;
1751 
1752  Real real_value = -std::numeric_limits<Real>::max();
1753  std::istringstream ss(pps_name);
1754 
1755  if (ss >> real_value && ss.eof())
1756  _current_params->setDefaultPostprocessorValue(short_name, real_value);
1757 
1758  if (in_global)
1759  {
1760  global_block->remove(short_name);
1761  global_block->setScalarParam<PostprocessorName>(short_name) = pps_name;
1762  }
1763 }
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:233
InputParameters * _current_params
The current parameter object for which parameters are being extracted.
Definition: Parser.h:260
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 1382 of file Parser.C.

1387 {
1388  setScalarParameter<T, Base>(full_name, short_name, param, in_global, global_block);
1389 
1390  // If this is a range checked param, we need to make sure that the value falls within the
1391  // requested range
1392  mooseAssert(_current_params, "Current params is nullptr");
1393 
1394  _current_params->rangeCheck<T, UP_T>(full_name, short_name, param, *_current_error_stream);
1395 }
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:263
InputParameters * _current_params
The current parameter object for which parameters are being extracted.
Definition: Parser.h:260

◆ 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 1557 of file Parser.C.

1562 {
1563  std::vector<double> vec;
1564  try
1565  {
1566  vec = _root->param<std::vector<double>>(full_name);
1567  }
1568  catch (hit::Error & err)
1569  {
1570  _errmsg += hit::errormsg(_input_filename, _root->find(full_name), err.what()) + "\n";
1571  return;
1572  }
1573 
1574  if (vec.size() % LIBMESH_DIM)
1575  {
1576  _errmsg += hit::errormsg(_input_filename,
1577  _root->find(full_name),
1578  "wrong number of values in vector component parameter ",
1579  full_name,
1580  ": size ",
1581  vec.size(),
1582  " is not a multiple of ",
1583  LIBMESH_DIM) +
1584  "\n";
1585  return;
1586  }
1587 
1588  std::vector<T> values;
1589  for (unsigned int i = 0; i < vec.size() / LIBMESH_DIM; ++i)
1590  {
1591  T value;
1592  for (int j = 0; j < LIBMESH_DIM; ++j)
1593  value(j) = Real(vec[i * LIBMESH_DIM + j]);
1594  values.push_back(value);
1595  }
1596 
1597  param->set() = values;
1598 
1599  if (in_global)
1600  {
1601  global_block->remove(short_name);
1602  global_block->setVectorParam<T>(short_name).resize(vec.size(), values[0]);
1603  for (unsigned int i = 0; i < vec.size() / LIBMESH_DIM; ++i)
1604  global_block->setVectorParam<T>(short_name)[i] = values[0];
1605  }
1606 }
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:251
std::string _errmsg
Definition: Parser.h:266
std::unique_ptr< hit::Node > _root
Definition: Parser.h:233
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 1434 of file Parser.C.

1440 {
1441  std::vector<T> vec;
1442  std::vector<std::string> rawvec;
1443  if (_root->find(full_name))
1444  {
1445  auto tmp = _root->param<std::vector<std::string>>(full_name);
1446  params.rawParamVal(short_name) = _root->param<std::string>(full_name);
1447  for (auto val : tmp)
1448  {
1449  std::string prefix;
1450  std::string postfix = val;
1451  size_t pos = _input_filename.find_last_of('/');
1452  if (pos != std::string::npos && postfix[0] != '/')
1453  prefix = _input_filename.substr(0, pos + 1);
1454  rawvec.push_back(postfix);
1455  vec.push_back(prefix + postfix);
1456  }
1457  }
1458 
1459  param->set() = vec;
1460 
1461  if (in_global)
1462  {
1463  global_block->remove(short_name);
1464  global_block->setVectorParam<T>(short_name).resize(param->get().size());
1465  for (unsigned int i = 0; i < vec.size(); ++i)
1466  global_block->setVectorParam<T>(short_name)[i] = param->get()[i];
1467  }
1468 }
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:251
std::unique_ptr< hit::Node > _root
Definition: Parser.h:233
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 1399 of file Parser.C.

1404 {
1405  std::vector<T> vec;
1406  if (_root->find(full_name))
1407  {
1408  try
1409  {
1410  auto tmp = _root->param<std::vector<Base>>(full_name);
1411  for (auto val : tmp)
1412  vec.push_back(val);
1413  }
1414  catch (hit::Error & err)
1415  {
1416  _errmsg += hit::errormsg(_input_filename, _root->find(full_name), err.what()) + "\n";
1417  return;
1418  }
1419  }
1420 
1421  param->set() = vec;
1422 
1423  if (in_global)
1424  {
1425  global_block->remove(short_name);
1426  global_block->setVectorParam<T>(short_name).resize(param->get().size());
1427  for (unsigned int i = 0; i < vec.size(); ++i)
1428  global_block->setVectorParam<T>(short_name)[i] = param->get()[i];
1429  }
1430 }
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:251
std::string _errmsg
Definition: Parser.h:266
std::unique_ptr< hit::Node > _root
Definition: Parser.h:233
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 1767 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:1557

◆ 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 1779 of file Parser.C.

1784 {
1785  setVectorComponentParameter(full_name, short_name, param, in_global, global_block);
1786 }
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:1557

◆ 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 1790 of file Parser.C.

1796 {
1797  std::vector<MooseEnum> enum_values = param->get();
1798  std::vector<std::string> values(enum_values.size());
1799  for (unsigned int i = 0; i < values.size(); ++i)
1800  values[i] = static_cast<std::string>(enum_values[i]);
1801 
1806  std::vector<std::string> vec;
1807  if (_root->find(full_name))
1808  {
1809  vec = _root->param<std::vector<std::string>>(full_name);
1810  param->set().resize(vec.size(), enum_values[0]);
1811  }
1812 
1813  for (unsigned int i = 0; i < vec.size(); ++i)
1814  param->set()[i] = vec[i];
1815 
1816  if (in_global)
1817  {
1818  global_block->remove(short_name);
1819  global_block->setVectorParam<MooseEnum>(short_name).resize(vec.size(), enum_values[0]);
1820  for (unsigned int i = 0; i < vec.size(); ++i)
1821  global_block->setVectorParam<MooseEnum>(short_name)[i] = values[0];
1822  }
1823 }
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:233
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 1831 of file Parser.C.

1837 {
1838  auto vec = _root->param<std::vector<std::string>>(full_name);
1839  auto strval = _root->param<std::string>(full_name);
1840  std::vector<VariableName> var_names(vec.size());
1841 
1842  bool has_var_names = false;
1843  for (unsigned int i = 0; i < vec.size(); ++i)
1844  {
1845  VariableName var_name = vec[i];
1846 
1847  Real real_value;
1848  std::istringstream ss(var_name);
1849 
1850  // If we are able to convert this value into a Real, then set a default coupled value
1851  // NOTE: parameter must be either all default or no defaults
1852  if (ss >> real_value && ss.eof())
1853  _current_params->defaultCoupledValue(short_name, real_value, i);
1854  else
1855  {
1856  var_names[i] = var_name;
1857  has_var_names = true;
1858  }
1859  }
1860 
1861  if (has_var_names)
1862  {
1863  param->set().resize(vec.size());
1864 
1865  for (unsigned int i = 0; i < vec.size(); ++i)
1866  if (var_names[i] == "")
1867  {
1868  _errmsg +=
1869  hit::errormsg(
1871  _root->find(full_name),
1872  "invalid value for ",
1873  full_name,
1874  ":\n"
1875  " MOOSE does not currently support a coupled vector where some parameters are ",
1876  "reals and others are variables") +
1877  "\n";
1878  return;
1879  }
1880  else
1881  param->set()[i] = var_names[i];
1882  }
1883 }
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:251
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:266
std::unique_ptr< hit::Node > _root
Definition: Parser.h:233
InputParameters * _current_params
The current parameter object for which parameters are being extracted.
Definition: Parser.h:260

◆ walk()

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

Definition at line 383 of file Parser.C.

384 {
385  // skip sections that were manually processed first.
386  for (auto & sec : _secs_need_first)
387  if (nodepath == sec)
388  return;
389  walkRaw(fullpath, nodepath, n);
390 }
void walkRaw(std::string fullpath, std::string nodepath, hit::Node *n)
Definition: Parser.C:306
std::vector< std::string > _secs_need_first
Definition: Parser.h:234
PetscInt n

◆ walkRaw()

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

Definition at line 306 of file Parser.C.

Referenced by parse(), and walk().

307 {
308  InputParameters active_list_params = validParams<Action>();
310 
311  std::string section_name = n->fullpath();
312  std::string curr_identifier = n->fullpath();
313 
314  // Before we retrieve any actions or build any objects, make sure that the section they are in
315  // is active
316  if (!isSectionActive(curr_identifier, _root.get()))
317  return;
318 
319  // Extract the block parameters before constructing the action
320  // There may be more than one Action registered for a given section in which case we need to
321  // build them all
322  bool is_parent;
323  std::string registered_identifier = _syntax.isAssociated(section_name, &is_parent);
324 
325  // We need to retrieve a list of Actions associated with the current identifier
326  auto iters = _syntax.getActions(registered_identifier);
327  if (iters.first == iters.second)
328  {
329  _errmsg += hit::errormsg(getFileName(),
330  n,
331  "section '",
332  curr_identifier,
333  "' does not have an associated \"Action\".\nDid you misspell it?") +
334  "\n";
335  return;
336  }
337 
338  for (auto it = iters.first; it != iters.second; ++it)
339  {
340  if (is_parent)
341  continue;
342  if (_syntax.isDeprecatedSyntax(registered_identifier))
343  mooseDeprecated(hit::errormsg(
344  getFileName(), n, _syntax.deprecatedActionSyntaxMessage(registered_identifier)));
345 
346  params = _action_factory.getValidParams(it->second._action);
347 
348  params.set<ActionWarehouse *>("awh") = &_action_wh;
349 
350  extractParams(curr_identifier, params);
351 
352  // Add the parsed syntax to the parameters object for consumption by the Action
353  params.set<std::string>("task") = it->second._task;
354  params.set<std::string>("registered_identifier") = registered_identifier;
355  params.blockLocation() = _input_filename + ":" + std::to_string(n->line());
356  params.blockFullpath() = n->fullpath();
357 
358  // Create the Action
359  std::shared_ptr<Action> action_obj =
360  _action_factory.create(it->second._action, MooseUtils::shortName(curr_identifier), params);
361 
362  {
363  // extract the MooseObject params if necessary
364  std::shared_ptr<MooseObjectAction> object_action =
366  if (object_action)
367  {
368  object_action->getObjectParams().blockLocation() = params.blockLocation();
369  object_action->getObjectParams().blockFullpath() = params.blockFullpath();
370  extractParams(curr_identifier, object_action->getObjectParams());
371  object_action->getObjectParams()
372  .set<std::vector<std::string>>("control_tags")
373  .push_back(MooseUtils::baseName(curr_identifier));
374  }
375  }
376 
377  // add it to the warehouse
378  _action_wh.addActionBlock(action_obj);
379  }
380 }
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:280
InputParameters validParams< EmptyAction >()
Definition: EmptyAction.C:20
InputParameters getValidParams(const std::string &name)
Definition: ActionFactory.C:70
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:957
Syntax & _syntax
Reference to an object that defines input file syntax.
Definition: Parser.h:245
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:363
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:251
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:186
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:218
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:266
ActionWarehouse & _action_wh
Action warehouse that will be filled by actions.
Definition: Parser.h:241
std::string baseName(const std::string &name)
Function for string the information before the final / in a parser block.
Definition: MooseUtils.C:369
PetscInt n
std::unique_ptr< hit::Node > _root
Definition: Parser.h:233
std::string getFileName(bool stripLeadingPath=true) const
Return the filename that was parsed.
Definition: Parser.C:290
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:175
ActionFactory & _action_factory
The Factory that builds actions.
Definition: Parser.h:243
std::string & blockLocation()
Get/set a string representing the location (i.e.
InputParameters validParams< Action >()
Definition: Action.C:22

Member Data Documentation

◆ _action_factory

ActionFactory& Parser::_action_factory
protected

The Factory that builds actions.

Definition at line 243 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 241 of file Parser.h.

Referenced by extractParams(), and walkRaw().

◆ _app

MooseApp& Parser::_app
protected

The MooseApp this Parser is part of.

Definition at line 237 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 232 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(), MultiApp::backup(), FEProblemBase::backupMultiApps(), FEProblemBase::checkProblemIntegrity(), IterationAdaptiveDT::computeAdaptiveDT(), Transient::computeConstrainedDT(), NonlinearSystemBase::computeDamping(), IterationAdaptiveDT::computeDT(), IterationAdaptiveDT::computeFailedDT(), IterationAdaptiveDT::computeInterpolationDT(), FEProblemBase::computeResidualTags(), IterationAdaptiveDT::constrainStep(), TimeStepper::constrainStep(), MultiApp::createApp(), FEProblemBase::execMultiApps(), FEProblemBase::execMultiAppTransfers(), MultiAppPostprocessorTransfer::execute(), MultiAppPostprocessorInterpolationTransfer::execute(), MultiAppVariableValueSamplePostprocessorTransfer::execute(), MultiAppPostprocessorToAuxScalarTransfer::execute(), MultiAppScalarToAuxScalarTransfer::execute(), MultiAppVariableValueSampleTransfer::execute(), MultiAppInterpolationTransfer::execute(), MultiAppMeshFunctionTransfer::execute(), MultiAppUserObjectTransfer::execute(), MultiAppVectorPostprocessorTransfer::execute(), MultiAppNearestNodeTransfer::execute(), MultiAppProjectionTransfer::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(), AB2PredictorCorrector::postSolve(), ActionWarehouse::printActionDependencySets(), EigenExecutionerBase::printEigenvalue(), MaterialPropertyDebugOutput::printMaterialMap(), SolutionTimeAdaptiveDT::rejectStep(), DT2::rejectStep(), MultiApp::restore(), FEProblemBase::restoreMultiApps(), SimplePredictor::shouldApply(), NonlinearSystem::solve(), PicardSolve::solve(), LStableDirk2::solve(), LStableDirk3::solve(), ImplicitMidpoint::solve(), ExplicitTVDRK2::solve(), LStableDirk4::solve(), AStableDirk4::solve(), ExplicitRK2::solve(), TransientMultiApp::solveStep(), PicardSolve::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 263 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 260 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 254 of file Parser.h.

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

◆ _factory

Factory& Parser::_factory
protected

The Factory associated with that MooseApp.

Definition at line 239 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 234 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 257 of file Parser.h.

◆ _syntax

Syntax& Parser::_syntax
protected

Reference to an object that defines input file syntax.

Definition at line 245 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 248 of file Parser.h.

Referenced by buildFullTree(), and initSyntaxFormatter().

◆ _warnmsg

std::string Parser::_warnmsg
private

Definition at line 267 of file Parser.h.

Referenced by errorCheck().


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