Skip to content

Change of variable method for interface discontinuities#904

Merged
RemDelaporteMathurin merged 42 commits intofestim-dev:fenicsxfrom
RemDelaporteMathurin:change-of-var-method
Feb 18, 2025
Merged

Change of variable method for interface discontinuities#904
RemDelaporteMathurin merged 42 commits intofestim-dev:fenicsxfrom
RemDelaporteMathurin:change-of-var-method

Conversation

@RemDelaporteMathurin
Copy link
Collaborator

@RemDelaporteMathurin RemDelaporteMathurin commented Oct 30, 2024

needs #909

This implements the change of variable method we use in FESTIM 1 to handle interface discontinuities.

Example usage:

import festim as F
import numpy as np

my_model = F.HydrogenTransportProblemDiscontinuousChangeVar()

interface_1 = 0.2
interface_2 = 0.8

vertices = np.concatenate(
    [
        np.linspace(0, interface_1, num=100),
        np.linspace(interface_1, interface_2, num=100),
        np.linspace(interface_2, 1, num=100),
    ]
)

my_model.mesh = F.Mesh1D(vertices)

H = F.SpeciesChangeVar("H", mobile=True)
H2 = F.SpeciesChangeVar("H2", mobile=True)
trapped_H = F.SpeciesChangeVar("H_trapped", mobile=False)
empty_trap = F.ImplicitSpecies(n=0.5, others=[trapped_H])

my_model.species = [H, H2, trapped_H]

material_left = F.Material(D_0=2.0, E_D=0.1, K_S_0=2.0, E_K_S=0.1)
material_mid = F.Material(D_0=2.0, E_D=0.1, K_S_0=2.0, E_K_S=0.1)
material_right = F.Material(
    D_0=2.0, E_D=0.1, K_S_0={H: 2.0, H2: 4.0}, E_K_S={H: 0.1, H2: 0.1}
)

left_domain = F.VolumeSubdomain1D(3, borders=[0, interface_1], material=material_left)
middle_domain = F.VolumeSubdomain1D(
    4, borders=[interface_1, interface_2], material=material_mid
)
right_domain = F.VolumeSubdomain1D(5, borders=[interface_2, 1], material=material_right)

left_surface = F.SurfaceSubdomain1D(id=1, x=vertices[0])
right_surface = F.SurfaceSubdomain1D(id=2, x=vertices[-1])

my_model.subdomains = [
    left_domain,
    middle_domain,
    right_domain,
    left_surface,
    right_surface,
]

my_model.reactions = [
    F.Reaction(
        reactant=[H, empty_trap],
        product=[trapped_H],
        k_0=2,
        E_k=0,
        p_0=0.1,
        E_p=0,
        volume=domain,
    )
    for domain in [left_domain, middle_domain, right_domain]
]

my_model.boundary_conditions = [
    F.FixedConcentrationBC(left_surface, value=2, species=H),
    F.FixedConcentrationBC(right_surface, value=2, species=H),
    F.FixedConcentrationBC(left_surface, value=2, species=H2),
    F.FixedConcentrationBC(right_surface, value=2, species=H2),
]

my_model.temperature = lambda x, t: 400 + 100 * t + 100 * x[0]

my_model.settings = F.Settings(
    atol=1e-10,
    rtol=1e-10,
    final_time=10,
)
my_model.settings.stepsize = F.Stepsize(1)

my_model.exports = [
    F.VTXSpeciesExport(f"u_{field}.bp", field=field)
    for field in [H, trapped_H, H2]
]
my_model.initialise()
my_model.run()

@RemDelaporteMathurin RemDelaporteMathurin added enhancement New feature or request fenicsx Issue that is related to the fenicsx support labels Oct 30, 2024
@codecov
Copy link

codecov bot commented Oct 30, 2024

Codecov Report

Attention: Patch coverage is 80.46512% with 42 lines in your changes missing coverage. Please review.

Project coverage is 96.02%. Comparing base (819379a) to head (22d5d79).
Report is 341 commits behind head on fenicsx.

Files with missing lines Patch % Lines
src/festim/material.py 25.00% 18 Missing ⚠️
src/festim/problem_change_of_var.py 88.97% 14 Missing ⚠️
src/festim/boundary_conditions/dirichlet_bc.py 70.00% 9 Missing ⚠️
src/festim/hydrogen_transport_problem.py 94.73% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           fenicsx     #904      +/-   ##
===========================================
- Coverage    97.53%   96.02%   -1.52%     
===========================================
  Files           44       45       +1     
  Lines         2233     2439     +206     
===========================================
+ Hits          2178     2342     +164     
- Misses          55       97      +42     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@RemDelaporteMathurin RemDelaporteMathurin changed the title WIP Change of var method for interface discontinuities Change of variable method for interface discontinuities Feb 18, 2025
@RemDelaporteMathurin RemDelaporteMathurin marked this pull request as ready for review February 18, 2025 10:09
@RemDelaporteMathurin
Copy link
Collaborator Author

I fixed a bunch of things and it's now time to merge this.

There's quite a lot of tidy up to do but I'll do it in a separate PR

@RemDelaporteMathurin RemDelaporteMathurin merged commit d696744 into festim-dev:fenicsx Feb 18, 2025
6 of 9 checks passed
@RemDelaporteMathurin RemDelaporteMathurin deleted the change-of-var-method branch February 18, 2025 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request fenicsx Issue that is related to the fenicsx support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants