Skip to content

Commit

Permalink
reorient boundary normals to outward normals in ElementGlobal
Browse files Browse the repository at this point in the history
  • Loading branch information
kinnala committed Dec 23, 2023
1 parent 42b532e commit 29d2200
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
14 changes: 14 additions & 0 deletions skfem/element/element_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ def _eval_dofs(self, mesh, tind=None):
-w['n'][itr, 0, :]])
w['n'][itr] /= np.linalg.norm(w['n'][itr], axis=0)

# swap
from skfem.assembly import FacetBasis
fb = FacetBasis(mesh, mesh.elem(), intorder=0)
ix = np.isin(mesh.t2f, mesh.boundary_facets())
sortix = np.argsort(mesh.t2f[ix])
norms1 = np.vstack((w['n'][:, 0, :][ix][sortix],
w['n'][:, 1, :][ix][sortix]))
norms2 = fb.normals[:, :, 0]
signs = np.diag(norms1.T @ norms2)
signs1 = signs.copy()
signs1[sortix] = signs
w['n'][:, 0, :][ix] *= signs1
w['n'][:, 1, :][ix] *= signs1

# evaluate dofs, gdof implemented in subclasses
for itr in range(N):
for jtr in range(N):
Expand Down
21 changes: 21 additions & 0 deletions tests/test_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,3 +747,24 @@ def test_hcurl_projections_3d():

assert_almost_equal(curly, curlx)
assert_almost_equal(curly, curla)


def test_element_global_boundary_normal():

mesh = MeshTri().refined(3)
basis = Basis(mesh, ElementTriMorley())

D = basis.get_dofs().all('u_n')
x = basis.zeros()
x[D] = 1

@BilinearForm
def bilinf(u, v, w):
return ddot(u.hess, v.hess)

A = bilinf.assemble(basis)
f = unit_load.assemble(basis)

y = solve(*condense(A, f, D=D, x=x))

assert (y[basis.get_dofs(elements=True).all('u')] < 0).all()
3 changes: 2 additions & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class TestEx02(TestCase):

def runTest(self):
import docs.examples.ex02 as ex02
self.assertAlmostEqual(np.max(ex02.x), 0.001217973811129439)
self.assertAlmostEqual(np.max(ex02.x[ex02.ib.nodal_dofs[0]]),
0.00033840961095522285)


class TestEx03(TestCase):
Expand Down

0 comments on commit 29d2200

Please sign in to comment.