diff --git a/CMakeLists.txt b/CMakeLists.txt index 8888b5b3b3..6deadfb708 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,29 +42,33 @@ option(STELLA_UPDATE_GIT_SUBMODULES "Check submodules are up-to-date during buil # Sources that don't need preprocessing set(STELLA_SOURCES_f90 + arrays_dist_fn.f90 + arrays_fields.f90 + calculations_kxky.f90 common_types.f90 + debug_flags.f90 define.inc dist_fn.f90 - dist_fn_arrays.f90 dist_redistribute.f90 euterpe_interface.f90 extended_zgrid.f90 ffs_solve.f90 - fields_arrays.f90 finite_differences.f90 flow_shear.f90 g_tofrom_h.f90 + grids_kxky.f90 gyro_averages.f90 implicit_solve.f90 init_g.f90 - kt_grids.f90 mirror_terms.f90 multibox.f90 neoclassical_terms.f90 parallel_streaming.f90 - physics_flags.f90 - physics_parameters.f90 - run_parameters.f90 + parameters_kxky_grids.f90 + parameters_kxky_grids_box.f90 + parameters_kxky_grids_range.f90 + parameters_numerical.f90 + parameters_physics.f90 species.f90 stella_layouts.f90 stella_time.f90 @@ -72,6 +76,7 @@ set(STELLA_SOURCES_f90 time_advance.f90 volume_averages.f90 vpamu_grids.f90 + write_radial_grid.f90 zgrid.f90 diagnostics/parameters_diagnostics.f90 diagnostics/diagnostics.f90 diff --git a/Makefile.depend b/Makefile.depend index cec43634da..97e0879813 100644 --- a/Makefile.depend +++ b/Makefile.depend @@ -2,12 +2,16 @@ # Auto-generated file by fortdep. Do not edit! # stella_mod = \ + arrays_dist_fn.o \ + arrays_fields.o \ + calculations_kxky.o \ coll_dougherty.o \ coll_fokkerplanck.o \ command_line.o \ common_types.o \ constants.o \ convert.o \ + debug_flags.o \ diagnostics.o \ diagnostics_distribution.o \ diagnostics_fluxes.o \ @@ -19,14 +23,12 @@ stella_mod = \ diagnostics_potential.o \ dissipation.o \ dist_fn.o \ - dist_fn_arrays.o \ dist_redistribute.o \ euterpe_interface.o \ extended_zgrid.o \ ffs_solve.o \ fft_work.o \ fields.o \ - fields_arrays.o \ file_utils.o \ finite_differences.o \ flow_shear.o \ @@ -39,12 +41,12 @@ stella_mod = \ geometry_vmec_read_netCDF_file.o \ geometry_zpinch.o \ git_version.o \ + grids_kxky.o \ gyro_averages.o \ hyper.o \ implicit_solve.o \ init_g.o \ job_manage.o \ - kt_grids.o \ linear_solve.o \ mirror_terms.o \ mp.o \ @@ -56,12 +58,14 @@ stella_mod = \ netcdf_utils.o \ parallel_streaming.o \ parameters_diagnostics.o \ - physics_flags.o \ - physics_parameters.o \ + parameters_kxky_grids.o \ + parameters_kxky_grids_box.o \ + parameters_kxky_grids_range.o \ + parameters_numerical.o \ + parameters_physics.o \ ran.o \ redistribute.o \ response_matrix.o \ - run_parameters.o \ sfincs_interface.o \ sources.o \ species.o \ @@ -78,25 +82,37 @@ stella_mod = \ time_advance.o \ volume_averages.o \ vpamu_grids.o \ + write_radial_grid.o \ zgrid.o +arrays_dist_fn.o: +arrays_fields.o: \ + common_types.o +calculations_kxky.o: \ + grids_kxky.o \ + job_manage.o \ + mp.o \ + parameters_kxky_grids.o \ + stella_transforms.o coll_dougherty.o: \ - dist_fn_arrays.o \ + arrays_dist_fn.o \ + arrays_fields.o \ + calculations_kxky.o \ dist_redistribute.o \ fields.o \ - fields_arrays.o \ file_utils.o \ finite_differences.o \ g_tofrom_h.o \ geometry.o \ + grids_kxky.o \ gyro_averages.o \ job_manage.o \ - kt_grids.o \ linear_solve.o \ mp.o \ - physics_flags.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ + parameters_physics.o \ redistribute.o \ - run_parameters.o \ species.o \ stella_layouts.o \ stella_time.o \ @@ -104,9 +120,9 @@ coll_dougherty.o: \ vpamu_grids.o \ zgrid.o coll_fokkerplanck.o: \ + arrays_dist_fn.o \ common_types.o \ constants.o \ - dist_fn_arrays.o \ dist_redistribute.o \ fields.o \ file_utils.o \ @@ -115,13 +131,12 @@ coll_fokkerplanck.o: \ geometry.o \ gyro_averages.o \ job_manage.o \ - kt_grids.o \ linear_solve.o \ mp.o \ - physics_flags.o \ - physics_parameters.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ + parameters_physics.o \ redistribute.o \ - run_parameters.o \ species.o \ spfunc.o \ stella_layouts.o \ @@ -132,44 +147,48 @@ command_line.o: common_types.o: constants.o: convert.o: +debug_flags.o: \ + file_utils.o \ + mp.o diagnostics.o: \ + arrays_dist_fn.o \ + arrays_fields.o \ constants.o \ + debug_flags.o \ diagnostics_distribution.o \ diagnostics_fluxes.o \ diagnostics_moments.o \ diagnostics_omega.o \ diagnostics_potential.o \ dist_fn.o \ - dist_fn_arrays.o \ dist_redistribute.o \ fields.o \ - fields_arrays.o \ + grids_kxky.o \ init_g.o \ job_manage.o \ - kt_grids.o \ mp.o \ parameters_diagnostics.o \ - physics_flags.o \ - physics_parameters.o \ + parameters_numerical.o \ + parameters_physics.o \ redistribute.o \ - run_parameters.o \ species.o \ stella_io.o \ stella_save.o \ stella_time.o \ zgrid.o diagnostics_distribution.o: \ - dist_fn_arrays.o \ + arrays_dist_fn.o \ + arrays_fields.o \ dist_redistribute.o \ - fields_arrays.o \ g_tofrom_h.o \ geometry.o \ + grids_kxky.o \ job_manage.o \ - kt_grids.o \ mp.o \ parameters_diagnostics.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ redistribute.o \ - run_parameters.o \ species.o \ stella_io.o \ stella_layouts.o \ @@ -177,49 +196,53 @@ diagnostics_distribution.o: \ vpamu_grids.o \ zgrid.o diagnostics_fluxes.o: \ + arrays_dist_fn.o \ + arrays_fields.o \ + debug_flags.o \ diagnostics_fluxes_fluxtube.o \ diagnostics_fluxes_fullfluxsurface.o \ diagnostics_fluxes_radialvariation.o \ - dist_fn_arrays.o \ dist_redistribute.o \ - fields_arrays.o \ file_utils.o \ g_tofrom_h.o \ job_manage.o \ - kt_grids.o \ mp.o \ parameters_diagnostics.o \ - physics_flags.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ + parameters_physics.o \ redistribute.o \ - run_parameters.o \ species.o \ stella_io.o \ stella_time.o \ zgrid.o diagnostics_fluxes_fluxtube.o: \ + arrays_fields.o \ constants.o \ - fields_arrays.o \ + debug_flags.o \ geometry.o \ + grids_kxky.o \ gyro_averages.o \ - kt_grids.o \ mp.o \ parameters_diagnostics.o \ - physics_flags.o \ - run_parameters.o \ + parameters_numerical.o \ + parameters_physics.o \ species.o \ stella_layouts.o \ volume_averages.o \ vpamu_grids.o \ zgrid.o diagnostics_fluxes_fullfluxsurface.o: \ + arrays_dist_fn.o \ + arrays_fields.o \ + calculations_kxky.o \ constants.o \ - dist_fn_arrays.o \ - fields_arrays.o \ g_tofrom_h.o \ geometry.o \ + grids_kxky.o \ gyro_averages.o \ - kt_grids.o \ - run_parameters.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ species.o \ stella_layouts.o \ stella_transforms.o \ @@ -227,15 +250,17 @@ diagnostics_fluxes_fullfluxsurface.o: \ vpamu_grids.o \ zgrid.o diagnostics_fluxes_radialvariation.o: \ + arrays_dist_fn.o \ + calculations_kxky.o \ constants.o \ - dist_fn_arrays.o \ geometry.o \ + grids_kxky.o \ gyro_averages.o \ - kt_grids.o \ mp.o \ parameters_diagnostics.o \ - physics_flags.o \ - run_parameters.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ + parameters_physics.o \ species.o \ stella_layouts.o \ stella_transforms.o \ @@ -243,16 +268,18 @@ diagnostics_fluxes_radialvariation.o: \ vpamu_grids.o \ zgrid.o diagnostics_moments.o: \ - dist_fn_arrays.o \ - fields_arrays.o \ + arrays_dist_fn.o \ + arrays_fields.o \ + calculations_kxky.o \ geometry.o \ + grids_kxky.o \ gyro_averages.o \ job_manage.o \ - kt_grids.o \ mp.o \ parameters_diagnostics.o \ - physics_flags.o \ - run_parameters.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ + parameters_physics.o \ species.o \ stella_io.o \ stella_layouts.o \ @@ -260,66 +287,71 @@ diagnostics_moments.o: \ vpamu_grids.o \ zgrid.o diagnostics_omega.o: \ + arrays_fields.o \ constants.o \ - fields_arrays.o \ + debug_flags.o \ file_utils.o \ + grids_kxky.o \ job_manage.o \ - kt_grids.o \ mp.o \ parameters_diagnostics.o \ - physics_flags.o \ + parameters_kxky_grids.o \ + parameters_physics.o \ stella_io.o \ stella_time.o \ volume_averages.o diagnostics_potential.o: \ - dist_fn_arrays.o \ + arrays_dist_fn.o \ + arrays_fields.o \ fields.o \ - fields_arrays.o \ file_utils.o \ geometry.o \ + grids_kxky.o \ job_manage.o \ - kt_grids.o \ mp.o \ parameters_diagnostics.o \ - physics_flags.o \ + parameters_kxky_grids.o \ + parameters_physics.o \ stella_io.o \ stella_time.o \ volume_averages.o \ zgrid.o dissipation.o: \ + arrays_dist_fn.o \ coll_dougherty.o \ coll_fokkerplanck.o \ - dist_fn_arrays.o \ dist_redistribute.o \ file_utils.o \ hyper.o \ job_manage.o \ mp.o \ - physics_flags.o \ + parameters_numerical.o \ + parameters_physics.o \ redistribute.o \ - run_parameters.o \ stella_layouts.o \ vpamu_grids.o \ zgrid.o dist_fn.o: \ - dist_fn_arrays.o \ + arrays_dist_fn.o \ + calculations_kxky.o \ + debug_flags.o \ dist_redistribute.o \ extended_zgrid.o \ geometry.o \ + grids_kxky.o \ gyro_averages.o \ - kt_grids.o \ mp.o \ - physics_flags.o \ + parameters_kxky_grids.o \ + parameters_physics.o \ redistribute.o \ species.o \ stella_layouts.o \ stella_transforms.o \ vpamu_grids.o \ zgrid.o -dist_fn_arrays.o: dist_redistribute.o: \ mp.o \ - physics_flags.o \ + parameters_physics.o \ redistribute.o \ stella_layouts.o \ vpamu_grids.o \ @@ -330,12 +362,14 @@ euterpe_interface.o: \ finite_differences.o \ geometry.o \ mp.o \ - physics_parameters.o \ + parameters_physics.o \ spl.o extended_zgrid.o: \ constants.o \ - kt_grids.o \ + debug_flags.o \ + grids_kxky.o \ mp.o \ + parameters_kxky_grids.o \ zgrid.o ezcdf.o: \ ezcdf_GenGet.o \ @@ -346,13 +380,14 @@ ezcdf_GenGet.o: \ ezcdf_inqvar.o: ezcdf_opncls.o: ffs_solve.o: \ + arrays_dist_fn.o \ + calculations_kxky.o \ constants.o \ - dist_fn_arrays.o \ fields.o \ + grids_kxky.o \ gyro_averages.o \ - kt_grids.o \ - mp.o \ parallel_streaming.o \ + parameters_kxky_grids.o \ species.o \ stella_layouts.o \ stella_transforms.o \ @@ -362,24 +397,26 @@ fft_work.o: \ constants.o \ mp.o fields.o: \ + arrays_dist_fn.o \ + arrays_fields.o \ + calculations_kxky.o \ common_types.o \ constants.o \ - dist_fn_arrays.o \ + debug_flags.o \ dist_redistribute.o \ - fields_arrays.o \ file_utils.o \ geometry.o \ + grids_kxky.o \ gyro_averages.o \ job_manage.o \ - kt_grids.o \ linear_solve.o \ mp.o \ mp_lu_decomposition.o \ multibox.o \ - physics_flags.o \ - physics_parameters.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ + parameters_physics.o \ redistribute.o \ - run_parameters.o \ species.o \ spfunc.o \ stella_layouts.o \ @@ -387,23 +424,21 @@ fields.o: \ volume_averages.o \ vpamu_grids.o \ zgrid.o -fields_arrays.o: \ - common_types.o file_utils.o: \ command_line.o finite_differences.o: flow_shear.o: \ + arrays_fields.o \ constants.o \ fields.o \ - fields_arrays.o \ file_utils.o \ geometry.o \ + grids_kxky.o \ job_manage.o \ - kt_grids.o \ mp.o \ - physics_flags.o \ - physics_parameters.o \ - run_parameters.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ + parameters_physics.o \ species.o \ stella_layouts.o \ stella_time.o \ @@ -411,12 +446,13 @@ flow_shear.o: \ vpamu_grids.o \ zgrid.o g_tofrom_h.o: \ - dist_fn_arrays.o \ + arrays_dist_fn.o \ + calculations_kxky.o \ geometry.o \ gyro_averages.o \ - kt_grids.o \ - physics_flags.o \ - run_parameters.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ + parameters_physics.o \ species.o \ stella_layouts.o \ stella_transforms.o \ @@ -429,14 +465,14 @@ gauss_quad.o: \ geometry.o: \ common_types.o \ constants.o \ + debug_flags.o \ file_utils.o \ geometry_inputprofiles_interface.o \ geometry_miller.o \ geometry_vmec.o \ geometry_zpinch.o \ mp.o \ - physics_flags.o \ - physics_parameters.o \ + parameters_physics.o \ text_options.o \ zgrid.o geometry_inputprofiles_interface.o: \ @@ -445,7 +481,7 @@ geometry_inputprofiles_interface.o: \ finite_differences.o \ geometry_miller.o \ mp.o \ - physics_parameters.o \ + parameters_physics.o \ spl.o geometry_miller.o: \ common_types.o \ @@ -457,10 +493,11 @@ geometry_miller.o: \ geometry_vmec.o: \ common_types.o \ constants.o \ + debug_flags.o \ file_utils.o \ geometry_vmec_read_netCDF_file.o \ mp.o \ - physics_flags.o \ + parameters_physics.o \ spl.o \ stella_transforms.o \ text_options.o \ @@ -470,13 +507,26 @@ geometry_vmec_read_netCDF_file.o: \ geometry_zpinch.o: \ common_types.o git_version.o: +grids_kxky.o: \ + common_types.o \ + constants.o \ + file_utils.o \ + geometry.o \ + mp.o \ + parameters_kxky_grids.o \ + parameters_physics.o \ + ran.o \ + write_radial_grid.o \ + zgrid.o gyro_averages.o: \ + arrays_dist_fn.o \ + calculations_kxky.o \ common_types.o \ - dist_fn_arrays.o \ + debug_flags.o \ geometry.o \ - kt_grids.o \ mp.o \ - physics_flags.o \ + parameters_kxky_grids.o \ + parameters_physics.o \ species.o \ spfunc.o \ stella_layouts.o \ @@ -484,51 +534,55 @@ gyro_averages.o: \ vpamu_grids.o \ zgrid.o hyper.o: \ - dist_fn_arrays.o \ + arrays_dist_fn.o \ dist_redistribute.o \ extended_zgrid.o \ file_utils.o \ finite_differences.o \ geometry.o \ - kt_grids.o \ + grids_kxky.o \ mp.o \ - physics_flags.o \ + parameters_kxky_grids.o \ + parameters_physics.o \ redistribute.o \ stella_layouts.o \ stella_time.o \ vpamu_grids.o \ zgrid.o implicit_solve.o: \ + arrays_dist_fn.o \ + arrays_fields.o \ constants.o \ - dist_fn_arrays.o \ + debug_flags.o \ extended_zgrid.o \ ffs_solve.o \ fields.o \ - fields_arrays.o \ + grids_kxky.o \ gyro_averages.o \ job_manage.o \ - kt_grids.o \ linear_solve.o \ mp.o \ neoclassical_terms.o \ parallel_streaming.o \ - physics_flags.o \ - run_parameters.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ + parameters_physics.o \ species.o \ stella_layouts.o \ stella_time.o \ vpamu_grids.o \ zgrid.o init_g.o: \ + arrays_dist_fn.o \ constants.o \ - dist_fn_arrays.o \ extended_zgrid.o \ file_utils.o \ - kt_grids.o \ + grids_kxky.o \ mp.o \ - physics_flags.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ + parameters_physics.o \ ran.o \ - run_parameters.o \ species.o \ stella_layouts.o \ stella_save.o \ @@ -539,37 +593,25 @@ init_g.o: \ job_manage.o: \ file_utils.o \ mp.o -kt_grids.o: \ - common_types.o \ - constants.o \ - file_utils.o \ - geometry.o \ - job_manage.o \ - mp.o \ - physics_flags.o \ - physics_parameters.o \ - ran.o \ - stella_transforms.o \ - text_options.o \ - zgrid.o linear_solve.o: mirror_terms.o: \ + arrays_dist_fn.o \ + calculations_kxky.o \ constants.o \ - dist_fn_arrays.o \ + debug_flags.o \ dist_redistribute.o \ fields.o \ - fields_arrays.o \ finite_differences.o \ g_tofrom_h.o \ geometry.o \ gyro_averages.o \ job_manage.o \ - kt_grids.o \ mp.o \ neoclassical_terms.o \ - physics_flags.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ + parameters_physics.o \ redistribute.o \ - run_parameters.o \ species.o \ stella_layouts.o \ stella_time.o \ @@ -583,28 +625,29 @@ mp_lu_decomposition.o: \ linear_solve.o mt19937.o: multibox.o: \ + arrays_fields.o \ constants.o \ fft_work.o \ - fields_arrays.o \ file_utils.o \ geometry.o \ + grids_kxky.o \ job_manage.o \ - kt_grids.o \ linear_solve.o \ mp.o \ - physics_flags.o \ - physics_parameters.o \ - run_parameters.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ + parameters_physics.o \ stella_layouts.o \ stella_time.o \ text_options.o \ zgrid.o neasyf.o: neoclassical_terms.o: \ + debug_flags.o \ file_utils.o \ finite_differences.o \ - kt_grids.o \ mp.o \ + parameters_kxky_grids.o \ sfincs_interface.o \ species.o \ stella_layouts.o \ @@ -616,18 +659,18 @@ netcdf_utils.o: \ file_utils.o \ mp.o parallel_streaming.o: \ - dist_fn_arrays.o \ + arrays_fields.o \ + calculations_kxky.o \ + debug_flags.o \ extended_zgrid.o \ - fields.o \ - fields_arrays.o \ finite_differences.o \ geometry.o \ gyro_averages.o \ job_manage.o \ - kt_grids.o \ mp.o \ - physics_flags.o \ - run_parameters.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ + parameters_physics.o \ species.o \ stella_layouts.o \ stella_time.o \ @@ -635,71 +678,86 @@ parallel_streaming.o: \ vpamu_grids.o \ zgrid.o parameters_diagnostics.o: \ + debug_flags.o \ file_utils.o \ mp.o \ - physics_flags.o -physics_flags.o: \ + parameters_physics.o +parameters_kxky_grids.o: \ + file_utils.o \ + mp.o \ + parameters_kxky_grids_box.o \ + parameters_kxky_grids_range.o \ + text_options.o +parameters_kxky_grids_box.o: \ file_utils.o \ mp.o \ + parameters_numerical.o \ + parameters_physics.o \ text_options.o -physics_parameters.o: \ +parameters_kxky_grids_range.o: \ file_utils.o \ mp.o \ - physics_flags.o + parameters_numerical.o \ + parameters_physics.o \ + text_options.o +parameters_numerical.o: \ + file_utils.o \ + mp.o \ + parameters_physics.o \ + text_options.o +parameters_physics.o: \ + debug_flags.o \ + file_utils.o \ + mp.o \ + text_options.o ran.o: \ mt19937.o redistribute.o: \ job_manage.o \ mp.o response_matrix.o: \ + arrays_dist_fn.o \ + arrays_fields.o \ common_types.o \ - dist_fn_arrays.o \ + debug_flags.o \ extended_zgrid.o \ fields.o \ - fields_arrays.o \ geometry.o \ + grids_kxky.o \ gyro_averages.o \ implicit_solve.o \ job_manage.o \ - kt_grids.o \ linear_solve.o \ mp.o \ mp_lu_decomposition.o \ - parallel_streaming.o \ - physics_flags.o \ - physics_parameters.o \ - run_parameters.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ + parameters_physics.o \ species.o \ stella_layouts.o \ system_fortran.o \ vpamu_grids.o \ zgrid.o -run_parameters.o: \ - file_utils.o \ - mp.o \ - physics_flags.o \ - physics_parameters.o \ - species.o \ - text_options.o sfincs_interface.o: \ mp.o \ zgrid.o sources.o: \ + arrays_dist_fn.o \ + arrays_fields.o \ constants.o \ - dist_fn_arrays.o \ dist_redistribute.o \ - fields_arrays.o \ file_utils.o \ geometry.o \ + grids_kxky.o \ gyro_averages.o \ job_manage.o \ - kt_grids.o \ linear_solve.o \ mp.o \ mp_lu_decomposition.o \ - physics_flags.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ + parameters_physics.o \ redistribute.o \ - run_parameters.o \ species.o \ stella_layouts.o \ stella_time.o \ @@ -715,41 +773,42 @@ species.o: \ geometry_inputprofiles_interface.o \ job_manage.o \ mp.o \ - physics_flags.o \ - physics_parameters.o \ + parameters_physics.o \ text_options.o spfunc.o: \ constants.o spl.o: \ constants.o stella.o: \ + arrays_dist_fn.o \ + arrays_fields.o \ + calculations_kxky.o \ + debug_flags.o \ diagnostics.o \ diagnostics_omega.o \ dissipation.o \ dist_fn.o \ - dist_fn_arrays.o \ dist_redistribute.o \ extended_zgrid.o \ fields.o \ - fields_arrays.o \ file_utils.o \ geometry.o \ git_version.o \ + grids_kxky.o \ implicit_solve.o \ init_g.o \ job_manage.o \ - kt_grids.o \ mirror_terms.o \ mp.o \ multibox.o \ parallel_streaming.o \ parameters_diagnostics.o \ - physics_flags.o \ - physics_parameters.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ + parameters_physics.o \ ran.o \ redistribute.o \ response_matrix.o \ - run_parameters.o \ sources.o \ species.o \ stella_layouts.o \ @@ -761,17 +820,17 @@ stella.o: \ vpamu_grids.o \ zgrid.o stella_io.o: \ + arrays_dist_fn.o \ convert.o \ - dist_fn_arrays.o \ file_utils.o \ geometry.o \ git_version.o \ - kt_grids.o \ + grids_kxky.o \ mp.o \ neasyf.o \ netcdf_utils.o \ - physics_flags.o \ - physics_parameters.o \ + parameters_kxky_grids.o \ + parameters_physics.o \ species.o \ vpamu_grids.o \ zgrid.o @@ -780,13 +839,13 @@ stella_layouts.o: \ file_utils.o \ mp.o stella_save.o: \ + arrays_dist_fn.o \ + arrays_fields.o \ common_types.o \ - dist_fn_arrays.o \ - fields_arrays.o \ file_utils.o \ - kt_grids.o \ mp.o \ netcdf_utils.o \ + parameters_kxky_grids.o \ sources.o \ stella_layouts.o \ vpamu_grids.o \ @@ -795,52 +854,54 @@ stella_time.o: \ mp.o stella_transforms.o: \ fft_work.o \ - physics_flags.o \ + parameters_physics.o \ stella_layouts.o system_fortran.o: text_options.o: \ mp.o time_advance.o: \ + arrays_dist_fn.o \ + arrays_fields.o \ + calculations_kxky.o \ constants.o \ + debug_flags.o \ dissipation.o \ - dist_fn_arrays.o \ dist_redistribute.o \ extended_zgrid.o \ fields.o \ - fields_arrays.o \ file_utils.o \ finite_differences.o \ flow_shear.o \ g_tofrom_h.o \ geometry.o \ + grids_kxky.o \ gyro_averages.o \ hyper.o \ implicit_solve.o \ job_manage.o \ - kt_grids.o \ mirror_terms.o \ mp.o \ multibox.o \ neoclassical_terms.o \ parallel_streaming.o \ - physics_flags.o \ - physics_parameters.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ + parameters_physics.o \ redistribute.o \ response_matrix.o \ - run_parameters.o \ sources.o \ species.o \ stella_layouts.o \ stella_time.o \ stella_transforms.o \ - text_options.o \ vpamu_grids.o \ zgrid.o volume_averages.o: \ extended_zgrid.o \ geometry.o \ - kt_grids.o \ - physics_flags.o \ + grids_kxky.o \ + parameters_kxky_grids.o \ + parameters_physics.o \ stella_transforms.o \ zgrid.o vpamu_grids.o: \ @@ -848,16 +909,20 @@ vpamu_grids.o: \ file_utils.o \ gauss_quad.o \ geometry.o \ - kt_grids.o \ mp.o \ - physics_flags.o \ - run_parameters.o \ + parameters_kxky_grids.o \ + parameters_numerical.o \ + parameters_physics.o \ species.o \ stella_layouts.o \ zgrid.o +write_radial_grid.o: \ + file_utils.o \ + geometry.o \ + parameters_physics.o zgrid.o: \ constants.o \ file_utils.o \ mp.o \ - physics_flags.o \ + parameters_physics.o \ text_options.o diff --git a/dist_fn_arrays.f90 b/arrays_dist_fn.f90 similarity index 97% rename from dist_fn_arrays.f90 rename to arrays_dist_fn.f90 index 6a810bc518..c52cf162ed 100644 --- a/dist_fn_arrays.f90 +++ b/arrays_dist_fn.f90 @@ -2,7 +2,7 @@ !! These need to be accessible at a lower dependency level than the dist_fn module itself. !! These arrays are allocated in the function dist_fn::allocate_arrays. -module dist_fn_arrays +module arrays_dist_fn public :: gnew, gold, g_symm, g_scratch public :: g0, g1, g2, g3 @@ -53,4 +53,4 @@ module dist_fn_arrays ! (naky, nakx, nalpha, -nzgrid:nzgrid) ! note: dkperp2dr is divided by kperp2 -end module dist_fn_arrays +end module arrays_dist_fn diff --git a/fields_arrays.f90 b/arrays_fields.f90 similarity index 97% rename from fields_arrays.f90 rename to arrays_fields.f90 index b7c44c1bb7..7a2b8a60b5 100644 --- a/fields_arrays.f90 +++ b/arrays_fields.f90 @@ -1,4 +1,4 @@ -module fields_arrays +module arrays_fields use mpi use common_types, only: response_matrix_type, eigen_type @@ -56,4 +56,4 @@ module fields_arrays real :: tcorr_source_qn, exp_fac_qn integer :: qn_window = MPI_WIN_NULL, qn_zf_window = MPI_WIN_NULL -end module fields_arrays +end module arrays_fields diff --git a/calculations_kxky.f90 b/calculations_kxky.f90 new file mode 100644 index 0000000000..5344571a75 --- /dev/null +++ b/calculations_kxky.f90 @@ -0,0 +1,271 @@ +module calculations_kxky + + implicit none + + public :: swap_kxky, swap_kxky_back + public :: swap_kxky_ordered, swap_kxky_back_ordered + public :: multiply_by_rho + public :: communicate_ktgrids_multibox + + private + + interface swap_kxky + module procedure swap_kxky_real + module procedure swap_kxky_complex + end interface swap_kxky + interface swap_kxky_ordered + module procedure swap_kxky_ordered_real + module procedure swap_kxky_ordered_complex + end interface swap_kxky_ordered + +contains + + ! take an array with ky >= 0 and all kx (ordered like 0, ..., kxmax, -kxmax, ..., -dkx) + ! and uses reality condition to return array + ! with kx >= 0 and all ky (ordered like 0, ..., kymax, -kymax, ..., -dky) + subroutine swap_kxky_complex(gin, gout) + + use parameters_kxky_grids, only: naky, naky_all, ikx_max, nakx + + implicit none + + complex, dimension(:, :), intent(in) :: gin + complex, dimension(:, :), intent(out) :: gout + + integer :: ikx, ikxneg + integer :: iky, ikyneg + + ! first set arrays equal for ky >= 0 and kx >= 0 + gout(:naky, :) = gin(:, :ikx_max) + ! next fill in ky < 0, kx >= 0 elements of array using reality + ikx = 1 + ikxneg = ikx + do iky = naky + 1, naky_all + ! this is the ky index corresponding to +ky in original array + ikyneg = naky_all - iky + 2 + gout(iky, ikx) = conjg(gin(ikyneg, ikxneg)) + end do + do ikx = 2, ikx_max + ikxneg = nakx - ikx + 2 + do iky = naky + 1, naky_all + ! this is the ky index corresponding to +ky in original array + ikyneg = naky_all - iky + 2 + gout(iky, ikx) = conjg(gin(ikyneg, ikxneg)) + end do + end do + + end subroutine swap_kxky_complex + + ! take an array with ky >= 0 and all kx (ordered like 0, ..., kxmax, -kxmax, ..., -dkx) + ! and uses reality condition to return array + ! with kx >= 0 and all ky (ordered like 0, ..., kymax, -kymax, ..., -dky) + subroutine swap_kxky_real(gin, gout) + + use parameters_kxky_grids, only: naky, naky_all, ikx_max, nakx + implicit none + + real, dimension(:, :), intent(in) :: gin + real, dimension(:, :), intent(out) :: gout + + integer :: ikx, ikxneg + integer :: iky, ikyneg + + ! first set arrays equal for ky >= 0 and kx >= 0 + gout(:naky, :) = gin(:, :ikx_max) + ! next fill in ky < 0, kx >= 0 elements of array using reality + ikx = 1 + ikxneg = ikx + do iky = naky + 1, naky_all + ! this is the ky index corresponding to +ky in original array + ikyneg = naky_all - iky + 2 + gout(iky, ikx) = gin(ikyneg, ikxneg) + end do + do ikx = 2, ikx_max + ikxneg = nakx - ikx + 2 + do iky = naky + 1, naky_all + ! this is the ky index corresponding to +ky in original array + ikyneg = naky_all - iky + 2 + gout(iky, ikx) = gin(ikyneg, ikxneg) + end do + end do + + end subroutine swap_kxky_real + + ! take an array with ky >= 0 and all kx (ordered like 0, ..., kxmax, -kxmax, ..., -dkx) + ! and uses reality condition to return array + ! with kx >= 0 and all ky (ordered like -kymax, ..., 0, ..., kymax) + subroutine swap_kxky_ordered_real(gin, gout) + + use parameters_kxky_grids, only: ikx_max, naky, nakx + implicit none + + real, dimension(:, :), intent(in) :: gin + real, dimension(:, :), intent(out) :: gout + + integer :: ikx, ikxneg + integer :: iky, ikyneg + + ! first set arrays equal for ky >= 0 and kx >= 0 + gout(naky:, :) = gin(:, :ikx_max) + ! next fill in ky < 0, kx >= 0 elements of array using reality + ikx = 1 + ikxneg = ikx + do iky = 1, naky - 1 + ! this is the ky index corresponding to +ky in original array + ikyneg = naky - iky + 1 + gout(iky, ikx) = gin(ikyneg, ikxneg) + end do + do ikx = 2, ikx_max + ikxneg = nakx - ikx + 2 + do iky = 1, naky - 1 + ! this is the ky index corresponding to +ky in original array + ikyneg = naky - iky + 1 + gout(iky, ikx) = gin(ikyneg, ikxneg) + end do + end do + + end subroutine swap_kxky_ordered_real + + ! take an array with ky >= 0 and all kx (ordered like 0, ..., kxmax, -kxmax, ..., -dkx) + ! and uses reality condition to return array + ! with kx >= 0 and all ky (ordered like -kymax, ..., 0, ..., kymax) + subroutine swap_kxky_ordered_complex(gin, gout) + + use parameters_kxky_grids, only: naky, nakx, ikx_max + implicit none + + complex, dimension(:, :), intent(in) :: gin + complex, dimension(:, :), intent(out) :: gout + + integer :: ikx, ikxneg + integer :: iky, ikyneg + + ! first set arrays equal for ky >= 0 and kx >= 0 + gout(naky:, :) = gin(:, :ikx_max) + ! next fill in ky < 0, kx >= 0 elements of array using reality + ikx = 1 + ikxneg = ikx + do iky = 1, naky - 1 + ! this is the ky index corresponding to +ky in original array + ikyneg = naky - iky + 1 + gout(iky, ikx) = conjg(gin(ikyneg, ikxneg)) + end do + do ikx = 2, ikx_max + ikxneg = nakx - ikx + 2 + do iky = 1, naky - 1 + ! this is the ky index corresponding to +ky in original array + ikyneg = naky - iky + 1 + gout(iky, ikx) = conjg(gin(ikyneg, ikxneg)) + end do + end do + + end subroutine swap_kxky_ordered_complex + + ! take an array with kx >= 0 and all ky (ordered like 0, ..., kymax, -kymax, ..., -dky) + ! and uses reality condition to return array + ! with ky >= 0 and all kx (ordered like 0, ..., kxmax, -kxmax, ..., -dkx) + subroutine swap_kxky_back(gin, gout) + + use parameters_kxky_grids, only: naky, nakx, naky_all, ikx_max + implicit none + + complex, dimension(:, :), intent(in) :: gin + complex, dimension(:, :), intent(out) :: gout + + integer :: ikx, ikxneg + integer :: iky, ikyneg + + ! first set arrays equal for ky >= 0 and kx >= 0 + gout(:, :ikx_max) = gin(:naky, :) + ! next fill in kx < 0, ky >= 0 elements of array using reality + do ikx = ikx_max + 1, nakx + ikxneg = nakx - ikx + 2 + iky = 1 + ikyneg = iky + gout(iky, ikx) = conjg(gin(ikyneg, ikxneg)) + do iky = 2, naky + ikyneg = naky_all - iky + 2 + gout(iky, ikx) = conjg(gin(ikyneg, ikxneg)) + end do + end do + + end subroutine swap_kxky_back + + ! take an array with kx >= 0 and all ky (ordered like -kymax, ..., 0, ..., kymax) + ! and uses reality condition to return array + ! with ky >= 0 and all kx (ordered like 0, ..., kxmax, -kxmax, ..., -dkx) + subroutine swap_kxky_back_ordered(gin, gout) + + use parameters_kxky_grids, only: ikx_max, naky, nakx + implicit none + + complex, dimension(:, :), intent(in) :: gin + complex, dimension(:, :), intent(out) :: gout + + integer :: ikx, ikxneg + integer :: iky, ikyneg + + ! first set arrays equal for ky >= 0 and kx >= 0 + gout(:, :ikx_max) = gin(naky:, :) + ! next fill in kx < 0, ky >= 0 elements of array using reality + do ikx = ikx_max + 1, nakx + ikxneg = nakx - ikx + 2 + do iky = 1, naky + ikyneg = naky - iky + 1 + gout(iky, ikx) = conjg(gin(ikyneg, ikxneg)) + end do + end do + + end subroutine swap_kxky_back_ordered + + subroutine communicate_ktgrids_multibox + use job_manage, only: njobs + use mp, only: job, scope, & + crossdomprocs, subprocs, & + send, receive + use parameters_kxky_grids, only: phase_shift_angle + + implicit none + + call scope(crossdomprocs) + + if (job == 1) then + call send(phase_shift_angle, 0, 120) + call send(phase_shift_angle, njobs - 1, 130) + elseif (job == 0) then + call receive(phase_shift_angle, 1, 120) + elseif (job == njobs - 1) then + call receive(phase_shift_angle, 1, 130) + end if + + call scope(subprocs) + + end subroutine communicate_ktgrids_multibox + + subroutine multiply_by_rho(gin) + + use stella_transforms, only: transform_kx2x_unpadded, transform_x2kx_unpadded + ! use stella_transforms, only: transform_kx2x_xfirst, transform_x2kx_xfirst + use grids_kxky, only: rho_d_clamped, zonal_mode, g0x + use parameters_kxky_grids, only: nakx, naky + implicit none + + complex, dimension(:, :), intent(inout) :: gin + + if (.not. allocated(g0x)) allocate (g0x(naky, nakx)) + + call transform_kx2x_unpadded(gin, g0x) + g0x = spread(rho_d_clamped, 1, naky) * g0x + if (zonal_mode(1)) g0x(1, :) = real(g0x(1, :)) + call transform_x2kx_unpadded(g0x, gin) + + ! if(.not.allocated(g0x)) allocate(g0x(naky,nx)) + + ! call transform_kx2x_xfirst(gin,g0x) + ! g0x = spread(rho_clamped,1,naky)*g0x + ! if(zonal_mode(1)) g0x(1,:) = real(g0x(1,:)) + ! call transform_x2kx_xfirst(g0x,gin) + + end subroutine multiply_by_rho + +end module calculations_kxky diff --git a/debug_flags.f90 b/debug_flags.f90 new file mode 100644 index 0000000000..b43961e14f --- /dev/null +++ b/debug_flags.f90 @@ -0,0 +1,241 @@ +!############################################################################### +!############################### READ DEBUG FLAGS ############################## +!############################################################################### +! Namelist: &debug_flags +! These flags will allow you to toggle the debug flags in each file of stella. +! If you would like to debug a specific file then the corresponding flag to turn +! the debug messages in that file will be . +! As an example, if you want to debug the fields.fpp debug flags then the +! corresponding debug flag in the input file will be . +! If you would like all the debug flags on in every file then simply set +! in the input file; this will set every debug flag to true +!############################################################################### +module debug_flags + + implicit none + + !> Publuc routines + public :: read_debug_flags + + !> Public debug flags + public :: stella_debug + + public :: fields_debug + + public :: time_advance_debug + public :: implicit_solve_debug + public :: parallel_streaming_debug + public :: response_matrix_debug + public :: mirror_terms_debug + public :: neoclassical_terms_debug + + public :: extended_grid_debug + + public :: diagnostics_main_debug + public :: diagnostics_parameters + public :: diagnostics_fluxes_fluxtube_debug + public :: diagnostics_omega_debug + public :: fluxes_debug + + public :: geometry_debug + + public :: dist_fn_debug + public :: gyro_averages_debug + !> Debug flags for full flux surface + public :: ffs_solve_debug + !> Debug flug for debugging full flux surface + !> This will set the geometry of all field lines to be equation to + !> the geometry on alpha = 0 (i.e. the first field line) + public :: const_alpha_geo + + private + + logical :: debug_all + !> Main stella file debug flag + logical :: stella_debug + !> Fields debug flags + logical :: fields_debug + !> Gyrokinetic terms, debug flags + logical :: time_advance_debug + logical :: implicit_solve_debug + logical :: parallel_streaming_debug + logical :: response_matrix_debug + logical :: mirror_terms_debug + logical :: neoclassical_terms_debug + logical :: extended_grid_debug + + !> Diagnostics debug flags + logical :: diagnostics_debug + logical :: diagnostics_parameters + logical :: diagnostics_fluxes_fluxtube_debug + logical :: diagnostics_omega_debug + logical :: diagnostics_main_debug + logical :: fluxes_debug + + logical :: geometry_debug + + logical :: dist_fn_debug + logical :: gyro_averages_debug + !> For FFS + logical :: ffs_solve_debug + logical :: const_alpha_geo + + logical :: initialised = .false. + +contains + + !====================================================================== + !========================= READ DEBUG FLAGS ========================== + !====================================================================== + subroutine read_debug_flags + + use mp, only: proc0 + + implicit none + + namelist /debug_flags/ debug_all, stella_debug, ffs_solve_debug, fields_debug, & + implicit_solve_debug, parallel_streaming_debug, mirror_terms_debug, neoclassical_terms_debug, & + response_matrix_debug, time_advance_debug, extended_grid_debug, & + diagnostics_debug, diagnostics_parameters, diagnostics_fluxes_fluxtube_debug, & + diagnostics_omega_debug, diagnostics_main_debug, dist_fn_debug,& + gyro_averages_debug, fluxes_debug, geometry_debug, const_alpha_geo + + if (initialised) return + initialised = .true. + + if (proc0) call set_default_parameters + if (proc0) call read_input_file + call broadcast_parameters + + + contains + + !********************************************************************** + ! SET DEFAULT PARAMETERS ! + !********************************************************************** + ! If not specified in the input file these are the default options that + ! will be set for all parameters under the namelist + ! &debug_flags'. + ! The default here is that all debug flags are set to .false. + !********************************************************************** + subroutine set_default_parameters + + implicit none + + stella_debug = .false. + ffs_solve_debug = .false. + fields_debug = .false. + implicit_solve_debug = .false. + mirror_terms_debug = .false. + neoclassical_terms_debug = .false. + parallel_streaming_debug = .false. + response_matrix_debug = .false. + time_advance_debug = .false. + + extended_grid_debug = .false. + + !> Diagnostircs debug + diagnostics_debug = .false. + diagnostics_main_debug = .false. + diagnostics_parameters = .false. + diagnostics_omega_debug = .false. + diagnostics_fluxes_fluxtube_debug = .false. + fluxes_debug = .false. + + geometry_debug = .false. + + dist_fn_debug = .false. + gyro_averages_debug = .false. + !################################### + ! FOR THE PURPOSE OF DEBUGGING + !################################### + const_alpha_geo = .false. + + end subroutine set_default_parameters + + !********************************************************************** + ! READ INPUT OPTIONS ! + !********************************************************************** + ! Overwrite any default options with those specified in the input file. + ! Then change the other parameters consistently. + !********************************************************************** + subroutine read_input_file + + use file_utils, only: input_unit, error_unit, input_unit_exist + + implicit none + + integer :: in_file + logical :: nml_exist + + !> Overwrite the default input parameters by those specified in the input file + !> under the heading '&numerical' + in_file = input_unit_exist("debug_flags", nml_exist) + if (nml_exist) read (unit=in_file, nml=debug_flags) + + if(debug_all) then + stella_debug = .true. + ffs_solve_debug = .true. + fields_debug = .true. + time_advance_debug = .true. + implicit_solve_debug = .true. + parallel_streaming_debug = .true. + response_matrix_debug = .true. + mirror_terms_debug = .true. + neoclassical_terms_debug = .true. + extended_grid_debug = .true. + !> Set all diagnostics flags to be on + diagnostics_debug = .true. + + dist_fn_debug = .true. + gyro_averages_debug = .true. + geometry_debug = .true. + end if + + if(diagnostics_debug) then + diagnostics_main_debug = .true. + diagnostics_parameters = .true. + diagnostics_fluxes_fluxtube_debug = .true. + diagnostics_omega_debug = .true. + fluxes_debug = .true. + end if + end subroutine read_input_file + + !********************************************************************** + ! BROADCAST OPTIONS ! + !********************************************************************** + ! Broadcast these parameters to all the processors - necessary because + ! the above was only done for the first processor (proc0). + !********************************************************************** + subroutine broadcast_parameters + + use mp, only: broadcast + + call broadcast(stella_debug) + + call broadcast(ffs_solve_debug) + call broadcast(fields_debug) + call broadcast(implicit_solve_debug) + call broadcast(mirror_terms_debug) + call broadcast(neoclassical_terms_debug) + call broadcast(parallel_streaming_debug) + call broadcast(response_matrix_debug) + call broadcast(diagnostics_main_debug) + call broadcast(diagnostics_parameters) + call broadcast(diagnostics_fluxes_fluxtube_debug) + call broadcast(diagnostics_omega_debug) + call broadcast(time_advance_debug) + call broadcast(extended_grid_debug) + + call broadcast(dist_fn_debug) + call broadcast(gyro_averages_debug) + + call broadcast(fluxes_debug) + call broadcast(geometry_debug) + call broadcast(const_alpha_geo) + + end subroutine broadcast_parameters + + end subroutine read_debug_flags + +end module debug_flags diff --git a/diagnostics/diagnostics.f90 b/diagnostics/diagnostics.f90 index 25be8e8a42..15fb8eb39a 100644 --- a/diagnostics/diagnostics.f90 +++ b/diagnostics/diagnostics.f90 @@ -1,6 +1,9 @@ ! Routines for calculating and writing various physical diagnostics. module diagnostics + ! Debug Flags + use debug_flags, only: debug => diagnostics_main_debug + implicit none public :: diagnostics_stella, init_diagnostics, finish_diagnostics @@ -27,15 +30,15 @@ module diagnostics subroutine diagnostics_stella(istep) ! Data - use fields_arrays, only: phi, apar, bpar - use dist_fn_arrays, only: gnew + use arrays_fields, only: phi, apar, bpar + use arrays_dist_fn, only: gnew use fields, only: advance_fields use constants, only: zi ! Flags - use physics_flags, only: radial_variation + use parameters_physics, only: radial_variation use fields, only: fields_updated - use parameters_diagnostics, only: nc_mult, nwrite, debug + use parameters_diagnostics, only: nc_mult, nwrite ! Write data use diagnostics_omega, only: write_omega_to_netcdf_file, calculate_omega @@ -124,9 +127,9 @@ end subroutine diagnostics_stella subroutine init_diagnostics(restart, tstart, git_commit, git_date) use zgrid, only: init_zgrid - use kt_grids, only: init_kt_grids - use physics_parameters, only: init_physics_parameters - use run_parameters, only: init_run_parameters + use grids_kxky, only: init_grids_kxky + use parameters_physics, only: read_parameters_physics + use parameters_numerical, only: read_parameters_numerical use species, only: init_species use dist_fn, only: init_dist_fn use init_g, only: init_init_g @@ -155,9 +158,9 @@ subroutine init_diagnostics(restart, tstart, git_commit, git_date) ! Should have been taken care off in the subroutine in the module. ! Nonetheless, make sure that the other routines are intialized. call init_zgrid - call init_physics_parameters - call init_kt_grids - call init_run_parameters + call read_parameters_physics + call init_grids_kxky + call read_parameters_numerical call init_species call init_init_g call init_dist_fn @@ -186,7 +189,7 @@ subroutine finish_diagnostics(istep) use stella_time, only: code_dt, code_time use stella_save, only: stella_save_for_restart use dist_redistribute, only: kxkyz2vmu - use dist_fn_arrays, only: gnew, gvmu + use arrays_dist_fn, only: gnew, gvmu use diagnostics_omega, only: finish_diagnostics_omega use diagnostics_fluxes, only: finish_diagnostics_fluxes use diagnostics_potential, only: finish_diagnostics_potential diff --git a/diagnostics/diagnostics_distribution.f90 b/diagnostics/diagnostics_distribution.f90 index a6ea901f4a..97880b46dc 100644 --- a/diagnostics/diagnostics_distribution.f90 +++ b/diagnostics/diagnostics_distribution.f90 @@ -16,6 +16,9 @@ module diagnostics_distribution private + ! Debugging + logical :: debug = .false. + contains !############################################################################### @@ -28,16 +31,16 @@ module diagnostics_distribution subroutine write_distribution_to_netcdf_file(nout, timer) ! Data - use dist_fn_arrays, only: gnew, gvmu - use fields_arrays, only: phi, bpar - use run_parameters, only: fphi + use arrays_dist_fn, only: gnew, gvmu + use arrays_fields, only: phi, bpar + use parameters_numerical, only: fphi ! Redistribute data from i[vpa,mu,s] to i[kx,ky,z,s] use redistribute, only: scatter use dist_redistribute, only: kxkyz2vmu ! Dimensions - use kt_grids, only: nakx, naky + use parameters_kxky_grids, only: nakx, naky use vpamu_grids, only: nvpa, nmu use zgrid, only: nztot, ntubes use species, only: nspec @@ -80,7 +83,6 @@ subroutine write_distribution_to_netcdf_file(nout, timer) use parameters_diagnostics, only: write_g2_vs_zmus use parameters_diagnostics, only: write_g2_vs_kxkyzs use parameters_diagnostics, only: write_g2_vs_zvpamus - use parameters_diagnostics, only: debug ! Routines use g_tofrom_h, only: g_to_f, g_to_h @@ -228,11 +230,11 @@ subroutine calculate_distribution(g_vs_kykxztube, g_vs_vpamuikxkyzs, g2_vs_tzmus use geometry, only: dl_over_b ! Dimensions - use kt_grids, only: zonal_mode + use grids_kxky, only: zonal_mode use volume_averages, only: mode_fac use zgrid, only: nzgrid, ntubes use vpamu_grids, only: nvpa, nmu - use kt_grids, only: nakx, naky + use parameters_kxky_grids, only: nakx, naky ! Calculations use vpamu_grids, only: integrate_vpa, integrate_mu, integrate_vmu @@ -248,7 +250,6 @@ subroutine calculate_distribution(g_vs_kykxztube, g_vs_vpamuikxkyzs, g2_vs_tzmus use parameters_diagnostics, only: write_g2_vs_zmus use parameters_diagnostics, only: write_g2_vs_kxkyzs use parameters_diagnostics, only: write_g2_vs_zvpamus - use parameters_diagnostics, only: debug implicit none diff --git a/diagnostics/diagnostics_fluxes.f90 b/diagnostics/diagnostics_fluxes.f90 index 31848cfd34..d52823112d 100644 --- a/diagnostics/diagnostics_fluxes.f90 +++ b/diagnostics/diagnostics_fluxes.f90 @@ -10,9 +10,11 @@ ! The heat flux is denoted by qflux. ! !############################################################################### - -module diagnostics_fluxes +module diagnostics_fluxes + + use debug_flags, only: debug => fluxes_debug + implicit none public :: init_diagnostics_fluxes @@ -38,22 +40,22 @@ module diagnostics_fluxes !================= CALCULATE AND WRITE FLUXES TO NETCDF FILE ================ !============================================================================ subroutine write_fluxes_to_netcdf_file(nout, timer, write_to_netcdf_file) + + ! Knowledge of first processor + use mp, only: proc0 ! Dimensions - use kt_grids, only: naky, nakx + use parameters_kxky_grids, only: naky, nakx use zgrid, only: nztot, ntubes use species, only: nspec ! Flags - use physics_flags, only: radial_variation - use physics_flags, only: full_flux_surface - - ! Input file + use parameters_physics, only: radial_variation + use parameters_physics, only: full_flux_surface use parameters_diagnostics, only: write_fluxes_vs_time use parameters_diagnostics, only: write_fluxes_kxkyz use parameters_diagnostics, only: write_fluxes_kxky use parameters_diagnostics, only: write_radial_fluxes - use parameters_diagnostics, only: debug ! Routines use job_manage, only: time_message @@ -75,7 +77,10 @@ subroutine write_fluxes_to_netcdf_file(nout, timer, write_to_netcdf_file) real, dimension(:, :, :), allocatable :: pflux_vs_kxkys, vflux_vs_kxkys, qflux_vs_kxkys !---------------------------------------------------------------------- - + ! Debugging + debug = debug .and. proc0 + !---------------------------------------------------------------------- + ! Start timer if (proc0) call time_message(.false., timer(:), 'Write fluxes') @@ -174,12 +179,12 @@ end subroutine write_fluxes_to_netcdf_file subroutine write_fluxes_for_fluxtube(pflux_vs_kxkyzts, vflux_vs_kxkyzts, qflux_vs_kxkyzts, pflux_vs_kxkys, vflux_vs_kxkys, qflux_vs_kxkys) ! Flags - use physics_flags, only: include_apar, include_bpar + use parameters_physics, only: include_apar, include_bpar ! Load data - use dist_fn_arrays, only: gnew, gvmu - use fields_arrays, only: phi, bpar - use run_parameters, only: fphi + use arrays_dist_fn, only: gnew, gvmu + use arrays_fields, only: phi, bpar + use parameters_numerical, only: fphi ! Redistribute data from i[vpa,mu,s] to i[kx,ky,z,s] use redistribute, only: scatter @@ -236,15 +241,14 @@ subroutine write_fluxes_for_fluxtube_radialvariation(nout, pflux_vs_kxkyzts, vfl ! Input file use parameters_diagnostics, only: write_radial_fluxes - use parameters_diagnostics, only: debug ! Data - use fields_arrays, only: phi, phi_corr_QN - use physics_flags, only: radial_variation - use dist_fn_arrays, only: gnew + use arrays_fields, only: phi, phi_corr_QN + use parameters_physics, only: radial_variation + use arrays_dist_fn, only: gnew ! Dimensions - use kt_grids, only: nakx, naky + use parameters_kxky_grids, only: nakx, naky use zgrid, only: nzgrid, ntubes use species, only: nspec @@ -307,10 +311,10 @@ end subroutine write_fluxes_for_fluxtube_radialvariation subroutine write_fluxes_for_fullfluxsurface(pflux_vs_kxkyzts, vflux_vs_kxkyzts, qflux_vs_kxkyzts) ! Data - use dist_fn_arrays, only: gnew + use arrays_dist_fn, only: gnew ! Dimensions - use kt_grids, only: ny, ikx_max + use parameters_kxky_grids, only: ny, ikx_max use species, only: nspec use zgrid, only: nzgrid @@ -447,6 +451,9 @@ subroutine init_diagnostics_fluxes(restart) !---------------------------------------------------------------------- + ! Only debug on the first processor + debug = debug .and. proc0 + ! Allocate the arrays for the fluxes ! These are needed on all processors since will add data to it from each processor allocate (qflux_vs_s(nspec)); qflux_vs_s = 0. diff --git a/diagnostics/diagnostics_fluxes_fluxtube.f90 b/diagnostics/diagnostics_fluxes_fluxtube.f90 index ace6abf7d4..4d50f18f93 100644 --- a/diagnostics/diagnostics_fluxes_fluxtube.f90 +++ b/diagnostics/diagnostics_fluxes_fluxtube.f90 @@ -48,6 +48,8 @@ module diagnostics_fluxes_fluxtube + use debug_flags, only: debug => diagnostics_fluxes_fluxtube_debug + implicit none public :: calculate_fluxes_fluxtube @@ -95,16 +97,15 @@ subroutine calculate_fluxes_fluxtube(df_vs_vpamuikxkyzs, pflux_vs_s, vflux_vs_s, pflux_vs_kxkyzts, vflux_vs_kxkyzts, qflux_vs_kxkyzts, pflux_vs_kxkys, vflux_vs_kxkys, qflux_vs_kxkys) ! Flags - use physics_flags, only: include_apar, include_bpar + use parameters_physics, only: include_apar, include_bpar ! Input file use parameters_diagnostics, only: write_fluxes_kxkyz use parameters_diagnostics, only: write_fluxes_kxky - use parameters_diagnostics, only: debug ! Data - use fields_arrays, only: phi, apar, bpar - use run_parameters, only: fphi, fapar + use arrays_fields, only: phi, apar, bpar + use parameters_numerical, only: fphi ! Geometry use geometry, only: bmag, btor, gds2, gds21, gds22, geo_surf @@ -116,7 +117,7 @@ subroutine calculate_fluxes_fluxtube(df_vs_vpamuikxkyzs, pflux_vs_s, vflux_vs_s, use vpamu_grids, only: vperp2, vpa, mu use vpamu_grids, only: nvpa, nmu use zgrid, only: nzgrid, ntubes - use kt_grids, only: aky, theta0 + use grids_kxky, only: aky, theta0 use species, only: spec, nspec ! Calculations @@ -374,7 +375,7 @@ subroutine get_one_flux(iky, iz, norm, velocityintegrand_vs_vpamu, phi, flux_out use vpamu_grids, only: integrate_vmu use volume_averages, only: mode_fac use geometry, only: flux_fac - use kt_grids, only: aky + use grids_kxky, only: aky implicit none diff --git a/diagnostics/diagnostics_fluxes_fullfluxsurface.f90 b/diagnostics/diagnostics_fluxes_fullfluxsurface.f90 index 2cc5a2cab2..43460daa7c 100644 --- a/diagnostics/diagnostics_fluxes_fullfluxsurface.f90 +++ b/diagnostics/diagnostics_fluxes_fullfluxsurface.f90 @@ -13,9 +13,6 @@ module diagnostics_fluxes_fullfluxsurface private - ! Debugging - logical :: debug = .false. - contains !############################################################################### @@ -33,9 +30,9 @@ subroutine calculate_fluxes_fullfluxsurface(dens, upar, pres, pflux_vs_s, & use constants, only: zi use zgrid, only: nzgrid, delzed - use kt_grids, only: naky, nakx, ny - use kt_grids, only: aky, dy - use fields_arrays, only: phi + use parameters_kxky_grids, only: naky, nakx, ny + use grids_kxky, only: aky, dy + use arrays_fields, only: phi use geometry, only: grad_x, jacob implicit none @@ -45,7 +42,6 @@ subroutine calculate_fluxes_fullfluxsurface(dens, upar, pres, pflux_vs_s, & real, dimension(:, :, -nzgrid:, :, :), intent(out) :: pflux_kxkyzts, vflux_kxkyzts, qflux_kxkyzts integer :: iky, it - integer :: iy, iz real, dimension(:, :), allocatable :: flxfac complex, dimension(:, :, :), allocatable :: dphidy @@ -89,8 +85,8 @@ end subroutine calculate_fluxes_fullfluxsurface subroutine get_one_flux_ffs(mom, dphidy, flxfac, flx, flx_vs_kxkyz) use species, only: nspec - use zgrid, only: nzgrid, delzed - use kt_grids, only: naky, nakx + use zgrid, only: nzgrid + use parameters_kxky_grids, only: naky, nakx use volume_averages, only: mode_fac implicit none @@ -103,7 +99,6 @@ subroutine get_one_flux_ffs(mom, dphidy, flxfac, flx, flx_vs_kxkyz) integer :: iky, ikx, iz, is complex, dimension(:, :, :, :), allocatable :: mom_ky - complex, dimension (:,:), allocatable :: flx_x allocate (mom_ky(naky, nakx, -nzgrid:nzgrid, nspec)) @@ -146,9 +141,8 @@ subroutine get_modified_fourier_coefficient(moment, moment_ky, flxfac) use species, only: nspec use zgrid, only: nzgrid - use kt_grids, only: ikx_max, naky_all, ny - use kt_grids, only: swap_kxky_back - use geometry, only: bmag + use parameters_kxky_grids, only: ikx_max, naky_all, ny + use calculations_kxky, only: swap_kxky_back use stella_transforms, only: transform_y2ky implicit none @@ -192,18 +186,18 @@ subroutine calculate_moments_fullfluxsurface(g, dens, upar, pres) use zgrid, only: nzgrid use vpamu_grids, only: integrate_vmu_ffs use vpamu_grids, only: vpa, vperp2 - use kt_grids, only: naky_all, ikx_max, ny - use kt_grids, only: swap_kxky - use dist_fn_arrays, only: g0, g1, g2 + use parameters_kxky_grids, only: naky_all, ikx_max, ny + use calculations_kxky, only: swap_kxky + use arrays_dist_fn, only: g0, g1, g2 use gyro_averages, only: gyro_average, j0_ffs - use fields_arrays, only: phi + use arrays_fields, only: phi use stella_transforms, only: transform_ky2y - use kt_grids, only: akx, aky - use kt_grids, only: nakx, theta0, naky + use grids_kxky, only: aky, theta0 + use parameters_kxky_grids, only: nakx use constants, only: zi, pi use zgrid, only: ntubes - use run_parameters, only: fphi + use parameters_numerical, only: fphi use g_tofrom_h, only: g_to_h !> For momentum flux @@ -337,9 +331,9 @@ subroutine g_to_f0(g, phi, f) use gyro_averages, only: gyro_average, j0_ffs use stella_transforms, only: transform_ky2y, transform_y2ky - use kt_grids, only: swap_kxky, swap_kxky_back + use calculations_kxky, only: swap_kxky, swap_kxky_back use vpamu_grids, only: maxwell_vpa, maxwell_mu - use kt_grids, only: naky, naky_all, nakx, ikx_max, ny + use parameters_kxky_grids, only: naky, naky_all, nakx, ikx_max, ny use stella_layouts, only: iv_idx, imu_idx, is_idx implicit none @@ -404,9 +398,9 @@ subroutine g_to_f1(g, phi, f) use gyro_averages, only: gyro_average, j0_ffs use stella_transforms, only: transform_ky2y, transform_y2ky - use kt_grids, only: swap_kxky, swap_kxky_back + use calculations_kxky, only: swap_kxky, swap_kxky_back use vpamu_grids, only: maxwell_vpa, maxwell_mu - use kt_grids, only: naky, naky_all, nakx, ikx_max, ny + use parameters_kxky_grids, only: naky, naky_all, nakx, ikx_max, ny use stella_layouts, only: iv_idx, imu_idx, is_idx implicit none diff --git a/diagnostics/diagnostics_fluxes_radialvariation.f90 b/diagnostics/diagnostics_fluxes_radialvariation.f90 index e94d8003fe..b3c2b8bbd6 100644 --- a/diagnostics/diagnostics_fluxes_radialvariation.f90 +++ b/diagnostics/diagnostics_fluxes_radialvariation.f90 @@ -33,7 +33,7 @@ subroutine calculate_fluxes_radialvariation(g, phi, pflux_vs_s, vflux_vs_s, qflu use mp, only: sum_reduce use constants, only: zi - use dist_fn_arrays, only: g1, g2, kperp2, dkperp2dr + use arrays_dist_fn, only: g1, g2, kperp2, dkperp2dr use stella_layouts, only: vmu_lo use stella_layouts, only: iv_idx, imu_idx, is_idx use species, only: spec @@ -46,10 +46,12 @@ subroutine calculate_fluxes_radialvariation(g, phi, pflux_vs_s, vflux_vs_s, qflu use zgrid, only: nzgrid, ntubes use vpamu_grids, only: vperp2, vpa, mu use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac - use run_parameters, only: fphi - use run_parameters, only: maxwellian_normalization - use kt_grids, only: aky, theta0, naky, nakx, multiply_by_rho - use physics_flags, only: radial_variation + use parameters_numerical, only: fphi + use parameters_numerical, only: maxwellian_normalization + use grids_kxky, only: aky, theta0 + use parameters_kxky_grids, only: naky, nakx + use calculations_kxky, only: multiply_by_rho + use parameters_physics, only: radial_variation use gyro_averages, only: gyro_average, gyro_average_j1, aj0x, aj1x ! Flags @@ -330,13 +332,14 @@ subroutine get_one_flux_vmulo_int(weights, gin, fld, flxout) use vpamu_grids, only: integrate_vmu use stella_layouts, only: vmu_lo - use kt_grids, only: aky, nakx, naky, boundary_size + use grids_kxky, only: aky, boundary_size + use parameters_kxky_grids, only: nakx, naky use zgrid, only: nzgrid, ntubes use species, only: nspec use volume_averages, only: mode_fac use geometry, only: dVolume use stella_transforms, only: transform_kx2x_unpadded - use physics_flags, only: radial_variation + use parameters_physics, only: radial_variation implicit none @@ -408,7 +411,8 @@ subroutine get_one_flux_vmulo_kxkyz(weights, gin, fld, flxout) use vpamu_grids, only: integrate_vmu use stella_layouts, only: vmu_lo - use kt_grids, only: aky, nakx, naky + use grids_kxky, only: aky + use parameters_kxky_grids, only: nakx, naky use zgrid, only: nzgrid, ntubes use species, only: nspec use volume_averages, only: mode_fac @@ -450,7 +454,8 @@ subroutine get_one_flux_radial(weights, gin, fld, flxout) use vpamu_grids, only: integrate_vmu use geometry, only: dVolume use stella_layouts, only: vmu_lo - use kt_grids, only: aky, nakx, naky + use grids_kxky, only: aky + use parameters_kxky_grids, only: nakx, naky use zgrid, only: nzgrid, ntubes use species, only: nspec use volume_averages, only: mode_fac diff --git a/diagnostics/diagnostics_moments.f90 b/diagnostics/diagnostics_moments.f90 index c454dd8af5..3821c53af3 100644 --- a/diagnostics/diagnostics_moments.f90 +++ b/diagnostics/diagnostics_moments.f90 @@ -35,16 +35,16 @@ module diagnostics_moments subroutine write_moments_to_netcdf_file(nout, timer) ! Data - use dist_fn_arrays, only: gnew + use arrays_dist_fn, only: gnew ! Dimensions - use kt_grids, only: naky, nakx + use parameters_kxky_grids, only: naky, nakx use zgrid, only: nztot, ntubes use species, only: nspec ! Flags - use physics_flags, only: radial_variation - use physics_flags, only: full_flux_surface + use parameters_physics, only: radial_variation + use parameters_physics, only: full_flux_surface ! Write to netcdf file use stella_io, only: write_radial_moments_nc @@ -135,19 +135,20 @@ subroutine get_moments_fluxtube(g, density, upar_vs_kykxzts, temperature, spitze use species, only: spec, nspec use vpamu_grids, only: vpa, vperp2, integrate_vmu use vpamu_grids, only: maxwell_mu, ztmax, maxwell_fac, maxwell_vpa - use kt_grids, only: naky, nakx, multiply_by_rho + use parameters_kxky_grids, only: naky, nakx + use calculations_kxky, only: multiply_by_rho use stella_layouts, only: vmu_lo use stella_layouts, only: iv_idx, imu_idx, is_idx use gyro_averages, only: aj0x, gyro_average - use fields_arrays, only: phi - use run_parameters, only: fphi - use run_parameters, only: maxwellian_normalization - use physics_flags, only: radial_variation + use arrays_fields, only: phi + use parameters_numerical, only: fphi + use parameters_numerical, only: maxwellian_normalization + use parameters_physics, only: radial_variation use stella_transforms, only: transform_kx2x_unpadded ! Import temp arrays g1 and g2 with dimensions (nky, nkx, -nzgrid:nzgrid, ntubes, -vmu-layout-) - use dist_fn_arrays, only: g_gyro => g1 - use dist_fn_arrays, only: integrand => g2 + use arrays_dist_fn, only: g_gyro => g1 + use arrays_dist_fn, only: integrand => g2 implicit none @@ -258,17 +259,19 @@ subroutine get_moments_radial_variation(g, dens, upar_vs_kykxzts, temp, dens_kxs use vpamu_grids, only: integrate_vmu use vpamu_grids, only: vpa, vperp2, mu use vpamu_grids, only: maxwell_mu, ztmax, maxwell_fac, maxwell_vpa - use kt_grids, only: naky, nakx, multiply_by_rho, rho_d_clamped + use parameters_kxky_grids, only: naky, nakx + use grids_kxky, only: rho_d_clamped + use calculations_kxky, only: multiply_by_rho use stella_layouts, only: vmu_lo use stella_layouts, only: iv_idx, imu_idx, is_idx - use dist_fn_arrays, only: g1, g2, kperp2, dkperp2dr + use arrays_dist_fn, only: g1, g2, kperp2, dkperp2dr use geometry, only: bmag, dBdrho use geometry, only: dl_over_b, d_dl_over_b_drho use gyro_averages, only: aj0x, aj1x, gyro_average - use fields_arrays, only: phi, phi_corr_QN, phi_proj - use run_parameters, only: fphi - use run_parameters, only: maxwellian_normalization - use physics_flags, only: radial_variation + use arrays_fields, only: phi, phi_corr_QN, phi_proj + use parameters_numerical, only: fphi + use parameters_numerical, only: maxwellian_normalization + use parameters_physics, only: radial_variation use stella_transforms, only: transform_kx2x_unpadded ! Input file diff --git a/diagnostics/diagnostics_omega.f90 b/diagnostics/diagnostics_omega.f90 index 6dabfc7abd..c10a249ab7 100644 --- a/diagnostics/diagnostics_omega.f90 +++ b/diagnostics/diagnostics_omega.f90 @@ -14,6 +14,8 @@ module diagnostics_omega + use debug_flags, only: debug => diagnostics_omega_debug + implicit none ! These routines are called from diagnostics.f90 @@ -49,14 +51,14 @@ subroutine calculate_omega(istep, timer) use mp, only: proc0 ! Physics flags - use physics_flags, only: include_apar + use parameters_physics, only: include_apar ! Fields - use fields_arrays, only: phi, phi_old - use fields_arrays, only: apar, apar_old + use arrays_fields, only: phi, phi_old + use arrays_fields, only: apar, apar_old ! Grids - use kt_grids, only: nakx, naky + use parameters_kxky_grids, only: nakx, naky use stella_time, only: code_dt use constants, only: zi @@ -80,6 +82,8 @@ subroutine calculate_omega(istep, timer) !---------------------------------------------------------------------- + debug = debug .and. proc0 + ! We only calculate omega on the first processor and if = True if (.not. write_omega) return @@ -141,9 +145,6 @@ subroutine write_omega_to_netcdf_file(istep, nout, timer, write_to_netcdf_file) ! Write to netCDF file use stella_io, only: write_omega_nc - ! Grids - use kt_grids, only: nakx, naky - ! Parallelisation use job_manage, only: time_message use mp, only: proc0 @@ -249,7 +250,7 @@ subroutine init_diagnostics_omega(restart) use parameters_diagnostics, only: navg ! Grids - use kt_grids, only: nakx, naky + use parameters_kxky_grids, only: nakx, naky ! Multiprocessing use mp, only: proc0 @@ -284,7 +285,6 @@ subroutine finish_diagnostics_omega use parameters_diagnostics, only: write_omega_vs_kxky use file_utils, only: close_output_file - use mp, only: proc0 implicit none @@ -350,8 +350,8 @@ subroutine write_omega_to_ascii_file(istep, omega_vs_kykx, omega_runningavg_vs_k use parameters_diagnostics, only: write_omega_avg_vs_kxky use parameters_diagnostics, only: write_omega_vs_kxky use stella_time, only: code_time - use kt_grids, only: naky, nakx - use kt_grids, only: aky, akx + use parameters_kxky_grids, only: naky, nakx + use grids_kxky, only: aky, akx implicit none diff --git a/diagnostics/diagnostics_potential.f90 b/diagnostics/diagnostics_potential.f90 index 6e9912eab1..e491bc6d97 100644 --- a/diagnostics/diagnostics_potential.f90 +++ b/diagnostics/diagnostics_potential.f90 @@ -35,15 +35,15 @@ module diagnostics_potential subroutine write_potential_to_netcdf_file(istep, nout, timer, write_to_netcdf_file) ! Data - use fields_arrays, only: phi, apar, bpar, phi_corr_QN + use arrays_fields, only: phi, apar, bpar, phi_corr_QN ! Dimensions - use kt_grids, only: naky, nakx + use parameters_kxky_grids, only: naky, nakx use zgrid, only: ntubes, nzgrid ! Flags - use physics_flags, only: radial_variation - use physics_flags, only: include_apar, include_bpar + use parameters_physics, only: radial_variation + use parameters_physics, only: include_apar, include_bpar ! Calculations use volume_averages, only: volume_average, fieldline_average @@ -140,23 +140,23 @@ subroutine write_potential_to_netcdf_file(istep, nout, timer, write_to_netcdf_fi deallocate (phi2_vs_kxky) ! For apar - if (include_apar) then - allocate (apar2_vs_kxky(naky, nakx)) - call fieldline_average(real(apar_vs_kykxzt * conjg(apar_vs_kykxzt)), apar2_vs_kxky) - call write_kspectra_nc(nout, apar2_vs_kxky, "apar2_vs_kxky", "parallel vector potential") - deallocate (apar2_vs_kxky) - end if - - ! For bpar - if (include_bpar) then - allocate (bpar2_vs_kxky(naky, nakx)) - call fieldline_average(real(bpar_vs_kykxzt * conjg(bpar_vs_kykxzt)), bpar2_vs_kxky) - call write_kspectra_nc(nout, bpar2_vs_kxky, "bpar2_vs_kxky", "parallel magnetic field fluctuation") - deallocate (bpar2_vs_kxky) - end if + if (include_apar) then + allocate (apar2_vs_kxky(naky, nakx)) + call fieldline_average(real(apar_vs_kykxzt * conjg(apar_vs_kykxzt)), apar2_vs_kxky) + call write_kspectra_nc(nout, apar2_vs_kxky, "apar2_vs_kxky", "parallel vector potential") + deallocate (apar2_vs_kxky) + end if + + ! For bpar + if (include_bpar) then + allocate (bpar2_vs_kxky(naky, nakx)) + call fieldline_average(real(bpar_vs_kykxzt * conjg(bpar_vs_kykxzt)), bpar2_vs_kxky) + call write_kspectra_nc(nout, bpar2_vs_kxky, "bpar2_vs_kxky", "parallel magnetic field fluctuation") + deallocate (bpar2_vs_kxky) + end if end if - + end if @@ -239,14 +239,15 @@ end subroutine write_potential_to_ascii_file subroutine write_potential_to_ascii_file_atfinaltimestep ! Data - use fields_arrays, only: phi, apar, bpar + use arrays_fields, only: phi, apar, bpar ! Geometry - USE dist_fn_arrays, only: kperp2 + USE arrays_dist_fn, only: kperp2 use geometry, only: zed_eqarc ! Dimensions - use kt_grids, only: naky, nakx, aky, akx, zed0 + use parameters_kxky_grids, only: naky, nakx + use grids_kxky, only: aky, akx, zed0 use zgrid, only: nzgrid, ntubes, zed ! Routines diff --git a/diagnostics/parameters_diagnostics.f90 b/diagnostics/parameters_diagnostics.f90 index 06c185b06f..ac20298483 100644 --- a/diagnostics/parameters_diagnostics.f90 +++ b/diagnostics/parameters_diagnostics.f90 @@ -1,10 +1,9 @@ module parameters_diagnostics + use debug_flags, only: debug => diagnostics_parameters + implicit none - - ! Turn debugging on the diagnostics module - public :: debug - + ! Routine to read "diagnostics_knobs" in the input file public :: read_diagnostics_knobs @@ -47,9 +46,6 @@ module parameters_diagnostics public :: write_moments private - - ! Debugging - logical :: debug ! Variables used to write diagnostics integer :: nwrite, nsave, navg, nc_mult @@ -113,10 +109,6 @@ subroutine read_diagnostics_knobs if (proc0) call read_input_file call broadcast_parameters - ! Debugging on first processor - debug = .false. - if (proc0) debug = .false. - contains @@ -128,8 +120,8 @@ subroutine read_diagnostics_knobs !********************************************************************** subroutine set_default_parameters - use physics_flags, only: radial_variation - use physics_flags, only: nonlinear + use parameters_physics, only: radial_variation + use parameters_physics, only: nonlinear implicit none @@ -245,7 +237,7 @@ end subroutine set_default_parameters subroutine read_input_file use file_utils, only: input_unit_exist - use physics_flags, only: nonlinear + use parameters_physics, only: nonlinear implicit none diff --git a/dissipation/coll_dougherty.f90 b/dissipation/coll_dougherty.f90 index 7794e6dce2..c0dd2685a0 100644 --- a/dissipation/coll_dougherty.f90 +++ b/dissipation/coll_dougherty.f90 @@ -107,7 +107,7 @@ subroutine init_vpadiff_matrix use stella_layouts, only: kxkyz_lo use stella_layouts, only: iky_idx, ikx_idx, iz_idx, is_idx use geometry, only: bmag - use dist_fn_arrays, only: kperp2 + use arrays_dist_fn, only: kperp2 implicit none @@ -150,7 +150,7 @@ subroutine init_mudiff_matrix use vpamu_grids, only: dmu_cell, mu_cell, wgts_mu_bare use stella_layouts, only: kxkyz_lo use stella_layouts, only: iky_idx, ikx_idx, iz_idx, is_idx - use dist_fn_arrays, only: kperp2 + use arrays_dist_fn, only: kperp2 implicit none @@ -211,15 +211,16 @@ subroutine init_vpadiff_conserve use vpamu_grids, only: ztmax, maxwell_vpa, maxwell_mu use vpamu_grids, only: nmu, vpa, vperp2 use vpamu_grids, only: set_vpa_weights - use kt_grids, only: naky, nakx, zonal_mode + use parameters_kxky_grids, only: naky, nakx + use grids_kxky, only: zonal_mode use stella_layouts, only: kxkyz_lo use stella_layouts, only: iky_idx, ikx_idx, iz_idx, it_idx, is_idx use geometry, only: dl_over_b - use dist_fn_arrays, only: gvmu + use arrays_dist_fn, only: gvmu use gyro_averages, only: aj0v use fields, only: get_fields, get_fields_by_spec, efac, gamtot_h - use physics_flags, only: adiabatic_option_switch - use physics_flags, only: adiabatic_option_fieldlineavg + use parameters_physics, only: adiabatic_option_switch + use parameters_physics, only: adiabatic_option_fieldlineavg implicit none @@ -465,15 +466,16 @@ subroutine init_mudiff_conserve use zgrid, only: nzgrid, ntubes use vpamu_grids, only: ztmax, maxwell_vpa, maxwell_mu use vpamu_grids, only: nvpa, vpa, vperp2 - use kt_grids, only: naky, nakx, zonal_mode + use parameters_kxky_grids, only: naky, nakx + use grids_kxky, only: zonal_mode use geometry, only: dl_over_b, bmag use stella_layouts, only: kxkyz_lo use stella_layouts, only: iky_idx, ikx_idx, iz_idx, it_idx, is_idx - use dist_fn_arrays, only: gvmu, kperp2 + use arrays_dist_fn, only: gvmu, kperp2 use gyro_averages, only: aj0v, aj1v use fields, only: get_fields, get_fields_by_spec, efac, gamtot_h - use physics_flags, only: adiabatic_option_switch - use physics_flags, only: adiabatic_option_fieldlineavg + use parameters_physics, only: adiabatic_option_switch + use parameters_physics, only: adiabatic_option_fieldlineavg implicit none @@ -910,17 +912,19 @@ subroutine advance_collisions_dougherty_explicit(g, phi, bpar, gke_rhs, time_col use stella_time, only: code_dt use zgrid, only: nzgrid, ntubes use species, only: spec - use run_parameters, only: fphi - use physics_flags, only: radial_variation, full_flux_surface - use kt_grids, only: naky, nakx, multiply_by_rho, rho_d_clamped + use parameters_numerical, only: fphi + use parameters_physics, only: radial_variation, full_flux_surface + use parameters_kxky_grids, only: naky, nakx + use grids_kxky, only: rho_d_clamped + use calculations_kxky, only: multiply_by_rho use vpamu_grids, only: nvpa, nmu use vpamu_grids, only: set_vpa_weights use geometry, only: bmag, dBdrho use stella_layouts, only: vmu_lo, kxkyz_lo use stella_layouts, only: is_idx, iky_idx, ikx_idx, iz_idx use dist_redistribute, only: kxkyz2vmu - use dist_fn_arrays, only: gvmu, kperp2, dkperp2dr - use fields_arrays, only: phi_corr_QN + use arrays_dist_fn, only: gvmu, kperp2, dkperp2dr + use arrays_fields, only: phi_corr_QN use g_tofrom_h, only: g_to_h use stella_transforms, only: transform_kx2x_unpadded, transform_x2kx_unpadded @@ -1187,7 +1191,7 @@ subroutine conserve_momentum(iky, ikx, iz, is, ikxkyz, h, Ch) use vpamu_grids, only: vpa, nvpa, nmu, vperp2 use vpamu_grids, only: maxwell_vpa, maxwell_mu ! use vpamu_grids, only: int_vpa2 - use dist_fn_arrays, only: kperp2 + use arrays_dist_fn, only: kperp2 use gyro_averages, only: aj0v, aj1v implicit none @@ -1271,13 +1275,14 @@ subroutine conserve_momentum_vmulo(h, gke_rhs) use stella_layouts, only: vmu_lo use stella_layouts, only: imu_idx, iv_idx, is_idx use species, only: spec - use physics_flags, only: radial_variation + use parameters_physics, only: radial_variation use geometry, only: bmag, dBdrho - use kt_grids, only: nakx, naky, multiply_by_rho + use parameters_kxky_grids, only: nakx, naky + use calculations_kxky, only: multiply_by_rho use zgrid, only: nzgrid, ntubes use vpamu_grids, only: integrate_species, mu, vpa, vperp2 use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac - use dist_fn_arrays, only: kperp2, dkperp2dr + use arrays_dist_fn, only: kperp2, dkperp2dr use gyro_averages, only: gyro_average, gyro_average_j1, aj0x, aj1x implicit none @@ -1405,14 +1410,15 @@ subroutine conserve_energy_vmulo(h, gke_rhs) use stella_layouts, only: vmu_lo use stella_layouts, only: imu_idx, iv_idx, is_idx use species, only: spec - use physics_flags, only: radial_variation + use parameters_physics, only: radial_variation use geometry, only: bmag, dBdrho - use kt_grids, only: nakx, naky, multiply_by_rho + use parameters_kxky_grids, only: nakx, naky + use calculations_kxky, only: multiply_by_rho use zgrid, only: nzgrid, ntubes use vpamu_grids, only: integrate_species use vpamu_grids, only: mu, vpa, nmu, vperp2 use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac - use dist_fn_arrays, only: kperp2, dkperp2dr + use arrays_dist_fn, only: kperp2, dkperp2dr use gyro_averages, only: gyro_average, gyro_average_j1, aj0x, aj1x implicit none @@ -1506,7 +1512,7 @@ end subroutine conserve_energy_vmulo subroutine advance_collisions_dougherty_implicit(phi, apar, bpar) use zgrid, only: nzgrid - use dist_fn_arrays, only: gvmu + use arrays_dist_fn, only: gvmu implicit none @@ -1523,21 +1529,22 @@ subroutine advance_vpadiff_implicit(phi, apar, bpar, g) use finite_differences, only: tridag use linear_solve, only: lu_back_substitution use stella_time, only: code_dt - use run_parameters, only: fphi + use parameters_numerical, only: fphi use species, only: nspec, spec, has_electron_species use zgrid, only: nzgrid, ntubes use vpamu_grids, only: nmu, nvpa use vpamu_grids, only: maxwell_vpa, maxwell_mu, vpa, vperp2 use vpamu_grids, only: set_vpa_weights - use kt_grids, only: naky, nakx, zonal_mode + use parameters_kxky_grids, only: naky, nakx + use grids_kxky, only: zonal_mode use geometry, only: dl_over_b use stella_layouts, only: kxkyz_lo use stella_layouts, only: iky_idx, ikx_idx, iz_idx, it_idx, is_idx use g_tofrom_h, only: g_to_h use gyro_averages, only: aj0v use fields, only: get_fields, efac, gamtot_h - use physics_flags, only: adiabatic_option_switch - use physics_flags, only: adiabatic_option_fieldlineavg + use parameters_physics, only: adiabatic_option_switch + use parameters_physics, only: adiabatic_option_fieldlineavg implicit none @@ -1687,22 +1694,23 @@ subroutine advance_mudiff_implicit(phi, apar, bpar, g) use finite_differences, only: tridag use linear_solve, only: lu_back_substitution use stella_time, only: code_dt - use run_parameters, only: fphi + use parameters_numerical, only: fphi use species, only: nspec, spec, has_electron_species use zgrid, only: nzgrid, ntubes use vpamu_grids, only: nmu, nvpa use vpamu_grids, only: maxwell_vpa, maxwell_mu, vpa, vperp2 use vpamu_grids, only: set_vpa_weights - use kt_grids, only: naky, nakx, zonal_mode + use parameters_kxky_grids, only: naky, nakx + use grids_kxky, only: zonal_mode use stella_layouts, only: kxkyz_lo use stella_layouts, only: iky_idx, ikx_idx, iz_idx, it_idx, is_idx - use dist_fn_arrays, only: kperp2 + use arrays_dist_fn, only: kperp2 use gyro_averages, only: aj0v, aj1v use g_tofrom_h, only: g_to_h use fields, only: get_fields, efac, gamtot_h use geometry, only: bmag, dl_over_b - use physics_flags, only: adiabatic_option_switch - use physics_flags, only: adiabatic_option_fieldlineavg + use parameters_physics, only: adiabatic_option_switch + use parameters_physics, only: adiabatic_option_fieldlineavg ! TMP FOR TESTING ! use vpamu_grids, only: mu diff --git a/dissipation/coll_fokkerplanck.f90 b/dissipation/coll_fokkerplanck.f90 index 2f228b41ea..5d363fd980 100644 --- a/dissipation/coll_fokkerplanck.f90 +++ b/dissipation/coll_fokkerplanck.f90 @@ -61,7 +61,7 @@ module coll_fokkerplanck subroutine read_parameters_fp use file_utils, only: input_unit_exist - use physics_flags, only: full_flux_surface, radial_variation + use parameters_physics, only: full_flux_surface, radial_variation use mp, only: proc0, broadcast implicit none @@ -158,7 +158,7 @@ subroutine init_collisions_fp(collisions_implicit, cfl_dt_vpadiff, cfl_dt_mudiff use vpamu_grids, only: dvpa, dmu, mu, nmu use geometry, only: bmag use stella_layouts - use run_parameters, only: fully_explicit + use parameters_numerical, only: fully_explicit use common_types, only: spec_type implicit none @@ -346,11 +346,11 @@ subroutine init_fp_diffmatrix use stella_layouts, only: kxkyz_lo use stella_layouts, only: iky_idx, ikx_idx, iz_idx, is_idx use geometry, only: bmag - use dist_fn_arrays, only: kperp2 - use physics_parameters, only: zeff + use arrays_dist_fn, only: kperp2 + use parameters_physics, only: zeff use constants, only: pi use common_types, only: spec_type - use kt_grids, only: naky, nakx + use parameters_kxky_grids, only: naky, nakx use spfunc, only: erf => erf_ext use file_utils, only: open_output_file, close_output_file @@ -1599,8 +1599,8 @@ subroutine init_bessel_fn use gyro_averages, only: aj0v use species, only: spec, nspec use geometry, only: bmag - use kt_grids, only: naky, nakx - use dist_fn_arrays, only: kperp2 + use parameters_kxky_grids, only: naky, nakx + use arrays_dist_fn, only: kperp2 use file_utils, only: open_output_file, close_output_file implicit none @@ -1964,7 +1964,7 @@ subroutine init_deltaj_vmu use constants, only: pi use stella_layouts, only: kxkyz_lo, iky_idx, ikx_idx, iz_idx, is_idx, it_idx use stella_time, only: code_dt - use kt_grids, only: naky + use parameters_kxky_grids, only: naky implicit none @@ -2558,9 +2558,9 @@ subroutine init_fp_conserve use species, only: nspec use zgrid, only: nzgrid, ntubes use vpamu_grids, only: ztmax, maxwell_mu, nmu, nvpa, set_vpa_weights - use kt_grids, only: naky, nakx + use parameters_kxky_grids, only: naky, nakx use stella_layouts, only: kxkyz_lo, iky_idx, ikx_idx, iz_idx, is_idx, it_idx - use dist_fn_arrays, only: gvmu + use arrays_dist_fn, only: gvmu use fields, only: get_fields, get_fields_by_spec_idx use job_manage, only: time_message, timer_local use file_utils, only: open_output_file, close_output_file @@ -2899,7 +2899,6 @@ subroutine get_psi_response(ll, mm, jj, isa, response) use zgrid, only: ntubes use vpamu_grids, only: nmu, nvpa use vpamu_grids, only: set_vpa_weights - use kt_grids, only: naky, nakx use stella_layouts, only: kxkyz_lo use stella_layouts, only: iky_idx, ikx_idx, iz_idx, is_idx, it_idx use fields, only: get_fields, get_fields_by_spec @@ -3296,15 +3295,15 @@ subroutine advance_collisions_fp_explicit(g, phi, bpar, gke_rhs, time_collisions use redistribute, only: scatter, gather use stella_time, only: code_dt use zgrid, only: nzgrid, ntubes - use run_parameters, only: fphi - use physics_flags, only: full_flux_surface - use kt_grids, only: naky, nakx + use parameters_numerical, only: fphi + use parameters_physics, only: full_flux_surface + use parameters_kxky_grids, only: naky, nakx use vpamu_grids, only: nvpa, nmu use vpamu_grids, only: set_vpa_weights use stella_layouts, only: vmu_lo, kxkyz_lo use stella_layouts, only: is_idx, iky_idx, ikx_idx, iz_idx use dist_redistribute, only: kxkyz2vmu - use dist_fn_arrays, only: gvmu + use arrays_dist_fn, only: gvmu use g_tofrom_h, only: g_to_h implicit none @@ -3538,7 +3537,7 @@ subroutine mu_differential_operator_fp(h, Dh, iv, iz, is, ia, iky, ikx, cfac) use vpamu_grids, only: nmu, mu, dmu, vpa, dvpa, nvpa, maxwell_vpa, equally_spaced_mu_grid use geometry, only: bmag use species, only: spec - use dist_fn_arrays, only: kperp2 + use arrays_dist_fn, only: kperp2 use constants, only: pi use job_manage, only: timer_local, time_message @@ -3834,7 +3833,7 @@ subroutine mu_differential_operator_fp_conservative(h, Dh, iv, iz, is, ia, iky, use vpamu_grids, only: nmu, mu, dmu, vpa, dvpa, nvpa, maxwell_vpa, equally_spaced_mu_grid use geometry, only: bmag use species, only: spec - use dist_fn_arrays, only: kperp2 + use arrays_dist_fn, only: kperp2 use constants, only: pi use job_manage, only: timer_local, time_message @@ -3994,7 +3993,7 @@ subroutine advance_collisions_fp_implicit(phi, apar, bpar) use zgrid, only: nzgrid use vpamu_grids, only: set_vpa_weights - use dist_fn_arrays, only: gvmu + use arrays_dist_fn, only: gvmu implicit none @@ -4021,13 +4020,13 @@ subroutine advance_implicit_fp(phi, apar, bpar, g) use finite_differences, only: tridag use linear_solve, only: lu_back_substitution use stella_time, only: code_dt - use run_parameters, only: fphi + use parameters_numerical, only: fphi use species, only: nspec, spec use zgrid, only: nzgrid, ntubes use vpamu_grids, only: nmu, nvpa, integrate_vmu use vpamu_grids, only: vpa use vpamu_grids, only: set_vpa_weights - use kt_grids, only: naky, nakx + use parameters_kxky_grids, only: naky, nakx use stella_layouts, only: kxkyz_lo use stella_layouts, only: iky_idx, ikx_idx, iz_idx, is_idx, it_idx use g_tofrom_h, only: g_to_h diff --git a/dissipation/dissipation.f90 b/dissipation/dissipation.f90 index 2cd5fc2800..bd6d8936e4 100644 --- a/dissipation/dissipation.f90 +++ b/dissipation/dissipation.f90 @@ -33,7 +33,7 @@ subroutine init_dissipation use mp, only: proc0 use hyper, only: init_hyper - use run_parameters, only: print_extra_info_to_terminal + use parameters_numerical, only: print_extra_info_to_terminal implicit none @@ -76,7 +76,7 @@ subroutine read_parameters use file_utils, only: input_unit_exist use mp, only: proc0, broadcast - use run_parameters, only: fully_explicit + use parameters_numerical, only: fully_explicit use coll_dougherty, only: read_parameters_dougherty use coll_fokkerplanck, only: read_parameters_fp use hyper, only: read_parameters_hyper @@ -166,7 +166,7 @@ end subroutine finish_collisions subroutine advance_collisions_explicit(g, phi, bpar, gke_rhs) use mp, only: mp_abort - use physics_flags, only: full_flux_surface + use parameters_physics, only: full_flux_surface use stella_layouts, only: vmu_lo use zgrid, only: nzgrid use coll_dougherty, only: advance_collisions_dougherty_explicit @@ -199,7 +199,7 @@ subroutine advance_collisions_implicit(mirror_implicit, phi, apar, bpar, g) use zgrid, only: nzgrid use vpamu_grids, only: set_vpa_weights use stella_layouts, only: vmu_lo - use dist_fn_arrays, only: gvmu + use arrays_dist_fn, only: gvmu use coll_dougherty, only: advance_collisions_dougherty_implicit use coll_fokkerplanck, only: advance_collisions_fp_implicit diff --git a/dissipation/hyper.f90 b/dissipation/hyper.f90 index 1a5f886505..f6dec1bf20 100644 --- a/dissipation/hyper.f90 +++ b/dissipation/hyper.f90 @@ -24,7 +24,7 @@ module hyper subroutine read_parameters_hyper use file_utils, only: input_unit_exist - use physics_flags, only: full_flux_surface, radial_variation + use parameters_physics, only: full_flux_surface, radial_variation use mp, only: proc0, broadcast implicit none @@ -59,11 +59,11 @@ end subroutine read_parameters_hyper subroutine init_hyper - use kt_grids, only: ikx_max, nakx, naky - use kt_grids, only: aky, akx, theta0 + use parameters_kxky_grids, only: ikx_max, nakx, naky + use grids_kxky, only: aky, akx, theta0 use zgrid, only: nzgrid, zed use geometry, only: geo_surf, q_as_x - use dist_fn_arrays, only: kperp2 + use arrays_dist_fn, only: kperp2 implicit none @@ -112,9 +112,9 @@ subroutine advance_hyper_dissipation(g) use stella_time, only: code_dt use zgrid, only: nzgrid, ntubes, zed use stella_layouts, only: vmu_lo - use dist_fn_arrays, only: kperp2 - use kt_grids, only: naky - use kt_grids, only: aky, akx, theta0, zonal_mode + use arrays_dist_fn, only: kperp2 + use parameters_kxky_grids, only: naky + use grids_kxky, only: aky, akx, theta0, zonal_mode implicit none @@ -235,7 +235,7 @@ subroutine get_dgdz_fourth_order(g, dgdz) use extended_zgrid, only: ikxmod use extended_zgrid, only: fill_zed_ghost_zones use extended_zgrid, only: periodic - use kt_grids, only: naky + use parameters_kxky_grids, only: naky use stella_layouts, only: iv_idx, imu_idx, is_idx diff --git a/dist_fn.f90 b/dist_fn.f90 index 2f57048430..2fadf1ca37 100644 --- a/dist_fn.f90 +++ b/dist_fn.f90 @@ -1,5 +1,7 @@ module dist_fn + use debug_flags, only: debug => dist_fn_debug + implicit none public :: init_gxyz @@ -19,19 +21,18 @@ module dist_fn logical :: dkp2drinit = .false. logical :: vp2init = .false. - logical :: debug = .false. - contains subroutine init_gxyz(restarted) - use dist_fn_arrays, only: gvmu, gold, gnew + use arrays_dist_fn, only: gvmu, gold, gnew use redistribute, only: gather, scatter use dist_redistribute, only: kxkyz2vmu - use physics_flags, only: radial_variation + use parameters_physics, only: radial_variation use stella_layouts, only: vmu_lo, iv_idx, imu_idx, is_idx use stella_transforms, only: transform_kx2x_xfirst, transform_x2kx_xfirst - use kt_grids, only: nalpha, nakx, naky, multiply_by_rho + use parameters_kxky_grids, only: nalpha, nakx, naky + use calculations_kxky, only: multiply_by_rho use vpamu_grids, only: mu, vpa, vperp2 use zgrid, only: nzgrid, ntubes use species, only: spec, pfac @@ -91,7 +92,7 @@ end subroutine init_gxyz subroutine init_dist_fn use mp, only: proc0 - use physics_flags, only: radial_variation + use parameters_physics, only: radial_variation use stella_layouts, only: init_dist_fn_layouts use gyro_averages, only: init_bessel @@ -126,14 +127,13 @@ end subroutine init_dist_fn !> init_kperp2 allocates and initialises the kperp2 array subroutine init_kperp2 - use dist_fn_arrays, only: kperp2 + use arrays_dist_fn, only: kperp2 use geometry, only: gds2, gds21, gds22 use geometry, only: geo_surf, q_as_x use zgrid, only: nzgrid - use kt_grids, only: naky, nakx, theta0 - use kt_grids, only: akx, aky - use kt_grids, only: zonal_mode - use kt_grids, only: nalpha + use parameters_kxky_grids, only: naky, nakx, nalpha + use grids_kxky, only: akx, aky, theta0 + use grids_kxky, only: zonal_mode implicit none @@ -177,14 +177,13 @@ end subroutine init_kperp2 !> init_dkperp2dr allocates and initialises the dkperp2dr array, needed for radial variation subroutine init_dkperp2dr - use dist_fn_arrays, only: kperp2, dkperp2dr + use arrays_dist_fn, only: kperp2, dkperp2dr use geometry, only: dgds2dr, dgds21dr, dgds22dr use geometry, only: geo_surf, q_as_x use zgrid, only: nzgrid - use kt_grids, only: naky, nakx, theta0 - use kt_grids, only: akx, aky - use kt_grids, only: zonal_mode - use kt_grids, only: nalpha + use parameters_kxky_grids, only: naky, nakx, nalpha + use grids_kxky, only: akx, aky, theta0 + use grids_kxky, only: zonal_mode implicit none @@ -226,8 +225,8 @@ end subroutine init_dkperp2dr subroutine enforce_single_valued_kperp2 - use dist_fn_arrays, only: kperp2 - use kt_grids, only: naky, nalpha + use arrays_dist_fn, only: kperp2 + use parameters_kxky_grids, only: naky, nalpha use zgrid, only: nzgrid use extended_zgrid, only: neigen, nsegments, ikxmod @@ -258,10 +257,10 @@ subroutine allocate_arrays use stella_layouts, only: kxkyz_lo, vmu_lo use zgrid, only: nzgrid, ntubes - use kt_grids, only: naky, nakx + use parameters_kxky_grids, only: naky, nakx use vpamu_grids, only: nvpa, nmu - use dist_fn_arrays, only: gnew, gold, g_scratch - use dist_fn_arrays, only: gvmu + use arrays_dist_fn, only: gnew, gold, g_scratch + use arrays_dist_fn, only: gvmu implicit none @@ -286,7 +285,7 @@ subroutine init_vperp2 use zgrid, only: nzgrid use vpamu_grids, only: vperp2 use vpamu_grids, only: nmu, mu - use kt_grids, only: nalpha + use parameters_kxky_grids, only: nalpha implicit none @@ -321,7 +320,7 @@ end subroutine finish_dist_fn subroutine deallocate_arrays - use dist_fn_arrays, only: gnew, gold, g_scratch, gvmu + use arrays_dist_fn, only: gnew, gold, g_scratch, gvmu implicit none @@ -334,7 +333,7 @@ end subroutine deallocate_arrays subroutine finish_kperp2 - use dist_fn_arrays, only: kperp2, dkperp2dr + use arrays_dist_fn, only: kperp2, dkperp2dr implicit none @@ -361,7 +360,7 @@ end subroutine finish_vperp2 subroutine checksum_field(field, total) use zgrid, only: nzgrid, ntubes - use kt_grids, only: naky + use parameters_kxky_grids, only: naky use extended_zgrid, only: neigen, nsegments, ikxmod use extended_zgrid, only: iz_low, iz_up @@ -398,7 +397,7 @@ subroutine checksum_dist(dist, total, norm) use mp, only: sum_allreduce use zgrid, only: nzgrid, ntubes use stella_layouts, only: vmu_lo, iv_idx, imu_idx, is_idx - use kt_grids, only: naky, nakx + use parameters_kxky_grids, only: naky, nakx use vpamu_grids, only: maxwell_vpa, maxwell_mu implicit none diff --git a/dist_redistribute.f90 b/dist_redistribute.f90 index 8a7aa0845c..b79222cffd 100644 --- a/dist_redistribute.f90 +++ b/dist_redistribute.f90 @@ -21,8 +21,8 @@ module dist_redistribute subroutine init_redistribute - use physics_flags, only: full_flux_surface - use physics_flags, only: include_parallel_nonlinearity + use parameters_physics, only: full_flux_surface + use parameters_physics, only: include_parallel_nonlinearity implicit none diff --git a/euterpe_interface.f90 b/euterpe_interface.f90 index 5ded03d31b..c87691a66d 100644 --- a/euterpe_interface.f90 +++ b/euterpe_interface.f90 @@ -10,7 +10,7 @@ subroutine read_species_euterpe(nspec, spec) use finite_differences, only: fd3pt, d2_3pt use common_types, only: spec_type use splines, only: geo_spline - use physics_parameters, only: vnew_ref, rhostar, tite, nine + use parameters_physics, only: vnew_ref, rhostar, tite, nine use geometry, only: geo_surf, aref, bref implicit none diff --git a/extended_zgrid.f90 b/extended_zgrid.f90 index dadaf222e2..11a897d270 100644 --- a/extended_zgrid.f90 +++ b/extended_zgrid.f90 @@ -1,5 +1,7 @@ module extended_zgrid + use debug_flags, only: debug => extended_grid_debug + implicit none public :: nsegments @@ -17,8 +19,6 @@ module extended_zgrid public :: map_to_iz_ikx_from_izext private - - logical :: debug = .false. !> these arrays needed to keep track of connections between different !> 2pi segments @@ -48,9 +48,9 @@ subroutine init_extended_zgrid use zgrid, only: boundary_option_linked use zgrid, only: boundary_option_linked_stellarator use zgrid, only: nperiod, nzgrid, nzed, ntubes - use kt_grids, only: nakx, naky - use kt_grids, only: jtwist, ikx_twist_shift, phase_shift_angle - use kt_grids, only: aky, ikx_max + use parameters_kxky_grids, only: nakx, naky, ikx_max + use parameters_kxky_grids, only: jtwist, ikx_twist_shift, phase_shift_angle + use grids_kxky, only: aky use constants, only: zi use mp, only: proc0 diff --git a/ffs_solve.f90 b/ffs_solve.f90 index 62e769a5bd..0c71563313 100644 --- a/ffs_solve.f90 +++ b/ffs_solve.f90 @@ -11,7 +11,7 @@ module ffs_solve subroutine add_correction_ffs (phiin, gin, source_out) use zgrid, only: nzgrid, ntubes - use kt_grids, only: naky, nakx + use parameters_kxky_grids, only: naky, nakx use stella_layouts, only: vmu_lo implicit none @@ -39,24 +39,23 @@ end subroutine add_correction_ffs subroutine get_source_ffs_itteration (phi, g, source) - use mp, only: proc0 use stella_layouts, only: vmu_lo use stella_layouts, only: iv_idx, imu_idx, is_idx use stella_transforms, only: transform_ky2y use zgrid, only: nzgrid, ntubes - use kt_grids, only: naky, naky_all, nakx, ikx_max, ny - use kt_grids, only: swap_kxky + use parameters_kxky_grids, only: naky, naky_all, nakx, ikx_max, ny + use calculations_kxky, only: swap_kxky use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac, maxwell_mu_avg use species, only: spec - use fields, only: advance_fields, fields_updated - use gyro_averages, only: j0_ffs, j0_const, gyro_average + use fields, only: advance_fields + use gyro_averages, only: j0_ffs, gyro_average - use kt_grids, only: swap_kxky_back + use calculations_kxky, only: swap_kxky_back use stella_transforms, only: transform_y2ky use parallel_streaming, only: center_zed, get_dgdz_centered, get_dzed - use parallel_streaming, only: stream_correction, stream, stream_store_full + use parallel_streaming, only: stream_correction, stream_store_full use species, only: has_electron_species implicit none @@ -65,8 +64,8 @@ subroutine get_source_ffs_itteration (phi, g, source) complex, dimension(:, :, -nzgrid:, :, vmu_lo%llim_proc:), intent(in) :: g complex, dimension(:, :, -nzgrid:, :, vmu_lo%llim_proc:), intent (out) :: source - integer :: ivmu, iv, imu, is, ia, iz, it, ikx - complex, dimension(:, :, :, :), allocatable :: g0, g1 + integer :: ivmu, iv, imu, is, ia, iz, it + complex, dimension(:, :, :, :), allocatable :: g0 complex, dimension(:, :, :, :), allocatable :: dgphi_dz, dphi_dz, dgdz complex, dimension(:, :, :, :), allocatable :: g0y, g1y, g2y, g3y complex, dimension(:, :), allocatable :: g_swap @@ -178,18 +177,17 @@ end subroutine get_source_ffs_itteration subroutine get_drifts_ffs_itteration (phi, g, source) - use mp, only: proc0 use stella_layouts, only: vmu_lo use stella_layouts, only: iv_idx, imu_idx, is_idx use stella_transforms, only: transform_ky2y,transform_y2ky use zgrid, only: nzgrid, ntubes - use kt_grids, only: naky, naky_all, nakx, ikx_max, ny - use kt_grids, only: swap_kxky, swap_kxky_back + use parameters_kxky_grids, only: naky, naky_all, nakx, ikx_max, ny + use calculations_kxky, only: swap_kxky, swap_kxky_back use gyro_averages, only: j0_ffs, gyro_average - use dist_fn_arrays, only: wdriftx_g, wdriftx_phi - use dist_fn_arrays, only: wdrifty_g, wdrifty_phi - use dist_fn_arrays, only: wstar + use arrays_dist_fn, only: wdriftx_g, wdriftx_phi + use arrays_dist_fn, only: wdrifty_g, wdrifty_phi + use arrays_dist_fn, only: wstar use parallel_streaming, only: center_zed @@ -276,7 +274,8 @@ subroutine get_dgdy(gin, dgdy) use constants, only: zi use zgrid, only: nzgrid, ntubes - use kt_grids, only: nakx, aky + use parameters_kxky_grids, only: nakx + use grids_kxky, only: aky implicit none @@ -299,7 +298,8 @@ subroutine get_dgdx(gin, dgdx) use constants, only: zi use zgrid, only: nzgrid, ntubes - use kt_grids, only: akx, nakx + use parameters_kxky_grids, only: nakx + use grids_kxky, only: akx implicit none @@ -320,9 +320,8 @@ end subroutine get_dgdx subroutine add_explicit_term_ffs_fields(g, pre_factor, src) - use stella_layouts, only: vmu_lo use zgrid, only: nzgrid, ntubes - use kt_grids, only: ikx_max, nalpha + use parameters_kxky_grids, only: ikx_max, nalpha implicit none @@ -330,7 +329,6 @@ subroutine add_explicit_term_ffs_fields(g, pre_factor, src) real, dimension(:, -nzgrid:), intent(in) :: pre_factor complex, dimension(:, :, -nzgrid:, :), intent(in out) :: src - integer :: ivmu integer :: ia, ikx, iz, it do it = 1, ntubes diff --git a/fields.fpp b/fields.fpp index d3eb9096d2..bc39e07110 100644 --- a/fields.fpp +++ b/fields.fpp @@ -1,5 +1,6 @@ module fields + use debug_flags, only: debug => fields_debug use common_types, only: eigen_type use mpi @@ -39,7 +40,6 @@ module fields #ifdef ISO_C_BINDING integer :: phi_shared_window = MPI_WIN_NULL #endif - logical :: debug = .false. integer :: zm integer :: nfields @@ -62,8 +62,8 @@ contains use mp, only: proc0 use linear_solve, only: lu_decomposition - use physics_flags, only: full_flux_surface - use physics_flags, only: include_apar, include_bpar + use parameters_physics, only: full_flux_surface + use parameters_physics, only: include_apar, include_bpar implicit none @@ -91,13 +91,13 @@ contains use mp, only: sum_allreduce use stella_layouts, only: kxkyz_lo use stella_layouts, onlY: iz_idx, it_idx, ikx_idx, iky_idx, is_idx - use dist_fn_arrays, only: kperp2, dkperp2dr + use arrays_dist_fn, only: kperp2, dkperp2dr use gyro_averages, only: aj0v, aj1v - use run_parameters, only: fphi - use run_parameters, only: ky_solve_radial - use run_parameters, only: maxwellian_normalization - use physics_parameters, only: tite, nine, beta - use physics_flags, only: radial_variation + use parameters_numerical, only: fphi + use parameters_numerical, only: ky_solve_radial + use parameters_numerical, only: maxwellian_normalization + use parameters_physics, only: tite, nine, beta + use parameters_physics, only: radial_variation use species, only: spec, has_electron_species, ion_species use geometry, only: dl_over_b, dBdrho, bmag use zgrid, only: nzgrid @@ -105,14 +105,14 @@ contains use vpamu_grids, only: vpa, vperp2 use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac use vpamu_grids, only: integrate_vmu - use kt_grids, only: naky, nakx, akx - use kt_grids, only: zonal_mode - use physics_flags, only: include_apar, include_bpar - use physics_flags, only: adiabatic_option_switch - use physics_flags, only: adiabatic_option_fieldlineavg - use fields_arrays, only: gamtot, dgamtotdr, gamtot3 - use fields_arrays, only: gamtot13, gamtot31, gamtot33 - use fields_arrays, only: gamtotinv11, gamtotinv13, gamtotinv31, gamtotinv33 + use parameters_kxky_grids, only: naky, nakx + use grids_kxky, only: zonal_mode, akx + use parameters_physics, only: include_apar, include_bpar + use parameters_physics, only: adiabatic_option_switch + use parameters_physics, only: adiabatic_option_fieldlineavg + use arrays_fields, only: gamtot, dgamtotdr, gamtot3 + use arrays_fields, only: gamtot13, gamtot31, gamtot33 + use arrays_fields, only: gamtotinv11, gamtotinv13, gamtotinv31, gamtotinv33 implicit none @@ -406,24 +406,24 @@ contains use mp, only: job #ifdef ISO_C_BINDING use, intrinsic :: iso_c_binding, only: c_ptr, c_f_pointer, c_intptr_t - use fields_arrays, only: qn_window, phi_shared + use arrays_fields, only: qn_window, phi_shared use mp, only: sgproc0, curr_focus, sharedsubprocs use mp, only: scope, real_size, nbytes_real use mp, only: split_n_tasks, create_shared_memory_window use mpi #endif - use run_parameters, only: ky_solve_radial, ky_solve_real + use parameters_numerical, only: ky_solve_radial, ky_solve_real use species, only: spec, has_electron_species use stella_transforms, only: transform_kx2x_unpadded, transform_x2kx_unpadded use zgrid, only: nzgrid, ntubes, nztot - use kt_grids, only: naky, nakx - use kt_grids, only: zonal_mode, rho_d_clamped - use physics_flags, only: adiabatic_option_switch - use physics_flags, only: adiabatic_option_fieldlineavg + use parameters_kxky_grids, only: naky, nakx + use grids_kxky, only: zonal_mode, rho_d_clamped + use parameters_physics, only: adiabatic_option_switch + use parameters_physics, only: adiabatic_option_fieldlineavg use linear_solve, only: lu_decomposition, lu_inverse use multibox, only: init_mb_get_phi - use fields_arrays, only: gamtot, dgamtotdr - use fields_arrays, only: phi_solve, c_mat, theta + use arrays_fields, only: gamtot, dgamtotdr + use arrays_fields, only: phi_solve, c_mat, theta use file_utils, only: runtype_option_switch, runtype_multibox implicit none @@ -632,31 +632,31 @@ contains subroutine init_gamma0_factor_ffs use spfunc, only: j0 - use dist_fn_arrays, only: kperp2 + use arrays_dist_fn, only: kperp2 use stella_transforms, only: transform_alpha2kalpha - use physics_parameters, only: nine, tite + use parameters_physics, only: nine, tite use species, only: spec, nspec use species, only: adiabatic_electrons use zgrid, only: nzgrid, nztot use geometry, only: bmag use stella_layouts, only: vmu_lo use stella_layouts, only: iv_idx, imu_idx, is_idx - use kt_grids, only: nalpha, ikx_max, naky_all, naky - use kt_grids, only: swap_kxky_ordered + use parameters_kxky_grids, only: nalpha, ikx_max, naky_all, naky + use calculations_kxky, only: swap_kxky_ordered use vpamu_grids, only: vperp2, maxwell_vpa, maxwell_mu use vpamu_grids, only: integrate_species use gyro_averages, only: band_lu_factorisation_ffs - use kt_grids, only: nakx - use fields_arrays, only: gamtot, gamtot3 + use parameters_kxky_grids, only: nakx + use arrays_fields, only: gamtot, gamtot3 use mp, only: sum_allreduce, proc0 - use kt_grids, only: swap_kxky_back_ordered + use calculations_kxky, only: swap_kxky_back_ordered use gyro_averages, only: find_max_required_kalpha_index !! For gamtot3 - clean up use species, only: has_electron_species, ion_species - use kt_grids, only: zonal_mode , akx - use physics_flags, only: adiabatic_option_switch, adiabatic_option_fieldlineavg + use grids_kxky, only: zonal_mode , akx + use parameters_physics, only: adiabatic_option_switch, adiabatic_option_fieldlineavg use geometry, only: dl_over_b implicit none @@ -823,10 +823,10 @@ contains !> is stored in adiabatic_response_factor subroutine init_adiabatic_response_factor - use physics_parameters, only: nine, tite + use parameters_physics, only: nine, tite use zgrid, only: nzgrid use stella_transforms, only: transform_alpha2kalpha - use kt_grids, only: naky, naky_all, ikx_max + use parameters_kxky_grids, only: naky, naky_all, ikx_max use gyro_averages, only: band_lu_solve_ffs use volume_averages, only: flux_surface_average_ffs @@ -862,15 +862,15 @@ contains subroutine allocate_arrays - use fields_arrays, only: phi, phi_old - use fields_arrays, only: apar, apar_old - use fields_arrays, only: bpar, bpar_old - use fields_arrays, only: phi_corr_QN, phi_corr_GA - use fields_arrays, only: apar_corr_QN, apar_corr_GA + use arrays_fields, only: phi, phi_old + use arrays_fields, only: apar, apar_old + use arrays_fields, only: bpar, bpar_old + use arrays_fields, only: phi_corr_QN, phi_corr_GA + use arrays_fields, only: apar_corr_QN, apar_corr_GA use zgrid, only: nzgrid, ntubes use stella_layouts, only: vmu_lo - use physics_flags, only: radial_variation - use kt_grids, only: naky, nakx + use parameters_physics, only: radial_variation + use parameters_kxky_grids, only: naky, nakx implicit none @@ -927,7 +927,7 @@ contains ! as these modes should be stable, but I made this function (and ! its relative in the dist file) just in case - use kt_grids, only: nakx + use parameters_kxky_grids, only: nakx use zgrid, only: nzgrid implicit none @@ -950,11 +950,11 @@ contains use stella_layouts, only: vmu_lo use job_manage, only: time_message use redistribute, only: scatter - use dist_fn_arrays, only: gvmu + use arrays_dist_fn, only: gvmu use zgrid, only: nzgrid use dist_redistribute, only: kxkyz2vmu - use run_parameters, only: fields_kxkyz - use physics_flags, only: full_flux_surface + use parameters_numerical, only: fields_kxkyz + use parameters_physics, only: full_flux_surface implicit none @@ -1008,8 +1008,8 @@ contains use job_manage, only: time_message use redistribute, only: scatter use zgrid, only: nzgrid - use run_parameters, only: fields_kxkyz - use physics_flags, only: full_flux_surface + use parameters_numerical, only: fields_kxkyz + use parameters_physics, only: full_flux_surface implicit none @@ -1041,11 +1041,11 @@ contains use job_manage, only: time_message use stella_layouts, only: kxkyz_lo use stella_layouts, only: iz_idx, it_idx, ikx_idx, iky_idx, is_idx - use dist_fn_arrays, only: kperp2 + use arrays_dist_fn, only: kperp2 use gyro_averages, only: gyro_average, gyro_average_j1 - use physics_flags, only: include_apar, include_bpar - use run_parameters, only: fphi - use physics_parameters, only: beta + use parameters_physics, only: include_apar, include_bpar + use parameters_numerical, only: fphi + use parameters_physics, only: beta use zgrid, only: nzgrid, ntubes use vpamu_grids, only: nvpa, nmu use vpamu_grids, only: vpa, mu @@ -1162,11 +1162,11 @@ contains use job_manage, only: time_message use stella_layouts, only: vmu_lo, iv_idx, imu_idx use gyro_averages, only: gyro_average, gyro_average_j1 - use run_parameters, only: fphi - use physics_parameters, only: beta - use physics_flags, only: include_apar, include_bpar - use physics_flags, only: radial_variation - use dist_fn_arrays, only: g_scratch + use parameters_numerical, only: fphi + use parameters_physics, only: beta + use parameters_physics, only: include_apar, include_bpar + use parameters_physics, only: radial_variation + use arrays_dist_fn, only: g_scratch use zgrid, only: nzgrid use vpamu_grids, only: integrate_species use vpamu_grids, only: vpa, mu @@ -1254,7 +1254,7 @@ contains ! MRH remove optimisation for ease of including bpar call gyro_average(g, g_scratch) - ! for parallel Ampere's Law, need to calculate parallel current rather than density, + ! for parallel Amperes Law, need to calculate parallel current rather than density, ! so multiply by vpa before integrating do ivmu = vmu_lo%llim_proc, vmu_lo%ulim_proc ! get the vpa index @@ -1283,9 +1283,9 @@ contains use stella_layouts, only: vmu_lo use zgrid, only: nzgrid, ntubes - use kt_grids, only: naky, nakx - use fields_arrays, only: gamtot - use kt_grids, only: akx + use parameters_kxky_grids, only: naky, nakx + use arrays_fields, only: gamtot + use grids_kxky, only: akx use gyro_averages, only: gyro_average implicit none @@ -1332,7 +1332,7 @@ contains use stella_layouts, only: vmu_lo use species, only: spec use zgrid, only: nzgrid - use kt_grids, only: naky, nakx + use parameters_kxky_grids, only: naky, nakx use vpamu_grids, only: integrate_species_ffs use gyro_averages, only: gyro_average, j0_B_ffs @@ -1378,22 +1378,22 @@ contains subroutine get_fields_ffs(g, phi, apar, implicit_solve) use mp, only: mp_abort - use physics_parameters, only: nine, tite - use physics_flags, only: include_apar + use parameters_physics, only: nine, tite + use parameters_physics, only: include_apar use stella_layouts, only: vmu_lo - use run_parameters, only: fphi + use parameters_numerical, only: fphi use species, only: modified_adiabatic_electrons, adiabatic_electrons use zgrid, only: nzgrid, ntubes - use kt_grids, only: nakx, ikx_max, naky, naky_all - use kt_grids, only: swap_kxky_ordered, swap_kxky_back_ordered + use parameters_kxky_grids, only: nakx, ikx_max, naky, naky_all + use calculations_kxky, only: swap_kxky_ordered, swap_kxky_back_ordered use volume_averages, only: flux_surface_average_ffs - use fields_arrays, only: gamtot - use kt_grids, only: akx, zonal_mode + use arrays_fields, only: gamtot + use grids_kxky, only: akx, zonal_mode - use fields_arrays, only: gamtot3 + use arrays_fields, only: gamtot3 use species, only: spec, has_electron_species - use physics_flags, only: adiabatic_option_switch - use physics_flags, only: adiabatic_option_fieldlineavg + use parameters_physics, only: adiabatic_option_switch + use parameters_physics, only: adiabatic_option_fieldlineavg use geometry, only: dl_over_b implicit none @@ -1530,7 +1530,7 @@ contains use stella_layouts, only: vmu_lo use species, only: spec use zgrid, only: nzgrid - use kt_grids, only: naky, nakx + use parameters_kxky_grids, only: naky, nakx use vpamu_grids, only: integrate_species_ffs use gyro_averages, only: gyro_average, j0_B_ffs @@ -1584,16 +1584,16 @@ contains use stella_layouts, only: kxkyz_lo use stella_layouts, only: iz_idx, it_idx, ikx_idx, iky_idx, is_idx use gyro_averages, only: gyro_average - use run_parameters, only: fphi + use parameters_numerical, only: fphi use geometry, only: dl_over_b use zgrid, only: nzgrid, ntubes use vpamu_grids, only: nvpa, nmu use vpamu_grids, only: integrate_vmu - use kt_grids, only: nakx - use kt_grids, only: zonal_mode + use parameters_kxky_grids, only: nakx + use grids_kxky, only: zonal_mode use species, only: spec, nspec, has_electron_species - use physics_flags, only: adiabatic_option_switch - use physics_flags, only: adiabatic_option_fieldlineavg + use parameters_physics, only: adiabatic_option_switch + use parameters_physics, only: adiabatic_option_fieldlineavg implicit none @@ -1660,17 +1660,17 @@ contains use stella_layouts, only: kxkyz_lo use stella_layouts, only: iz_idx, it_idx, ikx_idx, iky_idx, is_idx use gyro_averages, only: gyro_average - use run_parameters, only: fphi + use parameters_numerical, only: fphi use geometry, only: dl_over_b, bmag use zgrid, only: nzgrid, ntubes use vpamu_grids, only: vperp2, nvpa, nmu use vpamu_grids, only: integrate_vmu - use kt_grids, only: nakx - use kt_grids, only: zonal_mode + use parameters_kxky_grids, only: nakx + use grids_kxky, only: zonal_mode use species, only: spec, nspec, has_electron_species - use physics_flags, only: adiabatic_option_switch - use physics_flags, only: adiabatic_option_fieldlineavg - use dist_fn_arrays, only: kperp2 + use parameters_physics, only: adiabatic_option_switch + use parameters_physics, only: adiabatic_option_fieldlineavg + use arrays_dist_fn, only: kperp2 use spfunc, only: j0 implicit none @@ -1732,16 +1732,17 @@ contains use mp, only: proc0, mp_abort, job use job_manage, only: time_message - use physics_flags, only: radial_variation - use run_parameters, only: ky_solve_radial, ky_solve_real + use parameters_physics, only: radial_variation + use parameters_numerical, only: ky_solve_radial, ky_solve_real use zgrid, only: nzgrid, ntubes use geometry, only: dl_over_b - use kt_grids, only: nakx, naky, zonal_mode - use physics_flags, only: adiabatic_option_switch - use physics_flags, only: adiabatic_option_fieldlineavg + use parameters_kxky_grids, only: nakx, naky + use grids_kxky, only: zonal_mode + use parameters_physics, only: adiabatic_option_switch + use parameters_physics, only: adiabatic_option_fieldlineavg use species, only: spec, has_electron_species use multibox, only: mb_get_phi - use fields_arrays, only: gamtot, gamtot3 + use arrays_fields, only: gamtot, gamtot3 use file_utils, only: runtype_option_switch, runtype_multibox implicit none @@ -1840,8 +1841,8 @@ contains use mp, only: proc0, mp_abort use job_manage, only: time_message use zgrid, only: nzgrid, ntubes - use kt_grids, only: nakx, naky - use fields_arrays, only: gamtotinv11, gamtotinv13, gamtotinv33, gamtotinv31 + use parameters_kxky_grids, only: nakx, naky + use arrays_fields, only: gamtotinv11, gamtotinv13, gamtotinv33, gamtotinv31 implicit none @@ -1891,18 +1892,19 @@ contains use mp, only: curr_focus, sharedsubprocs, scope use mp, only: split_n_tasks, sgproc0 use zgrid, only: nztot - use fields_arrays, only: phi_shared + use arrays_fields, only: phi_shared use mp_lu_decomposition, only: lu_matrix_multiply_local #endif use stella_transforms, only: transform_kx2x_unpadded, transform_x2kx_unpadded - use physics_flags, only: adiabatic_option_switch - use physics_flags, only: adiabatic_option_fieldlineavg - use run_parameters, only: ky_solve_radial + use parameters_physics, only: adiabatic_option_switch + use parameters_physics, only: adiabatic_option_fieldlineavg + use parameters_numerical, only: ky_solve_radial use zgrid, only: nzgrid, ntubes use species, only: spec, has_electron_species - use kt_grids, only: nakx, naky, zonal_mode + use parameters_kxky_grids, only: nakx, naky + use grids_kxky, only: zonal_mode use linear_solve, only: lu_back_substitution - use fields_arrays, only: gamtot, phi_solve + use arrays_fields, only: gamtot, phi_solve implicit none @@ -1990,7 +1992,7 @@ contains use mp, only: proc0, mp_abort use zgrid, only: nzgrid, ntubes - use dist_fn_arrays, only: kperp2 + use arrays_dist_fn, only: kperp2 implicit none @@ -2021,8 +2023,8 @@ contains use mp, only: mp_abort, sum_allreduce use stella_layouts, only: kxkyz_lo use stella_layouts, only: iky_idx, ikx_idx, iz_idx, it_idx, is_idx - use physics_flags, only: include_apar - use physics_parameters, only: beta + use parameters_physics, only: include_apar + use parameters_physics, only: beta use species, only: spec use zgrid, only: nzgrid, ntubes use vpamu_grids, only: nvpa, nmu, vpa @@ -2071,7 +2073,7 @@ contains #ifdef ISO_C_BINDING use mpi use mp, only: sgproc0, comm_sgroup - use fields_arrays, only: qn_zf_window + use arrays_fields, only: qn_zf_window use mp_lu_decomposition, only: lu_matrix_multiply_local #else use linear_solve, only: lu_back_substitution @@ -2079,10 +2081,11 @@ contains use zgrid, only: nzgrid, ntubes use stella_transforms, only: transform_kx2x_unpadded, transform_x2kx_unpadded use geometry, only: dl_over_b, d_dl_over_b_drho - use kt_grids, only: nakx, boundary_size, rho_d_clamped - use fields_arrays, only: phizf_solve, phi_ext - use fields_arrays, only: phi_proj, phi_proj_stage, theta - use fields_arrays, only: exclude_boundary_regions_qn, exp_fac_qn, tcorr_source_qn + use parameters_kxky_grids, only: nakx + use grids_kxky, only: boundary_size, rho_d_clamped + use arrays_fields, only: phizf_solve, phi_ext + use arrays_fields, only: phi_proj, phi_proj_stage, theta + use arrays_fields, only: exclude_boundary_regions_qn, exp_fac_qn, tcorr_source_qn implicit none @@ -2196,8 +2199,8 @@ contains subroutine get_phi_ffs(rhs, phi) use zgrid, only: nzgrid - use kt_grids, only: swap_kxky_ordered, swap_kxky_back_ordered - use kt_grids, only: naky_all, ikx_max + use calculations_kxky, only: swap_kxky_ordered, swap_kxky_back_ordered + use parameters_kxky_grids, only: naky_all, ikx_max use gyro_averages, only: band_lu_solve_ffs implicit none @@ -2238,11 +2241,12 @@ contains use stella_layouts, only: imu_idx, is_idx use gyro_averages, only: aj0x, aj1x use geometry, only: dBdrho, bmag - use dist_fn_arrays, only: kperp2, dkperp2dr + use arrays_dist_fn, only: kperp2, dkperp2dr use zgrid, only: nzgrid, ntubes use vpamu_grids, only: vperp2 - use kt_grids, only: nakx, naky, multiply_by_rho - use run_parameters, only: ky_solve_radial + use parameters_kxky_grids, only: nakx, naky + use calculations_kxky, only: multiply_by_rho + use parameters_numerical, only: ky_solve_radial use species, only: spec implicit none @@ -2296,20 +2300,21 @@ contains use stella_layouts, only: vmu_lo use gyro_averages, only: gyro_average, gyro_average_j1 use gyro_averages, only: aj0x, aj1x - use run_parameters, only: fphi, ky_solve_radial + use parameters_numerical, only: fphi, ky_solve_radial use geometry, only: dl_over_b, d_dl_over_b_drho, bmag, dBdrho use stella_layouts, only: imu_idx, is_idx use zgrid, only: nzgrid, ntubes use vpamu_grids, only: integrate_species, vperp2 - use kt_grids, only: nakx, nx, naky, rho_d_clamped - use kt_grids, only: zonal_mode, multiply_by_rho + use parameters_kxky_grids, only: nakx, naky + use grids_kxky, only: zonal_mode, rho_d_clamped + use calculations_kxky, only: multiply_by_rho use species, only: spec, has_electron_species - use fields_arrays, only: phi_corr_QN, phi_corr_GA - use fields_arrays, only: gamtot, dgamtotdr - use fields_arrays, only: gamtot3 - use dist_fn_arrays, only: kperp2, dkperp2dr - use physics_flags, only: adiabatic_option_switch - use physics_flags, only: adiabatic_option_fieldlineavg + use arrays_fields, only: phi_corr_QN, phi_corr_GA + use arrays_fields, only: gamtot, dgamtotdr + use arrays_fields, only: gamtot3 + use arrays_dist_fn, only: kperp2, dkperp2dr + use parameters_physics, only: adiabatic_option_switch + use parameters_physics, only: adiabatic_option_fieldlineavg use stella_transforms, only: transform_kx2x_unpadded, transform_x2kx_unpadded implicit none @@ -2445,8 +2450,8 @@ contains subroutine rescale_fields(target_amplitude) use mp, only: scope, subprocs, crossdomprocs, sum_allreduce - use fields_arrays, only: phi, apar - use dist_fn_arrays, only: gnew, gvmu + use arrays_fields, only: phi, apar + use arrays_dist_fn, only: gnew, gvmu use volume_averages, only: volume_average use job_manage, only: njobs use file_utils, only: runtype_option_switch, runtype_multibox @@ -2482,16 +2487,17 @@ contains use gyro_averages, only: gyro_average_j1 use stella_layouts, only: vmu_lo use stella_layouts, only: is_idx, iv_idx, imu_idx - use physics_flags, only: include_apar - use physics_flags, only: include_bpar - use run_parameters, only: fphi + use parameters_physics, only: include_apar + use parameters_physics, only: include_bpar + use parameters_numerical, only: fphi use species, only: spec use zgrid, only: nzgrid, ntubes use vpamu_grids, only: vpa, mu - use kt_grids, only: nakx, aky, naky + use parameters_kxky_grids, only: nakx, naky + use grids_kxky, only: aky use gyro_averages, only: j0_ffs - use physics_flags, only: full_flux_surface + use parameters_physics, only: full_flux_surface implicit none @@ -2545,15 +2551,16 @@ contains use gyro_averages, only: gyro_average_j1 use stella_layouts, only: vmu_lo use stella_layouts, only: is_idx, iv_idx, imu_idx - use physics_flags, only: include_apar - use physics_flags, only: include_bpar - use run_parameters, only: fphi + use parameters_physics, only: include_apar + use parameters_physics, only: include_bpar + use parameters_numerical, only: fphi use species, only: spec use vpamu_grids, only: vpa, mu - use kt_grids, only: nakx, aky, naky + use parameters_kxky_grids, only: nakx, naky + use grids_kxky, only: aky use gyro_averages, only: j0_ffs - use physics_flags, only: full_flux_surface + use parameters_physics, only: full_flux_surface implicit none @@ -2600,15 +2607,16 @@ contains use gyro_averages, only: gyro_average_j1 use stella_layouts, only: vmu_lo use stella_layouts, only: is_idx, iv_idx, imu_idx - use physics_flags, only: include_apar - use physics_flags, only: include_bpar - use run_parameters, only: fphi + use parameters_physics, only: include_apar + use parameters_physics, only: include_bpar + use parameters_numerical, only: fphi use species, only: spec use vpamu_grids, only: vpa, mu - use kt_grids, only: akx, naky, nakx + use grids_kxky, only: akx + use parameters_kxky_grids, only: naky, nakx use gyro_averages, only: j0_ffs - use physics_flags, only: full_flux_surface + use parameters_physics, only: full_flux_surface implicit none @@ -2649,19 +2657,19 @@ contains subroutine finish_fields - use fields_arrays, only: phi, phi_old - use fields_arrays, only: apar, apar_old - use fields_arrays, only: bpar, bpar_old - use fields_arrays, only: phi_corr_QN, phi_corr_GA - use fields_arrays, only: apar_corr_QN, apar_corr_GA - use fields_arrays, only: gamtot, dgamtotdr, gamtot3 - use fields_arrays, only: gamtot13, gamtot33, gamtot31 - use fields_arrays, only: c_mat, theta + use arrays_fields, only: phi, phi_old + use arrays_fields, only: apar, apar_old + use arrays_fields, only: bpar, bpar_old + use arrays_fields, only: phi_corr_QN, phi_corr_GA + use arrays_fields, only: apar_corr_QN, apar_corr_GA + use arrays_fields, only: gamtot, dgamtotdr, gamtot3 + use arrays_fields, only: gamtot13, gamtot33, gamtot31 + use arrays_fields, only: c_mat, theta #ifdef ISO_C_BINDING - use fields_arrays, only: qn_window + use arrays_fields, only: qn_window use mpi #else - use fields_arrays, only: phi_solve + use arrays_fields, only: phi_solve #endif implicit none diff --git a/flow_shear.f90 b/flow_shear.f90 index 2266185fed..6db669e105 100644 --- a/flow_shear.f90 +++ b/flow_shear.f90 @@ -30,18 +30,19 @@ subroutine init_flow_shear use species, only: spec use constants, only: zi, pi use zgrid, only: nzgrid - use kt_grids, only: x, x_d, nalpha, nx, nakx, naky, akx, aky, ikx_max, zonal_mode, box - use fields_arrays, only: shift_state + use grids_kxky, only: x, x_d, akx, aky, zonal_mode, box + use parameters_kxky_grids, only: nalpha, nx, nakx, naky, ikx_max + use arrays_fields, only: shift_state use geometry, only: q_as_x, geo_surf, bmag, btor, rmajor, dBdrho, dIdrho use geometry, only: dydalpha, drhodpsi - use physics_parameters, only: g_exb, g_exbfac, omprimfac + use parameters_physics, only: g_exb, g_exbfac, omprimfac use vpamu_grids, only: vperp2, vpa, mu use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac - use physics_flags, only: radial_variation, prp_shear_enabled, hammett_flow_shear + use parameters_physics, only: radial_variation, prp_shear_enabled, hammett_flow_shear use file_utils, only: runtype_option_switch, runtype_multibox use job_manage, only: njobs use mp, only: job, send, receive, crossdomprocs, subprocs, scope - use run_parameters, only: maxwellian_normalization + use parameters_numerical, only: maxwellian_normalization implicit none @@ -145,12 +146,12 @@ end subroutine init_flow_shear subroutine advance_parallel_flow_shear(gout) use mp, only: proc0, mp_abort - use physics_flags, only: full_flux_surface + use parameters_physics, only: full_flux_surface use stella_layouts, only: vmu_lo use zgrid, only: nzgrid, ntubes - use kt_grids, only: nakx, naky + use parameters_kxky_grids, only: nakx, naky use fields, only: get_dchidy - use fields_arrays, only: phi, apar, bpar + use arrays_fields, only: phi, apar, bpar implicit none @@ -187,11 +188,12 @@ subroutine advance_perp_flow_shear(g) use stella_layouts, only: vmu_lo use constants, only: zi - use physics_flags, only: prp_shear_enabled, hammett_flow_shear + use parameters_physics, only: prp_shear_enabled, hammett_flow_shear use stella_transforms, only: transform_kx2x_unpadded, transform_x2kx_unpadded use zgrid, only: nzgrid, ntubes - use fields_arrays, only: shift_state - use kt_grids, only: aky, nakx, naky, ikx_max, zonal_mode + use arrays_fields, only: shift_state + use grids_kxky, only: aky, zonal_mode + use parameters_kxky_grids, only: nakx, naky, ikx_max use file_utils, only: runtype_option_switch, runtype_multibox use stella_time, only: code_dt @@ -289,7 +291,7 @@ subroutine advance_perp_flow_shear(g) end subroutine advance_perp_flow_shear subroutine finish_flow_shear - use fields_arrays, only: shift_state + use arrays_fields, only: shift_state implicit none diff --git a/g_tofrom_h.f90 b/g_tofrom_h.f90 index c2a2e326aa..c77203c556 100644 --- a/g_tofrom_h.f90 +++ b/g_tofrom_h.f90 @@ -112,7 +112,7 @@ subroutine gbar_to_g_kxkyz(g, apar, facapar) use stella_layouts, only: kxkyz_lo use stella_layouts, only: iky_idx, ikx_idx, iz_idx, it_idx, is_idx use gyro_averages, only: gyro_average - use run_parameters, only: maxwellian_normalization + use parameters_numerical, only: maxwellian_normalization implicit none @@ -151,7 +151,7 @@ subroutine gbar_to_g_1d_vpa(g, apar, imu, ikxkyz, facapar) use stella_layouts, only: kxkyz_lo use stella_layouts, only: iz_idx, is_idx use gyro_averages, only: gyro_average - use run_parameters, only: maxwellian_normalization + use parameters_numerical, only: maxwellian_normalization implicit none @@ -203,12 +203,12 @@ subroutine gbar_to_g_vmu_single(ivmu, g0, apar, facapar) use species, only: spec use zgrid, only: nzgrid, ntubes use stella_layouts, only: vmu_lo, iv_idx, imu_idx, is_idx - use kt_grids, only: naky, nakx - use kt_grids, only: multiply_by_rho + use parameters_kxky_grids, only: naky, nakx + use calculations_kxky, only: multiply_by_rho use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac use vpamu_grids, only: vpa use gyro_averages, only: gyro_average - use run_parameters, only: maxwellian_normalization + use parameters_numerical, only: maxwellian_normalization implicit none @@ -270,14 +270,14 @@ subroutine g_to_h_vmu_single(ivmu, g0, phi, bpar, facphi, phi_corr) use zgrid, only: nzgrid, ntubes use stella_layouts, only: vmu_lo, iv_idx, imu_idx, is_idx use geometry, only: bmag, dBdrho - use dist_fn_arrays, only: kperp2, dkperp2dr - use kt_grids, only: naky, nakx - use kt_grids, only: multiply_by_rho + use arrays_dist_fn, only: kperp2, dkperp2dr + use parameters_kxky_grids, only: naky, nakx + use calculations_kxky, only: multiply_by_rho use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac use vpamu_grids, only: vpa, vperp2, mu use gyro_averages, only: gyro_average, gyro_average_j1, aj0x, aj1x - use physics_flags, only: radial_variation, include_bpar - use run_parameters, only: maxwellian_normalization + use parameters_physics, only: radial_variation, include_bpar + use parameters_numerical, only: maxwellian_normalization implicit none @@ -346,6 +346,56 @@ subroutine g_to_h_vmu_single(ivmu, g0, phi, bpar, facphi, phi_corr) end subroutine g_to_h_vmu_single +! subroutine g_to_h_vmu_zext (gext, phiext, facphi, iky, ie) + +! use species, only: spec +! use extended_zgrid, only: ikxmod +! use extended_zgrid, only: iz_low, iz_up +! use extended_zgrid, only: nsegments +! use vpamu_grids, only: maxwell_vpa, maxwell_mu +! use stella_layouts, only: vmu_lo +! use stella_layouts, only: iv_idx, imu_idx, is_idx +! use gyro_averages, only: aj0x + +! implicit none +! complex, dimension (:,vmu_lo%llim_proc:), intent (in out) :: gext +! complex, dimension (:), intent (in) :: phiext +! real, intent (in) :: facphi +! integer, intent (in) :: iky, ie + +! integer :: ivmu, iseg, iz, ikx, is, imu, iv +! integer :: idx +! complex :: adj + +! do ivmu = vmu_lo%llim_proc, vmu_lo%ulim_proc +! iv = iv_idx(vmu_lo,ivmu) +! imu = imu_idx(vmu_lo,ivmu) +! is = is_idx(vmu_lo,ivmu) + +! idx = 0 +! iseg = 1 +! ikx = ikxmod(iseg,ie,iky) +! do iz = iz_low(iseg), iz_up(iseg) +! idx = idx + 1 +! adj = aj0x(iky,ikx,iz,ivmu)*spec(is)%zt*maxwell_vpa(iv)*maxwell_mu(1,iz,imu) & +! * facphi*phiext(idx) +! gext(idx,ivmu) = gext(idx,ivmu) + adj +! end do +! if (nsegments(ie,iky) > 1) then +! do iseg = 2, nsegments(ie,iky) +! do iz = iz_low(iseg)+1, iz_up(iseg) +! adj = aj0x(iky,ikx,iz,ivmu)*spec(is)%zt*maxwell_vpa(iv)*maxwell_mu(1,iz,imu) & +! * facphi*phiext(idx) +! gext(idx,ivmu) = gext(idx,ivmu) + adj +! idx = idx + 1 +! end do +! end do +! end if + +! end do + +! end subroutine g_to_h_vmu_zext + subroutine g_to_h_kxkyz(g, phi, bpar, facphi) use species, only: spec @@ -355,8 +405,8 @@ subroutine g_to_h_kxkyz(g, phi, bpar, facphi) use stella_layouts, only: kxkyz_lo use stella_layouts, only: iky_idx, ikx_idx, iz_idx, it_idx, is_idx use gyro_averages, only: gyro_average, gyro_average_j1 - use run_parameters, only: maxwellian_normalization - use physics_flags, only: include_bpar + use parameters_numerical, only: maxwellian_normalization + use parameters_physics, only: include_bpar implicit none @@ -414,14 +464,15 @@ subroutine g_to_f_vmu(g, phi, facphi, phi_corr) use stella_layouts, only: vmu_lo use stella_layouts, only: iv_idx, imu_idx, is_idx use geometry, only: bmag, dBdrho - use dist_fn_arrays, only: kperp2, dkperp2dr - use kt_grids, only: naky, nakx, multiply_by_rho + use arrays_dist_fn, only: kperp2, dkperp2dr + use parameters_kxky_grids, only: naky, nakx + use calculations_kxky, only: multiply_by_rho use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac, vperp2, mu, vpa use stella_transforms, only: transform_kx2x_xfirst, transform_x2kx_xfirst use gyro_averages, only: gyro_average, aj0x, aj1x - use physics_flags, only: radial_variation + use parameters_physics, only: radial_variation - use physics_flags, only: full_flux_surface + use parameters_physics, only: full_flux_surface use gyro_averages, only: j0_ffs implicit none diff --git a/geometry/geometry.f90 b/geometry/geometry.f90 index 36a26786d8..f73e9944a8 100644 --- a/geometry/geometry.f90 +++ b/geometry/geometry.f90 @@ -15,6 +15,7 @@ module geometry + use debug_flags, only: debug => geometry_debug use common_types, only: flux_surface_type implicit none @@ -58,9 +59,6 @@ module geometry private - ! Debugging - logical :: debug = .false. - type(flux_surface_type) :: geo_surf real :: grad_x_grad_y_end, clebsch_factor @@ -127,7 +125,7 @@ subroutine init_geometry(nalpha, naky) use vmec_geometry, only: read_vmec_parameters, get_vmec_geometry ! Flags - use physics_flags, only: include_geometric_variation + use parameters_physics, only: include_geometric_variation ! Routines use file_utils, only: get_unused_unit @@ -342,7 +340,7 @@ subroutine get_geometry_arrays_from_VMEC(nalpha, naky) use vmec_geometry, only: read_vmec_parameters, get_vmec_geometry use vmec_geometry, only: radial_coordinate_option, radial_coordinate_sgnpsitpsit use vmec_geometry, only: radial_coordinate_minuspsit, radial_coordinate_r - use physics_flags, only: const_alpha_geo + use debug_flags, only: const_alpha_geo use zgrid, only: nzgrid implicit none @@ -987,7 +985,7 @@ end subroutine allocate_arrays subroutine read_parameters ! Flags - use physics_flags, only: radial_variation + use parameters_physics, only: radial_variation ! Multibox runs use file_utils, only: runtype_option_Switch, runtype_multibox @@ -1287,7 +1285,7 @@ end subroutine integrate_zed !============================================================================ subroutine get_x_to_rho(llim, x_in, rho_out) - use physics_parameters, only: rhostar + use parameters_physics, only: rhostar implicit none diff --git a/geometry/geometry_inputprofiles_interface.f90 b/geometry/geometry_inputprofiles_interface.f90 index a473c12240..9e9d230071 100644 --- a/geometry/geometry_inputprofiles_interface.f90 +++ b/geometry/geometry_inputprofiles_interface.f90 @@ -202,7 +202,7 @@ subroutine read_inputprof_spec(nspec, spec) use splines, only: geo_spline use common_types, only: spec_type use geometry_miller, only: local - use physics_parameters, only: vnew_ref, rhostar + use parameters_physics, only: vnew_ref, rhostar implicit none diff --git a/geometry/geometry_miller.f90 b/geometry/geometry_miller.f90 index 95c9cf40bd..2975243b1b 100644 --- a/geometry/geometry_miller.f90 +++ b/geometry/geometry_miller.f90 @@ -980,7 +980,6 @@ subroutine get_drho(f, df) real, dimension(:, -nz:), intent(in) :: f real, dimension(-nz:), intent(out) :: df - real :: zero df = 0.5 * (f(3, :) - f(1, :)) / local%dr @@ -995,7 +994,6 @@ subroutine get_d2dthet2(f, d2f) real, dimension(-nz:), intent(in) :: f real, dimension(-nz:), intent(out) :: d2f - real :: zero ! assuming equal grid spacing in theta here d2f(-nz + 1:nz - 1) = (f(:nz - 2) - 2.*f(-nz + 1:nz - 1) + f(-nz + 2:)) / delthet(-nz + 1:nz - 1)**2 @@ -1015,7 +1013,6 @@ subroutine get_dthet(f, df) real, dimension(-nz:), intent(in) :: f real, dimension(-nz:), intent(out) :: df - real :: zero ! assuming equal grid spacing in theta here df(-nz + 1:nz - 1) = (f(-nz + 2:) - f(:nz - 2)) / (delthet(:nz - 2) + delthet(-nz + 1:)) @@ -1413,7 +1410,6 @@ subroutine theta_integrate_indef(integrand, integral) real, dimension(-nz:), intent(out) :: integral integer :: i - real :: zero ! use trapezoidal rule to integrate in theta integral(0) = 0.0 diff --git a/geometry/geometry_vmec.f90 b/geometry/geometry_vmec.f90 index 5000486e0b..c3eb0a677f 100644 --- a/geometry/geometry_vmec.f90 +++ b/geometry/geometry_vmec.f90 @@ -191,7 +191,8 @@ subroutine get_vmec_geometry(nzgrid, nalpha, naky, surf, grho, bmag, & use constants, only: pi use common_types, only: flux_surface_type use splines, only: geo_spline - use physics_flags, only: full_flux_surface, const_alpha_geo + use parameters_physics, only: full_flux_surface + use debug_flags, only: const_alpha_geo use zgrid, only: zed_equal_arc, get_total_arc_length, get_arc_length_grid use zgrid, only: zed use geometry_vmec_read_netCDF_file, only: calculate_vmec_geometry diff --git a/git_version_impl.f90 b/git_version_impl.f90 index a447ec4504..032621046e 100644 --- a/git_version_impl.f90 +++ b/git_version_impl.f90 @@ -1,6 +1,7 @@ ! SPDX-License-Identifier: MIT + submodule (git_version) git_version_impl implicit none contains @@ -8,9 +9,9 @@ integer, parameter :: max_length = 40 integer :: length - length = min(max_length, len("v0.5.1-370-g195f3b679-dirty")) + length = min(max_length, len("v0.5.1-359-g0680478343-dirty")) allocate(character(length)::get_git_version) - get_git_version = "v0.5.1-370-g195f3b679-dirty"(1:length) + get_git_version = "v0.5.1-359-g0680478343-dirty"(1:length) get_git_version = trim(get_git_version) end procedure get_git_version @@ -25,7 +26,7 @@ end if allocate(character(length)::get_git_hash) - get_git_hash = "195f3b6799303aca690d9a6fc0fd4a51749d27d6"(1:length) + get_git_hash = "0680478343e987c2265329e8cadeb4da034418ee"(1:length) end procedure get_git_hash module procedure get_git_state @@ -37,6 +38,7 @@ end procedure get_git_state module procedure get_git_date - get_git_date = "2024-07-26" + get_git_date = "2024-08-05" end procedure get_git_date end submodule git_version_impl + diff --git a/grids_kxky.f90 b/grids_kxky.f90 new file mode 100644 index 0000000000..8c2d767b88 --- /dev/null +++ b/grids_kxky.f90 @@ -0,0 +1,509 @@ +module grids_kxky + + implicit none + + public :: init_grids_kxky, finish_grids_kxky + + public :: aky, akx + public :: aky_all, aky_all_ordered + public :: theta0, zed0 + public :: zonal_mode + + public :: x, x_d, y + public :: dy, dx + public :: boundary_size, copy_size, krook_size + + public :: rho, rho_d, rho_clamped, rho_d_clamped + public :: g0x + public :: box + + private + + real, dimension(:), allocatable :: aky, akx + real, dimension(:), allocatable :: aky_all, aky_all_ordered + real, dimension(:, :), allocatable :: theta0, zed0 + real, dimension(:), allocatable :: x, x_d, y + logical, dimension(:), allocatable :: zonal_mode + + !> For radial variation + real, dimension(:), allocatable :: rho, rho_d, rho_clamped, rho_d_clamped + complex, dimension(:, :), allocatable :: g0x + + !> Not allocated here - need to work out where to put these + integer :: boundary_size, copy_size, krook_size + + !> Required for flux calculations + real :: dx, dy + + !> Internal Calculations + real :: dkx, dky, dx_d + logical :: box + + logical :: initialised + +contains + + !====================================================================== + !======================= INITIALISE KXKY GRIDS ======================== + !====================================================================== + subroutine init_grids_kxky + + use mp, only: mp_abort + use common_types, only: flux_surface_type + use zgrid, only: init_zgrid + use parameters_kxky_grids, only: gridopt_switch, gridopt_range, gridopt_box + use parameters_kxky_grids, only: naky + + implicit none + + if (initialised) return + + + call init_zgrid + + select case (gridopt_switch) + case (gridopt_range) + call init_grids_kxky_range + case (gridopt_box) + call init_grids_kxky_box + end select + + !> determine if iky corresponds to zonal mode + if (.not. allocated(zonal_mode)) allocate (zonal_mode(naky)) + zonal_mode = .false. + if (abs(aky(1)) < epsilon(0.)) zonal_mode(1) = .true. + + initialised = .true. + + contains + + !********************************************************************** + ! INITIALISE RANGE KXKY GRID ! + !********************************************************************** + !> DESCRIPTION + !********************************************************************** + + subroutine init_grids_kxky_range + + use common_types, only: flux_surface_type + use geometry, only: geo_surf, q_as_x + use zgrid, only: shat_zero + + use parameters_kxky_grids, only: naky, nakx, aky_min, aky_max, & + akx_min, akx_max, theta0_min, theta0_max, & + kyspacing_option_switch, kyspacing_linear, kyspacing_exponential, & + ikx_max, naky_all + + implicit none + + integer :: i, j + real :: dkx, dky, dtheta0, tfac + real :: zero + + box = .false. + call allocate_arrays + + ! NB: we are assuming here that all ky are positive + ! when running in range mode + dky = 0.0 + + if (naky > 1) then + select case (kyspacing_option_switch) + case (kyspacing_linear) + dky = (aky_max - aky_min) / real(naky - 1) + aky = (/(aky_min + dky * real(i), i=0, naky - 1)/) + case (kyspacing_exponential) + dky = (log(aky_max) - log(aky_min)) / real(naky - 1) + aky = (/(exp(log(aky_min) + dky * real(i)), i=0, naky - 1)/) + end select + else + aky = (/(aky_min, i=0, naky - 1)/) + end if + + ! set default kx and theta0 to 0 + akx = 0.0; theta0 = 0.0 + + if (q_as_x) then + tfac = 1.0 + else + tfac = geo_surf%shat + end if + + zero = 100.*epsilon(0.) + + ! if theta0_min and theta0_max have been specified, + ! use them to determine akx_min and akx_max + if (theta0_max > theta0_min - zero) then + if (geo_surf%shat > epsilon(0.)) then + akx_min = theta0_min * tfac * aky(1) + akx_max = theta0_max * tfac * aky(1) + else + akx_min = theta0_max * tfac * aky(1) + akx_max = theta0_min * tfac * aky(1) + end if + end if + + ! shat_zero is minimum shat value below which periodic BC is enforced + if (abs(geo_surf%shat) > shat_zero) then ! ie assumes boundary_option .eq. 'linked' + ! if kx_min and akx_max specified in input + ! instead of theta0_min and theta0_max, + ! use them to get theta0_min and theta0_max + if (theta0_min > theta0_max + zero .and. abs(aky(1)) > zero) then + theta0_min = akx_min / (tfac * aky(1)) + theta0_max = akx_max / (tfac * aky(1)) + dtheta0 = 0.0 + if (nakx > 1) dtheta0 = (theta0_max - theta0_min) / real(nakx - 1) + + do j = 1, naky + theta0(j, :) & + = (/(theta0_min + dtheta0 * real(i), i=0, nakx - 1)/) + end do + akx= theta0(1, :) * tfac * aky(1) + else if (akx_max > akx_min - zero .or. nakx == 1) then + dkx = 0.0 + if (nakx > 1) dkx = (akx_max - akx_min) / real(nakx - 1) + akx = (/(akx_min + dkx * real(i), i=0, nakx - 1)/) + + dtheta0 = 0.0 + if (nakx > 1) dtheta0 = (theta0_max - theta0_min) / real(nakx - 1) + + if (geo_surf%shat > epsilon(0.)) then + do j = 1, naky + theta0(j, :) & + = (/(theta0_min + dtheta0 * real(i), i=0, nakx - 1)/) + end do + else + do j = 1, naky + theta0(j, :) & + = (/(theta0_min + dtheta0 * real(i), i=nakx - 1, 0, -1)/) + end do + end if + else + call mp_abort('ky=0 is inconsistent with akx_min different from akx_max. aborting.') + end if + + else + ! here assume boundary_option .eq. 'periodic' + ! used for periodic finite kx ballooning space runs with shat=0 + dkx = 0.0 + if (nakx > 1) dkx = (akx_max - akx_min) / real(nakx - 1) + akx = (/(akx_min + dkx * real(i), i=0, nakx - 1)/) + end if + + zed0 = theta0 * geo_surf%zed0_fac + + ikx_max = nakx + naky_all = naky + + end subroutine init_grids_kxky_range + + + !********************************************************************** + ! INITIALISE BOX KXKY GRID ! + !********************************************************************** + !> DESCRIPTION + !********************************************************************** + subroutine init_grids_kxky_box + + use mp, only: mp_abort, proc0, broadcast + use common_types, only: flux_surface_type + use constants, only: pi, zi + use geometry, only: geo_surf, twist_and_shift_geo_fac, dydalpha + use geometry, only: q_as_x, get_x_to_rho, dxdpsi, drhodpsi + use geometry, only: geo_option_switch, geo_option_vmec + use parameters_physics, only: rhostar + use parameters_physics, only: full_flux_surface, radial_variation + use file_utils, only: runtype_option_switch, runtype_multibox + use zgrid, only: nperiod + use zgrid, only: boundary_option_switch, boundary_option_linked + use zgrid, only: boundary_option_linked_stellarator + use ran, only: ranf + + use write_radial_grid, only: dump_radial_grid + + use parameters_kxky_grids, only: nx, ny, ikx_max, naky_all, naky, nakx, & + x0, y0, jtwist, jtwistfac, phase_shift_angle, ikx_twist_shift, & + centered_in_rho, randomize_phase_shift, periodic_variation + + implicit none + + integer :: ikx, iky + integer :: ikyneg + real :: x_shift, dqdrho, pfac, norm + + box = .true. + call allocate_arrays + + !> set jtwist and y0 for cases where they have not been specified + !> and for which it makes sense to set them automatically + if (jtwist < 1) then + jtwist = max(1, int(abs(twist_and_shift_geo_fac) + 0.5)) + jtwist = max(1, int(jtwistfac * jtwist + 0.5)) + end if + !> signed version of jtwist, with sign determined by, e.g., magnetic shear + ikx_twist_shift = -jtwist * int(sign(1.0, twist_and_shift_geo_fac)) + + if (y0 < 0.) then + if (full_flux_surface) then + !> if simulating a flux annulus, then + !> y0 determined by the physical + !> extent of the device + if (rhostar > 0.) then + !y0 = 1./(rhostar*geo_surf%rhotor) + y0 = geo_surf%rhotor / rhostar + else + call mp_abort('must set rhostar if simulating a full flux surface. aborting.') + end if + else + !> if simulating a flux tube + !> makes no sense to have y0 < 0.0 + !> so abort + call mp_abort('y0 negative only makes sense when simulating a flux annulus. aborting.') + end if + end if + + !> get the grid spacing in ky and then in kx using twist-and-shift BC + dky = 1./y0 + + ! kx = ky * twist_shift_geo_fac / jtwist for every linked boundary condition + ! except for the periodic ones + select case (boundary_option_switch) + case (boundary_option_linked) + dkx = (2 * nperiod - 1) * dky * abs(twist_and_shift_geo_fac) / real(jtwist) + case (boundary_option_linked_stellarator) + dkx = dky * abs(twist_and_shift_geo_fac) / real(jtwist) + case default + if (x0 < epsilon(0.0)) then + dkx = dky + else + dkx = 1./x0 + end if + end select + + x0 = 1./dkx + + !> ky goes from zero to aky_max + do iky = 1, naky + aky(iky) = real(iky - 1) * dky + end do + + !> aky_all contains all ky values (positive and negative), + !> stored in the same order as akx (0 -> aky_max, -aky_max -> -dky) + !> first set arrays equal for ky >= 0 + aky_all(:naky) = aky + !> aky_all_ordered contains all ky values, stored from + !> most negative to most positive (-aky_max -> aky_max) + aky_all_ordered(naky:naky_all) = aky + !> next fill in ky < 0 + do iky = naky + 1, naky_all + !> this is the ky index corresponding to +ky in original array + ikyneg = naky_all - iky + 2 + aky_all(iky) = -aky(ikyneg) + end do + aky_all_ordered(:naky - 1) = aky_all(naky + 1:) + + !> kx goes from zero to kx_max down to zero... + do ikx = 1, ikx_max + akx(ikx) = real(ikx - 1) * dkx + end do + !> and then from -kx_max to -|akx_min| + do ikx = ikx_max + 1, nakx + akx(ikx) = real(ikx - nakx - 1) * dkx + end do + + !> set theta0=0 for ky=0 + theta0(1, :) = 0.0 + if (q_as_x) then + do ikx = 1, nakx + !> theta0 = kx/ky + theta0(2:, ikx) = akx(ikx) / aky(2:) + end do + else + do ikx = 1, nakx + !> theta0 = kx/ky/shat + theta0(2:, ikx) = akx(ikx) / (aky(2:) * geo_surf%shat) + end do + end if + + norm = 1. + if (naky > 1) norm = aky(2) + if (rhostar > 0.) then + if (geo_option_switch == geo_option_vmec) then + phase_shift_angle = -2.*pi * (2 * nperiod - 1) * dydalpha / (rhostar * geo_surf%qinp_psi0) + else + phase_shift_angle = -2.*pi * (2 * nperiod - 1) * geo_surf%qinp_psi0 * dydalpha / rhostar + end if + else if (randomize_phase_shift) then + if (proc0) phase_shift_angle = 2.*pi * ranf() / norm + call broadcast(phase_shift_angle) + else + phase_shift_angle = 2.*pi * phase_shift_angle / norm + end if + + !> MAB: a lot of the radial variation coding below should probably be tidied away + !> into one or more separate subroutines + + dx = (2 * pi * x0) / nx + dy = (2 * pi * y0) / ny + + x_shift = pi * x0 + pfac = 1.0 + if (periodic_variation) pfac = 0.5 + if (centered_in_rho) then + if (q_as_x) then + dqdrho = geo_surf%shat * geo_surf%qinp / geo_surf%rhoc + x_shift = pi * x0 * (1.0 - 0.5 * pfac * rhostar * pi * x0 * geo_surf%d2qdr2 / (dqdrho**2 * dxdpsi)) + else + x_shift = pi * x0 * (1.0 - 0.5 * pfac * rhostar * pi * x0 * geo_surf%d2psidr2 * drhodpsi**2 / dxdpsi) + end if + end if + + do ikx = 1, nx + if (radial_variation .or. runtype_option_switch == runtype_multibox) then + if (periodic_variation) then + if (ikx <= nx / 2) then + x(ikx) = (ikx - 1) * dx - 0.5 * x_shift + else + x(ikx) = x(nx - ikx + 1) + end if + else + x(ikx) = (ikx - 0.5) * dx - x_shift + end if + else + x(ikx) = (ikx - 1) * dx + end if + end do + + dx_d = (2 * pi * x0) / nakx + do ikx = 1, nakx + if (radial_variation .or. runtype_option_switch == runtype_multibox) then + if (periodic_variation) then + if (ikx <= (nakx + 1) / 2) then + x_d(ikx) = (ikx - 1) * dx_d - 0.5 * x_shift + else + x_d(ikx) = x_d(nakx - ikx + 1) + end if + else + x_d(ikx) = (ikx - 0.5) * dx_d - x_shift + end if + else + x_d(ikx) = (ikx - 1) * dx_d + end if + end do + + call get_x_to_rho(1, x, rho) + call get_x_to_rho(1, x_d, rho_d) + + rho_clamped = rho + rho_d_clamped = rho_d + + zed0 = theta0 * geo_surf%zed0_fac + + if (radial_variation) call dump_radial_grid (x, rho, nx) + + if (radial_variation .and. (any((rho + geo_surf%rhoc) < 0.0) & + .or. any((rho + geo_surf%rhoc) > 1.0))) then + call mp_abort('rho(x) is beyond range [0,1]. Try changing rhostar or q/psi profiles') + end if + + do iky = 1, ny + y(iky) = (iky - 1) * dy + end do + + call broadcast_parameters + + end subroutine init_grids_kxky_box + + !********************************************************************** + ! ALLOCATE ARRAYS FOR KXKY GRIDS ! + !********************************************************************** + !> DESCRIPTION + !********************************************************************** + + subroutine allocate_arrays + + use parameters_kxky_grids, only: nakx, naky, naky_all, nx , ny + + implicit none + + if(.not. allocated(akx)) allocate (akx(nakx)) + if(.not. allocated(aky)) allocate (aky(naky)) + if(.not. allocated(aky_all)) allocate(aky_all(naky_all)) + if(.not. allocated(aky_all_ordered)) allocate (aky_all_ordered(naky_all)) + if(.not. allocated(theta0)) allocate (theta0(naky, nakx)) + if(.not. allocated(zed0)) allocate (zed0(naky, nakx)) + + if (box) then + if (.not. allocated(x_d)) allocate (x_d(nakx)) + if (.not. allocated(rho)) allocate (rho(nx)) + if (.not. allocated(rho_d)) allocate (rho_d(nakx)) + if (.not. allocated(rho_clamped)) allocate (rho_clamped(nx)) + if (.not. allocated(rho_d_clamped)) allocate (rho_d_clamped(nakx)) + + if (.not. allocated(x)) allocate (x(nx)) + if (.not. allocated(y)) allocate (y(ny)) + + end if + + end subroutine allocate_arrays + + + end subroutine init_grids_kxky + + subroutine broadcast_parameters + + use mp, only: broadcast + + implicit none + + ! call broadcast(akx) + ! call broadcast(aky) + ! call broadcast(aky_all) + ! call broadcast(aky_all_ordered) + ! call broadcast(theta0) + ! call broadcast(zed0) + +! if(box) then + call broadcast(x_d) + call broadcast(rho) + call broadcast(rho_d) + call broadcast(rho_clamped) + call broadcast(rho_d_clamped) +! call broadcast(x) +! call broadcast(y) +! end if + + end subroutine broadcast_parameters + + !====================================================================== + !======================= INITIALISE KXKY GRIDS ======================== + !====================================================================== + + subroutine finish_grids_kxky + + use parameters_kxky_grids, only: reality + implicit none + + if (allocated(aky)) deallocate (aky) + if (allocated(aky_all)) deallocate (aky_all) + if (allocated(aky_all_ordered)) deallocate (aky_all_ordered) + if (allocated(akx)) deallocate (akx) + if (allocated(theta0)) deallocate (theta0) + if (allocated(zed0)) deallocate (zed0) + + if (allocated(x)) deallocate (x) + if (allocated(y)) deallocate (y) + + if (allocated(x_d)) deallocate (x_d) + if (allocated(rho)) deallocate (rho) + if (allocated(rho_d)) deallocate (rho_d) + if (allocated(rho_clamped)) deallocate (rho_clamped) + if (allocated(rho_d_clamped)) deallocate (rho_d_clamped) + + if (allocated(g0x)) deallocate (g0x) + + reality = .false. + initialised = .false. + end subroutine finish_grids_kxky + +end module grids_kxky diff --git a/gyro_averages.f90 b/gyro_averages.f90 index 0fe2c26700..dcc4b1e80b 100644 --- a/gyro_averages.f90 +++ b/gyro_averages.f90 @@ -1,7 +1,8 @@ module gyro_averages use common_types, only: coupled_alpha_type - + use debug_flags, only: debug => gyro_averages_debug + public :: aj0x, aj0v, aj1x, aj1v public :: init_bessel, finish_bessel public :: gyro_average @@ -49,8 +50,6 @@ module gyro_averages logical :: bessinit = .false. - logical :: debug = .false. - type(coupled_alpha_type), dimension(:, :, :, :), allocatable :: j1_ffs real, dimension(:, :, :, :), allocatable :: j0_const, j0_B_const, j0max_const @@ -58,13 +57,13 @@ module gyro_averages subroutine init_bessel - use dist_fn_arrays, only: kperp2 - use physics_flags, only: full_flux_surface + use arrays_dist_fn, only: kperp2 + use parameters_physics, only: full_flux_surface use species, only: spec use geometry, only: bmag use zgrid, only: nzgrid use vpamu_grids, only: vperp2, nmu - use kt_grids, only: naky, nakx + use parameters_kxky_grids, only: naky, nakx use stella_layouts, only: kxkyz_lo, vmu_lo use stella_layouts, only: iky_idx, ikx_idx, iz_idx, is_idx, imu_idx use spfunc, only: j0, j1 @@ -265,11 +264,12 @@ subroutine init_bessel_ffs use zgrid, only: nzgrid, nztot use vpamu_grids, only: nmu, nvpa use vpamu_grids, only: vperp2, maxwell_vpa, maxwell_mu - use kt_grids, only: nalpha, naky, naky_all, ikx_max - use kt_grids, only: swap_kxky_ordered - use dist_fn_arrays, only: kperp2 + use parameters_kxky_grids, only: nalpha, naky, naky_all, ikx_max + use calculations_kxky, only: swap_kxky_ordered + use arrays_dist_fn, only: kperp2 - use kt_grids, only: nakx, swap_kxky_back_ordered + use parameters_kxky_grids, only: nakx + use calculations_kxky, only: swap_kxky_back_ordered use spfunc, only: j1 implicit none @@ -653,7 +653,7 @@ end subroutine gyro_average_local subroutine gyro_average_kxky_local(field, iz, ivmu, gyro_field) - use physics_flags, only: full_flux_surface + use parameters_physics, only: full_flux_surface implicit none @@ -674,7 +674,7 @@ end subroutine gyro_average_kxky_local subroutine gyro_average_kxkyz_local(field, ivmu, gyro_field) - use physics_flags, only: full_flux_surface + use parameters_physics, only: full_flux_surface use zgrid, only: nzgrid, ntubes implicit none @@ -696,7 +696,7 @@ end subroutine gyro_average_kxkyz_local subroutine gyro_average_kxkyzv_local(field, gyro_field) - use physics_flags, only: full_flux_surface + use parameters_physics, only: full_flux_surface use zgrid, only: nzgrid use stella_layouts, only: vmu_lo @@ -721,9 +721,9 @@ end subroutine gyro_average_kxkyzv_local subroutine gyro_average_ffs_kxky_local(field, gyro_field, coefs) - use kt_grids, only: naky - use kt_grids, only: naky_all, ikx_max - use kt_grids, only: swap_kxky_ordered, swap_kxky_back_ordered + use parameters_kxky_grids, only: naky + use parameters_kxky_grids, only: naky_all, ikx_max + use calculations_kxky, only: swap_kxky_ordered, swap_kxky_back_ordered implicit none @@ -972,7 +972,7 @@ subroutine gyro_average_j1_kxkyzv_local(field, gyro_field) use mp, only: proc0, mp_abort use zgrid, only: nzgrid use stella_layouts, only: vmu_lo - use physics_flags, only: full_flux_surface + use parameters_physics, only: full_flux_surface implicit none @@ -999,7 +999,7 @@ subroutine band_lu_solve_ffs(lu, solvec) use common_types, only: gam0_ffs_type use zgrid, only: nzgrid - use kt_grids, only: ikx_max + use parameters_kxky_grids, only: ikx_max implicit none @@ -1019,7 +1019,7 @@ end subroutine band_lu_solve_ffs subroutine band_lu_solve_ffs_single(lu, solvec) use common_types, only: gam0_ffs_type - use kt_grids, only: naky + use parameters_kxky_grids, only: naky implicit none @@ -1052,7 +1052,7 @@ subroutine band_lu_factorisation_ffs(gam0, lu_gam0) use common_types, only: coupled_alpha_type, gam0_ffs_type use zgrid, only: nzgrid - use kt_grids, only: ikx_max, naky_all, naky + use parameters_kxky_grids, only: ikx_max, naky_all, naky implicit none @@ -1082,7 +1082,7 @@ end subroutine band_lu_factorisation_ffs subroutine band_lu_factorisation_single(gam0, lu_gam0) use common_types, only: gam0_ffs_type - use kt_grids, only: naky, naky_all + use parameters_kxky_grids, only: naky, naky_all implicit none diff --git a/implicit_solve.f90 b/implicit_solve.f90 index ca2fa3d958..46141e8a56 100644 --- a/implicit_solve.f90 +++ b/implicit_solve.f90 @@ -1,5 +1,7 @@ module implicit_solve + use debug_flags, only: debug => implicit_solve_debug + implicit none public :: time_implicit_advance @@ -16,31 +18,29 @@ module implicit_solve subroutine advance_implicit_terms(g, phi, apar, bpar) - use mp, only: proc0 + use mp, only: proc0 + use job_manage, only: time_message use stella_layouts, only: vmu_lo - use physics_flags, only: include_apar, include_bpar + use parameters_physics, only: include_apar, include_bpar use zgrid, only: nzgrid, ntubes - use kt_grids, only: naky, nakx - use dist_fn_arrays, only: g1, g2 - use run_parameters, only: stream_matrix_inversion - use run_parameters, only: use_deltaphi_for_response_matrix - use run_parameters, only: tupwnd_p => time_upwind_plus - use run_parameters, only: tupwnd_m => time_upwind_minus - use run_parameters, only: fphi + use parameters_kxky_grids, only: naky, nakx + use arrays_dist_fn, only: g1, g2 + use parameters_numerical, only: stream_matrix_inversion + use parameters_numerical, only: use_deltaphi_for_response_matrix + use parameters_numerical, only: tupwnd_p => time_upwind_plus + use parameters_numerical, only: tupwnd_m => time_upwind_minus + use parameters_numerical, only: fphi use fields, only: advance_fields, fields_updated use extended_zgrid, only: map_to_extended_zgrid, map_from_extended_zgrid use extended_zgrid, only: nsegments, nzed_segment - use run_parameters, only: driftkinetic_implicit - use gyro_averages, only: gyro_average, j0_ffs, j0_const - use parallel_streaming, only: stream + use parameters_numerical, only: driftkinetic_implicit + use gyro_averages, only: gyro_average use stella_layouts, only: iv_idx, imu_idx, is_idx - use species, only: spec - use dist_fn_arrays, only: g0 use fields, only: get_fields_source - use run_parameters, only: nitt + use parameters_numerical, only: nitt use ffs_solve, only: get_source_ffs_itteration, get_drifts_ffs_itteration use species, only: has_electron_species @@ -54,16 +54,16 @@ subroutine advance_implicit_terms(g, phi, apar, bpar) complex, dimension(:, :, :, :), allocatable :: phi_source, apar_source, bpar_source character(5) :: dist_choice - logical :: implicit_solve = .false. complex, dimension(:, :, :, :, :), allocatable :: phi_source_ffs complex, dimension(:, :, :, :), allocatable :: fields_source_ffs complex, dimension(:, :, :, :, :), allocatable :: drifts_source_ffs - integer :: ikx, iky, iz integer :: itt logical :: modify - real :: error, tol + debug = debug .and. proc0 + if(debug) write (*,*) 'No debug messages for implicit_solve.f90 yet' + if(driftkinetic_implicit) then if (.not. allocated(phi_source_ffs)) allocate (phi_source_ffs(naky, nakx, -nzgrid:nzgrid, ntubes, vmu_lo%llim_proc:vmu_lo%ulim_alloc)) phi_source_ffs = 0.0 @@ -289,7 +289,7 @@ subroutine update_pdf(mod) ! to the standard zed domain; the mapped pdf is called 'g' call map_from_extended_zgrid(it, ie, iky, pdf2, g(iky, :, :, :, ivmu)) deallocate (pdf1, pdf2, phiext, aparext, aparext_new, aparext_old, bparext) - if (present(mod)) deallocate(phiffsext) + if (present(mod)) deallocate(phiffsext) end do end do end do @@ -309,8 +309,6 @@ end subroutine advance_implicit_terms !> for 'pdf', 'phi', 'apar', 'aparnew' and 'aparold' subroutine get_gke_rhs(ivmu, iky, ie, pdf, phi, apar, aparnew, aparold, bpar, rhs, phi_ffs) - use kt_grids, only: naky, nakx - implicit none integer, intent(in) :: ivmu, iky, ie @@ -353,7 +351,7 @@ end subroutine get_gke_rhs !> involving phi and apar that appear on the RHS of the GK equation when g is the pdf subroutine get_contributions_from_fields(phi, apar, aparnew, bpar, ivmu, iky, ie, scratch, rhs) - use physics_flags, only: include_apar, include_bpar + use parameters_physics, only: include_apar, include_bpar use extended_zgrid, only: map_to_iz_ikx_from_izext implicit none @@ -399,10 +397,9 @@ subroutine get_contributions_from_phi(phi, ivmu, iky, iz_from_izext, ikx_from_iz use zgrid, only: nzgrid, ntubes use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac, maxwell_mu_avg use vpamu_grids, only: vpa - use kt_grids, only: naky, nakx - use run_parameters, only: driftkinetic_implicit, maxwellian_normalization - use run_parameters, only: maxwellian_inside_zed_derivative - use run_parameters, only: drifts_implicit + use parameters_numerical, only: driftkinetic_implicit, maxwellian_normalization + use parameters_numerical, only: maxwellian_inside_zed_derivative + use parameters_numerical, only: drifts_implicit use stella_layouts, only: vmu_lo, iv_idx, imu_idx, is_idx use neoclassical_terms, only: include_neoclassical_terms use neoclassical_terms, only: dfneo_dvpa @@ -452,7 +449,7 @@ subroutine add_streaming_contribution_phi use parallel_streaming, only: center_zed use parallel_streaming, only: gradpar_c, stream_sign - use run_parameters, only: driftkinetic_implicit + use parameters_numerical, only: driftkinetic_implicit integer :: izext complex :: scratch_left, scratch_right @@ -475,8 +472,8 @@ subroutine add_streaming_contribution_phi ! and store in dummy variable z_scratch z_scratch = maxwell_mu(ia, :, imu, is) call center_zed(iv, z_scratch, -nzgrid) - else - z_scratch = 1.0 + else + z_scratch = 1.0 end if end if ! multiply by Maxwellian factor @@ -513,9 +510,8 @@ end subroutine add_streaming_contribution_phi subroutine add_drifts_contribution_phi use constants, only: zi - use kt_grids, only: nakx, naky - use kt_grids, only: aky, akx - use dist_fn_arrays, only: wstar, wdriftx_phi, wdrifty_phi + use grids_kxky, only: aky, akx + use arrays_dist_fn, only: wstar, wdriftx_phi, wdrifty_phi use parallel_streaming, only: center_zed use extended_zgrid, only: periodic @@ -546,10 +542,9 @@ subroutine get_contributions_from_bpar(bpar, ivmu, iky, iz_from_izext, ikx_from_ use zgrid, only: nzgrid, ntubes use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac use vpamu_grids, only: vpa, mu - use kt_grids, only: naky, nakx - use run_parameters, only: driftkinetic_implicit, maxwellian_normalization - use run_parameters, only: maxwellian_inside_zed_derivative - use run_parameters, only: drifts_implicit + use parameters_numerical, only: driftkinetic_implicit, maxwellian_normalization + use parameters_numerical, only: maxwellian_inside_zed_derivative + use parameters_numerical, only: drifts_implicit use stella_layouts, only: vmu_lo, iv_idx, imu_idx, is_idx use neoclassical_terms, only: include_neoclassical_terms use neoclassical_terms, only: dfneo_dvpa @@ -653,9 +648,8 @@ end subroutine add_streaming_contribution_bpar subroutine add_drifts_contribution_bpar use constants, only: zi - use kt_grids, only: nakx, naky - use kt_grids, only: aky, akx - use dist_fn_arrays, only: wstar, wdriftx_bpar, wdrifty_bpar + use grids_kxky, only: aky, akx + use arrays_dist_fn, only: wstar, wdriftx_bpar, wdrifty_bpar use parallel_streaming, only: center_zed use extended_zgrid, only: periodic @@ -684,7 +678,7 @@ end subroutine get_contributions_from_bpar !> involving apar that appear on the RHS of the GK equation when g is the pdf subroutine get_contributions_from_apar(apar, aparnew, ivmu, iky, iz_from_izext, ikx_from_izext, scratch, rhs) - use run_parameters, only: driftkinetic_implicit, drifts_implicit + use parameters_numerical, only: driftkinetic_implicit, drifts_implicit use stella_layouts, only: vmu_lo, iv_idx, imu_idx, is_idx implicit none @@ -734,7 +728,7 @@ end subroutine get_contributions_from_apar ! aparnew=0 so that scratch2 will be zero below subroutine add_gbar_to_g_contribution_apar(scratch2, iky, ia, iv, imu, is, nz_ext, iz_from_izext, rhs) - use run_parameters, only: maxwellian_normalization + use parameters_numerical, only: maxwellian_normalization use vpamu_grids, only: vpa, maxwell_vpa, maxwell_mu, maxwell_fac use parallel_streaming, only: center_zed use species, only: spec @@ -775,8 +769,8 @@ subroutine add_drifts_contribution_apar(scratch, iky, ia, ivmu, iv, is, nz_ext, use constants, only: zi use species, only: spec - use kt_grids, only: aky - use dist_fn_arrays, only: wstar + use grids_kxky, only: aky + use arrays_dist_fn, only: wstar use parallel_streaming, only: center_zed use extended_zgrid, only: periodic use vpamu_grids, only: vpa @@ -805,7 +799,7 @@ subroutine gbar_to_g_zext(pdf, apar, facapar, iky, ivmu, ikx_from_izext, iz_from use species, only: spec use stella_layouts, only: vmu_lo, iv_idx, imu_idx, is_idx - use run_parameters, only: maxwellian_normalization + use parameters_numerical, only: maxwellian_normalization use vpamu_grids, only: vpa, maxwell_vpa, maxwell_mu, maxwell_fac implicit none @@ -896,18 +890,17 @@ subroutine get_contributions_from_pdf(pdf, apar, ivmu, iky, ie, rhs, source_ffs) use constants, only: zi use stella_time, only: code_dt - use physics_flags, only: include_apar + use parameters_physics, only: include_apar use species, only: spec use zgrid, only: nzgrid, ntubes - use kt_grids, only: naky, nakx - use kt_grids, only: aky, akx + use grids_kxky, only: aky, akx use vpamu_grids, only: vpa use stella_layouts, only: vmu_lo, iv_idx, is_idx - use run_parameters, only: time_upwind_minus - use run_parameters, only: drifts_implicit + use parameters_numerical, only: time_upwind_minus + use parameters_numerical, only: drifts_implicit use parallel_streaming, only: get_zed_derivative_extended_domain, center_zed use parallel_streaming, only: gradpar_c, stream_sign - use dist_fn_arrays, only: wdriftx_g, wdrifty_g + use arrays_dist_fn, only: wdriftx_g, wdrifty_g use extended_zgrid, only: fill_zext_ghost_zones use extended_zgrid, only: map_to_iz_ikx_from_izext use extended_zgrid, only: periodic @@ -1004,11 +997,12 @@ subroutine sweep_g_zext(iky, ie, it, ivmu, pdf) use constants, only: zi use zgrid, only: nzgrid, ntubes, delzed - use run_parameters, only: drifts_implicit - use run_parameters, only: zed_upwind_plus, zed_upwind_minus - use run_parameters, only: time_upwind_plus - use kt_grids, only: nakx, akx, aky - use dist_fn_arrays, only: wdriftx_g, wdrifty_g + use parameters_numerical, only: drifts_implicit + use parameters_numerical, only: zed_upwind_plus, zed_upwind_minus + use parameters_numerical, only: time_upwind_plus + use parameters_kxky_grids, only: nakx + use grids_kxky, only: akx, aky + use arrays_dist_fn, only: wdriftx_g, wdrifty_g use extended_zgrid, only: map_to_extended_zgrid use extended_zgrid, only: periodic, phase_shift use parallel_streaming, only: stream_sign, stream_c @@ -1103,9 +1097,9 @@ end subroutine sweep_g_zext subroutine get_updated_pdf(iz, iv, is, sgn, iz1, iz2, wdrift_ext, pdf) use zgrid, only: nzgrid, delzed - use run_parameters, only: drifts_implicit - use run_parameters, only: zed_upwind_plus, zed_upwind_minus - use run_parameters, only: time_upwind_plus + use parameters_numerical, only: drifts_implicit + use parameters_numerical, only: zed_upwind_plus, zed_upwind_minus + use parameters_numerical, only: time_upwind_plus use parallel_streaming, only: stream_c implicit none @@ -1147,7 +1141,7 @@ subroutine sweep_zed_zonal(iky, iv, is, sgn, g, llim) use zgrid, only: nzgrid, delzed use extended_zgrid, only: phase_shift - use run_parameters, only: zed_upwind, time_upwind + use parameters_numerical, only: zed_upwind, time_upwind use parallel_streaming, only: stream_c implicit none @@ -1199,7 +1193,7 @@ end subroutine sweep_zed_zonal subroutine invert_parstream_response(phi, apar, bpar) use linear_solve, only: lu_back_substitution - use physics_flags, only: include_apar, include_bpar + use parameters_physics, only: include_apar, include_bpar use zgrid, only: nzgrid, ntubes use extended_zgrid, only: neigen use extended_zgrid, only: nsegments @@ -1208,9 +1202,9 @@ subroutine invert_parstream_response(phi, apar, bpar) use extended_zgrid, only: map_from_extended_zgrid use extended_zgrid, only: ikxmod use extended_zgrid, only: periodic, phase_shift - use kt_grids, only: naky + use parameters_kxky_grids, only: naky use fields, only: nfields - use fields_arrays, only: response_matrix + use arrays_fields, only: response_matrix implicit none diff --git a/init_g.f90 b/init_g.f90 index 190416237e..0f5e4253db 100644 --- a/init_g.f90 +++ b/init_g.f90 @@ -105,7 +105,7 @@ end subroutine init_init_g subroutine ginit(restarted, istep0) use stella_save, only: init_tstart - use run_parameters, only: maxwellian_normalization + use parameters_numerical, only: maxwellian_normalization logical, intent(out) :: restarted integer, intent(out) :: istep0 @@ -170,32 +170,32 @@ subroutine read_parameters oddparity integer :: ierr, in_file - tstart = 0. ! Used for restarted simulations - scale = 1.0 ! Used for restarted simulations - ginit_option = "default" ! Select the - width0 = -3.5 ! Used for = {default, kpar} - refac = 1. ! Used for = {kpar} - imfac = 0. ! Used for = {kpar} - den0 = 1. ! Used for = {default, kpar} - upar0 = 0. ! Used for = {default, kpar} - tpar0 = 0. ! Used for = {kpar} - tperp0 = 0. ! Used for = {kpar} - den1 = 0. ! Used for = {kpar} - upar1 = 0. ! Used for = {kpar} - tpar1 = 0. ! Used for = {kpar} - tperp1 = 0. ! Used for = {kpar} - den2 = 0. ! Used for = {kpar} - upar2 = 0. ! Used for = {kpar} - tpar2 = 0. ! Used for = {kpar} - tperp2 = 0. ! Used for = {kpar} - phiinit = 1.0 ! Used in all - zf_init = 1.0 ! Used for = {noise} - kxmax = 1.e100 ! Used for = {rh} - kxmin = 0. ! Used for = {rh} - chop_side = .false. ! Used for = {default, noise, kpar} - scale_to_phiinit = .false. ! Used to call rescale_fields() to rescale {phi, apar, g} to - left = .true. ! Used for = {default, noise, kpar} - oddparity = .false. ! Used for = {default} + tstart = 0. ! Used for restarted simulations + scale = 1.0 ! Used for restarted simulations + ginit_option = "default" ! Select the + width0 = -3.5 ! Used for = {default, kpar} + refac = 1. ! Used for = {kpar} + imfac = 0. ! Used for = {kpar} + den0 = 1. ! Used for = {default, kpar} + upar0 = 0. ! Used for = {default, kpar} + tpar0 = 0. ! Used for = {kpar} + tperp0 = 0. ! Used for = {kpar} + den1 = 0. ! Used for = {kpar} + upar1 = 0. ! Used for = {kpar} + tpar1 = 0. ! Used for = {kpar} + tperp1 = 0. ! Used for = {kpar} + den2 = 0. ! Used for = {kpar} + upar2 = 0. ! Used for = {kpar} + tpar2 = 0. ! Used for = {kpar} + tperp2 = 0. ! Used for = {kpar} + phiinit = 1.0 ! Used in all + zf_init = 1.0 ! Used for = {noise} + kxmax = 1.e100 ! Used for = {rh} + kxmin = 0. ! Used for = {rh} + chop_side = .false. ! Used for = {default, noise, kpar} + scale_to_phiinit = .false. ! Used to call rescale_fields() to rescale {phi, apar, g} to + left = .true. ! Used for = {default, noise, kpar} + oddparity = .false. ! Used for = {default} restart_file = trim(run_name)//".nc" restart_dir = "./" @@ -214,13 +214,13 @@ subroutine ginit_default use constants, only: zi use species, only: spec use zgrid, only: nzgrid, zed - use kt_grids, only: naky, nakx, ikx_max - use kt_grids, only: theta0, akx - use kt_grids, only: reality, zonal_mode + use parameters_kxky_grids, only: naky, nakx, ikx_max + use grids_kxky, only: theta0, akx, zonal_mode + use parameters_kxky_grids, only: reality use vpamu_grids, only: nvpa, nmu use vpamu_grids, only: vpa use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac - use dist_fn_arrays, only: gvmu + use arrays_dist_fn, only: gvmu use stella_layouts, only: kxkyz_lo, iz_idx, ikx_idx, iky_idx, is_idx use ran, only: ranf @@ -398,22 +398,23 @@ end subroutine ginit_default subroutine ginit_noise use mp, only: proc0, broadcast - use dist_fn_arrays, only: kperp2 + use arrays_dist_fn, only: kperp2 use species, only: spec use zgrid, only: nzgrid, ntubes use extended_zgrid, only: ikxmod, nsegments, neigen use extended_zgrid, only: it_right use extended_zgrid, only: periodic, phase_shift - use kt_grids, only: naky, nakx, reality, zonal_mode + use parameters_kxky_grids, only: naky, nakx, reality + use grids_kxky, only: zonal_mode use vpamu_grids, only: nvpa, nmu use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac - use dist_fn_arrays, only: gvmu + use arrays_dist_fn, only: gvmu use stella_layouts, only: kxkyz_lo use stella_layouts, only: iky_idx, ikx_idx, iz_idx, it_idx, is_idx use mp, only: proc0, broadcast, max_allreduce use mp, only: scope, crossdomprocs, subprocs use file_utils, only: runtype_option_switch, runtype_multibox - use physics_flags, only: nonlinear + use parameters_physics, only: nonlinear use ran implicit none @@ -542,11 +543,12 @@ subroutine ginit_kpar ! use species, only: spec, has_electron_species use zgrid, only: nzgrid, zed - use kt_grids, only: naky, nakx, theta0 + use parameters_kxky_grids, only: naky, nakx + use grids_kxky, only: theta0 use vpamu_grids, only: nvpa, nmu use vpamu_grids, only: vpa, vperp2 use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac - use dist_fn_arrays, only: gvmu + use arrays_dist_fn, only: gvmu use stella_layouts, only: kxkyz_lo, iky_idx, ikx_idx, iz_idx, is_idx use constants, only: zi @@ -615,12 +617,12 @@ end subroutine ginit_kpar subroutine ginit_rh use species, only: spec - use dist_fn_arrays, only: gvmu, kperp2 + use arrays_dist_fn, only: gvmu, kperp2 use stella_layouts, only: kxkyz_lo use stella_layouts, only: iky_idx, ikx_idx, iz_idx, is_idx use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac use vpamu_grids, only: nvpa, nmu - use kt_grids, only: akx + use grids_kxky, only: akx implicit none @@ -650,7 +652,7 @@ end subroutine ginit_rh subroutine ginit_remap use species, only: spec - use dist_fn_arrays, only: gvmu + use arrays_dist_fn, only: gvmu use stella_layouts, only: kxkyz_lo use stella_layouts, only: iky_idx, ikx_idx, iz_idx, is_idx use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac @@ -682,7 +684,7 @@ end subroutine ginit_remap subroutine ginit_restart_many - use dist_fn_arrays, only: gvmu + use arrays_dist_fn, only: gvmu use stella_save, only: stella_restore use mp, only: proc0 use file_utils, only: error_unit @@ -706,7 +708,7 @@ end subroutine ginit_restart_many subroutine normalize_by_maxwellian use stella_layouts, only: kxkyz_lo, is_idx, iz_idx - use dist_fn_arrays, only: gvmu + use arrays_dist_fn, only: gvmu use vpamu_grids, only: nmu use vpamu_grids, only: maxwell_mu, maxwell_vpa, maxwell_fac diff --git a/kt_grids.f90 b/kt_grids.f90 deleted file mode 100644 index 7edb0c910a..0000000000 --- a/kt_grids.f90 +++ /dev/null @@ -1,936 +0,0 @@ -! Set up the perpendicular wavenumbers by calling the appropriate sub-modules. -module kt_grids - - implicit none - - public :: init_kt_grids, finish_kt_grids - public :: read_kt_grids_parameters, box - public :: aky, theta0, akx, zed0 - public :: aky_all, aky_all_ordered - public :: naky, nakx, nx, ny, reality - public :: dx, dy, dkx, dky, dx_d - public :: jtwist, jtwistfac, ikx_twist_shift, x0, y0 - public :: x, x_d, y - public :: rho, rho_d, rho_clamped, rho_d_clamped - public :: nalpha - public :: ikx_max, naky_all - public :: phase_shift_angle - public :: zonal_mode - public :: swap_kxky, swap_kxky_back - public :: swap_kxky_ordered, swap_kxky_back_ordered - public :: multiply_by_rho, centered_in_rho - public :: periodic_variation - public :: communicate_ktgrids_multibox - public :: boundary_size, copy_size, krook_size - - private - - interface swap_kxky - module procedure swap_kxky_real - module procedure swap_kxky_complex - end interface - interface swap_kxky_ordered - module procedure swap_kxky_ordered_real - module procedure swap_kxky_ordered_complex - end interface - - real, dimension(:, :), allocatable :: theta0, zed0 - real, dimension(:), allocatable :: aky, akx, aky_all, aky_all_ordered - real, dimension(:), allocatable :: x, x_d, y - real, dimension(:), allocatable :: rho, rho_d, rho_clamped, rho_d_clamped - complex, dimension(:, :), allocatable :: g0x - real :: dx, dy, dkx, dky, dx_d - real :: jtwistfac, phase_shift_angle - integer :: naky, nakx, nx, ny, nalpha - integer :: jtwist, ikx_twist_shift - integer :: ikx_max, naky_all - integer :: boundary_size, copy_size, krook_size - logical :: reality = .false. - logical :: centered_in_rho, periodic_variation, randomize_phase_shift - character(20) :: grid_option - logical, dimension(:), allocatable :: zonal_mode - - namelist /kt_grids_knobs/ grid_option - - ! internal variables - integer :: gridopt_switch - integer, parameter :: gridopt_range = 1, gridopt_box = 2 - - integer :: kyspacing_option_switch - integer, parameter :: kyspacing_linear = 1, kyspacing_exponential = 2 - - real :: aky_min, aky_max - real :: akx_min, akx_max - real :: theta0_min, theta0_max - real :: x0, y0 - logical :: read_kt_grids_initialized = .false. - logical :: init_kt_grids_initialized = .false. - logical :: box - -contains - - subroutine read_kt_grids_parameters - - use mp, only: proc0 - - implicit none - - if (read_kt_grids_initialized) return - read_kt_grids_initialized = .true. - - if (proc0) then - call read_grid_option - select case (gridopt_switch) - case (gridopt_range) - call read_kt_grids_range - case (gridopt_box) - call read_kt_grids_box - end select - end if - - call broadcast_input - - call allocate_arrays - - end subroutine read_kt_grids_parameters - - subroutine read_grid_option - - use file_utils, only: input_unit, error_unit, input_unit_exist - use text_options, only: text_option, get_option_value - - implicit none - - type(text_option), dimension(5), parameter :: gridopts = & - (/text_option('default', gridopt_range), & - text_option('range', gridopt_range), & - text_option('box', gridopt_box), & - text_option('annulus', gridopt_box), & - text_option('nonlinear', gridopt_box)/) - - integer :: ierr, in_file - logical :: nml_exist - - grid_option = 'default' - - in_file = input_unit_exist("kt_grids_knobs", nml_exist) - if (nml_exist) read (unit=in_file, nml=kt_grids_knobs) - - ierr = error_unit() - call get_option_value(grid_option, gridopts, gridopt_switch, & - ierr, "grid_option in kt_grids_knobs") - - end subroutine read_grid_option - - subroutine read_kt_grids_box - - use file_utils, only: input_unit_exist - use physics_flags, only: full_flux_surface - - implicit none - - integer :: in_file - logical :: exist - - namelist /kt_grids_box_parameters/ nx, ny, jtwist, jtwistfac, x0, y0, & - centered_in_rho, periodic_variation, & - randomize_phase_shift, phase_shift_angle - - ! note that jtwist and y0 will possibly be modified - ! later in init_kt_grids_box if they make it out - ! of this subroutine with negative values - ! it is necessary to wait until later to do this check - ! because the values to which they may be set will - ! depend on information from the geometry module, - ! which itself may rely on ny from here (number of alphas) - nx = 1 - ny = 1 - jtwist = -1 - jtwistfac = 1. - phase_shift_angle = 0. - x0 = -1.0 - y0 = -1.0 - nalpha = 1 - centered_in_rho = .true. - randomize_phase_shift = .false. - periodic_variation = .false. - - in_file = input_unit_exist("kt_grids_box_parameters", exist) - if (exist) read (in_file, nml=kt_grids_box_parameters) - - ! get the number of de-aliased modes in y and x, using reality to halve the number of ky modes - naky = (ny - 1) / 3 + 1 - nakx = 2 * ((nx - 1) / 3) + 1 - - ! get the total number of ky values, including negative ky; - ! this is approximately 2/3 ny because ny includes padding to avoid aliasing - naky_all = 2 * naky - 1 - - reality = .true. - - if (full_flux_surface) nalpha = ny - - end subroutine read_kt_grids_box - - subroutine read_kt_grids_range - - use mp, only: mp_abort, proc0 - use file_utils, only: input_unit, error_unit, input_unit_exist - use physics_flags, only: full_flux_surface - use text_options, only: text_option, get_option_value - - implicit none - - type(text_option), dimension(3), parameter :: kyspacingopts = & - (/text_option('default', kyspacing_linear), & - text_option('linear', kyspacing_linear), & - text_option('exponential', kyspacing_exponential)/) - - character(20) :: kyspacing_option = 'default' - - integer :: ierr, in_file - logical :: exist - - namelist /kt_grids_range_parameters/ naky, nakx, & - aky_min, aky_max, theta0_min, theta0_max, akx_min, akx_max, kyspacing_option - - nalpha = 1 - naky = 1 - nakx = 1 - aky_min = 0.0 - aky_max = 0.0 - ! set these to be nonsense values - ! so can check later if they've been set - akx_min = 0.0 - akx_max = -1.0 - theta0_min = 0.0 - theta0_max = -1.0 - phase_shift_angle = 0. - - in_file = input_unit_exist("kt_grids_range_parameters", exist) - if (exist) read (in_file, nml=kt_grids_range_parameters) - - if (full_flux_surface) then - if (proc0) then - write (*, *) '!!! ERROR !!!' - write (*, *) 'kt_grids "range" option is not supported for full_flux_surface = T. aborting' - write (*, *) '!!! ERROR !!!' - end if - call mp_abort('kt_grids "range" option is not supported for full_flux_surface = T. aborting') - end if - - naky_all = naky - - ierr = error_unit() - call get_option_value(kyspacing_option, kyspacingopts, kyspacing_option_switch, & - ierr, "kyspacing_option in kt_grids_range_parameters", .true.) - - end subroutine read_kt_grids_range - - subroutine init_kt_grids - - use common_types, only: flux_surface_type - use zgrid, only: init_zgrid - - implicit none - - if (init_kt_grids_initialized) return - init_kt_grids_initialized = .true. - - call init_zgrid - - select case (gridopt_switch) - case (gridopt_range) - call init_kt_grids_range - case (gridopt_box) - call init_kt_grids_box - end select - - !> determine if iky corresponds to zonal mode - if (.not. allocated(zonal_mode)) allocate (zonal_mode(naky)) - zonal_mode = .false. - if (abs(aky(1)) < epsilon(0.)) zonal_mode(1) = .true. - - end subroutine init_kt_grids - - subroutine init_kt_grids_box - - use mp, only: mp_abort, proc0, broadcast - use common_types, only: flux_surface_type - use constants, only: pi, zi - use geometry, only: geo_surf, twist_and_shift_geo_fac, dydalpha - use geometry, only: q_as_x, get_x_to_rho, dxdpsi, drhodpsi - use geometry, only: geo_option_switch, geo_option_vmec - use physics_parameters, only: rhostar - use physics_flags, only: full_flux_surface, radial_variation - use file_utils, only: runtype_option_switch, runtype_multibox - use zgrid, only: nperiod - use zgrid, only: boundary_option_switch, boundary_option_linked - use zgrid, only: boundary_option_linked_stellarator - use ran, only: ranf - - implicit none - - integer :: ikx, iky - integer :: ikyneg - real :: x_shift, dqdrho, pfac, norm - - box = .true. - - !> set jtwist and y0 for cases where they have not been specified - !> and for which it makes sense to set them automatically - if (jtwist < 1) then - jtwist = max(1, int(abs(twist_and_shift_geo_fac) + 0.5)) - jtwist = max(1, int(jtwistfac * jtwist + 0.5)) - end if - !> signed version of jtwist, with sign determined by, e.g., magnetic shear - ikx_twist_shift = -jtwist * int(sign(1.0, twist_and_shift_geo_fac)) - - if (y0 < 0.) then - if (full_flux_surface) then - !> if simulating a flux annulus, then - !> y0 determined by the physical - !> extent of the device - if (rhostar > 0.) then - !y0 = 1./(rhostar*geo_surf%rhotor) - y0 = geo_surf%rhotor / rhostar - else - call mp_abort('must set rhostar if simulating a full flux surface. aborting.') - end if - else - !> if simulating a flux tube - !> makes no sense to have y0 < 0.0 - !> so abort - call mp_abort('y0 negative only makes sense when simulating a flux annulus. aborting.') - end if - end if - - !> get the grid spacing in ky and then in kx using twist-and-shift BC - dky = 1./y0 - - ! kx = ky * twist_shift_geo_fac / jtwist for every linked boundary condition - ! except for the periodic ones - select case (boundary_option_switch) - case (boundary_option_linked) - dkx = (2 * nperiod - 1) * dky * abs(twist_and_shift_geo_fac) / real(jtwist) - case (boundary_option_linked_stellarator) - dkx = dky * abs(twist_and_shift_geo_fac) / real(jtwist) - case default - if (x0 < epsilon(0.0)) then - dkx = dky - else - dkx = 1./x0 - end if - end select - - x0 = 1./dkx - - !> ky goes from zero to ky_max - do iky = 1, naky - aky(iky) = real(iky - 1) * dky - end do - - !> get the ikx index corresponding to kx_max - ikx_max = nakx / 2 + 1 - - !> aky_all contains all ky values (positive and negative), - !> stored in the same order as akx (0 -> ky_max, -ky_max -> -dky) - !> first set arrays equal for ky >= 0 - aky_all(:naky) = aky - !> aky_all_ordered contains all ky values, stored from - !> most negative to most positive (-ky_max -> ky_max) - aky_all_ordered(naky:naky_all) = aky - !> next fill in ky < 0 - do iky = naky + 1, naky_all - !> this is the ky index corresponding to +ky in original array - ikyneg = naky_all - iky + 2 - aky_all(iky) = -aky(ikyneg) - end do - aky_all_ordered(:naky - 1) = aky_all(naky + 1:) - - !> kx goes from zero to kx_max down to zero... - do ikx = 1, ikx_max - akx(ikx) = real(ikx - 1) * dkx - end do - !> and then from -kx_max to -|kx_min| - do ikx = ikx_max + 1, nakx - akx(ikx) = real(ikx - nakx - 1) * dkx - end do - - !> set theta0=0 for ky=0 - theta0(1, :) = 0.0 - if (q_as_x) then - do ikx = 1, nakx - !> theta0 = kx/ky - theta0(2:, ikx) = akx(ikx) / aky(2:) - end do - else - do ikx = 1, nakx - !> theta0 = kx/ky/shat - theta0(2:, ikx) = akx(ikx) / (aky(2:) * geo_surf%shat) - end do - end if - - norm = 1. - if (naky > 1) norm = aky(2) - if (rhostar > 0.) then - if (geo_option_switch == geo_option_vmec) then - phase_shift_angle = -2.*pi * (2 * nperiod - 1) * dydalpha / (rhostar * geo_surf%qinp_psi0) - else - phase_shift_angle = -2.*pi * (2 * nperiod - 1) * geo_surf%qinp_psi0 * dydalpha / rhostar - end if - else if (randomize_phase_shift) then - if (proc0) phase_shift_angle = 2.*pi * ranf() / norm - call broadcast(phase_shift_angle) - else - phase_shift_angle = 2.*pi * phase_shift_angle / norm - end if - - !> MAB: a lot of the radial variation coding below should probably be tidied away - !> into one or more separate subroutines - - !> for radial variation - if (.not. allocated(x_d)) allocate (x_d(nakx)) - if (.not. allocated(rho)) allocate (rho(nx)) - if (.not. allocated(rho_d)) allocate (rho_d(nakx)) - if (.not. allocated(rho_clamped)) allocate (rho_clamped(nx)) - if (.not. allocated(rho_d_clamped)) allocate (rho_d_clamped(nakx)) - - if (.not. allocated(x)) allocate (x(nx)) - if (.not. allocated(y)) allocate (y(ny)) - - dx = (2 * pi * x0) / nx - dy = (2 * pi * y0) / ny - - x_shift = pi * x0 - pfac = 1.0 - if (periodic_variation) pfac = 0.5 - if (centered_in_rho) then - if (q_as_x) then - dqdrho = geo_surf%shat * geo_surf%qinp / geo_surf%rhoc - x_shift = pi * x0 * (1.0 - 0.5 * pfac * rhostar * pi * x0 * geo_surf%d2qdr2 / (dqdrho**2 * dxdpsi)) - else - x_shift = pi * x0 * (1.0 - 0.5 * pfac * rhostar * pi * x0 * geo_surf%d2psidr2 * drhodpsi**2 / dxdpsi) - end if - end if - - do ikx = 1, nx - if (radial_variation .or. runtype_option_switch == runtype_multibox) then - if (periodic_variation) then - if (ikx <= nx / 2) then - x(ikx) = (ikx - 1) * dx - 0.5 * x_shift - else - x(ikx) = x(nx - ikx + 1) - end if - else - x(ikx) = (ikx - 0.5) * dx - x_shift - end if - else - x(ikx) = (ikx - 1) * dx - end if - end do - - dx_d = (2 * pi * x0) / nakx - do ikx = 1, nakx - if (radial_variation .or. runtype_option_switch == runtype_multibox) then - if (periodic_variation) then - if (ikx <= (nakx + 1) / 2) then - x_d(ikx) = (ikx - 1) * dx_d - 0.5 * x_shift - else - x_d(ikx) = x_d(nakx - ikx + 1) - end if - else - x_d(ikx) = (ikx - 0.5) * dx_d - x_shift - end if - else - x_d(ikx) = (ikx - 1) * dx_d - end if - end do - - call get_x_to_rho(1, x, rho) - call get_x_to_rho(1, x_d, rho_d) - - if (.not. allocated(rho_clamped)) allocate (rho_clamped(nx)); rho_clamped = rho - if (.not. allocated(rho_d_clamped)) allocate (rho_d_clamped(nakx)); rho_d_clamped = rho_d - - zed0 = theta0 * geo_surf%zed0_fac - - if (radial_variation) call dump_radial_grid - - if (radial_variation .and. (any((rho + geo_surf%rhoc) < 0.0) & - .or. any((rho + geo_surf%rhoc) > 1.0))) then - call mp_abort('rho(x) is beyond range [0,1]. Try changing rhostar or q/psi profiles') - end if - - do iky = 1, ny - y(iky) = (iky - 1) * dy - end do - - end subroutine init_kt_grids_box - - subroutine init_kt_grids_range - - use mp, only: mp_abort - use common_types, only: flux_surface_type - use geometry, only: geo_surf, q_as_x - use zgrid, only: shat_zero - - implicit none - - integer :: i, j - real :: dkx, dky, dtheta0, tfac - real :: zero - - box = .false. - - ! NB: we are assuming here that all ky are positive - ! when running in range mode - dky = 0.0 - if (naky > 1) then - select case (kyspacing_option_switch) - case (kyspacing_linear) - dky = (aky_max - aky_min) / real(naky - 1) - aky = (/(aky_min + dky * real(i), i=0, naky - 1)/) - case (kyspacing_exponential) - dky = (log(aky_max) - log(aky_min)) / real(naky - 1) - aky = (/(exp(log(aky_min) + dky * real(i)), i=0, naky - 1)/) - end select - else - aky = (/(aky_min, i=0, naky - 1)/) - end if - - ! set default akx and theta0 to 0 - akx = 0.0; theta0 = 0.0 - - if (q_as_x) then - tfac = 1.0 - else - tfac = geo_surf%shat - end if - - zero = 100.*epsilon(0.) - - ! if theta0_min and theta0_max have been specified, - ! use them to determine akx_min and akx_max - if (theta0_max > theta0_min - zero) then - if (geo_surf%shat > epsilon(0.)) then - akx_min = theta0_min * tfac * aky(1) - akx_max = theta0_max * tfac * aky(1) - else - akx_min = theta0_max * tfac * aky(1) - akx_max = theta0_min * tfac * aky(1) - end if - end if - - ! shat_zero is minimum shat value below which periodic BC is enforced - if (abs(geo_surf%shat) > shat_zero) then ! ie assumes boundary_option .eq. 'linked' - ! if akx_min and akx_max specified in input - ! instead of theta0_min and theta0_max, - ! use them to get theta0_min and theta0_max - if (theta0_min > theta0_max + zero .and. abs(aky(1)) > zero) then - theta0_min = akx_min / (tfac * aky(1)) - theta0_max = akx_max / (tfac * aky(1)) - dtheta0 = 0.0 - if (nakx > 1) dtheta0 = (theta0_max - theta0_min) / real(nakx - 1) - - do j = 1, naky - theta0(j, :) & - = (/(theta0_min + dtheta0 * real(i), i=0, nakx - 1)/) - end do - akx = theta0(1, :) * tfac * aky(1) - else if (akx_max > akx_min - zero .or. nakx == 1) then - dkx = 0.0 - if (nakx > 1) dkx = (akx_max - akx_min) / real(nakx - 1) - akx = (/(akx_min + dkx * real(i), i=0, nakx - 1)/) - - dtheta0 = 0.0 - if (nakx > 1) dtheta0 = (theta0_max - theta0_min) / real(nakx - 1) - - if (geo_surf%shat > epsilon(0.)) then - do j = 1, naky - theta0(j, :) & - = (/(theta0_min + dtheta0 * real(i), i=0, nakx - 1)/) - end do - else - do j = 1, naky - theta0(j, :) & - = (/(theta0_min + dtheta0 * real(i), i=nakx - 1, 0, -1)/) - end do - end if - else - call mp_abort('ky=0 is inconsistent with kx_min different from kx_max. aborting.') - end if - - else - ! here assume boundary_option .eq. 'periodic' - ! used for periodic finite kx ballooning space runs with shat=0 - dkx = 0.0 - if (nakx > 1) dkx = (akx_max - akx_min) / real(nakx - 1) - akx = (/(akx_min + dkx * real(i), i=0, nakx - 1)/) - end if - - zed0 = theta0 * geo_surf%zed0_fac - - ikx_max = nakx - naky_all = naky - - end subroutine init_kt_grids_range - - subroutine broadcast_input - - use mp, only: broadcast - - implicit none - - call broadcast(gridopt_switch) - call broadcast(centered_in_rho) - call broadcast(periodic_variation) - call broadcast(naky) - call broadcast(naky_all) - call broadcast(nakx) - call broadcast(ny) - call broadcast(nx) - call broadcast(nalpha) - call broadcast(reality) - call broadcast(jtwist) - call broadcast(jtwistfac) - call broadcast(x0) - call broadcast(y0) - call broadcast(aky_min) - call broadcast(aky_max) - call broadcast(akx_min) - call broadcast(akx_max) - call broadcast(theta0_min) - call broadcast(theta0_max) - call broadcast(randomize_phase_shift) - call broadcast(phase_shift_angle) - call broadcast(kyspacing_option_switch) - - end subroutine broadcast_input - - subroutine dump_radial_grid - - use file_utils, only: run_name - use physics_parameters, only: rhostar - use geometry, only: q_as_x, geo_surf, dxdpsi, drhodpsip - - implicit none - - integer :: ix - character(300) :: filename - - filename = trim(trim(run_name)//'.radial_grid') - open (1047, file=filename, status='unknown') - if (q_as_x) then - write (1047, '(1a12,1e12.4,1a12,1e12.4,1a12,1e12.4,1a12,1e12.4)') & - '#dxdpsi = ', dxdpsi, & - ' q = ', geo_surf%qinp, & - ' dqdr = ', geo_surf%shat * geo_surf%qinp / geo_surf%rhoc, & - ' d2qdr2 = ', geo_surf%d2qdr2 - write (1047, '(3a12)') '#1.x', '2.q', '3.rho' - do ix = 1, nx - write (1047, '(3e12.4,i9)') & - x(ix), & - rhostar * x(ix) / dxdpsi + geo_surf%qinp, & - rho(ix) + geo_surf%rhoc - end do - else - write (1047, '(1a12,1e12.4,1a12,1e12.4,1a12,1e12.4,1a12,1e12.4)') & - '#dxdpsi = ', dxdpsi, & - ' dpsidr = ', 1.0 / drhodpsip, & - ' d2psidr2 = ', geo_surf%d2psidr2 - write (1047, '(3a12,a9)') '#1.x', '2.psi-psi0', '3.rho' - do ix = 1, nx - write (1047, '(3e12.4,i9)') & - x(ix), & - rhostar * x(ix) / dxdpsi, & - rho(ix) + geo_surf%rhoc - end do - end if - - close (1047) - - end subroutine dump_radial_grid - - subroutine allocate_arrays - - implicit none - - allocate (akx(nakx)) - allocate (aky(naky)) - allocate (aky_all(naky_all)) - allocate (aky_all_ordered(naky_all)) - allocate (theta0(naky, nakx)) - allocate (zed0(naky, nakx)) - - end subroutine allocate_arrays - - ! take an array with ky >= 0 and all kx (ordered like 0, ..., kxmax, -kxmax, ..., -dkx) - ! and uses reality condition to return array - ! with kx >= 0 and all ky (ordered like 0, ..., kymax, -kymax, ..., -dky) - subroutine swap_kxky_complex(gin, gout) - - implicit none - - complex, dimension(:, :), intent(in) :: gin - complex, dimension(:, :), intent(out) :: gout - - integer :: ikx, ikxneg - integer :: iky, ikyneg - - ! first set arrays equal for ky >= 0 and kx >= 0 - gout(:naky, :) = gin(:, :ikx_max) - ! next fill in ky < 0, kx >= 0 elements of array using reality - ikx = 1 - ikxneg = ikx - do iky = naky + 1, naky_all - ! this is the ky index corresponding to +ky in original array - ikyneg = naky_all - iky + 2 - gout(iky, ikx) = conjg(gin(ikyneg, ikxneg)) - end do - do ikx = 2, ikx_max - ikxneg = nakx - ikx + 2 - do iky = naky + 1, naky_all - ! this is the ky index corresponding to +ky in original array - ikyneg = naky_all - iky + 2 - gout(iky, ikx) = conjg(gin(ikyneg, ikxneg)) - end do - end do - - end subroutine swap_kxky_complex - - ! take an array with ky >= 0 and all kx (ordered like 0, ..., kxmax, -kxmax, ..., -dkx) - ! and uses reality condition to return array - ! with kx >= 0 and all ky (ordered like 0, ..., kymax, -kymax, ..., -dky) - subroutine swap_kxky_real(gin, gout) - - implicit none - - real, dimension(:, :), intent(in) :: gin - real, dimension(:, :), intent(out) :: gout - - integer :: ikx, ikxneg - integer :: iky, ikyneg - - ! first set arrays equal for ky >= 0 and kx >= 0 - gout(:naky, :) = gin(:, :ikx_max) - ! next fill in ky < 0, kx >= 0 elements of array using reality - ikx = 1 - ikxneg = ikx - do iky = naky + 1, naky_all - ! this is the ky index corresponding to +ky in original array - ikyneg = naky_all - iky + 2 - gout(iky, ikx) = gin(ikyneg, ikxneg) - end do - do ikx = 2, ikx_max - ikxneg = nakx - ikx + 2 - do iky = naky + 1, naky_all - ! this is the ky index corresponding to +ky in original array - ikyneg = naky_all - iky + 2 - gout(iky, ikx) = gin(ikyneg, ikxneg) - end do - end do - - end subroutine swap_kxky_real - - ! take an array with ky >= 0 and all kx (ordered like 0, ..., kxmax, -kxmax, ..., -dkx) - ! and uses reality condition to return array - ! with kx >= 0 and all ky (ordered like -kymax, ..., 0, ..., kymax) - subroutine swap_kxky_ordered_real(gin, gout) - - implicit none - - real, dimension(:, :), intent(in) :: gin - real, dimension(:, :), intent(out) :: gout - - integer :: ikx, ikxneg - integer :: iky, ikyneg - - ! first set arrays equal for ky >= 0 and kx >= 0 - gout(naky:, :) = gin(:, :ikx_max) - ! next fill in ky < 0, kx >= 0 elements of array using reality - ikx = 1 - ikxneg = ikx - do iky = 1, naky - 1 - ! this is the ky index corresponding to +ky in original array - ikyneg = naky - iky + 1 - gout(iky, ikx) = gin(ikyneg, ikxneg) - end do - do ikx = 2, ikx_max - ikxneg = nakx - ikx + 2 - do iky = 1, naky - 1 - ! this is the ky index corresponding to +ky in original array - ikyneg = naky - iky + 1 - gout(iky, ikx) = gin(ikyneg, ikxneg) - end do - end do - - end subroutine swap_kxky_ordered_real - - ! take an array with ky >= 0 and all kx (ordered like 0, ..., kxmax, -kxmax, ..., -dkx) - ! and uses reality condition to return array - ! with kx >= 0 and all ky (ordered like -kymax, ..., 0, ..., kymax) - subroutine swap_kxky_ordered_complex(gin, gout) - - implicit none - - complex, dimension(:, :), intent(in) :: gin - complex, dimension(:, :), intent(out) :: gout - - integer :: ikx, ikxneg - integer :: iky, ikyneg - - ! first set arrays equal for ky >= 0 and kx >= 0 - gout(naky:, :) = gin(:, :ikx_max) - ! next fill in ky < 0, kx >= 0 elements of array using reality - ikx = 1 - ikxneg = ikx - do iky = 1, naky - 1 - ! this is the ky index corresponding to +ky in original array - ikyneg = naky - iky + 1 - gout(iky, ikx) = conjg(gin(ikyneg, ikxneg)) - end do - do ikx = 2, ikx_max - ikxneg = nakx - ikx + 2 - do iky = 1, naky - 1 - ! this is the ky index corresponding to +ky in original array - ikyneg = naky - iky + 1 - gout(iky, ikx) = conjg(gin(ikyneg, ikxneg)) - end do - end do - - end subroutine swap_kxky_ordered_complex - - ! take an array with kx >= 0 and all ky (ordered like 0, ..., kymax, -kymax, ..., -dky) - ! and uses reality condition to return array - ! with ky >= 0 and all kx (ordered like 0, ..., kxmax, -kxmax, ..., -dkx) - subroutine swap_kxky_back(gin, gout) - - implicit none - - complex, dimension(:, :), intent(in) :: gin - complex, dimension(:, :), intent(out) :: gout - - integer :: ikx, ikxneg - integer :: iky, ikyneg - - ! first set arrays equal for ky >= 0 and kx >= 0 - gout(:, :ikx_max) = gin(:naky, :) - ! next fill in kx < 0, ky >= 0 elements of array using reality - do ikx = ikx_max + 1, nakx - ikxneg = nakx - ikx + 2 - iky = 1 - ikyneg = iky - gout(iky, ikx) = conjg(gin(ikyneg, ikxneg)) - do iky = 2, naky - ikyneg = naky_all - iky + 2 - gout(iky, ikx) = conjg(gin(ikyneg, ikxneg)) - end do - end do - - end subroutine swap_kxky_back - - ! take an array with kx >= 0 and all ky (ordered like -kymax, ..., 0, ..., kymax) - ! and uses reality condition to return array - ! with ky >= 0 and all kx (ordered like 0, ..., kxmax, -kxmax, ..., -dkx) - subroutine swap_kxky_back_ordered(gin, gout) - - implicit none - - complex, dimension(:, :), intent(in) :: gin - complex, dimension(:, :), intent(out) :: gout - - integer :: ikx, ikxneg - integer :: iky, ikyneg - - ! first set arrays equal for ky >= 0 and kx >= 0 - gout(:, :ikx_max) = gin(naky:, :) - ! next fill in kx < 0, ky >= 0 elements of array using reality - do ikx = ikx_max + 1, nakx - ikxneg = nakx - ikx + 2 - do iky = 1, naky - ikyneg = naky - iky + 1 - gout(iky, ikx) = conjg(gin(ikyneg, ikxneg)) - end do - end do - - end subroutine swap_kxky_back_ordered - - subroutine communicate_ktgrids_multibox - use job_manage, only: njobs - use mp, only: job, scope, & - crossdomprocs, subprocs, & - send, receive - - implicit none - - call scope(crossdomprocs) - - if (job == 1) then - call send(phase_shift_angle, 0, 120) - call send(phase_shift_angle, njobs - 1, 130) - elseif (job == 0) then - call receive(phase_shift_angle, 1, 120) - elseif (job == njobs - 1) then - call receive(phase_shift_angle, 1, 130) - end if - - call scope(subprocs) - - end subroutine communicate_ktgrids_multibox - - subroutine finish_kt_grids - - implicit none - - if (allocated(aky)) deallocate (aky) - if (allocated(aky_all)) deallocate (aky_all) - if (allocated(aky_all_ordered)) deallocate (aky_all_ordered) - if (allocated(akx)) deallocate (akx) - if (allocated(theta0)) deallocate (theta0) - if (allocated(zed0)) deallocate (zed0) - - if (allocated(x)) deallocate (x) - if (allocated(y)) deallocate (y) - - if (allocated(x_d)) deallocate (x_d) - if (allocated(rho)) deallocate (rho) - if (allocated(rho_d)) deallocate (rho_d) - if (allocated(rho_clamped)) deallocate (rho_clamped) - if (allocated(rho_d_clamped)) deallocate (rho_d_clamped) - - if (allocated(g0x)) deallocate (g0x) - - reality = .false. - read_kt_grids_initialized = .false. - init_kt_grids_initialized = .false. - - end subroutine finish_kt_grids - - subroutine multiply_by_rho(gin) - - use stella_transforms, only: transform_kx2x_unpadded, transform_x2kx_unpadded -! use stella_transforms, only: transform_kx2x_xfirst, transform_x2kx_xfirst - - implicit none - - complex, dimension(:, :), intent(inout) :: gin - - if (.not. allocated(g0x)) allocate (g0x(naky, nakx)) - - call transform_kx2x_unpadded(gin, g0x) - g0x = spread(rho_d_clamped, 1, naky) * g0x - if (zonal_mode(1)) g0x(1, :) = real(g0x(1, :)) - call transform_x2kx_unpadded(g0x, gin) - -! if(.not.allocated(g0x)) allocate(g0x(naky,nx)) - -! call transform_kx2x_xfirst(gin,g0x) -! g0x = spread(rho_clamped,1,naky)*g0x -! if(zonal_mode(1)) g0x(1,:) = real(g0x(1,:)) -! call transform_x2kx_xfirst(g0x,gin) - - end subroutine multiply_by_rho - -end module kt_grids - diff --git a/mirror_terms.f90 b/mirror_terms.f90 index 0b58ffac26..1f941d6ad7 100644 --- a/mirror_terms.f90 +++ b/mirror_terms.f90 @@ -1,5 +1,6 @@ module mirror_terms + use debug_flags, only: debug => mirror_terms_debug implicit none public :: mirror_initialized @@ -30,21 +31,22 @@ module mirror_terms contains - subroutine init_mirror - + subroutine init_mirror + + use mp, only: proc0 use stella_time, only: code_dt use species, only: spec, nspec use vpamu_grids, only: nmu use vpamu_grids, only: mu use zgrid, only: nzgrid, nztot - use kt_grids, only: nalpha + use parameters_kxky_grids, only: nalpha use geometry, only: dbdzed, b_dot_grad_z, gfac use geometry, only: d2Bdrdth, dgradpardrho use neoclassical_terms, only: include_neoclassical_terms use neoclassical_terms, only: dphineo_dzed - use run_parameters, only: mirror_implicit, mirror_semi_lagrange - use physics_flags, only: include_apar - use physics_flags, only: include_mirror, radial_variation + use parameters_numerical, only: mirror_implicit, mirror_semi_lagrange + use parameters_physics, only: include_apar + use parameters_physics, only: include_mirror, radial_variation implicit none @@ -54,6 +56,9 @@ subroutine init_mirror if (mirror_initialized) return mirror_initialized = .true. + debug = debug .and. proc0 + if (debug) write(*,*) 'no debug messages for mirror_terms.f90 yet' + if (.not. allocated(mirror)) allocate (mirror(nalpha, -nzgrid:nzgrid, nmu, nspec)); mirror = 0. if (.not. allocated(mirror_sign)) allocate (mirror_sign(nalpha, -nzgrid:nzgrid)); mirror_sign = 0 @@ -127,7 +132,7 @@ subroutine init_mirror_semi_lagrange use zgrid, only: nzgrid use vpamu_grids, only: nmu, dvpa use species, only: nspec - use kt_grids, only: nalpha + use parameters_kxky_grids, only: nalpha implicit none @@ -153,14 +158,14 @@ subroutine init_invert_mirror_operator use zgrid, only: nzgrid use vpamu_grids, only: dvpa, vpa, mu use vpamu_grids, only: nvpa, nmu - use physics_flags, only: full_flux_surface + use parameters_physics, only: full_flux_surface use species, only: spec - use kt_grids, only: nalpha + use parameters_kxky_grids, only: nalpha use geometry, only: dbdzed use neoclassical_terms, only: include_neoclassical_terms use neoclassical_terms, only: dphineo_dzed - use run_parameters, only: vpa_upwind, time_upwind - use run_parameters, only: maxwellian_normalization + use parameters_numerical, only: vpa_upwind, time_upwind + use parameters_numerical, only: maxwellian_normalization implicit none @@ -289,7 +294,7 @@ subroutine init_mirror_response use stella_layouts, only: kxkyz_lo use zgrid, only: nzgrid, ntubes use vpamu_grids, only: nmu, nvpa - use kt_grids, only: naky, nakx + use parameters_kxky_grids, only: naky, nakx use fields, only: advance_apar implicit none @@ -338,18 +343,18 @@ subroutine advance_mirror_explicit(g, gout) use mp, only: proc0 use redistribute, only: gather, scatter - use dist_fn_arrays, only: gvmu + use arrays_dist_fn, only: gvmu use job_manage, only: time_message use stella_layouts, only: kxyz_lo, kxkyz_lo, vmu_lo use stella_layouts, only: iv_idx, is_idx use stella_transforms, only: transform_ky2y use zgrid, only: nzgrid, ntubes - use physics_flags, only: full_flux_surface - use kt_grids, only: nakx, naky, naky_all, ny, ikx_max - use kt_grids, only: swap_kxky + use parameters_physics, only: full_flux_surface + use parameters_kxky_grids, only: nakx, naky, naky_all, ny, ikx_max + use calculations_kxky, only: swap_kxky use vpamu_grids, only: nvpa, nmu use vpamu_grids, only: vpa, maxwell_vpa - use run_parameters, only: fields_kxkyz, maxwellian_normalization + use parameters_numerical, only: fields_kxkyz, maxwellian_normalization use dist_redistribute, only: kxkyz2vmu, kxyz2vmu implicit none @@ -362,7 +367,7 @@ subroutine advance_mirror_explicit(g, gout) complex, dimension(:, :), allocatable :: dgdv, g_swap integer :: ikxyz, iz, it - integer :: ivmu, iv, imu, is + integer :: ivmu, iv, is !> start the timer for this subroutine if (proc0) call time_message(.false., time_mirror(:, 1), ' Mirror advance') @@ -450,14 +455,14 @@ subroutine add_mirror_radial_variation(g, gout) use mp, only: proc0 use redistribute, only: gather, scatter - use dist_fn_arrays, only: gvmu + use arrays_dist_fn, only: gvmu use job_manage, only: time_message use stella_layouts, only: kxkyz_lo, vmu_lo use stella_layouts, only: is_idx, imu_idx use zgrid, only: nzgrid, ntubes - use physics_flags, only: full_flux_surface + use parameters_physics, only: full_flux_surface use vpamu_grids, only: nvpa, nmu - use run_parameters, only: fields_kxkyz + use parameters_numerical, only: fields_kxkyz use dist_redistribute, only: kxkyz2vmu implicit none @@ -570,7 +575,7 @@ subroutine add_mirror_term(g, src) use stella_layouts, only: vmu_lo use stella_layouts, only: imu_idx, is_idx use zgrid, only: nzgrid, ntubes - use kt_grids, only: nakx + use parameters_kxky_grids, only: nakx implicit none @@ -599,7 +604,7 @@ subroutine add_mirror_term_ffs(g, src) use stella_layouts, only: vmu_lo use stella_layouts, only: imu_idx, is_idx use zgrid, only: nzgrid, ntubes - use kt_grids, only: ikx_max + use parameters_kxky_grids, only: ikx_max implicit none @@ -636,24 +641,25 @@ subroutine advance_mirror_implicit(collisions_implicit, g, apar) use stella_layouts, only: iv_idx, imu_idx use stella_transforms, only: transform_ky2y, transform_y2ky use zgrid, only: nzgrid, ntubes - use dist_fn_arrays, only: gvmu - use physics_flags, only: full_flux_surface - use kt_grids, only: ny, nakx + use arrays_dist_fn, only: gvmu + use parameters_physics, only: full_flux_surface + use parameters_kxky_grids, only: ny, nakx use vpamu_grids, only: nvpa, nmu use vpamu_grids, only: maxwell_vpa use neoclassical_terms, only: include_neoclassical_terms - use run_parameters, only: vpa_upwind, time_upwind - use run_parameters, only: mirror_semi_lagrange, maxwellian_normalization - use physics_flags, only: include_apar + use parameters_numerical, only: vpa_upwind, time_upwind + use parameters_numerical, only: mirror_semi_lagrange, maxwellian_normalization + use parameters_physics, only: include_apar use dist_redistribute, only: kxkyz2vmu, kxyz2vmu use fields, only: advance_apar, fields_updated use g_tofrom_h, only: gbar_to_g - use run_parameters, only: time_upwind - use vpamu_grids, only: vpa, dvpa + use parameters_numerical, only: time_upwind + use vpamu_grids, only: dvpa use stella_layouts, only: iy_idx - use kt_grids, only: swap_kxky, swap_kxky_back - use kt_grids, only: naky_all, ikx_max, naky + use calculations_kxky, only: swap_kxky, swap_kxky_back + use parameters_kxky_grids, only: naky_all, ikx_max + implicit none logical, intent(in) :: collisions_implicit @@ -662,7 +668,7 @@ subroutine advance_mirror_implicit(collisions_implicit, g, apar) integer :: ikxyz, ikxkyz, ivmu integer :: iky, ikx, iz, it, is - integer :: iv, imu + integer :: imu character(5) :: dist real :: tupwnd complex, dimension(:), allocatable :: rhs @@ -671,7 +677,7 @@ subroutine advance_mirror_implicit(collisions_implicit, g, apar) !! GA - arrays for FFS complex, dimension(:, :, :), allocatable :: dgdvpa - integer :: iy, ia + integer :: iy complex, dimension(:, :), allocatable :: g_swap if (proc0) call time_message(.false., time_mirror(:, 1), ' Mirror advance') @@ -878,14 +884,13 @@ end subroutine advance_mirror_implicit subroutine get_mirror_rhs_g_contribution(g_in, apar, imu, ikxkyz, rhs) - use physics_flags, only: include_apar - use run_parameters, only: vpa_upwind, time_upwind_minus - use run_parameters, only: maxwellian_normalization + use parameters_physics, only: include_apar + use parameters_numerical, only: vpa_upwind, time_upwind_minus + use parameters_numerical, only: maxwellian_normalization use g_tofrom_h, only: gbar_to_g use stella_layouts, only: kxkyz_lo, iz_idx, is_idx use finite_differences, only: fd_variable_upwinding_vpa use vpamu_grids, only: dvpa, vpa, nvpa - use fields_arrays, only: phi implicit none @@ -936,7 +941,7 @@ subroutine get_mirror_rhs_apar_contribution(rhs, apar, imu, ikxkyz) use species, only: spec use vpamu_grids, only: nvpa use vpamu_grids, only: maxwell_vpa, maxwell_mu, vpa - use run_parameters, only: maxwellian_normalization + use parameters_numerical, only: maxwellian_normalization use stella_layouts, only: kxkyz_lo, is_idx, iz_idx use gyro_averages, only: gyro_average @@ -973,7 +978,7 @@ subroutine vpa_interpolation(grid, interp) use vpamu_grids, only: nvpa, nmu use stella_layouts, only: kxkyz_lo use stella_layouts, only: iz_idx, is_idx - use run_parameters, only: mirror_linear_interp + use parameters_numerical, only: mirror_linear_interp implicit none @@ -1120,7 +1125,7 @@ end subroutine invert_mirror_operator subroutine finish_mirror - use run_parameters, only: mirror_implicit, mirror_semi_lagrange + use parameters_numerical, only: mirror_implicit, mirror_semi_lagrange implicit none diff --git a/multibox.f90 b/multibox.f90 index 8c72028d20..d776c09e44 100644 --- a/multibox.f90 +++ b/multibox.f90 @@ -90,7 +90,8 @@ subroutine read_multibox_parameters use file_utils, only: runtype_option_switch, runtype_multibox use text_options, only: text_option, get_option_value use mp, only: broadcast, proc0 - use kt_grids, only: nx, nakx, boundary_size, copy_size, krook_size + use parameters_kxky_grids, only: nx, nakx + use grids_kxky, only: boundary_size, copy_size, krook_size use job_manage, only: njobs use mp, only: scope, crossdomprocs, subprocs, & send, receive, job @@ -225,13 +226,16 @@ subroutine init_multibox use geometry, only: geo_surf, q_as_x, get_x_to_rho use geometry, only: drhodpsi, dxdpsi use zgrid, only: nzgrid, ntubes - use kt_grids, only: nakx, naky, akx, aky, nx, x, x_d, x0 - use kt_grids, only: centered_in_rho, rho_clamped, rho_d, rho_d_clamped - use kt_grids, only: periodic_variation - use kt_grids, only: boundary_size, krook_size + use parameters_kxky_grids, only: nakx, naky, nx, x0 + use grids_kxky, only: akx, aky + use grids_kxky, only: x, x_d + use grids_kxky, only: rho_clamped, rho_d, rho_d_clamped + use parameters_kxky_grids, only: centered_in_rho + use parameters_kxky_grids, only: periodic_variation + use grids_kxky, only: boundary_size, krook_size use file_utils, only: runtype_option_switch, runtype_multibox use job_manage, only: njobs - use physics_parameters, only: rhostar + use parameters_physics, only: rhostar use mp, only: scope, crossdomprocs, subprocs, & send, receive, job @@ -479,14 +483,15 @@ end subroutine finish_multibox subroutine multibox_communicate(gin) use constants, only: zi - use kt_grids, only: nakx, naky, naky_all, akx, aky, nx, ny, dx, dy, zonal_mode - use kt_grids, only: periodic_variation, boundary_size + use parameters_kxky_grids, only: nakx, naky, naky_all, nx, ny + use grids_kxky, only: akx, aky, dx, dy, zonal_mode, boundary_size + use parameters_kxky_grids, only: periodic_variation use file_utils, only: runtype_option_switch, runtype_multibox use file_utils, only: get_unused_unit - use fields_arrays, only: phi, phi_corr_QN, shift_state + use arrays_fields, only: phi, phi_corr_QN, shift_state use job_manage, only: njobs, time_message - use physics_flags, only: radial_variation, prp_shear_enabled, hammett_flow_shear - use physics_parameters, only: g_exb, g_exbfac + use parameters_physics, only: radial_variation, prp_shear_enabled, hammett_flow_shear + use parameters_physics, only: g_exb, g_exbfac use stella_layouts, only: vmu_lo use geometry, only: dl_over_b use zgrid, only: nzgrid @@ -662,9 +667,9 @@ subroutine multibox_communicate(gin) end subroutine multibox_communicate subroutine apply_radial_boundary_conditions(gin) - - use kt_grids, only: naky, zonal_mode - use kt_grids, only: periodic_variation, boundary_size + + use grids_kxky, only: zonal_mode, boundary_size + use parameters_kxky_grids, only: periodic_variation, naky use stella_layouts, only: vmu_lo use zgrid, only: nzgrid @@ -729,7 +734,8 @@ subroutine add_multibox_krook(g, rhs) use stella_time, only: code_dt use stella_layouts, only: vmu_lo - use kt_grids, only: nakx, naky, periodic_variation, boundary_size + use parameters_kxky_grids, only: nakx, naky, periodic_variation + use grids_kxky, only: boundary_size use zgrid, only: nzgrid, ntubes use mp, only: job, proc0 use job_manage, only: time_message @@ -796,12 +802,13 @@ end subroutine add_multibox_krook !! It is done here because the radial grid may include an extra point subroutine init_mb_get_phi(has_elec, adiabatic_elec, efac, efacp) - use kt_grids, only: nakx, naky, boundary_size + use parameters_kxky_grids, only: nakx, naky + use grids_kxky, only: boundary_size use zgrid, only: nzgrid - use physics_flags, only: radial_variation + use parameters_physics, only: radial_variation use geometry, only: dl_over_b, d_dl_over_b_drho - use run_parameters, only: ky_solve_radial - use fields_arrays, only: phi_solve, phizf_solve, gamtot, dgamtotdr + use parameters_numerical, only: ky_solve_radial + use arrays_fields, only: phi_solve, phizf_solve, gamtot, dgamtotdr use linear_solve, only: lu_decomposition, lu_inverse implicit none @@ -911,11 +918,12 @@ end subroutine init_mb_get_phi subroutine mb_get_phi(phi, has_elec, adiabatic_elec) use constants, only: zi - use kt_grids, only: akx, nakx, naky, zonal_mode, boundary_size + use parameters_kxky_grids, only: nakx, naky + use grids_kxky, only: zonal_mode, boundary_size, akx use zgrid, only: nzgrid, ntubes use geometry, only: dl_over_b, d_dl_over_b_drho - use run_parameters, only: ky_solve_radial - use fields_arrays, only: gamtot, dgamtotdr, phi_solve, phizf_solve + use parameters_numerical, only: ky_solve_radial + use arrays_fields, only: gamtot, dgamtotdr, phi_solve, phizf_solve use linear_solve, only: lu_back_substitution implicit none @@ -1081,7 +1089,7 @@ end subroutine mb_get_phi subroutine init_mb_transforms use stella_layouts, only: init_stella_layouts - use kt_grids, only: nakx, naky, naky_all + use parameters_kxky_grids, only: nakx, naky, naky_all implicit none @@ -1113,7 +1121,7 @@ end subroutine init_x_fft subroutine init_y_fft - use kt_grids, only: naky, naky_all + use parameters_kxky_grids, only: naky, naky_all use fft_work, only: init_crfftw, init_rcfftw, FFT_BACKWARD, FFT_FORWARD implicit none @@ -1132,7 +1140,7 @@ end subroutine init_y_fft subroutine transform_kx2x(gkx, gx) - use kt_grids, only: ikx_max + use parameters_kxky_grids, only: ikx_max implicit none @@ -1153,7 +1161,7 @@ end subroutine transform_kx2x subroutine transform_x2kx(gx, gkx) - use kt_grids, only: ikx_max + use parameters_kxky_grids, only: ikx_max implicit none diff --git a/neoclassical_terms.f90 b/neoclassical_terms.f90 index 90bf97d58f..e78cc77abe 100644 --- a/neoclassical_terms.f90 +++ b/neoclassical_terms.f90 @@ -1,5 +1,6 @@ module neoclassical_terms + use debug_flags, only: debug => neoclassical_terms_debug implicit none public :: init_neoclassical_terms @@ -21,14 +22,14 @@ module neoclassical_terms real, dimension(:, :), allocatable :: dphineo_dzed, dphineo_drho, dphineo_dalpha logical :: neoinit = .false. - logical :: debug = .false. contains subroutine init_neoclassical_terms + use mp, only: proc0 use zgrid, only: nzgrid - use kt_grids, only: nalpha + use parameters_kxky_grids, only: nalpha use vpamu_grids, only: nvpa, nmu use species, only: nspec use stella_layouts, only: vmu_lo @@ -45,6 +46,8 @@ subroutine init_neoclassical_terms if (neoinit) return neoinit = .true. + debug = debug .and. proc0 + call read_parameters if (include_neoclassical_terms) then allocate (f_neoclassical(nalpha, -nzgrid:nzgrid, nvpa, nmu, nspec, -nradii / 2:nradii / 2)) @@ -171,7 +174,7 @@ subroutine get_dfneo_dvpa(fneo, dfneo) use vpamu_grids, only: nvpa, nmu use vpamu_grids, only: dvpa use species, only: nspec - use kt_grids, only: nalpha + use parameters_kxky_grids, only: nalpha implicit none @@ -216,7 +219,7 @@ subroutine get_dfneo_dzed(fneo, dfneo) use vpamu_grids, only: nvpa, nmu use species, only: nspec use stella_layouts, only: vmu_lo - use kt_grids, only: nalpha + use parameters_kxky_grids, only: nalpha implicit none @@ -261,7 +264,7 @@ subroutine get_dfneo_drho(fneo, dfneo) use vpamu_grids, only: nvpa, nmu use species, only: nspec use stella_layouts, only: vmu_lo - use kt_grids, only: nalpha + use parameters_kxky_grids, only: nalpha implicit none @@ -309,7 +312,7 @@ subroutine get_dphineo_dzed(phineo, dphineo) use finite_differences, only: fd5pt use zgrid, only: nztot, nzgrid, delzed - use kt_grids, only: nalpha + use parameters_kxky_grids, only: nalpha implicit none @@ -336,7 +339,7 @@ subroutine get_dphineo_drho(phineo, dphineo) use finite_differences, only: fd3pt, fd5pt use zgrid, only: nzgrid - use kt_grids, only: nalpha + use parameters_kxky_grids, only: nalpha implicit none @@ -375,7 +378,7 @@ subroutine write_neoclassical(fnc, phinc) use stella_layouts, only: vmu_lo use stella_layouts, only: iv_idx, imu_idx, is_idx use stella_layouts, only: idx_local, proc_id - use kt_grids, only: nalpha + use parameters_kxky_grids, only: nalpha implicit none diff --git a/parallel_streaming.f90 b/parallel_streaming.f90 index ffebcbbee6..0368c762f5 100644 --- a/parallel_streaming.f90 +++ b/parallel_streaming.f90 @@ -1,5 +1,6 @@ module parallel_streaming + use debug_flags, only: debug => parallel_streaming_debug implicit none public :: init_parallel_streaming, finish_parallel_streaming @@ -43,12 +44,12 @@ module parallel_streaming integer, dimension(:,:), allocatable :: stream_correction_sign, stream_full_sign real, dimension(:, :, :, :), allocatable :: stream_correction, stream_store_full - logical :: debug = .false. - contains - subroutine init_parallel_streaming - + subroutine init_parallel_streaming + + use mp, only: proc0 + use finite_differences, only: fd3pt use stella_time, only: code_dt use stella_layouts, only: vmu_lo @@ -57,14 +58,13 @@ subroutine init_parallel_streaming use vpamu_grids, only: nvpa, nvpa use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac use vpamu_grids, only: vperp2, vpa, mu - use kt_grids, only: nalpha + use parameters_kxky_grids, only: nalpha use zgrid, only: nzgrid, nztot use geometry, only: gradpar, dgradpardrho, dBdrho, gfac, b_dot_grad_z - use run_parameters, only: stream_implicit, driftkinetic_implicit - use physics_flags, only: include_parallel_streaming, radial_variation - use physics_flags, only: full_flux_surface - use run_parameters, only: tupwnd_m => time_upwind_minus - use mp, only: proc0 + use parameters_numerical, only: stream_implicit, driftkinetic_implicit + use parameters_physics, only: include_parallel_streaming, radial_variation + use parameters_physics, only: full_flux_surface + implicit none integer :: iv, imu, is, ivmu @@ -73,6 +73,9 @@ subroutine init_parallel_streaming real, dimension(:), allocatable :: energy real, dimension(:, :, :), allocatable :: stream_store + debug = debug .and. proc0 + if(debug) write (*,*) 'No debug messages for parallel_streaming.f90 yet' + if (parallel_streaming_initialized) return parallel_streaming_initialized = .true. @@ -188,7 +191,7 @@ subroutine init_invert_stream_operator use zgrid, only: delzed use extended_zgrid, only: iz_low, iz_up use extended_zgrid, only: nsegments, neigen_max - use run_parameters, only: zed_upwind_plus, zed_upwind_minus, time_upwind_plus + use parameters_numerical, only: zed_upwind_plus, zed_upwind_minus, time_upwind_plus implicit none @@ -241,22 +244,18 @@ subroutine advance_parallel_streaming_explicit(g, phi, bpar, gout) use job_manage, only: time_message use stella_transforms, only: transform_ky2y use zgrid, only: nzgrid, ntubes - use kt_grids, only: naky, naky_all, nakx, ikx_max, ny - use kt_grids, only: swap_kxky - use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac, maxwell_mu_avg + use parameters_kxky_grids, only: naky, naky_all, nakx, ikx_max, ny + use calculations_kxky, only: swap_kxky + use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac use vpamu_grids, only: mu use species, only: spec - use physics_flags, only: full_flux_surface, include_bpar + use parameters_physics, only: full_flux_surface, include_bpar use gyro_averages, only: gyro_average, gyro_average_j1 - use run_parameters, only: driftkinetic_implicit, maxwellian_normalization + use parameters_numerical, only: driftkinetic_implicit, maxwellian_normalization !! For FFS - use fields, only: advance_fields, fields_updated - use fields_arrays, only: apar - use gyro_averages, only: j0_ffs, j0_const - use kt_grids, only: aky, akx - use zgrid, only: nztot - use dist_fn_arrays, only: kperp2 + use gyro_averages, only: j0_ffs + implicit none complex, dimension(:, :, -nzgrid:, :, vmu_lo%llim_proc:), intent(in) :: g @@ -268,9 +267,6 @@ subroutine advance_parallel_streaming_explicit(g, phi, bpar, gout) complex, dimension(:, :, :, :), allocatable :: g0y, g1y complex, dimension(:, :), allocatable :: g0_swap - logical :: implicit_solve = .true. - - integer :: iky, ikx !> if flux tube simulation parallel streaming stays in ky,kx,z space with ky,kx,z local !> if full flux surface (flux annulus), will need to calculate in y space @@ -372,11 +368,11 @@ subroutine add_parallel_streaming_radial_variation(g, gout, rhs) use stella_layouts, only: iv_idx, imu_idx, is_idx use job_manage, only: time_message use zgrid, only: nzgrid, ntubes - use kt_grids, only: naky, nakx + use parameters_kxky_grids, only: naky, nakx use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac use species, only: spec use gyro_averages, only: gyro_average, gyro_average_j1 - use fields_arrays, only: phi, phi_corr_QN, phi_corr_GA + use arrays_fields, only: phi, phi_corr_QN, phi_corr_GA implicit none @@ -459,7 +455,7 @@ subroutine get_dgdz(g, ivmu, dgdz) use extended_zgrid, only: ikxmod use extended_zgrid, only: fill_zed_ghost_zones use extended_zgrid, only: periodic - use kt_grids, only: naky + use parameters_kxky_grids, only: naky implicit none @@ -501,7 +497,7 @@ subroutine get_dgdz_centered(g, ivmu, dgdz) use extended_zgrid, only: ikxmod use extended_zgrid, only: fill_zed_ghost_zones use extended_zgrid, only: periodic - use kt_grids, only: naky + use parameters_kxky_grids, only: naky implicit none @@ -594,37 +590,12 @@ subroutine add_stream_term(g, ivmu, src) end subroutine add_stream_term - subroutine add_stream_term_ffs(g, ivmu, src) - - use stella_layouts, only: vmu_lo - use stella_layouts, only: iv_idx, is_idx - use zgrid, only: nzgrid - use kt_grids, only: ny - - implicit none - - complex, dimension(:, :, -nzgrid:, :), intent(in) :: g - complex, dimension(:, :, -nzgrid:, :), intent(in out) :: src - integer, intent(in) :: ivmu - - integer :: iz, iy, iv, is - - iv = iv_idx(vmu_lo, ivmu) - is = is_idx(vmu_lo, ivmu) - do iz = -nzgrid, nzgrid - do iy = 1, ny - src(iy, :, iz, :) = src(iy, :, iz, :) + stream(iy, iz, iv, is) * g(iy, :, iz, :) - end do - end do - - end subroutine add_stream_term_ffs - subroutine add_stream_term_full_ffs(g, ivmu, src) use stella_layouts, only: vmu_lo use stella_layouts, only: iv_idx, is_idx use zgrid, only: nzgrid - use kt_grids, only: ny + use parameters_kxky_grids, only: ny implicit none @@ -644,30 +615,6 @@ subroutine add_stream_term_full_ffs(g, ivmu, src) end subroutine add_stream_term_full_ffs - subroutine add_stream_term_ffs_correction(g, ivmu, src) - - use stella_layouts, only: vmu_lo - use stella_layouts, only: iv_idx, is_idx - use zgrid, only: nzgrid - use kt_grids, only: ny - - implicit none - complex, dimension(:, :, -nzgrid:, :), intent(in) :: g - complex, dimension(:, :, -nzgrid:, :), intent(in out) :: src - integer, intent(in) :: ivmu - integer :: iz, iy, iv, is - - iv = iv_idx(vmu_lo, ivmu) - is = is_idx(vmu_lo, ivmu) - do iz = -nzgrid, nzgrid - do iy = 1, ny - src(iy, :, iz, :) = src(iy, :, iz, :) + stream_correction(iy, iz, iv, is) * g(iy, :, iz, :) - end do - end do - - end subroutine add_stream_term_ffs_correction - - subroutine stream_tridiagonal_solve(iky, ie, iv, is, g) use finite_differences, only: tridag @@ -731,7 +678,7 @@ end subroutine stream_tridiagonal_solve subroutine get_dzed(iv, g, dgdz) use finite_differences, only: fd_cell_centres_zed - use kt_grids, only: naky + use parameters_kxky_grids, only: naky use zgrid, only: nzgrid, delzed, ntubes use extended_zgrid, only: neigen, nsegments use extended_zgrid, only: iz_low, iz_up @@ -785,13 +732,13 @@ end subroutine get_zed_derivative_extended_domain subroutine center_zed_extended(iv, g) use finite_differences, only: cell_centres_zed - use kt_grids, only: naky, nakx + use parameters_kxky_grids, only: naky, nakx use zgrid, only: nzgrid, ntubes use extended_zgrid, only: neigen, nsegments use extended_zgrid, only: iz_low, iz_up use extended_zgrid, only: ikxmod use extended_zgrid, only: fill_zed_ghost_zones - use run_parameters, only: zed_upwind + use parameters_numerical, only: zed_upwind implicit none @@ -831,7 +778,7 @@ end subroutine center_zed_extended ! it is assumed that any function passed to this subroutine is periodic subroutine center_zed_segment_real(iv, f, llim) - use run_parameters, only: zed_upwind_plus, zed_upwind_minus + use parameters_numerical, only: zed_upwind_plus, zed_upwind_minus integer, intent(in) :: iv, llim real, dimension(llim:), intent(in out) :: f @@ -855,8 +802,8 @@ end subroutine center_zed_segment_real !> and overwrites f with the cell-centered version; subroutine center_zed_segment_complex(iv, f, llim, periodic) - use run_parameters, only: zupwnd_p => zed_upwind_plus - use run_parameters, only: zupwnd_m => zed_upwind_minus + use parameters_numerical, only: zupwnd_p => zed_upwind_plus + use parameters_numerical, only: zupwnd_m => zed_upwind_minus integer, intent(in) :: iv, llim complex, dimension(llim:), intent(in out) :: f @@ -885,27 +832,10 @@ subroutine center_zed_segment_complex(iv, f, llim, periodic) end subroutine center_zed_segment_complex - subroutine center_zed_midpoint(iv, g) - - use zgrid, only: nzgrid - - integer, intent(in) :: iv - real, dimension(-nzgrid:), intent(in out) :: g - - if (stream_sign(iv) > 0) then - g(:nzgrid - 1) = 0.5 * (g(:nzgrid - 1) + g(-nzgrid + 1:)) - g(nzgrid) = g(-nzgrid) - else - g(-nzgrid + 1:) = 0.5 * (g(:nzgrid - 1) + g(-nzgrid + 1:)) - g(-nzgrid) = g(nzgrid) - end if - - end subroutine center_zed_midpoint - subroutine finish_parallel_streaming - use run_parameters, only: stream_implicit, driftkinetic_implicit - use physics_flags, only: full_flux_surface + use parameters_numerical, only: stream_implicit, driftkinetic_implicit + use parameters_physics, only: full_flux_surface implicit none if (allocated(stream)) deallocate (stream) diff --git a/parameters_kxky_grids.f90 b/parameters_kxky_grids.f90 new file mode 100644 index 0000000000..20cdffb4ec --- /dev/null +++ b/parameters_kxky_grids.f90 @@ -0,0 +1,171 @@ +!############################################################################### +!######################## READ PARAMETES FOR KXKY GRIDS ######################## +!############################################################################### +! Namelist: ¶meters_kxky_grids +! These flags will allow you to toggle the algorithm choices in stella. +!############################################################################### + +module parameters_kxky_grids + + public :: read_kxky_grid_parameters + + !> Public parameters + + !> Read grid type + public :: gridopt_switch, gridopt_range, gridopt_box + + !> For Box/Range + public :: naky, nakx + public :: nx, ny + public :: nalpha, naky_all, ikx_max + public :: reality + public :: phase_shift_angle + public :: jtwist, jtwistfac, ikx_twist_shift + public :: centered_in_rho + public :: periodic_variation, randomize_phase_shift + public :: aky_min, aky_max + public :: akx_min, akx_max + public :: theta0_min, theta0_max + public :: x0, y0 + + !> ky spaction options + public :: kyspacing_option_switch, kyspacing_linear, kyspacing_exponential + + private + + !> Internal + integer :: gridopt_switch + integer, parameter :: gridopt_range = 1, gridopt_box = 2 + + integer :: naky, nakx, nx, ny + integer :: nalpha, naky_all, ikx_max + logical :: reality = .false. + real :: phase_shift_angle + integer :: jtwist + real :: jtwistfac + real :: ikx_twist_shift + + logical :: centered_in_rho, periodic_variation, randomize_phase_shift + + !> For Range + real :: aky_min, aky_max + real :: akx_min, akx_max + real :: theta0_min, theta0_max + integer :: kyspacing_option_switch +!! character(20) :: kyspacing_option = 'default' + integer, parameter :: kyspacing_linear = 1, kyspacing_exponential = 2 + + !> For Box + real :: x0, y0 + + logical :: initialised + +contains + + subroutine read_kxky_grid_parameters + + use mp, only: proc0, mp_abort + use text_options, only: text_option, get_option_value + use file_utils, only: input_unit, error_unit, input_unit_exist + + use parameters_kxky_grids_box, only : read_kxky_grids_box + use parameters_kxky_grids_range, only : read_kxky_grids_range + + implicit none + + if (initialised) return + + if (proc0) then + call read_grid_option + select case (gridopt_switch) + case (gridopt_range) + call read_kxky_grids_range (nalpha, naky, nakx, aky_min, aky_max, & + akx_min, akx_max, theta0_min, theta0_max, & + kyspacing_option_switch, phase_shift_angle, ikx_max, naky_all) + case (gridopt_box) + call read_kxky_grids_box (nx, ny, ikx_max, naky_all, naky, nakx, nalpha, & + x0, y0, jtwist, jtwistfac, phase_shift_angle, & + centered_in_rho, randomize_phase_shift, periodic_variation, reality) + end select + end if + + call broadcast_parameters + initialised = .true. + + contains + + !********************************************************************** + ! READ GRID OPTION FOR KXK ! + !********************************************************************** + ! Read which option to select for the kxky grid layouts + !********************************************************************** + subroutine read_grid_option + + + use file_utils, only: input_unit, error_unit, input_unit_exist + use text_options, only: text_option, get_option_value + + implicit none + + type(text_option), dimension(5), parameter :: gridopts = & + (/text_option('default', gridopt_range), & + text_option('range', gridopt_range), & + text_option('box', gridopt_box), & + text_option('annulus', gridopt_box), & + text_option('nonlinear', gridopt_box)/) + + integer :: ierr, in_file + logical :: nml_exist + + character(20) :: grid_option + + namelist /kt_grids_knobs/ grid_option + + grid_option = 'default' + + in_file = input_unit_exist("kt_grids_knobs", nml_exist) + if (nml_exist) read (unit=in_file, nml=kt_grids_knobs) + + ierr = error_unit() + call get_option_value(grid_option, gridopts, gridopt_switch, & + ierr, "grid_option in kt_grids_knobs") + + end subroutine read_grid_option + + subroutine broadcast_parameters + + use mp, only: broadcast + + implicit none + + call broadcast(gridopt_switch) + call broadcast(naky) + call broadcast(nakx) + call broadcast(ny) + call broadcast(nx) + call broadcast(nalpha) + call broadcast(naky_all) + call broadcast(ikx_max) + call broadcast(reality) + call broadcast(phase_shift_angle) + call broadcast(jtwist) + call broadcast(jtwistfac) + call broadcast(ikx_twist_shift) + call broadcast(centered_in_rho) + call broadcast(periodic_variation) + call broadcast(randomize_phase_shift) + call broadcast(aky_min) + call broadcast(aky_max) + call broadcast(akx_min) + call broadcast(akx_max) + call broadcast(theta0_min) + call broadcast(theta0_max) + call broadcast(kyspacing_option_switch) + call broadcast(x0) + call broadcast(y0) + + end subroutine broadcast_parameters + + end subroutine read_kxky_grid_parameters + +end module parameters_kxky_grids diff --git a/parameters_kxky_grids_box.f90 b/parameters_kxky_grids_box.f90 new file mode 100644 index 0000000000..c75f75d39a --- /dev/null +++ b/parameters_kxky_grids_box.f90 @@ -0,0 +1,167 @@ +!############################################################################### +!###################### READ PARAMETERS FOR KXKY BOX GRID ###################### +!############################################################################### +! Namelist: ¶meters_kxky_grids_box +! These flags will allow you to toggle the algorithm choices in stella. +!############################################################################### + +module parameters_kxky_grids_box + + public :: read_kxky_grids_box + + private + + logical :: initialised + + contains + + !====================================================================== + !================= READ PARAMETERS FOR KXKY BOX GRID ================== + !====================================================================== + subroutine read_kxky_grids_box (nx, ny, ikx_max, naky_all, naky, nakx, nalpha, & + x0, y0, jtwist, jtwistfac, phase_shift_angle, & + centered_in_rho, randomize_phase_shift, periodic_variation, reality) + + use mp, only: mp_abort + use text_options, only: text_option, get_option_value + use file_utils, only: input_unit, error_unit, input_unit_exist + + implicit none + + integer, intent (out) :: nx, ny, nalpha + integer, intent (out) :: jtwist + integer, intent (out) :: naky, nakx + integer, intent (out) :: ikx_max, naky_all + real, intent (out) :: jtwistfac + real, intent (out) :: phase_shift_angle + real, intent (out) :: x0, y0 + logical, intent (out) :: centered_in_rho, periodic_variation, randomize_phase_shift + logical, intent (out) :: reality + + if (initialised) return + + call read_default_box + call read_input_file_box + + initialised = .true. + + contains + + !********************************************************************** + ! SET DEFAULT PARAMETERS ! + !********************************************************************** + ! If not specified in the input file these are the default options that + ! will be set for all parameters under the namelist + ! &numerical'. + !********************************************************************** + + subroutine read_default_box + + implicit none + + nx = 1 + ny = 1 + jtwist = -1 + jtwistfac = 1. + phase_shift_angle = 0. + x0 = -1.0 + y0 = -1.0 + nalpha = 1 + centered_in_rho = .true. + randomize_phase_shift = .false. + periodic_variation = .false. + + end subroutine read_default_box + + + !********************************************************************** + ! READ GRID OPTION FOR KXK ! + !********************************************************************** + ! Read which option to select for the kxky grid layouts + !********************************************************************** + subroutine read_input_file_box + + use file_utils, only: input_unit_exist + use parameters_physics, only: full_flux_surface + implicit none + + integer :: in_file + logical :: exist + + namelist /parameters_kxky_grids_box/ nx, ny, jtwist, jtwistfac, x0, y0, & + centered_in_rho, periodic_variation, & + randomize_phase_shift, phase_shift_angle + + ! note that jtwist and y0 will possibly be modified + ! later in init_kt_grids_box if they make it out + ! of this subroutine with negative values + ! it is necessary to wait until later to do this check + ! because the values to which they may be set will + ! depend on information from the geometry module, + ! which itself may rely on ny from here (number of alphas) + + in_file = input_unit_exist("parameters_kxky_grids_box", exist) + if (exist) read (in_file, nml=parameters_kxky_grids_box) + + call check_backwards_compatability_box + + !> Get the number of de-aliased modes in y and x, using reality to halve the number of ky modes + naky = (ny - 1) / 3 + 1 + nakx = 2 * ((nx - 1) / 3) + 1 + + if (full_flux_surface) nalpha = ny + + !> Get the ikx index corresponding to kx_max + ikx_max = nakx / 2 + 1 + + reality = .true. + !> Get the total number of ky values, including negative ky; + !> this is approximately 2/3 ny because ny includes padding to avoid aliasing + naky_all = 2 * naky - 1 + + end subroutine read_input_file_box + + !********************************************************************** + ! CHECK BACKWARDS COMPATIBILITY ! + !********************************************************************** + ! Make sure stella either runs or aborts old names for variables or + ! namelists are used + !********************************************************************** + + subroutine check_backwards_compatability_box + + use file_utils, only: input_unit, input_unit_exist + use parameters_numerical, only: print_extra_info_to_terminal + implicit none + + logical :: old_nml_exist + integer :: in_file + + namelist /kt_grids_box_parameters/ nx, ny, jtwist, jtwistfac, x0, y0, & + centered_in_rho, periodic_variation, & + randomize_phase_shift, phase_shift_angle + + !> rrm phase_shift angle + + in_file = input_unit_exist("kt_grids_box_parameters", old_nml_exist) + if (old_nml_exist) then + read (in_file, nml=kt_grids_box_parameters) + if (print_extra_info_to_terminal) then + write(*,*) '!!!!!!!!!!!!!!!!!!!!!!!!!!WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + write(*,*) 'Please replace the namelist in the' + write(*,*) 'input file with and include all' + write(*,*) 'variable names under this new namelist.' + end if + ! write(*,*) "Aborting in parameters_kxky_grids_box.f90. & + ! The namelist does not exist. & + ! Please replace this with the title " + ! call mp_abort("Aborting in parameters_kxky_grids_box.f90. & + ! The namelist does not exist. & + ! Please replace this with the title ") + end if + + end subroutine check_backwards_compatability_box + + end subroutine read_kxky_grids_box + +end module parameters_kxky_grids_box diff --git a/parameters_kxky_grids_range.f90 b/parameters_kxky_grids_range.f90 new file mode 100644 index 0000000000..0ae082c290 --- /dev/null +++ b/parameters_kxky_grids_range.f90 @@ -0,0 +1,181 @@ +!############################################################################### +!##################### READ PARAMETERS FOR KXKY RANGE GRID ##################### +!############################################################################### +! Namelist: ¶meters_kxky_grids_range +! These flags will allow you to toggle the algorithm choices in stella. +!############################################################################### + +module parameters_kxky_grids_range + + public :: read_kxky_grids_range + + logical :: initialised + + contains + + !====================================================================== + !================= READ PARAMETERS FOR KXKY range GRID ================ + !====================================================================== + subroutine read_kxky_grids_range (nalpha, naky, nakx, aky_min, aky_max, & + akx_min, akx_max, theta0_min, theta0_max, & + kyspacing_option_switch, phase_shift_angle, ikx_max, naky_all) + + use mp, only: mp_abort + + implicit none + + + integer, intent (out) :: nalpha, naky, nakx + real, intent (out) :: aky_min, aky_max, akx_min, akx_max + real, intent (out) :: theta0_min, theta0_max + integer, intent (out) :: kyspacing_option_switch + real, intent (out) :: phase_shift_angle + integer, intent (out) :: ikx_max, naky_all + + integer, parameter :: kyspacing_linear = 1, kyspacing_exponential = 2 + + if (initialised) return + + call read_default_range + call read_input_file_range + + initialised = .true. + + contains + + !********************************************************************** + ! SET DEFAULT PARAMETERS ! + !********************************************************************** + ! If not specified in the input file these are the default options that + ! will be set for all parameters under the namelist + ! &numerical'. + !********************************************************************** + + subroutine read_default_range + + implicit none + + nalpha = 1 + naky = 1 + nakx = 1 + aky_min = 0.0 + aky_max = 0.0 + !> set these to be nonsense values + !> so can check later if they've been set + akx_min = 0.0 + akx_max = -1.0 + theta0_min = 0.0 + theta0_max = -1.0 + phase_shift_angle = 0. + + end subroutine read_default_range + + + !********************************************************************** + ! READ INPUT FOR KXKY GRIDS, RANGE ! + !********************************************************************** + ! Read which option to select for the kxky grid layouts + !********************************************************************** + subroutine read_input_file_range + + use file_utils, only: input_unit, error_unit, input_unit_exist + use parameters_physics, only: full_flux_surface + use text_options, only: text_option, get_option_value + + implicit none + + type(text_option), dimension(3), parameter :: kyspacingopts = & + (/text_option('default', kyspacing_linear), & + text_option('linear', kyspacing_linear), & + text_option('exponential', kyspacing_exponential)/) + + character(20) :: kyspacing_option = 'default' + + integer :: ierr, in_file + logical :: exist + + namelist /kt_grids_range_parameters/ naky, nakx, & + aky_min, aky_max, theta0_min, theta0_max, akx_min, akx_max, kyspacing_option + + ! note that jtwist and y0 will possibly be modified + ! later in init_kt_grids_range if they make it out + ! of this subroutine with negative values + ! it is necessary to wait until later to do this check + ! because the values to which they may be set will + ! depend on information from the geometry module, + ! which itself may rely on ny from here (number of alphas) + + in_file = input_unit_exist("parameters_kxky_grids_range", exist) + if (exist) read (in_file, nml=kt_grids_range_parameters) + + call check_backwards_compatability_range + + if (full_flux_surface) then + write (*, *) '!!! ERROR !!!' + write (*, *) 'kt_grids "range" option is not supported for full_flux_surface = T. aborting' + write (*, *) '!!! ERROR !!!' + call mp_abort('kt_grids "range" option is not supported for full_flux_surface = T. aborting') + end if + + ierr = error_unit() + call get_option_value(kyspacing_option, kyspacingopts, kyspacing_option_switch, & + ierr, "kyspacing_option in kt_grids_range_parameters", .true.) + + naky_all = naky + ikx_max = nakx + + end subroutine read_input_file_range + + !********************************************************************** + ! CHECK BACKWARDS COMPATIBILITY ! + !********************************************************************** + ! Make sure stella either runs or aborts old names for variables or + ! namelists are used + !********************************************************************** + + subroutine check_backwards_compatability_range + + use file_utils, only: input_unit, error_unit, input_unit_exist + use parameters_numerical, only: print_extra_info_to_terminal + use text_options, only: text_option, get_option_value + + implicit none + + type(text_option), dimension(3), parameter :: kyspacingopts = & + (/text_option('default', kyspacing_linear), & + text_option('linear', kyspacing_linear), & + text_option('exponential', kyspacing_exponential)/) + + character(20) :: kyspacing_option = 'default' + + logical :: old_nml_exist + integer :: ierr, in_file + + !> akx -> kx and aky -> ky + !> TODO-GA: make this back compatible + + namelist /kt_grids_range_parameters/ naky, nakx, & + aky_min, aky_max, theta0_min, theta0_max, akx_min, akx_max, kyspacing_option + + in_file = input_unit_exist("kt_grids_range_parameters", old_nml_exist) + if (old_nml_exist) then + read (in_file, nml=kt_grids_range_parameters) + + ierr = error_unit() + call get_option_value(kyspacing_option, kyspacingopts, kyspacing_option_switch, & + ierr, "kyspacing_option in kt_grids_range_parameters", .true.) + + if (print_extra_info_to_terminal) then + write(*,*) "Aborting in parameters_kxky_grids_range.f90. & + The namelist does not exist. & + Please replace this with the title " +! call mp_abort("Aborting in parameters_kxky_grids_range.f90. & + ! The namelist does not exist. & + ! Please replace this with the title ") + end if + end if + end subroutine check_backwards_compatability_range + + end subroutine read_kxky_grids_range + +end module parameters_kxky_grids_range diff --git a/parameters_numerical.f90 b/parameters_numerical.f90 new file mode 100644 index 0000000000..514262530f --- /dev/null +++ b/parameters_numerical.f90 @@ -0,0 +1,550 @@ +!############################################################################### +!########################### READ NUMERICAL PARAMETES ########################## +!############################################################################### +! Namelist: &numerical +! These flags will allow you to toggle the algorithm choices in stella. +!############################################################################### +module parameters_numerical + + implicit none + + !> Public subroutines that are read by the main stella routine. + public :: read_parameters_numerical, finish_read_parameters_numerical + + !> Algorithm schemes + public :: stream_implicit, stream_iterative_implicit, stream_matrix_inversion, driftkinetic_implicit + public :: mirror_implicit, mirror_semi_lagrange, mirror_linear_interp + public :: drifts_implicit + public :: fully_implicit, fully_explicit + public :: maxwellian_inside_zed_derivative, use_deltaphi_for_response_matrix + + public :: maxwellian_normalization + + !> Upwinding options + public :: time_upwind, time_upwind_plus, time_upwind_minus + public :: zed_upwind, zed_upwind_plus, zed_upwind_minus + public :: vpa_upwind + + !> Time options -> TODO-GA or TODO-HT need better description + public :: nstep, delt, tend, nitt + + public :: flip_flop + public :: cfl_cushion_upper, cfl_cushion_middle, cfl_cushion_lower + public :: avail_cpu_time + public :: delt_max, delt_min + public :: autostop + !> TODO-HT or TODO-GA get rid of this?? + public :: fphi + + public :: ky_solve_radial, ky_solve_real + public :: fields_kxkyz, mat_gen, mat_read + + public :: print_extra_info_to_terminal + + !> Explicit time-stepping option + public :: explicit_option_switch, explicit_option_rk3, explicit_option_rk2 + public :: explicit_option_rk4, explicit_option_euler + + !> Delt-options + public :: delt_option_switch + public :: delt_option_hand, delt_option_auto + + !> LU-option + public :: lu_option_switch + public :: lu_option_local, lu_option_none, lu_option_global + + !> TODO-GA - REMOVE + public :: rng_seed + + private + + !> Algorithm schemes + logical :: stream_implicit, stream_iterative_implicit, stream_matrix_inversion, driftkinetic_implicit + logical :: mirror_implicit, mirror_semi_lagrange, mirror_linear_interp + logical :: drifts_implicit, fully_implicit, fully_explicit + logical :: maxwellian_inside_zed_derivative, use_deltaphi_for_response_matrix + !> REMOVE + logical :: maxwellian_normalization + + !> Upwinding options + real :: time_upwind, time_upwind_plus, time_upwind_minus + real :: zed_upwind, zed_upwind_plus, zed_upwind_minus + real :: vpa_upwind + + integer :: delt_option_switch, lu_option_switch + integer, parameter :: delt_option_hand = 1, delt_option_auto = 2 + + integer, parameter :: lu_option_none = 1, & + lu_option_local = 2, & + lu_option_global = 3 + + !> For CFL conditions + integer :: nstep + real :: delt, tend + real :: cfl_cushion_upper, cfl_cushion_middle, cfl_cushion_lower + real :: avail_cpu_time + real :: delt_max, delt_min + integer :: explicit_option_switch + logical :: flip_flop + integer, parameter :: explicit_option_rk3 = 1, & + explicit_option_rk2 = 2, & + explicit_option_rk4 = 3, & + explicit_option_euler = 4 + + logical :: autostop + real :: fphi + logical :: fields_kxkyz, mat_gen, mat_read + logical :: ky_solve_real + integer :: ky_solve_radial + integer :: nitt + logical :: print_extra_info_to_terminal + + logical :: initialised = .false. + + !> REMOVE + integer :: rng_seed + + !> Internal + logical :: old_nml_exist + +contains + + !====================================================================== + !===================== READ NUMERICAL PARAMETERS ====================== + !====================================================================== + subroutine read_parameters_numerical + + use mp, only: proc0, mp_abort + use text_options, only: text_option, get_option_value + use file_utils, only: input_unit, error_unit, input_unit_exist + + implicit none + + logical :: error = .false. + character(10) :: explicit_option + character(20) :: delt_option, lu_option + + if (initialised) return + + if (proc0) call set_default_parameters + if (proc0) call read_input_file + call broadcast_parameters + + initialised = .true. + + contains + !********************************************************************** + ! SET DEFAULT PARAMETERS ! + !********************************************************************** + ! If not specified in the input file these are the default options that + ! will be set for all parameters under the namelist + ! &numerical'. + !********************************************************************** + subroutine set_default_parameters + + implicit none + + stream_implicit = .true. + stream_iterative_implicit = .false. + mirror_implicit = .true. + drifts_implicit = .false. + + stream_matrix_inversion = .false. + mirror_semi_lagrange = .true. + mirror_linear_interp = .false. + maxwellian_inside_zed_derivative = .false. + use_deltaphi_for_response_matrix = .false. + maxwellian_normalization = .false. + zed_upwind = 0.02 + vpa_upwind = 0.02 + time_upwind = 0.02 + fphi = 1.0 + !> Stella runs until t*v_{th,i}/a=tend or until istep=nstep + nstep = - 1 + delt = 0.03 !> Set some number for the time step - QUESTION: should we set to be a silly number? + tend = -1.0 + delt_option = 'default' + !> The response matrix is solved with a none, local or global scheme, local seems to be the most efficient + lu_option = 'default' + avail_cpu_time = 1.e10 + !> Code_dt needs to stay within [cfl_dt*cfl_cushion_upper, cfl_dt*cfl_cushion_lower] + !> code_dt can be increased if cfl_dt increases, however, never increase above delt_max (=delt by default) + !> Exit stella if code_dt < delt_min (e.g. when the code blows up) + cfl_cushion_upper = 0.5 !> Stay a factor of 2 under the CFL condition, otherwise it might run out of control + cfl_cushion_middle = 0.25 !> If code_dt>cfl_dt/2 or code_dt Default is very low to not trigger it. + delt_max = -1 + delt_min = 1.e-10 + autostop = .true. + + fields_kxkyz = .false. + mat_gen = .false. + mat_read = .false. + + ky_solve_radial = 0 + ky_solve_real = .false. + nitt = 1 + print_extra_info_to_terminal = .true. + + explicit_option = 'default' + flip_flop = .false. + + !> TODO-GA REMOVE + rng_seed = -1 !negative values use current time as seed + end subroutine + + !********************************************************************** + ! READ INPUT OPTIONS ! + !********************************************************************** + ! Overwrite any default options with those specified in the input file. + ! Then change the other parameters consistently. + !********************************************************************** + subroutine read_input_file + + use parameters_physics, only: full_flux_surface + use parameters_physics, only: include_apar, include_bpar + use parameters_physics, only: include_parallel_streaming + use parameters_physics, only: include_mirror + use parameters_physics, only: nonlinear + use parameters_physics, only: rhostar + !> For FFS - need to delete + + implicit none + + type(text_option), dimension(3), parameter :: deltopts = & + (/text_option('default', delt_option_auto), & + text_option('set_by_hand', delt_option_hand), & + text_option('check_restart', delt_option_auto)/) + + type(text_option), dimension(4), parameter :: lu_opts = & + (/text_option('default', lu_option_local), & + text_option('none', lu_option_none), & + text_option('local', lu_option_local), & + text_option('global', lu_option_global)/) + + type(text_option), dimension(5), parameter :: explicitopts = & + (/text_option('default', explicit_option_rk3), & + text_option('rk3', explicit_option_rk3), & + text_option('rk2', explicit_option_rk2), & + text_option('rk4', explicit_option_rk4), & + text_option('euler', explicit_option_euler)/) + + integer :: ierr, in_file + logical :: nml_exist + + namelist /parameters_numerical/ stream_implicit, stream_iterative_implicit, stream_matrix_inversion, & + driftkinetic_implicit, mirror_implicit, mirror_semi_lagrange, mirror_linear_interp, & + drifts_implicit, fully_implicit, fully_explicit, & + maxwellian_inside_zed_derivative, use_deltaphi_for_response_matrix, & + maxwellian_normalization, zed_upwind, vpa_upwind, time_upwind, & + fphi, nstep, delt, tend, delt_option, lu_option, avail_cpu_time, & + cfl_cushion_upper, cfl_cushion_middle, cfl_cushion_lower, delt_max, delt_min, & + fields_kxkyz, mat_gen, mat_read, & + ky_solve_radial, ky_solve_real, nitt, print_extra_info_to_terminal, & + explicit_option, flip_flop, rng_seed, autostop + + !> Overwrite the default input parameters by those specified in the input file + !> under the heading '&numerical' + in_file = input_unit_exist("parameters_numerical", nml_exist) + if (nml_exist) read (unit=in_file, nml=parameters_numerical) + + call check_backwards_compatability + + ierr = error_unit() + call get_option_value & + (delt_option, deltopts, delt_option_switch, ierr, & + "delt_option in parameters_numerical") + call get_option_value & + (lu_option, lu_opts, lu_option_switch, ierr, & + "lu_option in parameters_numerical") + call get_option_value & + (explicit_option, explicitopts, explicit_option_switch, & + ierr, "explicit_option in parameters_numerical") + + !> Abort if neither tend nor nstep are set + if (tend < 0 .and. nstep < 0) then + ierr = error_unit() + write (ierr, *) '' + write (ierr, *) 'Please specify either or in the namelist.' + write (ierr, *) 'Aborting.' + write (*, *) '' + write (*, *) 'Please specify either or in the namelist.' + write (*, *) 'Aborting.' + error = .true. + end if + + !> Abort if cfl_cushion_lower>cfl_cushion_upper or if cfl_cushion_lower==cfl_cushion_upper + if ((cfl_cushion_lower > cfl_cushion_upper - 0.001) & + .or. (cfl_cushion_middle > cfl_cushion_upper - 0.001) & + .or. (cfl_cushion_middle < cfl_cushion_lower + 0.001)) then + ierr = error_unit() + write (ierr, *) '' + write (ierr, *) 'Please make sure that is bigger than ,' + write (ierr, *) 'and that lies in between and .' + write (ierr, *) 'Aborting.' + write (*, *) '' + write (*, *) 'Please make sure that is bigger than ,' + write (*, *) 'and that lies in between and .' + write (*, *) 'Aborting.' + error = .true. + end if + + !> Semi-lagrange advance of mirror term is not supported for EM simulations + if (include_apar .and. mirror_semi_lagrange) then + write (*, *) '!!!WARNING!!!' + write (*, *) 'mirror_semi_lagrange = .true. is not supported for electromagnetic simulations.' + write (*, *) 'forcing mirror_semi_lagrange = .false.' + write (*, *) '!!!WARNING!!!' + mirror_semi_lagrange = .false. + end if + + if (drifts_implicit) then + if (.not. stream_implicit) then + write (*, *) '!!!WARNING!!!' + write (*, *) 'drifts_implicit = T requires stream_implicit = T.' + write (*, *) 'forcing drifts_implicit = F.' + write (*, *) '!!!WARNING!!!' + drifts_implicit = .false. + else if (.not. include_parallel_streaming) then + write (*, *) '!!!WARNING!!!' + write (*, *) 'drifts_implicit = T requires include_parallel_streaming = T.' + write (*, *) 'forcing drifts_implicit = F.' + write (*, *) '!!!WARNING!!!' + drifts_implicit = .false. + end if + + if (rhostar > epsilon(0.0)) then + write (*, *) '!!!WARNING!!!' + write (*, *) 'drifts_implicit = T, coupled with rhostar > 0, has been observed' + write (*, *) 'to lead to numerical instability. unless you know what you are doing,' + write (*, *) 'it is suggested that you set drifts_implicit = F or rhostar = 0.' + write (*, *) '!!!WARNING!!!' + end if + end if + + if (.not. full_flux_surface) then + nitt = 1 + end if + + !> Print warning messages and override inconsistent or unsupported options for full_flux_surface = T + if (full_flux_surface) then + if (fields_kxkyz) then + write (*, *) + write (*, *) '!!!WARNING!!!' + write (*, *) 'The option fields_kxkyz=T is not currently supported for full_flux_surface=T.' + write (*, *) 'Forcing fields_kxkyz=F.' + write (*, *) '!!!WARNING!!!' + write (*, *) + fields_kxkyz = .false. + end if + if (mirror_semi_lagrange) then + write (*, *) + write (*, *) '!!!WARNING!!!' + write (*, *) 'The option mirror_semi_lagrange=T is not consistent with full_flux_surface=T.' + write (*, *) 'Forcing mirror_semi_lagrange=F.' + write (*, *) '!!!WARNING!!!' + mirror_semi_lagrange = .false. + end if + if (stream_implicit) then + driftkinetic_implicit = .true. + end if + if (maxwellian_normalization) then + write (*, *) + write (*, *) '!!!WARNING!!!' + write (*, *) 'The option maxwellian_normalisation=T is not consistent with full_flux_surface=T.' + write (*, *) 'Forcing maxwellian_normalisation=F.' + write (*, *) '!!!WARNING!!!' + maxwellian_normalization = .false. + end if + + else + driftkinetic_implicit = .false. + end if + + if (fully_explicit) flip_flop = .false. + + !> Calculate some useful derived quantities that are used repeatedly across modules + time_upwind_plus = 0.5 * (1.0 + time_upwind) + time_upwind_minus = 0.5 * (1.0 - time_upwind) + zed_upwind_plus = 0.5 * (1.0 + zed_upwind) + zed_upwind_minus = 0.5 * (1.0 - zed_upwind) + + if (.not. include_mirror) mirror_implicit = .false. + if (.not. include_parallel_streaming) then + stream_implicit = .false. + driftkinetic_implicit = .false. + end if + + if (mirror_implicit .or. stream_implicit .or. drifts_implicit) then + fully_explicit = .false. + else + fully_explicit = .true. + end if + + if (mirror_implicit .and. stream_implicit .and. drifts_implicit .and. .not. nonlinear) then + fully_implicit = .true. + else + fully_implicit = .false. + end if + + + end subroutine read_input_file + + !********************************************************************** + ! CHECK BACKWARDS COMPATIBILITY ! + !********************************************************************** + ! Make sure stella either runs or aborts old names for variables or + ! namelists are used + !********************************************************************** + subroutine check_backwards_compatability + + use file_utils, only: input_unit, input_unit_exist + use parameters_physics, only: explicit_option_old, flip_flop_old, time_advance_knob_exists + + implicit none + + integer :: in_file + + namelist /knobs/ fphi, delt, nstep, tend, & + delt_option, lu_option, autostop, & + avail_cpu_time, delt_max, delt_min, & + cfl_cushion_upper, cfl_cushion_middle, cfl_cushion_lower, & + stream_implicit, mirror_implicit, & + drifts_implicit, use_deltaphi_for_response_matrix, & + maxwellian_normalization, & + stream_matrix_inversion, maxwellian_inside_zed_derivative, & + mirror_semi_lagrange, mirror_linear_interp, & + zed_upwind, vpa_upwind, time_upwind, & + fields_kxkyz, mat_gen, mat_read, rng_seed, & + ky_solve_radial, ky_solve_real, nitt, print_extra_info_to_terminal + +!! namelist /time_advance_knobs/ xdriftknob, ydriftknob, wstarknob, explicit_option, flip_flop + + in_file = input_unit_exist("knobs", old_nml_exist) + if (old_nml_exist) then + read (unit=in_file, nml=knobs) + if(print_extra_info_to_terminal) then + write(*,*) '!!!!!!!!!!!!!!!!!!!!!!!!!!WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + write(*,*) 'Please replace the namelist in the input file with' + write(*,*) ' and include all variable names under' + write(*,*) 'this new namelist.' + write(*,*) '!!!!!!!!!!!!!!!!!!!!!!!!!!WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + end if + ! write(*,*) "Aborting in parameters_numerical.f90. & + ! The namelist does not exist. & + ! Please replace this with the title " + ! call mp_abort("Aborting in parameters_numerical.f90. & + ! The namelist does not exist. & + ! Please replace this with the title ") + end if + + !! in_file = input_unit_exist("time_advance_knobs", old_nml_exist) +!! if (old_nml_exist) then + if (time_advance_knob_exists) then +!! read(unit=in_file, nml=time_advance_knobs) + explicit_option = explicit_option_old + flip_flop = flip_flop_old + if (print_extra_info_to_terminal) then + write(*,*) '!!!!!!!!!!!!!!!!!!!!!!!!!!WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + write(*,*) 'Please replace the namelist in the input file.' + write(*,*) 'Refer to the input paramters text file as to which namelist to use.' + write(*,*) 'Some of these parameters have been moved to ' + write(*,*) 'and others have been moves to .' + write(*,*) '!!!!!!!!!!!!!!!!!!!!!!!!!!WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + end if + + ! write(*,*) "Aborting in parameters_numerical.f90.& + ! The namelist does not exist.& + ! Please replace this with the title " + ! call mp_abort("Aborting in parameters_numerical.f90.& + ! The namelist does not exist.& + ! Please replace this with the title ") + end if + + end subroutine check_backwards_compatability + + !********************************************************************** + ! BROADCAST OPTIONS ! + !********************************************************************** + ! Broadcast these parameters to all the processors - necessary because + ! the above was only done for the first processor (proc0). + !********************************************************************** + subroutine broadcast_parameters + + use mp, only: broadcast + !use parameters_physics, only: xdriftknob, ydriftknob, wstarknob + + implicit none + !> Exit stella if we ran into an error + call broadcast(error) + if (error) call mp_abort('Aborting in parameters_numerical.f90') + + call broadcast(stream_implicit) + call broadcast(stream_iterative_implicit) + call broadcast(stream_matrix_inversion) + call broadcast(driftkinetic_implicit) + call broadcast(mirror_implicit) + call broadcast(mirror_semi_lagrange) + call broadcast(mirror_linear_interp) + call broadcast(drifts_implicit) + call broadcast(fully_explicit) + call broadcast(fully_implicit) + + call broadcast(maxwellian_inside_zed_derivative) + call broadcast(use_deltaphi_for_response_matrix) + call broadcast(maxwellian_normalization) + + call broadcast(time_upwind_plus) + call broadcast(time_upwind_minus) + call broadcast(zed_upwind_plus) + call broadcast(zed_upwind_minus) + call broadcast(zed_upwind) + call broadcast(vpa_upwind) + call broadcast(time_upwind) + + call broadcast(nstep) + call broadcast(delt) + call broadcast(tend) + call broadcast(nitt) + + call broadcast(explicit_option_switch) + call broadcast(flip_flop) + + call broadcast(cfl_cushion_upper) + call broadcast(cfl_cushion_middle) + call broadcast(cfl_cushion_lower) + call broadcast(avail_cpu_time) + + call broadcast(delt_max) + call broadcast(delt_min) + call broadcast(autostop) + call broadcast(fphi) + + call broadcast(ky_solve_radial) + call broadcast(ky_solve_real) + call broadcast(fields_kxkyz) + + call broadcast(delt_option_switch) + call broadcast(lu_option_switch) + + call broadcast(mat_gen) + call broadcast(mat_read) + + call broadcast(print_extra_info_to_terminal) + + !> GA REMOVE + call broadcast(rng_seed) + + + end subroutine broadcast_parameters + + end subroutine read_parameters_numerical + + subroutine finish_read_parameters_numerical + + implicit none + initialised = .false. + + end subroutine finish_read_parameters_numerical + +end module parameters_numerical diff --git a/parameters_physics.f90 b/parameters_physics.f90 new file mode 100644 index 0000000000..47d2cef7c7 --- /dev/null +++ b/parameters_physics.f90 @@ -0,0 +1,361 @@ +!############################################################################### +!############################ READ PHYSICS PARAMETES ########################### +!############################################################################### +! Namelist: ¶meters_physics +! These are different logicals and parameters that adjust the physics in the +! problem. These will allow you to toggles whether you want to include different +! terms in the gyrokinetic equation, as well as allowing you to include different +! large scale effects such as whether the system allows for electromanetic +! effect, full flux surface effect, or radially global effects. +!############################################################################### + +module parameters_physics + + implicit none + + !> Public subroutines that are read by the main stella routine. + public :: read_parameters_physics + public :: finish_read_parameters_physics + + !> Available physics options: These are standard gyrokinetic terms that + !> can be turned on/off with the following toggles. + public :: include_parallel_streaming + public :: include_mirror + public :: nonlinear + public :: xdriftknob, ydriftknob, wstarknob + + !> Adiabatic options: This is used when nspec = 1. The non-kinetic + !> species (usually electrons) is set to have an adiabatic response. + !> This can be either the classic adiabatic option, or the modified + !> adiabatic option (i.e. modified Boltzmann electrons). + public :: adiabatic_option_switch, adiabatic_option_fieldlineavg + + !> Additional physics effects + public :: prp_shear_enabled + public :: hammett_flow_shear + public :: include_pressure_variation + public :: include_geometric_variation + public :: include_parallel_nonlinearity + public :: suppress_zonal_interaction + + !> Large scale physics options of the system - e.g. whether we have full flux effects, + !> electromagnetic effects, or radially global effects. + public :: full_flux_surface + public :: include_apar + public :: include_bpar + public :: radial_variation + + public :: beta, zeff, tite, nine, rhostar, vnew_ref + public :: g_exb, g_exbfac, omprimfac + + public :: flip_flop_old + public :: explicit_option_old + public :: time_advance_knob_exists + + private + + logical :: include_parallel_streaming + logical :: include_mirror + logical :: nonlinear + real :: xdriftknob, ydriftknob, wstarknob + + integer :: adiabatic_option_switch + integer, parameter :: adiabatic_option_periodic = 1, & + adiabatic_option_zero = 2, & + adiabatic_option_fieldlineavg = 3 + + + logical :: prp_shear_enabled + logical :: hammett_flow_shear + logical :: include_pressure_variation + logical :: include_geometric_variation + logical :: include_parallel_nonlinearity + logical :: suppress_zonal_interaction + + logical :: full_flux_surface + logical :: include_apar + logical :: include_bpar + logical :: radial_variation + + real :: beta, zeff, tite, nine, rhostar, irhostar, vnew_ref + real :: g_exb, g_exbfac, omprimfac + logical :: initialised = .false. + + !!> Need to fix for the warning messages + logical :: debug = .false. + + !!> TODO-GA: need to fix somehow + logical :: flip_flop_old + character(10) :: explicit_option_old + logical :: time_advance_knob_exists +contains + + !====================================================================== + !====================== READ PHYSICS PARAMETERS ======================= + !====================================================================== + subroutine read_parameters_physics + + use mp, only: proc0 + use text_options, only: text_option, get_option_value + use file_utils, only: input_unit, error_unit, input_unit_exist + + implicit none + + character(30) :: adiabatic_option + + if (initialised) return + + if (proc0) call set_default_parameters + if (proc0) call read_input_file + call broadcast_parameters + + initialised = .true. + + contains + + !********************************************************************** + ! SET DEFAULT PARAMETERS ! + !********************************************************************** + ! If not specified in the input file these are the default options that + ! will be set for all parameters under the namelist + ! ¶meters_physics'. + !********************************************************************** + subroutine set_default_parameters + + implicit none + + !> Standard gyrokinetic terms + include_parallel_streaming = .true. + include_mirror = .true. + nonlinear = .false. + xdriftknob = 1.0 + ydriftknob = 1.0 + wstarknob = 1.0 + + !> If not chose we set adiabatic option to be adiabatic electrons (no modified Boltzmann response) + adiabatic_option = 'field-line-average-term' + + !> Additional effects that can be included but are not by default + prp_shear_enabled = .false. + hammett_flow_shear = .true. + include_pressure_variation = .false. + include_geometric_variation = .true. + include_parallel_nonlinearity = .false. + suppress_zonal_interaction = .false. + + full_flux_surface = .false. + include_apar = .false. + include_bpar = .false. + radial_variation = .false. + + beta = 0.0 ! beta = 8 * pi * p_ref / B_ref^2 + zeff = 1.0 + tite = 1.0 + nine = 1.0 + rhostar = -1.0 ! = m_ref * vt_ref / (e * B_ref * a_ref), with refs in SI + vnew_ref = -1.0 ! various input options will override this value if it is negative + + !> Zonal flow options -> TODO-HT: how to turn on/off + g_exb = 0.0 + g_exbfac = 1.0 + omprimfac = 1.0 + irhostar = -1.0 + + flip_flop_old = .false. + explicit_option_old = 'default' + time_advance_knob_exists = .false. + end subroutine set_default_parameters + + !********************************************************************** + ! READ INPUT OPTIONS ! + !********************************************************************** + ! Overwrite any default options with those specified in the input file. + ! Then change the other parameters consistently. + !********************************************************************** + subroutine read_input_file + + use file_utils, only: input_unit_exist, error_unit + + implicit none + + type(text_option), dimension(6), parameter :: adiabaticopts = & + (/text_option('default', adiabatic_option_fieldlineavg), & + !> TODO-HT or TODO-GA: sed: adiabatic_option_default -> adiabatic_option_periodic + text_option('no-field-line-average-term', adiabatic_option_periodic), & + text_option('field-line-average-term', adiabatic_option_fieldlineavg), & + text_option('iphi00=0', adiabatic_option_periodic), & + text_option('iphi00=1', adiabatic_option_periodic), & + text_option('iphi00=2', adiabatic_option_fieldlineavg)/) + + integer :: ierr, in_file + logical :: nml_exist + + namelist /parameters_physics/ include_parallel_streaming, include_mirror, nonlinear, & + xdriftknob, ydriftknob, wstarknob, adiabatic_option, prp_shear_enabled, & + hammett_flow_shear, include_pressure_variation, include_geometric_variation, & + include_parallel_nonlinearity, suppress_zonal_interaction, full_flux_surface, & + include_apar, include_bpar, radial_variation, & + beta, zeff, tite, nine, rhostar, vnew_ref, & + g_exb, g_exbfac, omprimfac, irhostar + + !> Overwrite the default options with any that are explicitly given in the input file + !> under the heading '¶meters_physics' + in_file = input_unit_exist("parameters_physics", nml_exist) + if (nml_exist) read (unit=in_file, nml=parameters_physics) + + call check_backwards_compatability + + if (irhostar > 0) rhostar = 1./irhostar + !> Don't allow people to set rhostar when its not full flux + !> Otherwise phase_shift_angle will be changed in grids_kxky.f90 + if (.not. full_flux_surface) rhostar = 0 + + ierr = error_unit() + call get_option_value & + (adiabatic_option, adiabaticopts, adiabatic_option_switch, & + ierr, "adiabatic_option in parameters_physics") + + end subroutine + + !********************************************************************** + ! CHECK BACKWARDS COMPATIBILITY ! + !********************************************************************** + ! Make sure stella either runs or aborts old names for variables or + ! namelists are used + !********************************************************************** + subroutine check_backwards_compatability + + use mp, only: mp_abort, broadcast + use debug_flags, only: const_alpha_geo + implicit none + + logical :: old_nml_exist + integer :: in_file + + character(10) :: explicit_option + logical :: flip_flop + + namelist /physics_flags/ full_flux_surface, radial_variation, & + include_parallel_nonlinearity, include_parallel_streaming, & + include_mirror, include_apar, include_bpar, nonlinear, & + include_pressure_variation, include_geometric_variation, & + adiabatic_option, const_alpha_geo, suppress_zonal_interaction + + namelist /parameters/ beta, zeff, tite, nine, rhostar, vnew_ref, & + g_exb, g_exbfac, omprimfac, irhostar + + namelist /time_advance_knobs/ xdriftknob, ydriftknob, wstarknob, explicit_option, flip_flop + + in_file = input_unit_exist("physics_flags", old_nml_exist) + if (old_nml_exist) then + read (unit=in_file, nml=physics_flags) + if(debug) then + write(*,*) '!!!!!!!!!!!!!!!!!!!!!!!!!!WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + write(*,*) 'Please change the namelist in the input file' + write(*,*) 'to . You can inlclude the old flags under' + write(*,*) 'this new namelist' + write(*,*) '!!!!!!!!!!!!!!!!!!!!!!!!!!WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + end if +! call broadcast(const_alpha_geo) + ! write(*,*) "Aborting in parameters_physics.f90.& + ! The namelist does not exist. & + ! Please replace this with the title " + ! call mp_abort('Aborting in parameters_physics.f90.& + ! The namelist does not exist. & + ! Please replace this with the title ') + end if + in_file = input_unit_exist("parameters", old_nml_exist) + if (old_nml_exist) then + read (unit=in_file, nml=parameters) + if(debug) then + write(*,*) '!!!!!!!!!!!!!!!!!!!!!!!!!!WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + write(*,*) 'Please change the namelist in the input file' + write(*,*) 'to . You can inlclude the old flags under' + write(*,*) 'this new namelist' + write(*,*) '!!!!!!!!!!!!!!!!!!!!!!!!!!WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + end if + ! write(*,*) "Aborting in parameters_physics.f90.& + ! The namelist does not exist. & + ! Please replace this with the title " + ! call mp_abort("Aborting in parameters_physics.f90.& + ! The namelist does not exist. & + ! Please replace this with the title ") + end if + + in_file = input_unit_exist("time_advance_knobs", old_nml_exist) + if (old_nml_exist) then + time_advance_knob_exists = .true. + read(unit=in_file, nml=time_advance_knobs) + explicit_option_old = explicit_option + write(*,*) 'explicit_option_old', explicit_option_old + flip_flop_old = flip_flop + end if + + + end subroutine check_backwards_compatability + + !********************************************************************** + ! BROADCAST OPTIONS ! + !********************************************************************** + ! Broadcast these parameters to all the processors - necessary because + ! the above was only done for the first processor (proc0). + !********************************************************************** + subroutine broadcast_parameters + + use mp, only: broadcast + + implicit none + + call broadcast(include_parallel_streaming) + call broadcast(include_mirror) + call broadcast(nonlinear) + call broadcast(xdriftknob) + call broadcast(ydriftknob) + call broadcast(wstarknob) + + call broadcast(adiabatic_option_switch) + + call broadcast(prp_shear_enabled) + call broadcast(hammett_flow_shear) + call broadcast(include_pressure_variation) + call broadcast(include_geometric_variation) + call broadcast(include_parallel_nonlinearity) + call broadcast(suppress_zonal_interaction) + + call broadcast(full_flux_surface) + call broadcast(include_apar) + call broadcast(include_bpar) + call broadcast(radial_variation) + + call broadcast(beta) + call broadcast(vnew_ref) + call broadcast(zeff) + call broadcast(rhostar) + call broadcast(tite) + call broadcast(nine) + call broadcast(g_exb) + call broadcast(g_exbfac) + call broadcast(omprimfac) + + + !> TODO-GA: FIX PLEASE + call broadcast(flip_flop_old) + call broadcast(explicit_option_old) + call broadcast(time_advance_knob_exists) + end subroutine broadcast_parameters + + end subroutine read_parameters_physics + + !********************************************************************** + ! FINISH READ PARAMETERS ! + !********************************************************************** + ! Set the initialised flag to be false such that we do not initialise + ! twice. + !> TODO-HT or TODO-GA: sed: initialised -> initialized + !********************************************************************** + subroutine finish_read_parameters_physics + implicit none + initialised = .false. + end subroutine finish_read_parameters_physics + +end module parameters_physics diff --git a/physics_flags.f90 b/physics_flags.f90 deleted file mode 100644 index c77ab16453..0000000000 --- a/physics_flags.f90 +++ /dev/null @@ -1,138 +0,0 @@ -module physics_flags - - implicit none - - public :: init_physics_flags - public :: finish_physics_flags - public :: full_flux_surface - public :: radial_variation - public :: include_apar - public :: include_bpar - public :: include_parallel_nonlinearity - public :: include_parallel_streaming - public :: include_mirror - public :: prp_shear_enabled - public :: hammett_flow_shear - public :: include_pressure_variation - public :: include_geometric_variation - public :: nonlinear - public :: adiabatic_option_switch - public :: adiabatic_option_fieldlineavg - public :: const_alpha_geo - public :: suppress_zonal_interaction - - private - - logical :: full_flux_surface - logical :: radial_variation - logical :: include_apar - logical :: include_bpar - logical :: include_parallel_nonlinearity - logical :: include_parallel_streaming - logical :: include_pressure_variation - logical :: include_geometric_variation - logical :: include_mirror - logical :: nonlinear - logical :: prp_shear_enabled - logical :: hammett_flow_shear - logical :: const_alpha_geo - logical :: suppress_zonal_interaction - - integer :: adiabatic_option_switch - integer, parameter :: adiabatic_option_default = 1, & - adiabatic_option_zero = 2, & - adiabatic_option_fieldlineavg = 3 - - logical :: initialized = .false. - -contains - - subroutine init_physics_flags - - implicit none - - if (initialized) return - initialized = .true. - - call read_parameters - - end subroutine init_physics_flags - - subroutine read_parameters - - use file_utils, only: input_unit_exist, error_unit - use mp, only: proc0, broadcast - use text_options, only: text_option, get_option_value - - implicit none - - integer :: in_file, ierr - logical :: rpexist - - type(text_option), dimension(6), parameter :: adiabaticopts = & - (/text_option('default', adiabatic_option_default), & - text_option('no-field-line-average-term', adiabatic_option_default), & - text_option('field-line-average-term', adiabatic_option_fieldlineavg), & - text_option('iphi00=0', adiabatic_option_default), & - text_option('iphi00=1', adiabatic_option_default), & - text_option('iphi00=2', adiabatic_option_fieldlineavg)/) - character(30) :: adiabatic_option - - namelist /physics_flags/ full_flux_surface, radial_variation, & - include_parallel_nonlinearity, include_parallel_streaming, & - include_mirror, include_apar, include_bpar, nonlinear, & - include_pressure_variation, include_geometric_variation, & - adiabatic_option, const_alpha_geo, suppress_zonal_interaction - - if (proc0) then - full_flux_surface = .false. - radial_variation = .false. - include_apar = .false. - include_bpar = .false. - include_pressure_variation = .true. - include_geometric_variation = .true. - include_parallel_nonlinearity = .false. - include_parallel_streaming = .true. - include_mirror = .true. - nonlinear = .false. - adiabatic_option = 'default' - const_alpha_geo = .false. - suppress_zonal_interaction = .false. - - in_file = input_unit_exist("physics_flags", rpexist) - if (rpexist) read (unit=in_file, nml=physics_flags) - - ierr = error_unit() - call get_option_value & - (adiabatic_option, adiabaticopts, adiabatic_option_switch, & - ierr, "adiabatic_option in physics_flags") - end if - - prp_shear_enabled = .false. - hammett_flow_shear = .true. - - call broadcast(full_flux_surface) - call broadcast(radial_variation) - call broadcast(include_apar) - call broadcast(include_bpar) - call broadcast(include_pressure_variation) - call broadcast(include_geometric_variation) - call broadcast(include_parallel_nonlinearity) - call broadcast(include_parallel_streaming) - call broadcast(include_mirror) - call broadcast(nonlinear) - call broadcast(adiabatic_option_switch) - call broadcast(const_alpha_geo) - call broadcast(suppress_zonal_interaction) - - end subroutine read_parameters - - subroutine finish_physics_flags - - implicit none - - initialized = .false. - - end subroutine finish_physics_flags - -end module physics_flags diff --git a/physics_parameters.f90 b/physics_parameters.f90 deleted file mode 100644 index 4db070c2a9..0000000000 --- a/physics_parameters.f90 +++ /dev/null @@ -1,93 +0,0 @@ -module physics_parameters - - implicit none - - public :: init_physics_parameters - public :: finish_physics_parameters - public :: beta, zeff, tite, nine, rhostar, vnew_ref - public :: g_exb, g_exbfac, omprimfac - - private - - real :: beta, zeff, tite, nine, rhostar, irhostar, vnew_ref - real :: g_exb, g_exbfac, omprimfac - logical :: initialized = .false. - -contains - - subroutine init_physics_parameters - - implicit none - - if (initialized) return - initialized = .true. - - call read_parameters - - end subroutine init_physics_parameters - - subroutine read_parameters - - use file_utils, only: input_unit_exist - use physics_flags, only: full_flux_surface - use mp, only: proc0, broadcast - - implicit none - - integer :: in_file - logical :: rpexist - - namelist /parameters/ beta, zeff, tite, nine, rhostar, vnew_ref, & - g_exb, g_exbfac, omprimfac, irhostar - - if (proc0) then - beta = 0.0 ! beta = 8 * pi * p_ref / B_ref^2 - ! vnew_ref is the reference collision frequency for stella, which - ! uses the mass, density and temperature of the reference species, - ! along with the proton charge in the expression - ! vnew_ref = (aref/vtref)*(4/3)sqrt(2pi)/(4pi*epsilon_0)**2 * nref * e**4 * loglam / sqrt(mref) / Tref**1.5 - ! note that all quantities are given in SI units and epsilon_0 is permittivity of vacuum - vnew_ref = -1.0 ! various input options will override this value if it is negative - rhostar = -1.0 ! = m_ref * vt_ref / (e * B_ref * a_ref), with refs in SI - irhostar = -1.0 - zeff = 1.0 - tite = 1.0 - nine = 1.0 - - g_exb = 0.0 - g_exbfac = 1.0 - omprimfac = 1.0 - - ! Read input file - in_file = input_unit_exist("parameters", rpexist) - if (rpexist) read (unit=in_file, nml=parameters) - - if (irhostar > 0) rhostar = 1./irhostar - - ! Don't allow people to set rhostar when its not full flux - ! Otherwise phase_shift_angle will be changed in kt_grids.f90 - if (.not. full_flux_surface) rhostar = 0 - - end if - - call broadcast(beta) - call broadcast(vnew_ref) - call broadcast(zeff) - call broadcast(rhostar) - call broadcast(tite) - call broadcast(nine) - call broadcast(g_exb) - call broadcast(g_exbfac) - call broadcast(omprimfac) - - end subroutine read_parameters - - subroutine finish_physics_parameters - - implicit none - - initialized = .false. - - end subroutine finish_physics_parameters - -end module physics_parameters diff --git a/response_matrix.fpp b/response_matrix.fpp index 22d6f5fed4..2d947815c6 100644 --- a/response_matrix.fpp +++ b/response_matrix.fpp @@ -5,6 +5,7 @@ module response_matrix #ifdef ISO_C_BINDING use, intrinsic :: iso_c_binding, only: c_intptr_t #endif + use debug_flags, only: debug => response_matrix_debug implicit none @@ -23,21 +24,19 @@ module response_matrix real, dimension(2) :: time_dgdphi real, dimension(2) :: time_QN real, dimension(2) :: time_lu - logical :: debug = .false. contains subroutine init_response_matrix use linear_solve, only: lu_decomposition - use fields_arrays, only: response_matrix - use stella_layouts, only: vmu_lo + use arrays_fields, only: response_matrix use stella_layouts, only: iv_idx, is_idx - use kt_grids, only: naky + use parameters_kxky_grids, only: naky use mp, only: proc0 - use run_parameters, only: mat_gen + use parameters_numerical, only: mat_gen #ifdef ISO_C_BINDING - use fields_arrays, only: response_window + use arrays_fields, only: response_window #endif implicit none @@ -102,9 +101,9 @@ contains subroutine setup_response_matrix_file_io use mp, only: proc0, job - use run_parameters, only: mat_gen + use parameters_numerical, only: mat_gen use system_fortran, only: systemf - use kt_grids, only: naky + use parameters_kxky_grids, only: naky implicit none @@ -132,9 +131,9 @@ contains use, intrinsic :: iso_c_binding, only: c_intptr_t use mp, only: sgproc0, real_size use mp, only: create_shared_memory_window - use fields_arrays, only: response_window + use arrays_fields, only: response_window use fields, only: nfields - use kt_grids, only: naky + use parameters_kxky_grids, only: naky use extended_zgrid, only: neigen, nsegments, nzed_segment use extended_zgrid, only: periodic @@ -174,12 +173,12 @@ contains use mp, only: proc0 use job_manage, only: time_message - use run_parameters, only: mat_gen - use fields_arrays, only: response_matrix - use kt_grids, only: naky + use parameters_numerical, only: mat_gen + use arrays_fields, only: response_matrix + use parameters_kxky_grids, only: naky use extended_zgrid, only: neigen #ifdef ISO_C_BINDING - use fields_arrays, only: response_window + use arrays_fields, only: response_window #endif implicit none @@ -260,8 +259,8 @@ contains subroutine calculate_vspace_integrated_response(iky) use mp, only: proc0 - use run_parameters, only: mat_gen - use physics_flags, only: include_apar, include_bpar + use parameters_numerical, only: mat_gen + use parameters_physics, only: include_apar, include_bpar use extended_zgrid, only: neigen, ikxmod use extended_zgrid, only: nsegments, nzed_segment use extended_zgrid, only: periodic @@ -357,7 +356,7 @@ contains use, intrinsic :: iso_c_binding, only: c_ptr, c_f_pointer use mp, only: nbytes_real #endif - use fields_arrays, only: response_matrix + use arrays_fields, only: response_matrix implicit none @@ -401,11 +400,11 @@ contains #ifdef ISO_C_BINDING use mp, only: sgproc0 #endif - use physics_flags, only: include_apar, include_bpar + use parameters_physics, only: include_apar, include_bpar use extended_zgrid, only: neigen use extended_zgrid, only: nsegments, nzed_segment use extended_zgrid, only: periodic - use fields_arrays, only: response_matrix + use arrays_fields, only: response_matrix implicit none @@ -542,9 +541,9 @@ contains use mp, only: sgproc0 #endif use mp, only: mp_abort - use fields_arrays, only: response_matrix - use run_parameters, only: lu_option_switch - use run_parameters, only: lu_option_none, lu_option_local, lu_option_global + use arrays_fields, only: response_matrix + use parameters_numerical, only: lu_option_switch + use parameters_numerical, only: lu_option_none, lu_option_local, lu_option_global use extended_zgrid, only: neigen use linear_solve, only: lu_decomposition @@ -585,9 +584,9 @@ contains subroutine read_response_matrix - use fields_arrays, only: response_matrix + use arrays_fields, only: response_matrix use common_types, only: response_matrix_type - use kt_grids, only: naky + use parameters_kxky_grids, only: naky use extended_zgrid, only: neigen use extended_zgrid, only: nsegments use extended_zgrid, only: nzed_segment @@ -687,13 +686,12 @@ contains subroutine get_dpdf_dphi_matrix_column(iky, ie, idx, nz_ext, nresponse, phi_ext, apar_ext, bpar_ext, pdf_ext) use stella_layouts, only: vmu_lo - use run_parameters, only: time_upwind_plus - use physics_flags, only: include_apar, include_bpar + use parameters_numerical, only: time_upwind_plus + use parameters_physics, only: include_apar, include_bpar use implicit_solve, only: get_gke_rhs, sweep_g_zext - use fields_arrays, only: response_matrix + use arrays_fields, only: response_matrix use extended_zgrid, only: periodic, phase_shift - use parallel_streaming, only: stream_sign - use physics_flags, only: full_flux_surface + use parameters_physics, only: full_flux_surface #ifdef ISO_C_BINDING use mp, only: sgproc0 #endif @@ -775,10 +773,10 @@ contains subroutine get_dpdf_dapar_matrix_column(iky, ie, idx, nz_ext, nresponse, phi_ext, apar_ext, bpar_ext, pdf_ext) use stella_layouts, only: vmu_lo - use run_parameters, only: time_upwind_plus - use physics_flags, only: include_apar, include_bpar + use parameters_numerical, only: time_upwind_plus + use parameters_physics, only: include_apar, include_bpar use implicit_solve, only: get_gke_rhs, sweep_g_zext - use fields_arrays, only: response_matrix + use arrays_fields, only: response_matrix use extended_zgrid, only: periodic #ifdef ISO_C_BINDING use mp, only: sgproc0 @@ -861,10 +859,10 @@ contains subroutine get_dpdf_dbpar_matrix_column(iky, ie, idx, nz_ext, nresponse, phi_ext, apar_ext, bpar_ext, pdf_ext) use stella_layouts, only: vmu_lo - use run_parameters, only: time_upwind_plus - use physics_flags, only: include_apar, include_bpar + use parameters_numerical, only: time_upwind_plus + use parameters_physics, only: include_apar, include_bpar use implicit_solve, only: get_gke_rhs, sweep_g_zext - use fields_arrays, only: response_matrix + use arrays_fields, only: response_matrix use extended_zgrid, only: periodic #ifdef ISO_C_BINDING use mp, only: sgproc0 @@ -946,7 +944,7 @@ contains subroutine integrate_over_velocity(g, phi, apar, bpar, iky, ie) use stella_layouts, only: vmu_lo - use physics_flags, only: include_apar, include_bpar + use parameters_physics, only: include_apar, include_bpar implicit none @@ -972,13 +970,10 @@ contains use mp, only: sum_allreduce use stella_layouts, only: iv_idx, imu_idx, is_idx - use run_parameters, only: driftkinetic_implicit + use parameters_numerical, only: driftkinetic_implicit use vpamu_grids, only: integrate_species_ffs_rm - use physics_flags, only: full_flux_surface - - use geometry, only: bmag - use kt_grids, only: nalpha + use parameters_physics, only: full_flux_surface use gyro_averages, only: j0_B_const @@ -1052,7 +1047,7 @@ contains use stella_layouts, only: vmu_lo, imu_idx use species, only: nspec, spec - use physics_parameters, only: beta + use parameters_physics, only: beta use extended_zgrid, only: iz_low, iz_up use extended_zgrid, only: ikxmod use extended_zgrid, only: nsegments @@ -1114,7 +1109,7 @@ contains subroutine integrate_over_velocity_apar(g, apar, iky, ie) use stella_layouts, only: vmu_lo, iv_idx - use physics_parameters, only: beta + use parameters_physics, only: beta use species, only: nspec, spec use extended_zgrid, only: iz_low, iz_up use extended_zgrid, only: ikxmod @@ -1178,7 +1173,7 @@ contains subroutine get_fields_for_response_matrix(phi, apar, bpar, iky, ie, dist) - use physics_flags, only: include_apar, include_bpar + use parameters_physics, only: include_apar, include_bpar implicit none @@ -1204,11 +1199,11 @@ contains use extended_zgrid, only: iz_low, iz_up use extended_zgrid, only: ikxmod use extended_zgrid, only: nsegments - use kt_grids, only: zonal_mode, akx - use fields_arrays, only: gamtot, gamtot3 + use grids_kxky, only: zonal_mode, akx + use arrays_fields, only: gamtot, gamtot3 use fields, only: gamtot_h, gamtot3_h - use physics_flags, only: adiabatic_option_switch - use physics_flags, only: adiabatic_option_fieldlineavg + use parameters_physics, only: adiabatic_option_switch + use parameters_physics, only: adiabatic_option_fieldlineavg implicit none @@ -1284,11 +1279,11 @@ contains use extended_zgrid, only: iz_low, iz_up use extended_zgrid, only: ikxmod use extended_zgrid, only: nsegments - use kt_grids, only: zonal_mode, akx - use fields_arrays, only: gamtotinv11, gamtotinv13, gamtotinv31, gamtotinv33 + use grids_kxky, only: zonal_mode, akx + use arrays_fields, only: gamtotinv11, gamtotinv13, gamtotinv31, gamtotinv33 use fields, only: gamtot_h - use physics_flags, only: adiabatic_option_switch - use physics_flags, only: adiabatic_option_fieldlineavg + use parameters_physics, only: adiabatic_option_switch + use parameters_physics, only: adiabatic_option_fieldlineavg use mp, only: mp_abort implicit none @@ -1376,9 +1371,9 @@ contains use extended_zgrid, only: iz_low, iz_up use extended_zgrid, only: ikxmod use extended_zgrid, only: nsegments - use kt_grids, only: zonal_mode, akx + use grids_kxky, only: zonal_mode, akx use fields, only: apar_denom - use dist_fn_arrays, only: kperp2 + use arrays_dist_fn, only: kperp2 implicit none @@ -1433,13 +1428,13 @@ contains subroutine finish_response_matrix - use fields_arrays, only: response_matrix + use arrays_fields, only: response_matrix #if !defined ISO_C_BINDING implicit none #else - use fields_arrays, only: response_window + use arrays_fields, only: response_window use mpi implicit none @@ -1469,7 +1464,7 @@ contains subroutine parallel_LU_decomposition_local(iky) use, intrinsic :: iso_c_binding, only: c_ptr, c_f_pointer - use fields_arrays, only: response_matrix + use arrays_fields, only: response_matrix use mp, only: barrier, broadcast, sum_allreduce use mp, only: mp_comm, scope, allprocs, sharedprocs, curr_focus use mp, only: scrossdomprocs, sgproc0, mp_abort, real_size @@ -1624,7 +1619,7 @@ contains !all cores. Ideal speed up: ncores subroutine parallel_LU_decomposition_global(iky) - use fields_arrays, only: response_matrix + use arrays_fields, only: response_matrix use mp, only: barrier, broadcast, sum_allreduce use mp, only: mp_comm, scope, allprocs, sharedprocs, curr_focus use mp, only: job, iproc, proc0, nproc, mpicmplx diff --git a/run_parameters.f90 b/run_parameters.f90 deleted file mode 100644 index 7e7c42439f..0000000000 --- a/run_parameters.f90 +++ /dev/null @@ -1,379 +0,0 @@ -!> This module is basically a store for the input parameters that are specified in the namelists \a knobs and \a parameters. In general, the names of the public variables in this module are the same as the name of the input parameter they correspond to. - -module run_parameters - - implicit none - - public :: init_run_parameters, finish_run_parameters - public :: fphi, fapar, fbpar - public :: nstep, tend, delt - public :: cfl_cushion_upper, cfl_cushion_middle, cfl_cushion_lower - public :: delt_max, delt_min - public :: avail_cpu_time, autostop - public :: stream_implicit, mirror_implicit - public :: drifts_implicit - public :: driftkinetic_implicit - public :: fully_explicit, fully_implicit - public :: ky_solve_radial, ky_solve_real - public :: maxwellian_inside_zed_derivative - public :: stream_matrix_inversion - public :: mirror_semi_lagrange, mirror_linear_interp - public :: zed_upwind, vpa_upwind, time_upwind - public :: fields_kxkyz, mat_gen, mat_read - public :: rng_seed - public :: use_deltaphi_for_response_matrix - public :: maxwellian_normalization - public :: time_upwind_plus, time_upwind_minus - public :: zed_upwind_plus, zed_upwind_minus - public :: print_extra_info_to_terminal - public :: nitt - - private - - real :: cfl_cushion_upper, cfl_cushion_middle, cfl_cushion_lower - real :: fphi, fapar, fbpar - real :: delt, tend, delt_max, delt_min - real :: vpa_upwind - real :: time_upwind, time_upwind_plus, time_upwind_minus - real :: zed_upwind, zed_upwind_plus, zed_upwind_minus - logical :: stream_implicit, mirror_implicit, drifts_implicit - logical :: driftkinetic_implicit - logical :: fully_explicit, fully_implicit - logical :: maxwellian_inside_zed_derivative - logical :: stream_matrix_inversion - logical :: mirror_semi_lagrange, mirror_linear_interp - logical :: fields_kxkyz, mat_gen, mat_read - logical :: ky_solve_real - logical :: use_deltaphi_for_response_matrix - logical :: maxwellian_normalization, autostop - real :: avail_cpu_time - integer :: nstep, ky_solve_radial - integer :: rng_seed - integer, public :: delt_option_switch, lu_option_switch - integer, public, parameter :: delt_option_hand = 1, delt_option_auto = 2 - integer, public, parameter :: lu_option_none = 1, & - lu_option_local = 2, & - lu_option_global = 3 - logical :: initialized = .false. - logical :: knexist - logical :: print_extra_info_to_terminal - integer :: nitt - -contains - - subroutine init_run_parameters - - implicit none - - if (initialized) return - initialized = .true. - - call read_parameters - - end subroutine init_run_parameters - - subroutine read_parameters - - use file_utils, only: input_unit, error_unit, input_unit_exist - use mp, only: mp_abort, proc0, broadcast - use text_options, only: text_option, get_option_value - use physics_flags, only: include_mirror, full_flux_surface, radial_variation - use physics_flags, only: nonlinear, include_apar, include_parallel_streaming - use physics_parameters, only: rhostar - !> For FFS - need to delete - use species, only: has_electron_species, spec - implicit none - - type(text_option), dimension(3), parameter :: deltopts = & - (/text_option('default', delt_option_auto), & - text_option('set_by_hand', delt_option_hand), & - text_option('check_restart', delt_option_auto)/) - type(text_option), dimension(4), parameter :: lu_opts = & - (/text_option('default', lu_option_local), & - text_option('none', lu_option_none), & - text_option('local', lu_option_local), & - text_option('global', lu_option_global)/) - - character(20) :: delt_option, lu_option - logical :: error = .false. - integer :: ierr, in_file - - namelist /knobs/ fphi, fapar, fbpar, delt, nstep, tend, & - delt_option, lu_option, autostop, & - avail_cpu_time, delt_max, delt_min, & - cfl_cushion_upper, cfl_cushion_middle, cfl_cushion_lower, & - stream_implicit, mirror_implicit, & - drifts_implicit, use_deltaphi_for_response_matrix, & - maxwellian_normalization, & - stream_matrix_inversion, maxwellian_inside_zed_derivative, & - mirror_semi_lagrange, mirror_linear_interp, & - zed_upwind, vpa_upwind, time_upwind, & - fields_kxkyz, mat_gen, mat_read, rng_seed, & - ky_solve_radial, ky_solve_real, nitt, print_extra_info_to_terminal - - if (proc0) then - - ! Default parameters in namelist - fphi = 1.0 - fapar = -1.0 ! fapar deprecated; keeping for now for backward compatibility - fbpar = -1.0 ! fbpar deprecated; keeping for now for backward compatibility - fields_kxkyz = .false. - stream_implicit = .true. - mirror_implicit = .true. - drifts_implicit = .false. - maxwellian_inside_zed_derivative = .false. - mirror_semi_lagrange = .true. - mirror_linear_interp = .false. - stream_matrix_inversion = .false. - use_deltaphi_for_response_matrix = .false. - maxwellian_normalization = .false. - delt_option = 'default' - zed_upwind = 0.02 - vpa_upwind = 0.02 - time_upwind = 0.02 - rng_seed = -1 !negative values use current time as seed - ky_solve_radial = 0 - ky_solve_real = .false. - mat_gen = .false. - mat_read = .false. - print_extra_info_to_terminal = .true. - nitt = 1 - - ! Stella runs until t*v_{th,i}/a=tend or until istep=nstep - tend = -1.0 - nstep = -1 - - ! Set the available wall time in seconds, 5 minutes before the wall, stella will make a clean exit - avail_cpu_time = 1.e10 - - ! Stop linear simulations when gamma is constant (careful since we won't catch jumpers!) - ! It will check gamma over time steps - autostop = .true. - - ! code_dt needs to stay within [cfl_dt*cfl_cushion_upper, cfl_dt*cfl_cushion_lower] - ! code_dt can be increased if cfl_dt increases, however, never increase above delt_max (=delt by default) - ! Exit stella if code_dt < delt_min (e.g. when the code blows up) - cfl_cushion_upper = 0.5 ! Stay a factor of 2 under the CFL condition, otherwise it might run out of control - cfl_cushion_middle = 0.25 ! If code_dt>cfl_dt/2 or code_dt or in the namelist.' - write (ierr, *) 'Aborting.' - write (*, *) '' - write (*, *) 'Please specify either or in the namelist.' - write (*, *) 'Aborting.' - error = .true. - end if - - ! Abort if cfl_cushion_lower>cfl_cushion_upper or if cfl_cushion_lower==cfl_cushion_upper - if ((cfl_cushion_lower > cfl_cushion_upper - 0.001) & - .or. (cfl_cushion_middle > cfl_cushion_upper - 0.001) & - .or. (cfl_cushion_middle < cfl_cushion_lower + 0.001)) then - ierr = error_unit() - write (ierr, *) '' - write (ierr, *) 'Please make sure that is bigger than ,' - write (ierr, *) 'and that lies in between and .' - write (ierr, *) 'Aborting.' - write (*, *) '' - write (*, *) 'Please make sure that is bigger than ,' - write (*, *) 'and that lies in between and .' - write (*, *) 'Aborting.' - error = .true. - end if - - if (fapar > -1.0 .or. fbpar > -1.0) then - write (*, *) '!!!WARNING!!!' - write (*, *) 'fapar and fbpar are deprecated:' - write (*, *) 'use include_apar and include_bpar instead in namelist physics_flags.' - if (fapar > epsilon(0.0)) then - write (*, *) 'to include apar, set include_apar = .true.' - end if - if (fbpar > epsilon(0.0)) then - write (*, *) 'to include bpar, set include_bpar = .true.' - end if - write (*, *) 'Aborting simulation.' - write (*, *) '!!!WARNING!!!' - error = .true. - end if - - ! semi-lagrange advance of mirror term is not supported for EM simulations - if (include_apar .and. mirror_semi_lagrange) then - write (*, *) '!!!WARNING!!!' - write (*, *) 'mirror_semi_lagrange = .true. is not supported for electromagnetic simulations.' - write (*, *) 'forcing mirror_semi_lagrange = .false.' - write (*, *) '!!!WARNING!!!' - mirror_semi_lagrange = .false. - end if - - if (drifts_implicit) then - if (.not. stream_implicit) then - write (*, *) '!!!WARNING!!!' - write (*, *) 'drifts_implicit = T requires stream_implicit = T.' - write (*, *) 'forcing drifts_implicit = F.' - write (*, *) '!!!WARNING!!!' - drifts_implicit = .false. - else if (.not. include_parallel_streaming) then - write (*, *) '!!!WARNING!!!' - write (*, *) 'drifts_implicit = T requires include_parallel_streaming = T.' - write (*, *) 'forcing drifts_implicit = F.' - write (*, *) '!!!WARNING!!!' - drifts_implicit = .false. - end if - - if (rhostar > epsilon(0.0)) then - write (*, *) '!!!WARNING!!!' - write (*, *) 'drifts_implicit = T, coupled with rhostar > 0, has been observed' - write (*, *) 'to lead to numerical instability. unless you know what you are doing,' - write (*, *) 'it is suggested that you set drifts_implicit = F or rhostar = 0.' - write (*, *) '!!!WARNING!!!' - end if - end if - - ! Notify the user that rng_seed is set - if ((rng_seed > 0) .and. print_extra_info_to_terminal) then - write (*, '(A)') "############################################################" - write (*, '(A)') " RUN PARAMETERS" - write (*, '(A)') "############################################################" - write (*,*) ' '; write (*,'(A12, I2)') 'rng_seed = ', rng_seed; write (*,*) ' '; - end if - - if (.not. full_flux_surface) then - nitt = 1 - end if - - !> print warning messages and override inconsistent or unsupported options for full_flux_surface = T - if (full_flux_surface) then - if (has_electron_species(spec)) call mp_abort('FFS not set up for kinetic electrons yet') - if (fields_kxkyz) then - write (*, *) - write (*, *) '!!!WARNING!!!' - write (*, *) 'The option fields_kxkyz=T is not currently supported for full_flux_surface=T.' - write (*, *) 'Forcing fields_kxkyz=F.' - write (*, *) '!!!WARNING!!!' - write (*, *) - fields_kxkyz = .false. - end if - if (mirror_semi_lagrange) then - write (*, *) - write (*, *) '!!!WARNING!!!' - write (*, *) 'The option mirror_semi_lagrange=T is not consistent with full_flux_surface=T.' - write (*, *) 'Forcing mirror_semi_lagrange=F.' - write (*, *) '!!!WARNING!!!' - mirror_semi_lagrange = .false. - end if - if (stream_implicit) then - driftkinetic_implicit = .true. - end if - if (maxwellian_normalization) then - write (*, *) - write (*, *) '!!!WARNING!!!' - write (*, *) 'The option maxwellian_normalisation=T is not consistent with full_flux_surface=T.' - write (*, *) 'Forcing maxwellian_normalisation=F.' - write (*, *) '!!!WARNING!!!' - maxwellian_normalization = .false. - end if - - else - driftkinetic_implicit = .false. - end if - end if - - ! Exit stella if we ran into an error - call broadcast(error) - if (error) call mp_abort('Aborting in run_parameters.f90') - - call broadcast(fields_kxkyz) - call broadcast(delt_option_switch) - call broadcast(delt) - call broadcast(lu_option_switch) - call broadcast(cfl_cushion_upper) - call broadcast(cfl_cushion_middle) - call broadcast(cfl_cushion_lower) - call broadcast(delt_max) - call broadcast(delt_min) - call broadcast(fphi) - call broadcast(stream_implicit) - call broadcast(mirror_implicit) - call broadcast(drifts_implicit) - call broadcast(driftkinetic_implicit) - call broadcast(maxwellian_inside_zed_derivative) - call broadcast(mirror_semi_lagrange) - call broadcast(mirror_linear_interp) - call broadcast(stream_matrix_inversion) - call broadcast(use_deltaphi_for_response_matrix) - call broadcast(maxwellian_normalization) - call broadcast(zed_upwind) - call broadcast(vpa_upwind) - call broadcast(time_upwind) - call broadcast(nstep) - call broadcast(tend) - call broadcast(avail_cpu_time) - call broadcast(autostop) - call broadcast(rng_seed) - call broadcast(ky_solve_radial) - call broadcast(ky_solve_real) - call broadcast(mat_gen) - call broadcast(mat_read) - call broadcast(print_extra_info_to_terminal) -!!GA: may remove from input - call broadcast(nitt) - ! include_apar broadcast in case it is reset according to specification of - ! (deprecated) fapar variable - ! call broadcast(include_apar) - - ! calculate some useful derived quantities that are used repeatedly across modules - time_upwind_plus = 0.5 * (1.0 + time_upwind) - time_upwind_minus = 0.5 * (1.0 - time_upwind) - zed_upwind_plus = 0.5 * (1.0 + zed_upwind) - zed_upwind_minus = 0.5 * (1.0 - zed_upwind) - - if (.not. include_mirror) mirror_implicit = .false. - if (.not. include_parallel_streaming) then - stream_implicit = .false. - driftkinetic_implicit = .false. - end if - - if (mirror_implicit .or. stream_implicit .or. drifts_implicit) then - fully_explicit = .false. - else - fully_explicit = .true. - end if - - if (mirror_implicit .and. stream_implicit .and. drifts_implicit .and. .not. nonlinear) then - fully_implicit = .true. - else - fully_implicit = .false. - end if - - end subroutine read_parameters - - subroutine finish_run_parameters - - implicit none - - initialized = .false. - - end subroutine finish_run_parameters - -end module run_parameters diff --git a/sfincs_interface.fpp b/sfincs_interface.fpp index 8f8f1d3c1c..b240a91538 100644 --- a/sfincs_interface.fpp +++ b/sfincs_interface.fpp @@ -812,7 +812,7 @@ contains use zgrid, only: nzgrid, nz2pi use export_f, only: h_sfincs => delta_f use globalVariables, only: Phi1Hat - use kt_grids, only: nalpha + use parameters_kxky_grids, only: nalpha implicit none @@ -987,7 +987,7 @@ contains use zgrid, only: nz2pi, zed use geometry, only: dzetadz use geometry, only: alpha - use kt_grids, only: nalpha + use parameters_kxky_grids, only: nalpha use globalVariables, only: iota implicit none @@ -1221,7 +1221,7 @@ contains subroutine get_field_on_extended_zed(field_stella, field_neoclassical) use zgrid, only: nzgrid, nz2pi, nperiod - use kt_grids, only: nalpha + use parameters_kxky_grids, only: nalpha implicit none diff --git a/sources.fpp b/sources.fpp index 7634910d8a..99375543b6 100644 --- a/sources.fpp +++ b/sources.fpp @@ -46,17 +46,18 @@ contains subroutine init_sources use mp, only: job, proc0 - use run_parameters, only: fphi - use run_parameters, only: ky_solve_radial, ky_solve_real - use kt_grids, only: naky, nakx, zonal_mode + use parameters_numerical, only: fphi + use parameters_numerical, only: ky_solve_radial, ky_solve_real + use parameters_kxky_grids, only: naky, nakx + use grids_kxky, only: zonal_mode use zgrid, only: nzgrid, ntubes use stella_layouts, only: vmu_lo - use dist_fn_arrays, only: g_krook, g_proj, g_symm - use fields_arrays, only: phi_proj, phi_proj_stage - use physics_flags, only: radial_variation + use arrays_dist_fn, only: g_krook, g_proj, g_symm + use arrays_fields, only: phi_proj, phi_proj_stage + use parameters_physics, only: radial_variation use species, only: spec, has_electron_species - use physics_flags, only: adiabatic_option_switch - use physics_flags, only: adiabatic_option_fieldlineavg + use parameters_physics, only: adiabatic_option_switch + use parameters_physics, only: adiabatic_option_fieldlineavg use file_utils, only: runtype_option_switch, runtype_multibox implicit none @@ -112,10 +113,10 @@ contains subroutine read_parameters use file_utils, only: input_unit_exist, error_unit - use physics_flags, only: radial_variation + use parameters_physics, only: radial_variation use mp, only: proc0, broadcast - use kt_grids, only: ikx_max, periodic_variation - use fields_arrays, only: tcorr_source_qn, exclude_boundary_regions_qn + use parameters_kxky_grids, only: ikx_max, periodic_variation + use arrays_fields, only: tcorr_source_qn, exclude_boundary_regions_qn use text_options, only: text_option, get_option_value implicit none @@ -184,7 +185,7 @@ contains subroutine init_source_timeaverage use stella_time, only: code_dt - use fields_arrays, only: tcorr_source_qn, exp_fac_qn + use arrays_fields, only: tcorr_source_qn, exp_fac_qn implicit none @@ -204,12 +205,12 @@ contains subroutine finish_sources - use dist_fn_arrays, only: g_krook, g_proj, g_symm - use fields_arrays, only: phi_proj, phi_proj_stage + use arrays_dist_fn, only: g_krook, g_proj, g_symm + use arrays_fields, only: phi_proj, phi_proj_stage #ifdef ISO_C_BINDING - use fields_arrays, only: qn_zf_window + use arrays_fields, only: qn_zf_window #else - use fields_arrays, only: phizf_solve, phi_ext + use arrays_fields, only: phizf_solve, phi_ext #endif implicit none @@ -240,10 +241,11 @@ contains use job_manage, only: time_message use zgrid, only: nzgrid, ntubes use constants, only: pi, zi - use kt_grids, only: akx, nakx, zonal_mode, boundary_size + use grids_kxky, only: akx, zonal_mode, boundary_size + use parameters_kxky_grids, only: nakx use stella_layouts, only: vmu_lo use stella_time, only: code_dt - use dist_fn_arrays, only: g_krook, g_symm + use arrays_dist_fn, only: g_krook, g_symm use stella_transforms, only: transform_kx2x_unpadded, transform_x2kx_unpadded implicit none @@ -345,9 +347,10 @@ contains use mp, only: proc0 use job_manage, only: time_message use constants, only: pi, zi - use dist_fn_arrays, only: g_krook, g_symm + use arrays_dist_fn, only: g_krook, g_symm use zgrid, only: nzgrid, ntubes - use kt_grids, only: akx, nakx, zonal_mode, boundary_size + use grids_kxky, only: akx, zonal_mode, boundary_size + use parameters_kxky_grids, only: nakx use stella_layouts, only: vmu_lo use stella_time, only: code_dt use stella_transforms, only: transform_kx2x_unpadded, transform_x2kx_unpadded @@ -436,7 +439,7 @@ contains use stella_layouts, only: imu_idx, is_idx, iv_idx use vpamu_grids, only: nvgrid, nvpa, nmu use dist_redistribute, only: kxkyz2vmu - use dist_fn_arrays, only: gvmu + use arrays_dist_fn, only: gvmu use zgrid, only: nzgrid implicit none @@ -471,14 +474,15 @@ contains use mp, only: sum_allreduce use species, only: spec - use physics_flags, only: radial_variation + use parameters_physics, only: radial_variation use vpamu_grids, only: integrate_species, mu, vpa, vperp2 use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac - use kt_grids, only: nakx, rho_d_clamped + use parameters_kxky_grids, only: nakx + use grids_kxky, only: rho_d_clamped use stella_layouts, only: vmu_lo, imu_idx, is_idx, iv_idx use geometry, only: bmag, dBdrho, dl_over_b, d_dl_over_b_drho use gyro_averages, only: gyro_average, aj0x, aj1x - use dist_fn_arrays, only: kperp2, dkperp2dr + use arrays_dist_fn, only: kperp2, dkperp2dr use zgrid, only: nzgrid, ntubes use stella_transforms, only: transform_kx2x_unpadded, transform_x2kx_unpadded @@ -562,10 +566,11 @@ contains use job_manage, only: time_message use zgrid, only: nzgrid, ntubes use constants, only: pi, zi - use kt_grids, only: zonal_mode, akx, nakx, boundary_size + use grids_kxky, only: zonal_mode, akx, boundary_size + use parameters_kxky_grids, only: nakx use stella_layouts, only: vmu_lo use stella_time, only: code_dt - use dist_fn_arrays, only: g_proj, g_symm + use arrays_dist_fn, only: g_proj, g_symm use stella_transforms, only: transform_kx2x_unpadded, transform_x2kx_unpadded implicit none @@ -684,7 +689,7 @@ contains #ifdef ISO_C_BINDING use, intrinsic :: iso_c_binding, only: c_ptr, c_f_pointer, c_intptr_t - use fields_arrays, only: qn_zf_window + use arrays_fields, only: qn_zf_window use mp, only: sgproc0, sharedsubprocs, comm_sgroup use mp, only: real_size, nbytes_real, create_shared_memory_window use mp_lu_decomposition, only: lu_decomposition_local, lu_inverse_local @@ -693,10 +698,11 @@ contains use geometry, only: dl_over_b, d_dl_over_b_drho use stella_transforms, only: transform_kx2x_unpadded, transform_x2kx_unpadded use zgrid, only: nzgrid, nztot - use kt_grids, only: nakx, rho_d_clamped, boundary_size + use parameters_kxky_grids, only: nakx + use grids_kxky, only: rho_d_clamped, boundary_size use linear_solve, only: lu_decomposition - use fields_arrays, only: phizf_solve, c_mat, theta, phi_ext - use fields_arrays, only: tcorr_source_qn, exclude_boundary_regions_qn, exp_fac_qn + use arrays_fields, only: phizf_solve, c_mat, theta, phi_ext + use arrays_fields, only: tcorr_source_qn, exclude_boundary_regions_qn, exp_fac_qn implicit none @@ -878,8 +884,8 @@ contains subroutine update_quasineutrality_source - use fields_arrays, only: phi_proj, phi_proj_stage - use fields_arrays, only: tcorr_source_qn, exp_fac_qn + use arrays_fields, only: phi_proj, phi_proj_stage + use arrays_fields, only: tcorr_source_qn, exp_fac_qn implicit none diff --git a/species.f90 b/species.f90 index ef403582eb..d049b6bbfb 100644 --- a/species.f90 +++ b/species.f90 @@ -49,13 +49,14 @@ module species subroutine init_species ! use mp, only: trin_flag - use mp, only: proc0, broadcast - use physics_parameters, only: vnew_ref, zeff - use physics_flags, only: include_pressure_variation - use physics_flags, only: adiabatic_option_switch, adiabatic_option_fieldlineavg + use mp, only: proc0, broadcast, mp_abort + use parameters_physics, only: vnew_ref, zeff + use parameters_physics, only: include_pressure_variation + use parameters_physics, only: adiabatic_option_switch, adiabatic_option_fieldlineavg use geometry_inputprofiles_interface, only: read_inputprof_spec use euterpe_interface, only: read_species_euterpe + use parameters_physics, only: full_flux_surface implicit none integer :: is, is2 @@ -128,6 +129,10 @@ subroutine init_species modified_adiabatic_electrons = adiabatic_electrons & .and. adiabatic_option_switch == adiabatic_option_fieldlineavg + if(has_electron_species(spec) .and. full_flux_surface) then + write (*,*) 'full_flux_surface is not set up for kinetic electrons yet' + call mp_abort('full_flux_surface is not set up for kinetic electrons yet') + end if ! if (trin_flag) call reinit_species (ntspec_trin, dens_trin, & ! temp_trin, fprim_trin, tprim_trin, nu_trin) end subroutine init_species @@ -137,7 +142,7 @@ subroutine read_species_knobs use mp, only: proc0, job, broadcast, mp_abort use file_utils, only: error_unit, input_unit_exist use file_utils, only: runtype_option_switch, runtype_multibox - use physics_flags, only: radial_variation + use parameters_physics, only: radial_variation use text_options, only: text_option, get_option_value implicit none diff --git a/stella.f90 b/stella.f90 index 242a448e11..a4934bf8bc 100644 --- a/stella.f90 +++ b/stella.f90 @@ -3,25 +3,24 @@ program stella use redistribute, only: scatter use job_manage, only: time_message, checkstop, job_fork use job_manage, only: checktime - use run_parameters, only: nstep, tend - use run_parameters, only: avail_cpu_time + use parameters_numerical, only: nstep, tend + use parameters_numerical, only: avail_cpu_time use stella_time, only: update_time, code_time, code_dt, checkcodedt use dist_redistribute, only: kxkyz2vmu use time_advance, only: advance_stella use diagnostics, only: diagnostics_stella use stella_save, only: stella_save_for_restart - use dist_fn_arrays, only: gnew, gvmu + use arrays_dist_fn, only: gnew, gvmu use file_utils, only: error_unit, flush_output_file use git_version, only: get_git_version, get_git_date use diagnostics_omega, only: checksaturation - + + use debug_flags, only: debug => stella_debug ! Input file use parameters_diagnostics, only: nsave implicit none - logical :: debug = .false. - logical :: stop_stella = .false. logical :: mpi_initialized = .false. @@ -89,18 +88,20 @@ subroutine init_stella(istep0, git_commit, git_date) use mp, only: init_mp, broadcast, sum_allreduce use mp, only: proc0, job + use debug_flags, only: read_debug_flags use file_utils, only: init_file_utils use file_utils, only: runtype_option_switch, runtype_multibox use file_utils, only: run_name, init_job_name use file_utils, only: flush_output_file, error_unit use job_manage, only: checktime, time_message - use physics_parameters, only: init_physics_parameters - use physics_flags, only: init_physics_flags, radial_variation - use run_parameters, only: init_run_parameters - use run_parameters, only: avail_cpu_time, nstep, rng_seed, delt, delt_max, delt_min - use run_parameters, only: stream_implicit, driftkinetic_implicit - use run_parameters, only: delt_option_switch, delt_option_auto - use run_parameters, only: mat_gen, mat_read + use parameters_physics, only: read_parameters_physics + use parameters_physics, only: radial_variation + use parameters_numerical, only: read_parameters_numerical + use parameters_numerical, only: avail_cpu_time, nstep, rng_seed, delt, delt_max, delt_min + use parameters_numerical, only: stream_implicit, driftkinetic_implicit + use parameters_numerical, only: delt_option_switch, delt_option_auto + use parameters_numerical, only: mat_gen, mat_read + use parameters_kxky_grids, only: read_kxky_grid_parameters use species, only: init_species, read_species_knobs use species, only: nspec use zgrid, only: init_zgrid @@ -116,14 +117,14 @@ subroutine init_stella(istep0, git_commit, git_date) use stella_time, only: init_tstart, init_delt use diagnostics, only: init_diagnostics use parameters_diagnostics, only: read_diagnostics_knobs - use fields_arrays, only: phi, apar, bpar - use dist_fn_arrays, only: gnew + use arrays_fields, only: phi, apar, bpar + use arrays_dist_fn, only: gnew use dist_fn, only: init_gxyz, init_dist_fn use dist_redistribute, only: init_redistribute use time_advance, only: init_time_advance use extended_zgrid, only: init_extended_zgrid - use kt_grids, only: init_kt_grids, read_kt_grids_parameters - use kt_grids, only: naky, nakx, ny, nx, nalpha + use grids_kxky, only: init_grids_kxky + use parameters_kxky_grids, only: naky, nakx, ny, nx, nalpha use vpamu_grids, only: init_vpamu_grids, read_vpamu_grids_parameters use vpamu_grids, only: nvgrid, nmu use stella_transforms, only: init_transforms @@ -154,7 +155,6 @@ subroutine init_stella(istep0, git_commit, git_date) !> initialize mpi message passing if (.not. mpi_initialized) call init_mp mpi_initialized = .true. - debug = debug .and. proc0 !> initialize timer if (debug) write (*, *) 'stella::init_stella::check_time' @@ -169,13 +169,14 @@ subroutine init_stella(istep0, git_commit, git_date) call init_file_utils(list) end if + call read_debug_flags +! if(stella_debug) debug = .true. + debug = debug .and. proc0 + call broadcast(list) call broadcast(runtype_option_switch) if (list) call job_fork - !proc0 may have changed - debug = debug .and. proc0 - if (proc0) then call time_message(.false., time_total, ' Total') call time_message(.false., time_init, ' Initialization') @@ -184,13 +185,12 @@ subroutine init_stella(istep0, git_commit, git_date) if (proc0) cbuff = trim(run_name) call broadcast(cbuff) if (.not. proc0) call init_job_name(cbuff) - - !> read the physics_flags namelist from the input file - if (debug) write (6, *) "stella::init_stella::init_physics_flags" - call init_physics_flags - !> read the physics_parameters namelist from the input file - if (debug) write (6, *) "stella::init_stella::init_physics_parameters" - call init_physics_parameters + + !> read the parameters_physics namelist from the input file + if (debug) write (6, *) "stella::init_stella::read_parameters_physics" + call read_parameters_physics + if (debug) write (6, *) "stella::init_stella::read_parameters_numerical" + call read_parameters_numerical !> read the zgrid_parameters namelist from the input file and setup the z grid if (debug) write (6, *) "stella::init_stella::init_zgrid" call init_zgrid @@ -200,8 +200,8 @@ subroutine init_stella(istep0, git_commit, git_date) !> read the grid option from the kt_grids_knobs namelist in the input file; !> depending on the grid option chosen, read the corresponding kt_grids_XXXX_parameters !> namelist from the input file and allocate some kx and ky arrays - if (debug) write (6, *) "stella::init_stella::read_kt_grids_parameters" - call read_kt_grids_parameters + if (debug) write (6, *) "stella::init_stella::read_kxky_grid_parameters" + call read_kxky_grid_parameters !> read the vpamu_grids_parameters namelist from the input file if (debug) write (6, *) "stella::init_stella::read_vpamu_grids_parameters" call read_vpamu_grids_parameters @@ -226,6 +226,8 @@ subroutine init_stella(istep0, git_commit, git_date) !> and use it to calculate all of the required geometric coefficients if (debug) write (6, *) "stella::init_stella::init_geometry" call init_geometry(nalpha, naky) + if (debug) write (6, *) 'stella::init_stella::init_grids_kxky' + call init_grids_kxky !> read species_parameters from input file and use the info to, e.g., !> determine if a modified Boltzmann response is to be used if (debug) write (6, *) 'stella::init_stella::init_species' @@ -237,7 +239,7 @@ subroutine init_stella(istep0, git_commit, git_date) !> read knobs namelist from the input file !> and the info to determine the mixture of implicit and explicit time advance if (debug) write (6, *) "stella::init_stella::init_run_parameters" - call init_run_parameters + call read_parameters_physics if (debug) write (6, *) "stella::init_stella::init_ranf" n = get_rnd_seed_length() @@ -255,8 +257,6 @@ subroutine init_stella(istep0, git_commit, git_date) if (debug) write (6, *) 'stella::init_stella::init_stella_layouts' call init_stella_layouts !> setup the (kx,ky) grids and (x,y) grids, if applicable - if (debug) write (6, *) 'stella::init_stella::init_kt_grids' - call init_kt_grids if (debug) write (6, *) 'stella::init_stella::init_multibox_subcalls' call init_multibox_subcalls !> finish_init_geometry deallocates various geometric arrays that @@ -380,9 +380,9 @@ subroutine init_multibox_subcalls use mp, only: proc0, job use species, only: communicate_species_multibox use geometry, only: communicate_geo_multibox - use kt_grids, only: communicate_ktgrids_multibox + use calculations_kxky, only: communicate_ktgrids_multibox use file_utils, only: runtype_option_switch, runtype_multibox - use physics_flags, only: radial_variation + use parameters_physics, only: radial_variation use multibox, only: init_multibox, rhoL, rhoR use multibox, only: communicate_multibox_parameters, multibox_communicate @@ -413,10 +413,10 @@ end subroutine init_multibox_subcalls subroutine check_transforms(needs_transforms) use file_utils, only: runtype_option_switch, runtype_multibox - use physics_flags, only: nonlinear, include_parallel_nonlinearity - use physics_flags, only: radial_variation, full_flux_surface - use physics_flags, only: hammett_flow_shear - use physics_parameters, only: g_exb, g_exbfac + use parameters_physics, only: nonlinear, include_parallel_nonlinearity + use parameters_physics, only: radial_variation, full_flux_surface + use parameters_physics, only: hammett_flow_shear + use parameters_physics, only: g_exb, g_exbfac ! Input file use parameters_diagnostics, only: write_radial_moments, write_radial_fluxes @@ -444,7 +444,7 @@ end subroutine check_transforms subroutine write_start_message(git_commit, git_date) use mp, only: proc0, nproc - use run_parameters, only: print_extra_info_to_terminal + use parameters_numerical, only: print_extra_info_to_terminal implicit none @@ -495,9 +495,8 @@ end subroutine write_start_message subroutine print_header use mp, only: proc0 - use run_parameters, only: print_extra_info_to_terminal - use physics_flags, only: include_apar - + use parameters_numerical, only: print_extra_info_to_terminal + use parameters_physics, only: include_apar implicit none ! Only print the header on the first processor @@ -563,9 +562,9 @@ subroutine finish_stella(last_call) use mp, only: proc0 use file_utils, only: finish_file_utils, runtype_option_switch, runtype_multibox use job_manage, only: time_message - use physics_parameters, only: finish_physics_parameters - use physics_flags, only: finish_physics_flags, include_parallel_nonlinearity, radial_variation - use run_parameters, only: finish_run_parameters + use parameters_physics, only: finish_read_parameters_physics + use parameters_physics, only: include_parallel_nonlinearity, radial_variation + use parameters_numerical, only: finish_read_parameters_numerical use zgrid, only: finish_zgrid use species, only: finish_species use time_advance, only: time_gke, time_parallel_nl @@ -584,13 +583,13 @@ subroutine finish_stella(last_call) use geometry, only: finish_geometry use extended_zgrid, only: finish_extended_zgrid use vpamu_grids, only: finish_vpamu_grids - use kt_grids, only: finish_kt_grids + use grids_kxky, only: finish_grids_kxky use volume_averages, only: finish_volume_averages use multibox, only: finish_multibox, time_multibox - use run_parameters, only: stream_implicit, drifts_implicit, fields_kxkyz + use parameters_numerical, only: stream_implicit, drifts_implicit, fields_kxkyz use implicit_solve, only: time_implicit_advance - use run_parameters, only: print_extra_info_to_terminal - use run_parameters, only: fields_kxkyz + use parameters_numerical, only: print_extra_info_to_terminal + use parameters_numerical, only: fields_kxkyz implicit none @@ -621,16 +620,14 @@ subroutine finish_stella(last_call) call finish_init_g if (debug) write (*, *) 'stella::finish_stella::finish_vpamu_grids' call finish_vpamu_grids - if (debug) write (*, *) 'stella::finish_stella::finish_kt_grids' - call finish_kt_grids - if (debug) write (*, *) 'stella::finish_stella::finish_run_parameters' - call finish_run_parameters + if (debug) write (*, *) 'stella::finish_stella::finish_grids_kxky' + call finish_grids_kxky + if (debug) write (*, *) 'stella::finish_stella::finish_read_parameters_numerical' + call finish_read_parameters_numerical if (debug) write (*, *) 'stella::finish_stella::finish_species' call finish_species - if (debug) write (*, *) 'stella::finish_stella::finish_physics_flags' - call finish_physics_flags - if (debug) write (*, *) 'stella::finish_stella::finish_physics_parameters' - call finish_physics_parameters + if (debug) write (*, *) 'stella::finish_stella::finish_parameters_physics' + call finish_read_parameters_physics if (debug) write (*, *) 'stella::finish_stella::finish_geometry' call finish_geometry if (debug) write (*, *) 'stella::finish_stella::finish_zgrid' diff --git a/stella_io.fpp b/stella_io.fpp index 928f94b5ed..26bd8377df 100644 --- a/stella_io.fpp +++ b/stella_io.fpp @@ -152,12 +152,13 @@ contains ! Ensure the netCDF file contains all the dimensions and grids, creating them if necessary subroutine write_grids(file_id) #ifdef NETCDF - use kt_grids, only: nakx, naky, akx, aky, nalpha, theta0, phase_shift_angle, x_d, rho_d + use parameters_kxky_grids, only: nakx, naky, nalpha, phase_shift_angle + use grids_kxky, only: x_d, rho_d, akx, aky, theta0 use zgrid, only: nzgrid, ntubes, zed use vpamu_grids, only: nvpa, vpa, nmu, mu use species, only: nspec - use physics_flags, only: radial_variation - use physics_parameters, only: rhostar + use parameters_physics, only: radial_variation + use parameters_physics, only: rhostar use geometry, only: geo_surf, dxdpsi, q_as_x use mp, only: nproc use neasyf, only: neasyf_dim, neasyf_write @@ -282,11 +283,11 @@ contains character(line_length), dimension(:), allocatable :: input_file_array integer :: n, unit, status, dim_id, previous_nlines - ! Don't attempt to write zero-sized arrays + ! Dont attempt to write zero-sized arrays if (num_input_lines <= 0) return ! If the existing input file in the output file was longer than - ! the current one, blank out the whole thing so that we're not + ! the current one, blank out the whole thing so that we are not ! left with "extra" bits at the end status = nf90_inq_dimid(file_id, "nlines", dim_id) if (status == NF90_NOERR) then @@ -1390,9 +1391,9 @@ contains use geometry, only: bmag, gradpar, gbdrift, gbdrift0 use geometry, only: cvdrift, cvdrift0, gds2, gds21, gds22, grho, jacob use geometry, only: drhodpsi, djacdrho, b_dot_grad_z, geo_surf - use physics_parameters, only: beta - use dist_fn_arrays, only: kperp2 - use kt_grids, only: jtwist + use parameters_physics, only: beta + use arrays_dist_fn, only: kperp2 + use parameters_kxky_grids, only: jtwist #endif implicit none diff --git a/stella_save.fpp b/stella_save.fpp index 51cdbb57c1..47fb18ae40 100644 --- a/stella_save.fpp +++ b/stella_save.fpp @@ -73,9 +73,9 @@ contains (g, istep0, t0, delt0, istatus, exit_in, fileopt) # ifdef NETCDF - use fields_arrays, only: shift_state, phi_proj - use dist_fn_arrays, only: g_krook, g_proj - use kt_grids, only: naky, nakx + use arrays_fields, only: shift_state, phi_proj + use arrays_dist_fn, only: g_krook, g_proj + use parameters_kxky_grids, only: naky, nakx # else use mp, only: proc0 # endif @@ -707,9 +707,9 @@ contains subroutine stella_restore_many(g, scale, istatus) # ifdef NETCDF - use fields_arrays, only: shift_state, phi_proj - use dist_fn_arrays, only: g_krook, g_proj - use kt_grids, only: naky, nakx + use arrays_fields, only: shift_state, phi_proj + use arrays_dist_fn, only: g_krook, g_proj + use parameters_kxky_grids, only: naky, nakx # endif # ifdef NETCDF_PARALLEL use zgrid, only: nztot diff --git a/stella_transforms.f90 b/stella_transforms.f90 index a63ee3fd68..93fbb2beca 100644 --- a/stella_transforms.f90 +++ b/stella_transforms.f90 @@ -55,7 +55,7 @@ module stella_transforms subroutine init_transforms - use physics_flags, only: full_flux_surface + use parameters_physics, only: full_flux_surface use stella_layouts, only: init_stella_layouts implicit none @@ -570,7 +570,7 @@ end subroutine transform_alpha2kalpha subroutine finish_transforms - use physics_flags, only: full_flux_surface + use parameters_physics, only: full_flux_surface implicit none diff --git a/time_advance.f90 b/time_advance.f90 index d26c48f6e7..037787962e 100644 --- a/time_advance.f90 +++ b/time_advance.f90 @@ -1,6 +1,8 @@ module time_advance + use debug_flags, only: debug => time_advance_debug + public :: init_time_advance, finish_time_advance public :: advance_stella public :: time_gke, time_parallel_nl @@ -34,21 +36,6 @@ module time_advance logical :: radialinit = .false. logical :: driftimpinit = .false. - ! if .true., dist fn is represented on alpha grid - ! if .false., dist fn is given on k-alpha grid - ! default is .false.; will only ever be set to - ! .true. during full_flux_surface simulations -! logical :: alpha_space = .false. - - integer :: explicit_option_switch - integer, parameter :: explicit_option_rk3 = 1, & - explicit_option_rk2 = 2, & - explicit_option_rk4 = 3, & - explicit_option_euler = 4 - - real :: xdriftknob, ydriftknob, wstarknob - logical :: flip_flop - ! factor multiplying parallel nonlinearity real, dimension(:, :), allocatable :: par_nl_fac, d_par_nl_fac_dr ! factor multiplying higher order linear term in parallel acceleration @@ -59,16 +46,13 @@ module time_advance ! needed for timing various pieces of gke solve real, dimension(2, 10) :: time_gke = 0. real, dimension(2, 2) :: time_parallel_nl = 0. - - logical :: debug = .false. - contains subroutine init_time_advance use mp, only: proc0 - use physics_flags, only: radial_variation - use physics_flags, only: include_parallel_nonlinearity + use parameters_physics, only: radial_variation + use parameters_physics, only: include_parallel_nonlinearity use neoclassical_terms, only: init_neoclassical_terms use dissipation, only: init_collisions, include_collisions use parallel_streaming, only: init_parallel_streaming @@ -86,8 +70,6 @@ subroutine init_time_advance !> read time_advance_knobs namelist from the input file; !> sets the explicit time advance option, as well as allows for scaling of !> the x and y components of the magnetic drifts and of the drive term - if (debug) write (6, *) 'time_advance::init_time_advance::read_parameters' - call read_parameters !> allocate distribution function sized arrays needed, e.g., for Runge-Kutta time advance if (debug) write (6, *) 'time_advance::init_time_advance::allocate_arrays' call allocate_arrays @@ -131,70 +113,18 @@ subroutine init_time_advance end subroutine init_time_advance - subroutine read_parameters - - use file_utils, only: error_unit, input_unit_exist - use text_options, only: text_option, get_option_value - use mp, only: proc0, broadcast - use run_parameters, only: fully_explicit - - implicit none - - logical :: taexist - - type(text_option), dimension(5), parameter :: explicitopts = & - (/text_option('default', explicit_option_rk3), & - text_option('rk3', explicit_option_rk3), & - text_option('rk2', explicit_option_rk2), & - text_option('rk4', explicit_option_rk4), & - text_option('euler', explicit_option_euler)/) - character(10) :: explicit_option - - namelist /time_advance_knobs/ xdriftknob, ydriftknob, wstarknob, explicit_option, flip_flop - - integer :: ierr, in_file - - if (readinit) return - readinit = .true. - - if (proc0) then - explicit_option = 'default' - xdriftknob = 1.0 - ydriftknob = 1.0 - wstarknob = 1.0 - flip_flop = .false. - - in_file = input_unit_exist("time_advance_knobs", taexist) - if (taexist) read (unit=in_file, nml=time_advance_knobs) - - ierr = error_unit() - call get_option_value & - (explicit_option, explicitopts, explicit_option_switch, & - ierr, "explicit_option in time_advance_knobs") - end if - - call broadcast(explicit_option_switch) - call broadcast(xdriftknob) - call broadcast(ydriftknob) - call broadcast(wstarknob) - call broadcast(flip_flop) - - if (fully_explicit) flip_flop = .false. - - end subroutine read_parameters - subroutine init_wdrift use mp, only: mp_abort - use dist_fn_arrays, only: wdriftx_g, wdrifty_g - use dist_fn_arrays, only: wdriftx_phi, wdrifty_phi - use dist_fn_arrays, only: wdriftx_bpar, wdrifty_bpar + use arrays_dist_fn, only: wdriftx_g, wdrifty_g + use arrays_dist_fn, only: wdriftx_phi, wdrifty_phi + use arrays_dist_fn, only: wdriftx_bpar, wdrifty_bpar use stella_layouts, only: vmu_lo use stella_layouts, only: iv_idx, imu_idx, is_idx use stella_time, only: code_dt use species, only: spec use zgrid, only: nzgrid - use kt_grids, only: nalpha + use parameters_kxky_grids, only: nalpha use geometry, only: cvdrift, gbdrift use geometry, only: cvdrift0, gbdrift0 use geometry, only: gds23, gds24 @@ -205,8 +135,9 @@ subroutine init_wdrift use neoclassical_terms, only: include_neoclassical_terms use neoclassical_terms, only: dphineo_dzed, dphineo_drho, dphineo_dalpha use neoclassical_terms, only: dfneo_dvpa, dfneo_dzed, dfneo_dalpha - use run_parameters, only: maxwellian_normalization + use parameters_numerical, only: maxwellian_normalization + use parameters_physics, only: xdriftknob, ydriftknob implicit none integer :: ivmu, iv, imu, is @@ -350,15 +281,16 @@ subroutine init_wstar use stella_time, only: code_dt use species, only: spec use zgrid, only: nzgrid - use kt_grids, only: nalpha + use parameters_kxky_grids, only: nalpha use geometry, only: dydalpha, drhodpsi, clebsch_factor use vpamu_grids, only: vperp2, vpa use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac - use dist_fn_arrays, only: wstar + use arrays_dist_fn, only: wstar use neoclassical_terms, only: include_neoclassical_terms use neoclassical_terms, only: dfneo_drho - use run_parameters, only: maxwellian_normalization + use parameters_numerical, only: maxwellian_normalization + use parameters_physics, only: wstarknob implicit none integer :: is, imu, iv, ivmu @@ -416,7 +348,7 @@ end subroutine init_wstar subroutine init_parallel_nonlinearity - use physics_parameters, only: rhostar + use parameters_physics, only: rhostar use species, only: spec, nspec use zgrid, only: nztot, nzgrid use geometry, only: geo_surf, drhodpsi, q_as_x @@ -424,8 +356,9 @@ subroutine init_parallel_nonlinearity use geometry, only: cvdrift, cvdrift0 use geometry, only: dIdrho, dgradpardrho, dBdrho, d2Bdrdth use geometry, only: dcvdriftdrho, dcvdrift0drho - use physics_flags, only: radial_variation + use parameters_physics, only: radial_variation + use parameters_physics, only: ydriftknob implicit none if (.not. allocated(par_nl_fac)) allocate (par_nl_fac(-nzgrid:nzgrid, nspec)) @@ -483,17 +416,20 @@ subroutine init_radial_variation use stella_time, only: code_dt use species, only: spec, pfac use zgrid, only: nzgrid - use kt_grids, only: nalpha + use parameters_kxky_grids, only: nalpha use geometry, only: drhodpsi, dydalpha, gfac use geometry, only: dBdrho, geo_surf, q_as_x use geometry, only: dcvdriftdrho, dcvdrift0drho use geometry, only: dgbdriftdrho, dgbdrift0drho use vpamu_grids, only: vperp2, vpa, mu use vpamu_grids, only: maxwell_vpa, maxwell_mu, maxwell_fac - use dist_fn_arrays, only: wstarp - use dist_fn_arrays, only: wdriftx_phi, wdrifty_phi - use dist_fn_arrays, only: wdriftpx_g, wdriftpy_g - use dist_fn_arrays, only: wdriftpx_phi, wdriftpy_phi!, adiabatic_phi + use arrays_dist_fn, only: wstarp + use arrays_dist_fn, only: wdriftx_phi, wdrifty_phi + use arrays_dist_fn, only: wdriftpx_g, wdriftpy_g + use arrays_dist_fn, only: wdriftpx_phi, wdriftpy_phi!, adiabatic_phi + + use parameters_physics, only: xdriftknob, ydriftknob, wstarknob + ! use neoclassical_terms, only: include_neoclassical_terms implicit none @@ -609,8 +545,10 @@ subroutine allocate_arrays use stella_layouts, only: vmu_lo use zgrid, only: nzgrid, ntubes - use kt_grids, only: naky, nakx - use dist_fn_arrays, only: g0, g1, g2, g3 + use parameters_kxky_grids, only: naky, nakx + use arrays_dist_fn, only: g0, g1, g2, g3 + use parameters_numerical, only: explicit_option_switch, explicit_option_rk3, & + explicit_option_rk2, explicit_option_rk4, explicit_option_euler implicit none @@ -636,14 +574,15 @@ subroutine init_cfl use mp, only: proc0, nproc, max_allreduce, min_allreduce use mp, only: scope, allprocs, subprocs - use dist_fn_arrays, only: wdriftx_g, wdrifty_g + use arrays_dist_fn, only: wdriftx_g, wdrifty_g use stella_time, only: code_dt, write_dt, cfl_dt_linear - use run_parameters, only: cfl_cushion_upper, cfl_cushion_middle, cfl_cushion_lower - use physics_flags, only: radial_variation, prp_shear_enabled + use parameters_numerical, only: cfl_cushion_upper, cfl_cushion_middle, cfl_cushion_lower + use parameters_physics, only: radial_variation, prp_shear_enabled use zgrid, only: delzed use vpamu_grids, only: dvpa - use kt_grids, only: akx, aky, nx, rho - use run_parameters, only: stream_implicit, mirror_implicit, drifts_implicit + use grids_kxky, only: akx, aky, rho + use parameters_kxky_grids, only: nx + use parameters_numerical, only: stream_implicit, mirror_implicit, drifts_implicit use parallel_streaming, only: stream use parallel_streaming, only: stream_rad_var1, stream_rad_var2 use mirror_terms, only: mirror @@ -651,7 +590,7 @@ subroutine init_cfl use file_utils, only: runtype_option_switch, runtype_multibox use dissipation, only: include_collisions, collisions_implicit use dissipation, only: cfl_dt_vpadiff, cfl_dt_mudiff - use run_parameters, only: print_extra_info_to_terminal + use parameters_numerical, only: print_extra_info_to_terminal implicit none @@ -778,14 +717,14 @@ subroutine reset_dt use parallel_streaming, only: parallel_streaming_initialized use parallel_streaming, only: init_parallel_streaming use dissipation, only: init_collisions, collisions_initialized, include_collisions - use run_parameters, only: stream_implicit, driftkinetic_implicit + use parameters_numerical, only: stream_implicit, driftkinetic_implicit use response_matrix, only: response_matrix_initialized use response_matrix, only: init_response_matrix use mirror_terms, only: mirror_initialized use mirror_terms, only: init_mirror use flow_shear, only: flow_shear_initialized use flow_shear, only: init_flow_shear - use physics_flags, only: radial_variation + use parameters_physics, only: radial_variation use sources, only: init_source_timeaverage use sources, only: init_quasineutrality_source, qn_source_initialized @@ -837,11 +776,11 @@ end subroutine reset_dt subroutine advance_stella(istep, stop_stella) - use dist_fn_arrays, only: gold, gnew - use fields_arrays, only: phi, apar, bpar - use fields_arrays, only: phi_old, apar_old + use arrays_dist_fn, only: gold, gnew + use arrays_fields, only: phi, apar, bpar + use arrays_fields, only: phi_old, apar_old use fields, only: advance_fields, fields_updated - use run_parameters, only: fully_explicit, fully_implicit + use parameters_numerical, only: fully_explicit, fully_implicit use multibox, only: RK_step use sources, only: include_qn_source, update_quasineutrality_source use sources, only: source_option_switch, source_option_projection @@ -849,6 +788,7 @@ subroutine advance_stella(istep, stop_stella) use sources, only: update_tcorr_krook, project_out_zero use mp, only: proc0, broadcast + use parameters_numerical, only: flip_flop implicit none integer, intent(in) :: istep @@ -965,14 +905,18 @@ subroutine advance_explicit(g, restart_time_step, istep) use job_manage, only: time_message use zgrid, only: nzgrid use extended_zgrid, only: periodic, phase_shift - use kt_grids, only: naky + use parameters_kxky_grids, only: naky use stella_layouts, only: vmu_lo, iv_idx - use physics_flags, only: include_apar + use parameters_physics, only: include_apar use parallel_streaming, only: stream_sign - use fields_arrays, only: phi, apar, bpar + use arrays_fields, only: phi, apar, bpar use fields, only: advance_fields use g_tofrom_h, only: gbar_to_g + use parameters_numerical, only: explicit_option_switch, explicit_option_rk3, & + explicit_option_rk2, explicit_option_rk4, explicit_option_euler + + implicit none complex, dimension(:, :, -nzgrid:, :, vmu_lo%llim_proc:), intent(in out) :: g @@ -1037,7 +981,7 @@ end subroutine advance_explicit !> advance_explicit_euler uses forward Euler to advance one time step subroutine advance_explicit_euler(g, restart_time_step, istep) - use dist_fn_arrays, only: g0 + use arrays_dist_fn, only: g0 use zgrid, only: nzgrid use stella_layouts, only: vmu_lo use multibox, only: RK_step @@ -1062,7 +1006,7 @@ end subroutine advance_explicit_euler !> advance_expliciit_rk2 uses strong stability-preserving RK2 to advance one time step subroutine advance_explicit_rk2(g, restart_time_step, istep) - use dist_fn_arrays, only: g0, g1 + use arrays_dist_fn, only: g0, g1 use zgrid, only: nzgrid use stella_layouts, only: vmu_lo use multibox, only: RK_step @@ -1109,7 +1053,7 @@ end subroutine advance_explicit_rk2 !> strong stability-preserving RK3 subroutine advance_explicit_rk3(g, restart_time_step, istep) - use dist_fn_arrays, only: g0, g1, g2 + use arrays_dist_fn, only: g0, g1, g2 use zgrid, only: nzgrid use stella_layouts, only: vmu_lo use multibox, only: RK_step @@ -1160,7 +1104,7 @@ end subroutine advance_explicit_rk3 !> standard RK4 subroutine advance_explicit_rk4(g, restart_time_step, istep) - use dist_fn_arrays, only: g0, g1, g2, g3 + use arrays_dist_fn, only: g0, g1, g2, g3 use zgrid, only: nzgrid use stella_layouts, only: vmu_lo use multibox, only: RK_step @@ -1225,21 +1169,21 @@ end subroutine advance_explicit_rk4 subroutine solve_gke(pdf, rhs_ky, restart_time_step, istep) use job_manage, only: time_message - use fields_arrays, only: phi, apar, bpar + use arrays_fields, only: phi, apar, bpar use stella_layouts, only: vmu_lo use stella_transforms, only: transform_y2ky use redistribute, only: gather, scatter - use physics_flags, only: include_parallel_nonlinearity - use physics_flags, only: include_parallel_streaming - use physics_flags, only: include_mirror, include_apar - use physics_flags, only: nonlinear, include_bpar - use physics_flags, only: full_flux_surface, radial_variation - use physics_parameters, only: g_exb + use parameters_physics, only: include_parallel_nonlinearity + use parameters_physics, only: include_parallel_streaming + use parameters_physics, only: include_mirror, include_apar + use parameters_physics, only: nonlinear, include_bpar + use parameters_physics, only: full_flux_surface, radial_variation + use parameters_physics, only: g_exb use zgrid, only: nzgrid, ntubes - use kt_grids, only: ikx_max, ny, naky_all - use kt_grids, only: swap_kxky_back - use kt_grids, only: zonal_mode, akx - use run_parameters, only: stream_implicit, mirror_implicit, drifts_implicit + use parameters_kxky_grids, only: ikx_max, ny, naky_all + use calculations_kxky, only: swap_kxky_back + use grids_kxky, only: zonal_mode, akx + use parameters_numerical, only: stream_implicit, mirror_implicit, drifts_implicit use dissipation, only: include_collisions, advance_collisions_explicit, collisions_implicit use sources, only: source_option_switch, source_option_krook use sources, only: add_krook_operator @@ -1248,7 +1192,7 @@ subroutine solve_gke(pdf, rhs_ky, restart_time_step, istep) use mirror_terms, only: advance_mirror_explicit use flow_shear, only: advance_parallel_flow_shear use multibox, only: include_multibox_krook, add_multibox_krook - use dist_fn_arrays, only: g_scratch + use arrays_dist_fn, only: g_scratch use gyro_averages, only: gyro_average, j0_ffs use g_tofrom_h, only: gbar_to_g use dissipation, only: hyper_dissipation @@ -1407,7 +1351,7 @@ subroutine advance_hyper_explicit(gin, gout) use stella_layouts, only: vmu_lo use zgrid, only: nzgrid, ntubes - use kt_grids, only: naky, nakx + use parameters_kxky_grids, only: naky, nakx use hyper, only: advance_hyper_vpa, advance_hyper_zed use hyper, only: hyp_zed, hyp_vpa @@ -1539,14 +1483,14 @@ subroutine advance_wstar_explicit(phi, gout) use mp, only: proc0, mp_abort use job_manage, only: time_message use fields, only: get_dchidy - use fields_arrays, only: apar, bpar + use arrays_fields, only: apar, bpar use stella_layouts, only: vmu_lo use stella_transforms, only: transform_ky2y use zgrid, only: nzgrid, ntubes - use kt_grids, only: naky, naky_all, nakx, ikx_max, ny - use kt_grids, only: swap_kxky - use physics_flags, only: full_flux_surface - use dist_fn_arrays, only: wstar, g_scratch + use parameters_kxky_grids, only: naky, naky_all, nakx, ikx_max, ny + use calculations_kxky, only: swap_kxky + use parameters_physics, only: full_flux_surface + use arrays_dist_fn, only: wstar, g_scratch use gyro_averages, only: gyro_average implicit none @@ -1611,12 +1555,12 @@ subroutine advance_wdrifty_explicit(g, phi, bpar, gout) use job_manage, only: time_message use stella_transforms, only: transform_ky2y use zgrid, only: nzgrid, ntubes - use kt_grids, only: nakx, ikx_max, naky, naky_all, ny - use kt_grids, only: swap_kxky - use physics_flags, only: full_flux_surface, include_bpar + use parameters_kxky_grids, only: nakx, ikx_max, naky, naky_all, ny + use calculations_kxky, only: swap_kxky + use parameters_physics, only: full_flux_surface, include_bpar use gyro_averages, only: gyro_average, gyro_average_j1 - use dist_fn_arrays, only: wdrifty_g, wdrifty_phi, wdrifty_bpar - use dist_fn_arrays, only: g_scratch + use arrays_dist_fn, only: wdrifty_g, wdrifty_phi, wdrifty_bpar + use arrays_dist_fn, only: g_scratch implicit none @@ -1717,12 +1661,13 @@ subroutine advance_wdriftx_explicit(g, phi, bpar, gout) use job_manage, only: time_message use stella_transforms, only: transform_ky2y use zgrid, only: nzgrid, ntubes - use kt_grids, only: nakx, ikx_max, naky, naky_all, ny, akx - use kt_grids, only: swap_kxky - use physics_flags, only: full_flux_surface, include_bpar + use parameters_kxky_grids, only: nakx, ikx_max, naky, naky_all, ny + use grids_kxky, only: akx + use calculations_kxky, only: swap_kxky + use parameters_physics, only: full_flux_surface, include_bpar use gyro_averages, only: gyro_average - use dist_fn_arrays, only: wdriftx_g, wdriftx_phi, wdriftx_bpar - use dist_fn_arrays, only: g_scratch + use arrays_dist_fn, only: wdriftx_g, wdriftx_phi, wdriftx_bpar + use arrays_dist_fn, only: g_scratch implicit none @@ -1820,26 +1765,27 @@ subroutine advance_ExB_nonlinearity(g, gout, restart_time_step, istep) use job_manage, only: time_message use gyro_averages, only: gyro_average use fields, only: get_dchidx, get_dchidy - use fields_arrays, only: phi, apar, bpar, shift_state - use fields_arrays, only: phi_corr_QN, phi_corr_GA -! use fields_arrays, only: apar_corr_QN, apar_corr_GA + use arrays_fields, only: phi, apar, bpar, shift_state + use arrays_fields, only: phi_corr_QN, phi_corr_GA +! use arrays_fields, only: apar_corr_QN, apar_corr_GA use stella_transforms, only: transform_y2ky, transform_x2kx use stella_transforms, only: transform_y2ky_xfirst, transform_x2kx_xfirst use stella_time, only: cfl_dt_ExB, cfl_dt_linear, code_dt, code_dt_max - use run_parameters, only: cfl_cushion_upper, cfl_cushion_middle, cfl_cushion_lower, fphi - use physics_parameters, only: g_exb, g_exbfac + use parameters_numerical, only: cfl_cushion_upper, cfl_cushion_middle, cfl_cushion_lower, fphi + use parameters_physics, only: g_exb, g_exbfac use zgrid, only: nzgrid, ntubes use geometry, only: exb_nonlin_fac, exb_nonlin_fac_p, gfac - use kt_grids, only: nakx, ikx_max, naky, naky_all, nx, ny - use kt_grids, only: akx, aky, rho_clamped - use physics_flags, only: full_flux_surface, radial_variation - use physics_flags, only: prp_shear_enabled, hammett_flow_shear - use physics_flags, only: include_apar, include_bpar - use kt_grids, only: x, swap_kxky, swap_kxky_back + use parameters_kxky_grids, only: nakx, ikx_max, naky, naky_all, nx, ny + use grids_kxky, only: akx, aky, rho_clamped + use parameters_physics, only: full_flux_surface, radial_variation + use parameters_physics, only: prp_shear_enabled, hammett_flow_shear + use parameters_physics, only: include_apar, include_bpar + use grids_kxky, only: x + use calculations_kxky, only: swap_kxky, swap_kxky_back use constants, only: pi, zi use file_utils, only: runtype_option_switch, runtype_multibox - use physics_flags, only: suppress_zonal_interaction - use dist_fn_arrays, only: g_scratch + use parameters_physics, only: suppress_zonal_interaction + use arrays_dist_fn, only: g_scratch use g_tofrom_h, only: g_to_h implicit none @@ -2110,18 +2056,19 @@ subroutine advance_parallel_nonlinearity(g, gout, restart_time_step) use finite_differences, only: second_order_centered_zed use finite_differences, only: third_order_upwind use redistribute, only: gather, scatter - use fields_arrays, only: phi, phi_corr_QN, phi_corr_GA + use arrays_fields, only: phi, phi_corr_QN, phi_corr_GA use stella_transforms, only: transform_ky2y, transform_y2ky use stella_transforms, only: transform_kx2x, transform_x2kx use stella_time, only: cfl_dt_parallel, cfl_dt_linear, code_dt, code_dt_max - use run_parameters, only: cfl_cushion_upper, cfl_cushion_middle, cfl_cushion_lower + use parameters_numerical, only: cfl_cushion_upper, cfl_cushion_middle, cfl_cushion_lower use zgrid, only: nzgrid, delzed, ntubes use extended_zgrid, only: neigen, nsegments, ikxmod use extended_zgrid, only: iz_low, iz_up use extended_zgrid, only: periodic - use physics_flags, only: full_flux_surface, radial_variation - use kt_grids, only: akx, aky, nakx, naky, nx, ny, ikx_max - use kt_grids, only: swap_kxky, swap_kxky_back, rho_clamped + use parameters_physics, only: full_flux_surface, radial_variation + use grids_kxky, only: akx, aky, rho_clamped + use parameters_kxky_grids, only: nakx, naky, nx, ny, ikx_max + use calculations_kxky, only: swap_kxky, swap_kxky_back use vpamu_grids, only: nvpa, nmu use vpamu_grids, only: dvpa, vpa, mu use gyro_averages, only: gyro_average @@ -2394,22 +2341,23 @@ subroutine advance_radial_variation(g, gout) use mp, only: mp_abort, proc0 use job_manage, only: time_message use fields, only: get_dchidy - use fields_arrays, only: phi, apar, bpar - use fields_arrays, only: phi_corr_QN, phi_corr_GA -! use fields_arrays, only: apar_corr_QN, apar_corr_GA + use arrays_fields, only: phi, apar, bpar + use arrays_fields, only: phi_corr_QN, phi_corr_GA +! use arrays_fields, only: apar_corr_QN, apar_corr_GA use stella_layouts, only: vmu_lo use stella_layouts, only: iv_idx, imu_idx, is_idx use stella_transforms, only: transform_kx2x_xfirst, transform_x2kx_xfirst use zgrid, only: nzgrid, ntubes - use kt_grids, only: nakx, naky, multiply_by_rho + use parameters_kxky_grids, only: nakx, naky + use calculations_kxky, only: multiply_by_rho use gyro_averages, only: gyro_average, gyro_average_j1 - use run_parameters, only: fphi - use physics_flags, only: full_flux_surface - use physics_flags, only: include_parallel_streaming, include_mirror - use dist_fn_arrays, only: wdriftx_phi, wdrifty_phi - use dist_fn_arrays, only: wdriftpx_g, wdriftpy_g - use dist_fn_arrays, only: wdriftpx_phi, wdriftpy_phi !, adiabatic_phi - use dist_fn_arrays, only: wstar, wstarp + use parameters_numerical, only: fphi + use parameters_physics, only: full_flux_surface + use parameters_physics, only: include_parallel_streaming, include_mirror + use arrays_dist_fn, only: wdriftx_phi, wdrifty_phi + use arrays_dist_fn, only: wdriftpx_g, wdriftpy_g + use arrays_dist_fn, only: wdriftpx_phi, wdriftpy_phi !, adiabatic_phi + use arrays_dist_fn, only: wstar, wstarp use mirror_terms, only: add_mirror_radial_variation use flow_shear, only: prl_shear, prl_shear_p use parallel_streaming, only: add_parallel_streaming_radial_variation @@ -2540,7 +2488,8 @@ end subroutine advance_radial_variation subroutine get_dgdy_2d(g, dgdy) use constants, only: zi - use kt_grids, only: nakx, aky + use parameters_kxky_grids, only: nakx + use grids_kxky, only: aky implicit none @@ -2556,9 +2505,10 @@ end subroutine get_dgdy_2d subroutine get_dgdy_3d(g, dgdy) use constants, only: zi + use parameters_kxky_grids, only: nakx + use grids_kxky, only: aky use zgrid, only: nzgrid, ntubes - use kt_grids, only: nakx, aky - + implicit none complex, dimension(:, :, -nzgrid:, :), intent(in) :: g @@ -2583,7 +2533,8 @@ subroutine get_dgdy_4d(g, dgdy) use constants, only: zi use stella_layouts, only: vmu_lo use zgrid, only: nzgrid, ntubes - use kt_grids, only: nakx, aky + use parameters_kxky_grids, only: nakx + use grids_kxky, only: aky implicit none @@ -2609,7 +2560,8 @@ end subroutine get_dgdy_4d subroutine get_dgdx_2d(g, dgdx) use constants, only: zi - use kt_grids, only: naky, akx + use parameters_kxky_grids, only: naky + use grids_kxky, only: akx implicit none @@ -2626,7 +2578,8 @@ subroutine get_dgdx_3d(g, dgdx) use constants, only: zi use zgrid, only: nzgrid, ntubes - use kt_grids, only: akx, nakx + use parameters_kxky_grids, only: nakx + use grids_kxky, only: akx implicit none @@ -2652,7 +2605,8 @@ subroutine get_dgdx_4d(g, dgdx) use constants, only: zi use stella_layouts, only: vmu_lo use zgrid, only: nzgrid, ntubes - use kt_grids, only: akx, nakx + use parameters_kxky_grids, only: nakx + use grids_kxky, only: akx implicit none @@ -2677,7 +2631,7 @@ subroutine add_explicit_term(g, pre_factor, src) use stella_layouts, only: vmu_lo use zgrid, only: nzgrid, ntubes - use kt_grids, only: naky, nakx + use parameters_kxky_grids, only: naky, nakx implicit none @@ -2707,7 +2661,7 @@ subroutine add_explicit_term_ffs(g, pre_factor, src) use stella_layouts, only: vmu_lo use zgrid, only: nzgrid, ntubes - use kt_grids, only: ikx_max, nalpha + use parameters_kxky_grids, only: ikx_max, nalpha implicit none @@ -2740,10 +2694,10 @@ subroutine advance_implicit(istep, phi, apar, bpar, g) use zgrid, only: nzgrid use dissipation, only: hyper_dissipation use hyper, only: advance_hyper_dissipation - use physics_flags, only: include_parallel_streaming - use physics_flags, only: radial_variation, full_flux_surface - use physics_flags, only: include_mirror, prp_shear_enabled - use run_parameters, only: stream_implicit, mirror_implicit, drifts_implicit + use parameters_physics, only: include_parallel_streaming + use parameters_physics, only: radial_variation, full_flux_surface + use parameters_physics, only: include_mirror, prp_shear_enabled + use parameters_numerical, only: stream_implicit, mirror_implicit, drifts_implicit use implicit_solve, only: advance_implicit_terms use fields, only: advance_fields, fields_updated use mirror_terms, only: advance_mirror_implicit @@ -2751,7 +2705,7 @@ subroutine advance_implicit(istep, phi, apar, bpar, g) use dissipation, only: advance_collisions_implicit use flow_shear, only: advance_perp_flow_shear use multibox, only: RK_step - + use parameters_numerical, only: flip_flop implicit none integer, intent(in) :: istep @@ -2884,7 +2838,7 @@ subroutine mb_communicate(g_in) use zgrid, only: nzgrid use multibox, only: multibox_communicate, use_dirichlet_bc, apply_radial_boundary_conditions use fields, only: fields_updated, advance_fields - use fields_arrays, only: phi, apar, bpar + use arrays_fields, only: phi, apar, bpar use file_utils, only: runtype_option_switch, runtype_multibox implicit none @@ -2913,7 +2867,7 @@ end subroutine mb_communicate subroutine checksum_field(field, total) use zgrid, only: nzgrid, ntubes - use kt_grids, only: naky + use parameters_kxky_grids, only: naky use extended_zgrid, only: neigen, nsegments, ikxmod use extended_zgrid, only: iz_low, iz_up @@ -2950,7 +2904,7 @@ subroutine checksum_dist(dist, total, norm) use mp, only: sum_allreduce use zgrid, only: nzgrid, ntubes use stella_layouts, only: vmu_lo, iv_idx, imu_idx, is_idx - use kt_grids, only: naky, nakx + use parameters_kxky_grids, only: naky, nakx use vpamu_grids, only: maxwell_vpa, maxwell_mu implicit none @@ -2997,7 +2951,7 @@ end subroutine checksum_dist subroutine finish_time_advance use stella_transforms, only: finish_transforms - use physics_flags, only: full_flux_surface + use parameters_physics, only: full_flux_surface use extended_zgrid, only: finish_extended_zgrid use parallel_streaming, only: finish_parallel_streaming use mirror_terms, only: finish_mirror @@ -3038,11 +2992,11 @@ end subroutine finish_parallel_nonlinearity subroutine finish_wdrift - use dist_fn_arrays, only: wdriftx_g, wdrifty_g - use dist_fn_arrays, only: wdriftx_phi, wdrifty_phi - use dist_fn_arrays, only: wdriftpx_g, wdriftpy_g - use dist_fn_arrays, only: wdriftpx_phi, wdriftpy_phi -! use dist_fn_arrays, only: adiabatic_phi + use arrays_dist_fn, only: wdriftx_g, wdrifty_g + use arrays_dist_fn, only: wdriftx_phi, wdrifty_phi + use arrays_dist_fn, only: wdriftpx_g, wdriftpy_g + use arrays_dist_fn, only: wdriftpx_phi, wdriftpy_phi +! use arrays_dist_fn, only: adiabatic_phi implicit none @@ -3062,7 +3016,7 @@ end subroutine finish_wdrift subroutine finish_wstar - use dist_fn_arrays, only: wstar, wstarp + use arrays_dist_fn, only: wstar, wstarp implicit none @@ -3075,7 +3029,7 @@ end subroutine finish_wstar subroutine deallocate_arrays - use dist_fn_arrays, only: g0, g1, g2, g3 + use arrays_dist_fn, only: g0, g1, g2, g3 implicit none diff --git a/volume_averages.f90 b/volume_averages.f90 index 7fdb8d8fb0..cf0797c599 100644 --- a/volume_averages.f90 +++ b/volume_averages.f90 @@ -26,10 +26,11 @@ module volume_averages subroutine init_volume_averages use zgrid, only: nzgrid, nztot, delzed - use kt_grids, only: nalpha, aky, nakx, naky, rho_d_clamped + use parameters_kxky_grids, only: nalpha, nakx, naky + use grids_kxky, only: rho_d_clamped, aky use geometry, only: geo_surf, drhodpsip use geometry, only: geo_surf, jacob, djacdrho, q_as_x, dVolume - use physics_flags, only: full_flux_surface, radial_variation + use parameters_physics, only: full_flux_surface, radial_variation implicit none @@ -77,7 +78,7 @@ end subroutine init_volume_averages subroutine finish_volume_averages use geometry, only: dVolume - use physics_flags, only: full_flux_surface + use parameters_physics, only: full_flux_surface implicit none @@ -95,7 +96,7 @@ end subroutine finish_volume_averages subroutine fieldline_average_real(unavg, avg) use zgrid, only: nzgrid, ntubes - use kt_grids, only: nakx, naky + use parameters_kxky_grids, only: nakx, naky use geometry, only: dl_over_b implicit none @@ -118,7 +119,7 @@ end subroutine fieldline_average_real subroutine fieldline_average_complex(unavg, avg) use zgrid, only: nzgrid, ntubes - use kt_grids, only: nakx, naky + use parameters_kxky_grids, only: nakx, naky use geometry, only: dl_over_b implicit none @@ -144,7 +145,7 @@ end subroutine fieldline_average_complex subroutine volume_average(unavg, avg) use zgrid, only: nzgrid, ntubes - use kt_grids, only: naky, nakx + use parameters_kxky_grids, only: naky, nakx use geometry, only: dl_over_b implicit none @@ -174,7 +175,7 @@ end subroutine volume_average subroutine init_flux_surface_average_ffs use zgrid, only: nzgrid - use kt_grids, only: naky + use parameters_kxky_grids, only: naky use extended_zgrid, only: periodic use geometry, only: jacob use stella_transforms, only: transform_alpha2kalpha @@ -199,7 +200,7 @@ end subroutine init_flux_surface_average_ffs subroutine flux_surface_average_ffs(no_fsa, fsa) use zgrid, only: nzgrid, delzed - use kt_grids, only: naky, naky_all + use parameters_kxky_grids, only: naky, naky_all implicit none @@ -207,7 +208,7 @@ subroutine flux_surface_average_ffs(no_fsa, fsa) complex, intent(out) :: fsa integer :: iky, ikymod - real :: area + complex :: area ! the normalising factor int dy dz Jacobian area = 0.0 diff --git a/vpamu_grids.f90 b/vpamu_grids.f90 index e54f6622de..973cdd37ae 100644 --- a/vpamu_grids.f90 +++ b/vpamu_grids.f90 @@ -138,7 +138,7 @@ subroutine init_vpa_grid use mp, only: mp_abort use constants, only: pi use species, only: spec, nspec - use run_parameters, only: maxwellian_normalization + use parameters_numerical, only: maxwellian_normalization implicit none @@ -779,12 +779,12 @@ subroutine init_mu_grid use gauss_quad, only: get_laguerre_grids use zgrid, only: nzgrid, nztot - use kt_grids, only: nalpha + use parameters_kxky_grids, only: nalpha use species, only: spec, nspec use geometry, only: bmag, bmag_psi0 - use run_parameters, only: maxwellian_normalization + use parameters_numerical, only: maxwellian_normalization - use physics_flags, only: full_flux_surface + use parameters_physics, only: full_flux_surface implicit none integer :: imu diff --git a/write_radial_grid.f90 b/write_radial_grid.f90 new file mode 100644 index 0000000000..498ca96e2a --- /dev/null +++ b/write_radial_grid.f90 @@ -0,0 +1,57 @@ +module write_radial_grid + + implicit none + + public :: dump_radial_grid + private + +contains + + subroutine dump_radial_grid (x, rho, nx) + + use file_utils, only: run_name + use parameters_physics, only: rhostar + use geometry, only: q_as_x, geo_surf, dxdpsi, drhodpsip + + implicit none + + real, dimension(:), intent (in) :: x, rho + integer, intent (in) :: nx + + integer :: ix + character(300) :: filename + + filename = trim(trim(run_name)//'.radial_grid') + open (1047, file=filename, status='unknown') + if (q_as_x) then + write (1047, '(1a12,1e12.4,1a12,1e12.4,1a12,1e12.4,1a12,1e12.4)') & + '#dxdpsi = ', dxdpsi, & + ' q = ', geo_surf%qinp, & + ' dqdr = ', geo_surf%shat * geo_surf%qinp / geo_surf%rhoc, & + ' d2qdr2 = ', geo_surf%d2qdr2 + write (1047, '(3a12)') '#1.x', '2.q', '3.rho' + do ix = 1, nx + write (1047, '(3e12.4,i9)') & + x(ix), & + x(ix) / dxdpsi + geo_surf%qinp, & + rho(ix) + geo_surf%rhoc + end do + else + write (1047, '(1a12,1e12.4,1a12,1e12.4,1a12,1e12.4,1a12,1e12.4)') & + '#dxdpsi = ', dxdpsi, & + ' dpsidr = ', 1.0 / drhodpsip, & + ' d2psidr2 = ', geo_surf%d2psidr2 + write (1047, '(3a12,a9)') '#1.x', '2.psi-psi0', '3.rho' + do ix = 1, nx + write (1047, '(3e12.4,i9)') & + x(ix), & + rhostar * x(ix) / dxdpsi, & + rho(ix) + geo_surf%rhoc + end do + end if + + close (1047) + + end subroutine dump_radial_grid + + end module write_radial_grid diff --git a/zgrid.f90 b/zgrid.f90 index 142928e84b..54640fa934 100644 --- a/zgrid.f90 +++ b/zgrid.f90 @@ -71,7 +71,7 @@ subroutine read_parameters use file_utils, only: input_unit_exist, error_unit use text_options, only: text_option, get_option_value - use physics_flags, only: full_flux_surface + use parameters_physics, only: full_flux_surface implicit none