Skip to content

Commit

Permalink
facet indices not dofs
Browse files Browse the repository at this point in the history
  • Loading branch information
jhdark committed Oct 25, 2023
1 parent 487ea24 commit eab5181
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
15 changes: 9 additions & 6 deletions festim/hydrogen_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions festim/subdomain/surface_subdomain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from dolfinx import fem
import dolfinx.mesh
import numpy as np

Expand All @@ -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]

0 comments on commit eab5181

Please sign in to comment.