def test_rt2d_vicious_boundary_case():#{{{ # Test the ray trace routine with a small test case ############################################### # # Hydro rho value : # # .-------------------------------. # | | | | 4 | 5 | # | 3 | 3 | 4 |---|---| # | | | | 4 | 4 | # |-------|-------|-------|-------| # | | | | | # | 3 | 3 | 4 | 4 | # | | | | | # |-------------------------------| # | | | | | # | 1 | 1 | 2 | 2 | # | | | | | # |-------|-------|-------|-------| # | | | | | # | 1 | 1 | 2 | 2 | # | | | | | # |-------------------------------| # ^ / ^ ^ ^ # | | | | # 0 1 2 3 4 # # The second ray pass trough the middle of block with value 3 # # Block with rho value 1 and 3 belongs to cpu (or dset) 1 # Block with rho value 2 and 4 and 5 belongs to cpu (or dset) 2 ################################################ # Define rays to be traced ray_origins = numpy.array([[0.,0.],[.1,0.],[.25,0.],[.5,0.],[0.875,0.]]) ray_vectors = numpy.array([[0.,1.],[.2*1.04**-.5,1.*1.04**-.5],[0.,1.],[0.,1.],[0.,1.]]) ray_lengths = numpy.array([2.,2.,2.,2.,2.]) # The second ray pass trough the middle of block with value 3 # Get datasets and operator (dset_1, dset_2, info) = bluid_simple_dset() op = build_simple_operator() # Do the ray trace through the first dset: map, ray_length_mapsDset = ray_trace_amr(dset_1, ray_origins, ray_vectors, ray_lengths, op, info) map_asserted_result=numpy.array([[2.],[2*1.04**.5],[2.],[0.],[0.]]) print("\nThe second ray is a simple diagonal") print("map_asserted_result =",map_asserted_result) print("map =",map) assert (abs(map_asserted_result - map) < 10e-15).all() # Do the ray trace through the second dset: map, ray_length_mapsDset = ray_trace_amr(dset_2, ray_origins, ray_vectors, ray_lengths, op, info) map_asserted_result=numpy.array([[0.],[0.],[0.],[3.],[3.+1./8.]]) print("\nmap_asserted_result =",map_asserted_result) print("map =",map) assert (abs(map_asserted_result - map) < 10e-15).all()
def test_rt2d_simple_diagonal():#{{{ # Test the ray trace routine with a small test case ############################################### # # Hydro rho value : # # .-------------------------------. # | | | | 4 | 5 | # | 3 | 3 | 4 |---|---| # | | | | 4 | 4 | # |-------|-------|-------|-------| # | | | | | # | 3 | 3 | 4 | 4 | # | | | | | # |-------------------------------| # | | | | | # | 1 | 1 | 2 | 2 | # | | | | | # |-------|-------|-------|-------| # | | | | | # | 1 | 1 | 2 | 2 | # | | | | | # |-------------------------------| # / #ray # # Block with rho value 1 and 3 belongs to cpu (or dset) 1 # Block with rho value 2 and 4 and 5 belongs to cpu (or dset) 2 ################################################ # Define rays to be traced ray_origins = numpy.array([[.1,0.]]) ray_vectors = numpy.array([[.1*1.01**-.5,1.*1.01**-.5]]) # so that ray ends at ([0.1,1]) ray_lengths = numpy.array([2.]) # Get datasets and operator (dset_1, dset_2, info) = bluid_simple_dset() op = build_simple_operator() # Do the ray trace through the first dset: map, ray_length_mapsDset = ray_trace_amr(dset_1, ray_origins, ray_vectors, ray_lengths, op, info) map_asserted_result=numpy.array([[2*1.01**.5]]) print("\nmap_asserted_result =",map_asserted_result) print("map =",map) print("ray_length_mapsDset", ray_length_mapsDset) assert (abs(map_asserted_result - map) < 10e-15).all() assert (abs(ray_length_mapsDset - [[1.01**.5]]) < 1e-15).all()
def test_rt2d_with_overlap():#{{{ # Test the ray trace routine with a small test case # Define rays to be traced ray_origins = numpy.array([[.1,0.],[.3,0.],[.45,0.],[.6,0.]]) ray_vectors = numpy.array([[0.,1.],[0.,1.],[0.,1.],[0.,1.]]) ray_lengths = numpy.array([1.,1.,1.,1.]) #ray_origins = numpy.array([[.6,0.]]) #ray_vectors = numpy.array([[0.,1.]]) # Get,[ datasets and operator (dset_1, dset_2, info) = bluid_dset_with_overlap() op = build_simple_operator() # Do the ray trace through the first dset: map, ray_length_mapsDset = ray_trace_amr(dset_1, ray_origins, ray_vectors, ray_lengths, op, info) map_asserted_result=numpy.array([[1.*.75+2.*.25],[1.*.5+2.*.375+1.*.125],[1.*.5+2.*.375+1.*.125],[0.0625]]) print("\nmap_asserted_result =",map_asserted_result) print("map =",map) assert (abs(map_asserted_result - map) < 10e-15).all()
def test_rt2d_complex_WITHOUT_C_CODE():#{{{ # Test the ray trace routine with the same amr structure as test_rt2d_simple() # but with more specific values to reveal eventual mistakes # Define rays to be traced trough the first dataset ray_origins = numpy.array([[0.1,0.],[0.3,0.]]) ray_vectors = numpy.array([[0.,1.],[0.,1.]]) ray_lengths = numpy.array([1.,1.]) # Get datasets and operator (dset_1, dset_2, info) = bluid_simple_dset(various_value = True) op = build_simple_operator() # Do the ray trace through the first dset: map, ray_length_mapsDset = ray_trace_amr(dset_1, ray_origins, ray_vectors, ray_lengths, op, info, use_C_code = False) map_asserted_result=numpy.array([[0.01*0.25+0.04*0.25+0.0001*0.25+0.0004*0.25],\ [0.02*0.25+0.08*0.25+0.0002*0.25+0.0008*0.25]]) print("\nmap_asserted_result =",map_asserted_result) print("map =",map) assert (abs(map_asserted_result - map) < 10e-15).all()
def test_rt2d_simple():#{{{ # Test the ray trace routine with a small test case ############################################### # # Hydro rho value : # # .-------------------------------. # | | | | 4 | 5 | # | 3 | 3 | 4 |---|---| # | | | | 4 | 4 | # |-------|-------|-------|-------| # | | | | | # | 3 | 3 | 4 | 4 | # | | | | | # |-------------------------------| # | | | | | # | 1 | 1 | 2 | 2 | # | | | | | # |-------|-------|-------|-------| # | | | | | # | 1 | 1 | 2 | 2 | # | | | | | # |-------------------------------| # ^ ^ ^ ^ # | | | | # ray 0 1 2 3 # # Block with rho value 1 and 3 belongs to cpu (or dset) 1 # Block with rho value 2 and 4 and 5 belongs to cpu (or dset) 2 ################################################ # Define rays to be traced ray_origins = numpy.array([[0.1,0.],[0.3,0.],[0.7,0.],[0.9,0.]]) ray_vectors = numpy.array([[0.,1.],[0.,1.],[0.,1.],[0.,1.]]) ray_lengths = numpy.array([1.,.6,1.,1.]) # Get datasets and operator (dset_1, dset_2, info) = bluid_simple_dset() op = build_simple_operator() # Do the ray trace through the first dset: map, ray_length_mapsDset = ray_trace_amr(dset_1, ray_origins, ray_vectors, ray_lengths, op, info) map_asserted_result=numpy.array([[1*0.25+1*0.25+3*0.25+3*0.25],[1*0.25+1*0.25+3*.1],[0.],[0.]]) print("\nmap_asserted_result =",map_asserted_result) print("map =",map) assert (abs(map_asserted_result - map) < 10e-15).all() print("ray_length_mapsDset =", ray_length_mapsDset) assert (ray_length_mapsDset == [[1.],[.6],[0.],[0.]]).all() # Do the ray trace through the second dset: map, ray_length_mapsDset= ray_trace_amr(dset_2, ray_origins, ray_vectors, ray_lengths, op, info) map_asserted_result=numpy.array([[0.],[0.],[2*0.25+2*0.25+4*0.25+4*0.25],[2*0.25+2*0.25+4*0.25+4*0.125+5*0.125]]) print("\nmap_asserted_result =",map_asserted_result) print("map =",map) assert (abs(map_asserted_result - map) < 10e-15).all() # Do the ray trace through the second dset with level_max: map, ray_length_mapsDset= ray_trace_amr(dset_2, ray_origins, ray_vectors, ray_lengths, op, info, level_max = 2) map_asserted_result=numpy.array([[0.],[0.],[2*0.25+2*0.25+4*0.25+4*0.25],[2*0.25+2*0.25+4*0.25+4.25*0.25]]) print("\nmap_asserted_result =",map_asserted_result) print("map =",map) assert (abs(map_asserted_result - map) < 10e-15).all()