Skip to content

Commit

Permalink
sy - for docker
Browse files Browse the repository at this point in the history
  • Loading branch information
yisangriB committed Oct 18, 2024
1 parent a2afd7e commit 1adb6f5
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 29 deletions.
3 changes: 2 additions & 1 deletion modules/createEDP/surrogateEDP/surrogateEDP.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import argparse
import json

errPath = os.path.join(os.getcwd(),'workflow.err') # noqa: N816

def write_RV(AIM_input_path, EDP_input_path, EDP_type): # noqa: ARG001, N802, N803, D103
# load the AIM file
Expand All @@ -24,7 +25,7 @@ def write_RV(AIM_input_path, EDP_input_path, EDP_type): # noqa: ARG001, N802, N
root_AIM['Applications']['Modeling']['Application']
!= 'SurrogateGPBuildingModel'
):
with open('./workflow.err', 'w') as f: # noqa: PTH123
with open(errPath, 'w') as f: # noqa: PTH123
f.write(
'Do not select [None] in the EDP tab. [None] is used only when using pre-trained surrogate, i.e. when [Surrogate] is selected in the SIM Tab.'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from convertWindMat import * # noqa: F403

errPath = os.path.join(os.getcwd(),'workflow.err') # noqa: N816

def main(aimName, evtName, getRV): # noqa: C901, N803, D103, PLR0915
# THIS IS PERFORMED ONLY ONCE with open(aimName, 'r', encoding='utf-8') as f:
Expand Down Expand Up @@ -648,7 +649,7 @@ def simulation_gaussian( # noqa: D103, PLR0913

def err_exit(msg): # noqa: D103
print(msg) # noqa: T201
with open('../workflow.err', 'w') as f: # noqa: PTH123
with open(errPath, 'w') as f: # noqa: PTH123
f.write(msg)
exit(-1) # noqa: PLR1722

Expand All @@ -669,7 +670,7 @@ def err_exit(msg): # noqa: D103
getRV = True # noqa: N816

if error_tag and getRV:
with open('../workflow.err', 'w') as f: # noqa: PTH123
with open(errPath, 'w') as f: # noqa: PTH123
print('Failed to import module ' + moduleName) # noqa: T201
f.write(
'Failed to import module '
Expand All @@ -687,7 +688,7 @@ def err_exit(msg): # noqa: D103
import traceback

if getRV:
with open('../workflow.err', 'w') as f: # noqa: PTH123
with open(errPath, 'w') as f: # noqa: PTH123
f.write(
'Failed in wind load generator preprocessor:'
+ str(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import numpy as np

moduleName = 'scipy' # noqa: N816
import os

from scipy import interpolate
from scipy.interpolate import interp1d
from scipy.signal import butter, csd, lfilter, windows
Expand All @@ -21,7 +19,7 @@

from convertWindMat import * # noqa: F403

errPath = './workflow.err' # error file name # noqa: N816
errPath = os.path.join(os.getcwd(),'workflow.err') # noqa: N816
sys.stderr = open( # noqa: SIM115, PTH123
errPath, 'w'
) # redirecting stderr (this way we can capture all sorts of python errors)
Expand Down
5 changes: 3 additions & 2 deletions modules/createSAM/surrogateGP/SurrogateGP.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import os
import sys

errFileName = os.path.join(os.getcwd(),'workflow.err') # noqa: N816

def create_SAM(AIM_file, SAM_file): # noqa: N802, N803, D103
#
Expand Down Expand Up @@ -82,7 +83,7 @@ def create_SAM(AIM_file, SAM_file): # noqa: N802, N803, D103
if root_AIM['Applications']['EDP']['Application'] != 'SurrogateEDP':
msg = 'Please select [None] in the EDP tab.'
print(msg, file=sys.stderr) # noqa: T201
with open('./workflow.err', 'w') as f: # noqa: PTH123
with open(errFileName, 'w') as f: # noqa: PTH123
f.write(msg)
exit(-1) # noqa: PLR1722

Expand All @@ -92,7 +93,7 @@ def create_SAM(AIM_file, SAM_file): # noqa: N802, N803, D103
):
msg = 'Please select [None] in the FEM tab.'
print(msg, file=sys.stderr) # noqa: T201
with open('./workflow.err', 'w') as f: # noqa: PTH123
with open(errFileName, 'w') as f: # noqa: PTH123
f.write(msg)
exit(-1) # noqa: PLR1722

Expand Down
2 changes: 1 addition & 1 deletion modules/performFEM/surrogateGP/gpPredict.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np
from scipy.stats import lognorm, norm

errFileName = 'workflow.err' # noqa: N816
errFileName = os.path.join(os.getcwd(),'workflow.err') # noqa: N816
sys.stderr = open(errFileName, 'a') # noqa: SIM115, PTH123

try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

import numpy as np

errFileName = 'workflow.err' # noqa: N816
errFileName = os.path.join(os.getcwd(),'workflow.err') # noqa: N816
sys.stderr = open(errFileName, 'a') # noqa: SIM115, PTH123

# from simcenter_common import *
Expand Down
50 changes: 34 additions & 16 deletions modules/performUQ/SimCenterUQ/nataf_gsa/ERANataf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#include <random>
#include <filesystem>
#include "nlopt.hpp"
#include <thread> // This is necessary for std::this_thread

//#include <chrono>

Expand Down Expand Up @@ -767,29 +768,46 @@ vector<vector<double>> ERANataf::simulateAppOnce(int i, string workingDirs, stri
writeFile.close();
}

//
// (4) run workflow_driver.bat(e.g. It will make "SimCenterInput.tcl" and run OpenSees)
//

bool tryMore = true;
auto tryStart = std::chrono::high_resolution_clock::now();
double elapsedTime;

string workflowDriver_string = "cd \"" + workDir + "\" && \"" + workDir + "/" + workflowDriver + "\"" ;
std::ifstream readFile; // Declare the ifstream object


const char* workflowDriver_char = workflowDriver_string.c_str();
system(workflowDriver_char);
while (tryMore) {


if (i == 0) {
//std::cout << workflowDriver_char << "\n\n";
//std::cout << "Simulating Workdir." << i +1 << "\n\n";
//
// (4) run workflow_driver.bat(e.g. It will make "SimCenterInput.tcl" and run OpenSees)
//


string workflowDriver_string = "cd \"" + workDir + "\" && \"" + workDir + "/" + workflowDriver + "\"" ;

const char* workflowDriver_char = workflowDriver_string.c_str();
system(workflowDriver_char);

//
// (5) get the values in "results.out"
//

string results = workDir + "/results.out";
//std::ifstream readFile(results.data());
readFile.open(results.data()); // Assign by opening the file

elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - tryStart).count() / 1.e3; // seconds

// Check if the file opened successfully or if the elapsed time exceeds 1 second
if (readFile.is_open() || elapsedTime > 1.0) {
tryMore = false; // Exit the loop if the file opened or if time limit exceeded
} else {
// Wait for a short period before retrying
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}

//
// (5) get the values in "results.out"
//

string results = workDir + "/results.out";
std::ifstream readFile(results.data());

if (!readFile.is_open()) {
//*ERROR*
std::string errMsg = "Error running FEM: results.out missing in workdir." + std::to_string(i + 1) + ".";
Expand Down
4 changes: 3 additions & 1 deletion modules/performUQ/SimCenterUQ/surrogateBuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@
error_tag = True
print('Failed to import module:' + moduleName) # noqa: T201

errFileName = 'dakota.err' # noqa: N816
#errFileName = 'dakota.err' # noqa: N816

errFileName = os.path.join(os.getcwd(),'dakota.err') # noqa: N816
sys.stderr = open(errFileName, 'w') # noqa: SIM115, PTH123


Expand Down
8 changes: 7 additions & 1 deletion modules/performUQ/dakota/DakotaUQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,17 @@ def main(args): # noqa: C901, D103
dakotaErrFile = os.path.join(os.getcwd(), 'dakota.err') # noqa: PTH109, PTH118, N806
dakotaOutFile = os.path.join(os.getcwd(), 'dakota.out') # noqa: PTH109, PTH118, N806
dakotaTabFile = os.path.join(os.getcwd(), 'dakotaTab.out') # noqa: PTH109, PTH118, N806
checkErrFile = os.path.getsize(dakotaErrFile) # noqa: PTH202, N806
checkErrFile = os.path.exists(dakotaErrFile) # noqa: PTH110, N806
checkOutFile = os.path.exists(dakotaOutFile) # noqa: PTH110, N806
checkTabFile = os.path.exists(dakotaTabFile) # noqa: F841, N806, PTH110


checkErrSize=-1
if checkErrFile>0:
checkErrSize = os.path.getsize(dakotaErrFile) # noqa: PTH202, N806

if checkOutFile == False and checkErrFile == 0: # noqa: E712

with open(dakotaErrFile, 'a') as file: # noqa: PTH123
file.write(result.decode('utf-8'))
else:
Expand Down

0 comments on commit 1adb6f5

Please sign in to comment.