![]() ![]() ![]() ![]() Next: Macros Up: Examples Previous: Fortran Contents C
This function computes the curved-space Laplacian of a scalar field
/* * This function computes the curved-space Laplacian of a scalar field, * $\del^i \del_i \phi * = g^{ij} \partial_{ij} \phi - g^{ij} \Gamma^k_{ij} \partial_k \phi$ * at the interior grid points only; it doesn't do anything at all on the * boundaries. * * This function uses the following Cactus grid functions: * input: dx_phi, dy_phi, dz_phi # 1st derivatives of phi * dxx_phi, dxy_phi, dxz_phi, # 2nd derivatives of phi * dyy_phi, dyz_phi, * dzz_phi * output: Laplacian_phi */ void compute_Laplacian(CCTK_ARGUMENTS) { DECLARE_CCTK_ARGUMENTS int i,j,k; /* contracted Christoffel symbols $\Gamma^k = g^{ij} \Gamma^k_{ij}$ */ CCTK_REAL Gamma_u_x, Gamma_u_y, Gamma_u_z; /* grid-function strides for ADMMacros */ const int di = 1; const int dj = cctk_lsh[0]; const int dk = cctk_lsh[0]*cctk_lsh[1]; /* declare the ADMMacros variables for $g^{ij}$ and $\Gamma^k_{ij}$ */ #include "CactusEinstein/ADMMacros/src/macro/UPPERMET_declare.h" #include "CactusEinstein/ADMMacros/src/macro/CHR2_declare.h" for (k = 1 ; k < cctk_lsh[2]-1 ; ++k) { for (j = 1 ; j < cctk_lsh[1]-1 ; ++j) { for (i = 1 ; i < cctk_lsh[0]-1 ; ++i) { const int ijk = CCTK_GFINDEX3D(cctkGH,i,j,k); /* grid-function subscripting index for ADMMacros */ /* (must be assigned inside the i,j,k loops) */ /* compute the ADMMacros $g^{ij}$ and $\Gamma^k_{ij}$ variables at the (i,j,k) grid point */ #include "CactusEinstein/ADMMacros/src/macro/UPPERMET_guts.h" #include "CactusEinstein/ADMMacros/src/macro/CHR2_guts.h" /* compute the contracted Christoffel symbols $\Gamma^k = g^{ij} \Gamma^k_{ij}$ */ Gamma_u_x = UPPERMET_UXX*CHR2_XXX + 2.0*UPPERMET_UXY*CHR2_XXY + 2.0*UPPERMET_UXZ*CHR2_XXZ + UPPERMET_UYY*CHR2_XYY + 2.0*UPPERMET_UYZ*CHR2_XYZ + UPPERMET_UZZ*CHR2_XZZ; Gamma_u_y = UPPERMET_UXX*CHR2_YXX + 2.0*UPPERMET_UXY*CHR2_YXY + 2.0*UPPERMET_UXZ*CHR2_YXZ + UPPERMET_UYY*CHR2_YYY + 2.0*UPPERMET_UYZ*CHR2_YYZ + UPPERMET_UZZ*CHR2_YZZ; Gamma_u_z = UPPERMET_UXX*CHR2_ZXX + 2.0*UPPERMET_UXY*CHR2_ZXY + 2.0*UPPERMET_UXZ*CHR2_ZXZ + UPPERMET_UYY*CHR2_ZYY + 2.0*UPPERMET_UYZ*CHR2_ZYZ + UPPERMET_UZZ*CHR2_ZZZ; /* compute the Laplacian */ Laplacian_phi[ijk] = UPPERMET_UXX*dxx_phi[ijk] + 2.0*UPPERMET_UXY*dxy_phi[ijk] + 2.0*UPPERMET_UXZ*dxz_phi[ijk] + UPPERMET_UYY*dyy_phi[ijk] + 2.0*UPPERMET_UYZ*dyz_phi[ijk] + UPPERMET_UZZ*dzz_phi[ijk] - Gamma_u_x*dx_phi[ijk] - Gamma_u_y*dy_phi[ijk] - Gamma_u_z*dz_phi[ijk]; } } } #include "CactusEinstein/ADMMacros/src/macro/UPPERMET_undefine.h" #include "CactusEinstein/ADMMacros/src/macro/CHR2_undefine.h" }
|