From e38733892767ea31fdb110738cf6fca40dedfb93 Mon Sep 17 00:00:00 2001 From: allen Date: Thu, 6 Jan 2000 15:14:38 +0000 Subject: More tidying of elliptic infrastructure to pick up errors like registering the same class twice. git-svn-id: http://svn.cactuscode.org/arrangements/CactusElliptic/EllBase/trunk@31 57bc7290-fb3d-4efd-a9b1-28e84cce6043 --- src/EllBase.h | 8 ++++---- src/Ell_Interface.c | 10 +++++----- src/Ell_Register.c | 49 ++++++++++++++++++++++++++++++++++++++++--------- src/Startup.c | 42 +++++++++++++++++++++++++----------------- 4 files changed, 74 insertions(+), 35 deletions(-) diff --git a/src/EllBase.h b/src/EllBase.h index 59f40bc..fa4c518 100644 --- a/src/EllBase.h +++ b/src/EllBase.h @@ -14,10 +14,10 @@ #define ELL_SUCCESS 0 #define ELL_NOSOLVER -1 #define ELL_NOCONVERGENCE -2 +#define ELL_NOCLASS -3 #ifdef CCODE - /* Argumennt structure for the four different types of elliptic solvers provided at this point. Difference is MetricI, MetricPsiI and StencilGFI, which are arrays holding the grid function indices of the metric, metric+psi or @@ -35,9 +35,9 @@ extern "C" { #endif -void Ell_RegisterSolver(void (*function), - const char *sname, - const char *eqname); +int Ell_RegisterSolver(void (*function), + const char *sname, + const char *eqname); #ifdef __cplusplus } diff --git a/src/Ell_Interface.c b/src/Ell_Interface.c index c94f4fe..259f40b 100644 --- a/src/Ell_Interface.c +++ b/src/Ell_Interface.c @@ -48,7 +48,7 @@ int Ell_LinConfMetricSolver(cGH *GH, const char *sname) { - int retval=0; + int retval=ELL_SUCCESS; int (*fn)(cGH *GH, int *MetricPsi, int FieldIndex, @@ -123,7 +123,7 @@ int Ell_LinMetricSolver(cGH *GH, const char *sname) { - int retval=0; + int retval=ELL_SUCCESS; int (*fn)(cGH *GH, int *Metric, int FieldIndex, @@ -195,7 +195,7 @@ int Ell_LinFlatSolver(cGH *GH, const char *sname) { - int retval=0; + int retval=ELL_SUCCESS; int (*fn)(cGH *GH, int FieldIndex, int MIndex, @@ -265,7 +265,7 @@ int Ell_BrBrConfMetricSolver(cGH *GH, const char *sname) { - int retval=0; + int retval=ELL_SUCCESS; int (*fn)(cGH *GH, int *MetricPsi, int FieldIndex, @@ -340,7 +340,7 @@ int Ell_PolyConfMetricSolver(cGH *GH, const char *sname) { - int retval=0; + int retval=ELL_SUCCESS; int (*fn)(cGH *GH, int *MetricPsi, int FieldIndex, diff --git a/src/Ell_Register.c b/src/Ell_Register.c index 09e39f2..ee233b7 100644 --- a/src/Ell_Register.c +++ b/src/Ell_Register.c @@ -1,3 +1,12 @@ + /*@@ + @header Ell_Register.h + @date + @author Gerd Lanferman + @desc + Registration routines for elliptic classes and solvers + @enddesc + @version $Header$ + @@*/ #include #include @@ -7,11 +16,13 @@ #include "cctk_parameters.h" #include "cctk_WarnLevel.h" +#include "EllBase.h" + #include "StoreNamedData.h" static pNamedData *EqNameDB; -/* Ell_RegisterEq takes a routine ("function") and registers that routi ne +/* Ell_RegisterEq takes a routine ("function") and registers that routine under the name "eqname" in the EqNameDB" Application: Call Ell_Register with the routine that registers a solver for a elliptic equation class. */ @@ -21,13 +32,27 @@ int Ell_RegisterEq(void *(function)(const char *, void*), const char *eqname) DECLARE_CCTK_PARAMETERS - if (StoreNamedData(&EqNameDB, eqname, (void*)function)==0) + /* Register if function not already there with this name */ + + if (!GetNamedData(EqNameDB, eqname)) { - if CCTK_EQUALS(elliptic_verbose,"yes") + + if (StoreNamedData(&EqNameDB, eqname, (void*)function)==0) + { + if CCTK_EQUALS(elliptic_verbose,"yes") + { + char *msg; + msg = (char *)malloc( (200+strlen(eqname))*sizeof(char) ); + sprintf(msg,"Registered elliptic class: %s",eqname); + CCTK_INFO(msg); + free(msg); + } + } + else { char *msg; msg = (char *)malloc( (200+strlen(eqname))*sizeof(char) ); - sprintf(msg,"Registered elliptic class: %s",eqname); + sprintf(msg,"Failed to register elliptic class: %s",eqname); CCTK_INFO(msg); free(msg); } @@ -36,14 +61,14 @@ int Ell_RegisterEq(void *(function)(const char *, void*), const char *eqname) { char *msg; msg = (char *)malloc( (200+strlen(eqname))*sizeof(char) ); - sprintf(msg,"Failed to register elliptic class: %s",eqname); + sprintf(msg,"Elliptic class %s already registered",eqname); CCTK_INFO(msg); free(msg); } } -/* Ell_RegistersSolver takes a routine ("function") and registers that +/* Ell_RegisterSolver takes a routine ("function") and registers that routine under the name "sname" with the database specified by "eqname". So, how do we get to the database, after all it needs to be hardcoded as pNamedData ? Well, we know its name and in Ell_RegisterEq we have @@ -54,13 +79,14 @@ int Ell_RegisterEq(void *(function)(const char *, void*), const char *eqname) declaration) in his own routine and does not have to put it in a central place. Amen*/ -void Ell_RegisterSolver(void (*function), - const char *sname, - const char *eqname) +int Ell_RegisterSolver(void (*function), + const char *sname, + const char *eqname) { DECLARE_CCTK_PARAMETERS + int retval; void (*fn)(void *, const char *); fn = (void(*)(void (*function), const char *sname)) @@ -79,10 +105,15 @@ void Ell_RegisterSolver(void (*function), CCTK_INFO(msg); free(msg); } + + retval = ELL_SUCCESS; } else { CCTK_WARN(0,"Cannot get function in EqName"); + retval = ELL_NOCLASS; } + return retval; + } diff --git a/src/Startup.c b/src/Startup.c index 6384fc1..c11ce66 100644 --- a/src/Startup.c +++ b/src/Startup.c @@ -24,33 +24,41 @@ void Ell_RegisterBaseEqTypes(cGH *GH) int err; - Ell_RegisterEq(Ell_LinConfMetricRegistry,"Ell_LinConfMetric"); + Ell_RegisterEq(Ell_LinConfMetricRegistry, "Ell_LinConfMetric"); Ell_RegisterEq(Ell_BrBrConfMetricRegistry,"Ell_BrBrConfMetric"); Ell_RegisterEq(Ell_PolyConfMetricRegistry,"Ell_PolyConfMetric"); - Ell_RegisterEq(Ell_LinMetricRegistry,"Ell_LinMetric"); - Ell_RegisterEq(Ell_LinFlatRegistry,"Ell_LinFlat"); + Ell_RegisterEq(Ell_LinMetricRegistry, "Ell_LinMetric"); + Ell_RegisterEq(Ell_LinFlatRegistry, "Ell_LinFlat"); - /* Register boundary SOR can handle */ - err = - - err = Ell_CreateKey(CCTK_VARIABLE_STRING,"EllLinFlat::Bnd"); - err = Ell_CreateKey(CCTK_VARIABLE_STRING,"EllLinConfMetric::Bnd"); - err = Ell_CreateKey(CCTK_VARIABLE_STRING,"EllLinMetric::Bnd"); + err = Ell_CreateKey(CCTK_VARIABLE_STRING, + "EllLinFlat::Bnd"); + err = Ell_CreateKey(CCTK_VARIABLE_STRING, + "EllLinConfMetric::Bnd"); + err = Ell_CreateKey(CCTK_VARIABLE_STRING, + "EllLinMetric::Bnd"); /* Register the variables needed to use these boundaries */ - err = Ell_CreateKey(CCTK_VARIABLE_REAL, "EllLinConfMetric::Bnd::Robin::inf"); - err = Ell_CreateKey(CCTK_VARIABLE_INT, "EllLinConfMetric::Bnd::Robin::falloff"); - err = Ell_CreateKey(CCTK_VARIABLE_REAL, "EllLinConfMetric::Bnd::Const::V0"); + err = Ell_CreateKey(CCTK_VARIABLE_REAL, + "EllLinConfMetric::Bnd::Robin::inf"); + err = Ell_CreateKey(CCTK_VARIABLE_INT, + "EllLinConfMetric::Bnd::Robin::falloff"); + err = Ell_CreateKey(CCTK_VARIABLE_REAL, + "EllLinConfMetric::Bnd::Const::V0"); /* Register the variables needed to use these boundaries */ - err = Ell_CreateKey(CCTK_VARIABLE_REAL, "EllLinMetric::Bnd::Robin::inf"); - err = Ell_CreateKey(CCTK_VARIABLE_INT, "EllLinMetric::Bnd::Robin::falloff"); + err = Ell_CreateKey(CCTK_VARIABLE_REAL, + "EllLinMetric::Bnd::Robin::inf"); + err = Ell_CreateKey(CCTK_VARIABLE_INT, + "EllLinMetric::Bnd::Robin::falloff"); err = Ell_CreateKey(CCTK_VARIABLE_REAL, "EllLinMetric::Bnd::Const::V0"); /* Register the variables needed to use these boundaries */ - err = Ell_CreateKey(CCTK_VARIABLE_REAL, "EllLinFlat::Bnd::Robin::inf"); - err = Ell_CreateKey(CCTK_VARIABLE_INT, "EllLinFlat::Bnd::Robin::falloff"); - err = Ell_CreateKey(CCTK_VARIABLE_REAL, "EllLinFlat::Bnd::Const::V0"); + err = Ell_CreateKey(CCTK_VARIABLE_REAL, + "EllLinFlat::Bnd::Robin::inf"); + err = Ell_CreateKey(CCTK_VARIABLE_INT, + "EllLinFlat::Bnd::Robin::falloff"); + err = Ell_CreateKey(CCTK_VARIABLE_REAL, + "EllLinFlat::Bnd::Const::V0"); } -- cgit v1.2.3