| { |
| "thorn_name": "CactusNumerical/SpaceMask", |
| "url": "https://bitbucket.org/cactuscode/cactusnumerical.git", |
| "configuration": "# Configuration definition for thorn SpaceMask\n# $Header$\n\nPROVIDES SpaceMask\n{\n SCRIPT\n LANG\n}\n\nREQUIRES CartGrid3D\n", |
| "interface": "# Interface definition for thorn SpaceMask\n# $Header$\n\nimplements: SpaceMask\ninherits: grid\n\nUSES INCLUDE: Symmetry.h\n\n# our header file \"SpaceMask.h\" may be #included by other thorns\nINCLUDE HEADER: SpaceMask.h in SpaceMask.h\n\npublic:\n\nCCTK_INT space_mask_group type=GF tags='tensortypealias=\"Scalar\" Prolongation=\"None\"'\n{\n space_mask\n}\n\n#\n# The following emask GF is kept for the sake of compatibility with\n# the existing excision thorns. Once these are translated to the new\n# mask, this function will disappear. Please don't use it for\n# anything.\n#\nreal mask type = GF tags='tensortypealias=\"Scalar\" Prolongation=\"None\"'\n{\n emask\n} \"Mask\"\n\n", |
| "param": "# Parameter definitions for thorn SpaceMask\n# $Header$\n\nrestricted:\n\nBOOLEAN use_mask \"Turn on storage for mask?\"\n{\n} \"no\"\n", |
| "schedule": "# Schedule definitions for thorn SpaceMask\n# $Header$\n\nif (use_mask)\n{\n STORAGE: space_mask_group\n\n schedule MaskZero at CCTK_BASEGRID\n {\n LANG: C\n WRITES: SPACEMASK::space_mask(everywhere)\n } \"Initialise mask to zero\"\n\n schedule MaskSym at CCTK_WRAGH\n {\n LANG: C\n OPTIONS: global\n } \"Set grid symmetries for mask\"\n\n#Initialize the mask again for mesh refinement\n schedule MaskZero at CCTK_POSTREGRIDINITIAL\n {\n LANG: C\n WRITES: SPACEMASK::space_mask(everywhere)\n } \"Initialise mask to zero\"\n\n schedule MaskZero at CCTK_POSTREGRID\n {\n LANG: C\n WRITES: SPACEMASK::space_mask(everywhere)\n } \"Initialise mask to zero\"\n\n #\n # The following is for compatibility with current excision routines,\n # and will be removed once they are up-to-date with the new mask\n # scheme.\n #\n STORAGE: mask\n schedule MaskSym_emask at CCTK_WRAGH\n {\n LANG: C\n OPTIONS: global\n } \"Set grid symmetries for emask (compatibility mode)\"\n\n schedule MaskOne at CCTK_BASEGRID\n {\n LANG: C\n WRITES: SPACEMASK::emask(everywhere)\n } \"Set old style mask to one\"\n\n schedule CheckMask at CCTK_POSTSTEP\n {\n LANG: C\n READS: SPACEMASK::emask(everywhere)\n } \"Ensure that all mask values are legal\"\n\n#Initialize the mask again for mesh refinement\n schedule MaskOne at CCTK_POSTREGRIDINITIAL\n {\n LANG: C\n WRITES: SPACEMASK::emask(everywhere)\n } \"Set mask to one\"\n\n schedule MaskOne at CCTK_POSTREGRID\n {\n LANG: C\n WRITES: SPACEMASK::emask(everywhere)\n } \"Set mask to one\"\n\n}\n", |
| "src": { |
| "make.code.defn": "# Main make.code.defn file for thorn SpaceMask\n# $Header$\n\n# Source files in this directory\nSRCS = MaskInit.c MaskUtils.c\n\n# Subdirectories containing source files\nSUBDIRS = \n\n", |
| "MaskUtils.c": "/*@@\n @file MaskUtils.c\n @date October 2002\n @author Denis Pollney\n @desc\n Utilities for registering/setting/checking the mask.\n @desc\n @version $Header$\n@@*/\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"cctk.h\"\n#include \"cctk_FortranString.h\"\n\n#include \"SpaceMask.h\"\n\nstatic const char* rcsid = \"$Header$\";\n\nCCTK_FILEVERSION(CACTUSEINSTEIN_SPACEMASK_MaskUtils_c);\n\nSpaceMask_Registry* spacemask_registry = NULL;\n\n/* prototypes for functions local to this file */\nstatic\n int SpaceMask_get_bit_nbr(int nstates);\nstatic\n CCTK_INT SpaceMask_get_free_bits(int nbits);\nstatic\n CCTK_INT* SpaceMask_determine_state_mask(CCTK_INT allocated_bits,\n int nstates);\nstatic\n SpaceMask_State* SpaceMask_setup_new_state(CCTK_INT state_mask,\n const char* name);\nstatic\n SpaceMask_Type*\n SpaceMask_setup_new_type(CCTK_INT new_bits, const char* type_name,\n int nstates, const char* const state_list[], \n const CCTK_INT state_mask[]);\nstatic\n void SpaceMask_append_type_to_registry(SpaceMask_Type* new_type);\n\n/* prototypes for Fortran wrapper functions defined in this file */\nvoid CCTK_FCALL CCTK_FNAME(SpaceMask_GetTypeBits)(CCTK_INT* type_bits,\n ONE_FORTSTRING_ARG);\nvoid CCTK_FCALL CCTK_FNAME(SpaceMask_GetStateBits)(CCTK_INT* state_bits,\n TWO_FORTSTRING_ARG);\nvoid CCTK_FCALL CCTK_FNAME(SpaceMask_SetState)(CCTK_INT* mask,\n CCTK_INT* point, TWO_FORTSTRING_ARG);\nvoid CCTK_FCALL CCTK_FNAME(SpaceMask_CheckState)(int* retval,\n CCTK_INT* mask,\n CCTK_INT* point,\n TWO_FORTSTRING_ARG);\n\n/*@@\n @routine SpaceMask_get_bit_nbr\n @author Denis Pollney\n @date 15 October 2002\n @desc \n Return the number of bits required to represent a given number.\n Cheesy divide-by-two method, maybe something else is quicker.\n @enddesc \n@@*/\nstatic \nint\nSpaceMask_get_bit_nbr(int nstates)\n{\n int bstates;\n int bit_nbr;\n\n bstates = nstates-1;\n\n for (bit_nbr=0; bstates>0; ++bit_nbr)\n bstates /= 2;\n\n return bit_nbr;\n}\n\n/*@@\n @routine SpaceMask_get_free_bits\n @author Denis Pollney\n @date 15 October 2002\n @desc \n Determine the mask bits which have not yet been allocated.\n The return value is a bitmask with the requested number of\n free bits set to 1. If there are not enough free bits left\n to satisfy the request, stop with an error.\n @enddesc \n@@*/\nstatic\nCCTK_INT\nSpaceMask_get_free_bits(int nbits)\n{\n CCTK_INT used_bits;\n CCTK_INT new_bits;\n int i;\n int j;\n int n;\n\n used_bits = 0;\n if (spacemask_registry != NULL)\n {\n for (i=0; i<spacemask_registry->ntypes; ++i)\n used_bits |= spacemask_registry->type_list[i]->bitmask;\n }\n\n n=1;\n new_bits = 0;\n j = 0;\n /* Do not use the 2 top bits. Signed integer datatypes in C do not\n have the overflow semantics that many people expect. With care,\n we could use the second topmost bit as well, but this doesn't\n seem important at the moment. */\n for (i=0; i < (int) sizeof(CCTK_INT)*8-2 && j<nbits; ++i)\n {\n if (!(n & used_bits))\n {\n ++j;\n new_bits |= n;\n }\n n *= 2;\n }\n\n if (j<nbits)\n {\n CCTK_WARN (1, \"Cannot allocate mask: Not enough free bits.\");\n return 0;\n }\n\n return new_bits;\n}\n\n/*@@\n @routine SpaceMask_determine_state_mask\n @author Denis Pollney\n @date 15 October 2002\n @desc \n Determine appropriate bitmasks to represent a number of\n states, using the allocated bit mask.\n That is, if allocated_bits is set to 00111000, then\n the returned list of states are permutations of the three\n non-zero (active) bits.\n @enddesc \n@@*/\nstatic\nCCTK_INT*\nSpaceMask_determine_state_mask(CCTK_INT allocated_bits, int nstates)\n{\n CCTK_INT* state_mask;\n int n;\n int bit;\n int i;\n int j;\n\n state_mask =\n (CCTK_INT*) malloc (nstates*sizeof(CCTK_INT));\n\n for (j=0; j<nstates; ++j)\n state_mask[j] = 0;\n\n n=1;\n bit=1;\n\n /* Do not use the 2 top bits. Signed integer datatypes in C do not\n have the overflow semantics that many people expect. With care,\n we could use the second topmost bit as well, but this doesn't\n seem important at the moment. */\n for (i=0; i < (int) sizeof(CCTK_INT)*8-2; ++i)\n {\n if (n & allocated_bits)\n {\n for (j=0; j<nstates; ++j)\n {\n if (bit & j)\n state_mask[j] += n;\n }\n bit *= 2;\n }\n n *= 2;\n }\n\n return state_mask;\n}\n\n/*@@\n @routine SpaceMask_setup_new_state\n @author Denis Pollney\n @date 15 October 2002\n @desc \n Allocate a new SpaceMask_State, giving it a name and\n a bit mask.\n @enddesc \n@@*/\nstatic\nSpaceMask_State*\nSpaceMask_setup_new_state(CCTK_INT state_mask, const char* name)\n{\n SpaceMask_State* new_state;\n\n new_state = (SpaceMask_State*) malloc (sizeof(SpaceMask_State));\n new_state->name = name;\n new_state->bitmask = state_mask;\n\n return new_state;\n}\n\n/*@@\n @routine SpaceMask_setup_new_type\n @author Denis Pollney\n @date 15 October 2002\n @desc \n Allocate a new SpaceMask_Type. This involves allocating\n a set of bits within the mask to the new type, and creating\n appropriate bitmasks (using the allocated bits) for each of\n the requested states.\n @enddesc \n@@*/\nstatic\nSpaceMask_Type*\nSpaceMask_setup_new_type(CCTK_INT new_bits, const char* type_name,\n int nstates, const char* const state_list[], \n const CCTK_INT state_mask[])\n{\n SpaceMask_Type* new_type;\n int j;\n\n new_type = (SpaceMask_Type*) malloc (sizeof(SpaceMask_Type));\n\n if (new_type == NULL)\n return NULL;\n\n new_type->bitmask = new_bits;\n new_type->nstates = nstates;\n new_type->name = type_name;\n new_type->state_list =\n (SpaceMask_State**) malloc (nstates*sizeof(SpaceMask_State*));\n\n if (state_list==NULL)\n {\n for (j=0; j<nstates; ++j)\n new_type->state_list[j] = SpaceMask_setup_new_state(state_mask[j],\n NULL);\n }\n else\n {\n for (j=0; j<nstates; ++j)\n new_type->state_list[j] = SpaceMask_setup_new_state(state_mask[j],\n state_list[j]);\n }\n\n return new_type;\n}\n\n/*@@\n @routine SpaceMask_append_type_to_registry\n @author Denis Pollney\n @date 15 October 2002\n @desc \n Adds a new type to the spacemask_registry.\n @enddesc \n@@*/\nstatic\nvoid\nSpaceMask_append_type_to_registry(SpaceMask_Type* new_type)\n{\n SpaceMask_Type** new_type_list;\n int ntypes;\n int i;\n\n if (spacemask_registry == NULL)\n {\n spacemask_registry =\n (SpaceMask_Registry*) malloc (sizeof(SpaceMask_Registry));\n ntypes = 1;\n new_type_list = (SpaceMask_Type**) malloc (sizeof(SpaceMask_Type*));\n new_type_list[0] = new_type;\n }\n else\n {\n ntypes = spacemask_registry->ntypes + 1;\n new_type_list = \n (SpaceMask_Type**) malloc (ntypes*sizeof(SpaceMask_Type*));\n for (i=0; i<ntypes-1; ++i)\n new_type_list[i] = spacemask_registry->type_list[i];\n new_type_list[ntypes-1] = new_type;\n free(spacemask_registry->type_list);\n }\n\n spacemask_registry->ntypes = ntypes;\n spacemask_registry->type_list = new_type_list;\n}\n\n/*@@\n @routine SpaceMask_RegisterType\n @author Denis Pollney\n @date 15 October 2002\n @desc \n Allocates a set of bits of the SpaceMask to represent\n a set of states of the named type.\n @enddesc \n@@*/\n\nint\nSpaceMask_RegisterType(const char* type_name, int nstates,\n const char* const state_list[])\n{\n SpaceMask_Type* new_type;\n CCTK_INT new_bits;\n CCTK_INT* state_mask;\n int bit_nbr;\n \n bit_nbr = SpaceMask_get_bit_nbr(nstates);\n new_bits = SpaceMask_get_free_bits(bit_nbr);\n\n if (new_bits == 0)\n return -1;\n\n state_mask = SpaceMask_determine_state_mask(new_bits, nstates);\n\n new_type = SpaceMask_setup_new_type(new_bits, type_name, nstates, \n state_list, state_mask);\n if (new_type == NULL)\n return -1;\n\n SpaceMask_append_type_to_registry (new_type);\n\n return 0;\n}\n\n/*@@\n @routine SpaceMask_AppendStatesToType\n @author Denis Pollney\n @date 15 October 2002\n @desc \n Adds a new set of possible states to an already existing\n type. If required, new bits of the mask are allocated to the\n given state. If bits are not available for this, then an\n error is returned.\n @enddesc \n@@*/\n\nint\nSpaceMask_AppendStatesToType(const char* type_name, int nstates,\n const char* const state_list[])\n{\n CCTK_INT new_bits;\n CCTK_INT allocated_bits;\n CCTK_INT* state_mask;\n SpaceMask_Type* old_type;\n SpaceMask_Type* new_type;\n const char** new_state_list;\n int i;\n int j;\n int old_type_idx;\n int new_bit_nbr;\n int total_nstates;\n \n old_type = NULL;\n for (i=0; i<spacemask_registry->ntypes; ++i)\n {\n if (!strcmp(spacemask_registry->type_list[i]->name, type_name))\n {\n old_type = spacemask_registry->type_list[i];\n old_type_idx = i;\n }\n }\n\n if (old_type == NULL)\n {\n CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Mask type \\\"%s\\\" has not been registered\", type_name);\n return -1;\n }\n\n total_nstates = old_type->nstates + nstates;\n new_bit_nbr = SpaceMask_get_bit_nbr(total_nstates) - \n SpaceMask_get_bit_nbr(old_type->nstates);\n\n new_bits = SpaceMask_get_free_bits(new_bit_nbr);\n\n if (new_bits == 0)\n return -1;\n\n allocated_bits = old_type->bitmask | new_bits;\n\n state_mask = SpaceMask_determine_state_mask(allocated_bits, total_nstates);\n\n new_state_list = (const char**) malloc (total_nstates*sizeof(char*));\n\n i = 0;\n for (j=0; j<old_type->nstates; ++j, ++i)\n new_state_list[i] = old_type->state_list[j]->name;\n for (j=0; j<nstates; ++j, ++i)\n new_state_list[i] = state_list[j];\n\n new_type = SpaceMask_setup_new_type(allocated_bits, type_name, total_nstates,\n new_state_list, state_mask);\n if (new_type == NULL)\n return -1;\n\n free(old_type);\n\n spacemask_registry->type_list[old_type_idx] = new_type;\n\n return 0;\n}\n\n/*@@\n @routine SpaceMask_GetTypeBits\n @author Denis Pollney\n @date 15 October 2002\n @desc \n Returns the bitmask corresponding to the given type. Bits\n which are allocated to the given type are set to 1, all other\n bits are 0.\n @enddesc \n@@*/\n\nCCTK_INT\nSpaceMask_GetTypeBits(const char* type_name)\n{\n int i;\n\n if (spacemask_registry != NULL)\n {\n for (i=0; i<spacemask_registry->ntypes; ++i)\n {\n if (!strcmp(spacemask_registry->type_list[i]->name, type_name))\n return spacemask_registry->type_list[i]->bitmask;\n }\n }\n\n CCTK_VInfo (CCTK_THORNSTRING, \"Type \\\"%s\\\" has not been registered.\\n\",\n type_name);\n\n return 0;\n}\n\n/*@@\n @routine SpaceMask_GetStateBits\n @author Denis Pollney\n @date 15 October 2002\n @desc \n Returns the bitmask corresponding to the given state, or\n -1 if the state does not exist.\n @enddesc \n@@*/\n\nCCTK_INT\nSpaceMask_GetStateBits(const char* type_name, const char* state_name)\n{\n SpaceMask_Type* type;\n int i, j;\n\n if (spacemask_registry != NULL)\n {\n for (i=0; i<spacemask_registry->ntypes; ++i)\n {\n if (!strcmp(spacemask_registry->type_list[i]->name, type_name))\n {\n type = spacemask_registry->type_list[i];\n for (j=0; j<type->nstates; ++j)\n {\n if (!strcmp(type->state_list[j]->name, state_name))\n return type->state_list[j]->bitmask;\n }\n }\n\t}\n }\n\n CCTK_VInfo (CCTK_THORNSTRING, \n \"Requested state \\\"%s\\\" could not be found in type \\\"%s\\\"\\n\",\n state_name, type_name);\n\n return -1;\n}\n\n/*@@\n @routine SpaceMask_GetStateBitsList\n @author Denis Pollney\n @date 25 May 2003\n @desc \n Returns a list of all of the state masks allocated\n for a given type. The number of elements in the list\n is equal to the number of states of the type.\n If the type name is not recognised, NULL is returned.\n @enddesc \n@@*/\n\nCCTK_INT*\nSpaceMask_GetStateBitsList(const char* type_name)\n{\n SpaceMask_Type* type;\n CCTK_INT* state_bits_list;\n int i, j;\n\n for (i=0; i<spacemask_registry->ntypes; ++i)\n {\n if (!strcmp(spacemask_registry->type_list[i]->name, type_name))\n {\n type = spacemask_registry->type_list[i];\n state_bits_list = (CCTK_INT*) \n malloc (sizeof(CCTK_INT)*(type->nstates));\n\n for (j=0; j<type->nstates; ++j)\n state_bits_list[j] = type->state_list[j]->bitmask;\n\n return state_bits_list;\n }\n }\n\n CCTK_VInfo (CCTK_THORNSTRING, \n \"Requested type \\\"%s\\\" could not be found\\n\", type_name);\n\n return NULL;\n}\n\n/*@@\n @routine SpaceMask_SetState\n @author Denis Pollney\n @date 15 October 2002\n @desc \n Sets the mask at a point to the given state.\n @enddesc \n@@*/\n\nvoid\nSpaceMask_SetState(CCTK_INT* mask, int point, const char* type_name, const char* state)\n{\n CCTK_INT type_bits;\n CCTK_INT state_bits;\n\n type_bits = SpaceMask_GetTypeBits(type_name);\n state_bits = SpaceMask_GetStateBits(type_name, state);\n\n SpaceMask_SetStateBits(mask, point, type_bits, state_bits);\n}\n\n/*@@\n @routine SpaceMask_CheckState\n @author Denis Pollney\n @date 15 October 2002\n @desc \n Checks that the mask at a point has the given state, in which\n case return 1, otherwise return 0.\n @enddesc \n@@*/\n\nCCTK_INT\nSpaceMask_CheckState(const CCTK_INT* mask, int point, const char* type_name, const char* state)\n{\n CCTK_INT type_bits;\n CCTK_INT state_bits;\n\n type_bits = SpaceMask_GetTypeBits(type_name);\n state_bits = SpaceMask_GetStateBits(type_name, state);\n\n return SpaceMask_CheckStateBits(mask, point, type_bits, state_bits);\n}\n\n\n/********************************************************************\n ********************* Fortran Wrappers ***************************\n ********************************************************************/\n\n/* How do you pass the char** state list from fortran???\nvoid\nCCTK_FCALL CCTK_FNAME(SpaceMask_RegisterType)(int* ierr, char* type_name,\n int* nstates, char** state_list)\n{\n *ierr = SpaceMask_RegisterType(type_name, *nstates, state_list);\n}\n*/\n\nvoid\nCCTK_FCALL CCTK_FNAME(SpaceMask_GetTypeBits)(CCTK_INT* type_bits,\n ONE_FORTSTRING_ARG)\n{\n ONE_FORTSTRING_CREATE(type_name)\n\n *type_bits = SpaceMask_GetTypeBits(type_name);\n\n free(type_name);\n}\n\nvoid\nCCTK_FCALL CCTK_FNAME(SpaceMask_GetStateBits)(CCTK_INT* state_bits,\n TWO_FORTSTRING_ARG)\n{\n\n TWO_FORTSTRING_CREATE(type_name, state_name)\n\n *state_bits = SpaceMask_GetStateBits(type_name, state_name);\n\n free(type_name);\n free(state_name);\n}\n\nvoid\nCCTK_FCALL CCTK_FNAME(SpaceMask_SetState)(CCTK_INT* mask,\n CCTK_INT* point, TWO_FORTSTRING_ARG)\n{\n TWO_FORTSTRING_CREATE(type_name, state)\n\n SpaceMask_SetState(mask, *point, type_name, state);\n\n free(type_name);\n free(state);\n}\n\nvoid\nCCTK_FCALL CCTK_FNAME(SpaceMask_CheckState)(int* retval,\n CCTK_INT* mask,\n CCTK_INT* point,\n TWO_FORTSTRING_ARG)\n{\n TWO_FORTSTRING_CREATE(type_name, state)\n\n *retval = SpaceMask_CheckState(mask, *point, type_name, state);\n\n free(type_name);\n free(state);\n}\n", |
| "MaskInit.c": " /*@@\n @file MaskInit.c\n @date Fri Apr 26 17:20:13 2002\n @author Miguel Alcubierre\n @desc \n Initialise the mask (I just copied LapseInits.c)\n @enddesc \n @version $Header$\n @@*/\n\n#include <math.h>\n#include <stdio.h>\n#include <stdlib.h>\n\n#include \"cctk.h\"\n\n#include \"cctk_Parameters.h\"\n#include \"cctk_Arguments.h\"\n\n#include \"Symmetry.h\"\n#include \"SpaceMask.h\"\n\nstatic const char *rcsid = \"$Header$\";\n\nCCTK_FILEVERSION(CactusEinstein_Einstein_MaskInit_c);\n\n\n/********************************************************************\n ********************* Local Data Types ***********************\n ********************************************************************/\n\n/********************************************************************\n ********************* Local Routine Prototypes *********************\n ********************************************************************/\n\n/********************************************************************\n ***************** Scheduled Routine Prototypes *********************\n ********************************************************************/\n\nvoid MaskOne(CCTK_ARGUMENTS);\nvoid MaskSym(CCTK_ARGUMENTS);\nvoid MaskSym_emask(CCTK_ARGUMENTS);\nvoid MaskZero(CCTK_ARGUMENTS);\n\n/********************************************************************\n ********************* External Routines **********************\n ********************************************************************/\n\n/*@@\n @routine MaskSym\n @date October 2002\n @author Denis Pollney\n @desc \n Scheduled routine to set symmetries for mask\n @enddesc \n @calls \n @calledby \n @history \n \n @endhistory \n \n@@*/\nvoid MaskSym(CCTK_ARGUMENTS)\n{\n DECLARE_CCTK_ARGUMENTS_MaskSym\n\n int one;\n int sym[3];\n\n one = 1;\n \n sym[0] = one;\n sym[1] = one;\n sym[2] = one;\n\n SetCartSymVN(cctkGH, sym, \"spacemask::space_mask\");\n\n return;\n}\n\n/*@@\n @routine MaskSym_emask\n @date Fri 3 May 2002\n @author Gabrielle Allen\n @desc \n Scheduled routine to set symmetries for mask\n @enddesc \n @calls \n @calledby \n @history \n \n @endhistory \n \n@@*/\nvoid MaskSym_emask(CCTK_ARGUMENTS)\n{\n DECLARE_CCTK_ARGUMENTS_MaskSym_emask\n\n int one;\n int sym[3];\n\n one = 1;\n \n sym[0] = one;\n sym[1] = one;\n sym[2] = one;\n\n SetCartSymVN(cctkGH, sym, \"spacemask::emask\");\n\n return;\n}\n\n/*@@\n @routine MaskOne\n @date \n @author Miguel Alcubierre\n @desc \n Scheduled routine to initialise the mask to one.\n @enddesc \n @calls \n @calledby \n @history \n \n @endhistory \n \n@@*/\nvoid MaskOne(CCTK_ARGUMENTS)\n{\n int i;\n DECLARE_CCTK_ARGUMENTS_MaskOne;\n\n for(i = 0; i < cctk_ash[0]*cctk_ash[1]*cctk_ash[2]; i++)\n {\n emask[i] = 1.0;\n }\n\n return;\n}\n\n/*@@\n @routine CheckMask\n @date \n @author Erik Schnetter\n @desc \n Ensure that all mask values are legal.\n @enddesc \n @calls \n @calledby \n @history \n \n @endhistory \n \n@@*/\nvoid CheckMask(CCTK_ARGUMENTS)\n{\n DECLARE_CCTK_ARGUMENTS_CheckMask\n int i;\n\n for(i = 0; i < cctk_ash[0]*cctk_ash[1]*cctk_ash[2]; i++)\n {\n if ( fabs(emask[i] - 1.0) > 1.0e-12\n && fabs(emask[i] - 0.5) > 1.0e-12 \n && fabs(emask[i] - 0.0) > 1.0e-12)\n {\n CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Illegal mask value %g detected at grid point %d\",\n (double)emask[i], i);\n }\n }\n}\n\n/*@@\n @routine MaskZero\n @date \n @author Denis Pollney\n @desc \n Initialise the mask to zero.\n @enddesc \n @calls \n @calledby \n @history \n \n @endhistory \n \n@@*/\nvoid MaskZero(CCTK_ARGUMENTS)\n{\n DECLARE_CCTK_ARGUMENTS_MaskZero\n\n int i;\n\n for(i = 0; i < cctk_ash[0]*cctk_ash[1]*cctk_ash[2]; i++)\n space_mask[i] = 0;\n\n return;\n}\n\n/********************************************************************\n ********************* Local Routines *************************\n ********************************************************************/\n", |
| "SpaceMask.h": "/*@@\n @file MaskUtils.c\n @date October 2002\n @author Denis Pollney\n @desc\n Function prototypes and macros mask utilities.\n @desc\n @version $Header$\n@@*/\n\n#ifndef __CACTUSEINSTEIN_SPACEMASK_H__\n#define __CACTUSEINSTEIN_SPACEMASK_H__\n\n#define SPACEMASK_DEBUG 0\n\n/********************************************************************\n ********************* Routine Prototypes *************************\n ********************************************************************/\n#ifdef CCODE\n\n#ifdef __cplusplus\nextern \"C\"\n{\n#endif \n\n/* publicly visible routines */\nint SpaceMask_RegisterType(const char* type_name, int nstates,\n const char* const state_list[]);\nint SpaceMask_AppendStatesToType(const char* type_name, int nstates,\n const char* const state_list[]);\nCCTK_INT SpaceMask_GetTypeBits(const char* type_name);\nCCTK_INT SpaceMask_GetStateBits(const char* type_name, const char* state_name);\nvoid SpaceMask_SetState(CCTK_INT* mask, int point,\n const char* type_name, const char* state);\nCCTK_INT SpaceMask_CheckState(const CCTK_INT* mask, int point,\n const char* type_name, const char* state);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif\n\n/********************************************************************\n ********************* Local Data Types **********************\n ********************************************************************/\n\n#ifdef CCODE\n\ntypedef struct\n{\n const char* name;\n CCTK_INT bitmask;\n} SpaceMask_State;\n\ntypedef struct\n{\n const char* name;\n int nstates;\n CCTK_INT bitmask;\n SpaceMask_State** state_list;\n} SpaceMask_Type;\n\ntypedef struct\n{\n int ntypes;\n SpaceMask_Type** type_list;\n} SpaceMask_Registry;\n\nextern SpaceMask_Registry* spacemask_registry;\n\n#endif\n\n/********************************************************************\n ********************* Macros ******************************\n ********************************************************************/\n\n/*@@\n @routine SpaceMask_SetStateBits\n @author Denis Pollney\n @date 15 October 2002\n @desc \n Sets the mask at a point to the given state, as specified\n using a bitmask.\n @enddesc \n@@*/\n\n#ifdef FCODE\n#define SpaceMask_SetStateBitsF90(mask, i,j,k, type_bits, state_bits) \\\n mask(i,j,k) = ior(iand(mask(i,j,k), not(type_bits)), state_bits)\n#endif\n\n#ifdef CCODE\n#define SpaceMask_SetStateBits(mask, ijk, type_bits, state_bits) \\\n ((mask)[ijk] = (((mask)[ijk] & ~(type_bits)) | (state_bits)))\n#endif\n\n/*@@\n @routine SpaceMask_CheckStateBits\n @author Denis Pollney\n @date 15 October 2002\n @desc \n Checks that the mask at a point has the specified state,\n in which case return 1, otherwise return 0.\n @enddesc \n@@*/\n\n#ifdef FCODE\n#define SpaceMask_CheckStateBitsF90(mask,i,j,k,type_bits,state_bits) \\\n (iand(mask((i),(j),(k)),(type_bits)).eq.(state_bits))\n#endif\n\n#ifdef CCODE\n#define SpaceMask_CheckStateBits(mask, ijk, type_bits, state_bits) \\\n (((mask)[ijk] & (type_bits)) == (state_bits))\n#endif\n\n#endif /* __CACTUSEINSTEIN_SPACEMASK_H__ */\n" |
| }, |
| "test": {}, |
| "doc": { |
| "space_mask.pdf": "%PDF-1.3\n%\uc3e2\n5 0 obj\n<</Length 6 0 R/Filter /FlateDecode>>\nstream\nxTn0\u0010+glcR/^zi^Ql%a;\u0018\u0016\u0010\u008a1fOR\u0001J=Z\u3753\b`,PE\u023boB\u0007O@^\u0012\u0005\u0016!\u0011F\u0004Ap\u0504,\u077d`\u001b\u05f6\u0014\u001fa\u0003\u0005I/`q\u0017 g\u0002\u0016:)\u0015>1@n-+X\u001d\u001a\u0007NYb)\u00110\u03e1\u012c(\u0e4b\u0014\"\b\u05aeT&\u0016\u051a7\u001eLFN.,P\u0006-K%n`g9~\u0204\u001e|\"UKzIY\u0003\u0012R\u00b1aP`9\u0011:d-[9eWO\u000b\u0001B0:\nf\u00136\u001b6\u001c\u0011;\u0017\u001fQ\u0010\u0011\u001f2\tR<9\u0006\u0247Y\u0019\u0607\u0012a8uTah+X\u001c&\u016b\u0019f%t\u0019uV:\\o\u0119a)j%\u001b\\SE\u007fS4|%E\u00157\n;{g94mW\u0004TBVfy\u0013o?;+\b\u001e\u0183a/\u0002\n\u000fam'\u04eaxx-\ubdfd6m;n\u06b2<D\u0000{DJ]\u007f\b{s\u0004Tg (6\u000b$7ES56sK\u0016Dlw>\u048eyQCG1L@o2(Eo!j}\u000f~\u0001\u0005_endstream\nendobj\n6 0 obj\n585\nendobj\n4 0 obj\n<</Type/Page/MediaBox [0 0 400 242]\n/Parent 3 0 R\n/Resources<</ProcSet[/PDF /Text]\n/ExtGState 9 0 R\n/Font 10 0 R\n>>\n/Contents 5 0 R\n>>\nendobj\n3 0 obj\n<< /Type /Pages /Kids [\n4 0 R\n] /Count 1\n>>\nendobj\n1 0 obj\n<</Type /Catalog /Pages 3 0 R\n>>\nendobj\n7 0 obj\n<</Type/ExtGState\n/OPM 1>>endobj\n9 0 obj\n<</R7\n7 0 R>>\nendobj\n10 0 obj\n<</R8\n8 0 R>>\nendobj\n8 0 obj\n<</BaseFont/Helvetica-Bold/Type/Font\n/Subtype/Type1>>\nendobj\n2 0 obj\n<</Producer(ESP Ghostscript 815.03)\n/CreationDate(D:20090202090434)\n/ModDate(D:20090202090434)>>endobj\nxref\n0 11\n0000000000 65535 f \n0000000898 00000 n \n0000001115 00000 n \n0000000839 00000 n \n0000000689 00000 n \n0000000015 00000 n \n0000000670 00000 n \n0000000946 00000 n \n0000001046 00000 n \n0000000987 00000 n \n0000001016 00000 n \ntrailer\n<< /Size 11 /Root 1 0 R /Info 2 0 R\n/ID [(\u000b\u000eB'2Sy\u0016|)(\u000b\u000eB'2Sy\u0016|)]\n>>\nstartxref\n1226\n%%EOF\n", |
| "space_mask.fig": "#FIG 3.2\nLandscape\nCenter\nMetric\nA4 \n100.00\nSingle\n-2\n1200 2\n2 1 0 2 0 7 50 0 -1 0.000 0 0 -1 0 0 4\n\t 7200 4275 900 4275 900 4725 7200 4725\n2 2 0 2 0 6 50 0 20 0.000 0 0 -1 0 0 5\n\t 900 4275 1350 4275 1350 4725 900 4725 900 4275\n2 2 0 2 0 6 50 0 20 0.000 0 0 -1 0 0 5\n\t 1350 4275 1800 4275 1800 4725 1350 4725 1350 4275\n2 2 0 2 0 3 50 0 20 0.000 0 0 -1 0 0 5\n\t 1800 4275 2250 4275 2250 4725 1800 4725 1800 4275\n2 2 0 2 0 3 50 0 20 0.000 0 0 -1 0 0 5\n\t 2250 4275 2700 4275 2700 4725 2250 4725 2250 4275\n2 2 0 2 0 3 50 0 20 0.000 0 0 -1 0 0 5\n\t 2700 4275 3150 4275 3150 4725 2700 4725 2700 4275\n2 2 0 2 0 6 50 0 -1 0.000 0 0 -1 0 0 5\n\t 3150 4275 3600 4275 3600 4725 3150 4725 3150 4275\n2 2 0 2 0 6 50 0 -1 0.000 0 0 -1 0 0 5\n\t 3600 4275 4050 4275 4050 4725 3600 4725 3600 4275\n2 2 0 2 0 6 50 0 -1 0.000 0 0 -1 0 0 5\n\t 4050 4275 4500 4275 4500 4725 4050 4725 4050 4275\n2 2 0 2 0 6 50 0 -1 0.000 0 0 -1 0 0 5\n\t 4500 4275 4950 4275 4950 4725 4500 4725 4500 4275\n2 2 0 2 0 6 50 0 -1 0.000 0 0 -1 0 0 5\n\t 4950 4275 5400 4275 5400 4725 4950 4725 4950 4275\n2 2 0 2 0 6 50 0 -1 0.000 0 0 -1 0 0 5\n\t 5400 4275 5850 4275 5850 4725 5400 4725 5400 4275\n2 2 0 2 0 6 50 0 -1 0.000 0 0 -1 0 0 5\n\t 5850 4275 6300 4275 6300 4725 5850 4725 5850 4275\n2 2 0 2 0 6 50 0 -1 0.000 0 0 -1 0 0 5\n\t 6300 4275 6750 4275 6750 4725 6300 4725 6300 4275\n2 2 0 2 0 6 50 0 -1 0.000 0 0 -1 0 0 5\n\t 1485 5535 3420 5535 3420 6885 1485 6885 1485 5535\n2 2 0 2 0 6 50 0 -1 0.000 0 0 -1 0 0 5\n\t 4140 5535 6030 5535 6030 7785 4140 7785 4140 5535\n2 1 0 2 0 6 50 0 -1 0.000 0 0 -1 0 0 3\n\t 1125 4725 1125 4950 1575 4950\n2 1 0 2 0 6 50 0 -1 0.000 0 0 -1 0 0 2\n\t 1575 4725 1575 5535\n2 1 0 2 0 6 50 0 -1 0.000 0 0 -1 0 0 4\n\t 2025 4725 2025 4950 4230 4950 4230 5535\n2 1 0 2 0 6 50 0 -1 0.000 0 0 -1 0 0 2\n\t 2475 4725 2475 4950\n2 1 0 2 0 6 50 0 -1 0.000 0 0 -1 0 0 2\n\t 2925 4725 2925 4950\n2 2 0 2 0 6 50 0 20 0.000 0 0 -1 0 0 5\n\t 1485 5535 3420 5535 3420 5940 1485 5940 1485 5535\n2 2 0 2 0 3 50 0 20 0.000 0 0 -1 0 0 5\n\t 4140 5535 6030 5535 6030 5895 4140 5895 4140 5535\n4 0 0 50 0 18 14 0.0000 4 165 1425 1575 6165 00 = \"normal\"\\001\n4 0 0 50 0 18 14 0.0000 4 165 1485 1575 6420 01 = \"excised\"\\001\n4 0 0 50 0 18 14 0.0000 4 210 1710 1575 6705 10 = \"boundary\"\\001\n4 0 0 50 0 18 14 0.0000 4 165 1380 4275 6165 000 = \"black\"\\001\n4 0 0 50 0 18 14 0.0000 4 165 1170 4275 6420 001 = \"red\"\\001\n4 0 0 50 0 18 14 0.0000 4 165 1275 4275 6675 010 = \"blue\"\\001\n4 0 0 50 0 18 14 0.0000 4 210 1425 4275 6930 011 = \"green\"\\001\n4 0 0 50 0 18 14 0.0000 4 210 1470 4275 7185 100 = \"yellow\"\\001\n4 0 0 50 0 18 14 0.0000 4 210 1560 4275 7440 101 = \"orange\"\\001\n4 0 0 50 0 18 14 0.0000 4 165 1365 4275 7695 110 = \"white\"\\001\n4 0 0 50 0 18 14 0.0000 4 210 1470 4275 5805 type: \"colour\"\\001\n4 0 0 50 0 18 14 0.0000 4 210 1275 900 4140 space_mask\\001\n4 0 0 50 0 18 14 0.0000 4 210 1650 1575 5805 type: \"excision\"\\001\n", |
| "documentation.tex": "\\documentclass{article}\n\n% Use the Cactus ThornGuide style file\n% (Automatically used from Cactus distribution, if you have a \n% thorn without the Cactus Flesh download this from the Cactus\n% homepage at www.cactuscode.org)\n\\usepackage{../../../../doc/latex/cactus}\n\n\\begin{document}\n\n\\title{Using SpaceMask}\n\\author{Denis Pollney}\n\\date{$ $Date$ $}\n\n\\maketitle\n\n% Do not delete next line\n% START CACTUS THORNGUIDE\n\n\\begin{abstract}\nThe SpaceMask thorn provides a grid function which can be used to\nstore user-defined states at each grid point. Routines are provided\nfor quickly setting and checking the mask states.\n\\end{abstract}\n\n\\section{The mask bit-field}\n\nThe mask is a grid function which can be used to assign a state to\neach point on the grid. It is used as a bit field, with different\nbits, or combinations of bits, assigned to represent various states.\nThe mask is currently implemented as a CCTK\\_INT grid function,\nproviding 32 bits per point.\\footnote{The original implementation of\nthese functions used a CCTK\\_INT8 for 64 bits, however this data type\nis not supported by some Fortran compilers.} Appropriate numbers of\nbits within the mask can be allocated to represent individual states\nof a given type.\n\nFor instance, a programmer wants to record whether each point of the\ngrid has \\emph{state} ``interior'', ``excised'' or ``boundary''. The\ncollection of these states is called a \\emph{type}, and 2-bits of the\nmask (enough to represent the three possible states of the type) are\nallocated to hold this information. If an independent classification\nof points (ie. a new type) is required, bits are allocated to it from\nthe remaining free bits in the mask. (See Figure \\ref{fig:mask_bits}.)\n\nThe SpaceMask thorn provides a set of routines for allocating bits\nwithin the mask, and for setting and checking the mask state at\nindividual points.\n\n\\begin{figure}\n \\centering\n \\includegraphics{space_mask}\n \\caption{The \\texttt{SpaceMask\\_RegisterType()} function allocates\n bits of the mask to a new ``type'' (eg. ``excision'' and ``colour''\n in the figure). The number of bits that are allocated is determined\n by the number of possible states of the given type.}\n \\label{fig:mask_bits}\n\\end{figure}\n\n\\section{Using the mask}\n\nA number of functions are provided for registering new types, and\nchecking and setting mask values at a point. The interface to these\nfunctions differs slightly for C and Fortran90 code.\n\n\\subsection{Accessing the mask from C Code}\n\nThe following description describes the C interface for manipulating\nthe mask. An example of code using these functions can be found in\nAppendix \\ref{app:eg_C}.\n\n\\subsubsection{Registering a new type}\\label{sec:reg_C}\n\nBits of the mask are allocated to a new type using the function:\n\n\\indent\\parbox{\\linewidth}{\n\\vspace{\\baselineskip}\\noindent\\texttt{\nint SpaceMask\\_RegisterType(const char* \\emph{type\\_name},\n \\\\\\hspace*{10mm}\n int \\emph{nstates}, const char* const \\emph{state\\_list}[])\n}\\\\\n\\hspace*{10mm}\\parbox{\\linewidth}{\n\\begin{description}\n \\item[\\emph{type\\_name}] The name of the new type to be registered;\n \\item[\\emph{nstates}] The number of states in the new type;\n \\item[\\emph{state\\_list}] A list of names, one for each state, or NULL.\n\\end{description}\n}\n}\n\n\\noindent An appropriate number of bits of the mask are allocated to\nhold a unique value for the $n$ states specified by the \\emph{nstates}\nargument. The registration must take place before the type can be\nused, so for instance, this could be scheduled at CCTK\\_STARTUP. The\nfunction returns a $-1$ if the required states cannot be allocated\n(for example, if there are not enough free bits remaining in the\nmask), otherwise it returns $0$.\n\nIt is possible to allocate a portion of the mask without assigning\nnames to any of the states by passing NULL as the \\emph{state\\_list}.\nThis is useful when some integer number of states is required for a\ngiven type, but the number of states and appropriate names are not\nknown at compile time. States which are allocated in this way can be\naccessed using the \\texttt{SpaceMask\\_GetStateBitsList()}.\n\nNew states can be added to an already allocated type using the\nfunction:\n\n\\indent\\parbox{\\linewidth}{\n\\vspace{\\baselineskip}\\noindent\\texttt{\nint SpaceMask\\_AppendStatesToType(const char* \\emph{type\\_name},\n \\\\\\hspace*{10mm}\n int \\emph{nstates}, const char* const \\emph{state\\_list}[])\n}\\\\\n\\hspace*{10mm}\\parbox{\\linewidth}{\n\\begin{description}\n \\item[\\emph{type\\_name}] The name of an already registered type;\n \\item[\\emph{nstates}] The number of states to be added;\n \\item[\\emph{state\\_list}] A list of names, one for each of the new\n states.\n\\end{description}\n}}\n\n\\noindent A number of new bits will be added to the specified type\nappropriate to hold the number of existing states plus the extra\nstates. The allocated bits need not be contiguous within the mask.\nThe function returns $0$ if successful, otherwise a $-1$ if the new\nstates could not be allocated.\n\n\n\\subsubsection{Setting and checking mask states}\n\nThe state of the mask at a given point is set using the function:\n\n\\indent\\parbox{\\linewidth}{\n\\vspace{\\baselineskip}\\noindent\\texttt{\nvoid SpaceMask\\_SetState(CCTK\\_INT* \\emph{mask}, int \\emph{point},\n \\\\\\hspace*{10mm}\n const char* \\emph{type\\_name}, const char* \\emph{state})\n}\\\\\n\\hspace*{10mm}\\parbox{\\linewidth}{\n\\begin{description}\n \\item[\\emph{mask}] A pointer to the mask grid function;\n \\item[\\emph{point}] The index of the point within the grid function\n array;\n \\item[\\emph{type\\_name}] The name of the type containing the state;\n \\item[\\emph{state\\_name}] The particular state to be set.\n\\end{description}\n}}\n\nThe state of the mask at a given point can be checked using:\n\n\\indent\\parbox{\\linewidth}{\n\\vspace{\\baselineskip}\\noindent\\texttt{\nint SpaceMask\\_CheckState(const CCTK\\_INT* \\emph{mask}, int \\emph{point},\n \\\\\\hspace*{10mm}\n const char* \\emph{type\\_name}, const char* \\emph{state})\n}\\\\\n\\hspace*{10mm}\\parbox{\\linewidth}{\n\\begin{description}\n \\item[\\emph{mask}] A pointer to the mask grid function;\n \\item[\\emph{point}] The index of the point within the grid function\n array;\n \\item[\\emph{type\\_name}] The name of the type containing the state;\n \\item[\\emph{state\\_name}] The particular state to be compared.\n\\end{description}\n}}\n\nThe return value is 1 if the given \\emph{state\\_name} has been set at\nthe point, or 0 otherwise.\n\n\\subsubsection{Faster bitwise operators}\n\nThe above mentioned functions for checking and setting the mask are\nrather inefficient, since they require strings to be compared at each\npoint. A set of faster macros are provided which operate on the mask\nby performing bit operations directly. In order to use these\nfunctions, the bitmasks corresponding to the desired type and it's\nstates need to be obtained using the following functions:\n\n\\indent\\parbox{\\linewidth}{\n\\vspace{\\baselineskip}\\noindent\\texttt{\nCCTK\\_INT SpaceMask\\_GetTypeBits(const char* \\emph{type\\_name})\n}\\\\\n\\hspace*{10mm}\\parbox{\\linewidth}{\n\\begin{description}\n \\item[\\emph{type\\_name}] The type for which the bitmask is to be\n determined.\n\\end{description}\n}}\n\n\\indent\\parbox{\\linewidth}{\n\\vspace{\\baselineskip}\\noindent\\texttt{\nCCTK\\_INT SpaceMask\\_GetStateBits(const char* \\emph{type\\_name},\n const char* \\emph{state\\_name})\n}\n\\hspace*{10mm}\\parbox{\\linewidth}{\n\\begin{description}\n \\item[\\emph{type\\_name}] The type containing the state in question;\n \\item[\\emph{state\\_name}] The state whose bitmask is to be determined.\n\\end{description}\n}}\n\n\\noindent Each of these functions returns a CCTK\\_INT8 which holds the\nbitmask corresponding to the given type or state. For example, if a\ngiven type uses three bits of the mask, the returned value could be\nthe integer corresponding to the bitfield $001110000$\\ldots, where the\nlocation of $1$s indicates the bits which have been allocated to the\ngiven type. A return value of $0$ (GetTypeBits) or $-1$ (GetStateBits)\nindicates that the bitmask could\nnot be determined for some reason (for example, the requested state\nwas not previously registered).\n\nAll of the state masks allocated for a given type can be retrieved\nusing the following function:\n\n\\indent\\parbox{\\linewidth}{\n\\vspace{\\baselineskip}\\noindent\\texttt{\nCCTK\\_INT* SpaceMask\\_GetStateBitsList(const char* \\emph{type\\_name})\n}\\\\\n\\hspace*{10mm}\\parbox{\\linewidth}{\n\\begin{description}\n \\item[\\emph{type\\_name}] The type for which the bitmask is to be\n determined.\n\\end{description}\n}}\n\nThe return value is a list of integers, with a length corresponding to\nthe number of states of the given type. Each of the entries is a\nbitmask which identifies the state. List entries are returned in the\norder in which they were originally assigned. This allows for a simple\ncorrespondence between states and integers (given by the index of the\nlist entry). \\emph{A fortran wrapper does not currently exist for this\nfunctionality.}\n\nThe following macros have been defined for fast setting and checking\nof the mask by direct bitwise operations:\n\n\\indent\\parbox{\\linewidth}{\n\\vspace{\\baselineskip}\\noindent\\texttt{\nvoid SpaceMask\\_SetStateBits(CCTK\\_INT* \\emph{mask}, int \\emph{point},\n \\\\\\hspace*{10mm}\n CCTK\\_INT \\emph{type\\_bits}, CCTK\\_INT \\emph{state\\_bits})\n}\\\\\n\\hspace*{10mm}\\parbox{\\linewidth}{\n\\begin{description}\n \\item[\\emph{mask}] A pointer to the mask grid function;\n \\item[\\emph{point}] The index of the point within the grid function\n array;\n \\item[\\emph{type\\_bits}] The bitmask corresponding to the required\n type;\n \\item[\\emph{state\\_bits}] The bitmask corrsponding to the required\n state;\n\\end{description}\n}}\n\n\\indent\\parbox{\\linewidth}{\n\\vspace{\\baselineskip}\\noindent\\texttt{\nint SpaceMask\\_CheckStateBits(const CCTK\\_INT* \\emph{mask}, int \\emph{point},\n \\\\\\hspace*{10mm}\n CCTK\\_INT \\emph{type\\_bits}, CCTK\\_INT \\emph{state\\_bits})\n}\\\\\n\\hspace*{10mm}\\parbox{\\linewidth}{\n\\begin{description}\n \\item[\\emph{mask}] A pointer to the mask grid function;\n \\item[\\emph{point}] The index of the point within the grid function\n array;\n \\item[\\emph{type\\_bits}] The bitmask corresponding to the required\n type;\n \\item[\\emph{state\\_bits}] The bitmask corrsponding to the required\n state;\n\\end{description}\n}}\n\n\\noindent The latter macro returns a 1 if the given state has been\nset, a 0 otherwise. The \\emph{type\\_bits} and \\emph{state\\_bits} can\nbe obtained using the \\texttt{SpaceMask\\_Get*Bits} functions,\ndescribed above.\n\n\\subsection{Accessing the mask from Fortran90 Code}\n\nThe following Fortran interfaces to the mask utilities apply only to\nFortran90 code, since fast bitwise operations are not a part of the\nFortran77 standard. An example of the use of the Fortran90 interface\ncan be found in Appendix \\ref{app:eg_F90}.\n\n\\subsubsection{Registering a new type}\n\nRegistration functions have not been implemented for the Fortran90\ninterface, though they can easily be written in C by following the\ndescriptions in Section \\ref{sec:reg_C} and the example in Appendix\n\\ref{app:eg_C}.\n\n\\subsubsection{Setting and checking mask states}\n\nThe mask states can be manipulated using the following functions:\n\n\\indent\\parbox{\\linewidth}{\n\\vspace{\\baselineskip}\\noindent\\texttt{\n SpaceMask\\_SetState(CCTK\\_INT \\emph{mask(,,)}, int \\emph{point}, \n character \\emph{type\\_name},\\\\\\hspace*{10mm} character \\emph{state\\_name})\n}\\\\\n\\hspace*{10mm}\\parbox{\\linewidth}{\n\\begin{description}\n \\item[\\emph{mask}] A pointer to the mask grid function;\n \\item[\\emph{point}] The index of the point within the grid function\n array;\n \\item[\\emph{type\\_name}] The name of the type containing the state;\n type;\n \\item[\\emph{state\\_name}] The name of the state to be set.\n\\end{description}\n}}\n\n\\noindent The value of the \\emph{mask} variable is changed to turn on\nthe specified state at the point.\n\n\\indent\\parbox{\\linewidth}{\n\\vspace{\\baselineskip}\\noindent\\texttt{\n SpaceMask\\_CheckState(CCTK\\_INT \\emph{check}, CCTK\\_INT \\emph{mask(,,)},\n int \\emph{point},\\\\\\hspace*{10mm} character \\emph{type\\_name},\n character \\emph{state\\_name})\n}\\\\\n\\hspace*{10mm}\\parbox{\\linewidth}{\n\\begin{description}\n \\item[\\emph{check}] A variable which is set to 1 if the requested\n state has been set;\n \\item[\\emph{mask}] A pointer to the mask grid function;\n \\item[\\emph{point}] The index of the point within the grid function\n array;\n \\item[\\emph{type\\_name}] The name of the type containing the state;\n type;\n \\item[\\emph{state\\_name}] The name of the state to be checked.\n\\end{description}\n}}\n\n\\subsubsection{Faster bitwise operators}\n\nAs in the C interface, alternative bitwise operators have been defined\nin order to more quickly operate on the mask at a point. In order to\nuse these functions, the bitmasks corresponding to the type and states\nin question must first be obtained using the following functions:\n\n\\indent\\parbox{\\linewidth}{\n\\vspace{\\baselineskip}\\noindent\\texttt{\n SpaceMask\\_GetTypeBits(CCTK\\_INT \\emph{type\\_bits},\n character \\emph{type\\_name})\n}\n\\hspace*{10mm}\\parbox{\\linewidth}{\n\\begin{description}\n \\item[\\emph{type\\_bits}] A variable which will be set to the bitmask of\n the requested type;\n \\item[\\emph{type\\_name}] A character string naming the type.\n\\end{description}\n}}\n\n\\indent\\parbox{\\linewidth}{\n\\vspace{\\baselineskip}\\noindent\\texttt{\n SpaceMask\\_GetStateBits(CCTK\\_INT \\emph{state\\_bits},\n character \\emph{type\\_name},\\\\\\hspace*{10mm} character \\emph{state\\_name})\n}\\\\\n\\hspace*{10mm}\\parbox{\\linewidth}{\n\\begin{description}\n \\item[\\emph{state\\_bits}] A variable which will be set to the bitmask of\n the requested state;\n \\item[\\emph{type\\_name}] A character string naming the type\n containing the state;\n \\item[\\emph{type\\_name}] A character string naming the state.\n\\end{description}\n}}\n\n\\noindent Once the bitmasks for the type and state have been obtained,\nthe following macros can be used directly:\n\n\\vspace{\\baselineskip}\\noindent\\texttt{\n SpaceMask\\_SetStateBitsF90(mask, i, j, k, type\\_bits, state\\_bits)\n}\\\\\n\n\\noindent This macro sets the value of the mask at the index $(i,j,k)$\nto the given state. It doesn't have a return value, and can be used\ndirectly inline (without a Fortran `call').\n\n\\vspace{\\baselineskip}\\noindent\\texttt{\n SpaceMask\\_CheckStateBitsF90(mask, i, j, k, type\\_bits, state\\_bits)\n}\\\\\n\n\\noindent A value of `\\texttt{.true.}' is returned if the given state\nhas been set, or `\\texttt{.false.}' otherwise. The macro can be used\ndirectly in Fortran boolean expressions, as in the examples in\nAppendix \\ref{app:eg_F90}.\n\n\n\\section{Notes}\n\nA proposal exists to provide a more versatile solution by allowing\ntables to be associated with each grid point. This could be\nimplemented using the existing standard outlined here through the\naddition of an additional integer grid function\n\n\\texttt{space\\_table\\_field}\n\nA bit of the existing \\texttt{space\\_mask} would be allocated to\nindicate whether or not a table has been associated with the given\npoint. If so, then the corresponding point in the\n\\texttt{space\\_table\\_field} would hold the table handle.\n\n\n\\section{Acknowledgements}\n\nThanks to Jonathan Thornburg, Tom Goodale, and Erik Schnetter for\nhelpful comments on the original specification. Useful implementation\nof the mask required grid symmetries to work for integer grid\nfunctions. This was done by Thomas Radke. Peter Diener helped with the\ncoding of the Fortran90 bitwise operators.\n\n\\section{Appendix}\n\n\\subsection{Example: C code}\\label{app:eg_C}\n\n\\begin{verbatim}\n#include \"cctk.h\"\n#include \"cctk_Arguments.h\"\n#include \"cctk_Parameters.h\"\n\n#include \"SpaceMask.h\"\n\n/*\n * Register a mask type with three states.\n */\nvoid Eg_RegisterMask (void)\n{\n char *state_list_excision[3] = {\"normal\", \"excise\", \"boundary\"};\n\n SpaceMask_RegisterType(\"excision\", 3, state_list_excision);\n\n return;\n}\n\n/*\n * Set the mask to the ``normal'' state at each point using the\n * slower name-reference function. See below for an example using\n * the faster bitwise operator to check the mask states.\n */\nvoid Eg_SetMaskStates (CCTK_ARGUMENTS)\n{\n DECLARE_CCTK_ARGUMENTS\n DECLARE_CCTK_PARAMETERS\n\n int i, j, k, ijk;\n\n for (k=0; k<cctk_lsh[2]; ++k)\n {\n for (j=0; j<cctk_lsh[1]; ++j)\n {\n for (i=0; i<cctk_lsh[0]; ++i)\n {\n ijk = CCTK_GFINDEX3D(cctkGH, i, j, k);\n\t\n SpaceMask_SetState(space_mask, ijk, \"excision\", \"normal\");\n }\n }\n }\n return;\n}\n\n/*\n * Check which of the points of the mask have been set to the\n * ``boundary'' state using the bitwise macro.\n */\nvoid Eg_CheckMaskStates (CCTK_ARGUMENTS)\n{\n DECLARE_CCTK_ARGUMENTS\n DECLARE_CCTK_PARAMETERS\n\n int i, j, k, ijk;\n\n CCTK_INT excision_mask;\n CCTK_INT boundary_mask;\n\n excision_mask = SpaceMask_GetTypeBits(\"excision\");\n boundary_mask = SpaceMask_GetStateBits(\"boundary\");\n\n for (k=0; k<cctk_lsh[2]; ++k)\n {\n for (j=0; j<cctk_lsh[1]; ++j)\n {\n for (i=0; i<cctk_lsh[0]; ++i)\n {\n ijk = CCTK_GFINDEX3D(cctkGH, i, j, k);\n\n if (SpaceMask_CheckStateBits(space_mask, ijk, excision_mask,\n boundary_mask))\n {\n CCTK_VINFO(CCTK_THORNSTRING, \n \"Point (%d,%d,%d) is a boundary point.\\n\",\n i, j, k);\n }\n }\n }\n }\n return;\n}\n\\end{verbatim}\n\n\n\\subsection{Example: Fortran90 code}\\label{app:eg_F90}\n\n\\begin{verbatim}\n#include \"cctk.h\"\n#include \"cctk_Arguments.h\"\n#include \"cctk_Parameters.h\"\n\n#include \"SpaceMask.h\"\n\n!\n! Sets each point of the mask to the 'normal' state. Here, 'normal'\n! is one of the states of the 'excision' type, which should have\n! been registered previously using the C SpaceMask_RegisterType()\n! function.\n!\nsubroutine Eg_SetStateByName(CCTK_ARGUMENTS)\n implicit none\n\n integer ni, nj, nk\n integer i, j, k, ijk\n\n ni = cctk_lsh(1)\n nj = cctk_lsh(2)\n nk = cctk_lsh(3)\n\n do k=1,nk\n do j=1,nj\n do i=1,ni\n \n ijk = (i-1) + ni*((j-1) + nj*(k-1))\n\n call SpaceMask_SetState(space_mask, ijk, \"excision\", \"normal\")\n \n end do\n end do\n end do\n\nend subroutine Eg_SetStateByName\n\n!\n! Sets the mask values within a radius of 1 to the 'excise' state,\n! then does a check of the state of each point. The bitwise macros\n! are used in this case for greater efficiency in setting/checking\n! the mask.\n!\nsubroutine Eg_SetExcisedRegionByBitmask(CCTK_ARGUMENTS)\n implicit none\n\n integer ni, nj, nk\n integer i, j, k, ijk\n\n CCTK_INT type_bits, excised\n\n ni = cctk_lsh(1)\n nj = cctk_lsh(2)\n nk = cctk_lsh(3)\n\n call SpaceMask_GetTypeBits(type_bits, \"excision\")\n call SpaceMask_GetStateBits(excised, \"excision\", \"excised\")\n\n do k=1,nk\n do j=1,nj\n do i=1,ni\n\n if (r(i,j,k).lt.1.d0) then\n SpaceMask_SetStateBitsF90(space_mask, i, j, k, type_bits, &\n excised)\n end if\n\n end do\n end do\n end do\n\n do k=1,nk\n do j=1,nj\n do i=1,ni\n if (SpaceMask_CheckStateBitsF90(space_mask, i, j, k, type_bits, &\n excised)) then\n write(*,*) \"The point (\", i, j, k, \") has been excised.\"\n end if\n end do\n end do\n end do\n\nend subroutine Eg_SetExcisedRegionByBitmask\n\\end{verbatim}\n\n% Do not delete next line\n% END CACTUS THORNGUIDE\n\n\\end{document}\n" |
| } |
| } |