diff options
author | hawke <hawke@578cdeb0-5ea1-4b81-8215-5a3b8777ee0b> | 2003-05-21 09:12:14 +0000 |
---|---|---|
committer | hawke <hawke@578cdeb0-5ea1-4b81-8215-5a3b8777ee0b> | 2003-05-21 09:12:14 +0000 |
commit | f3a2829b5b32b6fad8383ac16c16ac6c2f58b696 (patch) | |
tree | 19a58318d2bcb7f95ecf044e5713453d9bff0bea /src | |
parent | 7e9dff2f70bd9950b27092e816f9a3cc14ff3582 (diff) |
Add support for evolving complex GFs and (real and complex) GAs.
Only works with ICN or RK2 for now - in fact this commit may break the generic RK methods temporarily.
Note the documentation isn't quite right - there's no longer a seperate function for each different type...
git-svn-id: http://svn.cactuscode.org/arrangements/CactusNumerical/MoL/trunk@12 578cdeb0-5ea1-4b81-8215-5a3b8777ee0b
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeType.c | 125 | ||||
-rw-r--r-- | src/Counter.c | 2 | ||||
-rw-r--r-- | src/ExternalVariables.h | 37 | ||||
-rw-r--r-- | src/GenericRK.c | 185 | ||||
-rw-r--r-- | src/ICN.c | 56 | ||||
-rw-r--r-- | src/IndexArrays.c | 178 | ||||
-rw-r--r-- | src/InitialCopy.c | 211 | ||||
-rw-r--r-- | src/ParamCheck.c | 2 | ||||
-rw-r--r-- | src/RK2.c | 100 | ||||
-rw-r--r-- | src/Registration.c | 1893 | ||||
-rw-r--r-- | src/SandR.c | 17 | ||||
-rw-r--r-- | src/SetTime.c | 2 | ||||
-rw-r--r-- | src/Startup.c | 30 |
13 files changed, 2816 insertions, 22 deletions
diff --git a/src/ChangeType.c b/src/ChangeType.c index 5e229b4..966445e 100644 --- a/src/ChangeType.c +++ b/src/ChangeType.c @@ -47,6 +47,34 @@ CCTK_INT MoL_ChangeToSaveAndRestore(CCTK_INT SandRIndex); CCTK_INT MoL_ChangeToNone(CCTK_INT RemoveIndex); + +CCTK_INT MoL_ChangeToEvolvedComplex(CCTK_INT EvolvedIndex, CCTK_INT RHSIndex); + +CCTK_INT MoL_ChangeToConstrainedComplex(CCTK_INT ConstrainedIndex); + +CCTK_INT MoL_ChangeToSaveAndRestoreComplex(CCTK_INT SandRIndex); + +CCTK_INT MoL_ChangeToNoneComplex(CCTK_INT RemoveIndex); + + +CCTK_INT MoL_ChangeToEvolvedArray(CCTK_INT EvolvedIndex, CCTK_INT RHSIndex); + +CCTK_INT MoL_ChangeToConstrainedArray(CCTK_INT ConstrainedIndex); + +CCTK_INT MoL_ChangeToSaveAndRestoreArray(CCTK_INT SandRIndex); + +CCTK_INT MoL_ChangeToNoneArray(CCTK_INT RemoveIndex); + + +CCTK_INT MoL_ChangeToEvolvedComplexArray(CCTK_INT EvolvedIndex, + CCTK_INT RHSIndex); + +CCTK_INT MoL_ChangeToConstrainedComplexArray(CCTK_INT ConstrainedIndex); + +CCTK_INT MoL_ChangeToSaveAndRestoreComplexArray(CCTK_INT SandRIndex); + +CCTK_INT MoL_ChangeToNoneComplexArray(CCTK_INT RemoveIndex); + /******************************************************************** ********************* Local Data ***************************** ********************************************************************/ @@ -441,7 +469,7 @@ CCTK_INT MoL_ChangeToNone(CCTK_INT RemoveIndex) CCTK_INT index, usedindex; CCTK_INT vartype; /* See the defines at the top of file */ - CCTK_INT timelevs; +/* CCTK_INT timelevs; */ vartype = 0; usedindex = -1; @@ -531,13 +559,107 @@ CCTK_INT MoL_ChangeToNone(CCTK_INT RemoveIndex) } +/* + Currently no-op test functions. +*/ + + +CCTK_INT MoL_ChangeToEvolvedComplex(CCTK_INT EvolvedIndex, CCTK_INT RHSIndex) +{ + CCTK_INT dummy; + dummy = EvolvedIndex; + dummy = RHSIndex; + return 0; +} + +CCTK_INT MoL_ChangeToConstrainedComplex(CCTK_INT ConstrainedIndex) +{ + CCTK_INT dummy; + dummy = ConstrainedIndex; + return 0; +} + +CCTK_INT MoL_ChangeToSaveAndRestoreComplex(CCTK_INT SandRIndex) +{ + CCTK_INT dummy; + dummy = SandRIndex; + return 0; +} + +CCTK_INT MoL_ChangeToNoneComplex(CCTK_INT RemoveIndex) +{ + CCTK_INT dummy; + dummy = RemoveIndex; + return 0; +} + + +CCTK_INT MoL_ChangeToEvolvedArray(CCTK_INT EvolvedIndex, CCTK_INT RHSIndex) +{ + CCTK_INT dummy; + dummy = EvolvedIndex; + dummy = RHSIndex; + return 0; +} + +CCTK_INT MoL_ChangeToConstrainedArray(CCTK_INT ConstrainedIndex) +{ + CCTK_INT dummy; + dummy = ConstrainedIndex; + return 0; +} + +CCTK_INT MoL_ChangeToSaveAndRestoreArray(CCTK_INT SandRIndex) +{ + CCTK_INT dummy; + dummy = SandRIndex; + return 0; +} + +CCTK_INT MoL_ChangeToNoneArray(CCTK_INT RemoveIndex) +{ + CCTK_INT dummy; + dummy = RemoveIndex; + return 0; +} +CCTK_INT MoL_ChangeToEvolvedComplexArray(CCTK_INT EvolvedIndex, + CCTK_INT RHSIndex) +{ + CCTK_INT dummy; + dummy = EvolvedIndex; + dummy = RHSIndex; + return 0; +} + +CCTK_INT MoL_ChangeToConstrainedComplexArray(CCTK_INT ConstrainedIndex) +{ + CCTK_INT dummy; + dummy = ConstrainedIndex; + return 0; +} + +CCTK_INT MoL_ChangeToSaveAndRestoreComplexArray(CCTK_INT SandRIndex) +{ + CCTK_INT dummy; + dummy = SandRIndex; + return 0; +} + +CCTK_INT MoL_ChangeToNoneComplexArray(CCTK_INT RemoveIndex) +{ + CCTK_INT dummy; + dummy = RemoveIndex; + return 0; +} + /* Fortran wrappers for the above functions. Should be replaced by using function aliasing eventually. */ +/* void CCTK_FCALL CCTK_FNAME(MoL_ChangeToEvolved)(int *ierr, CCTK_INT *EvolvedIndex, CCTK_INT *RHSIndex) @@ -566,6 +688,7 @@ void CCTK_FCALL CCTK_FNAME(MoL_ChangeToNone)(int *ierr, *ierr = MoL_ChangeToNone(*EvolvedIndex); return; } +*/ /******************************************************************** ********************* Local Routines ************************* diff --git a/src/Counter.c b/src/Counter.c index fca7f58..72ca776 100644 --- a/src/Counter.c +++ b/src/Counter.c @@ -65,7 +65,7 @@ int MoL_SetCounter(CCTK_ARGUMENTS) DECLARE_CCTK_ARGUMENTS; DECLARE_CCTK_PARAMETERS; - CCTK_REAL *Var; +/* CCTK_REAL *Var; */ *MoL_Intermediate_Step = MoL_Intermediate_Steps; diff --git a/src/ExternalVariables.h b/src/ExternalVariables.h index db4ea8f..229c6bb 100644 --- a/src/ExternalVariables.h +++ b/src/ExternalVariables.h @@ -24,3 +24,40 @@ extern CCTK_INT *SandRVariableIndex; extern CCTK_INT MoLNumEvolvedVariables; extern CCTK_INT MoLNumConstrainedVariables; extern CCTK_INT MoLNumSandRVariables; + + + +extern CCTK_INT *EvolvedComplexVariableIndex; +extern CCTK_INT *RHSComplexVariableIndex; +extern CCTK_INT *ConstrainedComplexVariableIndex; +extern CCTK_INT *SandRComplexVariableIndex; + + +extern CCTK_INT MoLNumEvolvedComplexVariables; +extern CCTK_INT MoLNumConstrainedComplexVariables; +extern CCTK_INT MoLNumSandRComplexVariables; + + + +extern CCTK_INT *EvolvedArrayVariableIndex; +extern CCTK_INT *RHSArrayVariableIndex; +extern CCTK_INT *ConstrainedArrayVariableIndex; +extern CCTK_INT *SandRArrayVariableIndex; + + +extern CCTK_INT MoLNumEvolvedArrayVariables; +extern CCTK_INT MoLNumConstrainedArrayVariables; +extern CCTK_INT MoLNumSandRArrayVariables; + + + +extern CCTK_INT *EvolvedComplexArrayVariableIndex; +extern CCTK_INT *RHSComplexArrayVariableIndex; +extern CCTK_INT *ConstrainedComplexArrayVariableIndex; +extern CCTK_INT *SandRComplexArrayVariableIndex; + + +extern CCTK_INT MoLNumEvolvedComplexArrayVariables; +extern CCTK_INT MoLNumConstrainedComplexArrayVariables; +extern CCTK_INT MoLNumSandRComplexArrayVariables; + diff --git a/src/GenericRK.c b/src/GenericRK.c index 939faa3..d1e3bc8 100644 --- a/src/GenericRK.c +++ b/src/GenericRK.c @@ -70,7 +70,16 @@ void MoL_GenericRKAdd(CCTK_ARGUMENTS) DECLARE_CCTK_ARGUMENTS; DECLARE_CCTK_PARAMETERS; - + + cGroupDynamicData arraydata; + CCTK_INT groupindex, ierr; + CCTK_INT arraytotalsize, arraydim; + + CCTK_COMPLEX Complex_alpha, Complex_beta, Complex_Delta_Time; + CCTK_COMPLEX *UpdateComplexVar; + CCTK_COMPLEX *RHSComplexVar; + CCTK_COMPLEX *ScratchComplexVar; + CCTK_INT index, var, scratchstep, alphaindex, scratchindex; CCTK_INT totalsize; CCTK_REAL alpha, beta; @@ -80,8 +89,13 @@ void MoL_GenericRKAdd(CCTK_ARGUMENTS) totalsize = cctk_lsh[0] * cctk_lsh[1] * cctk_lsh[2]; + Complex_Delta_Time = CCTK_Cmplx((*Original_Delta_Time), 0); + beta = RKBetaCoefficients[MoL_Intermediate_Steps - (*MoL_Intermediate_Step)]; + Complex_beta = CCTK_Cmplx(beta, 0); + + /* Real GFs */ for (var = 0; var < MoLNumEvolvedVariables; var++) { @@ -176,6 +190,175 @@ void MoL_GenericRKAdd(CCTK_ARGUMENTS) } } } + + /* Complex GFs */ + + for (var = 0; var < MoLNumEvolvedComplexVariables; var++) + { + + UpdateComplexVar = (CCTK_COMPLEX *)CCTK_VarDataPtrI(cctkGH, 0, + EvolvedComplexVariableIndex[var]); + RHSComplexVar = (CCTK_COMPLEX *)CCTK_VarDataPtrI(cctkGH, 0, + RHSVariableIndex[var]); + + for (index = 0; index < totalsize; index++) + { + UpdateComplexVar[index] = CCTK_CmplxMul(Complex_Delta_Time, + CCTK_CmplxMul(Complex_beta, RHSComplexVar[index])); + } + + for (scratchstep = 0; + scratchstep < MoL_Intermediate_Steps - (*MoL_Intermediate_Step) + 1; + scratchstep++) + { + + alphaindex = AlphaIndex(*MoL_Intermediate_Step, scratchstep); + scratchindex = scratchstep - 1; + + alpha = RKAlphaCoefficients[alphaindex]; + Complex_alpha = CCTK_Cmplx(alpha, 0); + + if (scratchstep) + { + ScratchComplexVar = &ComplexScratchSpace[(var * + MoL_Num_Scratch_Levels + + scratchindex) * totalsize]; + } + else + { + ScratchComplexVar = (CCTK_COMPLEX*)CCTK_VarDataPtrI(cctkGH, 1, + EvolvedComplexVariableIndex[var]); + } + + if ( (alpha > MoL_Tiny)||(alpha < -MoL_Tiny) ) + { + for (index = 0; index < totalsize; index++) + { + UpdateComplexVar[index] = + CCTK_CmplxAdd(UpdateComplexVar[index], + CCTK_CmplxMul(Complex_alpha, + ScratchComplexVar[index])); + } + } + + } + + } + + if (*MoL_Intermediate_Step > 1) + { + for (var = 0; var < MoLNumEvolvedComplexVariables; var++) + { + UpdateComplexVar = (CCTK_COMPLEX *)CCTK_VarDataPtrI(cctkGH, 0, + EvolvedComplexVariableIndex[var]); + ScratchComplexVar = &ComplexScratchSpace[(var * MoL_Num_Scratch_Levels + + MoL_Intermediate_Steps - + (*MoL_Intermediate_Step)) * + totalsize]; + for (index = 0; index < totalsize; index++) + { + ScratchComplexVar[index] = UpdateComplexVar[index]; + } + } + } + + /* Real arrays */ + + for (var = 0; var < MoLNumEvolvedArrayVariables; var++) + { + + UpdateVar = (CCTK_REAL *)CCTK_VarDataPtrI(cctkGH, 0, + EvolvedArrayVariableIndex[var]); + RHSVar = (CCTK_REAL *)CCTK_VarDataPtrI(cctkGH, 0, + RHSArrayVariableIndex[var]); + + groupindex = CCTK_GroupIndexFromVarI(EvolvedArrayVariableIndex[var]); + ierr = CCTK_GroupDynamicData(cctkGH, groupindex, + &arraydata); + if (ierr) + { + CCTK_VWarn(0, __LINE__, __FILE__, "MoL", + "The driver does not return group information for group '%s'.", + CCTK_GroupName(groupindex)); + } + arraytotalsize = 1; + for (arraydim = 0; arraydim < arraydata.dim; arraydim++) + { + arraytotalsize *= arraydata.lsh[arraydim]; + } + + for (index = 0; index < arraytotalsize; index++) + { + UpdateVar[index] = (*Original_Delta_Time) * beta * RHSVar[index]; + } + + for (scratchstep = 0; + scratchstep < MoL_Intermediate_Steps - (*MoL_Intermediate_Step) + 1; + scratchstep++) + { + + alphaindex = AlphaIndex(*MoL_Intermediate_Step, scratchstep); + scratchindex = scratchstep - 1; + + alpha = RKAlphaCoefficients[alphaindex]; + + if (scratchstep) + { + ScratchVar = &ScratchSpace[(var * MoL_Num_Scratch_Levels + + scratchindex) * totalsize]; +#ifdef MOLDEBUG + printf("Reading from scratch space, initial address %ld index %d\n", + ScratchVar, (var * MoL_Num_Scratch_Levels + + scratchindex) * totalsize); +#endif + } + else + { + ScratchVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 1, + EvolvedVariableIndex[var]); + } + + if ( (alpha > MoL_Tiny)||(alpha < -MoL_Tiny) ) + { + for (index = 0; index < totalsize; index++) + { + UpdateVar[index] += alpha * ScratchVar[index]; +#ifdef MOLDEBUG + printf("Variable: %d. Index: %d. step: %d. alpha: %f. Scratch: %f. q: %f.\n", + var, index, (*MoL_Intermediate_Step), alpha, ScratchVar[index], UpdateVar[index]); +#endif + } + } + + } + + } + + if (*MoL_Intermediate_Step > 1) + { + for (var = 0; var < MoLNumEvolvedVariables; var++) + { + UpdateVar = (CCTK_REAL *)CCTK_VarDataPtrI(cctkGH, 0, + EvolvedVariableIndex[var]); + ScratchVar = &ScratchSpace[(var * MoL_Num_Scratch_Levels + + MoL_Intermediate_Steps - + (*MoL_Intermediate_Step)) * totalsize]; +#ifdef MOLDEBUG + printf("Writing to scratch space, initial address %ld, index %d \n", + ScratchVar, (var * MoL_Num_Scratch_Levels + + MoL_Intermediate_Steps - + (*MoL_Intermediate_Step)) * totalsize); +#endif + for (index = 0; index < totalsize; index++) + { + ScratchVar[index] = UpdateVar[index]; +#ifdef MOLDEBUG + printf("Variable: %d. Index: %d. step: %d. Scratch: %f.\n", + var, index, (*MoL_Intermediate_Step), ScratchVar[index]); +#endif + } + } + } return; } @@ -69,12 +69,21 @@ void MoL_ICNAdd(CCTK_ARGUMENTS) DECLARE_CCTK_ARGUMENTS; DECLARE_CCTK_PARAMETERS; + cGroupDynamicData arraydata; + CCTK_INT groupindex, ierr; + CCTK_INT arraytotalsize, arraydim; + CCTK_INT index, var; CCTK_INT totalsize; CCTK_REAL *OldVar; CCTK_REAL *UpdateVar; CCTK_REAL *RHSVar; + CCTK_COMPLEX *OldComplexVar; + CCTK_COMPLEX *UpdateComplexVar; + CCTK_COMPLEX *RHSComplexVar; + CCTK_COMPLEX Complex_Delta_Time = CCTK_Cmplx(CCTK_DELTA_TIME, 0); + #ifdef MOLDEBUG printf("Inside ICN.\nProcessor %d.\nStep %d.\nRefinement %d.\nTimestep %g.\nSpacestep %g.\nTime %g\n", CCTK_MyProc(cctkGH), @@ -104,6 +113,53 @@ void MoL_ICNAdd(CCTK_ARGUMENTS) } } + for (var = 0; var < MoLNumEvolvedArrayVariables; var++) + { + OldVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 1, + EvolvedArrayVariableIndex[var]); + UpdateVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 0, + EvolvedArrayVariableIndex[var]); + RHSVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 0, + RHSArrayVariableIndex[var]); + + groupindex = CCTK_GroupIndexFromVarI(EvolvedArrayVariableIndex[var]); + ierr = CCTK_GroupDynamicData(cctkGH, groupindex, + &arraydata); + if (ierr) + { + CCTK_VWarn(0, __LINE__, __FILE__, "MoL", + "The driver does not return group information for group '%s'.", + CCTK_GroupName(groupindex)); + } + arraytotalsize = 1; + for (arraydim = 0; arraydim < arraydata.dim; arraydim++) + { + arraytotalsize *= arraydata.lsh[arraydim]; + } + + for (index = 0; index < arraytotalsize; index++) + { + UpdateVar[index] = OldVar[index] + CCTK_DELTA_TIME * RHSVar[index]; + } + } + + for (var = 0; var < MoLNumEvolvedComplexVariables; var++) + { + OldComplexVar = (CCTK_COMPLEX*)CCTK_VarDataPtrI(cctkGH, 1, + EvolvedComplexVariableIndex[var]); + UpdateComplexVar = (CCTK_COMPLEX*)CCTK_VarDataPtrI(cctkGH, 0, + EvolvedComplexVariableIndex[var]); + RHSComplexVar = (CCTK_COMPLEX*)CCTK_VarDataPtrI(cctkGH, 0, + RHSComplexVariableIndex[var]); + + for (index = 0; index < totalsize; index++) + { + UpdateComplexVar[index] = CCTK_CmplxAdd(OldComplexVar[index], + CCTK_CmplxMul(Complex_Delta_Time, + RHSComplexVar[index])); + } + } + return; } diff --git a/src/IndexArrays.c b/src/IndexArrays.c index 7050e2d..01820eb 100644 --- a/src/IndexArrays.c +++ b/src/IndexArrays.c @@ -35,7 +35,7 @@ CCTK_FILEVERSION(AlphaThorns_MoL_IndexArrays_c); void MoL_SetupIndexArrays(CCTK_ARGUMENTS); -void MoL_FreeIndexArrays(); +void MoL_FreeIndexArrays(void); /******************************************************************** ********************* Other Routine Prototypes ********************* @@ -114,6 +114,108 @@ void MoL_SetupIndexArrays(CCTK_ARGUMENTS) CCTK_WARN(0,"Failed to allocate the save and restore variable index array"); } + + if (EvolvedComplexVariableIndex) + { + return; + } + + EvolvedComplexVariableIndex = (CCTK_INT *)malloc(MoL_Num_ComplexEvolved_Vars * + sizeof(CCTK_INT)); + if (!EvolvedComplexVariableIndex) + { + CCTK_WARN(0,"Failed to allocate the evolved complex variable index array"); + } + + RHSComplexVariableIndex = (CCTK_INT *)malloc(MoL_Num_ComplexEvolved_Vars * + sizeof(CCTK_INT)); + if (!RHSComplexVariableIndex) + { + CCTK_WARN(0,"Failed to allocate the RHS complex variable index array"); + } + + ConstrainedComplexVariableIndex = (CCTK_INT *)malloc(MoL_Num_ComplexConstrained_Vars * + sizeof(CCTK_INT)); + if (!ConstrainedComplexVariableIndex) + { + CCTK_WARN(0,"Failed to allocate the constrained complex variable index array"); + } + + SandRComplexVariableIndex = (CCTK_INT *)malloc(MoL_Num_ComplexSaveAndRestore_Vars * + sizeof(CCTK_INT)); + if (!SandRComplexVariableIndex) + { + CCTK_WARN(0,"Failed to allocate the save and restore complex variable index array"); + } + + + if (EvolvedArrayVariableIndex) + { + return; + } + + EvolvedArrayVariableIndex = (CCTK_INT *)malloc(MoL_Num_ArrayEvolved_Vars * + sizeof(CCTK_INT)); + if (!EvolvedArrayVariableIndex) + { + CCTK_WARN(0,"Failed to allocate the evolved array variable index array"); + } + + RHSArrayVariableIndex = (CCTK_INT *)malloc(MoL_Num_ArrayEvolved_Vars * + sizeof(CCTK_INT)); + if (!RHSArrayVariableIndex) + { + CCTK_WARN(0,"Failed to allocate the RHS array variable index array"); + } + + ConstrainedArrayVariableIndex = (CCTK_INT *)malloc(MoL_Num_ArrayConstrained_Vars * + sizeof(CCTK_INT)); + if (!ConstrainedArrayVariableIndex) + { + CCTK_WARN(0,"Failed to allocate the constrained array variable index array"); + } + + SandRArrayVariableIndex = (CCTK_INT *)malloc(MoL_Num_ArraySaveAndRestore_Vars * + sizeof(CCTK_INT)); + if (!SandRArrayVariableIndex) + { + CCTK_WARN(0,"Failed to allocate the save and restore array variable index array"); + } + + + if (EvolvedComplexArrayVariableIndex) + { + return; + } + + EvolvedComplexArrayVariableIndex = (CCTK_INT *)malloc(MoL_Num_ComplexArrayEvolved_Vars * + sizeof(CCTK_INT)); + if (!EvolvedComplexArrayVariableIndex) + { + CCTK_WARN(0,"Failed to allocate the evolved complex array variable index array"); + } + + RHSComplexArrayVariableIndex = (CCTK_INT *)malloc(MoL_Num_ComplexArrayEvolved_Vars * + sizeof(CCTK_INT)); + if (!RHSComplexArrayVariableIndex) + { + CCTK_WARN(0,"Failed to allocate the RHS complex array variable index array"); + } + + ConstrainedComplexArrayVariableIndex = (CCTK_INT *)malloc(MoL_Num_ComplexArrayConstrained_Vars * + sizeof(CCTK_INT)); + if (!ConstrainedComplexArrayVariableIndex) + { + CCTK_WARN(0,"Failed to allocate the constrained complex array variable index array"); + } + + SandRComplexArrayVariableIndex = (CCTK_INT *)malloc(MoL_Num_ComplexArraySaveAndRestore_Vars * + sizeof(CCTK_INT)); + if (!SandRComplexArrayVariableIndex) + { + CCTK_WARN(0,"Failed to allocate the save and restore complex array variable index array"); + } + infoline = (char *)malloc(100*sizeof(char)); if (!infoline) { @@ -175,7 +277,7 @@ void MoL_SetupIndexArrays(CCTK_ARGUMENTS) @@*/ -void MoL_FreeIndexArrays() +void MoL_FreeIndexArrays(void) { if (EvolvedVariableIndex) @@ -201,6 +303,78 @@ void MoL_FreeIndexArrays() free(SandRVariableIndex); SandRVariableIndex = NULL; } + + if (EvolvedComplexVariableIndex) + { + free(EvolvedComplexVariableIndex); + EvolvedComplexVariableIndex = NULL; + } + + if (RHSComplexVariableIndex) + { + free(RHSComplexVariableIndex); + RHSComplexVariableIndex = NULL; + } + + if (ConstrainedComplexVariableIndex) + { + free(ConstrainedComplexVariableIndex); + ConstrainedComplexVariableIndex = NULL; + } + + if (SandRComplexVariableIndex) + { + free(SandRComplexVariableIndex); + SandRComplexVariableIndex = NULL; + } + + if (EvolvedArrayVariableIndex) + { + free(EvolvedArrayVariableIndex); + EvolvedArrayVariableIndex = NULL; + } + + if (RHSArrayVariableIndex) + { + free(RHSArrayVariableIndex); + RHSArrayVariableIndex = NULL; + } + + if (ConstrainedArrayVariableIndex) + { + free(ConstrainedArrayVariableIndex); + ConstrainedArrayVariableIndex = NULL; + } + + if (SandRArrayVariableIndex) + { + free(SandRArrayVariableIndex); + SandRArrayVariableIndex = NULL; + } + + if (EvolvedComplexArrayVariableIndex) + { + free(EvolvedComplexArrayVariableIndex); + EvolvedComplexArrayVariableIndex = NULL; + } + + if (RHSComplexArrayVariableIndex) + { + free(RHSComplexArrayVariableIndex); + RHSComplexArrayVariableIndex = NULL; + } + + if (ConstrainedComplexArrayVariableIndex) + { + free(ConstrainedComplexArrayVariableIndex); + ConstrainedComplexArrayVariableIndex = NULL; + } + + if (SandRComplexArrayVariableIndex) + { + free(SandRComplexArrayVariableIndex); + SandRComplexArrayVariableIndex = NULL; + } return; diff --git a/src/InitialCopy.c b/src/InitialCopy.c index 0a6a54b..9004f37 100644 --- a/src/InitialCopy.c +++ b/src/InitialCopy.c @@ -11,6 +11,8 @@ @version $Header$ @@*/ +#include <string.h> + #include "cctk.h" #include "cctk_Arguments.h" #include "cctk_Parameters.h" @@ -54,10 +56,14 @@ void MoL_InitialCopy(CCTK_ARGUMENTS) DECLARE_CCTK_ARGUMENTS DECLARE_CCTK_PARAMETERS + + cGroupDynamicData arraydata; + CCTK_INT groupindex, ierr; + CCTK_INT arraytotalsize, arraydim; CCTK_INT var; - CCTK_INT index; - CCTK_INT i,j,k; +/* CCTK_INT index; */ +/* CCTK_INT i,j,k; */ CCTK_INT totalsize; CCTK_REAL *CurrentVar; @@ -65,6 +71,10 @@ void MoL_InitialCopy(CCTK_ARGUMENTS) CCTK_REAL *ScratchVar; CCTK_INT StorageOn; + CCTK_COMPLEX *CurrentComplexVar; + CCTK_COMPLEX *PreviousComplexVar; + CCTK_COMPLEX *ScratchComplexVar; + totalsize = cctk_lsh[0]*cctk_lsh[1]*cctk_lsh[2]; for (var = 0; var < MoLNumEvolvedVariables; var++) @@ -100,6 +110,77 @@ void MoL_InitialCopy(CCTK_ARGUMENTS) } } + + for (var = 0; var < MoLNumEvolvedArrayVariables; var++) + { + PreviousVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 1, + EvolvedArrayVariableIndex[var]); + CurrentVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 0, + EvolvedArrayVariableIndex[var]); + + groupindex = CCTK_GroupIndexFromVarI(EvolvedArrayVariableIndex[var]); + ierr = CCTK_GroupDynamicData(cctkGH, groupindex, + &arraydata); + if (ierr) + { + CCTK_VWarn(0, __LINE__, __FILE__, "MoL", + "The driver does not return group information for group '%s'.", + CCTK_GroupName(groupindex)); + } + arraytotalsize = 1; + for (arraydim = 0; arraydim < arraydata.dim; arraydim++) + { + arraytotalsize *= arraydata.lsh[arraydim]; + } + + if (PreviousVar && CurrentVar) + { + memcpy(CurrentVar, PreviousVar, arraytotalsize * sizeof(CCTK_REAL)); + } + else + { + printf("The pointers are %p (prev) and %p (curr)\n.", + PreviousVar, CurrentVar); + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","Null pointer for variable %s", + CCTK_VarName(EvolvedArrayVariableIndex[var])); + } + + } + + + for (var = 0; var < MoLNumEvolvedComplexVariables; var++) + { + + StorageOn = CCTK_QueryGroupStorage(cctkGH, + CCTK_GroupNameFromVarI(EvolvedComplexVariableIndex[var])); + + if (StorageOn < 0) + { + CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for index %i", + EvolvedComplexVariableIndex[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(EvolvedComplexVariableIndex[var])); + CCTK_WARN(0, "The grid function does not have storage assigned."); + } + + PreviousComplexVar = (CCTK_COMPLEX*)CCTK_VarDataPtrI(cctkGH, 1, + EvolvedComplexVariableIndex[var]); + CurrentComplexVar = (CCTK_COMPLEX*)CCTK_VarDataPtrI(cctkGH, 0, + EvolvedComplexVariableIndex[var]); + if (PreviousComplexVar && CurrentComplexVar) + { + memcpy(CurrentComplexVar, PreviousComplexVar, totalsize * sizeof(CCTK_COMPLEX)); + } + else + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","Null pointer for variable %s", + CCTK_VarName(EvolvedComplexVariableIndex[var])); + } + + } /* Now the Save and Restore variables. Shift the data in the @@ -145,7 +226,7 @@ void MoL_InitialCopy(CCTK_ARGUMENTS) else { CCTK_VWarn(0,__LINE__,__FILE__,"MoL","Null pointer for variable %s", - CCTK_VarName(SandRScratchSpace[var])); + CCTK_VarName(SandRVariableIndex[var])); } #ifdef MOLDEBUG printf("Init2:Variable %s, current %g, previous %g, scratch %g\n", @@ -154,6 +235,46 @@ void MoL_InitialCopy(CCTK_ARGUMENTS) #endif } + + for (var = 0; var < MoLNumSandRComplexVariables; var++) + { + + StorageOn = CCTK_QueryGroupStorage(cctkGH, + CCTK_GroupNameFromVarI(SandRComplexVariableIndex[var])); + + if (StorageOn < 0) + { + CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for index %i", + SandRComplexVariableIndex[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(SandRComplexVariableIndex[var])); + CCTK_WARN(0, "The grid function does not have storage assigned."); + } + + PreviousComplexVar = (CCTK_COMPLEX*)CCTK_VarDataPtrI(cctkGH, 1, + SandRComplexVariableIndex[var]); + CurrentComplexVar = (CCTK_COMPLEX*)CCTK_VarDataPtrI(cctkGH, 0, + SandRComplexVariableIndex[var]); + ScratchComplexVar = &ComplexSandRScratchSpace[var*totalsize]; +#ifdef MOLDEBUG + printf("Pointers for the SandR vars are to %ld, %ld and %ld.\n", + PreviousComplexVar, CurrentComplexVar, ScratchComplexVar); +#endif + if (PreviousComplexVar && CurrentComplexVar && ScratchComplexVar) + { + memcpy(ScratchComplexVar, CurrentComplexVar, totalsize * sizeof(CCTK_COMPLEX)); + memcpy(CurrentComplexVar, PreviousComplexVar, totalsize * sizeof(CCTK_COMPLEX)); + } + else + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","Null pointer for variable %s", + CCTK_VarName(SandRComplexVariableIndex[var])); + } + } + /* Now do the constrained variables. */ @@ -193,6 +314,42 @@ void MoL_InitialCopy(CCTK_ARGUMENTS) } + + for (var = 0; var < MoLNumConstrainedComplexVariables; var++) + { + + StorageOn = CCTK_QueryGroupStorage(cctkGH, + CCTK_GroupNameFromVarI(ConstrainedComplexVariableIndex[var])); + + if (StorageOn < 0) + { + CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for index %i", + ConstrainedComplexVariableIndex[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(ConstrainedComplexVariableIndex[var])); + CCTK_WARN(0, "The grid function does not have storage assigned."); + } + + PreviousComplexVar = (CCTK_COMPLEX*)CCTK_VarDataPtrI(cctkGH, 1, + ConstrainedComplexVariableIndex[var]); + CurrentComplexVar = (CCTK_COMPLEX*)CCTK_VarDataPtrI(cctkGH, 0, + ConstrainedComplexVariableIndex[var]); + + if (PreviousComplexVar && CurrentComplexVar) + { + memcpy(CurrentComplexVar, PreviousComplexVar, totalsize * sizeof(CCTK_COMPLEX)); + } + else + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","Null pointer for variable %s", + CCTK_VarName(ConstrainedComplexVariableIndex[var])); + } + + } + return; } @@ -280,18 +437,60 @@ void MoL_FillAllLevels(CCTK_ARGUMENTS) } CCTK_VInfo(CCTK_THORNSTRING, - "The maximum number of evolved variables is %d. %d are registered", + "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", + "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", + "The maximum number of SandR variables is %d. %d are registered.", MoL_Num_SaveAndRestore_Vars,MoLNumSandRVariables); + + CCTK_VInfo(CCTK_THORNSTRING, + "The maximum number of evolved complex variables is %d. %d are registered.", + MoL_Num_ComplexEvolved_Vars,MoLNumEvolvedComplexVariables); + + CCTK_VInfo(CCTK_THORNSTRING, + "The maximum number of constrained complex variables is %d. %d are registered.", + MoL_Num_ComplexConstrained_Vars,MoLNumConstrainedComplexVariables); + CCTK_VInfo(CCTK_THORNSTRING, + "The maximum number of SandR complex variables is %d. %d are registered.", + MoL_Num_ComplexSaveAndRestore_Vars,MoLNumSandRComplexVariables); + + + CCTK_VInfo(CCTK_THORNSTRING, + "The maximum number of evolved array variables is %d. %d are registered.", + MoL_Num_ArrayEvolved_Vars,MoLNumEvolvedArrayVariables); + + CCTK_VInfo(CCTK_THORNSTRING, + "The maximum number of constrained array variables is %d. %d are registered.", + MoL_Num_ArrayConstrained_Vars,MoLNumConstrainedArrayVariables); + + CCTK_VInfo(CCTK_THORNSTRING, + "The maximum number of SandR array variables is %d. %d are registered.", + MoL_Num_ArraySaveAndRestore_Vars,MoLNumSandRArrayVariables); + + + CCTK_VInfo(CCTK_THORNSTRING, + "The maximum number of evolved complex array variables is %d. %d are registered.", + MoL_Num_ComplexArrayEvolved_Vars,MoLNumEvolvedComplexArrayVariables); + + CCTK_VInfo(CCTK_THORNSTRING, + "The maximum number of constrained complex array variables is %d. %d are registered.", + MoL_Num_ComplexArrayConstrained_Vars,MoLNumConstrainedComplexArrayVariables); + + CCTK_VInfo(CCTK_THORNSTRING, + "The maximum number of SandR complex array variables is %d. %d are registered.", + MoL_Num_ComplexArraySaveAndRestore_Vars,MoLNumSandRComplexArrayVariables); + + CCTK_VInfo(CCTK_THORNSTRING, + "The maximum size of any array variables is %d.", + MoL_Max_Evolved_Array_Size); + return; } diff --git a/src/ParamCheck.c b/src/ParamCheck.c index 8c44691..d9cf1ae 100644 --- a/src/ParamCheck.c +++ b/src/ParamCheck.c @@ -28,7 +28,7 @@ CCTK_FILEVERSION(AlphaThorns_MoL_ParamCheck_c); ***************** Scheduled Routine Prototypes ********************* ********************************************************************/ -int ParamCheck(CCTK_ARGUMENTS); +int MoL_ParamCheck(CCTK_ARGUMENTS); /******************************************************************** ********************* Other Routine Prototypes ********************* @@ -67,12 +67,22 @@ void MoL_RK2Add(CCTK_ARGUMENTS) DECLARE_CCTK_ARGUMENTS; DECLARE_CCTK_PARAMETERS; + + cGroupDynamicData arraydata; + CCTK_INT groupindex, ierr; + CCTK_INT arraytotalsize, arraydim; CCTK_INT index, var; CCTK_INT totalsize; CCTK_REAL *OldVar; CCTK_REAL *UpdateVar; CCTK_REAL *RHSVar; + + CCTK_COMPLEX *OldComplexVar; + CCTK_COMPLEX *UpdateComplexVar; + CCTK_COMPLEX *RHSComplexVar; + CCTK_COMPLEX Complex_Delta_Time = CCTK_Cmplx(CCTK_DELTA_TIME, 0); + CCTK_COMPLEX Complex_Half = CCTK_Cmplx(0.5, 0); #ifdef MOLDEBUG printf("Inside RK2.\nStep %d.\nRefinement %d.\nTimestep %g.\nSpacestep %g.\nTime %g\n", @@ -102,6 +112,48 @@ void MoL_RK2Add(CCTK_ARGUMENTS) UpdateVar[index] += CCTK_DELTA_TIME * RHSVar[index]; } } + + for (var = 0; var < MoLNumEvolvedArrayVariables; var++) + { + UpdateVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 0, + EvolvedArrayVariableIndex[var]); + RHSVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 0, + RHSArrayVariableIndex[var]); + groupindex = CCTK_GroupIndexFromVarI(EvolvedArrayVariableIndex[var]); + ierr = CCTK_GroupDynamicData(cctkGH, groupindex, + &arraydata); + if (ierr) + { + CCTK_VWarn(0, __LINE__, __FILE__, "MoL", + "The driver does not return group information for group '%s'.", + CCTK_GroupName(groupindex)); + } + arraytotalsize = 1; + for (arraydim = 0; arraydim < arraydata.dim; arraydim++) + { + arraytotalsize *= arraydata.lsh[arraydim]; + } + + for (index = 0; index < arraytotalsize; index++) + { + UpdateVar[index] += CCTK_DELTA_TIME * RHSVar[index]; + } + } + + for (var = 0; var < MoLNumEvolvedComplexVariables; var++) + { + UpdateComplexVar = (CCTK_COMPLEX*)CCTK_VarDataPtrI(cctkGH, 0, + EvolvedComplexVariableIndex[var]); + RHSComplexVar = (CCTK_COMPLEX*)CCTK_VarDataPtrI(cctkGH, 0, + RHSComplexVariableIndex[var]); + + for (index = 0; index < totalsize; index++) + { + UpdateComplexVar[index] = CCTK_CmplxAdd(UpdateComplexVar[index], + CCTK_CmplxMul(Complex_Delta_Time, + RHSComplexVar[index])); + } + } break; } case 1: @@ -121,6 +173,54 @@ void MoL_RK2Add(CCTK_ARGUMENTS) CCTK_DELTA_TIME * RHSVar[index]; } } + + for (var = 0; var < MoLNumEvolvedArrayVariables; var++) + { + OldVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 1, + EvolvedVariableIndex[var]); + UpdateVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 0, + EvolvedVariableIndex[var]); + RHSVar = (CCTK_REAL*)CCTK_VarDataPtrI(cctkGH, 0, + RHSVariableIndex[var]); + + groupindex = CCTK_GroupIndexFromVarI(EvolvedArrayVariableIndex[var]); + ierr = CCTK_GroupDynamicData(cctkGH, groupindex, + &arraydata); + if (ierr) + { + CCTK_VWarn(0, __LINE__, __FILE__, "MoL", + "The driver does not return group information for group '%s'.", + CCTK_GroupName(groupindex)); + } + arraytotalsize = 1; + for (arraydim = 0; arraydim < arraydata.dim; arraydim++) + { + arraytotalsize *= arraydata.lsh[arraydim]; + } + + for (index = 0; index < arraytotalsize; index++) + { + UpdateVar[index] = 0.5 * (OldVar[index] + UpdateVar[index]) + + CCTK_DELTA_TIME * RHSVar[index]; + } + } + + for (var = 0; var < MoLNumEvolvedComplexVariables; var++) + { + OldComplexVar = (CCTK_COMPLEX*)CCTK_VarDataPtrI(cctkGH, 1, + EvolvedComplexVariableIndex[var]); + UpdateComplexVar = (CCTK_COMPLEX*)CCTK_VarDataPtrI(cctkGH, 0, + EvolvedComplexVariableIndex[var]); + RHSComplexVar = (CCTK_COMPLEX*)CCTK_VarDataPtrI(cctkGH, 0, + RHSComplexVariableIndex[var]); + + for (index = 0; index < totalsize; index++) + { + UpdateComplexVar[index] = + CCTK_CmplxAdd(CCTK_CmplxMul(Complex_Half, + (CCTK_CmplxAdd(OldComplexVar[index], UpdateComplexVar[index]))), CCTK_CmplxMul(Complex_Delta_Time, RHSComplexVar[index])); + } + } break; } default: diff --git a/src/Registration.c b/src/Registration.c index c0b33cd..71c98ee 100644 --- a/src/Registration.c +++ b/src/Registration.c @@ -48,6 +48,64 @@ CCTK_INT MoL_RegisterConstrainedGroup(CCTK_INT ConstrainedGroupIndex); CCTK_INT MoL_RegisterSaveAndRestoreGroup(CCTK_INT SandRGroupIndex); + + +CCTK_INT MoL_RegisterEvolvedReal(CCTK_INT EvolvedIndex, CCTK_INT RHSIndex); + +CCTK_INT MoL_RegisterConstrainedReal(CCTK_INT ConstrainedIndex); + +CCTK_INT MoL_RegisterSaveAndRestoreReal(CCTK_INT SandRIndex); + +CCTK_INT MoL_RegisterEvolvedRealGroup(CCTK_INT EvolvedGroupIndex, + CCTK_INT RHSGroupIndex); + +CCTK_INT MoL_RegisterConstrainedRealGroup(CCTK_INT ConstrainedGroupIndex); + +CCTK_INT MoL_RegisterSaveAndRestoreRealGroup(CCTK_INT SandRGroupIndex); + + +CCTK_INT MoL_RegisterEvolvedComplex(CCTK_INT EvolvedIndex, CCTK_INT RHSIndex); + +CCTK_INT MoL_RegisterConstrainedComplex(CCTK_INT ConstrainedIndex); + +CCTK_INT MoL_RegisterSaveAndRestoreComplex(CCTK_INT SandRIndex); + +CCTK_INT MoL_RegisterEvolvedComplexGroup(CCTK_INT EvolvedGroupIndex, + CCTK_INT RHSGroupIndex); + +CCTK_INT MoL_RegisterConstrainedComplexGroup(CCTK_INT ConstrainedGroupIndex); + +CCTK_INT MoL_RegisterSaveAndRestoreComplexGroup(CCTK_INT SandRGroupIndex); + + +CCTK_INT MoL_RegisterEvolvedArray(CCTK_INT EvolvedIndex, CCTK_INT RHSIndex); + +CCTK_INT MoL_RegisterConstrainedArray(CCTK_INT ConstrainedIndex); + +CCTK_INT MoL_RegisterSaveAndRestoreArray(CCTK_INT SandRIndex); + +CCTK_INT MoL_RegisterEvolvedArrayGroup(CCTK_INT EvolvedGroupIndex, + CCTK_INT RHSGroupIndex); + +CCTK_INT MoL_RegisterConstrainedArrayGroup(CCTK_INT ConstrainedGroupIndex); + +CCTK_INT MoL_RegisterSaveAndRestoreArrayGroup(CCTK_INT SandRGroupIndex); + + +CCTK_INT MoL_RegisterEvolvedComplexArray(CCTK_INT EvolvedIndex, + CCTK_INT RHSIndex); + +CCTK_INT MoL_RegisterConstrainedComplexArray(CCTK_INT ConstrainedIndex); + +CCTK_INT MoL_RegisterSaveAndRestoreComplexArray(CCTK_INT SandRIndex); + +CCTK_INT MoL_RegisterEvolvedComplexArrayGroup(CCTK_INT EvolvedGroupIndex, + CCTK_INT RHSGroupIndex); + +CCTK_INT MoL_RegisterConstrainedComplexArrayGroup(CCTK_INT ConstrainedGroupIndex); + +CCTK_INT MoL_RegisterSaveAndRestoreComplexArrayGroup(CCTK_INT SandRGroupIndex); + /******************************************************************** ********************* Local Data ***************************** ********************************************************************/ @@ -75,9 +133,574 @@ CCTK_INT MoL_RegisterSaveAndRestoreGroup(CCTK_INT SandRGroupIndex); CCTK_INT MoL_RegisterEvolved(CCTK_INT EvolvedIndex, CCTK_INT RHSIndex) { + CCTK_INT retval, GroupType; + + retval = 0; + + GroupType = CCTK_GroupTypeFromVarI(EvolvedIndex); + if (GroupType < 0) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "Evolved index %i is not a real variable index.", + EvolvedIndex); + retval++; + } + + if (!retval) + { + switch (CCTK_VarTypeI(EvolvedIndex)) + { + case CCTK_VARIABLE_REAL: + { + switch (GroupType) + { + case CCTK_GF: + { + retval += + MoL_RegisterEvolvedReal(EvolvedIndex, + RHSIndex); + break; + } + case CCTK_ARRAY: + { + retval += + MoL_RegisterEvolvedArray(EvolvedIndex, + RHSIndex); + break; + } + default: + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable '%s' is not a GF or an array", + CCTK_VarName(EvolvedIndex)); + retval++; + break; + } + } + break; + } + case CCTK_VARIABLE_COMPLEX: + { + switch (GroupType) + { + case CCTK_GF: + { + retval += + MoL_RegisterEvolvedComplex(EvolvedIndex, + RHSIndex); + break; + } + case CCTK_ARRAY: + { + retval += + MoL_RegisterEvolvedComplexArray(EvolvedIndex, + RHSIndex); + break; + } + default: + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable '%s' is not a GF or an array", + CCTK_VarName(EvolvedIndex)); + retval++; + break; + } + } + break; + } + default: + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable '%s' is neither REAL nor COMPLEX.", + CCTK_VarName(EvolvedIndex)); + retval++; + break; + } + } + } + + return retval; + +} + + /*@@ + @routine MoL_RegisterConstrained + @date Thu May 30 12:35:58 2002 + @author Ian Hawke + @desc + Given the index of the GF, register it as a constrained variable. + If there's only one timelevel then ignore it as there will be no + rotation and so MoL doesn't have to do anything. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ + +CCTK_INT MoL_RegisterConstrained(CCTK_INT ConstrainedIndex) +{ + + CCTK_INT retval, GroupType; + + retval = 0; + + GroupType = CCTK_GroupTypeFromVarI(ConstrainedIndex); + if (GroupType < 0) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "Constrained index %i is not a real variable index.", + ConstrainedIndex); + retval++; + return retval; + } + + switch (CCTK_VarTypeI(ConstrainedIndex)) + { + case CCTK_VARIABLE_REAL: + { + switch (GroupType) + { + case CCTK_GF: + { + retval += + MoL_RegisterConstrainedReal(ConstrainedIndex); + break; + } + case CCTK_ARRAY: + { + retval += + MoL_RegisterConstrainedArray(ConstrainedIndex); + break; + } + default: + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable '%s' is not a GF or an array", + CCTK_VarName(ConstrainedIndex)); + retval++; + break; + } + } + break; + } + case CCTK_VARIABLE_COMPLEX: + { + switch (GroupType) + { + case CCTK_GF: + { + retval += + MoL_RegisterConstrainedComplex(ConstrainedIndex); + break; + } + case CCTK_ARRAY: + { + retval += + MoL_RegisterConstrainedComplexArray(ConstrainedIndex); + break; + } + default: + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable '%s' is not a GF or an array", + CCTK_VarName(ConstrainedIndex)); + retval++; + break; + } + } + break; + } + default: + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable '%s' is neither REAL nor COMPLEX.", + CCTK_VarName(ConstrainedIndex)); + retval++; + break; + } + } + + return retval; + +} + + /*@@ + @routine MoL_RegisterSaveAndRestore + @date Thu May 30 12:37:40 2002 + @author Ian Hawke + @desc + Given a GF index store it for later use as a save and restore type. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ + +CCTK_INT MoL_RegisterSaveAndRestore(CCTK_INT SandRIndex) +{ + + CCTK_INT retval, GroupType; + + retval = 0; + + GroupType = CCTK_GroupTypeFromVarI(SandRIndex); + if (GroupType < 0) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "SaveAndRestore index %i is not a real variable index.", + SandRIndex); + retval++; + return retval; + } + + switch (CCTK_VarTypeI(SandRIndex)) + { + case CCTK_VARIABLE_REAL: + { + switch (GroupType) + { + case CCTK_GF: + { + retval += + MoL_RegisterSaveAndRestoreReal(SandRIndex); + break; + } + case CCTK_ARRAY: + { + retval += + MoL_RegisterSaveAndRestoreArray(SandRIndex); + break; + } + default: + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable '%s' is not a GF or an array", + CCTK_VarName(SandRIndex)); + retval++; + break; + } + } + break; + } + case CCTK_VARIABLE_COMPLEX: + { + switch (GroupType) + { + case CCTK_GF: + { + retval += + MoL_RegisterSaveAndRestoreComplex(SandRIndex); + break; + } + case CCTK_ARRAY: + { + retval += + MoL_RegisterSaveAndRestoreComplexArray(SandRIndex); + break; + } + default: + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable '%s' is not a GF or an array", + CCTK_VarName(SandRIndex)); + retval++; + break; + } + } + break; + } + default: + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable '%s' is neither REAL nor COMPLEX.", + CCTK_VarName(SandRIndex)); + retval++; + break; + } + } + + return retval; + +} + +CCTK_INT MoL_RegisterEvolvedGroup(CCTK_INT EvolvedGroupIndex, + CCTK_INT RHSGroupIndex) +{ + + CCTK_INT retval, GroupFirstVar; + + retval = 0; + + GroupFirstVar = CCTK_FirstVarIndexI(EvolvedGroupIndex); + if (GroupFirstVar < 0) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "Evolved group index %i is not a real group index.", + EvolvedGroupIndex); + retval++; + } + + switch (CCTK_VarTypeI(CCTK_FirstVarIndexI(EvolvedGroupIndex))) + { + case CCTK_VARIABLE_REAL: + { + switch (CCTK_GroupTypeI(EvolvedGroupIndex)) + { + case CCTK_GF: + { + retval += + MoL_RegisterEvolvedRealGroup(EvolvedGroupIndex, + RHSGroupIndex); + break; + } + case CCTK_ARRAY: + { + retval += + MoL_RegisterEvolvedArrayGroup(EvolvedGroupIndex, + RHSGroupIndex); + break; + } + default: + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The group '%s' is not a GF or an array", + CCTK_GroupName(EvolvedGroupIndex)); + retval++; + break; + } + } + break; + } + case CCTK_VARIABLE_COMPLEX: + { + switch (CCTK_GroupTypeI(EvolvedGroupIndex)) + { + case CCTK_GF: + { + retval += + MoL_RegisterEvolvedComplexGroup(EvolvedGroupIndex, + RHSGroupIndex); + break; + } + case CCTK_ARRAY: + { + retval += + MoL_RegisterEvolvedComplexArrayGroup(EvolvedGroupIndex, + RHSGroupIndex); + break; + } + default: + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The group '%s' is not a GF or an array", + CCTK_GroupName(EvolvedGroupIndex)); + retval++; + break; + } + } + break; + } + default: + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The group '%s' is neither REAL nor COMPLEX.", + CCTK_GroupName(EvolvedGroupIndex)); + retval++; + break; + } + } + + return retval; + +} + + +CCTK_INT MoL_RegisterConstrainedGroup(CCTK_INT ConstrainedGroupIndex) +{ + + CCTK_INT retval, GroupFirstVar; + + retval = 0; + + GroupFirstVar = CCTK_FirstVarIndexI(ConstrainedGroupIndex); + if (GroupFirstVar < 0) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "Constrained group index %i is not a real group index.", + ConstrainedGroupIndex); + retval++; + } + + switch (CCTK_VarTypeI(CCTK_FirstVarIndexI(ConstrainedGroupIndex))) + { + case CCTK_VARIABLE_REAL: + { + switch (CCTK_GroupTypeI(ConstrainedGroupIndex)) + { + case CCTK_GF: + { + retval += + MoL_RegisterConstrainedRealGroup(ConstrainedGroupIndex); + break; + } + case CCTK_ARRAY: + { + retval += + MoL_RegisterConstrainedArrayGroup(ConstrainedGroupIndex); + break; + } + default: + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The group '%s' is not a GF or an array", + CCTK_GroupName(ConstrainedGroupIndex)); + retval++; + break; + } + } + break; + } + case CCTK_VARIABLE_COMPLEX: + { + switch (CCTK_GroupTypeI(ConstrainedGroupIndex)) + { + case CCTK_GF: + { + retval += + MoL_RegisterConstrainedComplexGroup(ConstrainedGroupIndex); + break; + } + case CCTK_ARRAY: + { + retval += + MoL_RegisterConstrainedComplexArrayGroup(ConstrainedGroupIndex); + break; + } + default: + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The group '%s' is not a GF or an array", + CCTK_GroupName(ConstrainedGroupIndex)); + retval++; + break; + } + } + break; + } + default: + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The group '%s' is neither REAL nor COMPLEX.", + CCTK_GroupName(ConstrainedGroupIndex)); + retval++; + break; + } + } + + return retval; + +} + +CCTK_INT MoL_RegisterSaveAndRestoreGroup(CCTK_INT SandRGroupIndex) +{ + + CCTK_INT retval, GroupFirstVar; + + retval = 0; + + GroupFirstVar = CCTK_FirstVarIndexI(SandRGroupIndex); + if (GroupFirstVar < 0) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "SaveAndRestore group index %i is not a real group index.", + SandRGroupIndex); + retval++; + } + + switch (CCTK_VarTypeI(CCTK_FirstVarIndexI(SandRGroupIndex))) + { + case CCTK_VARIABLE_REAL: + { + switch (CCTK_GroupTypeI(SandRGroupIndex)) + { + case CCTK_GF: + { + retval += + MoL_RegisterSaveAndRestoreRealGroup(SandRGroupIndex); + break; + } + case CCTK_ARRAY: + { + retval += + MoL_RegisterSaveAndRestoreArrayGroup(SandRGroupIndex); + break; + } + default: + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The group '%s' is not a GF or an array", + CCTK_GroupName(SandRGroupIndex)); + retval++; + break; + } + } + break; + } + case CCTK_VARIABLE_COMPLEX: + { + switch (CCTK_GroupTypeI(SandRGroupIndex)) + { + case CCTK_GF: + { + retval += + MoL_RegisterSaveAndRestoreComplexGroup(SandRGroupIndex); + break; + } + case CCTK_ARRAY: + { + retval += + MoL_RegisterSaveAndRestoreComplexArrayGroup(SandRGroupIndex); + break; + } + default: + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The group '%s' is not a GF or an array", + CCTK_GroupName(SandRGroupIndex)); + retval++; + break; + } + } + break; + } + default: + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The group '%s' is neither REAL nor COMPLEX.", + CCTK_GroupName(SandRGroupIndex)); + retval++; + break; + } + } + + return retval; + +} + +/* + Temporary no-op functions for testing. +*/ + + /*@@ + @routine MoL_RegisterEvolved + @date Thu May 30 11:36:59 2002 + @author Ian Hawke + @desc + Given the index of the GF to be evolved and the RHS GF, it stores + the indexes for later use together with various error checking. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ + +CCTK_INT MoL_RegisterEvolvedReal(CCTK_INT EvolvedIndex, CCTK_INT RHSIndex) +{ + DECLARE_CCTK_PARAMETERS; - CCTK_INT ierr, index, varused, numtimelevs1, numtimelevs2; + CCTK_INT /* ierr, */ index, varused, numtimelevs1, numtimelevs2; #ifdef MOLDEBUG printf("Arrived in MoLRegisterEvolved \n"); @@ -88,6 +711,30 @@ CCTK_INT MoL_RegisterEvolved(CCTK_INT EvolvedIndex, CCTK_INT RHSIndex) EvolvedVariableIndex); #endif + if (!(CCTK_GroupTypeFromVarI(EvolvedIndex)==CCTK_GF)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not a GF and so should not be registered with MoLRegisterEvolved.", + CCTK_VarName(EvolvedIndex)); + } + + if (!(CCTK_GroupTypeFromVarI(RHSIndex)==CCTK_GF)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The rhs variable %s is not a GF and so should not be registered with MoLRegisterEvolved.", + CCTK_VarName(RHSIndex)); + } + + if (!(CCTK_VarTypeI(EvolvedIndex)==CCTK_VARIABLE_REAL)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not of type CCTK_REAL and so should not be registered with MoLRegisterEvolved.", + CCTK_VarName(EvolvedIndex)); + } + + if (!(CCTK_VarTypeI(RHSIndex)==CCTK_VARIABLE_REAL)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The rhs variable %s is not of type CCTK_REAL and so should not be registered with MoLRegisterEvolved.", + CCTK_VarName(RHSIndex)); + } + numtimelevs1 = CCTK_NumTimeLevelsFromVarI(EvolvedIndex); numtimelevs2 = CCTK_NumTimeLevelsFromVarI(RHSIndex); @@ -192,12 +839,24 @@ CCTK_INT MoL_RegisterEvolved(CCTK_INT EvolvedIndex, CCTK_INT RHSIndex) @@*/ -CCTK_INT MoL_RegisterConstrained(CCTK_INT ConstrainedIndex) +CCTK_INT MoL_RegisterConstrainedReal(CCTK_INT ConstrainedIndex) { DECLARE_CCTK_PARAMETERS; CCTK_INT numtimelevs, varused, evolved, index; + + if (!(CCTK_GroupTypeFromVarI(ConstrainedIndex)==CCTK_GF)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not a GF and so should not be registered with MoLRegisterConstrained.", + CCTK_VarName(ConstrainedIndex)); + } + + if (!(CCTK_VarTypeI(ConstrainedIndex)==CCTK_VARIABLE_REAL)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not of type CCTK_REAL and so should not be registered with MoLRegisterConstrained.", + CCTK_VarName(ConstrainedIndex)); + } numtimelevs = CCTK_NumTimeLevelsFromVarI(ConstrainedIndex); @@ -278,12 +937,24 @@ CCTK_INT MoL_RegisterConstrained(CCTK_INT ConstrainedIndex) @@*/ -CCTK_INT MoL_RegisterSaveAndRestore(CCTK_INT SandRIndex) +CCTK_INT MoL_RegisterSaveAndRestoreReal(CCTK_INT SandRIndex) { DECLARE_CCTK_PARAMETERS; CCTK_INT numtimelevs, varused, evolved; + + if (!(CCTK_GroupTypeFromVarI(SandRIndex)==CCTK_GF)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not a GF and so should not be registered with MoLRegisterSaveAndRestore.", + CCTK_VarName(SandRIndex)); + } + + if (!(CCTK_VarTypeI(SandRIndex)==CCTK_VARIABLE_REAL)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not of type CCTK_REAL and so should not be registered with MoLRegisterSaveAndRestore.", + CCTK_VarName(SandRIndex)); + } numtimelevs = CCTK_NumTimeLevelsFromVarI(SandRIndex); @@ -338,7 +1009,7 @@ CCTK_INT MoL_RegisterSaveAndRestore(CCTK_INT SandRIndex) } -CCTK_INT MoL_RegisterEvolvedGroup(CCTK_INT EvolvedGroupIndex, +CCTK_INT MoL_RegisterEvolvedRealGroup(CCTK_INT EvolvedGroupIndex, CCTK_INT RHSGroupIndex) { @@ -374,14 +1045,14 @@ CCTK_INT MoL_RegisterEvolvedGroup(CCTK_INT EvolvedGroupIndex, EvolvedVar < EvolvedGroupFirstVar + GroupNumVars; EvolvedVar++, RHSVar++) { - retval += MoLRegisterEvolved(EvolvedVar, RHSVar); + retval += MoL_RegisterEvolvedReal(EvolvedVar, RHSVar); } return retval; } -CCTK_INT MoL_RegisterConstrainedGroup(CCTK_INT ConstrainedGroupIndex) +CCTK_INT MoL_RegisterConstrainedRealGroup(CCTK_INT ConstrainedGroupIndex) { CCTK_INT ConstrainedGroupFirstVar, GroupNumVars, retval; @@ -403,13 +1074,13 @@ CCTK_INT MoL_RegisterConstrainedGroup(CCTK_INT ConstrainedGroupIndex) ConstrainedVar < ConstrainedGroupFirstVar + GroupNumVars; ConstrainedVar++) { - retval += MoLRegisterConstrained(ConstrainedVar); + retval += MoL_RegisterConstrainedReal(ConstrainedVar); } return retval; } -CCTK_INT MoL_RegisterSaveAndRestoreGroup(CCTK_INT SandRGroupIndex) +CCTK_INT MoL_RegisterSaveAndRestoreRealGroup(CCTK_INT SandRGroupIndex) { CCTK_INT SandRGroupFirstVar, GroupNumVars, retval; @@ -431,17 +1102,1214 @@ CCTK_INT MoL_RegisterSaveAndRestoreGroup(CCTK_INT SandRGroupIndex) SandRVar < SandRGroupFirstVar + GroupNumVars; SandRVar++) { - retval += MoLRegisterSaveAndRestore(SandRVar); + retval += MoL_RegisterSaveAndRestoreReal(SandRVar); } return retval; } +CCTK_INT MoL_RegisterEvolvedComplex(CCTK_INT EvolvedIndex, CCTK_INT RHSIndex) +{ + + DECLARE_CCTK_PARAMETERS; + + CCTK_INT /* ierr, */ index, varused, numtimelevs1, numtimelevs2; + +#ifdef MOLDEBUG + printf("Arrived in MoLRegisterEvolvedComplex \n"); + printf("The indexes are %d and %d.\n",EvolvedIndex, RHSIndex); + printf("These correspond to variables %s and %s.\n", + CCTK_VarName(EvolvedIndex),CCTK_VarName(RHSIndex)); + printf("The pointer to EvolvedVariableIndex: %p\n", + EvolvedComplexVariableIndex); +#endif + + if (!(CCTK_GroupTypeFromVarI(EvolvedIndex)==CCTK_GF)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not a GF and so should not be registered with MoLRegisterEvolved.", + CCTK_VarName(EvolvedIndex)); + } + + if (!(CCTK_GroupTypeFromVarI(RHSIndex)==CCTK_GF)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The rhs variable %s is not a GF and so should not be registered with MoLRegisterEvolved.", + CCTK_VarName(RHSIndex)); + } + + if (!(CCTK_VarTypeI(EvolvedIndex)==CCTK_VARIABLE_REAL)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not of type CCTK_REAL and so should not be registered with MoLRegisterEvolved.", + CCTK_VarName(EvolvedIndex)); + } + + if (!(CCTK_VarTypeI(EvolvedIndex)==CCTK_VARIABLE_COMPLEX)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not of type CCTK_COMPLEX and so should not be registered with MoLRegisterEvolvedComplex.", + CCTK_VarName(EvolvedIndex)); + } + + if (!(CCTK_VarTypeI(RHSIndex)==CCTK_VARIABLE_COMPLEX)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The rhs variable %s is not of type CCTK_COMPLEX and so should not be registered with MoLRegisterEvolvedComplex.", + CCTK_VarName(RHSIndex)); + } + + numtimelevs1 = CCTK_NumTimeLevelsFromVarI(EvolvedIndex); + numtimelevs2 = CCTK_NumTimeLevelsFromVarI(RHSIndex); + + if ( (numtimelevs1 < 0) || (numtimelevs2 < 0) ) + { + CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for variable index %i", EvolvedIndex); + CCTK_WARN(0, "The index passed does not correspond to a GF."); + } + + if (numtimelevs1 < 2) + { + CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for variable index %i name %s", EvolvedIndex, CCTK_VarName(EvolvedIndex)); + CCTK_WARN(0, "The GF passed only has one timelevel. It must have at least two."); + } + + varused = 0; + + for (index = 0; (index < MoLNumEvolvedComplexVariables)&&(!varused); index++) + { + varused = (EvolvedIndex == EvolvedComplexVariableIndex[index]); +#ifdef MOLDEBUG + printf("Registering %d. Checking index %d which is %d\n",EvolvedIndex, + index,EvolvedComplexVariableIndex[index]); +#endif + } + + if (varused) + { + + CCTK_VWarn(2,__LINE__,__FILE__,"MoL", + "The GF %s has already been registered as a complex evolved variable with RHS GF %s. The attempt to register with RHS GF %s will be ignored", + CCTK_VarName(EvolvedIndex), + CCTK_VarName(RHSComplexVariableIndex[index-1]), + CCTK_VarName(RHSIndex)); + + } + else + { + + EvolvedComplexVariableIndex[MoLNumEvolvedComplexVariables] = EvolvedIndex; + RHSComplexVariableIndex[MoLNumEvolvedComplexVariables] = RHSIndex; + + MoLNumEvolvedComplexVariables++; + + if (MoLNumEvolvedComplexVariables > MoL_Num_ComplexEvolved_Vars) + { + CCTK_WARN(0,"You have tried to register more evolved complex variables than the accumulator parameter MoL_Num_ComplexEvolved_Variables allows. Check that you are accumulating onto this parameter correctly"); + } + + } + + varused = 0; + + for (index = 0; (index < + MoLNumConstrainedComplexVariables)&&(!varused); + index++) + { + varused = (EvolvedIndex == ConstrainedComplexVariableIndex[index]); + } + + if (varused) + { + for (index = varused; index < MoLNumConstrainedComplexVariables-1; index++) + { + ConstrainedComplexVariableIndex[index] = + ConstrainedComplexVariableIndex[index+1]; + } + MoLNumConstrainedComplexVariables--; + } + + varused = 0; + + for (index = 0; (index < MoLNumSandRComplexVariables)&&(!varused); index++) + { + varused = (EvolvedIndex == SandRComplexVariableIndex[index]); + } + + if (varused) + { + for (index = varused; index < MoLNumSandRComplexVariables-1; index++) + { + SandRComplexVariableIndex[index] = SandRComplexVariableIndex[index+1]; + } + MoLNumSandRComplexVariables--; + } + + return 0; + +} + +CCTK_INT MoL_RegisterConstrainedComplex(CCTK_INT ConstrainedIndex) +{ + + DECLARE_CCTK_PARAMETERS; + + CCTK_INT numtimelevs, varused, evolved, index; + + if (!(CCTK_GroupTypeFromVarI(ConstrainedIndex)==CCTK_GF)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not a GF and so should not be registered with MoLRegisterConstrained.", + CCTK_VarName(ConstrainedIndex)); + } + + if (!(CCTK_VarTypeI(ConstrainedIndex)==CCTK_VARIABLE_COMPLEX)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not of type CCTK_COMPLEX and so should not be registered with MoLRegisterConstrainedComplex.", + CCTK_VarName(ConstrainedIndex)); + } + + numtimelevs = CCTK_NumTimeLevelsFromVarI(ConstrainedIndex); + + if (numtimelevs < 1) { + + CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for constrained complex variable index %i", ConstrainedIndex); + CCTK_WARN(0, "The index passed does not correspond to a GF."); + + } + else if (numtimelevs > 1) { + + varused = 0; + + for (evolved = 0; (evolved < MoLNumEvolvedComplexVariables)&&(!varused); evolved++) + { + varused = (EvolvedComplexVariableIndex[evolved] == ConstrainedIndex); + } + + for (evolved = 0; (evolved < + MoLNumConstrainedComplexVariables)&&(!varused); + evolved++) + { + varused = (ConstrainedComplexVariableIndex[evolved] == ConstrainedIndex); + } + + if (!varused) + { + ConstrainedComplexVariableIndex[MoLNumConstrainedComplexVariables] = ConstrainedIndex; + MoLNumConstrainedComplexVariables++; + + if (MoLNumConstrainedComplexVariables > + MoL_Num_ComplexConstrained_Vars) + { + CCTK_WARN(0,"You have tried to register more evolved complex variables than the accumulator parameter MoL_Num_ComplexEvolved_Variables allows. Check that you are accumulating onto this parameter correctly"); + } + + } + + varused = 0; + + for (evolved = 0; (evolved < + MoLNumSandRComplexVariables)&&(!varused); + evolved++) + { + varused = (SandRComplexVariableIndex[evolved] == ConstrainedIndex); + } + + if (varused) + { + for (index = evolved; index < MoLNumSandRComplexVariables-1; index++) + { + SandRComplexVariableIndex[index] = SandRComplexVariableIndex[index+1]; + } + MoLNumSandRComplexVariables--; + } + + } + else + { + + CCTK_VInfo(CCTK_THORNSTRING, + "MoL will not treat variable %s as a constrained complex variable at it has only one timelevel. This should not cause problems with the evolution.\n", + CCTK_VarName(ConstrainedIndex)); + + } + + return 0; + +} + +CCTK_INT MoL_RegisterSaveAndRestoreComplex(CCTK_INT SandRIndex) +{ + + DECLARE_CCTK_PARAMETERS; + + CCTK_INT numtimelevs, varused, evolved; + + if (!(CCTK_GroupTypeFromVarI(SandRIndex)==CCTK_GF)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not a GF and so should not be registered with MoLRegisterSaveAndRestore.", + CCTK_VarName(SandRIndex)); + } + + if (!(CCTK_VarTypeI(SandRIndex)==CCTK_VARIABLE_COMPLEX)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not of type CCTK_COMPLEX and so should not be registered with MoLRegisterSaveAndRestoreComplex.", + CCTK_VarName(SandRIndex)); + } + + numtimelevs = CCTK_NumTimeLevelsFromVarI(SandRIndex); + + if (numtimelevs < 1) { + + CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for save and restore complex variable index %i", SandRIndex); + CCTK_WARN(0, "The index passed does not correspond to a GF."); + + } + else if (numtimelevs > 1) { + + varused = 0; + + for (evolved = 0; (evolved < MoLNumEvolvedComplexVariables)&&(!varused); evolved++) + { + varused = (EvolvedComplexVariableIndex[evolved] == SandRIndex); + } + + for (evolved = 0; (evolved < + MoLNumConstrainedComplexVariables)&&(!varused); + evolved++) + { + varused = (ConstrainedComplexVariableIndex[evolved] == SandRIndex); + } + + for (evolved = 0; (evolved < + MoLNumSandRComplexVariables)&&(!varused); + evolved++) + { + varused = (SandRComplexVariableIndex[evolved] == SandRIndex); + } + + if (!varused) + { + SandRComplexVariableIndex[MoLNumSandRComplexVariables] = SandRIndex; + MoLNumSandRComplexVariables++; + + if (MoLNumSandRComplexVariables > MoL_Num_ComplexSaveAndRestore_Vars) + { + CCTK_WARN(0,"You have tried to register more evolved complex variables than the accumulator parameter MoL_Num_ComplexEvolved_Variables allows. Check that you are accumulating onto this parameter correctly"); + } + + } + + } + else + { + + CCTK_VInfo(CCTK_THORNSTRING, + "MoL will not treat variable %s as a save and restore complex variable at it has only one timelevel. This should not cause problems with the evolution.\n", + CCTK_VarName(SandRIndex)); + + } + + return 0; + +} + +CCTK_INT MoL_RegisterEvolvedComplexGroup(CCTK_INT EvolvedGroupIndex, + CCTK_INT RHSGroupIndex) +{ + + CCTK_INT EvolvedGroupFirstVar, RHSGroupFirstVar, GroupNumVars, retval; + CCTK_INT EvolvedVar, RHSVar; + + EvolvedGroupFirstVar = CCTK_FirstVarIndexI(EvolvedGroupIndex); + if (EvolvedGroupFirstVar < 0) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "Evolved complex group index %i is not a real group index.", + EvolvedGroupIndex); + } + + RHSGroupFirstVar = CCTK_FirstVarIndexI(RHSGroupIndex); + if (RHSGroupFirstVar < 0) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "RHS complex group index %d is not a real group index.", + RHSGroupIndex); + } + + GroupNumVars = CCTK_NumVarsInGroupI(EvolvedGroupIndex); + if (CCTK_NumVarsInGroupI(RHSGroupIndex) != GroupNumVars) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "There are a different number of variables in evolved complex group %d and RHS group %d.", EvolvedGroupIndex, RHSGroupIndex); + } + + retval = 0; + + for (EvolvedVar = EvolvedGroupFirstVar, RHSVar = RHSGroupFirstVar; + EvolvedVar < EvolvedGroupFirstVar + GroupNumVars; + EvolvedVar++, RHSVar++) + { + retval += MoL_RegisterEvolvedComplex(EvolvedVar, RHSVar); + } + + return retval; + +} + +CCTK_INT MoL_RegisterConstrainedComplexGroup(CCTK_INT ConstrainedGroupIndex) +{ + + CCTK_INT ConstrainedGroupFirstVar, GroupNumVars, retval; + CCTK_INT ConstrainedVar; + + ConstrainedGroupFirstVar = CCTK_FirstVarIndexI(ConstrainedGroupIndex); + if (ConstrainedGroupFirstVar < 0) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "Constrained complex group index %i is not a real group index.", + ConstrainedGroupIndex); + } + + GroupNumVars = CCTK_NumVarsInGroupI(ConstrainedGroupIndex); + + retval = 0; + + for (ConstrainedVar = ConstrainedGroupFirstVar; + ConstrainedVar < ConstrainedGroupFirstVar + GroupNumVars; + ConstrainedVar++) + { + retval += MoL_RegisterConstrainedComplex(ConstrainedVar); + } + + return retval; + +} + +CCTK_INT MoL_RegisterSaveAndRestoreComplexGroup(CCTK_INT SandRGroupIndex) +{ + + CCTK_INT SandRGroupFirstVar, GroupNumVars, retval; + CCTK_INT SandRVar; + + SandRGroupFirstVar = CCTK_FirstVarIndexI(SandRGroupIndex); + if (SandRGroupFirstVar < 0) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "Save and Restore complex group index %i is not a real group index.", + SandRGroupIndex); + } + + GroupNumVars = CCTK_NumVarsInGroupI(SandRGroupIndex); + + retval = 0; + + for (SandRVar = SandRGroupFirstVar; + SandRVar < SandRGroupFirstVar + GroupNumVars; + SandRVar++) + { + retval += MoL_RegisterSaveAndRestoreComplex(SandRVar); + } + + return retval; + +} + + +CCTK_INT MoL_RegisterEvolvedArray(CCTK_INT EvolvedIndex, CCTK_INT RHSIndex) +{ + + DECLARE_CCTK_PARAMETERS; + + CCTK_INT /* ierr, */ index, varused, numtimelevs1, numtimelevs2; + +#ifdef MOLDEBUG + printf("Arrived in MoLRegisterEvolvedArray \n"); + printf("The indexes are %d and %d.\n",EvolvedIndex, RHSIndex); + printf("These correspond to variables %s and %s.\n", + CCTK_VarName(EvolvedIndex),CCTK_VarName(RHSIndex)); + printf("The pointer to EvolvedVariableIndex: %p\n", + EvolvedArrayVariableIndex); +#endif + + if (!(CCTK_GroupTypeFromVarI(EvolvedIndex)==CCTK_ARRAY)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not a ARRAY and so should not be registered with MoLRegisterEvolved.", + CCTK_VarName(EvolvedIndex)); + } + + if (!(CCTK_GroupTypeFromVarI(RHSIndex)==CCTK_ARRAY)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The rhs variable %s is not a ARRAY and so should not be registered with MoLRegisterEvolved.", + CCTK_VarName(RHSIndex)); + } + + if (!(CCTK_VarTypeI(EvolvedIndex)==CCTK_VARIABLE_REAL)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not of type CCTK_REAL and so should not be registered with MoLRegisterEvolvedArray.", + CCTK_VarName(EvolvedIndex)); + } + + if (!(CCTK_VarTypeI(RHSIndex)==CCTK_VARIABLE_REAL)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The rhs variable %s is not of type CCTK_REAL and so should not be registered with MoLRegisterEvolvedArray.", + CCTK_VarName(RHSIndex)); + } + + numtimelevs1 = CCTK_NumTimeLevelsFromVarI(EvolvedIndex); + numtimelevs2 = CCTK_NumTimeLevelsFromVarI(RHSIndex); + + if ( (numtimelevs1 < 0) || (numtimelevs2 < 0) ) + { + CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for variable index %i", EvolvedIndex); + CCTK_WARN(0, "The index passed does not correspond to an array."); + } + + if (numtimelevs1 < 2) + { + CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for variable index %i name %s", EvolvedIndex, CCTK_VarName(EvolvedIndex)); + CCTK_WARN(0, "The ARRAY passed only has one timelevel. It must have at least two."); + } + + varused = 0; + + for (index = 0; (index < MoLNumEvolvedArrayVariables)&&(!varused); index++) + { + varused = (EvolvedIndex == EvolvedArrayVariableIndex[index]); +#ifdef MOLDEBUG + printf("Registering %d. Checking index %d which is %d\n",EvolvedIndex, + index,EvolvedArrayVariableIndex[index]); +#endif + } + + if (varused) + { + + CCTK_VWarn(2,__LINE__,__FILE__,"MoL", + "The array %s has already been registered as a array evolved variable with RHS array %s. The attempt to register with RHS array %s will be ignored", + CCTK_VarName(EvolvedIndex), + CCTK_VarName(RHSArrayVariableIndex[index-1]), + CCTK_VarName(RHSIndex)); + + } + else + { + + EvolvedArrayVariableIndex[MoLNumEvolvedArrayVariables] = EvolvedIndex; + RHSArrayVariableIndex[MoLNumEvolvedArrayVariables] = RHSIndex; + + MoLNumEvolvedArrayVariables++; + + if (MoLNumEvolvedArrayVariables > MoL_Num_ArrayEvolved_Vars) + { + CCTK_WARN(0,"You have tried to register more evolved array variables than the accumulator parameter MoL_Num_ArrayEvolved_Variables allows. Check that you are accumulating onto this parameter correctly"); + } + + } + + varused = 0; + + for (index = 0; (index < + MoLNumConstrainedArrayVariables)&&(!varused); + index++) + { + varused = (EvolvedIndex == ConstrainedArrayVariableIndex[index]); + } + + if (varused) + { + for (index = varused; index < MoLNumConstrainedArrayVariables-1; index++) + { + ConstrainedArrayVariableIndex[index] = + ConstrainedArrayVariableIndex[index+1]; + } + MoLNumConstrainedArrayVariables--; + } + + varused = 0; + + for (index = 0; (index < MoLNumSandRArrayVariables)&&(!varused); index++) + { + varused = (EvolvedIndex == SandRArrayVariableIndex[index]); + } + + if (varused) + { + for (index = varused; index < MoLNumSandRArrayVariables-1; index++) + { + SandRArrayVariableIndex[index] = SandRArrayVariableIndex[index+1]; + } + MoLNumSandRArrayVariables--; + } + + return 0; + +} + +CCTK_INT MoL_RegisterConstrainedArray(CCTK_INT ConstrainedIndex) +{ + + DECLARE_CCTK_PARAMETERS; + + CCTK_INT numtimelevs, varused, evolved, index; + + if (!(CCTK_GroupTypeFromVarI(ConstrainedIndex)==CCTK_ARRAY)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not a ARRAY and so should not be registered with MoLRegisterConstrained.", + CCTK_VarName(ConstrainedIndex)); + } + + if (!(CCTK_VarTypeI(ConstrainedIndex)==CCTK_VARIABLE_REAL)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not of type CCTK_REAL and so should not be registered with MoLRegisterConstrainedArray.", + CCTK_VarName(ConstrainedIndex)); + } + + numtimelevs = CCTK_NumTimeLevelsFromVarI(ConstrainedIndex); + + if (numtimelevs < 1) { + + CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for constrained array variable index %i", ConstrainedIndex); + CCTK_WARN(0, "The index passed does not correspond to a array."); + + } + else if (numtimelevs > 1) { + + varused = 0; + + for (evolved = 0; (evolved < MoLNumEvolvedArrayVariables)&&(!varused); evolved++) + { + varused = (EvolvedArrayVariableIndex[evolved] == ConstrainedIndex); + } + + for (evolved = 0; (evolved < + MoLNumConstrainedArrayVariables)&&(!varused); + evolved++) + { + varused = (ConstrainedArrayVariableIndex[evolved] == ConstrainedIndex); + } + + if (!varused) + { + ConstrainedArrayVariableIndex[MoLNumConstrainedArrayVariables] = ConstrainedIndex; + MoLNumConstrainedArrayVariables++; + + if (MoLNumConstrainedArrayVariables > + MoL_Num_ArrayConstrained_Vars) + { + CCTK_WARN(0,"You have tried to register more evolved array variables than the accumulator parameter MoL_Num_ArrayEvolved_Variables allows. Check that you are accumulating onto this parameter correctly"); + } + + } + + varused = 0; + + for (evolved = 0; (evolved < + MoLNumSandRArrayVariables)&&(!varused); + evolved++) + { + varused = (SandRArrayVariableIndex[evolved] == ConstrainedIndex); + } + + if (varused) + { + for (index = evolved; index < MoLNumSandRArrayVariables-1; index++) + { + SandRArrayVariableIndex[index] = SandRArrayVariableIndex[index+1]; + } + MoLNumSandRArrayVariables--; + } + + } + else + { + + CCTK_VInfo(CCTK_THORNSTRING, + "MoL will not treat variable %s as a constrained array variable at it has only one timelevel. This should not cause problems with the evolution.\n", + CCTK_VarName(ConstrainedIndex)); + + } + + return 0; + +} + +CCTK_INT MoL_RegisterSaveAndRestoreArray(CCTK_INT SandRIndex) +{ + + DECLARE_CCTK_PARAMETERS; + + CCTK_INT numtimelevs, varused, evolved; + + if (!(CCTK_GroupTypeFromVarI(SandRIndex)==CCTK_ARRAY)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not a ARRAY and so should not be registered with MoLRegisterSaveAndRestore.", + CCTK_VarName(SandRIndex)); + } + + if (!(CCTK_VarTypeI(SandRIndex)==CCTK_VARIABLE_REAL)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not of type CCTK_REAL and so should not be registered with MoLRegisterSaveAndRestoreArray.", + CCTK_VarName(SandRIndex)); + } + + numtimelevs = CCTK_NumTimeLevelsFromVarI(SandRIndex); + + if (numtimelevs < 1) { + + CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for save and restore array variable index %i", SandRIndex); + CCTK_WARN(0, "The index passed does not correspond to a GF."); + + } + else if (numtimelevs > 1) { + + varused = 0; + + for (evolved = 0; (evolved < MoLNumEvolvedArrayVariables)&&(!varused); evolved++) + { + varused = (EvolvedArrayVariableIndex[evolved] == SandRIndex); + } + + for (evolved = 0; (evolved < + MoLNumConstrainedArrayVariables)&&(!varused); + evolved++) + { + varused = (ConstrainedArrayVariableIndex[evolved] == SandRIndex); + } + + for (evolved = 0; (evolved < + MoLNumSandRArrayVariables)&&(!varused); + evolved++) + { + varused = (SandRArrayVariableIndex[evolved] == SandRIndex); + } + + if (!varused) + { + SandRArrayVariableIndex[MoLNumSandRArrayVariables] = SandRIndex; + MoLNumSandRArrayVariables++; + + if (MoLNumSandRArrayVariables > MoL_Num_ArraySaveAndRestore_Vars) + { + CCTK_WARN(0,"You have tried to register more evolved array variables than the accumulator parameter MoL_Num_ArrayEvolved_Variables allows. Check that you are accumulating onto this parameter correctly"); + } + + } + + } + else + { + + CCTK_VInfo(CCTK_THORNSTRING, + "MoL will not treat variable %s as a save and restore array variable at it has only one timelevel. This should not cause problems with the evolution.\n", + CCTK_VarName(SandRIndex)); + + } + + return 0; + +} + +CCTK_INT MoL_RegisterEvolvedArrayGroup(CCTK_INT EvolvedGroupIndex, + CCTK_INT RHSGroupIndex) +{ + + CCTK_INT EvolvedGroupFirstVar, RHSGroupFirstVar, GroupNumVars, retval; + CCTK_INT EvolvedVar, RHSVar; + + EvolvedGroupFirstVar = CCTK_FirstVarIndexI(EvolvedGroupIndex); + if (EvolvedGroupFirstVar < 0) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "Evolved array group index %i is not a real group index.", + EvolvedGroupIndex); + } + + RHSGroupFirstVar = CCTK_FirstVarIndexI(RHSGroupIndex); + if (RHSGroupFirstVar < 0) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "RHS array group index %d is not a real group index.", + RHSGroupIndex); + } + + GroupNumVars = CCTK_NumVarsInGroupI(EvolvedGroupIndex); + if (CCTK_NumVarsInGroupI(RHSGroupIndex) != GroupNumVars) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "There are a different number of variables in evolved array group %d and RHS group %d.", EvolvedGroupIndex, RHSGroupIndex); + } + + retval = 0; + + for (EvolvedVar = EvolvedGroupFirstVar, RHSVar = RHSGroupFirstVar; + EvolvedVar < EvolvedGroupFirstVar + GroupNumVars; + EvolvedVar++, RHSVar++) + { + retval += MoL_RegisterEvolvedArray(EvolvedVar, RHSVar); + } + + return retval; + +} + +CCTK_INT MoL_RegisterConstrainedArrayGroup(CCTK_INT ConstrainedGroupIndex) +{ + + CCTK_INT ConstrainedGroupFirstVar, GroupNumVars, retval; + CCTK_INT ConstrainedVar; + + ConstrainedGroupFirstVar = CCTK_FirstVarIndexI(ConstrainedGroupIndex); + if (ConstrainedGroupFirstVar < 0) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "Constrained array group index %i is not a real group index.", + ConstrainedGroupIndex); + } + + GroupNumVars = CCTK_NumVarsInGroupI(ConstrainedGroupIndex); + + retval = 0; + + for (ConstrainedVar = ConstrainedGroupFirstVar; + ConstrainedVar < ConstrainedGroupFirstVar + GroupNumVars; + ConstrainedVar++) + { + retval += MoL_RegisterConstrainedArray(ConstrainedVar); + } + + return retval; + +} + +CCTK_INT MoL_RegisterSaveAndRestoreArrayGroup(CCTK_INT SandRGroupIndex) +{ + + CCTK_INT SandRGroupFirstVar, GroupNumVars, retval; + CCTK_INT SandRVar; + + SandRGroupFirstVar = CCTK_FirstVarIndexI(SandRGroupIndex); + if (SandRGroupFirstVar < 0) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "Save and Restore array group index %i is not a real group index.", + SandRGroupIndex); + } + + GroupNumVars = CCTK_NumVarsInGroupI(SandRGroupIndex); + + retval = 0; + + for (SandRVar = SandRGroupFirstVar; + SandRVar < SandRGroupFirstVar + GroupNumVars; + SandRVar++) + { + retval += MoL_RegisterSaveAndRestoreArray(SandRVar); + } + + return retval; + +} + + +CCTK_INT MoL_RegisterEvolvedComplexArray(CCTK_INT EvolvedIndex, + CCTK_INT RHSIndex) +{ + + DECLARE_CCTK_PARAMETERS; + + CCTK_INT /* ierr, */ index, varused, numtimelevs1, numtimelevs2; + +#ifdef MOLDEBUG + printf("Arrived in MoLRegisterEvolvedComplexArray \n"); + printf("The indexes are %d and %d.\n",EvolvedIndex, RHSIndex); + printf("These correspond to variables %s and %s.\n", + CCTK_VarName(EvolvedIndex),CCTK_VarName(RHSIndex)); + printf("The pointer to EvolvedVariableIndex: %p\n", + EvolvedComplexArrayVariableIndex); +#endif + + if (!(CCTK_GroupTypeFromVarI(EvolvedIndex)==CCTK_ARRAY)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not a ARRAY and so should not be registered with MoLRegisterEvolved.", + CCTK_VarName(EvolvedIndex)); + } + + if (!(CCTK_GroupTypeFromVarI(RHSIndex)==CCTK_ARRAY)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The rhs variable %s is not a ARRAY and so should not be registered with MoLRegisterEvolved.", + CCTK_VarName(RHSIndex)); + } + + if (!(CCTK_VarTypeI(EvolvedIndex)==CCTK_VARIABLE_COMPLEX)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not of type CCTK_COMPLEX and so should not be registered with MoLRegisterEvolvedArrayComplex.", + CCTK_VarName(EvolvedIndex)); + } + + if (!(CCTK_VarTypeI(RHSIndex)==CCTK_VARIABLE_COMPLEX)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The rhs variable %s is not of type CCTK_COMPLEX and so should not be registered with MoLRegisterEvolvedArrayComplex.", + CCTK_VarName(RHSIndex)); + } + + numtimelevs1 = CCTK_NumTimeLevelsFromVarI(EvolvedIndex); + numtimelevs2 = CCTK_NumTimeLevelsFromVarI(RHSIndex); + + if ( (numtimelevs1 < 0) || (numtimelevs2 < 0) ) + { + CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for variable index %i", EvolvedIndex); + CCTK_WARN(0, "The index passed does not correspond to a GF."); + } + + if (numtimelevs1 < 2) + { + CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for variable index %i name %s", EvolvedIndex, CCTK_VarName(EvolvedIndex)); + CCTK_WARN(0, "The GF passed only has one timelevel. It must have at least two."); + } + + varused = 0; + + for (index = 0; (index < MoLNumEvolvedComplexArrayVariables)&&(!varused); index++) + { + varused = (EvolvedIndex == EvolvedComplexArrayVariableIndex[index]); +#ifdef MOLDEBUG + printf("Registering %d. Checking index %d which is %d\n",EvolvedIndex, + index,EvolvedComplexArrayVariableIndex[index]); +#endif + } + + if (varused) + { + + CCTK_VWarn(2,__LINE__,__FILE__,"MoL", + "The GF %s has already been registered as a complex array evolved variable with RHS GF %s. The attempt to register with RHS GF %s will be ignored", + CCTK_VarName(EvolvedIndex), + CCTK_VarName(RHSComplexArrayVariableIndex[index-1]), + CCTK_VarName(RHSIndex)); + + } + else + { + + EvolvedComplexArrayVariableIndex[MoLNumEvolvedComplexArrayVariables] = EvolvedIndex; + RHSComplexArrayVariableIndex[MoLNumEvolvedComplexArrayVariables] = RHSIndex; + + MoLNumEvolvedComplexArrayVariables++; + + if (MoLNumEvolvedComplexArrayVariables > MoL_Num_ComplexArrayEvolved_Vars) + { + CCTK_WARN(0,"You have tried to register more evolved complex array variables than the accumulator parameter MoL_Num_ComplexArrayEvolved_Variables allows. Check that you are accumulating onto this parameter correctly"); + } + + } + + varused = 0; + + for (index = 0; (index < + MoLNumConstrainedComplexArrayVariables)&&(!varused); + index++) + { + varused = (EvolvedIndex == ConstrainedComplexArrayVariableIndex[index]); + } + + if (varused) + { + for (index = varused; index < MoLNumConstrainedComplexArrayVariables-1; index++) + { + ConstrainedComplexArrayVariableIndex[index] = + ConstrainedComplexArrayVariableIndex[index+1]; + } + MoLNumConstrainedComplexArrayVariables--; + } + + varused = 0; + + for (index = 0; (index < MoLNumSandRComplexArrayVariables)&&(!varused); index++) + { + varused = (EvolvedIndex == SandRComplexArrayVariableIndex[index]); + } + + if (varused) + { + for (index = varused; index < MoLNumSandRComplexArrayVariables-1; index++) + { + SandRComplexArrayVariableIndex[index] = SandRComplexArrayVariableIndex[index+1]; + } + MoLNumSandRComplexArrayVariables--; + } + + return 0; + +} + +CCTK_INT MoL_RegisterConstrainedComplexArray(CCTK_INT ConstrainedIndex) +{ + + DECLARE_CCTK_PARAMETERS; + + CCTK_INT numtimelevs, varused, evolved, index; + + if (!(CCTK_GroupTypeFromVarI(ConstrainedIndex)==CCTK_ARRAY)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not a ARRAY and so should not be registered with MoLRegisterConstrained.", + CCTK_VarName(ConstrainedIndex)); + } + + if (!(CCTK_VarTypeI(ConstrainedIndex)==CCTK_VARIABLE_COMPLEX)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not of type CCTK_COMPLEX and so should not be registered with MoLRegisterConstrainedArrayComplex.", + CCTK_VarName(ConstrainedIndex)); + } + + numtimelevs = CCTK_NumTimeLevelsFromVarI(ConstrainedIndex); + + if (numtimelevs < 1) { + + CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for constrained complex array variable index %i", ConstrainedIndex); + CCTK_WARN(0, "The index passed does not correspond to a GF."); + + } + else if (numtimelevs > 1) { + + varused = 0; + + for (evolved = 0; (evolved < MoLNumEvolvedComplexArrayVariables)&&(!varused); evolved++) + { + varused = (EvolvedComplexArrayVariableIndex[evolved] == ConstrainedIndex); + } + + for (evolved = 0; (evolved < + MoLNumConstrainedComplexArrayVariables)&&(!varused); + evolved++) + { + varused = (ConstrainedComplexArrayVariableIndex[evolved] == ConstrainedIndex); + } + + if (!varused) + { + ConstrainedComplexArrayVariableIndex[MoLNumConstrainedComplexArrayVariables] = ConstrainedIndex; + MoLNumConstrainedComplexArrayVariables++; + + if (MoLNumConstrainedComplexArrayVariables > + MoL_Num_ComplexArrayConstrained_Vars) + { + CCTK_WARN(0,"You have tried to register more evolved complex array variables than the accumulator parameter MoL_Num_ComplexArrayEvolved_Variables allows. Check that you are accumulating onto this parameter correctly"); + } + + } + + varused = 0; + + for (evolved = 0; (evolved < + MoLNumSandRComplexArrayVariables)&&(!varused); + evolved++) + { + varused = (SandRComplexArrayVariableIndex[evolved] == ConstrainedIndex); + } + + if (varused) + { + for (index = evolved; index < MoLNumSandRComplexArrayVariables-1; index++) + { + SandRComplexArrayVariableIndex[index] = SandRComplexArrayVariableIndex[index+1]; + } + MoLNumSandRComplexArrayVariables--; + } + + } + else + { + + CCTK_VInfo(CCTK_THORNSTRING, + "MoL will not treat variable %s as a constrained complex array variable at it has only one timelevel. This should not cause problems with the evolution.\n", + CCTK_VarName(ConstrainedIndex)); + + } + + return 0; + +} + +CCTK_INT MoL_RegisterSaveAndRestoreComplexArray(CCTK_INT SandRIndex) +{ + + DECLARE_CCTK_PARAMETERS; + + CCTK_INT numtimelevs, varused, evolved; + + if (!(CCTK_GroupTypeFromVarI(SandRIndex)==CCTK_ARRAY)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not a ARRAY and so should not be registered with MoLRegisterSaveAndRestore.", + CCTK_VarName(SandRIndex)); + } + + if (!(CCTK_VarTypeI(SandRIndex)==CCTK_VARIABLE_COMPLEX)) + { + CCTK_VWarn(0,__LINE__,__FILE__,"MoL","The variable %s is not of type CCTK_COMPLEX and so should not be registered with MoLRegisterSaveAndRestoreArrayComplex.", + CCTK_VarName(SandRIndex)); + } + + numtimelevs = CCTK_NumTimeLevelsFromVarI(SandRIndex); + + if (numtimelevs < 1) { + + CCTK_VWarn(1,__LINE__,__FILE__,"MoL","Warning for save and restore complex array variable index %i", SandRIndex); + CCTK_WARN(0, "The index passed does not correspond to a GF."); + + } + else if (numtimelevs > 1) { + + varused = 0; + + for (evolved = 0; (evolved < MoLNumEvolvedComplexArrayVariables)&&(!varused); evolved++) + { + varused = (EvolvedComplexArrayVariableIndex[evolved] == SandRIndex); + } + + for (evolved = 0; (evolved < + MoLNumConstrainedComplexArrayVariables)&&(!varused); + evolved++) + { + varused = (ConstrainedComplexArrayVariableIndex[evolved] == SandRIndex); + } + + for (evolved = 0; (evolved < + MoLNumSandRComplexArrayVariables)&&(!varused); + evolved++) + { + varused = (SandRComplexArrayVariableIndex[evolved] == SandRIndex); + } + + if (!varused) + { + SandRComplexArrayVariableIndex[MoLNumSandRComplexArrayVariables] = SandRIndex; + MoLNumSandRComplexArrayVariables++; + + if (MoLNumSandRComplexArrayVariables > MoL_Num_ComplexArraySaveAndRestore_Vars) + { + CCTK_WARN(0,"You have tried to register more evolved complex array variables than the accumulator parameter MoL_Num_ComplexArrayEvolved_Variables allows. Check that you are accumulating onto this parameter correctly"); + } + + } + + } + else + { + + CCTK_VInfo(CCTK_THORNSTRING, + "MoL will not treat variable %s as a save and restore complex array variable at it has only one timelevel. This should not cause problems with the evolution.\n", + CCTK_VarName(SandRIndex)); + + } + + return 0; + +} + +CCTK_INT MoL_RegisterEvolvedComplexArrayGroup(CCTK_INT EvolvedGroupIndex, + CCTK_INT RHSGroupIndex) +{ + + CCTK_INT EvolvedGroupFirstVar, RHSGroupFirstVar, GroupNumVars, retval; + CCTK_INT EvolvedVar, RHSVar; + + EvolvedGroupFirstVar = CCTK_FirstVarIndexI(EvolvedGroupIndex); + if (EvolvedGroupFirstVar < 0) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "Evolved complex array group index %i is not a real group index.", + EvolvedGroupIndex); + } + + RHSGroupFirstVar = CCTK_FirstVarIndexI(RHSGroupIndex); + if (RHSGroupFirstVar < 0) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "RHS complex array group index %d is not a real group index.", + RHSGroupIndex); + } + + GroupNumVars = CCTK_NumVarsInGroupI(EvolvedGroupIndex); + if (CCTK_NumVarsInGroupI(RHSGroupIndex) != GroupNumVars) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "There are a different number of variables in evolved complex array group %d and RHS group %d.", EvolvedGroupIndex, RHSGroupIndex); + } + + retval = 0; + + for (EvolvedVar = EvolvedGroupFirstVar, RHSVar = RHSGroupFirstVar; + EvolvedVar < EvolvedGroupFirstVar + GroupNumVars; + EvolvedVar++, RHSVar++) + { + retval += MoL_RegisterEvolvedComplexArray(EvolvedVar, RHSVar); + } + + return retval; + +} + +CCTK_INT MoL_RegisterConstrainedComplexArrayGroup(CCTK_INT ConstrainedGroupIndex) +{ + + CCTK_INT ConstrainedGroupFirstVar, GroupNumVars, retval; + CCTK_INT ConstrainedVar; + + ConstrainedGroupFirstVar = CCTK_FirstVarIndexI(ConstrainedGroupIndex); + if (ConstrainedGroupFirstVar < 0) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "Constrained complex array group index %i is not a real group index.", + ConstrainedGroupIndex); + } + + GroupNumVars = CCTK_NumVarsInGroupI(ConstrainedGroupIndex); + + retval = 0; + + for (ConstrainedVar = ConstrainedGroupFirstVar; + ConstrainedVar < ConstrainedGroupFirstVar + GroupNumVars; + ConstrainedVar++) + { + retval += MoL_RegisterConstrainedComplexArray(ConstrainedVar); + } + + return retval; + +} + +CCTK_INT MoL_RegisterSaveAndRestoreComplexArrayGroup(CCTK_INT SandRGroupIndex) +{ + + CCTK_INT SandRGroupFirstVar, GroupNumVars, retval; + CCTK_INT SandRVar; + + SandRGroupFirstVar = CCTK_FirstVarIndexI(SandRGroupIndex); + if (SandRGroupFirstVar < 0) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "Save and Restore complex array group index %i is not a real group index.", + SandRGroupIndex); + } + + GroupNumVars = CCTK_NumVarsInGroupI(SandRGroupIndex); + + retval = 0; + + for (SandRVar = SandRGroupFirstVar; + SandRVar < SandRGroupFirstVar + GroupNumVars; + SandRVar++) + { + retval += MoL_RegisterSaveAndRestoreComplexArray(SandRVar); + } + + return retval; + +} + + /* Old function names. Just calls the new version. Included for compatibility + Now removed. */ +/* CCTK_INT MoL_RegisterVar(CCTK_INT molvarindex,CCTK_INT molrhsvarindex) { return MoL_RegisterEvolved(molvarindex, molrhsvarindex); @@ -491,12 +2359,15 @@ CCTK_INT MoL_ChangeVarToNone(CCTK_INT removeindex) { return MoL_ChangeToNone(removeindex); } +*/ /* Fortran wrappers for the above functions. Should be replaced by using function aliasing eventually. + Now removed. */ +/* void CCTK_FCALL CCTK_FNAME(MoL_RegisterEvolved)(int *ierr, CCTK_INT *EvolvedIndex, CCTK_INT *RHSIndex) @@ -518,9 +2389,12 @@ void CCTK_FCALL CCTK_FNAME(MoL_RegisterSaveAndRestore)(int *ierr, *ierr = MoL_RegisterSaveAndRestore(*EvolvedIndex); return; } +*/ /* And for MoL compatibility... */ +/* Now removed */ +/* void CCTK_FCALL CCTK_FNAME(MoL_RegisterVar)(int *ierr, CCTK_INT *molvarindex, CCTK_INT *molrhsvarindex) @@ -593,6 +2467,7 @@ void CCTK_FCALL CCTK_FNAME(MoL_ChangeVarToNone)(int *ierr, *ierr = MoL_ChangeVarToNone(*removeindex); return; } +*/ /******************************************************************** ********************* Local Routines ************************* diff --git a/src/SandR.c b/src/SandR.c index ea419ff..586b31f 100644 --- a/src/SandR.c +++ b/src/SandR.c @@ -8,6 +8,8 @@ @version $Header$ @@*/ +#include <string.h> + #include "cctk.h" #include "cctk_Arguments.h" #include "cctk_Parameters.h" @@ -72,10 +74,11 @@ void MoL_RestoreSandR(CCTK_ARGUMENTS) DECLARE_CCTK_ARGUMENTS; DECLARE_CCTK_PARAMETERS; - CCTK_INT index, var; + CCTK_INT /* index, */ var; CCTK_INT totalsize; CCTK_INT vectorstart; CCTK_REAL *SandRDataArray; + CCTK_COMPLEX *SandRComplexDataArray; totalsize = cctk_lsh[0] * cctk_lsh[1] * cctk_lsh[2]; @@ -96,6 +99,18 @@ void MoL_RestoreSandR(CCTK_ARGUMENTS) memcpy(SandRDataArray, &SandRScratchSpace[vectorstart], totalsize * sizeof(CCTK_REAL)); } + + for (var = 0; var < MoLNumSandRComplexVariables; var++) + { + + SandRComplexDataArray = (CCTK_COMPLEX *)CCTK_VarDataPtrI(cctkGH, 0, + SandRComplexVariableIndex[var]); + + vectorstart = var * totalsize; + + memcpy(SandRComplexDataArray, &ComplexSandRScratchSpace[vectorstart], + totalsize * sizeof(CCTK_COMPLEX)); + } return; diff --git a/src/SetTime.c b/src/SetTime.c index 71d2f61..aeeee77 100644 --- a/src/SetTime.c +++ b/src/SetTime.c @@ -9,6 +9,8 @@ @version $Header$ @@*/ +#include <stdlib.h> + #include "cctk.h" #include "cctk_Arguments.h" #include "cctk_Parameters.h" diff --git a/src/Startup.c b/src/Startup.c index 3839de6..01ff6d6 100644 --- a/src/Startup.c +++ b/src/Startup.c @@ -32,6 +32,36 @@ CCTK_INT MoLNumEvolvedVariables = 0; CCTK_INT MoLNumConstrainedVariables = 0; CCTK_INT MoLNumSandRVariables = 0; + +CCTK_INT *EvolvedComplexVariableIndex = NULL; +CCTK_INT *RHSComplexVariableIndex = NULL; +CCTK_INT *ConstrainedComplexVariableIndex = NULL; +CCTK_INT *SandRComplexVariableIndex = NULL; + +CCTK_INT MoLNumEvolvedComplexVariables = 0; +CCTK_INT MoLNumConstrainedComplexVariables = 0; +CCTK_INT MoLNumSandRComplexVariables = 0; + + +CCTK_INT *EvolvedArrayVariableIndex = NULL; +CCTK_INT *RHSArrayVariableIndex = NULL; +CCTK_INT *ConstrainedArrayVariableIndex = NULL; +CCTK_INT *SandRArrayVariableIndex = NULL; + +CCTK_INT MoLNumEvolvedArrayVariables = 0; +CCTK_INT MoLNumConstrainedArrayVariables = 0; +CCTK_INT MoLNumSandRArrayVariables = 0; + + +CCTK_INT *EvolvedComplexArrayVariableIndex = NULL; +CCTK_INT *RHSComplexArrayVariableIndex = NULL; +CCTK_INT *ConstrainedComplexArrayVariableIndex = NULL; +CCTK_INT *SandRComplexArrayVariableIndex = NULL; + +CCTK_INT MoLNumEvolvedComplexArrayVariables = 0; +CCTK_INT MoLNumConstrainedComplexArrayVariables = 0; +CCTK_INT MoLNumSandRComplexArrayVariables = 0; + /******************************************************************** ********************* Local Data Types *********************** ********************************************************************/ |