Loading...
Searching...
No Matches
ParameterGroup.hpp
//===========================================================================
//
// File: ParameterGroup.hpp
//
// Created: Tue Jun 2 19:11:11 2009
//
// Author(s): Bård Skaflestad <bard.skaflestad@sintef.no>
// Atgeirr F Rasmussen <atgeirr@sintef.no>
//
// $Date$
//
// $Revision$
//
//===========================================================================
/*
Copyright 2009, 2010 SINTEF ICT, Applied Mathematics.
Copyright 2009, 2010 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_PARAMETERGROUP_HEADER
#define OPM_PARAMETERGROUP_HEADER
#include <exception>
#include <map>
#include <string>
#include <vector>
#include <memory>
#include <opm/common/utility/parameters/ParameterMapItem.hpp>
#include <opm/common/utility/parameters/ParameterRequirement.hpp>
namespace Opm {
// for parameter ``param1'' lying at the root and ``param2'' in the group
class ParameterGroup : public ParameterMapItem {
public:
struct NotFoundException : public std::exception {};
struct WrongTypeException : public std::exception {};
struct ConversionFailedException : public std::exception {};
template<typename T>
struct RequirementFailedException : public std::exception {};
ParameterGroup();
ParameterGroup(const std::string& path, const ParameterGroup* parent,
const bool enable_output);
// From ParameterMapItem
~ParameterGroup() override;
std::string getTag() const override;
template <typename StringArray>
ParameterGroup(int argc, StringArray argv, const bool verify_syntax = true,
const bool enabled_output=true);
bool has(const std::string& name) const;
template<typename T>
T get(const std::string& name) const;
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;
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;
void disableOutput();
void enableOutput();
bool isOutputEnabled() const;
// The '/' separates ParameterGroups and Parameters
void readParam(const std::string& param_filename);
void writeParam(const std::string& param_filename) const;
void writeParamToStream(std::ostream& stream) const;
template<typename T>
void get(const char* name, T& value, const T& default_value) const {
value = this->getDefault<T>(name, default_value);
}
template<typename T>
void get(const char* name, T& value) const {
value = this->get<T>(name);
}
bool anyUnused() const;
void displayUsage(bool used_params = false) const;
const std::string& path() const;
void insert(const std::string& name,
const std::shared_ptr<ParameterMapItem>& data);
void insertParameter(const std::string& name, const std::string& value);
const std::vector<std::string>& unhandledArguments() const;
private:
typedef std::shared_ptr<ParameterMapItem> data_type;
typedef std::pair<std::string, data_type> pair_type;
typedef std::map<std::string, data_type> map_type;
std::string path_;
map_type map_;
const ParameterGroup* parent_;
bool output_is_enabled_;
std::vector<std::string> unhandled_arguments_;
template<typename T, class Requirement>
T translate(const pair_type& data, const Requirement& chk) const;
template <typename StringArray>
void parseCommandLineArguments(int argc, StringArray argv, bool verify_syntax);
void recursiveSetIsOutputEnabled(bool output_is_enabled);
// helper routines to do textual I/O
template <typename T>
static std::string to_string(const T& val);
static std::pair<std::string, std::string>
filename_split(const std::string& filename);
};
} // namespace Opm
#include <opm/common/utility/parameters/ParameterGroup_impl.hpp>
#endif // OPM_PARAMETERGROUP_HEADER
Opm::ParameterGroup
ParameterGroup is a class that is used to provide run-time parameters.
Definition ParameterGroup.hpp:81
Opm::ParameterGroup::path
const std::string & path() const
Returns the path of the parameter group.
Definition ParameterGroup.cpp:82
Opm::ParameterGroup::insert
void insert(const std::string &name, const std::shared_ptr< ParameterMapItem > &data)
Insert a new item into the group.
Definition ParameterGroup.cpp:169
Opm::ParameterGroup::get
void get(const char *name, T &value, const T &default_value) const
vki param interface - deprecated
Definition ParameterGroup.hpp:216
Opm::ParameterGroup::anyUnused
bool anyUnused() const
Return true if any parameters are unused.
Definition ParameterGroup.cpp:266
Opm::ParameterGroup::getGroup
ParameterGroup getGroup(const std::string &name) const
This method returns the parameter group given by name, i.e.
Definition ParameterGroup.cpp:95
Opm::ParameterGroup::unhandledArguments
const std::vector< std::string > & unhandledArguments() const
Unhandled arguments from command line parsing.
Definition ParameterGroup.cpp:327
Opm::ParameterGroup::writeParam
void writeParam(const std::string &param_filename) const
Writes this ParameterGroup into a param file specified by param_filename.
Definition ParameterGroup.cpp:139
Opm::ParameterGroup::disableOutput
void disableOutput()
Disables the output from get, getDefault and getGroup.
Definition ParameterGroup.cpp:304
Opm::ParameterGroup::insertParameter
void insertParameter(const std::string &name, const std::string &value)
Insert a new parameter item into the group.
Definition ParameterGroup.cpp:201
Opm::ParameterGroup::writeParamToStream
void writeParamToStream(std::ostream &stream) const
Writes this ParameterGroup to a stream.
Definition ParameterGroup.cpp:149
Opm::ParameterGroup::enableOutput
void enableOutput()
Enables the output from get, getDefault and getGroup.
Definition ParameterGroup.cpp:308
Opm::ParameterGroup::getTag
std::string getTag() const override
This function returns a string describing the ParameterMapItem.
Definition ParameterGroup.cpp:63
Opm::ParameterGroup::get
void get(const char *name, T &value) const
vki param interface - deprecated
Definition ParameterGroup.hpp:222
Opm::ParameterGroup::displayUsage
void displayUsage(bool used_params=false) const
Shows which parameters which are used or unused.
Definition ParameterGroup.cpp:286
Opm::ParameterGroup::has
bool has(const std::string &name) const
This method checks if there is something with name name in the parameter gropup.
Definition ParameterGroup.cpp:68
Opm::ParameterGroup::isOutputEnabled
bool isOutputEnabled() const
Returs true if and only if output from get, getDefault and getGroup is enabled.
Definition ParameterGroup.cpp:312
Opm::ParameterGroup::getDefault
T getDefault(const std::string &name, const T &default_value) const
This method is used to read a parameter from the parameter group.
Definition ParameterGroup_impl.hpp:219
Opm::ParameterGroup::readParam
void readParam(const std::string &param_filename)
Reads the contents of the param file specified by param_filename into this ParameterGroup.
Definition ParameterGroup.cpp:107
Opm::ParameterGroup::get
T get(const std::string &name) const
This method is used to read a parameter from the parameter group.
Definition ParameterGroup_impl.hpp:175
Opm
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Opm::ParameterGroup::ConversionFailedException
Definition ParameterGroup.hpp:85
Opm::ParameterGroup::NotFoundException
Definition ParameterGroup.hpp:83
Opm::ParameterGroup::RequirementFailedException
Definition ParameterGroup.hpp:88
Opm::ParameterGroup::WrongTypeException
Definition ParameterGroup.hpp:84
Opm::ParameterMapItem
The parameter handlig system is structured as a tree, where each node inhertis from ParameterMapItem.
Definition ParameterMapItem.hpp:47