summaryrefslogtreecommitdiff
path: root/doc/UsersGuide/Infrastructure.tex
blob: cf236421d8f98cfd4a9b87309d4b883ea3da0502 (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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
\part{Infrastructure Thorn Writer's Guide}

\begin{enumerate}

 \item{} Concepts and Terminology (Overloading and registration of functions)
 \item{} The cGH structure --- what it is and how to use it
 \item{} Extending the cGH structure
 \item{} Querying Group and Variable Information
 \item{} Providing an IO layer
 \item{} Providing a communication layer
 \item{} Doing more --- replacing the rest of the code
 \item{} Appendices
 \begin{itemize}
  \item{} Overloadable Functions in the F***h
  \begin{itemize}
   \item{} Main
   \begin{itemize}
    \item{} {\t int CCTK\_Initialise(tFleshConfig *)}
    \item{} {\t int CCTK\_Evolve(tFleshConfig *)} 
    \item{} {\t int CCTK\_Shutdown(tFleshconfig *)}
    \item{} Defaults
   \end{itemize}
   \item{} IO
   \begin{itemize}
    \item{} {\t int CCTK\_OutputGH(cGH *GH)}
    \item{} {\t int CCTK\_OutputVarAsByMethod(cGH *GH, const char *var,
          const char *method, const char *alias)}
    \item{} Defaults
    \begin{itemize}
     \item{} {\t CCTK\_OutputGH}
     \item{} {\t CCTK\_OutputVarAsByMethod}
    \end{itemize}
   \end{itemize}
   \item{} Comm
   \begin{itemize}
    \item{} {\t int CCTK\_SyncGroup(cGH *GH, const char *group)}
    \item{} {\t int CCTK\_EnableGroupStorage(cGH *GH, const char *group)}
    \item{} {\t int CCTK\_DisableGroupStorage(cGH *GH, const char *group)}
    \item{} {\t int CCTK\_EnableGroupComm(cGH *GH, const char *group)}
    \item{} {\t int CCTK\_DisableGroupComm(cGH *GH, const char *group)}
    \item{} {\t int CCTK\_Barrier(cGH *GH)}
    \item{} {\t int CCTK\_Reduce(cGH *GH, const char *operation, 
            int n\_infields, int n\_outfields,
            int out\_type, void **outarray, ...)}
    \item{} {\t int CCTK\_Interp(cGH *GH, const char *operation, 
            int n\_coords, int n\_infields, int n\_outfields,
            int n\_points, int type, ...)}
    \item{} {\t int CCTK\_ParallelInit(cGH *GH)}
    \item{} {\t int CCTK\_Init(cGH *GH)}
    \item{} {\t int CCTK\_Exit(cGH *GH)}
    \item{} {\t int CCTK\_Abort(cGH *GH)}
    \item{} {\t cGH *CCTK\_SetupGH(tFleshConfig *config, int convergence\_level)}
    \item{} Defaults
    \begin{itemize}
     \item{} {\t CCTK\_SetupGH} 
    \end{itemize}
   \end{itemize}
  \end{itemize}
  \item{} Registerable Functions in the F***h
  \begin{itemize}
   \item{} Main
   \begin{itemize}
    \item{} Defaults
   \end{itemize}
   \item{} IO
   \begin{itemize}
    \item{} Defaults
   \end{itemize}
   \item{} Comm
   \begin{itemize}
    \item{} Defaults
   \end{itemize}
  \end{itemize}
 \end{itemize}
\end{enumerate}

\begin{CCTKroutine}

\CCTKname{CCTK\_EnableGroupStorage}
\CCTKdesc{Assigns storage for all grid variables in a given group.}
\end{CCTKroutine}

\begin{CCTKsyn}
\hfill {\bf C} && int storage = {\t CCTK\_EnableGroupStorage( cGH *GH, const char *group )}\\
\hfill {\bf Fortran} && 
{\t call CCTK\_EnableGroupStorage( storage, GH, group ) }\\
&& CCTK\_POINTER GH \\
&& CCTK\_INTEGER storage\\
&& CCTK\_STRING group 
\end{CCTKsyn}

\begin{CCTKpar}
\hfill {\t storage}&-&integer status code returned by routine:
\\
&&
  \begin{tabular}{ll}
  -1 & error\\
  0 & storage toggled from unassigned to assigned\\
  1 & storage was already assigned
  \end{tabular}
\\
\hfill {\t GH} &-&Pointer to CCTK grid hierachy
\\
\hfill {\t group}&-&character string denoting the group to assign storage to, in the format {\t <implementation>::<group>}
\end{CCTKpar}

\noindent
\begin{tabular}{p{14cm}}
\\{\bf Discussion} \hfill\\
This routine is overloadable in the flesh, and must be provided by a thorn 
(usually by the thorn implementing the driver, 
{\it e.g. } the default unigrid driver {\t packages/pugh}).\\
\end{tabular}

\noindent
\begin{tabular}{p{3cm}cp{11cm}}
&&\\
{\bf Examples} \hfill &&\\
\hfill {\bf C} && storage = {\t CCTK\_EnableGroupStorage(GH,``imp::group'')};
\\
\hfill {\bf Fortran} && call {\t CCTK\_ENABLEGROUPSTORAGE(istorage,GH,``imp::group'')};
\\
&\\
{\bf Errors} \hfill&&
\\
&& {\bf FIXME} here will be stuff like can return CCTK\_ERROR\_STORAGEERROR
\end{tabular}

\section{Group and Variable Utility Routines}

The CCTK provides a number of utility routines for dealing
with groups and variables. 
Each group has a {\it group index} 
and each variable has a {\it variable index}. 

\subsection{Routines supplying group or variable indices}


\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t int CCTK\_GetNumGroups(void);}
\vskip .25cm
Returns the total number of groups in all implementations.


\vskip .5cm

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t int CCTK\_GetGroupNum(const char *imp, const char *grp);}
\vskip .25cm
Returns the group index given either
\begin{itemize}
\item{} {\t imp = NULL}, {\t grp = <implementation>::<group>}
\item{} {\t imp = <implementation>}, {\t grp = <group>}
\end{itemize}
 
A valided returned group index will lie between 0 and the number of groups
minus one. The routine returns the error codes
\begin{itemize}
\item{} -1 if no group can be found with the given name
\item{} -2 if both arguments were null
\item{} -3 if the first argument was null and the second argument did not have 
           the correct synthax
\item{} -4 if memory allocation failed
\end{itemize} 

\vskip .5cm

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t int CCTK\_GetNumVars(void);}
\vskip .25cm
Returns the total number of variables in all groups.


\vskip .5cm

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t int CCTK\_GetVarNum(const char *imp, const char *grp, const char *var);}
\vskip .25cm
Returns the variable index given either:
\begin{itemize}
\item{}  {\t imp = NULL}, {\t grp = NULL}, {\t var = <implementation::variable>}
\item{} {\t imp = <implementation>}, {\t grp = NULL}, {\t var = <variable>}
\item{} {\t imp = <implementation>}, {\t grp = <group>}, {\t var = <variable>}
\end{itemize}

A valid returned variable index will lie 
between 0 and the number of variables
minus one. The routine returns the error codes
\begin{itemize}
\item{} -4 if string memory allocation failed
\item{} -3 if the first two arguments were {\t NULL} and the 
           variable name does not contain the implementation
\item{} -2 if the implementation contains no group with
the given group name 
\item{} -1 if there is no variable with the variable name 
in the group
\end{itemize}

\vskip .5cm

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t int CCTK\_GetFirstVarNum(int group);}
\vskip .25cm
Given the global index for a group, this routine returns the 
global index for the first variable in the group, or -1 if
the given group index lies outside the allowed range of
$0 \le {\t group} < {\t CCTK\_GetNumGroups()}$.

\vskip .5cm

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t int CCTK\_GetNumVarsInGroup(int group);}
\vskip .25cm
Given the global index for a group, this routine returns the 
number of variables in the group, or -1 if
the given group index lies outside the allowed range of
$0 \le {\t group} < {\t CCTK\_GetNumGroups()}$.




\subsection{Routines which take indices and return names}

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t char *CCTK\_GetGroupName(int group);}
\vskip .25cm
Given the global index for a group, this routine returns 
the name of the group prepended by the associated implementation,
e.g. {\t implementation::group}. 
If the index is outside the allowed
range of $0 \le {\t group} < {\t CCTK\_GetNumGroups()}$, or 
memory allocation for the returned string fails then {\t NULL}
is returned. Note that the memory for the returned string should
be freed after it is no longer needed.

\vskip .5cm

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t char *CCTK\_GetVarName(int variable);}
\vskip .25cm
Given the global index for a variable, this routine returns 
the name of the variable. If the index is outside the allowed
range of $0 \le {\t variable} < {\t CCTK\_GetNumVars()}$, then {\t NULL}
is returned.

\vskip .5cm

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t char *CCTK\_GetGroupFromVar(int variable);}
\vskip .25cm
Given the global index for a variable, this routine returns 
the name of the group associated with the variable. If there
is no variable associated with this index {\t NULL} is returned.

\vskip .5cm

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t char *CCTK\_GetImplementationFromVar(int variable);}
\vskip .25cm
Given the global index for a variable, this routine returns 
the name of the implementation associated with the variable. If there
is no variable associated with this index {\t NULL} is returned.

\vskip .5cm

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t char *CCTK\_GetFullName(int variable);}
\vskip .25cm
Given the global index for a variable, this routine returns 
the full name of the variable, that is the variable name prepended
by ``<implementation>::''. The routine returns {\t NULL} if there is 
no variable associated with the given index, or if memory allocation
failed. Note that the memory associated with 
the returned string should be freed after use. 





\subsection{Routines concerned with sizes of variables}

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t int CCTK\_GetMaxDim(void);}
\vskip .25cm
Returns the maximum dimension used by any group.


\vskip .5cm

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t int CCTK\_QueryGroupStorage(cGH *GH, const char *group);}
\vskip .25cm
{\bf ROUTINE STILL TO BE WRITTEN !!!!}

Checks if the given group has storage assigned to the arrays 
it contains.


\vskip .5cm

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t int CCTK\_ArrayGroupSize(cGH *GH, const char *group, int direction);}
\vskip .25cm
{\bf ROUTINE STILL TO BE WRITTEN !!!!}

Returns the size of the arrays in a group, in a given direction.





\subsection{Routines concerned with types of variables}

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t int CCTK\_GetGroupData(int group, int *gtype, int *vtype, int *dim, int *n\_variables, int *n\_timelevels);}
\vskip .25cm
Given the index number for a group, on exit the remaining entries 
in the function argument contain the kind of variables held by
the group, the data type of the variables, their dimension, the
number of variables and the number of timelevels. {\bf QUERY: I
don't understand why these are all pointers, I mean how the right 
number gets into the pointer}. The function returns 1, unless the
group index is outside the allowed range, whence it returns 0.
 
\vskip .5cm

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t int CCTK\_GTypeNumber(const char *type);}
\vskip .25cm
A group contains variables all with a certain kind,
which can be {\t ``SCALAR''}, {\t ``GF''} or {\t ``ARRAY''}.
Each of these type strings for a group has an associated 
integer index {\t GROUP\_SCALAR}, {\t GROUP\_GF} and {\t GROUP\_ARRAY} (defined in src/include/Groups.h). This routine
returns the type index associated with a type string.
{\bf QUERY: ANY REASON THIS DOESNT RETURN AN ERROR IF IT DOESNT
GET ONE}

\vskip .5cm

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t int CCTK\_VTypeNumber(const char *type);}
\vskip .25cm
The data type of variables can be
{\t ``INTEGER''}, {\t ``REAL''}, {\t ``COMPLEX''} or {\t ``CHAR''}.
Each of these data type for a variable has an associated 
integer index {\t VARIABLE\_INTEGER}, {\t VARIABLE\_REAL}, {\t VARIABLE\_COMPLEX}  and {\t VARIABLE\_CHAR} (defined in src/include/Groups.h). 
This routine returns the type index associated with a type string.
{\bf QUERY: ANY REASON THIS DOESNT RETURN AN ERROR IF IT DOESNT
GET ONE}

\vskip .5cm

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t int CCTK\_GetVarGType(int variable);}
\vskip .25cm
Returns an index denoting the group kind for a given global variable 
index. The routine returns -1 if the variable index is outside the
allowed range of $0 \le {\t variable} < {\t CCTK\_GetNumVars()}$.

\vskip .5cm

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t int CCTK\_GetVarVType(int variable);}
\vskip .25cm
Returns an index denoting the variable data type for a given global variable 
index. The routine returns -1 if the variable index is outside the
allowed range of $0 \le {\t variable} < {\t CCTK\_GetNumVars()}$.

\vskip .5cm

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t int CCTK\_GetNumTimeLevels(int variable);}
\vskip .25cm
Returns the number of timelevels for a given global variable index.
The routine returns -1 if the variable index is outside the 
allowed range of  $0 \le {\t variable} < {\t CCTK\_GetNumVars()}$.



\subsection{Miscellaneous routines}

\noindent
{\t \#include ``Groups.h''}
\\
\noindent
{\t int CCTK\_DecomposeGroupName(const char *fullname, char **implementation, char **name);}
\vskip .25cm
This routines takes in the string {\t fullname} which should be of the form
{\t <implementation>::<name>}, and on exit {\t implementation} contains a 
pointer to the string {\t ``<implementation>''}, and {\t name} contains a 
pointer to the string {\t ``<name>''}. The routines returns 0 is the string {\t fullname} was
successfully decomposed, 1 is the given string did not contain {\t ::} and 2 
if memory allocation for the new strings failed. The memory for the two 
resulting strings should be freed when no longer needed.


\begin{itemize}
\item{} CCTK\_GetGHExtensionHandle
\item{} CCTK\_GetHandleName
\item{} CCTK\_GetHandle
\item{} CCTK\_GetHandledData
\item{} int CCTK\_SplitString(char **before, char **after, const char *string, const char *sep);
\item{} int CCTK\_Equals(const char *string1, const char *string2);
\item{} int CCTK\_InList(const char *string1, int n\_elements, ...);
\item{} int CCTK\_IntInRange(int inval, const char *range);
\item{} int CCTK\_DoubleInRange(double inval, const char *range);
\item{} int CCTK\_IntInRangeList(int inval, int n\_elements, ...);
\item{} int CCTK\_DoubleInRangeList(double inval, int n\_elements, ...);
\item{} int CCTK\_SetDoubleInRangeList(double *data, const char *value, 
\item{} int CCTK\_SetIntInRangeList(int *data, const char *value, 
\item{} int CCTK\_SetKeywordInRangeList(char **data, const char *value, 
\item{} int CCTK\_SetString(char **data, const char *value);
\item{} int CCTK\_SetLogical(int *data, const char *value);
\end{itemize}