Commit c545d0a5 authored by kraus's avatar kraus
Browse files

checking that all design variables occur in the template file; Implements #255

parent dbc17c9f
......@@ -65,20 +65,29 @@ public:
*
* @param[in] outputFile write resulting input file to this file
*/
void writeInputFile(std::string outputFile) {
void writeInputFile(std::string outputFile, const std::set<std::string> &dvarNames) {
std::ifstream infile(tmplFile_.c_str());
std::ostringstream outdata;
outdata.precision(15);
std::map<std::string, short> dvarCheck;
for (auto itr = dvarNames.begin(); itr != dvarNames.end(); ++ itr) {
dvarCheck.insert(std::make_pair(*itr, 0));
}
while(infile.good()) {
std::string line;
std::getline(infile, line, '\n');
//XXX doing the inverse would be better
for(std::map<std::string, std::string>::iterator itr = dictionary_.begin();
itr != dictionary_.end(); itr++) {
std::map<std::string, std::string>::iterator itr = dictionary_.begin();
for(;itr != dictionary_.end(); itr++) {
size_t pos = line.find("_" + itr->first + "_");
if (pos != std::string::npos &&
dvarCheck.find(itr->first) != dvarCheck.end()) {
dvarCheck.at(itr->first) = 1;
}
while(pos != std::string::npos) {
line.replace(pos, itr->first.length() + 2, itr->second);
pos = line.find("_" + itr->first + "_");
......@@ -89,6 +98,13 @@ public:
}
infile.close();
for (auto itr = dvarCheck.begin(); itr != dvarCheck.end(); ++ itr) {
if (itr->second == 0) {
throw OptPilotException("GenerateOpalSimulation::writeInputFile()",
"Couldn't find the design variable '" + itr->first + "' in '" + tmplFile_ + "'!");
}
}
// ensure the contents are written to disk
std::ofstream outfile(outputFile.c_str());
outfile.precision(15);
......
......@@ -64,6 +64,7 @@ OpalSimulation::OpalSimulation(Expressions::Named_t objectives,
std::ostringstream tmp;
tmp.precision(15);
tmp << parameter.first << "=" << parameter.second;
dvarNames_.insert(parameter.first);
dict.push_back(tmp.str());
std::ostringstream value;
......@@ -188,7 +189,7 @@ void OpalSimulation::setupSimulation() {
std::string infile = simulationDirName_ + "/" +
simulationName_ + ".in";
gs_->writeInputFile(infile);
gs_->writeInputFile(infile, dvarNames_);
// linking fieldmaps + distributions
if(getenv("FIELDMAPS") == NULL) {
......
......@@ -92,6 +92,7 @@ private:
Expressions::Named_t objectives_;
Expressions::Named_t constraints_;
std::set<std::string> dvarNames_;
MPI_Comm comm_;
......
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