Commit ef720067 authored by kraus's avatar kraus
Browse files

better solution for #255: don't have to check whethre design variables occur...

better solution for #255: don't have to check whethre design variables occur in template file with every simulation run, just once
parent c1cf5f63
......@@ -65,17 +65,12 @@ public:
*
* @param[in] outputFile write resulting input file to this file
*/
void writeInputFile(std::string outputFile, const std::set<std::string> &dvarNames) {
void writeInputFile(std::string outputFile) {
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');
......@@ -84,10 +79,6 @@ public:
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 + "_");
......@@ -98,13 +89,6 @@ 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);
......
......@@ -189,7 +189,7 @@ void OpalSimulation::setupSimulation() {
std::string infile = simulationDirName_ + "/" +
simulationName_ + ".in";
gs_->writeInputFile(infile, dvarNames_);
gs_->writeInputFile(infile);
// linking fieldmaps + distributions
if(getenv("FIELDMAPS") == NULL) {
......
......@@ -412,6 +412,46 @@ void OptimizeCmd::execute() {
}
}
{
std::string tmplFile = Attributes::getString(itsAttr[INPUT]);
size_t pos = tmplFile.find_last_of("/");
if(pos != std::string::npos)
tmplFile = tmplFile.substr(pos+1);
pos = tmplFile.find(".");
tmplFile = tmplFile.substr(0,pos);
tmplFile = Attributes::getString(itsAttr[TEMPLATEDIR]) + "/" + tmplFile + ".tmpl";
std::ifstream infile(tmplFile.c_str());
std::map<std::string, short> dvarCheck;
auto itr = dvars.begin();
for (; itr != dvars.end(); ++ itr) {
dvarCheck.insert(std::make_pair(boost::get<0>(itr->second), 0));
}
while(infile.good()) {
std::string line;
std::getline(infile, line, '\n');
//XXX doing the inverse would be better
for(auto &check: dvarCheck) {
size_t pos = line.find("_" + check.first + "_");
if (pos != std::string::npos &&
dvarCheck.find(check.first) != dvarCheck.end()) {
dvarCheck.at(check.first) = 1;
}
}
}
infile.close();
for (auto itr = dvarCheck.begin(); itr != dvarCheck.end(); ++ itr) {
if (itr->second == 0) {
throw OpalException("SampleCmd::execute()",
"Couldn't find the design variable '" + itr->first + "' in '" + tmplFile + "'!");
}
}
}
Inform *origGmsg = gmsg;
gmsg = 0;
stashEnvironment();
......
......@@ -333,7 +333,6 @@ void SampleCmd::execute() {
dir = path;
}
*gmsg << dir.native() << endl;
if (!fs::exists(dir)) {
fs::create_directory(dir);
}
......@@ -375,6 +374,46 @@ void SampleCmd::execute() {
setenv("DISTRIBUTIONS", dir.c_str(), 1);
}
{
std::string tmplFile = Attributes::getString(itsAttr[INPUT]);
size_t pos = tmplFile.find_last_of("/");
if(pos != std::string::npos)
tmplFile = tmplFile.substr(pos+1);
pos = tmplFile.find(".");
tmplFile = tmplFile.substr(0,pos);
tmplFile = Attributes::getString(itsAttr[TEMPLATEDIR]) + "/" + tmplFile + ".tmpl";
std::ifstream infile(tmplFile.c_str());
std::map<std::string, short> dvarCheck;
auto itr = dvars.begin();
for (; itr != dvars.end(); ++ itr) {
dvarCheck.insert(std::make_pair(boost::get<0>(itr->second), 0));
}
while(infile.good()) {
std::string line;
std::getline(infile, line, '\n');
//XXX doing the inverse would be better
for(auto &check: dvarCheck) {
size_t pos = line.find("_" + check.first + "_");
if (pos != std::string::npos &&
dvarCheck.find(check.first) != dvarCheck.end()) {
dvarCheck.at(check.first) = 1;
}
}
}
infile.close();
for (auto itr = dvarCheck.begin(); itr != dvarCheck.end(); ++ itr) {
if (itr->second == 0) {
throw OpalException("SampleCmd::execute()",
"Couldn't find the design variable '" + itr->first + "' in '" + tmplFile + "'!");
}
}
}
*gmsg << endl;
for (size_t i = 0; i < arguments.size(); ++ i) {
argv.push_back(const_cast<char*>(arguments[i].c_str()));
......
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