Fixed bugs. Added notebooks with halfspace and layer examples.

Code is working (returning results with in couple of % for a 1D analytic solution) but test need to be "automated".
This commit is contained in:
Gudni Karl Rosenkjaer
2015-03-02 14:58:53 -08:00
parent fbf4370a78
commit 52618bac35
10 changed files with 2318 additions and 318 deletions
+11 -4
View File
@@ -47,12 +47,19 @@ def getEHfields(m1d,sigma,freq,zd):
UDp[:,lnr+1] = elamh.dot(Pjinv.dot(Pj1)).dot(UDp[:,lnr])
# Calculate the fields
Ed = np.zeros((zd.size,),dtype=complex)
Eu = np.zeros((zd.size,),dtype=complex)
Hd = np.zeros((zd.size,),dtype=complex)
Hu = np.zeros((zd.size,),dtype=complex)
Ed = np.empty((zd.size,),dtype=complex)
Eu = np.empty((zd.size,),dtype=complex)
Hd = np.empty((zd.size,),dtype=complex)
Hu = np.empty((zd.size,),dtype=complex)
# Loop over the layers and calculate the fields
# In the halfspace below the mesh
dup = m1d.vectorNx[0]
dind = dup >= zd
Ed[dind] = UDp[1,0]*np.exp(-1j*k[0]*(dup-zd[dind]))
Eu[dind] = UDp[0,0]*np.exp(1j*k[0]*(dup-zd[dind]))
Hd[dind] = (k[0]/(w*mu[0]))*UDp[1,0]*np.exp(-1j*k[0]*(dup-zd[dind]))
Hu[dind] = -(k[0]/(w*mu[0]))*UDp[0,0]*np.exp(1j*k[0]*(dup-zd[dind]))
for ki,mui,epsi,dlow,dup,Up,Dp in zip(k[1::],mu[1::],eps[1::],m1d.vectorNx[:-1],m1d.vectorNx[1::],UDp[0,1::],UDp[1,1::]):
dind = np.logical_and(dup >= zd, zd > dlow)
Ed[dind] = Dp*np.exp(-1j*ki*(dup-zd[dind]))
+5 -3
View File
@@ -20,10 +20,12 @@ def get1DEfields(m1d,sigma,freq,sourceAmp=1.0):
Aio = A[1:-1,[0,-1]]
# Set the boundary conditions
Ed_low, Eu_low, Hd_low, Hu_low = getEHfields(m1d,sigma,freq,np.array([m1d.vectorNx[0]]))
Etot_low = Ed_low + Eu_low
Ed, Eu, Hd, Hu = getEHfields(m1d,sigma,freq,m1d.vectorNx)
Etot = Ed + Eu
if sourceAmp is not None:
Etot = ((Etot/Etot[-1])*sourceAmp) # Scale the fields to be equal to sourceAmp at the top
## Note: need to use conjugate of the analytic solution. It is derived with e^iwt
bc = np.r_[Etot_low.conj(),sourceAmp]
bc = np.r_[Etot[0],Etot[-1]]
# The right hand side
rhs = -Aio*bc
# Solve the system