From 0521d539ebd7de59faef358625309025e2ed0c32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Delaporte-Mathurin?= <40028739+RemDelaporteMathurin@users.noreply.github.com> Date: Fri, 9 Sep 2022 15:32:32 +0200 Subject: [PATCH 01/15] added link --- docs/source/getting_started.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index 7bf1d5082..5d3afc169 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -10,7 +10,7 @@ Installing FEniCS FESTIM requires FEniCS to run. -It can be installed using Docker:: +It can be installed using `Docker `_:: docker run -ti -v $(pwd):/home/fenics/shared quay.io/fenicsproject/stable:latest From f965d967415a51256821ef583fdf089068e48e59 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 14 Sep 2022 09:53:02 +0000 Subject: [PATCH 02/15] field argument is no longer optional --- festim/boundary_conditions/boundary_condition.py | 7 +------ festim/boundary_conditions/dirichlets/custom_dc.py | 2 +- festim/boundary_conditions/dirichlets/dc_imp.py | 2 +- festim/boundary_conditions/dirichlets/dirichlet_bc.py | 10 +++++----- festim/boundary_conditions/dirichlets/henrys_bc.py | 2 +- festim/boundary_conditions/dirichlets/sieverts_bc.py | 2 +- .../boundary_conditions/fluxes/recombination_flux.py | 2 +- test/system/test_system.py | 6 +++--- test/unit/test_boundary_conditions.py | 2 +- test/unit/test_mobile.py | 2 +- 10 files changed, 16 insertions(+), 21 deletions(-) diff --git a/festim/boundary_conditions/boundary_condition.py b/festim/boundary_conditions/boundary_condition.py index b86e69813..43dcce53d 100644 --- a/festim/boundary_conditions/boundary_condition.py +++ b/festim/boundary_conditions/boundary_condition.py @@ -1,10 +1,5 @@ -import festim -import fenics as f -import sympy as sp - - class BoundaryCondition: - def __init__(self, surfaces, field=0) -> None: + def __init__(self, surfaces, field) -> None: if not isinstance(surfaces, list): surfaces = [surfaces] diff --git a/festim/boundary_conditions/dirichlets/custom_dc.py b/festim/boundary_conditions/dirichlets/custom_dc.py index affa27de3..629944fc4 100644 --- a/festim/boundary_conditions/dirichlets/custom_dc.py +++ b/festim/boundary_conditions/dirichlets/custom_dc.py @@ -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() diff --git a/festim/boundary_conditions/dirichlets/dc_imp.py b/festim/boundary_conditions/dirichlets/dc_imp.py index 14bfea001..0e2ccc68b 100644 --- a/festim/boundary_conditions/dirichlets/dc_imp.py +++ b/festim/boundary_conditions/dirichlets/dc_imp.py @@ -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 diff --git a/festim/boundary_conditions/dirichlets/dirichlet_bc.py b/festim/boundary_conditions/dirichlets/dirichlet_bc.py index 18a17cbe6..4759648b0 100644 --- a/festim/boundary_conditions/dirichlets/dirichlet_bc.py +++ b/festim/boundary_conditions/dirichlets/dirichlet_bc.py @@ -8,13 +8,13 @@ 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): the field the boundary condition is + applied to. """ - 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 = [] diff --git a/festim/boundary_conditions/dirichlets/henrys_bc.py b/festim/boundary_conditions/dirichlets/henrys_bc.py index fdca4d61e..820d52fb4 100644 --- a/festim/boundary_conditions/dirichlets/henrys_bc.py +++ b/festim/boundary_conditions/dirichlets/henrys_bc.py @@ -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 diff --git a/festim/boundary_conditions/dirichlets/sieverts_bc.py b/festim/boundary_conditions/dirichlets/sieverts_bc.py index 398a8a866..c055c1678 100644 --- a/festim/boundary_conditions/dirichlets/sieverts_bc.py +++ b/festim/boundary_conditions/dirichlets/sieverts_bc.py @@ -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 diff --git a/festim/boundary_conditions/fluxes/recombination_flux.py b/festim/boundary_conditions/fluxes/recombination_flux.py index 37f362782..5d5e9daae 100644 --- a/festim/boundary_conditions/fluxes/recombination_flux.py +++ b/festim/boundary_conditions/fluxes/recombination_flux.py @@ -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) diff --git a/test/system/test_system.py b/test/system/test_system.py index 551a16b90..65ba9c837 100644 --- a/test/system/test_system.py +++ b/test/system/test_system.py @@ -827,7 +827,7 @@ def test_steady_state_with_2_materials(): my_mesh = festim.Mesh(mesh=mesh, volume_markers=vm, surface_markers=sm) my_temp = festim.Temperature(30) - my_bc = festim.DirichletBC([1], value=0) + my_bc = festim.DirichletBC([1], value=0, field=0) my_source = festim.Source(1, [1, 2, 3], "solute") my_settings = festim.Settings( @@ -873,7 +873,7 @@ def test_steady_state_traps_not_everywhere(): my_trap = festim.Trap(1, 0, 1, 0, ["mat_1", "mat_3"], 1) my_temp = festim.Temperature(1) - my_bc = festim.DirichletBC([1], value=1) + my_bc = festim.DirichletBC([1], value=1, field=0) my_settings = festim.Settings( absolute_tolerance=1e-10, @@ -1024,7 +1024,7 @@ def test_completion_tone(): my_model.materials = festim.Materials([festim.Material(id=1, D_0=1, E_D=0)]) my_model.T = festim.Temperature(100) my_model.boundary_conditions = [ - festim.DirichletBC(surfaces=[1, 2], value=0), + festim.DirichletBC(surfaces=[1, 2], value=0, field=0), ] my_stepsize = festim.Stepsize(1, stepsize_change_ratio=1.1, dt_min=1e-8) my_model.dt = my_stepsize diff --git a/test/unit/test_boundary_conditions.py b/test/unit/test_boundary_conditions.py index 428f60aca..1536e49e1 100644 --- a/test/unit/test_boundary_conditions.py +++ b/test/unit/test_boundary_conditions.py @@ -52,7 +52,7 @@ def test_define_dirichlet_bcs_theta(): mat2 = festim.Material(2, None, None, S_0=S_02, E_S=E_S2) my_mats = festim.Materials([mat1, mat2]) - my_bc = festim.DirichletBC([1, 2], value=200 + festim.t) + my_bc = festim.DirichletBC([1, 2], value=200 + festim.t, field=0) my_bc.create_dirichletbc( V, my_temp.T, diff --git a/test/unit/test_mobile.py b/test/unit/test_mobile.py index 56756b531..90c2fdab3 100644 --- a/test/unit/test_mobile.py +++ b/test/unit/test_mobile.py @@ -222,7 +222,7 @@ def test_fluxes(): my_mobile.test_function = f.TestFunction(V) my_mobile.boundary_conditions = [ festim.RecombinationFlux(Kr_0=Kr_0, E_Kr=E_Kr, order=order, surfaces=1), - festim.FluxBC(value=2 * festim.x + festim.t, surfaces=[1, 2]), + festim.FluxBC(value=2 * festim.x + festim.t, surfaces=[1, 2], field=0), ] T = festim.Temperature(value=1000) T.create_functions(my_mesh) From f4ea7941c3501a7304f7a45bfea69b7487a83c20 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 14 Sep 2022 10:00:59 +0000 Subject: [PATCH 03/15] added test that catches the bug --- test/unit/test_boundary_conditions.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/unit/test_boundary_conditions.py b/test/unit/test_boundary_conditions.py index 1536e49e1..56b696c99 100644 --- a/test/unit/test_boundary_conditions.py +++ b/test/unit/test_boundary_conditions.py @@ -506,3 +506,17 @@ def test_recomb_flux(): my_BC = festim.RecombinationFlux(surfaces=[0], Kr_0=expr, E_Kr=expr, order=2) my_BC.create_form(T, c) + +def test_string_for_field_in_dirichletbc(): + """Test catching issue #462 + """ + # build + mesh = fenics.UnitSquareMesh(4, 4) + + surface_marker = fenics.MeshFunction("size_t", mesh, 1, 0) + + V = fenics.VectorFunctionSpace(mesh, "P", 1, 2) + bc = festim.DirichletBC(surfaces=[0, 1], value=1, field="solute") + + # test + bc.create_dirichletbc(V, fenics.Constant(1), surface_marker) From c6eb856e5b5339b7f9af55f36c8502381580e72f Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 14 Sep 2022 10:01:24 +0000 Subject: [PATCH 04/15] field can now be "solute" --- festim/boundary_conditions/boundary_condition.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/festim/boundary_conditions/boundary_condition.py b/festim/boundary_conditions/boundary_condition.py index 43dcce53d..b05533bb6 100644 --- a/festim/boundary_conditions/boundary_condition.py +++ b/festim/boundary_conditions/boundary_condition.py @@ -5,6 +5,9 @@ def __init__(self, surfaces, field) -> None: surfaces = [surfaces] self.surfaces = surfaces - self.field = field + if field == "solute": + self.field = 0 + else: + self.field = field self.expression = None self.sub_expressions = [] From f9f970521338752de1048e78f39ed83f95a05ba1 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 14 Sep 2022 10:03:53 +0000 Subject: [PATCH 05/15] added docstrings --- festim/boundary_conditions/boundary_condition.py | 8 ++++++++ festim/boundary_conditions/dirichlets/dirichlet_bc.py | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/festim/boundary_conditions/boundary_condition.py b/festim/boundary_conditions/boundary_condition.py index b05533bb6..4d690361c 100644 --- a/festim/boundary_conditions/boundary_condition.py +++ b/festim/boundary_conditions/boundary_condition.py @@ -1,4 +1,12 @@ 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 + """ def __init__(self, surfaces, field) -> None: if not isinstance(surfaces, list): diff --git a/festim/boundary_conditions/dirichlets/dirichlet_bc.py b/festim/boundary_conditions/dirichlets/dirichlet_bc.py index 4759648b0..0af069c41 100644 --- a/festim/boundary_conditions/dirichlets/dirichlet_bc.py +++ b/festim/boundary_conditions/dirichlets/dirichlet_bc.py @@ -10,8 +10,9 @@ class DirichletBC(BoundaryCondition): surfaces (list or int): the surfaces of the BC value (float or sp.Expr): the value of the boundary condition. - field (int): the field the boundary condition is - applied to. + 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, field) -> None: From 23aa3f6dfdf4d50ccf1776c683ff7f317ff525ac Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 14 Sep 2022 10:09:42 +0000 Subject: [PATCH 06/15] fixed demos --- demos/demo_Ogorodnikova.ipynb | 2 +- demos/demo_derived_quantities.ipynb | 15 +++++++++++---- demos/demo_multi_materials.ipynb | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/demos/demo_Ogorodnikova.ipynb b/demos/demo_Ogorodnikova.ipynb index 1b9b8d6ea..5fe2f685e 100644 --- a/demos/demo_Ogorodnikova.ipynb +++ b/demos/demo_Ogorodnikova.ipynb @@ -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", "]" ] }, diff --git a/demos/demo_derived_quantities.ipynb b/demos/demo_derived_quantities.ipynb index b39a892f2..270c891c1 100644 --- a/demos/demo_derived_quantities.ipynb +++ b/demos/demo_derived_quantities.ipynb @@ -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", "]" ] @@ -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" }, @@ -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 diff --git a/demos/demo_multi_materials.ipynb b/demos/demo_multi_materials.ipynb index 872081fbd..2f10f990c 100644 --- a/demos/demo_multi_materials.ipynb +++ b/demos/demo_multi_materials.ipynb @@ -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", From a5be872bf90051e8a7cd87adc9690df7055ff22c Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 14 Sep 2022 10:12:05 +0000 Subject: [PATCH 07/15] black --- festim/boundary_conditions/boundary_condition.py | 1 + test/unit/test_boundary_conditions.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/festim/boundary_conditions/boundary_condition.py b/festim/boundary_conditions/boundary_condition.py index 4d690361c..1e751a09a 100644 --- a/festim/boundary_conditions/boundary_condition.py +++ b/festim/boundary_conditions/boundary_condition.py @@ -7,6 +7,7 @@ class BoundaryCondition: applied to. 0 and "solute" stand for the mobile concentration, "T" for temperature """ + def __init__(self, surfaces, field) -> None: if not isinstance(surfaces, list): diff --git a/test/unit/test_boundary_conditions.py b/test/unit/test_boundary_conditions.py index 56b696c99..eca259c20 100644 --- a/test/unit/test_boundary_conditions.py +++ b/test/unit/test_boundary_conditions.py @@ -507,9 +507,9 @@ def test_recomb_flux(): my_BC = festim.RecombinationFlux(surfaces=[0], Kr_0=expr, E_Kr=expr, order=2) my_BC.create_form(T, c) + def test_string_for_field_in_dirichletbc(): - """Test catching issue #462 - """ + """Test catching issue #462""" # build mesh = fenics.UnitSquareMesh(4, 4) From 25f28180c573a1245bc14d0eb481234f1b96f0a9 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 14 Sep 2022 11:19:35 +0000 Subject: [PATCH 08/15] added NonImplementedError and fixed test --- festim/concentration/traps/trap.py | 23 +++++++++-------------- test/unit/test_traps/test_trap.py | 15 +++++++++------ 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/festim/concentration/traps/trap.py b/festim/concentration/traps/trap.py index a94cfa5d0..1e014eb25 100644 --- a/festim/concentration/traps/trap.py +++ b/festim/concentration/traps/trap.py @@ -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 @@ -148,11 +148,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 @@ -185,24 +180,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 diff --git a/test/unit/test_traps/test_trap.py b/test/unit/test_traps/test_trap.py index 7733d76ea..36beff074 100644 --- a/test/unit/test_traps/test_trap.py +++ b/test/unit/test_traps/test_trap.py @@ -60,6 +60,7 @@ class TestCreateTrappingForm: my_mobile.test_function = f.TestFunction(V) my_temp = festim.Temperature(value=100) my_temp.T = f.interpolate(f.Constant(100), V) + my_temp.T_n = f.interpolate(f.Constant(100), V) dx = f.dx() dt = festim.Stepsize(initial_value=1) @@ -159,18 +160,20 @@ def test_chemical_potential(self): my_trap.test_function = f.TestFunction(self.V) my_mats = festim.Materials([self.mat1]) + mobile = festim.Theta() + mobile.solution = f.Function(self.V, name="theta_m") + mobile.previous_solution = f.Function(self.V, name="theta_m_n") + mobile.test_function = f.TestFunction(self.V) + # run my_trap.create_trapping_form( - self.my_mobile, my_mats, self.my_temp, self.dx, chemical_pot=True + mobile, my_mats, self.my_temp, self.dx, chemical_pot=True ) # test v = my_trap.test_function - c_0 = ( - self.my_mobile.solution - * self.mat1.S_0 - * f.exp(-self.mat1.E_S / festim.k_B / self.my_temp.T) - ) + S = self.mat1.S_0 * f.exp(-self.mat1.E_S / festim.k_B / self.my_temp.T) + c_0 = mobile.solution * S expected_form = ( -my_trap.k_0 * f.exp(-my_trap.E_k / festim.k_B / self.my_temp.T) From 1459fb49567b2418fea78fcc43a12988f562dfc5 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 14 Sep 2022 11:22:37 +0000 Subject: [PATCH 09/15] removed chemical_pot argument --- festim/concentration/traps/trap.py | 12 +++--------- festim/concentration/traps/traps.py | 4 ++-- festim/h_transport_problem.py | 4 +--- test/unit/test_traps/test_trap.py | 4 +--- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/festim/concentration/traps/trap.py b/festim/concentration/traps/trap.py index 1e014eb25..e7ac05eee 100644 --- a/festim/concentration/traps/trap.py +++ b/festim/concentration/traps/trap.py @@ -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 @@ -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: @@ -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 diff --git a/festim/concentration/traps/traps.py b/festim/concentration/traps/traps.py index b867a1a1f..d01cf32bd 100644 --- a/festim/concentration/traps/traps.py +++ b/festim/concentration/traps/traps.py @@ -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 diff --git a/festim/h_transport_problem.py b/festim/h_transport_problem.py index cd7a4997a..99dcd04e9 100644 --- a/festim/h_transport_problem.py +++ b/festim/h_transport_problem.py @@ -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 diff --git a/test/unit/test_traps/test_trap.py b/test/unit/test_traps/test_trap.py index 36beff074..ac03dc05c 100644 --- a/test/unit/test_traps/test_trap.py +++ b/test/unit/test_traps/test_trap.py @@ -166,9 +166,7 @@ def test_chemical_potential(self): mobile.test_function = f.TestFunction(self.V) # run - my_trap.create_trapping_form( - mobile, my_mats, self.my_temp, self.dx, chemical_pot=True - ) + my_trap.create_trapping_form(mobile, my_mats, self.my_temp, self.dx) # test v = my_trap.test_function From da19e577739b6fef71a997946f473fbdddfd7724 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 14 Sep 2022 11:25:56 +0000 Subject: [PATCH 10/15] fixed test --- test/system/test_chemical_potential.py | 31 ++++---------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/test/system/test_chemical_potential.py b/test/system/test_chemical_potential.py index 48a554c47..fec04a35c 100644 --- a/test/system/test_chemical_potential.py +++ b/test/system/test_chemical_potential.py @@ -26,29 +26,19 @@ def test_run_MMS_chemical_pot(tmpdir): """ d = tmpdir.mkdir("Solution_Test") u = 1 + sp.sin(2 * fenics.pi * festim.x) * festim.t + festim.t - v = 1 + sp.cos(2 * fenics.pi * festim.x) * festim.t size = 1 - k_0 = 2 - E_k = 1.5 - p_0 = 3 - E_p = 0.2 T = 700 + 30 * festim.x - n_trap = 1 E_D = 0.1 D_0 = 2 k_B = festim.k_B D = D_0 * sp.exp(-E_D / k_B / T) - p = p_0 * sp.exp(-E_p / k_B / T) - k = k_0 * sp.exp(-E_k / k_B / T) f = ( sp.diff(u, festim.t) - + sp.diff(v, festim.t) - D * sp.diff(u, festim.x, 2) - sp.diff(D, festim.x) * sp.diff(u, festim.x) ) - g = sp.diff(v, festim.t) + p * v - k * u * (n_trap - v) def run(h): my_materials = festim.Materials( @@ -64,23 +54,20 @@ def run(h): ) ] ) - my_traps = festim.Traps([festim.Trap(k_0, E_k, p_0, E_p, "mat", n_trap)]) my_initial_conditions = [ festim.InitialCondition(field=0, value=u), - festim.InitialCondition(field=1, value=v), ] my_mesh = festim.MeshFromRefinements(round(size / h), size) my_bcs = [ festim.DirichletBC(surfaces=[1, 2], value=u, field=0), - festim.DirichletBC(surfaces=[1, 2], value=v, field=1), ] my_temp = festim.Temperature(T) - my_sources = [festim.Source(f, 1, "0"), festim.Source(g, 1, "1")] + my_sources = [festim.Source(f, 1, "0")] my_settings = festim.Settings( absolute_tolerance=1e-10, @@ -103,7 +90,6 @@ def run(h): my_sim = festim.Simulation( mesh=my_mesh, materials=my_materials, - traps=my_traps, initial_conditions=my_initial_conditions, boundary_conditions=my_bcs, temperature=my_temp, @@ -120,28 +106,19 @@ def run(h): my_sim.mobile.post_processing_solution, my_sim.V_DG1 ) - computed_v = fenics.project( - my_sim.traps.traps[0].post_processing_solution, my_sim.V_DG1 - ) - error_u = compute_error(u, computed=computed_u, t=my_sim.t, norm="error_max") - error_v = compute_error(v, computed=computed_v, t=my_sim.t, norm="error_max") - return error_u, error_v + return error_u tol_u = 1e-7 - tol_v = 1e-6 sizes = [1 / 1600] dt = 0.1 / 50 for h in sizes: - error_max_u, error_max_v = run(h) + error_max_u = run(h) msg = ( "Maximum error on u is:" + str(error_max_u) + "\n \ - Maximum error on v is:" - + str(error_max_v) - + "\n \ with h = " + str(h) + "\n \ @@ -149,4 +126,4 @@ def run(h): + str(dt) ) print(msg) - assert error_max_u < tol_u and error_max_v < tol_v + assert error_max_u < tol_u From 5672933dfafedfdbc05383503bf64391eba046ce Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 14 Sep 2022 11:35:39 +0000 Subject: [PATCH 11/15] fixed test + added test for checking error --- test/system/test_chemical_potential.py | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/system/test_chemical_potential.py b/test/system/test_chemical_potential.py index fec04a35c..0b14b0254 100644 --- a/test/system/test_chemical_potential.py +++ b/test/system/test_chemical_potential.py @@ -2,6 +2,7 @@ import festim import fenics from pathlib import Path +import pytest import numpy as np @@ -127,3 +128,35 @@ def run(h): ) print(msg) assert error_max_u < tol_u + + +def test_error_raised_when_henry_and_traps(): + """Checks an error is raised when adding a trap with + chemical potential in a Henry material""" + + my_sim = festim.Simulation() + my_sim.materials = festim.Material( + name="mat", + id=1, + D_0=1, + E_D=0, + S_0=2, + E_S=0.1, + solubility_law="henry", + ) + + my_sim.mesh = festim.MeshFromVertices([0, 1, 2, 3, 4]) + + my_sim.traps = festim.Trap(k_0=1, E_k=0, p_0=1, E_p=0, materials="mat", density=1) + my_sim.T = festim.Temperature(400) + + my_sim.settings = festim.Settings( + absolute_tolerance=1e-10, + relative_tolerance=1e-9, + maximum_iterations=50, + chemical_pot=True, + transient=False, + ) + + with pytest.raises(NotImplementedError): + my_sim.initialise() From 74b0d67a4ef99d76f8dd15630f398d4fb682c2d6 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 14 Sep 2022 12:18:27 +0000 Subject: [PATCH 12/15] trigger1 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4a541af3d..6e02d4123 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Run the tests: pytest-3 test/ + ## Visualisation FESTIM results are exported to .csv, .txt or XDMF. The latter can then be opened in visualisation tools like [ParaView](https://www.paraview.org/) or [VisIt](https://wci.llnl.gov/simulation/computer-codes/visit/). From 056010142296b46c0102aea6b7a56b3cf12caa05 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 14 Sep 2022 12:18:39 +0000 Subject: [PATCH 13/15] trigger 2 --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 6e02d4123..4a541af3d 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,6 @@ Run the tests: pytest-3 test/ - ## Visualisation FESTIM results are exported to .csv, .txt or XDMF. The latter can then be opened in visualisation tools like [ParaView](https://www.paraview.org/) or [VisIt](https://wci.llnl.gov/simulation/computer-codes/visit/). From 1546b0261cb890f54f100feb4467abd60cb30795 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 14 Sep 2022 12:27:31 +0000 Subject: [PATCH 14/15] removed token --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 12a43f117..96e2aef07 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,4 +27,4 @@ jobs: 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 + bash <(curl -s https://codecov.io/bash) From 71ccb00119959b3c9a82976c8c3ab3042e3cc19d Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Wed, 14 Sep 2022 12:33:45 +0000 Subject: [PATCH 15/15] coverage to festim not FESTIM --- .circleci/config.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 96e2aef07..b99884c9c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 + python3 -m pytest test/system/ --cov festim --cov-append --cov-report xml --cov-report term bash <(curl -s https://codecov.io/bash)