Commit 6374f084 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

addBoundary*Operator, static updateAnimationFile and small changes in Initfile

parent 52419cef
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include <mpi.h> #include <mpi.h>
#endif #endif
#include <boost/algorithm/string.hpp>
#include "boost/tuple/tuple.hpp" #include "boost/tuple/tuple.hpp"
#include "AMDiS_fwd.h" #include "AMDiS_fwd.h"
...@@ -461,6 +462,7 @@ namespace AMDiS { ...@@ -461,6 +462,7 @@ namespace AMDiS {
GRD_PSI, GRD_PSI,
GRD_PHI GRD_PHI
}; };
} }
#endif // AMDIS_GLOBAL_H #endif // AMDIS_GLOBAL_H
......
...@@ -8,25 +8,29 @@ using namespace std; ...@@ -8,25 +8,29 @@ using namespace std;
namespace AMDiS { namespace AMDiS {
/// the small parser for the initfile. see description of read(Initfile&, istream&) /// the small parser for the initfile. see description of
/// read(Initfile&,istream&)
struct Parser { struct Parser {
Parser(const string& line) Parser(const string& line)
{ {
size_t pos = line.find(':'); size_t pos = line.find(':');
if (pos == string::npos) if (pos == string::npos) {
throw runtime_error("cannot find the delimiter ':' in line '" + line + "'"); throw runtime_error("cannot find the delimiter ':' in line "
"'" + line + "'");
}
name = line.substr(0, pos); name = line.substr(0, pos);
value = line.substr(pos + 1, line.length() - (pos + 1)); value = line.substr(pos + 1, line.length() - (pos + 1));
// remove everything after the % // remove everything after the %
pos = value.find('%'); pos = value.find('%');
if (pos != string::npos) if (pos != string::npos)
value = value.substr(0, pos); value = value.substr(0, pos);
} }
string name; string name;
string value; string value;
}; };
Initfile* Initfile::singlett= NULL; Initfile* Initfile::singlett= NULL;
std::set<std::string> Initfile::fn_include_list; std::set<std::string> Initfile::fn_include_list;
...@@ -39,7 +43,7 @@ namespace AMDiS { ...@@ -39,7 +43,7 @@ namespace AMDiS {
fn_include_list.clear(); fn_include_list.clear();
singlett->read(in); singlett->read(in);
singlett->getInternalParameters(); singlett->getInternalParameters();
// initialize global strcutures using parameters // initialize global strcutures using parameters
Global::init(); Global::init();
} }
...@@ -53,8 +57,8 @@ namespace AMDiS { ...@@ -53,8 +57,8 @@ namespace AMDiS {
std::ifstream inputFile; std::ifstream inputFile;
inputFile.open(fn.c_str(), std::ios::in); inputFile.open(fn.c_str(), std::ios::in);
if (!inputFile.is_open()) if (!inputFile.is_open())
throw runtime_error("init-file cannot be opened for reading"); throw runtime_error("init-file cannot be opened for reading");
fn_include_list.insert(fn); fn_include_list.insert(fn);
read(inputFile); read(inputFile);
} }
...@@ -71,34 +75,37 @@ namespace AMDiS { ...@@ -71,34 +75,37 @@ namespace AMDiS {
std::string whitespaces = " \t\r\f"; std::string whitespaces = " \t\r\f";
std::string sw(swap); std::string sw(swap);
size_t pos0 = sw.find_first_not_of(whitespaces); size_t pos0 = sw.find_first_not_of(whitespaces);
if (pos0 != std::string::npos && sw[pos0] != '%' && sw[pos0] != '#' && sw[pos0] != 0) { if (pos0 != std::string::npos && sw[pos0] != '%'
// parse line and extract map: tag->value && sw[pos0] != '#' && sw[pos0] != 0) {
Parser parser(sw); // parse line and extract map: tag->value
operator[](parser.name) = parser.value; Parser parser(sw);
} else if (sw[pos0] == '#' && static_cast<size_t>(sw.find("#include")) == pos0) { operator[](parser.name) = parser.value;
// include file by '#include "filename"' or '#include <filename>' } else if (sw[pos0] == '#'
size_t pos = sw.find_first_not_of(whitespaces, std::string("#include").size() + 1); && static_cast<size_t>(sw.find("#include")) == pos0) {
size_t epos = 0; // include file by '#include "filename"' or '#include <filename>'
std::string fn = ""; size_t pos = sw.find_first_not_of(whitespaces,
std::stringstream errorMsg; std::string("#include").size() + 1);
switch (char c= swap[pos++]) { size_t epos = 0;
case '<': std::string fn = "";
c= '>'; std::stringstream errorMsg;
case '\"': switch (char c= swap[pos++]) {
whitespaces += c; case '<':
epos = sw.find_first_of(whitespaces, pos); c= '>';
fn = sw.substr(pos, epos - pos); case '\"':
whitespaces += c;
if (sw[epos]!=c) { epos = sw.find_first_of(whitespaces, pos);
errorMsg << "filename in #include not terminated by " << c; fn = sw.substr(pos, epos - pos);
throw std::runtime_error(errorMsg.str());
} if (sw[epos]!=c) {
break; errorMsg << "filename in #include not terminated by " << c;
default: throw std::runtime_error(errorMsg.str());
throw std::runtime_error("no filename given for #include"); }
} break;
read(fn); default:
throw std::runtime_error("no filename given for #include");
}
read(fn);
} }
in.getline(swap, line_length); in.getline(swap, line_length);
} }
...@@ -109,8 +116,8 @@ namespace AMDiS { ...@@ -109,8 +116,8 @@ namespace AMDiS {
{ {
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++) {
if (strcmp("-rs", argv[i]) == 0) { if (strcmp("-rs", argv[i]) == 0) {
std::string input(argv[i + 1]); std::string input(argv[i + 1]);
add("argv->rs", input, 0); add("argv->rs", input, 0);
} }
} }
} }
...@@ -122,15 +129,15 @@ namespace AMDiS { ...@@ -122,15 +129,15 @@ namespace AMDiS {
int val = 0; int val = 0;
get("level of information", val, 0); get("level of information", val, 0);
msgInfo = val; msgInfo = val;
val = 1; val = 1;
get("WAIT", val, 0); get("WAIT", val, 0);
msgWait = val; msgWait = val;
val = 1; val = 1;
get("parameter information", val, 0); get("parameter information", val, 0);
paramInfo = val; paramInfo = val;
val = 0; val = 0;
get("break on missing tag", val, 0); get("break on missing tag", val, 0);
breakOnMissingTag = val; breakOnMissingTag = val;
...@@ -145,7 +152,7 @@ namespace AMDiS { ...@@ -145,7 +152,7 @@ namespace AMDiS {
{ {
initIntern(); initIntern();
for (Initfile::iterator it = singlett->begin(); it != singlett->end(); it++) for (Initfile::iterator it = singlett->begin(); it != singlett->end(); it++)
std::cout << (*it).first << " => " << (*it).second << std::endl; std::cout << (*it).first << " => " << (*it).second << std::endl;
} }
...@@ -153,7 +160,7 @@ namespace AMDiS { ...@@ -153,7 +160,7 @@ namespace AMDiS {
void Initfile::write(ostream& out) void Initfile::write(ostream& out)
{ {
for (Initfile::iterator it = begin() ; it!=end(); it++) for (Initfile::iterator it = begin() ; it!=end(); it++)
out << (*it).first << ": " << (*it).second << std::endl; out << (*it).first << ": " << (*it).second << std::endl;
} }
...@@ -164,8 +171,7 @@ namespace AMDiS { ...@@ -164,8 +171,7 @@ namespace AMDiS {
outFile.open(fn.c_str(), std::ios::out); outFile.open(fn.c_str(), std::ios::out);
if (!outFile.is_open()) if (!outFile.is_open())
throw runtime_error("init-file cannot be opened for writing"); throw runtime_error("init-file cannot be opened for writing");
write(outFile); write(outFile);
} }
} // end namespace AMDiS
}
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.
#ifndef INITFILE_H #ifndef INITFILE_H
#define INITFILE_H #define INITFILE_H
...@@ -25,23 +36,25 @@ ...@@ -25,23 +36,25 @@
namespace AMDiS { namespace AMDiS {
namespace InitfileInternal { namespace InitfileInternal {
/// Exceptions /// Exceptions
struct WrongVectorSize : std::runtime_error { struct WrongVectorSize : std::runtime_error {
WrongVectorSize(std::string m) WrongVectorSize(std::string m)
: std::runtime_error(m) : std::runtime_error(m)
{} {}
}; };
struct NoDelim : std::runtime_error { struct NoDelim : std::runtime_error {
NoDelim(std::string m) NoDelim(std::string m)
: std::runtime_error(m) : std::runtime_error(m)
{} {}
}; };
struct WrongVectorFormat : std::runtime_error { struct WrongVectorFormat : std::runtime_error {
WrongVectorFormat(std::string m) WrongVectorFormat(std::string m)
: std::runtime_error(m) : std::runtime_error(m)
{} {}
}; };
...@@ -49,33 +62,33 @@ namespace AMDiS { ...@@ -49,33 +62,33 @@ namespace AMDiS {
struct WrongValueFormat : std::runtime_error { struct WrongValueFormat : std::runtime_error {
static std::string name(int) static std::string name(int)
{ {
return "int"; return "int";
} }
static std::string name(bool) static std::string name(bool)
{ {
return "bool"; return "bool";
} }
static std::string name(double) static std::string name(double)
{ {
return "double"; return "double";
} }
static std::string name(unsigned int) static std::string name(unsigned int)
{ {
return "unsigned int"; return "unsigned int";
} }
template<typename G> template<typename G>
static std::string name(G) static std::string name(G)
{ {
return std::string(typeid(G).name()); return std::string(typeid(G).name());
} }
WrongValueFormat(std::string value) WrongValueFormat(std::string value)
: std::runtime_error(std::string("cannot convert '") + : std::runtime_error(std::string("cannot convert '") +
value + std::string("' into <") + name(T()) + ">") value + std::string("' into <") + name(T()) + ">")
{} {}
}; };
...@@ -83,38 +96,38 @@ namespace AMDiS { ...@@ -83,38 +96,38 @@ namespace AMDiS {
struct BadArithmeticExpression : std::runtime_error { struct BadArithmeticExpression : std::runtime_error {
static std::string name(int) static std::string name(int)
{ {
return "int"; return "int";
} }
static std::string name(bool) static std::string name(bool)
{ {
return "bool"; return "bool";
} }
static std::string name(double) static std::string name(double)
{ {
return "double"; return "double";
} }
static std::string name(unsigned int) static std::string name(unsigned int)
{ {
return "unsigned int"; return "unsigned int";
} }
template<typename G> template<typename G>
static std::string name(G) static std::string name(G)
{ {
return std::string(typeid(G).name()); return std::string(typeid(G).name());
} }
BadArithmeticExpression(std::string m, std::string value) BadArithmeticExpression(std::string m, std::string value)
: std::runtime_error(std::string("cannot evaluate expression '") + : std::runtime_error(std::string("cannot evaluate expression '") +
value + std::string("' into <") + name(T()) + value + std::string("' into <") + name(T()) +
">\nParser message: '" + m + "'") ">\nParser message: '" + m + "'")
{} {}
}; };
/// trim std::string /// trim std::string
inline std::string trim(const std::string& oldStr) inline std::string trim(const std::string& oldStr)
{ {
...@@ -124,14 +137,15 @@ namespace AMDiS { ...@@ -124,14 +137,15 @@ namespace AMDiS {
} }
/// return the delimiter or throw an exception if there is no known delimiter in value /// return the delimiter or throw an exception if there is no known
/// delimiter in value
inline size_t checkDelim(const std::string& value, const std::string& delims) inline size_t checkDelim(const std::string& value, const std::string& delims)
{ {
size_t pos(std::string::npos); size_t pos(std::string::npos);
for (unsigned i = 0; i < delims.length(); i++) { for (unsigned i = 0; i < delims.length(); i++) {
pos = value.find(delims[i]); pos = value.find(delims[i]);
if (pos != std::string::npos) if (pos != std::string::npos)
return i; return i;
} }
throw NoDelim("cannot detect the delimiter in " + value); throw NoDelim("cannot detect the delimiter in " + value);
return 0; return 0;
...@@ -139,12 +153,12 @@ namespace AMDiS { ...@@ -139,12 +153,12 @@ namespace AMDiS {
/** parse an container from tag tag. The Container must have the properties: /** parse an container from tag tag. The Container must have the properties:
* - type value_type * - type value_type
* - member function push_back * - member function push_back
*/ */
template< typename Container > template< typename Container >
inline void getContainer(const std::string val_, Container& c) inline void getContainer(const std::string val_, Container& c)
{ {
// accepted brackets and delimiters for vector input // accepted brackets and delimiters for vector input
std::string begBrackets= "{[("; std::string begBrackets= "{[(";
std::string endBrackets= "}])"; std::string endBrackets= "}])";
...@@ -154,35 +168,37 @@ namespace AMDiS { ...@@ -154,35 +168,37 @@ namespace AMDiS {
std::string val = trim(val_); std::string val = trim(val_);
size_t pos = begBrackets.find(val[0]); size_t pos = begBrackets.find(val[0]);
if (pos == std::string::npos) if (pos == std::string::npos)
throw WrongVectorFormat("cannot convert '" + val + "' into a list. No leading bracket found!"); throw WrongVectorFormat("cannot convert "
"'" + val + "' into a list. No leading bracket found!");
if (val[val.length() - 1] != endBrackets[pos]) if (val[val.length() - 1] != endBrackets[pos])
throw WrongVectorFormat("begin and end bracket are different in value '" + val + "'"); throw WrongVectorFormat("begin and end bracket are different in"
" value '" + val + "'");
size_t oldPos = 1; size_t oldPos = 1;
size_t curDelim = 0; size_t curDelim = 0;
typedef typename Container::value_type ValueType; typedef typename Container::value_type ValueType;
ValueType swap; ValueType swap;
try { try {
curDelim = checkDelim(val, delims); curDelim = checkDelim(val, delims);
pos = val.find(delims[curDelim], oldPos); pos = val.find(delims[curDelim], oldPos);
while (pos != std::string::npos) { while (pos != std::string::npos) {
std::string curWord = val.substr(oldPos, pos - oldPos); std::string curWord = val.substr(oldPos, pos - oldPos);
oldPos = pos + 1; oldPos = pos + 1;
convert(curWord, swap); convert(curWord, swap);
c.push_back(swap); c.push_back(swap);
pos= val.find(delims[curDelim], oldPos); pos = val.find(delims[curDelim], oldPos);
} }
//last entry //last entry
std::string curWord = val.substr(oldPos, val.length() - 1 - oldPos); std::string curWord = val.substr(oldPos, val.length() - 1 - oldPos);
convert(curWord, swap); convert(curWord, swap);
c.push_back(swap); c.push_back(swap);
} catch (NoDelim nd) { } catch (NoDelim nd) {
std::string curWord = val.substr(1, val.length() - 2); std::string curWord = val.substr(1, val.length() - 2);
curWord = trim(curWord); curWord = trim(curWord);
if (curWord.length() > 0) { if (curWord.length() > 0) {
// container with one entry // container with one entry
convert(curWord, swap); convert(curWord, swap);
c.push_back(swap); c.push_back(swap);
} }
} }
} }
...@@ -197,43 +213,62 @@ namespace AMDiS { ...@@ -197,43 +213,62 @@ namespace AMDiS {
/// convert string to intrinsic type /// convert string to intrinsic type
template<typename T> template<typename T>
inline void convert(const std::string valStr, T& value , inline void convert(const std::string valStr, T& value ,
typename boost::enable_if<boost::is_pod<T> >::type* p = NULL , typename boost::enable_if<boost::is_pod<T> >::type* p = NULL ,
typename boost::disable_if<boost::is_enum<T> >::type* p2 = NULL) typename boost::disable_if<boost::is_enum<T> >::type* p2 = NULL)
{ {
using boost::lexical_cast; using boost::lexical_cast;
using boost::numeric_cast; using boost::numeric_cast;
mu::Parser parser; mu::Parser parser;
parser.DefineConst(_T("M_PI"), m_pi); parser.DefineConst(_T("M_PI"), m_pi);
parser.DefineConst(_T("M_E"), m_e); parser.DefineConst(_T("M_E"), m_e);
try { try {
parser.SetExpr(valStr); parser.SetExpr(valStr);
value = numeric_cast< T >(parser.Eval()); value = numeric_cast< T >(parser.Eval());
} catch(boost::bad_lexical_cast e) { } catch (boost::bad_lexical_cast e) {
throw WrongValueFormat< T >(valStr); throw WrongValueFormat< T >(valStr);
} catch(boost::bad_numeric_cast e) { } catch (boost::bad_numeric_cast e) {
throw WrongValueFormat< T >(valStr); throw WrongValueFormat< T >(valStr);
} catch (mu::Parser::exception_type &e) { } catch (mu::Parser::exception_type &e) {
throw BadArithmeticExpression<T>(e.GetMsg(), valStr); throw BadArithmeticExpression<T>(e.GetMsg(), valStr);
} }
} }
template<typename T> template<typename T>
inline void convert(const std::string valStr, T& value, inline void convert(const std::string valStr, T& value,
typename boost::enable_if< boost::is_enum< T > >::type* p = NULL) typename boost::enable_if< boost::is_enum< T > >::type* p = NULL)