1CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
2C HSUBP
3CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
4 SUBROUTINE HSUBP (HCOMP,HD,HP,HR,HS,HT,JEDGE,PSCAHE)
5C 10/15/26 MHP via Claude
6C code changed to take JSON from DIMENSIONS_MOD instead of declaring
7C PARAMETER(JSON=5000) here.
8 USE DIMENSIONS_MOD
9C 10/14/26 MHP via Claude
10C code changed to convert COMMON/DEBHU/ into DEBHU_MOD.
11 USE DEBHU_MOD
12C 10/14/26 MHP via Claude
13C code changed to convert COMMON/NMLPAR/ into NMLPAR_MOD.
14 USE NMLPAR_MOD
15C 10/14/26 MHP via Claude
16C code changed to convert COMMON/CONSTANTS/ into CONSTANTS_MOD.
17 USE CONSTANTS_MOD
18C 10/20/26 MHP via Claude
19C code changed to replace implicit typing with IMPLICIT NONE and
20C explicit declarations.
21 IMPLICIT NONE
22 REAL*8 AMU,BETA,BETA14,BETAI,D,DELA,DL,EMU,ETA,FXION,HCOMP,HD,HP,
23 * * HR,HS,HT,P,PL,PSCAHE,PSCAP,QAP,QAT,QCP,QCPP,QCPT,QDP,QDT,
24 * * QDTP,QDTT,RL,RMU,SL,T,TL,X,Z
25 INTEGER JEDGE,KSAHA
26 LOGICAL*4 LATMO,LDERIV
27
28C 9/25/26 MHP via Claude
29C code changed to merge COMMON/CONST/, COMMON/CONST1/, COMMON/CONST2/,
30C and COMMON/CONST3/ into a single COMMON/CONSTANTS/
31C DBG 7/92 COMMON BLOCK ADDED TO COMPUTE DEBYE-HUCKEL CORRECTION.
32C 10/12/26 MHP via Claude
33C code changed to extend COMMON/NMLPAR/ to 234 members, adding the
34C namelist variables that the physics routines read from 27 COMMON
35C blocks which also held derived or working members. Those blocks keep
36C only their non-namelist members; five of them -- NEWMX, VMULT,
37C PMMWIND, CCOUT1 and ENVGEN -- had nothing left and are gone.
38C Derivation-only namelist variables from the same blocks went to
39C COMMON/NMLBYPASS/ instead, not here.
40C
41C Declared identically in all 121 files that hold any of these members.
42C Generated from one member list, so every copy is byte-identical; the
43C linker's 'size of symbol changed' warning is the check that they are.
44 DIMENSION HCOMP(15,JSON),HD(JSON),HP(JSON),HR(JSON),HS(JSON),
45 * * HT(JSON),FXION(3)
46 SAVE
47
48C *** CALCULATES THE LOCAL PRESSURE SCALE HEIGHT AT THE EDGE OF A
49C CONVECTIVE REGION (PD DEC. 1984) 2/91 MHP REVISED FOR YREC/MARK6***
50C
51C CALL EQUATION OF STATE TO DETERMINE THE MEAN MOLECULAR WEIGHT.
52 LDERIV = .FALSE.
53 LATMO = .TRUE.
54 KSAHA = 0
55 X = HCOMP(1,JEDGE)
56 Z = HCOMP(3,JEDGE)
57 PL = HP(JEDGE)
58 TL = HT(JEDGE)
59 DL = HD(JEDGE)
60 IF (LDH) THEN
61 XXDH = HCOMP(1,JEDGE)
62 YYDH = HCOMP(2,JEDGE)+HCOMP(4,JEDGE)
63 ZZDH = HCOMP(3,JEDGE)
64 ZDH(1) = HCOMP(5,JEDGE)+HCOMP(6,JEDGE)
65 ZDH(2) = HCOMP(7,JEDGE)+HCOMP(8,JEDGE)
66 ZDH(3) = HCOMP(9,JEDGE)+HCOMP(10,JEDGE)+HCOMP(11,JEDGE)
67 END IF
68 CALL EQSTAT(TL,T,PL,P,DL,D,X,Z,BETA,BETAI,BETA14,FXION,
69 * * RMU,AMU,EMU,ETA,QDT,QDP,QCP,DELA,QDTT,QDTP,
70 * * QAT,QAP,QCPT,QCPP,LDERIV,LATMO,KSAHA)
71C COMPUTE PRESSURE SCALE HEIGHT.
72 SL = HS(JEDGE)
73 RL = HR(JEDGE)
74 PSCAP = RMU*EXP(CLN*(TL-CGL-SL+RL+RL))
75 PSCAHE = EXP(CLN*(PL + 2.0D0*RL - DL - CGL - SL))
76 RETURN
77 END
1"""Python version of hsubp.f (YREC 7be4133): the pressure scale height at
2the edge of a convective region, for the overshoot."""
3
4import math
5
6import numpy as np
7
8from pyrec import constants_mod
9from pyrec import debhu_mod
10from pyrec import nmlpar_mod
11from pyrec.eqstat import eqstat
12
13# SAVE: the ionization fractions from the equation of state.
14fxion = np.zeros(3 + 1)
15
16
17def hsubp(hcomp: np.ndarray, hd: np.ndarray, hp: np.ndarray, hr: np.ndarray, hs: np.ndarray, ht: np.ndarray, jedge: int,
18 pscahe: float) -> float:
19 """Return the hydrostatic pressure scale height P r**2 / (rho G m) at
20 point jedge, with rho from the equation of state at the point's P,
21 T, X, Z (setting the Debye-Hueckel composition first, with
22 nmlpar_mod.ldh).
23
24 Translates: hsubp.f#HSUBP (7be4133)
25
26 Arguments: hcomp, hd, hp, hr, hs, ht (the model: composition, log
27 rho, log P, log r, log m, log T), jedge (the point); pscahe is only
28 set.
29
30 Returns pscahe, in cm.
31
32 """
33
34 c = constants_mod
35
36 # The equation of state at the point (Fortran lines 51–70).
37 lderiv = False
38 latmo = True
39 ksaha = 0
40 x = hcomp[1, jedge]
41 z = hcomp[3, jedge]
42 pl = hp[jedge]
43 tl = ht[jedge]
44 dl = hd[jedge]
45 if nmlpar_mod.ldh:
46 # Question (see the page): overwrites the Debye-Hueckel
47 # composition other EOS callers may rely on.
48 debhu_mod.xxdh = hcomp[1, jedge]
49 debhu_mod.yydh = hcomp[2, jedge] + hcomp[4, jedge]
50 debhu_mod.zzdh = hcomp[3, jedge]
51 debhu_mod.zdh[1] = hcomp[5, jedge] + hcomp[6, jedge]
52 debhu_mod.zdh[2] = hcomp[7, jedge] + hcomp[8, jedge]
53 debhu_mod.zdh[3] = hcomp[9, jedge] + hcomp[10, jedge] + hcomp[11, jedge]
54 (t, p, dl, d, beta, betai, beta14, rmu, amu, emu, eta, qdt, qdp, qcp,
55 dela, qdtt, qdtp, qat, qap, qcpt, qcpp, ksaha) = eqstat(
56 tl, 0.0, pl, 0.0, dl, 0.0, x, z, 0.0, 0.0, 0.0, fxion, 0.0, 0.0,
57 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
58 lderiv, latmo, ksaha)
59
60 # The pressure scale height (Fortran lines 71–75).
61 # Question (see the page): the EOS density, not hd[jedge].
62 sl = hs[jedge]
63 rl = hr[jedge]
64 pscap = rmu * math.exp(c.cln * (tl - c.cgl - sl + rl + rl)) # noqa: F841 (unused in the Fortran too)
65 pscahe = math.exp(c.cln * (pl + 2.0 * rl - dl - c.cgl - sl))
66 return pscahe