@@ -226,15 +226,10 @@ def magnetic_amplitude(kz,
226
226
227
227
sld_b , u1 , u3 = calculate_u1_u3 (H , rhoM , thetaM , Aguide )
228
228
229
- R1 , R2 , R3 , R4 = [np .empty (kz .shape , 'D' ) for pol in (1 , 2 , 3 , 4 )]
230
- # reflmodule._magnetic_amplitude(depth, sigma, rho, irho,
231
- # sld_b, u1, u3, Aguide, kz, rho_index,
232
- # R1, R2, R3, R4)
233
-
234
- magnetic_amplitude_py (depth , sigma , rho , irho ,
235
- sld_b , u1 , u3 , kz , rho_index ,
236
- R1 , R2 , R3 , R4 )
237
- return R1 , R2 , R3 , R4
229
+ # Note 2021-08-01: return Rpp, Rpm, Rmp, Rmm are no longer contiguous.
230
+ R = np .empty ((kz .size , 4 ), 'D' )
231
+ magnetic_amplitude_py (depth , sigma , rho , irho , sld_b , u1 , u3 , kz , R )
232
+ return R [:, 0 ], R [:, 1 ], R [:, 2 ], R [:, 3 ]
238
233
239
234
240
235
def calculate_u1_u3 (H , rhoM , thetaM , Aguide ):
@@ -553,17 +548,17 @@ def Cr4xa(N, D, SIGMA, IP, RHO, IRHO, RHOM, U1, U3, KZ, Y):
553
548
554
549
555
550
# Calculate reflectivity coefficients specified by POLSTAT
556
- Y [0 ] = (B24 * B41 - B21 * B44 )/ DETW # ++
557
- Y [1 ] = (B21 * B42 - B41 * B22 )/ DETW # +-
551
+ # IP = +1 fills in ++, +-, -+, --; IP = -1 only fills in -+, --.
552
+ if IP > 0 :
553
+ Y [0 ] = (B24 * B41 - B21 * B44 )/ DETW # ++
554
+ Y [1 ] = (B21 * B42 - B41 * B22 )/ DETW # +-
558
555
Y [2 ] = (B24 * B43 - B23 * B44 )/ DETW # -+
559
556
Y [3 ] = (B23 * B42 - B43 * B22 )/ DETW # --
560
557
561
558
#@cc.export('mag_amplitude')
562
- MAGAMP_SIG = 'void(f8[:], f8[:], f8[:], f8[:], f8[:], c16[:], c16[:], f8[:], i4[:], c16[:], c16[:], c16[:], c16[ :])'
559
+ MAGAMP_SIG = 'void(f8[:], f8[:], f8[:], f8[:], f8[:], c16[:], c16[:], f8[:], c16[:, :])'
563
560
@njit (MAGAMP_SIG , parallel = True , cache = True )
564
- def magnetic_amplitude_py (d , sigma , rho , irho ,
565
- rhoM , u1 , u3 , KZ , rho_index ,
566
- Ra , Rb , Rc , Rd ):
561
+ def magnetic_amplitude_py (d , sigma , rho , irho , rhoM , u1 , u3 , KZ , R ):
567
562
"""
568
563
python version of calculation
569
564
implicit returns: Ra, Rb, Rc, Rd
@@ -574,22 +569,17 @@ def magnetic_amplitude_py(d, sigma, rho, irho,
574
569
if (np .fabs (rhoM [0 ]) <= MINIMAL_RHO_M and np .fabs (rhoM [layers - 1 ]) <= MINIMAL_RHO_M ):
575
570
# calculations for I+ and I- are the same in the fronting and backing.
576
571
for i in prange (points ):
577
- Y = np .empty (4 , dtype = np .complex128 )
578
- Cr4xa (layers , d , sigma , 1.0 , rho , irho , rhoM , u1 , u3 , KZ [i ], Y )
579
- Ra [i ], Rb [i ], Rc [i ], Rd [i ] = Y [0 ], Y [1 ], Y [2 ], Y [3 ]
572
+ Cr4xa (layers , d , sigma , 1.0 , rho , irho , rhoM , u1 , u3 , KZ [i ], R [i ])
580
573
else :
581
- # plus polarization
574
+ # plus polarization must be before minus polarization because it
575
+ # fills in all R++, R+-, R-+, R--, but minus polarization only fills
576
+ # in R-+, R--.
582
577
for i in prange (points ):
583
- Y = np .empty (4 , dtype = np .complex128 )
584
- Cr4xa (layers , d , sigma , 1.0 , rho , irho , rhoM , u1 , u3 , KZ [i ], Y )
585
- Ra [i ], Rb [i ] = Y [0 ], Y [1 ]
578
+ Cr4xa (layers , d , sigma , 1.0 , rho , irho , rhoM , u1 , u3 , KZ [i ], R [i ])
586
579
587
580
# minus polarization
588
581
for i in prange (points ):
589
- Y = np .empty (4 , dtype = np .complex128 )
590
- Cr4xa (layers , d , sigma , - 1.0 , rho , irho , rhoM , u1 , u3 , KZ [i ], Y )
591
- Rc [i ], Rd [i ] = Y [2 ], Y [3 ]
592
-
582
+ Cr4xa (layers , d , sigma , - 1.0 , rho , irho , rhoM , u1 , u3 , KZ [i ], R [i ])
593
583
594
584
#try:
595
585
# from .magnetic_amplitude import mag_amplitude as magnetic_amplitude_py
0 commit comments