-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ion braginskii fluid #263
Ion braginskii fluid #263
Changes from all commits
e6676ef
53a673c
6f6df74
e92dc5c
f92f20f
a0e2b20
1dbf661
77a30c1
3b9bc66
1d8b559
bb64609
77cce1a
18cd33e
9a1e30a
0e28693
5ef19bd
4213c52
6fc4c76
14e510d
701ab84
0e6d395
b2b001d
9d92ca2
fab3f8a
8e5ecd9
78bf27e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -779,7 +779,8 @@ function reload_evolving_fields!(pdf, moments, fields, boundary_distributions, | |
length(moments.ion.external_source_controller_integral) == 1 | ||
moments.ion.external_source_controller_integral .= | ||
load_slice(dynamic, "external_source_controller_integral", time_index) | ||
elseif length(moments.ion.external_source_controller_integral) > 1 | ||
elseif size(moments.ion.external_source_controller_integral)[1] > 1 || | ||
size(moments.ion.external_source_controller_integral)[2] > 1 | ||
moments.ion.external_source_controller_integral .= | ||
reload_moment("external_source_controller_integral", dynamic, | ||
time_index, r, z, r_range, z_range, restart_r, | ||
|
@@ -4145,6 +4146,88 @@ function get_variable(run_info, variable_name; normalize_advection_speed_shape=t | |
if variable_name == "temperature" | ||
vth = get_variable(run_info, "thermal_speed"; kwargs...) | ||
variable = vth.^2 | ||
elseif variable_name == "dT_dz" | ||
T = get_variable(run_info, "temperature"; kwargs...) | ||
variable = similar(T) | ||
if :iz ∈ keys(kwargs) && kwargs[:iz] !== nothing | ||
error("Cannot take z-derivative when iz!==nothing") | ||
end | ||
if :ir ∈ keys(kwargs) && isa(kwargs[:ir], mk_int) | ||
for it ∈ 1:size(variable, 3) | ||
@views derivative!(variable[:,:,it], T[:,:,it], run_info.z, run_info.z_spectral) | ||
end | ||
else | ||
for it ∈ 1:size(variable, 4), ir ∈ 1:run_info.r.n | ||
@views derivative!(variable[:,:,ir,it], T[:,:,ir,it], run_info.z, run_info.z_spectral) | ||
end | ||
end | ||
elseif variable_name == "dn_dz" | ||
n = get_variable(run_info, "density"; kwargs...) | ||
variable = similar(n) | ||
if :iz ∈ keys(kwargs) && kwargs[:iz] !== nothing | ||
error("Cannot take z-derivative when iz!==nothing") | ||
end | ||
if :ir ∈ keys(kwargs) && isa(kwargs[:ir], mk_int) | ||
for it ∈ 1:size(variable, 3) | ||
@views derivative!(variable[:,:,it], n[:,:,it], run_info.z, run_info.z_spectral) | ||
end | ||
else | ||
for it ∈ 1:size(variable, 4), ir ∈ 1:run_info.r.n | ||
@views derivative!(variable[:,:,ir,it], n[:,:,ir,it], run_info.z, run_info.z_spectral) | ||
end | ||
end | ||
elseif variable_name == "dupar_dz" | ||
upar = get_variable(run_info, "parallel_flow"; kwargs...) | ||
variable = similar(upar) | ||
if :iz ∈ keys(kwargs) && kwargs[:iz] !== nothing | ||
error("Cannot take z-derivative when iz!==nothing") | ||
end | ||
if :ir ∈ keys(kwargs) && isa(kwargs[:ir], mk_int) | ||
for it ∈ 1:size(variable, 3) | ||
@views derivative!(variable[:,:,it], upar[:,:,it], run_info.z, run_info.z_spectral) | ||
end | ||
else | ||
for it ∈ 1:size(variable, 4), ir ∈ 1:run_info.r.n | ||
@views derivative!(variable[:,:,ir,it], upar[:,:,ir,it], run_info.z, run_info.z_spectral) | ||
end | ||
end | ||
elseif variable_name == "mfp" | ||
vth = get_variable(run_info, "thermal_speed"; kwargs...) | ||
nu_ii = get_variable(run_info, "collision_frequency_ii"; kwargs...) | ||
variable = vth ./ nu_ii | ||
elseif variable_name == "L_T" | ||
dT_dz = get_variable(run_info, "dT_dz"; kwargs...) | ||
temp = get_variable(run_info, "temperature"; kwargs...) | ||
# We define gradient lengthscale of T as LT^-1 = dln(T)/dz (ignore negative sign | ||
# tokamak convention as we're only concerned with comparing magnitudes) | ||
variable = abs.(temp .* dT_dz.^(-1)) | ||
# flat points in temperature have diverging LT, so ignore those with NaN | ||
# using a hard coded 10.0 tolerance for now | ||
variable[variable .> 10.0] .= NaN | ||
elseif variable_name == "L_n" | ||
dn_dz = get_variable(run_info, "dn_dz"; kwargs...) | ||
n = get_variable(run_info, "density"; kwargs...) | ||
# We define gradient lengthscale of n as Ln^-1 = dln(n)/dz (ignore negative sign | ||
# tokamak convention as we're only concerned with comparing magnitudes) | ||
variable = abs.(n .* dn_dz.^(-1)) | ||
# flat points in temperature have diverging Ln, so ignore those with NaN | ||
# using a hard coded 10.0 tolerance for now | ||
variable[variable .> 10.0] .= NaN | ||
elseif variable_name == "L_upar" | ||
dupar_dz = get_variable(run_info, "dupar_dz"; kwargs...) | ||
upar = get_variable(run_info, "parallel_flow"; kwargs...) | ||
# We define gradient lengthscale of upar as Lupar^-1 = dln(upar)/dz (ignore negative sign | ||
# tokamak convention as we're only concerned with comparing magnitudes) | ||
variable = abs.(upar .* dupar_dz.^(-1)) | ||
# flat points in temperature have diverging Lupar, so ignore those with NaN | ||
# using a hard coded 10.0 tolerance for now | ||
variable[variable .> 10.0] .= NaN | ||
elseif variable_name == "braginskii_heat_flux" | ||
n = get_variable(run_info, "density"; kwargs...) | ||
vth = get_variable(run_info, "thermal_speed"; kwargs...) | ||
dT_dz = get_variable(run_info, "dT_dz"; kwargs...) | ||
nu_ii = get_variable(run_info, "collision_frequency_ii"; kwargs...) | ||
variable = @. -(1/2) * 5/4 * n * vth^2 * dT_dz / nu_ii | ||
Comment on lines
+4226
to
+4230
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we introduce a function for the inside of the loop in function _calculate_ion_qpar_from_braginskii_inner(density, vth, nu_ii, dT_dz)
return @. -(1/2) * 5/4 * density[iz,ir] * vth[iz,ir]^2 /nu_ii * dT_dz[iz,ir,1]
end The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds great to me. There are a few other cases of re calculating things in the ‘load_data.jl’ file, so there might be a nicer way to revamp all of that function? |
||
elseif variable_name == "collision_frequency_ii" | ||
n = get_variable(run_info, "density"; kwargs...) | ||
vth = get_variable(run_info, "thermal_speed"; kwargs...) | ||
|
@@ -4256,7 +4339,7 @@ function get_variable(run_info, variable_name; normalize_advection_speed_shape=t | |
n = get_variable(run_info, "density"; kwargs...) | ||
|
||
# Note factor of 0.5 in front of qpar because the definition of qpar (see e.g. | ||
# `update_qpar_species!()`) is unconventional (i.e. missing a factor of 0.5). | ||
# `update_ion_qpar_species!()`) is unconventional (i.e. missing a factor of 0.5). | ||
# Factor of 3/2 in front of 1/2*n*vth^2*upar because this in 1V - would be 5/2 | ||
# for 2V/3V cases. | ||
variable = @. 0.5*qpar + 0.75*n*vth^2*upar + 0.5*n*upar^3 | ||
|
@@ -4271,7 +4354,7 @@ function get_variable(run_info, variable_name; normalize_advection_speed_shape=t | |
n = get_variable(run_info, "density_neutral"; kwargs...) | ||
|
||
# Note factor of 0.5 in front of qpar because the definition of qpar (see e.g. | ||
# `update_qpar_species!()`) is unconventional (i.e. missing a factor of 0.5). | ||
# `update_ion_qpar_species!()`) is unconventional (i.e. missing a factor of 0.5). | ||
# Factor of 3/2 in front of 1/2*n*vth^2*upar because this in 1V - would be 5/2 | ||
# for 2V/3V cases. | ||
variable = @. 0.5*qpar + 0.75*n*vth^2*upar + 0.5*n*upar^3 | ||
|
@@ -4343,9 +4426,6 @@ function get_variable(run_info, variable_name; normalize_advection_speed_shape=t | |
density = get_variable(run_info, "density") | ||
upar = get_variable(run_info, "parallel_flow") | ||
ppar = get_variable(run_info, "parallel_pressure") | ||
density_neutral = get_variable(run_info, "density_neutral") | ||
uz_neutral = get_variable(run_info, "uz_neutral") | ||
pz_neutral = get_variable(run_info, "pz_neutral") | ||
vth = get_variable(run_info, "thermal_speed") | ||
dupar_dz = get_z_derivative(run_info, "parallel_flow") | ||
dppar_dz = get_z_derivative(run_info, "parallel_pressure") | ||
|
@@ -4395,6 +4475,15 @@ function get_variable(run_info, variable_name; normalize_advection_speed_shape=t | |
setup_loop_ranges!(0, 1; s=nspecies, sn=run_info.n_neutral_species, r=nr, z=nz, | ||
vperp=nvperp, vpa=nvpa, vzeta=run_info.vzeta.n, | ||
vr=run_info.vr.n, vz=run_info.vz.n) | ||
|
||
# Use neutrals for fvec calculation in moment_kinetic version only when | ||
# n_neutrals != 0 | ||
if run_info.n_neutral_species != 0 | ||
density_neutral = get_variable(run_info, "density_neutral") | ||
uz_neutral = get_variable(run_info, "uz_neutral") | ||
pz_neutral = get_variable(run_info, "pz_neutral") | ||
end | ||
|
||
for it ∈ 1:nt | ||
begin_serial_region() | ||
# Only need some struct with a 'speed' variable | ||
|
@@ -4413,12 +4502,18 @@ function get_variable(run_info, variable_name; normalize_advection_speed_shape=t | |
evolve_density=run_info.evolve_density, | ||
evolve_upar=run_info.evolve_upar, | ||
evolve_ppar=run_info.evolve_ppar) | ||
@views fvec = (density=density[:,:,:,it], | ||
upar=upar[:,:,:,it], | ||
ppar=ppar[:,:,:,it], | ||
density_neutral=density_neutral[:,:,:,it], | ||
uz_neutral=uz_neutral[:,:,:,it], | ||
pz_neutral=pz_neutral[:,:,:,it]) | ||
if run_info.n_neutral_species != 0 | ||
@views fvec = (density=density[:,:,:,it], | ||
upar=upar[:,:,:,it], | ||
ppar=ppar[:,:,:,it], | ||
density_neutral=density_neutral[:,:,:,it], | ||
uz_neutral=uz_neutral[:,:,:,it], | ||
pz_neutral=pz_neutral[:,:,:,it]) | ||
else | ||
@views fvec = (density=density[:,:,:,it], | ||
upar=upar[:,:,:,it], | ||
ppar=ppar[:,:,:,it]) | ||
end | ||
@views update_speed_vpa!(advect, fields, fvec, moments, run_info.vpa, | ||
run_info.vperp, run_info.z, run_info.r, | ||
run_info.composition, run_info.collisions, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one, and also "dn_dz" and "dupar_dz", need a loop over species (in case there are multiple ion species). That would lead to 4 different cases depending on if
is
and/orir
is an integer. I think the following would be better, although the use ofCartesianIndices
is a bit more cryptic than I'd like@LucasMontoya4 what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like a pretty nice solution to me! Sorry about that, I was being lazy and avoiding writing multiple species functionality…