18 #ifndef __PARAMETERS_H 19 #define __PARAMETERS_H 24 #include <boost/optional.hpp> 25 #include <boost/variant.hpp> 26 #include "Parameter.h" 27 #include <dolfin/log/log.h> 31 namespace program_options
34 class options_description;
99 explicit Parameters(std::string key=
"parameters");
108 std::string name()
const;
111 void rename(std::string key);
128 template<
typename T>
void add(std::string key)
131 if (has_parameter(key))
135 "Parameter \"%s.%s\" already defined",
136 this->name().c_str(), key.c_str());
141 if (std::is_same<T, bool>::value)
142 _parameters.insert({key,
Parameter(key, Parameter::Type::Bool)});
143 else if (std::is_same<T, std::string>::value)
144 _parameters.insert({key,
Parameter(key, Parameter::Type::String)});
145 else if (std::is_integral<T>::value)
146 _parameters.insert({key,
Parameter(key, Parameter::Type::Int)});
147 else if (std::is_floating_point<T>::value)
148 _parameters.insert({key,
Parameter(key, Parameter::Type::Float)});
153 "Parameter type not supported");
160 template<
typename T>
void add(std::string key, T min, T max)
163 if (has_parameter(key))
167 "Parameter \"%s.%s\" already defined",
168 this->name().c_str(), key.c_str());
172 _parameters.insert({key,
Parameter(key, min, max)});
178 void add(std::string key, std::set<std::string> valid_values)
181 if (has_parameter(key))
185 "Parameter \"%s.%s\" already defined",
186 this->name().c_str(), key.c_str());
190 _parameters.insert({key,
Parameter(key, valid_values)});
194 void add(std::string key,
int value);
197 void add(std::string key,
int value,
int min_value,
int max_value);
200 void add(std::string key,
double value);
203 void add(std::string key,
double value,
double min_value,
double max_value);
206 void add(std::string key, std::string value);
209 void add(std::string key,
const char* value);
212 void add(std::string key, std::string value, std::set<std::string> range);
215 void add(std::string key,
const char* value, std::set<std::string> range);
218 void add(std::string key,
bool value);
224 void remove(std::string key);
227 virtual void parse(
int argc,
char* argv[]);
236 const Parameter& operator[] (std::string key)
const;
246 const Parameters& operator() (std::string key)
const;
252 bool has_key(std::string key)
const;
255 bool has_parameter(std::string key)
const;
258 bool has_parameter_set(std::string key)
const;
261 void get_parameter_keys(std::vector<std::string>& keys)
const;
264 void get_parameter_set_keys(std::vector<std::string>& keys)
const;
267 std::string str(
bool verbose)
const;
270 boost::optional<Parameter&> find_parameter(std::string key);
273 boost::optional<Parameters&> find_parameter_set(std::string key);
278 void parse_common(
int argc,
char* argv[]);
281 void parse_petsc(
int argc,
char* argv[]);
288 add_parameter_set_to_po(boost::program_options::options_description& desc,
290 std::string base_name=
"")
const;
293 void read_vm(boost::program_options::variables_map& vm,
295 std::string base_name=
"");
301 std::map<std::string, boost::variant<Parameter, Parameters>> _parameters;
306 std::size_t
size()
const {
return _parameters.size(); }
309 std::map<std::string, boost::variant<Parameter, Parameters>>::const_iterator
begin()
const 310 {
return _parameters.cbegin(); }
314 std::map<std::string, boost::variant<Parameter, Parameters>>::const_iterator
end()
const 315 {
return _parameters.cend(); }
void add(std::string key, T min, T max)
Definition: Parameters.h:160
Definition: XDMFFile.h:39
void add(std::string key, std::set< std::string > valid_values)
Definition: Parameters.h:178
Type
Enum for the parameter type.
Definition: Parameter.h:54
void add(std::string key)
Definition: Parameters.h:128
Parameters empty_parameters("empty")
Default empty parameters.
Definition: Parameters.h:321
Base class for parameters.
Definition: Parameter.h:33
Definition: Parameters.h:94
std::map< std::string, boost::variant< Parameter, Parameters > >::const_iterator end() const
Interface for pybind11 iterators.
Definition: Parameters.h:314
std::map< std::string, boost::variant< Parameter, Parameters > >::const_iterator begin() const
Interface for pybind11 iterators.
Definition: Parameters.h:309
void dolfin_error(std::string location, std::string task, std::string reason,...)
Definition: log.cpp:129
std::size_t size() const
Interface for pybind11 iterators.
Definition: Parameters.h:306
GlobalParameters parameters
The global parameter database.
Definition: GlobalParameters.cpp:32