@@ -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 ()
@@ -118,25 +119,41 @@ def readConfig(self):
118119 self ._ConfigContent [this_param ] = this_value
119120
120121 else :
121- print (this_param + " is an invalid option !" )
122+ self . MPIPrint (this_param + " is an invalid option !" , False )
122123
123124 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+ self . 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+ self . 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+ self . 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+ self . 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+ self .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 )
0 commit comments