LCOV - code coverage report
Current view: top level - eos/test/src - eos_support.f90 (source / functions) Coverage Total Hit
Test: coverage.info Lines: 64.0 % 75 48
Test Date: 2025-05-08 18:23:42 Functions: 66.7 % 3 2

            Line data    Source code
       1              : module eos_support
       2              :    use eos_def
       3              :    use eos_lib
       4              :    use const_def
       5              :    use chem_def
       6              :    use math_lib
       7              :    use utils_lib, only: is_bad_num
       8              :    implicit none
       9              : 
      10              :    logical, parameter :: use_shared_data_dir = .true.   ! MUST BE .true. FOR RELEASE
      11              :    !logical, parameter :: use_shared_data_dir = .false.
      12              : 
      13              :    real(dp) :: X, Z, Zinit, Y, dXC, dXO, XC, XO, abar, zbar, z2bar, z53bar, ye
      14              :    integer, parameter :: species = 7
      15              :    integer, parameter :: h1 = 1, he4 = 2, c12 = 3, n14 = 4, o16 = 5, ne20 = 6, mg24 = 7
      16              :    integer, target :: chem_id_array(species)
      17              :    integer, pointer, dimension(:) :: chem_id, net_iso
      18              :    real(dp) :: xa(species)
      19              : 
      20              :    real(dp), allocatable :: d_dxa(:, :)  ! (num_d_dxa_basic_results,species)
      21              : 
      22              :    integer :: handle
      23              :    type(EoS_General_Info), pointer :: rq
      24              : 
      25              :    character(len=eos_name_length) :: eos_names(num_eos_basic_results)
      26              : 
      27              :    ! if false, then test using data from mesa/eos/data/eos_data
      28              :    ! if true, then test using data from mesa/data/eos_data
      29              : 
      30              : contains
      31              : 
      32           36 :    subroutine Init_Composition(X_in, Zinit_in, XC_in, XO_in)
      33              :       use chem_lib
      34              :       real(dp), intent(IN) :: X_in, Zinit_in, XC_in, XO_in
      35              : 
      36              :       real(dp), parameter :: Zfrac_C = 0.173312d0
      37              :       real(dp), parameter :: Zfrac_N = 0.053177d0
      38              :       real(dp), parameter :: Zfrac_O = 0.482398d0
      39              :       real(dp), parameter :: Zfrac_Ne = 0.098675d0
      40              : 
      41          576 :       real(dp) :: Z, frac, dabar_dx(species), dzbar_dx(species), sumx, &
      42          324 :                   mass_correction, dmc_dx(species)
      43              : 
      44           36 :       chem_id => chem_id_array
      45              : 
      46           36 :       allocate (net_iso(num_chem_isos))
      47       282852 :       net_iso(:) = 0
      48              : 
      49           36 :       chem_id(h1) = ih1; net_iso(ih1) = h1
      50           36 :       chem_id(he4) = ihe4; net_iso(ihe4) = he4
      51           36 :       chem_id(c12) = ic12; net_iso(ic12) = c12
      52           36 :       chem_id(n14) = in14; net_iso(in14) = n14
      53           36 :       chem_id(o16) = io16; net_iso(io16) = o16
      54           36 :       chem_id(ne20) = ine20; net_iso(ine20) = ne20
      55           36 :       chem_id(mg24) = img24; net_iso(img24) = mg24
      56              : 
      57           36 :       X = X_in
      58           36 :       Zinit = Zinit_in
      59           36 :       XC = XC_in; XO = XO_in
      60           36 :       Y = 1 - (X + Zinit + XC + XO)
      61           36 :       if (Y < 0) then  ! adjust XC and XO
      62            0 :          if (XC + XO <= 0) then
      63            0 :             write (*, *) 'bad args to Init_Composition'
      64            0 :             call mesa_error(__FILE__, __LINE__)
      65              :          end if
      66            0 :          frac = (1 - X - Zinit)/(XC + XO)
      67            0 :          if (frac <= 0) call mesa_error(__FILE__, __LINE__, 'bad args to Init_Composition')
      68            0 :          XC = frac*XC; XO = frac*XO
      69            0 :          Y = 1 - (X + Zinit + XC + XO)
      70            0 :          if (Y < -1d-10) then
      71            0 :             write (*, *) 'screw up in Init_Composition'
      72            0 :             call mesa_error(__FILE__, __LINE__)
      73              :          end if
      74            0 :          if (Y < 0) Y = 0
      75              :       end if
      76              : 
      77           36 :       xa(h1) = X
      78           36 :       xa(he4) = Y
      79           36 :       xa(c12) = Zinit*Zfrac_C + XC
      80           36 :       xa(n14) = Zinit*Zfrac_N
      81           36 :       xa(o16) = Zinit*Zfrac_O + XO
      82           36 :       xa(ne20) = Zinit*Zfrac_Ne
      83          252 :       xa(species) = 1 - sum(xa(1:species - 1))
      84              : 
      85              :       call composition_info( &
      86              :          species, chem_id, xa, X, Y, Z, abar, zbar, z2bar, z53bar, &
      87           36 :          ye, mass_correction, sumx, dabar_dx, dzbar_dx, dmc_dx)
      88              : 
      89           36 :    end subroutine Init_Composition
      90              : 
      91            2 :    subroutine Setup_eos
      92           36 :       use chem_lib
      93              :       use const_lib, only: const_init
      94              :       !..allocate and load the eos tables
      95              : 
      96              :       character(len=256) :: my_mesa_dir
      97              :       integer :: info
      98              :       logical :: use_cache
      99              : 
     100            2 :       info = 0
     101            2 :       allocate (d_dxa(num_eos_d_dxa_results, species), stat=info)
     102            2 :       if (info /= 0) then
     103            0 :          write (*, *) 'allocate failed for Setup_eos'
     104            0 :          call mesa_error(__FILE__, __LINE__)
     105              :       end if
     106              : 
     107            2 :       my_mesa_dir = '../..'
     108            2 :       call const_init(my_mesa_dir, info)
     109            2 :       if (info /= 0) then
     110            0 :          write (*, *) 'const_init failed'
     111            0 :          call mesa_error(__FILE__, __LINE__)
     112              :       end if
     113              : 
     114            2 :       call math_init()
     115              : 
     116            2 :       call chem_init('isotopes.data', info)
     117            2 :       if (info /= 0) then
     118            0 :          write (*, *) 'chem_init failed'
     119            0 :          call mesa_error(__FILE__, __LINE__)
     120              :       end if
     121              : 
     122            2 :       use_cache = .true.
     123              : 
     124            2 :       call eos_init(' ', use_cache, info)
     125            2 :       if (info /= 0) then
     126            0 :          write (*, *) 'failed in eos_init'
     127            0 :          call mesa_error(__FILE__, __LINE__)
     128              :       end if
     129           54 :       eos_names = eosDT_result_names
     130              : 
     131            2 :       handle = alloc_eos_handle_using_inlist('inlist', info)
     132            2 :       if (info /= 0) then
     133            0 :          write (*, *) 'failed in alloc_eos_handle_using_inlist'
     134            0 :          call mesa_error(__FILE__, __LINE__)
     135              :       end if
     136              : 
     137            2 :       call eos_ptr(handle, rq, info)
     138            2 :       if (info /= 0) then
     139            0 :          write (*, *) 'failed in eos_ptr'
     140            0 :          call mesa_error(__FILE__, __LINE__)
     141              :       end if
     142              : 
     143           10 :    end subroutine Setup_eos
     144              : 
     145            0 :    subroutine Shutdown_eos
     146            0 :       call free_eos_handle(handle)
     147            0 :       call eos_shutdown
     148            0 :       deallocate (d_dxa)
     149            2 :    end subroutine Shutdown_eos
     150              : 
     151              : end module eos_support
        

Generated by: LCOV version 2.0-1