test_lattice.py 4.86 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
class TestQ9(unittest.TestCase):
    def setUp(self):
        self.seed = 20
MischaD's avatar
MischaD committed
20
21
22
        self.lattice = Lattice(
            dimension=2, order=4, shell_list=[1, 2, 4], seed=self.seed
        )
MischaD's avatar
MischaD committed
23
24
25
26

    def testOutput(self):
        weights = self.lattice.calculate_weights()
        self.assertEqual(len(weights), 4)
MischaD's avatar
MischaD committed
27
        interval = self.lattice._interval
MischaD's avatar
MischaD committed
28
29
        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
30
31
32
33
34


class TestV17(unittest.TestCase):
    def setUp(self):
        self.seed = 44
MischaD's avatar
MischaD committed
35
36
37
        self.lattice = Lattice(
            dimension=2, order=6, shell_list=[1, 2, 4, 8, 9], seed=self.seed
        )
MischaD's avatar
MischaD committed
38

MischaD's avatar
MischaD committed
39
40
41
    def testOutput(self):
        weights = self.lattice.calculate_weights()
        self.assertEqual(len(weights), 6)
MischaD's avatar
MischaD committed
42
43
44
        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
45
46
47
48
49


class Test3D(unittest.TestCase):
    def setUp(self):
        self.seed = 20
MischaD's avatar
MischaD committed
50
51
52
        self.lattice = Lattice(
            dimension=3, order=6, shell_list=[1, 2, 3, 4, 12, 16], seed=self.seed
        )
MischaD's avatar
MischaD committed
53
54
55
56

    def testOutput(self):
        weights = self.lattice.calculate_weights()
        self.assertEqual(len(weights), 7)
MischaD's avatar
MischaD committed
57
58
        interval = self.lattice._interval
        self.assertAlmostEqual(sp.N(interval.inf), 0.3510760, places=6)
MischaD's avatar
MischaD committed
59
        self.assertAlmostEqual(sp.N(interval.sup), 4 / 9, places=6)
MischaD's avatar
MischaD committed
60
61


MischaD's avatar
MischaD committed
62
63
64
class TestV37(unittest.TestCase):
    def setUp(self):
        self.seed = 20
MischaD's avatar
MischaD committed
65
66
67
        self.lattice = Lattice(
            dimension=2, order=8, shell_list=[1, 2, 4, 5, 8, 9, 10, 16], seed=self.seed
        )
MischaD's avatar
MischaD committed
68
69
70
71

    def testOutput(self):
        weights = self.lattice.calculate_weights()
        self.assertEqual(len(weights), 9)
MischaD's avatar
MischaD committed
72
73
74
        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
75
76


MischaD's avatar
MischaD committed
77
78
79
80
class TestReducibleShell(unittest.TestCase):
    def setUp(self):
        self.seed = 20
        # 25 can be shell 05 or shell 34
MischaD's avatar
MischaD committed
81
82
83
84
85
86
        self.lattice = Lattice(
            dimension=2,
            order=10,
            shell_list=[1, 2, 4, 5, 8, 9, 10, 13, 16, 25],
            seed=44,
        )
MischaD's avatar
MischaD committed
87
88
89
90

    def testOutput(self):
        weights = self.lattice.calculate_weights()
        self.assertEqual(len(weights), 12)
MischaD's avatar
MischaD committed
91
92
93
        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
94
95


96
97
98
class TestSupremum(unittest.TestCase):
    def setUp(self):
        self.seed = 20
MischaD's avatar
MischaD committed
99
100
101
        self.lattice = Lattice(
            dimension=2, order=4, shell_list=[1, 2, 4], seed=self.seed, boundary="sup"
        )
102
103
104
105
106
107
108
109
110
111

    def testOutput(self):
        weights = self.lattice.calculate_weights()
        self.assertEqual(len(weights), 4)
        self.assertEqual(self.lattice.shell_from_type("10").weight, 0)


class TestUnwantedSubshells(unittest.TestCase):
    def setUp(self):
        self.seed = 20
MischaD's avatar
MischaD committed
112
113
114
115
116
117
118
        self.lattice = Lattice(
            dimension=3,
            order=6,
            shell_list=[1, 2, 3, 9, 16, 27],
            boundary="sup",
            unwanted_subshells=["221", "511"],
        )
119
120
121
122
123
124
125
126
127
128
129
130

    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
MischaD's avatar
MischaD committed
131
132
133
        self.lattice = Lattice(
            dimension=2, order=4, shell_list=[1, 2, 4], seed=self.seed
        )
134
135
136
137
        self.lattice_from_order = Lattice.from_order(dimension=2, order=4)
        self.lattice_from_name = Lattice.from_name("D2Q9")

    def test_lattice_equivalent(self):
138
139
        self.assertTrue(self.lattice.reduced_weights == self.lattice_from_name.reduced_weights)
        self.assertTrue(self.lattice.reduced_weights == self.lattice_from_order.reduced_weights)
140
141


mischa's avatar
mischa committed
142
143
144
145
146
147
148
149
150
151
class TestVelocitySets(unittest.TestCase):
    def setUp(self):
        self.seed = 20
        self.lattice = Lattice.from_name("D2V37")

    def test_velocity_set(self):
        c_s_sq, weights, velocities = self.lattice.velocity_set()
        self.assertAlmostEqual(c_s_sq, 0.6979533220196831, places=10)


MischaD's avatar
MischaD committed
152
if __name__ == "__main__":
MischaD's avatar
MischaD committed
153
154
    logger.disabled = True
    unittest.main()