import qpms
import numpy as np
import os, sys, warnings, math
from scipy import interpolate
nx = None
s3 = math.sqrt(3)

# specifikace T-matice zde
cdn = c / math.sqrt(epsilon_b)
TMatrices_orig, freqs_orig, freqs_weirdunits_orig, lMaxTM = qpms.loadScuffTMatrices(
    TMatrix_file)
lMax = lMaxTM
if pargs.lMax:
    lMax = pargs.lMax if pargs.lMax else lMaxTM
my, ny = qpms.get_mn_y(lMax)
nelem = len(my)
if pargs.lMax:  #force commandline specified lMax
    TMatrices_orig = TMatrices_orig[..., 0:nelem, :, 0:nelem]

TMatrices = np.array(
    np.broadcast_to(TMatrices_orig[:, nx, :, :, :, :],
                    (len(freqs_orig), 2, 2, nelem, 2, nelem)))

#TMatrices[:,:,:,:,:,ny==3] *= factor13inc
#TMatrices[:,:,:,ny==3,:,:] *= factor13scat
xfl = qpms.xflip_tyty(lMax)
yfl = qpms.yflip_tyty(lMax)
zfl = qpms.zflip_tyty(lMax)
c2rot = qpms.apply_matrix_left(qpms.yflip_yy(3), qpms.xflip_yy(3), -1)
Exemple #2
0
    def testRandom1to1(self):
        # The "maximum" argument of the Bessel's functions, i.e. maximum wave number times the distance,
        # for the "locally strongly varying fields"
        maxx = 10
        rfailtol = 0.01 # how much of the randomized test fail proportion will be tolerated
        lMax = 50 # To which order we decompose the waves
        lMax_outgoing = 4 # To which order we try the outgoing waves
        rtol = 1e-5 # relative required precision
        atol = 1. # absolute tolerance, does not really play a role
        nsamples = 4 # frequency samples per order of magnitude and test
        npoints = 15 # points to evaluate per frequency and center
     
        ncentres = 3 # number of spherical coordinate centres between which the translations are to be made
        maxxd = 2000 # the center position standard deviation

        failcounter = 0
        passcounter = 0
        my, ny = qpms.get_mn_y(lMax)
        nelem_full = len(my)
        nelem_out = lMax_outgoing * (lMax_outgoing + 2)
        for oom in lengthOrdersOfMagnitude:
            centres = oom * maxxd * np.random.randn(ncentres, 3)
            ksizs = np.random.randn(nsamples)
            for ksiz in ksizs:
                for i in range(ncentres): # "source"
                    Rs = centres[i]
                    testr = oom * maxx * np.random.randn(npoints, 3)
                    for j in range(ncentres): # "destination"
                        if j == i:
                            continue
                        Rd = centres[j]
                        shift = Rd - Rs
                        shift_sph = qpms.cart2sph(shift)
                        shift_kr = ksiz * shift_sph[0]
                        shift_theta = shift_sph[1]
                        shift_phi = shift_sph[2]

                        A_yd_ys = np.empty((nelem_full,nelem_out), dtype = np.complex_)
                        B_yd_ys = np.empty((nelem_full,nelem_out), dtype = np.complex_)
                        for yd in range(nelem_full):
                            for ys in range(nelem_out):
                                A_yd_ys[yd, ys] = qpms.Ã(my[yd],ny[yd],my[ys],ny[ys],shift_kr, shift_theta, shift_phi, True, 1) 
                                B_yd_ys[yd, ys] = qpms.B̃(my[yd],ny[yd],my[ys],ny[ys],shift_kr, shift_phi, shift_phi, True, 1)
                        for r in testr:
                            sph_ssys = qpms.cart2sph(r+Rd-Rs)
                            M_ssys, N_ssys = qpms.vswf_yr1(np.array([ksiz * sph_ssys[0], sph_ssys[1], sph_ssys[2]]), lMax_outgoing, J=1)
                            sph_dsys = qpms.cart2sph(r)
                            M_dsys, N_dsys = qpms.vswf_yr1(np.array([ksiz * sph_dsys[0], sph_dsys[1], sph_dsys[2]]), lMax, J=1)
                            for ys in range(nelem_out): 
                                # Electrical waves
                                E_1 = -1j*qpms.sph_loccart2cart(N_ssys[ys], sph_ssys)
                                E_2 = -1j*qpms.sph_loccart2cart(np.dot(A_yd_ys[:,ys],N_dsys)+np.dot(B_yd_ys[:,ys],M_dsys),sph_dsys)
                                if not np.allclose(E_1, E_2, rtol=rtol, atol=atol):
                                    failcounter += 1
                                else:
                                    passcounter += 1
                                # Magnetic waves
                                E_1 = -1j*qpms.sph_loccart2cart(M_ssys[ys], sph_ssys)
                                E_2 = -1j*qpms.sph_loccart2cart(np.dot(A_yd_ys[:,ys],M_dsys)+np.dot(B_yd_ys[:,ys],N_dsys),sph_dsys)
                                if not np.allclose(E_1, E_2, rtol=rtol, atol=atol):
                                    failcounter += 1
                                else:
                                    passcounter += 1
        self.assertLess(failcounter / (failcounter + passcounter), rfailtol, 
                '%d / %d (%.2e) randomized numerical tests failed (tolerance %.2e)' 
                % (failcounter, failcounter + passcounter, 
                    failcounter / (failcounter + passcounter), rfailtol))
        return