Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing messages in parallel runs #937

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions festim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
as_constant,
as_expression,
as_constant_or_expression,
festim_print,
)

from .meshing.mesh import Mesh
Expand Down
11 changes: 9 additions & 2 deletions festim/concentration/mobile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from festim import Concentration, FluxBC, k_B, RadioactiveDecay, SurfaceKinetics
from festim import (
Concentration,
FluxBC,
k_B,
RadioactiveDecay,
SurfaceKinetics,
festim_print,
)
from fenics import *


Expand Down Expand Up @@ -178,7 +185,7 @@ def create_source_form(self, dx):
F_source = 0
expressions_source = []

print("Defining source terms")
festim_print("Defining source terms")
for source in self.sources:
if type(source.volume) is list:
volumes = source.volume
Expand Down
4 changes: 2 additions & 2 deletions festim/concentration/traps/extrinsic_trap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from festim import Trap, as_constant_or_expression
from festim import Trap, as_constant_or_expression, festim_print
from fenics import NewtonSolver, MPI


Expand Down Expand Up @@ -65,7 +65,7 @@ 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")
festim_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
10 changes: 5 additions & 5 deletions festim/generic_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,15 @@ def run_transient(self):
self.h_transport_problem.compute_jacobian()

# Time-stepping
print("Time stepping...")
festim.festim_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...")
festim.festim_print("Solving steady state problem...")

nb_iterations, converged = self.h_transport_problem.solve_once()

Expand All @@ -480,7 +480,7 @@ def run_steady(self):
# print final message
if converged:
msg = "Solved problem in {:.2f} s".format(elapsed_time)
print(msg)
festim.festim_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 +517,9 @@ def display_time(self):
not np.isclose(self.t, self.settings.final_time, atol=0)
and self.log_level == 40
):
print(msg, end="\r")
festim.festim_print(msg, end="\r")
else:
print(msg)
festim.festim_print(msg)

def run_post_processing(self):
"""Create post processing functions and compute/write the exports"""
Expand Down
13 changes: 9 additions & 4 deletions festim/h_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ 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")
festim.festim_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 +104,7 @@ def initialise(self, mesh, materials, dt=None):
self.define_newton_solver()

# Boundary conditions
print("Defining boundary conditions")
festim.festim_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,8 @@ def initialise_concentrations(self):
concentration.test_function = list(split(self.v))[index]
index += 1

print("Defining initial values")
festim.festim_print("Defining initial values")

field_to_component = {
"solute": 0,
"0": 0,
Expand Down Expand Up @@ -253,7 +256,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
7 changes: 6 additions & 1 deletion festim/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import festim
import xml.etree.ElementTree as ET
from fenics import Expression, UserExpression, Constant
from fenics import Expression, UserExpression, Constant, MPI
import sympy as sp


Expand Down Expand Up @@ -108,3 +108,8 @@ def extract_xdmf_labels(filename):

unique_labels = list(set(labels))
return unique_labels


def festim_print(msg, end="\n"):
if MPI.comm_world.rank == 0:
print(msg, end=end)
7 changes: 5 additions & 2 deletions festim/meshing/mesh_from_xdmf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fenics as f
from festim import Mesh
from festim import Mesh, festim_print


class MeshFromXDMF(Mesh):
Expand Down Expand Up @@ -43,6 +43,9 @@ 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")
festim_print(
"Succesfully load mesh with " + str(len(volume_markers)) + " cells"
)

self.volume_markers = volume_markers
self.surface_markers = surface_markers
9 changes: 6 additions & 3 deletions festim/temperature/temperature_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ 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")
festim.festim_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 +133,8 @@ def create_functions(self, materials, mesh, dt=None):
self.define_newton_solver()

if not self.transient:
print("Solving stationary heat equation")
festim.festim_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,8 @@ 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.
"""
festim.festim_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
Loading