Commit 50f57133 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Initfile with variable replacement

parent 5695b4dd
...@@ -46,7 +46,7 @@ namespace AMDiS { ...@@ -46,7 +46,7 @@ namespace AMDiS {
// initialize global strcutures using parameters // initialize global strcutures using parameters
Global::init(); Global::init();
} };
/// Fill an initfile from a file with filename fn /// Fill an initfile from a file with filename fn
...@@ -62,7 +62,7 @@ namespace AMDiS { ...@@ -62,7 +62,7 @@ namespace AMDiS {
fn_include_list.insert(fn); fn_include_list.insert(fn);
read(inputFile); read(inputFile);
} }
} };
/// Fill an initfile from an input stream /// Fill an initfile from an input stream
...@@ -80,7 +80,8 @@ namespace AMDiS { ...@@ -80,7 +80,8 @@ namespace AMDiS {
&& sw[pos0] != '#' && sw[pos0] != 0) { && sw[pos0] != '#' && sw[pos0] != 0) {
// parse line and extract map: tag->value // parse line and extract map: tag->value
Parser parser(sw); Parser parser(sw);
operator[](parser.name) = parser.value;
operator[](variableReplacement(InitfileInternal::trim(parser.name))) = variableReplacement(InitfileInternal::trim(parser.value));
} else if (sw[pos0] == '#' } else if (sw[pos0] == '#'
&& static_cast<size_t>(sw.find("#include")) == pos0) { && static_cast<size_t>(sw.find("#include")) == pos0) {
// include file by '#include "filename"' or '#include <filename>' // include file by '#include "filename"' or '#include <filename>'
...@@ -109,7 +110,35 @@ namespace AMDiS { ...@@ -109,7 +110,35 @@ namespace AMDiS {
} }
in.getline(swap, line_length); 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) void Initfile::readArgv(int argc, char **argv)
...@@ -144,7 +173,7 @@ namespace AMDiS { ...@@ -144,7 +173,7 @@ namespace AMDiS {
if (msgInfo == 0) if (msgInfo == 0)
paramInfo = 0; paramInfo = 0;
} };
/// print all parameters to std::cout /// print all parameters to std::cout
...@@ -153,7 +182,7 @@ namespace AMDiS { ...@@ -153,7 +182,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;
} };
/// Write data-map to initfile /// Write data-map to initfile
......
...@@ -581,6 +581,11 @@ protected: ...@@ -581,6 +581,11 @@ protected:
return it->second; 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. /** Fill the initfile from an input stream.
* @param in: the stream to fill the data from. * @param in: the stream to fill the data from.
......
...@@ -519,6 +519,12 @@ namespace AMDiS { ...@@ -519,6 +519,12 @@ namespace AMDiS {
return exactSolutionFcts[i]; return exactSolutionFcts[i];
} }
///
vector< AbstractFunction<double, WorldVector<double> >* > getExactSolutionFcts()
{
return exactSolutionFcts;
}
/// ///
void setComputeExactError(bool v) void setComputeExactError(bool v)
{ {
......
...@@ -6,10 +6,9 @@ elliptMesh->global refinements: 0 ...@@ -6,10 +6,9 @@ elliptMesh->global refinements: 0
ellipt->mesh: elliptMesh ellipt->mesh: elliptMesh
ellipt->dim: 2 ellipt->dim: 2
ellipt->polynomial degree[0]: 1 ellipt->polynomial degree[0]: 1
ellipt->polynomial degree[1]: 1 ellipt->components: 1
ellipt->components: 2
ellipt->solver: umfpack %cg ellipt->solver: cg
ellipt->solver->symmetric strategy: 1 ellipt->solver->symmetric strategy: 1
ellipt->solver->store symbolic: 0 ellipt->solver->store symbolic: 0
ellipt->solver->max iteration: 1000 ellipt->solver->max iteration: 1000
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment