Skip to content

Commit 7f02981

Browse files
authored
Merge pull request #12 from NHERI-SimCenter/master
abs - merging updates from upstream
2 parents 77f23b1 + dfe8c48 commit 7f02981

9 files changed

Lines changed: 97 additions & 40 deletions

File tree

modules/Workflow/whale/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,7 +2293,7 @@ def preprocess_inputs( # noqa: C901
22932293
# This time, (1) we do it only for python; (2) added try statement
22942294

22952295
try:
2296-
if command.startswith('python'):
2296+
if command.startswith('python') and self.run_type == 'set_up':
22972297
if platform.system() == 'Windows':
22982298
driver_script += 'if %errorlevel% neq 0 exit /b -1 \n' #TODO ANYONE: This variable is not defined. Check This please. (Added by Sina)
22992299
else:
@@ -2461,7 +2461,7 @@ def create_driver_file( # noqa: C901
24612461
# This time, (1) we do it only for python; (2) added try statement
24622462

24632463
# try:
2464-
if 'python' in command_list[0].lower():
2464+
if 'python' in command_list[0].lower() and self.run_type == 'set_up':
24652465
if platform.system() == 'Windows':
24662466
driver_script += 'if %errorlevel% neq 0 exit /b -1 \n'
24672467
else:

modules/createEVENT/IsolatedBuildingCFD/IsolatedBuildingCFD.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,12 @@ def scale_event(filename_aim, filename_event):
350350
except (json.JSONDecodeError, IOError) as e:
351351
print(f"Error IsolatedBuilldingCFD::scale_event processing files: {e}")
352352

353-
353+
def GetFloorsCount(BIMFilePath): # noqa: N802, N803, D103
354+
with open(BIMFilePath) as BIMFile: # noqa: PTH123, N806
355+
bim = json.load(BIMFile)
356+
357+
return int(bim['GeneralInformation']['stories'])
358+
354359

355360
if __name__ == "__main__":
356361
"""
@@ -366,17 +371,34 @@ def scale_event(filename_aim, filename_event):
366371
parser.add_argument("--getRV", action="store_true", help="used to get random variable, if not multiply EVENT by gs")
367372

368373

374+
# #parsing arguments
375+
# arguments, unknowns = parser.parse_known_args()
376+
377+
# # [forcesOutputName, floors, startTime, lengthScale, velocityScale] = ReadBIM(arguments.bim)
378+
379+
# # GetOpenFOAMEvent(arguments.case, forcesOutputName, floors, startTime, lengthScale, velocityScale)
380+
381+
# if not arguments.getRV:
382+
383+
# scale_event(filename_aim = arguments.filenameAIM, filename_event = arguments.filenameEVENT)
384+
369385
#parsing arguments
370386
arguments, unknowns = parser.parse_known_args()
371387

372-
# [forcesOutputName, floors, startTime, lengthScale, velocityScale] = ReadBIM(arguments.bim)
373-
374-
# GetOpenFOAMEvent(arguments.case, forcesOutputName, floors, startTime, lengthScale, velocityScale)
388+
if arguments.getRV == True: # noqa: E712
389+
# Read the number of floors
390+
# floorsCount = GetFloorsCount(arguments.filenameAIM) # noqa: N816
391+
floorsCount = GetFloorsCount(arguments.filenameAIM) # noqa: N816
392+
forces = []
393+
for i in range(floorsCount): # noqa: B007
394+
forces.append(FloorForces()) # noqa: PERF401
395+
# write the event file
396+
writeEVENT(forces, arguments.filenameEVENT)
375397

376398
if not arguments.getRV:
377-
378399
scale_event(filename_aim = arguments.filenameAIM, filename_event = arguments.filenameEVENT)
379400

380401

381402

382403

404+

modules/createEVENT/stochasticWave/Jonswap.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929

3030
input_args = sys.argv[1:]
3131

32-
print( # noqa: T201
33-
'Jonswap.py - Backend-script post_process_sensors.py running: '
34-
+ str(sys.argv[0])
35-
)
36-
print( # noqa: T201
37-
'post_process_sensors.py - Backend-script post_process_sensors.py received input args: '
38-
+ str(input_args)
39-
)
32+
# print( # noqa: T201
33+
# 'Jonswap.py - Backend-script post_process_sensors.py running: '
34+
# + str(sys.argv[0])
35+
# )
36+
# print( # noqa: T201
37+
# 'post_process_sensors.py - Backend-script post_process_sensors.py received input args: '
38+
# + str(input_args)
39+
# )
4040

4141
inputFile = sys.argv[1] # noqa: N816
4242
outputPath = sys.argv[2] # noqa: N816
@@ -47,7 +47,7 @@
4747
with open(inputFile, encoding='utf-8') as BIMFile: # noqa: PTH123
4848
bim = json.load(BIMFile)
4949
for event_id in range(1):
50-
print('Running a sample simulation with JSON input parameters') # noqa: T201
50+
# print('Running a sample simulation with JSON input parameters') # noqa: T201
5151
g = 9.80665 # gravity [m/s^2]
5252
rho = 1000.0 # water density
5353

@@ -165,7 +165,7 @@
165165

166166
# if (si == seeds[-1]):
167167

168-
print('Saving wave spectra and time series') # noqa: T201
168+
# print('Saving wave spectra and time series') # noqa: T201
169169
spectra_df = pd.DataFrame()
170170

171171
spectra_df['Frequency'] = freq

modules/createEVENT/stochasticWave/StochasticWave.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ def readRV(aimFilePath='AIM.json', eventFilePath='EVENT.json'): # noqa: D103, N
196196
addFloorForceToEvent(
197197
timeSeriesArray, patternsArray, floorForces.X, 'X', floor, deltaT
198198
)
199-
addFloorForceToEvent(
200-
timeSeriesArray, patternsArray, floorForces.Y, 'Y', floor, deltaT
201-
)
199+
# addFloorForceToEvent(
200+
# timeSeriesArray, patternsArray, floorForces.Y, 'Y', floor, deltaT
201+
# )
202202
addFloorPressure(pressureArray, floor)
203203

204204
eventDict['Events'].append(event_json)
@@ -237,9 +237,9 @@ def writeEVENT(forces, eventFilePath, deltaT=1.0): # noqa: D103, N802, N803
237237
addFloorForceToEvent(
238238
timeSeriesArray, patternsArray, floorForces.X, 'X', floor, deltaT
239239
)
240-
addFloorForceToEvent(
241-
timeSeriesArray, patternsArray, floorForces.Y, 'Y', floor, deltaT
242-
)
240+
# addFloorForceToEvent(
241+
# timeSeriesArray, patternsArray, floorForces.Y, 'Y', floor, deltaT
242+
# )
243243
addFloorPressure(pressureArray, floor)
244244

245245
with open(eventFilePath, 'w', encoding='utf-8') as f: # noqa: PTH123

modules/performFEM/surrogateGP/gpPredict.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from scipy.stats import lognorm, norm
1111
from sklearn.linear_model import LinearRegression
1212

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

1616
try:
1717
moduleName = 'GPy' # noqa: N816

modules/performRegionalMapping/GISSpecifiedEvents/GISSpecifiedEvent.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,17 @@ def create_event(asset_file: str, event_grid_file: str, workflow_input: str, do_
7878
# open input file & get Regional Event data
7979
#
8080

81+
# candidate paths
8182
json_path = os.path.join(os.getcwd(), workflow_input)
8283

83-
with open(json_path, 'r') as f:
84-
data = json.load(f)
84+
if not os.path.exists(json_path):
85+
json_path = os.path.join(os.path.dirname(os.getcwd()), workflow_input)
86+
87+
if os.path.isfile(json_path):
88+
with open(json_path, 'r') as f:
89+
data = json.load(f)
90+
else:
91+
raise FileNotFoundError(f"Could not find {workflow_input} in current or parent directory")
8592

8693
regional_event = data.get("RegionalEvent")
8794

modules/performUQ/common/extractEDP.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int main(int argc, const char **argv)
4040
int numValues = json_array_size(sType);
4141
for (int i=0; i<numValues; i++) {
4242
double value = json_number_value(json_array_get(sType,i));
43-
printf("%f ", value);
43+
// FMK printf("%f ", value);
4444
fOut << value << " ";
4545
numEDP++;
4646
}
@@ -54,7 +54,7 @@ int main(int argc, const char **argv)
5454
int numValues = json_array_size(sType);
5555
for (int i=0; i<numValues; i++) {
5656
double value = json_number_value(json_array_get(sType,i));
57-
printf("%f ", value);
57+
// printf("%f ", value);
5858
fOut << value << " ";
5959
numEDP++;
6060
}
@@ -68,15 +68,15 @@ int main(int argc, const char **argv)
6868
int numValues = json_array_size(sType);
6969
for (int i=0; i<numValues; i++) {
7070
double value = json_number_value(json_array_get(sType,i));
71-
printf("%f ", value);
71+
// printf("%f ", value);
7272
fOut << value << " ";
7373
numEDP++;
7474
}
7575
}
7676
}
7777
}
7878

79-
printf("NUM_EDP= %d\n",numEDP);
79+
// printf("NUM_EDP= %d\n",numEDP);
8080

8181
fOut.close();
8282

modules/performUQ/dakota/postprocessDakota.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,14 @@ void processEDPs(const char* filenameEDP, const char* dakotaOUT, int numRV, int
103103
}
104104
}
105105

106+
/* fmk
106107
for (int i=0; i<numSample; i++) {
107108
for (int j=0; j<numEDP; j++) {
108109
printf("%f ", data[i*numEDP+j]);
109110
}
110111
printf("\n");
111112
}
113+
*/
112114

113115
json_dump_file(root,filenameEDP,0);
114116
}

modules/performUQ/dakota/simCenterDprepro.cpp

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include <fstream>
22
#include <sstream>
33
#include <iostream>
4-
#include <vector>
4+
#include <deque>
55
#include <iterator>
66

77
using std::string;
8-
using std::vector;
8+
using std::deque;
99

1010
/* ***************** params.in example ******
1111
{ DAKOTA_VARS = 2 }
@@ -47,14 +47,15 @@ int main(int argc, char **argv)
4747
}
4848

4949
//
50-
// vectors that will contain strinmgs to search for & their replacement
50+
// deques that will contain strinmgs to search for & their replacement
5151
//
5252

53-
vector<string> original;
54-
vector<string> replace;
55-
vector<int> originalLength;
56-
vector<int> replacementLength;
57-
53+
deque<string> original;
54+
deque<string> replace;
55+
deque<int> originalLength;
56+
deque<int> replacementLength;
57+
deque<string> rvNames; // original string of random variable names
58+
5859
//
5960
// from params file, 1) read # of RV and 2) then read RV names and values
6061
//
@@ -63,6 +64,8 @@ int main(int argc, char **argv)
6364
int numRVs = 0;
6465
string line;
6566
while (getline(params, line)) {
67+
68+
6669
std::istringstream buf(line);
6770
std::istream_iterator<std::string> beg(buf), end;
6871
vector<std::string> tokens(beg, end); // done!
@@ -75,12 +78,35 @@ int main(int argc, char **argv)
7578
} else {
7679

7780
// subsequent lines contain RV and value .. add to string vectors
78-
string rvName = "\"RV." + tokens.at(1) + "\""; // add SimCenter delimiters begin="RV. & end="
81+
string rvName = tokens.at(1); // add SimCenter delimiters begin="RV. &\ end="
7982
string rvValue = tokens.at(3);
83+
// check if an existing rvName starts as a substring of current
84+
bool subStringExists = false;
85+
for (size_t i = 0; i < rvNames.size(); ++i) {
86+
const std::string& s1 = rvName[i];
87+
if (rvName.find(s1) == 0) {
88+
subStringExists = true;
89+
break; // No need to check further if found
90+
}
91+
}
92+
}
93+
94+
if (subStringExists == false) {
95+
rvNames.push_back(rvName);
96+
rvName = "\"RV." + rvName + "\""; // add SimCenter delimiters begin="RV. &\ end="
8097
original.push_back(rvName);
8198
replace.push_back(rvValue);
8299
originalLength.push_back(rvName.length());
83100
replacementLength.push_back(rvValue.length());
101+
102+
} else {
103+
rvNames.push_front(rvName);
104+
rvName = "\"RV." + rvName + "\"";
105+
replace.push_front(rvValue);
106+
originalLength.push_front(rvName.length());
107+
replacementLength.push_front(rvValue.length());
108+
109+
}
84110
// std::cerr << rvName << " " << rvValue << "\n";
85111
}
86112

0 commit comments

Comments
 (0)