Skip to content

Commit f39abf6

Browse files
committed
Refactor processEvents to remove python call in tcl and move it outside of tcl
1 parent 896b1d7 commit f39abf6

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

modules/performSIMULATION/openSees/OpenSeesPreprocessor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,9 @@ OpenSeesPreprocessor::processEvents(ofstream &s){
978978
edpList.end(); ++itEDP) {
979979
s << " " << *itEDP;
980980
}
981-
s << "]\n puts $output\n }\nset pid [getPID]\nif {$pid==0} {call_python} \nbarrier\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";
982984

983985
} else if(strstr(postprocessingScript, ".tcl") != NULL) {
984986

modules/performSIMULATION/openSees/OpenSeesSimulation.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def main(args): # noqa: D103
106106
with open(samName, 'w') as samFile:
107107
json.dump(samData, samFile)
108108

109-
preprocessorCommand = f'"{scriptDir}/OpenSeesPreprocessor" {aimName} {samName} {evtName} {edpName} {simName} example.tcl > workflow.err1 2>&1' # noqa: N806
109+
preprocessorCommand = f'"{scriptDir}/OpenSeesPreprocessor" {aimName} {samName} {evtName} {edpName} {simName} example.tcl > workflow.err 2>&1' # noqa: N806
110110
exit_code = subprocess.Popen(preprocessorCommand, shell=True).wait() # noqa: S602
111111
# exit_code = subprocess.run(preprocessorCommand, shell=True).returncode # Maybe better for compatibility - jb
112112
# if not exit_code==0:
@@ -145,6 +145,31 @@ def main(args): # noqa: D103
145145
# exit_code = -1
146146
# exit(exit_code)
147147

148+
postprocess_commands = []
149+
150+
with open(edpName, 'r') as edpFile:
151+
edpData = json.load(edpFile)
152+
engdemand = edpData.get("EngineeringDemandParameters", [])
153+
for edp in engdemand:
154+
postprocessScript = edp.get("postprocessScript")
155+
if postprocessScript and postprocessScript.endswith(".py"):
156+
args = " ".join(arg.get("type", "") for arg in edp.get("responses", []))
157+
command = f'python {postprocessScript} {args} >> workflow.err 2>&1'
158+
postprocess_commands.append(command)
159+
if exit_code == 0:
160+
for postprocess in postprocess_commands:
161+
subprocess.Popen(
162+
postprocess,
163+
shell=True
164+
).wait()
165+
166+
print("Postprocess commands:")
167+
print(postprocess_commands)
168+
169+
170+
171+
172+
148173
# Run postprocessor
149174
postprocessorCommand = f'"{scriptDir}/OpenSeesPostprocessor" {aimName} {samName} {evtName} {edpName} >> workflow.err 2>&1' # noqa: N806
150175
exit_code = subprocess.Popen(postprocessorCommand, shell=True).wait() # noqa: S602, F841

0 commit comments

Comments
 (0)