LCOV - code coverage report
Current view: top level - eos/private - eos_ctrls_io.f90 (source / functions) Coverage Total Hit
Test: coverage.info Lines: 43.7 % 300 131
Test Date: 2025-05-08 18:23:42 Functions: 50.0 % 8 4

            Line data    Source code
       1              : ! ***********************************************************************
       2              : !
       3              : !   Copyright (C) 2020 The MESA Team
       4              : !
       5              : !   This program is free software: you can redistribute it and/or modify
       6              : !   it under the terms of the GNU Lesser General Public License
       7              : !   as published by the Free Software Foundation,
       8              : !   either version 3 of the License, or (at your option) any later version.
       9              : !
      10              : !   This program is distributed in the hope that it will be useful,
      11              : !   but WITHOUT ANY WARRANTY; without even the implied warranty of
      12              : !   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
      13              : !   See the GNU Lesser General Public License for more details.
      14              : !
      15              : !   You should have received a copy of the GNU Lesser General Public License
      16              : !   along with this program. If not, see <https://www.gnu.org/licenses/>.
      17              : !
      18              : ! ***********************************************************************
      19              : 
      20              :    module eos_ctrls_io
      21              : 
      22              :    use const_def, only: dp, max_extra_inlists
      23              :    use eos_def
      24              :    use math_lib
      25              :    use utils_lib, only: mesa_error
      26              : 
      27              :    implicit none
      28              : 
      29              :    public :: read_namelist, write_namelist, get_eos_controls, set_eos_controls
      30              :    private
      31              : 
      32              :    ! controls for HELM
      33              :    real(dp) :: Z_all_HELM  ! all HELM for Z >= this unless use_FreeEOS
      34              :    real(dp) :: logT_all_HELM  ! all HELM for lgT >= this
      35              :    real(dp) :: logT_low_all_HELM  ! all HELM for lgT <= this
      36              :    real(dp) :: coulomb_temp_cut_HELM, coulomb_den_cut_HELM
      37              : 
      38              :    ! controls for OPAL_SCVH
      39              :    logical :: use_OPAL_SCVH
      40              :    real(dp) :: logT_low_all_SCVH  ! SCVH for lgT >= this
      41              :    real(dp) :: logT_all_OPAL  ! OPAL for lgT <= this
      42              :    real(dp) :: logRho1_OPAL_SCVH_limit  ! don't use OPAL_SCVH for logRho > this
      43              :    real(dp) :: logRho2_OPAL_SCVH_limit  ! full OPAL_SCVH okay for logRho < this
      44              :    real(dp) :: logRho_min_OPAL_SCVH_limit  ! no OPAL/SCVH for logRho < this
      45              :    real(dp) :: logQ_max_OPAL_SCVH  ! no OPAL/SCVH for logQ > this
      46              :    real(dp) :: logQ_min_OPAL_SCVH  ! no OPAL/SCVH for logQ <= this.
      47              :    real(dp) :: Z_all_OPAL  ! all OPAL for Z <= this
      48              : 
      49              :    ! controls for FreeEOS
      50              :    logical :: use_FreeEOS
      51              :    real(dp) :: logQ_max_FreeEOS_hi
      52              :    real(dp) :: logQ_max_FreeEOS_lo
      53              :    real(dp) :: logQ_min_FreeEOS_hi
      54              :    real(dp) :: logQ_min_FreeEOS_lo
      55              :    real(dp) :: logRho_min_FreeEOS_hi
      56              :    real(dp) :: logRho_min_FreeEOS_lo
      57              :    real(dp) :: logRho_max_FreeEOS_hi
      58              :    real(dp) :: logRho_max_FreeEOS_lo
      59              :    real(dp) :: logT_min_FreeEOS_hi
      60              :    real(dp) :: logT_min_FreeEOS_lo
      61              :    real(dp) :: logT_max_FreeEOS_hi
      62              :    real(dp) :: logT_max_FreeEOS_lo
      63              :    real(dp) :: logQ_cut_FreeEOS_lo_Z_max
      64              :    real(dp) :: logQ_cut_lo_Z_FreeEOS_hi
      65              :    real(dp) :: logQ_cut_lo_Z_FreeEOS_lo
      66              :    real(dp) :: logQ_cut_hi_Z_FreeEOS_hi
      67              :    real(dp) :: logQ_cut_hi_Z_FreeEOS_lo
      68              :    real(dp) :: logRho_cut_FreeEOS_hi
      69              :    real(dp) :: logRho_cut_FreeEOS_lo
      70              :    real(dp) :: logT_cut_FreeEOS_hi
      71              :    real(dp) :: logT_cut_FreeEOS_lo
      72              :    character (len=30) :: suffix_for_FreeEOS_Z(num_FreeEOS_Zs)
      73              : 
      74              :    ! controls for CMS
      75              :    logical :: use_CMS, CMS_use_fixed_composition
      76              :    integer :: CMS_fixed_composition_index
      77              :    real(dp) :: max_Z_for_any_CMS, max_Z_for_all_CMS  ! set to -1 to disable CMS
      78              :    real(dp) :: logQ_max_for_any_CMS, logQ_max_for_all_CMS      ! for upper blend zone in logQ = logRho - 2*logT + 12
      79              :    real(dp) :: logQ_min_for_any_CMS, logQ_min_for_all_CMS      ! for lower blend zone in logQ
      80              :    real(dp) :: logRho_max_for_all_CMS, logRho_max_for_any_CMS  ! for upper blend zone in logRho
      81              :    real(dp) :: logRho_min_for_all_CMS, logRho_min_for_any_CMS  ! for lower blend zone in logRho
      82              :    real(dp) :: logT_max_for_all_CMS, logT_max_for_any_CMS      ! for upper blend zone in logT
      83              :    real(dp) :: logT_min_for_all_CMS, logT_min_for_any_CMS      ! for lower blend zone in logT
      84              :    real(dp) :: logT_max_for_all_CMS_pure_He, logT_max_for_any_CMS_pure_He  ! upper logT blend zone is different for pure He
      85              : 
      86              :    ! controls for PC
      87              :    logical :: use_PC
      88              :    real(dp) :: mass_fraction_limit_for_PC  ! skip any species with abundance < this
      89              :    real(dp) :: logRho1_PC_limit  ! okay for pure PC for logRho > this
      90              :    real(dp) :: logRho2_PC_limit  ! don't use PC for logRho < this (>= 2.8)
      91              :    logical :: PC_use_Gamma_limit_instead_of_T
      92              :    real(dp) :: logT1_PC_limit  ! okay for pure PC for logT < this (like logT_all_OPAL)
      93              :    real(dp) :: logT2_PC_limit  ! don't use PC for logT > this (like logT_all_HELM)
      94              :    real(dp) :: log_Gamma_e_all_HELM  ! HELM for log_Gamma_e <= this
      95              :    real(dp) :: Gamma_e_all_HELM  ! 10**log_Gamma_e_all_HELM
      96              :    real(dp) :: log_Gamma_e_all_PC  ! PC for log_Gamma_e >= this
      97              :    ! crystallization boundaries
      98              :    real(dp) :: PC_Gamma_start_crystal  ! Begin releasing latent heat of crystallization
      99              :    real(dp) :: PC_Gamma_full_crystal  ! Fully into the solid phase
     100              : 
     101              :    ! limits for Skye
     102              :    logical :: use_Skye
     103              :    logical :: Skye_use_ion_offsets
     104              :    real(dp) :: mass_fraction_limit_for_Skye
     105              :    real(dp) :: Skye_min_gamma_for_solid  ! The minimum Gamma_i at which to use the solid free energy fit (below this, extrapolate).
     106              :    real(dp) :: Skye_max_gamma_for_liquid  ! The maximum Gamma_i at which to use the liquid free energy fit (above this, extrapolate).
     107              :    character(len=128) :: Skye_solid_mixing_rule  ! Currently support 'Ogata' or 'PC'
     108              : 
     109              :    logical :: use_simple_Skye_blends
     110              :    real(dp) :: logRho_min_for_any_Skye, logRho_min_for_all_Skye
     111              :    real(dp) :: logT_min_for_any_Skye, logT_min_for_all_Skye
     112              : 
     113              :    ! misc
     114              :    logical :: include_radiation, include_elec_pos
     115              :    logical :: eosDT_use_linear_interp_for_X
     116              :    logical :: eosDT_use_linear_interp_to_HELM
     117              :    character(len=128) :: eosDT_file_prefix
     118              :    logical :: okay_to_convert_ierr_to_skip
     119              :    real(dp) :: tiny_fuzz
     120              : 
     121              :    ! other eos
     122              :    logical :: use_other_eos_component, use_other_eos_results
     123              : 
     124              :    ! debugging
     125              :    logical :: dbg
     126              :    real(dp) :: logT_lo, logT_hi
     127              :    real(dp) :: logRho_lo, logRho_hi
     128              :    real(dp) :: X_lo, X_hi
     129              :    real(dp) :: Z_lo, Z_hi
     130              : 
     131              :    logical, dimension(max_extra_inlists) :: read_extra_eos_inlist
     132              :    character (len=strlen), dimension(max_extra_inlists) :: extra_eos_inlist_name
     133              : 
     134              :    ! User supplied inputs
     135              :    real(dp) :: eos_ctrl(10)
     136              :    integer :: eos_integer_ctrl(10)
     137              :    logical :: eos_logical_ctrl(10)
     138              :    character(len=strlen) :: eos_character_ctrl(10)
     139              : 
     140              : 
     141              :    namelist /eos/ &
     142              :       use_FreeEOS, &
     143              : 
     144              :       ! controls for HELM
     145              :       Z_all_HELM, &  ! all HELM for Z >= this unless use_FreeEOS
     146              :       logT_all_HELM, &  ! all HELM for lgT >= this
     147              :       logT_low_all_HELM, &  ! all HELM for lgT <= this
     148              :       coulomb_temp_cut_HELM, &
     149              :       coulomb_den_cut_HELM, &
     150              : 
     151              :       ! controls for OPAL_SCVH
     152              :       use_OPAL_SCVH, &
     153              :       logT_low_all_SCVH, &  ! SCVH for lgT >= this
     154              :       logT_all_OPAL, &  ! OPAL for lgT <= this
     155              :       logRho1_OPAL_SCVH_limit, &  ! don't use OPAL_SCVH for logRho > this
     156              :       logRho2_OPAL_SCVH_limit, &  ! full OPAL_SCVH okay for logRho < this
     157              :       logRho_min_OPAL_SCVH_limit, &  ! no OPAL/SCVH for logRho < this
     158              :       logQ_max_OPAL_SCVH, &  ! no OPAL/SCVH for logQ > this
     159              :       logQ_min_OPAL_SCVH, &  ! no OPAL/SCVH for logQ <= this.
     160              :       Z_all_OPAL, &  ! all OPAL for Z <= this
     161              : 
     162              :       ! controls for FreeEOS
     163              :       use_FreeEOS, &
     164              :       logQ_max_FreeEOS_hi, &
     165              :       logQ_max_FreeEOS_lo, &
     166              :       logQ_min_FreeEOS_hi, &
     167              :       logQ_min_FreeEOS_lo, &
     168              :       logRho_min_FreeEOS_hi, &
     169              :       logRho_min_FreeEOS_lo, &
     170              :       logRho_max_FreeEOS_hi, &
     171              :       logRho_max_FreeEOS_lo, &
     172              :       logT_min_FreeEOS_hi, &
     173              :       logT_min_FreeEOS_lo, &
     174              :       logT_max_FreeEOS_hi, &
     175              :       logT_max_FreeEOS_lo, &
     176              :       logQ_cut_FreeEOS_lo_Z_max, &
     177              :       logQ_cut_lo_Z_FreeEOS_hi, &
     178              :       logQ_cut_lo_Z_FreeEOS_lo, &
     179              :       logQ_cut_hi_Z_FreeEOS_hi, &
     180              :       logQ_cut_hi_Z_FreeEOS_lo, &
     181              :       logRho_cut_FreeEOS_hi, &
     182              :       logRho_cut_FreeEOS_lo, &
     183              :       logT_cut_FreeEOS_hi, &
     184              :       logT_cut_FreeEOS_lo, &
     185              :       suffix_for_FreeEOS_Z, &
     186              : 
     187              :       ! controls for CMS
     188              :       use_CMS, CMS_use_fixed_composition, &
     189              :       CMS_fixed_composition_index, &
     190              :       max_Z_for_any_CMS, &
     191              :       max_Z_for_all_CMS, &  ! set to -1 to disable CMS
     192              :       logQ_max_for_any_CMS, &
     193              :       logQ_max_for_all_CMS, &      ! for upper blend zone in logQ = logRho - 2*logT + 12
     194              :       logQ_min_for_any_CMS, &
     195              :       logQ_min_for_all_CMS, &      ! for lower blend zone in logQ
     196              :       logRho_max_for_all_CMS, &
     197              :       logRho_max_for_any_CMS, &  ! for upper blend zone in logRho
     198              :       logRho_min_for_all_CMS, &
     199              :       logRho_min_for_any_CMS, &  ! for lower blend zone in logRho
     200              :       logT_max_for_all_CMS, &
     201              :       logT_max_for_any_CMS, &      ! for upper blend zone in logT
     202              :       logT_min_for_all_CMS, &
     203              :       logT_min_for_any_CMS, &      ! for lower blend zone in logT
     204              :       logT_max_for_all_CMS_pure_He, &
     205              :       logT_max_for_any_CMS_pure_He, &  ! upper logT blend zone is different for pure He
     206              : 
     207              :       ! controls for PC
     208              :       use_PC, &
     209              :       mass_fraction_limit_for_PC, &  ! skip any species with abundance < this
     210              :       logRho1_PC_limit, &  ! okay for pure PC for logRho > this
     211              :       logRho2_PC_limit, &  ! don't use PC for logRho < this (>= 2.8)
     212              :       PC_use_Gamma_limit_instead_of_T, &
     213              :       logT1_PC_limit, &  ! okay for pure PC for logT < this (like logT_all_OPAL)
     214              :       logT2_PC_limit, &  ! don't use PC for logT > this (like logT_all_HELM)
     215              :       log_Gamma_e_all_HELM, &  ! HELM for log_Gamma_e <= this
     216              :       log_Gamma_e_all_PC, &  ! PC for log_Gamma_e >= this
     217              :       ! crystallization boundaries
     218              :       PC_Gamma_start_crystal, &  ! Begin releasing latent heat of crystallization
     219              :       PC_Gamma_full_crystal, &  ! Fully into the solid phase
     220              : 
     221              :       ! controls for Skye
     222              :       use_Skye, &
     223              :       Skye_use_ion_offsets, &
     224              :       mass_fraction_limit_for_Skye, &
     225              :       Skye_min_gamma_for_solid, &  ! The minimum Gamma_i at which to use the solid free energy fit (below this, extrapolate).
     226              :       Skye_max_gamma_for_liquid, &  ! The maximum Gamma_i at which to use the liquid free energy fit (above this, extrapolate).
     227              :       Skye_solid_mixing_rule, &
     228              : 
     229              :       use_simple_Skye_blends, &
     230              :       logRho_min_for_any_Skye, &
     231              :       logRho_min_for_all_Skye, &
     232              :       logT_min_for_any_Skye, &
     233              :       logT_min_for_all_Skye, &
     234              : 
     235              :       ! misc
     236              :       include_radiation, &
     237              :       include_elec_pos, &
     238              :       eosDT_use_linear_interp_for_X, &
     239              :       eosDT_use_linear_interp_to_HELM, &
     240              :       eosDT_file_prefix, &
     241              : 
     242              :       okay_to_convert_ierr_to_skip, &
     243              :       tiny_fuzz, &
     244              : 
     245              :       ! other eos
     246              :       use_other_eos_component, use_other_eos_results, &
     247              : 
     248              :       ! debugging
     249              :       dbg, &
     250              :       logT_lo, logT_hi, &
     251              :       logRho_lo, logRho_hi, &
     252              :       X_lo, X_hi, &
     253              :       Z_lo, Z_hi, &
     254              : 
     255              :       read_extra_eos_inlist, extra_eos_inlist_name,&
     256              : 
     257              :    ! User supplied inputs
     258              :       eos_ctrl, &
     259              :       eos_integer_ctrl, &
     260              :       eos_logical_ctrl, &
     261              :       eos_character_ctrl
     262              : 
     263              : 
     264              :    contains
     265              : 
     266              : 
     267              :    ! read a "namelist" file and set parameters
     268           19 :    subroutine read_namelist(handle, inlist, ierr)
     269              :       integer, intent(in) :: handle
     270              :       character (len=*), intent(in) :: inlist
     271              :       integer, intent(out) :: ierr  ! 0 means AOK.
     272              :       type (EoS_General_Info), pointer :: rq
     273              :       include 'formats'
     274           19 :       call get_eos_ptr(handle,rq,ierr)
     275           19 :       if (ierr /= 0) return
     276           19 :       call set_default_controls
     277           19 :       call read_controls_file(rq, inlist, 1, ierr)
     278           19 :       if (ierr /= 0) return
     279           19 :       rq% Gamma_e_all_HELM = exp10(rq% log_Gamma_e_all_HELM)
     280           19 :       if (FreeEOS_XZ_struct% Zs(num_FreeEOS_Zs) /= 1d0) then
     281            0 :          write(*,*) 'ERROR: expect FreeEOS_XZ_struct% Zs(num_FreeEOS_Zs) == 1d0'
     282            0 :          call mesa_error(__FILE__,__LINE__,'init_eos_handle_data')
     283              :       end if
     284              :    end subroutine read_namelist
     285              : 
     286              : 
     287           19 :    recursive subroutine read_controls_file(rq, filename, level, ierr)
     288              :       use ISO_FORTRAN_ENV, only: IOSTAT_END
     289              :       character(*), intent(in) :: filename
     290              :       type (EoS_General_Info), pointer :: rq
     291              :       integer, intent(in) :: level
     292              :       integer, intent(out) :: ierr
     293              :       logical, dimension(max_extra_inlists) :: read_extra
     294              :       character (len=strlen), dimension(max_extra_inlists) :: extra
     295              :       integer :: unit, i
     296              : 
     297           19 :       ierr = 0
     298           19 :       if (level >= 10) then
     299            0 :          write(*,*) 'ERROR: too many levels of nested extra controls inlist files'
     300            0 :          ierr = -1
     301           10 :          return
     302              :       end if
     303              : 
     304           19 :       if (len_trim(filename) > 0) then
     305              :          open(newunit=unit, file=trim(filename), &
     306            9 :             action='read', delim='quote', status='old', iostat=ierr)
     307            9 :          if (ierr /= 0) then
     308            0 :             if (level == 1) then
     309            0 :                ierr = 0  ! no inlist file so just use defaults
     310            0 :                call store_controls(rq)
     311              :             else
     312            0 :                write(*, *) 'Failed to open eos namelist file ', trim(filename)
     313              :             end if
     314            0 :             return
     315              :          end if
     316            9 :          read(unit, nml=eos, iostat=ierr)
     317            9 :          close(unit)
     318            9 :          if (ierr == IOSTAT_END) then  ! end-of-file means didn't find an &eos namelist
     319            0 :             ierr = 0
     320            0 :             write(*, *) 'WARNING: Failed to find eos namelist in file: ', trim(filename)
     321            0 :             call store_controls(rq)
     322            0 :             close(unit)
     323            0 :             return
     324            9 :          else if (ierr /= 0) then
     325            0 :             write(*, *)
     326            0 :             write(*, *)
     327            0 :             write(*, *)
     328            0 :             write(*, *)
     329            0 :             write(*, '(a)') 'Failed while trying to read eos namelist file: ' // trim(filename)
     330            0 :             write(*, '(a)') 'Perhaps the following runtime error message will help you find the problem.'
     331            0 :             write(*, *)
     332            0 :             open(newunit=unit, file=trim(filename), action='read', delim='quote', status='old', iostat=ierr)
     333            0 :             read(unit, nml=eos)
     334            0 :             close(unit)
     335            0 :             return
     336              :          end if
     337              :       end if
     338              : 
     339           19 :       call store_controls(rq)
     340              : 
     341           19 :       if (len_trim(filename) == 0) return
     342              : 
     343              :       ! recursive calls to read other inlists
     344           54 :       do i=1, max_extra_inlists
     345           45 :          read_extra(i) = read_extra_eos_inlist(i)
     346           45 :          read_extra_eos_inlist(i) = .false.
     347           45 :          extra(i) = extra_eos_inlist_name(i)
     348           45 :          extra_eos_inlist_name(i) = 'undefined'
     349              : 
     350           54 :          if (read_extra(i)) then
     351            0 :             call read_controls_file(rq, extra(i), level+1, ierr)
     352            0 :             if (ierr /= 0) return
     353              :          end if
     354              :       end do
     355              : 
     356              : 
     357              :    end subroutine read_controls_file
     358              : 
     359              : 
     360           19 :    subroutine set_default_controls
     361              :       include 'eos.defaults'
     362           19 :    end subroutine set_default_controls
     363              : 
     364              : 
     365           19 :    subroutine store_controls(rq)
     366              :       type (EoS_General_Info), pointer :: rq
     367              :       ! controls for HELM
     368           19 :       rq% Z_all_HELM = Z_all_HELM
     369           19 :       rq% logT_all_HELM = logT_all_HELM
     370           19 :       rq% logT_low_all_HELM = logT_low_all_HELM
     371           19 :       rq% coulomb_temp_cut_HELM = coulomb_temp_cut_HELM
     372           19 :       rq% coulomb_den_cut_HELM = coulomb_den_cut_HELM
     373              :       ! controls for OPAL_SCVH
     374           19 :       rq% use_OPAL_SCVH = use_OPAL_SCVH
     375           19 :       rq% logT_low_all_SCVH = logT_low_all_SCVH
     376           19 :       rq% logT_all_OPAL = logT_all_OPAL
     377           19 :       rq% logRho1_OPAL_SCVH_limit = logRho1_OPAL_SCVH_limit
     378           19 :       rq% logRho2_OPAL_SCVH_limit = logRho2_OPAL_SCVH_limit
     379           19 :       rq% logRho_min_OPAL_SCVH_limit = logRho_min_OPAL_SCVH_limit
     380           19 :       rq% logQ_max_OPAL_SCVH = logQ_max_OPAL_SCVH
     381           19 :       rq% logQ_min_OPAL_SCVH = logQ_min_OPAL_SCVH
     382           19 :       rq% Z_all_OPAL = Z_all_OPAL
     383              :       ! controls for FreeEOS
     384           19 :       rq% use_FreeEOS = use_FreeEOS
     385           19 :       rq% logQ_max_FreeEOS_hi = logQ_max_FreeEOS_hi
     386           19 :       rq% logQ_max_FreeEOS_lo = logQ_max_FreeEOS_lo
     387           19 :       rq% logQ_min_FreeEOS_hi = logQ_min_FreeEOS_hi
     388           19 :       rq% logQ_min_FreeEOS_lo = logQ_min_FreeEOS_lo
     389           19 :       rq% logRho_min_FreeEOS_hi = logRho_min_FreeEOS_hi
     390           19 :       rq% logRho_min_FreeEOS_lo = logRho_min_FreeEOS_lo
     391           19 :       rq% logRho_max_FreeEOS_hi = logRho_max_FreeEOS_hi
     392           19 :       rq% logRho_max_FreeEOS_lo = logRho_max_FreeEOS_lo
     393           19 :       rq% logT_min_FreeEOS_hi = logT_min_FreeEOS_hi
     394           19 :       rq% logT_min_FreeEOS_lo = logT_min_FreeEOS_lo
     395           19 :       rq% logT_max_FreeEOS_hi = logT_max_FreeEOS_hi
     396           19 :       rq% logT_max_FreeEOS_lo = logT_max_FreeEOS_lo
     397           19 :       rq% logQ_cut_FreeEOS_lo_Z_max = logQ_cut_FreeEOS_lo_Z_max
     398           19 :       rq% logQ_cut_lo_Z_FreeEOS_hi = logQ_cut_lo_Z_FreeEOS_hi
     399           19 :       rq% logQ_cut_lo_Z_FreeEOS_lo = logQ_cut_lo_Z_FreeEOS_lo
     400           19 :       rq% logQ_cut_hi_Z_FreeEOS_hi = logQ_cut_hi_Z_FreeEOS_hi
     401           19 :       rq% logQ_cut_hi_Z_FreeEOS_lo = logQ_cut_hi_Z_FreeEOS_lo
     402           19 :       rq% logRho_cut_FreeEOS_hi = logRho_cut_FreeEOS_hi
     403           19 :       rq% logRho_cut_FreeEOS_lo = logRho_cut_FreeEOS_lo
     404           19 :       rq% logT_cut_FreeEOS_hi = logT_cut_FreeEOS_hi
     405           19 :       rq% logT_cut_FreeEOS_lo = logT_cut_FreeEOS_lo
     406              :       rq% suffix_for_FreeEOS_Z(1:num_FreeEOS_Zs) = &
     407          304 :          suffix_for_FreeEOS_Z(1:num_FreeEOS_Zs)
     408              :       ! controls for CMS
     409           19 :       rq% use_CMS = use_CMS
     410           19 :       rq% CMS_use_fixed_composition = CMS_use_fixed_composition
     411           19 :       rq% CMS_fixed_composition_index = CMS_fixed_composition_index
     412           19 :       rq% max_Z_for_any_CMS = max_Z_for_any_CMS
     413           19 :       rq% max_Z_for_all_CMS = max_Z_for_all_CMS
     414           19 :       rq% logQ_max_for_any_CMS = logQ_max_for_any_CMS
     415           19 :       rq% logQ_max_for_all_CMS = logQ_max_for_all_CMS
     416           19 :       rq% logQ_min_for_any_CMS = logQ_min_for_any_CMS
     417           19 :       rq% logQ_min_for_all_CMS = logQ_min_for_all_CMS
     418           19 :       rq% logRho_max_for_all_CMS = logRho_max_for_all_CMS
     419           19 :       rq% logRho_max_for_any_CMS = logRho_max_for_any_CMS
     420           19 :       rq% logRho_min_for_all_CMS = logRho_min_for_all_CMS
     421           19 :       rq% logRho_min_for_any_CMS = logRho_min_for_any_CMS
     422           19 :       rq% logT_max_for_all_CMS = logT_max_for_all_CMS
     423           19 :       rq% logT_max_for_any_CMS = logT_max_for_any_CMS
     424           19 :       rq% logT_min_for_all_CMS = logT_min_for_all_CMS
     425           19 :       rq% logT_min_for_any_CMS = logT_min_for_any_CMS
     426           19 :       rq% logT_max_for_all_CMS_pure_He = logT_max_for_all_CMS_pure_He
     427           19 :       rq% logT_max_for_any_CMS_pure_He = logT_max_for_any_CMS_pure_He
     428              :       ! controls for PC
     429           19 :       rq% use_PC = use_PC
     430           19 :       rq% mass_fraction_limit_for_PC = mass_fraction_limit_for_PC
     431           19 :       rq% logRho1_PC_limit = logRho1_PC_limit
     432           19 :       rq% logRho2_PC_limit = logRho2_PC_limit
     433           19 :       rq% PC_use_Gamma_limit_instead_of_T = PC_use_Gamma_limit_instead_of_T
     434           19 :       rq% logT1_PC_limit = logT1_PC_limit
     435           19 :       rq% logT2_PC_limit = logT2_PC_limit
     436           19 :       rq% log_Gamma_e_all_HELM = log_Gamma_e_all_HELM
     437           19 :       rq% log_Gamma_e_all_PC = log_Gamma_e_all_PC
     438           19 :       rq% PC_Gamma_start_crystal = PC_Gamma_start_crystal
     439           19 :       rq% PC_Gamma_full_crystal = PC_Gamma_full_crystal
     440              :       ! controls for Skye
     441           19 :       rq% use_Skye = use_Skye
     442           19 :       rq% Skye_use_ion_offsets = Skye_use_ion_offsets
     443           19 :       rq% mass_fraction_limit_for_Skye = mass_fraction_limit_for_Skye
     444           19 :       rq%Skye_min_gamma_for_solid = Skye_min_gamma_for_solid
     445           19 :       rq%Skye_max_gamma_for_liquid = Skye_max_gamma_for_liquid
     446           19 :       rq%Skye_solid_mixing_rule = Skye_solid_mixing_rule
     447           19 :       rq% use_simple_Skye_blends = use_simple_Skye_blends
     448           19 :       rq% logRho_min_for_any_Skye = logRho_min_for_any_Skye
     449           19 :       rq% logRho_min_for_all_Skye = logRho_min_for_all_Skye
     450           19 :       rq% logT_min_for_any_Skye = logT_min_for_any_Skye
     451           19 :       rq% logT_min_for_all_Skye = logT_min_for_all_Skye
     452              : 
     453              :       ! misc
     454           19 :       rq% include_radiation = include_radiation
     455           19 :       rq% include_elec_pos = include_elec_pos
     456           19 :       rq% eosDT_use_linear_interp_for_X = eosDT_use_linear_interp_for_X
     457           19 :       rq% eosDT_use_linear_interp_to_HELM = eosDT_use_linear_interp_to_HELM
     458           19 :       rq% eosDT_file_prefix = eosDT_file_prefix
     459           19 :       rq% okay_to_convert_ierr_to_skip = okay_to_convert_ierr_to_skip
     460           19 :       rq% tiny_fuzz = tiny_fuzz
     461              : 
     462              :       ! other eos
     463           19 :       rq% use_other_eos_component = use_other_eos_component
     464           19 :       rq% use_other_eos_results = use_other_eos_results
     465              : 
     466              :       ! user inputs
     467          209 :       rq% eos_ctrl = eos_ctrl
     468          209 :       rq% eos_integer_ctrl = eos_integer_ctrl
     469          209 :       rq% eos_logical_ctrl = eos_logical_ctrl
     470          209 :       rq% eos_character_ctrl = eos_character_ctrl
     471              : 
     472              :       ! debugging
     473           19 :       rq% dbg = dbg
     474           19 :       rq% logT_lo = logT_lo
     475           19 :       rq% logT_hi = logT_hi
     476           19 :       rq% logRho_lo = logRho_lo
     477           19 :       rq% logRho_hi = logRho_hi
     478           19 :       rq% X_lo = X_lo
     479           19 :       rq% X_hi = X_hi
     480           19 :       rq% Z_lo = Z_lo
     481           19 :       rq% Z_hi = Z_hi
     482           19 :    end subroutine store_controls
     483              : 
     484              : 
     485            0 :    subroutine write_namelist(handle, filename, ierr)
     486              :       integer, intent(in) :: handle
     487              :       character(*), intent(in) :: filename
     488              :       integer, intent(out) :: ierr
     489              :       type (EoS_General_Info), pointer :: rq
     490              :       integer :: iounit
     491              :       open(newunit=iounit, file=trim(filename), &
     492            0 :          action='write', status='replace', iostat=ierr)
     493            0 :       if (ierr /= 0) then
     494            0 :          write(*,*) 'failed to open ' // trim(filename)
     495            0 :          return
     496              :       end if
     497            0 :       call get_eos_ptr(handle,rq,ierr)
     498            0 :       if (ierr /= 0) then
     499            0 :          close(iounit)
     500            0 :          return
     501              :       end if
     502            0 :       call set_controls_for_writing(rq)
     503            0 :       write(iounit, nml=eos, iostat=ierr)
     504            0 :       close(iounit)
     505              :    end subroutine write_namelist
     506              : 
     507              : 
     508            0 :    subroutine set_controls_for_writing(rq)
     509              :       type (EoS_General_Info), pointer :: rq
     510              :       ! controls for HELM
     511            0 :       Z_all_HELM = rq% Z_all_HELM
     512            0 :       logT_all_HELM = rq% logT_all_HELM
     513            0 :       logT_low_all_HELM = rq% logT_low_all_HELM
     514            0 :       coulomb_temp_cut_HELM = rq% coulomb_temp_cut_HELM
     515            0 :       coulomb_den_cut_HELM = rq% coulomb_den_cut_HELM
     516              :       ! controls for OPAL_SCVH
     517            0 :       use_OPAL_SCVH = rq% use_OPAL_SCVH
     518            0 :       logT_low_all_SCVH = rq% logT_low_all_SCVH
     519            0 :       logT_all_OPAL = rq% logT_all_OPAL
     520            0 :       logRho1_OPAL_SCVH_limit = rq% logRho1_OPAL_SCVH_limit
     521            0 :       logRho2_OPAL_SCVH_limit = rq% logRho2_OPAL_SCVH_limit
     522            0 :       logRho_min_OPAL_SCVH_limit = rq% logRho_min_OPAL_SCVH_limit
     523            0 :       logQ_max_OPAL_SCVH = rq% logQ_max_OPAL_SCVH
     524            0 :       logQ_min_OPAL_SCVH = rq% logQ_min_OPAL_SCVH
     525            0 :       Z_all_OPAL = rq% Z_all_OPAL
     526              :       ! controls for FreeEOS
     527            0 :       use_FreeEOS = rq% use_FreeEOS
     528            0 :       logQ_max_FreeEOS_hi = rq% logQ_max_FreeEOS_hi
     529            0 :       logQ_max_FreeEOS_lo = rq% logQ_max_FreeEOS_lo
     530            0 :       logQ_min_FreeEOS_hi = rq% logQ_min_FreeEOS_hi
     531            0 :       logQ_min_FreeEOS_lo = rq% logQ_min_FreeEOS_lo
     532            0 :       logRho_min_FreeEOS_hi = rq% logRho_min_FreeEOS_hi
     533            0 :       logRho_min_FreeEOS_lo = rq% logRho_min_FreeEOS_lo
     534            0 :       logRho_max_FreeEOS_hi = rq% logRho_max_FreeEOS_hi
     535            0 :       logRho_max_FreeEOS_lo = rq% logRho_max_FreeEOS_lo
     536            0 :       logT_min_FreeEOS_hi = rq% logT_min_FreeEOS_hi
     537            0 :       logT_min_FreeEOS_lo = rq% logT_min_FreeEOS_lo
     538            0 :       logT_max_FreeEOS_hi = rq% logT_max_FreeEOS_hi
     539            0 :       logT_max_FreeEOS_lo = rq% logT_max_FreeEOS_lo
     540            0 :       logQ_cut_FreeEOS_lo_Z_max = rq% logQ_cut_FreeEOS_lo_Z_max
     541            0 :       logQ_cut_lo_Z_FreeEOS_hi = rq% logQ_cut_lo_Z_FreeEOS_hi
     542            0 :       logQ_cut_lo_Z_FreeEOS_lo = rq% logQ_cut_lo_Z_FreeEOS_lo
     543            0 :       logQ_cut_hi_Z_FreeEOS_hi = rq% logQ_cut_hi_Z_FreeEOS_hi
     544            0 :       logQ_cut_hi_Z_FreeEOS_lo = rq% logQ_cut_hi_Z_FreeEOS_lo
     545            0 :       logRho_cut_FreeEOS_hi = rq% logRho_cut_FreeEOS_hi
     546            0 :       logRho_cut_FreeEOS_lo = rq% logRho_cut_FreeEOS_lo
     547            0 :       logT_cut_FreeEOS_hi = rq% logT_cut_FreeEOS_hi
     548            0 :       logT_cut_FreeEOS_lo = rq% logT_cut_FreeEOS_lo
     549              :       suffix_for_FreeEOS_Z(1:num_FreeEOS_Zs) = &
     550            0 :          rq% suffix_for_FreeEOS_Z(1:num_FreeEOS_Zs)
     551              :       ! controls for CMS
     552            0 :       use_CMS = rq% use_CMS
     553            0 :       CMS_use_fixed_composition = rq% CMS_use_fixed_composition
     554            0 :       CMS_fixed_composition_index = rq% CMS_fixed_composition_index
     555            0 :       max_Z_for_any_CMS = rq% max_Z_for_any_CMS
     556            0 :       max_Z_for_all_CMS = rq% max_Z_for_all_CMS
     557            0 :       logQ_max_for_any_CMS = rq% logQ_max_for_any_CMS
     558            0 :       logQ_max_for_all_CMS = rq% logQ_max_for_all_CMS
     559            0 :       logQ_min_for_any_CMS = rq% logQ_min_for_any_CMS
     560            0 :       logQ_min_for_all_CMS = rq% logQ_min_for_all_CMS
     561            0 :       logRho_max_for_all_CMS = rq% logRho_max_for_all_CMS
     562            0 :       logRho_max_for_any_CMS = rq% logRho_max_for_any_CMS
     563            0 :       logRho_min_for_all_CMS = rq% logRho_min_for_all_CMS
     564            0 :       logRho_min_for_any_CMS = rq% logRho_min_for_any_CMS
     565            0 :       logT_max_for_all_CMS = rq% logT_max_for_all_CMS
     566            0 :       logT_max_for_any_CMS = rq% logT_max_for_any_CMS
     567            0 :       logT_min_for_all_CMS = rq% logT_min_for_all_CMS
     568            0 :       logT_min_for_any_CMS = rq% logT_min_for_any_CMS
     569            0 :       logT_max_for_all_CMS_pure_He = rq% logT_max_for_all_CMS_pure_He
     570            0 :       logT_max_for_any_CMS_pure_He = rq% logT_max_for_any_CMS_pure_He
     571              :       ! controls for PC
     572            0 :       use_PC = rq% use_PC
     573            0 :       mass_fraction_limit_for_PC = rq% mass_fraction_limit_for_PC
     574            0 :       logRho1_PC_limit = rq% logRho1_PC_limit
     575            0 :       logRho2_PC_limit = rq% logRho2_PC_limit
     576            0 :       PC_use_Gamma_limit_instead_of_T = rq% PC_use_Gamma_limit_instead_of_T
     577            0 :       logT1_PC_limit = rq% logT1_PC_limit
     578            0 :       logT2_PC_limit = rq% logT2_PC_limit
     579            0 :       log_Gamma_e_all_HELM = rq% log_Gamma_e_all_HELM
     580            0 :       log_Gamma_e_all_PC = rq% log_Gamma_e_all_PC
     581            0 :       PC_Gamma_start_crystal = rq% PC_Gamma_start_crystal
     582            0 :       PC_Gamma_full_crystal = rq% PC_Gamma_full_crystal
     583              :       ! controls for Skye
     584            0 :       use_Skye = rq% use_Skye
     585            0 :       Skye_use_ion_offsets = rq% Skye_use_ion_offsets
     586            0 :       mass_fraction_limit_for_Skye = rq% mass_fraction_limit_for_Skye
     587            0 :       Skye_min_gamma_for_solid = rq% Skye_min_gamma_for_solid
     588            0 :       Skye_max_gamma_for_liquid = rq% Skye_max_gamma_for_liquid
     589            0 :       Skye_solid_mixing_rule = rq% Skye_solid_mixing_rule
     590            0 :       use_simple_Skye_blends = rq% use_simple_Skye_blends
     591            0 :       logRho_min_for_any_Skye = rq% logRho_min_for_any_Skye
     592            0 :       logRho_min_for_all_Skye = rq% logRho_min_for_all_Skye
     593            0 :       logT_min_for_any_Skye = rq% logT_min_for_any_Skye
     594            0 :       logT_min_for_all_Skye = rq% logT_min_for_all_Skye
     595              : 
     596              :       ! misc
     597            0 :       include_radiation = rq% include_radiation
     598            0 :       include_elec_pos = rq% include_elec_pos
     599            0 :       eosDT_use_linear_interp_for_X = rq% eosDT_use_linear_interp_for_X
     600            0 :       eosDT_use_linear_interp_to_HELM = rq% eosDT_use_linear_interp_to_HELM
     601            0 :       eosDT_file_prefix = rq% eosDT_file_prefix
     602            0 :       okay_to_convert_ierr_to_skip = rq% okay_to_convert_ierr_to_skip
     603            0 :       tiny_fuzz = rq% tiny_fuzz
     604              : 
     605              :       ! other eos
     606            0 :       use_other_eos_component = rq% use_other_eos_component
     607            0 :       use_other_eos_results = rq% use_other_eos_results
     608              : 
     609              :       ! user inputs
     610            0 :       eos_ctrl = rq% eos_ctrl
     611            0 :       eos_integer_ctrl = rq% eos_integer_ctrl
     612            0 :       eos_logical_ctrl = rq% eos_logical_ctrl
     613            0 :       eos_character_ctrl = rq% eos_character_ctrl
     614              : 
     615              :       ! debugging
     616            0 :       dbg = rq% dbg
     617            0 :       logT_lo = rq% logT_lo
     618            0 :       logT_hi = rq% logT_hi
     619            0 :       logRho_lo = rq% logRho_lo
     620            0 :       logRho_hi = rq% logRho_hi
     621            0 :       X_lo = rq% X_lo
     622            0 :       X_hi = rq% X_hi
     623            0 :       Z_lo = rq% Z_lo
     624            0 :       Z_hi = rq% Z_hi
     625            0 :    end subroutine set_controls_for_writing
     626              : 
     627              : 
     628            0 :    subroutine get_eos_controls(rq, name, val, ierr)
     629              :       use utils_lib, only: StrUpCase
     630              :       type (EoS_General_Info), pointer :: rq
     631              :       character(len=*),intent(in) :: name
     632              :       character(len=*), intent(out) :: val
     633              :       integer, intent(out) :: ierr
     634              : 
     635            0 :       character(len(name)+1) :: upper_name
     636              :       character(len=512) :: str
     637              :       integer :: iounit,iostat,ind,i
     638              : 
     639            0 :       ierr = 0
     640              : 
     641              : 
     642              :       ! First save current controls
     643            0 :       call set_controls_for_writing(rq)
     644              : 
     645              :       ! Write namelist to temporary file
     646            0 :       open(newunit=iounit,status='scratch')
     647            0 :       write(iounit,nml=eos)
     648            0 :       rewind(iounit)
     649              : 
     650              :       ! Namelists get written in capitals
     651            0 :       upper_name = trim(StrUpCase(name))//'='
     652            0 :       val = ''
     653              :       ! Search for name inside namelist
     654              :       do
     655            0 :          read(iounit,'(A)',iostat=iostat) str
     656            0 :          ind = index(trim(str),trim(upper_name))
     657            0 :          if( ind /= 0 ) then
     658            0 :             val = str(ind+len_trim(upper_name):len_trim(str)-1)  ! Remove final comma and starting =
     659            0 :             do i=1,len(val)
     660            0 :                if(val(i:i)=='"') val(i:i) = ' '
     661              :             end do
     662              :             exit
     663              :          end if
     664            0 :          if(is_iostat_end(iostat)) exit
     665              :       end do
     666              : 
     667            0 :       if(len_trim(val) == 0 .and. ind==0 ) ierr = -1
     668              : 
     669            0 :       close(iounit)
     670              : 
     671            0 :    end subroutine get_eos_controls
     672              : 
     673            0 :    subroutine set_eos_controls(rq, name, val, ierr)
     674              :       type (EoS_General_Info), pointer :: rq
     675              :       character(len=*), intent(in) :: name, val
     676            0 :       character(len=len(name)+len(val)+8) :: tmp
     677              :       integer, intent(out) :: ierr
     678              : 
     679            0 :       ierr = 0
     680              : 
     681              :       ! First save current eos_controls
     682            0 :       call set_controls_for_writing(rq)
     683              : 
     684            0 :       tmp=''
     685            0 :       tmp = '&eos '//trim(name)//'='//trim(val)//' /'
     686              : 
     687              :       ! Load into namelist
     688            0 :       read(tmp, nml=eos)
     689              : 
     690              :       ! Add to eos
     691            0 :       call store_controls(rq)
     692            0 :       if(ierr/=0) return
     693              : 
     694              :    end subroutine set_eos_controls
     695              : 
     696              : 
     697              :    end module eos_ctrls_io
        

Generated by: LCOV version 2.0-1