[Mesa-users] using an index I found in another array

Rob Farmer r.j.farmer at uva.nl
Fri Feb 23 09:42:41 EST 2018


You could just use:

m_50_new= s% m(loc)

to get the mass at the zone given by loc

if(avg_charge_H(j) .eq. 0.5d0) then
            loc=j
            exit
          end if

You can't guarantee that any zone will have exactly avg_charge_H=0.5,
better to have something like

 do j=1, s% nz
         avg_charge_H(j)=star_get_profile_output(s,'avg_charge_H',j)
end do
loc =minloc(abs(avg_charge_H-0.5d0))

to find the nearest point to 0.5d0

Rob

On 23 February 2018 at 15:25, aldanag--- via Mesa-users <
mesa-users at lists.mesastar.org> wrote:

> Hello,
>
>
> I am trying to inject energy to a star using  the following subroutine I
> added to the run.star.extras:
>
> subroutine energy_routine(id, ierr)
>
>          use const_def, only: Rsun
>          integer, intent(in) :: id
>          integer, intent(out) :: ierr
>          type (star_info), pointer :: s
>          integer :: k
>          integer :: j
>          real(dp),allocatable,dimension(:) :: avg_charge_H
>          real(dp), pointer :: m_old(:)
>          real(dp) :: A
>          integer :: loc
>          real(dp) :: m_50_new
>          real(dp) :: m_50_old
>          real(dp) :: delta_m
>          real(dp) :: E_recomb
>          ierr=0
>          call star_ptr(id, s, ierr)
>     if (ierr /= 0) return
>     if (s% star_age > 1.2275500000700004d9 .and. s% star_age <
> 1.2275500017700004d9) then
>         allocate(avg_charge_H(1:s%nz))
>          do j=1, s% nz
>          avg_charge_H(j)=star_get_profile_output(s,'avg_charge_H',j)
>          if(avg_charge_H(j) .eq. 0.5d0) then
>             loc=j
>             exit
>           end if
>       end do
>       do k = 1, s% nz
>       avg_charge_H(k)=star_get_profile_output(s,'avg_charge_H',k)
>         if (avg_charge_H(k) > 0.1d0 .and. avg_charge_H(k) < 0.9d0) then
>                allocate(m_old(1:s%nz))
>                m_old(k) = s% M_center_old + s% q_old(k)*s% xmstar_old !gr
>                m_50_new= s% m(k .eq. loc) *!s% m(loc) *
>                !m_50_old= m_old(loc)
>                delta_m= m_50_old - m_50_new
>                A= 1.3d13 !13.6 ev/hydrogen mass where the energy in erg/gr
>                E_recomb= s% X(loc)*delta_m*A !erg
>                s% extra_heat(k) = E_recomb/ s% nz !erg/g/s
>         end if
>       end do
>     end if
>       end subroutine energy_routine
>
>  yet the run won't compile.  The error displayed on the screen is:
>                 m_50_new= s% m(k .eq. loc) !s% m(loc)
>                               1
> *Error*: Array index at (1) must be of INTEGER type, found LOGICAL
>
> I also tried adding the line in bold instead of what I wrote for m_50_new,
> in this case the run compiles yet I get the run time error:
>
> *Fortran runtime error*: Index '-861944544' of dimension 1 of array 's%m'
> below lower bound of 1
>
> So I suppose m_50_new is filled with junk instead of the value of m in the
> index of loc.
>
> Is there any way to convert the logical type into integer, so I could use
> the mass in which avg_charge_H = 0.5 (the mass in the index loc)?
>
> if not, is there an alternative way (maybe a built in function) in order
> to find the index where avg_charge_H = 0.5 and use the mass of that index
> in the subroutine?
>
> Thank in advance,
>
> Aldana.
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.mesastar.org/pipermail/mesa-users/attachments/20180223/dea389de/attachment.html>


More information about the Mesa-users mailing list