1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import scattnlay
- import os
- from scattnlay import fieldnlay
- import numpy as np
- class bcolors:
- HEADER = '\033[95m'
- OKBLUE = '\033[94m'
- OKGREEN = '\033[92m'
- WARNING = '\033[93m'
- FAIL = '\033[91m'
- ENDC = '\033[0m'
- BOLD = '\033[1m'
- UNDERLINE = '\033[4m'
- def is_test_coord_passed(x,m,coordX,coordY,coordZ):
- terms, E, H = fieldnlay(x, m, coordX,coordY,coordZ)
- Er = np.absolute(E)
- Eabs = np.sqrt(Er[0, :, 0]**2 + Er[0, :, 1]**2 + Er[0, :, 2]**2)
- analytic_E = (3/(m[0,0]**2+2)).real
- for value in Eabs:
-
- if ( value-analytic_E > 10e-7 ):
- print(bcolors.FAIL+"Test failed: value="+str(value)+" for m="+str(m[0,0])
- +" instead of analytic Eabs="+str(analytic_E))
- print("Coords",coord)
- return False
- return True
- def is_test_all_coord_passed(x,m):
- npts = 5
- scan = np.linspace(0.999*x[0, 0], -0.999*x[0, 0], npts)
- zero = np.zeros(npts, dtype = np.float64)
- if (is_test_coord_passed(x,m,scan, zero, zero)
- and is_test_coord_passed(x,m,zero, scan, zero)
- and is_test_coord_passed(x,m,zero, zero, scan)):
- return True
- return False
- def test_sphere():
- path = os.path.dirname(scattnlay.__file__)
- print(bcolors.HEADER+"===== Small dielectric sphere test ====="+bcolors.ENDC)
- print("Test for python module of Scattnlay: "+scattnlay.__file__)
-
- x = np.ones((1, 1), dtype = np.float64)
- x[0, 0] = 0.0001
- m = np.ones((1, 1), dtype = np.complex128)
- m[0, 0] = 1.0
- delta_m = 0.712
- for n in xrange(0,15):
- m[0,0] = 1.0 + delta_m*n
- print("Testing index m="+str(m[0,0]))
- if not is_test_all_coord_passed(x,m):
- print(bcolors.FAIL+"Test for dielectric sphere failed!"+bcolors.ENDC)
- return False
- print(bcolors.OKGREEN+"All tests for dielectric sphere passed!"+bcolors.ENDC)
- return True
- test_sphere()
|