Skip to content

Commit

Permalink
create meshtags and meaures from subdomains
Browse files Browse the repository at this point in the history
  • Loading branch information
jhdark committed Oct 10, 2023
1 parent 19e1abc commit 8e649e3
Showing 1 changed file with 45 additions and 12 deletions.
57 changes: 45 additions & 12 deletions festim/hydrogen_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -98,19 +95,55 @@ 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()

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:
Expand Down

0 comments on commit 8e649e3

Please sign in to comment.