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

call bounding_box_tree() in initialise() #571

Merged
merged 1 commit into from
Sep 28, 2023

Conversation

RemDelaporteMathurin
Copy link
Collaborator

Proposed changes

This fixes #498 by calling mesh.bounding_box_tree() in Simulation.initialise()

This was suggested by the FEniCS community to solve the processes communication issues.

I tested the fix with this MWE:

import festim as F
import fenics as f

my_model = F.Simulation(log_level=20)
mesh_size = 20
mesh = f.UnitSquareMesh(mesh_size, mesh_size)
material_tag = 1
volume_markers = f.MeshFunction("size_t", mesh, mesh.topology().dim(), material_tag)
surface_markers = f.MeshFunction("size_t", mesh, 1, 0)

boundary_left = f.CompiledSubDomain("on_boundary && near(x[0], L, tol)", tol=1e-14, L=0)
boundary_left.mark(surface_markers, 1)
my_model.mesh = F.Mesh(
    mesh=mesh, volume_markers=volume_markers, surface_markers=surface_markers
)
my_model.materials = F.Materials(
    [
        F.Material(
            id=material_tag,
            D_0=1,
            E_D=1,
            S_0=1,
            E_S=1,
        ),
    ]
)
my_model.T = F.Temperature(value=300)
my_model.boundary_conditions = [
    F.DirichletBC(surfaces=1, value=1e20, field=0),
]
my_model.settings = F.Settings(
    transient=False,
    absolute_tolerance=1e12,
    relative_tolerance=1e-08,
    chemical_pot=True,
)
my_model.initialise()
my_model.run()
mpirun -np 2 python3 test.py

Before the fix the solver would just hang.

Now the problem is solved correctly:

Process 0: Computed global bounding box tree with 3 boxes.
Process 1: Computed global bounding box tree with 3 boxes.
Process 0: No Jacobian form specified for nonlinear variational problem.
Process 0: Differentiating residual form F to obtain Jacobian J = F'.
Process 1: No Jacobian form specified for nonlinear variational problem.
Process 1: Differentiating residual form F to obtain Jacobian J = F'.
Process 0: Solving nonlinear variational problem.
Process 1: Solving nonlinear variational problem.
  Process 0: Newton iteration 0: r (abs) = 0.000e+00 (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-09)
  Process 0: Newton solver finished in 0 iterations and 0 linear solver iterations.
Process 0: No Jacobian form specified for nonlinear variational problem.
Process 0: Differentiating residual form F to obtain Jacobian J = F'.
Process 1: No Jacobian form specified for nonlinear variational problem.
Process 1: Differentiating residual form F to obtain Jacobian J = F'.
Process 0: Solving nonlinear variational problem.
Process 1: Solving nonlinear variational problem.
  Process 0: Newton iteration 0: r (abs) = 3.536e-02 (tol = 1.000e-10) r (rel) = 1.000e+00 (tol = 1.000e-09)
  Process 0: Newton iteration 1: r (abs) = 1.482e-18 (tol = 1.000e-10) r (rel) = 4.191e-17 (tol = 1.000e-09)
  Process 0: Newton solver finished in 1 iterations and 1 linear solver iterations.
Process 0: No Jacobian form specified for nonlinear variational problem.
Process 0: Differentiating residual form F to obtain Jacobian J = F'.
Process 1: No Jacobian form specified for nonlinear variational problem.
Process 1: Differentiating residual form F to obtain Jacobian J = F'.
Process 0: Solving nonlinear variational problem.
Process 1: Solving nonlinear variational problem.
  Process 0: Newton iteration 0: r (abs) = 3.241e-19 (tol = 1.000e-10) r (rel) = 1.000e+00 (tol = 1.000e-09)
  Process 0: Newton solver finished in 0 iterations and 0 linear solver iterations.
Process 0: Solving nonlinear variational problem.
Process 1: Solving nonlinear variational problem.
  Process 0: Newton iteration 0: r (abs) = 8.356e+37 (tol = 1.000e+12) r (rel) = 1.000e+00 (tol = 1.000e-08)
  Process 0: Newton iteration 1: r (abs) = 1.562e+22 (tol = 1.000e+12) r (rel) = 1.869e-16 (tol = 1.000e-08)
  Process 0: Newton solver finished in 1 iterations and 1 linear solver iterations.
Process 0: Solving nonlinear variational problem.
Process 1: Solving nonlinear variational problem.
  Process 0: Newton iteration 0: r (abs) = 0.000e+00 (tol = 1.000e-10) r (rel) = -nan (tol = 1.000e-10)
  Process 0: Newton solver finished in 0 iterations and 0 linear solver iterations.
Defining initial values
Defining variational problem
Defining source terms
Defining boundary conditions
Solving steady state problem...
Solved problem in 0.00 s
Defining initial values
Defining variational problem
Defining source terms
Defining boundary conditions
Solving steady state problem...
Solved problem in 0.00 s

Types of changes

What types of changes does your code introduce to FESTIM?

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code refactoring
  • Documentation Update (if none of the other choices apply)
  • New tests

Checklist

  • Black formatted
  • Unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

@codecov
Copy link

codecov bot commented Sep 5, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (5e71059) 98.84% compared to head (65c6119) 98.84%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #571   +/-   ##
=======================================
  Coverage   98.84%   98.84%           
=======================================
  Files          56       56           
  Lines        2072     2073    +1     
=======================================
+ Hits         2048     2049    +1     
  Misses         24       24           
Files Changed Coverage Δ
festim/generic_simulation.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@RemDelaporteMathurin
Copy link
Collaborator Author

@jhdark @ehodille have been testing this fix locally and it seems to work well enough.
We can merge this!

@RemDelaporteMathurin RemDelaporteMathurin merged commit e751955 into main Sep 28, 2023
3 checks passed
@RemDelaporteMathurin RemDelaporteMathurin deleted the fix-hang-parallel branch September 28, 2023 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] hang behaviour in parallel with chemical potential
1 participant