Skip to content
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

Feature gyroaverages #187

Merged
merged 34 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5ef537d
Addition of new module to take a gyroaverage of a spatial field, incl…
mrhardman Feb 28, 2024
25c4ce4
Change behaviour of gyroaverage to set to zero any <field> where the …
mrhardman Feb 29, 2024
ebb08f9
Correct position of bzeta in z and r positions taken by particles in …
mrhardman Feb 29, 2024
44a1832
Make phase of gyroangle consistent with notes.
mrhardman Feb 29, 2024
e6f6ccf
Extend gyroaverge operator to support periodic boundary conditions.
mrhardman Mar 2, 2024
d0102f9
Introduce test of gyroaverage based on the exact gyroaverage of a per…
mrhardman Mar 3, 2024
4c01327
Incomplete experimental changes adding the gyroaverage to the ion spe…
mrhardman Mar 3, 2024
6578af7
Refactored calculation of moments so that all diagnostic and derived …
mrhardman Mar 6, 2024
0e2890e
Update test script to also test the gyroaverage function used to appl…
mrhardman Mar 6, 2024
71222b1
Initial check-in test for gyroaverages for periodic test functions. C…
mrhardman Mar 6, 2024
743d10e
Add print statement for test output
mrhardman Mar 6, 2024
21a9bd9
Refactor order of initialisation calls to permit shared-memory MPI fu…
mrhardman Mar 6, 2024
509064d
Correct bug in choice of dummy array.
mrhardman Mar 12, 2024
6bb7761
Update shared_utils.jl to be compatible with the new composition stru…
mrhardman Mar 12, 2024
b2a4b77
Add species dependence to gyroaverage operator.
mrhardman Mar 13, 2024
14a79ba
Extend gyroaverages test to permit shared-memory MPI, extend gyroaver…
mrhardman Mar 13, 2024
f9689c8
Merge branch 'geometry-upgrade' into feature-gyroaverages
mrhardman Mar 14, 2024
89c27ff
Add example input file for studying gyroaverage operator in case with…
mrhardman Mar 14, 2024
245f807
Merge branch 'geometry-upgrade' into feature-gyroaverages
mrhardman Mar 14, 2024
b2fb26e
Merge branch 'geometry-upgrade' into feature-gyroaverages
mrhardman Mar 15, 2024
9ad86b5
Modify how the summation loops over izp and irp are carried out in th…
mrhardman Mar 17, 2024
d32f5f0
Refactor the arrays used to index over the gyroaverage matrix so that…
mrhardman Mar 18, 2024
99b926b
Merge branch 'master' into feature-gyroaverages
mrhardman Mar 19, 2024
db2f49d
Correct region for array copy for standard DK velocity moments calcul…
mrhardman Mar 20, 2024
e0257b6
Lower resolutions in examples/gk-ions/2D-periodic-gk.toml to reduce l…
mrhardman Mar 20, 2024
cd85aa7
Reduce resolution requirements for gyroaverages test to reduce load o…
mrhardman Mar 20, 2024
0fa4195
Update comments.
mrhardman Mar 21, 2024
d8f2f76
Merge branch 'mpi-init-only-once' into feature-gyroaverages
Mar 22, 2024
49381b3
Remove commented-out code
johnomotani Apr 23, 2024
bc059ff
Skip a couple of array copies when not gyroaveraging
johnomotani Apr 23, 2024
65308c7
Merge branch 'master' into feature-gyroaverages
mrhardman Apr 24, 2024
9b2d535
Debug-checks test for gyroaverage operator
johnomotani Apr 24, 2024
d239e31
Use FFTW.ESTIMATE when generating Chebyshev-Radau integration weights
johnomotani Apr 24, 2024
d60528a
Add test directory so gyroaverage tests work with FFTW-wisdom-saving
johnomotani Apr 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions examples/gk-ions/2D-periodic-gk.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
n_ion_species = 1
n_neutral_species = 0
boltzmann_electron_response = true
evolve_moments_density = false
evolve_moments_parallel_flow = false
evolve_moments_parallel_pressure = false
evolve_moments_conservation = false
gyrokinetic_ions = true
T_e = 1.0
T_wall = 1.0
initial_density1 = 1.0
initial_temperature1 = 1.0
z_IC_option1 = "gaussian"
z_IC_density_amplitude1 = 0.001
z_IC_density_phase1 = 0.0
z_IC_upar_amplitude1 = 1.0
z_IC_upar_phase1 = 0.0
z_IC_temperature_amplitude1 = 0.0
z_IC_temperature_phase1 = 0.0
vpa_IC_option1 = "gaussian"
vpa_IC_density_amplitude1 = 1.0
vpa_IC_density_phase1 = 0.0
vpa_IC_upar_amplitude1 = 0.0
vpa_IC_upar_phase1 = 0.0
vpa_IC_temperature_amplitude1 = 0.0
vpa_IC_temperature_phase1 = 0.0
initial_density2 = 1.0
initial_temperature2 = 1.0
z_IC_option2 = "gaussian"
z_IC_density_amplitude2 = 0.001
z_IC_density_phase2 = 0.0
z_IC_upar_amplitude2 = -1.0
z_IC_upar_phase2 = 0.0
z_IC_temperature_amplitude2 = 0.0
z_IC_temperature_phase2 = 0.0
vpa_IC_option2 = "gaussian"
vpa_IC_density_amplitude2 = 1.0
vpa_IC_density_phase2 = 0.0
vpa_IC_upar_amplitude2 = 0.0
vpa_IC_upar_phase2 = 0.0
vpa_IC_temperature_amplitude2 = 0.0
vpa_IC_temperature_phase2 = 0.0
charge_exchange_frequency = 0.5
ionization_frequency = 0.05
constant_ionization_rate = true
nstep = 50
dt = 1.0e-3
nwrite = 10
nwrite_dfns = 10
use_semi_lagrange = false
n_rk_stages = 4
split_operators = false
r_ngrid = 5
r_nelement = 2
r_bc = "periodic"
z_ngrid = 5
z_nelement = 2
z_bc = "periodic"
z_discretization = "chebyshev_pseudospectral"
vpa_ngrid = 5
vpa_nelement = 2
vpa_L = 6.0
vpa_bc = "zero"
vpa_discretization = "chebyshev_pseudospectral"
vperp_ngrid = 5
vperp_nelement = 1
vperp_L = 3.0
vperp_bc = "zero"
vperp_discretization = "chebyshev_pseudospectral"
vz_ngrid = 9
vz_nelement = 64
vz_L = 18.0
vz_bc = "both_zero"
vz_discretization = "chebyshev_pseudospectral"

[numerical_dissipation]
vpa_dissipation_coefficient = 1.0e-3 #1.0e-2 #1.0e-1
vperp_dissipation_coefficient = 1.0e-3 #1.0e-2 #1.0e-1
#r_disspipation_coefficient = 1.0e-3
#force_minimum_pdf_value = 0.0

[geometry]
#option="1D-mirror"
DeltaB=0.0
option="constant-helical"
pitch=0.1
rhostar= 0.1
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function get_composition(scan_input)
phi_wall = get(scan_input, "phi_wall", 0.0)
# if false use true Knudsen cosine for neutral wall bc
use_test_neutral_wall_pdf = get(scan_input, "use_test_neutral_wall_pdf", false)
gyrokinetic_ions = get(scan_input, "gyrokinetic_ions", false)
# constant to be used to test nonzero Er in wall boundary condition
Er_constant = get(scan_input, "Er_constant", 0.0)
recycling_fraction = get(scan_input, "recycling_fraction", 1.0)
Expand All @@ -106,7 +107,7 @@ function get_composition(scan_input)
me_over_mi = 1.0/1836.0
composition = species_composition(n_species, n_ion_species, n_neutral_species,
electron_physics, use_test_neutral_wall_pdf, T_e, T_wall, phi_wall, Er_constant,
mn_over_mi, me_over_mi, recycling_fraction, allocate_float(n_species))
mn_over_mi, me_over_mi, recycling_fraction, gyrokinetic_ions, allocate_float(n_species))
return composition

end
Expand Down
87 changes: 87 additions & 0 deletions moment_kinetics/debug_test/gyroaverage_inputs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
test_type = "gyroaverage"

# default inputs for tests
test_input = Dict(
"run_name" => "gyroaverage",
"n_ion_species" => 1,
"n_neutral_species" => 0,
"evolve_moments_density" => false,
"evolve_moments_parallel_flow" => false,
"evolve_moments_parallel_pressure" => false,
"evolve_moments_conservation" => false,
"gyrokinetic_ions" => true,
"T_e" => 1.0,
"T_wall" => 1.0,
"initial_density1" => 1.0,
"initial_temperature1" => 1.0,
"z_IC_option1" => "gaussian",
"z_IC_density_amplitude1" => 0.001,
"z_IC_density_phase1" => 0.0,
"z_IC_upar_amplitude1" => 1.0,
"z_IC_upar_phase1" => 0.0,
"z_IC_temperature_amplitude1" => 0.0,
"z_IC_temperature_phase1" => 0.0,
"vpa_IC_option1" => "gaussian",
"vpa_IC_density_amplitude1" => 1.0,
"vpa_IC_density_phase1" => 0.0,
"vpa_IC_upar_amplitude1" => 0.0,
"vpa_IC_upar_phase1" => 0.0,
"vpa_IC_temperature_amplitude1" => 0.0,
"vpa_IC_temperature_phase1" => 0.0,
"initial_density2" => 1.0,
"initial_temperature2" => 1.0,
"z_IC_option2" => "gaussian",
"z_IC_density_amplitude2" => 0.001,
"z_IC_density_phase2" => 0.0,
"z_IC_upar_amplitude2" => -1.0,
"z_IC_upar_phase2" => 0.0,
"z_IC_temperature_amplitude2" => 0.0,
"z_IC_temperature_phase2" => 0.0,
"vpa_IC_option2" => "gaussian",
"vpa_IC_density_amplitude2" => 1.0,
"vpa_IC_density_phase2" => 0.0,
"vpa_IC_upar_amplitude2" => 0.0,
"vpa_IC_upar_phase2" => 0.0,
"vpa_IC_temperature_amplitude2" => 0.0,
"vpa_IC_temperature_phase2" => 0.0,
"charge_exchange_frequency" => 0.5,
"ionization_frequency" => 0.05,
"constant_ionization_rate" => true,
"nstep" => 3,
"dt" => 1.0e-12,
"nwrite" => 2,
"nwrite_dfns" => 2,
"n_rk_stages" => 4,
"r_ngrid" => 5,
"r_nelement" => 2,
"r_bc" => "periodic",
"z_ngrid" => 5,
"z_nelement" => 2,
"z_bc" => "periodic",
"z_discretization" => "chebyshev_pseudospectral",
"vpa_ngrid" => 5,
"vpa_nelement" => 2,
"vpa_L" => 6.0,
"vpa_bc" => "zero",
"vpa_discretization" => "chebyshev_pseudospectral",
"vperp_ngrid" => 5,
"vperp_nelement" => 1,
"vperp_L" => 3.0,
"vperp_bc" => "zero",
"vperp_discretization" => "chebyshev_pseudospectral",
"vz_ngrid" => 5,
"vz_nelement" => 2,
"vz_L" => 6.0,
"vz_bc" => "zero",
"vz_discretization" => "chebyshev_pseudospectral",
"numerical_dissipation" => Dict("vpa_dissipation_coefficient" => 1.0e-3,
"vperp_dissipation_coefficient" => 1.0e-3),
"geometry" => Dict("DeltaB"=>0.0,
"option"=>"constant-helical",
"pitch"=>0.1,
"rhostar"=> 0.1),
)

test_input_list = [
test_input,
]
23 changes: 23 additions & 0 deletions moment_kinetics/debug_test/gyroaverage_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module GyroaverageDebug

# Debug test using wall boundary conditions.

include("setup.jl")

# Create a temporary directory for test output
test_output_directory = get_MPI_tempdir()
mkpath(test_output_directory)


# Input parameters for the test
include("gyroaverage_inputs.jl")

# Defines the test functions, using variables defined in the *_inputs.jl file
include("runtest_template.jl")

end # GyroaverageDebug


using .GyroaverageDebug

GyroaverageDebug.runtests()
1 change: 1 addition & 0 deletions moment_kinetics/debug_test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function runtests()
include(joinpath(@__DIR__, "harrisonthompson.jl"))
include(joinpath(@__DIR__, "mms_tests.jl"))
include(joinpath(@__DIR__, "restart_interpolation_tests.jl"))
include(joinpath(@__DIR__, "gyroaverage_tests.jl"))
end
end

Expand Down
2 changes: 1 addition & 1 deletion moment_kinetics/src/chebyshev.jl
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ function chebyshev_radau_weights(moments::Array{mk_float,1}, n)
# create array for moments on extended [0,2π] domain in theta = ArcCos[z]
fext = allocate_complex(nfft)
# make fft plan
forward_transform = plan_fft!(fext, flags=FFTW.WISDOM_ONLY)
forward_transform = plan_fft!(fext, flags=FFTW.ESTIMATE)
# assign values of fext from moments
@inbounds begin
for j ∈ 1:n
Expand Down
4 changes: 3 additions & 1 deletion moment_kinetics/src/coordinates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ struct coordinate
element_shift::Array{mk_float,1}
# option used to set up element spacing
element_spacing_option::String
# list of element boundaries
element_boundaries::Array{mk_float,1}
end

"""
Expand Down Expand Up @@ -167,7 +169,7 @@ function define_coordinate(input, parallel_io::Bool=false; run_directory=nothing
cell_width, igrid, ielement, imin, imax, igrid_full, input.discretization, input.fd_option, input.cheb_option,
input.bc, wgts, uniform_grid, duniform_dgrid, scratch, copy(scratch), copy(scratch),
scratch_2d, copy(scratch_2d), advection, send_buffer, receive_buffer, input.comm,
local_io_range, global_io_range, element_scale, element_shift, input.element_spacing_option)
local_io_range, global_io_range, element_scale, element_shift, input.element_spacing_option, element_boundaries)

if coord.n == 1 && occursin("v", coord.name)
spectral = null_velocity_dimension_info()
Expand Down
25 changes: 21 additions & 4 deletions moment_kinetics/src/em_fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@ using ..moment_kinetics_structs: em_fields_struct
using ..velocity_moments: update_density!
#using ..calculus: derivative!
using ..derivatives: derivative_r!, derivative_z!

using ..gyroaverages: gyro_operators, gyroaverage_field!
"""
"""
function setup_em_fields(nz, nr, force_phi, drive_amplitude, drive_frequency, force_Er_zero)
function setup_em_fields(nvperp, nz, nr, n_ion_species, force_phi, drive_amplitude, drive_frequency, force_Er_zero)
phi = allocate_shared_float(nz,nr)
phi0 = allocate_shared_float(nz,nr)
Er = allocate_shared_float(nz,nr)
Ez = allocate_shared_float(nz,nr)
return em_fields_struct(phi, phi0, Er, Ez, force_phi, drive_amplitude, drive_frequency, force_Er_zero)
gphi = allocate_shared_float(nvperp,nz,nr,n_ion_species)
gEr = allocate_shared_float(nvperp,nz,nr,n_ion_species)
gEz = allocate_shared_float(nvperp,nz,nr,n_ion_species)
return em_fields_struct(phi, phi0, Er, Ez, gphi, gEr, gEz, force_phi, drive_amplitude, drive_frequency, force_Er_zero)
end

"""
update_phi updates the electrostatic potential, phi
"""
function update_phi!(fields, fvec, z, r, composition, z_spectral, r_spectral, scratch_dummy)
function update_phi!(fields, fvec, vperp, z, r, composition, z_spectral, r_spectral, scratch_dummy, gyroavs::gyro_operators)
n_ion_species = composition.n_ion_species
@boundscheck size(fields.phi,1) == z.n || throw(BoundsError(fields.phi))
@boundscheck size(fields.phi,2) == r.n || throw(BoundsError(fields.phi))
Expand Down Expand Up @@ -137,6 +140,20 @@ function update_phi!(fields, fvec, z, r, composition, z_spectral, r_spectral, sc
fields.Ez[:,:] .= 0.0
end
end

# get gyroaveraged field arrays for distribution function advance
gkions = composition.gyrokinetic_ions
if gkions
gyroaverage_field!(fields.gphi,fields.phi,gyroavs,vperp,z,r,composition)
gyroaverage_field!(fields.gEz,fields.Ez,gyroavs,vperp,z,r,composition)
gyroaverage_field!(fields.gEr,fields.Er,gyroavs,vperp,z,r,composition)
else # use the drift-kinetic form of the fields in the kinetic equation
@loop_s_r_z_vperp is ir iz ivperp begin
fields.gphi[ivperp,iz,ir,is] = fields.phi[iz,ir]
fields.gEz[ivperp,iz,ir,is] = fields.Ez[iz,ir]
fields.gEr[ivperp,iz,ir,is] = fields.Er[iz,ir]
end
end

end

Expand Down
Loading
Loading