DUNE-FEM (unstable)

Container for User Specified Parameters. More...

#include <dune/fem/io/parameter.hh>

Static Public Member Functions

static void append (int &argc, char **argv)
 add parameters from the command line RangeType gRight; More...
 
static void append (const std::string &key, const std::string &value, const bool force=false)
 add a single parameter to the container More...
 
template<class NumberType >
static void append (const std::string &key, const NumberType &value, const bool force=false)
 add a single parameter to the container More...
 
static void append (const std::string &filename)
 add parameters from a file to the container More...
 
static void appendDGF (const std::string &filename)
 add parameters from a DGF file to the container More...
 
static bool exists (const std::string &key)
 find out, whether a parameter is defined in the container More...
 
template<class T >
static void get (const std::string &key, T &value)
 get a mandatory parameter from the container More...
 
template<class T >
static void get (const std::string &key, const T &defaultValue, T &value)
 get an optional parameter from the container More...
 
static void get (const std::string &key, const char *defaultValue, std::string &value)
 get an optional parameter from the container special case for string More...
 
template<class T , class Validator >
static void getValid (const std::string &key, const Validator &validator, T &value)
 get a mandatory parameter from the container More...
 
template<class T , class Validator >
static void getValid (const std::string &key, const T &defaultValue, const Validator &validator, T &value)
 get an optional parameter from the container More...
 
template<class T >
static T getValue (const std::string &key)
 get a mandatory parameter from the container More...
 
template<class T >
static T getValue (const std::string &key, const T &defaultValue)
 get an optional parameter from the container More...
 
template<class T , class Validator >
static T getValidValue (const std::string &key, const Validator &validator)
 get an optional parameter from the container More...
 
template<class T , class Validator >
static T getValidValue (const std::string &key, const T &defaultValue, const Validator &validator)
 get an optional parameter from the container More...
 
static std::string commonOutputPath ()
 obtain common output path More...
 
static std::string outputPath ()
 obtain unique output path for this process More...
 
static std::string commonInputPath ()
 obtain common input path More...
 
static bool verbose ()
 obtain the cached value for fem.verbose with default verbosity level 2
 
static bool verbose (const int level)
 obtain the cached value for fem.verbose
 
static void write (const std::string &filename, const std::string &fileextension="", bool writeAll=true)
 write the parameter database to a file More...
 
static void write (std::ostream &out, bool writeAll=true)
 write the parameter database to a stream More...
 

Static Protected Member Functions

static void write (const std::string &path, const std::string &filename, const std::string &fileextension, bool writeAll=true)
 write the parameter database to a file More...
 

Detailed Description

Container for User Specified Parameters.

The class Parameter provides parameters collected from given parameter files or the command line in a unified and easy to use way.

This class adheres to the singleton concept, i.e., all methods are static and internally use a single instance of this object to store all data.

Member Function Documentation

◆ append() [1/4]

static void Dune::Fem::Parameter::append ( const std::string &  filename)
inlinestatic

add parameters from a file to the container

Parameters
[in]filenamename of the file containing the parameters

◆ append() [2/4]

template<class NumberType >
static void Dune::Fem::Parameter::append ( const std::string &  key,
const NumberType &  value,
const bool  force = false 
)
inlinestatic

add a single parameter to the container

Parameters
[in]keykey of the parameter to add
[in]valuevalue of the parameter to add

◆ append() [3/4]

static void Dune::Fem::Parameter::append ( const std::string &  key,
const std::string &  value,
const bool  force = false 
)
inlinestatic

add a single parameter to the container

Parameters
[in]keykey of the parameter to add
[in]valuevalue of the parameter to add

◆ append() [4/4]

static void Dune::Fem::Parameter::append ( int &  argc,
char **  argv 
)
inlinestatic

add parameters from the command line RangeType gRight;

This mehtod adds all parameters (strings containing a colon) in the command line to the container. The parameters are then removed from the command line.

Parameters
[in]argcnumber of arguments (as given to main)
[in]argvvector of arguments (as given to main)

◆ appendDGF()

static void Dune::Fem::Parameter::appendDGF ( const std::string &  filename)
inlinestatic

add parameters from a DGF file to the container

Parameters can also be read from a DGF file containing a 'FemParameter' block.

Parameters
[in]filenamename of the DGF file containing the parameters

◆ commonInputPath()

static std::string Dune::Fem::Parameter::commonInputPath ( )
inlinestatic

obtain common input path

This common input path could for example be used for the determination of the location of parameter and grid files

Returns
value of parameter 'fem.input.prefix', which defaults to '.'.

◆ commonOutputPath()

static std::string Dune::Fem::Parameter::commonOutputPath ( )
inlinestatic

obtain common output path

For parallel jobs you need two different output paths:

  • Data common to all processes should be written to commonOutputPath(). Only one process (i.e., rank 0) should write this data.
  • Data unique to each process should be written to outputPath(). Each process should write this data.
Returns
value of parameter 'fem.prefix', which defaults to '.'.

Referenced by outputPath(), Dune::Fem::IOInterface::readPath(), and write().

◆ exists()

static bool Dune::Fem::Parameter::exists ( const std::string &  key)
inlinestatic

find out, whether a parameter is defined in the container

Parameters
[in]keyname of the parameter to check
Returns
true, if the parameter is found in the container, false otherwise

◆ get() [1/3]

static void Dune::Fem::Parameter::get ( const std::string &  key,
const char *  defaultValue,
std::string &  value 
)
inlinestatic

get an optional parameter from the container special case for string

Note
This method returns a default value, if the parameter cannot be found.
Parameters
[in]keyname of the parameter to get
[in]defaultValuedefault value for this parameter
[out]valuevalue of the parameter

◆ get() [2/3]

template<class T >
static void Dune::Fem::Parameter::get ( const std::string &  key,
const T &  defaultValue,
T &  value 
)
inlinestatic

get an optional parameter from the container

Note
This method returns a default value, if the parameter cannot be found.
Parameters
[in]keyname of the parameter to get
[in]defaultValuedefault value for this parameter
[out]valuevalue of the parameter

◆ get() [3/3]

template<class T >
static void Dune::Fem::Parameter::get ( const std::string &  key,
T &  value 
)
inlinestatic

get a mandatory parameter from the container

Note
This method throws an exception, if the parameter cannot be found.
Parameters
[in]keyname of the parameter to get
[out]valuevalue of the parameter

◆ getValid() [1/2]

template<class T , class Validator >
static void Dune::Fem::Parameter::getValid ( const std::string &  key,
const T &  defaultValue,
const Validator &  validator,
T &  value 
)
inlinestatic

get an optional parameter from the container

Note
This method returns a default value, if the parameter cannot be found.
Parameters
[in]keyname of the parameter to get
[in]defaultValuedefault value for this parameter
[in]validatorvalidator for the parameter value
[out]valuevalue of the parameter

◆ getValid() [2/2]

template<class T , class Validator >
static void Dune::Fem::Parameter::getValid ( const std::string &  key,
const Validator &  validator,
T &  value 
)
inlinestatic

get a mandatory parameter from the container

Note
This method throws an exception, if the parameter cannot be found.
Parameters
[in]keyname of the parameter to get
[in]validatorvalidator for the parameter value
[out]valuevalue of the parameter

◆ getValidValue() [1/2]

template<class T , class Validator >
static T Dune::Fem::Parameter::getValidValue ( const std::string &  key,
const T &  defaultValue,
const Validator &  validator 
)
inlinestatic

get an optional parameter from the container

Note
This method returns a default value, if the parameter cannot be found.
Parameters
[in]keyname of the parameter to get
[in]defaultValuedefault value for this parameter
[in]validatorvalidator for the parameter value
Returns
value of the parameter

◆ getValidValue() [2/2]

template<class T , class Validator >
static T Dune::Fem::Parameter::getValidValue ( const std::string &  key,
const Validator &  validator 
)
inlinestatic

get an optional parameter from the container

Note
This method returns a default value, if the parameter cannot be found.
Parameters
[in]keyname of the parameter to get
[in]validatorvalidator for the parameter value
Returns
value of the parameter

◆ getValue() [1/2]

template<class T >
static T Dune::Fem::Parameter::getValue ( const std::string &  key)
inlinestatic

get a mandatory parameter from the container

Note
This method throws an exception, if the parameter cannot be found.
Parameters
[in]keyname of the parameter to get
Returns
value of the parameter

◆ getValue() [2/2]

template<class T >
static T Dune::Fem::Parameter::getValue ( const std::string &  key,
const T &  defaultValue 
)
inlinestatic

get an optional parameter from the container

Note
This method returns a default value, if the parameter cannot be found.
Parameters
[in]keyname of the parameter to get
[in]defaultValuedefault value for this parameter
Returns
value of the parameter

◆ outputPath()

std::string Dune::Fem::Parameter::outputPath ( )
inlinestatic

obtain unique output path for this process

For parallel jobs you need two different output paths:

  • Data common to all processes should be written to commonOutputPath(). Only one process (i.e., rank 0) should write this data.
  • Data unique to each process should be written to outputPath(). Each process should write this data.
Returns
<prefix>/p<rank>, where
  • <prefix> denotes the value of 'fem.prefix', which defaults to '.',
  • <rank> denots the this processes rank.

References commonOutputPath().

◆ write() [1/3]

void Dune::Fem::Parameter::write ( const std::string &  filename,
const std::string &  fileextension = "",
bool  writeAll = true 
)
inlinestatic

write the parameter database to a file

This method writes paramters to the given file. If the second parameter is true all parameters are written; otherwise only used parameters which do not coincide with the default value are written.

Note
This method is safe for parallel jobs. Parameters are only written on rank 0.
Parameters
[in]filenamename of the file to store the parameters in; prefix() is used.
[in]fileextensionfile extension if you want to have time stemps in the log files, ! must contain the "." dot for fileextensions !
[in]writeAlldefault is true

References commonOutputPath(), and write().

Referenced by write().

◆ write() [2/3]

void Dune::Fem::Parameter::write ( const std::string &  path,
const std::string &  filename,
const std::string &  fileextension,
bool  writeAll = true 
)
inlinestaticprotected

write the parameter database to a file

This method writes paramters to the given file. If the second parameter is true all parameters are written; otherwise only used parameters which do not coincide with the default value are written.

Note
This method is safe for parallel jobs. Parameters are only written on rank 0.
Parameters
[in]pathpath where filename is stored (for parallel writing)
[in]filenamename of the file to store the parameters in; prefix() is used.
[in]fileextensionchosen fileextension
[in]writeAlldefault is true

References write().

◆ write() [3/3]

static void Dune::Fem::Parameter::write ( std::ostream &  out,
bool  writeAll = true 
)
inlinestatic

write the parameter database to a stream

This method writes paramters to the given stream. If the second parameter is true all parameters are written; otherwise only used parameters which do not coincide with the default value are written.

Note
This method is not safe for parallel jobs. Parameters are written on all ranks.
Parameters
[in]outstream for the parameters.
[in]writeAlldefault is true

The documentation for this class was generated from the following file:
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 1, 22:29, 2024)