File size: 1,452 Bytes
d68c650
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import copy
import unittest

import numpy as np

from stnn.pde.pde_system import PDESystem


class TestPDESystem(unittest.TestCase):

	def setUp(self):
		self.params = {
			'nx1': 50,
			'nx2': 100,
			'nx3': 75,
			'a1': 1.0,
			'a2': 2.0,
			'ell': 0.1,
			'eccentricity': 0.5
		}
		self.system = PDESystem(self.params)

	def test_initialization(self):
		self.assertEqual(self.system.params, self.params)

	def test_attribute_types(self):
		self.assertIsInstance(self.system.ib_slice, np.ndarray)
		self.assertIsInstance(self.system.ob_slice, np.ndarray)

	def test_attribute_values(self):
		self.assertEqual(self.system.a1, 1.0 - self.params['eccentricity'])

	def test_coordinate_system(self):
		expected_coords = 'ellipse' if self.params['eccentricity'] != 0 else 'circle'
		self.assertEqual(self.system._coords, expected_coords)

	def test_unused_params_warning(self):
		copied_params = copy.deepcopy(self.params)
		copied_params['unusedkey'] = 0
		with self.assertWarns(UserWarning) as _:
			_ = PDESystem(copied_params)

	def test_L(self):
		# If f(x1, x2, x3) is constant, then L * f should be 0 except adjacent to the boundary.
		L = self.system.L
		nx1, nx2, nx3 = self.params['nx1'], self.params['nx2'], self.params['nx3']
		f0 = 2.3 * np.ones((nx1, nx2, nx3))
		result = L @ f0.ravel()
		result = result.reshape((nx1, nx2, nx3))
		np.testing.assert_allclose(result[1:-1, ...], 0, atol = 1e-7)


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