diff options
Diffstat (limited to 'src/setup.cc')
-rw-r--r-- | src/setup.cc | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/src/setup.cc b/src/setup.cc index 608aa99..08b3dd6 100644 --- a/src/setup.cc +++ b/src/setup.cc @@ -9,6 +9,10 @@ //#include <mpi.h> +// local functions +static bool all_sf_names_are_unique(CCTK_INT warnlevel); +static int get_reflevel (cGH const * const cctkGH); + static int get_reflevel (cGH const * const cctkGH) { @@ -20,8 +24,75 @@ static int get_reflevel (cGH const * const cctkGH) } -//TODO: overlap with finer levels still seems to be incorrect! +// simple translation function from user-friendly name to numerical Id +// if name is not empty returns the matching name and -1 if no name matches +// if name is empty returns fallbackid +extern "C" CCTK_INT SphericalSurface_IdFromName (CCTK_INT fallbackid, CCTK_POINTER_TO_CONST sfname) +{ + DECLARE_CCTK_PARAMETERS; + CCTK_INT retval = -1; + + // re-check for unique names since the parameters are steerable + if(!all_sf_names_are_unique(CCTK_WARN_ALERT)) + CCTK_WARN(CCTK_WARN_ABORT, "Not all spherical surface names are unique."); + + if (CCTK_Equals(static_cast<CCTK_STRING>(sfname), "")) { + + retval = fallbackid; + } else { + + for (CCTK_INT n=0; n<nsurfaces; ++n) { + + if (CCTK_Equals(static_cast<CCTK_STRING>(sfname), name[n])) { + + retval = n; + break; + } + } + + if (retval == -1) { + CCTK_VWarn(CCTK_WARN_ALERT, __LINE__, __FILE__, CCTK_THORNSTRING, + "Did not find spherical surface with name '%s'.", + sfname); + } + } + + return retval; +} +// utility function to check if all SphericalSurface names are unique (or empty) +static bool all_sf_names_are_unique(CCTK_INT warnlevel) +{ + DECLARE_CCTK_PARAMETERS; + bool all_unique = true; + + for (int i=0; i<nsurfaces; ++i) { + if (CCTK_Equals(static_cast<CCTK_STRING>(name[i]), "")) + continue; + for (int j=i+1; j<nsurfaces; ++j) { + if (CCTK_Equals(static_cast<CCTK_STRING>(name[i]), static_cast<CCTK_STRING>(name[j]))) { + CCTK_VWarn(warnlevel, __LINE__, __FILE__, CCTK_THORNSTRING, + "Duplicate names for spherical surfaces %d and %d: %s == %s", + i,j, name[i], name[j]); + all_unique = false; + } + } + } + + return all_unique; +} + +// check early that all SphericalSurface names are valid +extern "C" void SphericalSurface_ParamCheck (CCTK_ARGUMENTS) +{ + DECLARE_CCTK_ARGUMENTS; + + if (!all_sf_names_are_unique(CCTK_WARN_ALERT)) { + CCTK_PARAMWARN("Not all spherical surface names are unique."); + } +} + +//TODO: overlap with finer levels still seems to be incorrect! extern "C" void SphericalSurface_Setup (CCTK_ARGUMENTS) { |