You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
2.5 KiB
Common Lisp

/*
* H update equations
*
* Template parameters:
* mu False if (mu == 1) everywhere
* pmc False if no PMC anywhere
* common_cl Rendered code from common.cl
*
* Arguments:
* ctype *E E-field
* ctype *H H-field
* ctype *inv_mu 1/mu (at H-field locations)
* char *pmc Boolean mask denoting presence of PMC (at H-field locations)
* ctype *inv_dex 1/dx_e (complex cell widths for x direction at E locations)
* ctype *inv_dey 1/dy_e (complex cell widths for y direction at E locations)
* ctype *inv_dez 1/dz_e (complex cell widths for z direction at E locations)
*
*/
{{common_cl}}
__global ctype *inv_mu_x = inv_mu + XX;
__global ctype *inv_mu_y = inv_mu + YY;
__global ctype *inv_mu_z = inv_mu + ZZ;
__global ctype *pmc_x = pmc + XX;
__global ctype *pmc_y = pmc + YY;
__global ctype *pmc_z = pmc + ZZ;
/*
* Implement periodic boundary conditions
*
* ipx gives the index of the adjacent cell in the plus-x direction ([i]ndex [p]lus [x]).
* In the event that we start at x == (sx - 1), we actually want to wrap around and grab the cell
* where x == 0 instead, ie. ipx = i - (sx - 1) * dix .
*/
int ipx, ipy, ipz;
if ( x == sx - 1 ) {
ipx = i - (sx - 1) * dix;
} else {
ipx = i + dix;
}
if ( y == sy - 1 ) {
ipy = i - (sy - 1) * diy;
} else {
ipy = i + diy;
}
if ( z == sz - 1 ) {
ipz = i - (sz - 1) * diz;
} else {
ipz = i + diz;
}
//Update H components; set them to 0 if PMC is enabled at that location.
//Mu division and PMC conditional are only included if {{mu}} and {{pmc}} are true
{% if pmc -%}
if (pmc_x[i] != 0) {
Hx[i] = zero;
} else
{%- endif -%}
{
ctype Dzy = mul(sub(Ez[ipy], Ez[i]), inv_dey[y]);
ctype Dyz = mul(sub(Ey[ipz], Ey[i]), inv_dez[z]);
ctype x_curl = sub(Dzy, Dyz);
{%- if mu -%}
Hx[i] = mul(inv_mu_x[i], x_curl);
{%- else -%}
Hx[i] = x_curl;
{%- endif %}
}
{% if pmc -%}
if (pmc_y[i] != 0) {
Hy[i] = zero;
} else
{%- endif -%}
{
ctype Dxz = mul(sub(Ex[ipz], Ex[i]), inv_dez[z]);
ctype Dzx = mul(sub(Ez[ipx], Ez[i]), inv_dex[x]);
ctype y_curl = sub(Dxz, Dzx);
{%- if mu -%}
Hy[i] = mul(inv_mu_y[i], y_curl);
{%- else -%}
Hy[i] = y_curl;
{%- endif %}
}
{% if pmc -%}
if (pmc_z[i] != 0) {
Hz[i] = zero;
} else
{%- endif -%}
{
ctype Dyx = mul(sub(Ey[ipx], Ey[i]), inv_dex[x]);
ctype Dxy = mul(sub(Ex[ipy], Ex[i]), inv_dey[y]);
ctype z_curl = sub(Dyx, Dxy);
{%- if mu -%}
Hz[i] = mul(inv_mu_z[i], z_curl);
{%- else -%}
Hz[i] = z_curl;
{%- endif %}
}
/*
* End H update equations
*/