Skip to content

Commit

Permalink
Fix various bugs in last commit so that refactored code runs and MMS …
Browse files Browse the repository at this point in the history
…tests can be executed.
  • Loading branch information
mrhardman committed Jul 8, 2024
1 parent d1d091f commit 1ad159c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 32 deletions.
19 changes: 5 additions & 14 deletions makie_post_processing/makie_post_processing/src/shared_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ export calculate_and_write_frequencies, get_geometry, get_composition
using moment_kinetics.analysis: fit_delta_phi_mode
using moment_kinetics.array_allocation: allocate_float
using moment_kinetics.coordinates: define_coordinate
using moment_kinetics.geo: init_magnetic_geometry
using moment_kinetics.input_structs: boltzmann_electron_response,
boltzmann_electron_response_with_simple_sheath,
grid_input, geometry_input, species_composition
using moment_kinetics.moment_kinetics_input: get_default_rhostar, setup_reference_parameters
using moment_kinetics.type_definitions: mk_float, mk_int
using moment_kinetics.reference_parameters: setup_reference_parameters
using moment_kinetics.moment_kinetics_input: get_default_rhostar
using moment_kinetics.geo: init_magnetic_geometry
using moment_kinetics.geo: init_magnetic_geometry, setup_geometry_input
using MPI

"""
Expand Down Expand Up @@ -90,7 +89,7 @@ function get_composition(scan_input)
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)
#Er_constant = get(scan_input, "Er_constant", 0.0)
recycling_fraction = get(scan_input, "recycling_fraction", 1.0)
# constant to be used to control Ez divergences
epsilon_offset = get(scan_input, "epsilon_offset", 0.001)
Expand All @@ -106,26 +105,18 @@ function get_composition(scan_input)
# ratio of the electron particle mass to the ion particle mass
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,
electron_physics, use_test_neutral_wall_pdf, T_e, T_wall, phi_wall, #Er_constant,
mn_over_mi, me_over_mi, recycling_fraction, gyrokinetic_ions, allocate_float(n_species))
return composition

end

function get_geometry(scan_input,z,r)
reference_params = setup_reference_parameters(scan_input)
# set geometry_input
# MRH need to get this in way that does not duplicate code
# MRH from moment_kinetics_input.jl
option = get(scan_input, "geometry_option", "constant-helical") #"1D-mirror"
pitch = get(scan_input, "pitch", 1.0)
rhostar = get(scan_input, "rhostar", get_default_rhostar(reference_params))
DeltaB = get(scan_input, "DeltaB", 1.0)
geo_in = geometry_input(rhostar,option,pitch,DeltaB)
reference_rhostar = get_default_rhostar(reference_params)
geo_in = setup_geometry_input(scan_input, reference_rhostar)
geometry = init_magnetic_geometry(geo_in,z,r)

return geometry

end

end # shared_utils.jl
8 changes: 4 additions & 4 deletions moment_kinetics/ext/manufactured_solns_ext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ using IfElse

if manufactured_solns_input.type == "default"
# calculate the electric fields and the potential
Er, Ez, phi = electric_fields(Lr, Lz, r_bc, z_bc, composition, nr,
Er, Ez, phi = electric_fields(Lr, Lz, r_bc, z_bc, composition, geometry, nr,
manufactured_solns_input, species)

# get geometric/composition data
Expand Down Expand Up @@ -417,7 +417,7 @@ using IfElse
# get N_e factor for boltzmann response
if composition.electron_physics == boltzmann_electron_response_with_simple_sheath && nr == 1
# so 1D MMS test with 3V neutrals where ion current can be calculated prior to knowing Er
jpari_into_LHS_wall = jpari_into_LHS_wall_sym(Lr, Lz, r_bc, z_bc, composition,
jpari_into_LHS_wall = jpari_into_LHS_wall_sym(Lr, Lz, r_bc, z_bc,
manufactured_solns_input)
N_e = -2.0*sqrt(pi*composition.me_over_mi)*exp(-composition.phi_wall/composition.T_e)*jpari_into_LHS_wall
elseif composition.electron_physics == boltzmann_electron_response_with_simple_sheath && nr > 1
Expand All @@ -442,8 +442,8 @@ using IfElse
# calculate the electric fields
dense = densi # get the electron density via quasineutrality with Zi = 1
phi = composition.T_e*log(dense/N_e) # use the adiabatic response of electrons for me/mi -> 0
Er = -Dr(phi)*rfac + composition.Er_constant
Ez = -Dz(phi)
Er = -Dr(phi)*rfac + geometry.Er_constant
Ez = -Dz(phi) + geometry.Ez_constant

Er_expanded = expand_derivatives(Er)
Ez_expanded = expand_derivatives(Ez)
Expand Down
4 changes: 2 additions & 2 deletions moment_kinetics/src/em_fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ function update_phi!(fields, fvec, vperp, z, r, composition, geometry, z_spectra
scratch_dummy.buffer_r_3, scratch_dummy.buffer_r_4,
z_spectral,z)
else
@serial_region begin
fields.Ez[:,:] .= = geometry.input.Ez_constant
@loop_r_z ir iz begin
fields.Ez[iz,ir] = geometry.input.Ez_constant
# Ez_constant defaults to 0.0 in geo.jl
end
end
Expand Down
6 changes: 3 additions & 3 deletions moment_kinetics/src/geo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module geo
export init_magnetic_geometry
export setup_geometry_input

using ..input_structs: geometry_input
using ..input_structs: geometry_input, set_defaults_and_check_section!
using ..file_io: input_option_error
using ..array_allocation: allocate_float
using ..type_definitions: mk_float, mk_int
Expand Down Expand Up @@ -77,9 +77,9 @@ function setup_geometry_input(toml_input::Dict, reference_rhostar)
input_section = set_defaults_and_check_section!(toml_input, "geometry",
# begin default inputs (as kwargs)
# rhostar ion (ref)
rhostar = reference_rhostar #used to premultiply ExB drift terms
rhostar = reference_rhostar, #used to premultiply ExB drift terms
# magnetic geometry option
option = "constant-helical" # "1D-mirror"
option = "constant-helical",# "1D-mirror"
# pitch ( = Bzed/Bmag if geometry_option == "constant-helical")
pitch = 1.0,
# DeltaB ( = (Bzed(z=L/2) - Bzed(0))/Bref if geometry_option == "1D-mirror")
Expand Down
12 changes: 5 additions & 7 deletions moment_kinetics/test/gyroaverage_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using SpecialFunctions: besselj0
import moment_kinetics
using moment_kinetics.input_structs
using moment_kinetics.coordinates: define_coordinate
using moment_kinetics.geo: init_magnetic_geometry
using moment_kinetics.geo: init_magnetic_geometry, setup_geometry_input
using moment_kinetics.communication
using moment_kinetics.looping
using moment_kinetics.array_allocation: allocate_float, allocate_shared_float
Expand Down Expand Up @@ -142,11 +142,9 @@ function gyroaverage_test(absolute_error; rhostar=0.1, pitch=0.5, ngrid=5, kr=2,
gyrophase, gyrophase_spectral = define_coordinate(gyrophase_input; collision_operator_dim=false, run_directory=test_output_directory)

# create test geometry
#rhostar = 0.1 #rhostar of ions for ExB drift
option = "constant-helical"
#pitch = 1.0
DeltaB = 1.0
geometry_in = geometry_input(rhostar,option,pitch,DeltaB)
inputdict = Dict("geometry" => Dict("option" => option, "rhostar" => rhostar, "pitch" => pitch))
geometry_in = setup_geometry_input(inputdict, 0.1)
geometry = init_magnetic_geometry(geometry_in,z,r)

# create test composition
Expand Down Expand Up @@ -243,7 +241,7 @@ function create_test_composition()
# wall potential at z = 0
phi_wall = 0.0
# constant to test nonzero Er
Er_constant = 0.0
#Er_constant = 0.0
# ratio of the neutral particle mass to the ion particle mass
mn_over_mi = 1.0
# ratio of the electron particle mass to the ion particle mass
Expand All @@ -253,7 +251,7 @@ function create_test_composition()
recycling_fraction = 1.0
gyrokinetic_ions = true
return 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,
electron_physics, use_test_neutral_wall_pdf, T_e, T_wall, phi_wall, #Er_constant,
mn_over_mi, me_over_mi, recycling_fraction, gyrokinetic_ions, allocate_float(n_species))
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ function get_MMS_error_data(path_list,scan_type,scan_name)
dfnn_func = manufactured_solns_list.dfnn_func
densn_func = manufactured_solns_list.densn_func

manufactured_E_fields = manufactured_electric_fields(Lr_in,z.L,r_bc,z_bc,composition,r.n,manufactured_solns_input,species)
manufactured_E_fields = manufactured_electric_fields(Lr_in,z.L,r_bc,z_bc,composition,geo_in,r.n,manufactured_solns_input,species)
Er_func = manufactured_E_fields.Er_func
Ez_func = manufactured_E_fields.Ez_func
phi_func = manufactured_E_fields.phi_func
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ function analyze_and_plot_data(prefix...; run_index=nothing)
densn_func = manufactured_solns_list.densn_func
manufactured_E_fields =
manufactured_electric_fields(Lr_in, z_global.L, r_global.bc, z_global.bc,
composition, r_global.n,
composition, geometry.input, r_global.n,
manufactured_solns_input, species)
Er_func = manufactured_E_fields.Er_func
Ez_func = manufactured_E_fields.Ez_func
Expand Down

0 comments on commit 1ad159c

Please sign in to comment.