From eab51811c7c1195836d21a2c427463f361bd3979 Mon Sep 17 00:00:00 2001 From: J Dark Date: Wed, 25 Oct 2023 10:52:42 -0400 Subject: [PATCH] facet indices not dofs --- festim/hydrogen_transport_problem.py | 15 +++++++++------ festim/subdomain/surface_subdomain.py | 12 ++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/festim/hydrogen_transport_problem.py b/festim/hydrogen_transport_problem.py index 471e42e4d..a9a9447ac 100644 --- a/festim/hydrogen_transport_problem.py +++ b/festim/hydrogen_transport_problem.py @@ -139,7 +139,8 @@ def defing_export_writers(self): def define_function_space(self): """Creates the function space of the model, creates a mixed element if - model is multispecies. Creates the main solution and previous solution function u and u_n.""" + model is multispecies. Creates the main solution and previous solution + function u and u_n.""" element_CG = basix.ufl.element( basix.ElementFamily.P, self.mesh.mesh.basix_cell(), @@ -193,7 +194,7 @@ def assign_functions_to_species(self): def define_markers_and_measures(self): """Defines the markers and measures of the model""" - dofs_facets, tags_facets = [], [] + facet_indices, tags_facets = [], [] # find all cells in domain and mark them as 0 num_cells = self.mesh.mesh.topology.index_map(self.mesh.vdim).size_local @@ -202,8 +203,10 @@ def define_markers_and_measures(self): for sub_dom in self.subdomains: if isinstance(sub_dom, F.SurfaceSubdomain1D): - dof = sub_dom.locate_dof(self.mesh.mesh, self.mesh.fdim) - dofs_facets.append(dof) + facet_index = sub_dom.locate_boundary_facet_indices( + self.mesh.mesh, self.mesh.fdim + ) + facet_indices.append(facet_index) tags_facets.append(sub_dom.id) if isinstance(sub_dom, F.VolumeSubdomain1D): # find all cells in subdomain and mark them as sub_dom.id @@ -218,12 +221,12 @@ def define_markers_and_measures(self): self.mesh.check_borders(self.volume_subdomains) # dofs and tags need to be in np.in32 format for meshtags - dofs_facets = np.array(dofs_facets, dtype=np.int32) + facet_indices = np.array(facet_indices, dtype=np.int32) tags_facets = np.array(tags_facets, dtype=np.int32) # define mesh tags self.facet_meshtags = meshtags( - self.mesh.mesh, self.mesh.fdim, dofs_facets, tags_facets + self.mesh.mesh, self.mesh.fdim, facet_indices, tags_facets ) self.volume_meshtags = meshtags( self.mesh.mesh, self.mesh.vdim, mesh_cell_indices, tags_volumes diff --git a/festim/subdomain/surface_subdomain.py b/festim/subdomain/surface_subdomain.py index f1ee32839..80fd082aa 100644 --- a/festim/subdomain/surface_subdomain.py +++ b/festim/subdomain/surface_subdomain.py @@ -1,4 +1,3 @@ -from dolfinx import fem import dolfinx.mesh import numpy as np @@ -23,18 +22,19 @@ def __init__(self, id, x) -> None: self.id = id self.x = x - def locate_dof(self, mesh, fdim): + def locate_boundary_facet_indices(self, mesh, fdim): """Locates the dof of the surface subdomain within the function space + and return the index of the dof Args: mesh (dolfinx.mesh.Mesh): the mesh of the simulation fdim (int): the dimension of the model facets Returns: - dof (np.array): the first value in the list of dofs of the surface - subdomain + index (np.array): the first value in the list of surface facet + indices of the subdomain """ - dofs = dolfinx.mesh.locate_entities_boundary( + indices = dolfinx.mesh.locate_entities_boundary( mesh, fdim, lambda x: np.isclose(x[0], self.x) ) - return dofs[0] + return indices[0]