Skip to content
Snippets Groups Projects
Commit 50f57133 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Initfile with variable replacement

parent 5695b4dd
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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.
......
......@@ -519,6 +519,12 @@ namespace AMDiS {
return exactSolutionFcts[i];
}
///
vector< AbstractFunction<double, WorldVector<double> >* > getExactSolutionFcts()
{
return exactSolutionFcts;
}
///
void setComputeExactError(bool v)
{
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment