Let’s say I have the following data file:
Using this file, I can plot a Maxwell-Boltzmann functon and see how it changes as a function of s
with this code:
# using necessary packages
using LaTeXStrings, Markdown, DataFrames, Queryverse, Plots, Printf
df = load("data.csv", spacedelim=true, header_exists=true) |> DataFrame
m_e = 9.11E-28 # electron mass [g]
k = 1.38E-16 # boltzmann constant [erg*K^-1]
function Maxwellian(v_Max, T_Max)
```Maxwellian distribution function for particles moving in only one direction```
normal = (m_e/(2*pi*k*T_Max))^1.5
exp_term = exp(-((m_e).*v_Max.*v_Max)/(3*k*T_Max))
return normal*exp_term
end
nu = 1 # collisional frequency [s^-1]
v_pos = range(0, 1e10, step=1e8) # positive velocity [cm/s]
f_s_pos = [Maxwellian.(v_pos, df.T[1])] # because boundary density is high at left footpoint, assume f_N = f_M
for is in 1:length(df.s) # for positive velocities, integrate from 0 to s_max
local_F_s_pos = Maxwellian.(v_pos, df.T[is])
push!(f_s_pos, f_s_pos[is] - (nu./v_pos).*(f_s_pos[is] - local_F_s_pos)*(df.ds[is]))
end
anim = @animate for i in 1:length(df.s)
plot(v_pos, f_s_pos[i]; label=@sprintf("f_s at s = %.3e cm", df.s[i]))
xlabel!("velocity (cm/s)")
ylabel!("probability density (s/cm)")
title!("Space-Dependent Maxwellian")
ylims!(-1e-28, 2e-27)
end;
gif(anim, "Simple_BGK_Spatial_Discretization_Pos.gif"; fps=20)
Now, I want to try to create this animation again, but instead, we have negative values for velocity (v_neg
instead of v_pos
) and we have to step through s values from the max value of s
to the min value of s
. Here is my attempt:
nu = 1 # collisional frequency [s^-1]
v_neg = range(0, -1e10, step=-1e8) # negative velocity [cm/s]
f_s_neg = [Maxwellian.(v_neg, df.T[end])] # because boundary density is high at right footpoint, assume f_N = f_M
for is in reverse(eachindex(df.s)) # for negative velocities, integrate from s_max to 0
local_F_s_neg = Maxwellian.(v_neg, df.T[is])
push!(f_s_neg, f_s_neg[length(df.s)+1-is] - (nu./v_neg).*(f_s_neg[length(df.s)+1-is] - local_F_s_neg)*(df.ds[is]))
end
anim = @animate for i in 1:length(df.s)
plot(v_neg, f_s_neg[i]; label=@sprintf("f_s_neg at s = %.3e cm", df.s[i]))
xlabel!("velocity (cm/s)")
ylabel!("probability density (s/cm)")
title!("Space-Dependent Maxwellian")
ylims!(-1e-30, 2e-27)
end;
gif(anim, "Simple_BGK_Spatial_Discretization_Neg.gif"; fps=20)
I was expecting the function to look symmetric to the previous plot along the y axis but this is not the case. This might be a problem specific in my field (physics), but before investigating further, from a Julia programming perspective, are there any glaring issues with the way I set up the code for the negative velocity case that may be the problem?