diff --git a/AMDiS/src/Initfile.cc b/AMDiS/src/Initfile.cc index d0aef6f9d08381c5c4ba1af23ae69bc81005892b..f36c36d604ca77ac30dcba020d1e3fd2ea037a91 100644 --- a/AMDiS/src/Initfile.cc +++ b/AMDiS/src/Initfile.cc @@ -46,7 +46,7 @@ namespace AMDiS { // initialize global strcutures using parameters Global::init(); - } + }; /// Fill an initfile from a file with filename fn @@ -62,7 +62,7 @@ namespace AMDiS { fn_include_list.insert(fn); read(inputFile); } - } + }; /// Fill an initfile from an input stream @@ -80,7 +80,8 @@ namespace AMDiS { && sw[pos0] != '#' && sw[pos0] != 0) { // parse line and extract map: tag->value Parser parser(sw); - operator[](parser.name) = parser.value; + + operator[](variableReplacement(InitfileInternal::trim(parser.name))) = variableReplacement(InitfileInternal::trim(parser.value)); } else if (sw[pos0] == '#' && static_cast<size_t>(sw.find("#include")) == pos0) { // include file by '#include "filename"' or '#include <filename>' @@ -109,7 +110,35 @@ namespace AMDiS { } in.getline(swap, line_length); } - } + }; + + + std::string Initfile::variableReplacement(const std::string& input) const + { + std::string whitespaces = " \t\r\f"; + std::string inputSwap = input; + size_t posVar = inputSwap.find_first_of('$'); + while (posVar != string::npos) { + size_t posVarBegin, posVarEnd; + if(inputSwap[posVar+1] == '{') { + posVarEnd = inputSwap.find_first_of('}',posVar + 2); + posVarBegin = posVar + 1; + } else { + posVarEnd = inputSwap.find_first_of(whitespaces, posVar + 1); + posVarBegin = posVar; + } + std::string varName = inputSwap.substr(posVarBegin + 1 , posVarEnd - posVarBegin - 1); + std::string varParam = checkedGet(varName); + // if varname is found in parameter list then replace variable by value + // otherwise throw tarNotFound exception + std::string replaceName = inputSwap.substr(posVar , posVarEnd - posVar + (posVarBegin - posVar)); + inputSwap.replace(inputSwap.find(replaceName), replaceName.length(), varParam); + + posVar = inputSwap.find_first_of('$'); + } + + return inputSwap; + }; void Initfile::readArgv(int argc, char **argv) @@ -144,7 +173,7 @@ namespace AMDiS { if (msgInfo == 0) paramInfo = 0; - } + }; /// print all parameters to std::cout @@ -153,7 +182,7 @@ namespace AMDiS { initIntern(); for (Initfile::iterator it = singlett->begin(); it != singlett->end(); it++) std::cout << (*it).first << " => " << (*it).second << std::endl; - } + }; /// Write data-map to initfile diff --git a/AMDiS/src/Initfile.h b/AMDiS/src/Initfile.h index e23c021001b9842ae6fbf2b9d129c9c39d2af090..9e20c6262bb93543476647fed176358026070be7 100644 --- a/AMDiS/src/Initfile.h +++ b/AMDiS/src/Initfile.h @@ -581,6 +581,11 @@ protected: return it->second; } + /// replace variables by its value defined as parameter previousely + /// variable definition is simple parameter definition + /// variable evaluation by ${variablename} or $variablename + /// the last version only for variablenames without whitespaces + std::string variableReplacement(const std::string& input) const; /** Fill the initfile from an input stream. * @param in: the stream to fill the data from. diff --git a/AMDiS/src/ProblemStat.h b/AMDiS/src/ProblemStat.h index a04a3aa5f59adfa5bc0ac7c2612590c0d7ec4381..75ee265f8298c93bf17759ff36d0751301b936b9 100644 --- a/AMDiS/src/ProblemStat.h +++ b/AMDiS/src/ProblemStat.h @@ -519,6 +519,12 @@ namespace AMDiS { return exactSolutionFcts[i]; } + /// + vector< AbstractFunction<double, WorldVector<double> >* > getExactSolutionFcts() + { + return exactSolutionFcts; + } + /// void setComputeExactError(bool v) { diff --git a/demo/init/ellipt.dat.2d b/demo/init/ellipt.dat.2d index 3a5ce968831e1b319b8134a10bbf2c5b0e23efc9..56a2be30f1033e3ba3472dc3bb011829a4d28527 100644 --- a/demo/init/ellipt.dat.2d +++ b/demo/init/ellipt.dat.2d @@ -6,10 +6,9 @@ elliptMesh->global refinements: 0 ellipt->mesh: elliptMesh ellipt->dim: 2 ellipt->polynomial degree[0]: 1 -ellipt->polynomial degree[1]: 1 -ellipt->components: 2 +ellipt->components: 1 -ellipt->solver: umfpack %cg +ellipt->solver: cg ellipt->solver->symmetric strategy: 1 ellipt->solver->store symbolic: 0 ellipt->solver->max iteration: 1000