/*@@ @routine PUGH_DestroyPGH @date Thu Aug 21 11:38:10 1997 @author Paul Walker @desc Destroys a GH object. @enddesc @var GHin @vdesc address of PUGH GH extensions object to be destroyed @vtype pGH ** @vio in @endvar @@*/ void PUGH_DestroyPGH (pGH **GHin) { pGH *GH; pGA *GA; cGroup pgroup; int i; int variable; int group; int this_var; GH = *GHin; #ifdef CCTK_MPI CACTUS_MPI_ERROR (MPI_Comm_free (&GH->PUGH_COMM_WORLD)); CACTUS_MPI_ERROR (MPI_Type_free (&GH->PUGH_mpi_complex)); #ifdef CCTK_REAL4 CACTUS_MPI_ERROR (MPI_Type_free (&GH->PUGH_mpi_complex8)); #endif #ifdef CCTK_REAL8 CACTUS_MPI_ERROR (MPI_Type_free (&GH->PUGH_mpi_complex16)); #endif #ifdef CCTK_REAL16 CACTUS_MPI_ERROR (MPI_Type_free (&GH->PUGH_mpi_complex32)); #endif #endif /* Great. Now go about the work of destroying me. */ variable = 0; for(group = 0; group < CCTK_NumGroups(); group++) { #ifdef DEBUG_PUGH printf("Calling Destroying Group %s\n", CCTK_GroupName(group)); fflush(stdout); #endif CCTK_GroupData(group,&pgroup); if (pgroup.grouptype == CCTK_ARRAY || pgroup.grouptype == CCTK_GF) { GA = (pGA *) GH->variables[variable][0]; /* Destroy group comm buffers */ if (GA->groupcomm) { if (GA->groupcomm->commflag != PUGH_NOCOMM) { PUGH_DisableGArrayGroupComm (GH, variable, GA->groupcomm); } PUGH_DestroyComm (&GA->groupcomm); } /* Destroy the group's connectivity and extras structure for CCTK_ARRAY groups. Remember that the connectivity and extras for CCTK_GF types are shared between all such groups and are destroyed later. */ if (GA->connectivity != GH->Connectivity[pgroup.dim-1]) { PUGH_DestroyConnectivity (&GA->connectivity); } if (GA->extras != GH->GFExtras[pgroup.dim-1]) { PUGH_DestroyPGExtras (&GA->extras); } } for (this_var = 0; this_var < pgroup.numvars; this_var++, variable++) { for(i = 0 ; i < pgroup.numtimelevels; i++) { switch(pgroup.grouptype) { case CCTK_GF: case CCTK_ARRAY: PUGH_DestroyGArray(&(((pGA ***)GH->variables)[variable][i])); break; case CCTK_SCALAR: if (GH->variables[variable][i]) { free(GH->variables[variable][i]); } break; } } free(GH->variables[variable]); } } for (i=1;i<=GH->dim;i++) { PUGH_DestroyConnectivity(&GH->Connectivity[i-1]); PUGH_DestroyPGExtras(&GH->GFExtras[i-1]); } if(GH->identity_string) { free(GH->identity_string); } free(GH->Connectivity); free(GH->GFExtras); free(GH->variables); free(GH); *GHin = NULL; }
/*@@ @routine CactusDefaultSetupGH @date Tue Sep 29 15:06:22 1998 @author Tom Goodale @desc Default cactus SetupGH routine. @enddesc @calls CCTK_MaxDim CCTK_NumVars CCTK_NumTimeLevelsFromVarI CCTK_NumGroups CCTKi_SetupGHExtensions @var config @vdesc Pointer to flesh configuration environment @vtype tFleshConfig * @vio in @endvar @var convergence_level @vdesc convergence leve of new cGH @vtype int @vio in @endvar @returntype cGH * @returndesc the pointer to the new cGH structure, or NULL if memory allocation failed @endreturndesc @@*/ cGH *CactusDefaultSetupGH(tFleshConfig *config, int convergence_level) { cGH *thisGH; int n_groups; int n_variables; int variable; int ntimelevels; int cctk_dim; /* Put this in for the moment until parameter stuff is done. */ if(convergence_level > 0) { return (NULL); } /* Initialise this since it is used later and in exceptional * circumstances might not be initialsed beforehand. */ variable = -1; /* Create a new Grid Hierarchy */ thisGH = (cGH *)malloc(sizeof(cGH)); if(thisGH) { thisGH->cctk_dim = CCTK_MaxDim(); /* Need this to be at least one otherwise the memory allocation will fail. */ cctk_dim = thisGH->cctk_dim; if(thisGH->cctk_dim == 0) cctk_dim = 1; thisGH->cctk_iteration = 0; thisGH->cctk_gsh = (int *)malloc(cctk_dim*sizeof(int)); thisGH->cctk_lsh = (int *)malloc(cctk_dim*sizeof(int)); thisGH->cctk_lbnd = (int *)malloc(cctk_dim*sizeof(int)); thisGH->cctk_ubnd = (int *)malloc(cctk_dim*sizeof(int)); thisGH->cctk_lssh = (int *)malloc(CCTK_NSTAGGER*cctk_dim*sizeof(int)); thisGH->cctk_to = (int *)malloc(cctk_dim*sizeof(int)); thisGH->cctk_from = (int *)malloc(cctk_dim*sizeof(int)); thisGH->cctk_bbox = (int *)malloc(2*cctk_dim*sizeof(int)); thisGH->cctk_nghostzones = (int *)malloc(2*cctk_dim*sizeof(int)); thisGH->cctk_levfac = (int *)malloc(cctk_dim*sizeof(int)); thisGH->cctk_delta_space = (CCTK_REAL *)malloc(cctk_dim*sizeof(CCTK_REAL)); /* FIXME : Next line goes when coords are done properly */ thisGH->cctk_origin_space = (CCTK_REAL *)malloc(cctk_dim*sizeof(CCTK_REAL)); thisGH->cctk_delta_time = 1; thisGH->cctk_convlevel = 0; n_variables = CCTK_NumVars(); /* Allocate memory for the variable data pointers. * Note we want at least one to prevent memory allocattion from failing ! */ thisGH->data = (void ***)malloc((n_variables ? n_variables:1)*sizeof(void **)); if(thisGH->data) { for(variable = 0; variable < n_variables; variable++) { ntimelevels = CCTK_NumTimeLevelsFromVarI(variable); thisGH->data[variable] = (void **)calloc(ntimelevels, sizeof(void *)); if(thisGH->data[variable] == NULL) { break; } } } thisGH->extensions = NULL; /* Allocate memory for the group data pointers. * Note we want at least one to prevent memory allocattion from failing ! */ n_groups = CCTK_NumGroups(); thisGH->GroupData = (cGHGroupData *)malloc((n_groups ? n_groups:1)*sizeof(cGHGroupData)); } if(thisGH && thisGH->cctk_gsh && thisGH->cctk_lsh && thisGH->cctk_lbnd && thisGH->cctk_ubnd && thisGH->cctk_lssh && thisGH->cctk_from && thisGH->cctk_to && thisGH->cctk_bbox && thisGH->cctk_nghostzones && thisGH->cctk_levfac && thisGH->cctk_delta_space && thisGH->cctk_origin_space && thisGH->data && variable == n_variables && thisGH->GroupData) { /* Traverse list of GH setup routines. */ CCTKi_SetupGHExtensions(config, convergence_level, thisGH); } else { /* FIXME: should free potentially allocated memory for this GH */ thisGH = NULL; } return (thisGH); }