My Project
Loading...
Searching...
No Matches
parametersystem.hpp File Reference

This file provides the infrastructure to retrieve run-time parameters. More...

#include <dune/common/classname.hh>
#include <cstring>
#include <functional>
#include <set>
#include <sstream>
#include <string>
#include <type_traits>
#include <vector>

Go to the source code of this file.

Classes

struct  Opm::Parameters::detail::has_name< typename, class >
 
struct  Opm::Parameters::detail::has_name< T, std::void_t< decltype(std::declval< T >().name)> >
 
struct  Opm::Parameters::Parameter
 A struct holding the key-value pair for a parameter. More...
 

Namespaces

namespace  Opm
 This file contains a set of helper functions used by VFPProd / VFPInj.
 

Typedefs

using Opm::Parameters::PositionalArgumentCallback
 Callback function for command line parsing.
 

Functions

template<class Parameter >
auto Opm::Parameters::detail::getParamName ()
 get the name data member of a parameter
 
template<class ParamType >
ParamType Opm::Parameters::detail::Get_ (const std::string &paramName, ParamType defaultValue, bool errorIfNotRegistered)
 Private implementation.
 
void Opm::Parameters::detail::Hide_ (const std::string &paramName)
 Private implementation.
 
bool Opm::Parameters::detail::IsSet_ (const std::string &paramName, bool errorIfNotRegistered)
 Private implementation.
 
void Opm::Parameters::detail::Register_ (const std::string &paramName, const std::string &paramTypeName, const std::string &defaultValue, const char *usageString)
 Private implementation.
 
void Opm::Parameters::detail::SetDefault_ (const std::string &paramName, const std::string &paramValue)
 Private implementation.
 
void Opm::Parameters::printUsage (const std::string &helpPreamble, std::ostream &os, const std::string &errorMsg="", const bool showAll=false)
 Print a usage message for all run-time parameters.
 
std::string Opm::Parameters::parseCommandLineOptions (int argc, const char **argv, const PositionalArgumentCallback &posArgCallback, const std::string &helpPreamble="")
 Parse the parameters provided on the command line.
 
bool Opm::Parameters::parseParameterFile (const std::string &fileName, bool overwrite=true)
 Read the parameters from an INI-style file.
 
void Opm::Parameters::printValues (std::ostream &os)
 Print values of the run-time parameters.
 
bool Opm::Parameters::printUnused (std::ostream &os)
 Print the list of unused run-time parameters.
 
template<class Param >
auto Opm::Parameters::Get (bool errorIfNotRegistered=true)
 Retrieve a runtime parameter.
 
template<class Param >
void Opm::Parameters::SetDefault (decltype(Param::value) new_value)
 Set a runtime parameter.
 
void Opm::Parameters::getLists (std::vector< Parameter > &usedParams, std::vector< Parameter > &unusedParams)
 Retrieves the lists of parameters specified at runtime and their values.
 
void Opm::Parameters::reset ()
 Reset parameter system.
 
template<class Param >
bool Opm::Parameters::IsSet (bool errorIfNotRegistered=true)
 Returns true if a parameter has been specified at runtime, false otherwise.
 
template<class Param >
void Opm::Parameters::Register (const char *usageString)
 Register a run-time parameter.
 
template<class Param >
void Opm::Parameters::Hide ()
 Indicate that a given parameter should not be mentioned in the help message.
 
bool Opm::Parameters::IsRegistrationOpen ()
 Query whether parameter registration is open or not.
 
void Opm::Parameters::endRegistration ()
 Indicate that all parameters are registered for a given type tag.
 

Detailed Description

This file provides the infrastructure to retrieve run-time parameters.

Internally, runtime parameters are implemented using Dune::ParameterTree with the default value taken from the parameter definition.

Typedef Documentation

◆ PositionalArgumentCallback

Initial value:
std::function<int(std::function<void(const std::string&,
const std::string&)>,
std::set<std::string>&,
std::string&,
int,
const char**,
int,
int)>

Callback function for command line parsing.

Function Documentation

◆ endRegistration()

void Opm::Parameters::endRegistration ( )

Indicate that all parameters are registered for a given type tag.

If registerParam is called after the invocation of endParamRegistration, a std::logic_error exception will be thrown.

◆ Get()

template<class Param >
auto Opm::Parameters::Get ( bool errorIfNotRegistered = true)

Retrieve a runtime parameter.

The default value is specified in the parameter struct.

Example:

// Retrieves value UpwindWeight, default
// is taken from the property UpwindWeight
::Opm::Parameters::get<::Opm::Parameters::UpwindWeight>();

◆ getLists()

void Opm::Parameters::getLists ( std::vector< Parameter > & usedParams,
std::vector< Parameter > & unusedParams )

Retrieves the lists of parameters specified at runtime and their values.

The two arguments besides the TypeTag are assumed to be STL containers which store std::pair<std::string, std::string>.

◆ Hide()

template<class Param >
void Opm::Parameters::Hide ( )

Indicate that a given parameter should not be mentioned in the help message.

This allows to deal with unused parameters

◆ IsRegistrationOpen()

bool Opm::Parameters::IsRegistrationOpen ( )

Query whether parameter registration is open or not.

Returns
True if registration is open, false otherwise

◆ IsSet()

template<class Param >
bool Opm::Parameters::IsSet ( bool errorIfNotRegistered = true)

Returns true if a parameter has been specified at runtime, false otherwise.

If the parameter in question has not been registered, this throws an exception.

◆ parseCommandLineOptions()

std::string Opm::Parameters::parseCommandLineOptions ( int argc,
const char ** argv,
const PositionalArgumentCallback & posArgCallback,
const std::string & helpPreamble = "" )

Parse the parameters provided on the command line.

This function does some basic syntax checks.

Parameters
argcThe number of parameters passed by the operating system to the main() function
argvThe array of strings passed by the operating system to the main() function
helpPreambleIf non-empty, the –help and -h parameters will be recognized and the content of the string will be printed before the list of command line parameters
Returns
Empty string if everything worked out. Otherwise the thing that could not be read.

◆ parseParameterFile()

bool Opm::Parameters::parseParameterFile ( const std::string & fileName,
bool overwrite = true )

Read the parameters from an INI-style file.

This function does some basic syntax checks.

◆ printUnused()

bool Opm::Parameters::printUnused ( std::ostream & os)

Print the list of unused run-time parameters.

Parameters
osThe std::ostream on which the message should be printed
Returns
true if something was printed

◆ printUsage()

void Opm::Parameters::printUsage ( const std::string & helpPreamble,
std::ostream & os,
const std::string & errorMsg = "",
const bool showAll = false )

Print a usage message for all run-time parameters.

Parameters
helpPreambleThe string that is printed after the error message and before the list of parameters.
errorMsgThe error message to be printed, if any
osThe std::ostream which should be used.

◆ printValues()

void Opm::Parameters::printValues ( std::ostream & os)

Print values of the run-time parameters.

Parameters
osThe std::ostream on which the message should be printed

◆ Register()

template<class Param >
void Opm::Parameters::Register ( const char * usageString)

Register a run-time parameter.

In OPM, parameters can only be used after they have been registered.

Example:

// Registers a run-time parameter "UpwindWeight"
and the description "Relative weight of the upwind node."
Register<UpwindWeight>("Relative weight of the upwind node.");

◆ SetDefault()

template<class Param >
void Opm::Parameters::SetDefault ( decltype(Param::value) new_value)

Set a runtime parameter.

Override the default value specified.

Example:

// Set the value UpwindWeight
::Opm::Parameters::Set<::Opm::Parameters::UpwindWeight>(3.0);