# Meaning of k-space vectors in ewald summation?

Hello,

I am trying to write some codes using ewald summation. As a beginner reading the literature, I was under the initial impression that a 3D-periodic system (cell size xprd, yprd, and zprd) would have 3 corresponding k-space vectors. I do see something like this in the calculation of unit vectors in setup() of ewald.cpp:

unitk[0] = 2.0MY_PI/xprd;
unitk[1] = 2.0
MY_PI/yprd;
unitk[2] = 2.0*MY_PI/zprd_slab;

However, after that, it looks like there are multiple k-space vectors detected in each dimension (kxmax, kymax, and kzmax), and then another value kmax3d. I have the understanding that kxmax, kymax, kzmax have something to do with accuracy. Are these the number of frequencies detected in each dimension, or do they have another meaning? What is the meaning of kmax3d?

kxmax = 1;
kymax = 1;
kzmax = 1;

err = rms(kxmax,xprd,natoms,q2);
while (err > accuracy) {
kxmax++;
err = rms(kxmax,xprd,natoms,q2);
}

err = rms(kymax,yprd,natoms,q2);
while (err > accuracy) {
kymax++;
err = rms(kymax,yprd,natoms,q2);
}

err = rms(kzmax,zprd_slab,natoms,q2);
while (err > accuracy) {
kzmax++;
err = rms(kzmax,zprd_slab,natoms,q2);
}
kmax = MAX(kxmax,kymax);
kmax = MAX(kmax,kzmax);
kmax3d = 4kmaxkmaxkmax + 6kmaxkmax + 3kmax;

The KSpace solvers in LAMMPS (kspace_style ewald and pppm) use a regular 3d
grid of KSpace points. That grid has a spacing in each dimension,
but the entire grid of points is looped over, so that many KSpace points are
treated.

Steve