<div dir="ltr">[I am posting this example in response to a request I received in private.]<div><br></div><div>This is how you can use complex numbers from C. This code assumes that you have declared CCTK_COMPLEX grid functions u, v, w.</div>
<div><br></div><div style>(I didn't actually try to compile this example, but the overall structure should be fine.)</div><div><br></div><div>#include <cctk.h></div><div>#include <cctk_Arguments.h></div><div>
<br></div><div>#include <complex.h></div><div>#include <math.h></div><div><br></div><div>void do_some_complex_calculations(CCTK_ARGUMENTS)</div><div>{</div><div> DECLARE_CCTK_ARGUMENTS;</div><div><br></div><div style>
#pragma omp parallel for</div><div> for (int k=0; k<cctk_lsh[2]; ++k) {</div><div> for (int j=0; j<cctk_lsh[1]; ++j) {</div><div style> for (int i=0; i<cctk_lsh[0]; ++i) {</div><div style> const int idx = CCTK_GFINDEX3D(cctkGH, i,j,k);</div>
<div style><br></div><div style> CCTK_COMPLEX tmp = 2.0 + 3.0 * I;</div><div style> u[idx] = conj(tmp) * v[idx] + 2.0 * cabs(w[idx]);</div><div style> u[idx] = cexp(u[idx]) - creal(tmp) + cimag(tmp);</div><div style>
<br></div><div style> }</div><div style> }</div><div style> }</div><div style>}</div><div><br><div>-erik<br clear="all"><div><br></div>-- <br>Erik Schnetter <<a href="mailto:schnetter@cct.lsu.edu" target="_blank">schnetter@cct.lsu.edu</a>><br>
<a href="http://www.perimeterinstitute.ca/personal/eschnetter/" target="_blank">http://www.perimeterinstitute.ca/personal/eschnetter/</a>
</div></div></div>