Skip to content

Commit

Permalink
Merge branch 'NHERI-SimCenter:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBonus authored Sep 29, 2024
2 parents 74b08f5 + c3d787e commit f54b8bc
Show file tree
Hide file tree
Showing 12 changed files with 1,093 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
1 change: 1 addition & 0 deletions modules/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_subdirectory(BRAILS)
add_subdirectory(ShakerMaker)


5 changes: 5 additions & 0 deletions modules/tools/ShakerMaker/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_subdirectory(Examples)
add_subdirectory(TapisFiles)
simcenter_add_python_script(SCRIPT faultplotter.py)
simcenter_add_python_script(SCRIPT ShakerMakersubmitjob.py)
simcenter_add_python_script(SCRIPT DatabaseMetadata.json)
19 changes: 19 additions & 0 deletions modules/tools/ShakerMaker/DatabaseMetadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"Contries":[

Check failure on line 2 in modules/tools/ShakerMaker/DatabaseMetadata.json

View workflow job for this annotation

GitHub Actions / spell-check

Contries ==> Countries
"Chile",
"United States"
],
"Chile": {
"Faults":["Sanramon"],
"Sanramon": {
"Magnitudes": ["6.7"],
"6.7":{
"Types": ["bl"],
"bl":{"Realizations": ["1","2","3","4","5","6","7","8","9","10"]}
}
}
},
"United States": {}


}
4 changes: 4 additions & 0 deletions modules/tools/ShakerMaker/Examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
simcenter_add_python_script(SCRIPT DRM_Sanramon.json)
simcenter_add_python_script(SCRIPT Single_Sanramon.json)


40 changes: 40 additions & 0 deletions modules/tools/ShakerMaker/Examples/DRM_Sanramon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"dt": 0.005,
"nfft": 2048,
"dk": 0.2,
"tmin":0,
"tmax": 60,
"dh": 40.0,
"dv_rec": 5.0,
"dv_src": 200,
"layers":[
{"Layer Name":"Layer1", "Thickness":0.20, "Vp":1.32, "Vs":0.75, "Density":2.4, "Qp": 1000, "Qs": 1000},
{"Layer Name":"Layer2", "Thickness":0.80, "Vp":2.75, "Vs":1.57, "Density":2.5, "Qp": 1000, "Qs": 1000},
{"Layer Name":"Layer3", "Thickness":14.5, "Vp":5.50, "Vs":3.14, "Density":2.5, "Qp": 1000, "Qs": 1000},
{"Layer Name":"Half Space Layer","Thickness":0, "Vp":7.00, "Vs":4.00, "Density":2.67,"Qp": 1000, "Qs": 1000}
],
"station_type": "DRM",
"station_info": {
"Latitude": -33.40657,
"Longitude": -70.50653,
"Width X": 105,
"Width Y": 105,
"Depth" : 30,
"Mesh Size X" : 2.5,
"Mesh Size Y" : 2.5,
"Mesh Size Z" : 2.5
},
"fault_type": "Database",
"fault_info": {
"Country": "Chile",
"Fault": "Sanramon",
"Magnitude": "6.7",
"Fault Type": "bl",
"Realization": "3"
},
"System": "Frontera",
"Queue": "development",
"Number of Nodes": 40,
"Cores per Node": 50,
"Max Run Time": "02:00:00"
}
34 changes: 34 additions & 0 deletions modules/tools/ShakerMaker/Examples/Single_Sanramon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"dt": 0.1,
"nfft": 1024,
"dk": 0.1,
"tmin":0,
"tmax": 10,
"dh": 0.1,
"dv_rec": 0.1,
"dv_src": 0.1,
"layers":[
{"Layer Name":"Layer1", "Thickness":10, "Vp":2000, "Vs":1000, "Density":2000, "Qp": 100, "Qs": 50},
{"Layer Name":"Layer2", "Thickness":20, "Vp":2500, "Vs":1200, "Density":2200, "Qp": 150, "Qs": 75},
{"Layer Name":"Layer3", "Thickness":30, "Vp":3000, "Vs":1500, "Density":2400, "Qp": 200, "Qs": 100},
{"Layer Name":"Half Space Layer","Thickness":0, "Vp":3500, "Vs":1800, "Density":2600, "Qp": 250, "Qs": 125}
],
"station_type": "Single",
"station_info": [
{"Latitude": -33.5, "Longitude": -70.5, "Depth": 5},
{"Latitude": -33.6, "Longitude": -70.6, "Depth": 1}
],
"fault_type": "Database",
"fault_info": {
"Country": "Chile",
"Fault": "Sanramon",
"Magnitude": "6.7",
"Fault Type": "bl",
"Realization": 1
},
"System": "Frontera",
"Queue": "normal",
"Number of Nodes": 40,
"Cores per Node": 50,
"Max Run Time": "04:00:00"
}
Loading

0 comments on commit f54b8bc

Please sign in to comment.