Loading...
Searching...
No Matches
Opm::ParameterGroup Class Reference

ParameterGroup is a class that is used to provide run-time parameters. More...

`#include <ParameterGroup.hpp>`

Inheritance diagram for Opm::ParameterGroup:

## Classes

struct | ConversionFailedException
struct | NotFoundException
struct | RequirementFailedException
struct | WrongTypeException

## Public Member Functions

| ParameterGroup (const std::string &path, const ParameterGroup *parent, const bool enable_output)
std::string | getTag () const override
| This function returns a string describing the ParameterMapItem.
template<typename StringArray >
| ParameterGroup (int argc, StringArray argv, const bool verify_syntax=true, const bool enabled_output=true)
| A constructor typically used to initialize a ParameterGroup from command-line arguments.
bool | has (const std::string &name) const
| This method checks if there is something with name `name` in the parameter gropup.
template<typename T >
T | get (const std::string &name) const
| This method is used to read a parameter from the parameter group.
template<typename T , class Requirement >
T | get (const std::string &name, const Requirement &) const
template<typename T >
T | getDefault (const std::string &name, const T &default_value) const
| This method is used to read a parameter from the parameter group.
template<typename T , class Requirement >
T | getDefault (const std::string &name, const T &default_value, const Requirement &r) const
ParameterGroup | getGroup (const std::string &name) const
| This method returns the parameter group given by name, i.e.
void | disableOutput ()
| Disables the output from get, getDefault and getGroup.
void | enableOutput ()
| Enables the output from get, getDefault and getGroup.
bool | isOutputEnabled () const
| Returs true if and only if output from get, getDefault and getGroup is enabled.
void | readParam (const std::string &param_filename)
| Reads the contents of the param file specified by param_filename into this ParameterGroup.
void | writeParam (const std::string &param_filename) const
| Writes this ParameterGroup into a param file specified by param_filename.
void | writeParamToStream (std::ostream &stream) const
| Writes this ParameterGroup to a stream.
template<typename T >
void | get (const char *name, T &value, const T &default_value) const
| vki param interface - deprecated
template<typename T >
void | get (const char *name, T &value) const
| vki param interface - deprecated
bool | anyUnused () const
| Return true if any parameters are unused.
void | displayUsage (bool used_params=false) const
| Shows which parameters which are used or unused.
const std::string & | path () const
| Returns the path of the parameter group.
void | insert (const std::string &name, const std::shared_ptr< ParameterMapItem > &data)
| Insert a new item into the group.
void | insertParameter (const std::string &name, const std::string &value)
| Insert a new parameter item into the group.
const std::vector< std::string > & | unhandledArguments () const
| Unhandled arguments from command line parsing.
template<>
std::string | to_string (const bool &b)
template<>
std::string | to_string (const ParameterGroup &)
Public Member Functions inherited from Opm::ParameterMapItem
| ParameterMapItem ()
| Default constructor.
virtual | ~ParameterMapItem ()
| Destructor.
void | setUsed () const
bool | used () const

## Detailed Description

ParameterGroup is a class that is used to provide run-time parameters.

The standard use of the class is to call create it with the (int argc, char** argv) constructor (where the arguments are those given by main). This parses the command line, where each token either A) specifies a parameter (by a "param=value" token). B) specifies a param file to be read (by a "filename.param" token). After the tokens are parsed they are stored in a tree structure in the ParameterGroup object; it is worth mentioning that parameters are inherited in this tree structure. Thus, if `‘grid\_prefix’' is given a value in the root node, this value will be visible in all parts of the tree (unless the parameter is overwritten in a subtree). Applications using this ParameterGroup objects will usually write out a message for each node in the three that is used by the application; this is one way to determine valid parameters.

Parameters specified as "param=value" on the command line

To specify a parameter on the command line, you must know where in the tree the parameter resides. The syntax for specifying parameters on the command line given an application called `‘simulator’' is simulator param1=value grp/param2=value `grp''. If the same parameters are specified multiple times on the command line, only the last will be used. Thus an application named`simulator'' run with the following command simulator param=value1 param=value2 will use value2 as the value of `‘param’'.

param files

A param file consists of multiple lienes, where each line consists of "param=value". This syntax is identical to the one for parameters specified on the command line.

## Constructor & Destructor Documentation

## ParameterGroup()

template<typename StringArray >

Opm::ParameterGroup::ParameterGroup | ( | int | argc,
|  | StringArray | argv,
|  | const bool | verify_syntax = `true`,
|  | const bool | enabled_output = `true`
| ) |  |

A constructor typically used to initialize a ParameterGroup from command-line arguments.

It is required that argv[0] is the program name, while if 0 < i < argc, then argv[i] is either the name of a parameter file or parametername=value.

Parameters

  argc | is the number of command-line arguments, including the name of the executable.
  argv | is an array of char*, each of which is a command line argument.
  verify_syntax | If true (default), then it is an error to pass arguments that cannot be handled by the ParameterGroup, or an empty argument list. If false, such arguments are stored and can be retrieved later with unhandledArguments().
  enable_output | Whether to enable output or not.

## Member Function Documentation

## disableOutput()

void Opm::ParameterGroup::disableOutput | ( |  | ) |

Disables the output from get, getDefault and getGroup.

By default, such output is enabled.

## enableOutput()

void Opm::ParameterGroup::enableOutput | ( |  | ) |

Enables the output from get, getDefault and getGroup.

By default, such output is enabled.

## get()

template<typename T >

T Opm::ParameterGroup::get | ( | const std::string & | name | ) | const

inline

This method is used to read a parameter from the parameter group.

NOTE: If the reading of the parameter fails, then this method throws an appropriate exception.

Parameters

  name | is the name of the parameter in question.

Returns
  The value associated with then name in this parameter group.

## getDefault()

template<typename T >

T Opm::ParameterGroup::getDefault | ( | const std::string & | name,
|  | const T & | default_value
| ) |  | const

inline

This method is used to read a parameter from the parameter group.

NOTE: If the reading of the parameter fails, then either a) this method returns `default_value` if there was no parameter with name `name` in the parameter group or b) this method throws an appropriate exception.

Parameters

  name | is the name of the parameter in question.
  default_value | the default value of the parameter in question.

Returns
  The value associated with this name in this parameter group.

## getGroup()

ParameterGroup Opm::ParameterGroup::getGroup | ( | const std::string & | name | ) | const

This method returns the parameter group given by name, i.e.

it is an alias of get<ParameterGroup>().

Parameters

  name | is the name of the parameter group sought.

Returns
  the parameter group sought.

## getTag()

std::string Opm::ParameterGroup::getTag | ( |  | ) | const

override virtual

This function returns a string describing the ParameterMapItem.

Implements Opm::ParameterMapItem.

## has()

bool Opm::ParameterGroup::has | ( | const std::string & | name | ) | const

This method checks if there is something with name `name` in the parameter gropup.

Parameters

  name | is the name of the parameter.

Returns
  true if `name` is the name of something in the parameter group, false otherwise.

## isOutputEnabled()

bool Opm::ParameterGroup::isOutputEnabled | ( |  | ) | const

Returs true if and only if output from get, getDefault and getGroup is enabled.

Returns
  true if and only if output from get, getDefault and getGroup is enabled.

## readParam()

void Opm::ParameterGroup::readParam | ( | const std::string & | param_filename | ) |

Reads the contents of the param file specified by param_filename into this ParameterGroup.

NOTE: A param file contains lines on the form 'a/b/c=d'. (e.g. c is a Parameter in the ParameterGroup b, and b is a ParameterGroup in the ParameterGroup a) while '=' separates the name from the value (e.g. the value of the parameter c above will be d). NOTE: A param file does not store any type information about its values.

Parameters

  param_filename | is the name of a param file.

## writeParam()

void Opm::ParameterGroup::writeParam | ( | const std::string & | param_filename | ) | const

Writes this ParameterGroup into a param file specified by param_filename.

Parameters

  param_filename | is the name of a param file.

## writeParamToStream()

void Opm::ParameterGroup::writeParamToStream | ( | std::ostream & | stream | ) | const

Writes this ParameterGroup to a stream.

Parameters

  stream | is the stream to write to.

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

- opm/common/utility/parameters/ParameterGroup.hpp
- opm/common/utility/parameters/ParameterGroup.cpp
- opm/common/utility/parameters/ParameterGroup_impl.hpp