#' Beam Shape Coefficients for Rectangular Wave Guides.
#'
#' @details Calculates the Beam Shape Coefficients used to do the Partial Wave
#' Expansion on Vector Spherical Wave Functions.
#' @param TM Type of the wave field.
#' @param kx Component \eqn{x} of the wave vector (single value).
#' @param ky Component \eqn{y} of the wave vector (single value).
#' @param kz Component \eqn{z} of the wave vector (single value).
#' @param x Component \eqn{x} of the origin of the expansion (vector).
#' @param y Component \eqn{y} of the origin of the expansion (vector).
#' @param z Component \eqn{z} of the origin of the expansion (vector).
#' @return The Beam Shape Coefficients \eqn{G^{TE}_{lm}} and \eqn{G^{TM}_{lm}}.
#' @include vswf.qlm.r
#' @export
#' @seealso \code{\link{vwfd.rwg}}, \code{\link{vswf.pwe}}, \code{\link{vswf.gwg}}.
#' @examples
#' lambda<-.5e-6 # Propagating wavelength
#' a<-7*lambda # Size x of the waveguide
#' b<-5*lambda # Size y of the waveguide
#' M<-6 # x wavefield mode
#' N<-5 # y wavefield mode
#' #-------------------------------------------------------------------------------
#' # Wave Field Parameters
#' #-------------------------------------------------------------------------------
#' k<-2*pi/lambda # Propagating wavenumber
#' kx<-M*pi/a # x component of the wavevector
#' ky<-N*pi/b # y component of the wavevector
#' gama<-sqrt(kx^2+ky^2) # gama component of the wavevector
#' kz<-sqrt(k^2-gama^2) # z component of the wavevector
#' #-------------------------------------------------------------------------------
#' # Geometry of the calculations
#' #-------------------------------------------------------------------------------
#' NPX=200 # Number of points in each direction (all equal)
#' NPY=200 # Number of points in each direction (all equal)
#' #-------------------------------------------------------------------------------
#' # Vectors
#' #-------------------------------------------------------------------------------
#' dx<-a/(NPX-1)
#' dy<-b/(NPY-1)
#' x<-seq(0,a,dx) # x vector of positions
#' y<-seq(0,b,dy) # y vector of positions
#' z<-0
#' #-------------------------------------------------------------------------------
#' TM<-FALSE
#' lmax<- 40
#' #-------------------------------------------------------------------------------
#' # POSITION AT WHICH THE EXPANSION WILL BE PERFORMED (REFERENCE SYSTEM)
#' #-------------------------------------------------------------------------------
#' # ARBITRARY
#' xo<-a/2
#' yo<-b/2
#' zo<-0
#' #-------------------------------------------------------------------------------
#' # CHANGE THE REFERENCE SYSTEM TO THE NEW POSITIONS
#' #-------------------------------------------------------------------------------
#' x<-x-xo
#' y<-y-yo
#' #-------------------------------------------------------------------------------
#' # ARBITRARY POINT FOR CALCULATIONS
#' #-------------------------------------------------------------------------------
#' x<-sample(x,1)
#' y<-sample(y,1)
#' #-------------------------------------------------------------------------------
#' # BSC CALCULATIONS
#' #-------------------------------------------------------------------------------
#' RWG<-vwfd.rwg(TE=!TM,kx,ky,kz,x+xo,y+yo,z+zo)
#' BSC<-vswf.rwg(kx,ky,kz,xo,yo,zo,lmax,TM)
#' PWE<-vswf.pwe(k,x,y,z,lmax,BSC$GTE,BSC$GTM)
#' #-------------------------------------------------------------------------------
#' # VALUES
#' #-------------------------------------------------------------------------------
#' cat("Distance x from origin in wavelength (from ",-a/(2*lambda),"to ",a/(2*lambda),"):",x/lambda,"\n")
#' cat("Distance y from origin in wavelength (from ",-b/(2*lambda),"to ",b/(2*lambda),"):",y/lambda,"\n")
#' df<-data.frame(
#' PWE=c(PWE$Em,PWE$Ez,PWE$Ep,PWE$Hm,PWE$Hz,PWE$Hp),
#' RWG=c(RWG$Em,RWG$Ez,RWG$Ep,RWG$Hm,RWG$Hz,RWG$Hp),
#' row.names=c("Em","Ez","Ep","Hm","Hz","Hp")
#' )
#' df$DIF<-df$PWE-df$RWG
#' print(df)
bscf.bbp<-function(M,X,m,s,p,gama,kz,x,y,z,lmax,TM=TRUE){
x[x==0]<-.Machine$double.xmin
y[y==0]<-.Machine$double.xmin
z[z==0]<-.Machine$double.xmin
nx<-length(x)
ny<-length(y)
nz<-length(z)
dummy<-rep(0,nx*ny*nz)
tm<-ifelse(TM,1,0)
u<-.C("bscf_bbp",
TM=as.integer(tm),
m=as.integer(m),
s=as.integer(s),
p=as.integer(p),
lmax=as.integer(lmax),
NMAX=as.integer(200),
kx=as.double(gama),
kz=as.double(kz),
M=as.complex(M),
X=as.complex(X),
x=as.double(x),
y=as.double(y),
z=as.double(z),
nx=as.integer(nx),
ny=as.integer(ny),
nz=as.integer(nz),
rx=as.double(dummy),
ry=as.double(dummy),
rz=as.double(dummy),
Fx=as.double(dummy),
Fy=as.double(dummy),
Fz=as.double(dummy))
return(data.frame(x=u$rx,y=u$ry,z=u$rz,Fx=u$Fx,Fy=u$Fy,Fz=u$Fz))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.