aboutsummaryrefslogtreecommitdiff
path: root/src/Slicing.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Slicing.c')
-rw-r--r--src/Slicing.c176
1 files changed, 176 insertions, 0 deletions
diff --git a/src/Slicing.c b/src/Slicing.c
new file mode 100644
index 0000000..5856dd3
--- /dev/null
+++ b/src/Slicing.c
@@ -0,0 +1,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 cHandleData *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(slic_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 *)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(Einstein_slicing, 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)(tFleshConfig *, int , cGH))
+{
+ int return_code;
+ struct Einstein_slicing *slicing;
+
+ slicing = CCTK_GetHandledData(Einstein_slicing, handle);
+
+ if (slicing) {
+ slicing->timetoslice=func;
+ return_code = 1;
+ }
+ else {
+ /* handle didn't return the data pointer */
+ return_code = 0;
+ }
+ return return_code;
+}
+
+
+
+
+