From 19e1abc9b9d9dcff767c44aacba2937135c0dc6c Mon Sep 17 00:00:00 2001 From: J Dark Date: Tue, 10 Oct 2023 15:27:31 -0400 Subject: [PATCH 01/22] subdomain classes --- festim/subdomain/surface_subdomain.py | 27 +++++++++++++++++++++++++++ festim/subdomain/volume_subdomain.py | 27 +++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 festim/subdomain/surface_subdomain.py create mode 100644 festim/subdomain/volume_subdomain.py diff --git a/festim/subdomain/surface_subdomain.py b/festim/subdomain/surface_subdomain.py new file mode 100644 index 000000000..e0c2520a2 --- /dev/null +++ b/festim/subdomain/surface_subdomain.py @@ -0,0 +1,27 @@ +from dolfinx import fem +import numpy as np + + +class SurfaceSubdomain1D: + """ + Subdomain class + Attributes: + + """ + + def __init__(self, id=None, x=None) -> None: + """Inits Mesh + Args: + id (int): the id of the surface subdomain + x (float): the x coordinate of the surface subdomain + """ + self.id = id + self.x = x + self.dofs = None + + def locate_dof(self, function_space): + """Creates smth""" + dofs = fem.locate_dofs_geometrical( + function_space, lambda x: np.isclose(x[0], self.x) + ) + return dofs[0] diff --git a/festim/subdomain/volume_subdomain.py b/festim/subdomain/volume_subdomain.py new file mode 100644 index 000000000..41be93165 --- /dev/null +++ b/festim/subdomain/volume_subdomain.py @@ -0,0 +1,27 @@ +from dolfinx.mesh import locate_entities +import numpy as np + + +class VolumeSubdomain1D: + """ + Volume subdomain class for 1D cases + """ + + def __init__(self, borders=None, material=None) -> None: + """Inits Mesh + Args: + borders (list of float): the borders of the volume subdomain + material (festim.Material): the material of the volume subdomain + """ + self.borders = borders + material = material + self.id = None + + def locate_subdomain_entities(self, mesh, vdim): + """Locates all cells in subdomain within domain""" + entities = locate_entities( + mesh, + vdim, + lambda x: np.logical_and(x[0] >= self.borders[0], x[0] <= self.borders[1]), + ) + return entities From 8e649e3cb0ca45909acb91cd164f5a18e4dbf4e1 Mon Sep 17 00:00:00 2001 From: J Dark Date: Tue, 10 Oct 2023 15:27:56 -0400 Subject: [PATCH 02/22] create meshtags and meaures from subdomains --- festim/hydrogen_transport_problem.py | 57 ++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/festim/hydrogen_transport_problem.py b/festim/hydrogen_transport_problem.py index 20a037fec..2ecf91e33 100644 --- a/festim/hydrogen_transport_problem.py +++ b/festim/hydrogen_transport_problem.py @@ -3,12 +3,9 @@ import ufl from mpi4py import MPI from dolfinx.fem import Function -from ufl import ( - TestFunction, - dot, - grad, - exp, -) +from dolfinx.mesh import meshtags, locate_entities +from ufl import TestFunction, dot, grad, exp, Measure +import numpy as np import festim as F @@ -98,12 +95,7 @@ def initialise(self): """ self.define_function_space() - ( - self.facet_tags, - self.volume_tags, - self.dx, - self.ds, - ) = self.mesh.create_measures_and_tags(self.function_space) + self.define_markers_and_measures() self.assign_functions_to_species() self.create_formulation() @@ -111,6 +103,47 @@ def define_function_space(self): elements = ufl.FiniteElement("CG", self.mesh.mesh.ufl_cell(), 1) self.function_space = fem.FunctionSpace(self.mesh.mesh, elements) + def define_markers_and_measures(self): + dofs_facets = [] + tags_facets = [] + + # find all cells in domain and mark them as 1 + num_cells = self.mesh.mesh.topology.index_map(vdim).size_local + mesh_cell_indicies = np.arange(num_cells, dtype=np.int32) + tags_volumes = np.full(num_cells, 0, dtype=np.int32) + + # TODO this should be a property of mesh + fdim = self.mesh.mesh.topology.dim - 1 + vdim = self.mesh.mesh.topology.dim + + for sub_dom in self.subdomains: + if isinstance(sub_dom, F.SurfaceSubdomain1D): + dof = sub_dom.locate_dof(self.function_space) + dofs_facets.append(dof) + tags_facets.append(sub_dom.id) + if isinstance(sub_dom, F.VolumeSubdomain): + # find all cells in subdomain and mark them as sub_dom.id + entities = sub_dom.locate_subdomain_entities(self.mesh.mesh, vdim) + tags_volumes[entities] = sub_dom.id + + # dofs and tags need to be in np.in32 format for meshtags + dofs_facets = np.array(dofs_facets, dtype=np.int32) + tags_facets = np.array(tags_facets, dtype=np.int32) + + # define mesh tags + self.mesh_tags_facets = meshtags(self.mesh.mesh, fdim, dofs_facets, tags_facets) + self.mesh_tags_volumes = meshtags( + self.mesh.mesh, vdim, mesh_cell_indicies, tags_volumes + ) + + # define measures + self.ds = Measure( + "ds", domain=self.mesh.mesh, subdomain_data=self.mesh_tags_facets + ) + self.dx = Measure( + "dx", domain=self.mesh.mesh, subdomain_data=self.mesh_tags_volumes + ) + def assign_functions_to_species(self): """Creates for each species the solution, prev solution and test function""" if len(self.species) > 1: From b2b0a2a5fbe8ee061d00116bc2652abfd7599e28 Mon Sep 17 00:00:00 2001 From: J Dark Date: Tue, 10 Oct 2023 15:32:26 -0400 Subject: [PATCH 03/22] meshtags and measures not made by mesh --- festim/mesh/mesh.py | 14 -------------- festim/mesh/mesh_1d.py | 31 ------------------------------- 2 files changed, 45 deletions(-) diff --git a/festim/mesh/mesh.py b/festim/mesh/mesh.py index 8d6a47d43..90f7746bc 100644 --- a/festim/mesh/mesh.py +++ b/festim/mesh/mesh.py @@ -26,17 +26,3 @@ def __init__(self, mesh=None): self.mesh.topology.create_connectivity( self.mesh.topology.dim - 1, self.mesh.topology.dim ) - - def create_measures_and_tags(self, function_space): - """Creates the ufl.measure.Measure objects for self.ds and - self.dx, also passes the facet and volume tags - """ - facet_tags, volume_tags = self.create_meshtags(function_space) - dx = ufl.Measure("dx", domain=self.mesh, subdomain_data=volume_tags) - ds = ufl.Measure("ds", domain=self.mesh, subdomain_data=facet_tags) - return ( - facet_tags, - volume_tags, - dx, - ds, - ) diff --git a/festim/mesh/mesh_1d.py b/festim/mesh/mesh_1d.py index 84f9a9faa..6a29e4c54 100644 --- a/festim/mesh/mesh_1d.py +++ b/festim/mesh/mesh_1d.py @@ -36,34 +36,3 @@ def generate_mesh(self): cells = np.stack((indexes[:-1], indexes[1:]), axis=-1) return mesh.create_mesh(MPI.COMM_WORLD, cells, mesh_points, domain) - - def create_meshtags(self, function_space): - """Creates the meshtags for a given function space - Args: - function_space (dolfinx.fem.function.FunctionSpace): the function - space of the model - - Returns: - dolfinx.mesh.MeshTagsMetaClass: the tags containing the facet - and volume tags - """ - - dofs_L = fem.locate_dofs_geometrical( - function_space, lambda x: np.isclose(x[0], min(self.vertices)) - ) - dofs_R = fem.locate_dofs_geometrical( - function_space, lambda x: np.isclose(x[0], max(self.vertices)) - ) - - dofs_facets = np.array([dofs_L[0], dofs_R[0]], dtype=np.int32) - tags_facets = np.array([1, 2], dtype=np.int32) - - facet_dimension = self.mesh.topology.dim - 1 - mesh_tags_facets = mesh.meshtags( - self.mesh, facet_dimension, dofs_facets, tags_facets - ) - - # TODO implement this - mesh_tags_volumes = None - - return mesh_tags_facets, mesh_tags_volumes From 2350e6843176c5eeb5c85e1c04dd5db84bd80699 Mon Sep 17 00:00:00 2001 From: J Dark Date: Tue, 10 Oct 2023 15:32:47 -0400 Subject: [PATCH 04/22] id a paramter of VolumeSubdomain1D --- festim/subdomain/volume_subdomain.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/festim/subdomain/volume_subdomain.py b/festim/subdomain/volume_subdomain.py index 41be93165..0f6496ebe 100644 --- a/festim/subdomain/volume_subdomain.py +++ b/festim/subdomain/volume_subdomain.py @@ -7,15 +7,16 @@ class VolumeSubdomain1D: Volume subdomain class for 1D cases """ - def __init__(self, borders=None, material=None) -> None: + def __init__(self, id=None, borders=None, material=None) -> None: """Inits Mesh Args: + id (int): the id of the volume subdomain borders (list of float): the borders of the volume subdomain material (festim.Material): the material of the volume subdomain """ self.borders = borders material = material - self.id = None + self.id = id def locate_subdomain_entities(self, mesh, vdim): """Locates all cells in subdomain within domain""" From e1895090bc0f43eef20e4252860ae5f635029c67 Mon Sep 17 00:00:00 2001 From: J Dark Date: Tue, 10 Oct 2023 15:34:39 -0400 Subject: [PATCH 05/22] move defintoin of fdim and vdim --- festim/hydrogen_transport_problem.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/festim/hydrogen_transport_problem.py b/festim/hydrogen_transport_problem.py index 2ecf91e33..7feaeb391 100644 --- a/festim/hydrogen_transport_problem.py +++ b/festim/hydrogen_transport_problem.py @@ -107,15 +107,15 @@ def define_markers_and_measures(self): dofs_facets = [] tags_facets = [] + # TODO this should be a property of mesh + fdim = self.mesh.mesh.topology.dim - 1 + vdim = self.mesh.mesh.topology.dim + # find all cells in domain and mark them as 1 num_cells = self.mesh.mesh.topology.index_map(vdim).size_local mesh_cell_indicies = np.arange(num_cells, dtype=np.int32) tags_volumes = np.full(num_cells, 0, dtype=np.int32) - # TODO this should be a property of mesh - fdim = self.mesh.mesh.topology.dim - 1 - vdim = self.mesh.mesh.topology.dim - for sub_dom in self.subdomains: if isinstance(sub_dom, F.SurfaceSubdomain1D): dof = sub_dom.locate_dof(self.function_space) From 94e28fab837cdf8c924a8ea4640eda72d7dc8f93 Mon Sep 17 00:00:00 2001 From: J Dark Date: Tue, 10 Oct 2023 15:44:44 -0400 Subject: [PATCH 06/22] parameter meshtags not tags --- festim/hydrogen_transport_problem.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/festim/hydrogen_transport_problem.py b/festim/hydrogen_transport_problem.py index 7feaeb391..cc67e40b4 100644 --- a/festim/hydrogen_transport_problem.py +++ b/festim/hydrogen_transport_problem.py @@ -85,8 +85,8 @@ def __init__( self.dx = None self.ds = None self.function_space = None - self.facet_tags = None - self.volume_tags = None + self.facet_meshtags = None + self.volume_meshtags = None self.formulation = None def initialise(self): @@ -121,7 +121,7 @@ def define_markers_and_measures(self): dof = sub_dom.locate_dof(self.function_space) dofs_facets.append(dof) tags_facets.append(sub_dom.id) - if isinstance(sub_dom, F.VolumeSubdomain): + if isinstance(sub_dom, F.VolumeSubdomain1D): # find all cells in subdomain and mark them as sub_dom.id entities = sub_dom.locate_subdomain_entities(self.mesh.mesh, vdim) tags_volumes[entities] = sub_dom.id @@ -131,17 +131,17 @@ def define_markers_and_measures(self): tags_facets = np.array(tags_facets, dtype=np.int32) # define mesh tags - self.mesh_tags_facets = meshtags(self.mesh.mesh, fdim, dofs_facets, tags_facets) - self.mesh_tags_volumes = meshtags( + self.facet_meshtags = meshtags(self.mesh.mesh, fdim, dofs_facets, tags_facets) + self.volume_meshtags = meshtags( self.mesh.mesh, vdim, mesh_cell_indicies, tags_volumes ) # define measures self.ds = Measure( - "ds", domain=self.mesh.mesh, subdomain_data=self.mesh_tags_facets + "ds", domain=self.mesh.mesh, subdomain_data=self.facet_meshtags ) self.dx = Measure( - "dx", domain=self.mesh.mesh, subdomain_data=self.mesh_tags_volumes + "dx", domain=self.mesh.mesh, subdomain_data=self.volume_meshtags ) def assign_functions_to_species(self): @@ -157,8 +157,6 @@ def create_formulation(self): """Creates the formulation of the model""" if len(self.sources) > 1: raise NotImplementedError("Sources not implemented yet") - if len(self.subdomains) > 1: - raise NotImplementedError("Multiple subdomains not implemented yet") if len(self.species) > 1: raise NotImplementedError("Multiple species not implemented yet") From 28aeb955553ba06f6431d5aa91941c8e8363117c Mon Sep 17 00:00:00 2001 From: J Dark Date: Tue, 10 Oct 2023 15:44:53 -0400 Subject: [PATCH 07/22] updated permeation test --- test/test_permeation_problem.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/test_permeation_problem.py b/test/test_permeation_problem.py index 3179684ed..68bc5b652 100644 --- a/test/test_permeation_problem.py +++ b/test/test_permeation_problem.py @@ -26,6 +26,11 @@ def test_permeation_problem(): my_model = F.HydrogenTransportProblem() my_model.mesh = my_mesh + my_subdomain = F.VolumeSubdomain1D(id=1, borders=[0, L]) + left_surface = F.SurfaceSubdomain1D(id=1, x=0) + right_surface = F.SurfaceSubdomain1D(id=1, x=L) + my_model.subdomains = [my_subdomain, left_surface, right_surface] + mobile_H = F.Species("H") my_model.species = [mobile_H] @@ -45,9 +50,9 @@ def siverts_law(T, S_0, E_S, pressure): return S * pressure**0.5 fdim = my_mesh.mesh.topology.dim - 1 - left_facets = my_model.facet_tags.find(1) + left_facets = my_model.facet_meshtags.find(1) left_dofs = locate_dofs_topological(V, fdim, left_facets) - right_facets = my_model.facet_tags.find(2) + right_facets = my_model.facet_meshtags.find(2) right_dofs = locate_dofs_topological(V, fdim, right_facets) S_0 = 4.02e21 From 5cb1d97e685e4f9e54c4c5e5c96c5047de0a1356 Mon Sep 17 00:00:00 2001 From: J Dark Date: Tue, 10 Oct 2023 15:45:04 -0400 Subject: [PATCH 08/22] subdomains in init --- festim/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/festim/__init__.py b/festim/__init__.py index ca22327fe..de4a2652c 100644 --- a/festim/__init__.py +++ b/festim/__init__.py @@ -21,4 +21,7 @@ from .species import Species, Trap +from .subdomain.surface_subdomain import SurfaceSubdomain1D +from .subdomain.volume_subdomain import VolumeSubdomain1D + from .hydrogen_transport_problem import HydrogenTransportProblem From 611b3648b54c12287ec18e521e96e4769f98db37 Mon Sep 17 00:00:00 2001 From: J Dark Date: Tue, 10 Oct 2023 15:59:47 -0400 Subject: [PATCH 09/22] relative error in abs to catch when all 0 result --- test/test_permeation_problem.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/test_permeation_problem.py b/test/test_permeation_problem.py index 68bc5b652..17296c52f 100644 --- a/test/test_permeation_problem.py +++ b/test/test_permeation_problem.py @@ -28,7 +28,7 @@ def test_permeation_problem(): my_subdomain = F.VolumeSubdomain1D(id=1, borders=[0, L]) left_surface = F.SurfaceSubdomain1D(id=1, x=0) - right_surface = F.SurfaceSubdomain1D(id=1, x=L) + right_surface = F.SurfaceSubdomain1D(id=2, x=L) my_model.subdomains = [my_subdomain, left_surface, right_surface] mobile_H = F.Species("H") @@ -121,10 +121,9 @@ def siverts_law(T, S_0, E_S, pressure): analytical_flux = P_up**0.5 * permeability / L * (2 * summation + 1) analytical_flux = np.abs(analytical_flux) - flux_values = np.array(np.abs(flux_values)) - relative_error = (flux_values - analytical_flux) / analytical_flux + relative_error = np.abs((flux_values - analytical_flux) / analytical_flux) relative_error = relative_error[ np.where(analytical_flux > 0.01 * np.max(analytical_flux)) From fcac4fce0e625b4dc3025f6a5cfdde89e0d3d744 Mon Sep 17 00:00:00 2001 From: J Dark Date: Tue, 10 Oct 2023 16:26:03 -0400 Subject: [PATCH 10/22] test volume_subdomain ids --- test/test_subdomains.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/test_subdomains.py diff --git a/test/test_subdomains.py b/test/test_subdomains.py new file mode 100644 index 000000000..119bc147c --- /dev/null +++ b/test/test_subdomains.py @@ -0,0 +1,34 @@ +import numpy as np +import festim as F + + +def test_different_volume_ids(): + my_model = F.HydrogenTransportProblem() + + sub_dom_1 = np.linspace(0, 1e-04, num=3) + sub_dom_2 = np.linspace(1e-04, 2e-04, num=4) + sub_dom_3 = np.linspace(2e-04, 3e-04, num=5) + my_model.mesh = F.Mesh1D( + np.unique(np.concatenate([sub_dom_1, sub_dom_2, sub_dom_3])) + ) + + vol_subdomains_ids = [2, 16, 7] + vol_subdomain_1 = F.VolumeSubdomain1D( + id=vol_subdomains_ids[0], borders=[sub_dom_1[0], sub_dom_1[-1]] + ) + vol_subdomain_2 = F.VolumeSubdomain1D( + id=vol_subdomains_ids[1], borders=[sub_dom_2[0], sub_dom_2[-1]] + ) + vol_subdomain_3 = F.VolumeSubdomain1D( + id=vol_subdomains_ids[2], borders=[sub_dom_3[0], sub_dom_3[-1]] + ) + my_model.subdomains = [vol_subdomain_1, vol_subdomain_2, vol_subdomain_3] + + my_model.define_markers_and_measures() + + for vol_id in vol_subdomains_ids: + assert vol_id in np.array(my_model.volume_meshtags.values) + + +if __name__ == "__main__": + test_different_volume_ids() From 26dde3b2580a604dae7052470a4965e5ba0fe5f3 Mon Sep 17 00:00:00 2001 From: J Dark Date: Tue, 10 Oct 2023 16:39:35 -0400 Subject: [PATCH 11/22] test ids in surface domains --- test/test_subdomains.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/test_subdomains.py b/test/test_subdomains.py index 119bc147c..e6c1282fa 100644 --- a/test/test_subdomains.py +++ b/test/test_subdomains.py @@ -2,6 +2,24 @@ import festim as F +def test_different_surface_ids(): + my_model = F.HydrogenTransportProblem() + + L = 3e-02 + my_model.mesh = F.Mesh1D(np.linspace(0, L, num=3)) + + surfacec_subdomains_ids = [3, 8] + surface_subdomain_1 = F.SurfaceSubdomain1D(id=surfacec_subdomains_ids[0], x=0) + surface_subdomain_2 = F.SurfaceSubdomain1D(id=surfacec_subdomains_ids[1], x=L) + my_model.subdomains = [surface_subdomain_1, surface_subdomain_2] + + my_model.define_function_space() + my_model.define_markers_and_measures() + + for surf_id in surfacec_subdomains_ids: + assert surf_id in np.array(my_model.facet_meshtags.values) + + def test_different_volume_ids(): my_model = F.HydrogenTransportProblem() From b2a27cf5300ebc353d637f6ec5172506fbf30689 Mon Sep 17 00:00:00 2001 From: J Dark Date: Tue, 10 Oct 2023 16:43:23 -0400 Subject: [PATCH 12/22] refactoring --- festim/hydrogen_transport_problem.py | 3 +-- test/test_subdomains.py | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/festim/hydrogen_transport_problem.py b/festim/hydrogen_transport_problem.py index cc67e40b4..4acc25c9c 100644 --- a/festim/hydrogen_transport_problem.py +++ b/festim/hydrogen_transport_problem.py @@ -104,8 +104,7 @@ def define_function_space(self): self.function_space = fem.FunctionSpace(self.mesh.mesh, elements) def define_markers_and_measures(self): - dofs_facets = [] - tags_facets = [] + dofs_facets, tags_facets = [], [] # TODO this should be a property of mesh fdim = self.mesh.mesh.topology.dim - 1 diff --git a/test/test_subdomains.py b/test/test_subdomains.py index e6c1282fa..3a7762f82 100644 --- a/test/test_subdomains.py +++ b/test/test_subdomains.py @@ -49,4 +49,5 @@ def test_different_volume_ids(): if __name__ == "__main__": + test_different_surface_ids() test_different_volume_ids() From 522eecb01403660cd763d2623c9d0b62c2f53681 Mon Sep 17 00:00:00 2001 From: J Dark Date: Tue, 10 Oct 2023 17:34:25 -0400 Subject: [PATCH 13/22] add init --- festim/subdomain/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 festim/subdomain/__init__.py diff --git a/festim/subdomain/__init__.py b/festim/subdomain/__init__.py new file mode 100644 index 000000000..e69de29bb From 11ee5e9df3ceae947f259dd5c46354ff2307afad Mon Sep 17 00:00:00 2001 From: James Dark <65899899+jhdark@users.noreply.github.com> Date: Wed, 11 Oct 2023 08:05:30 -0400 Subject: [PATCH 14/22] Update festim/hydrogen_transport_problem.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: RĂ©mi Delaporte-Mathurin <40028739+RemDelaporteMathurin@users.noreply.github.com> --- festim/hydrogen_transport_problem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/festim/hydrogen_transport_problem.py b/festim/hydrogen_transport_problem.py index 4acc25c9c..756b2736c 100644 --- a/festim/hydrogen_transport_problem.py +++ b/festim/hydrogen_transport_problem.py @@ -110,7 +110,7 @@ def define_markers_and_measures(self): fdim = self.mesh.mesh.topology.dim - 1 vdim = self.mesh.mesh.topology.dim - # find all cells in domain and mark them as 1 + # find all cells in domain and mark them as 0 num_cells = self.mesh.mesh.topology.index_map(vdim).size_local mesh_cell_indicies = np.arange(num_cells, dtype=np.int32) tags_volumes = np.full(num_cells, 0, dtype=np.int32) From b069d90f438bfac6e2c9d8562c73148cb3be0a79 Mon Sep 17 00:00:00 2001 From: J Dark Date: Wed, 11 Oct 2023 08:29:05 -0400 Subject: [PATCH 15/22] added details to doc strings --- festim/subdomain/surface_subdomain.py | 16 +++++++++------- festim/subdomain/volume_subdomain.py | 24 ++++++++++++++++-------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/festim/subdomain/surface_subdomain.py b/festim/subdomain/surface_subdomain.py index e0c2520a2..3b97fb5a8 100644 --- a/festim/subdomain/surface_subdomain.py +++ b/festim/subdomain/surface_subdomain.py @@ -4,23 +4,25 @@ class SurfaceSubdomain1D: """ - Subdomain class + Surface subdomain class for 1D cases + + Args: + id (int): the id of the surface subdomain + x (float): the x coordinate of the surface subdomain + Attributes: + id (int): the id of the surface subdomain + x (float): the x coordinate of the surface subdomain """ def __init__(self, id=None, x=None) -> None: - """Inits Mesh - Args: - id (int): the id of the surface subdomain - x (float): the x coordinate of the surface subdomain - """ self.id = id self.x = x self.dofs = None def locate_dof(self, function_space): - """Creates smth""" + """Locates the dof of the surface subdomain within the function space""" dofs = fem.locate_dofs_geometrical( function_space, lambda x: np.isclose(x[0], self.x) ) diff --git a/festim/subdomain/volume_subdomain.py b/festim/subdomain/volume_subdomain.py index 0f6496ebe..6047410d1 100644 --- a/festim/subdomain/volume_subdomain.py +++ b/festim/subdomain/volume_subdomain.py @@ -5,17 +5,25 @@ class VolumeSubdomain1D: """ Volume subdomain class for 1D cases + + Args: + id (int): the id of the volume subdomain + borders (list of float): the borders of the volume subdomain + material (festim.Material): the material of the volume subdomain + + Attributes: + id (int): the id of the volume subdomain + borders (list of float): the borders of the volume subdomain + material (festim.Material): the material of the volume subdomain + + Usage: + >>> import festim as F + >>> vol_subdomain = F.VolumeSubdomain1D(id=1, borders=[0, 1], material=F.Material(...)) """ - def __init__(self, id=None, borders=None, material=None) -> None: - """Inits Mesh - Args: - id (int): the id of the volume subdomain - borders (list of float): the borders of the volume subdomain - material (festim.Material): the material of the volume subdomain - """ + def __init__(self, id, borders, material) -> None: self.borders = borders - material = material + self.material = material self.id = id def locate_subdomain_entities(self, mesh, vdim): From 5d9bdc75d1c72923479bddb86b40091cb08f9c39 Mon Sep 17 00:00:00 2001 From: J Dark Date: Wed, 11 Oct 2023 08:29:17 -0400 Subject: [PATCH 16/22] typo --- festim/hydrogen_transport_problem.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/festim/hydrogen_transport_problem.py b/festim/hydrogen_transport_problem.py index 756b2736c..63de27a8f 100644 --- a/festim/hydrogen_transport_problem.py +++ b/festim/hydrogen_transport_problem.py @@ -112,7 +112,7 @@ def define_markers_and_measures(self): # find all cells in domain and mark them as 0 num_cells = self.mesh.mesh.topology.index_map(vdim).size_local - mesh_cell_indicies = np.arange(num_cells, dtype=np.int32) + mesh_cell_indices = np.arange(num_cells, dtype=np.int32) tags_volumes = np.full(num_cells, 0, dtype=np.int32) for sub_dom in self.subdomains: @@ -132,7 +132,7 @@ def define_markers_and_measures(self): # define mesh tags self.facet_meshtags = meshtags(self.mesh.mesh, fdim, dofs_facets, tags_facets) self.volume_meshtags = meshtags( - self.mesh.mesh, vdim, mesh_cell_indicies, tags_volumes + self.mesh.mesh, vdim, mesh_cell_indices, tags_volumes ) # define measures From bf0140ff456f88cf5a7c2ef2d2ff59d1c0ab5f6c Mon Sep 17 00:00:00 2001 From: J Dark Date: Wed, 11 Oct 2023 08:30:20 -0400 Subject: [PATCH 17/22] command lines not needed --- test/test_subdomains.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/test_subdomains.py b/test/test_subdomains.py index 3a7762f82..dbc0b54bd 100644 --- a/test/test_subdomains.py +++ b/test/test_subdomains.py @@ -46,8 +46,3 @@ def test_different_volume_ids(): for vol_id in vol_subdomains_ids: assert vol_id in np.array(my_model.volume_meshtags.values) - - -if __name__ == "__main__": - test_different_surface_ids() - test_different_volume_ids() From c61f5a2b4aba34d83fb6134a188fed6f062b45ce Mon Sep 17 00:00:00 2001 From: J Dark Date: Wed, 11 Oct 2023 14:52:03 -0400 Subject: [PATCH 18/22] added detail to docstrings, required args --- festim/subdomain/surface_subdomain.py | 17 +++++++++++++++-- festim/subdomain/volume_subdomain.py | 15 ++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/festim/subdomain/surface_subdomain.py b/festim/subdomain/surface_subdomain.py index 3b97fb5a8..b27b037d4 100644 --- a/festim/subdomain/surface_subdomain.py +++ b/festim/subdomain/surface_subdomain.py @@ -13,16 +13,29 @@ class SurfaceSubdomain1D: Attributes: id (int): the id of the surface subdomain x (float): the x coordinate of the surface subdomain + dofs (np.array): the dofs of the surface subdomain + Usage: + >>> surf_subdomain = F.SurfaceSubdomain1D(id=1, x=1) """ - def __init__(self, id=None, x=None) -> None: + def __init__(self, id, x) -> None: self.id = id self.x = x + self.dofs = None def locate_dof(self, function_space): - """Locates the dof of the surface subdomain within the function space""" + """Locates the dof of the surface subdomain within the function space + + Args: + function_space (dolfinx.fem.FunctionSpace): the function space of + the model + + Returns: + dof (np.array): the first value in the list of dofs of the surface + subdomain + """ dofs = fem.locate_dofs_geometrical( function_space, lambda x: np.isclose(x[0], self.x) ) diff --git a/festim/subdomain/volume_subdomain.py b/festim/subdomain/volume_subdomain.py index 6047410d1..af3447c9f 100644 --- a/festim/subdomain/volume_subdomain.py +++ b/festim/subdomain/volume_subdomain.py @@ -17,8 +17,8 @@ class VolumeSubdomain1D: material (festim.Material): the material of the volume subdomain Usage: - >>> import festim as F - >>> vol_subdomain = F.VolumeSubdomain1D(id=1, borders=[0, 1], material=F.Material(...)) + >>> vol_subdomain = F.VolumeSubdomain1D(id=1, borders=[0, 1], + material=F.Material(...)) """ def __init__(self, id, borders, material) -> None: @@ -27,7 +27,16 @@ def __init__(self, id, borders, material) -> None: self.id = id def locate_subdomain_entities(self, mesh, vdim): - """Locates all cells in subdomain within domain""" + """Locates all cells in subdomain borders within domain + + Args: + mesh (dolfinx.cpp.mesh.Mesh): the mesh of the model + vdim (int): the dimension of the volumes of the mesh, + for 1D this is always 1 + + Returns: + entities (np.array): the entities of the subdomain + """ entities = locate_entities( mesh, vdim, From bc47c004eec9e1d2b26ac07bae6040f981470674 Mon Sep 17 00:00:00 2001 From: J Dark Date: Wed, 11 Oct 2023 14:52:38 -0400 Subject: [PATCH 19/22] fixed test to work with new required args --- test/test_permeation_problem.py | 2 +- test/test_subdomains.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_permeation_problem.py b/test/test_permeation_problem.py index 17296c52f..87492dec4 100644 --- a/test/test_permeation_problem.py +++ b/test/test_permeation_problem.py @@ -26,7 +26,7 @@ def test_permeation_problem(): my_model = F.HydrogenTransportProblem() my_model.mesh = my_mesh - my_subdomain = F.VolumeSubdomain1D(id=1, borders=[0, L]) + my_subdomain = F.VolumeSubdomain1D(id=1, borders=[0, L], material=None) left_surface = F.SurfaceSubdomain1D(id=1, x=0) right_surface = F.SurfaceSubdomain1D(id=2, x=L) my_model.subdomains = [my_subdomain, left_surface, right_surface] diff --git a/test/test_subdomains.py b/test/test_subdomains.py index dbc0b54bd..c446804fc 100644 --- a/test/test_subdomains.py +++ b/test/test_subdomains.py @@ -32,13 +32,13 @@ def test_different_volume_ids(): vol_subdomains_ids = [2, 16, 7] vol_subdomain_1 = F.VolumeSubdomain1D( - id=vol_subdomains_ids[0], borders=[sub_dom_1[0], sub_dom_1[-1]] + id=vol_subdomains_ids[0], borders=[sub_dom_1[0], sub_dom_1[-1]], material=None ) vol_subdomain_2 = F.VolumeSubdomain1D( - id=vol_subdomains_ids[1], borders=[sub_dom_2[0], sub_dom_2[-1]] + id=vol_subdomains_ids[1], borders=[sub_dom_2[0], sub_dom_2[-1]], material=None ) vol_subdomain_3 = F.VolumeSubdomain1D( - id=vol_subdomains_ids[2], borders=[sub_dom_3[0], sub_dom_3[-1]] + id=vol_subdomains_ids[2], borders=[sub_dom_3[0], sub_dom_3[-1]], material=None ) my_model.subdomains = [vol_subdomain_1, vol_subdomain_2, vol_subdomain_3] From 48ceddd6162d8a6bd23dfe39db71fdb166e96c17 Mon Sep 17 00:00:00 2001 From: J Dark Date: Wed, 11 Oct 2023 14:53:05 -0400 Subject: [PATCH 20/22] updated doc strings --- festim/hydrogen_transport_problem.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/festim/hydrogen_transport_problem.py b/festim/hydrogen_transport_problem.py index 63de27a8f..e5dfd56b2 100644 --- a/festim/hydrogen_transport_problem.py +++ b/festim/hydrogen_transport_problem.py @@ -35,8 +35,8 @@ class HydrogenTransportProblem: dx (dolfinx.fem.dx): the volume measure of the model ds (dolfinx.fem.ds): the surface measure of the model function_space (dolfinx.fem.FunctionSpace): the function space of the model - facet_tags (dolfinx.cpp.mesh.MeshTags): the facet tags of the model - volume_tags (dolfinx.cpp.mesh.MeshTags): the volume tags of the model + facet_meshtags (dolfinx.cpp.mesh.MeshTags): the facet tags of the model + volume_meshtags (dolfinx.cpp.mesh.MeshTags): the volume tags of the model formulation (ufl.form.Form): the formulation of the model solver (dolfinx.nls.newton.NewtonSolver): the solver of the model From 594c7338b5adda4851d2856ad710932e5ba655a1 Mon Sep 17 00:00:00 2001 From: J Dark Date: Wed, 11 Oct 2023 15:21:20 -0400 Subject: [PATCH 21/22] remove dofs as attribute --- festim/subdomain/surface_subdomain.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/festim/subdomain/surface_subdomain.py b/festim/subdomain/surface_subdomain.py index b27b037d4..409ca6671 100644 --- a/festim/subdomain/surface_subdomain.py +++ b/festim/subdomain/surface_subdomain.py @@ -13,7 +13,6 @@ class SurfaceSubdomain1D: Attributes: id (int): the id of the surface subdomain x (float): the x coordinate of the surface subdomain - dofs (np.array): the dofs of the surface subdomain Usage: >>> surf_subdomain = F.SurfaceSubdomain1D(id=1, x=1) @@ -23,8 +22,6 @@ def __init__(self, id, x) -> None: self.id = id self.x = x - self.dofs = None - def locate_dof(self, function_space): """Locates the dof of the surface subdomain within the function space From 59037d4202cbc3f208a3fa889ce20c43bd0cc8e2 Mon Sep 17 00:00:00 2001 From: J Dark Date: Wed, 11 Oct 2023 15:22:01 -0400 Subject: [PATCH 22/22] added elipsis --- festim/subdomain/volume_subdomain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/festim/subdomain/volume_subdomain.py b/festim/subdomain/volume_subdomain.py index af3447c9f..a3398993c 100644 --- a/festim/subdomain/volume_subdomain.py +++ b/festim/subdomain/volume_subdomain.py @@ -18,7 +18,7 @@ class VolumeSubdomain1D: Usage: >>> vol_subdomain = F.VolumeSubdomain1D(id=1, borders=[0, 1], - material=F.Material(...)) + ... material=F.Material(...)) """ def __init__(self, id, borders, material) -> None: