Skip to content

Commit

Permalink
Merge pull request #605 from jhdark/mesh_normal
Browse files Browse the repository at this point in the history
Mesh normal as property of F.Mesh
  • Loading branch information
jhdark authored Oct 17, 2023
2 parents 4836eba + 4fb8584 commit 2ce0c38
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 1 addition & 3 deletions festim/hydrogen_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,10 @@ def run(self, final_time: float):
mobile_xdmf.write_function(self.u, t)

cm = self.species[0].solution
# TODO this should be a property of Mesh
n = FacetNormal(self.mesh.mesh)
D = self.subdomains[0].material.get_diffusion_coefficient(
self.mesh.mesh, self.temperature
)
surface_flux = form(D * dot(grad(cm), n) * self.ds(2))
surface_flux = form(D * dot(grad(cm), self.mesh.n) * self.ds(2))
flux = assemble_scalar(surface_flux)
flux_values.append(flux)
times.append(t)
Expand Down
8 changes: 8 additions & 0 deletions festim/mesh/mesh.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import ufl


class Mesh:
"""
Mesh class
Expand All @@ -9,6 +12,7 @@ class Mesh:
mesh (dolfinx.mesh.Mesh): the mesh
vdim (int): the dimension of the mesh cells
fdim (int): the dimension of the mesh facets
n (ufl.FacetNormal): the normal vector to the facets
"""

def __init__(self, mesh=None):
Expand All @@ -32,3 +36,7 @@ def vdim(self):
@property
def fdim(self):
return self.mesh.topology.dim - 1

@property
def n(self):
return ufl.FacetNormal(self.mesh)
16 changes: 5 additions & 11 deletions test/test_permeation_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
dirichletbc,
locate_dofs_topological,
)
from ufl import exp, FacetNormal
from ufl import exp
import numpy as np


Expand Down Expand Up @@ -44,11 +44,10 @@ def siverts_law(T, S_0, E_S, pressure):
S = S_0 * exp(-E_S / F.k_B / T)
return S * pressure**0.5

fdim = my_mesh.mesh.topology.dim - 1
left_facets = my_model.facet_meshtags.find(1)
left_dofs = locate_dofs_topological(V, fdim, left_facets)
left_dofs = locate_dofs_topological(V, my_mesh.fdim, left_facets)
right_facets = my_model.facet_meshtags.find(2)
right_dofs = locate_dofs_topological(V, fdim, right_facets)
right_dofs = locate_dofs_topological(V, my_mesh.fdim, right_facets)

S_0 = 4.02e21
E_S = 1.04
Expand Down Expand Up @@ -143,20 +142,15 @@ def test_permeation_problem_multi_volume():
D = my_mat.get_diffusion_coefficient(my_mesh.mesh, temperature)

V = my_model.function_space
u = mobile_H.solution

# TODO this should be a property of Mesh
n = FacetNormal(my_mesh.mesh)

def siverts_law(T, S_0, E_S, pressure):
S = S_0 * exp(-E_S / F.k_B / T)
return S * pressure**0.5

fdim = my_mesh.mesh.topology.dim - 1
left_facets = my_model.facet_meshtags.find(1)
left_dofs = locate_dofs_topological(V, fdim, left_facets)
left_dofs = locate_dofs_topological(V, my_mesh.fdim, left_facets)
right_facets = my_model.facet_meshtags.find(2)
right_dofs = locate_dofs_topological(V, fdim, right_facets)
right_dofs = locate_dofs_topological(V, my_mesh.fdim, right_facets)

S_0 = 4.02e21
E_S = 1.04
Expand Down

0 comments on commit 2ce0c38

Please sign in to comment.