summaryrefslogtreecommitdiff
path: root/src/main/Groups.c
diff options
context:
space:
mode:
authorgoodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac>1999-02-08 14:39:55 +0000
committergoodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac>1999-02-08 14:39:55 +0000
commit81e82b5ddfb97721addeea0a40c189f43ea9da3f (patch)
tree8bf56f68d4fc1126cecdcf2e00e7f6243349c780 /src/main/Groups.c
parent56683d5515e7a3baad1e0ea623749e9360602e83 (diff)
Reorganised group stuff.
Now all in Groups.c Tom git-svn-id: http://svn.cactuscode.org/flesh/trunk@225 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/main/Groups.c')
-rw-r--r--src/main/Groups.c445
1 files changed, 434 insertions, 11 deletions
diff --git a/src/main/Groups.c b/src/main/Groups.c
index 5dd68ca7..f75d1112 100644
--- a/src/main/Groups.c
+++ b/src/main/Groups.c
@@ -7,36 +7,459 @@
@enddesc
@@*/
-#include"flesh.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include "flesh.h"
+#include "Misc.h"
+#include "Groups.h"
static char *rcsid = "$Id$";
-int CCTK_EnableGroupStorage(cGH *GH, const char *group)
+/* Static variables needed to hold group and variable data. */
+
+static int n_groups = 0;
+static cGroupDefinition *groups = NULL;
+
+static int total_variables = 0;
+
+static int *group_of_variable = NULL;
+
+static int maxdim = 0;
+
+
+/* When passing to fortran, must pass by reference
+ * so need to define the odd global variable to pass 8-(
+ */
+
+int _cctk_one = 1;
+
+
+cGroupDefinition *CCTK_SetupGroup(const char *implementation, const char *group_name, int n_variables);
+
+
+ /*@@
+ @routine CCTK_CreateGroup
+ @date Thu Jan 14 15:25:54 1999
+ @author Tom Goodale
+ @desc
+
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int CCTK_CreateGroup(const char *gname, const char *thorn, const char *imp,
+ const char *gtype,
+ const char *vtype,
+ int dimension,
+ int n_variables,
+ ...)
{
- return 0;
+ int retval;
+
+ va_list ap;
+ char *position;
+
+ char *variable_name;
+
+ cGroupDefinition *group;
+
+ int variable;
+
+ retval = 0;
+
+ /* Allocate storage for the group and setup some stuff. */
+ if((group = CCTK_SetupGroup(imp, gname, n_variables)))
+ {
+ group->dim = dimension;
+ group->gtype = CCTK_GTypeNumber(gtype);
+ group->vtype = CCTK_VTypeNumber(vtype);
+
+ /* Extract the variable names from the argument list. */
+ va_start(ap, n_variables);
+
+ for(variable = 0; variable < n_variables; variable++)
+ {
+ variable_name = va_arg(ap, char *);
+
+ group->variables[variable].name = (char *)malloc((strlen(variable_name)+1*sizeof(char)));
+
+ if(group->variables[variable].name)
+ {
+ strcpy(group->variables[variable].name, variable_name);
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ va_end(ap);
+
+ if(variable < n_variables)
+ {
+ retval = 3;
+ }
+ else
+ {
+ if (dimension > maxdim) maxdim=dimension;
+ }
+ }
+ else
+ {
+ retval = 2;
+ }
+
+ if(retval)
+ {
+ fprintf(stderr, "Error %d in CCTK_CreateGroup\n", retval);
+ }
+
+ return retval;
+
}
-int CCTK_DisableGroupStorage(cGH *GH, const char *group)
+ /*@@
+ @routine CCTK_SetupGroup
+ @date Thu Jan 14 16:38:40 1999
+ @author Tom Goodale
+ @desc
+ Stores the data associated with a group.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+cGroupDefinition *CCTK_SetupGroup(const char *implementation,
+ const char *name,
+ int n_variables)
{
- return 0;
+ int *temp_int;
+ cGroupDefinition *temp;
+ cGroupDefinition *returndata;
+ int variable;
+ int group_num;
+
+ if((group_num = CCTK_GetGroupNum(implementation, name)) == -1)
+ {
+ /* Resize the array of groups */
+ if(temp = (cGroupDefinition *)realloc(groups, (n_groups+1)*sizeof(cGroupDefinition)))
+ {
+ groups = temp;
+
+ /* Allocate memory to various fields */
+ groups[n_groups].implementation = (char *)malloc((strlen(implementation)+1)*sizeof(char));
+
+ groups[n_groups].name = (char *)malloc((strlen(name)+1)*sizeof(char));
+
+ groups[n_groups].variables = (cVariableDefinition *)malloc(n_variables*sizeof(cVariableDefinition));
+
+ /* Resize the array holding correspondence between variables and groups. */
+
+ temp_int = (int *)realloc(group_of_variable, (total_variables+n_variables)*sizeof(int));
+
+ if(groups[n_groups].implementation &&
+ groups[n_groups].name &&
+ groups[n_groups].variables &&
+ temp_int)
+ {
+ /* Fill in the data structures. */
+ group_of_variable = temp_int;
+
+ strcpy(groups[n_groups].implementation, implementation);
+ strcpy(groups[n_groups].name, name);
+
+ groups[n_groups].number = n_groups;
+
+ groups[n_groups].n_variables = n_variables;
+
+ /* Fill in global variable numbers. */
+ for(variable = 0; variable < n_variables; variable++)
+ {
+ groups[n_groups].variables[variable].number = total_variables;
+
+ group_of_variable[total_variables] = n_groups;
+
+ total_variables++;
+ }
+
+ n_groups++;
+ }
+ else
+ {
+ /* Memory allocation failed, so free any which may have been allocated. */
+ free(groups[n_groups].implementation);
+ groups[n_groups].implementation = NULL;
+
+ free(groups[n_groups].name);
+ groups[n_groups].name = NULL;
+
+ free(groups[n_groups].variables);
+ groups[n_groups].variables = NULL;
+
+ }
+ }
+
+ /* Return the new group definition structure if successful, otherwise NULL.*/
+ if(temp && groups[n_groups-1].name)
+ {
+ returndata = &(groups[n_groups-1]);
+ }
+ else
+ {
+ returndata = NULL;
+ }
+ }
+ else
+ {
+ returndata = &(groups[group_num]);
+ }
+
+ return returndata;
}
-int CCTK_EnableGroupCommunication(cGH *GH, const char *group)
+ /*@@
+ @routine CCTK_GetGroupNumb
+ @date Fri Jan 29 08:43:48 1999
+ @author Tom Goodale
+ @desc
+ Gets the number for the specified group.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int CCTK_GetGroupNum(const char *implementation,
+ const char *name)
{
- return 0;
+ int group_num;
+
+ for(group_num = 0; group_num < n_groups; group_num++)
+ {
+ if(!strcmp(implementation, groups[group_num].implementation) &&
+ !strcmp(name, groups[group_num].name)) break;
+ }
+
+ if (group_num < n_groups)
+ {
+ return group_num;
+ }
+ else
+ {
+ return -1;
+ }
}
-int CCTK_DisableGroupCommunication(cGH *GH, const char *group)
+
+ /*@@
+ @routine CCTK_GetVarNum
+ @date Mon Feb 8 12:03:22 1999
+ @author Tom Goodale
+ @desc
+ Gets the global number associated wth a variable.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int CCTK_GetVarNum(const char *implementation,
+ const char *group_name,
+ const char *variable_name)
{
- return 0;
+ int retval;
+ int group_num;
+ int variable;
+
+ retval = -1;
+
+ group_num = CCTK_GetGroupNum(implementation, group_name);
+
+ if(group_num > -1)
+ {
+ for(variable=0; variable<groups[group_num].n_variables;variable++)
+ {
+ if(!strcmp(variable_name, groups[group_num].variables[variable].name))
+ {
+ retval = groups[group_num].variables[variable].number;
+ break;
+ }
+ }
+ }
+ else
+ {
+ retval = -2;
+ }
+
+ return retval;
}
-int CCTK_GetGroupNum(cGH *GH, const char *group)
+
+ /*@@
+ @routine CCTK_GetMaxDim
+ @date Mon Feb 8 12:04:01 1999
+ @author Tom Goodale
+ @desc
+ Gets the maximum dimesion of all groups.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int CCTK_GetMaxDim(void)
{
- return 0;
+ return maxdim;
}
+
+ /*@@
+ @routine CCTK_GetNumVars
+ @date Mon Feb 8 12:04:50 1999
+ @author Tom Goodale
+ @desc
+ Gets the total number of variables.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int CCTK_GetNumVars(void)
+{
+ return total_variables;
+}
+
+ /*@@
+ @routine CCTK_GetNumGroups
+ @date Mon Feb 8 12:04:50 1999
+ @author Tom Goodale
+ @desc
+ Gets the total number of groups.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int CCTK_GetNumGroups(void)
+{
+ return n_groups;
+}
+
+
+ /*@@
+ @routine CCTK_ArrayGroupSize
+ @date Mon Feb 8 12:05:50 1999
+ @author Tom Goodale
+ @desc
+ Gets the size of a array in a specific direction.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
int CCTK_ArrayGroupSize(cGH *GH, const char *group, int dim)
{
return 0;
}
+
+ /*@@
+ @routine CCTK_GTypeNumber
+ @date Mon Feb 8 14:44:45 1999
+ @author Tom Goodale
+ @desc
+ Gets the type number associated with a group.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int CCTK_GTypeNumber(const char *type)
+{
+ int retval;
+
+ if(!strcmp(type, "SCALAR"))
+ {
+ retval = GROUP_SCALAR;
+ }
+
+ if(!strcmp(type, "GF"))
+ {
+ retval = GROUP_GF;
+ }
+
+ if(!strcmp(type, "ARRAY"))
+ {
+ retval = GROUP_ARRAY;
+ }
+
+ return retval;
+}
+
+ /*@@
+ @routine CCTK_VTypeNumber
+ @date Mon Feb 8 14:44:45 1999
+ @author Tom Goodale
+ @desc
+ Gets the type number associated with a variable.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int CCTK_VTypeNumber(const char *type)
+{
+ int retval;
+
+ if(!strcmp(type, "INTEGER"))
+ {
+ retval = VARIABLE_INTEGER;
+ }
+
+ if(!strcmp(type, "REAL"))
+ {
+ retval = VARIABLE_REAL;
+ }
+
+ if(!strcmp(type, "COMPLEX"))
+ {
+ retval = VARIABLE_COMPLEX;
+ }
+
+ if(!strcmp(type, "CHAR"))
+ {
+ retval = VARIABLE_CHAR;
+ }
+
+ return retval;
+}