def test_StructuredGrid_Slice(s0, V, dirpath): # 2D slice origin = [-0.5, -0.5, 0.5] # origin of slice vectors = [[1, 0, 0], [0, 1, 0] ] # directional tangent directions (scaled in StructuredGrid) dL = [2., 2.] # extent of slice in both directions N = [50, 50] # number of points in each direction sl = StructuredGrid(V, N, origin, vectors, dL) sl(s0) # probe once sl(s0) # probe once more sl.tovtk(0, filename=dirpath + "dump_scalar.vtk") sl.toh5(0, 1, dirpath + 'dump_scalar.h5', dtype='float64') sl2 = StructuredGrid(V, restart=dirpath + 'dump_scalar.h5') assert sl.dL[0] == sl2.dL[0] and sl.dL[1] == sl2.dL[1] assert abs(sl.arithmetic_mean() - sl2.arithmetic_mean()) < 1e-14
def test_StructuredGrid_Box(s0, V, dirpath): origin = [0.25, 0.25, 0.25] # origin of box vectors = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] # coordinate vectors (scaled in StructuredGrid) dL = [0.5, 0.5, 0.5] # extent of slice in both directions N = [9, 9, 6] # number of points in each direction sl = StructuredGrid(V, N, origin, vectors, dL) sl(s0) # probe once sl(s0) # probe once more sl.tovtk(0, filename=dirpath + "dump_scalar.vtk") sl.toh5(0, 1, dirpath + 'dump_scalar.h5', dtype='float64') sl2 = StructuredGrid(V, restart=dirpath + 'dump_scalar.h5') assert sl.dL[0] == sl2.dL[0] and sl.dL[1] == sl2.dL[1] and sl.dL[ 2] == sl2.dL[2] assert sl.arithmetic_mean() == sl2.arithmetic_mean()
def test_StructuredGrid_Box_vector_statistics_seg(x, V, dirpath): origin = [0.25, 0.25, 0.25] # origin of box vectors = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] # coordinate vectors (scaled in StructuredGrid) dL = [0.5, 0.5, 0.5] # extent of slice in both directions N = [9, 9, 6] # number of points in each direction sl = StructuredGrid(V, N, origin, vectors, dL, statistics=True) sl(x[0], x[0], x[0]) # probe once sl(x[0], x[0], x[0]) # probe once more sl.tovtk(0, filename=dirpath + "dump_stats.vtk") sl.toh5(0, 1, dirpath + 'dump_stats.h5', dtype='float64') sl2 = StructuredGrid(V, restart=dirpath + 'dump_stats.h5') assert sl.dL[0] == sl2.dL[0] and sl.dL[1] == sl2.dL[1] and sl.dL[ 2] == sl2.dL[2] assert round(sl.arithmetic_mean() - sl2.arithmetic_mean(), 7) == 0 assert sl.probes.number_of_evaluations( ) == sl2.probes.number_of_evaluations()
def test_StructuredGrid_Box_vector(v0, Vv, dirpath): origin = [0.25, 0.25, 0.25] # origin of box vectors = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] # coordinate vectors (scaled in StructuredGrid) dL = [0.5, 0.5, 0.5] # extent of slice in both directions N = [9, 9, 6] # number of points in each direction sl = StructuredGrid(Vv, N, origin, vectors, dL) sl(v0) # probe once sl(v0) # probe once more sl.tovtk(0, filename=dirpath+"dump_vector.vtk") sl.toh5(0, 1, dirpath+'dump_vector.h5', dtype='float64') sl2 = StructuredGrid(Vv, restart=dirpath+'dump_vector.h5') assert sl.dL[0] == sl2.dL[0] and sl.dL[1] == sl2.dL[1] and sl.dL[2] == sl2.dL[2] assert sl.arithmetic_mean() == sl2.arithmetic_mean()
def test_StructuredGrid_Slice_mixed(w0, W, dirpath): # 2D slice origin = [-0.5, -0.5, 0.5] # origin of slice vectors = [[1, 0, 0], [0, 1, 0] ] # directional tangent directions (scaled in StructuredGrid) dL = [2., 2.] # extent of slice in both directions N = [50, 50] # number of points in each direction sl = StructuredGrid(W, N, origin, vectors, dL) sl(w0) # probe once sl(w0) # probe once more sl.toh5(0, 1, dirpath + 'dump_mixed.h5', dtype='float64') sl2 = StructuredGrid(W, restart=dirpath + 'dump_mixed.h5') assert sl.dL[0] == sl2.dL[0] and sl.dL[1] == sl2.dL[1] assert round(sl.arithmetic_mean() - sl2.arithmetic_mean(), 7) == 0
def test_StructuredGrid_Slice(s0, V, dirpath): # 2D slice origin = [-0.5, -0.5, 0.5] # origin of slice vectors = [[1, 0, 0], [0, 1, 0]] # directional tangent directions (scaled in StructuredGrid) dL = [2., 2.] # extent of slice in both directions N = [50, 50] # number of points in each direction sl = StructuredGrid(V, N, origin, vectors, dL) sl(s0) # probe once sl(s0) # probe once more sl.tovtk(0, filename=dirpath+"dump_scalar.vtk") sl.toh5(0, 1, dirpath+'dump_scalar.h5', dtype='float64') sl2 = StructuredGrid(V, restart=dirpath+'dump_scalar.h5') assert sl.dL[0] == sl2.dL[0] and sl.dL[1] == sl2.dL[1] assert abs(sl.arithmetic_mean() - sl2.arithmetic_mean()) < 1e-14
def test_StructuredGrid_Box_vector_statistics_seg(x, V, dirpath): origin = [0.25, 0.25, 0.25] # origin of box vectors = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] # coordinate vectors (scaled in StructuredGrid) dL = [0.5, 0.5, 0.5] # extent of slice in both directions N = [9, 9, 6] # number of points in each direction sl = StructuredGrid(V, N, origin, vectors, dL, statistics=True) sl(x[0], x[0], x[0]) # probe once sl(x[0], x[0], x[0]) # probe once more sl.tovtk(0, filename=dirpath+"dump_stats.vtk") sl.toh5(0, 1, dirpath+'dump_stats.h5', dtype='float64') sl2 = StructuredGrid(V, restart=dirpath+'dump_stats.h5') assert sl.dL[0] == sl2.dL[0] and sl.dL[1] == sl2.dL[1] and sl.dL[2] == sl2.dL[2] assert round(sl.arithmetic_mean() - sl2.arithmetic_mean(), 7) == 0 assert sl.probes.number_of_evaluations() == sl2.probes.number_of_evaluations()
def test_StructuredGrid_Slice_mixed(w0, W, dirpath): # 2D slice origin = [-0.5, -0.5, 0.5] # origin of slice vectors = [[1, 0, 0], [0, 1, 0]] # directional tangent directions (scaled in StructuredGrid) dL = [2., 2.] # extent of slice in both directions N = [50, 50] # number of points in each direction sl = StructuredGrid(W, N, origin, vectors, dL) sl(w0) # probe once sl(w0) # probe once more sl.toh5(0, 1, dirpath+'dump_mixed.h5', dtype='float64') sl2 = StructuredGrid(W, restart=dirpath+'dump_mixed.h5') assert sl.dL[0] == sl2.dL[0] and sl.dL[1] == sl2.dL[1] assert round(sl.arithmetic_mean() - sl2.arithmetic_mean(), 7) == 0
# 3D box origin = [0.25, 0.25, 0.25] # origin of box vectors = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] # coordinate vectors (scaled in StructuredGrid) dL = [0.5, 0.5, 0.5] # extent of slice in both directions N = [9, 9, 3] # number of points in each direction ## 2D slice #origin = [-0.5, -0.5, 0.5] # origin of slice #vectors = [[1, 0, 0], [0, 1, 0]] # directional tangent directions (scaled in StructuredGrid) #dL = [2., 2.] # extent of slice in both directions #N = [50, 50] # number of points in each direction # Test scalar first sl = StructuredGrid(V, N, origin, vectors, dL) sl(s0) # probe once sl(s0) # probe once more sl.surf(0) # check first probe sl.tovtk(0, filename="dump_scalar.vtk") sl.toh5(0, 1, 'dump_scalar.h5') # sl.toh5(0, 2, 'dump_scalar.h5') # sl.toh5(0, 3, 'dump_scalar.h5') print sl.arithmetic_mean() # then vector sl2 = StructuredGrid(Vv, N, origin, vectors, dL) for i in range(5): sl2(v0) # probe a few times sl2.surf(3) # Check the fourth probe instance sl2.tovtk(3, filename="dump_vector.vtk")
w0 = interpolate(Expression(('x[0]', 'x[1]', 'x[2]', 'x[1]*x[2]')), W) # 3D box origin = [0.25, 0.25, 0.25] # origin of box vectors = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] # coordinate vectors (scaled in StructuredGrid) dL = [0.5, 0.5, 0.5] # extent of slice in both directions N = [9, 9, 3] # number of points in each direction ## 2D slice #origin = [-0.5, -0.5, 0.5] # origin of slice #vectors = [[1, 0, 0], [0, 1, 0]] # directional tangent directions (scaled in StructuredGrid) #dL = [2., 2.] # extent of slice in both directions #N = [50, 50] # number of points in each direction # Test scalar first sl = StructuredGrid(V, N, origin, vectors, dL) sl(s0) # probe once sl(s0) # probe once more sl.surf(0) # check first probe sl.tovtk(0, filename="dump_scalar.vtk") sl.toh5(0, 1, 'dump_scalar.h5') # sl.toh5(0, 2, 'dump_scalar.h5') # sl.toh5(0, 3, 'dump_scalar.h5') print sl.arithmetic_mean() # then vector sl2 = StructuredGrid(Vv, N, origin, vectors, dL) for i in range(5): sl2(v0) # probe a few times sl2.surf(3) # Check the fourth probe instance sl2.tovtk(3, filename="dump_vector.vtk")