aboutsummaryrefslogtreecommitdiff
path: root/src/Slicing.c
blob: 4d41b556bed5db7de044dbcf57eabc131f91fcfd (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
 /*@@
   @file      Slicing.c
   @date      Wed Jul 14 16:03:12 1999
   @author    Gerd Lanfermann
   @desc 
     A flexible calling structure to calling slicing functions:
     * a slicing is registered with its name, with a flag to tell if its activated by
       a parameter, with a function, which tells if the slicing should be used 
       in the next interation. 
     * The function is registered in a startup routine of the code providing the 
       slicing.
     * The param_active flag is set where  ? FIXME
     * This structure is evaluted during a CCTK_PRESTEP, information can be queried 
       by all slicings, which can take their turn or skip.
   @enddesc 
 @@*/

#include <stdio.h>
#include <stdlib.h>

#include "cctk.h"
#include "StoreHandledData.h"
#include "WarnLevel.h"
#include "Slicing.h"
#include "ErrorCodes.h"
#include "Groups.h"
#include "Misc.h"

static char *rcsid = "$Id$";

/* Local data holding info on slicings..*/

static int num_slics = 0;
static cHandledData *Eslicings = NULL;

 /*@@
   @routine    Einstein_RegisterSlicing
   @date       Wed Jul 14 15:57:32 1999
   @author     Gerd Lanfermann
   @desc 
   This routine registers a slicing in a structure whcih provides information
   whether it is activated by parameter and which function is responsible 
   for evaluating whether the slicing should be used in the next iteartion.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/

int Einstein_RegisterSlicing(const char *slice_name)
{
  int handle;

  struct Einstein_slicing *new_slicing;
  
  /*Check that this Slicing has not been registered, yet */
  handle = Einstein_GetSlicing(slice_name);
  
  if (handle<0) {
    
    /* Allocate new slicing structure */
    new_slicing = (struct Einstein_slicing*) malloc(sizeof(struct Einstein_slicing));

    if (new_slicing) {
      
      /* store new_slicing in the StoreHandledData-array and returns the handle for it */
      handle = CCTK_NewHandle(&Eslicings, slice_name, new_slicing);

      /*Initialize the Einstein_slicing structure */

      /* we know the slicing name */
      new_slicing->name = (char *)slice_name; 

      /* Function pointer , evaluates if to perform this slicings, allowing 
	 for iteration checks, gridfucntion behavior, etc.  Will be set by
         Einstein_RegisterTimeToSlice */
      new_slicing->timetoslice = NULL;
      
      /* Flag to indicate if this slicing activated by a parameter [0/1] */
      new_slicing->param_active = 0;
      
    } else 
      {
	/* Memory failure */
	handle = -2;  /* FIXME: some decent MACROS here */
      }
  }
  else
    {
      /* Extension handle already exists */
      handle = -1;
    }
  
  return handle;
}

 /*@@
   @routine    Einstein_SetSliceActive
   @date       Wed Jul 14 16:13:33 1999
   @author     Gerd Lanfermann
   @desc 
     Sets the param_active flag to active (1) or inactive (0), reflecting that
     it is specified as slicing in the parameter database, or that is not used
     anymore.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/

int Einstein_SetSliceActive(int handle, int flag) 
{
  int return_code;
  struct Einstein_slicing *slicing;

  slicing = CCTK_GetHandledData(Eslicings, handle);
  
  if (slicing) {
    slicing->param_active = flag;
    return_code = 1;
  }
  else {
    /* handle didn't return the data pointer */
    return_code = 0;
  }
  
  return return_code;
}
  

 /*@@
   @routine    Einstein_RegisterTimeToSlice
   @date       Wed Jul 14 15:52:09 1999
   @author     Gerd Lanfermann
   @desc 
      Routine registers a function with the slicing. This function returns
      information whether the slicing is supposed to used during the next
      iteration. The user can register any function to check for iteration 
      conditions, grid function behavior, etc. 
   @enddesc 
   @calls     
   @calledby   The user
   @history 
 
   @endhistory 

@@*/

int Einstein_RegisterTimeToSlice(int handle, void (*func)(cGH *))
{
  int return_code;
  struct Einstein_slicing *slicing;

  slicing = CCTK_GetHandledData(Eslicings, handle);
  
  if (slicing)  {
    slicing->timetoslice=func;
    return_code = 1;
  }
  else {
    /* handle didn't return the data pointer */
    return_code = 0;
  }
  return return_code;
}