Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyan1214 committed Jan 21, 2025
2 parents 235cb5b + 73fd035 commit 7e78ae9
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 222 deletions.
Empty file modified modules/createEVENT/MPM/CMakeLists.txt
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion modules/createEVENT/MPM/MPM.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3 # noqa: D100
#!/usr/bin/env python3 # noqa: EXE001, D100
import argparse
import json

Expand Down
2 changes: 1 addition & 1 deletion modules/createEVENT/MPM/post_process_sensors.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python3 # noqa: EXE001

# -*- coding: utf-8 -*-
# Copyright (c) 2016-2017, The Regents of the University of California (Regents).
Expand Down
Binary file removed modules/createEVENT/MPM/sampleInputWindProfile.xlsx
Binary file not shown.
164 changes: 0 additions & 164 deletions modules/createEVENT/MPM/sampleInputWindProfileCSV.csv

This file was deleted.

2 changes: 1 addition & 1 deletion modules/createEVENT/MPM/setup_case.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python3 # noqa: EXE001
"""This script writes BC and initial condition, and setups the OpenFoam case
directory.
Expand Down
74 changes: 38 additions & 36 deletions modules/createEVENT/MPMEvent/MPMEvent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3 # noqa: D100
#!/usr/bin/env python3 # noqa: EXE001, D100

import argparse
import json
Expand All @@ -13,6 +13,7 @@
import numpy as np
import pandas as pd


class FloorForces: # noqa: D101
def __init__(self):
self.X = [0]
Expand Down Expand Up @@ -109,65 +110,67 @@ def GetFloorsCount(BIMFilePath): # noqa: N802, N803, D103
bim = json.load(BIMFile)
return int(bim['GeneralInformation']['stories'])


def GetExecutableFile(BIMFilePath): # noqa: N802, N803, D103
filePath = BIMFilePath # noqa: N806
with open(filePath, encoding='utf-8') as file: # noqa: PTH123
evt = json.load(file)
file.close # noqa: B018
executableNameKey = 'executableFile'
executablePathKey = executableNameKey + 'Path'

executableNameKey = 'executableFile' # noqa: N806
executablePathKey = executableNameKey + 'Path' # noqa: N806

for event in evt['Events']:
executableName = event[executableNameKey]
executablePath = event[executablePathKey]
return os.path.join(executablePath, executableName)
defaultExecutablePath = f'{os.path.realpath(os.path.dirname(__file__))}' # noqa: ISC003, PTH120
defaultExecutableName = 'osu_lwf.exe'
executableName = event[executableNameKey] # noqa: N806
executablePath = event[executablePathKey] # noqa: N806

return os.path.join(executablePath, executableName) # noqa: PTH118

defaultExecutablePath = f'{os.path.realpath(os.path.dirname(__file__))}' # noqa: N806, PTH120
defaultExecutableName = 'osu_lwf.exe' # noqa: N806
return defaultExecutablePath + defaultExecutableName


def GetSceneFile(BIMFilePath): # noqa: N802, N803, D103
filePath = BIMFilePath # noqa: N806
with open(filePath, encoding='utf-8') as file: # noqa: PTH123
evt = json.load(file)
file.close # noqa: B018

fileNameKey = 'configFile'
filePathKey = fileNameKey + 'Path'
fileNameKey = 'configFile' # noqa: N806
filePathKey = fileNameKey + 'Path' # noqa: N806

for event in evt['Events']:
fileName = event[fileNameKey]
filePath = event[filePathKey]
return os.path.join(filePath, fileName)
defaultScriptPath = f'{os.path.realpath(os.path.dirname(__file__))}' # noqa: ISC003, PTH120
defaultScriptName = 'scene.json'
return defaultScriptPath + defaultScriptName
fileName = event[fileNameKey] # noqa: N806
filePath = event[filePathKey] # noqa: N806

return os.path.join(filePath, fileName) # noqa: PTH118

defaultScriptPath = f'{os.path.realpath(os.path.dirname(__file__))}' # noqa: N806, PTH120
defaultScriptName = 'scene.json' # noqa: N806
return defaultScriptPath + defaultScriptName


def GetTimer(BIMFilePath): # noqa: N802, N803, D103
filePath = BIMFilePath # noqa: N806
with open(filePath, encoding='utf-8') as file: # noqa: PTH123
evt = json.load(file)
file.close # noqa: B018
timerKey = 'maxMinutes'

timerKey = 'maxMinutes' # noqa: N806

for event in evt['Events']:
timer = event[timerKey]
maxSeconds = timer * 60
return maxSeconds
maxSeconds = timer * 60 # noqa: N806
return maxSeconds # noqa: RET504

return 0


def main(): # noqa: D103
def main():
"""
Entry point to generate event file using MPMEvent.
"""
""" # noqa: D200
return 0


Expand Down Expand Up @@ -203,24 +206,23 @@ def main(): # noqa: D103

# Get json of filenameAIM
executableName = GetExecutableFile(arguments.filenameAIM) # noqa: N816
scriptName = GetSceneFile(arguments.filenameAIM) # noqa: N816
scriptName = GetSceneFile(arguments.filenameAIM) # noqa: N816
maxSeconds = GetTimer(arguments.filenameAIM) # noqa: N816

if arguments.getRV == True: # noqa: E712
print('RVs requested') # noqa: T201
# Read the number of floors
floorsCount = GetFloorsCount(arguments.filenameAIM) # noqa: N816
filenameEVENT = arguments.filenameEVENT # noqa: N816


result = subprocess.run( # noqa: S603
[ # noqa: S607
'timeout',
str(maxSeconds),
executableName,
'-f',
scriptName,
# f'{os.path.realpath(os.path.dirname(__file__))}' # noqa: ISC003, PTH120
# f'{os.path.realpath(os.path.dirname(__file__))}'
# + '/taichi_script.py',
],
stdout=subprocess.PIPE,
Expand All @@ -239,12 +241,12 @@ def main(): # noqa: D103
filenameEVENT = arguments.filenameEVENT # noqa: N816
result = subprocess.run( # noqa: S603
[ # noqa: S607
'timeout',
'timeout',
str(maxSeconds),
executableName,
'-f',
scriptName,
# f'{os.path.realpath(os.path.dirname(__file__))}' # noqa: ISC003, PTH120
# f'{os.path.realpath(os.path.dirname(__file__))}'
# + '/taichi_script.py',
],
stdout=subprocess.PIPE,
Expand Down
2 changes: 1 addition & 1 deletion modules/createEVENT/stochasticWave/Jonswap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python3 # noqa: EXE001

"""
Plot the JONSWAP spectrum for a given sea state and generate wave time series based on the Jonswap spectrum
Expand Down
2 changes: 1 addition & 1 deletion modules/createEVENT/stochasticWave/StochasticWave.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python3 # noqa: EXE001

"""Generate the event file using Stochastic Waves."""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python3 # noqa: EXE001

"""Compute inline/total hydrodynamic force and moments on a monopile using Morison's equation""" # noqa: D400

Expand Down
3 changes: 3 additions & 0 deletions modules/performFEM/surrogateGP/gpPredict.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
from scipy.stats import lognorm, norm
from sklearn.linear_model import LinearRegression

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

try:
moduleName = 'GPy' # noqa: N816
import GPy as GPy # noqa: PLC0414
Expand Down
7 changes: 4 additions & 3 deletions modules/performUQ/SimCenterUQ/nataf_gsa/ERANataf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,10 @@ void ERANataf::simulateAppBatch(string workflowDriver,
}
else if (inp.femAppName.compare("unknown") == 0) {
//*ERROR*
std::string errMsg = "FEM simulation model is unknown.";
theErrorFile.write(errMsg);
return;
//std::string errMsg = "FEM simulation model is unknown.";
//theErrorFile.write(errMsg);
//return;
//EE-UQ and other apps don't use fem app name
}

//
Expand Down
44 changes: 31 additions & 13 deletions modules/performUQ/SimCenterUQ/surrogateBuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
print('Initializing error log file..') # noqa: T201
print(f'Current working dir (getcwd): {os.getcwd()}') # noqa: T201, PTH109

# errFileName = os.path.join(os.getcwd(),'dakota.err')
work_dir_tmp = sys.argv[1].replace(os.sep, '/')
errFileName = os.path.join(work_dir_tmp, 'dakota.err') # noqa: N816, PTH118

Expand All @@ -105,7 +106,6 @@
sys.stderr = open(errFileName, 'w') # noqa: SIM115, PTH123
print(f'Error file created at: {errFileName}') # noqa: T201


#
# Modify GPy package
#
Expand Down Expand Up @@ -254,7 +254,10 @@ def readJson(self): # noqa: C901, N802, D102, PLR0912, PLR0915
self.isEEUQ = True
elif Evt[0]['EventClassification'] == 'Wind':
self.isWEUQ = True
elif Evt[0]['EventClassification'] == 'Hydro' or Evt[0]['EventClassification'] == 'Water':
elif (
Evt[0]['EventClassification'] == 'Hydro'
or Evt[0]['EventClassification'] == 'Water'
):
self.isHydroUQ = True

self.rv_name_ee = []
Expand Down Expand Up @@ -939,10 +942,16 @@ def predictStoVars(self, X_repl, Y_var_repl, X_new, Y_mean, counts): # noqa: AR
if parname.endswith('lengthscale'):
for nx in range(X_repl.shape[1]):
myrange = np.max(X_repl, axis=0) - np.min(X_repl, axis=0)
lb = myrange[nx] / X_repl.shape[0]
ub = myrange[nx] * 5
if lb >= ub:
lb = 0

m_var.Mat52.lengthscale[[nx]].constrain_bounded(
myrange[nx] / X_repl.shape[0], myrange[nx] * 5, warning=False
lb, ub, warning=False
)
m_var.Mat52.lengthscale[[nx]] = myrange[nx] # initial points

# m_var.Gaussian_noise.value = 0.05
# m_var.Gaussian_noise.constrain_bounded(0.1/np.var(log_vars), 0.8/np.var(log_vars), warning=False)
# m_var.Mat52.lengthscale[[nx]].constrain_bounded(
Expand Down Expand Up @@ -978,7 +987,6 @@ def predictStoVars(self, X_repl, Y_var_repl, X_new, Y_mean, counts): # noqa: AR
else:
norm_var_str = var_pred.T[0] # if normalization was not used..


# norm_var_str = (X_new+2)**2/max((X_new+2)**2)
Y_metadata = {'variance_structure': norm_var_str / counts} # noqa: N806

Expand Down Expand Up @@ -1122,8 +1130,8 @@ def calibrate(self): # noqa: C901, D102, RUF100
nugget_opt_tmp = self.nugget_opt
nopt = self.nopt

parallel_calib = True
# parallel_calib = self.do_parallel
# parallel_calib = True
parallel_calib = self.do_parallel

if parallel_calib:
iterables = (
Expand Down Expand Up @@ -3436,12 +3444,17 @@ def calibrating( # noqa: C901, D103
m_tmp[variance_keyword].constrain_bounded(0.05, 2, warning=False)
for parname in m_tmp.parameter_names():
if parname.endswith('lengthscale'):
for nx in range(X.shape[1]): # noqa: B007
myrange = np.max(X, axis=0) - np.min(X, axis=0) # noqa: F841, RUF100
for nx in range(X.shape[1]):
myrange = np.max(X, axis=0) - np.min(X, axis=0)
lb = myrange[nx]
ub = myrange[nx] / X.shape[0] * 10
if lb >= ub:
lb = 0

exec( # noqa: S102
'm_tmp.'
+ parname
+ '[[nx]].constrain_bounded(myrange[nx] / X.shape[0]*10, myrange[nx],warning=False)'
+ '[[nx]].constrain_bounded(lb, ub,warning=False)'
)
# m_tmp[parname][nx].constrain_bounded(myrange[nx] / X.shape[0], myrange[nx]*100)
elif nugget_opt_tmp == 'Fixed Values':
Expand Down Expand Up @@ -3470,12 +3483,17 @@ def calibrating( # noqa: C901, D103

for parname in m_tmp.parameter_names():
if parname.endswith('lengthscale'):
for nx in range(X.shape[1]): # noqa: B007
myrange = np.max(X, axis=0) - np.min(X, axis=0) # noqa: F841
for nx in range(X.shape[1]):
myrange = np.max(X, axis=0) - np.min(X, axis=0)
lb = myrange[nx] / X.shape[0] * 10
ub = myrange[nx]
if lb >= ub:
lb = 0

exec( # noqa: S102
'm_tmp.'
+ parname
+ '[[nx]].constrain_bounded(myrange[nx] / X.shape[0]*10, myrange[nx],warning=False)'
+ '[[nx]].constrain_bounded(lb, ub, warning=False)'
)
exec( # noqa: S102
'm_tmp.' + parname + '[[nx]] = myrange[nx]*1'
Expand Down Expand Up @@ -3527,7 +3545,7 @@ def calibrating( # noqa: C901, D103

print('Calibrating final surrogate') # noqa: T201
m_tmp = my_optimize_restart(m_tmp, nopt)
# noqa: RUF100, W293
# noqa: RUF100, W293
# if develop_mode:
# print(m_tmp)
# #print(m_tmp.rbf.lengthscale)
Expand Down

0 comments on commit 7e78ae9

Please sign in to comment.