test_lattice.py 4.31 KB
Newer Older
MischaD's avatar
MischaD committed
1
import unittest
MischaD's avatar
MischaD committed
2
import sympy as sp
MischaD's avatar
MischaD committed
3
4
5
6
from lbmweights import Lattice
from lbmweights.utils.mylog import logger


MischaD's avatar
MischaD committed
7
8
9
10
11
12
13
14
15
16
class SolutionExpected(unittest.TestCase):
    def setUp(self):
        pass

    def test_solution_expected(self):
        for name, lattice_args in Lattice.BY_NAME.items():
            lattice = Lattice(**lattice_args)
            self.assertTrue(lattice.solution_expected())


MischaD's avatar
MischaD committed
17
18
19
20
21
22
23
24
class TestQ9(unittest.TestCase):
    def setUp(self):
        self.seed = 20
        self.lattice = Lattice(dimension=2, order=4, shell_list=[1, 2, 4], seed=self.seed)

    def testOutput(self):
        weights = self.lattice.calculate_weights()
        self.assertEqual(len(weights), 4)
MischaD's avatar
MischaD committed
25
26
27
        interval = self.lattice._interval
        self.assertAlmostEqual(sp.N(interval.inf), 1/3, places=6)
        self.assertAlmostEqual(sp.N(interval.sup), 2/3, places=6)
MischaD's avatar
MischaD committed
28
29
30
31
32
33
34


class TestV17(unittest.TestCase):
    def setUp(self):
        self.seed = 44
        self.lattice = Lattice(dimension=2, order=6, shell_list=[1,2,4,8,9], seed=self.seed)

MischaD's avatar
MischaD committed
35

MischaD's avatar
MischaD committed
36
37
38
    def testOutput(self):
        weights = self.lattice.calculate_weights()
        self.assertEqual(len(weights), 6)
MischaD's avatar
MischaD committed
39
40
41
        interval = self.lattice._interval
        self.assertAlmostEqual(sp.N(interval.inf), 0.3702519, places=6)
        self.assertAlmostEqual(sp.N(interval.sup), 1.148412, places=6)
MischaD's avatar
MischaD committed
42
43
44
45
46
47
48
49
50
51


class Test3D(unittest.TestCase):
    def setUp(self):
        self.seed = 20
        self.lattice = Lattice(dimension=3, order=6, shell_list=[1,2,3,4,12,16], seed=self.seed)

    def testOutput(self):
        weights = self.lattice.calculate_weights()
        self.assertEqual(len(weights), 7)
MischaD's avatar
MischaD committed
52
53
54
        interval = self.lattice._interval
        self.assertAlmostEqual(sp.N(interval.inf), 0.3510760, places=6)
        self.assertAlmostEqual(sp.N(interval.sup), 4/9, places=6)
MischaD's avatar
MischaD committed
55
56


MischaD's avatar
MischaD committed
57
58
59
60
61
62
63
64
class TestV37(unittest.TestCase):
    def setUp(self):
        self.seed = 20
        self.lattice = Lattice(dimension=2, order=8, shell_list=[1,2,4,5,8,9,10,16], seed=self.seed)

    def testOutput(self):
        weights = self.lattice.calculate_weights()
        self.assertEqual(len(weights), 9)
MischaD's avatar
MischaD committed
65
66
67
        interval = self.lattice._interval
        self.assertAlmostEqual(sp.N(interval.inf), 0.6979533, places=6)
        self.assertAlmostEqual(sp.N(interval.sup), 0.8704738, places=6)
MischaD's avatar
MischaD committed
68
69


MischaD's avatar
MischaD committed
70
71
72
73
74
75
76
77
78
class TestReducibleShell(unittest.TestCase):
    def setUp(self):
        self.seed = 20
        # 25 can be shell 05 or shell 34
        self.lattice = Lattice(dimension=2, order=10, shell_list=[1,2,4,5,8,9,10,13,16,25], seed=44)

    def testOutput(self):
        weights = self.lattice.calculate_weights()
        self.assertEqual(len(weights), 12)
MischaD's avatar
MischaD committed
79
80
81
        interval = self.lattice._interval
        self.assertAlmostEqual(sp.N(interval.inf), 0.7592510, places=6)
        self.assertAlmostEqual(sp.N(interval.sup), 0.9054850, places=6)
MischaD's avatar
MischaD committed
82
83


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
class TestSupremum(unittest.TestCase):
    def setUp(self):
        self.seed = 20
        self.lattice = Lattice(dimension=2, order=4, shell_list=[1, 2, 4], seed=self.seed, boundary="sup")

    def testOutput(self):
        weights = self.lattice.calculate_weights()
        self.assertEqual(len(weights), 4)
        self.assertEqual(self.lattice.velocities, ["00", "10", "11", "20"])
        self.assertEqual(self.lattice.shell_from_type("10").weight, 0)


class TestUnwantedSubshells(unittest.TestCase):
    def setUp(self):
        self.seed = 20
        self.lattice = Lattice(dimension=3, order=6, shell_list=[1,2,3,9,16,27], boundary="sup", unwanted_subshells=["221", "511"])

    def testOutput(self):
        weights = self.lattice.calculate_weights()
        self.assertEqual(len(weights), 7)
        interval = self.lattice._interval
        self.assertAlmostEqual(sp.N(interval.inf), 0.3500280, places=6)
        self.assertAlmostEqual(sp.N(interval.sup), 0.3675445, places=6)


class TestInitSchemes(unittest.TestCase):
    def setUp(self):
        self.seed = 20
        self.lattice = Lattice(dimension=2, order=4, shell_list=[1, 2, 4], seed=self.seed)
        self.lattice_from_order = Lattice.from_order(dimension=2, order=4)
        self.lattice_from_name = Lattice.from_name("D2Q9")

    def test_lattice_equivalent(self):
        self.assertTrue(self.lattice.weights == self.lattice_from_name.weights)
        self.assertTrue(self.lattice.weights == self.lattice_from_order.weights)


MischaD's avatar
MischaD committed
121
122
123
if __name__ == '__main__':
    logger.disabled = True
    unittest.main()