test_mesh3D.py 1.51 KB
Newer Older
1
2
3
4
5
6
import tfields
import numpy as np
import unittest
import sympy  # NOQA: F401
import os
import sys
dboe's avatar
dboe committed
7
from .test_core import TensorFields_Check
8
9
10
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)))
11
12


dboe's avatar
dboe committed
13
class Mesh3D_Check(TensorFields_Check):
dboe's avatar
dboe committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
    def test_cut_split(self):
        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, self._inst.maps)
        # print(tri)
        # print(mesh, mesh.maps)
        # print(tfields.Tensors(self._inst).equal(mesh))
        self.assertTrue(self._inst.equal(mesh))


dboe's avatar
dboe committed
28
29
30
31
32
33
class Square_Test(Mesh3D_Check, unittest.TestCase):
    def setUp(self):
        self._inst = tfields.Mesh3D.plane((0, 1, 2j), (0, 1, 2j), (0, 0, 1j))


class Sphere_Test(Mesh3D_Check, unittest.TestCase):
34
35
36
37
38
39
40
41
42
    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

Daniel Boeckenhoff's avatar
Daniel Boeckenhoff committed
43

dboe's avatar
dboe committed
44
class IO_Stl_test(unittest.TestCase):  # no Mesh3D_Check for speed
Daniel Boeckenhoff's avatar
Daniel Boeckenhoff committed
45
    def setUp(self):
46
47
48
        self._inst = tfields.Mesh3D.load(os.path.join(THIS_DIR,
                                                      '../data/baffle.stl'))

49
50

if __name__ == '__main__':
51
    unittest.main()