/*@@ @file InitialCopy.c @date Sun May 26 04:43:06 2002 @author Ian Hawke @desc Performs the initial copy from the previous timelevel to the current. This is required because the driver has rotated the timelevels, but the physics thorns are expecting data in the current. @enddesc @version $Header$ @@*/ #include "cctk.h" #include "cctk_Arguments.h" #include "cctk_Parameters.h" #include "ExternalVariables.h" static const char *rcsid = "$Header$"; CCTK_FILEVERSION(AlphaThorns_MoL_InitialCopy_c); /******************************************************************** ********************* Local Data Types *********************** ********************************************************************/ /******************************************************************** ********************* Local Routine Prototypes ********************* ********************************************************************/ /******************************************************************** ***************** Scheduled Routine Prototypes ********************* ********************************************************************/ void MoL_InitialCopy(CCTK_ARGUMENTS); void MoL_FillAllLevels(CCTK_ARGUMENTS); /******************************************************************** ********************* Other Routine Prototypes ********************* ********************************************************************/ /******************************************************************** ********************* Local Data ***************************** ********************************************************************/ /******************************************************************** ********************* External Routines ********************** ********************************************************************/ void MoL_InitialCopy(CCTK_ARGUMENTS) { DECLARE_CCTK_ARGUMENTS DECLARE_CCTK_PARAMETERS CCTK_INT var; CCTK_INT index; CCTK_INT i,j,k; CCTK_INT totalsize; CCTK_REAL *CurrentVar; CCTK_REAL *PreviousVar; CCTK_REAL *ScratchVar; CCTK_INT StorageOn; totalsize = cctk_lsh[0]*cctk_lsh[1]*cctk_lsh[2]; for (var = 0; var < MoLNumEvolvedVariables; var++) { StorageOn = CCTK_QueryGroupStorage(cctkGH, CCTK_GroupNameFromVarI(EvolvedVariableIndex[var])); if (StorageOn < 0) { CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for index %i", EvolvedVariableIndex[var]); CCTK_WARN(0, "The index passed does not correspond to a GF."); } else if (StorageOn == 0) { CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for GF %s", CCTK_VarName(EvolvedVariableIndex[var])); CCTK_WARN(0, "The grid function does not have storage assigned."); } PreviousVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 1, EvolvedVariableIndex[var]); CurrentVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 0, EvolvedVariableIndex[var]); if (PreviousVar && CurrentVar) { memcpy(CurrentVar, PreviousVar, totalsize * sizeof(CCTK_REAL)); } else { CCTK_VWarn(0,__LINE__,__FILE__,"MoL","Null pointer for variable %s", CCTK_VarName(EvolvedVariableIndex[var])); } } /* Now the Save and Restore variables. Shift the data in the current level to the scratch space, then do the copy */ for (var = 0; var < MoLNumSandRVariables; var++) { StorageOn = CCTK_QueryGroupStorage(cctkGH, CCTK_GroupNameFromVarI(SandRVariableIndex[var])); if (StorageOn < 0) { CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for index %i", SandRVariableIndex[var]); CCTK_WARN(0, "The index passed does not correspond to a GF."); } else if (StorageOn == 0) { CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for GF %s", CCTK_VarName(SandRVariableIndex[var])); CCTK_WARN(0, "The grid function does not have storage assigned."); } PreviousVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 1, SandRVariableIndex[var]); CurrentVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 0, SandRVariableIndex[var]); ScratchVar = &SandRScratchSpace[var*totalsize]; #ifdef MOLDEBUG printf("Pointers for the SandR vars are to %ld, %ld and %ld.\n", PreviousVar, CurrentVar, ScratchVar); printf("Init1:Variable %s, current %g, previous %g, scratch %g\n", CCTK_VarName(SandRVariableIndex[var]), CurrentVar[0], PreviousVar[0], ScratchVar[0]); #endif if (PreviousVar && CurrentVar && ScratchVar) { memcpy(ScratchVar, CurrentVar, totalsize * sizeof(CCTK_REAL)); memcpy(CurrentVar, PreviousVar, totalsize * sizeof(CCTK_REAL)); } else { CCTK_VWarn(0,__LINE__,__FILE__,"MoL","Null pointer for variable %s", CCTK_VarName(SandRScratchSpace[var])); } #ifdef MOLDEBUG printf("Init2:Variable %s, current %g, previous %g, scratch %g\n", CCTK_VarName(SandRVariableIndex[var]), CurrentVar[0], PreviousVar[0], ScratchVar[0]); #endif } /* Now do the constrained variables. */ for (var = 0; var < MoLNumConstrainedVariables; var++) { StorageOn = CCTK_QueryGroupStorage(cctkGH, CCTK_GroupNameFromVarI(ConstrainedVariableIndex[var])); if (StorageOn < 0) { CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for index %i", ConstrainedVariableIndex[var]); CCTK_WARN(0, "The index passed does not correspond to a GF."); } else if (StorageOn == 0) { CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for GF %s", CCTK_VarName(ConstrainedVariableIndex[var])); CCTK_WARN(0, "The grid function does not have storage assigned."); } PreviousVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 1, ConstrainedVariableIndex[var]); CurrentVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 0, ConstrainedVariableIndex[var]); if (PreviousVar && CurrentVar) { memcpy(CurrentVar, PreviousVar, totalsize * sizeof(CCTK_REAL)); } else { CCTK_VWarn(0,__LINE__,__FILE__,"MoL","Null pointer for variable %s", CCTK_VarName(ConstrainedVariableIndex[var])); } } return; } /*@@ @routine MoL_FillAllLevels @date Fri Apr 25 16:11:18 2003 @author Ian Hawke @desc This routine is a bit of a hack, and I'm still not convinced it is really necessary. It fills the previous timelevels by copying the data from the current timelevels, which should have been set up during the CCTK_INITIAL timebin. It also prints some useful information about the number of registered functions. @enddesc @calls @calledby @history @endhistory @@*/ void MoL_FillAllLevels(CCTK_ARGUMENTS) { DECLARE_CCTK_ARGUMENTS DECLARE_CCTK_PARAMETERS CCTK_INT var, level; CCTK_INT totalsize; CCTK_REAL *CurrentVar; CCTK_REAL *PreviousVar; totalsize = cctk_lsh[0]*cctk_lsh[1]*cctk_lsh[2]; for (var = 0; var < MoLNumEvolvedVariables; var++) { CurrentVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 0, EvolvedVariableIndex[var]); for (level = 1; level < CCTK_NumTimeLevelsFromVarI(EvolvedVariableIndex[var]); level++) { PreviousVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, level, EvolvedVariableIndex[var]); if (PreviousVar) { memcpy(PreviousVar, CurrentVar, totalsize * sizeof(CCTK_REAL)); } } } for (var = 0; var < MoLNumConstrainedVariables; var++) { CurrentVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 0, ConstrainedVariableIndex[var]); for (level = 1; level < CCTK_QueryGroupStorage(cctkGH, CCTK_GroupNameFromVarI(ConstrainedVariableIndex[var])); level++) { PreviousVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, level, ConstrainedVariableIndex[var]); if (PreviousVar) { memcpy(CurrentVar, PreviousVar, totalsize * sizeof(CCTK_REAL)); } } } for (var = 0; var < MoLNumSandRVariables; var++) { CurrentVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 0, SandRVariableIndex[var]); for (level = 1; level < CCTK_QueryGroupStorage(cctkGH, CCTK_GroupNameFromVarI(SandRVariableIndex[var])); level++) { PreviousVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, level, SandRVariableIndex[var]); if (PreviousVar) { memcpy(CurrentVar, PreviousVar, totalsize * sizeof(CCTK_REAL)); } } } CCTK_VInfo(CCTK_THORNSTRING, "The maximum number of evolved variables is %d. %d are registered", MoL_Num_Evolved_Vars,MoLNumEvolvedVariables); CCTK_VInfo(CCTK_THORNSTRING, "The maximum number of constrained variables is %d. %d are registered", MoL_Num_Constrained_Vars,MoLNumConstrainedVariables); CCTK_VInfo(CCTK_THORNSTRING, "The maximum number of SandR variables is %d. %d are registered", MoL_Num_SaveAndRestore_Vars,MoLNumSandRVariables); return; } /******************************************************************** ********************* Local Routines ************************* ********************************************************************/