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

Checkpointing #952

Open
wants to merge 8 commits into
base: fenicsx
Choose a base branch
from

Conversation

RemDelaporteMathurin
Copy link
Collaborator

@RemDelaporteMathurin RemDelaporteMathurin commented Feb 26, 2025

Proposed changes

Contributes to #946 for the mono-material case. Checkpointing (ie. reading a function from a file) is implemented by leveraging adios4dolfinx (thanks @jorgensd for this!).

As it doesn't support submeshes for now, this only works for the non-mixed domain approach in the HydrogenTransportProblem class

Usage:

import festim as F

import dolfinx
import adios4dolfinx
import mpi4py.MPI as MPI

# build initial condition
mesh = dolfinx.mesh.create_unit_square(
    MPI.COMM_WORLD, nx=10, ny=10, cell_type=dolfinx.cpp.mesh.CellType.quadrilateral
)
el = "P"
degree = 1
V = dolfinx.fem.functionspace(mesh, (el, degree))


def f(x):
    return x[1] ** 2 + 2 * x[0] ** 2


u_ref = dolfinx.fem.Function(V)
u_ref.interpolate(f)
filename = "initial_condition.bp"

adios4dolfinx.write_mesh(filename, mesh)
adios4dolfinx.write_function(filename, u_ref, name="my_function", time=0.2)

# create problem
my_problem = F.HydrogenTransportProblem()
H = F.Species("H")
my_problem.species = [H]
my_problem.mesh = F.Mesh(mesh)
my_problem.initial_conditions = [
    F.InitialConcentrationFromFile(
        filename=filename, species=H, name="my_function", timestamp=0.2
    )
]
mat = F.Material(D_0=1, E_D=0.1, name="dummy_mat")
my_problem.subdomains = [F.VolumeSubdomain(id=0, material=mat)]

my_problem.temperature = 300

my_problem.exports = [
    F.VTXSpeciesExport(
        filename="H.bp",
        field=H,
        subdomain=my_problem.subdomains[0],
        checkpoint=False,
    ),
    F.VTXSpeciesExport(
        filename="H_for_checkpoint.bp",
        field=H,
        subdomain=my_problem.subdomains[0],
        checkpoint=True,
    )
]

my_problem.settings = F.Settings(atol=1e-10, rtol=1e-10, final_time=100)
my_problem.settings.stepsize = F.Stepsize(1)
my_problem.initialise()
my_problem.run()

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)

@RemDelaporteMathurin RemDelaporteMathurin added the fenicsx Issue that is related to the fenicsx support label Feb 26, 2025
Copy link

codecov bot commented Feb 26, 2025

Codecov Report

Attention: Patch coverage is 96.07843% with 2 lines in your changes missing coverage. Please review.

Project coverage is 96.00%. Comparing base (96d62ff) to head (bf6be2a).

Files with missing lines Patch % Lines
src/festim/hydrogen_transport_problem.py 93.10% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           fenicsx     #952      +/-   ##
===========================================
- Coverage    96.02%   96.00%   -0.02%     
===========================================
  Files           45       45              
  Lines         2439     2478      +39     
===========================================
+ Hits          2342     2379      +37     
- Misses          97       99       +2     

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fenicsx Issue that is related to the fenicsx support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant