def adjoin_GaNi(a, b): print('Gani') a.dct() # print(a.val) a.grad_transpose() # print(a.val) a.idct() adjoin = Chebyshev_element(name='adjoin', N=N, shape=(), multype='scal') adjoin.val = np.multiply(a.val, b.val) adjoin.dct() # print(adjoin.val) adjoin.idct() # print('ab') # print(adjoin.val) adjoin.integrate() #scalar = np.sum(adjoin.val) return adjoin.integral #scalar # #
def test_interpolate(self): print('\nChecking enlarge and decrease') for dim, Ni in itertools.product([2], [5, 15, 55]): N = np.array(dim * [ Ni, ], dtype=np.int) dN = tuple(np.array(N * 2 - 1, dtype=np.int)) x0 = Chebyshev_element(name='x', N=N, shape=(), Fourier=False) x0.set_nodal_coord() x0.val = load(x0.coord, 'continuous') a = copy.deepcopy(x0) # print(x0.val) x0.interpolate() # print(x0.val) x0.dct() # print(x0.val) x0.shrink() # print(x0.val) x0.idct() # print(x0.val) self.assertTrue(np.allclose( a.val, x0.val, atol=1e-12, ), msg="Enlarge and shrink does not preserve values")
def tester(a, b): a.dct() # print(a.val) a.idct() adjoin = Chebyshev_element(name='test', N=N, shape=(), multype='scal') adjoin.val = np.multiply(a.val, b.val) adjoin.dct() # print(adjoin.val) adjoin.idct() # print('ab') # print(adjoin.val) adjoin.integrate() #scalar = np.sum(adjoin.val) return adjoin.integral #scalar # #
def test_integral_w_projection(self): print('\nChecking integral with projection') solution = [0, 0.8, 8.3317] for dim, Ni in itertools.product([2, 3], [100, 155]): N = np.array(dim * [ Ni, ], dtype=np.int) dN = tuple(np.array(N * 2 - 1, dtype=np.int)) integrant = lambda x: (x[0]**4) + (x[1]**3) if x.__len__( ) == 2 else (x[0]**4) + (x[1]**3) + np.cos(x[2]) u = Chebyshev_element(name='u', N=N, shape=(), multype='scal') u.set_nodal_coord() u.val = integrant(u.coord) u.integrate() i_1 = u.integral u.dct() u.enlarge() u.idct() u.integrate() i_2 = u.integral u.dct() u.shrink() u.idct() i_3 = u.integral self.assertTrue(np.isclose(i_1, i_2, rtol=1e-05, atol=1e-08, equal_nan=False), msg="Integral does not work correctly") self.assertTrue(np.isclose(i_1, i_3, rtol=1e-05, atol=1e-08, equal_nan=False), msg="Integral does not work correctly")
def test_dct(self): print('\nChecking discrete cosine transform...') for dim, Ni in itertools.product([2, 3], [2, 4, 8]): N = tuple(np.array(dim * [ Ni, ], dtype=np.int)) values = np.random.random_sample(N) Element = Chebyshev_element(name='x', N=N, shape=()) Element.val = values u1 = copy.deepcopy(Element.val) Element.dct() Element.idct() u2 = copy.deepcopy(Element.val) self.assertTrue( np.allclose( u1, u2, atol=1e-15, ), msg="dct does not preserve values for dim {} and N{}".format( dim, Ni))