[I am posting this example in response to a request I received in private.]
This is how you can use complex numbers from C. This code assumes that you have declared CCTK_COMPLEX grid functions u, v, w.
(I didn't actually try to compile this example, but the overall structure should be fine.)
#include <cctk.h> #include <cctk_Arguments.h>
#include <complex.h> #include <math.h>
void do_some_complex_calculations(CCTK_ARGUMENTS) { DECLARE_CCTK_ARGUMENTS;
#pragma omp parallel for for (int k=0; k<cctk_lsh[2]; ++k) { for (int j=0; j<cctk_lsh[1]; ++j) { for (int i=0; i<cctk_lsh[0]; ++i) { const int idx = CCTK_GFINDEX3D(cctkGH, i,j,k);
CCTK_COMPLEX tmp = 2.0 + 3.0 * I; u[idx] = conj(tmp) * v[idx] + 2.0 * cabs(w[idx]); u[idx] = cexp(u[idx]) - creal(tmp) + cimag(tmp);
} } } }
-erik
users@lists.einsteintoolkit.org