Commit b00afb4b authored by Daniel Boeckenhoff's avatar Daniel Boeckenhoff
Browse files

presentation slides and test for sphere splitting added

parent 10d7a085
This diff is collapsed.
This diff is collapsed.
import tfields
import numpy as np
import unittest
import sympy # NOQA: F401
import os
import sys
THIS_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(THIS_DIR)))
from test_core import Base_Check
class Sphere_Test(Base_Check, unittest.TestCase):
def setUp(self):
self._inst = tfields.Mesh3D.grid(
(1, 1, 1),
(-np.pi, np.pi, 12),
(-np.pi / 2, np.pi / 2, 12),
coord_sys='spherical')
self._inst.transform('cartesian')
self._inst[:, 1] += 2
def test_cut_split(self):
x, y, z = sympy.symbols('x y z')
halfed = self._inst.cut(x > 0, at_intersection='split')
if __name__ == '__main__':
unittest.main()
...@@ -1512,7 +1512,9 @@ class TensorFields(Tensors): ...@@ -1512,7 +1512,9 @@ class TensorFields(Tensors):
if field_index is None: if field_index is None:
artist = super(TensorFields, self).plot(**kwargs) artist = super(TensorFields, self).plot(**kwargs)
else: else:
field = self.fields[field_index] field = self.fields[field_index].copy()
if self.dim == field.dim:
field.transform(self.coord_sys)
if field.dim == 1: if field.dim == 1:
artist = super(TensorFields, self).plot(c=field, **kwargs) artist = super(TensorFields, self).plot(c=field, **kwargs)
elif field.dim in (2, 3): elif field.dim in (2, 3):
......
...@@ -91,6 +91,10 @@ def _intersect(triangle, plane, vertices_rejected): ...@@ -91,6 +91,10 @@ def _intersect(triangle, plane, vertices_rejected):
# TODO handle special cases. For now triangles with at least two points on plane are excluded # TODO handle special cases. For now triangles with at least two points on plane are excluded
new_points = None new_points = None
print(triangle, plane, vertices_rejected)
print(lonely_bool, index)
print(s0, s1, s2)
print(d0, d1, d2)
if len(s0) == 2: if len(s0) == 2:
# both points on plane # both points on plane
return new_points return new_points
...@@ -111,7 +115,6 @@ def _intersect(triangle, plane, vertices_rejected): ...@@ -111,7 +115,6 @@ def _intersect(triangle, plane, vertices_rejected):
elif len(s0) == 1 and len(s2) == 1: elif len(s0) == 1 and len(s2) == 1:
new_points = [[couple_indices[0], couple_indices[1], s0[0]], new_points = [[couple_indices[0], couple_indices[1], s0[0]],
[couple_indices[1], s2[0], complex(2)]] [couple_indices[1], s2[0], complex(2)]]
else: else:
# one new triangle # one new triangle
if len(s0) == 1 and len(s1) == 1: if len(s0) == 1 and len(s1) == 1:
...@@ -590,7 +593,6 @@ class Mesh3D(tfields.TensorMaps): ...@@ -590,7 +593,6 @@ class Mesh3D(tfields.TensorMaps):
def _cut_sympy(self, expression, at_intersection="remove", _in_recursion=False): def _cut_sympy(self, expression, at_intersection="remove", _in_recursion=False):
""" """
Partition the mesh with the cuts given and return the template Partition the mesh with the cuts given and return the template
""" """
eps = 0.000000001 eps = 0.000000001
# direct return if self is empty # direct return if self is empty
...@@ -718,6 +720,7 @@ class Mesh3D(tfields.TensorMaps): ...@@ -718,6 +720,7 @@ class Mesh3D(tfields.TensorMaps):
Add the intersection points and faces Add the intersection points and faces
""" """
intersection = _intersect(triangle_points, plane, vertices_rejected) intersection = _intersect(triangle_points, plane, vertices_rejected)
print(intersection)
last_idx = len(vertices) - 1 last_idx = len(vertices) - 1
for tri_list in intersection: for tri_list in intersection:
new_face = [] new_face = []
...@@ -933,7 +936,7 @@ class Mesh3D(tfields.TensorMaps): ...@@ -933,7 +936,7 @@ class Mesh3D(tfields.TensorMaps):
>>> assert m_split_template.fields[0].equal( >>> assert m_split_template.fields[0].equal(
... list(range(8, 16)) + [np.nan] * 7, equal_nan=True) ... list(range(8, 16)) + [np.nan] * 7, equal_nan=True)
This seems irrelevant at first but Consider, the map field or the This seems irrelevant at first but consider, the map field or the
tensor field changes: tensor field changes:
>>> m_altered_fields = m.copy() >>> m_altered_fields = m.copy()
>>> m_altered_fields[0] += 42 >>> m_altered_fields[0] += 42
...@@ -941,7 +944,6 @@ class Mesh3D(tfields.TensorMaps): ...@@ -941,7 +944,6 @@ class Mesh3D(tfields.TensorMaps):
>>> assert tfields.Tensors(m_split).equal(m_altered_fields.cut(template)) >>> assert tfields.Tensors(m_split).equal(m_altered_fields.cut(template))
>>> assert tfields.Tensors(m_split.maps[0]).equal(m_altered_fields.cut(template).maps[0]) >>> assert tfields.Tensors(m_split.maps[0]).equal(m_altered_fields.cut(template).maps[0])
The cut expression may be a sympy.BooleanFunction: The cut expression may be a sympy.BooleanFunction:
>>> cut_expr_bool_fun = (x > 1.5) & (y < 1.5) & (y >0.2) & (z > -0.5) >>> cut_expr_bool_fun = (x > 1.5) & (y < 1.5) & (y >0.2) & (z > -0.5)
>>> m_split_bool = m.cut(cut_expr_bool_fun, at_intersection='split') >>> m_split_bool = m.cut(cut_expr_bool_fun, at_intersection='split')
...@@ -1006,5 +1008,5 @@ class Mesh3D(tfields.TensorMaps): ...@@ -1006,5 +1008,5 @@ class Mesh3D(tfields.TensorMaps):
if __name__ == '__main__': # pragma: no cover if __name__ == '__main__': # pragma: no cover
import doctest import doctest
# doctest.run_docstring_examples(Mesh3D.cut, globals()) doctest.run_docstring_examples(Mesh3D.cut, globals())
doctest.testmod() # doctest.testmod()
Supports Markdown
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