Skip to content

Commit

Permalink
Merge remote-tracking branch 'NHERI-SimCenter/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
snaeimi committed Sep 27, 2024
2 parents 60c23cd + 228c512 commit 8eb068a
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 26 deletions.
68 changes: 61 additions & 7 deletions modules/performFEM/OpenSeesPy/createOpenSeesPyDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
#include <filesystem>
#include <algorithm>
#include <regex>
#include <cstdio> // for freopen
#include <cstdlib> // for exit
#include <stdexcept>
#include <exception>
#include <csignal>



int getEDP(json_t *edp, std::vector<std::string> &edpList);
int getRV(json_t *edp, std::vector<std::string> &rvList);
Expand All @@ -33,7 +40,8 @@ std::string appendModelIndexToStem(int modelIndex, std::string filename) {
return filename;
}

int main(int argc, const char **argv) {
//int main(int argc, const char **argv) {
int createDriver(int argc, const char **argv) {

if (argc < 5) {
std::cerr << "createOpenSeesPyDriver:: expecting 4 inputs\n";
Expand Down Expand Up @@ -197,7 +205,21 @@ int main(int argc, const char **argv) {
if (modelIndex > 0) {
parametersScriptTemplate = appendModelIndexToStem(modelIndex, parametersScriptTemplate);
}
std::filesystem::copy_file(parametersScript, parametersScriptTemplate);
try {
std::filesystem::copy_file(parametersScript, parametersScriptTemplate);
std::cout << "File copied successfully from "
<< parametersScript << " to "
<< parametersScriptTemplate << std::endl;
} catch (const std::filesystem::filesystem_error& e) {
std::cerr << "Error copying file: " << e.what() << std::endl;
std::cerr << "Source: " << e.path1() << ", Destination: " << e.path2() << std::endl;
exit(-1);
} catch (const std::exception& e) {
std::cerr << "An unexpected error occurred: " << e.what() << std::endl;
exit(-1);
}


} else {
for(std::vector<std::string>::iterator itRV = rvList.begin(); itRV != rvList.end(); ++itRV) {
std::string nm = *itRV;
Expand All @@ -218,14 +240,14 @@ int main(int argc, const char **argv) {
}
std::string mainScript = json_string_value(femScript);
std::ifstream modelFile(mainScript);
while (!modelFile.eof()) {
std::string line;
std::getline(modelFile, line);
templateFile << line << std::endl;
std::string line;
while (std::getline(modelFile, line)) {
std::cout << line << std::endl; // Print line to console
templateFile << line << std::endl; // Write line to template file
}
templateFile.close();
if (strcmp(parametersScript.c_str(),"") == 0) {

if (strcmp(parametersScript.c_str(),"") == 0) {
// workflowDriverFile << moveCommand << mainScript << " tmpSimCenter.script \n";
workflowDriverFile << dpreproCommand << " params.in " << mainScriptTemplate << " " << mainScript << "\n";
} else {
Expand Down Expand Up @@ -268,7 +290,39 @@ int main(int argc, const char **argv) {
//
// done
//
std::cerr << "The run was successful" << std::endl;

exit(0);
}

void signalHandler(int signal) {
std::cerr << "Caught signal: " << signal << std::endl;
exit(signal);
}

void setupSignalHandlers() {
std::signal(SIGSEGV, signalHandler);
}

void redirectCerrToFile() {
if (freopen("FEMpreprocessor.err", "w", stderr) == nullptr) {
std::cerr << "Failed to redirect stderr to error.log" << std::endl;
exit(EXIT_FAILURE);
}
}


int main(int argc, const char **argv) {
// to redirect the file
redirectCerrToFile();
setupSignalHandlers();

try {
createDriver(argc, argv); // Pass arguments to the main logic function
} catch (const std::exception& e) {
std::cerr << "Caught exception in main: " << e.what() << std::endl;
}

return 0;

}
39 changes: 20 additions & 19 deletions modules/performUQ/dakota/dakotaProcedures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,26 @@ writeRV(std::ostream &dakotaFile, struct randomVariables &theRandomVariables, st
dakotaFile << "\n\n";
}

int numRealDiscrete = theRandomVariables.discreteDesignSetRVs.size();
if (numRealDiscrete > 0) {
dakotaFile << " discrete_design_set \n real = " << numRealDiscrete;
dakotaFile << "\n elements_per_variable = ";
for (auto it = theRandomVariables.discreteDesignSetRVs.begin(); it != theRandomVariables.discreteDesignSetRVs.end(); it++)
dakotaFile << it->elements.size() << " "; //std::list<struct betaRV>::iterator it;
dakotaFile << "\n elements = ";
for (auto it = theRandomVariables.discreteDesignSetRVs.begin(); it != theRandomVariables.discreteDesignSetRVs.end(); it++) {
it->elements.sort();
for (auto element = it->elements.begin(); element != it->elements.end(); element++)
dakotaFile << " \'" << *element << "\'";
}
dakotaFile << "\n descriptors = ";
for (auto it = theRandomVariables.discreteDesignSetRVs.begin(); it != theRandomVariables.discreteDesignSetRVs.end(); it++) {
dakotaFile << "\'" << it->name << "\' ";
rvList.push_back(it->name);
}
dakotaFile << "\n\n";
}
// sy - below is not needed. Both ground motion events and multiple FEM/EVT works without it
// int numRealDiscrete = theRandomVariables.discreteDesignSetRVs.size();
// if (numRealDiscrete > 0) {
// dakotaFile << " discrete_design_set \n real = " << numRealDiscrete;
// dakotaFile << "\n elements_per_variable = ";
// for (auto it = theRandomVariables.discreteDesignSetRVs.begin(); it != theRandomVariables.discreteDesignSetRVs.end(); it++)
// dakotaFile << it->elements.size() << " "; //std::list<struct betaRV>::iterator it;
// dakotaFile << "\n elements = ";
// for (auto it = theRandomVariables.discreteDesignSetRVs.begin(); it != theRandomVariables.discreteDesignSetRVs.end(); it++) {
// it->elements.sort();
// for (auto element = it->elements.begin(); element != it->elements.end(); element++)
// dakotaFile << " \'" << *element << "\'";
// }
// dakotaFile << "\n descriptors = ";
// for (auto it = theRandomVariables.discreteDesignSetRVs.begin(); it != theRandomVariables.discreteDesignSetRVs.end(); it++) {
// dakotaFile << "\'" << it->name << "\' ";
// rvList.push_back(it->name);
// }
// dakotaFile << "\n\n";
// }



Expand Down

0 comments on commit 8eb068a

Please sign in to comment.