Skip to content

Commit

Permalink
only print messages on master process
Browse files Browse the repository at this point in the history
  • Loading branch information
jhdark committed Jan 13, 2025
1 parent 8d6857b commit f284093
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
3 changes: 2 additions & 1 deletion festim/concentration/mobile.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ def create_source_form(self, dx):
F_source = 0
expressions_source = []

print("Defining source terms")
if MPI.comm_world.rank == 0:
print("Defining source terms")
for source in self.sources:
if type(source.volume) is list:
volumes = source.volume
Expand Down
3 changes: 2 additions & 1 deletion festim/concentration/traps/extrinsic_trap.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def newton_solver(self, value):
self._newton_solver = value
elif isinstance(value, NewtonSolver):
if self._newton_solver:
print("Settings for the Newton solver will be overwritten")
if MPI.comm_world.rank == 0:
print("Settings for the Newton solver will be overwritten")
self._newton_solver = value
else:
raise TypeError("accepted type for newton_solver is fenics.NewtonSolver")
Expand Down
15 changes: 10 additions & 5 deletions festim/generic_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,17 @@ def run_transient(self):
self.h_transport_problem.compute_jacobian()

# Time-stepping
print("Time stepping...")
if MPI.comm_world.rank == 0:
print("Time stepping...")
while self.t < self.settings.final_time and not np.isclose(
self.t, self.settings.final_time, atol=0
):
self.iterate()

def run_steady(self):
# Solve steady state
print("Solving steady state problem...")
if MPI.comm_world.rank == 0:
print("Solving steady state problem...")

nb_iterations, converged = self.h_transport_problem.solve_once()

Expand All @@ -480,7 +482,8 @@ def run_steady(self):
# print final message
if converged:
msg = "Solved problem in {:.2f} s".format(elapsed_time)
print(msg)
if MPI.comm_world.rank == 0:
print(msg)
else:
msg = "The solver diverged in "
msg += "{:.0f} iteration(s) ({:.2f} s)".format(nb_iterations, elapsed_time)
Expand Down Expand Up @@ -517,9 +520,11 @@ def display_time(self):
not np.isclose(self.t, self.settings.final_time, atol=0)
and self.log_level == 40
):
print(msg, end="\r")
if MPI.comm_world.rank == 0:
print(msg, end="\r")
else:
print(msg)
if MPI.comm_world.rank == 0:
print(msg)

def run_post_processing(self):
"""Create post processing functions and compute/write the exports"""
Expand Down
14 changes: 10 additions & 4 deletions festim/h_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def newton_solver(self, value):
self._newton_solver = value
elif isinstance(value, NewtonSolver):
if self._newton_solver:
print("Settings for the Newton solver will be overwritten")
if MPI.comm_world.rank == 0:
print("Settings for the Newton solver will be overwritten")
self._newton_solver = value
else:
raise TypeError("accepted type for newton_solver is fenics.NewtonSolver")
Expand Down Expand Up @@ -102,7 +103,8 @@ def initialise(self, mesh, materials, dt=None):
self.define_newton_solver()

# Boundary conditions
print("Defining boundary conditions")
if MPI.comm_world.rank == 0:
print("Defining boundary conditions")
self.create_dirichlet_bcs(materials, mesh)
if self.settings.transient:
self.traps.define_variational_problem_extrinsic_traps(mesh.dx, dt, self.T)
Expand Down Expand Up @@ -177,7 +179,9 @@ def initialise_concentrations(self):
concentration.test_function = list(split(self.v))[index]
index += 1

print("Defining initial values")
if MPI.comm_world.rank == 0:
print("Defining initial values")

field_to_component = {
"solute": 0,
"0": 0,
Expand Down Expand Up @@ -253,7 +257,9 @@ def define_variational_problem(self, materials, mesh, dt=None):
dt (festim.Stepsize, optional): the stepsize, only needed if
self.settings.transient is True. Defaults to None.
"""
print("Defining variational problem")
if MPI.comm_world.rank == 0:
print("Defining variational problem")

expressions = []
F = 0

Expand Down
4 changes: 3 additions & 1 deletion festim/meshing/mesh_from_xdmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def define_markers(self):
f.XDMFFile(self.boundary_file).read(surface_markers, "f")
surface_markers = f.MeshFunction("size_t", mesh, surface_markers)

print("Succesfully load mesh with " + str(len(volume_markers)) + " cells")
if f.MPI.comm_world.rank == 0:
print("Succesfully load mesh with " + str(len(volume_markers)) + " cells")

self.volume_markers = volume_markers
self.surface_markers = surface_markers
10 changes: 7 additions & 3 deletions festim/temperature/temperature_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def newton_solver(self, value):
self._newton_solver = value
elif isinstance(value, f.NewtonSolver):
if self._newton_solver:
print("Settings for the Newton solver will be overwritten")
if f.MPI.comm_world.rank == 0:
print("Settings for the Newton solver will be overwritten")
self._newton_solver = value
else:
raise TypeError("accepted type for newton_solver is fenics.NewtonSolver")
Expand Down Expand Up @@ -131,7 +132,9 @@ def create_functions(self, materials, mesh, dt=None):
self.define_newton_solver()

if not self.transient:
print("Solving stationary heat equation")
if f.MPI.comm_world.rank == 0:
print("Solving stationary heat equation")

dT = f.TrialFunction(self.T.function_space())
JT = f.derivative(self.F, self.T, dT)
problem = festim.Problem(JT, self.F, self.dirichlet_bcs)
Expand All @@ -153,8 +156,9 @@ def define_variational_problem(self, materials, mesh, dt=None):
dt (festim.Stepsize, optional): the stepsize. Only needed if
self.transient is True. Defaults to None.
"""
if f.MPI.comm_world.rank == 0:
print("Defining variational problem heat transfers")

print("Defining variational problem heat transfers")
T, T_n = self.T, self.T_n
v_T = self.v_T

Expand Down

0 comments on commit f284093

Please sign in to comment.