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 enable_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
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Opm::anyUnused
bool anyUnused() const
Return true if any parameters are unused.
Definition ParameterGroup.cpp:266
Opm::has
bool has(const std::string &name) const
This method checks if there is something with name name in the parameter gropup.
Opm::getDefault
T getDefault(const std::string &name, const T &default_value) const
This method is used to read a parameter from the parameter group.
Opm::unhandledArguments
const std::vector< std::string > & unhandledArguments() const
Unhandled arguments from command line parsing.
Definition ParameterGroup.cpp:327
Opm::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::get
T get(const std::string &name) const
This method is used to read a parameter from the parameter group.
Opm::path
const std::string & path() const
Returns the path of the parameter group.
Opm::disableOutput
void disableOutput()
Disables the output from get, getDefault and getGroup.
Definition ParameterGroup.cpp:304
Opm::insertParameter
void insertParameter(const std::string &name, const std::string &value)
Insert a new parameter item into the group.
Definition ParameterGroup.cpp:201
Opm::writeParamToStream
void writeParamToStream(std::ostream &stream) const
Writes this ParameterGroup to a stream.
Definition ParameterGroup.cpp:149
Opm::enableOutput
void enableOutput()
Enables the output from get, getDefault and getGroup.
Definition ParameterGroup.cpp:308
Opm::insert
void insert(const std::string &name, const std::shared_ptr< ParameterMapItem > &data)
Insert a new item into the group.
Opm::displayUsage
void displayUsage(bool used_params=false) const
Shows which parameters which are used or unused.
Definition ParameterGroup.cpp:286
Opm::isOutputEnabled
bool isOutputEnabled() const
Returs true if and only if output from get, getDefault and getGroup is enabled.
Definition ParameterGroup.cpp:312
Opm::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
ParameterGroup(int argc, StringArray argv, const bool verify_syntax=true, const bool enable_output=true)
ParameterGroup is a class that is used to provide run-time parameters.
Definition ParameterGroup_impl.hpp:113
Opm::getGroup
ParameterGroup getGroup(const std::string &name) const
This method returns the parameter group given by name, i.e.
Opm::ParameterMapItem
The parameter handlig system is structured as a tree, where each node inhertis from ParameterMapItem.
Definition ParameterMapItem.hpp:47