aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrhaas <rhaas@40f6ab95-0e4f-0410-8daa-ee8d7420be1d>2012-01-24 20:23:54 +0000
committerrhaas <rhaas@40f6ab95-0e4f-0410-8daa-ee8d7420be1d>2012-01-24 20:23:54 +0000
commit0a07f736e27a8b78f897bc8a9619326b1194cd7a (patch)
tree4d2717ad1b6dd5ebb2b25a5e72ca1c443a75932c
parent65cf16ad811cc982886780f8942eb6e27e463c01 (diff)
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
-rw-r--r--interface.ccl8
-rw-r--r--param.ccl6
-rw-r--r--src/setup.cc73
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 <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)
{