Skip to content

Commit 71d3fc0

Browse files
authored
Merge branch 'NHERI-SimCenter:master' into master
2 parents 6ac8b17 + ff2d32c commit 71d3fc0

10 files changed

Lines changed: 337 additions & 26 deletions

File tree

modules/Workflow/WorkflowApplications.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,11 @@
438438
"ExecutablePath": "applications/createEVENT/physicsBasedMotion/PhysicsBasedMotion",
439439
"ApplicationSpecificInputs": []
440440
},
441+
{
442+
"Name": "DRM",
443+
"ExecutablePath": "applications/createEVENT/DRM/DRM.py",
444+
"ApplicationSpecificInputs": []
445+
},
441446
{
442447
"Name": "ExistingPEER_Events",
443448
"ExecutablePath": "applications/createEVENT/multiplePEER/MultiplePEER",
@@ -737,6 +742,22 @@
737742
}
738743
]
739744
},
745+
{
746+
"Name": "FemoraInput",
747+
"ExecutablePath": "applications/createSAM/openSeesInput/OpenSeesInput",
748+
"ApplicationSpecificInputs": [
749+
{
750+
"id": "fileName",
751+
"type": "string",
752+
"description": "Defines the name of the main OpenSees model file."
753+
},
754+
{
755+
"id": "filePath",
756+
"type": "string",
757+
"description": "Defines the location of the main OpenSees model file."
758+
}
759+
]
760+
},
740761
{
741762
"Name": "CustomPyInput",
742763
"ExecutablePath": "applications/createSAM/customPyInput/customPyInput.py",

modules/Workflow/whale/main.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -987,17 +987,30 @@ def _parse_inputs(self): # noqa: C901
987987
log_msg(' OK', prepend_timestamp=False)
988988

989989
# store the specified units (if available)
990-
if 'units' in input_data:
990+
if 'units' in input_data: # TODO check for a bug. I think it should be input_data["GeneralInformation"]
991991
self.units = input_data['units']
992992

993993
log_msg('The following units were specified: ', prepend_timestamp=False)
994994
for key, unit in self.units.items():
995995
log_msg(f' {key}: {unit}', prepend_timestamp=False)
996996
else:
997-
self.units = None
998-
log_msg(
999-
'No units specified; using Standard units.', prepend_timestamp=False
1000-
)
997+
# check the general info for units
998+
general_info = input_data.get('GeneralInformation', None)
999+
if general_info:
1000+
self.units = general_info.get('units', None)
1001+
if self.units :
1002+
log_msg(
1003+
'The following units were specified in the GeneralInformation section: ',
1004+
prepend_timestamp=False
1005+
)
1006+
for key, unit in self.units.items():
1007+
log_msg(f' {key}: {unit}', prepend_timestamp=False)
1008+
else:
1009+
# if no units were specified, use the standard units
1010+
self.units = None
1011+
log_msg(
1012+
'No units specified; using Standard units.', prepend_timestamp=False
1013+
)
10011014

10021015
# store the specified output types
10031016
self.output_types = input_data.get('outputs', None)

modules/createEVENT/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ add_subdirectory(stochasticWave)
3131
add_subdirectory(TaichiEvent)
3232
add_subdirectory(Celeris)
3333
add_subdirectory(shakeMapEvent)
34+
add_subdirectory(DRM)
3435

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#Python scripts for pre and post-processing
2+
simcenter_add_python_script(SCRIPT DRM.py)
3+

modules/createEVENT/DRM/DRM.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import json
2+
import sys
3+
import h5py
4+
5+
def main(args):
6+
srtName = args[2]
7+
evtName = args[4]
8+
9+
# nothing to do with the random variables for now
10+
11+
with open(srtName, encoding='utf-8') as json_file:
12+
data = json.load(json_file)
13+
14+
15+
if "--getRV" in args:
16+
preprocessing = True
17+
18+
19+
20+
# create the event json file
21+
event_data = {
22+
"randomVariables": [],
23+
"Events" : []
24+
}
25+
# right now the drm only supports one event so the randomVariables should be empty
26+
27+
for i, event in enumerate(data["Events"][0]["Events"]):
28+
dt = event.get("dT", -1)
29+
numStep = event.get("numSteps", -1)
30+
if dt < 0 or numStep < 0:
31+
if data["Events"][0]["system"] == "local":
32+
# reading the dt from the hdf5 file
33+
with h5py.File(event["filePath"], 'r') as f:
34+
if dt < 0:
35+
dt = f["DRM_Metadata"]["dt"][()]
36+
if numStep < 0:
37+
tstart = f["DRM_Metadata"]["tstart"][()]
38+
tend = f["DRM_Metadata"]["tend"][()]
39+
numStep = int((tend - tstart) / dt)
40+
# update the event with the dt and numStep
41+
event["dT"] = dt
42+
event["numSteps"] = numStep
43+
event_data["Events"].append(event)
44+
event_data["Events"][i]["index"] = i
45+
event_data["Events"][i]["type"] = "DRM"
46+
event_data["Events"][i]["system"] = data["Events"][0]["system"]
47+
if event_data["Events"][i]["system"] == "predefined-designsafe":
48+
path = event_data["Events"][i]["filePath"]
49+
path = path.split("/")
50+
path = "../../"+ path[-1]
51+
event_data["Events"][i]["filePath"] = path
52+
53+
54+
55+
56+
57+
# create the event json file
58+
with open(evtName, 'w', encoding='utf-8') as outfile:
59+
json.dump(event_data, outfile, indent=2, ensure_ascii=False)
60+
61+
62+
63+
if __name__ == "__main__":
64+
main(sys.argv)
65+

modules/createSAM/openSeesInput/OpenSeesInput.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,22 @@ main(int argc, char **argv) {
157157
if (ndf != NULL)
158158
json_object_set(rootSAM,"ndf", ndf);
159159

160-
160+
json_t *inputType = json_object_get(theSIM, "type");
161+
if (inputType != NULL) {
162+
json_object_set(rootSAM,"subType", inputType);
163+
}
164+
json_t *useDamping = json_object_get(theSIM, "useDamping");
165+
if (useDamping != NULL) {
166+
json_object_set(rootSAM,"useDamping", useDamping);
167+
}
168+
json_t *numCoresPerModel = json_object_get(theSIM, "numCores");
169+
if (numCoresPerModel != NULL) {
170+
json_object_set(rootSAM,"coresPerModel", numCoresPerModel);
171+
} else {
172+
json_object_set(rootSAM,"coresPerModel", json_integer(1));
173+
}
174+
175+
161176
json_t *theRVs = json_object_get(theSIM,"randomVar");
162177

163178
// check nodes exists

modules/performSIMULATION/openSees/OpenSeesPreprocessor.cpp

Lines changed: 94 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ OpenSeesPreprocessor::processSections(ofstream &s) {
241241
}
242242

243243
int
244-
OpenSeesPreprocessor::processNodes(ofstream &s){
244+
OpenSeesPreprocessor::processNodes(ofstream &s)
245+
{
245246

246247
int index;
247248
json_t *node;
@@ -325,7 +326,8 @@ OpenSeesPreprocessor::processNodes(ofstream &s){
325326
}
326327

327328
int
328-
OpenSeesPreprocessor::processElements(ofstream &s){
329+
OpenSeesPreprocessor::processElements(ofstream &s)
330+
{
329331

330332
int index;
331333
json_t *element;
@@ -434,12 +436,21 @@ OpenSeesPreprocessor::processDamping(ofstream &s){
434436
*/
435437

436438
int
437-
OpenSeesPreprocessor::processDamping(ofstream &s){
439+
OpenSeesPreprocessor::processDamping(ofstream &s) {
438440

439441
//
440442
// determine dampingRatio .. should be in SAM, use SIM if not there
441443
//
442-
444+
json_t *useDamping = json_object_get(rootSAM,"useDamping");
445+
if (useDamping != NULL && json_is_true(useDamping) == false) {
446+
s << "# Damping not used in this analysis\n";
447+
return -1;
448+
} else {
449+
s << "# Damping used in this analysis\n";
450+
}
451+
452+
453+
443454
// get ratio from SAM, either mainbody or in Properties
444455
json_t *dampingT = json_object_get(rootSAM,"dampingRatio");
445456
if (dampingT == NULL) {
@@ -933,17 +944,27 @@ OpenSeesPreprocessor::processEvents(ofstream &s){
933944
s << "analysis " << json_string_value(json_object_get(rootSIM,"analysis")) << "\n";
934945

935946

936-
processDamping(s);
937-
938-
947+
int useDamping = processDamping(s);
948+
949+
if (useDamping == 0) {
950+
s << "set lambda1 [lindex $lambdaN 0]\n"
951+
<< "set T1 [expr 2*3.14159/$lambda1]\n"
952+
<< "set dTana [expr $T1/20.]\n"
953+
<< "if {$dt < $dTana} {set dTana $dt}\n";
954+
s << "analyze [expr int($numStep*$dt/$dTana)] $dTana \n";
955+
s << "remove recorders \n";
956+
}
957+
else if (useDamping == -1) {
958+
// damping not used
959+
s << "analyze $numStep $dt \n";
960+
s << "remove recorders \n";
961+
} else {
962+
// not supported
963+
std::cerr << "OpenSeesPreprocessor - damping model not supported.\n";
964+
return -1;
965+
}
939966

940967
//s << "set lambdaN [eigen 1];\n"
941-
s << "set lambda1 [lindex $lambdaN 0]\n"
942-
<< "set T1 [expr 2*3.14159/$lambda1]\n"
943-
<< "set dTana [expr $T1/20.]\n"
944-
<< "if {$dt < $dTana} {set dTana $dt}\n";
945-
s << "analyze [expr int($numStep*$dt/$dTana)] $dTana \n";
946-
s << "remove recorders \n";
947968
}
948969
}
949970

@@ -957,7 +978,9 @@ OpenSeesPreprocessor::processEvents(ofstream &s){
957978
edpList.end(); ++itEDP) {
958979
s << " " << *itEDP;
959980
}
960-
s << "]\n puts $output\n }\n call_python \n";
981+
s << "]\n puts $output\n }";
982+
// remove calling python inside tcl since it broke the mpi
983+
// "\nset pid [getPID]\nif {$pid==0} {call_python} \nbarrier\n";
961984

962985
} else if(strstr(postprocessingScript, ".tcl") != NULL) {
963986

@@ -993,6 +1016,63 @@ OpenSeesPreprocessor::processEvent(ofstream &s,
9931016
const char *eventType = json_string_value(json_object_get(event,"type"));
9941017
// std::cerr << "Processing Event type: " << eventType << "\n";
9951018

1019+
if (strcmp(eventType,"DRM") == 0) {
1020+
const char *eventName = json_string_value(json_object_get(event,"name"));
1021+
std::string eventPath = json_string_value(json_object_get(event,"filePath"));
1022+
double factor = json_number_value(json_object_get(event,"factor"));
1023+
double crdScale = json_number_value(json_object_get(event,"crd_scale"));
1024+
double distanceTolerance = json_number_value(json_object_get(event,"distance_tolerance"));
1025+
int doCoordinateTransformation = json_integer_value(json_object_get(event,"do_coordinate_transformation"));
1026+
double T00 = json_number_value(json_object_get(event,"T00"));
1027+
double T01 = json_number_value(json_object_get(event,"T01"));
1028+
double T02 = json_number_value(json_object_get(event,"T02"));
1029+
double T10 = json_number_value(json_object_get(event,"T10"));
1030+
double T11 = json_number_value(json_object_get(event,"T11"));
1031+
double T12 = json_number_value(json_object_get(event,"T12"));
1032+
double T20 = json_number_value(json_object_get(event,"T20"));
1033+
double T21 = json_number_value(json_object_get(event,"T21"));
1034+
double T22 = json_number_value(json_object_get(event,"T22"));
1035+
double x00 = json_number_value(json_object_get(event,"x00"));
1036+
double x01 = json_number_value(json_object_get(event,"x01"));
1037+
double x02 = json_number_value(json_object_get(event,"x02"));
1038+
const char *system = json_string_value(json_object_get(event,"system"));
1039+
double numSteps = json_integer_value(json_object_get(event,"numSteps"));
1040+
double dT = json_number_value(json_object_get(event,"dT"));
1041+
1042+
1043+
1044+
if (strcmp(system,"Remote") == 0 ||
1045+
strcmp(system,"remote") == 0 ||
1046+
strcmp(system,"REMOTE") == 0 ||
1047+
strcmp(system,"DesignSafe") == 0 ||
1048+
strcmp(system,"designsafe") == 0 ||
1049+
strcmp(system,"DESIGNSAFE") == 0)
1050+
{
1051+
// make the eventPath ..
1052+
eventPath = "../";
1053+
}
1054+
1055+
1056+
// print out the DRM event
1057+
s << "#set maxPatternTag [getMaxPatternTag]\n";
1058+
s << "set maxPatternTag 1000;\n";
1059+
s << "set patternTag [expr $maxPatternTag + 1]\n";
1060+
// pattern H5DRM $patternTag "/path/to/H5DRM/dataset" $factor $crd_scale $distance_tolerance $do_coordinate_transformation $T00 $T01 $T02 $T10 $T11 $T12 $T20 $T21 $T22 $x00 $x01 $x02
1061+
s << "pattern H5DRM $patternTag \"" << eventPath << "\"" << " " << factor << " "
1062+
<< crdScale << " " << distanceTolerance << " " << doCoordinateTransformation << " "
1063+
<< T00 << " " << T01 << " " << T02 << " "
1064+
<< T10 << " " << T11 << " " << T12 << " "
1065+
<< T20 << " " << T21 << " " << T22 << " "
1066+
<< x00 << " " << x01 << " " << x02 << "\n";
1067+
s << "set DRM_NAME \"" << eventName << "\"\n";
1068+
s << "set numStep " << numSteps << "\n";
1069+
s << "set dt " << dT << "\n";
1070+
analysisType = 1;
1071+
}
1072+
1073+
1074+
1075+
9961076
if (strcmp(eventType,"Seismic") == 0 ||
9971077
strcmp(eventType,"Wind") == 0 ||
9981078
strcmp(eventType,"timeHistory") == 0 ||

0 commit comments

Comments
 (0)