Skip to content

Commit f284093

Browse files
committed
only print messages on master process
1 parent 8d6857b commit f284093

File tree

6 files changed

+34
-15
lines changed

6 files changed

+34
-15
lines changed

festim/concentration/mobile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ def create_source_form(self, dx):
178178
F_source = 0
179179
expressions_source = []
180180

181-
print("Defining source terms")
181+
if MPI.comm_world.rank == 0:
182+
print("Defining source terms")
182183
for source in self.sources:
183184
if type(source.volume) is list:
184185
volumes = source.volume

festim/concentration/traps/extrinsic_trap.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def newton_solver(self, value):
6565
self._newton_solver = value
6666
elif isinstance(value, NewtonSolver):
6767
if self._newton_solver:
68-
print("Settings for the Newton solver will be overwritten")
68+
if MPI.comm_world.rank == 0:
69+
print("Settings for the Newton solver will be overwritten")
6970
self._newton_solver = value
7071
else:
7172
raise TypeError("accepted type for newton_solver is fenics.NewtonSolver")

festim/generic_simulation.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,15 +461,17 @@ def run_transient(self):
461461
self.h_transport_problem.compute_jacobian()
462462

463463
# Time-stepping
464-
print("Time stepping...")
464+
if MPI.comm_world.rank == 0:
465+
print("Time stepping...")
465466
while self.t < self.settings.final_time and not np.isclose(
466467
self.t, self.settings.final_time, atol=0
467468
):
468469
self.iterate()
469470

470471
def run_steady(self):
471472
# Solve steady state
472-
print("Solving steady state problem...")
473+
if MPI.comm_world.rank == 0:
474+
print("Solving steady state problem...")
473475

474476
nb_iterations, converged = self.h_transport_problem.solve_once()
475477

@@ -480,7 +482,8 @@ def run_steady(self):
480482
# print final message
481483
if converged:
482484
msg = "Solved problem in {:.2f} s".format(elapsed_time)
483-
print(msg)
485+
if MPI.comm_world.rank == 0:
486+
print(msg)
484487
else:
485488
msg = "The solver diverged in "
486489
msg += "{:.0f} iteration(s) ({:.2f} s)".format(nb_iterations, elapsed_time)
@@ -517,9 +520,11 @@ def display_time(self):
517520
not np.isclose(self.t, self.settings.final_time, atol=0)
518521
and self.log_level == 40
519522
):
520-
print(msg, end="\r")
523+
if MPI.comm_world.rank == 0:
524+
print(msg, end="\r")
521525
else:
522-
print(msg)
526+
if MPI.comm_world.rank == 0:
527+
print(msg)
523528

524529
def run_post_processing(self):
525530
"""Create post processing functions and compute/write the exports"""

festim/h_transport_problem.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def newton_solver(self, value):
5555
self._newton_solver = value
5656
elif isinstance(value, NewtonSolver):
5757
if self._newton_solver:
58-
print("Settings for the Newton solver will be overwritten")
58+
if MPI.comm_world.rank == 0:
59+
print("Settings for the Newton solver will be overwritten")
5960
self._newton_solver = value
6061
else:
6162
raise TypeError("accepted type for newton_solver is fenics.NewtonSolver")
@@ -102,7 +103,8 @@ def initialise(self, mesh, materials, dt=None):
102103
self.define_newton_solver()
103104

104105
# Boundary conditions
105-
print("Defining boundary conditions")
106+
if MPI.comm_world.rank == 0:
107+
print("Defining boundary conditions")
106108
self.create_dirichlet_bcs(materials, mesh)
107109
if self.settings.transient:
108110
self.traps.define_variational_problem_extrinsic_traps(mesh.dx, dt, self.T)
@@ -177,7 +179,9 @@ def initialise_concentrations(self):
177179
concentration.test_function = list(split(self.v))[index]
178180
index += 1
179181

180-
print("Defining initial values")
182+
if MPI.comm_world.rank == 0:
183+
print("Defining initial values")
184+
181185
field_to_component = {
182186
"solute": 0,
183187
"0": 0,
@@ -253,7 +257,9 @@ def define_variational_problem(self, materials, mesh, dt=None):
253257
dt (festim.Stepsize, optional): the stepsize, only needed if
254258
self.settings.transient is True. Defaults to None.
255259
"""
256-
print("Defining variational problem")
260+
if MPI.comm_world.rank == 0:
261+
print("Defining variational problem")
262+
257263
expressions = []
258264
F = 0
259265

festim/meshing/mesh_from_xdmf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def define_markers(self):
4343
f.XDMFFile(self.boundary_file).read(surface_markers, "f")
4444
surface_markers = f.MeshFunction("size_t", mesh, surface_markers)
4545

46-
print("Succesfully load mesh with " + str(len(volume_markers)) + " cells")
46+
if f.MPI.comm_world.rank == 0:
47+
print("Succesfully load mesh with " + str(len(volume_markers)) + " cells")
48+
4749
self.volume_markers = volume_markers
4850
self.surface_markers = surface_markers

festim/temperature/temperature_solver.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ def newton_solver(self, value):
7373
self._newton_solver = value
7474
elif isinstance(value, f.NewtonSolver):
7575
if self._newton_solver:
76-
print("Settings for the Newton solver will be overwritten")
76+
if f.MPI.comm_world.rank == 0:
77+
print("Settings for the Newton solver will be overwritten")
7778
self._newton_solver = value
7879
else:
7980
raise TypeError("accepted type for newton_solver is fenics.NewtonSolver")
@@ -131,7 +132,9 @@ def create_functions(self, materials, mesh, dt=None):
131132
self.define_newton_solver()
132133

133134
if not self.transient:
134-
print("Solving stationary heat equation")
135+
if f.MPI.comm_world.rank == 0:
136+
print("Solving stationary heat equation")
137+
135138
dT = f.TrialFunction(self.T.function_space())
136139
JT = f.derivative(self.F, self.T, dT)
137140
problem = festim.Problem(JT, self.F, self.dirichlet_bcs)
@@ -153,8 +156,9 @@ def define_variational_problem(self, materials, mesh, dt=None):
153156
dt (festim.Stepsize, optional): the stepsize. Only needed if
154157
self.transient is True. Defaults to None.
155158
"""
159+
if f.MPI.comm_world.rank == 0:
160+
print("Defining variational problem heat transfers")
156161

157-
print("Defining variational problem heat transfers")
158162
T, T_n = self.T, self.T_n
159163
v_T = self.v_T
160164

0 commit comments

Comments
 (0)