Skip to content

Commit

Permalink
WIP: fix flipping normal of manifold refs
Browse files Browse the repository at this point in the history
  • Loading branch information
joostvanzwieten committed May 14, 2020
1 parent 2c952c8 commit eeb7a99
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
12 changes: 12 additions & 0 deletions nutils/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ def withmanifoldedges(self):
else:
return self

@property
def flipped(self):
return self

strictreference = types.strict[Reference]

class EmptyLike(Reference):
Expand Down Expand Up @@ -933,6 +937,10 @@ def get_poly_coeffs(self, basis, **kwargs):
def get_edge_dofs(self, degree, iedge):
return self.baseref.get_edge_dofs(degree, iedge)

@property
def flipped(self):
return OwnChildReference(self.baseref.flipped)

class WithChildrenReference(Reference):
'base reference with explicit children'

Expand Down Expand Up @@ -1362,6 +1370,10 @@ def inside(self, point, eps=0):
def slice(self, levelfunc, ndivisions):
return ManifoldReference(self.ref.slice(lambda vertices: levelfunc(self.trans.apply(vertices)), ndivisions), self.trans)

@property
def flipped(self):
return ManifoldReference(self.ref, self.trans.flipped)

## UTILITY FUNCTIONS

def parse_legacy_ischeme(ischeme):
Expand Down
5 changes: 3 additions & 2 deletions nutils/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,8 @@ class OppositeTopology(Topology):

def __init__(self, basetopo):
self.basetopo = basetopo
super().__init__(basetopo.roots, basetopo.references, basetopo.opposites, basetopo.transforms)
refs = elementseq.asreferences((ref.flipped for ref in basetopo.references), self.basetopo.ndims)
super().__init__(basetopo.roots, refs, basetopo.opposites, basetopo.transforms)

def getitem(self, item):
return ~(self.basetopo.getitem(item))
Expand Down Expand Up @@ -2592,7 +2593,7 @@ def addnewedge(ielem, etrans):
iface = aname, bname
else:
iface = bname, aname
aetrans, betrans = betrans, aetrans
aetrans, betrans, aeref, beref = betrans, aetrans, beref, aeref
newreferences[iface].append(aeref)
newtransforms[iface].append(addnewedge(ibase, aetrans.separate(todims)))
newopposites[iface].append(addnewedge(ibase, betrans.separate(todims)))
Expand Down
14 changes: 13 additions & 1 deletion tests/test_finitecell.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ class partialtrim(TestCase):
# +-----+-----+

def setUp(self):
self.topo, geom = mesh.rectilinear([2,2])
self.topo, self.geom = mesh.rectilinear([2,2])
geom = self.geom
if self.method == 'trim':
self.topoA = self.topo.trim(geom[0]-1+geom[1]*(geom[1]-.5), maxrefine=1)
self.topoB = self.topo - self.topoA
Expand Down Expand Up @@ -415,5 +416,16 @@ def test_baseboundaries(self):
alttopo = topology.ConnectedTopology(topo.roots, topo.references, topo.transforms, topo.opposites, topo.connectivity)
self.assertEqual(dict(zip(alttopo.boundary.transforms, alttopo.boundary.references)), dict(zip(topo.boundary.transforms, topo.boundary.references)))

def test_volumes(self):
geom = self.geom
f = ((0.5 - geom)**2).sum(axis=0)
lhs = self.topoA.integrate(f.grad(geom)*function.J(geom), ischeme='gauss2')
rhs = self.topoA.boundary.integrate(f*function.normal(geom)*function.J(geom), ischeme='gauss2')
numpy.testing.assert_array_almost_equal(lhs, rhs)
lhs = self.topoB.integrate(f.grad(geom)*function.J(geom), ischeme='gauss2')
rhs = self.topoB.boundary.integrate(f*function.normal(geom)*function.J(geom), ischeme='gauss2')
numpy.testing.assert_array_almost_equal(lhs, rhs)


partialtrim(method='trim')
partialtrim(method='partition')

0 comments on commit eeb7a99

Please sign in to comment.