From 8f3b2c8c89cf067fa39cfa25fb97c760ad1ed590 Mon Sep 17 00:00:00 2001 From: HanneThienpondt Date: Thu, 27 Feb 2025 15:15:36 +0100 Subject: [PATCH] Start cleaning namelists. --- COMPILATION/Makefile.depend | 8 + COMPILATION/Makefile.stella | 12 +- STELLA_CODE/{parameters => }/debug_flags.f90 | 0 .../input_file_tool/Makefile | 0 .../input_file_tool/README.md | 0 .../input_file_tool/default_stella_input.in | 0 .../default_stella_input_after_cleaning.in | 0 .../make_default_input_pretty.py | 0 .../input_file_tool/namelist_to_code.py | 0 .../update_input_file_program.f90 | 0 .../namelist_adiabatic_electrons.f90 | 125 +++++++++ .../namelists/namelist_dissipation.f90 | 92 +++++++ .../parameters_diagnostics.f90 | 0 .../parameters_kxky_grids.f90 | 0 .../parameters_kxky_grids_box.f90 | 0 .../parameters_kxky_grids_range.f90 | 0 .../update_input_file.f90 | 20 +- .../{parameters => }/parameters_numerical.f90 | 0 .../{parameters => }/parameters_physics.f90 | 251 +++++++++--------- 19 files changed, 368 insertions(+), 140 deletions(-) rename STELLA_CODE/{parameters => }/debug_flags.f90 (100%) rename STELLA_CODE/{parameters => namelists}/input_file_tool/Makefile (100%) rename STELLA_CODE/{parameters => namelists}/input_file_tool/README.md (100%) rename STELLA_CODE/{parameters => namelists}/input_file_tool/default_stella_input.in (100%) rename STELLA_CODE/{parameters => namelists}/input_file_tool/default_stella_input_after_cleaning.in (100%) rename STELLA_CODE/{parameters => namelists}/input_file_tool/make_default_input_pretty.py (100%) rename STELLA_CODE/{parameters => namelists}/input_file_tool/namelist_to_code.py (100%) rename STELLA_CODE/{parameters => namelists}/input_file_tool/update_input_file_program.f90 (100%) create mode 100644 STELLA_CODE/namelists/namelist_adiabatic_electrons.f90 create mode 100644 STELLA_CODE/namelists/namelist_dissipation.f90 rename STELLA_CODE/{parameters => namelists}/parameters_diagnostics.f90 (100%) rename STELLA_CODE/{parameters => namelists}/parameters_kxky_grids.f90 (100%) rename STELLA_CODE/{parameters => namelists}/parameters_kxky_grids_box.f90 (100%) rename STELLA_CODE/{parameters => namelists}/parameters_kxky_grids_range.f90 (100%) rename STELLA_CODE/{parameters => namelists}/update_input_file.f90 (99%) rename STELLA_CODE/{parameters => }/parameters_numerical.f90 (100%) rename STELLA_CODE/{parameters => }/parameters_physics.f90 (51%) diff --git a/COMPILATION/Makefile.depend b/COMPILATION/Makefile.depend index aafcb9d5e1..366996bc0d 100644 --- a/COMPILATION/Makefile.depend +++ b/COMPILATION/Makefile.depend @@ -59,6 +59,7 @@ stella_mod = \ $(OBJ_DIR)/mp.o \ $(OBJ_DIR)/mp_lu_decomposition.o \ $(OBJ_DIR)/multibox.o \ + $(OBJ_DIR)/namelist_adiabatic_electrons.o \ $(OBJ_DIR)/namelist_dissipation.o \ $(OBJ_DIR)/neasyf.o \ $(OBJ_DIR)/neoclassical_terms.o \ @@ -131,6 +132,7 @@ update_input_file_program_mod = \ $(OBJ_DIR)/mp.o \ $(OBJ_DIR)/mp_lu_decomposition.o \ $(OBJ_DIR)/multibox.o \ + $(OBJ_DIR)/namelist_adiabatic_electrons.o \ $(OBJ_DIR)/namelist_dissipation.o \ $(OBJ_DIR)/neoclassical_terms.o \ $(OBJ_DIR)/netcdf_utils.o \ @@ -806,6 +808,10 @@ $(OBJ_DIR)/multibox.o: \ $(OBJ_DIR)/stella_time.o \ $(OBJ_DIR)/text_options.o \ $(OBJ_DIR)/zgrid.o +$(OBJ_DIR)/namelist_adiabatic_electrons.o: \ + $(OBJ_DIR)/file_utils.o \ + $(OBJ_DIR)/mp.o \ + $(OBJ_DIR)/text_options.o $(OBJ_DIR)/namelist_dissipation.o: \ $(OBJ_DIR)/file_utils.o \ $(OBJ_DIR)/mp.o @@ -874,6 +880,7 @@ $(OBJ_DIR)/parameters_numerical.o: \ $(OBJ_DIR)/parameters_physics.o: \ $(OBJ_DIR)/file_utils.o \ $(OBJ_DIR)/mp.o \ + $(OBJ_DIR)/namelist_adiabatic_electrons.o \ $(OBJ_DIR)/text_options.o $(OBJ_DIR)/ran.o: $(OBJ_DIR)/redistribute.o: \ @@ -1078,6 +1085,7 @@ $(OBJ_DIR)/update_input_file.o: \ $(OBJ_DIR)/hyper.o \ $(OBJ_DIR)/init_g.o \ $(OBJ_DIR)/multibox.o \ + $(OBJ_DIR)/namelist_adiabatic_electrons.o \ $(OBJ_DIR)/namelist_dissipation.o \ $(OBJ_DIR)/neoclassical_terms.o \ $(OBJ_DIR)/parameters_diagnostics.o \ diff --git a/COMPILATION/Makefile.stella b/COMPILATION/Makefile.stella index f0333db289..1f615d1a0c 100644 --- a/COMPILATION/Makefile.stella +++ b/COMPILATION/Makefile.stella @@ -54,14 +54,14 @@ export GEOMETRY=$(STELLA_DIR)/geometry export GRIDS=$(STELLA_DIR)/grids export GYROKINETIC_TERMS=$(STELLA_DIR)/gyrokinetic_terms export NEOCLASSICAL=$(STELLA_DIR)/neoclassical -export PARAMETERS=$(STELLA_DIR)/parameters +export NAMELISTS=$(STELLA_DIR)/namelists export RADIAL_VARIATION=$(STELLA_DIR)/radial_variation -export INPUTFILETOOL=$(STELLA_DIR)/parameters/input_file_tool +export INPUTFILETOOL=$(STELLA_DIR)/namelists/input_file_tool SUBFOLDERS := $(CALCULATIONS) $(DIAGNOSTICS) $(COLLISIONS) $(FIELDS) $(GEOMETRY) $(GRIDS) -SUBFOLDERS := $(SUBFOLDERS) $(GYROKINETIC_TERMS) $(NEOCLASSICAL) $(PARAMETERS) $(RADIAL_VARIATION) +SUBFOLDERS := $(SUBFOLDERS) $(GYROKINETIC_TERMS) $(NEOCLASSICAL) $(NAMELISTS) $(RADIAL_VARIATION) SUBFOLDERS := $(SUBFOLDERS) $(INPUTFILETOOL) VPATH_SUBFOLDERS := :$(CALCULATIONS):$(DIAGNOSTICS):$(COLLISIONS):$(FIELDS):$(GEOMETRY):$(GRIDS): -VPATH_SUBFOLDERS := :$(VPATH_SUBFOLDERS):$(GYROKINETIC_TERMS):$(NEOCLASSICAL):$(PARAMETERS):$(RADIAL_VARIATION): +VPATH_SUBFOLDERS := :$(VPATH_SUBFOLDERS):$(GYROKINETIC_TERMS):$(NEOCLASSICAL):$(NAMELISTS):$(RADIAL_VARIATION): VPATH_SUBFOLDERS := :$(VPATH_SUBFOLDERS):$(INPUTFILETOOL): # Check directories @@ -266,7 +266,7 @@ $(OBJ)/%.o: $(GYROKINETIC_TERMS)/%.f90 $(external_modules) | $(OBJ) $(MOD) $(OBJ)/%.o: $(NEOCLASSICAL)/%.f90 $(external_modules) | $(OBJ) $(MOD) @echo " (stella) *.f90 to *.o: $(notdir $<)" @$(FC) $(F90FLAGS) $(INC_FLAGS) $(MOD_FLAGS_STELLA) -o $@ -c $< -$(OBJ)/%.o: $(PARAMETERS)/%.f90 $(external_modules) | $(OBJ) $(MOD) +$(OBJ)/%.o: $(NAMELISTS)/%.f90 $(external_modules) | $(OBJ) $(MOD) @echo " (stella) *.f90 to *.o: $(notdir $<)" @$(FC) $(F90FLAGS) $(INC_FLAGS) $(MOD_FLAGS_STELLA) -o $@ -c $< $(OBJ)/%.o: $(RADIAL_VARIATION)/%.f90 $(external_modules) | $(OBJ) $(MOD) @@ -432,7 +432,7 @@ remove-temp-files: @echo " - remove temp files" @-rm -f $(UTILS)/*~ $(CALCULATIONS)/*~ $(DIAGNOSTICS)/*~ $(COLLISIONS)/*~ @-rm -f $(FIELDS)/*~ $(GEOMETRY)/*~ $(GRIDS)/*~ $(GYROKINETIC_TERMS)/*~ - @-rm -f $(NEOCLASSICAL)/*~ $(PARAMETERS)/*~ $(RADIAL_VARIATION)/*~ + @-rm -f $(NEOCLASSICAL)/*~ $(NAMELISTS)/*~ $(RADIAL_VARIATION)/*~ # In case cmake was used, clean it up as well CMAKE := $(COMPILATION_DIR)/build_cmake diff --git a/STELLA_CODE/parameters/debug_flags.f90 b/STELLA_CODE/debug_flags.f90 similarity index 100% rename from STELLA_CODE/parameters/debug_flags.f90 rename to STELLA_CODE/debug_flags.f90 diff --git a/STELLA_CODE/parameters/input_file_tool/Makefile b/STELLA_CODE/namelists/input_file_tool/Makefile similarity index 100% rename from STELLA_CODE/parameters/input_file_tool/Makefile rename to STELLA_CODE/namelists/input_file_tool/Makefile diff --git a/STELLA_CODE/parameters/input_file_tool/README.md b/STELLA_CODE/namelists/input_file_tool/README.md similarity index 100% rename from STELLA_CODE/parameters/input_file_tool/README.md rename to STELLA_CODE/namelists/input_file_tool/README.md diff --git a/STELLA_CODE/parameters/input_file_tool/default_stella_input.in b/STELLA_CODE/namelists/input_file_tool/default_stella_input.in similarity index 100% rename from STELLA_CODE/parameters/input_file_tool/default_stella_input.in rename to STELLA_CODE/namelists/input_file_tool/default_stella_input.in diff --git a/STELLA_CODE/parameters/input_file_tool/default_stella_input_after_cleaning.in b/STELLA_CODE/namelists/input_file_tool/default_stella_input_after_cleaning.in similarity index 100% rename from STELLA_CODE/parameters/input_file_tool/default_stella_input_after_cleaning.in rename to STELLA_CODE/namelists/input_file_tool/default_stella_input_after_cleaning.in diff --git a/STELLA_CODE/parameters/input_file_tool/make_default_input_pretty.py b/STELLA_CODE/namelists/input_file_tool/make_default_input_pretty.py similarity index 100% rename from STELLA_CODE/parameters/input_file_tool/make_default_input_pretty.py rename to STELLA_CODE/namelists/input_file_tool/make_default_input_pretty.py diff --git a/STELLA_CODE/parameters/input_file_tool/namelist_to_code.py b/STELLA_CODE/namelists/input_file_tool/namelist_to_code.py similarity index 100% rename from STELLA_CODE/parameters/input_file_tool/namelist_to_code.py rename to STELLA_CODE/namelists/input_file_tool/namelist_to_code.py diff --git a/STELLA_CODE/parameters/input_file_tool/update_input_file_program.f90 b/STELLA_CODE/namelists/input_file_tool/update_input_file_program.f90 similarity index 100% rename from STELLA_CODE/parameters/input_file_tool/update_input_file_program.f90 rename to STELLA_CODE/namelists/input_file_tool/update_input_file_program.f90 diff --git a/STELLA_CODE/namelists/namelist_adiabatic_electrons.f90 b/STELLA_CODE/namelists/namelist_adiabatic_electrons.f90 new file mode 100644 index 0000000000..ca5dae58b5 --- /dev/null +++ b/STELLA_CODE/namelists/namelist_adiabatic_electrons.f90 @@ -0,0 +1,125 @@ +!############################################################################### +!###################### READ ADIABATIC ELECTRONS NAMELIST ###################### +!############################################################################### +! Read the namelist in the input file: +! +! &adiabatic_electroms +! adiabatic_option = 'field-line-average-term' +! tite = 1.0 +! nine = 1.0 +!/ +!############################################################################### +module namelist_adiabatic_electrons + + implicit none + + public :: read_namelist + + private + +contains + + subroutine read_namelist(adiabatic_option_switch, nine, tite, & + adiabatic_option_fieldlineavg, adiabatic_option_periodic) + + use mp, only: proc0 + + implicit none + + real, intent(out) :: tite, nine + integer, intent(out) :: adiabatic_option_switch + integer, intent(out) :: adiabatic_option_periodic + integer, intent(out) :: adiabatic_option_fieldlineavg + + ! Local variable to set + character(30) :: adiabatic_option + + if (.not. proc0) return + call set_default_parameters + call read_input_file + call check_inputs + + contains + + !********************************************************************** + ! DEFAULT PARAMETERS ! + !********************************************************************** + ! Set the default input parameters. + !********************************************************************** + subroutine set_default_parameters() + + implicit none + + adiabatic_option = 'field-line-average-term' + tite = 1.0 + nine = 1.0 + + end subroutine set_default_parameters + + + !********************************************************************** + ! READ INPUT FILE ! + !********************************************************************** + ! 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 + use text_options, only: text_option, get_option_value + + implicit none + + ! Variables needed to read the input file + integer :: ierr, in_file + logical :: dexist + + ! Create parameters for the text option + integer, parameter :: periodic = 1 + integer, parameter :: fieldlineavg = 2 + + ! Link text options for to an integer value + type(text_option), dimension(6), parameter :: adiabaticopts = & + (/text_option('default', fieldlineavg), & + text_option('no-field-line-average-term', periodic), & + text_option('field-line-average-term', fieldlineavg), & + text_option('iphi00=0', periodic), & + text_option('iphi00=1', periodic), & + text_option('iphi00=2', fieldlineavg)/) + + ! Define variables in the namelist + namelist /adiabatic_electrons/ adiabatic_option, tite, nine + + !---------------------------------------------------------------------- + + ! Save the values of the adiabatic option + adiabatic_option_periodic = periodic + adiabatic_option_fieldlineavg = fieldlineavg + + ! Overwrite the default input parameters by those specified in the input file + in_file = input_unit_exist("adiabatic_electrons", dexist) + if (dexist) read (unit=in_file, nml=adiabatic_electrons) + + ! Read the text option in and store it in + ierr = error_unit() + call get_option_value(adiabatic_option, adiabaticopts, adiabatic_option_switch, & + ierr, "adiabatic_option in parameters_physics") + + end subroutine read_input_file + + + !********************************************************************** + ! CHECK INPUTS ! + !********************************************************************** + ! Make sure that the input variables are set correctly. + !********************************************************************** + subroutine check_inputs + + implicit none + + end subroutine check_inputs + + end subroutine read_namelist + +end module namelist_adiabatic_electrons + diff --git a/STELLA_CODE/namelists/namelist_dissipation.f90 b/STELLA_CODE/namelists/namelist_dissipation.f90 new file mode 100644 index 0000000000..cbd0ec4e60 --- /dev/null +++ b/STELLA_CODE/namelists/namelist_dissipation.f90 @@ -0,0 +1,92 @@ +!############################################################################### +!########################## READ DISSIPATION NAMELIST ########################## +!############################################################################### +! Read the namelist in the input file +!############################################################################### +module namelist_dissipation + + implicit none + + public :: read_namelist + + private + +contains + + subroutine read_namelist(include_collisions, collisions_implicit, collision_model, hyper_dissipation) + + use mp, only: proc0 + + implicit none + + logical, intent(out) :: include_collisions, collisions_implicit, hyper_dissipation + character(30), intent(out) :: collision_model + + if (.not. proc0) return + call set_default_parameters + call read_input_file + call check_inputs + + contains + + !********************************************************************** + ! READ INPUT FILE ! + !********************************************************************** + ! 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 + + implicit none + + integer :: in_file + logical :: dexist + + ! Variables in the namelist + namelist /dissipation/ include_collisions, collisions_implicit, collision_model, hyper_dissipation + + ! Overwrite the default input parameters by those specified in the input file + in_file = input_unit_exist("dissipation", dexist) + if (dexist) read (unit=in_file, nml=dissipation) + + end subroutine read_input_file + + + !********************************************************************** + ! CHECK INPUTS ! + !********************************************************************** + ! Make sure that the input variables are set correctly. + !********************************************************************** + subroutine check_inputs + + implicit none + + if (.not. include_collisions) collisions_implicit = .false. + + end subroutine check_inputs + + + !********************************************************************** + ! DEFAULT PARAMETERS ! + !********************************************************************** + ! Set the default input parameters. + !********************************************************************** + subroutine set_default_parameters() + + implicit none + + include_collisions = .false. + collisions_implicit = .true. + hyper_dissipation = .false. + + ! dougherty or fokker-planck + collision_model = "dougherty" + + end subroutine set_default_parameters + + end subroutine read_namelist + +end module namelist_dissipation + diff --git a/STELLA_CODE/parameters/parameters_diagnostics.f90 b/STELLA_CODE/namelists/parameters_diagnostics.f90 similarity index 100% rename from STELLA_CODE/parameters/parameters_diagnostics.f90 rename to STELLA_CODE/namelists/parameters_diagnostics.f90 diff --git a/STELLA_CODE/parameters/parameters_kxky_grids.f90 b/STELLA_CODE/namelists/parameters_kxky_grids.f90 similarity index 100% rename from STELLA_CODE/parameters/parameters_kxky_grids.f90 rename to STELLA_CODE/namelists/parameters_kxky_grids.f90 diff --git a/STELLA_CODE/parameters/parameters_kxky_grids_box.f90 b/STELLA_CODE/namelists/parameters_kxky_grids_box.f90 similarity index 100% rename from STELLA_CODE/parameters/parameters_kxky_grids_box.f90 rename to STELLA_CODE/namelists/parameters_kxky_grids_box.f90 diff --git a/STELLA_CODE/parameters/parameters_kxky_grids_range.f90 b/STELLA_CODE/namelists/parameters_kxky_grids_range.f90 similarity index 100% rename from STELLA_CODE/parameters/parameters_kxky_grids_range.f90 rename to STELLA_CODE/namelists/parameters_kxky_grids_range.f90 diff --git a/STELLA_CODE/parameters/update_input_file.f90 b/STELLA_CODE/namelists/update_input_file.f90 similarity index 99% rename from STELLA_CODE/parameters/update_input_file.f90 rename to STELLA_CODE/namelists/update_input_file.f90 index 20dcfa5bd1..614a624d9a 100644 --- a/STELLA_CODE/parameters/update_input_file.f90 +++ b/STELLA_CODE/namelists/update_input_file.f90 @@ -194,12 +194,13 @@ subroutine write_parameters_physics(unit_number, write_input_file) use file_utils, only: input_unit_exist use parameters_physics, only: set_default_parameters_physics => set_default_parameters use parameters_physics, only: include_parallel_streaming, include_mirror, nonlinear - use parameters_physics, only: xdriftknob, ydriftknob, wstarknob, adiabatic_option, prp_shear_enabled + use parameters_physics, only: xdriftknob, ydriftknob, wstarknob, prp_shear_enabled use parameters_physics, only: hammett_flow_shear, include_pressure_variation, include_geometric_variation use parameters_physics, only: include_parallel_nonlinearity, suppress_zonal_interaction, full_flux_surface use parameters_physics, only: include_apar, include_bpar, radial_variation - use parameters_physics, only: beta, zeff, tite, nine, rhostar, vnew_ref + use parameters_physics, only: beta, zeff, rhostar, vnew_ref use parameters_physics, only: g_exb, g_exbfac, omprimfac, irhostar + use namelist_adiabatic_electrons, only: read_adiabatic_electrons_namelist => read_namelist implicit none @@ -212,13 +213,19 @@ subroutine write_parameters_physics(unit_number, write_input_file) integer :: unit_number_temp logical :: new_nml_exist + ! Define the variables in the namelist + integer :: adiabatic_option_switch, adiabatic_option_periodic, adiabatic_option_fieldlineavg + character(30) :: adiabatic_option + real :: tite, nine + ! Current namelist namelist /parameters_physics/ include_parallel_streaming, include_mirror, nonlinear, & adiabatic_option, prp_shear_enabled, include_apar, include_bpar, radial_variation, & hammett_flow_shear, include_pressure_variation, include_geometric_variation, & include_parallel_nonlinearity, suppress_zonal_interaction, full_flux_surface, & xdriftknob, ydriftknob, wstarknob, g_exb, g_exbfac, omprimfac, irhostar, & - beta, zeff, tite, nine, rhostar, vnew_ref + beta, zeff, tite, nine, rhostar, vnew_ref + namelist /adiabatic_electrons/ adiabatic_option, tite, nine !------------------------------------------------------------------------- @@ -236,9 +243,16 @@ subroutine write_parameters_physics(unit_number, write_input_file) call backwards_compatibility_physics_flags() call backwards_compatibility_time_advance_knobs() end if + + ! TODO - Finish this + call read_adiabatic_electrons_namelist(adiabatic_option_switch, nine, tite, & + adiabatic_option_fieldlineavg, adiabatic_option_periodic) + if (adiabatic_option_switch==adiabatic_option_periodic) adiabatic_option = 'no-field-line-average-term' + if (adiabatic_option_switch==adiabatic_option_fieldlineavg) adiabatic_option = 'field-line-average-term' ! Write the namelist to _with_defaults.in or default_stella_input.in write(unit=unit_number, nml=parameters_physics) + write(unit=unit_number, nml=adiabatic_electrons) contains diff --git a/STELLA_CODE/parameters/parameters_numerical.f90 b/STELLA_CODE/parameters_numerical.f90 similarity index 100% rename from STELLA_CODE/parameters/parameters_numerical.f90 rename to STELLA_CODE/parameters_numerical.f90 diff --git a/STELLA_CODE/parameters/parameters_physics.f90 b/STELLA_CODE/parameters_physics.f90 similarity index 51% rename from STELLA_CODE/parameters/parameters_physics.f90 rename to STELLA_CODE/parameters_physics.f90 index 3b01f9ae6e..7a783f9f9f 100644 --- a/STELLA_CODE/parameters/parameters_physics.f90 +++ b/STELLA_CODE/parameters_physics.f90 @@ -12,6 +12,12 @@ module parameters_physics implicit none + + !> 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 !> Public subroutines that are read by the main stella routine. public :: read_parameters_physics @@ -25,12 +31,6 @@ module parameters_physics 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 @@ -50,20 +50,19 @@ module parameters_physics public :: g_exb, g_exbfac, omprimfac ! Only for the input file program - public :: irhostar, adiabatic_option + public :: irhostar private + + ! Adiabatic electrons + integer :: adiabatic_option_periodic + integer :: adiabatic_option_fieldlineavg + integer :: adiabatic_option_switch 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 - + real :: xdriftknob, ydriftknob, wstarknob logical :: prp_shear_enabled logical :: hammett_flow_shear @@ -80,8 +79,6 @@ module parameters_physics real :: beta, zeff, tite, nine, rhostar, irhostar, vnew_ref real :: g_exb, g_exbfac, omprimfac logical :: initialised = .false. - - character(30) :: adiabatic_option contains @@ -104,8 +101,6 @@ subroutine set_default_parameters 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. @@ -122,8 +117,6 @@ subroutine set_default_parameters 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 @@ -135,122 +128,118 @@ subroutine set_default_parameters end subroutine set_default_parameters - !====================================================================== - !====================== 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 - - if (initialised) return - - if (proc0) call set_default_parameters - if (proc0) call read_input_file - call broadcast_parameters - - initialised = .true. - - contains + !====================================================================== + !====================== READ PHYSICS PARAMETERS ======================= + !====================================================================== + subroutine read_parameters_physics - !********************************************************************** - ! 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 + use mp, only: proc0, broadcast + use text_options, only: text_option, get_option_value + use file_utils, only: input_unit, error_unit, input_unit_exist + use namelist_adiabatic_electrons, only: read_adiabatic_electrons_namelist => read_namelist 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) - - 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 - - !********************************************************************** - ! 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) + if (initialised) return + + ! Read namelist + if (proc0) call read_adiabatic_electrons_namelist(adiabatic_option_switch, nine, tite, & + adiabatic_option_fieldlineavg, adiabatic_option_periodic) - 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) - - end subroutine broadcast_parameters - - end subroutine read_parameters_physics + ! Broadcast to all processors + call broadcast(adiabatic_option_fieldlineavg) + call broadcast(adiabatic_option_periodic) + call broadcast(adiabatic_option_switch) + call broadcast(tite) + call broadcast(nine) + + if (proc0) call read_input_file + call broadcast_parameters + + initialised = .true. + + contains + + !********************************************************************** + ! 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 + + + integer :: ierr, in_file + logical :: nml_exist + + namelist /parameters_physics/ include_parallel_streaming, include_mirror, nonlinear, & + xdriftknob, ydriftknob, wstarknob, 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, 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) + + 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 + + + end subroutine + + !********************************************************************** + ! 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(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(g_exb) + call broadcast(g_exbfac) + call broadcast(omprimfac) + + end subroutine broadcast_parameters + + end subroutine read_parameters_physics !********************************************************************** ! FINISH READ PARAMETERS !