Skip to content

Commit

Permalink
Minor clean up in the CI test
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgrote committed Nov 8, 2023
1 parent 13e7dc3 commit 6f01eab
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 42 deletions.
57 changes: 29 additions & 28 deletions Examples/Tests/initial_distribution/analysis_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# 5 denotes maxwell-juttner distribution w/ spatially varying temperature
# 6 denotes maxwell-boltzmann distribution w/ constant velocity
# 7 denotes maxwell-boltzmann distribution w/ spatially-varying velocity
# 8 denotes uniform distribution
# 9 denotes gaussian_parser distribution w/ spatially-varying mean and thermal velocity
# The distribution is obtained through reduced diagnostic ParticleHistogram.

import os
Expand Down Expand Up @@ -261,34 +263,6 @@
assert(f7_error < tolerance)


#============================================
# Gaussian with parser mean and standard deviation
#============================================

# load data
bin_value_ux, bin_data_ux = read_reduced_diags_histogram("h9x.txt")[2:]
bin_value_uy, bin_data_uy = read_reduced_diags_histogram("h9y.txt")[2:]
bin_value_uz, bin_data_uz = read_reduced_diags_histogram("h9z.txt")[2:]

def Gaussian(mean, sigma, u):
V = 8.0 # volume in m^3
n = 1.0e21 # number density in 1/m^3
return (n*V/(sigma*np.sqrt(2.*np.pi)))*np.exp(-(u - mean)**2/(2.*sigma**2))

du = 2./50
f_ux = Gaussian(0.1 , 0.2 , bin_value_ux)*du
f_uy = Gaussian(0.12, 0.21, bin_value_uy)*du
f_uz = Gaussian(0.14, 0.22, bin_value_uz)*du

f9_error = np.sum(np.abs(f_ux - bin_data_ux)/f_ux.max()
+np.abs(f_uy - bin_data_uy)/f_ux.max()
+np.abs(f_uz - bin_data_uz)/f_uz.max()) / bin_value_ux.size

print('gaussian_parse_momentum_function velocity difference:', f9_error)

assert(f9_error < tolerance)


#============================================
# Cuboid distribution in momentum space
#============================================
Expand Down Expand Up @@ -368,6 +342,33 @@ def check_validity_uniform(bins, histogram, u_min, u_max, Ntrials=1000):
check_validity_uniform(bin_value_y, h8y[timestep] / N0, uy_min, uy_max)
check_validity_uniform(bin_value_z, h8z[timestep] / N0, uz_min, uz_max)

#=================================================
# Gaussian with parser mean and standard deviation
#=================================================

# load data
bin_value_ux, bin_data_ux = read_reduced_diags_histogram("h9x.txt")[2:]
bin_value_uy, bin_data_uy = read_reduced_diags_histogram("h9y.txt")[2:]
bin_value_uz, bin_data_uz = read_reduced_diags_histogram("h9z.txt")[2:]

def Gaussian(mean, sigma, u):
V = 8.0 # volume in m^3
n = 1.0e21 # number density in 1/m^3
return (n*V/(sigma*np.sqrt(2.*np.pi)))*np.exp(-(u - mean)**2/(2.*sigma**2))

du = 2./50
f_ux = Gaussian(0.1 , 0.2 , bin_value_ux)*du
f_uy = Gaussian(0.12, 0.21, bin_value_uy)*du
f_uz = Gaussian(0.14, 0.22, bin_value_uz)*du

f9_error = np.sum(np.abs(f_ux - bin_data_ux)/f_ux.max()
+np.abs(f_uy - bin_data_uy)/f_ux.max()
+np.abs(f_uz - bin_data_uz)/f_uz.max()) / bin_value_ux.size

print('gaussian_parse_momentum_function velocity difference:', f9_error)

assert(f9_error < tolerance)


test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, filename)
28 changes: 14 additions & 14 deletions Examples/Tests/initial_distribution/inputs
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,6 @@ velocity_parser.beta_distribution_type = "parser"
velocity_parser.beta_function(x,y,z) = "-0.2 + 0.4 * heaviside(z,0)"
velocity_parser.bulk_vel_dir = -y

gaussian_parser.charge = -q_e
gaussian_parser.mass = m_e
gaussian_parser.injection_style = "NRandomPerCell"
gaussian_parser.num_particles_per_cell = 1000
gaussian_parser.profile = constant
gaussian_parser.density = 1.0e21
gaussian_parser.momentum_distribution_type = "gaussian_parse_momentum_function"
gaussian_parser.momentum_function_ux_m(x,y,z) = 0.1*z
gaussian_parser.momentum_function_uy_m(x,y,z) = 0.12*z
gaussian_parser.momentum_function_uz_m(x,y,z) = 0.14*z
gaussian_parser.momentum_function_ux_th(x,y,z) = 0.2*z
gaussian_parser.momentum_function_uy_th(x,y,z) = 0.21*z
gaussian_parser.momentum_function_uz_th(x,y,z) = 0.22*z

uniform.charge = q_e
uniform.mass = m_e
uniform.injection_style = "NRandomPerCell"
Expand All @@ -147,6 +133,20 @@ uniform.uy_max = 0.1
uniform.uz_min = 10
uniform.uz_max = 11.2

gaussian_parser.charge = -q_e
gaussian_parser.mass = m_e
gaussian_parser.injection_style = "NRandomPerCell"
gaussian_parser.num_particles_per_cell = 1000
gaussian_parser.profile = constant
gaussian_parser.density = 1.0e21
gaussian_parser.momentum_distribution_type = "gaussian_parse_momentum_function"
gaussian_parser.momentum_function_ux_m(x,y,z) = 0.1*z
gaussian_parser.momentum_function_uy_m(x,y,z) = 0.12*z
gaussian_parser.momentum_function_uz_m(x,y,z) = 0.14*z
gaussian_parser.momentum_function_ux_th(x,y,z) = 0.2*z
gaussian_parser.momentum_function_uy_th(x,y,z) = 0.21*z
gaussian_parser.momentum_function_uz_th(x,y,z) = 0.22*z

#################################
########## DIAGNOSTIC ###########
#################################
Expand Down

0 comments on commit 6f01eab

Please sign in to comment.