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

WIP Change of var method for interface discontinuities #904

Draft
wants to merge 39 commits into
base: fenicsx
Choose a base branch
from

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
Copy link

codecov bot commented Oct 30, 2024

Codecov Report

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

Project coverage is 95.95%. Comparing base (effcbac) to head (e6ce4bc).

Files with missing lines Patch % Lines
src/festim/material.py 25.00% 18 Missing ⚠️
src/festim/problem_change_of_var.py 88.88% 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.49%   95.95%   -1.54%     
===========================================
  Files           44       45       +1     
  Lines         2193     2398     +205     
===========================================
+ Hits          2138     2301     +163     
- Misses          55       97      +42     

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


🚨 Try these New Features:

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