Skip to content

Commit

Permalink
use festim print
Browse files Browse the repository at this point in the history
  • Loading branch information
jhdark committed Jan 14, 2025
1 parent fc50534 commit 3eef19e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 31 deletions.
12 changes: 9 additions & 3 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,8 +185,7 @@ def create_source_form(self, dx):
F_source = 0
expressions_source = []

if MPI.comm_world.rank == 0:
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
5 changes: 2 additions & 3 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,8 +65,7 @@ def newton_solver(self, value):
self._newton_solver = value
elif isinstance(value, NewtonSolver):
if self._newton_solver:
if MPI.comm_world.rank == 0:
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
15 changes: 5 additions & 10 deletions festim/generic_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,17 +461,15 @@ def run_transient(self):
self.h_transport_problem.compute_jacobian()

# Time-stepping
if MPI.comm_world.rank == 0:
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
if MPI.comm_world.rank == 0:
print("Solving steady state problem...")
festim.festim_print("Solving steady state problem...")

nb_iterations, converged = self.h_transport_problem.solve_once()

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

def run_post_processing(self):
"""Create post processing functions and compute/write the exports"""
Expand Down
11 changes: 5 additions & 6 deletions festim/h_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ def newton_solver(self, value):
self._newton_solver = value
elif isinstance(value, NewtonSolver):
if self._newton_solver:
if MPI.comm_world.rank == 0:
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 @@ -103,8 +104,7 @@ def initialise(self, mesh, materials, dt=None):
self.define_newton_solver()

# Boundary conditions
if MPI.comm_world.rank == 0:
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 @@ -179,8 +179,7 @@ def initialise_concentrations(self):
concentration.test_function = list(split(self.v))[index]
index += 1

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

field_to_component = {
"solute": 0,
Expand Down
7 changes: 4 additions & 3 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,8 +43,9 @@ def define_markers(self):
f.XDMFFile(self.boundary_file).read(surface_markers, "f")
surface_markers = f.MeshFunction("size_t", mesh, surface_markers)

if f.MPI.comm_world.rank == 0:
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
11 changes: 5 additions & 6 deletions festim/temperature/temperature_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ def newton_solver(self, value):
self._newton_solver = value
elif isinstance(value, f.NewtonSolver):
if self._newton_solver:
if f.MPI.comm_world.rank == 0:
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 @@ -132,8 +133,7 @@ def create_functions(self, materials, mesh, dt=None):
self.define_newton_solver()

if not self.transient:
if f.MPI.comm_world.rank == 0:
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)
Expand All @@ -156,8 +156,7 @@ 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")
festim.festim_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 3eef19e

Please sign in to comment.