diff --git a/CTestConfig.cmake b/CTestConfig.cmake index 1b394e5d2..3495a9553 100644 --- a/CTestConfig.cmake +++ b/CTestConfig.cmake @@ -1,43 +1,43 @@ #=============================================================================== # @file CTestConfig.cmake # # @author Nicolas Richart # # @date Thu Jan 06 12:12:51 2011 # # @brief configuration for ctest # # @section LICENSE # # Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) # Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) # # Akantu is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Akantu 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 Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with Akantu. If not, see . # #=============================================================================== ## This file should be placed in the root directory of your project. ## Then modify the CMakeLists.txt file in the root directory of your ## project to incorporate the testing dashboard. ## # The following are required to uses Dart and the Cdash dashboard ## ENABLE_TESTING() ## INCLUDE(CTest) set(CTEST_PROJECT_NAME "Akantu") set(CTEST_NIGHTLY_START_TIME "06:10:00 EST") set(CTEST_CMAKE_GENERATOR "Unix Makefiles") -set(CTEST_DROP_METHOD "https") +set(CTEST_DROP_METHOD "http") set(CTEST_DROP_SITE "lsmssrv1.epfl.ch") set(CTEST_DROP_LOCATION "/CDash/submit.php?project=Akantu") set(CTEST_DROP_SITE_CDASH TRUE) diff --git a/src/io/parser/parser.cc b/src/io/parser/parser.cc index d456a4585..099691ace 100644 --- a/src/io/parser/parser.cc +++ b/src/io/parser/parser.cc @@ -1,221 +1,221 @@ /** * @file parser.cc * * @author Nicolas Richart * * @date Fri Aug 2 12:14:15 2013 * * @brief implementation of the parser * * @section LICENSE * * Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ // STL #include #include #include /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "parser.hh" #include "static_communicator.hh" /* -------------------------------------------------------------------------- */ //#include #include #include #include /* -------------------------------------------------------------------------- */ #include "algebraic_parser.hh" #include "input_file_parser.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ /* -------------------------------------------------------------------------- */ ParserSection::~ParserSection() { } /* -------------------------------------------------------------------------- */ ParserParameter & ParserSection::addParameter(const ParserParameter & param) { if(parameters.find(param.getName()) != parameters.end()) AKANTU_EXCEPTION("The parameter \"" + param.getName() + "\" is already defined in this section"); return (parameters.insert (std::pair(param.getName(), param)).first->second); } /* -------------------------------------------------------------------------- */ ParserSection & ParserSection::addSubSection(const ParserSection & section) { return ((sub_sections_by_type.insert (std::pair(section.getType(), section)))->second); } /* -------------------------------------------------------------------------- */ std::string Parser::getLastParsedFile() const { return last_parsed_file; } /* -------------------------------------------------------------------------- */ void Parser::parse(const std::string& filename) { std::ifstream input(filename.c_str()); input.unsetf(std::ios::skipws); // wrap istream into iterator spirit::istream_iterator fwd_begin(input); spirit::istream_iterator fwd_end; // wrap forward iterator with position iterator, to record the position typedef spirit::classic::position_iterator2 pos_iterator_type; pos_iterator_type position_begin(fwd_begin, fwd_end, filename); pos_iterator_type position_end; // parse parser::InputFileGrammar ag(this); bool result = qi::phrase_parse(position_begin, position_end, ag, ag.skipper); if(!result || position_begin != position_end) { spirit::classic::file_position pos = position_begin.get_position(); AKANTU_EXCEPTION("Parse error [ " << ag.getErrorMessage() << " ]" << " in file " << filename << " line " << pos.line << " column " << pos.column << std::endl << "'" << position_begin.get_currentline() << "'" << std::endl << std::setw(pos.column) << " " << "^- here"); } try { DebugLevel dbl = debug::getDebugLevel(); debug::setDebugLevel(dblError); bool permissive = getParameter("parser_permissive", _ppsc_current_scope); debug::setDebugLevel(dbl); parser_permissive = permissive; AKANTU_DEBUG_INFO("Parser switched permissive mode to " << std::boolalpha << parser_permissive); } catch (debug::Exception & e) { } last_parsed_file = filename; input.close(); } /* -------------------------------------------------------------------------- */ template T Parser::parseType(const std::string & value, Grammar & grammar) { using boost::spirit::ascii::space; std::string::const_iterator b = value.begin(); std::string::const_iterator e = value.end(); T resultat = T(); bool res = false; try { res = qi::phrase_parse(b, e, grammar, space, resultat); } catch(debug::Exception & ex) { AKANTU_EXCEPTION("Could not parse '" << value << "' as a " << debug::demangle(typeid(T).name()) << ", an unknown error append '" << ex.what()); } if(!res || (b != e)) { AKANTU_EXCEPTION("Could not parse '" << value << "' as a " << debug::demangle(typeid(T).name()) << ", an unknown error append '" << std::string(value.begin(), b) << "" << std::string(b, e) << "'"); } return resultat; } /* -------------------------------------------------------------------------- */ Real Parser::parseReal(const std::string & value, const ParserSection & section) { using boost::spirit::ascii::space_type; parser::AlgebraicGrammar grammar(section); return Parser::parseType(value, grammar); } /* -------------------------------------------------------------------------- */ Vector Parser::parseVector(const std::string & value, const ParserSection & section) { using boost::spirit::ascii::space_type; parser::VectorGrammar grammar(section); return Parser::parseType(value, grammar); } /* -------------------------------------------------------------------------- */ Matrix Parser::parseMatrix(const std::string & value, const ParserSection & section) { using boost::spirit::ascii::space_type; parser::MatrixGrammar grammar(section); return Parser::parseType(value, grammar); } /* -------------------------------------------------------------------------- */ RandomParameter Parser::parseRandomParameter(const std::string & value, const ParserSection & section) { using boost::spirit::ascii::space_type; parser::RandomGeneratorGrammar grammar(section); parser::ParsableRandomGenerator rg = Parser::parseType(value, grammar); Vector params = rg.parameters; switch(rg.type) { case _rdt_not_defined: return RandomParameter(rg.base); case _rdt_uniform: return RandomParameter(rg.base, UniformDistribution(params(0), params(1))); case _rdt_weibull: return RandomParameter(rg.base, WeibullDistribution(params(0), params(1))); default: AKANTU_EXCEPTION("This is an unknown random distribution in the parser"); } } /* -------------------------------------------------------------------------- */ void ParserSection::printself(std::ostream & stream, unsigned int indent) const { std::string space; std::string ind = AKANTU_INDENT; for(unsigned int i = 0; i < indent; i++, space += ind); stream << space << "Section(" << this->type << ") " << this->name << (option != "" ? (" " + option) : "") << " [" << std::endl; if(!this->parameters.empty()) { stream << space << ind << "Parameters [" << std::endl; Parameters::const_iterator pit = this->parameters.begin(); for(;pit != this->parameters.end(); ++pit) { stream << space << ind << " + "; pit->second.printself(stream); stream << std::endl; } stream << space << ind << "]" << std::endl; } if(!this->sub_sections_by_type.empty()) { stream << space << ind << "Subsections [" << std::endl; SubSections::const_iterator sit = this->sub_sections_by_type.begin(); for (;sit != this->sub_sections_by_type.end(); ++sit) sit->second.printself(stream, indent + 2); stream << std::endl; stream << space << ind << "]" << std::endl; } - stream << space << "]"; + stream << space << "]" << std::endl; } __END_AKANTU__ diff --git a/src/io/parser/parser.hh b/src/io/parser/parser.hh index 62b558230..02a5fe837 100644 --- a/src/io/parser/parser.hh +++ b/src/io/parser/parser.hh @@ -1,403 +1,404 @@ /** * @file boost_spirit_parser.cc * * @author Nicolas Richart * * @date Wed Jul 24 11:34:23 2013 * * @brief * * @section LICENSE * * Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "aka_random_generator.hh" /* -------------------------------------------------------------------------- */ #include /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_PARSER_HH__ #define __AKANTU_PARSER_HH__ __BEGIN_AKANTU__ #define AKANTU_SECTION_TYPES \ (global) \ (material) \ (model) \ + (mesh) \ (heat) \ (contact) \ (friction) \ (rules) \ (non_local) \ (user) \ (not_defined) #define AKANTU_SECTION_TYPES_PREFIX(elem) BOOST_PP_CAT(_st_, elem) #define AKANTU_SECT_PREFIX(s, data, elem) AKANTU_SECTION_TYPES_PREFIX(elem) enum SectionType { BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_TRANSFORM(AKANTU_SECT_PREFIX, _, AKANTU_SECTION_TYPES)) }; #undef AKANTU_SECT_PREFIX #define AKANTU_SECTION_TYPE_PRINT_CASE(r, data, elem) \ case AKANTU_SECTION_TYPES_PREFIX(elem): { \ stream << BOOST_PP_STRINGIZE(AKANTU_SECTION_TYPES_PREFIX(elem)); \ break; \ } inline std::ostream & operator <<(std::ostream & stream, SectionType type) { switch(type) { BOOST_PP_SEQ_FOR_EACH(AKANTU_SECTION_TYPE_PRINT_CASE, _, AKANTU_SECTION_TYPES) default: stream << "not a SectionType"; break; } return stream; } #undef AKANTU_SECTION_TYPE_PRINT_CASE enum ParserParameterSearchCxt { _ppsc_current_scope = 0x1, _ppsc_parent_scope = 0x2, _ppsc_current_and_parent_scope = 0x3 }; /* ------------------------------------------------------------------------ */ /* Parameters Class */ /* ------------------------------------------------------------------------ */ class ParserSection; class ParserParameter { public: ParserParameter() : parent_section(NULL), name(std::string()), value(std::string()), dbg_filename(std::string()) {} ParserParameter(const std::string & name, const std::string & value, const ParserSection & parent_section) : parent_section(&parent_section), name(name), value(value), dbg_filename(std::string()) {} ParserParameter(const ParserParameter & param) : parent_section(param.parent_section), name(param.name), value(param.value), dbg_filename(param.dbg_filename), dbg_line(param.dbg_line), dbg_column(param.dbg_column) {} virtual ~ParserParameter() {} const std::string & getName() const { return name; } const std::string & getValue() const { return value; } void setDebugInfo(const std::string & filename, UInt line, UInt column) { dbg_filename = filename; dbg_line = line; dbg_column = column; } template inline operator T() const; // template inline operator Vector() const; // template inline operator Matrix() const; void printself(std::ostream & stream, unsigned int indent = 0) const { stream << name << ": " << value << " (" << dbg_filename << ":" << dbg_line << ":" << dbg_column << ")"; } private: void setParent(const ParserSection & sect) { parent_section = § } friend class ParserSection; private: const ParserSection * parent_section; std::string name; std::string value; std::string dbg_filename; UInt dbg_line, dbg_column; }; /* ------------------------------------------------------------------------ */ /* Sections Class */ /* ------------------------------------------------------------------------ */ class ParserSection { public: typedef std::multimap SubSections; typedef std::map Parameters; private: typedef SubSections::const_iterator const_section_iterator_; public: /* ------------------------------------------------------------------------ */ /* SubSection iterator */ /* ------------------------------------------------------------------------ */ class const_section_iterator { public: const_section_iterator(const const_section_iterator & other) : it(other.it) { } const_section_iterator(const const_section_iterator_ & it) : it(it) { } const_section_iterator & operator=(const const_section_iterator & other) { if(this != &other) { it = other.it; } return *this; } const ParserSection & operator* () const { return it->second; } const ParserSection * operator-> () const { return &(it->second); } bool operator==(const const_section_iterator & other) const { return it == other.it; } bool operator!=(const const_section_iterator & other) const { return it != other.it; } const_section_iterator & operator++() { ++it; return *this; } const_section_iterator operator++(int) { const_section_iterator tmp = *this; operator++(); return tmp; } private: const_section_iterator_ it; }; /* ------------------------------------------------------------------------ */ /* Parameters iterator */ /* ------------------------------------------------------------------------ */ class const_parameter_iterator { public: const_parameter_iterator(const const_parameter_iterator & other) : it(other.it) { } const_parameter_iterator(const Parameters::const_iterator & it) : it(it) { } const_parameter_iterator & operator=(const const_parameter_iterator & other) { if(this != &other) { it = other.it; } return *this; } const ParserParameter & operator* () const { return it->second; } const ParserParameter * operator->() { return &(it->second); }; bool operator==(const const_parameter_iterator & other) const { return it == other.it; } bool operator!=(const const_parameter_iterator & other) const { return it != other.it; } const_parameter_iterator & operator++() { ++it; return *this; } const_parameter_iterator operator++(int) { const_parameter_iterator tmp = *this; operator++(); return tmp; } private: Parameters::const_iterator it; }; /* ---------------------------------------------------------------------- */ ParserSection() : parent_section(NULL), name(std::string()), type(_st_not_defined){} ParserSection(const std::string & name, SectionType type) : parent_section(NULL), name(name), type(type) {} ParserSection(const std::string & name, SectionType type, const std::string & option, const ParserSection & parent_section) : parent_section(&parent_section), name(name), type(type), option(option) {} ParserSection(const ParserSection & section) : parent_section(section.parent_section), name(section.name), type(section.type), option(section.option), parameters(section.parameters), sub_sections_by_type(section.sub_sections_by_type) { setChldrenPointers(); } ParserSection & operator=(const ParserSection & other) { if(&other != this) { parent_section = other.parent_section; name = other.name; type = other.type; option = other.option; parameters = other.parameters; sub_sections_by_type = sub_sections_by_type; setChldrenPointers(); } return *this; } virtual ~ParserSection(); virtual void printself(std::ostream & stream, unsigned int indent = 0) const; /* ---------------------------------------------------------------------- */ /* Creation functions */ /* ---------------------------------------------------------------------- */ public: ParserParameter & addParameter(const ParserParameter & param); ParserSection & addSubSection(const ParserSection & section); private: void setChldrenPointers() { Parameters::iterator pit = this->parameters.begin(); for(;pit != this->parameters.end(); ++pit) pit->second.setParent(*this); SubSections::iterator sit = this->sub_sections_by_type.begin(); for (;sit != this->sub_sections_by_type.end(); ++sit) sit->second.setParent(*this); } /* ---------------------------------------------------------------------- */ /* Accessors */ /* ---------------------------------------------------------------------- */ public: std::pair getSubSections(SectionType type = _st_not_defined) const { if(type != _st_not_defined) { std::pair range = sub_sections_by_type.equal_range(type); return std::pair(range.first, range.second); } else { return std::pair(sub_sections_by_type.begin(), sub_sections_by_type.end()); } } std::pair getParameters() const { return std::pair(parameters.begin(), parameters.end()); } /* ---------------------------------------------------------------------- */ const ParserParameter & getParameter(const std::string & name, ParserParameterSearchCxt search_ctx = _ppsc_current_scope) const { Parameters::const_iterator it; if(search_ctx & _ppsc_current_scope) it = parameters.find(name); if(it == parameters.end()) { if((search_ctx & _ppsc_parent_scope) && parent_section) return parent_section->getParameter(name, search_ctx); else { AKANTU_SILENT_EXCEPTION("The parameter " << name << " has not been found in the specified context"); } } return it->second; } /* ------------------------------------------------------------------------ */ bool hasParameter(const std::string & name, ParserParameterSearchCxt search_ctx = _ppsc_current_scope) const { Parameters::const_iterator it; if(search_ctx & _ppsc_current_scope) it = parameters.find(name); if(it == parameters.end()) { if((search_ctx & _ppsc_parent_scope) && parent_section) return parent_section->hasParameter(name, search_ctx); else { return false; } } return true; } /* -------------------------------------------------------------------------- */ template T getParameterValue(const std::string & name, ParserParameterSearchCxt search_ctx = _ppsc_current_scope) const { const ParserParameter & tmp_param = getParameter(name, search_ctx); T t = tmp_param; return t; } /* -------------------------------------------------------------------------- */ const std::string & getName() const { return name; } const SectionType & getType() const { return type; } const std::string & getOption() const { return option; } protected: void setParent(const ParserSection & sect) { parent_section = § } /* ---------------------------------------------------------------------- */ /* Members */ /* ---------------------------------------------------------------------- */ private: const ParserSection * parent_section; std::string name; SectionType type; std::string option; Parameters parameters; SubSections sub_sections_by_type; }; /* ------------------------------------------------------------------------ */ /* Parser Class */ /* ------------------------------------------------------------------------ */ class Parser : public ParserSection { public: Parser() : ParserSection("global", _st_global) {} void parse(const std::string & filename); std::string getLastParsedFile() const; static bool isPermissive() { return parser_permissive; } public: static Real parseReal (const std::string & value, const ParserSection & section); static Vector parseVector(const std::string & value, const ParserSection & section); static Matrix parseMatrix(const std::string & value, const ParserSection & section); static RandomParameter parseRandomParameter(const std::string & value, const ParserSection & section); protected: template static T parseType(const std::string & value, Grammar & grammar); protected: friend class Parsable; static bool parser_permissive; std::string last_parsed_file; }; inline std::ostream & operator <<(std::ostream & stream, const ParserParameter &_this) { _this.printself(stream); return stream; } inline std::ostream & operator <<(std::ostream & stream, const ParserSection & section) { section.printself(stream); return stream; } __END_AKANTU__ #include "parser_tmpl.hh" #endif /* __AKANTU_PARSER_HH__ */