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

54  _app(app),
55  _factory(app.getFactory()),
56  _action_wh(action_wh),
59  _syntax_formatter(nullptr),
60  _sections_read(false),
61  _current_params(nullptr),
62  _current_error_stream(nullptr)
63 {
64 }
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 66 of file Parser.C.

66 {}

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

Referenced by MooseApp::setupOptions().

782 {
783  std::vector<std::pair<std::string, Syntax::ActionInfo>> all_names;
784 
785  for (const auto & iter : _syntax.getAssociatedActions())
786  {
787  Syntax::ActionInfo act_info = iter.second;
793  if (act_info._task == "")
794  act_info._task = _action_factory.getTaskName(act_info._action);
795 
796  all_names.push_back(std::pair<std::string, Syntax::ActionInfo>(iter.first, act_info));
797  }
798 
799  for (const auto & act_names : all_names)
800  {
801  InputParameters action_obj_params = _action_factory.getValidParams(act_names.second._action);
802  _syntax_formatter->insertNode(
803  act_names.first, act_names.second._action, true, &action_obj_params);
804 
805  const std::string & task = act_names.second._task;
806  std::string act_name = act_names.first;
807 
813  if (action_obj_params.have_parameter<bool>("isObjectAction") &&
814  action_obj_params.get<bool>("isObjectAction"))
815  {
817  moose_obj != _factory.registeredObjectsEnd();
818  ++moose_obj)
819  {
820  InputParameters moose_obj_params = (moose_obj->second)();
825  const std::vector<std::string> & buildable_types = action_obj_params.getBuildableTypes();
826 
827  // See if the current Moose Object syntax belongs under this Action's block
828  if ((buildable_types.empty() || // Not restricted
829  std::find(buildable_types.begin(), buildable_types.end(), moose_obj->first) !=
830  buildable_types.end()) && // Restricted but found
831  moose_obj_params.have_parameter<std::string>("_moose_base") && // Has a registered base
832  _syntax.verifyMooseObjectTask(moose_obj_params.get<std::string>("_moose_base"),
833  task) && // and that base is associated
834  action_obj_params.mooseObjectSyntaxVisibility()) // and the Action says it's visible
835  {
836  std::string name;
837  size_t pos = 0;
838  bool is_action_params = false;
839  if (act_name[act_name.size() - 1] == '*')
840  {
841  pos = act_name.size();
842 
843  if (!action_obj_params.collapseSyntaxNesting())
844  name = act_name.substr(0, pos - 1) + moose_obj->first;
845  else
846  {
847  name = act_name.substr(0, pos - 1) + "/<type>/" + moose_obj->first;
848  is_action_params = true;
849  }
850  }
851  else
852  {
853  name = act_name + "/<type>/" + moose_obj->first;
854  }
855 
856  moose_obj_params.set<std::string>("type") = moose_obj->first;
857 
858  _syntax_formatter->insertNode(
859  name, moose_obj->first, is_action_params, &moose_obj_params);
860  }
861  }
862  }
863  }
864 
865  // Do not change to _console, we need this printed to the stdout in all cases
866  Moose::out << _syntax_formatter->print(search_string) << std::flush;
867 }
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
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 665 of file Parser.C.

Referenced by MooseApp::setupOptions().

666 {
667  std::vector<std::pair<std::string, Syntax::ActionInfo>> all_names;
668 
669  for (const auto & iter : _syntax.getAssociatedTypes())
670  root.addSyntaxType(iter.first, iter.second);
671 
672  for (const auto & iter : _syntax.getAssociatedActions())
673  {
674  Syntax::ActionInfo act_info = iter.second;
680  if (act_info._task == "")
681  act_info._task = _action_factory.getTaskName(act_info._action);
682 
683  all_names.push_back(std::make_pair(iter.first, act_info));
684  }
685 
686  for (const auto & act_names : all_names)
687  {
688  const auto & act_info = act_names.second;
689  const std::string & action = act_info._action;
690  const std::string & task = act_info._task;
691  const std::string act_name = act_names.first;
692  InputParameters action_obj_params = _action_factory.getValidParams(action);
693  bool params_added = root.addParameters("",
694  act_name,
695  false,
696  action,
697  true,
698  &action_obj_params,
699  _syntax.getLineInfo(act_name, action, ""),
700  "");
701 
702  if (params_added)
703  {
704  auto tasks = _action_factory.getTasksByAction(action);
705  for (auto & t : tasks)
706  {
707  auto info = _action_factory.getLineInfo(action, t);
708  root.addActionTask(act_name, action, t, info);
709  }
710  }
711 
717  if (action_obj_params.have_parameter<bool>("isObjectAction") &&
718  action_obj_params.get<bool>("isObjectAction"))
719  {
721  moose_obj != _factory.registeredObjectsEnd();
722  ++moose_obj)
723  {
724  InputParameters moose_obj_params = (moose_obj->second)();
725  // Now that we know that this is a MooseObjectAction we need to see if it has been
726  // restricted
727  // in any way by the user.
728  const std::vector<std::string> & buildable_types = action_obj_params.getBuildableTypes();
729 
730  // See if the current Moose Object syntax belongs under this Action's block
731  if ((buildable_types.empty() || // Not restricted
732  std::find(buildable_types.begin(), buildable_types.end(), moose_obj->first) !=
733  buildable_types.end()) && // Restricted but found
734  moose_obj_params.have_parameter<std::string>("_moose_base") && // Has a registered base
735  _syntax.verifyMooseObjectTask(moose_obj_params.get<std::string>("_moose_base"),
736  task) && // and that base is associated
737  action_obj_params.mooseObjectSyntaxVisibility()) // and the Action says it's visible
738  {
739  std::string name;
740  size_t pos = 0;
741  bool is_action_params = false;
742  bool is_type = false;
743  if (act_name[act_name.size() - 1] == '*')
744  {
745  pos = act_name.size();
746 
747  if (!action_obj_params.collapseSyntaxNesting())
748  name = act_name.substr(0, pos - 1) + moose_obj->first;
749  else
750  {
751  name = act_name.substr(0, pos - 1) + "/<type>/" + moose_obj->first;
752  is_action_params = true;
753  }
754  }
755  else
756  {
757  name = act_name + "/<type>/" + moose_obj->first;
758  is_type = true;
759  }
760 
761  moose_obj_params.set<std::string>("type") = moose_obj->first;
762 
763  auto lineinfo = _factory.getLineInfo(moose_obj->first);
764  std::string classname = _factory.associatedClassName(moose_obj->first);
765  root.addParameters(act_name,
766  name,
767  is_type,
768  moose_obj->first,
769  is_action_params,
770  &moose_obj_params,
771  lineinfo,
772  classname);
773  }
774  }
775  }
776  }
777  root.addGlobal();
778 }
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 598 of file Parser.C.

Referenced by MooseApp::errorCheck().

599 {
600  // this if guard is important in case the simulation was not configured via parsed input text -
601  // e.g. configured programatically.
602  if (!_root || !_cli_root)
603  return;
604 
606  UnusedWalker uwcli("CLI_ARG", _extracted_vars, *this);
607 
608  _root->walk(&uw);
609  _cli_root->walk(&uwcli);
610 
611  auto cli = _app.commandLine();
612  if (warn_unused)
613  {
614  for (auto arg : cli->unused(comm))
615  _warnmsg += hit::errormsg("CLI_ARG",
616  nullptr,
617  "unused command line parameter '",
618  cli->getArguments()[arg],
619  "'") +
620  "\n";
621  for (auto & msg : uwcli.errors)
622  _warnmsg += msg + "\n";
623  for (auto & msg : uw.errors)
624  _warnmsg += msg + "\n";
625  }
626  else if (err_unused)
627  {
628  for (auto arg : cli->unused(comm))
629  _errmsg += hit::errormsg("CLI_ARG",
630  nullptr,
631  "unused command line parameter '",
632  cli->getArguments()[arg],
633  "'") +
634  "\n";
635  for (auto & msg : uwcli.errors)
636  _errmsg += msg + "\n";
637  for (auto & msg : uw.errors)
638  _errmsg += msg + "\n";
639  }
640 
641  if (_warnmsg.size() > 0)
643  if (_errmsg.size() > 0)
645 }
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 965 of file Parser.C.

Referenced by walkRaw().

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

◆ getFileName()

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

Return the filename that was parsed.

Definition at line 291 of file Parser.C.

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

292 {
293  if (!stripLeadingPath)
294  return _input_filename;
295 
296  std::string filename;
297  size_t pos = _input_filename.find_last_of('/');
298  if (pos != std::string::npos)
299  filename = _input_filename.substr(pos + 1);
300  else
301  filename = _input_filename;
302 
303  return filename;
304 }
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 409 of file Parser.C.

Referenced by parse().

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

Referenced by MooseApp::setupOptions().

649 {
650  switch (type)
651  {
652  case INPUT_FILE:
653  _syntax_formatter = libmesh_make_unique<InputFileFormatter>(dump_mode);
654  break;
655  case YAML:
656  _syntax_formatter = libmesh_make_unique<YAMLFormatter>(dump_mode);
657  break;
658  default:
659  mooseError("Unrecognized Syntax Formatter requested");
660  break;
661  }
662 }
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 163 of file Parser.C.

Referenced by UnusedWalker::walk().

164 {
165  bool dummy;
166  std::string registered_identifier = _syntax.isAssociated(section_name, &dummy);
167  auto iters = _syntax.getActions(registered_identifier);
168 
169  std::vector<std::string> paramlist;
170  for (auto it = iters.first; it != iters.second; ++it)
171  {
172  auto params = _action_factory.getValidParams(it->second._action);
173  for (const auto & it : params)
174  paramlist.push_back(it.first);
175  }
176  return paramlist;
177 }
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 498 of file Parser.C.

Referenced by MooseApp::setupOptions().

499 {
500  // Save the filename
501  char abspath[PATH_MAX + 1];
502  realpath(input_filename.c_str(), abspath);
503  _input_filename = std::string(abspath);
504 
505  // vector for initializing active blocks
506  std::vector<std::string> all = {"__all__"};
507 
509 
510  std::ifstream f(_input_filename);
511  std::string input((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
512 
513  try
514  {
515  _root.reset(hit::parse(_input_filename, input));
516  auto cli_input = hitCLIFilter(_app.name(), _app.commandLine()->getArguments());
517 
518  _cli_root.reset(hit::parse("CLI_ARGS", cli_input));
519  hit::explode(_cli_root.get());
520  hit::explode(_root.get());
521  hit::merge(_cli_root.get(), _root.get());
522  }
523  catch (hit::ParseError & err)
524  {
525  mooseError(err.what());
526  }
527 
528  // expand ${bla} parameter values and mark/include variables used in expansions as "used". This
529  // MUST occur before parameter extraction - otherwise parameters will get wrong values.
530  hit::RawEvaler raw;
531  hit::EnvEvaler env;
532  hit::ReplaceEvaler repl;
533  FuncParseEvaler fparse_ev;
534  hit::BraceExpander exw(_input_filename);
535  exw.registerEvaler("raw", raw);
536  exw.registerEvaler("env", env);
537  exw.registerEvaler("fparse", fparse_ev);
538  exw.registerEvaler("replace", repl);
539  _root->walk(&exw);
540  for (auto & var : exw.used)
541  _extracted_vars.insert(var);
542  for (auto & msg : exw.errors)
543  _errmsg += msg + "\n";
544 
545  // do as much error checking as early as possible so that errors are more useful instead
546  // of surprising and disconnected from what caused them.
549  _root->walk(&dw, hit::NodeType::Field);
550  _root->walk(&bw, hit::NodeType::Section);
551  for (auto & msg : dw.errors)
552  _errmsg += msg + "\n";
553  for (auto & msg : bw.errors)
554  _errmsg += msg + "\n";
555 
556  // There are a few order dependent actions that have to be built first in
557  // order for the parser and application to function properly:
558  //
559  // SetupDebugAction: This action can contain an option for monitoring the parser progress. It must
560  // be parsed first to capture all of the parsing output.
561  //
562  // GlobalParamsAction: This action is checked during the parameter extraction routines of all
563  // subsequent blocks. It must be parsed early since it must exist during
564  // subsequent parameter extraction.
565  //
566  // DynamicObjectRegistration: This action must be built before any MooseObjectActions are built.
567  // This is because we retrieve valid parameters from the Factory
568  // during parse time. Objects must be registered before
569  // validParameters can be retrieved.
570  auto syntax = _syntax.getSyntaxByAction("SetupDebugAction");
571  std::copy(syntax.begin(), syntax.end(), std::back_inserter(_secs_need_first));
572 
573  syntax = _syntax.getSyntaxByAction("GlobalParamsAction");
574  std::copy(syntax.begin(), syntax.end(), std::back_inserter(_secs_need_first));
575 
576  syntax = _syntax.getSyntaxByAction("DynamicObjectRegistrationAction");
577  std::copy(syntax.begin(), syntax.end(), std::back_inserter(_secs_need_first));
578 
579  // walk all the sections extracting paramters from each into InputParameters objects
580  for (auto & sec : _secs_need_first)
581  {
582  auto n = _root->find(sec);
583  if (n)
584  walkRaw(n->parent()->fullpath(), n->path(), n);
585  }
586  _root->walk(this, hit::NodeType::Section);
587 
588  if (_errmsg.size() > 0)
590 }
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:307
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:409
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 1480 of file Parser.C.

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

1371 {
1372  std::string prefix;
1373  std::string postfix = _root->param<std::string>(full_name);
1374  size_t pos = _input_filename.find_last_of('/');
1375  if (pos != std::string::npos && postfix[0] != '/' && !postfix.empty())
1376  prefix = _input_filename.substr(0, pos + 1);
1377 
1378  params.rawParamVal(short_name) = postfix;
1379  param->set() = prefix + postfix;
1380 
1381  if (in_global)
1382  {
1383  global_block->remove(short_name);
1384  global_block->setScalarParam<T>(short_name) = param->get();
1385  }
1386 }
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 1520 of file Parser.C.

1525 {
1526  std::vector<double> vec;
1527  try
1528  {
1529  vec = _root->param<std::vector<double>>(full_name);
1530  }
1531  catch (hit::Error & err)
1532  {
1533  _errmsg += hit::errormsg(_input_filename, _root->find(full_name), err.what()) + "\n";
1534  return;
1535  }
1536 
1537  if (vec.size() != LIBMESH_DIM)
1538  {
1539  _errmsg += hit::errormsg(_input_filename,
1540  _root->find(full_name),
1541  "wrong number of values in scalar component parameter ",
1542  full_name,
1543  ": size ",
1544  vec.size(),
1545  " is not a multiple of ",
1546  LIBMESH_DIM) +
1547  "\n";
1548  return;
1549  }
1550 
1551  T value;
1552  for (unsigned int i = 0; i < vec.size(); ++i)
1553  value(i) = Real(vec[i]);
1554 
1555  param->set() = value;
1556  if (in_global)
1557  {
1558  global_block->remove(short_name);
1559  global_block->setScalarParam<T>(short_name) = value;
1560  }
1561 }
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 1302 of file Parser.C.

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

1624 {
1625  setScalarComponentParameter(full_name, short_name, param, in_global, global_block);
1626 }
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:1520

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

1635 {
1636  setScalarComponentParameter(full_name, short_name, param, in_global, global_block);
1637 }
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:1520

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

1646 {
1647  MooseEnum current_param = param->get();
1648 
1649  std::string value = _root->param<std::string>(full_name);
1650 
1651  param->set() = value;
1652  if (in_global)
1653  {
1654  global_block->remove(short_name);
1655  global_block->setScalarParam<MooseEnum>(short_name) = current_param;
1656  }
1657 }
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 1661 of file Parser.C.

1667 {
1668  MultiMooseEnum current_param = param->get();
1669 
1670  auto vec = _root->param<std::vector<std::string>>(full_name);
1671 
1672  std::string raw_values;
1673  for (unsigned int i = 0; i < vec.size(); ++i)
1674  raw_values += ' ' + vec[i];
1675 
1676  param->set() = raw_values;
1677 
1678  if (in_global)
1679  {
1680  global_block->remove(short_name);
1681  global_block->setScalarParam<MultiMooseEnum>(short_name) = current_param;
1682  }
1683 }
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 1687 of file Parser.C.

1693 {
1694  ExecFlagEnum current_param = param->get();
1695  auto vec = _root->param<std::vector<std::string>>(full_name);
1696 
1697  std::string raw_values;
1698  for (unsigned int i = 0; i < vec.size(); ++i)
1699  raw_values += ' ' + vec[i];
1700 
1701  param->set() = raw_values;
1702 
1703  if (in_global)
1704  {
1705  global_block->remove(short_name);
1706  global_block->setScalarParam<ExecFlagEnum>(short_name) = current_param;
1707  }
1708 }
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 1712 of file Parser.C.

1718 {
1719  auto vec = _root->param<std::vector<double>>(full_name);
1720  if (vec.size() != LIBMESH_DIM * LIBMESH_DIM)
1721  {
1722  _errmsg += hit::errormsg(_input_filename,
1723  _root->find(full_name),
1724  "invalid RealTensorValue parameter ",
1725  full_name,
1726  ": size is ",
1727  vec.size(),
1728  " but should be ",
1729  LIBMESH_DIM * LIBMESH_DIM) +
1730  "\n";
1731  return;
1732  }
1733 
1734  RealTensorValue value;
1735  for (int i = 0; i < LIBMESH_DIM; ++i)
1736  for (int j = 0; j < LIBMESH_DIM; ++j)
1737  value(i, j) = Real(vec[i * LIBMESH_DIM + j]);
1738 
1739  param->set() = value;
1740  if (in_global)
1741  {
1742  global_block->remove(short_name);
1743  global_block->setScalarParam<RealTensorValue>(short_name) = value;
1744  }
1745 }
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:97
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 1750 of file Parser.C.

1756 {
1757  PostprocessorName pps_name = _root->param<std::string>(full_name);
1758  param->set() = pps_name;
1759 
1760  Real real_value = -std::numeric_limits<Real>::max();
1761  std::istringstream ss(pps_name);
1762 
1763  if (ss >> real_value && ss.eof())
1764  _current_params->setDefaultPostprocessorValue(short_name, real_value);
1765 
1766  if (in_global)
1767  {
1768  global_block->remove(short_name);
1769  global_block->setScalarParam<PostprocessorName>(short_name) = pps_name;
1770  }
1771 }
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 1390 of file Parser.C.

1395 {
1396  setScalarParameter<T, Base>(full_name, short_name, param, in_global, global_block);
1397 
1398  // If this is a range checked param, we need to make sure that the value falls within the
1399  // requested range
1400  mooseAssert(_current_params, "Current params is nullptr");
1401 
1402  _current_params->rangeCheck<T, UP_T>(full_name, short_name, param, *_current_error_stream);
1403 }
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 1565 of file Parser.C.

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

1448 {
1449  std::vector<T> vec;
1450  std::vector<std::string> rawvec;
1451  if (_root->find(full_name))
1452  {
1453  auto tmp = _root->param<std::vector<std::string>>(full_name);
1454  params.rawParamVal(short_name) = _root->param<std::string>(full_name);
1455  for (auto val : tmp)
1456  {
1457  std::string prefix;
1458  std::string postfix = val;
1459  size_t pos = _input_filename.find_last_of('/');
1460  if (pos != std::string::npos && postfix[0] != '/')
1461  prefix = _input_filename.substr(0, pos + 1);
1462  rawvec.push_back(postfix);
1463  vec.push_back(prefix + postfix);
1464  }
1465  }
1466 
1467  param->set() = vec;
1468 
1469  if (in_global)
1470  {
1471  global_block->remove(short_name);
1472  global_block->setVectorParam<T>(short_name).resize(param->get().size());
1473  for (unsigned int i = 0; i < vec.size(); ++i)
1474  global_block->setVectorParam<T>(short_name)[i] = param->get()[i];
1475  }
1476 }
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 1407 of file Parser.C.

1412 {
1413  std::vector<T> vec;
1414  if (_root->find(full_name))
1415  {
1416  try
1417  {
1418  auto tmp = _root->param<std::vector<Base>>(full_name);
1419  for (auto val : tmp)
1420  vec.push_back(val);
1421  }
1422  catch (hit::Error & err)
1423  {
1424  _errmsg += hit::errormsg(_input_filename, _root->find(full_name), err.what()) + "\n";
1425  return;
1426  }
1427  }
1428 
1429  param->set() = vec;
1430 
1431  if (in_global)
1432  {
1433  global_block->remove(short_name);
1434  global_block->setVectorParam<T>(short_name).resize(param->get().size());
1435  for (unsigned int i = 0; i < vec.size(); ++i)
1436  global_block->setVectorParam<T>(short_name)[i] = param->get()[i];
1437  }
1438 }
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 1775 of file Parser.C.

1781 {
1782  setVectorComponentParameter(full_name, short_name, param, in_global, global_block);
1783 }
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:1565

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

1792 {
1793  setVectorComponentParameter(full_name, short_name, param, in_global, global_block);
1794 }
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:1565

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

1804 {
1805  std::vector<MooseEnum> enum_values = param->get();
1806  std::vector<std::string> values(enum_values.size());
1807  for (unsigned int i = 0; i < values.size(); ++i)
1808  values[i] = static_cast<std::string>(enum_values[i]);
1809 
1814  std::vector<std::string> vec;
1815  if (_root->find(full_name))
1816  {
1817  vec = _root->param<std::vector<std::string>>(full_name);
1818  param->set().resize(vec.size(), enum_values[0]);
1819  }
1820 
1821  for (unsigned int i = 0; i < vec.size(); ++i)
1822  param->set()[i] = vec[i];
1823 
1824  if (in_global)
1825  {
1826  global_block->remove(short_name);
1827  global_block->setVectorParam<MooseEnum>(short_name).resize(vec.size(), enum_values[0]);
1828  for (unsigned int i = 0; i < vec.size(); ++i)
1829  global_block->setVectorParam<MooseEnum>(short_name)[i] = values[0];
1830  }
1831 }
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 1839 of file Parser.C.

1845 {
1846  auto vec = _root->param<std::vector<std::string>>(full_name);
1847  auto strval = _root->param<std::string>(full_name);
1848  std::vector<VariableName> var_names(vec.size());
1849 
1850  bool has_var_names = false;
1851  for (unsigned int i = 0; i < vec.size(); ++i)
1852  {
1853  VariableName var_name = vec[i];
1854 
1855  Real real_value;
1856  std::istringstream ss(var_name);
1857 
1858  // If we are able to convert this value into a Real, then set a default coupled value
1859  // NOTE: parameter must be either all default or no defaults
1860  if (ss >> real_value && ss.eof())
1861  _current_params->defaultCoupledValue(short_name, real_value, i);
1862  else
1863  {
1864  var_names[i] = var_name;
1865  has_var_names = true;
1866  }
1867  }
1868 
1869  if (has_var_names)
1870  {
1871  param->set().resize(vec.size());
1872 
1873  for (unsigned int i = 0; i < vec.size(); ++i)
1874  if (var_names[i] == "")
1875  {
1876  _errmsg +=
1877  hit::errormsg(
1879  _root->find(full_name),
1880  "invalid value for ",
1881  full_name,
1882  ":\n"
1883  " MOOSE does not currently support a coupled vector where some parameters are ",
1884  "reals and others are variables") +
1885  "\n";
1886  return;
1887  }
1888  else
1889  param->set()[i] = var_names[i];
1890  }
1891 }
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 399 of file Parser.C.

400 {
401  // skip sections that were manually processed first.
402  for (auto & sec : _secs_need_first)
403  if (nodepath == sec)
404  return;
405  walkRaw(fullpath, nodepath, n);
406 }
void walkRaw(std::string fullpath, std::string nodepath, hit::Node *n)
Definition: Parser.C:307
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 307 of file Parser.C.

Referenced by parse(), and walk().

308 {
309  InputParameters active_list_params = validParams<Action>();
311 
312  std::string section_name = n->fullpath();
313  std::string curr_identifier = n->fullpath();
314 
315  // Before we retrieve any actions or build any objects, make sure that the section they are in
316  // is active
317  if (!isSectionActive(curr_identifier, _root.get()))
318  return;
319 
320  // Extract the block parameters before constructing the action
321  // There may be more than one Action registered for a given section in which case we need to
322  // build them all
323  bool is_parent;
324  std::string registered_identifier = _syntax.isAssociated(section_name, &is_parent);
325 
326  // We need to retrieve a list of Actions associated with the current identifier
327  auto iters = _syntax.getActions(registered_identifier);
328  if (iters.first == iters.second)
329  {
330  _errmsg += hit::errormsg(getFileName(),
331  n,
332  "section '",
333  curr_identifier,
334  "' does not have an associated \"Action\".\nDid you misspell it?") +
335  "\n";
336  return;
337  }
338 
339  for (auto it = iters.first; it != iters.second; ++it)
340  {
341  if (is_parent)
342  continue;
343  if (_syntax.isDeprecatedSyntax(registered_identifier))
344  mooseDeprecated(hit::errormsg(
345  getFileName(), n, _syntax.deprecatedActionSyntaxMessage(registered_identifier)));
346 
347  params = _action_factory.getValidParams(it->second._action);
348 
349  params.set<ActionWarehouse *>("awh") = &_action_wh;
350 
351  extractParams(curr_identifier, params);
352 
353  // Add the parsed syntax to the parameters object for consumption by the Action
354  params.set<std::string>("task") = it->second._task;
355  params.set<std::string>("registered_identifier") = registered_identifier;
356  params.blockLocation() = _input_filename + ":" + std::to_string(n->line());
357  params.blockFullpath() = n->fullpath();
358 
359  // Create the Action
360  std::shared_ptr<Action> action_obj =
361  _action_factory.create(it->second._action, MooseUtils::shortName(curr_identifier), params);
362 
363  {
364  // extract the MooseObject params if necessary
365  std::shared_ptr<MooseObjectAction> object_action =
367  if (object_action)
368  {
369  object_action->getObjectParams().blockLocation() = params.blockLocation();
370  object_action->getObjectParams().blockFullpath() = params.blockFullpath();
371  extractParams(curr_identifier, object_action->getObjectParams());
372  object_action->getObjectParams()
373  .set<std::vector<std::string>>("control_tags")
374  .push_back(MooseUtils::baseName(curr_identifier));
375  }
376  }
377 
378  {
379  // extract the MooseObject params if necessary
380  std::shared_ptr<MooseADObjectAction> object_action =
382  if (object_action)
383  {
384  object_action->getObjectParams().blockLocation() = params.blockLocation();
385  object_action->getObjectParams().blockFullpath() = params.blockFullpath();
386  extractParams(curr_identifier, object_action->getObjectParams());
387  object_action->getObjectParams()
388  .set<std::vector<std::string>>("control_tags")
389  .push_back(MooseUtils::baseName(curr_identifier));
390  }
391  }
392 
393  // add it to the warehouse
394  _action_wh.addActionBlock(action_obj);
395  }
396 }
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
InputParameters & getObjectParams()
Retreive the parameters of the object to be created by this action.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
Storage for action instances.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void addActionBlock(std::shared_ptr< Action > blk)
This method add an Action instance to the warehouse.
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
void extractParams(const std::string &prefix, InputParameters &p)
This function attempts to extract values from the input file based on the contents of the passed para...
Definition: Parser.C:965
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:69
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:291
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:19

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(), MultiAppProjectionTransfer::execute(), MultiAppVectorPostprocessorTransfer::execute(), MultiAppNearestNodeTransfer::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: