LCOV - code coverage report
Current view: top level - star/private - init.f90 (source / functions) Coverage Total Hit
Test: coverage.info Lines: 70.7 % 673 476
Test Date: 2025-05-08 18:23:42 Functions: 38.5 % 26 10

            Line data    Source code
       1              : ! ***********************************************************************
       2              : !
       3              : !   Copyright (C) 2010  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 init
      21              : 
      22              :       use star_private_def
      23              :       use const_def, only: dp, msun, secyer
      24              : 
      25              :       implicit none
      26              : 
      27              :       private
      28              :       public :: alloc_star_data
      29              :       public :: set_starting_star_data
      30              :       public :: do_star_init
      31              :       public :: do_starlib_shutdown
      32              :       public :: set_kap_and_eos_handles
      33              :       public :: load_zams_model
      34              :       public :: create_pre_ms_model
      35              :       public :: create_initial_model
      36              :       public :: create_RSP_model
      37              :       public :: create_RSP2_model
      38              :       public :: doing_restart
      39              :       public :: load_restart_photo
      40              :       public :: load_saved_model
      41              :       public :: do_garbage_collection
      42              : 
      43              :       integer, parameter :: do_create_pre_ms_model = 0
      44              :       integer, parameter :: do_load_zams_model = 1
      45              :       integer, parameter :: do_load_saved_model = 2
      46              :       integer, parameter :: do_create_initial_model = 3
      47              :       integer, parameter :: do_create_RSP_model = 4
      48              :       integer, parameter :: do_create_RSP2_model = 5
      49              : 
      50              :       logical :: have_done_starlib_init = .false.
      51              : 
      52              :       contains
      53              : 
      54            1 :       subroutine set_kap_and_eos_handles(id, ierr)
      55              :          use kap_lib, only: alloc_kap_handle_using_inlist, kap_ptr
      56              :          use eos_lib, only: alloc_eos_handle_using_inlist, eos_ptr
      57              :          integer, intent(in) :: id
      58              :          integer, intent(out) :: ierr  ! 0 means AOK.
      59              :          type (star_info), pointer :: s
      60            1 :          call get_star_ptr(id, s, ierr)
      61            1 :          if (ierr /= 0) then
      62            0 :             write(*,*) 'get_star_ptr failed in alloc_eos_handle'
      63            0 :             return
      64              :          end if
      65            1 :          if (s% eos_handle == 0) then
      66            1 :             s% eos_handle = alloc_eos_handle_using_inlist(s% inlist_fname, ierr)
      67            1 :             if (ierr /= 0) then
      68            0 :                write(*,*) 'set_kap_and_eos_handles failed in alloc_eos_handle_using_inlist'
      69            0 :                return
      70              :             end if
      71            1 :             call eos_ptr(s% eos_handle, s% eos_rq, ierr)
      72            1 :             if (ierr /= 0) then
      73            0 :                write(*,*) 'eos_ptr failed in alloc_eos_handle'
      74            0 :                return
      75              :             end if
      76              :          end if
      77            1 :          if (s% kap_handle == 0) then
      78            1 :             s% kap_handle = alloc_kap_handle_using_inlist(s% inlist_fname, ierr)
      79            1 :             if (ierr /= 0) then
      80            0 :                write(*,*) 'set_kap_and_eos_handles failed in alloc_kap_handle_using_inlist'
      81            0 :                return
      82              :             end if
      83            1 :             call kap_ptr(s% kap_handle,s% kap_rq,ierr)
      84            1 :             if (ierr /= 0) then
      85            0 :                write(*,*) 'kap_ptr failed in alloc_kap_handle'
      86            0 :                return
      87              :             end if
      88              :          end if
      89            1 :       end subroutine set_kap_and_eos_handles
      90              : 
      91              : 
      92            1 :       subroutine do_star_init( &
      93              :             my_mesa_dir, chem_isotopes_filename, &
      94              :             net_reaction_filename, jina_reaclib_filename, &
      95              :             use_suzuki_weak_rates, &
      96              :             use_special_weak_rates, special_weak_states_file, special_weak_transitions_file, &
      97              :             reaclib_min_T9, &
      98              :             rate_tables_dir, rates_cache_suffix, &
      99              :             ionization_file_prefix, ionization_Z1_suffix, &
     100              :             eosDT_cache_dir, &
     101              :             ionization_cache_dir, kap_cache_dir, rates_cache_dir, &
     102            1 :             color_num_files,color_file_names,color_num_colors,&
     103              :             ierr)
     104            1 :          use paquette_coeffs, only: initialise_collision_integrals
     105              :          use alloc, only: init_alloc
     106              :          character (len=*), intent(in) :: &
     107              :             my_mesa_dir, chem_isotopes_filename, net_reaction_filename, &
     108              :             jina_reaclib_filename, rate_tables_dir, &
     109              :             special_weak_states_file, special_weak_transitions_file, &
     110              :             rates_cache_suffix, &
     111              :             ionization_file_prefix, ionization_Z1_suffix, &
     112              :             eosDT_cache_dir, &
     113              :             ionization_cache_dir, kap_cache_dir, rates_cache_dir
     114              :          logical, intent(in) :: use_suzuki_weak_rates, use_special_weak_rates
     115              :          real(dp), intent(in) :: reaclib_min_T9
     116              :          integer, intent(in) :: color_num_files
     117              :          character (len=*), intent(in) :: color_file_names(:)
     118              :          integer , intent(in):: color_num_colors(:)
     119              :          integer, intent(out) :: ierr
     120              :          include 'formats'
     121            1 :          ierr = 0
     122            1 :          if (have_done_starlib_init) return
     123            1 :          call initialise_collision_integrals
     124            1 :          call init_alloc
     125              :          call stardata_init( &
     126              :             my_mesa_dir, chem_isotopes_filename, &
     127              :             net_reaction_filename, jina_reaclib_filename, &
     128              :             use_suzuki_weak_rates, &
     129              :             use_special_weak_rates, special_weak_states_file, special_weak_transitions_file, &
     130              :             reaclib_min_T9, &
     131              :             rate_tables_dir, rates_cache_suffix, &
     132              :             ionization_file_prefix, ionization_Z1_suffix, &
     133              :             eosDT_cache_dir, &
     134              :             ionization_cache_dir, kap_cache_dir, rates_cache_dir, &
     135              :             color_num_files,color_file_names,color_num_colors,&
     136            1 :             ierr)
     137            1 :          if (ierr /= 0) then
     138            0 :             write(*,*) 'failed in stardata_init'
     139            0 :             return
     140              :          end if
     141              : 
     142            1 :          have_done_starlib_init = .true.
     143              : 
     144            1 :       end subroutine do_star_init
     145              : 
     146              : 
     147            1 :       subroutine do_starlib_shutdown
     148              : 
     149            1 :         use alloc, only: shutdown_alloc
     150              :         use micro, only: shutdown_microphys
     151              :         use atm_lib, only: atm_shutdown
     152              :         use colors_lib, only: colors_shutdown
     153              :         use chem_lib, only: chem_shutdown
     154              :         use rates_lib, only: rates_shutdown
     155              :         use star_profile_def, only: profile_column_names_shutdown
     156              :         use star_history_def, only: history_column_names_shutdown
     157              :         use paquette_coeffs, only: free_collision_integrals
     158              : 
     159            1 :         call rates_shutdown()
     160            1 :         call atm_shutdown()
     161            1 :         call shutdown_microphys()
     162            1 :         call colors_shutdown()
     163            1 :         call chem_shutdown()
     164            1 :         call profile_column_names_shutdown()
     165            1 :         call history_column_names_shutdown()
     166              : 
     167            1 :         call free_collision_integrals()
     168              : 
     169            1 :         call shutdown_alloc()
     170              : 
     171            1 :         have_done_starlib_init = .false.
     172              : 
     173            1 :       end subroutine do_starlib_shutdown
     174              : 
     175              : 
     176            2 :       subroutine alloc_star_data(id, ierr)
     177            1 :          use chem_def, only: num_categories
     178              :          use net, only: default_set_rate_factors, &
     179              :             default_set_op_mono_factors
     180              : 
     181              : 
     182              :          integer, intent(out) :: id, ierr
     183              : 
     184              :          type (star_info), pointer :: s
     185              :          integer, parameter :: init_alloc_nvar = 20
     186              :          character (len=32) :: extra_name
     187              :          integer :: i
     188              : 
     189              :          ierr = 0
     190              : 
     191            2 :          call alloc_star(id, ierr)
     192            2 :          if (ierr /= 0) then
     193            0 :             write(*,*) 'alloc_star_data failed in alloc_star'
     194            0 :             return
     195              :          end if
     196              : 
     197            2 :          call get_star_ptr(id, s, ierr)
     198            2 :          if (ierr /= 0) then
     199            0 :             write(*,*) 'alloc_star_data failed in get_star_ptr'
     200            0 :             return
     201              :          end if
     202              : 
     203            2 :          nullify(s% dq)
     204            2 :          nullify(s% xa)
     205            2 :          nullify(s% xh)
     206              : 
     207              :          nullify( &
     208            2 :             s% op_mono_umesh1, s% op_mono_semesh1, s% op_mono_ff1, &
     209            2 :             s% op_mono_rs1)
     210              : 
     211            2 :          nullify(s% atm_structure)
     212            2 :          s% atm_structure_num_pts = 0
     213              : 
     214            2 :          nullify(s% chem_id)
     215            2 :          nullify(s% xa_removed)
     216              : 
     217            2 :          nullify(s% rate_factors)
     218            2 :          s% set_rate_factors => default_set_rate_factors
     219              : 
     220            2 :          nullify(s% op_mono_factors)
     221            2 :          s% set_op_mono_factors => default_set_op_mono_factors
     222              : 
     223            2 :          allocate(s% nameofvar(init_alloc_nvar),stat=ierr)
     224            2 :          if (ierr /= 0) return
     225              : 
     226            2 :          allocate(s% nameofequ(init_alloc_nvar),stat=ierr)
     227            2 :          if (ierr /= 0) return
     228              : 
     229            2 :          nullify(s% history_values)
     230            2 :          nullify(s% history_value_is_integer)
     231            2 :          nullify(s% history_names)
     232            2 :          nullify(s% history_names_dict)
     233              : 
     234            2 :          nullify(s% prev_mesh_xh)
     235            2 :          nullify(s% prev_mesh_xa)
     236            2 :          nullify(s% prev_mesh_j_rot)
     237            2 :          nullify(s% prev_mesh_omega)
     238            2 :          nullify(s% prev_mesh_dq)
     239              : 
     240            2 :          nullify(s% D_ST_start)
     241            2 :          nullify(s% prev_mesh_D_ST_start)
     242              : 
     243            2 :          nullify(s% other_star_info)
     244              : 
     245            2 :          nullify(s% bcyclic_odd_storage)
     246            2 :          nullify(s% bcyclic_odd_storage_qp)
     247              : 
     248            2 :          nullify(s% solver_iwork)
     249            2 :          nullify(s% solver_work)
     250            2 :          nullify(s% AF1)
     251              : 
     252            2 :          s% net_name = ''
     253            2 :          s% species = 0
     254            2 :          s% num_reactions = 0
     255              : 
     256            2 :          s% M_center = 0
     257            2 :          s% R_center = 0
     258            2 :          s% v_center = 0
     259            2 :          s% L_center = 0
     260              : 
     261            2 :          nullify(s% profile_column_spec)
     262            2 :          nullify(s% history_column_spec)
     263              : 
     264            2 :          s% num_conv_boundaries = 0
     265            2 :          nullify(s% conv_bdy_q)
     266            2 :          nullify(s% conv_bdy_loc)
     267            2 :          nullify(s% top_conv_bdy)
     268              : 
     269            2 :          s% num_mix_boundaries = 0
     270            2 :          nullify(s% mix_bdy_q)
     271            2 :          nullify(s% mix_bdy_loc)
     272            2 :          nullify(s% top_mix_bdy)
     273              : 
     274            2 :          nullify(s% burn_h_conv_region)
     275            2 :          nullify(s% burn_he_conv_region)
     276            2 :          nullify(s% burn_z_conv_region)
     277              : 
     278            2 :          s% have_burner_storage = .false.
     279            2 :          s% burner_num_threads = 0
     280            2 :          nullify(s% burner_storage)
     281              : 
     282            2 :          s% doing_timing = .false.
     283            2 :          s% time_evolve_step = 0
     284            2 :          s% time_remesh = 0
     285            2 :          s% time_adjust_mass = 0
     286            2 :          s% time_conv_premix = 0
     287            2 :          s% time_element_diffusion = 0
     288            2 :          s% time_struct_burn_mix = 0
     289            2 :          s% time_solver_matrix = 0
     290            2 :          s% time_solve_mix = 0
     291            2 :          s% time_solve_burn = 0
     292            2 :          s% time_solve_omega_mix = 0
     293            2 :          s% time_eos = 0
     294            2 :          s% time_neu_kap = 0
     295            2 :          s% time_nonburn_net = 0
     296            2 :          s% time_mlt = 0
     297            2 :          s% time_set_hydro_vars = 0
     298            2 :          s% time_set_mixing_info = 0
     299            2 :          s% time_total = 0
     300              : 
     301            2 :          s% timing_num_get_eos_calls = 0
     302            2 :          s% timing_num_solve_eos_calls = 0
     303            2 :          s% timing_num_get_kap_calls = 0
     304              : 
     305            2 :          s% model_profile_filename = ''
     306            2 :          s% most_recent_profile_filename = ''
     307              : 
     308            2 :          s% model_controls_filename = ''
     309            2 :          s% most_recent_controls_filename = ''
     310              : 
     311            2 :          s% most_recent_photo_name = ''
     312              : 
     313            2 :          s% doing_flash_wind = .false.
     314            2 :          s% doing_rlo_wind = .false.
     315              : 
     316            2 :          s% phase_of_evolution = phase_starting
     317            2 :          s% recent_log_header = -1000
     318              : 
     319            2 :          s% tau_base = 2d0/3d0
     320            2 :          s% tau_factor = 1
     321              : 
     322            2 :          s% solver_iter = 0
     323              : 
     324            2 :          s% using_gold_tolerances = .false.
     325            2 :          s% using_velocity_time_centering = .false.
     326              : 
     327            2 :          s% using_revised_net_name = .false.
     328            2 :          s% revised_net_name = ''
     329              : 
     330            2 :          s% using_revised_max_yr_dt = .false.
     331            2 :          s% revised_max_yr_dt = 0
     332              : 
     333            2 :          s% astero_using_revised_max_yr_dt = .false.
     334            2 :          s% astero_revised_max_yr_dt = 0
     335              : 
     336            2 :          s% cumulative_energy_error = 0
     337            2 :          s% cumulative_extra_heating = 0
     338              : 
     339            2 :          s% have_initial_energy_integrals = .false.
     340              : 
     341            2 :          s% num_solver_iterations = 0
     342            2 :          s% mesh_call_number = 0
     343            2 :          s% solver_call_number = 0
     344            2 :          s% diffusion_call_number = 0
     345            2 :          s% model_number = 0
     346            2 :          s% RSP_have_set_velocities = .false.
     347            2 :          s% RSP_just_set_velocities = .false.
     348            2 :          s% rsp_period = 0d0
     349              : 
     350            2 :          s% dt = 0d0
     351            2 :          s% mstar_dot = 0d0
     352              : 
     353            2 :          s% power_nuc_burn = -1
     354            2 :          s% power_h_burn = -1
     355            2 :          s% power_he_burn = -1
     356            2 :          s% power_z_burn = -1
     357            2 :          s% power_photo = -1
     358              : 
     359            2 :          s% k_const_mass = 1
     360            2 :          s% k_below_just_added = 1
     361            2 :          s% k_below_const_q = 1
     362              : 
     363            2 :          s% why_Tlim = Tlim_struc
     364          118 :          s% dt_why_count(:) = 0
     365          118 :          s% dt_why_retry_count(:) = 0
     366              : 
     367            2 :          s% len_extra_iwork = 0
     368            2 :          s% len_extra_work = 0
     369              : 
     370            2 :          s% eos_handle = 0
     371            2 :          s% kap_handle = 0
     372              : 
     373          202 :          do i = 1, max_num_profile_extras
     374          200 :             if (i < 10) then
     375           18 :                write(extra_name,'(a,i1)') 'profile_extra_', i
     376          182 :             else if (i < 100) then
     377          180 :                write(extra_name,'(a,i2)') 'profile_extra_', i
     378              :             else
     379            2 :                write(extra_name,'(a,i3)') 'profile_extra_', i
     380              :             end if
     381          202 :             s% profile_extra_name(i) = trim(extra_name)
     382              :          end do
     383              : 
     384            2 :          call set_starting_star_data(s, ierr)
     385            2 :          if (ierr /= 0) then
     386            0 :             write(*,*) 'alloc_star_data failed in set_starting_star_data'
     387            0 :             return
     388              :          end if
     389              : 
     390            8 :       end subroutine alloc_star_data
     391              : 
     392              : 
     393           11 :       subroutine null_other_new_generation(id, ierr)
     394              :          integer, intent(in) :: id
     395              :          integer, intent(out) :: ierr
     396           11 :          ierr = 0
     397            2 :       end subroutine null_other_new_generation
     398              : 
     399              : 
     400           11 :       subroutine null_other_set_current_to_old(id)
     401              :          integer, intent(in) :: id
     402           11 :       end subroutine null_other_set_current_to_old
     403              : 
     404              : 
     405            2 :       subroutine set_starting_star_data(s, ierr)
     406              :          use other_wind, only: null_other_wind
     407              :          use other_accreting_state, only: null_other_accreting_state
     408              :          use other_adjust_mdot, only: null_other_adjust_mdot
     409              :          use other_j_for_adjust_J_lost, only: null_other_j_for_adjust_J_lost
     410              :          use other_eval_fp_ft, only: null_other_eval_fp_ft
     411              :          use other_eval_i_rot, only: null_other_eval_i_rot
     412              :          use other_torque, only: default_other_torque
     413              :          use other_torque_implicit, only: default_other_torque_implicit
     414              :          use other_remove_surface, only: default_other_remove_surface
     415              :          use other_momentum, only: default_other_momentum
     416              :          use other_momentum_implicit, only: default_other_momentum_implicit
     417              :          use other_pressure, only: default_other_pressure
     418              :          use other_energy, only: default_other_energy
     419              :          use other_energy_implicit, only: default_other_energy_implicit
     420              :          use other_D_mix, only: null_other_D_mix
     421              :          use other_am_mixing, only: null_other_am_mixing
     422              :          use other_brunt, only: default_other_brunt
     423              :          use other_brunt_smoothing, only: null_other_brunt_smoothing
     424              :          use other_adjust_mlt_gradT_fraction, only: &
     425              :             default_other_adjust_mlt_gradT_fraction
     426              :          use other_after_set_mixing_info, only: &
     427              :             default_other_after_set_mixing_info
     428              :          use other_after_solver_setmatrix, only: &
     429              :             default_other_after_solver_setmatrix
     430              :          use other_diffusion, only: null_other_diffusion
     431              :          use other_diffusion_factor, only: default_other_diffusion_factor
     432              :          use other_neu, only: null_other_neu
     433              :          use other_net_get, only: null_other_net_get
     434              :          use other_cgrav, only: default_other_cgrav
     435              :          use other_mesh_delta_coeff_factor, only: default_other_mesh_delta_coeff_factor
     436              :          use other_alpha_mlt, only: default_other_alpha_mlt
     437              :          use other_mlt_results, only: null_other_mlt_results
     438              :          use other_opacity_factor, only: default_other_opacity_factor
     439              :          use other_pgstar_plots, only: null_other_pgstar_plots_info
     440              :          use other_mesh_functions
     441              :          use other_eps_grav, only: null_other_eps_grav
     442              :          use other_rsp_build_model, only: null_other_rsp_build_model
     443              :          use other_rsp_linear_analysis, only: null_other_rsp_linear_analysis
     444              :          use other_gradr_factor, only: null_other_gradr_factor
     445              :          use other_surface_PT, only: null_other_surface_PT
     446              :          use other_timestep_limit, only: null_other_timestep_limit
     447              :          use other_overshooting_scheme, only: null_other_overshooting_scheme
     448              :          use other_photo_write, only: default_other_photo_write
     449              :          use other_photo_read, only: default_other_photo_read
     450              :          use other_set_pgstar_controls, only: default_other_set_pgstar_controls
     451              :          use other_kap
     452              :          use pgstar_decorator
     453              :          use star_utils, only: init_random
     454              : 
     455              :          type (star_info), pointer :: s
     456              :          integer, intent(out) :: ierr
     457              : 
     458              :          ! note: keep the handles for eos, kap, and net
     459              : 
     460            2 :          ierr = 0
     461              : 
     462            2 :          s% model_number = 0
     463            2 :          s% time = 0
     464            2 :          s% dt = 0
     465              : 
     466            2 :          s% total_num_solver_iterations = 0
     467            2 :          s% total_num_solver_relax_iterations = 0
     468            2 :          s% total_num_solver_calls_made = 0
     469            2 :          s% total_num_solver_relax_calls_made = 0
     470            2 :          s% total_num_solver_calls_converged = 0
     471            2 :          s% total_num_solver_relax_calls_converged = 0
     472              : 
     473            2 :          s% num_solver_iterations = 0
     474            2 :          s% num_skipped_setvars = 0
     475            2 :          s% num_setvars = 0
     476            2 :          s% num_solver_setvars = 0
     477            2 :          s% num_retries = 0
     478            2 :          s% num_hydro_merges = 0
     479            2 :          s% num_hydro_splits = 0
     480            2 :          s% timestep_hold = -1
     481              : 
     482            2 :          s% mesh_call_number = 0
     483            2 :          s% solver_call_number = 0
     484            2 :          s% diffusion_call_number = 0
     485            2 :          s% model_number_for_last_retry = 0
     486            2 :          s% dt_limit_ratio = 0
     487            2 :          s% force_tau_factor = 0
     488            2 :          s% force_Tsurf_factor = 0
     489            2 :          s% force_opacity_factor = 0
     490              : 
     491            2 :          s% generations = 0
     492              : 
     493            2 :          s% nvar_hydro = 0
     494            2 :          s% nvar_chem = 0
     495            2 :          s% nvar_total = 0
     496              : 
     497            2 :          s% nz = 0
     498            2 :          s% prev_mesh_nz = 0
     499            2 :          s% net_name = ''
     500            2 :          s% species = 0
     501            2 :          s% num_reactions = 0
     502              : 
     503            2 :          s% fix_Pgas = .false.
     504            2 :          s% v_flag = .false.
     505            2 :          s% u_flag = .false.
     506            2 :          s% rotation_flag = .false.
     507            2 :          s% RTI_flag = .false.
     508            2 :          s% w_div_wc_flag = .false.
     509            2 :          s% D_omega_flag = .false.
     510            2 :          s% am_nu_rot_flag = .false.
     511            2 :          s% RSP_flag = .false.
     512            2 :          s% RSP2_flag = .false.
     513              : 
     514            2 :          s% have_mixing_info = .false.
     515            2 :          s% doing_solver_iterations = .false.
     516            2 :          s% need_to_setvars = .true.
     517            2 :          s% okay_to_set_mixing_info = .true.
     518            2 :          s% okay_to_set_mlt_vc = .false.  ! not until have set mlt_cv_old
     519            2 :          s% have_mlt_vc = .false.
     520              : 
     521            2 :          s% have_ST_start_info = .false.
     522            2 :          s% prev_mesh_have_ST_start_info = .false.
     523              : 
     524            2 :          s% just_wrote_terminal_header = .false.
     525            2 :          s% doing_relax = .false.
     526            2 :          s% mstar_dot = 0
     527            2 :          s% surf_lnS = 0
     528              : 
     529            2 :          s% termination_code = -1
     530              : 
     531            2 :          s% screening_mode_value = -1
     532              : 
     533            2 :          s% dt = -1
     534            2 :          s% dt_next = -1
     535            2 :          s% dt_next_unclipped = -1
     536              : 
     537            2 :          s% i_lnd = 0
     538            2 :          s% i_lnT = 0
     539            2 :          s% i_lnR = 0
     540            2 :          s% i_lum = 0
     541            2 :          s% i_v = 0
     542            2 :          s% i_u = 0
     543            2 :          s% i_alpha_RTI = 0
     544              : 
     545            2 :          s% i_dv_dt = 0
     546            2 :          s% i_du_dt = 0
     547            2 :          s% i_equL = 0
     548            2 :          s% i_dlnd_dt = 0
     549            2 :          s% i_dlnE_dt = 0
     550            2 :          s% i_dlnR_dt = 0
     551            2 :          s% i_dalpha_RTI_dt = 0
     552              : 
     553            2 :          s% op_mono_nptot = 0
     554            2 :          s% op_mono_ipe = 0
     555            2 :          s% op_mono_nrad = 0
     556            2 :          s% op_mono_n = 0
     557              : 
     558            2 :          s% number_of_history_columns = -1
     559            2 :          s% model_number_of_history_values = -1
     560            2 :          s% need_to_set_history_names_etc = .true.
     561            2 :          s% doing_finish_load_model = .false.
     562              : 
     563            2 :          nullify(s% finish_relax_step)
     564            2 :          nullify(s% finished_relax)
     565              : 
     566              :          s% how_many_extra_profile_header_items => &
     567            2 :             null_how_many_extra_header_items
     568              :          s% data_for_extra_profile_header_items => &
     569            2 :             null_data_for_extra_header_items
     570              : 
     571              :          s% how_many_extra_history_header_items => &
     572            2 :             null_how_many_extra_header_items
     573              :          s% data_for_extra_history_header_items => &
     574            2 :             null_data_for_extra_header_items
     575              : 
     576            2 :          s% other_wind => null_other_wind
     577            2 :          s% other_accreting_state => null_other_accreting_state
     578            2 :          s% other_adjust_mdot => null_other_adjust_mdot
     579            2 :          s% other_j_for_adjust_J_lost => null_other_j_for_adjust_J_lost
     580            2 :          s% other_D_mix => null_other_D_mix
     581            2 :          s% other_am_mixing => null_other_am_mixing
     582            2 :          s% other_eval_fp_ft => null_other_eval_fp_ft
     583            2 :          s% other_eval_i_rot => null_other_eval_i_rot
     584            2 :          s% other_torque => default_other_torque
     585            2 :          s% other_torque_implicit => default_other_torque_implicit
     586            2 :          s% other_remove_surface => default_other_remove_surface
     587            2 :          s% other_momentum => default_other_momentum
     588            2 :          s% other_momentum_implicit => default_other_momentum_implicit
     589            2 :          s% other_pressure => default_other_pressure
     590            2 :          s% other_energy => default_other_energy
     591            2 :          s% other_energy_implicit => default_other_energy_implicit
     592            2 :          s% other_cgrav => default_other_cgrav
     593            2 :          s% other_mesh_delta_coeff_factor => default_other_mesh_delta_coeff_factor
     594            2 :          s% other_alpha_mlt => default_other_alpha_mlt
     595            2 :          s% other_opacity_factor => default_other_opacity_factor
     596            2 :          s% other_brunt => default_other_brunt
     597            2 :          s% other_brunt_smoothing => null_other_brunt_smoothing
     598            2 :          s% other_adjust_mlt_gradT_fraction => default_other_adjust_mlt_gradT_fraction
     599            2 :          s% other_after_set_mixing_info => default_other_after_set_mixing_info
     600            2 :          s% other_after_solver_setmatrix => default_other_after_solver_setmatrix
     601            2 :          s% other_diffusion => null_other_diffusion
     602            2 :          s% other_diffusion_factor => default_other_diffusion_factor
     603            2 :          s% other_mlt_results => null_other_mlt_results
     604            2 :          s% other_neu => null_other_neu
     605            2 :          s% other_net_get => null_other_net_get
     606            2 :          s% other_eps_grav => null_other_eps_grav
     607            2 :          s% other_rsp_build_model => null_other_rsp_build_model
     608            2 :          s% other_rsp_linear_analysis => null_other_rsp_linear_analysis
     609            2 :          s% other_gradr_factor => null_other_gradr_factor
     610              : 
     611            2 :          s% other_kap_get => null_other_kap_get
     612            2 :          s% other_kap_get_op_mono => null_other_kap_get_op_mono
     613              : 
     614            2 :          s% other_surface_PT => null_other_surface_PT
     615              : 
     616            2 :          s% other_timestep_limit => null_other_timestep_limit
     617            2 :          s% other_overshooting_scheme => null_other_overshooting_scheme
     618              : 
     619            2 :          s% other_pgstar_plots_info => null_other_pgstar_plots_info
     620            2 :          s% how_many_other_mesh_fcns => null_how_many_other_mesh_fcns
     621            2 :          s% other_mesh_fcn_data => null_other_mesh_fcn_data
     622              : 
     623            2 :          s% other_photo_write => default_other_photo_write
     624            2 :          s% other_photo_read => default_other_photo_read
     625              : 
     626            2 :          s% other_set_pgstar_controls => default_other_set_pgstar_controls
     627              : 
     628            2 :          s% other_new_generation => null_other_new_generation
     629            2 :          s% other_set_current_to_old => null_other_set_current_to_old
     630              : 
     631            2 :          nullify(s% extra_profile_col_names)
     632            2 :          nullify(s% extra_profile_col_vals)
     633            2 :          s% num_extra_profile_cols = 0
     634              : 
     635            2 :          s% binary_id = 0
     636            2 :          s% include_binary_history_in_log_file = .false.
     637            2 :          s% how_many_binary_history_columns => null_how_many_binary_history_columns
     638            2 :          s% data_for_binary_history_columns => null_data_for_binary_history_columns
     639            2 :          s% how_many_extra_binary_history_columns => null_how_many_extra_binary_history_columns
     640            2 :          s% data_for_extra_binary_history_columns => null_data_for_extra_binary_history_columns
     641              : 
     642            2 :          s% generations = 0
     643              : 
     644            2 :          s% nz = 0
     645              : 
     646            2 :          s% nvar_hydro = 0
     647            2 :          s% nvar_chem = 0
     648            2 :          s% nvar_total = 0
     649              : 
     650            2 :          s% species = 0
     651            2 :          s% num_reactions = 0
     652              : 
     653            2 :          s% model_number = 0
     654            2 :          s% mstar = 0
     655            2 :          s% xmstar = 0
     656            2 :          s% M_center = 0
     657            2 :          s% v_center = 0
     658            2 :          s% R_center = 0
     659            2 :          s% L_center = 0
     660            2 :          s% time = 0
     661            2 :          s% total_angular_momentum = 0
     662              : 
     663            2 :          s% dt = 0
     664              : 
     665            2 :          s% have_previous_conv_vel = .false.
     666              : 
     667            2 :          s% net_name = ''
     668              : 
     669            2 :          s% mstar_dot = 0
     670            2 :          s% v_surf = 0
     671            2 :          s% L_nuc_burn_total = 0
     672           50 :          s% L_by_category = 0
     673            2 :          s% dt_limit_ratio = 0
     674            2 :          s% L_phot = 0
     675            2 :          s% T_surf = 0
     676            2 :          s% P_surf = 0
     677              : 
     678            2 :          s% gradT_excess_alpha = 0
     679            2 :          s% gradT_excess_alpha_old = 0
     680              : 
     681            2 :          s% h1_czb_mass = 0
     682              : 
     683            2 :          s% he_core_mass = 0
     684            2 :          s% co_core_mass = 0
     685            2 :          s% Teff = -1  ! need to calculate it
     686            2 :          s% center_eps_nuc = 0
     687            2 :          s% Lrad_div_Ledd_avg_surf = 0
     688            2 :          s% w_div_w_crit_avg_surf = 0
     689            2 :          s% total_internal_energy = 0d0
     690            2 :          s% total_gravitational_energy = 0d0
     691            2 :          s% total_radial_kinetic_energy = 0d0
     692            2 :          s% total_turbulent_energy = 0d0
     693            2 :          s% total_rotational_kinetic_energy = 0d0
     694            2 :          s% total_energy = 0d0
     695              : 
     696            2 :          s% n_conv_regions = 0
     697          202 :          s% cz_bot_mass(:) = 0
     698          202 :          s% cz_top_mass(:) = 0
     699            2 :          s% dt_next = 0
     700              : 
     701            2 :          s% model_profile_filename = ''
     702            2 :          s% model_controls_filename = ''
     703            2 :          s% model_data_filename = ''
     704              : 
     705            2 :          s% most_recent_profile_filename = ''
     706            2 :          s% most_recent_controls_filename = ''
     707              : 
     708            2 :          s% most_recent_model_data_filename = ''
     709              : 
     710            2 :          s% recent_log_header = -1000
     711            2 :          s% phase_of_evolution = 0
     712              : 
     713            2 :          s% num_solver_iterations = 0
     714            2 :          s% num_skipped_setvars = 0
     715            2 :          s% num_setvars = 0
     716            2 :          s% num_retries = 0
     717              : 
     718            2 :          s% num_hydro_merges = 0
     719            2 :          s% num_hydro_splits = 0
     720              : 
     721            2 :          s% timestep_hold = 0
     722            2 :          s% model_number_for_last_retry = 0
     723              : 
     724            2 :          s% mesh_call_number = 0
     725            2 :          s% solver_call_number = 0
     726            2 :          s% diffusion_call_number = 0
     727              : 
     728            2 :          s% num_rotation_solver_steps = 0
     729            2 :          s% num_diffusion_solver_steps = 0
     730            2 :          s% initial_timestep = 0
     731            2 :          s% why_Tlim = 0
     732            2 :          s% result_reason = 0
     733              : 
     734            2 :          s% have_new_generation = .false.
     735            2 :          s% have_new_cz_bdy_info = .false.
     736            2 :          s% need_to_update_history_now = .false.
     737            2 :          s% need_to_save_profiles_now = .false.
     738            2 :          s% save_profiles_model_priority = 0
     739              : 
     740            2 :          s% doing_flash_wind = .false.
     741            2 :          s% doing_rlo_wind = .false.
     742            2 :          s% most_recent_photo_name = ''
     743              : 
     744            2 :          s% len_extra_iwork = 0
     745            2 :          s% len_extra_work = 0
     746              : 
     747            2 :          s% crystal_core_boundary_mass = -1
     748            2 :          s% phase_sep_mixing_mass = -1
     749              : 
     750            2 :          call init_random(s)
     751              : 
     752            2 :       end subroutine set_starting_star_data
     753              : 
     754              : 
     755            0 :       subroutine create_pre_ms_model(id, ierr)
     756              :          integer, intent(in) :: id
     757              :          integer, intent(out) :: ierr
     758              :          character (len=0) :: model_dir
     759              :          call model_builder( &
     760              :             id, model_dir, do_create_pre_ms_model, &
     761            0 :             .false., 'restart_photo', ierr)
     762            2 :       end subroutine create_pre_ms_model
     763              : 
     764              : 
     765            0 :       subroutine create_initial_model(id, ierr)
     766              :          integer, intent(in) :: id
     767              :          integer, intent(out) :: ierr
     768              :          character (len=0) :: model_dir
     769              :          call model_builder( &
     770              :             id, model_dir, do_create_initial_model, &
     771            0 :             .false., 'restart_photo', ierr)
     772            0 :       end subroutine create_initial_model
     773              : 
     774              : 
     775            0 :       subroutine create_RSP_model(id, ierr)
     776              :          integer, intent(in) :: id
     777              :          integer, intent(out) :: ierr
     778              :          character (len=0) :: model_dir
     779              :          call model_builder( &
     780              :             id, model_dir, do_create_RSP_model, &
     781            0 :             .false., 'restart_photo', ierr)
     782            0 :       end subroutine create_RSP_model
     783              : 
     784              : 
     785            0 :       subroutine create_RSP2_model(id, ierr)
     786              :          integer, intent(in) :: id
     787              :          integer, intent(out) :: ierr
     788              :          character (len=0) :: model_dir
     789              :          call model_builder( &
     790              :             id, model_dir, do_create_RSP2_model, &
     791            0 :             .false., 'restart_photo', ierr)
     792            0 :       end subroutine create_RSP2_model
     793              : 
     794              : 
     795            1 :       subroutine load_zams_model(id, ierr)
     796              :          integer, intent(in) :: id
     797              :          integer, intent(out) :: ierr
     798              :          call model_builder( &
     799              :             id, '', do_load_zams_model, &
     800            1 :             .false., 'restart_photo', ierr)
     801            1 :       end subroutine load_zams_model
     802              : 
     803              : 
     804            0 :       subroutine load_saved_model(id, model_fname, ierr)
     805              :          integer, intent(in) :: id
     806              :          character (len=*), intent(in) :: model_fname
     807              :          integer, intent(out) :: ierr
     808              :          integer :: l
     809              :          l = len_trim(model_fname)
     810              :          call model_builder( &
     811              :             id, model_fname, do_load_saved_model, &
     812            0 :             .false., 'restart_photo', ierr)
     813            0 :       end subroutine load_saved_model
     814              : 
     815              : 
     816            0 :       subroutine load_restart_photo(id, restart_filename, ierr)
     817              :          integer, intent(in) :: id
     818              :          character (len=*), intent(in) :: restart_filename
     819              :          integer, intent(out) :: ierr
     820              :          call model_builder( &
     821            0 :             id, '', do_load_zams_model, .true., restart_filename, ierr)
     822            0 :       end subroutine load_restart_photo
     823              : 
     824              : 
     825              :       ! for both zams and pre-main-sequence
     826            1 :       subroutine model_builder( &
     827              :             id, model_info, do_which, restart, restart_filename, ierr)
     828              :          use net, only: set_net, do_micro_change_net
     829              :          use alloc, only: set_var_info
     830              :          use photo_in, only: read_star_photo
     831              :          use init_model, only: get_zams_model
     832              :          use star_utils, only: set_phase_of_evolution, yrs_for_init_timestep, &
     833              :             eval_deltaM_total_energy_integrals
     834              :          use adjust_xyz, only: set_z, set_y
     835              :          use pre_ms_model, only: build_pre_ms_model
     836              :          use create_initial_model, only: build_initial_model
     837              :          use rsp, only: build_rsp_model, rsp_total_energy_integrals
     838              :          use rsp_def, only: init_def
     839              :          use read_model, only: do_read_saved_model, &
     840              :             finish_load_model
     841              :          use relax, only: do_relax_to_limit, do_relax_mass, &
     842              :             do_relax_mass_scale, do_relax_num_steps, do_relax_to_radiative_core
     843              :          use auto_diff_support
     844              :          integer, intent(in) :: id, do_which
     845              :          character (len=*), intent(in) :: model_info, restart_filename
     846              :          logical, intent(in) :: restart
     847              :          integer, intent(out) :: ierr
     848              : 
     849              :          type (star_info), pointer :: s
     850            1 :          real(dp) :: initial_mass, initial_z
     851              :          real(dp), parameter :: lg_max_abs_mdot = -1000  ! use default
     852              :          real(dp), parameter :: change_mass_years_for_dt = 1
     853              :          real(dp), parameter :: min_mass_for_create_pre_ms = 0.03d0
     854            1 :          real(dp) :: total_radiation, warning_limit_for_max_residual
     855              :          integer :: k, num_trace_history_values
     856            1 :          real(dp) :: save_Pextra_factor
     857              :          character (len=256):: save_atm_option, &
     858              :             save_atm_T_tau_relation, save_atm_T_tau_opacity
     859            1 :          real(dp), allocatable, dimension(:) :: total_energy_profile
     860              : 
     861              :          include 'formats'
     862              : 
     863              :          ierr = 0
     864              : 
     865            1 :          call get_star_ptr(id, s, ierr)
     866            1 :          if (ierr /= 0) return
     867              : 
     868            1 :          initial_mass = s% initial_mass
     869            1 :          initial_z = s% initial_z
     870              : 
     871            1 :          if (s% initial_y < 0) s% initial_y = max(0d0, min(1d0, 0.24d0 + 2*initial_z))
     872              : 
     873            1 :          s% dt = 0
     874            1 :          s% termination_code = -1
     875              : 
     876            1 :          if (restart) then
     877            0 :             s% doing_first_model_of_run = .false.
     878            0 :             s% doing_first_model_after_restart = .true.
     879            0 :             call read_star_photo(s, restart_filename, ierr)
     880            0 :             if (ierr /= 0) return
     881            0 :             call check_initials
     882            0 :             call set_net(s, s% net_name, ierr)
     883            0 :             if (ierr /= 0) return
     884            0 :             if (s% rotation_flag) s% have_j_rot = .true.
     885            0 :             call init_def(s)  ! RSP
     886            0 :             call finish_load_model(s, restart, ierr)
     887            0 :             if (s% max_years_for_timestep > 0) &
     888            0 :                s% dt_next = min(s% dt_next, secyer*s% max_years_for_timestep)
     889            0 :             return
     890              :          end if
     891              : 
     892            1 :          num_trace_history_values = s% num_trace_history_values
     893            1 :          s% num_trace_history_values = 0
     894              : 
     895            1 :          warning_limit_for_max_residual = s% warning_limit_for_max_residual
     896            1 :          s% warning_limit_for_max_residual = 1d0
     897              : 
     898            1 :          s% doing_first_model_of_run = .true.
     899            1 :          s% doing_first_model_after_restart = .false.
     900              : 
     901            1 :          if (do_which == do_load_saved_model) then
     902            0 :             s% dt_next = -1
     903            0 :             call do_read_saved_model(s, model_info, ierr)
     904            0 :             if (ierr /= 0) then
     905            0 :                write(*,*) 'load failed in do_read_saved_model'
     906            0 :                return
     907              :             end if
     908            0 :             call check_initials
     909            0 :             if (s% dt_next < 0) s% dt_next = yrs_for_init_timestep(s)*secyer
     910              :          else
     911            1 :             s% net_name = s% default_net_name
     912            1 :             s% species = 0
     913            1 :             s% v_flag = .false.
     914            1 :             s% u_flag = .false.
     915            1 :             s% rotation_flag = .false.
     916            1 :             s% D_omega_flag = .false.
     917            1 :             s% am_nu_rot_flag = .false.
     918            1 :             s% star_mass = s% initial_mass
     919            1 :             s% mstar = s% initial_mass*Msun
     920            1 :             s% M_center = s% mstar - s% xmstar
     921            1 :             call set_var_info(s, ierr)
     922            1 :             if (ierr /= 0) then
     923            0 :                write(*,*) 'failed in set_var_info'
     924            0 :                return
     925              :             end if
     926            0 :             select case (do_which)
     927              :                case (do_create_initial_model)
     928            0 :                   if (s% initial_model_change_net) then
     929            0 :                      call do_micro_change_net(s, s% initial_model_new_net_name, ierr)
     930              :                   else
     931            0 :                      call set_net(s, s% net_name, ierr)
     932              :                   end if
     933            0 :                   if (ierr /= 0) then
     934            0 :                      write(*,*) 'failed in set_net'
     935            0 :                      return
     936              :                   end if
     937            0 :                   call build_initial_model(s, ierr)
     938            0 :                   if (ierr /= 0) then
     939            0 :                      write(*,*) 'failed in build_initial_model'
     940            0 :                      return
     941              :                   end if
     942            0 :                   s% generations = 1
     943            0 :                   s% dt_next = 1d-5*secyer
     944              :                case (do_create_pre_ms_model)
     945            0 :                   if (s% initial_mass < min_mass_for_create_pre_ms) then
     946            0 :                      write(*,'(A)')
     947            0 :                      write(*,'(A)')
     948            0 :                      write(*,'(A)')
     949            0 :                      write(*,'(a,1x,f5.2)') 'sorry: cannot create pre-ms smaller than', &
     950            0 :                         min_mass_for_create_pre_ms
     951              :                      write(*,'(a)') &
     952            0 :                         'please create pre-ms and then relax to lower mass as a separate operation'
     953            0 :                      write(*,'(A)')
     954            0 :                      write(*,'(a)') 'here is an example:'
     955            0 :                      write(*,'(a)') 'in your inlist &controls section, set initial_mass = 0.03'
     956            0 :                      write(*,'(a)') 'in the &star_job section, add something like these lines'
     957            0 :                      write(*,'(a)') '  relax_mass_scale = .true.'
     958            0 :                      write(*,'(a)') '  dlgm_per_step = 1d-3 ! log10(delta M/Msun/step)'
     959            0 :                      write(*,'(a)') '  new_mass = 2.863362d-3 ! 3 Mjupiter in Msun units'
     960            0 :                      write(*,'(a)') '  change_mass_years_for_dt = 1'
     961            0 :                      write(*,'(A)')
     962            0 :                      write(*,'(A)')
     963            0 :                      write(*,'(A)')
     964            0 :                      ierr = -1
     965            0 :                      return
     966              :                   end if
     967            0 :                   if (s% pre_ms_change_net) then
     968            0 :                      call do_micro_change_net(s, s% pre_ms_new_net_name, ierr)
     969              :                   else
     970            0 :                      call set_net(s, s% net_name, ierr)
     971              :                   end if
     972            0 :                   if (ierr /= 0) then
     973            0 :                      write(*,*) 'failed in set_net'
     974            0 :                      return
     975              :                   end if
     976            0 :                   write(*,2) 'species  mass', s% species, s% mstar/Msun
     977              : 
     978            0 :                   call build_pre_ms_model(id, s, s% nvar_hydro, s% species, ierr)
     979            0 :                   if (ierr /= 0) then
     980            0 :                      write(*,*) 'failed in build_pre_ms_model'
     981            0 :                      return
     982              :                   end if
     983            0 :                   s% generations = 1
     984            0 :                   s% dt_next = 1d-5*secyer
     985              :                case (do_load_zams_model)
     986            1 :                   s% generations = 1
     987            1 :                   call get_zams_model(s, s% zams_filename, ierr)
     988            1 :                   if (ierr /= 0) then
     989            0 :                      write(*,*) 'failed in get_zams_model'
     990            0 :                      return
     991              :                   end if
     992            1 :                   if (s% dt_next <= 0d0) then
     993            1 :                      s% dt_next = yrs_for_init_timestep(s)*secyer
     994              :                   end if
     995              :                case (do_create_RSP_model)
     996            0 :                   call build_rsp_model(s, ierr)  ! like build_pre_ms_model
     997            0 :                   if (ierr /= 0) then
     998            0 :                      write(*,*) 'failed in build_rsp_model'
     999            0 :                      return
    1000              :                   end if
    1001            0 :                   s% generations = 1
    1002            0 :                   s% dt_next = 1d-2*secyer
    1003              :                case (do_create_RSP2_model)
    1004              :                   !call build_rsp2_model(s, ierr) ! like build_pre_ms_model
    1005            0 :                   call mesa_error(__FILE__,__LINE__,'need to add build_rsp2_model')
    1006            0 :                   if (ierr /= 0) then
    1007            0 :                      write(*,*) 'failed in build_rsp2_model'
    1008            0 :                      return
    1009              :                   end if
    1010            0 :                   s% generations = 1
    1011            0 :                   s% dt_next = 1d-2*secyer
    1012              :                case default
    1013            0 :                   write(*,*) 'bad value for do_which in build_model'
    1014            0 :                   ierr = -1
    1015            1 :                   return
    1016              :             end select
    1017              :          end if
    1018              : 
    1019         2465 :          do k=1,s% nz
    1020         2465 :             s% extra_heat(k) = 0
    1021              :          end do
    1022              : 
    1023            1 :          call finish_load_model(s, restart, ierr)
    1024            1 :          if (ierr /= 0) then
    1025            0 :             write(*,*) 'failed in finish_load_model'
    1026            0 :             return
    1027              :          end if
    1028              : 
    1029            1 :          if (s% max_years_for_timestep > 0) &
    1030            0 :             s% dt_next = min(s% dt_next, secyer*s% max_years_for_timestep)
    1031            1 :          call set_phase_of_evolution(s)
    1032              : 
    1033            1 :          if (s% RSP_flag) then
    1034              :             call rsp_total_energy_integrals(s, &
    1035              :                s% total_internal_energy, &
    1036              :                s% total_gravitational_energy, &
    1037              :                s% total_radial_kinetic_energy, &
    1038              :                s% total_rotational_kinetic_energy, &
    1039              :                s% total_turbulent_energy, &
    1040            0 :                s% total_energy, total_radiation)
    1041              :          else
    1042            1 :             allocate(total_energy_profile(1:s% nz))
    1043              :             call eval_deltaM_total_energy_integrals( &
    1044              :                s, 1, s% nz, s% mstar, .false., &
    1045              :                total_energy_profile, &
    1046              :                s% total_internal_energy, &
    1047              :                s% total_gravitational_energy, &
    1048              :                s% total_radial_kinetic_energy, &
    1049              :                s% total_rotational_kinetic_energy, &
    1050              :                s% total_turbulent_energy, &
    1051            1 :                s% total_energy)
    1052              :          end if
    1053              : 
    1054            1 :          if (do_which == do_create_pre_ms_model) then
    1055            0 :             call setup_for_relax_after_create_pre_ms_model
    1056            0 :             if (s% mstar > s% initial_mass*Msun) then  ! need to reduce mass
    1057            0 :                write(*,1) 'reduce mass to', s% initial_mass
    1058            0 :                call do_relax_mass(s% id, s% initial_mass, lg_max_abs_mdot, ierr)
    1059            0 :                if (ierr /= 0) then
    1060            0 :                   write(*,*) 'failed in do_relax_mass'
    1061            0 :                   return
    1062              :                end if
    1063            0 :             else if (s% mstar < s% initial_mass*Msun) then  ! need to increase mass
    1064            0 :                write(*,1) 'increase mass to', s% initial_mass
    1065              :                call do_relax_mass_scale( &
    1066            0 :                   s% id, s% initial_mass, s% job% dlgm_per_step, s% job% change_mass_years_for_dt, ierr)
    1067            0 :                if (ierr /= 0) then
    1068            0 :                   write(*,*) 'failed in do_relax_mass'
    1069            0 :                   return
    1070              :                end if
    1071              :             end if
    1072              :             call do_relax_num_steps( &
    1073            0 :                s% id, s% pre_ms_relax_num_steps, s% dt_next, ierr)
    1074            0 :             if (ierr /= 0) then
    1075            0 :                write(*,*) 'failed in do_relax_num_steps'
    1076            0 :                return
    1077              :             end if
    1078              : 
    1079            0 :             if (s% job% pre_ms_relax_to_start_radiative_core) then
    1080            0 :                call do_relax_to_radiative_core(s% id, ierr)
    1081            0 :                if (ierr /= 0) then
    1082            0 :                   write(*,*) 'failed in do_relax_to_radiative_core'
    1083            0 :                   return
    1084              :                end if
    1085              :             end if
    1086            0 :             call done_relax_after_create_pre_ms_model
    1087            1 :          else if (do_which == do_create_initial_model .and. &
    1088              :                   s% initial_model_relax_num_steps > 0) then
    1089              :             call do_relax_num_steps( &
    1090            0 :                s% id, s% initial_model_relax_num_steps, s% dt_next, ierr)
    1091            0 :             if (ierr /= 0) then
    1092            0 :                write(*,*) 'failed in do_relax_num_steps'
    1093            0 :                return
    1094              :             end if
    1095              :          end if
    1096              : 
    1097            1 :          s% doing_first_model_of_run = .true.
    1098            1 :          s% num_trace_history_values = num_trace_history_values
    1099            1 :          s% warning_limit_for_max_residual = warning_limit_for_max_residual
    1100              : 
    1101              :          contains
    1102              : 
    1103            0 :          subroutine setup_for_relax_after_create_pre_ms_model
    1104            0 :             save_atm_option = s% atm_option
    1105            0 :             save_atm_T_tau_relation = s% atm_T_tau_relation
    1106            0 :             save_atm_T_tau_opacity = s% atm_T_tau_opacity
    1107            0 :             save_Pextra_factor = s% Pextra_factor
    1108            0 :             s% atm_option = 'T_tau'
    1109            0 :             s% atm_T_tau_relation = 'Eddington'
    1110            0 :             s% atm_T_tau_opacity = 'fixed'
    1111            0 :             s% Pextra_factor = 2
    1112            1 :          end subroutine setup_for_relax_after_create_pre_ms_model
    1113              : 
    1114            0 :          subroutine done_relax_after_create_pre_ms_model
    1115            0 :             s% atm_option = save_atm_option
    1116            0 :             s% atm_T_tau_relation = save_atm_T_tau_relation
    1117            0 :             s% atm_T_tau_opacity = save_atm_T_tau_opacity
    1118            0 :             s% Pextra_factor = save_Pextra_factor
    1119            0 :          end subroutine done_relax_after_create_pre_ms_model
    1120              : 
    1121            0 :          subroutine check_initials
    1122              :             include 'formats'
    1123              :             if (abs(initial_mass - s% initial_mass) > &
    1124            0 :                   1d-3*initial_mass .and. initial_mass > 0) then
    1125            0 :                write(*,1) "WARNING -- inlist initial_mass ignored", initial_mass
    1126            0 :                write(*,1) "using saved initial_mass instead", s% initial_mass
    1127            0 :                write(*,'(A)')
    1128              :             end if
    1129              :             if (abs(initial_z - s% initial_z) > &
    1130            0 :                   1d-3*initial_z .and. initial_z > 0) then
    1131            0 :                write(*,1) "WARNING -- inlist initial_z ignored", initial_z
    1132            0 :                write(*,1) "using saved initial_z instead", s% initial_z
    1133            0 :                write(*,'(A)')
    1134              :             end if
    1135            0 :          end subroutine check_initials
    1136              : 
    1137              :       end subroutine model_builder
    1138              : 
    1139              : 
    1140            1 :       logical function doing_restart(restart_filename)
    1141              :          character (len=*) :: restart_filename
    1142            1 :          inquire(file=restart_filename, exist=doing_restart)
    1143            1 :       end function doing_restart
    1144              : 
    1145              : 
    1146            0 :       integer function null_how_many_extra_header_items(id)
    1147              :          integer, intent(in) :: id
    1148            0 :          null_how_many_extra_header_items = 0
    1149            0 :       end function null_how_many_extra_header_items
    1150              : 
    1151              : 
    1152            0 :       subroutine null_data_for_extra_header_items(id, n, names, vals, ierr)
    1153              :          integer, intent(in) :: id, n
    1154              :          character (len=80) :: names(n)
    1155              :          real(dp) :: vals(n)
    1156              :          integer, intent(out) :: ierr
    1157            0 :          ierr = 0
    1158            0 :       end subroutine null_data_for_extra_header_items
    1159              : 
    1160              : 
    1161            0 :       integer function null_how_many_binary_history_columns(binary_id)
    1162              :          integer, intent(in) :: binary_id
    1163            0 :          null_how_many_binary_history_columns = 0
    1164            0 :       end function null_how_many_binary_history_columns
    1165              : 
    1166              : 
    1167            0 :       subroutine null_data_for_binary_history_columns( &
    1168              :             binary_id, n, names, vals, ierr)
    1169              :          use const_def, only: dp
    1170              :          integer, intent(in) :: binary_id, n
    1171              :          character (len=80) :: names(n)
    1172              :          real(dp) :: vals(n)
    1173              :          integer, intent(out) :: ierr
    1174            0 :          ierr = 0
    1175            0 :       end subroutine null_data_for_binary_history_columns
    1176              : 
    1177              : 
    1178            0 :       integer function null_how_many_extra_binary_history_columns(binary_id)
    1179              :          integer, intent(in) :: binary_id
    1180            0 :          null_how_many_extra_binary_history_columns = 0
    1181            0 :       end function null_how_many_extra_binary_history_columns
    1182              : 
    1183              : 
    1184            0 :       subroutine null_data_for_extra_binary_history_columns( &
    1185              :             binary_id, n, names, vals, ierr)
    1186              :          use const_def, only: dp
    1187              :          integer, intent(in) :: binary_id, n
    1188              :          character (len=80) :: names(n)
    1189              :          real(dp) :: vals(n)
    1190              :          integer, intent(out) :: ierr
    1191            0 :          ierr = 0
    1192            0 :       end subroutine null_data_for_extra_binary_history_columns
    1193              : 
    1194              : 
    1195            0 :       subroutine do_garbage_collection(eosDT_cache_dir, ierr)
    1196              :          use eos_lib, only: eos_init, eos_shutdown
    1197              :          use eos_def, only: use_cache_for_eos
    1198              :          integer, intent(inout) :: ierr
    1199              :          character (len=*), intent(in) :: eosDT_cache_dir
    1200              :          ! Remove existing eos data
    1201            0 :          call eos_shutdown()
    1202              :          ! Re-initialize eos
    1203              :          call eos_init(eosDT_cache_dir,&
    1204              :                ! After first init this is set in eos_def
    1205              :                use_cache_for_eos,&
    1206            0 :                ierr)
    1207            0 :       end subroutine do_garbage_collection
    1208              : 
    1209              :       end module init
        

Generated by: LCOV version 2.0-1