aboutsummaryrefslogtreecommitdiff
path: root/src/Ell_Register.c
blob: 09e39f2d2618c7684bad7f262a20b13cc271ddce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "cctk.h"
#include "cctk_parameters.h"
#include "cctk_WarnLevel.h"

#include "StoreNamedData.h"

static pNamedData *EqNameDB;

/* Ell_RegisterEq takes a routine ("function") and registers that routi  ne 
   under the name "eqname" in the EqNameDB"
   Application: Call Ell_Register with the routine that registers a solver 
   for a elliptic equation class. */

int Ell_RegisterEq(void *(function)(const char *, void*), const char *eqname) 
{

  DECLARE_CCTK_PARAMETERS

  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,"Failed to register elliptic class: %s",eqname);
    CCTK_INFO(msg);
    free(msg);
  }

}

/* Ell_RegistersSolver 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 
   registered a function under the equation class name. 
   We now get that function and use that function to register the solver.
   Sounds confusing, well it is. The advantage is, that somebody can come 
   up with a new equation class and can keep the database (the pNamedData
   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) 
{

  DECLARE_CCTK_PARAMETERS

  void (*fn)(void *, const char *);

  fn = (void(*)(void (*function), const char *sname))
    GetNamedData(EqNameDB, eqname);

  if (fn)
  {

    fn(function,sname);

    if CCTK_EQUALS(elliptic_verbose,"yes") 
    {
      char *msg;
      msg = (char *)malloc( (200+strlen(eqname)+strlen(sname))*sizeof(char) );
      sprintf(msg,"Registered elliptic solver %s for %s",sname,eqname);
      CCTK_INFO(msg);
      free(msg);
    }
  }
  else
  {
     CCTK_WARN(0,"Cannot get function in EqName");
  }

}