Ejemplo n.º 1
0
	def test_weights(self):
		# tests are tuple consisting of array containing s, array containing correct weight output, and order of derivative
		tests = ((np.array([-2,-1,0]),np.array([[1,-2,1]]),2),
				(np.array([-4,-3,-2,-1,0,1,2,3,4]),np.array([[1./280,-4./105,1./5,-4./5,0.,4./5,-1./5,4./105,-1./280]]),1),
				(np.array([-1,0,1]),np.array([[1,-2,1]]),2))

		for test in tests:
			stcl = stencil.Stencil(test[0])
			weights = stcl.get_weights(test[2])
			np.testing.assert_almost_equal(weights,test[1])
Ejemplo n.º 2
0
    def test_stencil_matrix(self):
        # tests are tuples consisting of array containing indicies s and an array corresponding to the correct output of s_matrix
        tests = (([-2, -1, 0, 1, 2],
                  np.array([[1, 1, 1, 1, 1], [-2, -1, 0, 1, 2],
                            [4, 1, 0, 1, 4], [-8, -1, 0, 1, 8],
                            [16, 1, 0, 1, 16]])), (np.array([-2, -1, 0]),
                                                   np.array([[1, 1, 1],
                                                             [-2, -1, 0],
                                                             [4, 1, 0]])))

        for test in tests:
            stcl = stencil.Stencil(test[0])
            stcl._stencil_matrix()

            np.testing.assert_array_equal(stcl.s_matrix, test[1])
Ejemplo n.º 3
0
    def __init__(self, s_list, deg):
        
        ## \var stncl A stencil object
        self.stncl = stencil.Stencil(s_list)

        ## \var deg The derivative degree
        self.deg = deg

        ## \var accuracy Accuracy of the approximation, which is
        #  equal to the number of stencil points minus the
        #  derivative degree
        self.accuracy = self.stncl.N - self.deg
        assert self.accuracy > 0, '''Improper 1D operator formation: 
                                  increase number of stencil points!'''

        ## \var weights The appropriate weighting coefficients for
        #  the finite difference approximation
        self.weights = self.stncl.get_weights(deg)