20 #include <deal2lkit/revision.h> 32 acceptor_id(class_list.size()),
53 const std::string out_filename)
59 #pragma GCC diagnostic push 60 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 62 if (filename.substr(filename.find_last_of(
".") + 1) ==
"prm")
64 else if (filename.substr(filename.find_last_of(
".") + 1) ==
"xml")
66 std::ifstream is(filename);
68 #pragma GCC diagnostic pop 74 if (out_filename !=
"")
76 std::ofstream outfile(out_filename.c_str());
78 std::string extension = out_filename.substr(out_filename.find_last_of(
".") + 1);
80 if ( extension ==
"prm")
82 outfile <<
"# Parameter file generated with " << std::endl
83 <<
"# D2K_GIT_BRANCH= " << D2K_GIT_BRANCH << std::endl
84 <<
"# D2K_GIT_SHORTREV= " << D2K_GIT_SHORTREV << std::endl
85 <<
"# DEAL_II_GIT_BRANCH= " << DEAL_II_GIT_BRANCH << std::endl
86 <<
"# DEAL_II_GIT_SHORTREV= " << DEAL_II_GIT_SHORTREV << std::endl;
89 else if (extension ==
"xml")
91 else if (extension ==
"latex" || extension ==
"tex")
101 for (
unsigned int i=0; i<
class_list.size(); ++i)
112 deallog.push(
"ParameterAcceptor");
113 for (
unsigned int i=0; i<
class_list.size(); ++i)
115 deallog <<
"Class " << i <<
":";
117 deallog <<
class_list[i]->get_section_name() << std::endl;
119 deallog <<
" NULL" << std::endl;
126 for (
unsigned int i=0; i<
class_list.size(); ++i)
138 for (
unsigned int i=0; i<
class_list.size(); ++i)
148 std::vector<std::string>
152 std::vector<std::string> sections =
154 bool is_absolute =
false;
155 if (sections.size() > 1)
158 if (sections[0] ==
"")
161 sections.erase(sections.begin());
164 if (is_absolute ==
false)
172 bool has_trailing =
class_list[i]->get_section_name().back() ==
sep;
177 sections.insert(sections.begin(), secs.begin()+1, secs.end()-(has_trailing ? 0 : 1));
188 for (
auto sec : sections)
197 for (
auto sec : sections)
208 std_cxx11::shared_ptr<Patterns::PatternBase> ParameterAcceptor::to_pattern<std::string>(
const std::string &)
214 std::string ParameterAcceptor::to_string<std::string>(
const std::string &entry)
220 std::string ParameterAcceptor::to_type<std::string>(
const std::string ¶meter)
227 std_cxx11::shared_ptr<Patterns::PatternBase> ParameterAcceptor::to_pattern<double>(
const double &)
233 std::string ParameterAcceptor::to_string<double>(
const double &entry)
235 return std::to_string(entry);
239 double ParameterAcceptor::to_type<double>(
const std::string ¶meter)
241 return std::stod(parameter);
247 std_cxx11::shared_ptr<Patterns::PatternBase> ParameterAcceptor::to_pattern<int>(
const int &)
253 std::string ParameterAcceptor::to_string<int>(
const int &entry)
255 return std::to_string(entry);
259 int ParameterAcceptor::to_type<int>(
const std::string ¶meter)
261 return std::stoi(parameter);
267 std_cxx11::shared_ptr<Patterns::PatternBase> ParameterAcceptor::to_pattern<unsigned int>(
const unsigned int &)
273 std::string ParameterAcceptor::to_string<unsigned int>(
const unsigned int &entry)
275 return std::to_string(entry);
279 unsigned int ParameterAcceptor::to_type<unsigned int>(
const std::string ¶meter)
281 return (
unsigned int)std::stoi(parameter);
287 std_cxx11::shared_ptr<Patterns::PatternBase> ParameterAcceptor::to_pattern<bool>(
const bool &)
293 std::string ParameterAcceptor::to_string<bool>(
const bool &entry)
295 return std::string((entry ?
"true" :
"false"));
299 bool ParameterAcceptor::to_type<bool>(
const std::string ¶meter)
301 return (parameter ==
"true" || parameter ==
"1");
308 std_cxx11::shared_ptr<Patterns::PatternBase> ParameterAcceptor::to_pattern<Point<dim> >(const Point<dim> &) {\ 309 return SP(new Patterns::List(Patterns::Double(),dim,dim));\ 313 std::string ParameterAcceptor::to_string<Point<dim> >(const Point<dim> &entry) {\ 314 return print(entry);\ 318 Point<dim> ParameterAcceptor::to_type<Point<dim> >(const std::string ¶meter) {\ 320 auto ps = Utilities::split_string_list(parameter);\ 321 AssertDimension(ps.size(), dim);\ 322 for(unsigned int i=0; i<dim; ++i)\ 323 p[i] = std::stod(ps[i]);\ 334 #define MYV(type, sep) \ 336 std_cxx11::shared_ptr<Patterns::PatternBase> ParameterAcceptor::to_pattern<std::vector<type> >(const std::vector<type> &) {\ 338 return SP(new Patterns::List(*to_pattern(p),0,Patterns::List::max_int_value,sep));\ 342 std::string ParameterAcceptor::to_string<std::vector<type> >(const std::vector<type> &entry) {\ 343 std::ostringstream s; \ 344 if(entry.size() > 0) \ 345 s << to_string(entry[0]); \ 346 for(unsigned int i=1; i<entry.size(); ++i) \ 347 s << std::string(sep) << " " << to_string(entry[i]); \ 352 std::vector<type> ParameterAcceptor::to_type<std::vector<type> >(const std::string ¶meter) {\ 353 auto ps = Utilities::split_string_list(parameter,sep[0]);\ 354 std::vector<type> p(ps.size());\ 355 for(unsigned int i=0; i<ps.size(); ++i)\ 356 p[i] = to_type<type>(ps[i]);\ 360 MYV(std::string,
",")
363 MYV(
unsigned int, ",")
371 MYV(
std::vector<
double>, ";")
372 MYV(
std::vector<
int>, ";")
373 MYV(
std::vector<
unsigned int>, ";")
383 inline bool to_boost_any(
const std::string &entry, boost::any &boost_parameter)
385 if (boost_parameter.type() ==
typeid(T *))
387 T ¶meter = *(boost::any_cast<T *>(boost_parameter));
388 parameter = ParameterAcceptor::to_type<T>(entry);
402 const std::string &entry= prm.
get(it.first);
403 boost::any &boost_parameter = it.second;
405 if (to_boost_any<std::string>(entry, boost_parameter)) {}
406 else if (to_boost_any<double>(entry, boost_parameter)) {}
407 else if (to_boost_any<int>(entry, boost_parameter)) {}
408 else if (to_boost_any<unsigned int>(entry, boost_parameter)) {}
409 else if (to_boost_any<bool>(entry, boost_parameter)) {}
410 else if (to_boost_any<
Point<1> >(entry, boost_parameter)) {}
411 else if (to_boost_any<
Point<2> >(entry, boost_parameter)) {}
412 else if (to_boost_any<
Point<3> >(entry, boost_parameter)) {}
413 else if (to_boost_any<std::vector<std::string> >(entry, boost_parameter)) {}
414 else if (to_boost_any<std::vector<double> >(entry, boost_parameter)) {}
415 else if (to_boost_any<std::vector<int> >(entry, boost_parameter)) {}
416 else if (to_boost_any<std::vector<unsigned int> >(entry, boost_parameter)) {}
418 else if (to_boost_any<std::vector<
Point<1> > >(entry, boost_parameter)) {}
419 else if (to_boost_any<std::vector<
Point<2> > >(entry, boost_parameter)) {}
420 else if (to_boost_any<std::vector<
Point<3> > >(entry, boost_parameter)) {}
421 else if (to_boost_any<std::vector<std::vector<std::string> > >(entry, boost_parameter)) {}
422 else if (to_boost_any<std::vector<std::vector<double> > >(entry, boost_parameter)) {}
423 else if (to_boost_any<std::vector<std::vector<int> > >(entry, boost_parameter)) {}
424 else if (to_boost_any<std::vector<std::vector<unsigned int> > >(entry, boost_parameter)) {}
static void clear()
Clear class list and global parameter file.
static ParameterHandler prm
Static parameter.
static::ExceptionBase & ExcIO()
static void log_info()
Print information about all stored classes.
virtual ~ParameterAcceptor()
The destructor sets to zero the pointer relative to this index, so that it is safe to destroy the mot...
static const char sep
Separator between section and subsection.
#define AssertThrow(cond, exc)
shared_ptr< T > SP(T *t)
Construct a shared pointer to a non const class T.
std::string get(const std::string &entry_string) const
void enter_my_subsection(ParameterHandler &prm)
Make sure we enter the right subsection of the global parameter file.
void enter_subsection(const std::string &subsection)
virtual void parse_parameters_call_back()
Parse parameter call back.
std::string get_section_name() const
Return the section name of this class.
static::ExceptionBase & ExcMessage(std::string arg1)
const std::string section_name
The subsection name for this class.
virtual bool read_input(std::istream &input, const std::string &filename="input file", const std::string &last_line="") 1
virtual bool read_input_from_xml(std::istream &input) 1
void leave_my_subsection(ParameterHandler &prm)
This function undoes what the enter_my_subsection() function did.
static void declare_all_parameters(ParameterHandler &prm=ParameterAcceptor::prm)
Initialize the ParameterHandler with all derived classes parameters.This function enters the subsecti...
std::string type(const T &t)
Return a human readable name of the type passed as argument.
#define Assert(cond, exc)
virtual void parse_parameters(ParameterHandler &prm)
Parse the parameter file.
ParameterAcceptor(const std::string section_name="")
The constructor adds derived classes to the list of acceptors.
#define MYV(type, sep)
vector
std::ostream & print_parameters(std::ostream &out, const OutputStyle style)
std::vector< std::string > split_string_list(const std::string &s, const char delimiter=',')
static void initialize(const std::string filename="", const std::string outfilename="")
Call declare_all_parameters(), read filename (if it is present as input parameter) and parse_all_para...
static::ExceptionBase & ExcNotImplemented()
static void parse_all_parameters(ParameterHandler &prm=ParameterAcceptor::prm)
Parse the given ParameterHandler.
static std::vector< SmartPointer< ParameterAcceptor > > class_list
A list containing all constructed classes of type ParameterAcceptor.
std::map< std::string, boost::any > parameters
A map of parameters that are initialized in this class with the functions add_parameters.
std::vector< std::string > get_section_path() const
Travers all registered classes, and figure out what subsections we need to enter. ...
const unsigned int acceptor_id
The index of this specific class within the class list.
static::ExceptionBase & ExcInternalError()