Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions modules/Workflow/WorkflowApplications.json
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,22 @@
}
]
},
{
"Name": "SSISimulation",
"ExecutablePath": "applications/createSAM/ssi_model/ssi.py",
"ApplicationSpecificInputs": [
{
"id": "fileName",
"type": "string",
"description": "Defines the name of the main OpenSees model file."
},
{
"id": "filePath",
"type": "string",
"description": "Defines the location of the main OpenSees model file."
}
]
},
{
"Name": "CustomPyInput",
"ExecutablePath": "applications/createSAM/customPyInput/customPyInput.py",
Expand Down
1 change: 1 addition & 0 deletions modules/createSAM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ add_subdirectory(AutoSDA)
add_subdirectory(RCFIAP)
add_subdirectory(customPyInput)
add_subdirectory(surrogateGP)
add_subdirectory(ssi_model)
1 change: 1 addition & 0 deletions modules/createSAM/ssi_model/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
simcenter_add_python_script(SCRIPT ssi.py)
100 changes: 100 additions & 0 deletions modules/createSAM/ssi_model/ssi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Copyright (c) 2022 Leland Stanford Junior University
# Copyright (c) 2022 The Regents of the University of California
#
# This file is part of the SimCenter Backend Applications
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# You should have received a copy of the BSD 3-Clause License along with
# this file. If not, see <http://www.opensource.org/licenses/>.
#
# Contributors:
# Amin Pakzad
#
# Description:
# implementing SSI simulations to the SIM tab


import argparse
import json
import os
import sys

errFileName = os.path.join(os.getcwd(), 'workflow.err')


def create_SAM(AIM_file, EVENT_file ,SAM_file):
print("create_SAM is called")
print("AIM_file: ", AIM_file)
print("SAM_file: ", SAM_file)
SAM_json = {}
AIM_json = {}
EVENT_json = {}
with open(EVENT_file, 'r') as f:
EVENT_json = json.load(f)
with open(AIM_file, 'r') as f:
AIM_json = json.load(f)

SAM_json = AIM_json['Modeling']
SAM_json['GeneralInformation'] = AIM_json['GeneralInformation']
SAM_json['subtype'] = "SSISimulation"


# {"mainScript": "femoramodel_example.tcl", "type": "OpenSeesInput", "NodeMapping": [], "numStory": -1, "ndm": 3, "ndf": 3, "subType": "FemoraInput", "useDamping": false, "coresPerModel": 10, "randomVar": [{"name": "softMat_vs", "value": 276.9518021028489}, {"name": "softMat_vp_vs_ratio", "value": 1.753312207525559}, {"name": "softMat_rho", "value": 2.049575892485012}], "dampingRatio": 0}
SAM_json['type'] = "OpenSeesInput"
SAM_json['mainScript'] = "" # will be set in the workflow
SAM_json['NodeMapping'] = AIM_json["Modeling"]["structure_info"].get("NodeMapping", [])
SAM_json['numStory'] = -1
SAM_json['ndm'] = AIM_json["Modeling"]["structure_info"].get("ndm", 3)
SAM_json['ndf'] = AIM_json["Modeling"]["structure_info"].get("ndf", 6)
SAM_json['subType'] = "SSISimulation"
SAM_json['useDamping'] = False
SAM_json['coresPerModel'] = -1 # will be set in the workflow
SAM_json['randomVar'] = AIM_json["Modeling"].get("randomVar", [])
SAM_json['dampingRatio'] = 0.0

with open(SAM_file, 'w') as f:
json.dump(SAM_json, f, indent=4)
print("SAM file is created")




if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--filenameAIM')
parser.add_argument('--filenameEVENT')
parser.add_argument('--filenameSAM')
parser.add_argument('--mainScript')
parser.add_argument('--getRV', nargs='?', const=True, default=False)
args = parser.parse_args()
print(args)
sys.exit(create_SAM(args.filenameAIM, args.filenameEVENT , args.filenameSAM))




3 changes: 3 additions & 0 deletions modules/performSIMULATION/openSees/OpenSeesPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,8 @@ OpenSeesPreprocessor::processEvents(ofstream &s){
// loop through EDPs and find corresponding EDP

char edpEventName[50];
s << "set pid [getPID]\n";
s << "if {$pid == 0} {\n";

for (int j=0; j<numEDPs; j++) {

Expand Down Expand Up @@ -885,6 +887,7 @@ OpenSeesPreprocessor::processEvents(ofstream &s){
}
}
}
s << "}\n"; // end of pid==0

// create analysis
if (analysisType == 1 || analysisType == 2) {
Expand Down
39 changes: 38 additions & 1 deletion modules/performSIMULATION/openSees/OpenSeesSimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,51 @@ def main(args): # noqa: D103
with open(samName, 'w') as samFile:
json.dump(samData, samFile)


if subtype == "SSISimulation":
# "building_type": "custom_3d_building"
if samData.get("building_type", "") not in ["custom_3d_building"]:
print(f"Error: building_type '{samData.get('building_type', '')}' is not supported for SSISimulation subtype.")
print("Only 'custom_3d_building' is supported.")
exit(1)
if samData.get("soil_type", "") not in ["soil_foundation_type_1"]:
print(f"Error: foundation_type '{samData.get('foundation_type', '')}' is not supported for SSISimulation subtype.")
print("Only 'foundation_type_1' is supported.")
exit(1)

if samData.get("building_type", "") == "custom_3d_building" and samData.get("soil_type", "") == "soil_foundation_type_1":
main_script = samData["structure_info"].get("model_file", None)
main_script = os.path.basename(main_script)
ext = "." + main_script.rsplit('.')[-1]
main_script = main_script[:-len(ext)] # remove the extension
main_script_new = main_script + "_example.tcl"
if main_script is None:
print("Error: model_file not found in structure_info of SAM file.")
exit(1)
from femora.components.simcenter.eeuq.soil_foundation_type_one import soil_foundation_type_one
num_cores = soil_foundation_type_one(model_filename=main_script_new,
info_file=samName,
EEUQ=True)
num_cores = int(num_cores)
samData["coresPerModel"] = num_cores
samData["mainScript"] = main_script_new


with open(samName, 'w') as samFile:
json.dump(samData, samFile)





preprocessorCommand = f'"{scriptDir}/OpenSeesPreprocessor" {aimName} {samName} {evtName} {edpName} {simName} example.tcl > workflow.err 2>&1' # noqa: N806
exit_code = subprocess.Popen(preprocessorCommand, shell=True).wait() # noqa: S602
# exit_code = subprocess.run(preprocessorCommand, shell=True).returncode # Maybe better for compatibility - jb
# if not exit_code==0:
# exit(exit_code)

# Run OpenSees
if subtype == "FemoraInput":
if subtype == "FemoraInput" or subtype == "SSISimulation":
coresPerModel = samData.get("coresPerModel", 1)
# Run OpenSees in parallel using mpirun
if runtype == "runningLocal":
Expand Down
Loading