Skip to content

Commit 0acf73d

Browse files
rjfarmeradamjermyn
andauthored
Other pressure implicit (#551)
Changed other_pressure hook to be implicit. --------- Co-authored-by: Adam Jermyn <[email protected]>
1 parent 3fb7174 commit 0acf73d

File tree

7 files changed

+46
-7
lines changed

7 files changed

+46
-7
lines changed

docs/source/changelog.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ Changes in main
1010

1111
.. _Backwards-incompatible changes main:
1212

13+
Backwards-incompatible changes
14+
------------------------------
15+
16+
Hooks
17+
-----
18+
19+
The ``other_pressure`` hook has been converted to use ``auto_diff``
20+
thus the variable ``s% extra_pressure`` is now an ``auto_diff``
21+
and allows for the setting of the partial derivatives the
22+
pressure with respect to other variables.
23+
24+
25+
1326
Changes in r23.05.1
1427
===================
1528

star/other/other_pressure.f90

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,18 @@ module other_pressure
3838

3939
subroutine default_other_pressure(id, ierr)
4040
use star_def
41+
use auto_diff
4142
integer, intent(in) :: id
4243
integer, intent(out) :: ierr
4344
type (star_info), pointer :: s
4445
integer :: k
4546
ierr = 0
4647
call star_ptr(id, s, ierr)
4748
if (ierr /= 0) return
48-
s% extra_pressure(:) = 0d0
49+
do k=1,s%nz
50+
s% extra_pressure(k) = 0d0
51+
end do
52+
! note that extra_pressure is type(auto_diff_real_star_order1) so includes partials.
4953
return
5054
end subroutine default_other_pressure
5155

star/private/alloc.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ subroutine star_info_arrays(s, c_in, action_in, ierr)
934934
call do1(s% extra_opacity_factor, c% extra_opacity_factor)
935935
if (failed('extra_opacity_factor')) exit
936936

937-
call do1(s% extra_pressure, c% extra_pressure)
937+
call do1_ad(s% extra_pressure, c% extra_pressure)
938938
if (failed('extra_pressure')) exit
939939
call do1(s% eps_heat, c% eps_heat)
940940
if (failed('eps_heat')) exit

star/private/hydro_energy.f90

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,12 +573,12 @@ subroutine eval1_work(s, k, skip_Peos, &
573573
real(dp), dimension(s% species), intent(out) :: &
574574
d_work_dxa00, d_work_dxam1
575575
integer, intent(out) :: ierr
576-
real(dp) :: alfa, beta, P_theta, extra_P, Peos_face, Av_face
576+
real(dp) :: alfa, beta, P_theta, Peos_face, Av_face
577577
real(dp), dimension(s% species) :: d_Pface_dxa00, d_Pface_dxam1
578578
type(auto_diff_real_star_order1) :: &
579579
P_face_ad, A_times_v_face_ad, mlt_Pturb_ad, &
580580
PtrbR_ad, PtrbL_ad, PvscL_ad, PvscR_ad, Ptrb_div_etrb, PL_ad, PR_ad, &
581-
Peos_ad, Ptrb_ad, Pvsc_ad, inv_R2
581+
Peos_ad, Ptrb_ad, Pvsc_ad, inv_R2, extra_P
582582
logical :: test_partials
583583
integer :: j
584584
include 'formats'
@@ -694,7 +694,8 @@ subroutine eval1_work(s, k, skip_Peos, &
694694
if (.not. s% use_other_pressure) then
695695
extra_P = 0d0
696696
else if (k > 1) then
697-
extra_P = alfa*s% extra_pressure(k) + beta*s% extra_pressure(k-1)
697+
! my_val_m1 = shift_m1(get_my_val(s,k-1)) for use in terms going into equation at k
698+
extra_P = alfa*s% extra_pressure(k) + beta * shift_m1(s%extra_pressure(k-1))
698699
else
699700
extra_P = s% extra_pressure(k)
700701
end if

star/private/star_utils.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3284,7 +3284,7 @@ subroutine calc_Ptot_ad_tw( &
32843284

32853285
Ptot_ad = Peos_ad + Pvsc_ad + Ptrb_ad + mlt_Pturb_ad
32863286

3287-
if (s% use_other_pressure) Ptot_ad%val = Ptot_ad%val + s% extra_pressure(k)
3287+
if (s% use_other_pressure) Ptot_ad = Ptot_ad + s% extra_pressure(k)
32883288

32893289
end subroutine calc_Ptot_ad_tw
32903290

star/test_suite/other_physics_hooks/src/run_star_extras.f90

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ subroutine extras_controls(id, ierr)
8080
s% use_other_close_gaps = .true.
8181
s% other_close_gaps => my_close_gaps
8282

83+
s% use_other_pressure = .true.
84+
s% other_pressure => my_other_pressure
85+
8386
s% extras_startup => extras_startup
8487
s% extras_check_model => extras_check_model
8588
s% extras_finish_step => extras_finish_step
@@ -418,6 +421,24 @@ subroutine my_close_gaps(id, mix_type, min_gap, ierr)
418421
end subroutine my_close_gaps
419422

420423

424+
subroutine my_other_pressure(id, ierr)
425+
use star_def
426+
use auto_diff
427+
integer, intent(in) :: id
428+
integer, intent(out) :: ierr
429+
type (star_info), pointer :: s
430+
integer :: k
431+
ierr = 0
432+
call star_ptr(id, s, ierr)
433+
if (ierr /= 0) return
434+
do k=1,s%nz
435+
s% extra_pressure(k) = 0d0
436+
end do
437+
! note that extra_pressure is type(auto_diff_real_star_order1) so includes partials.
438+
return
439+
end subroutine my_other_pressure
440+
441+
421442

422443
end module run_star_extras
423444

star_data/public/star_data_step_work.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@
276276
real(dp), pointer, dimension(:) :: extra_opacity_factor
277277

278278
! extra pressure profile (can be set by user)
279-
real(dp), pointer :: extra_pressure(:) ! (ergs/gm/sec)
279+
type(auto_diff_real_star_order1), pointer, dimension(:) :: extra_pressure(:) ! (ergs/gm/sec)
280280

281281
! extra heat profile (can be set by user)
282282
type(auto_diff_real_star_order1), pointer, dimension(:) :: extra_heat

0 commit comments

Comments
 (0)