def parent_index( self, grid_point_index, dim ): level, pos = grid_point_index.level_and_pos( dim ) parent_level, parent_pos = \ self.quadrature_rule_objects[self.indices[dim]].parent_index( level, pos ) parent_data = grid_point_index.data parent_index = GridPointIndex( parent_data ) parent_index.set_dimension_data( [parent_level,parent_pos], dim, 3 ) return parent_index
def test_tensor_product_basis( self ): # test piecewise basis functions num_dims = 2 basis_1d = [ PiecewiseLinearBasis() ] basis = TensorProductBasis( num_dims, basis_1d ) domain = TensorProductDomain( num_dims, ranges = [[-1.,1.]] ) assert basis.num_dims == num_dims x = numpy.random.uniform( -1., 1., ( 2, 20 ) ) index = GridPointIndex( numpy.array( [[1,0]], numpy.int32 ) ) true_val = basis_1d[0].value_set( x[0,:], index.get_dimension_data(0), -1., 1. ) * \ basis_1d[0].value_set( x[1,:], index.get_dimension_data(1), -1., 1. ) assert numpy.allclose( basis.value( x, index, domain ), true_val ) index = GridPointIndex( numpy.array( [[1,0,1,2]], numpy.int32 ) ) true_val = basis_1d[0].value_set( x[0,:], index.get_dimension_data(0), -1., 1. ) * \ basis_1d[0].value_set( x[1,:], index.get_dimension_data(1), -1., 1. ) assert numpy.allclose( basis.value( x, index, domain ), true_val )
def test_point_index( self ): s = set() # Test Initialisation and data access point_index = GridPointIndex( None ) s.add( point_index ) assert point_index.level_and_pos( 0 ) == (0,0) assert point_index.level_and_pos( 1 ) == (0,0) assert point_index.level_and_pos( 2 ) == (0,0) point_index = GridPointIndex( numpy.array( [[1,1,0]], numpy.int32 ) ) s.add( point_index ) assert point_index.level_and_pos( 0 ) == (0,0) assert point_index.level_and_pos( 1 ) == (1,0) assert point_index.level_and_pos( 2 ) == (0,0) point_index = GridPointIndex( numpy.array( [[2,1,0]], numpy.int32 ) ) s.add( point_index ) assert point_index.level_and_pos( 0 ) == (0,0) assert point_index.level_and_pos( 1 ) == (0,0) assert point_index.level_and_pos( 2 ) == (1,0) point_index = GridPointIndex( numpy.array( [[1,1,0],[2,1,0]], numpy.int32 ) ) s.add( point_index ) assert point_index.level_and_pos( 0 ) == (0,0) assert point_index.level_and_pos( 1 ) == (1,0) assert point_index.level_and_pos( 2 ) == (1,0) point_index = GridPointIndex( numpy.array( [[0,1,0],[2,1,0]], numpy.int32 ) ) s.add( point_index ) assert point_index.level_and_pos( 0 ) == (1,0) assert point_index.level_and_pos( 1 ) == (0,0) assert point_index.level_and_pos( 2 ) == (1,0) point_index = GridPointIndex( numpy.array( [[0,1,0],[1,1,0]], numpy.int32 ) ) s.add( point_index ) assert point_index.level_and_pos( 0 ) == (1,0) assert point_index.level_and_pos( 1 ) == (1,0) assert point_index.level_and_pos( 2 ) == (0,0) # Test hashing true_grid_point_indices = {} true_grid_point_indices[ None ] = 0 true_grid_point_indices[((1,1,0),)] = 0 true_grid_point_indices[((2,1,0),)] = 0 true_grid_point_indices[((1,1,0),(2,1,0))] = 0 true_grid_point_indices[((0,1,0),(2,1,0))] = 0 true_grid_point_indices[((0,1,0),(1,1,0))] = 0 assert len( s ) == 6 for pt in s: if ( not pt.is_root() ): # convert array to tuple key = tuple( tuple(x) for x in pt.get_id() ) assert true_grid_point_indices.has_key( key ) # add point already in set. The set should remain the same s.add( point_index ) assert len( s ) == 6