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