Skip to content

Commit 91592b0

Browse files
author
Nicola-Fonzi
committed
MPIPrint for raising errors only on master node
1 parent 34c46b6 commit 91592b0

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

SU2_PY/FSI_tools/FSI_config.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ class FSIConfig:
5454
Read the file and store all the options into a dictionary.
5555
"""
5656

57-
def __init__(self,FileName):
57+
def __init__(self,FileName,comm):
5858
self.ConfigFileName = FileName
59+
self.comm = comm
5960
self._ConfigContent = {}
6061
self.readConfig()
6162
self.applyDefaults()
@@ -124,19 +125,35 @@ def applyDefaults(self):
124125

125126
if "MAPPING_MODES" not in self._ConfigContent:
126127
self._ConfigContent["MAPPING_MODES"] = "NO"
127-
print("MAPPING_MODES keyword was not found in the configuration file of the interface, setting to NO")
128+
MPIPrint("MAPPING_MODES keyword was not found in the configuration file of the interface, setting to NO",False)
128129

129130
if "IMPOSED_MOTION" not in self._ConfigContent:
130131
self._ConfigContent["IMPOSED_MOTION"] = "NO"
131-
print("IMPOSED_MOTION keyword was not found in the configuration file of the interface, setting to NO")
132+
MPIPrint("IMPOSED_MOTION keyword was not found in the configuration file of the interface, setting to NO",False)
132133

133134
if self._ConfigContent["IMPOSED_MOTION"] == "YES":
134135
if self._ConfigContent["AITKEN_RELAX"] != "STATIC" or self._ConfigContent["AITKEN_PARAM"] != 1.0:
135-
raise Exception("When imposing motion, the Aitken parameter must be static and equal to 1")
136+
MPIPrint("When imposing motion, the Aitken parameter must be static and equal to 1",True)
136137

137138
if self._ConfigContent["RESTART_SOL"] == "YES":
138139
if self._ConfigContent["TIME_TRESHOLD"] != -1:
139-
raise Exception("When restarting a simulation, the time threshold must be -1 for immediate coupling")
140+
MPIPrint("When restarting a simulation, the time threshold must be -1 for immediate coupling",True)
140141

141142
if self._ConfigContent["MAPPING_MODES"] == "YES" and self._ConfigContent["CSD_SOLVER"]!="NATIVE":
142-
raise Exception("Mapping modes only works with the native solver")
143+
MPIPrint("Mapping modes only works with the native solver",True)
144+
145+
def MPIPrint(self, message, error):
146+
"""
147+
Print a message, or raise error, on screen only from the master process.
148+
"""
149+
150+
if self.comm:
151+
myid = self.comm.Get_rank()
152+
else:
153+
myid = 0
154+
155+
if not myid:
156+
if error:
157+
raise Exception(message)
158+
else:
159+
print(message)

SU2_PY/fsi_computation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def main():
8686

8787
confFile = str(options.filename)
8888

89-
FSI_config = FSI.FSIConfig(confFile) # FSI configuration file
89+
FSI_config = FSI.FSIConfig(confFile, comm) # FSI configuration file
9090
CFD_ConFile = FSI_config['CFD_CONFIG_FILE_NAME'] # CFD configuration file
9191
CSD_ConFile = FSI_config['CSD_CONFIG_FILE_NAME'] # CSD configuration file
9292

0 commit comments

Comments
 (0)