Skip to content

Commit

Permalink
Merge pull request #535 from RemDelaporteMathurin/dev
Browse files Browse the repository at this point in the history
Regular merge to main
  • Loading branch information
RemDelaporteMathurin authored Jan 3, 2023
2 parents 60a1098 + a8e5022 commit cbf6f77
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ venv.bak/

# mypy
.mypy_cache/

# version file
**_version.py
1 change: 1 addition & 0 deletions festim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
from .boundary_conditions.fluxes.recombination_flux import RecombinationFlux
from .boundary_conditions.fluxes.convective_flux import ConvectiveFlux
from .boundary_conditions.fluxes.flux_custom import CustomFlux
from .boundary_conditions.fluxes.mass_flux import MassFlux

from .exports.exports import Exports
from .exports.export import Export
Expand Down
30 changes: 30 additions & 0 deletions festim/boundary_conditions/fluxes/mass_flux.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from festim import FluxBC, k_B
import fenics as f
import sympy as sp


class MassFlux(FluxBC):
"""
FluxBC subclass for advective mass flux
-D * grad(c) * n = h_mass * (c - c_ext)
Args:
h_mass (float or sp.Expr): mass transfer coefficient (m/s)
c_ext (float or sp.Expr): external concentration (1/m3)
surfaces (list or int): the surfaces of the BC
Reference: Bergman, T. L., Bergman, T. L., Incropera, F. P., Dewitt, D. P.,
& Lavine, A. S. (2011). Fundamentals of heat and mass transfer. John Wiley & Sons.
"""

def __init__(self, h_coeff, c_ext, surfaces) -> None:
self.h_coeff = h_coeff
self.c_ext = c_ext
super().__init__(surfaces=surfaces, field=0)

def create_form(self, T, solute):
h_coeff = f.Expression(sp.printing.ccode(self.h_coeff), t=0, degree=1)
c_ext = f.Expression(sp.printing.ccode(self.c_ext), t=0, degree=1)

self.form = -h_coeff * (solute - c_ext)
self.sub_expressions = [h_coeff, c_ext]
3 changes: 2 additions & 1 deletion festim/concentration/traps/neutron_induced_trap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class NeutronInducedTrap(ExtrinsicTrapBase):
Class for neutron induced trap creation with annealing.
The temporal evolution of the trap density is given by
dn_t/dt = phi*K*(1 - n_t/n_max) + A_0*exp(-E_A/(k_B*T))*n_t
dn_t/dt = phi*K*(1 - n_t/n_max) - A_0*exp(-E_A/(k_B*T))*n_t
Args:
k_0 (float, list): trapping pre-exponential factor (m3 s-1)
Expand Down Expand Up @@ -55,6 +55,7 @@ def __init__(
A_0=A_0,
E_A=E_A,
id=id,
**kwargs,
)

def create_form_density(self, dx, dt, T):
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
requires = [
"setuptools >= 45",
"wheel",
"setuptools_scm[toml] >= 6.2",
"setuptools_scm_git_archive",
"setuptools_scm[toml] >= 7.0.5"
]
build-backend = "setuptools.build_meta"

Expand Down
9 changes: 9 additions & 0 deletions test/unit/test_boundary_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,15 @@ def test_recomb_flux():
my_BC.create_form(T, c)


def test_mass_flux():
expr = 2 + festim.x
T = fenics.Expression(sp.printing.ccode(expr), degree=1, t=0)
c = fenics.Expression(sp.printing.ccode(expr), degree=1, t=0)

my_BC = festim.MassFlux(surfaces=0, h_coeff=expr, c_ext=expr)
my_BC.create_form(T, c)


def test_string_for_field_in_dirichletbc():
"""Test catching issue #462"""
# build
Expand Down
45 changes: 45 additions & 0 deletions test/unit/test_traps/test_neutron_induced_trap.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,48 @@ def test_create_form_density(self):
print(expected_form)
print(self.my_trap.form_density)
assert self.my_trap.form_density.equals(expected_form)


class TestNeutronInducedTrapSolverParameters:
"""
Test for NeutronInducedTrap class, with defined ExtrinsicTrapBase
solver parameters
"""

my_trap = festim.NeutronInducedTrap(
1,
1,
1,
1,
"mat_name",
phi=1,
K=2,
n_max=3,
A_0=4,
E_A=5,
absolute_tolerance=2.5,
relative_tolerance=1.2e-10,
maximum_iterations=13,
linear_solver="mumps",
)

def test_attributes_from_instanciation(self):
"""
Tests the solver paramters are assigned and ensures that
the default values have been updated
"""

assert self.my_trap.absolute_tolerance == 2.5
assert self.my_trap.relative_tolerance == 1.2e-10
assert self.my_trap.maximum_iterations == 13
assert self.my_trap.linear_solver == "mumps"

def test_attributes_change_since_instanciation(self):
"""
Test to ensure values can be updated after instanciation
"""

expected_tolerance = 3.6
self.my_trap.absolute_tolerance = 3.6

assert self.my_trap.absolute_tolerance == expected_tolerance

0 comments on commit cbf6f77

Please sign in to comment.