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

Bugfixes #523

Merged
merged 18 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ jobs:
- run:
name: Run Unit tests
command: |
python3 -m pytest test/unit/ --cov FESTIM --cov-report xml --cov-report term
python3 -m pytest test/unit/ --cov festim --cov-report xml --cov-report term
- run:
name: Run HTransportProblem tests
command: |
python3 -m pytest test/h_transport_problem/ --cov FESTIM --cov-append --cov-report xml --cov-report term
python3 -m pytest test/h_transport_problem/ --cov festim --cov-append --cov-report xml --cov-report term
- run:
name: Run HeatTransferProblem tests
command: |
python3 -m pytest test/heat_transfer_problem/ --cov FESTIM --cov-append --cov-report xml --cov-report term
python3 -m pytest test/heat_transfer_problem/ --cov festim --cov-append --cov-report xml --cov-report term
- run:
name: Run Simulation tests
command: |
python3 -m pytest test/simulation/ --cov FESTIM --cov-append --cov-report xml --cov-report term
python3 -m pytest test/simulation/ --cov festim --cov-append --cov-report xml --cov-report term
- run:
name: Run System tests
command: |
python3 -m pytest test/system/ --cov FESTIM --cov-append --cov-report xml --cov-report term
bash <(curl -s https://codecov.io/bash) -t cf160fda-091b-4d7f-a22d-a9509c36720c
python3 -m pytest test/system/ --cov festim --cov-append --cov-report xml --cov-report term
bash <(curl -s https://codecov.io/bash)
2 changes: 1 addition & 1 deletion demos/demo_Ogorodnikova.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
"outputs": [],
"source": [
"my_model.boundary_conditions = [\n",
" F.DirichletBC(surfaces=[1, 2], value=0)\n",
" F.DirichletBC(surfaces=[1, 2], value=0, field=0)\n",
"]"
]
},
Expand Down
15 changes: 11 additions & 4 deletions demos/demo_derived_quantities.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,13 @@
"my_model.boundary_conditions = [\n",
" F.DirichletBC(\n",
" surfaces=1,\n",
" value=1e15\n",
" value=1e15,\n",
" field=0\n",
" ),\n",
" F.DirichletBC(\n",
" surfaces=2,\n",
" value=0\n",
" value=0,\n",
" field=0\n",
" )\n",
"]"
]
Expand Down Expand Up @@ -645,7 +647,7 @@
"metadata": {
"file_extension": ".py",
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3.6.9 64-bit",
"language": "python",
"name": "python3"
},
Expand All @@ -665,7 +667,12 @@
"name": "python",
"npconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": 3
"version": 3,
"vscode": {
"interpreter": {
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
3 changes: 2 additions & 1 deletion demos/demo_multi_materials.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@
"source": [
"left_bc = F.DirichletBC(\n",
" surfaces=1,\n",
" value=1e20\n",
" value=1e20,\n",
" field=0\n",
" )\n",
"\n",
"right_bc = F.RecombinationFlux(\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Installing FEniCS

FESTIM requires FEniCS to run.

It can be installed using Docker::
It can be installed using `Docker <https://www.docker.com/>`_::

docker run -ti -v $(pwd):/home/fenics/shared quay.io/fenicsproject/stable:latest

Expand Down
19 changes: 13 additions & 6 deletions festim/boundary_conditions/boundary_condition.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import festim
import fenics as f
import sympy as sp
class BoundaryCondition:
"""Base BoundaryCondition class

Args:
surfaces (list or int): the surfaces of the BC
field (int or str): the field the boundary condition is
applied to. 0 and "solute" stand for the mobile
concentration, "T" for temperature
"""

class BoundaryCondition:
def __init__(self, surfaces, field=0) -> None:
def __init__(self, surfaces, field) -> None:

if not isinstance(surfaces, list):
surfaces = [surfaces]
self.surfaces = surfaces

self.field = field
if field == "solute":
self.field = 0
else:
self.field = field
self.expression = None
self.sub_expressions = []
2 changes: 1 addition & 1 deletion festim/boundary_conditions/dirichlets/custom_dc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def fun(T, solute, param1):

def __init__(self, surfaces, function, field=0, **prms) -> None:

super().__init__(surfaces, field=field)
super().__init__(surfaces, field=field, value=None)
self.function = function
self.prms = prms
self.convert_prms()
Expand Down
2 changes: 1 addition & 1 deletion festim/boundary_conditions/dirichlets/dc_imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ImplantationDirichlet(DirichletBC):
"""

def __init__(self, surfaces, phi, R_p, D_0, E_D, Kr_0=None, E_Kr=None) -> None:
super().__init__(surfaces, field=0)
super().__init__(surfaces, field=0, value=None)
self.phi = phi
self.R_p = R_p
self.D_0 = D_0
Expand Down
11 changes: 6 additions & 5 deletions festim/boundary_conditions/dirichlets/dirichlet_bc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ class DirichletBC(BoundaryCondition):

Args:
surfaces (list or int): the surfaces of the BC
value (float or sp.Expr, optional): the value of the boundary
condition. Defaults to None.
field (int, optional): the field the boundary condition is
applied to. Defaults to 0.
value (float or sp.Expr): the value of the boundary
condition.
field (int or str): the field the boundary condition is
applied to. 0 and "solute" stand for the mobile
concentration, "T" for temperature
"""

def __init__(self, surfaces, value=None, field=0) -> None:
def __init__(self, surfaces, value, field) -> None:
super().__init__(surfaces, field=field)
self.value = value
self.dirichlet_bc = []
Expand Down
2 changes: 1 addition & 1 deletion festim/boundary_conditions/dirichlets/henrys_bc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class HenrysBC(DirichletBC):
"""

def __init__(self, surfaces, H_0, E_H, pressure) -> None:
super().__init__(surfaces, field=0)
super().__init__(surfaces, field=0, value=None)
self.H_0 = H_0
self.E_H = E_H
self.pressure = pressure
Expand Down
2 changes: 1 addition & 1 deletion festim/boundary_conditions/dirichlets/sieverts_bc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SievertsBC(DirichletBC):
"""

def __init__(self, surfaces, S_0, E_S, pressure) -> None:
super().__init__(surfaces, field=0)
super().__init__(surfaces, field=0, value=None)
self.S_0 = S_0
self.E_S = E_S
self.pressure = pressure
Expand Down
2 changes: 1 addition & 1 deletion festim/boundary_conditions/fluxes/recombination_flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, Kr_0, E_Kr, order, surfaces) -> None:
self.Kr_0 = Kr_0
self.E_Kr = E_Kr
self.order = order
super().__init__(surfaces=surfaces)
super().__init__(surfaces=surfaces, field=0)

def create_form(self, T, solute):
Kr_0_expr = f.Expression(sp.printing.ccode(self.Kr_0), t=0, degree=1)
Expand Down
35 changes: 12 additions & 23 deletions festim/concentration/traps/trap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from festim import Concentration, k_B, Material
from festim import Concentration, k_B, Material, Theta
from fenics import *
import sympy as sp
import numpy as np
Expand Down Expand Up @@ -107,7 +107,7 @@ def make_density(self, densities):
)
)

def create_form(self, mobile, materials, T, dx, dt=None, chemical_pot=False):
def create_form(self, mobile, materials, T, dx, dt=None):
"""Creates the general form associated with the trap
d ct/ dt = k c_m (n - c_t) - p c_t + S

Expand All @@ -118,17 +118,13 @@ def create_form(self, mobile, materials, T, dx, dt=None, chemical_pot=False):
dx (fenics.Measure): the dx measure of the sim
dt (festim.Stepsize, optional): If None assuming steady state.
Defaults to None.
chemical_pot (bool, optional): If True, continuity of chemical
potential is assumed. Defaults to False.
"""
self.F = 0
self.create_trapping_form(mobile, materials, T, dx, dt, chemical_pot)
self.create_trapping_form(mobile, materials, T, dx, dt)
if self.sources is not None:
self.create_source_form(dx)

def create_trapping_form(
self, mobile, materials, T, dx, dt=None, chemical_pot=False
):
def create_trapping_form(self, mobile, materials, T, dx, dt=None):
"""d ct/ dt = k c_m (n - c_t) - p c_t

Args:
Expand All @@ -138,8 +134,6 @@ def create_trapping_form(
dx (fenics.Measure): the dx measure of the sim
dt (festim.Stepsize, optional): If None assuming steady state.
Defaults to None.
chemical_pot (bool, optional): If True, continuity of chemical
potential is assumed. Defaults to False.
"""
solution = self.solution
prev_solution = self.previous_solution
Expand All @@ -148,11 +142,6 @@ def create_trapping_form(
if not all(isinstance(mat, Material) for mat in self.materials):
self.make_materials(materials)

T = T.T
c_0 = mobile.solution
if chemical_pot:
theta = c_0

expressions_trap = []
F_trapping = 0 # initialise the form

Expand Down Expand Up @@ -185,24 +174,24 @@ def create_trapping_form(
# expressions to be updated
expressions_trap.append(density)

if chemical_pot:
# TODO this needs changing for Henry
# change of variable
S_0 = mat.S_0
E_S = mat.E_S
c_0 = theta * S_0 * exp(-E_S / k_B / T)
if isinstance(mobile, Theta) and mat.solubility_law == "henry":
raise NotImplementedError(
"Henry law of solubility is not implemented with traps"
)

c_0, c_0_n = mobile.get_concentration_for_a_given_material(mat, T)

# k(T)*c_m*(n - c_t) - p(T)*c_t
F_trapping += (
-k_0
* exp(-E_k / k_B / T)
* exp(-E_k / k_B / T.T)
* c_0
* (density - solution)
* test_function
* dx(mat.id)
)
F_trapping += (
p_0 * exp(-E_p / k_B / T) * solution * test_function * dx(mat.id)
p_0 * exp(-E_p / k_B / T.T) * solution * test_function * dx(mat.id)
)

self.F_trapping = F_trapping
Expand Down
4 changes: 2 additions & 2 deletions festim/concentration/traps/traps.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def make_traps_materials(self, materials):
for trap in self.traps:
trap.make_materials(materials)

def create_forms(self, mobile, materials, T, dx, dt=None, chemical_pot=False):
def create_forms(self, mobile, materials, T, dx, dt=None):
self.F = 0
for trap in self.traps:
trap.create_form(mobile, materials, T, dx, dt=dt, chemical_pot=chemical_pot)
trap.create_form(mobile, materials, T, dx, dt=dt)
self.F += trap.F
self.sub_expressions += trap.sub_expressions

Expand Down
4 changes: 1 addition & 3 deletions festim/h_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,7 @@ def define_variational_problem(self, materials, mesh, dt=None):
expressions += self.mobile.sub_expressions

# Add traps
self.traps.create_forms(
self.mobile, materials, self.T, mesh.dx, dt, self.settings.chemical_pot
)
self.traps.create_forms(self.mobile, materials, self.T, mesh.dx, dt)
F += self.traps.F
expressions += self.traps.sub_expressions
self.F = F
Expand Down
Loading