/*
enode.c

E on node
*/

#include "oth.h"
#include "complex.h"
#include "oth_prototype.h"

void enode(int f, int i, int j, int k, int exclude, d_complex_t e[])
{
	assert((f >= 0) && (f < NFrequency));
	assert((i >= 0) && (i <= Nx) && (j >= 0) && (j <= Ny) && (k >= 0) && (k <= Nz));

	// Ex
	if      (i == 0) {
		e[0] = d_sub(d_rmul(1.5, exyee(f,      0, j, k, exclude)), d_rmul(0.5, exyee(f,      1, j, k, exclude)));
	}
	else if (i == Nx) {
		e[0] = d_sub(d_rmul(1.5, exyee(f, Nx - 1, j, k, exclude)), d_rmul(0.5, exyee(f, Nx - 2, j, k, exclude)));
	}
	else {
		e[0] = d_add(d_rmul(0.5, exyee(f, i  - 1, j, k, exclude)), d_rmul(0.5, exyee(f, i     , j, k, exclude)));
	}

	// Ey
	if      (j == 0) {
		e[1] = d_sub(d_rmul(1.5, eyyee(f, i,      0, k, exclude)), d_rmul(0.5, eyyee(f, i,      1, k, exclude)));
	}
	else if (j == Ny) {
		e[1] = d_sub(d_rmul(1.5, eyyee(f, i, Ny - 1, k, exclude)), d_rmul(0.5, eyyee(f, i, Ny - 2, k, exclude)));
	}
	else {
		e[1] = d_add(d_rmul(0.5, eyyee(f, i, j  - 1, k, exclude)), d_rmul(0.5, eyyee(f, i, j     , k, exclude)));
	}

	// Ez
	if      (k == 0) {
		e[2] = d_sub(d_rmul(1.5, ezyee(f, i, j,      0, exclude)), d_rmul(0.5, ezyee(f, i, j,      1, exclude)));
	}
	else if (k == Nz) {
		e[2] = d_sub(d_rmul(1.5, ezyee(f, i, j, Nz - 1, exclude)), d_rmul(0.5, ezyee(f, i, j, Nz - 2, exclude)));
	}
	else {
		e[2] = d_add(d_rmul(0.5, ezyee(f, i, j, k  - 1, exclude)), d_rmul(0.5, ezyee(f, i, j, k     , exclude)));
	}
}
