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

Radioactive decay #679

Merged
merged 16 commits into from
Jan 18, 2024
Merged

Radioactive decay #679

merged 16 commits into from
Jan 18, 2024

Conversation

RemDelaporteMathurin
Copy link
Collaborator

@RemDelaporteMathurin RemDelaporteMathurin commented Jan 16, 2024

Proposed changes

This PR implements radioactive decay (fixes #488).

The new formulation is:

$$ \frac{\partial c_m}{\partial t} = \nabla \cdot (D \nabla c_m) - \lambda c_m - \sum \left( -k_i \ c_m \ (n_i - c_{t,i}) + p_i \ c_{t,i} \right) $$

$$ \frac{\partial c_{t,i}}{\partial t}=k_i \ c_m \ (n_i - c_{t,i})- p_i \ c_{t,i} - \lambda c_{t,i} $$

where $\lambda$ is the decay constant (expressed in s^-1).

It is implemented as a volumetric source object inheriting from F.Source.
It takes a decay constant parameter.

Usage:

import festim as F
import numpy as np


my_model = F.Simulation()

my_model.traps = [
    F.Trap(0, 1, 0, 3, materials=my_model.materials.materials[0], density=100)
]

half_life = 50  # seconds
decay_constant = np.log(2) / half_life

my_model.sources = [
    F.RadioactiveDecay(decay_constant=decay_constant, volume=1, field="solute"),
    F.RadioactiveDecay(decay_constant=decay_constant, volume=1, field="1"),
]

Alternatively, a single decay source can be applied to all concentrations (default behaviour):

import festim as F
import numpy as np


my_model = F.Simulation()

my_model.traps = [
    F.Trap(0, 1, 0, 3, materials=my_model.materials.materials[0], density=100)
]

half_life = 50  # seconds
decay_constant = np.log(2) / half_life

my_model.sources = [
    F.RadioactiveDecay(decay_constant=decay_constant, volume=1, field="all"),
]

On a simple simulation with no BCs, no trapping/detrapping, but initial conditions (200 for mobile and 100 for trapped concentration), a half-life of 50 s, things work as expected:

image

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)

Further comments

@jhdark I had to modify the formulation in order to make this work. Before, we had:

$$ \frac{\partial c_m}{\partial t} = \nabla \cdot (D \nabla c_m ) + S - \sum \frac{\partial c_{t,i}}{\partial t} $$

This trapping term wouldn't work when adding decay. Since:

$$ \frac{\partial c_{t,i}}{\partial t}=k_i \ c_m \ (n_i - c_{t,i})- p_i \ c_{t,i} - \lambda c_{t,i} $$

then the decay of trapped particles would create mobile particles!

I therefore had to:

  • modify the formulation
  • modify the MMS tests
  • modify some other units tests

I'm happy to break this PR down and open a smaller PR that just does this

Also, it might be interesting to allow several materials per source!

Copy link

codecov bot commented Jan 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (7c6ca17) 98.93% compared to head (5093be4) 98.95%.
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #679      +/-   ##
==========================================
+ Coverage   98.93%   98.95%   +0.01%     
==========================================
  Files          57       58       +1     
  Lines        2154     2195      +41     
==========================================
+ Hits         2131     2172      +41     
  Misses         23       23              

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

@RemDelaporteMathurin RemDelaporteMathurin marked this pull request as ready for review January 16, 2024 14:33
@RemDelaporteMathurin RemDelaporteMathurin added the enhancement New feature or request label Jan 16, 2024
Copy link
Collaborator

@jhdark jhdark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor things from me, and it seems there is still a little coverage missing. Otherwise looks good, could be very useful!

Copy link
Collaborator

@jhdark jhdark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

@RemDelaporteMathurin
Copy link
Collaborator Author

@Allentro You seemed interested in this feature. Do you have anything to add about this implementation?

@RemDelaporteMathurin RemDelaporteMathurin merged commit 759e7ec into main Jan 18, 2024
6 checks passed
@RemDelaporteMathurin RemDelaporteMathurin deleted the radioactive-decay branch January 18, 2024 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Radioactive decay
2 participants