| "setup.cc": "#include <assert.h>\n#include <math.h>\n#include <stdio.h>\n\n#include \"cctk.h\"\n#include \"cctk_Arguments.h\"\n#include \"cctk_Parameters.h\"\n\n//#include <mpi.h>\n\n\n// local functions\nstatic bool all_sf_names_are_unique(CCTK_INT warnlevel);\nstatic int get_reflevel (cGH const * const cctkGH);\n\n\nstatic int get_reflevel (cGH const * const cctkGH)\n{\n if (CCTK_IsFunctionAliased (\"GetRefinementLevel\")) {\n return GetRefinementLevel (cctkGH);\n } else {\n return 0;\n }\n}\n\n\n// simple translation function from user-friendly name to numerical Id\n// if name is not empty returns the matching name and -1 if no name matches\n// if name is empty returns fallbackid\nextern \"C\" CCTK_INT SphericalSurface_IdFromName (CCTK_INT fallbackid, CCTK_POINTER_TO_CONST sfname)\n{\n DECLARE_CCTK_PARAMETERS;\n CCTK_INT retval = -1;\n\n // re-check for unique names since the parameters are steerable\n if(!all_sf_names_are_unique(CCTK_WARN_ALERT))\n CCTK_WARN(CCTK_WARN_ABORT, \"Not all spherical surface names are unique.\"); \n\n if (CCTK_Equals(static_cast<CCTK_STRING>(sfname), \"\")) {\n\n retval = fallbackid;\n } else {\n\n for (CCTK_INT n=0; n<nsurfaces; ++n) {\n \n if (CCTK_Equals(static_cast<CCTK_STRING>(sfname), name[n])) {\n \n retval = n;\n break;\n }\n }\n\n if (retval == -1) {\n CCTK_VWarn(CCTK_WARN_ALERT, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Did not find spherical surface with name '%s'.\", \n static_cast<CCTK_STRING>(sfname));\n }\n }\n\n return retval;\n}\n\n// utility function to check if all SphericalSurface names are unique (or empty)\nstatic bool all_sf_names_are_unique(CCTK_INT warnlevel)\n{\n DECLARE_CCTK_PARAMETERS;\n bool all_unique = true;\n\n for (int i=0; i<nsurfaces; ++i) {\n if (CCTK_Equals(static_cast<CCTK_STRING>(name[i]), \"\"))\n continue;\n for (int j=i+1; j<nsurfaces; ++j) {\n if (CCTK_Equals(static_cast<CCTK_STRING>(name[i]), static_cast<CCTK_STRING>(name[j]))) {\n CCTK_VWarn(warnlevel, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Duplicate names for spherical surfaces %d and %d: %s == %s\", \n i,j, name[i], name[j]);\n all_unique = false;\n }\n }\n }\n\n return all_unique;\n}\n\n// check early that all SphericalSurface names are valid\nextern \"C\" void SphericalSurface_ParamCheck (CCTK_ARGUMENTS)\n{\n DECLARE_CCTK_ARGUMENTS_SphericalSurface_ParamCheck;\n\n if (!all_sf_names_are_unique(CCTK_WARN_ALERT)) {\n CCTK_PARAMWARN(\"Not all spherical surface names are unique.\");\n }\n}\n \n//TODO: overlap with finer levels still seems to be incorrect!\n\nextern \"C\" void SphericalSurface_Setup (CCTK_ARGUMENTS)\n{\n DECLARE_CCTK_ARGUMENTS_SphericalSurface_Setup;\n DECLARE_CCTK_PARAMETERS;\n \n CCTK_REAL const pi = 4 * atan(CCTK_REAL(1.0));\n \n int ierr;\n \n \n \n if (nsurfaces == 0) return;\n \n \n \n int const group = CCTK_GroupIndex (\"SphericalSurface::sf_radius\");\n assert (group>=0);\n cGroup groupinfo;\n ierr = CCTK_GroupData (group, &groupinfo);\n assert (!ierr);\n cGroupDynamicData groupdata;\n ierr = CCTK_GroupDynamicData (cctkGH, group, &groupdata);\n assert (!ierr);\n \n \n \n for (int n=0; n<nsurfaces; ++n) {\n \n if (!auto_res[n])\n {\n // set resolution according to given parameters\n \n // internal consistency checks\n assert (groupdata.dim == 2);\n assert (groupdata.gsh[0] >= ntheta[n]);\n assert (groupdata.gsh[1] >= nphi[n]);\n \n assert (ntheta[n] >= 3*nghoststheta[n] && ntheta[n] <= maxntheta);\n assert (nphi[n] >= 3*nghostsphi[n] && nphi[n] <= maxnphi);\n \n \n \n // copy parameters into grid functions\n sf_ntheta[n] = ntheta[n];\n sf_nphi[n] = nphi[n];\n sf_nghoststheta[n] = nghoststheta[n];\n sf_nghostsphi[n] = nghostsphi[n];\n }\n else\n {\n // we already have an approximate delta-spacing calculated in \"SetupRes\"\n // based on that, we calculate the number of necessary gridpoints...\n CCTK_WARN(1, \"AutoRes will NOT work with checkpoint/recovery!\");\n \n CCTK_REAL theta_range = pi;\n CCTK_REAL phi_range = 2*pi;\n \n if (symmetric_x[n])\n phi_range /= 2;\n \n if (symmetric_y[n])\n phi_range /= 2;\n \n if (symmetric_z[n])\n theta_range /= 2;\n \n sf_ntheta[n] = lrint(theta_range/sf_delta_theta_estimate[n]) + 2*nghoststheta[n];\n sf_nphi[n] = lrint(phi_range /sf_delta_phi_estimate[n] ) + 2*nghostsphi[n];\n \n // ...make number of theta-gridpoints odd...\n if (sf_ntheta[n] % 2 != 1)\n sf_ntheta[n] += 1;\n \n // ... and make inner phi-gridpoints divisible by 4 since some thorns require that (e.g. IsolatedHorizon)\n sf_nphi[n] += 4 - (sf_nphi[n]-2*nghostsphi[n]) % 4 + 2*nghostsphi[n];\n \n // consistency check\n if (sf_ntheta[n] < 3*nghoststheta[n]) \n {\n CCTK_WARN(1, \"AutoRes: Determined sf_ntheta[n] < 3*nghoststheta[n]! Setting sf_ntheta[n] = 3*nghoststheta[n]!\");\n sf_ntheta[n] = 3*nghoststheta[n];\n }\n if (sf_ntheta[n] > maxntheta)\n {\n CCTK_WARN(1, \"AutoRes: Determined sf_ntheta[n] > maxntheta! You should increase maxntheta or auto_res_ratio[n]! Setting sf_ntheta[n] = maxntheta!\");\n sf_ntheta[n] = maxntheta;\n }\n if (sf_nphi[n] < 3*nghostsphi[n]) \n {\n CCTK_WARN(1, \"AutoRes: Determined sf_nphi[n] < 3*nghostsphi[n]! Setting sf_nphi[n] = 3*nghostsphi[n]!\");\n sf_nphi[n] = 3*nghostsphi[n];\n }\n if (sf_nphi[n] > maxnphi)\n {\n CCTK_WARN(1, \"AutoRes: Determined sf_nphi[n] > maxnphi! You should increase maxnphi or auto_res_ratio[n]! Setting sf_nphi[n] = maxnphi!\");\n sf_nphi[n] = maxnphi;\n }\n \n // check, if there are enough maxntheta,maxnphi gridpoints to remove symmetries\n // (some thorns require that)\n if (symmetric_z[n])\n {\n if (2*(sf_ntheta[n]-2*nghoststheta[n])+2*nghoststheta[n] > maxntheta)\n\t CCTK_WARN(0, \"maxntheta is not big enough to remove z-symmetry (some thorns may require that)!\");\n }\n \n if (symmetric_x[n])\n {\n if (symmetric_y[n])\n {\n if (4*(sf_nphi[n]-2*nghostsphi[n])+2*nghostsphi[n] > maxnphi)\n {\n CCTK_WARN(0, \"maxnphi is not big enough to remove x-symmetry and y-symmetry (some thorns may require that)!\");\n }\n }\n else\n {\n if (2*(sf_nphi[n]-2*nghostsphi[n])+2*nghostsphi[n] > maxnphi)\n {\n CCTK_WARN(0, \"maxnphi is not big enough to remove x-symmetry and y-symmetry (some thorns may require that)!\");\n }\n }\n }\n else\n {\n if (symmetric_y[n])\n {\n if (2*(sf_nphi[n]-2*nghostsphi[n])+2*nghostsphi[n] > maxnphi)\n {\n CCTK_WARN(0, \"maxnphi is not big enough to remove x-symmetry and y-symmetry (some thorns may require that)!\");\n }\n }\n }\n\n \n sf_nghoststheta[n] = nghoststheta[n];\n sf_nghostsphi[n] = nghostsphi[n];\n \n if (verbose)\n {\n CCTK_VInfo (CCTK_THORNSTRING, \"SphericalSurface[%d]: setting sf_ntheta = %d\", n, int(sf_ntheta[n]));\n CCTK_VInfo (CCTK_THORNSTRING, \"SphericalSurface[%d]: setting sf_nphi = %d\", n, int(sf_nphi[n]));\n }\n }\n \n if (verbose)\n {\n CCTK_VInfo (CCTK_THORNSTRING, \"SphericalSurface[%d]: finest refinement-level that fully contains this surface: sf_maxreflevel = %d\", n, int(sf_maxreflevel[n]));\n CCTK_VInfo (CCTK_THORNSTRING, \"SphericalSurface[%d]: finest refinement-level that overlaps with this surface : sf_minreflevel = %d\", n, int(sf_minreflevel[n]));\n }\n \n // coordinates in the theta direction\n // avoid_sf_origin_theta = 1\n if (symmetric_z[n]) {\n \n // upper hemisphere: z>=0, theta in (0, pi/2)\n sf_delta_theta[n] = pi/2 / (sf_ntheta[n] - 2*nghoststheta[n] - 0.5);\n sf_origin_theta[n] = - (nghoststheta[n] - 0.5) * sf_delta_theta[n];\n \n } else {\n \n // both hemispheres: theta in (0, pi)\n sf_delta_theta[n] = pi / (sf_ntheta[n] - 2*nghoststheta[n]);\n sf_origin_theta[n] = - (nghoststheta[n] - 0.5) * sf_delta_theta[n];\n \n }\n \n \n \n // coordinates in the phi direction\n // avoid_sf_origin_phi = 0\n if (symmetric_x[n]) {\n if (symmetric_y[n]) {\n \n // one quadrant: x>=0, y>=0, phi in [0, pi/2]\n assert (sf_nphi[n] - 2*nghostsphi[n] >= 1);\n sf_delta_phi[n] = pi/2 / (sf_nphi[n] - 2*nghostsphi[n] - 1);\n sf_origin_phi[n] = - nghostsphi[n] * sf_delta_phi[n];\n \n } else {\n \n // two quadrants: x>=0, phi in [-pi/2, pi/2]\n assert (sf_nphi[n] - 2*nghostsphi[n] >= 2);\n sf_delta_phi[n] = pi / (sf_nphi[n] - 2*nghostsphi[n] - 1);\n sf_origin_phi[n] = - pi/2 - nghostsphi[n] * sf_delta_phi[n];\n \n }\n } else {\n if (symmetric_y[n]) {\n \n // two quadrants: y>=0, phi in [0, pi]\n assert (sf_nphi[n] - 2*nghostsphi[n] >= 2);\n sf_delta_phi[n] = pi / (sf_nphi[n] - 2*nghostsphi[n] - 1);\n sf_origin_phi[n] = - nghostsphi[n] * sf_delta_phi[n];\n \n } else {\n \n // all quadrants: phi in [0, 2pi)\n assert (sf_nphi[n] - 2*nghostsphi[n] >= 4);\n sf_delta_phi[n] = 2*pi / (sf_nphi[n] - 2*nghostsphi[n]);\n sf_origin_phi[n] = - nghostsphi[n] * sf_delta_phi[n];\n \n }\n }\n \n if (verbose) {\n CCTK_VInfo (CCTK_THORNSTRING, \"SphericalSurface[%d]: sf_delta_theta = %.6f, sf_delta_phi = %.6f\\n\", n, sf_delta_theta[n], sf_delta_phi[n]);\n }\n \n // mark surface as uninitialised\n sf_active[n] = 0;\n sf_valid[n] = 0;\n \n } // for n\n}\n\n\n\nextern \"C\" void SphericalSurface_SetupRes (CCTK_ARGUMENTS)\n{\n DECLARE_CCTK_ARGUMENTS_SphericalSurface_SetupRes;\n DECLARE_CCTK_PARAMETERS;\n \n static bool first_call = true;\n \n int min_reduction_handle = CCTK_ReductionArrayHandle(\"minimum\");\n int max_reduction_handle = CCTK_ReductionArrayHandle(\"maximum\");\n\n if (min_reduction_handle < 0)\n CCTK_WARN(0, \"Cannot get reduction handle for minimum operation.\");\n if (max_reduction_handle < 0)\n CCTK_WARN(0, \"Cannot get reduction handle for maximum operation.\");\n \n for (int n=0; n<nsurfaces; ++n) \n {\n \n // try to find out with which Carpet::reflevel completely contains\n // the current surface and will intersect and and store the\n // result so that other thorns such as the kick-thorn\n // can decide which reflevel to use\n \n // set resolution according to Radius and Cartesian resolution\n\n if (!auto_res[n])\n continue;\n \n CCTK_REAL my_radius;\n \n if (!set_spherical[n] && !set_elliptic[n])\n {\n // we have a problem...without a radius we cannot estimate a proper resolution\n // Here, we simply assume r=1 if radius[n] == 0.\n // If you want a better estimate of the resolution, set the radius parameter to an initial guess!\n \n if (radius[n] == 0)\n my_radius = 1;\n else\n\t my_radius = radius[n];\n }\n else\n {\n my_radius = radius[n];\n }\n \n if (verbose) {\n CCTK_VInfo (CCTK_THORNSTRING, \"SphericalSurface: myradius = %f\", double(my_radius));\n }\n // get theta/phi delta-spacing by looking at Cartesian grid\n \n // first test, if we have an overlap with a certain reflevel\n // we do this by calculating a sphere based on the corners of the Cartesian local patch\n // on this processor.\n //unsigned long l[2];\n \n //l[0] = CCTK_GFINDEX3D(cctkGH, 0, 0, 0);\n //l[1] = CCTK_GFINDEX3D(cctkGH, cctk_lsh[0]-1, cctk_lsh[1]-1, cctk_lsh[2]-1);\n \n bool is_overlapping = false;\n CCTK_REAL cart_radius = 0; // radius of Cart. grid\n CCTK_REAL cart_origin[3]; // origin of Cart. grid\n \n //CCTK_ORIGIN_SPACE(0) + (cctk_lbnd[0]) * CCTK_DELTA_SPACE(0) - (CCTK_ORIGIN_SPACE(0) + (cctk_lbnd[0] + cctk_lsh[0]) * CCTK_DELTA_SPACE(0))\n \n // calculate radius of Cartesian grid\n cart_origin[0] = 0.5 * cctk_lsh[0] * CCTK_DELTA_SPACE(0); //(x[l[1]] - x[l[0]]) / 2.0;\n cart_origin[1] = 0.5 * cctk_lsh[1] * CCTK_DELTA_SPACE(1); //(y[l[1]] - y[l[0]]) / 2.0;\n cart_origin[2] = 0.5 * cctk_lsh[2] * CCTK_DELTA_SPACE(2); //(z[l[1]] - z[l[0]]) / 2.0;\n \n cart_radius = sqrt(cart_origin[0]*cart_origin[0] + cart_origin[1]*cart_origin[1] + cart_origin[2]*cart_origin[2]);\n \n if (verbose) {\n CCTK_VInfo (CCTK_THORNSTRING, \"SphericalSurface: cart_radius = %f, cart_origin = %f, %f, %f\", double(cart_radius), double(cart_origin[0]), double(cart_origin[1]), double(cart_origin[2]));\n }\n\n // set origin of Cartesian grid\n cart_origin[0] += CCTK_ORIGIN_SPACE(0) + cctk_lbnd[0] * CCTK_DELTA_SPACE(0); //x[l[0]];\n cart_origin[1] += CCTK_ORIGIN_SPACE(1) + cctk_lbnd[1] * CCTK_DELTA_SPACE(1); //y[l[0]];\n cart_origin[2] += CCTK_ORIGIN_SPACE(2) + cctk_lbnd[2] * CCTK_DELTA_SPACE(2); //z[l[0]];\n \n // norm of displacement vector between origin of Cart. grid and origin of SphericalSurface\n CCTK_REAL dist = sqrt( (cart_origin[0]-origin_x[n]) * (cart_origin[0]-origin_x[n])\n + (cart_origin[1]-origin_y[n]) * (cart_origin[1]-origin_y[n])\n + (cart_origin[2]-origin_z[n]) * (cart_origin[2]-origin_z[n]));\n \n // does our spherical shell overlap with the processor's local grid patch? \n if (my_radius+cart_radius >= dist && // Cart. grid and SphericalSurface overlap\n cart_radius+dist > my_radius && // Cart. grid patch is not fully contained in this SphericalSurface\n -cart_radius+dist < my_radius) // Cart. grid patch is not outside of the spherical shell\n is_overlapping = true;\n \n // get resolution\n if (is_overlapping)\n {\n if (CCTK_Equals(auto_res_grid[n], \"overlap\"))\n {\n sf_delta_theta_estimate[n] = auto_res_ratio[n] / my_radius * sqrt(CCTK_DELTA_SPACE(0)*CCTK_DELTA_SPACE(0) \n + CCTK_DELTA_SPACE(1)*CCTK_DELTA_SPACE(1) \n + CCTK_DELTA_SPACE(2)*CCTK_DELTA_SPACE(2));\n \n sf_delta_phi_estimate[n] = auto_res_ratio[n] / my_radius * sqrt(CCTK_DELTA_SPACE(0)*CCTK_DELTA_SPACE(0) \n + CCTK_DELTA_SPACE(1)*CCTK_DELTA_SPACE(1) \n + CCTK_DELTA_SPACE(2)*CCTK_DELTA_SPACE(2));\n }\n \n // store reflevel\n sf_minreflevel[n] = get_reflevel(cctkGH);\n }\n else if (first_call)\n {\n // set to very high value initially (otherwise would be zero\n // and reported as minimum value in following MPI communication)\n sf_delta_theta_estimate[n] = 10000;\n sf_delta_phi_estimate[n] = 10000; \n }\n \n if (CCTK_Equals(auto_res_grid[n], \"overlap\"))\n {\n // find minimum value of \"sf_delta_phi/theta\" over all processors\n CCTK_REAL dummy = 0;\n //MPI_Allreduce(&sf_delta_theta_estimate[n], &dummy, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD);\n CCTK_ReduceLocScalar(cctkGH, -1, min_reduction_handle, &sf_delta_theta_estimate[n], &dummy, CCTK_VARIABLE_REAL);\n sf_delta_theta_estimate[n] = dummy;\n \n dummy = 0;\n //MPI_Allreduce(&sf_delta_phi_estimate[n], &dummy, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD);\n CCTK_ReduceLocScalar(cctkGH, -1, min_reduction_handle, &sf_delta_phi_estimate[n], &dummy, CCTK_VARIABLE_REAL);\n sf_delta_phi_estimate[n] = dummy;\n \n /*\n // input arrays and output values\n const CCTK_INT input_array_variable_indices[2]\n = { CCTK_VarIndex(\"SphericalSurface::sf_delta_theta_estimate\"),\n CCTK_VarIndex(\"SphericalSurface::sf_delta_phi_estimate\") };\n const CCTK_INT output_value_type_codes[2]\n = { CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL };\n void *const output_numbers[2]\n = { (void *) output_for_real_values,\n (void *) output_for_real_values };\n \n const int status\n = CCTK_ReduceGridArrays(GH,\n 0,\n 2, input_array_variable_indices,\n 2, output_value_type_codes,\n output_values);\n */\n }\n \n // find maximum value of \"sf_minreflevel\" over all processors\n int idummy;\n //MPI_Allreduce(&sf_minreflevel[n], &idummy, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);\n CCTK_ReduceLocScalar(cctkGH, -1, max_reduction_handle, &sf_minreflevel[n], &idummy, CCTK_VARIABLE_INT);\n sf_minreflevel[n] = idummy;\n\n\n\n // find reflevel that completely contains this surface\n // FIXME: This algorithm does not take into account multiple\n // disconnected refinement regions.\n \n \n //safety margin of 6 points around sphere\n CCTK_INT const np = 6;\n \n CCTK_REAL max_radius = my_radius + ( sqrt( np*np*CCTK_DELTA_SPACE(0)*CCTK_DELTA_SPACE(0) \n + np*np*CCTK_DELTA_SPACE(1)*CCTK_DELTA_SPACE(1)\n + np*np*CCTK_DELTA_SPACE(2)*CCTK_DELTA_SPACE(2) ) ); \n\n if (verbose) {\n //CCTK_VInfo (CCTK_THORNSTRING, \"SphericalSurface: calculated max_radius = %.12f\\n\", max_radius);\n CCTK_VInfo (CCTK_THORNSTRING, \"SphericalSurface: buffer_radius = %.12f\", double (sqrt( np*np*CCTK_DELTA_SPACE(0)*CCTK_DELTA_SPACE(0) \n + np*np*CCTK_DELTA_SPACE(1)*CCTK_DELTA_SPACE(1)\n + np*np*CCTK_DELTA_SPACE(2)*CCTK_DELTA_SPACE(2) )));\n }\n\n /*\n unsigned long k[8];\n \n k[0] = CCTK_GFINDEX3D(cctkGH, 0, 0, 0);\n k[1] = CCTK_GFINDEX3D(cctkGH, cctk_lsh[0]-1, 0, 0);\n k[2] = CCTK_GFINDEX3D(cctkGH, 0, cctk_lsh[1]-1, 0);\n k[3] = CCTK_GFINDEX3D(cctkGH, cctk_lsh[0]-1, cctk_lsh[1]-1, 0);\n k[4] = CCTK_GFINDEX3D(cctkGH, 0, 0, cctk_lsh[2]-1);\n k[5] = CCTK_GFINDEX3D(cctkGH, cctk_lsh[0]-1, 0, cctk_lsh[2]-1);\n k[6] = CCTK_GFINDEX3D(cctkGH, 0, cctk_lsh[1]-1, cctk_lsh[2]-1);\n k[7] = CCTK_GFINDEX3D(cctkGH, cctk_lsh[0]-1, cctk_lsh[1]-1, cctk_lsh[2]-1);\n */\n \n unsigned long kx[8], ky[8], kz[8];\n \n kx[0] = 0; ky[0] = 0; kz[0] = 0;\n kx[1] = cctk_lsh[0]-1, ky[1] = 0; kz[1] = 0;\n kx[2] = 0; ky[2] = cctk_lsh[1]-1; kz[2] = 0;\n kx[3] = cctk_lsh[0]-1; ky[3] = cctk_lsh[1]-1; kz[3] = 0;\n kx[4] = 0; ky[4] = 0; kz[4] = cctk_lsh[2]-1;\n kx[5] = cctk_lsh[0]-1; ky[5] = 0; kz[5] = cctk_lsh[2]-1;\n kx[6] = 0; ky[6] = cctk_lsh[1]-1; kz[6] = cctk_lsh[2]-1;\n kx[7] = cctk_lsh[0]-1; ky[7] = cctk_lsh[1]-1; kz[7] = cctk_lsh[2]-1;\n \n \n int i;\n bool is_contained = false;\n for (i=0; i < 8; i++)\n {\n //if (max_radius < sqrt(x[k[i]]*x[k[i]] + y[k[i]]*y[k[i]] + z[k[i]]*z[k[i]]))\n // is_contained = true;\n CCTK_REAL xx = CCTK_ORIGIN_SPACE(0) + (cctk_lbnd[0] + kx[i]) * CCTK_DELTA_SPACE(0);\n CCTK_REAL yy = CCTK_ORIGIN_SPACE(1) + (cctk_lbnd[1] + ky[i]) * CCTK_DELTA_SPACE(1);\n CCTK_REAL zz = CCTK_ORIGIN_SPACE(2) + (cctk_lbnd[2] + kz[i]) * CCTK_DELTA_SPACE(2);\n if (max_radius < sqrt(xx*xx + yy*yy + zz*zz))\n is_contained = true;\n }\n \n int max_rl = 0;\n if (is_contained)\n {\n if (CCTK_Equals(auto_res_grid[n], \"fully contained\"))\n {\n sf_delta_theta_estimate[n] = auto_res_ratio[n] / my_radius * sqrt(CCTK_DELTA_SPACE(0)*CCTK_DELTA_SPACE(0) \n + CCTK_DELTA_SPACE(1)*CCTK_DELTA_SPACE(1) \n + CCTK_DELTA_SPACE(2)*CCTK_DELTA_SPACE(2));\n \n sf_delta_phi_estimate[n] = auto_res_ratio[n] / my_radius * sqrt(CCTK_DELTA_SPACE(0)*CCTK_DELTA_SPACE(0) \n + CCTK_DELTA_SPACE(1)*CCTK_DELTA_SPACE(1) \n + CCTK_DELTA_SPACE(2)*CCTK_DELTA_SPACE(2));\n }\n \n max_rl = get_reflevel(cctkGH);\n }\n else if (first_call)\n {\n // set to zero initially\n sf_delta_theta_estimate[n] = 0;\n sf_delta_phi_estimate[n] = 0; \n }\n \n \n // find minimum value of \"sf_maxreflevel\" over all processors\n //MPI_Allreduce(&max_rl, &idummy, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);\n CCTK_ReduceLocScalar(cctkGH, -1, min_reduction_handle, &max_rl, &idummy, CCTK_VARIABLE_INT);\n if (idummy != 0 || first_call)\n\tsf_maxreflevel[n] = idummy;\n \n // this condition can become true because of this approximate algorithm\n // which does not take into account disconnected ref. regions\n if (sf_maxreflevel[n] > sf_minreflevel[n])\n sf_maxreflevel[n] = sf_minreflevel[n]; // can still be incorrect!\n\t\n \n if (CCTK_Equals(auto_res_grid[n], \"fully contained\"))\n {\n // find maximum value of \"sf_delta_phi/theta\" over all processors\n CCTK_REAL dummy = 0;\n //MPI_Allreduce(&sf_delta_theta_estimate[n], &dummy, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);\n CCTK_ReduceLocScalar(cctkGH, -1, max_reduction_handle, &sf_delta_theta_estimate[n], &dummy, CCTK_VARIABLE_REAL);\n sf_delta_theta_estimate[n] = dummy;\n \n dummy = 0;\n //MPI_Allreduce(&sf_delta_phi_estimate[n], &dummy, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);\n CCTK_ReduceLocScalar(cctkGH, -1, max_reduction_handle, &sf_delta_phi_estimate[n], &dummy, CCTK_VARIABLE_REAL);\n sf_delta_phi_estimate[n] = dummy;\n }\n \n if (verbose) {\n CCTK_VInfo (CCTK_THORNSTRING, \"SphericalSurface: sf_maxreflevel[%d] = %d, sf_minreflevel[%d] = %d\", n, int(sf_maxreflevel[n]), n, int(sf_minreflevel[n]));\n CCTK_VInfo (CCTK_THORNSTRING, \"SphericalSurface: sf_delta_theta[%d] = %.6f, sf_delta_phi[%d] = %.6f\\n\", n, sf_delta_theta_estimate[n], n, sf_delta_phi_estimate[n]);\n }\n\n }\n \n first_call = false;\n \n}\n" |
| "documentation.tex": "% *======================================================================*\n% Cactus Thorn template for ThornGuide documentation\n% Author: Ian Kelley\n% Date: Sun Jun 02, 2002\n%\n% Thorn documentation in the latex file doc/documentation.tex \n% will be included in ThornGuides built with the Cactus make system.\n% The scripts employed by the make system automatically include \n% pages about variables, parameters and scheduling parsed from the \n% relevant thorn CCL files.\n% \n% This template contains guidelines which help to assure that your \n% documentation will be correctly added to ThornGuides. More \n% information is available in the Cactus UsersGuide.\n% \n% Guidelines:\n% - Do not change anything before the line\n% % START CACTUS THORNGUIDE\",\n% except for filling in the title, author, date, etc. fields.\n% - Each of these fields should only be on ONE line.\n% - Author names should be separated with a \\\\ or a comma.\n% - You can define your own macros, but they must appear after\n% the START CACTUS THORNGUIDE line, and must not redefine standard \n% latex commands.\n% - To avoid name clashes with other thorns, 'labels', 'citations', \n% 'references', and 'image' names should conform to the following \n% convention: \n% ARRANGEMENT_THORN_LABEL\n% For example, an image wave.eps in the arrangement CactusWave and \n% thorn WaveToyC should be renamed to CactusWave_WaveToyC_wave.eps\n% - Graphics should only be included using the graphicx package. \n% More specifically, with the \"\\includegraphics\" command. Do\n% not specify any graphic file extensions in your .tex file. This \n% will allow us to create a PDF version of the ThornGuide\n% via pdflatex.\n% - References should be included with the latex \"\\bibitem\" command. \n% - Use \\begin{abstract}...\\end{abstract} instead of \\abstract{...}\n% - Do not use \\appendix, instead include any appendices you need as \n% standard sections. \n% - For the benefit of our Perl scripts, and for future extensions, \n% please use simple latex. \n%\n% *======================================================================* \n% \n% Example of including a graphic image:\n% \\begin{figure}[ht]\n% \t\\begin{center}\n% \t \\includegraphics[width=6cm]{MyArrangement_MyThorn_MyFigure}\n% \t\\end{center}\n% \t\\caption{Illustration of this and that}\n% \t\\label{MyArrangement_MyThorn_MyLabel}\n% \\end{figure}\n%\n% Example of using a label:\n% \\label{MyArrangement_MyThorn_MyLabel}\n%\n% Example of a citation:\n% \\cite{MyArrangement_MyThorn_Author99}\n%\n% Example of including a reference\n% \\bibitem{MyArrangement_MyThorn_Author99}\n% {J. Author, {\\em The Title of the Book, Journal, or periodical}, 1 (1999), \n% 1--16. {\\tt http://www.nowhere.com/}}\n%\n% *======================================================================* \n\n\\documentclass{article}\n\n% Use the Cactus ThornGuide style file\n% (Automatically used from Cactus distribution, if you have a \n% thorn without the Cactus Flesh download this from the Cactus\n% homepage at www.cactuscode.org)\n\\usepackage{../../../../doc/latex/cactus}\n\n\\begin{document}\n\n% The author of the documentation\n\\author{Erik Schnetter \\textless schnetter@cct.lsu.edu\\textgreater}\n\n% The title of the document (not necessarily the name of the Thorn)\n\\title{SphericalSurface}\n\n% the date your document was last changed\n\\date{2007-03-06}\n\n\\maketitle\n\n% Do not delete next line\n% START CACTUS THORNGUIDE\n\n% Add all definitions used in this documentation here \n% \\def\\mydef etc\n\n\\begin{abstract}\nThis thorn provides a repository for two-dimensional surfaces with\nspherical topology. This thorn does not actually do anything with\nthese surfaces, but allows other thorns to store and retrieve the\nsurfaces and some associated information. The exact interpretation of\nthe stored quantities is up to the using thorns, but certain standard\ndefinitions are suggested.\n\\end{abstract}\n\n\n\n\\section{Introduction}\n\nMany thorns work on manifolds that are two-dimensional, closed\nsurfaces. Examples are apparent and event horizons, or the surfaces\non which gravitational waves are extracted. Other such surfaces might\nbe excision or outer boundaries (although these are currently not\ntreated as such). There is a need to have a common representation for\nsuch surfaces, so that the surface-finding thorns and the thorns\nworking with these surfaces can be independent. A common\nrepresentation will also facilitate visualisation. This thorn\n\\texttt{SphericalSurface} provides just such a common representation.\n\nThis thorn is not meant to do anything else but be a ``repository''\nfor surfaces. It is up to the surface-finding and surface-using\nthorns to agree on the details of the information stored. Of course,\nstandard definitions for the stored quantities are suggested. (For\nexample, there is no exact definition of the quadrupole moment,\nbecause this definition will depend on the kind of surface that is\nstored. However, it is specified that the quadrupole moment should be\ncalculate with respect to the centroid, and that it should not be\ntrace-free.)\n\nThis thorn provides storage for several independent surfaces,\nidentified by an \\emph{index}. It is up to the user to specify,\nprobably in the parameter file, which thorns use what surfaces for\nwhat purpose.\n\n\n\n\\section{Surface Definition}\n\nThis thorn provides, for each surface, a two-dimensional grid array\n\\code{sf\\_radius} and grid scalars \\code{sf\\_origin\\_x},\n\\code{sf\\_origin\\_y}, and \\code{sf\\_origin\\_z}. The number of\nsurfaces is determined by the parameter \\code{nsurfaces}, which has\nto be set in the parameter file.\n\n\\code{sf\\_radius} should contain the radius of the surface as\nmeasured from its origin, where the arrays indices vary in the\n$\\theta$ and $\\phi$ direction, respectively. Both the radius array\nand the surface origin are supposed to be set when a surface is\nstored.\n\nThe coordinates on the surface, i.e.\\ the grid origin and spacing in\nthe $\\theta$ and $\\phi$ directions, is available from the grid scalars\n\\code{sf\\_origin\\_theta}, \\code{sf\\_origin\\_phi},\n\\code{sf\\_delta\\_theta}, and \\code{sf\\_delta\\_phi}. These grid\nscalars are set by the thorn SphericalSurface in the \\code{basegrid}\nbin, and are meant to be read-only for other thorns.\n\n\n\n\\begin{quotation}\n\\subsection*{A note on vector grid variables}\n\nA relatively new addition to Cactus (in November 2003) are vector grid\nvariables. These are essentially arrays of grid variables. Thorn\nSphericalSurface makes use of these by storing the surfaces in such\narrays. That means that in order to access data from a single\nsurface, on has to use the corresponding surface index as array index.\nIn a similar manner, thorn SurfaceIndex uses array parameters for its\nparameters (except certain global ones).\n\nThis should be kept in mind when writing source code. C has the\nunfortunate property of converting arrays into meaningless integers if\nan array subscript is accidentally omitted. Fortran knows whole-array\nexpressions, meaning that it would act on all surfaces instead of a\nsingle one if an array subscript is accidentally omitted.\n\nEach element of a vector grid function is a grid function. (The term\n``grid function vector'' might have been more appropriate.) As such,\nit has a name, which can be used e.g.\\ for output. The name consists\nof the vector grid function name to which the surface index in square\nbrackets has been appended.\n\\end{quotation}\n\n\n\n\\subsection{Global Surface Quantities}\n\nIn many cases, only some abstract information about the surface is of\ninterest, such as its mean radius or its quadrupole moment. For that\npurpose there are additional grid scalars that carry this information.\nThese grid scalars are also supposed to be set when a surface is\nstored. These grid scalars are\n\\begin{description}\n\n\\item[\\code{sf\\_mean\\_radius}] Mean of the surface radius. This\nshould be the arithmetic mean where the radii have been weighted with\n$\\sin\\theta$, or a suitable generalisation thereof. This quantity is\nalso supposed to be a measure of the surface's monopole moment. One\nsuggested expression is $M=\\sqrt{A}$ with $A = \\int_S d\\Omega\\, r^2 /\n\\int_S d\\Omega$.\n\n\\item[\\code{sf\\_min\\_radius}, \\code{sf\\_max\\_radius}] Minimum and\nmaximum of the surface radius.\n\n\\item[\\code{sf\\_centroid\\_x}, \\code{sf\\_centroid\\_y},\n\\code{sf\\_centroid\\_z}] The centre of the surface. While the\nquantities \\code{sf\\_origin\\_*} denote the point from which the\nradius of the surface is measured, the quantities\n\\code{sf\\_centroid\\_*} should contain the point which is\n``logically'' the centre of the surface. This quantity is supposed to\nbe a measure of the dipole moment of the surface. One suggested\nexpression is $D^i = \\int_S d\\Omega\\, x^i / A$.\n\n\\item[\\code{sf\\_quadrupole\\_xx}, \\code{sf\\_quadrupole\\_xy},\n\\code{sf\\_quadrupole\\_xz}, \\code{sf\\_quadrupole\\_yy},\n\\code{sf\\_quadrupole\\_yz}, \\code{sf\\_quadrupole\\_zz}] The\nquadrupole moment of the surface. This should be the full quadrupole\nmoment and not a trace-free quantity. One suggested expression is\n$Q^{ij} = \\int_S d\\Omega\\, y^i y^j / A$ with $y^i = x^i - D^i$.\n\n\\item[\\code{sf\\_min\\_x}, \\code{sf\\_min\\_y}, \\code{sf\\_min\\_z},\n\\code{sf\\_max\\_x}, \\code{sf\\_max\\_y}, \\code{sf\\_max\\_z}] The\nbounding box of the surface.\n\n\\end{description}\nNote that the integral expressions are only suggestions which should\nbe adapted to whatever is natural for the stored surface. The\nsuggested integral expressions also depend on the metric which is\nused; this should be a ``natural'' metric for the surface. E.g.\\ for\napparent horizons, this might be the induced two-metric $q_{ij}$ from\nthe projection of the ADM three-metric $\\gamma_{ij}$.\n\n\n\n\\subsection{Validity of Surface Data}\n\nThere is also an integer flag \\code{valid} available. Its\ndefinition is up to the surface-providing thorn. The following\ninterpretations are \\emph{suggested}:\n\\begin{description}\n\n\\item[zero:] No surface is provided at this time step.\n\n\\item[negative:] No surface could be found at this time step.\n\n\\item[positive:] The surface data are valid.\n\n\\end{description}\nNote that, if this flag is used, it is necessary to set this flag at\nevery iteration. This flag is not automatically reset to zero.\n\n\n\n\\section{Surface Array Shape}\n\nThe number of grid points in the radius array \\code{sf\\_radius} is\ndetermined by the parameters \\code{ntheta} and \\code{nphi}. These\narrays exist for each surface. (Internally, thorn SphericalSurface\nstores all surfaces with the same array shape \\code{maxntheta} and\n\\code{maxnphi}, so that the parameters \\code{ntheta} and\n\\code{nphi} must not be used for index calculations. Use the\nsurfaces \\code{lsh} instead.) The surface array shape includes\nghost or boundary zones at the array edges. These ghost zones have\nthe same size for all surfaces.\n\nNote that because the radius arrays are stored with larger size\n$\\code{maxntheta} \\times \\code{maxnphi}$, the actual radius data\n(of size\n$\\code{ntheta[surface\\_number]} \\times \\code{nphi[surface\\_number]}$\nelements) is in general {\\em not contiguous in memory.\\/}\nIf you want to interpolate a SphericalSurface surface radius,\nyou need to either copy the radius data to a contiguous 2-D array of size\n$\\code{ntheta[surface\\_number]} \\times \\code{nphi[surface\\_number]}$,\nor use an interpolator which supports such non-contiguous input arrays.\nThe AEIThorns/AEILocalInterp local interpolation thorn supports these\nvia the \\code{input\\_array\\_strides} parameter-table option.\nSee the AEILocalInterp thorn guide for details.\n\n\n\n\\section{Surface Symmetries}\n\nIt is often the case that one uses symmetries to reduce the size of\nthe simulation domain, such as octant or quadrant mode. Whenever a\nsymmetry plane intersects a surface, only part of the surface is\nactually stored. The user has to define the symmetries of each\nsurface in the parameter file via the parameters\n\\code{sf\\_symmetry\\_x}, \\code{sf\\_symmetry\\_y}, and\n\\code{sf\\_symmetry\\_z}. They indicate that a \nreflection symmetry exists in the corresponding direction. The\nsurface origin is required to lie in the corresponding symmetry\nplanes.\n\nThorn SphericalSurface takes these symmetries into account when it\ncalculates the grid spacing and the origin of the surface coordinates\n$\\theta$ and $\\phi$.\n\n\n\n\\section{Input and Output}\n\nAs the surfaces are stored as grid variables, the standard input and\noutput routines will work for them. The standard visualisation tools\nwill be able to visualise them. The surfaces will also automatically\nbe checkpointed and restored.\n\n\n\n\\subsection{Acknowledgements}\n\nThis thorn was suggested during meetings of the numerical relativity\ngroup at the AEI. Jonathan Thornburg provided many detailed and\nuseful suggestions. Ed Evans, Carsten Gundlach, Ian Hawke, and Denis\nPollney contributed comments and suggestions.\n\n% Do not delete next line\n% END CACTUS THORNGUIDE\n\n\\end{document}\n" |