From 0a07f736e27a8b78f897bc8a9619326b1194cd7a Mon Sep 17 00:00:00 2001 From: rhaas Date: Tue, 24 Jan 2012 20:23:54 +0000 Subject: Add functionality to name spherical surfaces This provides a simple function sf_IdFromName(CCTK_INT id, CCTK_STRING name) to translate from a parameter SphericalSurface::name[] to interger ids. git-svn-id: http://svn.cactuscode.org/arrangements/CactusNumerical/SphericalSurface/trunk@47 40f6ab95-0e4f-0410-8daa-ee8d7420be1d --- interface.ccl | 8 ++++++- param.ccl | 6 +++++ src/setup.cc | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 85 insertions(+), 2 deletions(-) diff --git a/interface.ccl b/interface.ccl index 5a9886f..46defb9 100644 --- a/interface.ccl +++ b/interface.ccl @@ -9,6 +9,13 @@ inherits: grid CCTK_INT FUNCTION GetRefinementLevel (CCTK_POINTER_TO_CONST IN cctkGH) USES FUNCTION GetRefinementLevel +# 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 +CCTK_INT \ +FUNCTION sf_IdFromName (CCTK_INT IN fallbackid, CCTK_POINTER_TO_CONST IN name) +PROVIDES FUNCTION sf_IdFromName WITH SphericalSurface_IdFromName LANGUAGE C + PUBLIC: @@ -108,4 +115,3 @@ CCTK_REAL sf_coordinate_estimators[nsurfaces] TYPE=scalar { sf_delta_theta_estimate sf_delta_phi_estimate } "Surface coordinate estimators" - diff --git a/param.ccl b/param.ccl index 8d04742..37a2f26 100644 --- a/param.ccl +++ b/param.ccl @@ -11,6 +11,12 @@ CCTK_INT nsurfaces "Number of surfaces" STEERABLE=recover 0:42 :: "" } 0 +# can be queried via SphericalSurface_IdFromName() +CCTK_STRING name[42] "User friendly name of spherical surface" STEERABLE=always +{ + "" :: "none set" + ".*" :: "any string" +} "" BOOLEAN auto_res[42] "Automatically determine resolution according to radius and Cartesian resolution" 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 +// 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(sfname), "")) { + + retval = fallbackid; + } else { + + for (CCTK_INT n=0; n(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(name[i]), "")) + continue; + for (int j=i+1; j(name[i]), static_cast(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) { -- cgit v1.2.3