88Edited by Hector Afonso G. Cruz
99JHU - July 2024
1010
11+ Edited by Sarah Libanore
12+ BGU - July 2025
13+
1114"""
1215
1316import numpy as np
@@ -144,12 +147,16 @@ def __init__(self, User_Parameters, Cosmo_Parameters, Astro_Parameters, ClassCos
144147 self .RSD_MODE = RSD_MODE #redshift-space distortion mode. 0 = None (mu=0), 1 = Spherical avg (like 21-cmFAST), 2 = LoS only (mu=1). 2 is more observationally relevant, whereas 1 the standard assumption in sims. 0 is just for comparison with real-space #TODO: mode to save at different mu
145148
146149 #first get the linear window functions -- note it already has growth factor in it, so it multiplies Pmatter(z=0)
147- self .kwindow , self .windowalpha_II = self .get_xa_window (Cosmo_Parameters , Correlations , T21_coefficients , pop = 2 )
148- self ._kwindowX , self .windowxray_II = self .get_Tx_window (Cosmo_Parameters , Correlations , T21_coefficients , pop = 2 )
150+ # SarahLibanore: add AstroParams to use flag on quadratic order
151+ self .kwindow , self .windowalpha_II = self .get_xa_window (Astro_Parameters , Cosmo_Parameters , Correlations , T21_coefficients , pop = 2 )
152+ # SarahLibanore: add AstroParams to use flag on quadratic order
153+ self ._kwindowX , self .windowxray_II = self .get_Tx_window (Astro_Parameters , Cosmo_Parameters , Correlations , T21_coefficients , pop = 2 )
149154
150155 if Astro_Parameters .USE_POPIII == True :
151- self .kwindow , self .windowalpha_III = self .get_xa_window (Cosmo_Parameters , Correlations , T21_coefficients , pop = 3 )
152- self ._kwindowX , self .windowxray_III = self .get_Tx_window (Cosmo_Parameters , Correlations , T21_coefficients , pop = 3 )
156+ # SarahLibanore: add AstroParams to use flag on quadratic order
157+ self .kwindow , self .windowalpha_III = self .get_xa_window (Astro_Parameters , Cosmo_Parameters , Correlations , T21_coefficients , pop = 3 )
158+ # SarahLibanore: add AstroParams to use flag on quadratic order
159+ self ._kwindowX , self .windowxray_III = self .get_Tx_window (Astro_Parameters , Cosmo_Parameters , Correlations , T21_coefficients , pop = 3 )
153160 else :
154161 self .windowalpha_III = np .zeros_like (self .windowalpha_II )
155162 self .windowxray_III = np .zeros_like (self .windowxray_II )
@@ -173,7 +180,8 @@ def __init__(self, User_Parameters, Cosmo_Parameters, Astro_Parameters, ClassCos
173180# print("STEP 1: Computing Nonlinear Power Spectra")
174181 #finally, get all the nonlinear correlation functions:
175182# print("Computing Pop II-dependent power spectra")
176- self .get_all_corrs_II (User_Parameters , Cosmo_Parameters , Correlations , T21_coefficients )
183+ # SarahLibanore: add AstroParams to use flag on quadratic order
184+ self .get_all_corrs_II (Astro_Parameters , User_Parameters , Cosmo_Parameters , Correlations , T21_coefficients )
177185
178186 if Astro_Parameters .USE_POPIII == True :
179187# print("Computing Pop IIxIII-dependent cross power spectra")
@@ -452,7 +460,8 @@ def __init__(self, User_Parameters, Cosmo_Parameters, Astro_Parameters, ClassCos
452460
453461
454462
455- def get_xa_window (self , Cosmo_Parameters , Correlations , T21_coefficients , pop = 0 ): #set pop to 2 or 3, default zero just so python doesn't complain
463+ # SarahLibanore: add AstroParams to use flag on quadratic order
464+ def get_xa_window (self , Astro_Parameters , Cosmo_Parameters , Correlations , T21_coefficients , pop = 0 ): #set pop to 2 or 3, default zero just so python doesn't complain
456465 "Returns the xa window function for all z in zintegral"
457466
458467 zGreaterMatrix100 = np .copy (T21_coefficients .zGreaterMatrix )
@@ -473,6 +482,9 @@ def get_xa_window(self, Cosmo_Parameters, Correlations, T21_coefficients, pop =
473482 print ("Must set pop to either 2 or 3!" )
474483
475484 _wincoeffsMatrix = coeffRmatrix * gammaRmatrix
485+ # SarahLibanore: quadratic order in the lognormal
486+ if Astro_Parameters .quadratic_SFRD_lognormal :
487+ _wincoeffsMatrix *= 1. / (1 - 2. * T21_coefficients .gamma2_II_index2D * T21_coefficients .sigmaofRtab ** 2 )
476488
477489 if (Cosmo_Parameters .Flag_emulate_21cmfast == False ): #do the standard 1D TopHat
478490 _wincoeffsMatrix /= (4 * np .pi * T21_coefficients .Rtabsmoo ** 2 ) * (T21_coefficients .Rtabsmoo * T21_coefficients .dlogRR ) # so we can just use mcfit for logFFT, 1/(4pir^2 * Delta r)
@@ -494,7 +506,8 @@ def get_xa_window(self, Cosmo_Parameters, Correlations, T21_coefficients, pop =
494506 return _kwinalpha , _win_alpha
495507
496508
497- def get_Tx_window (self , Cosmo_Parameters , Correlations , T21_coefficients , pop = 0 ): #set pop to 2 or 3, default zero just so python doesn't complain
509+ # SarahLibanore: add AstroParams to use flag on quadratic order
510+ def get_Tx_window (self , Astro_Parameters , Cosmo_Parameters , Correlations , T21_coefficients , pop = 0 ): #set pop to 2 or 3, default zero just so python doesn't complain
498511 "Returns the Tx window function for all z in zintegral"
499512
500513 zGreaterMatrix100 = np .copy (T21_coefficients .zGreaterMatrix )
@@ -514,6 +527,10 @@ def get_Tx_window(self, Cosmo_Parameters, Correlations, T21_coefficients, pop =
514527 else :
515528 print ("Must set pop to either 2 or 3!" )
516529
530+ # SarahLibanore: quadratic order in the lognormal
531+ if Astro_Parameters .quadratic_SFRD_lognormal :
532+ gammaRmatrix *= (1 / (1 - 2. * T21_coefficients .gamma2_II_index2D * T21_coefficients .sigmaofRtab ** 2 ))
533+
517534 if (Cosmo_Parameters .Flag_emulate_21cmfast == False ): #do the standard 1D TopHat
518535 _wincoeffs = coeffRmatrix * gammaRmatrix #array in logR space
519536 _wincoeffs /= (4 * np .pi * T21_coefficients .Rtabsmoo ** 2 ) * (T21_coefficients .Rtabsmoo * T21_coefficients .dlogRR ) # so we can just use mcfit for logFFT, 1/(4pir^2) * Delta r
@@ -538,8 +555,9 @@ def get_Tx_window(self, Cosmo_Parameters, Correlations, T21_coefficients, pop =
538555 return _kwinTx , _win_Tx
539556
540557
558+ # SarahLibanore: function modified to include quadratic order
559+ def get_all_corrs_II (self , Astro_Parameters , User_Parameters , Cosmo_Parameters , Correlations , T21_coefficients ):
541560
542- def get_all_corrs_II (self , User_Parameters , Cosmo_Parameters , Correlations , T21_coefficients ):
543561 "Returns the Pop II components of the correlation functions of all observables at each z in zintegral"
544562 #HAC: I deleted the bubbles and EoR part, to be done later.....
545563 #_iRnonlinear = np.arange(Cosmo_Parameters.indexminNL,Cosmo_Parameters.indexmaxNL)
@@ -556,38 +574,103 @@ def get_all_corrs_II(self, User_Parameters, Cosmo_Parameters, Correlations, T21_
556574 _coeffTx_units = T21_coefficients .coeff_Gammah_Tx_II #includes -10^40 erg/s/SFR normalizaiton and erg/K conversion factor
557575
558576 growthRmatrix = cosmology .growth (Cosmo_Parameters ,zGreaterMatrix100 [:, _iRnonlinear ])
559- gammaR1 = T21_coefficients .gamma_II_index2D [:, _iRnonlinear ] * growthRmatrix
560577
561578 coeffzp1xa = T21_coefficients .coeff1LyAzp * T21_coefficients .coeff_Ja_xa
562579 coeffzp1Tx = T21_coefficients .coeff1Xzp
563580
564581 coeffR1xa = T21_coefficients .coeff2LyAzpRR_II [:,_iRnonlinear ]
565582 coeffR1Tx = T21_coefficients .coeff2XzpRR_II [:,_iRnonlinear ]
566583
567- gammamatrixR1R1 = gammaR1 .reshape (len (T21_coefficients .zintegral ), 1 , len (_iRnonlinear ),1 ) * gammaR1 .reshape (len (T21_coefficients .zintegral ), len (_iRnonlinear ), 1 ,1 )
568584 coeffmatrixxa = coeffR1xa .reshape (len (T21_coefficients .zintegral ), 1 , len (_iRnonlinear ),1 ) * coeffR1xa .reshape (len (T21_coefficients .zintegral ), len (_iRnonlinear ), 1 ,1 )
569585
570- gammaTimesCorrdNL = ne .evaluate ('gammamatrixR1R1 * corrdNL' )#np.einsum('ijkl,ijkl->ijkl', gammamatrixR1R1, corrdNL, optimize = True) #same thing as gammamatrixR1R1 * corrdNL but faster
571- expGammaCorrMinusLinear = ne .evaluate ('exp(gammaTimesCorrdNL) - 1 - gammaTimesCorrdNL' )
586+ # gammaR1 = T21_coefficients.gamma_II_index2D[:, _iRnonlinear] * growthRmatrix
587+ # gammamatrixR1R1 = gammaR1.reshape(len(T21_coefficients.zintegral), 1, len(_iRnonlinear),1) * gammaR1.reshape(len(T21_coefficients.zintegral), len(_iRnonlinear), 1,1)
588+
589+ # gammaTimesCorrdNL = ne.evaluate('gammamatrixR1R1 * corrdNL')#np.einsum('ijkl,ijkl->ijkl', gammamatrixR1R1, corrdNL, optimize = True) #same thing as gammamatrixR1R1 * corrdNL but faster
590+
591+
592+ # SarahLibanore : change to introduce quantities required in the second order correction
593+ # --- #
594+ growthRmatrix1 = growthRmatrix .reshape (len (T21_coefficients .zintegral ), 1 , len (_iRnonlinear ),1 )
595+ growthRmatrix2 = growthRmatrix .reshape (len (T21_coefficients .zintegral ), len (_iRnonlinear ), 1 ,1 )
596+ growth_corr = growthRmatrix1 * growthRmatrix2
597+
598+ gammaR1 = T21_coefficients .gamma_II_index2D [:, _iRnonlinear ]
599+ sigmaR1 = T21_coefficients .sigmaofRtab [:, _iRnonlinear ]
600+ sR1 = (sigmaR1 ).reshape (len (T21_coefficients .zintegral ), 1 , len (_iRnonlinear ),1 )
601+ sR2 = (sigmaR1 ).reshape (len (T21_coefficients .zintegral ), len (_iRnonlinear ), 1 ,1 )
602+
603+ g1 = (gammaR1 * sigmaR1 ).reshape (len (T21_coefficients .zintegral ), 1 , len (_iRnonlinear ),1 )
604+ g2 = (gammaR1 * sigmaR1 ).reshape (len (T21_coefficients .zintegral ), len (_iRnonlinear ), 1 ,1 )
605+ gammamatrixR1R1 = g1 * g2
606+
607+ corrdNL_gs = ne .evaluate ('corrdNL * growth_corr/ (sR1 * sR2)' )
608+ gammaTimesCorrdNL = ne .evaluate ('gammamatrixR1R1 * corrdNL_gs' )
609+
610+ if Astro_Parameters .quadratic_SFRD_lognormal :
611+
612+ gammaR1NL = T21_coefficients .gamma2_II_index2D [:, _iRnonlinear ]
613+ g1NL = (gammaR1NL * sigmaR1 ** 2 ).reshape (len (T21_coefficients .zintegral ), 1 , len (_iRnonlinear ),1 )
614+ g2NL = (gammaR1NL * sigmaR1 ** 2 ).reshape (len (T21_coefficients .zintegral ), len (_iRnonlinear ), 1 ,1 )
615+
616+ numerator_NL = ne .evaluate ('gammaTimesCorrdNL+ g1 * g1 * (0.5 - g2NL * (1 - corrdNL_gs * corrdNL_gs)) + g2 * g2 * (0.5 - g1NL * (1 - corrdNL_gs * corrdNL_gs))' )
617+
618+ denominator_NL = ne .evaluate ('1. - 2 * g1NL - 2 * g2NL + 4 * g1NL * g2NL * (1 - corrdNL_gs * corrdNL_gs)' )
619+
620+ norm1 = ne .evaluate ('exp(g1 * g1 / (2 - 4 * g1NL)) / sqrt(1 - 2 * g1NL)' )
621+ norm2 = ne .evaluate ('exp(g2 * g2 / (2 - 4 * g2NL)) / sqrt(1 - 2 * g2NL)' )
622+
623+ log_norm = ne .evaluate ('log(sqrt(denominator_NL) * norm1 * norm2)' )
624+ nonlinearcorrelation = ne .evaluate ('exp(numerator_NL/denominator_NL - log_norm)' )
625+
626+ # use second order in SFRD lognormal approx
627+ expGammaCorrMinusLinear = ne .evaluate ('nonlinearcorrelation - 1-gammaTimesCorrdNL/((-1+2.*g1NL)*(-1+2.*g2NL))' )
628+ else :
629+ expGammaCorrMinusLinear = ne .evaluate ('exp(gammaTimesCorrdNL) - 1 - gammaTimesCorrdNL' )
630+
572631 self ._II_deltaxi_xa = np .einsum ('ijkl->il' , coeffmatrixxa * expGammaCorrMinusLinear , optimize = True )
573632 self ._II_deltaxi_xa *= np .array ([coeffzp1xa ]).T ** 2 #brings it to xa units
574633
575634 if (User_Parameters .FLAG_DO_DENS_NL ):
576635 D_coeffR1xa = coeffR1xa .reshape (* coeffR1xa .shape , 1 )
577- D_gammaR1 = gammaR1 .reshape (* gammaR1 .shape , 1 )
636+ DDgammaR1 = T21_coefficients .gamma_II_index2D [:, _iRnonlinear ]
637+ D_gammaR1 = DDgammaR1 .reshape (* DDgammaR1 .shape , 1 )
578638 D_growthRmatrix = growthRmatrix [:,:1 ].reshape (* growthRmatrix [:,:1 ].shape , 1 )
579639 D_corrdNL = corrdNL [:1 ,0 ,:,:]
580640
581- self ._II_deltaxi_dxa = np .sum (D_coeffR1xa * ((np .exp (D_gammaR1 * D_growthRmatrix * D_corrdNL )- 1.0 ) - D_gammaR1 * D_growthRmatrix * D_corrdNL ), axis = 1 )
582- self ._II_deltaxi_dxa *= np .array ([coeffzp1xa ]).T
641+ # SarahLibanore
642+ if Astro_Parameters .quadratic_SFRD_lognormal :
643+
644+ DDsigmaR1 = T21_coefficients .sigmaofRtab [:, _iRnonlinear ]
645+ D_sigmaR1 = DDsigmaR1 .reshape (* DDsigmaR1 .shape , 1 )
646+ DDgammaR1N = T21_coefficients .gamma2_II_index2D [:, _iRnonlinear ]
647+ D_gammaR1N = DDgammaR1N .reshape (* DDgammaR1N .shape , 1 )
648+
649+ gammaTimesCorrdNL = ne .evaluate ('D_gammaR1 * D_growthRmatrix* D_growthRmatrix * D_corrdNL' )
650+ numerator_NL = ne .evaluate ('gammaTimesCorrdNL+ D_gammaR1 * D_gammaR1 * D_sigmaR1* D_sigmaR1 /2 + D_gammaR1N * D_growthRmatrix * D_growthRmatrix* D_growthRmatrix * D_growthRmatrix * (D_corrdNL * D_corrdNL)' )
651+
652+ denominator_NL = ne .evaluate ('1. - 2 * D_gammaR1N*D_sigmaR1*D_sigmaR1' )
653+
654+ norm1 = ne .evaluate ('exp(D_gammaR1 * D_gammaR1 * D_sigmaR1* D_sigmaR1 * D_gammaR1 * D_gammaR1 * D_sigmaR1* D_sigmaR1 / (2 - 4 * D_gammaR1N*D_sigmaR1*D_sigmaR1)) / sqrt(1 - 2 * D_gammaR1N*D_sigmaR1*D_sigmaR1)' )
655+
656+ log_norm = ne .evaluate ('log(sqrt(denominator_NL) * norm1)' )
657+ nonlinearcorrelation = ne .evaluate ('exp(numerator_NL/denominator_NL - log_norm)' )
658+
659+ self ._II_deltaxi_dxa = np .sum (D_coeffR1xa * (
660+ nonlinearcorrelation - 1 - D_gammaR1 * D_growthRmatrix ** 2 * D_corrdNL / (1 - 2. * D_gammaR1N * D_sigmaR1 ** 2 )
661+ ), axis = 1 )
662+
663+ else :
664+ self ._II_deltaxi_dxa = np .sum (D_coeffR1xa * ((np .exp (D_gammaR1 * D_growthRmatrix ** 2 * D_corrdNL )- 1.0 ) - D_gammaR1 * D_growthRmatrix ** 2 * D_corrdNL ), axis = 1 )
583665
584666 self ._II_deltaxi_d = (np .exp (growthRmatrix [:,:1 ]** 2 * corrdNL [0 ,0 ,0 ,:]) - 1.0 ) - growthRmatrix [:,:1 ]** 2 * corrdNL [0 ,0 ,0 ,:]
585-
667+
668+ self ._II_deltaxi_dxa *= np .array ([coeffzp1xa ]).T
586669
587670
588671 ### To compute Tx quantities, I'm broadcasting arrays such that the axes are zp1, R1, zp2, R2, and looping over r
589- gammaR2 = np .copy (gammaR1 ) #already has growth factor in this
590- gammamatrixR1R2 = gammaR1 .reshape (* gammaR1 .shape , 1 , 1 ) * gammaR2 .reshape (1 , 1 , * gammaR2 .shape )
672+ # gammaR2 = np.copy(gammaR1) #already has growth factor in this
673+ # gammamatrixR1R2 = gammaR1.reshape(*gammaR1.shape, 1, 1) * gammaR2.reshape(1, 1, *gammaR2.shape)
591674
592675 coeffzp1Tx = np .copy (T21_coefficients .coeff1Xzp ).reshape (* T21_coefficients .coeff1Xzp .shape , 1 , 1 , 1 )
593676 coeffzp2Tx = np .copy (T21_coefficients .coeff1Xzp ).reshape (1 , 1 , * T21_coefficients .coeff1Xzp .shape , 1 )
@@ -598,16 +681,48 @@ def get_all_corrs_II(self, User_Parameters, Cosmo_Parameters, Correlations, T21_
598681 coeffsTxALL = coeffzp1Tx * coeffzp2Tx * coeffmatrixTxTx
599682 coeffsXaTxALL = coeffzp2Tx * coeffmatrixxaTx
600683
684+ gammaR2 = np .copy (gammaR1 ) #already has growth factor in this
685+ sigmaR2 = np .copy (sigmaR1 ) #already has growth factor in this
686+
687+ growthRmatrix1 = growthRmatrix .reshape (* gammaR1 .shape , 1 , 1 )
688+ growthRmatrix2 = growthRmatrix .reshape (1 , 1 , * gammaR2 .shape )
689+ growth_corr = growthRmatrix1 * growthRmatrix2
690+
691+ g1 = (gammaR1 * sigmaR1 ).reshape (* gammaR1 .shape , 1 , 1 )
692+ sR1 = (sigmaR1 ).reshape (* gammaR1 .shape , 1 , 1 )
693+ g2 = (gammaR2 * sigmaR2 ).reshape (1 , 1 , * gammaR2 .shape )
694+ sR2 = (sigmaR2 ).reshape (1 , 1 , * gammaR2 .shape )
695+ if Astro_Parameters .quadratic_SFRD_lognormal :
696+ gammaR2NL = np .copy (gammaR1NL )
697+ g1NL = (gammaR1NL * sigmaR1 ** 2 ).reshape (* gammaR1NL .shape , 1 , 1 )
698+ g2NL = (gammaR2NL * sigmaR2 ** 2 ).reshape (1 , 1 , * gammaR2NL .shape )
699+
700+ gammamatrixR1R2 = g1 * g2
601701
602702 self ._II_deltaxi_Tx = np .zeros_like (self ._II_deltaxi_xa )
603703 self ._II_deltaxi_xaTx = np .zeros_like (self ._II_deltaxi_xa )
604704 corrdNLBIG = corrdNL [:,:, np .newaxis , :,:] #dimensions zp1, R1, zp2, R2, and r which will be looped over below
605705 for ir in range (len (T21_coefficients .Rtabsmoo )):
606706 corrdNL = corrdNLBIG [:,:,:,:,ir ]
607707
708+ corrdNL_gs = ne .evaluate ('corrdNL * growth_corr / (sR1 * sR2)' )
709+
608710 #HAC: Computations using ne.evaluate(...) use numexpr, which speeds up computations of massive numpy arrays
609- gammaTimesCorrdNL = ne .evaluate ('gammamatrixR1R2 * corrdNL' )
610- expGammaCorrMinusLinear = ne .evaluate ('exp(gammaTimesCorrdNL) - 1 - gammaTimesCorrdNL' )
711+ gammaTimesCorrdNL = ne .evaluate ('gammamatrixR1R2 * corrdNL_gs' )
712+ if Astro_Parameters .quadratic_SFRD_lognormal :
713+
714+ numerator_NL = ne .evaluate ('gammaTimesCorrdNL + g1 * g1 * (0.5 - g2NL * (1 - corrdNL_gs * corrdNL_gs)) + g2 * g2 * (0.5 - g1NL * (1 - corrdNL_gs * corrdNL_gs))' )
715+ denominator_NL = ne .evaluate ('1. - 2 * g1NL - 2 * g2NL + 4 * g1NL * g2NL * (1 - corrdNL_gs * corrdNL_gs)' )
716+ norm1 = ne .evaluate ('exp(g1 * g1 / (2 - 4 * g1NL)) / sqrt(1 - 2 * g1NL)' )
717+ norm2 = ne .evaluate ('exp(g2 * g2 / (2 - 4 * g2NL)) / sqrt(1 - 2 * g2NL)' )
718+
719+ log_norm = ne .evaluate ('log(sqrt(denominator_NL) * norm1 * norm2)' )
720+ nonlinearcorrelation = ne .evaluate ('exp(numerator_NL/denominator_NL - log_norm)' )
721+
722+ # use second order in SFRD lognormal approx
723+ expGammaCorrMinusLinear = ne .evaluate ('nonlinearcorrelation - 1-gammaTimesCorrdNL/((-1+2.*g1NL)*(-1+2.*g2NL))' )
724+ else :
725+ expGammaCorrMinusLinear = ne .evaluate ('exp(gammaTimesCorrdNL) - 1 - gammaTimesCorrdNL' )
611726
612727 deltaXiTxAddend = ne .evaluate ('coeffsTxALL * expGammaCorrMinusLinear' )
613728 deltaXiTxAddend = np .einsum ('ijkl->ik' , deltaXiTxAddend , optimize = True ) #equivalent to np.sum(deltaXiTxAddend, axis = (1, 3))
@@ -630,11 +745,33 @@ def get_all_corrs_II(self, User_Parameters, Cosmo_Parameters, Correlations, T21_
630745 if (User_Parameters .FLAG_DO_DENS_NL ):
631746 D_coeffR2Tx = coeffR2Tx .reshape (1 , * coeffR2Tx .shape , 1 )
632747 D_coeffzp2Tx = coeffzp2Tx .flatten ().reshape (1 , * coeffzp2Tx .flatten ().shape , 1 )
633- D_gammaR2 = gammaR2 .reshape (1 , * gammaR2 .shape , 1 )
748+ DDgammaR2 = np .copy (DDgammaR1 )
749+ D_gammaR2 = DDgammaR2 .reshape (1 , * DDgammaR2 .shape , 1 )
634750 D_growthRmatrix = growthRmatrix [:,0 ].reshape (* growthRmatrix [:,0 ].shape , 1 , 1 , 1 )
635751 D_corrdNL = corrdNLBIG .squeeze ()[0 ].reshape (1 , 1 , * corrdNLBIG .squeeze ()[0 ].shape )
752+
753+ if Astro_Parameters .quadratic_SFRD_lognormal :
754+
755+ DDsigmaR2 = np .copy (DDsigmaR1 )
756+ D_sigmaR2 = DDsigmaR2 .reshape (1 , * DDsigmaR2 .shape , 1 )
757+ DDgammaR2N = np .copy (DDgammaR1N )
758+ D_gammaR2N = DDgammaR2N .reshape (1 , * DDgammaR2N .shape , 1 )
759+
760+ gammaTimesCorrdNL = ne .evaluate ('D_gammaR2 * D_growthRmatrix* D_growthRmatrix * D_corrdNL' )
761+ numerator_NL = ne .evaluate ('gammaTimesCorrdNL+ D_gammaR2 * D_gammaR2 * D_sigmaR2* D_sigmaR2 /2 + D_gammaR2N * D_growthRmatrix* D_growthRmatrix* D_growthRmatrix* D_growthRmatrix * (D_corrdNL * D_corrdNL)' )
762+
763+ denominator_NL = ne .evaluate ('1. - 2 * D_gammaR2N*D_sigmaR2*D_sigmaR2' )
764+
765+ norm2 = ne .evaluate ('exp(D_gammaR2 * D_gammaR2 * D_sigmaR2* D_sigmaR2 * D_gammaR2 * D_gammaR2 * D_sigmaR2* D_sigmaR2 / (2 - 4 * D_gammaR2N*D_sigmaR2*D_sigmaR2)) / sqrt(1 - 2 * D_gammaR2N*D_sigmaR2*D_sigmaR2)' )
766+
767+ log_norm = ne .evaluate ('log(sqrt(denominator_NL) * norm2)' )
768+ nonlinearcorrelation = ne .evaluate ('exp(numerator_NL/denominator_NL - log_norm)' )
769+
770+ self ._II_deltaxi_dTx = D_coeffzp2Tx * np .sum (D_coeffR2Tx * (nonlinearcorrelation - 1 - D_gammaR2 * D_growthRmatrix ** 2 * D_corrdNL / (1 - 2. * D_gammaR2N * D_sigmaR2 ** 2 )), axis = 2 )
771+
772+ else :
773+ self ._II_deltaxi_dTx = D_coeffzp2Tx * np .sum (D_coeffR2Tx * ((np .exp (D_gammaR2 * D_growthRmatrix ** 2 * D_corrdNL )- 1.0 ) - D_gammaR2 * D_growthRmatrix ** 2 * D_corrdNL ), axis = 2 )
636774
637- self ._II_deltaxi_dTx = D_coeffzp2Tx * np .sum (D_coeffR2Tx * ((np .exp (D_gammaR2 * D_growthRmatrix * D_corrdNL )- 1.0 ) - D_gammaR2 * D_growthRmatrix * D_corrdNL ), axis = 2 )
638775
639776 self ._II_deltaxi_dTx = np .moveaxis (self ._II_deltaxi_dTx , 1 , 0 )
640777 self ._II_deltaxi_dTx = np .cumsum (self ._II_deltaxi_dTx [::- 1 ], axis = 0 )[::- 1 ]
0 commit comments