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 getSyntaxByAction (const std::string &action, const std::string &task)
 Retrieve the Syntax associated with the passed Action and task. More...
 
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< 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< RealTensorValue > *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setScalarParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< PostprocessorName > *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setVectorParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< std::vector< RealVectorValue >> *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setVectorParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< std::vector< Point >> *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setVectorParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< std::vector< MooseEnum >> *param, bool in_global, GlobalParamsAction *global_block)
 
template<>
void setVectorParameter (const std::string &full_name, const std::string &short_name, InputParameters::Parameter< std::vector< VariableName >> *param, bool, GlobalParamsAction *)
 Specialization for coupling vectors. More...
 

Protected Attributes

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

Private Member Functions

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

Private Attributes

std::string _errmsg
 
std::string _warnmsg
 

Detailed Description

Class for parsing input files.

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

Definition at line 120 of file Parser.h.

Member Enumeration Documentation

Enumerator
INPUT_FILE 
YAML 

Definition at line 123 of file Parser.h.

124  {
125  INPUT_FILE,
126  YAML
127  };

Constructor & Destructor Documentation

Parser::Parser ( MooseApp app,
ActionWarehouse action_wh 
)

Definition at line 55 of file Parser.C.

57  _app(app),
58  _factory(app.getFactory()),
59  _action_wh(action_wh),
62  _syntax_formatter(nullptr),
63  _sections_read(false),
64  _current_params(nullptr),
65  _current_error_stream(nullptr)
66 {
67 }
MooseApp & _app
The MooseApp this Parser is part of.
Definition: Parser.h:267
bool _sections_read
Boolean to indicate whether parsing has started (sections have been extracted)
Definition: Parser.h:287
Syntax & _syntax
Reference to an object that defines input file syntax.
Definition: Parser.h:275
ActionFactory & getActionFactory()
Retrieve the ActionFactory associated with this App.
Definition: MooseApp.h:258
Factory & getFactory()
Retrieve the Factory associated with this App.
Definition: MooseApp.h:253
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:278
ActionWarehouse & _action_wh
Action warehouse that will be filled by actions.
Definition: Parser.h:271
std::ostringstream * _current_error_stream
The current stream object used for capturing errors during extraction.
Definition: Parser.h:293
InputParameters * _current_params
The current parameter object for which parameters are being extracted.
Definition: Parser.h:290
Factory & _factory
The Factory associated with that MooseApp.
Definition: Parser.h:269
ActionFactory & _action_factory
The Factory that builds actions.
Definition: Parser.h:273
Parser::~Parser ( )
virtual

Definition at line 69 of file Parser.C.

69 {}

Member Function Documentation

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

Referenced by MooseApp::setupOptions().

751 {
752  std::vector<std::pair<std::string, Syntax::ActionInfo>> all_names;
753 
754  for (const auto & iter : _syntax.getAssociatedActions())
755  {
756  Syntax::ActionInfo act_info = iter.second;
762  if (act_info._task == "")
763  act_info._task = _action_factory.getTaskName(act_info._action);
764 
765  all_names.push_back(std::pair<std::string, Syntax::ActionInfo>(iter.first, act_info));
766  }
767 
768  for (const auto & act_names : all_names)
769  {
770  InputParameters action_obj_params = _action_factory.getValidParams(act_names.second._action);
771  _syntax_formatter->insertNode(
772  act_names.first, act_names.second._action, true, &action_obj_params);
773 
774  const std::string & task = act_names.second._task;
775  std::string act_name = act_names.first;
776 
782  if (action_obj_params.have_parameter<bool>("isObjectAction") &&
783  action_obj_params.get<bool>("isObjectAction"))
784  {
786  moose_obj != _factory.registeredObjectsEnd();
787  ++moose_obj)
788  {
789  InputParameters moose_obj_params = (moose_obj->second)();
794  const std::vector<std::string> & buildable_types = action_obj_params.getBuildableTypes();
795 
796  // See if the current Moose Object syntax belongs under this Action's block
797  if ((buildable_types.empty() || // Not restricted
798  std::find(buildable_types.begin(), buildable_types.end(), moose_obj->first) !=
799  buildable_types.end()) && // Restricted but found
800  moose_obj_params.have_parameter<std::string>("_moose_base") && // Has a registered base
801  _syntax.verifyMooseObjectTask(moose_obj_params.get<std::string>("_moose_base"),
802  task) && // and that base is associated
803  action_obj_params.mooseObjectSyntaxVisibility()) // and the Action says it's visible
804  {
805  std::string name;
806  size_t pos = 0;
807  bool is_action_params = false;
808  if (act_name[act_name.size() - 1] == '*')
809  {
810  pos = act_name.size();
811 
812  if (!action_obj_params.collapseSyntaxNesting())
813  name = act_name.substr(0, pos - 1) + moose_obj->first;
814  else
815  {
816  name = act_name.substr(0, pos - 1) + "/<type>/" + moose_obj->first;
817  is_action_params = true;
818  }
819  }
820  else
821  {
822  name = act_name + "/<type>/" + moose_obj->first;
823  }
824 
825  moose_obj_params.set<std::string>("type") = moose_obj->first;
826 
827  _syntax_formatter->insertNode(
828  name, moose_obj->first, is_action_params, &moose_obj_params);
829  }
830  }
831  }
832  }
833 
834  // Do not change to _console, we need this printed to the stdout in all cases
835  Moose::out << _syntax_formatter->print(search_string) << std::flush;
836 }
const std::multimap< std::string, ActionInfo > & getAssociatedActions() const
Definition: Syntax.h:108
registeredMooseObjectIterator registeredObjectsEnd()
Access to registered object iterator (end)
Definition: Factory.h:310
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:74
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:275
std::map< std::string, paramsPtr >::iterator registeredMooseObjectIterator
alias for registered Object iterator
Definition: Factory.h:137
std::string _action
Definition: Syntax.h:31
bool verifyMooseObjectTask(const std::string &base, const std::string &task) const
Definition: Syntax.C:231
std::unique_ptr< SyntaxTree > _syntax_formatter
Object for holding the syntax parse tree.
Definition: Parser.h:278
registeredMooseObjectIterator registeredObjectsBegin()
Access to registered object iterator (begin)
Definition: Factory.h:305
std::string getTaskName(const std::string &action)
Definition: ActionFactory.C:95
std::string _task
Definition: Syntax.h:32
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:269
const std::vector< std::string > & getBuildableTypes() const
Returns the list of buildable types as a std::vector<std::string>
ActionFactory & _action_factory
The Factory that builds actions.
Definition: Parser.h:273
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 634 of file Parser.C.

Referenced by MooseApp::setupOptions().

635 {
636  std::vector<std::pair<std::string, Syntax::ActionInfo>> all_names;
637 
638  for (const auto & iter : _syntax.getAssociatedTypes())
639  root.addSyntaxType(iter.first, iter.second);
640 
641  for (const auto & iter : _syntax.getAssociatedActions())
642  {
643  Syntax::ActionInfo act_info = iter.second;
649  if (act_info._task == "")
650  act_info._task = _action_factory.getTaskName(act_info._action);
651 
652  all_names.push_back(std::make_pair(iter.first, act_info));
653  }
654 
655  for (const auto & act_names : all_names)
656  {
657  const auto & act_info = act_names.second;
658  const std::string & action = act_info._action;
659  const std::string & task = act_info._task;
660  const std::string act_name = act_names.first;
661  InputParameters action_obj_params = _action_factory.getValidParams(action);
662  bool params_added = root.addParameters("",
663  act_name,
664  false,
665  action,
666  true,
667  &action_obj_params,
668  _syntax.getLineInfo(act_name, action, ""),
669  "");
670 
671  if (params_added)
672  {
673  auto tasks = _action_factory.getTasksByAction(action);
674  for (auto & t : tasks)
675  {
676  auto info = _action_factory.getLineInfo(action, t);
677  root.addActionTask(act_name, action, t, info);
678  }
679  }
680 
686  if (action_obj_params.have_parameter<bool>("isObjectAction") &&
687  action_obj_params.get<bool>("isObjectAction"))
688  {
690  moose_obj != _factory.registeredObjectsEnd();
691  ++moose_obj)
692  {
693  InputParameters moose_obj_params = (moose_obj->second)();
694  // Now that we know that this is a MooseObjectAction we need to see if it has been
695  // restricted
696  // in any way by the user.
697  const std::vector<std::string> & buildable_types = action_obj_params.getBuildableTypes();
698 
699  // See if the current Moose Object syntax belongs under this Action's block
700  if ((buildable_types.empty() || // Not restricted
701  std::find(buildable_types.begin(), buildable_types.end(), moose_obj->first) !=
702  buildable_types.end()) && // Restricted but found
703  moose_obj_params.have_parameter<std::string>("_moose_base") && // Has a registered base
704  _syntax.verifyMooseObjectTask(moose_obj_params.get<std::string>("_moose_base"),
705  task) && // and that base is associated
706  action_obj_params.mooseObjectSyntaxVisibility()) // and the Action says it's visible
707  {
708  std::string name;
709  size_t pos = 0;
710  bool is_action_params = false;
711  bool is_type = false;
712  if (act_name[act_name.size() - 1] == '*')
713  {
714  pos = act_name.size();
715 
716  if (!action_obj_params.collapseSyntaxNesting())
717  name = act_name.substr(0, pos - 1) + moose_obj->first;
718  else
719  {
720  name = act_name.substr(0, pos - 1) + "/<type>/" + moose_obj->first;
721  is_action_params = true;
722  }
723  }
724  else
725  {
726  name = act_name + "/<type>/" + moose_obj->first;
727  is_type = true;
728  }
729 
730  moose_obj_params.set<std::string>("type") = moose_obj->first;
731 
732  auto lineinfo = _factory.getLineInfo(moose_obj->first);
733  std::string classname = _factory.associatedClassName(moose_obj->first);
734  root.addParameters(act_name,
735  name,
736  is_type,
737  moose_obj->first,
738  is_action_params,
739  &moose_obj_params,
740  lineinfo,
741  classname);
742  }
743  }
744  }
745  }
746  root.addGlobal();
747 }
FileLineInfo getLineInfo(const std::string &name) const
Gets file and line information where an object was initially registered.
Definition: Factory.C:136
const std::multimap< std::string, ActionInfo > & getAssociatedActions() const
Definition: Syntax.h:108
registeredMooseObjectIterator registeredObjectsEnd()
Access to registered object iterator (end)
Definition: Factory.h:310
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:74
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:252
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
std::string associatedClassName(const std::string &name) const
Get the associated class name for an object name.
Definition: Factory.C:148
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:275
std::map< std::string, paramsPtr >::iterator registeredMooseObjectIterator
alias for registered Object iterator
Definition: Factory.h:137
std::string _action
Definition: Syntax.h:31
bool verifyMooseObjectTask(const std::string &base, const std::string &task) const
Definition: Syntax.C:231
registeredMooseObjectIterator registeredObjectsBegin()
Access to registered object iterator (begin)
Definition: Factory.h:305
std::string getTaskName(const std::string &action)
Definition: ActionFactory.C:95
std::string _task
Definition: Syntax.h:32
const std::multimap< std::string, std::string > & getAssociatedTypes() const
Get a multimap of registered associations of syntax with type.
Definition: Syntax.h:80
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:269
const std::vector< std::string > & getBuildableTypes() const
Returns the list of buildable types as a std::vector<std::string>
ActionFactory & _action_factory
The Factory that builds actions.
Definition: Parser.h:273
FileLineInfo getLineInfo(const std::string &name, const std::string &task) const
Gets file and line information where an action was registered.
std::set< std::string > getTasksByAction(const std::string &action) const
void Parser::errorCheck ( const Parallel::Communicator &  comm,
bool  warn_unused,
bool  err_unused 
)

Definition at line 573 of file Parser.C.

Referenced by MooseApp::errorCheck().

574 {
575  // this if guard is important in case the simulation was not configured via parsed input text -
576  // e.g. configured programatically.
577  if (!_root || !_cli_root)
578  return;
579 
581  UnusedWalker uwcli("CLI_ARG", _extracted_vars, *this);
582 
583  _root->walk(&uw);
584  _cli_root->walk(&uwcli);
585 
586  auto cli = _app.commandLine();
587  if (warn_unused)
588  {
589  for (auto arg : cli->unused(comm))
590  _warnmsg +=
591  errormsg("CLI_ARG", nullptr, "unused command line parameter '", cli->argv()[arg], "'") +
592  "\n";
593  for (auto & msg : uwcli.errors)
594  _warnmsg += msg + "\n";
595  for (auto & msg : uw.errors)
596  _warnmsg += msg + "\n";
597  }
598  else if (err_unused)
599  {
600  for (auto arg : cli->unused(comm))
601  _errmsg +=
602  errormsg("CLI_ARG", nullptr, "unused command line parameter '", cli->argv()[arg], "'") +
603  "\n";
604  for (auto & msg : uwcli.errors)
605  _errmsg += msg + "\n";
606  for (auto & msg : uw.errors)
607  _errmsg += msg + "\n";
608  }
609 
610  if (_warnmsg.size() > 0)
612  if (_errmsg.size() > 0)
614 }
MooseApp & _app
The MooseApp this Parser is part of.
Definition: Parser.h:267
std::string _warnmsg
Definition: Parser.h:297
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:281
std::unique_ptr< hit::Node > _cli_root
Definition: Parser.h:262
std::shared_ptr< CommandLine > commandLine()
Get the command line.
Definition: MooseApp.h:265
std::string _errmsg
Definition: Parser.h:296
std::set< std::string > _extracted_vars
The set of all variables extracted from the input file.
Definition: Parser.h:284
std::string errormsg(std::string, hit::Node *)
Definition: Parser.h:39
std::unique_ptr< hit::Node > _root
Definition: Parser.h:263
MPI_Comm comm
void mooseWarning(Args &&...args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:194
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 926 of file Parser.C.

Referenced by walkRaw().

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

Return the filename that was parsed.

Definition at line 293 of file Parser.C.

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

294 {
295  if (!stripLeadingPath)
296  return _input_filename;
297 
298  std::string filename;
299  size_t pos = _input_filename.find_last_of('/');
300  if (pos != std::string::npos)
301  filename = _input_filename.substr(pos + 1);
302  else
303  filename = _input_filename;
304 
305  return filename;
306 }
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:281
std::string Parser::getSyntaxByAction ( const std::string &  action,
const std::string &  task 
)
inline

Retrieve the Syntax associated with the passed Action and task.

Definition at line 134 of file Parser.h.

135  {
136  return _syntax.getSyntaxByAction(action, task);
137  }
Syntax & _syntax
Reference to an object that defines input file syntax.
Definition: Parser.h:275
std::string getSyntaxByAction(const std::string &action, const std::string &task)
Definition: Syntax.C:143
std::string Parser::hitCLIFilter ( std::string  appname,
int  argc,
char *  argv[] 
)
private

Definition at line 392 of file Parser.C.

Referenced by parse().

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

Creates a syntax formatter for printing.

Definition at line 617 of file Parser.C.

Referenced by MooseApp::setupOptions().

618 {
619  switch (type)
620  {
621  case INPUT_FILE:
622  _syntax_formatter = libmesh_make_unique<InputFileFormatter>(dump_mode);
623  break;
624  case YAML:
625  _syntax_formatter = libmesh_make_unique<YAMLFormatter>(dump_mode);
626  break;
627  default:
628  mooseError("Unrecognized Syntax Formatter requested");
629  break;
630  }
631 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::unique_ptr< SyntaxTree > _syntax_formatter
Object for holding the syntax parse tree.
Definition: Parser.h:278
MatType type
std::vector< std::string > Parser::listValidParams ( std::string &  section_name)

Definition at line 165 of file Parser.C.

166 {
167  bool dummy;
168  std::string registered_identifier = _syntax.isAssociated(section_name, &dummy);
169  auto iters = _syntax.getActions(registered_identifier);
170 
171  std::vector<std::string> paramlist;
172  for (auto it = iters.first; it != iters.second; ++it)
173  {
174  auto params = _action_factory.getValidParams(it->second._action);
175  for (const auto & it : params)
176  paramlist.push_back(it.first);
177  }
178  return paramlist;
179 }
InputParameters getValidParams(const std::string &name)
Definition: ActionFactory.C:74
Syntax & _syntax
Reference to an object that defines input file syntax.
Definition: Parser.h:275
std::string isAssociated(const std::string &real_id, bool *is_parent)
Method for determining whether a piece of syntax is associated with an Action TODO: I need a better n...
Definition: Syntax.C:159
std::pair< std::multimap< std::string, ActionInfo >::iterator, std::multimap< std::string, ActionInfo >::iterator > getActions(const std::string &name)
Definition: Syntax.C:225
ActionFactory & _action_factory
The Factory that builds actions.
Definition: Parser.h:273
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 481 of file Parser.C.

Referenced by MooseApp::setupOptions().

482 {
483  // Save the filename
484  char abspath[PATH_MAX + 1];
485  realpath(input_filename.c_str(), abspath);
486  _input_filename = std::string(abspath);
487 
488  // vector for initializing active blocks
489  std::vector<std::string> all = {"__all__"};
490 
491  MooseUtils::checkFileReadable(_input_filename, true);
492 
493  std::ifstream f(_input_filename);
494  std::string input((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
495 
496  try
497  {
498  _root.reset(hit::parse(_input_filename, input));
499 
500  int argc = _app.commandLine()->argc();
501  char ** argv = _app.commandLine()->argv();
502  auto cli_input = hitCLIFilter(_app.name(), argc, argv);
503 
504  _cli_root.reset(hit::parse("CLI_ARGS", cli_input));
505  hit::explode(_cli_root.get());
506  hit::explode(_root.get());
507  hit::merge(_cli_root.get(), _root.get());
508  }
509  catch (hit::ParseError & err)
510  {
511  mooseError(err.what());
512  }
513 
514  // expand ${bla} parameter values and mark/include variables used in expansions as "used". This
515  // MUST occur before parameter extraction - otherwise parameters will get wrong values.
516  ExpandWalker exw(_input_filename);
517  _root->walk(&exw);
518  for (auto & var : exw.used)
519  _extracted_vars.insert(var);
520  for (auto & msg : exw.errors)
521  _errmsg += msg + "\n";
522 
523  // do as much error checking as early as possible so that errors are more useful instead
524  // of surprising and disconnected from what caused them.
525  DupParamWalker dw(_input_filename);
526  BadActiveWalker bw(_input_filename);
527  _root->walk(&dw, hit::NodeType::Field);
528  _root->walk(&bw, hit::NodeType::Section);
529  for (auto & msg : dw.errors)
530  _errmsg += msg + "\n";
531  for (auto & msg : bw.errors)
532  _errmsg += msg + "\n";
533 
534  if (_errmsg.size() > 0)
536 
537  // There are a few order dependent actions that have to be built first in
538  // order for the parser and application to function properly:
539  //
540  // SetupDebugAction: This action can contain an option for monitoring the parser progress. It must
541  // be parsed first to capture all of the parsing output.
542  //
543  // GlobalParamsAction: This action is checked during the parameter extraction routines of all
544  // subsequent blocks. It must be parsed early since it must exist during
545  // subsequent parameter extraction.
546  //
547  // DynamicObjectRegistration: This action must be built before any MooseObjectActions are built.
548  // This is because we retrieve valid parameters from the Factory
549  // during parse time. Objects must be registered before
550  // validParameters can be retrieved.
551  _secs_need_first = {
552  _syntax.getSyntaxByAction("SetupDebugAction", "setup_debug"),
553  _syntax.getSyntaxByAction("GlobalParamsAction", "set_global_params"),
554  _syntax.getSyntaxByAction("DynamicObjectRegistrationAction", "dynamic_object_registration"),
555  };
556 
557  // walk all the sections extracting paramters from each into InputParameters objects
558  for (auto & sec : _secs_need_first)
559  {
560  auto n = _root->find(sec);
561  if (n)
562  walkRaw(n->parent()->fullpath(), n->path(), n);
563  }
564  _root->walk(this, hit::NodeType::Section);
565 }
MooseApp & _app
The MooseApp this Parser is part of.
Definition: Parser.h:267
void walkRaw(std::string fullpath, std::string nodepath, hit::Node *n)
Definition: Parser.C:309
std::vector< std::string > _secs_need_first
Definition: Parser.h:264
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
Syntax & _syntax
Reference to an object that defines input file syntax.
Definition: Parser.h:275
const std::string & name() const
Get the name of the object.
Definition: MooseApp.h:70
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:281
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:121
std::unique_ptr< hit::Node > _cli_root
Definition: Parser.h:262
std::string hitCLIFilter(std::string appname, int argc, char *argv[])
Definition: Parser.C:392
std::shared_ptr< CommandLine > commandLine()
Get the command line.
Definition: MooseApp.h:265
std::string getSyntaxByAction(const std::string &action, const std::string &task)
Definition: Syntax.C:143
std::string _errmsg
Definition: Parser.h:296
std::set< std::string > _extracted_vars
The set of all variables extracted from the input file.
Definition: Parser.h:284
PetscInt n
std::unique_ptr< hit::Node > _root
Definition: Parser.h:263
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 1405 of file Parser.C.

1410 {
1411  // Get the full string assigned to the variable full_name
1412  std::string buffer = _root->param<std::string>(full_name);
1413 
1414  // split vector at delim ;
1415  // NOTE: the substrings are _not_ of type T yet
1416  std::vector<std::string> first_tokenized_vector;
1417  MooseUtils::tokenize(buffer, first_tokenized_vector, 1, ";");
1418  param->set().resize(first_tokenized_vector.size());
1419 
1420  for (unsigned j = 0; j < first_tokenized_vector.size(); ++j)
1421  if (!MooseUtils::tokenizeAndConvert<T>(first_tokenized_vector[j], param->set()[j]))
1422  mooseError("Reading parameter ", short_name, " failed.");
1423 
1424  if (in_global)
1425  {
1426  global_block->remove(short_name);
1427  global_block->setDoubleIndexParam<T>(short_name).resize(first_tokenized_vector.size());
1428  for (unsigned j = 0; j < first_tokenized_vector.size(); ++j)
1429  {
1430  global_block->setDoubleIndexParam<T>(short_name)[j].resize(param->get()[j].size());
1431  for (unsigned int i = 0; i < param->get()[j].size(); ++i)
1432  global_block->setDoubleIndexParam<T>(short_name)[j][i] = param->get()[j][i];
1433  }
1434  }
1435 }
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:350
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::vector< std::vector< T > > & setDoubleIndexParam(const std::string &name)
std::unique_ptr< hit::Node > _root
Definition: Parser.h:263
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...
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 1298 of file Parser.C.

1304 {
1305  std::string prefix;
1306  std::string postfix = _root->param<std::string>(full_name);
1307  size_t pos = _input_filename.find_last_of('/');
1308  if (pos != std::string::npos && postfix[0] != '/' && !postfix.empty())
1309  prefix = _input_filename.substr(0, pos + 1);
1310 
1311  params.set<std::string>("_raw_" + short_name) = postfix;
1312  param->set() = prefix + postfix;
1313 
1314  if (in_global)
1315  {
1316  global_block->remove(short_name);
1317  global_block->setScalarParam<T>(short_name) = param->get();
1318  }
1319 }
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:281
T & setScalarParam(const std::string &name)
std::unique_ptr< hit::Node > _root
Definition: Parser.h:263
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...
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 1439 of file Parser.C.

Referenced by setScalarParameter().

1444 {
1445  auto vec = _root->param<std::vector<double>>(full_name);
1446 
1447  if (vec.size() != LIBMESH_DIM)
1448  mooseError(std::string("Error in Scalar Component parameter ") + full_name + ": size is ",
1449  vec.size(),
1450  ", should be ",
1451  LIBMESH_DIM);
1452 
1453  T value;
1454  for (unsigned int i = 0; i < vec.size(); ++i)
1455  value(i) = Real(vec[i]);
1456 
1457  param->set() = value;
1458  if (in_global)
1459  {
1460  global_block->remove(short_name);
1461  global_block->setScalarParam<T>(short_name) = value;
1462  }
1463 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
T & setScalarParam(const std::string &name)
std::unique_ptr< hit::Node > _root
Definition: Parser.h:263
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...
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 1234 of file Parser.C.

1239 {
1240 
1241  try
1242  {
1243  param->set() = _root->param<Base>(full_name);
1244  }
1245  catch (hit::Error & err)
1246  {
1247  // handle the case where the user put a number inside quotes - we really shouldn't allow this,
1248  // but "backwards compatibility" :-(
1249  auto & t = typeid(T);
1250  if (t == typeid(int) || t == typeid(unsigned int) || t == typeid(SubdomainID) ||
1251  t == typeid(BoundaryID))
1252  {
1253  try
1254  {
1255  auto v = std::stoi(_root->param<std::string>(full_name));
1256  param->set() = *reinterpret_cast<T *>(&v);
1257  }
1258  catch (...)
1259  {
1261  _root->find(full_name),
1262  "invalid integer syntax for parameter: ",
1263  full_name,
1264  "=",
1265  _root->param<std::string>(full_name)));
1266  }
1267  }
1268  else if (t == typeid(double))
1269  {
1270  try
1271  {
1272  auto v = std::stod(_root->param<std::string>(full_name));
1273  param->set() = *reinterpret_cast<T *>(&v);
1274  }
1275  catch (...)
1276  {
1278  _root->find(full_name),
1279  "invalid float syntax for parameter: ",
1280  full_name,
1281  "=",
1282  _root->param<std::string>(full_name)));
1283  }
1284  }
1285  else
1286  throw;
1287  }
1288 
1289  if (in_global)
1290  {
1291  global_block->remove(short_name);
1292  global_block->setScalarParam<T>(short_name) = param->get();
1293  }
1294 }
subdomain_id_type SubdomainID
Definition: MooseTypes.h:77
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::string _input_filename
The input file name that is used for parameter extraction.
Definition: Parser.h:281
T & setScalarParam(const std::string &name)
std::string errormsg(std::string, hit::Node *)
Definition: Parser.h:39
std::unique_ptr< hit::Node > _root
Definition: Parser.h:263
boundary_id_type BoundaryID
Definition: MooseTypes.h:75
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...
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
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
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
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
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
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
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 1503 of file Parser.C.

1509 {
1510  setScalarComponentParameter(full_name, short_name, param, in_global, global_block);
1511 }
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:1439
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 1515 of file Parser.C.

1520 {
1521  setScalarComponentParameter(full_name, short_name, param, in_global, global_block);
1522 }
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:1439
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 1526 of file Parser.C.

1531 {
1532  MooseEnum current_param = param->get();
1533 
1534  std::string value = _root->param<std::string>(full_name);
1535 
1536  param->set() = value;
1537  if (in_global)
1538  {
1539  global_block->remove(short_name);
1540  global_block->setScalarParam<MooseEnum>(short_name) = current_param;
1541  }
1542 }
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:37
std::unique_ptr< hit::Node > _root
Definition: Parser.h:263
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...
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 1546 of file Parser.C.

1552 {
1553  MultiMooseEnum current_param = param->get();
1554 
1555  auto vec = _root->param<std::vector<std::string>>(full_name);
1556 
1557  std::string raw_values;
1558  for (unsigned int i = 0; i < vec.size(); ++i)
1559  raw_values += ' ' + vec[i];
1560 
1561  param->set() = raw_values;
1562 
1563  if (in_global)
1564  {
1565  global_block->remove(short_name);
1566  global_block->setScalarParam<MultiMooseEnum>(short_name) = current_param;
1567  }
1568 }
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:263
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...
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 1572 of file Parser.C.

1578 {
1579  auto vec = _root->param<std::vector<double>>(full_name);
1580  if (vec.size() != LIBMESH_DIM * LIBMESH_DIM)
1581  mooseError(std::string("Error in RealTensorValue parameter ") + full_name + ": size is ",
1582  vec.size(),
1583  ", should be ",
1584  LIBMESH_DIM * LIBMESH_DIM);
1585 
1586  RealTensorValue value;
1587  for (int i = 0; i < LIBMESH_DIM; ++i)
1588  for (int j = 0; j < LIBMESH_DIM; ++j)
1589  value(i, j) = Real(vec[i * LIBMESH_DIM + j]);
1590 
1591  param->set() = value;
1592  if (in_global)
1593  {
1594  global_block->remove(short_name);
1595  global_block->setScalarParam<RealTensorValue>(short_name) = value;
1596  }
1597 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
T & setScalarParam(const std::string &name)
std::unique_ptr< hit::Node > _root
Definition: Parser.h:263
TensorValue< Real > RealTensorValue
Definition: Assembly.h:45
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...
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 1602 of file Parser.C.

1608 {
1609  PostprocessorName pps_name = _root->param<std::string>(full_name);
1610  param->set() = pps_name;
1611 
1612  Real real_value = -std::numeric_limits<Real>::max();
1613  std::istringstream ss(pps_name);
1614 
1615  if (ss >> real_value && ss.eof())
1616  _current_params->setDefaultPostprocessorValue(short_name, real_value);
1617 
1618  if (in_global)
1619  {
1620  global_block->remove(short_name);
1621  global_block->setScalarParam<PostprocessorName>(short_name) = pps_name;
1622  }
1623 }
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:263
InputParameters * _current_params
The current parameter object for which parameters are being extracted.
Definition: Parser.h:290
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...
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 1323 of file Parser.C.

1328 {
1329  setScalarParameter<T, Base>(full_name, short_name, param, in_global, global_block);
1330 
1331  // If this is a range checked param, we need to make sure that the value falls within the
1332  // requested range
1333  mooseAssert(_current_params, "Current params is nullptr");
1334 
1335  _current_params->rangeCheck<T, UP_T>(full_name, short_name, param, *_current_error_stream);
1336 }
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:293
InputParameters * _current_params
The current parameter object for which parameters are being extracted.
Definition: Parser.h:290
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 1467 of file Parser.C.

Referenced by setVectorParameter().

1472 {
1473  auto vec = _root->param<std::vector<double>>(full_name);
1474 
1475  if (vec.size() % LIBMESH_DIM)
1476  mooseError(std::string("Error in Vector Component parameter ") + full_name + ": size is ",
1477  vec.size(),
1478  ", should be a multiple of ",
1479  LIBMESH_DIM);
1480 
1481  std::vector<T> values;
1482  for (unsigned int i = 0; i < vec.size() / LIBMESH_DIM; ++i)
1483  {
1484  T value;
1485  for (int j = 0; j < LIBMESH_DIM; ++j)
1486  value(j) = Real(vec[i * LIBMESH_DIM + j]);
1487  values.push_back(value);
1488  }
1489 
1490  param->set() = values;
1491 
1492  if (in_global)
1493  {
1494  global_block->remove(short_name);
1495  global_block->setVectorParam<T>(short_name).resize(vec.size(), values[0]);
1496  for (unsigned int i = 0; i < vec.size() / LIBMESH_DIM; ++i)
1497  global_block->setVectorParam<T>(short_name)[i] = values[0];
1498  }
1499 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::vector< T > & setVectorParam(const std::string &name)
std::unique_ptr< hit::Node > _root
Definition: Parser.h:263
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...
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 1367 of file Parser.C.

1373 {
1374  std::vector<T> vec;
1375  std::vector<std::string> rawvec;
1376  if (_root->find(full_name))
1377  {
1378  auto tmp = _root->param<std::vector<std::string>>(full_name);
1379  for (auto val : tmp)
1380  {
1381  std::string prefix;
1382  std::string postfix = val;
1383  size_t pos = _input_filename.find_last_of('/');
1384  if (pos != std::string::npos && postfix[0] != '/')
1385  prefix = _input_filename.substr(0, pos + 1);
1386  rawvec.push_back(postfix);
1387  vec.push_back(prefix + postfix);
1388  }
1389  }
1390 
1391  params.set<std::vector<std::string>>("_raw_" + short_name) = rawvec;
1392  param->set() = vec;
1393 
1394  if (in_global)
1395  {
1396  global_block->remove(short_name);
1397  global_block->setVectorParam<T>(short_name).resize(param->get().size());
1398  for (unsigned int i = 0; i < vec.size(); ++i)
1399  global_block->setVectorParam<T>(short_name)[i] = param->get()[i];
1400  }
1401 }
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
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:281
std::unique_ptr< hit::Node > _root
Definition: Parser.h:263
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...
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 1340 of file Parser.C.

1345 {
1346  std::vector<T> vec;
1347  if (_root->find(full_name))
1348  {
1349  auto tmp = _root->param<std::vector<Base>>(full_name);
1350  for (auto val : tmp)
1351  vec.push_back(val);
1352  }
1353 
1354  param->set() = vec;
1355 
1356  if (in_global)
1357  {
1358  global_block->remove(short_name);
1359  global_block->setVectorParam<T>(short_name).resize(param->get().size());
1360  for (unsigned int i = 0; i < vec.size(); ++i)
1361  global_block->setVectorParam<T>(short_name)[i] = param->get()[i];
1362  }
1363 }
std::vector< T > & setVectorParam(const std::string &name)
std::unique_ptr< hit::Node > _root
Definition: Parser.h:263
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...
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
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
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
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
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 1627 of file Parser.C.

1633 {
1634  setVectorComponentParameter(full_name, short_name, param, in_global, global_block);
1635 }
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:1467
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 1639 of file Parser.C.

1644 {
1645  setVectorComponentParameter(full_name, short_name, param, in_global, global_block);
1646 }
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:1467
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 1650 of file Parser.C.

1656 {
1657  std::vector<MooseEnum> enum_values = param->get();
1658  std::vector<std::string> values(enum_values.size());
1659  for (unsigned int i = 0; i < values.size(); ++i)
1660  values[i] = static_cast<std::string>(enum_values[i]);
1661 
1666  std::vector<std::string> vec;
1667  if (_root->find(full_name))
1668  {
1669  vec = _root->param<std::vector<std::string>>(full_name);
1670  param->set().resize(vec.size(), enum_values[0]);
1671  }
1672 
1673  for (unsigned int i = 0; i < vec.size(); ++i)
1674  param->set()[i] = vec[i];
1675 
1676  if (in_global)
1677  {
1678  global_block->remove(short_name);
1679  global_block->setVectorParam<MooseEnum>(short_name).resize(vec.size(), enum_values[0]);
1680  for (unsigned int i = 0; i < vec.size(); ++i)
1681  global_block->setVectorParam<MooseEnum>(short_name)[i] = values[0];
1682  }
1683 }
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:37
std::unique_ptr< hit::Node > _root
Definition: Parser.h:263
void remove(const std::string &name)
This function is here to remove parameters of a type so that global parameters can potentially use th...
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 1691 of file Parser.C.

1697 {
1698  auto vec = _root->param<std::vector<std::string>>(full_name);
1699  std::vector<VariableName> var_names(vec.size());
1700 
1701  bool has_var_names = false;
1702  for (unsigned int i = 0; i < vec.size(); ++i)
1703  {
1704  VariableName var_name = vec[i];
1705 
1706  Real real_value;
1707  std::istringstream ss(var_name);
1708 
1709  // If we are able to convert this value into a Real, then set a default coupled value
1710  if (ss >> real_value && ss.eof())
1711  /* FIXME: the real_value is assigned to defaultCoupledValue overriding the value assigned
1712  * before. Currently there is no functionality to separately assign the correct
1713  * "real_value[i]" in InputParameters.*/
1714  _current_params->defaultCoupledValue(short_name, real_value);
1715  else
1716  {
1717  var_names[i] = var_name;
1718  has_var_names = true;
1719  }
1720  }
1721 
1722  if (has_var_names)
1723  {
1724  param->set().resize(vec.size());
1725 
1726  for (unsigned int i = 0; i < vec.size(); ++i)
1727  if (var_names[i] == "")
1728  mooseError("MOOSE does not currently support a coupled vector where some parameters are "
1729  "reals and others are variables");
1730  else
1731  param->set()[i] = var_names[i];
1732  }
1733 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
Real defaultCoupledValue(const std::string &coupling_name) const
Get the default value for an optionally coupled variable.
std::unique_ptr< hit::Node > _root
Definition: Parser.h:263
InputParameters * _current_params
The current parameter object for which parameters are being extracted.
Definition: Parser.h:290
void Parser::walk ( const std::string &  fullpath,
const std::string &  nodepath,
hit::Node *  n 
)

Definition at line 382 of file Parser.C.

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

Definition at line 309 of file Parser.C.

Referenced by parse(), and walk().

310 {
311  InputParameters active_list_params = validParams<Action>();
313 
314  std::string section_name = n->fullpath();
315  std::string curr_identifier = n->fullpath();
316 
317  // Before we retrieve any actions or build any objects, make sure that the section they are in
318  // is active
319  if (!isSectionActive(curr_identifier, _root.get()))
320  return;
321 
322  // Extract the block parameters before constructing the action
323  // There may be more than one Action registered for a given section in which case we need to
324  // build them all
325  bool is_parent;
326  std::string registered_identifier = _syntax.isAssociated(section_name, &is_parent);
327 
328  // We need to retrieve a list of Actions associated with the current identifier
329  std::pair<std::multimap<std::string, Syntax::ActionInfo>::iterator,
330  std::multimap<std::string, Syntax::ActionInfo>::iterator>
331  iters = _syntax.getActions(registered_identifier);
332 
333  if (iters.first == iters.second)
334  {
336  n,
337  "section '",
338  curr_identifier,
339  "' does not have an associated \"Action\".\nDid you misspell it?"));
340  }
341 
342  for (auto it = iters.first; it != iters.second; ++it)
343  {
344  if (is_parent)
345  continue;
346  if (_syntax.isDeprecatedSyntax(registered_identifier))
348  errormsg(getFileName(), n, "\"[", registered_identifier, "]\" is deprecated."));
349 
350  params = _action_factory.getValidParams(it->second._action);
351 
352  params.set<ActionWarehouse *>("awh") = &_action_wh;
353 
354  extractParams(curr_identifier, params);
355 
356  // Add the parsed syntax to the parameters object for consumption by the Action
357  params.set<std::string>("task") = it->second._task;
358  params.set<std::string>("registered_identifier") = registered_identifier;
359  params.addPrivateParam<std::string>("parser_syntax", curr_identifier);
360 
361  // Create the Action
362  std::shared_ptr<Action> action_obj =
363  _action_factory.create(it->second._action, MooseUtils::shortName(curr_identifier), params);
364 
365  // extract the MooseObject params if necessary
366  std::shared_ptr<MooseObjectAction> object_action =
367  std::dynamic_pointer_cast<MooseObjectAction>(action_obj);
368  if (object_action)
369  {
370  extractParams(curr_identifier, object_action->getObjectParams());
371  object_action->getObjectParams()
372  .set<std::vector<std::string>>("control_tags")
373  .push_back(MooseUtils::baseName(curr_identifier));
374  }
375 
376  // add it to the warehouse
377  _action_wh.addActionBlock(action_obj);
378  }
379 }
InputParameters validParams< EmptyAction >()
Definition: EmptyAction.C:19
InputParameters getValidParams(const std::string &name)
Definition: ActionFactory.C:74
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
void mooseDeprecated(Args &&...args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition: MooseError.h:202
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.
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:926
Syntax & _syntax
Reference to an object that defines input file syntax.
Definition: Parser.h:275
bool isSectionActive(std::string path, hit::Node *root)
Definition: Parser.C:72
std::string shortName(const std::string &name)
Function for stripping name after the file / in parser block.
Definition: MooseUtils.C:325
std::string getFileName(bool stripLeadingPath=true) const
Return the filename that was parsed.
Definition: Parser.C:293
std::string isAssociated(const std::string &real_id, bool *is_parent)
Method for determining whether a piece of syntax is associated with an Action TODO: I need a better n...
Definition: Syntax.C:159
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:137
std::pair< std::multimap< std::string, ActionInfo >::iterator, std::multimap< std::string, ActionInfo >::iterator > getActions(const std::string &name)
Definition: Syntax.C:225
ActionWarehouse & _action_wh
Action warehouse that will be filled by actions.
Definition: Parser.h:271
std::string baseName(const std::string &name)
Function for string the information before the final / in a parser block.
Definition: MooseUtils.C:331
PetscInt n
std::string errormsg(std::string, hit::Node *)
Definition: Parser.h:39
std::unique_ptr< hit::Node > _root
Definition: Parser.h:263
std::shared_ptr< Action > create(const std::string &action, const std::string &action_name, InputParameters parameters)
Definition: ActionFactory.C:26
ActionFactory & _action_factory
The Factory that builds actions.
Definition: Parser.h:273
InputParameters validParams< Action >()
Definition: Action.C:23

Member Data Documentation

ActionFactory& Parser::_action_factory
protected

The Factory that builds actions.

Definition at line 273 of file Parser.h.

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

ActionWarehouse& Parser::_action_wh
protected

Action warehouse that will be filled by actions.

Definition at line 271 of file Parser.h.

Referenced by extractParams(), and walkRaw().

MooseApp& Parser::_app
protected

The MooseApp this Parser is part of.

Definition at line 267 of file Parser.h.

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

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

Definition at line 262 of file Parser.h.

Referenced by errorCheck(), and parse().

const ConsoleStream ConsoleStreamInterface::_console
inherited

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

Definition at line 37 of file ConsoleStreamInterface.h.

Referenced by IterationAdaptiveDT::acceptStep(), CreateProblemAction::act(), SetupRecoverFileBaseAction::act(), Adaptivity::adaptMesh(), FEProblemBase::adaptMesh(), FEProblemBase::advanceMultiApps(), SimplePredictor::apply(), FEProblemBase::backupMultiApps(), FEProblemBase::checkProblemIntegrity(), IterationAdaptiveDT::computeAdaptiveDT(), Transient::computeConstrainedDT(), NonlinearSystemBase::computeDamping(), IterationAdaptiveDT::computeDT(), IterationAdaptiveDT::computeFailedDT(), IterationAdaptiveDT::computeInterpolationDT(), FEProblemBase::computeResidualType(), IterationAdaptiveDT::constrainStep(), TimeStepper::constrainStep(), AB2PredictorCorrector::converged(), FEProblemBase::execMultiApps(), FEProblemBase::execMultiAppTransfers(), MultiAppPostprocessorTransfer::execute(), MultiAppPostprocessorInterpolationTransfer::execute(), MultiAppVariableValueSamplePostprocessorTransfer::execute(), MultiAppNearestNodeTransfer::execute(), MultiAppPostprocessorToAuxScalarTransfer::execute(), MultiAppScalarToAuxScalarTransfer::execute(), MultiAppVariableValueSampleTransfer::execute(), MultiAppUserObjectTransfer::execute(), MultiAppInterpolationTransfer::execute(), MultiAppMeshFunctionTransfer::execute(), MultiAppProjectionTransfer::execute(), MultiAppCopyTransfer::execute(), Steady::execute(), MultiAppDTKUserObjectTransfer::execute(), ActionWarehouse::executeActionsWithAction(), ActionWarehouse::executeAllActions(), 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(), DOFMapOutput::output(), VariableResidualNormsDebugOutput::output(), Console::output(), ControlOutput::outputActiveObjects(), ControlOutput::outputChangedControls(), ControlOutput::outputControls(), Console::outputInput(), Console::outputPostprocessors(), Console::outputScalarVariables(), Console::outputSystemInformation(), FEProblemBase::possiblyRebuildGeomSearchPatches(), EigenExecutionerBase::postExecute(), ActionWarehouse::printActionDependencySets(), EigenExecutionerBase::printEigenvalue(), MaterialPropertyDebugOutput::printMaterialMap(), SolutionTimeAdaptiveDT::rejectStep(), DT2::rejectStep(), FEProblemBase::restoreMultiApps(), SimplePredictor::shouldApply(), NonlinearSystem::solve(), LStableDirk2::solve(), LStableDirk3::solve(), ImplicitMidpoint::solve(), ExplicitTVDRK2::solve(), AStableDirk4::solve(), LStableDirk4::solve(), ExplicitRK2::solve(), TransientMultiApp::solveStep(), Transient::solveStep(), DT2::step(), AB2PredictorCorrector::step(), NonlinearEigen::takeStep(), FEProblemBase::useFECache(), Console::writeTimestepInformation(), Console::writeVariableNorms(), and FEProblemBase::~FEProblemBase().

std::ostringstream* Parser::_current_error_stream
protected

The current stream object used for capturing errors during extraction.

Definition at line 293 of file Parser.h.

Referenced by extractParams(), and setScalarValueTypeParameter().

InputParameters* Parser::_current_params
protected

The current parameter object for which parameters are being extracted.

Definition at line 290 of file Parser.h.

Referenced by extractParams(), setScalarParameter(), setScalarValueTypeParameter(), and setVectorParameter().

std::string Parser::_errmsg
private

Definition at line 296 of file Parser.h.

Referenced by errorCheck(), and parse().

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

The set of all variables extracted from the input file.

Definition at line 284 of file Parser.h.

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

Factory& Parser::_factory
protected

The Factory associated with that MooseApp.

Definition at line 269 of file Parser.h.

Referenced by buildFullTree(), and buildJsonSyntaxTree().

std::string Parser::_input_filename
protected

The input file name that is used for parameter extraction.

Definition at line 281 of file Parser.h.

Referenced by errorCheck(), getFileName(), parse(), setFilePathParam(), setScalarParameter(), and setVectorFilePathParam().

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

Definition at line 264 of file Parser.h.

Referenced by parse(), and walk().

bool Parser::_sections_read
protected

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

Definition at line 287 of file Parser.h.

Syntax& Parser::_syntax
protected

Reference to an object that defines input file syntax.

Definition at line 275 of file Parser.h.

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

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

Object for holding the syntax parse tree.

Definition at line 278 of file Parser.h.

Referenced by buildFullTree(), and initSyntaxFormatter().

std::string Parser::_warnmsg
private

Definition at line 297 of file Parser.h.

Referenced by errorCheck().


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