def test_Li_Lj_coeffs(): ''' ''' threshold = 2e-9 N_LGL = 8 numerical_L3_xi_L4_eta_coeffs = wave_equation_2d.Li_Lj_coeffs(N_LGL)[:, :, 28] analytical_L3_xi_L4_eta_coeffs = af.np_to_af_array(np.array([\ [-129.727857225405, 27.1519390573796, 273.730966722451, - 57.2916772505673\ , - 178.518337439857, 37.3637484073274, 34.5152279428116, -7.22401021413973], \ [- 27.1519390573797, 5.68287960923199, 57.2916772505669, - 11.9911032408375,\ - 37.3637484073272, 7.82020331954072, 7.22401021413968, - 1.51197968793550 ],\ [273.730966722451, - 57.2916772505680,- 577.583286622990, 120.887730163458,\ 376.680831166362, - 78.8390033617950, - 72.8285112658236, 15.2429504489039],\ [57.2916772505673, - 11.9911032408381, - 120.887730163459, 25.3017073771593, \ 78.8390033617947, -16.5009417437969, - 15.2429504489039, 3.19033760747451],\ [- 178.518337439857, 37.3637484073272, 376.680831166362, - 78.8390033617954,\ - 245.658854496594, 51.4162061168383, 47.4963607700889, - 9.94095116237084],\ [- 37.3637484073274, 7.82020331954070, 78.8390033617948, - 16.5009417437970,\ - 51.4162061168385, 10.7613717277423, 9.94095116237085, -2.08063330348620],\ [34.5152279428116, - 7.22401021413972, - 72.8285112658235, 15.2429504489038,\ 47.4963607700889, - 9.94095116237085, - 9.18307744707700, 1.92201092760671],\ [7.22401021413973, - 1.51197968793550, -15.2429504489039, 3.19033760747451,\ 9.94095116237084, - 2.08063330348620, - 1.92201092760671, 0.402275383947182]])) af.display(numerical_L3_xi_L4_eta_coeffs - analytical_L3_xi_L4_eta_coeffs, 14) assert (af.max( af.abs(numerical_L3_xi_L4_eta_coeffs - analytical_L3_xi_L4_eta_coeffs)) <= threshold)
def initialize_f(q1, q2, p1, p2, p3, params): PETSc.Sys.Print("Initializing f") k = params.boltzmann_constant params.mu = 0. * q1 + params.initial_mu params.T = 0. * q1 + params.initial_temperature params.vel_drift_x = 0. * q1 params.vel_drift_y = 0. * q1 params.phi = 0. * q1 params.mu_ee = params.mu.copy() params.T_ee = params.T.copy() params.vel_drift_x = 0. * q1 + 0e-3 params.vel_drift_y = 0. * q1 + 0e-3 params.j_x = 0. * q1 params.j_y = 0. * q1 params.E_band = params.band_energy(p1, p2) params.vel_band = params.band_velocity(p1, p2) E_upper = params.E_band + params.charge[0] * params.phi if (params.p_space_grid == 'cartesian'): p_x = p1 p_y = p2 elif (params.p_space_grid == 'polar2D'): p_x = p1 * af.cos(p2) p_y = p1 * af.sin(p2) else: raise NotImplementedError('Unsupported coordinate system in p_space') # Initialize to zero f = 0 * q1 * p1 # Parameters to define a gaussian in space (representing a 2D ball) A = domain.N_p2 # Amplitude (required for normalization) sigma_x = 0.1 # Standard deviation in x sigma_y = 0.1 # Standard deviation in y x_0 = 0. # Center in x y_0 = 0. # Center in y # TODO: This will work with polar2D coordinates only for the moment # Particles lying on the ball need to have the same velocity (direction) #theta_0_index = (5*N_p2/8) - 1 # Direction of initial velocity theta_0_index = int(4 * domain.N_p2 / 8) # Direction of initial velocity print("Initial angle : ") af.display(p2[theta_0_index]) x, y = coords.get_cartesian_coords(q1, q2) f[theta_0_index, :, :] = A*af.exp(-( (x-x_0)**2/(2*sigma_x**2) + \ (y-y_0)**2/(2*sigma_y**2) ) ) af.eval(f) return (f)
####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. # # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## import arrayfire as af a = 10 * af.randu(6, 6) a3 = 10 * af.randu(5, 5, 3) dx, dy = af.gradient(a) af.display(dx) af.display(dy) af.display(af.resize(a, scale=0.5)) af.display(af.resize(a, odim0=8, odim1=8)) t = af.randu(3, 2) af.display(af.transform(a, t)) af.display(af.rotate(a, 3.14)) af.display(af.translate(a, 1, 1)) af.display(af.scale(a, 1.2, 1.2, 7, 7)) af.display(af.skew(a, 0.02, 0.02)) h = af.histogram(a, 3) af.display(h) af.display(af.hist_equal(a, h))
if __name__ == "__main__": if (len(sys.argv) > 1): af.set_device(int(sys.argv[1])) af.info() print("\n---- Intro to ArrayFire using signed(s32) arrays ----\n") h_A = array('i', (1, 2, 4, -1, 2, 0, 4, 2, 3)) h_B = array('i', (2, 3, 5, 6, 0, 10, -12, 0, 1)) A = af.Array(h_A, (3, 3)) B = af.Array(h_B, (3, 3)) print("\n---- Sub referencing and sub assignment\n") af.display(A) af.display(A[0, :]) af.display(A[:, 0]) A[0, 0] = 11 A[1] = 100 af.display(A) af.display(B) A[1, :] = B[2, :] af.display(A) print("\n---- Bitwise operations\n") af.display(A & B) af.display(A | B) af.display(A ^ B) print("\n---- Transpose\n")
####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. # # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## import arrayfire as af a = 10 * af.randu(6, 6) a3 = 10 * af.randu(5,5,3) dx,dy = af.gradient(a) af.display(dx) af.display(dy) af.display(af.resize(a, scale=0.5)) af.display(af.resize(a, odim0=8, odim1=8)) t = af.randu(3,2) af.display(af.transform(a, t)) af.display(af.rotate(a, 3.14)) af.display(af.translate(a, 1, 1)) af.display(af.scale(a, 1.2, 1.2, 7, 7)) af.display(af.skew(a, 0.02, 0.02)) h = af.histogram(a, 3) af.display(h) af.display(af.hist_equal(a, h))
#load input on device arr = af.np_to_af_array(input.T) print(center_of_mass(arr), ndimage.measurements.center_of_mass(input)) normalizer = af.sum(arr) t_dims = list(arr.dims()) mod_dims = [1] * len(t_dims) for dim in range(len(t_dims)): # swap mod_dims[dim] = t_dims[dim] t_dims[dim] = 1 print(mod_dims, t_dims) grid = af.iota(mod_dims[0], mod_dims[1], mod_dims[2], tile_dims=t_dims) af.display(grid) af.display(af.iota(mod_dims[0], mod_dims[1], mod_dims[2])) # results = [np.sum(input * grids[dir].astype(float)) / normalizer # for dir in range(input.ndim)] # # if numpy.isscalar(results[0]): # return tuple(results) # # return [tuple(v) for v in numpy.array(results).T] # d_type # multiplier = - 0.5 * alpha / pow(sgma[0], 2); # af::array # exponent = pow((range(data_dim, 0) - (data_dim[0] - 1) / 2.0).as(f64), 2)*multiplier;
#!/usr/bin/python ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. # # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## import arrayfire as af import array as host a = af.array([1, 2, 3]) af.display(a) print(a.elements(), a.type(), a.dims(), a.numdims()) print(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row()) print(a.is_complex(), a.is_real(), a.is_double(), a.is_single()) print(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool()) a = af.array(host.array('i', [4, 5, 6])) af.display(a) print(a.elements(), a.type(), a.dims(), a.numdims()) print(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row()) print(a.is_complex(), a.is_real(), a.is_double(), a.is_single()) print(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool()) a = af.array(host.array('l', [7, 8, 9] * 3), (3, 3)) af.display(a) print(a.elements(), a.type(), a.dims(), a.numdims()) print(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row())
#!/usr/bin/python ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. # # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## import arrayfire as af a = af.randu(10, 1) pos0 = af.randu(10) * 10 af.display(af.approx1(a, pos0)) a = af.randu(3, 3) pos0 = af.randu(3, 3) * 10 pos1 = af.randu(3, 3) * 10 af.display(af.approx2(a, pos0, pos1)) a = af.randu(8, 1) af.display(a) af.display(af.fft(a)) af.display(af.dft(a)) af.display(af.real(af.ifft(af.fft(a)))) af.display(af.real(af.idft(af.dft(a)))) a = af.randu(4, 4)
def print(arr, **kwargs): af.display(arr)
####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. # # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## import arrayfire as af a = af.randu(3, 3) print(af.sum(a), af.product(a), af.min(a), af.max(a), af.count(a), af.any_true(a), af.all_true(a)) af.display(af.sum(a, 0)) af.display(af.sum(a, 1)) af.display(af.product(a, 0)) af.display(af.product(a, 1)) af.display(af.min(a, 0)) af.display(af.min(a, 1)) af.display(af.max(a, 0)) af.display(af.max(a, 1)) af.display(af.count(a, 0)) af.display(af.count(a, 1)) af.display(af.any_true(a, 0))
#!/usr/bin/python ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. # # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## import arrayfire as af from arrayfire import parallel_range import array as host a = af.randu(5, 5) af.display(a) b = af.array(a) af.display(b) c = a.copy() af.display(c) af.display(a[0,0]) af.display(a[0]) af.display(a[:]) af.display(a[:,:]) af.display(a[0:3,]) af.display(a[-2:-1,-1]) af.display(a[0:5]) af.display(a[0:5:2]) idx = af.array(host.array('i', [0, 3, 2])) af.display(idx)
if __name__ == "__main__": if (len(sys.argv) > 1): af.set_device(int(sys.argv[1])) af.info() print("\n---- Intro to ArrayFire using signed(s32) arrays ----\n") h_A = array('i', ( 1, 2, 4, -1, 2, 0, 4, 2, 3)) h_B = array('i', ( 2, 3, 5, 6, 0, 10,-12, 0, 1)) A = af.Array(h_A, (3,3)) B = af.Array(h_B, (3,3)) print("\n---- Sub referencing and sub assignment\n") af.display(A) af.display(A[0,:]) af.display(A[:,0]) A[0,0] = 11 A[1] = 100 af.display(A) af.display(B) A[1,:] = B[2,:] af.display(A) print("\n---- Bitwise operations\n") af.display(A & B) af.display(A | B) af.display(A ^ B) print("\n---- Transpose\n")
#!/usr/bin/python ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. # # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## import arrayfire as af a = af.randu(3,3,dtype=af.u32) b = af.constant(4, 3, 3, dtype=af.u32) af.display(a) af.display(b) c = a + b d = a d += b af.display(c) af.display(d) af.display(a + 2) af.display(3 + a) c = a - b d = a d -= b
#!/usr/bin/python ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. # # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## import arrayfire as af import array as host a = af.array([1, 2, 3]) af.display(a) print(a.elements(), a.type(), a.dims(), a.numdims()) print(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row()) print(a.is_complex(), a.is_real(), a.is_double(), a.is_single()) print(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool()) a = af.array(host.array("i", [4, 5, 6])) af.display(a) print(a.elements(), a.type(), a.dims(), a.numdims()) print(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row()) print(a.is_complex(), a.is_real(), a.is_double(), a.is_single()) print(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool()) a = af.array(host.array("l", [7, 8, 9] * 3), (3, 3)) af.display(a) print(a.elements(), a.type(), a.dims(), a.numdims())
#!/usr/bin/python ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. # # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## import arrayfire as af from arrayfire import parallel_range import array as host a = af.randu(5, 5) af.display(a) b = af.array(a) af.display(b) c = a.copy() af.display(c) af.display(a[0, 0]) af.display(a[0]) af.display(a[:]) af.display(a[:, :]) af.display(a[0:3, ]) af.display(a[-2:-1, -1]) af.display(a[0:5]) af.display(a[0:5:2]) idx = af.array(host.array('i', [0, 3, 2])) af.display(idx)
def initialize_f(q1, q2, p1, p2, p3, params): PETSc.Sys.Print("Initializing f") k = params.boltzmann_constant params.mu = 0. * q1 + params.initial_mu params.T = 0. * q1 + params.initial_temperature params.vel_drift_x = 0. * q1 params.vel_drift_y = 0. * q1 params.phi = 0. * q1 params.mu_ee = params.mu.copy() params.T_ee = params.T.copy() params.vel_drift_x = 0. * q1 + 0e-3 params.vel_drift_y = 0. * q1 + 0e-3 params.j_x = 0. * q1 params.j_y = 0. * q1 params.E_band = params.band_energy(p1, p2) params.vel_band = params.band_velocity(p1, p2) E_upper = params.E_band + params.charge[0] * params.phi if (params.p_space_grid == 'cartesian'): p_x = p1 p_y = p2 elif (params.p_space_grid == 'polar2D'): p_x = p1 * af.cos(p2) p_y = p1 * af.sin(p2) else: raise NotImplementedError('Unsupported coordinate system in p_space') # Initialize to zero f = 0 * q1 * p1 # Parameters to define a gaussian in space (representing a 2D ball) A = domain.N_p2 # Amplitude (required for normalization) sigma_x = 0.05 # Standard deviation in x sigma_y = 0.05 # Standard deviation in y x_0 = 0. # Center in x y_0 = 0. # Center in y # TODO: This will work with polar2D p-space only for the moment # Particles lying on the ball need to have the same velocity (direction) #theta_0_index = (5*N_p2/8) - 1 # Direction of initial velocity theta_0_index = int(5 * domain.N_p2 / 8) # Direction of initial velocity print("Initial angle : ") af.display(p2[theta_0_index]) # Load shift indices for all 4 boundaries into params. Required to perform # mirroring operations along boundaries at arbitrary angles. params.shift_indices_left, params.shift_indices_right, \ params.shift_indices_bottom, params.shift_indices_top = \ compute_shift_indices(q1, q2, p1, p2, p3, params) x, y = coords.get_cartesian_coords(q1, q2) # f[theta_0_index, :, :] = A + A*af.exp(-( (x-x_0)**2/(2*sigma_x**2) + \ # (y-y_0)**2/(2*sigma_y**2) # ) # ) f = (1. / (af.exp( (E_upper - params.vel_drift_x * p_x - params.vel_drift_y * p_y - params.mu) / (k * params.T)) + 1.)) af.eval(f) return (f)
#!/usr/bin/python ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. # # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## import arrayfire as af a = af.randu(5, 5) b = af.randu(5, 5) af.display(af.matmul(a, b)) af.display(af.matmul(a, b, af.AF_MAT_TRANS)) af.display(af.matmul(a, b, af.AF_MAT_NONE, af.AF_MAT_TRANS)) b = af.randu(5, 1) af.display(af.dot(b, b))
#!/usr/bin/python ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. # # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## import arrayfire as af a = af.randu(3, 3, dtype=af.u32) b = af.constant(4, 3, 3, dtype=af.u32) af.display(a) af.display(b) c = a + b d = a d += b af.display(c) af.display(d) af.display(a + 2) af.display(3 + a) c = a - b d = a d -= b af.display(c)
# Copyright (c) 2015, ArrayFire # All rights reserved. # # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## import arrayfire as af a = af.randu(3, 3) print(af.sum(a), af.product(a), af.min(a), af.max(a), af.count(a), af.any_true(a), af.all_true(a)) af.display(af.sum(a, 0)) af.display(af.sum(a, 1)) af.display(af.product(a, 0)) af.display(af.product(a, 1)) af.display(af.min(a, 0)) af.display(af.min(a, 1)) af.display(af.max(a, 0)) af.display(af.max(a, 1)) af.display(af.count(a, 0)) af.display(af.count(a, 1)) af.display(af.any_true(a, 0))
#!/usr/bin/python ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. # # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## import arrayfire as af # Display backend information af.info() # Generate a uniform random array with a size of 5 elements a = af.randu(5, 1) # Print a and its minimum value af.display(a) # Print min and max values of a print("Minimum, Maximum: ", af.min(a), af.max(a))
#!/usr/bin/python ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. # # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## import arrayfire as af a = af.randu(5, 5) l, u, p = af.lu(a) af.display(l) af.display(u) af.display(p) p = af.lu_inplace(a, "full") af.display(a) af.display(p) a = af.randu(5, 3) q, r, t = af.qr(a) af.display(q) af.display(r) af.display(t)
#!/usr/bin/python ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. # # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## import arrayfire as af af.display(af.constant(100, 3,3, dtype=af.f32)) af.display(af.constant(25, 3,3, dtype=af.c32)) af.display(af.constant(2**50, 3,3, dtype=af.s64)) af.display(af.constant(2+3j, 3,3)) af.display(af.constant(3+5j, 3,3, dtype=af.c32)) af.display(af.range(3, 3)) af.display(af.iota(3, 3, tile_dims=(2,2))) af.display(af.randu(3, 3, 1, 2)) af.display(af.randu(3, 3, 1, 2, af.b8)) af.display(af.randu(3, 3, dtype=af.c32)) af.display(af.randn(3, 3, 1, 2)) af.display(af.randn(3, 3, dtype=af.c32)) af.set_seed(1024) assert(af.get_seed() == 1024)
def display(array: ndarray): if isinstance(array, ndarray): af.display(array._af_array) else: print(array)
def initialize_f(q1, q2, p1, p2, p3, params): PETSc.Sys.Print("Initializing f") k = params.boltzmann_constant params.mu = 0. * q1 + params.initial_mu params.T = 0. * q1 + params.initial_temperature params.vel_drift_x = 0. * q1 params.vel_drift_y = 0. * q1 params.mu_ee = params.mu.copy() params.T_ee = params.T.copy() params.vel_drift_x = 0. * q1 + 0e-3 params.vel_drift_y = 0. * q1 + 0e-3 params.j_x = 0. * q1 params.j_y = 0. * q1 params.p_x, params.p_y = params.get_p_x_and_p_y(p1, p2) params.E_band = params.band_energy(p1, p2) params.vel_band = params.band_velocity(p1, p2) # TODO: Injecting get_cartesian_coords into params to avoid circular dependency params.get_cartesian_coords = coords.get_cartesian_coords # Load shift indices for all 4 boundaries into params. Required to perform # mirroring operations along boundaries at arbitrary angles. params.shift_indices_left, params.shift_indices_right, \ params.shift_indices_bottom, params.shift_indices_top = \ compute_shift_indices(q1, q2, p1, p2, p3, params) params.x, params.y = coords.get_cartesian_coords( q1, q2, q1_start_local_left=params.q1_start_local_left, q2_start_local_bottom=params.q2_start_local_bottom) # TODO : Testing : Dump left, bottom, right, top faces also d_q1 = (q1[0, 0, 1, 0] - q1[0, 0, 0, 0]).scalar() d_q2 = (q2[0, 0, 0, 1] - q2[0, 0, 0, 0]).scalar() q1_left_faces = q1 - 0.5 * d_q1 q2_bottom_faces = q2 - 0.5 * d_q2 q1_right_faces = q1 + 0.5 * d_q1 q2_top_faces = q2 + 0.5 * d_q2 params.x_top_center, params.y_top_center = coords.get_cartesian_coords( q1, q2_top_faces, q1_start_local_left=params.q1_start_local_left, q2_start_local_bottom=params.q2_start_local_bottom) params.x_right_center, params.y_right_center = coords.get_cartesian_coords( q1_right_faces, q2, q1_start_local_left=params.q1_start_local_left, q2_start_local_bottom=params.q2_start_local_bottom) params.q1 = q1 params.q2 = q2 [[params.dx_dq1, params.dx_dq2], [params.dy_dq1, params.dy_dq2] ] = jacobian_dx_dq(q1, q2, q1_start_local_left=params.q1_start_local_left, q2_start_local_bottom=params.q2_start_local_bottom) [[params.dq1_dx, params.dq1_dy], [params.dq2_dx, params.dq2_dy] ] = jacobian_dq_dx(q1, q2, q1_start_local_left=params.q1_start_local_left, q2_start_local_bottom=params.q2_start_local_bottom) params.sqrt_det_g = sqrt_det_g( q1, q2, q1_start_local_left=params.q1_start_local_left, q2_start_local_bottom=params.q2_start_local_bottom) # Calculation of integral measure # Evaluating velocity space resolution for each species: dp1 = [] dp2 = [] dp3 = [] N_p1 = domain.N_p1 N_p2 = domain.N_p2 N_p3 = domain.N_p3 p1_start = domain.p1_start p1_end = domain.p1_end p2_start = domain.p2_start p2_end = domain.p2_end p3_start = domain.p3_start p3_end = domain.p3_end N_species = len(params.mass) for i in range(N_species): dp1.append((p1_end[i] - p1_start[i]) / N_p1) dp2.append((p2_end[i] - p2_start[i]) / N_p2) dp3.append((p3_end[i] - p3_start[i]) / N_p3) theta = af.atan(params.p_y / params.p_x) p_f = params.fermi_momentum_magnitude(theta) if (params.p_space_grid == 'cartesian'): dp_x = dp1[0] dp_y = dp2[0] dp_z = dp3[0] params.integral_measure = \ (4./(2.*np.pi*params.h_bar)**2) * dp_z * dp_y * dp_x elif (params.p_space_grid == 'polar2D'): # In polar2D coordinates, p1 = radius and p2 = theta # Integral : \int delta(r - r_F) F(r, theta) r dr dtheta r = p1 theta = p2 dp_r = dp1[0] dp_theta = dp2[0] if (params.zero_temperature): # Assumption : F(r, theta) = delta(r-r_F)*F(theta) params.integral_measure = \ (4./(2.*np.pi*params.h_bar)**2) * p_f * dp_theta else: params.integral_measure = \ (4./(2.*np.pi*params.h_bar)**2) * r * dp_r * dp_theta else: raise NotImplementedError('Unsupported coordinate system in p_space') # Initialize to zero f = 0 * q1 * p1 # Parameters to define a gaussian in space (representing a 2D ball) A = domain.N_p2 # Amplitude (required for normalization) sigma_x = 0.05 # Standard deviation in x sigma_y = 0.05 # Standard deviation in y x_0 = -0.7 # Center in x y_0 = 0. # Center in y # TODO: This will work with polar2D p-space only for the moment # Particles lying on the ball need to have the same velocity (direction) #theta_0_index = (5*N_p2/8) - 1 # Direction of initial velocity theta_0_index = int(4 * domain.N_p2 / 8) # Direction of initial velocity print("Initial angle : ") af.display(p2[theta_0_index]) # f[theta_0_index, :, :] = A*af.exp(-( (params.x-x_0)**2/(2*sigma_x**2) + \ # (params.y-y_0)**2/(2*sigma_y**2) # ) # ) + A*af.exp(-( (params.x-x_0)**2/(2*sigma_x**2) + \ # (params.y-(-0.5))**2/(2*sigma_y**2) # ) # ) + A*af.exp(-( (params.x-x_0)**2/(2*sigma_x**2) + \ # (params.y-0.5)**2/(2*sigma_y**2) # ) # ) f[theta_0_index, :, :] = A * af.exp(-((params.x - x_0)**2 / (2 * sigma_x**2))) af.eval(f) return (f)
####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. # # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## import arrayfire as af a = af.randu(5, 5) b = af.randu(5, 5) w = af.randu(5, 1) af.display(af.mean(a, dim=0)) af.display(af.mean(a, weights=w, dim=0)) print(af.mean(a)) print(af.mean(a, weights=w)) af.display(af.var(a, dim=0)) af.display(af.var(a, isbiased=True, dim=0)) af.display(af.var(a, weights=w, dim=0)) print(af.var(a)) print(af.var(a, isbiased=True)) print(af.var(a, weights=w)) af.display(af.stdev(a, dim=0)) print(af.stdev(a)) af.display(af.var(a, dim=0))
# All rights reserved. # # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## import arrayfire as af try: # Display backend information af.info() print("Create a 5-by-3 matrix of random floats on the GPU\n") A = af.randu(5, 3, 1, 1, af.Dtype.f32) af.display(A) print("Element-wise arithmetic\n") B = af.sin(A) + 1.5 af.display(B) print("Negate the first three elements of second column\n") B[0:3, 1] = B[0:3, 1] * -1 af.display(B) print("Fourier transform the result\n"); C = af.fft(B); af.display(C); print("Grab last row\n"); c = C[-1,:];