Commit 507575a9 authored by dboe's avatar dboe
Browse files

not much

parent 08625a6e
......@@ -24,6 +24,12 @@ class Sphere_Test(Tensors_Check, unittest.TestCase):
x, y, z = sympy.symbols('x y z')
self._inst.cut(x + 1./100*y > 0, at_intersection='split')
def test_triangle(self):
tri = self._inst.triangles()
mesh = tri.mesh()
print(self._inst, mesh)
self.assertTrue(self._inst.equal(mesh))
class IO_Stl_test(unittest.TestCase):
def setUp(self):
......
......@@ -1406,6 +1406,26 @@ class Tensors(AbstractNdarray):
return inst, template
def _cut_template(self, template):
# # Redirect fields
# fields = []
# if template.fields:
# template_field = np.array(template.fields[0])
# if len(self) > 0:
# '''
# if new vertices have been created in the template, it is
# in principle unclear what fields we have to refer to.
# Thus in creating the template, we gave np.nan.
# To make it fast, we replace nan with 0 as a dummy and correct
# the field entries afterwards with np.nan.
# '''
# nan_mask = np.isnan(template_field)
# template_field[nan_mask] = 0 # dummy reference to index 0.
# template_field = template_field.astype(int)
# for field in self.fields:
# projected_field = field[template_field]
# projected_field[nan_mask] = np.nan # correction for nan
# fields.append(projected_field)
# return type(self)(Tensors(template), *fields)
return self[template.fields[0]]
def cut(self, expression, coord_sys=None, return_template=False, **kwargs):
......@@ -2389,7 +2409,52 @@ class TensorMaps(TensorFields):
return inst, template
def _cut_template(self, template):
"""
Args:
template (tfields.TensorMaps)
Examples:
>>> import tfields
>>> import numpy as np
Build mesh
>>> mmap = tfields.TensorFields([[0, 1, 2], [0, 3, 4]],
... [[42, 21], [-42, -21]])
>>> m = tfields.Mesh3D([[0]*3, [1]*3, [2]*3, [3]*3, [4]*3],
... [0.0, 0.1, 0.2, 0.3, 0.4],
... [0.0, -0.1, -0.2, -0.3, -0.4],
... maps=[mmap])
Build template
>>> tmap = tfields.TensorFields([[0, 3, 4], [0, 1, 2]],
... [1, 0])
>>> t = tfields.Mesh3D([[0]*3, [-1]*3, [-2]*3, [-3]*3, [-4]*3],
... [1, 0, 3, 2, 4],
... maps=[tmap])
Use template as instruction to make a fast cut
>>> res = m._cut_template(t)
>>> assert np.array_equal(res.fields,
... [[0.1, 0.0, 0.3, 0.2, 0.4],
... [-0.1, 0.0, -0.3, -0.2, -0.4]])
>>> assert np.array_equal(res.maps[3].fields[0],
... [[-42, -21], [42, 21]])
"""
inst = super()._cut_template(template)
# # Redirect maps and their fields
# maps = []
# for mp, template_mp in zip(self.maps.values(), template.maps.values()):
# mp_fields = []
# for field in mp.fields:
# if len(template_mp) == 0 and len(template_mp.fields) == 0:
# mp_fields.append(field[0:0]) # np.empty
# else:
# mp_fields.append(field[template_mp.fields[0].astype(int)])
# new_mp = tfields.TensorFields(tfields.Tensors(template_mp),
# *mp_fields)
# maps.append(new_mp)
if template.fields:
# bulk was cut so we need to correct the map references.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment