aboutsummaryrefslogtreecommitdiff
path: root/src/SetupGroup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/SetupGroup.c')
-rw-r--r--src/SetupGroup.c162
1 files changed, 16 insertions, 146 deletions
diff --git a/src/SetupGroup.c b/src/SetupGroup.c
index 346da2a..1e91bc4 100644
--- a/src/SetupGroup.c
+++ b/src/SetupGroup.c
@@ -8,6 +8,7 @@
@version $Id$
@@*/
+#include <assert.h>
#include <stdlib.h>
#include <string.h>
@@ -23,12 +24,6 @@ CCTK_FILEVERSION (CactusPUGH_PUGH_SetupGroup_c)
/********************************************************************
******************** Internal Routines ************************
********************************************************************/
-static int PUGH_SetupScalarGroup (pGH *newGH,
- int vtype,
- int n_variables,
- int n_timelevels,
- int vectorgroup);
-
static int PUGH_SetupGAGroup (pGH *newGH,
int *nsize,
int *ghostsize,
@@ -36,124 +31,10 @@ static int PUGH_SetupGAGroup (pGH *newGH,
int vtype,
int dim,
int n_variables,
+ int vectorlength,
int staggercode,
int n_timelevels,
- int vectorgroup);
-
-
- /*@@
- @routine PUGH_SetupScalarGroup
- @date Wed Feb 17 04:45:49 1999
- @author Tom Goodale
- @desc
- Set up a group of scalar variables on a pGH.
- For efficiency reasons, PUGH allocates storage for scalars
- only once when the group is created.
- The current state of storage allocation (which is toggled by
- Enable/DisableGroupStorage) is stored in a byte-sized flag
- immediately after the scalar data.
- @enddesc
-
- @var newGH
- @vdesc Pointer to PUGH grid hierarchy
- @vtype pGH *
- @vio in
- @endvar
- @var vtype
- @vdesc CCTK data type for variables in this group
- @vtype int
- @vio in
- @endvar
- @var n_variables
- @vdesc number of variables in this group
- @vtype int
- @vio in
- @endvar
- @var n_timelevels
- @vdesc number of timelevels in this group
- @vtype int
- @vio in
- @endvar
- @var vectorgroup
- @vdesc is this a vector group ?
- @vtype int
- @vio in
- @endvar
-
- @returntype int
- @returndesc
- PUGH_SUCCESS (0) if successful, or
- PUGH_ERRORMEMORY (negative) if memory allocation failed
- @endreturndesc
-@@*/
-static int PUGH_SetupScalarGroup (pGH *newGH,
- int vtype,
- int n_variables,
- int n_timelevels,
- int vectorgroup)
-{
- DECLARE_CCTK_PARAMETERS
- int variable, level, vtypesize, retval;
- void *temp;
-
-
- (void) (vectorgroup + 0);
-
- retval = 0; /* PUGH_SUCCESS */
-
- temp = realloc (newGH->variables,
- (newGH->nvariables + n_variables) * sizeof (void **));
- if (temp)
- {
- newGH->variables = (void ***) temp;
- vtypesize = CCTK_VarTypeSize (vtype);
-
- for (variable = 0; variable < n_variables && retval == 0; variable++)
- {
- temp = malloc (n_timelevels * sizeof (void *));
- if (temp)
- {
- newGH->variables[newGH->nvariables + variable] = (void **) temp;
- for (level = 0; level < n_timelevels; level++)
- {
- /* allocate one more byte for the query_storage flag */
- temp = malloc (vtypesize + 1);
- if (temp)
- {
- newGH->variables[newGH->nvariables + variable][level] = temp;
-
- /* reset the query_storage flag */
- ((char *) temp)[vtypesize] = PUGH_NOSTORAGE;
- }
- else
- {
- retval = PUGH_ERRORMEMORY;
- break;
- }
- }
- }
- else
- {
- retval = PUGH_ERRORMEMORY;
- }
- }
- }
- else
- {
- retval = PUGH_ERRORMEMORY;
- }
-
- if (! retval)
- {
- newGH->nvariables += n_variables;
- }
- else
- {
- CCTK_WARN (1, "Memory allocation error in PUGH_SetupScalarGroup");
- }
-
- return (retval);
-}
+ int vectorgroup);
/*@@
@@ -161,8 +42,7 @@ static int PUGH_SetupScalarGroup (pGH *newGH,
@date January 19 2000
@author Gabrielle Allen
@desc
- Set up a group of grid array variables (CCTK_GF or CCTK_ARRAY
- types) on a pGH.
+ Set up a group of grid array variables on a pGH.
@enddesc
@calls CCTK_VarTypeSize
PUGH_SetupConnectivity
@@ -234,6 +114,7 @@ static int PUGH_SetupGAGroup (pGH *newGH,
int vtype,
int dim,
int n_variables,
+ int vectorlength,
int staggercode,
int n_timelevels,
int vectorgroup)
@@ -254,7 +135,7 @@ static int PUGH_SetupGAGroup (pGH *newGH,
retval = PUGH_SUCCESS;
var_size = CCTK_VarTypeSize (vtype);
- if (gtype == CCTK_ARRAY)
+ if (gtype == CCTK_ARRAY || gtype == CCTK_SCALAR)
{
/* Arrays can't (yet) have periodicity and manual setup,
so initialize them to zero */
@@ -293,6 +174,7 @@ static int PUGH_SetupGAGroup (pGH *newGH,
else
{
/* this is for CCTK_GF variables */
+ assert (dim > 0);
connectivity = newGH->Connectivity[dim-1];
extras = newGH->GFExtras[dim-1];
}
@@ -341,9 +223,9 @@ static int PUGH_SetupGAGroup (pGH *newGH,
var_size,
vtype,
staggercode,
- vectorgroup ? n_variables : 1,
- variable,
- variable > 0 ? newGH->variables[newGH->nvariables-variable][level] : NULL);
+ vectorlength,
+ variable%vectorlength,
+ variable%vectorlength > 0 ? newGH->variables[newGH->nvariables-variable%vectorlength][level] : NULL);
newGH->narrays++;
}
newGH->nvariables++;
@@ -376,8 +258,7 @@ static int PUGH_SetupGAGroup (pGH *newGH,
@desc
Sets up a group on a pGH
@enddesc
- @calls PUGH_SetupScalarGroup
- PUGH_SetupGAGroup
+ @calls PUGH_SetupGAGroup
@var newGH
@vdesc Pointer to PUGH grid hierarchy
@@ -432,8 +313,7 @@ static int PUGH_SetupGAGroup (pGH *newGH,
@returntype int
@returndesc
- return code of @seeroutine PUGH_SetupScalarGroup or
- @seeroutine PUGH_SetupGAGroup, or
+ return code of @seeroutine PUGH_SetupGAGroup, or
PUGH_ERROR if invalid group type was passed in
@endreturndesc
@@*/
@@ -444,26 +324,16 @@ int PUGH_SetupGroup (pGH *newGH,
int vtype,
int dim,
int n_variables,
+ int vectorlength,
int staggercode,
int n_timelevels,
int vectorgroup)
{
int retval;
- if (gtype == CCTK_SCALAR)
- {
- retval = PUGH_SetupScalarGroup (newGH, vtype, n_variables, n_timelevels, vectorgroup);
- }
- else if (gtype == CCTK_ARRAY || gtype == CCTK_GF)
- {
- retval = PUGH_SetupGAGroup (newGH, nsize, nghostsize, gtype, vtype, dim,
- n_variables, staggercode, n_timelevels,vectorgroup);
- }
- else
- {
- CCTK_WARN (0, "Unknown group type in PUGH_SetupGroup");
- retval = PUGH_ERROR;
- }
+ retval = PUGH_SetupGAGroup (newGH, nsize, nghostsize, gtype, vtype, dim,
+ n_variables, vectorlength, staggercode,
+ n_timelevels, vectorgroup);
return (retval);
}