{ "thorn_name": "CactusBase/Boundary", "url": "https://bitbucket.org/cactuscode/cactusbase.git", "configuration": "# Configuration definition for thorn Boundary\n# $Header$\n\n# This will disappear once function aliasing has requires\n\nPROVIDES Boundary\n{\n SCRIPT\n LANG\n}\n\n", "interface": "# Interface definition for thorn Boundary\n# $Header$\n\nimplements: boundary\n\nINCLUDES HEADER: Boundary.h in Boundary.h\n\n\n\n# Implementation of new boundary spec:\n\nCCTK_INT FUNCTION Boundary_RegisterPhysicalBC(CCTK_POINTER_TO_CONST IN GH, \\\n CCTK_INT IN CCTK_FPOINTER function_pointer(CCTK_POINTER_TO_CONST IN GH, \\\n CCTK_INT IN num_vars, \\\n CCTK_INT ARRAY IN var_indices, \\\n CCTK_INT ARRAY IN faces, \\\n CCTK_INT ARRAY IN boundary_widths, \\\n CCTK_INT ARRAY IN table_handles),\\\n CCTK_STRING IN bc_name)\nPROVIDES FUNCTION Boundary_RegisterPhysicalBC WITH \\\n Bdry_Boundary_RegisterPhysicalBC LANGUAGE C\nUSES FUNCTION Boundary_RegisterPhysicalBC\n\nCCTK_POINTER_TO_CONST FUNCTION Boundary_QueryRegisteredPhysicalBC( \\\n CCTK_POINTER_TO_CONST IN GH, \\\n CCTK_STRING IN bc_name)\nPROVIDES FUNCTION Boundary_QueryRegisteredPhysicalBC WITH \\\n Bdry_Boundary_QueryRegisteredPhysicalBC LANGUAGE C\n\nCCTK_INT FUNCTION Boundary_SelectVarForBC(CCTK_POINTER_TO_CONST IN GH, \\\n CCTK_INT IN faces, CCTK_INT IN boundary_width, CCTK_INT IN table_handle, \\\n CCTK_STRING IN var_name, CCTK_STRING IN bc_name)\nCCTK_INT FUNCTION Boundary_SelectVarForBCI(CCTK_POINTER_TO_CONST IN GH, \\\n CCTK_INT IN faces, CCTK_INT IN boundary_width, CCTK_INT IN table_handle, \\\n CCTK_INT IN var_index, CCTK_STRING IN bc_name)\nCCTK_INT FUNCTION Boundary_SelectGroupForBC(CCTK_POINTER_TO_CONST IN GH, \\\n CCTK_INT IN faces, CCTK_INT IN boundary_width, CCTK_INT IN table_handle, \\\n CCTK_STRING IN group_name, CCTK_STRING IN bc_name)\nCCTK_INT FUNCTION Boundary_SelectGroupForBCI(CCTK_POINTER_TO_CONST IN GH, \\\n CCTK_INT IN faces, CCTK_INT IN boundary_width, CCTK_INT IN table_handle, \\\n CCTK_INT IN group_index, CCTK_STRING IN bc_name)\nPROVIDES FUNCTION Boundary_SelectVarForBC WITH Bdry_Boundary_SelectVarForBC \\\n LANGUAGE C\nPROVIDES FUNCTION Boundary_SelectVarForBCI WITH \\\n Bdry_Boundary_SelectVarForBCI LANGUAGE C\nPROVIDES FUNCTION Boundary_SelectGroupForBC WITH \\\n Bdry_Boundary_SelectGroupForBC LANGUAGE C\nPROVIDES FUNCTION Boundary_SelectGroupForBCI WITH \\\n Bdry_Boundary_SelectGroupForBCI LANGUAGE C\n\nCCTK_INT FUNCTION Boundary_SelectedGVs(CCTK_POINTER_TO_CONST IN GH, \\\n CCTK_INT IN array_size, CCTK_INT ARRAY OUT var_indicies, \\\n CCTK_INT ARRAY OUT faces, CCTK_INT ARRAY OUT boundary_widths, \\\n CCTK_INT ARRAY OUT table_handles, CCTK_STRING IN bc_name)\nPROVIDES FUNCTION Boundary_SelectedGVs WITH Bdry_Boundary_SelectedGVs \\\n LANGUAGE C\n\nCCTK_INT FUNCTION\n Driver_FilterOutVarForBCI\n (CCTK_POINTER_TO_CONST IN cctkGH,\n CCTK_INT IN var_index)\nUSES FUNCTION Driver_FilterOutVarForBCI\n\nCCTK_INT FUNCTION Driver_NotifyDataModified\n (CCTK_POINTER_TO_CONST IN cctkGH,\n CCTK_INT ARRAY IN variables,\n CCTK_INT ARRAY IN tls,\n CCTK_INT IN nvariables,\n CCTK_INT ARRAY IN where)\nUSES FUNCTION Driver_NotifyDataModified\n\nCCTK_INT FUNCTION \\\n SymmetryTableHandleForGrid (CCTK_POINTER_TO_CONST IN cctkGH)\nREQUIRES FUNCTION SymmetryTableHandleForGrid\n\n", "param": "# Parameter definitions for thorn Boundary\n# $Header$\n\nshares: cactus\n\nUSES KEYWORD presync_mode\n\nrestricted:\n\nINT radpower \"Power of decay rate in extrapolation used in radiative boundaries\"\n{\n : :: \"A negative value switches off this feature\"\n} -1\n\nBOOLEAN register_scalar \"Register routine to handle the 'Scalar' boundary condition\"\n{\n} \"yes\"\n\nBOOLEAN register_flat \"Register routine to handle the 'Flat' boundary condition\"\n{\n} \"yes\"\n\nBOOLEAN register_radiation \"Register routine to handle the 'Radiation' boundary condition\"\n{\n} \"yes\"\n\nBOOLEAN register_copy \"Register routine to handle the 'Copy' boundary condition\"\n{\n} \"yes\"\n\nBOOLEAN register_robin \"Register routine to handle the 'Robin' boundary condition\"\n{\n} \"yes\"\n\nBOOLEAN register_static \"Register routine to handle the 'Static' boundary condition\"\n{\n} \"yes\"\n\nBOOLEAN register_none \"Register routine to handle the 'None' boundary condition\"\n{\n} \"yes\"\n", "schedule": "# Schedule definitions for thorn Boundary\n# $Header$\n\nschedule Boundary_Check at CCTK_PARAMCHECK\n{\n LANG: C\n} \"Check dimension of grid variables\"\n\nschedule Boundary_RegisterBCs at CCTK_WRAGH before Driver_BoundarySelect\n{\n LANG: C\n OPTIONS: global\n} \"Register boundary conditions that this thorn provides\"\n\n# New boundary infrastructure:\n\nschedule GROUP ApplyBCs\n{\n} \"Apply boundary conditions\"\n\nschedule GROUP BoundaryConditions in ApplyBCs BEFORE Boundary_ClearSelection\n{\n} \"Execute all boundary conditions\"\n\nschedule Boundary_ApplyPhysicalBCs in BoundaryConditions\n{\n LANG: C\n} \"Apply all requested local physical boundary conditions\"\n\nschedule Boundary_ClearSelection in ApplyBCs\n{\n LANG: C\n OPTIONS: level\n} \"Unselect all grid variables for boundary conditions\"\n", "src": { "make.code.defn": "# Main make.code.defn file for thorn Boundary\n# $Header$\n\n# Source files in this directory\nSRCS = ScalarBoundary.c\\\n StaticBoundary.c\\\n CopyBoundary.c\\\n FlatBoundary.c\\\n RadiationBoundary.c\\\n RobinBoundary.c\\\n NoneBoundary.c\\\n Boundary.c\\\n Register.c\\\n Check.c\n", "Check.c": "/*@@\n @file Check.c\n @date 19 May 2003\n @author David Rideout\n @desc\n Check that the dimension of any grid variables is not greater than\n what the faces specification can handle (currently 15).\n @enddesc\n @history\n @hdate\n @hauthor\n @hdesc\n @endhistory\n @version $Header$\n@@*/\n\n#include \"cctk.h\"\n#include \"cctk_Arguments.h\"\n\n#include \n#include \n\n#include \"Boundary.h\"\n\n/* the rcs ID and its dummy function to use it */\nstatic const char *rcsid = \"$Header$\";\nCCTK_FILEVERSION(CactusBase_Boundary_Check_c);\n\n/* Maximum dimension for grid variables to be selected for BC.\n Restriction is representation of set of faces in a 32 bit signed integer. */\n#define MAX_DIM 15\n\n/********************************************************************\n ******************** Scheduled Routines ***********************\n ********************************************************************/\n\n/*@@\n @routine Boundary_Check\n @date 19 May 2003\n @author David Rideout\n @desc\n Check that the dimension of any grid variables is not greater than\n what the faces specification can handle (currently 15).\n @enddesc\n @calls\n @history\n Note that in future versions of Cactus this will require the GH\n passed through CCTK_ARGUMENTS.\n @endhistory\n @var CCTK_ARGUMENTS\n @vdesc standard Cactus argument list\n @vtype various\n @vio in\n @endvar\n @returntype int\n @returndesc\n 0 success\n -1 cactus executable contains variable group with too many\n dimensions\n @endreturndesc\n@@*/\n\nvoid Boundary_Check(CCTK_ARGUMENTS) {\n DECLARE_CCTK_ARGUMENTS;\n\n if (CCTK_MaxDim() > 15) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Executable contains variable group with more than 15 \"\n \"dimensions. Thorn Boundary will not function properly for \"\n \"these variable groups.\");\n }\n}\n\n/********************************************************************\n ********************* Externally visible helpers *******************\n ********************************************************************/\n\n/*@@\n @routine BndSanityCheckWidths\n @date Wed Dec 11 17:54:25 PST 2013\n @author Roland Haas\n @desc\n Checks that boundary width is less then 100 grid points. Aborts\n if this is not the case since this likely points to a user\n error.\n @enddesc\n @calls\n @history\n @endhistory\n @var GH\n @vdesc cctkGH *\n @vtype CCTK_POINTER_TO_CONST\n @vio in\n @endvar\n @var varindex\n @vdesc Cactus variable to which symmetry is applid\n @vtype CCTK_INT\n @vio in\n @endvar\n @var dim\n @vdesc Dimensionality of variable, there are 2*dim faces.\n @vtype CCTK_INT\n @vio int\n @endvar\n @var boundary_widths\n @vdesc width of boundary at each face\n @vtype const CCTK_INT *\n @vio in\n @endvar\n @var bcname\n @vdesc user readable name of Boundary condition\n @vtype const char *\n @vio in\n @endvar\n @returntype none\n @returndesc\n aborts on error\n @endreturndesc\n@@*/\nvoid BndSanityCheckWidths(const cGH *GH, CCTK_INT varindex, CCTK_INT dim,\n const CCTK_INT *boundary_widths, const char *bcname) {\n for (int i = 0; i < 2 * dim; i++) {\n // due to the special meaning of width<0 in Boundary this does not catch\n // width<0 in the SelectVarForBCs call, but only negative BOUNDARY_WIDTH\n // table entries\n if (boundary_widths[i] > 100 || boundary_widths[i] < 0) {\n char *fullname = CCTK_FullName(varindex);\n const char dims[3] = \"xyz\";\n const char *cond = boundary_widths[i] < 0 ? \"<0\" : \">100\";\n assert(dim < (int)sizeof(dims));\n CCTK_VError(__LINE__, __FILE__, CCTK_THORNSTRING,\n \"Tried to register a physical boundary condition \\\"%s\\\" for \"\n \"variable \\\"%s\\\" with a boundary zone width %s in the %c \"\n \"direction -- this looks like an error.\",\n bcname, fullname, cond, dims[dim]);\n free(fullname);\n }\n }\n}\n", "Boundary.h": "/*@@\n @file Boundary.h\n @date Tue Sep 26 11:50:46 2000\n @author Gerd Lanfermann\n @desc\n Prototypes for boundary routines\n @enddesc\n @version $Header$\n@@*/\n\n#ifndef _BOUNDARY_H_\n#define _BOUNDARY_H_\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/* data type for pointer to function which implements a physical boundary\n condition: */\ntypedef CCTK_INT (*phys_bc_fn_ptr)(CCTK_POINTER_TO_CONST, const CCTK_INT,\n const CCTK_INT *, const CCTK_INT *,\n const CCTK_INT *, const CCTK_INT *);\n\n/* check boundary withd and abort if unlikely large (>100 points) */\nvoid BndSanityCheckWidths(const cGH *GH, CCTK_INT varindex, CCTK_INT dim,\n const CCTK_INT *boundary_widths, const char *bcname);\n\n/* prototype for routine registed as providing 'None' boundary condition */\nCCTK_INT BndNone(const cGH *GH, CCTK_INT num_vars, CCTK_INT *var_indicies,\n CCTK_INT *faces, CCTK_INT *boundary_widths,\n CCTK_INT *table_handle);\n\n/* Scalar boundaries */\n\n/* prototype for routine registed as providing 'Scalar' boundary condition */\nCCTK_INT BndScalar(const cGH *GH, CCTK_INT num_vars, CCTK_INT *var_indicies,\n CCTK_INT *faces, CCTK_INT *boundary_widths,\n CCTK_INT *table_handle);\n\nint BndScalarDirGI(const cGH *GH, int stencil_size, int dir, CCTK_REAL var0,\n int gi);\nint BndScalarDirGN(const cGH *GH, int stencil_size, int dir, CCTK_REAL var0,\n const char *gname);\nint BndScalarDirVI(const cGH *GH, int stencil_size, int dir, CCTK_REAL var0,\n int vi);\nint BndScalarDirVN(const cGH *GH, int stencil_size, int dir, CCTK_REAL var0,\n const char *vname);\n\nint BndScalarGI(const cGH *GH, const int *stencil, CCTK_REAL var0, int gi);\nint BndScalarGN(const cGH *GH, const int *stencil, CCTK_REAL var0,\n const char *gname);\nint BndScalarVI(const cGH *GH, const int *stencil, CCTK_REAL var0, int vi);\nint BndScalarVN(const cGH *GH, const int *stencil, CCTK_REAL var0,\n const char *vname);\n\n/* Copying boundaries */\n\n/* prototype for routine registed as providing 'Copy' boundary condition */\nCCTK_INT BndCopy(const cGH *GH, CCTK_INT num_vars, CCTK_INT *var_indicies,\n CCTK_INT *faces, CCTK_INT *boundary_widths,\n CCTK_INT *table_handle);\n\nint BndCopyDirGI(const cGH *GH, int stencil_size, int dir, int gi_to,\n int gi_from);\nint BndCopyDirGN(const cGH *GH, int stencil_size, int dir, const char *gname_to,\n const char *gname_from);\nint BndCopyDirVI(const cGH *GH, int stencil_size, int dir, int vi_to,\n int vi_from);\nint BndCopyDirVN(const cGH *GH, int stencil_size, int dir, const char *vname_to,\n const char *vname_from);\n\nint BndCopyGI(const cGH *GH, const int *stencil, int gi_to, int gi_from);\nint BndCopyGN(const cGH *GH, const int *stencil, const char *gname_to,\n const char *gname_from);\nint BndCopyVI(const cGH *GH, const int *stencil, int vi_to, int vi_from);\nint BndCopyVN(const cGH *GH, const int *stencil, const char *vname_to,\n const char *vname_from);\n\n/* Static boundaries */\n\n/* prototype for routine registed as providing 'Static' boundary condition */\nCCTK_INT BndStatic(const cGH *GH, CCTK_INT num_vars, CCTK_INT *var_indicies,\n CCTK_INT *faces, CCTK_INT *boundary_widths,\n CCTK_INT *table_handle);\n\nint BndStaticDirGI(const cGH *GH, int stencil_size, int dir, int gi);\nint BndStaticDirGN(const cGH *GH, int stencil_size, int dir, const char *gname);\nint BndStaticDirVI(const cGH *GH, int stencil_size, int dir, int vi);\nint BndStaticDirVN(const cGH *GH, int stencil_size, int dir, const char *vname);\n\nint BndStaticGI(const cGH *GH, const int *stencil, int gi);\nint BndStaticGN(const cGH *GH, const int *stencil, const char *gname);\nint BndStaticVI(const cGH *GH, const int *stencil, int vi);\nint BndStaticVN(const cGH *GH, const int *stencil, const char *vname);\n\n/* Radiative boundaries */\n\n/* prototype for routine registed as providing 'Radiative' boundary conditions\n */\nCCTK_INT BndRadiative(const cGH *GH, CCTK_INT num_vars, CCTK_INT *var_indicies,\n CCTK_INT *faces, CCTK_INT *boundary_widths,\n CCTK_INT *table_handle);\n\nint BndRadiativeDirGI(const cGH *GH, int stencil_size, int dir, CCTK_REAL var0,\n CCTK_REAL v0, int gi, int gi_p);\nint BndRadiativeDirGN(const cGH *GH, int stencil_size, int dir, CCTK_REAL var0,\n CCTK_REAL v0, const char *gname_to,\n const char *gname_from);\nint BndRadiativeDirVI(const cGH *GH, int stencil_size, int dir, CCTK_REAL var0,\n CCTK_REAL v0, int vi, int vi_p);\nint BndRadiativeDirVN(const cGH *GH, int stencil_size, int dir, CCTK_REAL var0,\n CCTK_REAL v0, const char *vname_to,\n const char *vname_from);\n\nint BndRadiativeGI(const cGH *GH, const int *stencil, CCTK_REAL var0,\n CCTK_REAL v0, int gi, int gi_p);\nint BndRadiativeGN(const cGH *GH, const int *stencil, CCTK_REAL var0,\n CCTK_REAL v0, const char *gname_to, const char *gname_from);\nint BndRadiativeVI(const cGH *GH, const int *stencil, CCTK_REAL var0,\n CCTK_REAL v0, int vi, int vi_p);\nint BndRadiativeVN(const cGH *GH, const int *stencil, CCTK_REAL var0,\n CCTK_REAL v0, const char *vname_to, const char *vname_from);\n\n/* Robin boundaries */\n\n/* prototype for routine registed as providing 'Robin' boundary condition */\nCCTK_INT BndRobin(const cGH *GH, CCTK_INT num_vars, CCTK_INT *var_indicies,\n CCTK_INT *faces, CCTK_INT *boundary_widths,\n CCTK_INT *table_handle);\n\nint BndRobinGI(const cGH *GH, const int *stencil, CCTK_REAL finf, int npow,\n int gi);\nint BndRobinGN(const cGH *GH, const int *stencil, CCTK_REAL finf, int npow,\n const char *gname);\nint BndRobinVI(const cGH *GH, const int *stencil, CCTK_REAL finf, int npow,\n int vi);\nint BndRobinVN(const cGH *GH, const int *stencil, CCTK_REAL finf, int npow,\n const char *vname);\n\n/* Flat boundaries */\n\n/* prototype for routine registed as providing 'Flat' boundary condition */\nCCTK_INT BndFlat(const cGH *GH, CCTK_INT num_vars, CCTK_INT *var_indicies,\n CCTK_INT *faces, CCTK_INT *boundary_widths,\n CCTK_INT *table_handle);\n\nint BndFlatDirGI(const cGH *GH, int stencil_size, int dir, int gi);\nint BndFlatDirGN(const cGH *GH, int stencil_size, int dir, const char *gname);\nint BndFlatDirVI(const cGH *GH, int stencil_size, int dir, int vi);\nint BndFlatDirVN(const cGH *GH, int stencil_size, int dir, const char *vname);\n\nint BndFlatGI(const cGH *GH, const int *stencil, int gi);\nint BndFlatGN(const cGH *GH, const int *stencil, const char *gname);\nint BndFlatVI(const cGH *GH, const int *stencil, int vi);\nint BndFlatVN(const cGH *GH, const int *stencil, const char *vname);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* _BOUNDARY_H_ */\n", "Boundary.c": "/*@@\n @file Boundary.c\n @date Sat Oct 26 22:39:40 CEST 2002\n @author David Rideout\n @desc\n Implements the new boundary specification.\n @enddesc\n @version $Header$\n@@*/\n\n#include \n#include \n#include \n\n#include \"cctk.h\"\n#include \"cctk_Arguments.h\"\n#include \"cctk_Functions.h\"\n#include \"cctk_Parameters.h\"\n#include \"util_Table.h\"\n#include \"util_String.h\"\n#include \"Boundary.h\"\n\nstatic const char *rcsid = \"$Header$\";\n\nCCTK_FILEVERSION(CactusBase_Boundary_Boundary_c);\n\n/********************************************************************\n ********************* Local Data Types ***********************\n ********************************************************************/\n/* #define DEBUG 1 */\n\n/* Linked list, called a var list, for holding variables selected for a bc:\n * Entries are sorted in the order they appear in struct BCVAR,\n * i.e. the var index varies more rapidly that table handle.\n * (Currently no sorting is done on faces specification.)\n *\n * There will be one such linked list for each type of boundary\n * condition selected (i.e. one for each bc_name).\n */\nstruct BCVAR {\n struct BCVAR *next; /* pointer to next entry in list */\n int faces; /* set of faces for this application of bc */\n int width; /* width of the boundary, if it is equal for all faces */\n int table; /* table handle holding extra arguments */\n int var; /* index of grid variable to which to apply the bc */\n};\n\n/*\n * Linked list of var lists, one for each type of requested bc\n * (i.e. one for each bc_name).\n *\n * Here is also recorded how many of each bc type have\n * been selected so far, so that the GetSelectedBCs doesn't have to be\n * run through twice; once simply to get the number of selected vars.\n *\n * This list is sorted by bc_name. Alternatively one could sort it by\n * associated function pointer, but this seems a bit obtuse.\n */\nstruct BCDATA {\n struct BCDATA *next; /* pointer to next element of this list */\n struct BCVAR *var_list; /* pointer to first element of a var list */\n const char *bc_name; /* name of bc */\n int num; /* number of entries for this bc in var list */\n};\n\n/********************************************************************\n ********************* Local Routine Prototypes *********************\n ********************************************************************/\n\nstatic int entry_greater_than(struct BCVAR *new, struct BCVAR *current);\n#ifdef DEBUG\nstatic void print_selections_database(void);\nstatic void print_selected_faces(void);\n#endif\n\n/********************************************************************\n ***************** Aliased Routine Prototypes ***********************\n ********************************************************************/\n\nCCTK_INT Bdry_Boundary_RegisterPhysicalBC(CCTK_POINTER_TO_CONST _GH,\n phys_bc_fn_ptr fn_pointer,\n CCTK_STRING bc_name);\nCCTK_POINTER_TO_CONST\nBdry_Boundary_QueryRegisteredPhysicalBC(CCTK_POINTER_TO_CONST _GH,\n CCTK_STRING bc_name);\nCCTK_INT Bdry_Boundary_SelectVarForBC(CCTK_POINTER_TO_CONST _GH, CCTK_INT faces,\n CCTK_INT boundary_width,\n CCTK_INT table_handle,\n CCTK_STRING var_name,\n CCTK_STRING bc_name);\nCCTK_INT Bdry_Boundary_SelectVarForBCI(CCTK_POINTER_TO_CONST _GH,\n CCTK_INT faces, CCTK_INT boundary_width,\n CCTK_INT table_handle,\n CCTK_INT var_index, CCTK_STRING bc_name);\nCCTK_INT Bdry_Boundary_SelectGroupForBC(CCTK_POINTER_TO_CONST _GH,\n CCTK_INT faces, CCTK_INT boundary_width,\n CCTK_INT table_handle,\n CCTK_STRING group_name,\n CCTK_STRING bc_name);\nCCTK_INT\nBdry_Boundary_SelectGroupForBCI(CCTK_POINTER_TO_CONST _GH, CCTK_INT faces,\n CCTK_INT boundary_width, CCTK_INT table_handle,\n CCTK_INT group_index, CCTK_STRING bc_name);\nCCTK_INT Bdry_Boundary_SelectedGVs(CCTK_POINTER_TO_CONST _GH,\n CCTK_INT array_size, CCTK_INT *var_indices,\n CCTK_INT *faces, CCTK_INT *boundary_widths,\n CCTK_INT *table_handles,\n CCTK_STRING bc_name);\n\n/********************************************************************\n ***************** Scheduled Routine Prototypes *********************\n ********************************************************************/\n\nvoid Boundary_ApplyPhysicalBCs(CCTK_ARGUMENTS);\nvoid Boundary_ClearSelection(CCTK_ARGUMENTS);\n\n/********************************************************************\n ********************* Local Data *****************************\n ********************************************************************/\n\n/* Table for holding function pointers associated with each boundary condition:\n * This table has\n * key = boundary condition name (eg \"Radiation\")\n * value = a CCTK_FPOINTER pointing to a function to implement that BC\n */\nstatic int physbc_table_handle = -1;\n\n/* Linked list for storing data associated with selections list itself */\nstatic struct BCDATA *bcdata_list = NULL;\n\n/* Array of (number of variables) faces specifications, for checking\n for duplicate bc selection */\nstatic CCTK_INT *selected_faces = NULL;\nstatic int num_cctk_vars = 0;\n\n/* 'The' GH, i.e. to check that there is not more than one... */\nstatic CCTK_POINTER_TO_CONST theGH = NULL;\n\n/********************************************************************\n ********************* Aliased Routines **********************\n ********************************************************************/\n\n/*@@\n @routine Bdry_Boundary_RegisterPhysicalBC\n @date Sun Nov 3 19:51:37 CET 2002\n @author David Rideout\n @desc\n Used to register physical boundary conditions with the boundary\n thorn.\n @enddesc\n @calls\n @history\n @endhistory\n @var _GH\n @vdesc cctkGH *\n @vtype CCTK_POINTER_TO_CONST\n @vio in\n @endvar\n @var fn_pointer\n @vdesc pointer to function which implements boundary condition bc_name\n @vtype phys_bc_fn_ptr\n @vio in\n @endvar\n @var bc_name\n @vdesc name of boundary condition\n @vtype CCTK_STRING\n @vio in\n @endvar\n @returntype CCTK_INT\n @returndesc\n 0 success\n -1 error creating table to hold bcs\n -2 duplicate registration of bc_name\n -3 error adding bc to table\n @endreturndesc\n@@*/\nCCTK_INT Bdry_Boundary_RegisterPhysicalBC(CCTK_POINTER_TO_CONST _GH,\n phys_bc_fn_ptr fn_pointer,\n CCTK_STRING bc_name) {\n int retval;\n const cGH *GH = _GH;\n\n#ifdef DEBUG\n printf(\"Boundary_RegisterPhysicalBC: called with GH=%p\\n\", GH);\n#endif\n\n /* Check to see if this is a new GH */\n if (!theGH) /* This is the first valid GH passed to a Boundary routine */\n {\n theGH = GH;\n } else if (GH != theGH) {\n CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"New GH passed to Boundary_RegisterPhysicalBC. \"\n \"Thorn CactusBase/Boundary does not yet handle multiple GHs \"\n \"properly.\");\n }\n\n /* Check input arguments */\n if (!fn_pointer) {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Null pointer passed to Boundary_RegisterPhysicalBC. \"\n \"Is this intentional?\");\n }\n\n /* Check if NULL has been passed for fn_pointer */\n if (!fn_pointer) {\n /* Use dummy function if NULL function registered (e.g. for\n non-local physical bcs) */\n fn_pointer = (phys_bc_fn_ptr)&BndNone;\n }\n\n /* Create the registered routines table if necessary */\n if (physbc_table_handle == -1) {\n physbc_table_handle = Util_TableCreate(UTIL_TABLE_FLAGS_CASE_INSENSITIVE);\n if (physbc_table_handle < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Error creating table to hold registered physical boundary \"\n \"conditions\");\n retval = -1;\n }\n }\n\n /* Check if boundary condition has already been registered under this name */\n if (Util_TableGetFnPointer(physbc_table_handle, NULL, bc_name) >= 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"There already exists a physical boundary condition \"\n \"registered under the name \\\"%s\\\"\",\n bc_name);\n retval = -2;\n } else {\n /* Add boundary condition to table */\n if (Util_TableSetFnPointer(physbc_table_handle, (CCTK_FPOINTER)fn_pointer,\n bc_name) < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Error adding boundary condition to table\");\n retval = -3;\n }\n retval = 0;\n }\n\n return retval;\n}\n\n/*@@\n @routine Bdry_Boundary_QueryRegisteredPhysicalBC\n @date Thu May 7 17:30:43 CDT 2020\n @author Roland Haas\n @desc\n Returns the function pointer associated with a registered\n boundary condition.\n @enddesc\n @calls\n @history\n @endhistory\n @var _GH\n @vdesc cctkGH *\n @vtype CCTK_POINTER_TO_CONST\n @vio in\n @endvar\n @var bc_name\n @vdesc name of boundary condition\n @vtype CCTK_STRING\n @vio in\n @endvar\n @returntype CCTK_POINTER_TO_CONST\n @returndesc\n pointer to boundary condition function\n NULL no such boundary condition registered\n @endreturndesc\n@@*/\nCCTK_POINTER_TO_CONST\nBdry_Boundary_QueryRegisteredPhysicalBC(CCTK_POINTER_TO_CONST _GH,\n CCTK_STRING bc_name) {\n /* Has some function implementing bc_name been registered? */\n CCTK_FPOINTER retval = NULL;\n int err = Util_TableGetFnPointer(physbc_table_handle, &retval, bc_name);\n if(err < 0) {\n retval = NULL;\n }\n\n return retval;\n}\n\n/*@@\n @routine Bdry_Boundary_SelectVarForBC\n @date Sun Nov 3 19:51:37 CET 2002\n @author David Rideout\n @desc\n Used to select a Cactus variable to have boundary\n conditions applied, using its variable name.\n @enddesc\n @calls\n @history\n @endhistory\n @var _GH\n @vdesc cctkGH *\n @vtype CCTK_POINTER_TO_CONST\n @vio in\n @endvar\n @var faces\n @vdesc set of faces to which to apply the boundary condition\n @vtype CCTK_INT\n @vio in\n @endvar\n @var width\n @vdesc if >=0, width of boundary in all directions\n @vtype CCTK_INT\n @vio in\n @endvar\n @var table_handle\n @vdesc handle of table which holds arguments to be passed to bc\n @vtype CCTK_INT\n @vio in\n @endvar\n @var var_name\n @vdesc name of variable to which to apply bc\n @vtype CCTK_STRING\n @vio in\n @endvar\n @var bc_name\n @vdesc name of bc to apply\n @vtype CCTK_STRING\n @vio in\n @endvar\n @returntype CCTK_INT\n @returndesc\n 0 success\n -11 invalid variable name\n or the returncode of @seeroutine Bdry_Boundary_SelectVarForBCI\n @endreturndesc\n@@*/\nCCTK_INT Bdry_Boundary_SelectVarForBC(CCTK_POINTER_TO_CONST _GH, CCTK_INT faces,\n CCTK_INT width, CCTK_INT table_handle,\n CCTK_STRING var_name,\n CCTK_STRING bc_name) {\n int retval, var_index;\n const cGH *GH = _GH;\n\n#ifdef DEBUG\n printf(\"Boundary_SelectVarForBC:\\n\");\n printf(\" called with faces=%d, width=%d, table_handle=%d, var_name=%s, \"\n \"bc_name=%s\\n\",\n faces, width, table_handle, var_name, bc_name);\n#endif\n\n retval = 0;\n\n var_index = CCTK_VarIndex(var_name);\n if (var_index < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable name\");\n retval = -11;\n } else {\n retval = Bdry_Boundary_SelectVarForBCI(GH, faces, width, table_handle,\n var_index, bc_name);\n }\n\n return retval;\n}\n\n/*@@\n @routine Bdry_Boundary_SelectVarForBCI\n @date Sun Nov 3 19:51:37 CET 2002\n @author David Rideout\n @desc\n Used to select a Cactus variable to have boundary\n conditions applied, using its var index.\n @enddesc\n @calls\n @history\n @endhistory\n @var _GH\n @vdesc cctkGH *\n @vtype CCTK_POINTER_TO_CONST\n @vio in\n @endvar\n @var faces\n @vdesc set of faces to which to apply the boundary condition\n @vtype CCTK_INT\n @vio in\n @endvar\n @var width\n @vdesc if >=0, width of boundary in all directions\n @vtype CCTK_INT\n @vio in\n @endvar\n @var table_handle\n @vdesc handle of table which holds arguments to be passed to bc\n @vtype CCTK_INT\n @vio in\n @endvar\n @var var_index\n @vdesc index of variable to which to apply bc\n @vtype CCTK_INT\n @vio in\n @endvar\n @var bc_name\n @vdesc name of bc to apply\n @vtype CCTK_STRING\n @vio in\n @endvar\n @returntype CCTK_INT\n @returndesc\n 0 success\n -2 no such physical boundary condition registered\n -3 faces already selected for bc\n -5 new value for GH passed in\n -7 invalid variable index\n @endreturndesc\n@@*/\nCCTK_INT Bdry_Boundary_SelectVarForBCI(CCTK_POINTER_TO_CONST _GH,\n CCTK_INT faces, CCTK_INT width,\n CCTK_INT table_handle,\n CCTK_INT var_index,\n CCTK_STRING bc_name) {\n DECLARE_CCTK_PARAMETERS;\n\n int retval;\n struct BCVAR *new_entry;\n struct BCVAR *current;\n struct BCVAR *previous;\n struct BCDATA *current_bcdata;\n struct BCDATA *previous_bcdata;\n struct BCDATA *new_bcdata;\n const cGH *GH = _GH;\n\n retval = 0;\n\n if (var_index < 0 || var_index >= CCTK_NumVars()) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable index\");\n retval = -7;\n return retval;\n }\n\n#ifdef DEBUG\n printf(\"Boundary_SelectVarForBCI:\\n\");\n printf(\" called with GH=%p, faces=%d, width=%d, table_handle=%d, \"\n \"var_index=%d, bc_name=%s\\n\",\n GH, faces, width, table_handle, var_index, bc_name);\n printf(\" vi %d corresponds to %s\\n\", var_index, CCTK_VarName(var_index));\n#endif\n\n /* Check to see if this is a new GH */\n if (!theGH) /* This is the first valid GH passed to a Boundary routine */\n {\n theGH = GH;\n } else if (GH != theGH) {\n CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"New GH passed to Boundary_SelectVarForBCI. \"\n \"Thorn CactusBase/Boundary does not yet handle multiple GHs \"\n \"properly.\");\n retval = -5;\n }\n\n /* Check that this request is allowed\n ---------------------------------- */\n\n /* Has some function implementing bc_name been registered? */\n if (!Util_TableQueryValueInfo(physbc_table_handle, NULL, NULL, bc_name)) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"There is no function implementing the physical boundary \"\n \"condition %s\",\n bc_name);\n retval = -2;\n }\n\n/* Have any of these faces already been selected for a bc? */\n#ifdef DEBUG\n print_selected_faces();\n#endif\n if (selected_faces && selected_faces[var_index] & faces) {\n /* we quietly accept the very same bc being selected twice if one of them\n * may have been a driver bc to allow code to easily support both */\n if (!CCTK_EQUALS(presync_mode, \"off\")) {\n for (current_bcdata = bcdata_list; current_bcdata;\n current_bcdata = current_bcdata->next) {\n if (CCTK_Equals(current_bcdata->bc_name, bc_name)) {\n for(current = current_bcdata->var_list; current;\n current = current->next) {\n if(current->var == var_index && current->faces == faces &&\n current->width == width && current->table == table_handle) {\n return 0;\n }\n }\n }\n }\n }\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"%s has already been selected for a bc\",\n CCTK_VarName(var_index));\n retval = -3;\n }\n\n /* Honor request\n ------------- */\n if (!retval) {\n\n /* allocate memory for new entry in database */\n new_entry = malloc(sizeof(struct BCVAR));\n if (!new_entry) {\n CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Unable to allocate memory for entry into \"\n \"'selected for bcs' database\");\n /*retval = -1;*/\n }\n\n /* populate new entry with data */\n new_entry->faces = faces;\n new_entry->width = width;\n new_entry->table = table_handle;\n new_entry->var = var_index;\n /* new_entry -> next will be filled in later */\n\n /* Into which of bcdata's lists should this variable be placed? */\n current = previous = NULL;\n for (current_bcdata = bcdata_list; current_bcdata;\n previous_bcdata = current_bcdata,\n current_bcdata = current_bcdata->next) {\n#ifdef DEBUG\n printf(\"Boundary_SelectVarForBCI: looping through bcdata list, at \"\n \"current_bcdata for %s\\n\",\n current_bcdata->bc_name);\n#endif\n\n if (CCTK_Equals(current_bcdata->bc_name, bc_name)) {\n current = current_bcdata->var_list;\n current_bcdata->num++;\n#ifdef DEBUG\n printf(\"Boundary_SelectVarForBCI: var %s brings bc %s to %d vars\\n\",\n CCTK_VarName(var_index), bc_name, current_bcdata->num);\n#endif\n break; /* now that current is set we don't need to look at any\n more bcdata entries */\n }\n }\n\n /* If current_bcdata is NULL, we got to the end of the above loop, this is\n * a new bc_name that does not appear in the bcdata list.\n */\n if (!current_bcdata) /* bc_name was not found in bcdata_list */\n {\n#ifdef DEBUG\n printf(\"Boundary_SelectVarForBCI: adding new entry to bcdata list\\n\");\n#endif\n\n /* new bc_name. Create new entry for bcdata list. */\n new_bcdata = malloc(sizeof(struct BCDATA));\n if (!new_bcdata) {\n CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Unable to allocate memory for internal 'bcdata' list\");\n /*retval = -4;*/\n }\n /* new_bcdata->next is set below, when inserting into bcdata_list */\n new_bcdata->var_list = NULL;\n new_bcdata->bc_name = Util_Strdup(bc_name);\n /* new_bcdata->num is set further below, when adding first entry to\n var_list */\n\n /* Place new entry into bcdata list, maintaining case independent sort */\n for (current_bcdata = bcdata_list, previous_bcdata = NULL; current_bcdata;\n previous_bcdata = current_bcdata,\n current_bcdata = current_bcdata->next) {\n#ifdef DEBUG\n printf(\" looping through bcdata list, to insert new entry; at %s\\n\",\n current_bcdata->bc_name);\n#endif\n if (Util_StrCmpi(bc_name, current_bcdata->bc_name) < 0) {\n /* bc_name precedes current->bc_name; place new entry here */\n if (!previous_bcdata) /* goes at start of bcdata list */\n {\n#ifdef DEBUG\n printf(\" new entry goes at beginning of bcdata list\\n\");\n#endif\n bcdata_list = new_bcdata;\n new_bcdata->next = current_bcdata;\n } else {\n new_bcdata->next = current_bcdata;\n previous_bcdata->next = new_bcdata;\n }\n break;\n }\n }\n\n /* If current_bcdata still NULL, this is the last entry in the list */\n if (!current_bcdata) {\n if (!bcdata_list) /* list is empty */\n {\n bcdata_list = new_bcdata;\n } else {\n previous_bcdata->next = new_bcdata;\n }\n new_bcdata->next = NULL;\n }\n\n /* Set current_bcdata to new_bcdata, so the new bcdata entry will be\n filled in below */\n current_bcdata = new_bcdata;\n }\n\n#ifdef DEBUG\n printf(\" Finished sorting out which bcdata to use. Now add entry to var \"\n \"list.\\n\");\n printf(\" Preparing to loop through elements of var list. current is %p\"\n current);\n#endif\n\n if (!current) /* This is the first element in the var_list */\n {\n#ifdef DEBUG\n printf(\" New element of var list.\\n\");\n#endif\n current_bcdata->var_list = new_entry;\n new_entry->next = NULL;\n current_bcdata->num = 1;\n }\n\n /* Enter new_entry into correct location in linked list.\n * Note that this loop is skipped if new_entry was already inserted as\n * first element of a new var list above (since in that case current will\n * be NULL) */\n for (; /* starting value for current is selected using the bcdata\n list, above */\n current && entry_greater_than(new_entry, current) > 0;\n /* continue if not at end of list, and new_entry is greater than\n current entry */\n previous = current,\n current = current->next)\n /* store previous value for later use */\n {\n }\n\n /* The possibilities:\n * 1 nothing NULL: new_entry goes between previous and current\n * 2 previous NULL, but current non-null : new_entry goes at the start of\n * the list\n * 3 current NULL, previous non-NULL : new_entry goes at the end of list\n * 4 both NULL: selections list is empty, case already caught above\n */\n if (previous) /* case 1 or 3 */\n {\n if (current) /* case 1 : goes in middle of list */\n {\n previous->next = new_entry;\n new_entry->next = current;\n } else /* case 3 : goes at end of list */\n {\n previous->next = new_entry;\n new_entry->next = NULL;\n }\n } else /* case 2 or 4 */\n {\n if (current) /* case 2 : goes at start of list */\n {\n current_bcdata->var_list = new_entry;\n new_entry->next = current;\n } /* case 4 : starts list, this case has already been handled above */\n }\n\n /* Record that this variable has been selected for a bc on these\n faces, for duplicate physical bc checking */\n if (!selected_faces) {\n num_cctk_vars = CCTK_NumVars();\n selected_faces = calloc(num_cctk_vars, sizeof(CCTK_INT));\n if (!selected_faces) {\n CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Unable to allocate memory for internal 'selected_faces' \"\n \"array\");\n }\n }\n selected_faces[var_index] |= faces;\n }\n\n#ifdef DEBUG\n print_selections_database();\n printf(\"\\n\");\n#endif\n return retval;\n}\n\n/*@@\n @routine Bdry_Boundary_SelectGroupForBC\n @date Thu Dec 26 21:45:34 CET 2002\n @author David Rideout\n @desc\n Used to select a Cactus variable group to have boundary\n conditions applied, using the group name.\n Table handle and faces must be the same for each member of the\n group.\n @enddesc\n @calls\n @history\n @endhistory\n @var _GH\n @vdesc cctkGH *\n @vtype CCTK_POINTER_TO_CONST\n @vio in\n @endvar\n @var faces\n @vdesc set of faces to which to apply bc\n @vtype CCTK_INT\n @vio in\n @endvar\n @var width\n @vdesc if >=0, width of boundary in all directions\n @vtype CCTK_INT\n @vio in\n @endvar\n @var table_handle\n @vdesc handle of table which holds arguments to be passed to bc\n @vtype CCTK_INT\n @vio in\n @endvar\n @var group_name\n @vdesc name of group to which to apply bc\n @vtype CCTK_STRING\n @vio in\n @endvar\n @var bc_name\n @vdesc name of bc to apply\n @vtype CCTK_STRING\n @vio in\n @endvar\n @returntype CCTK_INT\n @returndesc\n 0 success\n -6 invalid group name\n or the returncode of @seeroutine Bdry_Boundary_SelectGroupForBCI\n @endreturndesc\n@@*/\nCCTK_INT Bdry_Boundary_SelectGroupForBC(CCTK_POINTER_TO_CONST _GH,\n CCTK_INT faces, CCTK_INT width,\n CCTK_INT table_handle,\n CCTK_STRING group_name,\n CCTK_STRING bc_name) {\n int retval, gi;\n const cGH *GH = _GH;\n\n#ifdef DEBUG\n printf(\"Boundary_SelectGroupForBC: called for group %s\\n\", group_name);\n#endif\n\n /* get group index */\n gi = CCTK_GroupIndex(group_name);\n if (gi < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group name %s\\n\", group_name);\n retval = -6;\n } else {\n /* call Bdry_Boundary_SelectGroupForBCI() */\n retval = Bdry_Boundary_SelectGroupForBCI(GH, faces, width, table_handle, gi,\n bc_name);\n }\n\n return retval;\n}\n\n/*@@\n @routine Bdry_Boundary_SelectGroupForBCI\n @date Thu Dec 26 21:45:34 CET 2002\n @author David Rideout\n @desc\n Used to select a Cactus variable group to have boundary\n conditions applied, using the group index.\n @enddesc\n @calls\n @history\n @endhistory\n @var _GH\n @vdesc cctkGH *\n @vtype CCTK_POINTER_TO_CONST\n @vio in\n @endvar\n @var faces\n @vdesc set of faces to which to apply bc\n @vtype CCTK_INT\n @vio in\n @endvar\n @var width\n @vdesc if >=0, width of boundary in all directions\n @vtype CCTK_INT\n @vio in\n @endvar\n @var table_handle\n @vdesc handle of table which holds arguments to be passed to bc\n @vtype CCTK_INT\n @vio in\n @endvar\n @var group_index\n @vdesc index of group to which to apply bc\n @vtype CCTK_INT\n @vio in\n @endvar\n @var bc_name\n @vdesc name of bc to apply\n @vtype CCTK_STRING\n @vio in\n @endvar\n @returntype CCTK_INT\n @returndesc\n 0 success\n -7 invalid group index\n -8 group has zero vars\n or the returncode of @seeroutine Bdry_Boundary_SelectVarForBCI\n @endreturndesc\n@@*/\nCCTK_INT Bdry_Boundary_SelectGroupForBCI(CCTK_POINTER_TO_CONST _GH,\n CCTK_INT faces, CCTK_INT width,\n CCTK_INT table_handle,\n CCTK_INT group_index,\n CCTK_STRING bc_name) {\n int num_vars, vi, max_vi, retval;\n const cGH *GH = _GH;\n\n retval = -8;\n\n /* Get var indices from group name */\n num_vars = CCTK_NumVarsInGroupI(group_index);\n if (num_vars < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING, \"Invalid group index\");\n retval = -7;\n return retval;\n }\n\n#ifdef DEBUG\n printf(\"Boundary_SelectGroupForBCI: group %s has %d vars\\n\",\n CCTK_GroupName(group_index), num_vars);\n#endif\n\n /* loop over variables in group */\n vi = CCTK_FirstVarIndexI(group_index);\n max_vi = vi + num_vars;\n for (; vi < max_vi; ++vi) {\n retval = Bdry_Boundary_SelectVarForBCI(GH, faces, width, table_handle, vi,\n bc_name);\n }\n\n return retval;\n}\n\n/*@@\n @routine Bdry_Boundary_SelectedGVs\n @date Sun Nov 3 19:51:37 CET 2002\n @author David Rideout\n @desc\n Returns list of variable indices and table handles of\n variables selected for boundary conditions.\n @enddesc\n @calls\n @history\n @endhistory\n @var _GH\n @vdesc cctkGH *\n @vtype CCTK_POINTER_TO_CONST\n @vio in\n @endvar\n @var array_size\n @vdesc size of arrays to which var_indices and table_handles point\n @vtype CCTK_INT\n @vio in\n @endvar\n @var var_indices\n @vdesc array into which selected variable indices will be placed\n @vtype CCTK_INT\n @vio out\n @endvar\n @var faces\n @vdesc array into which a set of selected faces for variables selected\n for bc will be placed\n @vtype CCTK_INT\n @vio out\n @endvar\n @var widths\n @vdesc array into which boundary widths of selected variables will be\n placed\n @vtype CCTK_INT\n @vio in\n @endvar\n @var table_handles\n @vdesc array into which table_handles for variables selected for bc\n will be placed\n @vtype CCTK_INT\n @vio out\n @endvar\n @var bc_name\n @vdesc name of bc for which to get the selected vars,\n NULL returns all selected vars for all bcs\n @vtype CCTK_STRING\n @vio in\n @endvar\n @returntype CCTK_INT\n @returndesc\n -1 no boundary condition registered under bc_name\n -5 new value passed for GH\n number of variables selected for bc_name\n @endreturndesc\n@@*/\nCCTK_INT Bdry_Boundary_SelectedGVs(CCTK_POINTER_TO_CONST _GH,\n CCTK_INT array_size, CCTK_INT *var_indices,\n CCTK_INT *faces, CCTK_INT *widths,\n CCTK_INT *table_handles,\n CCTK_STRING bc_name) {\n DECLARE_CCTK_PARAMETERS;\n\n int retval, i, j;\n struct BCVAR *current;\n struct BCDATA *current_bcdata;\n const cGH *GH = _GH;\n\n current = NULL;\n retval = 0;\n\n /* Check to see if this is a new GH */\n if (!theGH) /* This is the first valid GH passed to a Boundary routine */\n {\n theGH = GH;\n } else if (GH != theGH) {\n CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"New GH passed to Boundary_SelectedGVs. \"\n \"Thorn CactusBase/Boundary does not yet handle multiple GHs \"\n \"properly.\");\n retval = -5;\n }\n\n#ifdef DEBUG\n printf(\"Boundary_SelectedGVs: called with bc_name=\\\"%s\\\" array_size=%d\\n\",\n bc_name, array_size);\n fflush(stdout);\n#endif\n\n const int have_driver_query =\n CCTK_IsFunctionAliased(\"Driver_FilterOutVarForBCI\");\n\n i = 0; /* i indexes the location in the returned arrays */\n\n /* Step through bcdata list */\n for (current_bcdata = bcdata_list; current_bcdata;\n current_bcdata = current_bcdata->next) {\n#ifdef DEBUG\n printf(\" looping through bcdata list, at bcdata entry for %s bc\\n\",\n current_bcdata->bc_name);\n#endif\n\n if (!bc_name || CCTK_Equals(current_bcdata->bc_name, bc_name)) {\n\n /* Loop through var list, j counts the bcs to check internal consistency */\n for (current = current_bcdata->var_list, j = 0; current;\n current = current->next, ++j) {\n\n#ifdef DEBUG\n printf(\" looping through selected vars, at current->var_index = \"\n \"%d\\n\",\n current->var);\n printf(\" current->next is %p\\n\", current->next);\n#endif\n\n /* if using PreSync only apply BC on grid variables not vetoed by\n * driver bc so that user codes do not have to distinguish between\n * PreSync and non PreSync runs */\n if (!CCTK_EQUALS(presync_mode, \"off\") && have_driver_query) {\n /* this is not perfect since the details of the b/c could be\n * different between the two select calls, but given that this is a\n * backwards compatibiltiy kludge anyway, this should do. */\n if (Driver_FilterOutVarForBCI(GH, current->var)) {\n continue;\n }\n }\n\n if (i < array_size) {\n if (faces) {\n faces[i] = current->faces;\n }\n if (widths) {\n widths[i] = current->width;\n }\n if (table_handles) {\n table_handles[i] = current->table;\n }\n if (var_indices) {\n var_indices[i] = current->var;\n }\n i += 1;\n }\n\n retval += 1;\n }\n if (j > current_bcdata->num)\n CCTK_WARN(0, \"internal error\");\n if (i != array_size && j != current_bcdata->num)\n CCTK_WARN(0, \"internal error\");\n }\n }\n\n /* Warn if there is no bc registered under this name */\n if (bc_name &&\n !Util_TableQueryValueInfo(physbc_table_handle, NULL, NULL, bc_name)) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"There is no boundary condition registered under the name %s\",\n bc_name);\n retval = -1;\n }\n\n return retval;\n}\n\n/********************************************************************\n ********************* Scheduled Routines **********************\n ********************************************************************/\n\n/*@@\n @routine Boundary_ApplyPhysicalBCs\n @date Sun Nov 3 19:51:37 CET 2002\n @author David Rideout\n @desc\n This will apply all requested physical boundary conditions.\n @enddesc\n @calls\n @history\n @endhistory\n @var CCTK_ARGUMENTS\n @vdesc Cactus argument list\n @vtype CCTK_*\n @vio in\n @endvar\n @returntype void\n @returndesc\n @endreturndesc\n@@*/\n\nvoid Boundary_ApplyPhysicalBCs(CCTK_ARGUMENTS) {\n phys_bc_fn_ptr bc_fn;\n int num_vars, max_num_vars, err;\n CCTK_INT *vars, *faces, *widths, *tables, *timelevels, *regions;\n struct BCDATA *current_bcdata;\n\n num_vars = -1; // initialize to unusable value\n max_num_vars = 0;\n vars = NULL; /* avoids a compiler warning */\n faces = NULL; /* avoids a compiler warning */\n widths = NULL; /* avoids a compiler warning */\n tables = NULL; /* avoids a compiler warning */\n timelevels = NULL; /* avoids a compiler warning */\n regions = NULL; /* avoids a compiler warning */\n\n /* Warning: This function does not consider which GH it is called on */\n\n /* Step through each requested physical boundary condition */\n for (current_bcdata = bcdata_list; current_bcdata;\n current_bcdata = current_bcdata->next) {\n#ifdef DEBUG\n printf(\"Boundary_ApplyPhysicalBCs: looping through bcdata list, at bcdata \"\n \"entry for %s bc\\n\",\n current_bcdata->bc_name);\n printf(\" num_vars is %d\\n\", num_vars);\n#endif\n\n /* Allocate memory to hold selected vars */\n num_vars = Bdry_Boundary_SelectedGVs(cctkGH, 0, NULL, NULL, NULL, NULL,\n current_bcdata->bc_name);\n#ifdef DEBUG\n printf(\" num_vars is %d\\n\", num_vars);\n#endif\n if (num_vars > max_num_vars) {\n max_num_vars = num_vars; /* store new maximum */\n vars = realloc(vars, num_vars * sizeof(CCTK_INT));\n faces = realloc(faces, num_vars * sizeof(CCTK_INT));\n widths = realloc(widths, num_vars * sizeof(CCTK_INT));\n tables = realloc(tables, num_vars * sizeof(CCTK_INT));\n timelevels = realloc(timelevels, num_vars * sizeof(CCTK_INT));\n regions = realloc(regions, num_vars * sizeof(CCTK_INT));\n }\n\n /* get selected vars for this bc_name */\n err = Bdry_Boundary_SelectedGVs(cctkGH, num_vars, vars, faces, widths,\n tables, current_bcdata->bc_name);\n if (err < 0) /* This is a redundant test for now,\n Bdry_Boundary_SelectedGVs never returns <0 */\n {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Error in Boundary_SelectedGVs for %s boundary condition\",\n current_bcdata->bc_name);\n } else if (err != num_vars) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Boundary_SelectedGVs returned %d selected variables for \"\n \"\\\"%s\\\" boundary condition, but %d expected\\n\",\n err, current_bcdata->bc_name, num_vars);\n }\n\n/* Get the fn ptr for the bc */\n#ifdef DEBUG\n printf(\"Boundary_ApplyPhysicalBCs: current_bcdata->bc_name=\\\"%s\\\"\\n\",\n current_bcdata->bc_name);\n#endif\n err = Util_TableGetFnPointer(physbc_table_handle, (CCTK_FPOINTER *)&bc_fn,\n current_bcdata->bc_name);\n if (err < 0) {\n CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Boundary_ApplyPhysicalBCs: Util_TableGetFnPointer \"\n \"returned %d for %s\",\n err, current_bcdata->bc_name);\n }\n\n /* check that all variables have storage at least on the current level\n * individual boundary conditions (eg static) may check for more */\n err = 0;\n for (int i = 0; i < num_vars; i++) {\n if (CCTK_VarDataPtrI(cctkGH, 0, vars[i]) == NULL) {\n char *fullname = CCTK_FullName(vars[i]);\n CCTK_VWarn(CCTK_WARN_ALERT, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Boundary_ApplyPhysicalBCs: variable \\\"%s\\\" has no storage \"\n \"when attempting to apply boundary condition \\\"%s\\\".\",\n fullname, current_bcdata->bc_name);\n err += 1;\n free(fullname);\n }\n }\n if (err) {\n CCTK_VError(__LINE__, __FILE__, CCTK_THORNSTRING,\n \"Boundary_ApplyPhysicalBCs: boundary conditions were \"\n \"requested for %d variables that do not have storage\",\n err);\n }\n\n/* Apply bc to vi */\n#ifdef DEBUG\n printf(\n \"Boundary_ApplyPhysicalBCs: Attempting to call boundary condition\\n\"\n \" Using function pointer %p with arguments\\n\"\n \" cctkGH %p, num_vars %d, vars, tables\\n\",\n (void *)bc_fn, (const void *)cctkGH, num_vars);\n#endif\n err = (*bc_fn)(cctkGH, num_vars, vars, faces, widths, tables);\n if (err < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Function associated with boundary condition %s returned %d\",\n current_bcdata->bc_name, err);\n }\n\n if(CCTK_IsFunctionAliased(\"Driver_NotifyDataModified\")) {\n for (int i = 0; i < num_vars; i++) {\n timelevels[i] = 0;\n regions[i] = CCTK_VALID_BOUNDARY;\n }\n Driver_NotifyDataModified(cctkGH, vars, timelevels, num_vars, regions);\n }\n }\n\n /* Free data */\n free(vars);\n free(faces);\n free(widths);\n free(tables);\n free(timelevels);\n free(regions);\n}\n\n/*@@\n @routine Boundary_ClearSelection\n @date Sun Nov 3 19:51:37 CET 2002\n @author David Rideout\n @desc\n Clears all boundary condition selections.\n @enddesc\n @calls\n @history\n @endhistory\n@@*/\n\nvoid Boundary_ClearSelection(CCTK_ARGUMENTS) {\n struct BCVAR *current, *next;\n struct BCDATA *current_bcdata;\n\n/* Warning: This function does not consider which GH it is called on, which\n will be a bug in Cactus 4.1. */\n\n/* Step through bcdata list */\n#ifdef DEBUG\n printf(\"Boundary_ClearSelection: looping through bcdata list for freeing\\n\");\n#endif\n for (current_bcdata = bcdata_list; current_bcdata;\n current_bcdata = current_bcdata->next) {\n#ifdef DEBUG\n printf(\"Boundary_ClearSelection: freeing var list rooted at %p\\n\",\n current_bcdata);\n#endif\n\n /* Free selections list */\n current = next = current_bcdata->var_list;\n for (; current; current = next) {\n next = current->next;\n free(current);\n }\n\n current_bcdata->var_list = NULL;\n current_bcdata->num = 0;\n }\n\n /* Clear list of selected faces */\n memset(selected_faces, 0, num_cctk_vars * sizeof(CCTK_INT));\n}\n\n/*@@\n @routine Boundary_MakeSureThatTheSelectionIsEmpty\n @date Mon Jul 7 21:51:37 CET 2003\n @author Erik Schnetter\n @desc\n Abort if the selections is not empty.\n This routine is currently unused, but is very\n helpful for debugging.\n @enddesc\n @calls\n @history\n @endhistory\n@@*/\n\nvoid Boundary_MakeSureThatTheSelectionIsEmpty(void);\nvoid Boundary_MakeSureThatTheSelectionIsEmpty(void) {\n struct BCDATA *current_bcdata;\n struct BCVAR *current;\n int is_empty;\n\n is_empty = 1;\n for (current_bcdata = bcdata_list; current_bcdata;\n current_bcdata = current_bcdata->next) {\n for (current = current_bcdata->var_list; current; current = current->next) {\n char *fullname = CCTK_FullName(current->var);\n if (is_empty) {\n is_empty = 0;\n printf(\"The following boundary conditions are currently selected for \"\n \"the following variables:\\n\");\n }\n printf(\"Boundary condition %s for variable %s\\n\", current_bcdata->bc_name,\n fullname);\n free(fullname);\n }\n }\n\n if (!is_empty) {\n CCTK_WARN(0, \"Someone thinks that the boundary selection list should be \"\n \"empty at this point. Alas, it is not; I better abort.\");\n }\n}\n\n/********************************************************************\n ********************* Local Routines *************************\n ********************************************************************/\n\n/*@@\n @routine entry_greater_than\n @date Sun Nov 3 19:51:37 CET 2002\n @author David Rideout\n @desc\n Sorts entries in selections list.\n Returns non-zero value if new > current.\n @enddesc\n @calls\n @history\n @endhistory\n @var new\n @vdesc new entry to be inserted into selections list\n @vtype struct BCVAR *\n @vio in\n @endvar\n @var current\n @vdesc entry in selections list to which to compare new\n @vtype struct BCVAR *\n @vio in\n @endvar\n @returntype CCTK_INT\n @returndesc\n -1 new equals current\n 0 new 'less than' current\n 1 new->table_handle > current->table_handle\n 2 new and current have same table_handle, but new has greater\n var_index\n @endreturndesc\n@@*/\nstatic int entry_greater_than(struct BCVAR *new, struct BCVAR *current) {\n int retval;\n\n /* can assume both arguments are valid (non-null) */\n if (new->table > current->table) {\n retval = 1;\n } else if (new->table < current->table) {\n retval = 0;\n } else if (new->var > current->var) {\n retval = 2;\n } else if (new->var < current->var) {\n retval = 0;\n } else {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"%s has already been selected for this boundary condition!\",\n CCTK_VarName(new->var));\n retval = -1;\n }\n\n return retval;\n}\n\n/*@@\n @routine print_selections_database\n @date 13 March 2003\n @author David Rideout\n @desc\n Prints selected variables database, for debugging only\n @enddesc\n @calls\n @history\n @endhistory\n@@*/\n\n#ifdef DEBUG\n\nstatic void print_selections_database(void) {\n struct BCDATA *current_bcdata;\n struct BCVAR *current;\n\n printf(\"Current list of selected vars:\\n\");\n for (current_bcdata = bcdata_list; current_bcdata;\n current_bcdata = current_bcdata->next) {\n printf(\"%d entries for %s:\\n\", current_bcdata->num,\n current_bcdata->bc_name);\n printf(\" vi gi var name table handle\\n\");\n for (current = current_bcdata->var_list; current; current = current->next) {\n printf(\"%3d %2d %12s %2d\\n\", current->var,\n CCTK_GroupIndexFromVarI(current->var), CCTK_VarName(current->var),\n current->table);\n }\n }\n}\n\n#endif\n\n/*@@\n @routine print_selected_faces\n @date 13 May 2003\n @author David Rideout\n @desc\n Prints selected faces database, for debugging only\n @enddesc\n @calls\n @history\n @endhistory\n@@*/\n\n#ifdef DEBUG\n\nstatic void print_selected_faces(void) {\n int i;\n\n if (selected_faces) {\n for (i = 0; i < num_cctk_vars; ++i) {\n printf(\"selected_faces[%d] = %d\\n\", i, selected_faces[i]);\n }\n } else {\n printf(\"no selected faces database yet\\n\");\n }\n}\n\n#endif\n", "ScalarBoundary.c": "/*@@\n @file ScalarBoundary.c\n @date Mon Mar 15 15:09:00 1999\n @author Gabrielle Allen, Gerd Lanfermann\n @desc\n Routines for applying scalar boundary conditions\n @enddesc\n @history\n @hdate Tue 10 Apr 2001\n @hauthor Thomas Radke\n @hdesc BC routines generalized for applying to arbitrary CCTK data types\n @endhistory\n @version $Id$\n@@*/\n\n#include \n#include \n\n#include \"cctk.h\"\n#include \"util_Table.h\"\n#include \"util_ErrorCodes.h\"\n#include \"cctk_Parameters.h\"\n#include \"cctk_FortranString.h\"\n\n#include \"Boundary.h\"\n\n/* the rcs ID and its dummy function to use it */\nstatic const char *rcsid = \"$Header$\";\nCCTK_FILEVERSION(CactusBase_Boundary_ScalarBoundary_c);\n\nstatic int ApplyBndScalar(const cGH *GH,\n CCTK_INT width_dir, const CCTK_INT *in_widths,\n int dir, CCTK_INT faces,\n CCTK_REAL scalar, int first_var, int num_vars);\nstatic int OldApplyBndScalar(const cGH *GH, int stencil_dir,\n const int *stencil_alldirs, int dir,\n CCTK_REAL scalar, int first_var, int num_vars);\n\n/********************************************************************\n ******************** External Routines ************************\n ********************************************************************/\n\n/*@@\n @routine BndScalar\n @date 13 Feb 2003\n @author David Rideout\n @desc\n Top level function which is registered as handling\n the Scalar boundary condition\n @enddesc\n @calls ApplyBndScalar\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var num_vars\n @vdesc number of variables passed in through var_indices[]\n @vtype int\n @vio in\n @endvar\n @var var_indices\n @vdesc array of variable indicies to which to apply this boundary\n condition\n @vtype int *\n @vio in\n @endvar\n @var faces\n @vdesc array of set of faces to which to apply the bc\n @vtype int\n @vio in\n @endvar\n @var widths\n @vdesc array of boundary widths for each variable\n @vtype int\n @vio in\n @endvar\n @var table_handles\n @vdesc array of table handles which hold extra arguments\n @vtype int\n @vio in\n @endvar\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndScalar\n -21 error reading boundary width array from table\n -22 wrong size boundary width array in table\n @endreturndesc\n@@*/\nCCTK_INT BndScalar(const cGH *GH, CCTK_INT num_vars, CCTK_INT *vars,\n CCTK_INT *faces, CCTK_INT *widths, CCTK_INT *tables) {\n int i, j, k, gi, gdim, max_gdim, err, retval;\n\n /* variables to pass to ApplyBndScalar */\n CCTK_INT *width_alldirs; /* width of stencil in all directions */\n int dir; /* direction in which to apply bc */\n CCTK_REAL scalar;\n\n retval = 0;\n width_alldirs = NULL;\n max_gdim = 0;\n\n /* loop through variables, j at a time */\n for (i = 0; i < num_vars; i += j) {\n /* find other adjacent vars which are selected for identical bcs */\n j = 1;\n /* Since GFs are allowed to have different staggering, the best we\n can do is find variables of the same group which are selected\n for identical bcs. If all GFs had the same staggering then we\n could groups many GFs together. */\n gi = CCTK_GroupIndexFromVarI(vars[i]);\n while (i + j < num_vars && vars[i + j] == vars[i] + j &&\n CCTK_GroupIndexFromVarI(vars[i + j]) == gi &&\n tables[i + j] == tables[i] && faces[i + j] == faces[i] &&\n widths[i + j] == widths[i]) {\n ++j;\n }\n\n dir = 0; /* apply bc to all faces */\n\n /* Set up default arguments for ApplyBndScalar */\n scalar = 0.;\n\n /* Look on table for possible non-default arguments\n * (If any of these table look-ups fail, the value will be unchanged\n * from its default value)\n */\n /* Scalar value */\n err = Util_TableGetReal(tables[i], &scalar, \"SCALAR\");\n if (err == UTIL_ERROR_BAD_HANDLE) {\n CCTK_VWarn(5, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid table handle passed for Scalar boundary \"\n \"conditions for %s. Using all default values.\",\n CCTK_VarName(vars[i]));\n }\n\n /* Determine boundary width on all faces */\n /* allocate memory for buffer */\n gdim = CCTK_GroupDimI(gi);\n if (gdim > max_gdim) {\n width_alldirs =\n (CCTK_INT *)realloc(width_alldirs, 2 * gdim * sizeof(CCTK_INT));\n max_gdim = gdim;\n }\n\n /* fill it with values, either from table or the boundary_width\n parameter */\n if (widths[i] < 0) {\n err = Util_TableGetIntArray(tables[i], 2 * gdim, width_alldirs,\n \"BOUNDARY_WIDTH\");\n if (err < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Error %d when reading boundary width array from table \"\n \"for %s\",\n err, CCTK_VarName(vars[i]));\n return -21;\n } else if (err != 2 * gdim) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Boundary width array for %s has %d elements, but %d \"\n \"expected\",\n CCTK_VarName(vars[i]), err, 2 * gdim);\n return -22;\n }\n } else {\n for (k = 0; k < 2 * gdim; ++k) {\n width_alldirs[k] = widths[i];\n }\n }\n\n /* Apply the boundary condition */\n if ((retval = ApplyBndScalar(GH, 0, width_alldirs, dir, faces[i], scalar,\n vars[i], j)) < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"ApplyBndScalar() returned %d\", retval);\n }\n }\n free(width_alldirs);\n\n return retval;\n}\n\n/* prototypes for external C routines are declared in header Boundary.h\n here only follow the fortran wrapper prototypes */\nvoid CCTK_FCALL\n CCTK_FNAME(BndScalarDirVI)(int *ierr, const cGH **GH,\n const int *stencil_size, const int *dir,\n const CCTK_REAL *scalar, const int *vi);\nvoid CCTK_FCALL CCTK_FNAME(BndScalarVI)(int *ierr, const cGH **GH,\n const int *stencil,\n const CCTK_REAL *scalar, const int *vi);\nvoid CCTK_FCALL\n CCTK_FNAME(BndScalarDirGI)(int *ierr, const cGH **GH,\n const int *stencil_size, const int *dir,\n const CCTK_REAL *scalar, const int *gi);\nvoid CCTK_FCALL CCTK_FNAME(BndScalarGI)(int *ierr, const cGH **GH,\n const int *stencil,\n const CCTK_REAL *scalar, const int *gi);\nvoid CCTK_FCALL\n CCTK_FNAME(BndScalarDirGN)(int *ierr, const cGH **GH,\n const int *stencil_size, const int *dir,\n const CCTK_REAL *scalar, ONE_FORTSTRING_ARG);\nvoid CCTK_FCALL\n CCTK_FNAME(BndScalarGN)(int *ierr, const cGH **GH, const int *stencil,\n const CCTK_REAL *scalar, ONE_FORTSTRING_ARG);\nvoid CCTK_FCALL\n CCTK_FNAME(BndScalarDirVN)(int *ierr, const cGH **GH,\n const int *stencil_size, const int *dir,\n const CCTK_REAL *scalar, ONE_FORTSTRING_ARG);\nvoid CCTK_FCALL\n CCTK_FNAME(BndScalarVN)(int *ierr, const cGH **GH, const int *stencil,\n const CCTK_REAL *scalar, ONE_FORTSTRING_ARG);\n\n/********************************************************************\n ******************** Internal Routines ************************\n ********************************************************************/\n/*@@\n @routine BndScalarDirVI\n @date Tue Jan 16 2001\n @author Gabrielle Allen\n @desc\n Apply scalar boundary conditions by variable index\n in given direction\n @enddesc\n @calls ApplyBndScalar\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to apply BC\n @vtype int\n @vio in\n @endvar\n @var scalar\n @vdesc scalar to set the boundaries to\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var vi\n @vdesc index of variable to apply BC to\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndScalar
\n -1 if invalid variable index was given\n @endreturndesc\n@@*/\nint BndScalarDirVI(const cGH *GH, int stencil_size, int dir, CCTK_REAL scalar,\n int vi) {\n int retval;\n\n if (vi >= 0 && vi < CCTK_NumVars()) {\n retval = ApplyBndScalar(GH, stencil_size, NULL, dir, CCTK_ALL_FACES, scalar,\n vi, 1);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable index %d in BndScalarDirVI\", vi);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL\n CCTK_FNAME(BndScalarDirVI)(int *ierr, const cGH **GH,\n const int *stencil_size, const int *dir,\n const CCTK_REAL *scalar, const int *vi) {\n *ierr = BndScalarDirVI(*GH, *stencil_size, *dir, *scalar, *vi);\n}\n\n/*@@\n @routine BndScalarVI\n @date Thu Mar 2 11:07:11 2000\n @author Gerd Lanfermann\n @desc\n Apply scalar boundary conditions by variable index\n @enddesc\n @calls ApplyBndScalar\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int\n @vio in\n @endvar\n @var scalar\n @vdesc scalar to set the boundaries to\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var vi\n @vdesc index of variable to apply BC to\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndScalar
\n -1 if invalid variable index was given\n @endreturndesc\n@@*/\nint BndScalarVI(const cGH *GH, const int *stencil, CCTK_REAL scalar, int vi) {\n int retval;\n\n if (vi >= 0 && vi < CCTK_NumVars()) {\n retval = OldApplyBndScalar(GH, -1, stencil, 0, scalar, vi, 1);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable index %d in ApplyBndScalar\", vi);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL\n CCTK_FNAME(BndScalarVI)(int *ierr, const cGH **GH, const int *stencil,\n const CCTK_REAL *scalar, const int *vi) {\n *ierr = BndScalarVI(*GH, stencil, *scalar, *vi);\n}\n\n/* ===================================================================== */\n\n/*@@\n @routine BndScalarDirGI\n @date Tue Jan 16 2001\n @author Gabrielle Allen\n @desc\n Apply scalar boundary conditions by group index\n in given direction\n @enddesc\n @calls ApplyBndScalar\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to apply BC\n @vtype int\n @vio in\n @endvar\n @var scalar\n @vdesc scalar to set the boundaries to\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var gi\n @vdesc index of group to apply BC to\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndScalar
\n -1 if invalid group index was given\n @endreturndesc\n@@*/\nint BndScalarDirGI(const cGH *GH, int stencil_size, int dir, CCTK_REAL scalar,\n int gi) {\n int first_vi, retval;\n\n first_vi = CCTK_FirstVarIndexI(gi);\n if (first_vi >= 0) {\n retval = ApplyBndScalar(GH, stencil_size, NULL, dir, CCTK_ALL_FACES, scalar,\n first_vi, CCTK_NumVarsInGroupI(gi));\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group index %d in BndScalarDirGI\", gi);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL\n CCTK_FNAME(BndScalarDirGI)(int *ierr, const cGH **GH,\n const int *stencil_size, const int *dir,\n const CCTK_REAL *scalar, const int *gi) {\n *ierr = BndScalarDirGI(*GH, *stencil_size, *dir, *scalar, *gi);\n}\n\n/*@@\n @routine BndScalarGI\n @date Thu Mar 2 11:07:11 2000\n @author Gerd Lanfermann\n @desc\n Apply scalar boundary conditions by group index\n @enddesc\n @calls ApplyBndScalar\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int\n @vio in\n @endvar\n @var scalar\n @vdesc scalar to set the boundaries to\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var gi\n @vdesc index of group to apply BC to\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndScalar
\n -1 if invalid group index was given\n @endreturndesc\n@@*/\nint BndScalarGI(const cGH *GH, const int *stencil, CCTK_REAL scalar, int gi) {\n int first_vi, retval;\n\n first_vi = CCTK_FirstVarIndexI(gi);\n if (first_vi >= 0) {\n retval = OldApplyBndScalar(GH, -1, stencil, 0, scalar, first_vi,\n CCTK_NumVarsInGroupI(gi));\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group index %d in BndScalarGI\", gi);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL\n CCTK_FNAME(BndScalarGI)(int *ierr, const cGH **GH, const int *stencil,\n const CCTK_REAL *scalar, const int *gi) {\n *ierr = BndScalarGI(*GH, stencil, *scalar, *gi);\n}\n\n/* ===================================================================== */\n\n/*@@\n @routine BndScalarDirGN\n @date Tue Jan 16 2001\n @author Gabrielle Allen\n @desc\n Apply scalar boundary conditions by group name in given direction\n @enddesc\n @calls BndScalarDirGI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to apply BC\n @vtype int\n @vio in\n @endvar\n @var scalar\n @vdesc scalar to set the boundaries to\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var gname\n @vdesc name of group to apply BC to\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndScalarDirGI
\n -1 if invalid group name was given\n @endreturndesc\n@@*/\nint BndScalarDirGN(const cGH *GH, int stencil_size, int dir, CCTK_REAL scalar,\n const char *gname) {\n int gi, retval;\n\n gi = CCTK_GroupIndex(gname);\n if (gi >= 0) {\n retval = BndScalarDirGI(GH, stencil_size, dir, scalar, gi);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group name '%s' in BndScalarDirGN\", gname);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL\n CCTK_FNAME(BndScalarDirGN)(int *ierr, const cGH **GH,\n const int *stencil_size, const int *dir,\n const CCTK_REAL *scalar, ONE_FORTSTRING_ARG) {\n ONE_FORTSTRING_CREATE(gname)\n *ierr = BndScalarDirGN(*GH, *stencil_size, *dir, *scalar, gname);\n free(gname);\n}\n\n/*@@\n @routine BndScalarGN\n @date Thu Mar 2 11:07:11 2000\n @author Gerd Lanfermann\n @desc\n Apply scalar boundary conditions by group name\n @enddesc\n @calls BndScalarGI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int\n @vio in\n @endvar\n @var scalar\n @vdesc scalar to set the boundaries to\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var gname\n @vdesc name of group to apply BC to\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndScalarGI
\n -1 if invalid group name was given\n @endreturndesc\n@@*/\nint BndScalarGN(const cGH *GH, const int *stencil, CCTK_REAL scalar,\n const char *gname) {\n int gi, retval;\n\n gi = CCTK_GroupIndex(gname);\n if (gi >= 0) {\n retval = BndScalarGI(GH, stencil, scalar, gi);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group name '%s' in BndScalarGN\", gname);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL\n CCTK_FNAME(BndScalarGN)(int *ierr, const cGH **GH, const int *stencil,\n const CCTK_REAL *scalar, ONE_FORTSTRING_ARG) {\n ONE_FORTSTRING_CREATE(gname)\n *ierr = BndScalarGN(*GH, stencil, *scalar, gname);\n free(gname);\n}\n\n/*@@\n @routine BndScalarDirVN\n @date Tue Jan 16 2001\n @author Gabrielle Allen\n @desc\n Apply scalar boundaries by variable name in given direction\n @enddesc\n @calls BndScalarDirVI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to apply BC\n @vtype int\n @vio in\n @endvar\n @var scalar\n @vdesc scalar to set the boundaries to\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var vname\n @vdesc name of variable to apply BC to\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndScalarDirVI
\n -1 if invalid variable name was given\n @endreturndesc\n@@*/\nint BndScalarDirVN(const cGH *GH, int stencil_size, int dir, CCTK_REAL scalar,\n const char *vname) {\n int vi, retval;\n\n vi = CCTK_VarIndex(vname);\n if (vi >= 0) {\n retval = BndScalarDirVI(GH, stencil_size, dir, scalar, vi);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable name '%s' in BndScalarDirVN\", vname);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL\n CCTK_FNAME(BndScalarDirVN)(int *ierr, const cGH **GH,\n const int *stencil_size, const int *dir,\n const CCTK_REAL *scalar, ONE_FORTSTRING_ARG) {\n ONE_FORTSTRING_CREATE(vname)\n *ierr = BndScalarDirVN(*GH, *stencil_size, *dir, *scalar, vname);\n free(vname);\n}\n\n/*@@\n @routine BndScalarVN\n @date Thu Mar 2 11:07:11 2000\n @author Gerd Lanfermann\n @desc\n Apply scalar boundaries by variable name\n @enddesc\n @calls BndScalarVI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int\n @vio in\n @endvar\n @var scalar\n @vdesc scalar to set the boundaries to\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var vname\n @vdesc name of variable to apply BC to\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndScalarVI
\n -1 if invalid variable name was given\n @endreturndesc\n@@*/\nint BndScalarVN(const cGH *GH, const int *stencil, CCTK_REAL scalar,\n const char *vname) {\n int vi, retval;\n\n vi = CCTK_VarIndex(vname);\n if (vi >= 0) {\n retval = BndScalarVI(GH, stencil, scalar, vi);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable name '%s' in BndScalarVN\", vname);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL\n CCTK_FNAME(BndScalarVN)(int *ierr, const cGH **GH, const int *stencil,\n const CCTK_REAL *scalar, ONE_FORTSTRING_ARG) {\n ONE_FORTSTRING_CREATE(vname)\n *ierr = BndScalarVN(*GH, stencil, *scalar, vname);\n free(vname);\n}\n\n/********************************************************************\n ********************* Local Routines *************************\n ********************************************************************/\n\n/* maximum dimension we can deal with */\n#define MAXDIM 3\n\n/* macro to compute the linear index of a 3D point */\n#define INDEX_3D(ash, i, j, k) ((i) + (ash)[0] * ((j) + (ash)[1] * (k)))\n\n/* an empty macro */\n#define NOTHING\n\n/*@@\n @routine SCALAR_BOUNDARY_TYPED\n @date Sat 20 Jan 2001\n @author Thomas Radke\n @desc\n Macro to apply scalar boundary conditions to a variable\n of given datatype\n Currently it is limited up to 3D variables only.\n @enddesc\n\n @var doBC\n @vdesc flag telling whether to apply boundary conditions or not\n @vtype int\n @vio in\n @endvar\n @var iend, jend, kend\n @vdesc upper ranges for the loopers\n @vtype int\n @vio in\n @endvar\n @var ii, jj, kk\n @vdesc indices of the current grid point\n @vtype int\n @vio in\n @endvar\n @var cctk_type\n @vdesc CCTK datatype of the variable\n @vtype \n @vio in\n @endvar\n@@*/\n#define SCALAR_BOUNDARY_TYPED(doBC, iend, jend, kend, ii, jj, kk, \\\n left_cctk_type, right_cctk_type) \\\n { \\\n if (doBC) { \\\n for (k = 0; k < kend; k++) { \\\n for (j = 0; j < jend; j++) { \\\n for (i = 0; i < iend; i++) { \\\n int _index; \\\n \\\n _index = INDEX_3D(ash, ii, jj, kk); \\\n ((left_cctk_type *)GH->data[var][timelvl])[_index] = \\\n (right_cctk_type)scalar; \\\n } \\\n } \\\n } \\\n } \\\n }\n\n/*@@\n @routine SCALAR_BOUNDARY\n @date Sat 20 Jan 2001\n @author Thomas Radke\n @desc\n Macro to apply scalar boundary conditions to a variable\n of a given datatype in all directions\n Currently it is limited up to 3D variables only.\n @enddesc\n\n @var cctk_type\n @vdesc CCTK datatype of the variable\n @vtype \n @vio in\n @endvar\n@@*/\n#define SCALAR_BOUNDARY(left_cctk_type, right_cctk_type) \\\n { \\\n /* now set the boundaries face by face */ \\\n if (gdim > 0) { \\\n /* lower x */ \\\n SCALAR_BOUNDARY_TYPED(doBC[0], widths[0], lsh[1], lsh[2], i, j, k, \\\n left_cctk_type, right_cctk_type); \\\n /* upper x */ \\\n SCALAR_BOUNDARY_TYPED(doBC[1], widths[1], lsh[1], lsh[2], \\\n lsh[0] - i - 1, j, k, left_cctk_type, \\\n right_cctk_type); \\\n } \\\n if (gdim > 1) { \\\n /* lower y */ \\\n SCALAR_BOUNDARY_TYPED(doBC[2], lsh[0], widths[2], lsh[2], i, j, k, \\\n left_cctk_type, right_cctk_type); \\\n /* upper y */ \\\n SCALAR_BOUNDARY_TYPED(doBC[3], lsh[0], widths[3], lsh[2], i, \\\n lsh[1] - j - 1, k, left_cctk_type, \\\n right_cctk_type); \\\n } \\\n if (gdim > 2) { \\\n /* lower z */ \\\n SCALAR_BOUNDARY_TYPED(doBC[4], lsh[0], lsh[1], widths[4], i, j, k, \\\n left_cctk_type, right_cctk_type); \\\n /* upper z */ \\\n SCALAR_BOUNDARY_TYPED(doBC[5], lsh[0], lsh[1], widths[5], i, j, \\\n lsh[2] - k - 1, left_cctk_type, right_cctk_type); \\\n } \\\n }\n\n/*@@\n @routine ApplyBndScalar\n @date Tue Jul 18 18:10:33 2000\n @author Gerd Lanfermann\n @desc\n Apply scalar boundary conditions to a group of grid functions\n given by their indices\n This routine is called by the various BndScalarXXX wrappers.\n\n Although it is currently limited to handle 3D variables only\n it can easily be extended for other dimensions\n by adapting the appropriate macros.\n @enddesc\n @calls CCTK_VarTypeI\n CCTK_GroupDimFromVarI\n SCALAR_BOUNDARY\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var width_dir\n @vdesc boundary width in direction dir\n @vtype int\n @vio in\n @endvar\n @var in_widths\n @vdesc boundary widths for all directions\n @vtype CCTK_INT [ dimension of variable(s) ]\n @vio in\n @endvar\n @var dir\n @vdesc direction to set boundaries (0 for setting all directions)\n @vtype int\n @vio in\n @endvar\n @var scalar\n @vdesc scalar value to set the boundaries to\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var first_var\n @vdesc index of first variable to apply boundary conditions to\n @vtype int\n @vio in\n @endvar\n @var num_vars\n @vdesc number of variables\n @vtype int\n @vio in\n @endvar\n\n @history\n @hdate Tue 10 Apr 2001\n @hauthor Thomas Radke\n @hdesc Merged separate routines for 1D, 2D, and 3D\n into a single generic routine\n @endhistory\n\n @returntype int\n @returndesc\n 0 for success\n -1 if abs(direction) is greater than variables' dimension\n -2 if variable dimension is not supported\n -3 if NULL pointer passed as boundary width array\n -4 if variable type is not supported\n @endreturndesc\n@@*/\nstatic int ApplyBndScalar(const cGH *GH,\n CCTK_INT width_dir, const CCTK_INT *in_widths,\n int dir, CCTK_INT faces,\n CCTK_REAL scalar, int first_var, int num_vars) {\n int ierr;\n int i, j, k;\n int gindex, gdim;\n int var, timelvl;\n int doBC[2 * MAXDIM], ash[MAXDIM], lsh[MAXDIM];\n CCTK_INT widths[2 * MAXDIM];\n CCTK_INT symtable;\n CCTK_INT symbnd[2 * MAXDIM];\n CCTK_INT is_physical[2 * MAXDIM];\n\n /* check the direction parameter */\n if (abs(dir) > MAXDIM) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"ApplyBndScalar: direction %d is greater than maximum \"\n \"dimension %d\",\n dir, MAXDIM);\n return (-1);\n }\n\n /* get the group index and dimension */\n gindex = CCTK_GroupIndexFromVarI(first_var);\n gdim = CCTK_GroupDimI(gindex);\n\n /* check the dimension */\n if (gdim > MAXDIM) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"ApplyBndScalar: variable dimension of %d not supported\", gdim);\n return (-2);\n }\n\n /* set up boundary width array */\n if (dir) {\n widths[2 * (abs(dir) - 1)] = width_dir;\n widths[2 * (abs(dir) - 1) + 1] = width_dir;\n } else if (in_widths) {\n memcpy(widths, in_widths, 2 * gdim * sizeof *widths);\n } else {\n CCTK_WARN(1, \"ApplyBndScalar: NULL pointer passed \"\n \"for boundary width array\");\n return (-3);\n }\n\n /* sanity check on width of boundary, */\n BndSanityCheckWidths(GH, first_var, gdim, widths, \"Scalar\");\n\n /* initialize arrays for variables with less dimensions than MAXDIM\n so that we can use the INDEX_3D macro later on */\n for (i = gdim; i < MAXDIM; i++) {\n ash[i] = 1;\n lsh[i] = 1;\n }\n\n /* get the current timelevel */\n timelvl = 0;\n\n /* see if we have a physical boundary */\n symtable = SymmetryTableHandleForGrid(GH);\n if (symtable < 0)\n CCTK_WARN(0, \"internal error\");\n ierr = Util_TableGetIntArray(symtable, 2 * gdim, symbnd, \"symmetry_handle\");\n if (ierr != 2 * gdim)\n CCTK_WARN(0, \"internal error\");\n for (i = 0; i < 2 * gdim; i++) {\n is_physical[i] = symbnd[i] < 0;\n }\n\n /* now loop over all variables */\n for (var = first_var; var < first_var + num_vars; var++) {\n /* Apply condition if:\n + boundary is a physical boundary\n + boundary is an outer boundary\n + have enough grid points\n */\n for (i = 0; i < 2 * gdim; i++) {\n doBC[i] = is_physical[i] && (faces == CCTK_ALL_FACES || (faces & (1<cctk_ash[i];\n lsh[i] = GH->cctk_lsh[i];\n doBC[i * 2] &= GH->cctk_lsh[i] > widths[i * 2] && GH->cctk_bbox[i * 2];\n doBC[i * 2 + 1] &=\n GH->cctk_lsh[i] > widths[i * 2 + 1] && GH->cctk_bbox[i * 2 + 1];\n if (dir != 0) {\n doBC[i * 2] &= (dir < 0 && (i + 1 == abs(dir)));\n doBC[i * 2 + 1] &= (dir > 0 && (i + 1 == abs(dir)));\n }\n }\n\n switch (CCTK_VarTypeI(var)) {\n /* FIXME: can't pass an empty preprocessor constant as a macro argument\n on some systems (e.g. MacOS X), so we have to define it outside */\n case CCTK_VARIABLE_BYTE:\n SCALAR_BOUNDARY(CCTK_BYTE, CCTK_BYTE);\n break;\n\n case CCTK_VARIABLE_INT:\n SCALAR_BOUNDARY(CCTK_INT, CCTK_INT);\n break;\n\n case CCTK_VARIABLE_REAL:\n SCALAR_BOUNDARY(CCTK_REAL, CCTK_REAL);\n break;\n\n#ifdef HAVE_CCTK_INT1\n case CCTK_VARIABLE_INT1:\n SCALAR_BOUNDARY(CCTK_INT1, CCTK_INT1);\n break;\n#endif\n\n#ifdef HAVE_CCTK_INT2\n case CCTK_VARIABLE_INT2:\n SCALAR_BOUNDARY(CCTK_INT2, CCTK_INT2);\n break;\n#endif\n\n#ifdef HAVE_CCTK_INT4\n case CCTK_VARIABLE_INT4:\n SCALAR_BOUNDARY(CCTK_INT4, CCTK_INT4);\n break;\n#endif\n\n#ifdef HAVE_CCTK_INT8\n case CCTK_VARIABLE_INT8:\n SCALAR_BOUNDARY(CCTK_INT8, CCTK_INT8);\n break;\n#endif\n\n#ifdef HAVE_CCTK_INT16\n case CCTK_VARIABLE_INT16:\n SCALAR_BOUNDARY(CCTK_INT16, CCTK_INT16);\n break;\n#endif\n\n#ifdef HAVE_CCTK_REAL4\n case CCTK_VARIABLE_REAL4:\n SCALAR_BOUNDARY(CCTK_REAL4, CCTK_REAL4);\n break;\n#endif\n\n#ifdef HAVE_CCTK_REAL8\n case CCTK_VARIABLE_REAL8:\n SCALAR_BOUNDARY(CCTK_REAL8, CCTK_REAL8);\n break;\n#endif\n\n#ifdef HAVE_CCTK_REAL16\n case CCTK_VARIABLE_REAL16:\n SCALAR_BOUNDARY(CCTK_REAL16, CCTK_REAL16);\n break;\n#endif\n\n case CCTK_VARIABLE_COMPLEX:\n SCALAR_BOUNDARY(CCTK_COMPLEX, CCTK_REAL);\n break;\n\n default:\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Unsupported variable type %d for variable '%s'\",\n CCTK_VarTypeI(var), CCTK_VarName(var));\n return (-4);\n }\n }\n\n return (0);\n}\n\n/*@@\n @routine OldApplyBndScalar\n @date 5 May 2003\n @author David Rideout\n @desc\n The new boundary API expects a 2d-element array for the\n boundary_widths (d=dimension of grid variable), while\n the old API expects a d-element array. This function\n converts the old array to the new format.\n @enddesc\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_dir\n @vdesc boundary width in direction dir\n @vtype int\n @vio in\n @endvar\n @var stencil_alldirs\n @vdesc boundary widths for all directions\n @vtype int [ dimension of variable(s) ]\n @vio in\n @endvar\n @var dir\n @vdesc direction to set boundaries (0 for setting all directions)\n @vtype int\n @vio in\n @endvar\n @var scalar\n @vdesc scalar value to set the boundaries to\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var first_var\n @vdesc index of first variable to apply boundary conditions to\n @vtype int\n @vio in\n @endvar\n @var num_vars\n @vdesc number of variables\n @vtype int\n @vio in\n @endvar\n\n @calls CCTK_GroupIndexFromVarI\n ApplyBndScalar\n @returntype int\n @returndesc\n returncode from @seeroutine ApplyBndScalar\n @endreturndesc\n@@*/\n\nstatic int OldApplyBndScalar(const cGH *GH, int stencil_dir,\n const int *stencil_alldirs, int dir,\n CCTK_REAL scalar, int first_var, int num_vars) {\n int retval, dim, i;\n CCTK_INT *boundary_widths;\n static int warned;\n\n /* Convert stencil_alldirs to new format */\n dim = CCTK_GroupDimFromVarI(first_var);\n boundary_widths = malloc(2 * dim * sizeof(CCTK_INT));\n for (i = 0; i < 2 * dim; ++i) {\n boundary_widths[i] = stencil_alldirs[i / 2];\n }\n\n /* Bug people for using the old interface */\n if (!warned) {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Copied older d-element array of boundary widths into the \"\n \"newer 2d-element format. Please use the new boundary \"\n \"interface to avoid this.\");\n warned = 1;\n }\n\n /* Call ApplyBnd... with new boundary width array */\n retval = ApplyBndScalar(GH, stencil_dir, boundary_widths, dir, CCTK_ALL_FACES,\n scalar, first_var, num_vars);\n\n free(boundary_widths);\n return retval;\n}\n", "RadiationBoundary.c": "/*@@\n @file RadiationBoundary.c\n @date Mon Mar 15 15:09:00 1999\n @author Miguel Alcubierre, Gabrielle Allen, Gerd Lanfermann\n @desc\n Routines for applying radiation boundary conditions\n\n The radiative boundary condition that is implemented is:\n\n f = f0 + u(r - v*t) / r + h(r + v*t) / r\n\n That is, I assume outgoing radial waves with a 1/r\n fall off, and the correct asymptotic value f0, plus\n I include the possibility of incoming waves as well\n (these incoming waves should be modeled somehow).\n\n The condition above leads to the differential equation:\n\n (x / r) d f + v d f + v x (f - f0) / r^2 = v x H / r^2\n i t i i i\n\n where x_i is the normal direction to the given boundaries,\n and H = 2 dh(s)/ds.\n\n So at a given boundary I only worry about derivatives in\n the normal direction. Notice that u(r-v*t) has dissapeared,\n but we still do not know the value of H.\n\n To get H what I do is the following: I evaluate the\n expression one point in from the boundary and solve for H\n there. We now need a way of extrapolation H to the boundary.\n For this I assume that H falls off as a power law:\n\n H = k/r**n => d H = - n H/r\n i\n\n The value of n is is defined by the parameter \"radpower\".\n If this parameter is negative, H is forced to be zero (this\n corresponds to pure outgoing waves and is the default).\n\n The behaviour I have observed is the following: Using H=0\n is very stable, but has a very bad initial transient. Taking\n n to be 0 or positive improves the initial behaviour considerably,\n but introduces a drift that can kill the evolution at very late\n times. Empirically, the best value I have found is n=2, for\n which the initial behaviour is very nice, and the late time drift\n is quite small.\n\n Another problem with this condition is that it does not\n use the physical characteristic speed, but rather it assumes\n a wave speed of v, so the boundaries should be out in\n the region where the characteristic speed is constant.\n Notice that this speed does not have to be 1. For gauge\n quantities {alpha,phi,trK} we can have a different asymptotic\n speed, which is why the value of v is passed as a parameter.\n @enddesc\n @history\n @hdate unknown\n @hauthor Gerd Lanfermann\n @hdesc Ported to Cactus 4.0\n @hdate Fri 6 Apr 2001\n @hauthor Thomas Radke\n @hdesc BC routines generalized for applying to arbitrary CCTK data types\n @endhistory\n @version $Id$\n@@*/\n\n#include \n#include \n#include \n\n#include \"cctk.h\"\n#include \"util_Table.h\"\n#include \"util_ErrorCodes.h\"\n#include \"cctk_FortranString.h\"\n#include \"cctk_Parameters.h\"\n\n#include \"Boundary.h\"\n\n/* #define DEBUG */\n\n/* the rcs ID and its dummy function to use it */\nstatic const char *rcsid = \"$Header$\";\nCCTK_FILEVERSION(CactusBase_Boundary_RadiationBoundary_c);\n\nstatic int ApplyBndRadiative(const cGH *GH, int stencil_dir,\n const CCTK_INT *stencil_alldirs, int dir,\n CCTK_REAL var0, CCTK_REAL speed,\n CCTK_INT first_var_to, CCTK_INT first_var_from,\n int num_vars);\nstatic int OldApplyBndRadiative(const cGH *GH, int stencil_dir,\n const CCTK_INT *stencil_alldirs, int dir,\n CCTK_REAL var0, CCTK_REAL speed,\n int first_var_to, int first_var_from,\n int num_vars);\n\n/********************************************************************\n ******************** External Routines ************************\n ********************************************************************/\n\n/*@@\n @routine BndRadiative\n @date 6 Nov 2002\n @author David Rideout\n @desc\n Top level function which is registered as handling\n the Radiative boundary condition\n @enddesc\n @calls ApplyBndRadiative\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var num_vars\n @vdesc number of variables passed in through var_indices[]\n @vtype CCTK_INT\n @vio in\n @endvar\n @var var_indices\n @vdesc array of variable indicies to which to apply this boundary\n condition\n @vtype CCTK_INT *\n @vio in\n @endvar\n @var faces\n @vdesc array of set of faces to which to apply the bc\n @vtype CCTK_INT\n @vio in\n @endvar\n @var widths\n @vdesc array of boundary widths for each variable\n @vtype CCTK_INT\n @vio in\n @endvar\n @var table_handles\n @vdesc array of table handles which hold extra arguments\n @vtype CCTK_INT\n @vio in\n @endvar\n @returntype CCTK_INT\n @returndesc\n return code of @seeroutine ApplyBndRadiative\n -21 error reading boundary width array from table\n -22 wrong size boundary width array in table\n @endreturndesc\n@@*/\n\nCCTK_INT BndRadiative(const cGH *GH, CCTK_INT num_vars, CCTK_INT *vars,\n CCTK_INT *faces, CCTK_INT *widths, CCTK_INT *tables) {\n int i, j, k, gi, gdim, max_gdim, err, retval;\n\n /* variables to pass to ApplyBndRadiative */\n CCTK_INT *width_alldirs; /* width of boundary in all directions */\n int dir; /* direction in which to apply bc */\n CCTK_REAL limit, speed;\n CCTK_INT\n prev_time_level; /* variable index which holds the previous time level */\n\n#ifdef DEBUG\n printf(\"BndRadiative() got passed: GH=%p, num_vars=%d:\\n\", (const void *)GH,\n num_vars);\n printf(\"var index var name table handle\\n\");\n for (i = 0; i < num_vars; ++i) {\n printf(\"%d %12s %d\\n\", vars[i], CCTK_VarName(vars[i]), tables[i]);\n }\n printf(\"end of table\\n\");\n\n/* CCTK_WARN(0, \"stopping code\"); */\n#endif\n\n /* Initialize variables */\n retval = 0;\n width_alldirs = NULL;\n max_gdim = 0;\n\n /* loop through variables, j at a time */\n for (i = 0; i < num_vars; i += j) {\n /* find other adjacent vars which are selected for identical bcs */\n j = 1;\n /* Since GFs are allowed to have different staggering, the best we\n can do is find variables of the same group which are selected\n for identical bcs. If all GFs had the same staggering then we\n could groups many GFs together. */\n gi = CCTK_GroupIndexFromVarI(vars[i]);\n#ifdef DEBUG\n printf(\"starting increment computation with group %d:\\n\", gi);\n printf(\"this group had %d members\\n\", CCTK_NumVarsInGroupI(gi));\n#endif\n while (i + j < num_vars && vars[i + j] == vars[i] + j &&\n CCTK_GroupIndexFromVarI(vars[i + j]) == gi &&\n tables[i + j] == tables[i] && faces[i + j] == faces[i] &&\n widths[i + j] == widths[i]) {\n ++j;\n }\n\n /* Check to see if faces specification is valid */\n if (faces[i] != CCTK_ALL_FACES) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Faces specification %d for Radiative boundary conditions on \"\n \"%s is not implemented yet. \"\n \"Applying Radiative bcs to all (external) faces.\",\n (int)faces[i], CCTK_VarName(vars[i]));\n }\n dir = 0; /* apply bc to all faces */\n\n /* Set up default arguments for ApplyBndRadiative */\n /* Defaults for remainder of arguments */\n limit = 0.;\n prev_time_level = vars[i];\n speed = 1.;\n\n /* Look on table for possible non-default arguments\n * (If any of these table look-ups fail, the value will be unchanged\n * from its default value)\n */\n /* Asymptotic value of function at infinity */\n err = Util_TableGetReal(tables[i], &limit, \"LIMIT\");\n if (err == UTIL_ERROR_BAD_HANDLE) {\n CCTK_VWarn(5, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid table handle passed for Radiative boundary \"\n \"conditions for %s. Using all default values.\",\n CCTK_VarName(vars[i]));\n } else {\n /* Wave speed */\n Util_TableGetReal(tables[i], &speed, \"SPEED\");\n }\n\n /* Determine boundary width on all faces */\n /* allocate memory for buffer */\n gdim = CCTK_GroupDimI(gi);\n if (gdim > max_gdim) {\n width_alldirs = realloc(width_alldirs, 2 * gdim * sizeof(CCTK_INT));\n max_gdim = gdim;\n }\n\n /* fill it with values, either from table or the boundary_width\n parameter */\n if (widths[i] < 0) {\n err = Util_TableGetIntArray(tables[i], 2 * gdim, width_alldirs,\n \"BOUNDARY_WIDTH\");\n if (err < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Error %d when reading boundary width array from table \"\n \"for %s\",\n err, CCTK_VarName(vars[i]));\n return -21;\n } else if (err != 2 * gdim) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Boundary width array for %s has %d elements, but %d \"\n \"expected\",\n CCTK_VarName(vars[i]), err, 2 * gdim);\n return -22;\n }\n } else {\n for (k = 0; k < 2 * gdim; ++k) {\n width_alldirs[k] = widths[i];\n }\n }\n\n /* Apply the boundary condition */\n if ((retval = ApplyBndRadiative(GH, 0, width_alldirs, dir, limit, speed,\n vars[i], prev_time_level, j)) < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"ApplyBndRadiative() returned %d\", retval);\n }\n }\n#ifdef DEBUG\n printf(\"BndRadiative(): returning %d\\n\", retval);\n#endif\n free(width_alldirs);\n\n return retval;\n}\n\n/* prototypes for external C routines are declared in header Boundary.h\n here only follow the fortran wrapper prototypes */\nvoid CCTK_FCALL\n CCTK_FNAME(BndRadiativeDirGI)(int *ierr, const cGH **GH,\n const int *stencil_size, const int *dir,\n const CCTK_REAL *var0, const CCTK_REAL *speed,\n const int *gi_to, const int *gi_from);\nvoid CCTK_FCALL\n CCTK_FNAME(BndRadiativeGI)(int *ierr, const cGH **GH, const int *stencil,\n const CCTK_REAL *var0, const CCTK_REAL *speed,\n const int *gi_to, const int *gi_from);\nvoid CCTK_FCALL\n CCTK_FNAME(BndRadiativeDirGN)(int *ierr, const cGH **GH,\n const int *stencil_size, const int *dir,\n const CCTK_REAL *var0, const CCTK_REAL *speed,\n TWO_FORTSTRING_ARG);\nvoid CCTK_FCALL\n CCTK_FNAME(BndRadiativeGN)(int *ierr, const cGH **GH, const int *stencil,\n const CCTK_REAL *var0, const CCTK_REAL *speed,\n TWO_FORTSTRING_ARG);\nvoid CCTK_FCALL\n CCTK_FNAME(BndRadiativeDirVI)(int *ierr, const cGH **GH,\n const int *stencil_size, const int *dir,\n const CCTK_REAL *var0, const CCTK_REAL *speed,\n const int *vi_to, const int *vi_from);\nvoid CCTK_FCALL\n CCTK_FNAME(BndRadiativeVI)(int *ierr, const cGH **GH, const int *stencil,\n const CCTK_REAL *var0, const CCTK_REAL *speed,\n const int *vi_to, const int *vi_from);\nvoid CCTK_FCALL\n CCTK_FNAME(BndRadiativeDirVN)(int *ierr, const cGH **GH,\n const int *stencil_size, const int *dir,\n const CCTK_REAL *var0, const CCTK_REAL *speed,\n TWO_FORTSTRING_ARG);\nvoid CCTK_FCALL\n CCTK_FNAME(BndRadiativeVN)(int *ierr, const cGH **GH, const int *stencil,\n const CCTK_REAL *var0, const CCTK_REAL *speed,\n TWO_FORTSTRING_ARG);\n\n/********************************************************************\n ******************** Internal Routines ************************\n ********************************************************************/\n/*@@\n @routine BndRadiativeDirGI\n @date Sat Jan 20 2001\n @author Gabrielle Allen\n @desc\n Aply radiative BC's by group index in given direction\n @enddesc\n @calls ApplyBndRadiative\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to apply BC\n @vtype int\n @vio in\n @endvar\n @var var0\n @vdesc asymptotic value of function at infinity\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var speed\n @vdesc wave speed\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var gi_to\n @vdesc index of group to apply BC to\n @vtype int\n @vio in\n @endvar\n @var gi_from\n @vdesc index of group to apply BC from\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndRadiative
\n -1 if invalid group indices are given\n @endreturndesc\n@@*/\nint BndRadiativeDirGI(const cGH *GH, int stencil_size, int dir, CCTK_REAL var0,\n CCTK_REAL speed, int gi_to, int gi_from) {\n int first_vi_to, first_vi_from, retval;\n\n first_vi_to = CCTK_FirstVarIndexI(gi_to);\n first_vi_from = CCTK_FirstVarIndexI(gi_from);\n if (first_vi_to >= 0 && first_vi_from >= 0) {\n retval =\n ApplyBndRadiative(GH, stencil_size, NULL, dir, var0, speed, first_vi_to,\n first_vi_from, CCTK_NumVarsInGroupI(gi_to));\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group indices %d and/or %d in BndRadiativeDirGI\", gi_to,\n gi_from);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL\n CCTK_FNAME(BndRadiativeDirGI)(int *ierr, const cGH **GH,\n const int *stencil_size, const int *dir,\n const CCTK_REAL *var0, const CCTK_REAL *speed,\n const int *gi_to, const int *gi_from) {\n *ierr = BndRadiativeDirGI(*GH, *stencil_size, *dir, *var0, *speed, *gi_to,\n *gi_from);\n}\n\n/*@@\n @routine BndRadiativeGI\n @date Tue Jul 18 18:04:07 2000\n @author Gerd Lanfermann\n @desc\n Aply radiative BC's by group index\n @enddesc\n @calls ApplyBndRadiative\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int [ dimension of group ]\n @vio in\n @endvar\n @var var0\n @vdesc asymptotic value of function at infinity\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var speed\n @vdesc wave speed\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var gi_to\n @vdesc index of group to apply BC to\n @vtype int\n @vio in\n @endvar\n @var gi_from\n @vdesc index of group to apply BC from\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndRadiative\n -1 if invalid group indices are given\n @endreturndesc\n@@*/\nint BndRadiativeGI(const cGH *GH, const int *stencil, CCTK_REAL var0,\n CCTK_REAL speed, int gi_to, int gi_from) {\n int first_vi_to, first_vi_from, retval;\n\n first_vi_to = CCTK_FirstVarIndexI(gi_to);\n first_vi_from = CCTK_FirstVarIndexI(gi_from);\n if (first_vi_to >= 0 && first_vi_from >= 0) {\n retval = OldApplyBndRadiative(GH, -1, (const CCTK_INT *)stencil, 0, var0,\n speed, first_vi_to, first_vi_from,\n CCTK_NumVarsInGroupI(gi_to));\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group indices %d and/or %d in BndRadiativeGI\", gi_to,\n gi_from);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL\n CCTK_FNAME(BndRadiativeGI)(int *ierr, const cGH **GH, const int *stencil,\n const CCTK_REAL *var0, const CCTK_REAL *speed,\n const int *gi_to, const int *gi_from) {\n *ierr = BndRadiativeGI(*GH, stencil, *var0, *speed, *gi_to, *gi_from);\n}\n\n/* ===================================================================== */\n\n/*@@\n @routine BndRadiativeDirGN\n @date Sat Jan 20 2001\n @author Gabrielle Allen\n @desc\n Apply radiative BC's by group name in given direction\n @enddesc\n @calls BndRadiativeDirGI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to apply BC\n @vtype int\n @vio in\n @endvar\n @var var0\n @vdesc asymptotic value of function at infinity\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var speed\n @vdesc wave speed\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var gname_to\n @vdesc name of group to apply BC to\n @vtype const char *\n @vio in\n @endvar\n @var gname_from\n @vdesc name of group to apply BC from\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndRadiativeDirGI\n -1 if invalid group names are given\n @endreturndesc\n@@*/\nint BndRadiativeDirGN(const cGH *GH, int stencil_size, int dir, CCTK_REAL var0,\n CCTK_REAL speed, const char *gname_to,\n const char *gname_from) {\n int gi_to, gi_from, retval;\n\n gi_to = CCTK_GroupIndex(gname_to);\n gi_from = CCTK_GroupIndex(gname_from);\n if (gi_to >= 0 && gi_from >= 0) {\n retval =\n BndRadiativeDirGI(GH, stencil_size, dir, var0, speed, gi_to, gi_from);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group names '%s' and/or '%s' in BndRadiativeDirGN\",\n gname_to, gname_from);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL\n CCTK_FNAME(BndRadiativeDirGN)(int *ierr, const cGH **GH,\n const int *stencil_size, const int *dir,\n const CCTK_REAL *var0, const CCTK_REAL *speed,\n TWO_FORTSTRING_ARG) {\n TWO_FORTSTRINGS_CREATE(gname_to, gname_from)\n *ierr = BndRadiativeDirGN(*GH, *stencil_size, *dir, *var0, *speed, gname_to,\n gname_from);\n free(gname_to);\n free(gname_from);\n}\n\n/*@@\n @routine BndRadiativeGN\n @date Tue Jul 18 18:04:07 2000\n @author Gerd Lanfermann\n @desc\n Aply radiative BC's by group name\n @enddesc\n @calls BndRadiativeGI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int [ dimension of group ]\n @vio in\n @endvar\n @var var0\n @vdesc asymptotic value of function at infinity\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var speed\n @vdesc wave speed\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var gname_to\n @vdesc name of group to apply BC to\n @vtype const char *\n @vio in\n @endvar\n @var gname_from\n @vdesc name of group to apply BC from\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndRadiativeGI
\n -1 if invalid group names are given\n @endreturndesc\n@@*/\nint BndRadiativeGN(const cGH *GH, const int *stencil, CCTK_REAL var0,\n CCTK_REAL speed, const char *gname_to,\n const char *gname_from) {\n int gi_to, gi_from, retval;\n\n gi_to = CCTK_GroupIndex(gname_to);\n gi_from = CCTK_GroupIndex(gname_from);\n if (gi_to >= 0 && gi_from >= 0) {\n retval = BndRadiativeGI(GH, stencil, var0, speed, gi_to, gi_from);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group names '%s' and/or '%s' in BndRadiativeGN\",\n gname_to, gname_from);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL\n CCTK_FNAME(BndRadiativeGN)(int *ierr, const cGH **GH, const int *stencil,\n const CCTK_REAL *var0, const CCTK_REAL *speed,\n TWO_FORTSTRING_ARG) {\n TWO_FORTSTRINGS_CREATE(gname_to, gname_from)\n *ierr = BndRadiativeGN(*GH, stencil, *var0, *speed, gname_to, gname_from);\n free(gname_to);\n free(gname_from);\n}\n\n/* ===================================================================== */\n\n/*@@\n @routine BndRadiativeDirVI\n @date Sat Jan 20 2001\n @author Gabrielle Allen\n @desc\n Apply radiative BC's by variable index in given direction\n @enddesc\n @calls ApplyBndRadiative\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to apply BC\n @vtype int\n @vio in\n @endvar\n @var var0\n @vdesc asymptotic value of function at infinity\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var speed\n @vdesc wave speed\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var vi_to\n @vdesc index of variable to apply BC to\n @vtype int\n @vio in\n @endvar\n @var vi_from\n @vdesc index of variable to apply BC from\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndRadiative
\n -1 if invalid variable indices are given\n @endreturndesc\n@@*/\nint BndRadiativeDirVI(const cGH *GH, int stencil_size, int dir, CCTK_REAL var0,\n CCTK_REAL speed, int vi_to, int vi_from) {\n int retval, num_vars;\n\n num_vars = CCTK_NumVars();\n if (vi_to >= 0 && vi_to < num_vars && vi_from >= 0 && vi_from < num_vars) {\n retval = ApplyBndRadiative(GH, stencil_size, NULL, dir, var0, speed, vi_to,\n vi_from, 1);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable indices %d and/or %d in BndRadiativeDirVI\",\n vi_to, vi_from);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL\n CCTK_FNAME(BndRadiativeDirVI)(int *ierr, const cGH **GH,\n const int *stencil_size, const int *dir,\n const CCTK_REAL *var0, const CCTK_REAL *speed,\n const int *vi_to, const int *vi_from) {\n *ierr = BndRadiativeDirVI(*GH, *stencil_size, *dir, *var0, *speed, *vi_to,\n *vi_from);\n}\n\n/*@@\n @routine BndRadiativeVI\n @date Tue Jul 18 18:04:07 2000\n @author Gerd Lanfermann\n @desc\n Apply radiative BC's by variable index\n @enddesc\n @calls ApplyBndRadiative\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int [ dimension of variable ]\n @vio in\n @endvar\n @var var0\n @vdesc asymptotic value of function at infinity\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var speed\n @vdesc wave speed\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var vi_to\n @vdesc index of variable to apply BC to\n @vtype int\n @vio in\n @endvar\n @var vi_from\n @vdesc index of variable to apply BC from\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndRadiative
\n -1 if invalid variable indices are given\n @endreturndesc\n@@*/\nint BndRadiativeVI(const cGH *GH, const int *stencil, CCTK_REAL var0,\n CCTK_REAL speed, int vi_to, int vi_from) {\n int retval, num_vars;\n\n num_vars = CCTK_NumVars();\n if (vi_to >= 0 && vi_to < num_vars && vi_from >= 0 && vi_from < num_vars) {\n retval = OldApplyBndRadiative(GH, -1, (const CCTK_INT *)stencil, 0, var0,\n speed, vi_to, vi_from, 1);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable indices %d and/or %d in BndRadiativeVI\", vi_to,\n vi_from);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL\n CCTK_FNAME(BndRadiativeVI)(int *ierr, const cGH **GH, const int *stencil,\n const CCTK_REAL *var0, const CCTK_REAL *speed,\n const int *vi_to, const int *vi_from) {\n *ierr = BndRadiativeVI(*GH, stencil, *var0, *speed, *vi_to, *vi_from);\n}\n\n/* ======================================================================= */\n\n/*@@\n @routine BndRadiativeDirVN\n @date Sat Jan 20 2001\n @author Gabrielle Allen\n @desc\n Apply radiative BC's by variable name in given direction\n @enddesc\n @calls BndRadiativeDirVI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to apply BC\n @vtype int\n @vio in\n @endvar\n @var var0\n @vdesc asymptotic value of function at infinity\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var speed\n @vdesc wave speed\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var vname_to\n @vdesc name of variable to apply BC to\n @vtype const char *\n @vio in\n @endvar\n @var vname_from\n @vdesc name of variable to apply BC from\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndRadiativeDirVI
\n -1 if invalid variable names are given\n @endreturndesc\n@@*/\nint BndRadiativeDirVN(const cGH *GH, int stencil_size, int dir, CCTK_REAL var0,\n CCTK_REAL speed, const char *vname_to,\n const char *vname_from) {\n int vi_to, vi_from, num_vars, retval;\n\n vi_to = CCTK_VarIndex(vname_to);\n vi_from = CCTK_VarIndex(vname_from);\n num_vars = CCTK_NumVars();\n\n if (vi_to >= 0 && vi_to < num_vars && vi_from >= 0 && vi_from < num_vars) {\n retval =\n BndRadiativeDirVI(GH, stencil_size, dir, var0, speed, vi_to, vi_from);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable names '%s' and/or '%s' in BndRadiativeDirVN\",\n vname_to, vname_from);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL\n CCTK_FNAME(BndRadiativeDirVN)(int *ierr, const cGH **GH,\n const int *stencil_size, const int *dir,\n const CCTK_REAL *var0, const CCTK_REAL *speed,\n TWO_FORTSTRING_ARG) {\n TWO_FORTSTRINGS_CREATE(vname_to, vname_from)\n *ierr = BndRadiativeDirVN(*GH, *stencil_size, *dir, *var0, *speed, vname_to,\n vname_from);\n free(vname_to);\n free(vname_from);\n}\n\n/*@@\n @routine BndRadiativeVN\n @date Tue Jul 18 18:04:07 2000\n @author Gerd Lanfermann\n @desc\n Apply radiative BC's by variable name\n @enddesc\n @calls BndRadiativeVI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int [ dimension of variable ]\n @vio in\n @endvar\n @var var0\n @vdesc asymptotic value of function at infinity\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var speed\n @vdesc wave speed\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var vname_to\n @vdesc name of variable to apply BC to\n @vtype const char *\n @vio in\n @endvar\n @var vname_from\n @vdesc name of variable to apply BC from\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndRadiativeVI
\n -1 if invalid variable names are given\n @endreturndesc\n@@*/\nint BndRadiativeVN(const cGH *GH, const int *stencil, CCTK_REAL var0,\n CCTK_REAL speed, const char *vname_to,\n const char *vname_from) {\n int vi_to, vi_from, num_vars, retval;\n\n vi_to = CCTK_VarIndex(vname_to);\n vi_from = CCTK_VarIndex(vname_from);\n num_vars = CCTK_NumVars();\n\n if (vi_to >= 0 && vi_to < num_vars && vi_from >= 0 && vi_from < num_vars) {\n retval = BndRadiativeVI(GH, stencil, var0, speed, vi_to, vi_from);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable names '%s' and/or '%s' in BndRadiativeVN\",\n vname_to, vname_from);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL\n CCTK_FNAME(BndRadiativeVN)(int *ierr, const cGH **GH, const int *stencil,\n const CCTK_REAL *var0, const CCTK_REAL *speed,\n TWO_FORTSTRING_ARG) {\n TWO_FORTSTRINGS_CREATE(vname_to, vname_from)\n *ierr = BndRadiativeVN(*GH, stencil, *var0, *speed, vname_to, vname_from);\n free(vname_to);\n free(vname_from);\n}\n\n/********************************************************************\n ********************* Local Routines *************************\n ********************************************************************/\n\n/* shortcut for multiplying a variable with itself */\n#define SQR(a) ((a) * (a))\n\n/* the maximum dimension we can deal with */\n#define MAXDIM 3\n\n/*@@\n @routine LOWER_RADIATIVE_BOUNDARY_3D\n @date Mon 9 Apr 2001\n @author Thomas Radke\n @desc\n Macro to apply radiative BC to a lower bound of a 3D variable\n @enddesc\n\n @var istart, jstart, kstart\n @vdesc start index for the x,y,z direction\n @vtype int\n @vio in\n @endvar\n @var dim\n @vdesc dimension to apply BC\n @vtype int\n @vio in\n @endvar\n @var cctk_type\n @vdesc CCTK datatypes of the source and target variable\n @vtype \n @vio in\n @endvar\n@@*/\n#define LOWER_RADIATIVE_BOUNDARY_3D(istart, jstart, kstart, dim, cctk_type) \\\n { \\\n int _i, _j, _k; \\\n int _0 = 0 * offset[dim], _1 = 1 * offset[dim], _2 = 2 * offset[dim]; \\\n \\\n for (_k = kstart - 1; _k >= 0; _k--) { \\\n for (_j = jstart - 1; _j >= 0; _j--) { \\\n int _idx = CCTK_GFINDEX3D(GH, istart - 1, _j, _k); \\\n const CCTK_REAL *_r = xyzr[MAXDIM] + _idx, *_xyz = xyzr[dim] + _idx; \\\n cctk_type *_to = (cctk_type *)to_ptr + _idx; \\\n const cctk_type *_from = (const cctk_type *)from_ptr + _idx; \\\n \\\n for (_i = istart - 1; _i >= 0; _i--) { \\\n CCTK_REAL _r0_inv = 1 / _r[_0], _r1_inv = 1 / _r[_1]; \\\n \\\n if (radpower > 0) { \\\n CCTK_REAL H; \\\n \\\n H = 0.25 * radpower * dxyz[dim] * \\\n (_xyz[_0] * SQR(_r0_inv) + _xyz[_1] * SQR(_r1_inv)); \\\n H = (1 + H) / (1 - H); \\\n H *= dtv * (0.25 * (_to[_1] + _to[_2] + _from[_1] + _from[_2]) - \\\n var0) + \\\n 0.5 * (_r[_1] * (_to[_1] - _from[_1]) + \\\n _r[_2] * (_to[_2] - _from[_2])) + \\\n 0.25 * (_to[_2] - _to[_1] + _from[_2] - _from[_1]) * \\\n rho[dim] * \\\n (SQR(_r[_1]) / _xyz[_1] + SQR(_r[_2]) / _xyz[_2]); \\\n dtvvar0H = dtvvar0 + H; \\\n } \\\n \\\n _to[_0] = (cctk_type)( \\\n (dtvvar0H * \\\n (_xyz[_0] * SQR(_r0_inv) + _xyz[_1] * SQR(_r1_inv)) - \\\n _to[_1] * \\\n (rho[dim] + _xyz[_1] * _r1_inv * (1 + dtvh * _r1_inv)) + \\\n _from[_0] * \\\n (rho[dim] + _xyz[_0] * _r0_inv * (1 - dtvh * _r0_inv)) - \\\n _from[_1] * \\\n (rho[dim] - _xyz[_1] * _r1_inv * (1 - dtvh * _r1_inv))) / \\\n (-rho[dim] + _xyz[_0] * _r0_inv * (1 + dtvh * _r0_inv))); \\\n _r--; \\\n _xyz--; \\\n _to--; \\\n _from--; \\\n } \\\n } \\\n } \\\n }\n\n/*@@\n @routine UPPER_RADIATIVE_BOUNDARY_3D\n @date Mon 9 Apr 2001\n @author Thomas Radke\n @desc\n Macro to apply radiative BC to an upper bound of a 3D variable\n @enddesc\n\n @var istart, jstart, kstart\n @vdesc start index for the x,y,z direction\n @vtype int\n @vio in\n @endvar\n @var dim\n @vdesc dimension to apply BC\n @vtype int\n @vio in\n @endvar\n @var cctk_type\n @vdesc CCTK datatypes of the source and target variable\n @vtype \n @vio in\n @endvar\n@@*/\n#define UPPER_RADIATIVE_BOUNDARY_3D(istart, jstart, kstart, dim, cctk_type) \\\n { \\\n int _i, _j, _k; \\\n int _0 = -0 * offset[dim], _1 = -1 * offset[dim], _2 = -2 * offset[dim]; \\\n \\\n for (_k = kstart; _k < GH->cctk_lsh[2]; _k++) { \\\n for (_j = jstart; _j < GH->cctk_lsh[1]; _j++) { \\\n int _idx = CCTK_GFINDEX3D(GH, istart, _j, _k); \\\n const CCTK_REAL *_r = xyzr[MAXDIM] + _idx, *_xyz = xyzr[dim] + _idx; \\\n cctk_type *_to = (cctk_type *)to_ptr + _idx; \\\n const cctk_type *_from = (const cctk_type *)from_ptr + _idx; \\\n \\\n for (_i = istart; _i < GH->cctk_lsh[0]; _i++) { \\\n CCTK_REAL _r0_inv = 1 / _r[_0], _r1_inv = 1 / _r[_1]; \\\n \\\n if (radpower > 0) { \\\n CCTK_REAL H; \\\n \\\n H = 0.25 * radpower * dxyz[dim] * \\\n (_xyz[_0] * SQR(_r0_inv) + _xyz[_1] * SQR(_r1_inv)); \\\n H = (1 - H) / (1 + H); \\\n H *= dtv * (0.25 * (_to[_1] + _to[_2] + _from[_1] + _from[_2]) - \\\n var0) + \\\n 0.5 * (_r[_1] * (_to[_1] - _from[_1]) + \\\n _r[_2] * (_to[_2] - _from[_2])) + \\\n 0.25 * (_to[_1] - _to[_2] + _from[_1] - _from[_2]) * \\\n rho[dim] * \\\n (SQR(_r[_1]) / _xyz[_1] + SQR(_r[_2]) / _xyz[_2]); \\\n dtvvar0H = dtvvar0 + H; \\\n } \\\n \\\n _to[_0] = (cctk_type)( \\\n (dtvvar0H * \\\n (_xyz[_0] * (SQR(_r0_inv)) + _xyz[_1] * (SQR(_r1_inv))) + \\\n _to[_1] * \\\n (rho[dim] - _xyz[_1] * _r1_inv * (1 + dtvh * _r1_inv)) + \\\n _from[_0] * \\\n (-rho[dim] + _xyz[_0] * _r0_inv * (1 - dtvh * _r0_inv)) + \\\n _from[_1] * \\\n (rho[dim] + _xyz[_1] * _r1_inv * (1 - dtvh * _r1_inv))) / \\\n (rho[dim] + _xyz[_0] * _r0_inv * (1 + dtvh * _r0_inv))); \\\n _r++; \\\n _xyz++; \\\n _to++; \\\n _from++; \\\n } \\\n } \\\n } \\\n }\n\n/*@@\n @routine RADIATIVE_BOUNDARY\n @date Mon 9 Apr 2001\n @author Thomas Radke\n @desc\n Macro to apply radiative BC to a variable\n Currently it is limited to 3D variables only.\n @enddesc\n @calls LOWER_RADIATIVE_BOUNDARY_3D\n UPPER_RADIATIVE_BOUNDARY_3D\n\n @var lsh\n @vdesc local shape of the variable\n @vtype int [ dim ]\n @vio in\n @endvar\n @var stencil\n @vdesc stencils in every direction\n @vtype int [ 2*dim ]\n @vio in\n @endvar\n @var cctk_type\n @vdesc CCTK datatypes of the source and target variable\n @vtype \n @vio in\n @endvar\n@@*/\n#define RADIATIVE_BOUNDARY(lsh, stencil, cctk_type) \\\n { \\\n /* check the dimensionality */ \\\n if (gdim != 3) { \\\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING, \\\n \"ApplyBndRadiative: variable dimension of %d not supported\", \\\n gdim); \\\n return (-5); \\\n } \\\n \\\n /* Lower x-bound */ \\\n if (doBC[0]) { \\\n LOWER_RADIATIVE_BOUNDARY_3D(stencil[0], lsh[1], lsh[2], 0, cctk_type); \\\n } \\\n \\\n /* Upper x-bound */ \\\n if (doBC[1]) { \\\n UPPER_RADIATIVE_BOUNDARY_3D(lsh[0] - stencil[1], 0, 0, 0, cctk_type); \\\n } \\\n \\\n /* Lower y-bound */ \\\n if (doBC[2]) { \\\n LOWER_RADIATIVE_BOUNDARY_3D(lsh[0], stencil[2], lsh[2], 1, cctk_type); \\\n } \\\n \\\n /* Upper y-bound */ \\\n if (doBC[3]) { \\\n UPPER_RADIATIVE_BOUNDARY_3D(0, lsh[1] - stencil[3], 0, 1, cctk_type); \\\n } \\\n \\\n /* Lower z-bound */ \\\n if (doBC[4]) { \\\n LOWER_RADIATIVE_BOUNDARY_3D(lsh[0], lsh[1], stencil[4], 2, cctk_type); \\\n } \\\n \\\n /* Upper z-bound */ \\\n if (doBC[5]) { \\\n UPPER_RADIATIVE_BOUNDARY_3D(0, 0, lsh[2] - stencil[5], 2, cctk_type); \\\n } \\\n }\n\n/*@@\n @routine ApplyBndRadiative\n @date Tue Jul 18 18:04:07 2000\n @author Gerd Lanfermann\n @desc\n Apply radiation boundary conditions to a group of grid functions\n given by their indices\n This routine is called by the various BndRadiativeXXX wrappers.\n\n Although it is currently limited to handle 3D variables only\n it can easily be extended for other dimensions\n by adapting the appropriate macros.\n @enddesc\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var width_dir\n @vdesc boundary width in direction dir\n @vtype int\n @vio in\n @endvar\n @var in_widths\n @vdesc boundary widths for all directions\n @vtype const CCTK_INT [ dimension of variable(s) ]\n @vio in\n @endvar\n @var dir\n @vdesc direction to copy boundaries (0 for copying all directions)\n @vtype int\n @vio in\n @endvar\n @var var0\n @vdesc asymptotic value of function at infinity\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var speed\n @vdesc wave speed\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var first_var_to\n @vdesc index of first variable to copy boundaries to\n @vtype CCTK_INT\n @vio in\n @endvar\n @var first_var_from\n @vdesc index of first variable to copy boundaries from\n @vtype CCTK_INT\n @vio in\n @endvar\n @var num_vars\n @vdesc number of variables\n @vtype int\n @vio in\n @endvar\n @calls CCTK_VarTypeI\n CCTK_GroupDimFromVarI\n RADIATIVE_BOUNDARY\n @history\n @hdate Mon 9 Apr 2001\n @hauthor Thomas Radke\n @hdesc Merged separate routines for 1D, 2D, and 3D\n into a single generic routine\n @endhistory\n\n @returntype int\n @returndesc\n 0 for success\n -1 if abs(direction) is greater than variables' dimension\n -2 if variable dimension is not supported\n -3 if NULL pointer passed as boundary width array\n -4 if variable type is not supported\n -5 if variable dimension is other than 3D\n -6 if a coordinate is not found\n @endreturndesc\n@@*/\nstatic int ApplyBndRadiative(const cGH *GH, int width_dir,\n const CCTK_INT *in_widths, int dir, CCTK_REAL var0,\n CCTK_REAL speed, CCTK_INT first_var_to,\n CCTK_INT first_var_from, int num_vars) {\n int i, gdim, indx;\n int var_to, var_from;\n int timelvl_from;\n char coord_system_name[10];\n int written;\n CCTK_REAL dxyz[MAXDIM], rho[MAXDIM];\n const CCTK_REAL *xyzr[MAXDIM + 1];\n CCTK_INT doBC[2 * MAXDIM], widths[2 * MAXDIM], offset[MAXDIM];\n CCTK_INT symtable;\n CCTK_INT symbnd[2 * MAXDIM];\n CCTK_INT is_physical[2 * MAXDIM];\n CCTK_INT ierr;\n CCTK_REAL dtv, dtvh, dtvvar0, dtvvar0H;\n void *to_ptr;\n const void *from_ptr;\n DECLARE_CCTK_PARAMETERS\n\n /* check the direction parameter */\n if (abs(dir) > MAXDIM) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"ApplyBndRadiative: direction %d is greater than maximum \"\n \"dimension %d\",\n dir, MAXDIM);\n return (-1);\n }\n\n /* get the dimensionality */\n gdim = CCTK_GroupDimFromVarI(first_var_to);\n\n /* check the dimensionality */\n if (gdim > MAXDIM) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"ApplyBndRadiative: variable dimension of %d not supported\",\n gdim);\n return (-2);\n }\n\n /* set up boundary width array */\n if (dir) {\n widths[2 * (abs(dir) - 1)] = width_dir;\n widths[2 * (abs(dir) - 1) + 1] = width_dir;\n } else if (in_widths) {\n memcpy(widths, in_widths, 2 * gdim * sizeof *widths);\n } else {\n CCTK_WARN(1, \"ApplyBndRadiative: NULL pointer passed \"\n \"for boundary width array\");\n return (-3);\n }\n\n /* sanity check on width of boundary, */\n BndSanityCheckWidths(GH, first_var_to, gdim, widths, \"Radiative\");\n\n /* Use next time level, if available */\n timelvl_from = 0;\n if (CCTK_DeclaredTimeLevelsVI(first_var_from) > 1) {\n timelvl_from = 1;\n }\n\n /* Find Courant parameters. */\n dtv = speed * GH->cctk_delta_time;\n dtvh = 0.5 * dtv;\n dtvvar0 = dtv * var0;\n dtvvar0H = dtvvar0;\n\n written = snprintf(coord_system_name, sizeof(coord_system_name), \"cart%dd\",\n gdim);\n if (written >= sizeof(coord_system_name)) {\n CCTK_VWARN(1, \"Buffer too small for gdim=%d\", gdim);\n return (-6);\n }\n for (i = 0; i < gdim; i++) {\n /* Radiative boundaries need the underlying Cartesian coordinates */\n indx = CCTK_CoordIndex(i + 1, NULL, coord_system_name);\n if (indx < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Coordinate for system %s not found\", coord_system_name);\n return (-6);\n }\n xyzr[i] = GH->data[indx][0];\n\n /* According to the Cactus spec, the true delta_space values for a\n grid are calculated as follows: */\n dxyz[i] = GH->cctk_delta_space[i] / GH->cctk_levfac[i];\n\n rho[i] = dtv / dxyz[i];\n\n offset[i] = i == 0 ? 1 : offset[i - 1] * GH->cctk_lsh[i - 1];\n }\n\n /* Append r grid variable to end of xyzr[] array */\n written = snprintf(coord_system_name, sizeof(coord_system_name), \"spher%dd\",\n gdim);\n if (written >= sizeof(coord_system_name)) {\n CCTK_VWARN(1, \"Buffer too small for gdim=%d\", gdim);\n return (-6);\n }\n indx = CCTK_CoordIndex(-1, \"r\", coord_system_name);\n if (indx < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Coordinate for system %s not found\", coord_system_name);\n return (-6);\n }\n xyzr[MAXDIM] = GH->data[indx][0];\n\n /* see if we have a physical boundary */\n symtable = SymmetryTableHandleForGrid(GH);\n if (symtable < 0)\n CCTK_WARN(0, \"internal error\");\n ierr = Util_TableGetIntArray(symtable, 2 * gdim, symbnd, \"symmetry_handle\");\n if (ierr != 2 * gdim)\n CCTK_WARN(0, \"internal error\");\n for (i = 0; i < 2 * gdim; i++) {\n is_physical[i] = symbnd[i] < 0;\n }\n\n /* now loop over all variables */\n for (var_to = first_var_to, var_from = first_var_from;\n var_to < first_var_to + num_vars; var_to++, var_from++) {\n to_ptr = GH->data[var_to][0];\n from_ptr = GH->data[var_from][timelvl_from];\n\n /* Apply condition if:\n + boundary is a physical boundary\n + boundary is an outer boundary\n + have enough grid points\n */\n for (i = 0; i < 2 * MAXDIM; i++) {\n doBC[i] = is_physical[i];\n }\n for (i = 0; i < MAXDIM; i++) {\n doBC[i * 2] &= GH->cctk_lsh[i] > widths[i * 2] && GH->cctk_bbox[i * 2];\n doBC[i * 2 + 1] &=\n GH->cctk_lsh[i] > widths[i * 2 + 1] && GH->cctk_bbox[i * 2 + 1];\n if (dir != 0) {\n doBC[i * 2] &= (dir < 0 && (i + 1 == abs(dir)));\n doBC[i * 2 + 1] &= (dir > 0 && (i + 1 == abs(dir)));\n }\n }\n\n switch (CCTK_VarTypeI(var_to)) {\n case CCTK_VARIABLE_REAL:\n RADIATIVE_BOUNDARY(GH->cctk_lsh, widths, CCTK_REAL);\n break;\n\n#ifdef HAVE_CCTK_REAL4\n case CCTK_VARIABLE_REAL4:\n RADIATIVE_BOUNDARY(GH->cctk_lsh, widths, CCTK_REAL4);\n break;\n#endif\n\n#ifdef HAVE_CCTK_REAL8\n case CCTK_VARIABLE_REAL8:\n RADIATIVE_BOUNDARY(GH->cctk_lsh, widths, CCTK_REAL8);\n break;\n#endif\n\n#ifdef HAVE_CCTK_REAL16\n case CCTK_VARIABLE_REAL16:\n RADIATIVE_BOUNDARY(GH->cctk_lsh, widths, CCTK_REAL16);\n break;\n#endif\n\n default:\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Unsupported variable type %d for variable '%s'\",\n CCTK_VarTypeI(var_to), CCTK_VarName(var_to));\n return (-4);\n }\n }\n\n return (0);\n}\n\n/*@@\n @routine OldApplyBndRadiative\n @date 5 May 2003\n @author David Rideout\n @desc\n The new boundary API expects a 2d-element array for the\n boundary_widths (d=dimension of grid variable), while\n the old API expects a d-element array. This function\n converts the old array to the new format.\n @enddesc\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var width_dir\n @vdesc boundary width in direction dir\n @vtype int\n @vio in\n @endvar\n @var stencil_alldirs\n @vdesc boundary widths for all directions\n @vtype const CCTK_INT [ dimension of variable(s) ]\n @vio in\n @endvar\n @var dir\n @vdesc direction to copy boundaries (0 for copying all directions)\n @vtype int\n @vio in\n @endvar\n @var var0\n @vdesc asymptotic value of function at infinity\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var speed\n @vdesc wave speed\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var first_var_to\n @vdesc index of first variable to copy boundaries to\n @vtype int\n @vio in\n @endvar\n @var first_var_from\n @vdesc index of first variable to copy boundaries from\n @vtype int\n @vio in\n @endvar\n @var num_vars\n @vdesc number of variables\n @vtype int\n @vio in\n @endvar\n\n @calls CCTK_GroupIndexFromVarI\n ApplyBndRadiative\n @returntype int\n @returndesc\n returncode from @seeroutine ApplyBndRadiative\n @endreturndesc\n@@*/\n\nstatic int OldApplyBndRadiative(const cGH *GH, int width_dir,\n const CCTK_INT *stencil_alldirs, int dir,\n CCTK_REAL var0, CCTK_REAL speed,\n int first_var_to, int first_var_from,\n int num_vars) {\n int i, dim, retval;\n CCTK_INT *boundary_widths;\n static int warned;\n\n /* Convert stencil_alldirs to new format */\n dim = CCTK_GroupDimFromVarI(first_var_to);\n boundary_widths = malloc(2 * dim * sizeof(CCTK_INT));\n for (i = 0; i < 2 * dim; ++i) {\n boundary_widths[i] = stencil_alldirs[i / 2];\n }\n\n /* Bug people for using the old interface */\n if (!warned) {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Copied older d-element array of boundary widths into the \"\n \"newer 2d-element format. Please use the new boundary \"\n \"interface to avoid this.\");\n warned = 1;\n }\n\n /* Call ApplyBnd... with new boundary width array */\n retval = ApplyBndRadiative(GH, width_dir, boundary_widths, dir, var0, speed,\n first_var_to, first_var_from, num_vars);\n\n free(boundary_widths);\n return retval;\n}\n", "Register.c": "/*@@\n @file Register.c\n @date Sat Oct 26 22:39:40 CEST 2002\n @author David Rideout\n @desc\n Register implemented boundary conditions.\n @enddesc\n @version $Header$\n@@*/\n\n#include \"cctk.h\"\n#include \"cctk_Arguments.h\"\n#include \"cctk_Parameters.h\"\n#include \"util_Table.h\"\n#include \"Boundary.h\"\n\nstatic const char *rcsid = \"$Header$\";\n\nCCTK_FILEVERSION(CactusBase_Boundary_Register_c);\n\n/********************************************************************\n ********************* Local Data Types ***********************\n ********************************************************************/\n\n/********************************************************************\n ********************* Local Routine Prototypes *********************\n ********************************************************************/\n\nvoid Boundary_RegisterBCs(CCTK_ARGUMENTS);\n\n/********************************************************************\n ***************** Aliased Routine Prototypes ***********************\n ********************************************************************/\n\n/********************************************************************\n ***************** Scheduled Routine Prototypes *********************\n ********************************************************************/\n\n/********************************************************************\n ********************* Other Routine Prototypes *********************\n ********************************************************************/\n\n/********************************************************************\n ********************* Local Data *****************************\n ********************************************************************/\n\n/********************************************************************\n ********************* Aliased Routines ***********************\n ********************************************************************/\n\n/********************************************************************\n ********************* Scheduled Routines *********************\n ********************************************************************/\n\n/*@@\n @routine Boundary_RegisterBCs\n @date Sun Nov 3 19:51:37 CET 2002\n @author David Rideout\n @desc\n Register all boundary conditions implemented by this thorn.\n @enddesc\n @calls\n @history\n @endhistory\n @var CCTK_ARGUMENTS\n @vdesc Cactus argument list\n @vtype CCTK_*\n @vio in\n @endvar\n @returntype void\n@@*/\n\nvoid Boundary_RegisterBCs(CCTK_ARGUMENTS) {\n DECLARE_CCTK_PARAMETERS;\n int err;\n\n if (register_scalar) {\n err = Boundary_RegisterPhysicalBC((CCTK_POINTER)cctkGH,\n (phys_bc_fn_ptr)&BndScalar, \"Scalar\");\n if (err) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Error %d when registering routine to handle \\\"Scalar\\\" \"\n \"boundary condition\",\n err);\n }\n }\n\n if (register_flat) {\n err = Boundary_RegisterPhysicalBC((CCTK_POINTER)cctkGH,\n (phys_bc_fn_ptr)&BndFlat, \"Flat\");\n if (err) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Error %d when registering routine to handle \\\"Flat\\\" \"\n \"boundary condition\",\n err);\n }\n }\n\n if (register_radiation) {\n err = Boundary_RegisterPhysicalBC(\n (CCTK_POINTER)cctkGH, (phys_bc_fn_ptr)&BndRadiative, \"Radiation\");\n if (err) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Error %d when registering routine to handle \\\"Radiation\\\" \"\n \"boundary condition\",\n err);\n }\n }\n\n if (register_copy) {\n err = Boundary_RegisterPhysicalBC((CCTK_POINTER)cctkGH,\n (phys_bc_fn_ptr)&BndCopy, \"Copy\");\n if (err) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Error %d when registering routine to handle \\\"Copy\\\" \"\n \"boundary condition\",\n err);\n }\n }\n\n if (register_robin) {\n err = Boundary_RegisterPhysicalBC((CCTK_POINTER)cctkGH,\n (phys_bc_fn_ptr)&BndRobin, \"Robin\");\n if (err) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Error %d when registering routine to handle \\\"Robin\\\" \"\n \"boundary condition\",\n err);\n }\n }\n\n if (register_static) {\n err = Boundary_RegisterPhysicalBC((CCTK_POINTER)cctkGH,\n (phys_bc_fn_ptr)&BndStatic, \"Static\");\n if (err) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Error %d when registering routine to handle \\\"Static\\\" \"\n \"boundary condition\",\n err);\n }\n }\n\n if (register_none) {\n err = Boundary_RegisterPhysicalBC((CCTK_POINTER)cctkGH,\n (phys_bc_fn_ptr)&BndNone, \"None\");\n if (err) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Error %d when registering routine to handle \\\"None\\\" \"\n \"boundary condition\",\n err);\n }\n }\n}\n\n/********************************************************************\n ********************* Local Routines *************************\n ********************************************************************/\n", "StaticBoundary.c": "/*@@\n @file StaticBoundary.c\n @date Sat Mar 16 15:09:00 2001\n @author Gabrielle Allen\n @desc\n Routines for applying static-boundary conditions\n @enddesc\n @version $Id$\n@@*/\n\n#include \n#include \n\n#include \"cctk.h\"\n#include \"util_Table.h\"\n#include \"util_ErrorCodes.h\"\n#include \"cctk_FortranString.h\"\n\n#include \"Boundary.h\"\n\n/* the rcs ID and its dummy function to use it */\nstatic const char *rcsid = \"$Header$\";\nCCTK_FILEVERSION(CactusBase_Boundary_StaticBoundary_c);\n\nstatic int ApplyBndStatic(const cGH *GH,\n CCTK_INT stencil_dir, const CCTK_INT *stencil_alldirs,\n int dir, CCTK_INT faces,\n int first_var, int num_vars);\nstatic int OldApplyBndStatic(const cGH *GH, int stencil_dir,\n const int *stencil_alldirs, int dir, int first_var,\n int num_vars);\n\n/********************************************************************\n ******************** External Routines ************************\n ********************************************************************/\n/*@@\n @routine BndStatic\n @date 14 Feb 2003\n @author David Rideout\n @desc\n Top level function which is registered as handling\n this boundary condition\n @enddesc\n @calls ApplyBndStatic\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var num_vars\n @vdesc number of variables passed in through var_indices[]\n @vtype CCTK_INT\n @vio in\n @endvar\n @var var_indices\n @vdesc array of variable indicies to which to apply this boundary\n condition\n @vtype CCTK_INT *\n @vio in\n @endvar\n @var faces\n @vdesc array of set of faces to which to apply the bc\n @vtype CCTK_INT\n @vio in\n @endvar\n @var widths\n @vdesc array of boundary widths for each variable\n @vtype CCTK_INT\n @vio in\n @endvar\n @var table_handles\n @vdesc array of table handles which hold extra arguments\n @vtype CCTK_INT\n @vio in\n @endvar\n @returntype CCTK_INT\n @returndesc\n return code of @seeroutine ApplyBndStatic\n -21 error reading boundary width array from table\n -22 wrong size boundary width array in table\n @endreturndesc\n@@*/\nCCTK_INT BndStatic(const cGH *GH, CCTK_INT num_vars, CCTK_INT *vars,\n CCTK_INT *faces, CCTK_INT *widths, CCTK_INT *tables) {\n int i, j, k, gi, err, gdim, max_gdim, retval;\n\n /* variables to pass to ApplyBndStatic */\n CCTK_INT *width_alldirs; /* width of boundary in all directions */\n int dir; /* direction in which to apply bc */\n\n#ifdef DEBUG\n printf(\n \"BndStatic(): got passed GH=%p, num_vars=%d, vars[0]=%d, tables[0]=%d\\n\",\n (const void *)GH, num_vars, vars[0], tables[0]);\n#endif\n\n retval = 0;\n width_alldirs = NULL;\n max_gdim = 0;\n\n /* loop through variables, j at a time */\n for (i = 0; i < num_vars; i += j) {\n /* find other adjacent vars which are selected for identical bcs */\n j = 1;\n /* Since GFs are allowed to have different staggering, the best we\n can do is find variables of the same group which are selected\n for identical bcs. If all GFs had the same staggering then we\n could groups many GFs together. */\n gi = CCTK_GroupIndexFromVarI(vars[i]);\n while (i + j < num_vars && vars[i + j] == vars[i] + j &&\n CCTK_GroupIndexFromVarI(vars[i + j]) == gi &&\n tables[i + j] == tables[i] && faces[i + j] == faces[i] &&\n widths[i + j] == widths[i]) {\n ++j;\n }\n\n dir = 0;\n\n /* Determine boundary width on all faces */\n /* allocate memory for buffer */\n gdim = CCTK_GroupDimI(gi);\n if (gdim > max_gdim) {\n width_alldirs =\n (CCTK_INT *)realloc(width_alldirs, 2 * gdim * sizeof(CCTK_INT));\n max_gdim = gdim;\n }\n\n /* fill it with values, either from table or the boundary_width\n parameter */\n if (widths[i] < 0) {\n err = Util_TableGetIntArray(tables[i], 2 * gdim, width_alldirs,\n \"BOUNDARY_WIDTH\");\n if (err < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Error %d when reading boundary width array from table \"\n \"for %s\",\n err, CCTK_FullName(vars[i]));\n return -21;\n } else if (err != 2 * gdim) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Boundary width array for %s has %d elements, but %d \"\n \"expected\",\n CCTK_FullName(vars[i]), err, 2 * gdim);\n return -22;\n }\n } else {\n for (k = 0; k < 2 * gdim; ++k) {\n width_alldirs[k] = widths[i];\n }\n }\n\n /* Apply the boundary condition */\n if ((retval = ApplyBndStatic(GH, 0, width_alldirs, dir, faces[i], vars[i],\n j)) < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"ApplyBndStatic() returned %d\", retval);\n }\n }\n#ifdef DEBUG\n printf(\"BndStatic(): returning %d\\n\", retval);\n#endif\n free(width_alldirs);\n\n return retval;\n}\n\n/* prototypes for external C routines are declared in header Boundary.h\n here only follow the fortran wrapper prototypes */\nvoid CCTK_FCALL CCTK_FNAME(BndStaticDirVI)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, const int *vi);\nvoid CCTK_FCALL CCTK_FNAME(BndStaticVI)(int *ierr, const cGH **GH,\n const int *stencil, const int *vi);\nvoid CCTK_FCALL CCTK_FNAME(BndStaticDirGI)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, const int *gi);\nvoid CCTK_FCALL CCTK_FNAME(BndStaticGI)(int *ierr, const cGH **GH,\n const int *stencil, const int *gi);\nvoid CCTK_FCALL CCTK_FNAME(BndStaticDirVN)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, ONE_FORTSTRING_ARG);\nvoid CCTK_FCALL CCTK_FNAME(BndStaticVN)(int *ierr, const cGH **GH,\n const int *stencil, ONE_FORTSTRING_ARG);\nvoid CCTK_FCALL CCTK_FNAME(BndStaticDirGN)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, ONE_FORTSTRING_ARG);\nvoid CCTK_FCALL CCTK_FNAME(BndStaticGN)(int *ierr, const cGH **GH,\n const int *stencil, ONE_FORTSTRING_ARG);\n\n/********************************************************************\n ******************** Internal Routines ************************\n ********************************************************************/\n\n/*@@\n @routine BndStaticDirVI\n @date Sat Jan 20 2001\n @author Gabrielle Allen\n @desc\n Apply static boundary routines by var index in given direction\n @enddesc\n @calls ApplyBndStatic\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to apply boundary\n @vtype int\n @vio in\n @endvar\n @var vi\n @vdesc index of variable to apply static boundaries\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndStatic
\n -1 if invalid variable indices are given\n @endreturndesc\n@@*/\nint BndStaticDirVI(const cGH *GH, int stencil_size, int dir, int vi) {\n int retval, num_vars;\n\n num_vars = CCTK_NumVars();\n if (vi >= 0 && vi < num_vars) {\n retval = ApplyBndStatic(GH, stencil_size, NULL, dir, CCTK_ALL_FACES, vi, 1);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable index %d in BndStaticDirVI\", vi);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndStaticDirVI)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, const int *vi) {\n *ierr = BndStaticDirVI(*GH, *stencil_size, *dir, *vi);\n}\n\n/*@@\n @routine BndStaticVI\n @date Thu Mar 2 11:02:10 2000\n @author Gerd Lanfermann\n @desc\n Apply static boundary routines by var index\n @enddesc\n @calls ApplyBndStatic\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int [ dimension of variable ]\n @vio in\n @endvar\n @var vi\n @vdesc index of variable to apply static boundaries to\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndStatic
\n -1 if invalid variable indices are given\n @endreturndesc\n@@*/\nint BndStaticVI(const cGH *GH, const int *stencil, int vi) {\n int retval, num_vars;\n\n num_vars = CCTK_NumVars();\n if (vi >= 0 && vi < num_vars) {\n retval = OldApplyBndStatic(GH, -1, stencil, 0, vi, 1);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable index %d in BndStaticVI\", vi);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndStaticVI)(int *ierr, const cGH **GH,\n const int *stencil, const int *vi) {\n *ierr = BndStaticVI(*GH, stencil, *vi);\n}\n\n/* ====================================================== */\n\n/*@@\n @routine BndStaticDirGI\n @date Sat Jan 20 2001\n @author Gabrielle Allen\n @desc\n Apply static boundaries by group index in given direction\n @enddesc\n @calls ApplyBndStatic\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to apply static boundaries\n @vtype int\n @vio in\n @endvar\n @var gi\n @vdesc index of group to apply static boundaries to\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndStatic
\n -1 if invalid group indices are given\n @endreturndesc\n@@*/\nint BndStaticDirGI(const cGH *GH, int stencil_size, int dir, int gi) {\n int first_vi, retval;\n\n first_vi = CCTK_FirstVarIndexI(gi);\n if (first_vi >= 0) {\n retval = ApplyBndStatic(GH, stencil_size, NULL, dir, CCTK_ALL_FACES,\n first_vi, CCTK_NumVarsInGroupI(gi));\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group indices %d in BndStaticDirGI\", gi);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndStaticDirGI)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, const int *gi) {\n *ierr = BndStaticDirGI(*GH, *stencil_size, *dir, *gi);\n}\n\n/*@@\n @routine BndStaticGI\n @date Thu Mar 2 11:07:11 2000\n @author Gerd Lanfermann\n @desc\n Apply static boundaries by group index\n @enddesc\n @calls ApplyBndStatic\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int [ dimension of group ]\n @vio in\n @endvar\n @var gi\n @vdesc index of group to apply static boundaries to\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndStatic
\n -1 if invalid group indices are given\n @endreturndesc\n@@*/\nint BndStaticGI(const cGH *GH, const int *stencil, int gi) {\n int first_vi, retval;\n\n first_vi = CCTK_FirstVarIndexI(gi);\n if (first_vi >= 0) {\n retval = OldApplyBndStatic(GH, -1, stencil, 0, first_vi,\n CCTK_NumVarsInGroupI(gi));\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group index %d in BndStaticGI\", gi);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndStaticGI)(int *ierr, const cGH **GH,\n const int *stencil, const int *gi) {\n *ierr = BndStaticGI(*GH, stencil, *gi);\n}\n\n/* ======================================================= */\n\n/*@@\n @routine BndStaticDirGN\n @date Sat Jan 20 2001\n @author Gabrielle Allen\n @desc\n Apply static boundary routines by group name in given direction\n @enddesc\n @calls BndStaticDirGI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to apply static boundaries\n @vtype int\n @vio in\n @endvar\n @var gname\n @vdesc name of group to apply static boundaries to\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndStaticDirGI
\n -1 if invalid group names are given\n @endreturndesc\n@@*/\nint BndStaticDirGN(const cGH *GH, int stencil_size, int dir,\n const char *gname) {\n int gi, num_groups, retval;\n\n gi = CCTK_GroupIndex(gname);\n num_groups = CCTK_NumGroups();\n\n if (gi >= 0 && gi < num_groups) {\n retval = BndStaticDirGI(GH, stencil_size, dir, gi);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group name '%s' in BndStaticDirGN\", gname);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndStaticDirGN)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, ONE_FORTSTRING_ARG) {\n ONE_FORTSTRING_CREATE(gname)\n *ierr = BndStaticDirGN(*GH, *stencil_size, *dir, gname);\n free(gname);\n}\n\n/*@@\n @routine BndStaticGN\n @date Thu Mar 2 11:02:10 2000\n @author Gerd Lanfermann\n @desc\n Apply static boundary routines by group name\n @enddesc\n @calls BndStaticGI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int [ dimension of group ]\n @vio in\n @endvar\n @var gname\n @vdesc name of group to apply static boundaries to\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndStaticGI
\n -1 if invalid group names are given\n @endreturndesc\n@@*/\nint BndStaticGN(const cGH *GH, const int *stencil, const char *gname) {\n int gi, num_groups, retval;\n\n gi = CCTK_GroupIndex(gname);\n num_groups = CCTK_NumGroups();\n\n if (gi >= 0 && gi < num_groups) {\n retval = BndStaticGI(GH, stencil, gi);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group name '%s' in BndStaticGN\", gname);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndStaticGN)(int *ierr, const cGH **GH,\n const int *stencil,\n ONE_FORTSTRING_ARG) {\n ONE_FORTSTRING_CREATE(gname)\n *ierr = BndStaticGN(*GH, stencil, gname);\n free(gname);\n}\n\n/* ======================================================= */\n\n/*@@\n @routine BndStaticDirVN\n @date Sat Jan 20 2001\n @author Gabrielle Allen\n @desc\n Apply static boundary routines by group name in given direction\n @enddesc\n @calls BndStaticDirVI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to apply static boundaries\n @vtype int\n @vio in\n @endvar\n @var vname\n @vdesc name of variable to apply static boundaries to\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndStaticDirVI
\n -1 if invalid variable names are given\n @endreturndesc\n@@*/\nint BndStaticDirVN(const cGH *GH, int stencil_size, int dir,\n const char *vname) {\n int vi, num_vars, retval;\n\n vi = CCTK_VarIndex(vname);\n num_vars = CCTK_NumVars();\n\n if (vi >= 0 && vi < num_vars) {\n retval = BndStaticDirVI(GH, stencil_size, dir, vi);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable name '%s' in BndStaticDirVN\", vname);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndStaticDirVN)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, ONE_FORTSTRING_ARG) {\n ONE_FORTSTRING_CREATE(vname)\n *ierr = BndStaticDirVN(*GH, *stencil_size, *dir, vname);\n free(vname);\n}\n\n/*@@\n @routine BndStaticVN\n @date Thu Mar 2 11:02:10 2000\n @author Gerd Lanfermann\n @desc\n Apply static boundary routines by variable name\n @enddesc\n @calls BndStaticVI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int [ dimension of variable ]\n @vio in\n @endvar\n @var vname\n @vdesc name of variable to apply static boundaries to\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndStaticVI
\n -1 if invalid variable names are given\n @endreturndesc\n@@*/\nint BndStaticVN(const cGH *GH, const int *stencil, const char *vname) {\n int vi, num_vars, retval;\n\n vi = CCTK_VarIndex(vname);\n num_vars = CCTK_NumVars();\n\n if (vi >= 0 && vi < num_vars) {\n retval = BndStaticVI(GH, stencil, vi);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable name '%s' in BndStaticVN\", vname);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndStaticVN)(int *ierr, const cGH **GH,\n const int *stencil,\n ONE_FORTSTRING_ARG) {\n ONE_FORTSTRING_CREATE(vname)\n *ierr = BndStaticVN(*GH, stencil, vname);\n free(vname);\n}\n\n/********************************************************************\n ********************* Local Routines *************************\n ********************************************************************/\n\n/* maximum dimension we can deal with */\n#define MAXDIM 3\n\n/* macro to compute the linear index of a 3D point */\n#define INDEX_3D(ash, i, j, k) ((i) + (ash)[0] * ((j) + (ash)[1] * (k)))\n\n/*@@\n @routine STATIC_BOUNDARY\n @date Sat 20 Jan 2001\n @author Thomas Radke\n @desc\n Macro to apply static boundary conditions to a variable\n Currently it is limited up to 3D variables only.\n @enddesc\n\n @var doBC\n @vdesc flag telling whether to apply boundary conditions or not\n @vtype int\n @vio in\n @endvar\n @var iend, jend, kend\n @vdesc upper ranges for the loopers\n @vtype int\n @vio in\n @endvar\n @var ii, jj, kk\n @vdesc indices of the current grid point\n @vtype int\n @vio in\n @endvar\n@@*/\n#define STATIC_BOUNDARY(doBC, iend, jend, kend, ii, jj, kk) \\\n { \\\n if (doBC) { \\\n for (k = 0; k < kend; k++) { \\\n for (j = 0; j < jend; j++) { \\\n for (i = 0; i < iend; i++) { \\\n int _index; \\\n \\\n _index = INDEX_3D(ash, ii, jj, kk) * vtypesize; \\\n memcpy((char *)GH->data[var][timelvl_to] + _index, \\\n (char *)GH->data[var][timelvl_from] + _index, vtypesize); \\\n } \\\n } \\\n } \\\n } \\\n }\n\n/*@@\n @routine ApplyBndStatic\n @date Thu Mar 2 11:02:10 2000\n @author Gerd Lanfermann\n @desc\n Apply static boundary conditions to a group of grid functions\n given by their indices\n This routine is called by the various BndStaticXXX wrappers.\n\n Although it is currently limited to handle 1D, 2D, or 3D\n variables only it can easily be extended for higher dimensions\n by adapting the appropriate macros.\n @enddesc\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var width_dir\n @vdesc boundary width in direction dir\n @vtype CCTK_INT\n @vio in\n @endvar\n @var in_widths\n @vdesc boundary widths for all directions\n @vtype CCTK_INT [ dimension of variable(s) ]\n @vio in\n @endvar\n @var dir\n @vdesc direction for static boundaries (0 for copying all directions)\n @vtype int\n @vio in\n @endvar\n @var first_var\n @vdesc index of first variable to apply static boundaries to\n @vtype int\n @vio in\n @endvar\n @var num_vars\n @vdesc number of variables\n @vtype int\n @vio in\n @endvar\n\n @calls CCTK_GroupIndexFromVarI\n CCTK_GroupDimI\n CCTK_VarTypeI\n CCTK_GroupStaggerDirArrayGI\n STATIC_BOUNDARY\n @history\n @hdate Sat 20 Jan 2001\n @hauthor Thomas Radke\n @hdesc Merged separate routines for 1D, 2D, and 3D\n into a single generic routine\n @endhistory\n\n @returntype int\n @returndesc\n 0 for success\n -1 if dimension is not supported\n -2 if direction parameter is invalid\n -3 if stencil width array parameter is NULL\n -4 if there is only one timelevel\n @endreturndesc\n@@*/\nstatic int ApplyBndStatic(const cGH *GH,\n CCTK_INT width_dir, const CCTK_INT *in_widths,\n int dir, CCTK_INT faces,\n int first_var, int num_vars) {\n int ierr;\n int i, j, k;\n int timelvl_to, timelvl_from;\n int gindex, gdim;\n int var, vtypesize;\n int doBC[2 * MAXDIM], ash[MAXDIM], lsh[MAXDIM];\n CCTK_INT widths[2 * MAXDIM];\n CCTK_INT symtable;\n CCTK_INT symbnd[2 * MAXDIM];\n CCTK_INT is_physical[2 * MAXDIM];\n\n /* Only apply boundary condition if more than one timelevel */\n if (CCTK_DeclaredTimeLevelsVI(first_var) <= 1) {\n return (-4);\n }\n\n /* get the group index of the target variable */\n gindex = CCTK_GroupIndexFromVarI(first_var);\n\n /* get the number of dimensions and the size of the variable's type */\n gdim = CCTK_GroupDimI(gindex);\n vtypesize = CCTK_VarTypeSize(CCTK_VarTypeI(first_var));\n\n /* make sure we can deal with this number of dimensions */\n if (gdim > MAXDIM) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Variable dimension of %d not supported\", gdim);\n return (-1);\n }\n\n /* check the direction parameter */\n if (abs(dir) > gdim) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"ApplyBndStatic: direction %d greater than dimension %d\", dir,\n gdim);\n return (-2);\n }\n\n /* set up boundary width array */\n if (dir) {\n widths[2 * (abs(dir) - 1)] = width_dir;\n widths[2 * (abs(dir) - 1) + 1] = width_dir;\n } else if (in_widths) {\n memcpy(widths, in_widths, 2 * gdim * sizeof *widths);\n } else {\n CCTK_WARN(1, \"ApplyBndStatic: NULL pointer passed for boundary width \"\n \"array\");\n return (-3);\n }\n\n /* sanity check on width of boundary, */\n BndSanityCheckWidths(GH, first_var, gdim, widths, \"Static\");\n\n /* initialize arrays for variables with less dimensions than MAXDIM\n so that we can use the INDEX_3D macro later on */\n for (i = gdim; i < MAXDIM; i++) {\n ash[i] = 1;\n lsh[i] = 1;\n }\n\n /* get the current timelevel */\n timelvl_to = 0;\n timelvl_from = 1;\n\n /* see if we have a physical boundary */\n symtable = SymmetryTableHandleForGrid(GH);\n if (symtable < 0)\n CCTK_WARN(0, \"internal error\");\n ierr = Util_TableGetIntArray(symtable, 2 * gdim, symbnd, \"symmetry_handle\");\n if (ierr != 2 * gdim)\n CCTK_WARN(0, \"internal error\");\n for (i = 0; i < 2 * gdim; i++) {\n is_physical[i] = symbnd[i] < 0;\n }\n\n /* now loop over all variables */\n for (var = first_var; var < first_var + num_vars; var++) {\n if (CCTK_ActiveTimeLevelsVI(GH, var) < 2) {\n CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Static Boundary condition needs at least two timelevels \"\n \"active, but %s only has %d.\",\n CCTK_FullName(var), CCTK_ActiveTimeLevelsVI(GH, var));\n }\n /* Apply condition if:\n + boundary is an outer boundary\n + have enough grid points\n */\n for (i = 0; i < 2 * gdim; i++) {\n doBC[i] = is_physical[i] && (faces == CCTK_ALL_FACES || (faces & (1<cctk_ash[i];\n lsh[i] = GH->cctk_lsh[i];\n doBC[i * 2] &= GH->cctk_lsh[i] > widths[i * 2] && GH->cctk_bbox[i * 2];\n doBC[i * 2 + 1] &=\n GH->cctk_lsh[i] > widths[i * 2 + 1] && GH->cctk_bbox[i * 2 + 1];\n if (dir != 0) {\n doBC[i * 2] &= (dir < 0 && (i + 1 == abs(dir)));\n doBC[i * 2 + 1] &= (dir > 0 && (i + 1 == abs(dir)));\n }\n }\n\n /* now copy the boundaries face by face */\n if (gdim > 0) {\n /* lower x */\n STATIC_BOUNDARY(doBC[0], widths[0], lsh[1], lsh[2], i, j, k);\n /* upper x */\n STATIC_BOUNDARY(doBC[1], widths[1], lsh[1], lsh[2], lsh[0] - i - 1, j, k);\n }\n if (gdim > 1) {\n /* lower y */\n STATIC_BOUNDARY(doBC[2], lsh[0], widths[2], lsh[2], i, j, k);\n /* upper y */\n STATIC_BOUNDARY(doBC[3], lsh[0], widths[3], lsh[2], i, lsh[1] - j - 1, k);\n }\n if (gdim > 2) {\n /* lower z */\n STATIC_BOUNDARY(doBC[4], lsh[0], lsh[1], widths[4], i, j, k);\n /* upper z */\n STATIC_BOUNDARY(doBC[5], lsh[0], lsh[1], widths[5], i, j, lsh[2] - k - 1);\n }\n }\n\n return (0);\n}\n\n/*@@\n @routine OldApplyBndStatic\n @date 5 May 2003\n @author David Rideout\n @desc\n The new boundary API expects a 2d-element array for the\n boundary_widths (d=dimension of grid variable), while\n the old API expects a d-element array. This function\n converts the old array to the new format.\n @enddesc\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_dir\n @vdesc boundary width in direction dir\n @vtype int\n @vio in\n @endvar\n @var stencil_alldirs\n @vdesc boundary widths for all directions\n @vtype int [ dimension of variable(s) ]\n @vio in\n @endvar\n @var dir\n @vdesc direction for static boundaries (0 for copying all directions)\n @vtype int\n @vio in\n @endvar\n @var first_var\n @vdesc index of first variable to apply static boundaries to\n @vtype int\n @vio in\n @endvar\n @var num_vars\n @vdesc number of variables\n @vtype int\n @vio in\n @endvar\n\n @calls CCTK_GroupIndexFromVarI\n ApplyBndScalar\n @returntype int\n @returndesc\n returncode from @seeroutine ApplyBndScalar\n @endreturndesc\n@@*/\n\nstatic int OldApplyBndStatic(const cGH *GH, int stencil_dir,\n const int *stencil_alldirs, int dir, int first_var,\n int num_vars) {\n int retval, dim, i;\n CCTK_INT *boundary_widths;\n static int warned;\n\n /* Convert stencil_alldirs to new format */\n dim = CCTK_GroupDimFromVarI(first_var);\n boundary_widths = malloc(2 * dim * sizeof(CCTK_INT));\n for (i = 0; i < 2 * dim; ++i) {\n boundary_widths[i] = stencil_alldirs[i / 2];\n }\n\n /* Bug people for using the old interface */\n if (!warned) {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Copied older d-element array of boundary widths into the \"\n \"newer 2d-element format. Please use the new boundary \"\n \"interface to avoid this.\");\n warned = 1;\n }\n\n /* Call ApplyBnd... with new boundary width array */\n retval = ApplyBndStatic(GH, stencil_dir, boundary_widths, dir, CCTK_ALL_FACES,\n first_var, num_vars);\n\n free(boundary_widths);\n return retval;\n}\n", "NoneBoundary.c": "/*@@\n @file NoneBoundary.c\n @date Sat Jan 4 05:43:35 CET 2003\n @author David Rideout\n @desc\n Implements 'no boundary condition'. This can be used to\n inform the Boundary thorn that this variable should have\n boundary conditions applied to it, but then not actually\n apply any local physical boundary condition. This is\n useful e.g. if the physical boundary is being updated in\n some other manner, but the symmetry boundaries should be\n updated normally.\n\n BndNone is also used as a dummy local physical boundary\n condition, when the true physical bc is non-local.\n @enddesc\n @history\n @hdate\n @hauthor\n @hdesc\n @endhistory\n @version $Header$\n@@*/\n\n#include \"cctk.h\"\n#include \"Boundary.h\"\n\n/* the rcs ID and its dummy function to use it */\nstatic const char *rcsid = \"$Header$\";\nCCTK_FILEVERSION(CactusBase_Boundary_NoneBoundary_c);\n\n/********************************************************************\n ******************** External Routines ************************\n ********************************************************************/\n\n/*@@\n @routine BndNone\n @date 4 Jan 2003\n @author David Rideout\n @desc\n Function which handles 'None' boundary condition\n @enddesc\n @calls\n @history\n @endhistory\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var num_vars\n @vdesc number of variables passed in through var_indices[]\n @vtype CCTK_INT\n @vio in\n @endvar\n @var var_indices\n @vdesc array of variable indicies to which to apply this boundary\n condition\n @vtype CCTK_INT *\n @vio in\n @endvar\n @var faces\n @vdesc array of set of faces to which to apply the bc\n @vtype CCTK_INT\n @vio in\n @endvar\n @var widths\n @vdesc array of boundary widths for each variable\n @vtype CCTK_INT\n @vio in\n @endvar\n @var table_handles\n @vdesc array of table handles which hold extra arguments\n @vtype CCTK_INT\n @vio in\n @endvar\n @returntype CCTK_INT\n @returndesc\n 0 success\n @endreturndesc\n@@*/\n\nCCTK_INT BndNone(const cGH *GH, CCTK_INT num_vars, CCTK_INT *var_indices,\n CCTK_INT *faces, CCTK_INT *widths, CCTK_INT *table_handles) {\n#ifdef DEBUG\n printf(\"BndNone(): got passed GH=%p, num_vars=%d, var_indices[0]=%d, \"\n \"table_handles[0]=%d\\n\",\n (const void *)GH, num_vars, var_indices[0], table_handles[0]);\n#endif\n\n /* Ignore all input arguments */\n GH = GH;\n num_vars = num_vars;\n var_indices = var_indices;\n faces = faces;\n widths = widths;\n table_handles = table_handles;\n\n return 0;\n}\n", "CopyBoundary.c": "/*@@\n @file CopyBoundary.c\n @date Mon Mar 15 15:09:00 1999\n @author Gerd Lanfermann, Gabrielle Allen\n @desc\n Routines for applying copying-boundary conditions\n @enddesc\n @history\n @hdate Sun 25 Feb 2001\n @hauthor Thomas Radke\n @hdesc BC routines generalized for applying to arbitrary CCTK data types\n @endhistory\n @version $Id$\n@@*/\n\n#include \n#include \n\n#include \"cctk.h\"\n#include \"util_Table.h\"\n#include \"util_ErrorCodes.h\"\n#include \"cctk_FortranString.h\"\n\n#include \"Boundary.h\"\n\n/* the rcs ID and its dummy function to use it */\nstatic const char *rcsid = \"$Header$\";\nCCTK_FILEVERSION(CactusBase_Boundary_CopyBoundary_c);\n\nstatic int ApplyBndCopy(const cGH *GH,\n CCTK_INT width_dir, const CCTK_INT *in_widths,\n int dir, CCTK_INT faces,\n int first_var_to, int first_var_from, int num_vars);\n\n/********************************************************************\n ******************** External Routines ************************\n ********************************************************************/\n/*@@\n @routine BndCopy\n @date 13 Feb 2003\n @author David Rideout\n @desc\n Top level function which is registered as handling\n the Copy boundary condition\n @enddesc\n @calls ApplyBndCopy\n CCTK_GroupDimFromVarI\n Util_TableGetIntArray\n Util_TableQueryValueInfo\n CCTK_VWarn\n Util_TableGetString\n CCTK_VarIndex\n Util_TableGetInt\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var num_vars\n @vdesc number of variables passed in through var_indices[]\n @vtype CCTK_INT\n @vio in\n @endvar\n @var var_indices\n @vdesc array of variable indicies to which to apply this boundary\n condition\n @vtype CCTK_INT *\n @vio in\n @endvar\n @var faces\n @vdesc array of set of faces to which to apply the bc\n @vtype CCTK_INT\n @vio in\n @endvar\n @var widths\n @vdesc array of boundary widths for each variable\n @vtype CCTK_INT\n @vio in\n @endvar\n @var table_handles\n @vdesc array of table handles which hold extra arguments\n @vtype CCTK_INT\n @vio in\n @endvar\n @returntype CCTK_INT\n @returndesc\n return code of @seeroutine ApplyBndCopy\n -11 invalid table handle\n -12 no \"COPY_FROM\" key in table\n -21 error reading boundary width array from table\n -22 wrong size boundary width array in table\n @endreturndesc\n@@*/\nCCTK_INT BndCopy(const cGH *GH, CCTK_INT num_vars, CCTK_INT *vars,\n CCTK_INT *faces, CCTK_INT *widths, CCTK_INT *tables) {\n int i, j, k, gi, gdim, max_gdim, err, retval;\n CCTK_INT value_type, value_size;\n char *copy_from_name;\n\n /* variables to pass to ApplyBndCopy */\n CCTK_INT *width_alldirs; /* width of boundary on each face */\n int dir; /* direction in which to apply bc */\n CCTK_INT\n copy_from; /* variable (index) from which to copy the boundary data */\n\n retval = 0;\n width_alldirs = NULL;\n max_gdim = 0;\n\n /* loop through variables, j at a time */\n for (i = 0; i < num_vars; i += j) {\n /* find other adjacent vars which are selected for identical bcs */\n j = 1;\n /* Since GFs are allowed to have different staggering, the best we\n can do is find variables of the same group which are selected\n for identical bcs. If all GFs had the same staggering then we\n could groups many GFs together. */\n gi = CCTK_GroupIndexFromVarI(vars[i]);\n while (i + j < num_vars && vars[i + j] == vars[i] + j &&\n CCTK_GroupIndexFromVarI(vars[i + j]) == gi &&\n tables[i + j] == tables[i] && faces[i + j] == faces[i] &&\n widths[i + j] == widths[i]) {\n ++j;\n }\n\n dir = 0; /* apply bc to all faces */\n\n /* Look on table for copy-from variable */\n err = Util_TableQueryValueInfo(tables[i], &value_type, &value_size,\n \"COPY_FROM\");\n if (err == UTIL_ERROR_BAD_HANDLE) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid table handle passed for Copy boundary \"\n \"conditions for %s. Name or index of variable to copy from \"\n \"must be provided via key \\\"COPY_FROM\\\". Aborting.\",\n CCTK_VarName(vars[i]));\n return -11;\n } else if (err == 1) {\n if (value_type == CCTK_VARIABLE_STRING) {\n copy_from_name = malloc(value_size * sizeof(char));\n Util_TableGetString(tables[i], value_size, copy_from_name, \"COPY_FROM\");\n copy_from = CCTK_VarIndex(copy_from_name);\n free(copy_from_name);\n } else if (value_type == CCTK_VARIABLE_INT) {\n Util_TableGetInt(tables[i], ©_from, \"COPY_FROM\");\n } else {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid data type for key \\\"COPY_FROM\\\" \"\n \"Please use CCTK_STRING for the variable name, \"\n \"or CCTK_INT for the variable index.\");\n }\n } else {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"No key \\\"COPY_FROM\\\" provided in table. Please enter the \"\n \"name or index of variable to copy from into the table \"\n \"under this key. Aborting.\");\n return -12;\n }\n\n /* Determine boundary width on all faces */\n /* (re-)allocate memory for buffer */\n gdim = CCTK_GroupDimI(gi);\n if (gdim > max_gdim) {\n width_alldirs =\n (CCTK_INT *)realloc(width_alldirs, 2 * gdim * sizeof(CCTK_INT));\n max_gdim = gdim;\n }\n\n /* fill it with values, either from table or the boundary_width\n parameter */\n if (widths[i] < 0) {\n err = Util_TableGetIntArray(tables[i], 2 * gdim, width_alldirs,\n \"BOUNDARY_WIDTH\");\n if (err < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Error %d when reading boundary width array from table \"\n \"for %s\",\n err, CCTK_VarName(vars[i]));\n return -21;\n } else if (err != 2 * gdim) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Boundary width array for %s has %d elements, but %d \"\n \"expected\",\n CCTK_VarName(vars[i]), err, 2 * gdim);\n return -22;\n }\n } else {\n for (k = 0; k < 2 * gdim; ++k) {\n width_alldirs[k] = widths[i];\n }\n }\n\n /* Apply the boundary condition */\n if (!retval &&\n (retval = ApplyBndCopy(GH, 0, width_alldirs, dir, vars[i], faces[i],\n copy_from, j)) < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"ApplyBndCopy() returned %d\", retval);\n }\n }\n free(width_alldirs);\n\n return retval;\n}\n\n/* prototypes for external C routines are declared in header Boundary.h\n here only follow the fortran wrapper prototypes */\nvoid CCTK_FCALL CCTK_FNAME(BndCopyDirVI)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, const int *vi_to,\n const int *vi_from);\nvoid CCTK_FCALL CCTK_FNAME(BndCopyVI)(int *ierr, const cGH **GH,\n const int *stencil, const int *vi_to,\n const int *vi_from);\nvoid CCTK_FCALL CCTK_FNAME(BndCopyDirGI)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, const int *gi_to,\n const int *gi_from);\nvoid CCTK_FCALL CCTK_FNAME(BndCopyGI)(int *ierr, const cGH **GH,\n const int *stencil, const int *gi_to,\n const int *gi_from);\nvoid CCTK_FCALL CCTK_FNAME(BndCopyDirVN)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, TWO_FORTSTRING_ARG);\nvoid CCTK_FCALL CCTK_FNAME(BndCopyVN)(int *ierr, const cGH **GH,\n const int *stencil, TWO_FORTSTRING_ARG);\nvoid CCTK_FCALL CCTK_FNAME(BndCopyDirGN)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, TWO_FORTSTRING_ARG);\nvoid CCTK_FCALL CCTK_FNAME(BndCopyGN)(int *ierr, const cGH **GH,\n const int *stencil, TWO_FORTSTRING_ARG);\n\n/********************************************************************\n ******************** Internal Routines ************************\n ********************************************************************/\n\n/*@@\n @routine BndCopyDirVI\n @date Sat Jan 20 2001\n @author Gabrielle Allen\n @desc\n Apply copy boundary routines by var index in given direction\n @enddesc\n @calls ApplyBndCopy\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to copy\n @vtype int\n @vio in\n @endvar\n @var vi_to\n @vdesc index of variable to copy boundaries to\n @vtype int\n @vio in\n @endvar\n @var vi_from\n @vdesc index of variable to copy boundaries from\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndCopy
\n -1 if invalid variable indices are given\n @endreturndesc\n@@*/\nint BndCopyDirVI(const cGH *GH, int stencil_size, int dir, int vi_to,\n int vi_from) {\n int retval, num_vars;\n\n num_vars = CCTK_NumVars();\n if (vi_to >= 0 && vi_to < num_vars && vi_from >= 0 && vi_from < num_vars) {\n retval = ApplyBndCopy(GH, stencil_size, NULL, dir, CCTK_ALL_FACES, vi_to,\n vi_from, 1);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable indices %d and/or %d in BndCopyDirVI\", vi_to,\n vi_from);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndCopyDirVI)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, const int *vi_to,\n const int *vi_from) {\n *ierr = BndCopyDirVI(*GH, *stencil_size, *dir, *vi_to, *vi_from);\n}\n\n/*@@\n @routine BndCopyVI\n @date Thu Mar 2 11:02:10 2000\n @author Gerd Lanfermann\n @desc\n Apply copy boundary routines by var index\n @enddesc\n @calls ApplyBndCopy\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int [ dimension of variable ]\n @vio in\n @endvar\n @var vi_to\n @vdesc index of variable to copy boundaries to\n @vtype int\n @vio in\n @endvar\n @var vi_from\n @vdesc index of variable to copy boundaries from\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndCopy
\n -1 if invalid variable indices are given\n @endreturndesc\n@@*/\nint BndCopyVI(const cGH *GH, const int *stencil, int vi_to, int vi_from) {\n int retval, num_vars, dim, i;\n CCTK_INT *boundary_widths; /* boundary widths as expected by ApplyBndCopy */\n\n /* Set up boundary_widths array */\n dim = CCTK_GroupDimFromVarI(vi_to);\n boundary_widths = malloc(2 * dim * sizeof(CCTK_INT));\n for (i = 0; i < 2 * dim; i += 2) {\n boundary_widths[i] = stencil[i / 2];\n }\n\n num_vars = CCTK_NumVars();\n if (vi_to >= 0 && vi_to < num_vars && vi_from >= 0 && vi_from < num_vars) {\n retval = ApplyBndCopy(GH, -1, boundary_widths, 0, CCTK_ALL_FACES, vi_to,\n vi_from, 1);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable indices %d and/or %d in BndCopyVI\", vi_to,\n vi_from);\n retval = -1;\n }\n\n free(boundary_widths);\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndCopyVI)(int *ierr, const cGH **GH,\n const int *stencil, const int *vi_to,\n const int *vi_from) {\n *ierr = BndCopyVI(*GH, stencil, *vi_to, *vi_from);\n}\n\n/* ====================================================== */\n\n/*@@\n @routine BndCopyDirGI\n @date Sat Jan 20 2001\n @author Gabrielle Allen\n @desc\n Apply copy boundaries by group index in given direction\n @enddesc\n @calls ApplyBndCopy\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to copy boundaries\n @vtype int\n @vio in\n @endvar\n @var gi_to\n @vdesc index of group to copy boundaries to\n @vtype int\n @vio in\n @endvar\n @var gi_from\n @vdesc index of group to copy boundaries from\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndCopy
\n -1 if invalid group indices are given\n @endreturndesc\n@@*/\nint BndCopyDirGI(const cGH *GH, int stencil_size, int dir, int gi_to,\n int gi_from) {\n int first_vi_to, first_vi_from, retval;\n\n first_vi_to = CCTK_FirstVarIndexI(gi_to);\n first_vi_from = CCTK_FirstVarIndexI(gi_from);\n if (first_vi_to >= 0 && first_vi_from >= 0) {\n retval = ApplyBndCopy(GH, stencil_size, NULL, dir, CCTK_ALL_FACES,\n first_vi_to, first_vi_from,\n CCTK_NumVarsInGroupI(gi_to));\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group indices %d and/or %d in BndCopyDirGI\", gi_to,\n gi_from);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndCopyDirGI)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, const int *gi_to,\n const int *gi_from) {\n *ierr = BndCopyDirGI(*GH, *stencil_size, *dir, *gi_to, *gi_from);\n}\n\n/*@@\n @routine BndCopyGI\n @date Thu Mar 2 11:07:11 2000\n @author Gerd Lanfermann\n @desc\n Apply copy boundaries by group index\n @enddesc\n @calls ApplyBndCopy\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int [ dimension of group ]\n @vio in\n @endvar\n @var gi_to\n @vdesc index of group to copy boundaries to\n @vtype int\n @vio in\n @endvar\n @var gi_from\n @vdesc index of group to copy boundaries from\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndCopy
\n -1 if invalid group indices are given\n @endreturndesc\n@@*/\nint BndCopyGI(const cGH *GH, const int *stencil, int gi_to, int gi_from) {\n int first_vi_to, first_vi_from, retval;\n int i, dim;\n CCTK_INT *boundary_widths;\n\n /* Set up boundary_widths array */\n dim = CCTK_GroupDimI(gi_to);\n boundary_widths = malloc(2 * dim * sizeof(CCTK_INT));\n for (i = 0; i < 2 * dim; i += 2) {\n boundary_widths[i] = stencil[i / 2];\n }\n\n first_vi_to = CCTK_FirstVarIndexI(gi_to);\n first_vi_from = CCTK_FirstVarIndexI(gi_from);\n if (first_vi_to >= 0 && first_vi_from >= 0) {\n retval = ApplyBndCopy(GH, -1, boundary_widths, 0, CCTK_ALL_FACES,\n first_vi_to, first_vi_from,\n CCTK_NumVarsInGroupI(gi_to));\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group indices %d and/or %d in BndCopyGI\", gi_to,\n gi_from);\n retval = -1;\n }\n\n free(boundary_widths);\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndCopyGI)(int *ierr, const cGH **GH,\n const int *stencil, const int *gi_to,\n const int *gi_from) {\n *ierr = BndCopyGI(*GH, stencil, *gi_to, *gi_from);\n}\n\n/* ======================================================= */\n\n/*@@\n @routine BndCopyDirGN\n @date Sat Jan 20 2001\n @author Gabrielle Allen\n @desc\n Apply copy boundary routines by group name in given direction\n @enddesc\n @calls BndCopyDirGI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to copy boundaries\n @vtype int\n @vio in\n @endvar\n @var gname_to\n @vdesc name of group to copy boundaries to\n @vtype const char *\n @vio in\n @endvar\n @var gname_from\n @vdesc name of group to copy boundaries from\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndCopyDirGI
\n -1 if invalid group names are given\n @endreturndesc\n@@*/\nint BndCopyDirGN(const cGH *GH, int stencil_size, int dir, const char *gname_to,\n const char *gname_from) {\n int gi_to, gi_from, num_groups, retval;\n\n gi_to = CCTK_GroupIndex(gname_to);\n gi_from = CCTK_GroupIndex(gname_from);\n num_groups = CCTK_NumGroups();\n\n if (gi_to >= 0 && gi_to < num_groups && gi_from >= 0 &&\n gi_from < num_groups) {\n retval = BndCopyDirGI(GH, stencil_size, dir, gi_to, gi_from);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group names '%s' and/or '%s' in BndCopyDirGN\", gname_to,\n gname_from);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndCopyDirGN)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, TWO_FORTSTRING_ARG) {\n TWO_FORTSTRINGS_CREATE(gname_to, gname_from)\n *ierr = BndCopyDirGN(*GH, *stencil_size, *dir, gname_to, gname_from);\n free(gname_to);\n free(gname_from);\n}\n\n/*@@\n @routine BndCopyGN\n @date Thu Mar 2 11:02:10 2000\n @author Gerd Lanfermann\n @desc\n Apply copy boundary routines by group name\n @enddesc\n @calls BndCopyGI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int [ dimension of group ]\n @vio in\n @endvar\n @var gname_to\n @vdesc name of group to copy boundaries to\n @vtype const char *\n @vio in\n @endvar\n @var gname_from\n @vdesc name of group to copy boundaries from\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndCopyGI
\n -1 if invalid group names are given\n @endreturndesc\n@@*/\nint BndCopyGN(const cGH *GH, const int *stencil, const char *gname_to,\n const char *gname_from) {\n int gi_to, gi_from, num_groups, retval;\n int i, dim, *boundary_widths;\n\n gi_to = CCTK_GroupIndex(gname_to);\n gi_from = CCTK_GroupIndex(gname_from);\n num_groups = CCTK_NumGroups();\n\n /* Set up boundary_widths array */\n dim = CCTK_GroupDimI(gi_to);\n boundary_widths = malloc(2 * dim * sizeof(int));\n for (i = 0; i < 2 * dim; i += 2) {\n boundary_widths[i] = stencil[i / 2];\n }\n\n if (gi_to >= 0 && gi_to < num_groups && gi_from >= 0 &&\n gi_from < num_groups) {\n retval = BndCopyGI(GH, boundary_widths, gi_to, gi_from);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group names '%s' and/or '%s' in BndCopyGN\", gname_to,\n gname_from);\n retval = -1;\n }\n\n free(boundary_widths);\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndCopyGN)(int *ierr, const cGH **GH,\n const int *stencil, TWO_FORTSTRING_ARG) {\n TWO_FORTSTRING_CREATE(gname_to, gname_from)\n *ierr = BndCopyGN(*GH, stencil, gname_to, gname_from);\n free(gname_to);\n free(gname_from);\n}\n\n/* ======================================================= */\n\n/*@@\n @routine BndCopyDirVN\n @date Sat Jan 20 2001\n @author Gabrielle Allen\n @desc\n Apply copy boundary routines by group name in given direction\n @enddesc\n @calls BndCopyDirVI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to copy boundaries\n @vtype int\n @vio in\n @endvar\n @var vname_to\n @vdesc name of variable to copy boundaries to\n @vtype const char *\n @vio in\n @endvar\n @var vname_from\n @vdesc name of variable to copy boundaries from\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndCopyDirVI
\n -1 if invalid variable names are given\n @endreturndesc\n@@*/\nint BndCopyDirVN(const cGH *GH, int stencil_size, int dir, const char *vname_to,\n const char *vname_from) {\n int vi_to, vi_from, num_vars, retval;\n\n vi_to = CCTK_VarIndex(vname_to);\n vi_from = CCTK_VarIndex(vname_from);\n num_vars = CCTK_NumVars();\n\n if (vi_to >= 0 && vi_to < num_vars && vi_from >= 0 && vi_from < num_vars) {\n retval = BndCopyDirVI(GH, stencil_size, dir, vi_to, vi_from);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable names '%s' and/or '%s' in BndCopyDirVN\",\n vname_to, vname_from);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndCopyDirVN)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, TWO_FORTSTRING_ARG) {\n TWO_FORTSTRINGS_CREATE(vname_to, vname_from)\n *ierr = BndCopyDirVN(*GH, *stencil_size, *dir, vname_to, vname_from);\n free(vname_to);\n free(vname_from);\n}\n\n/*@@\n @routine BndCopyVN\n @date Thu Mar 2 11:02:10 2000\n @author Gerd Lanfermann\n @desc\n Apply copy boundary routines by variable name\n @enddesc\n @calls BndCopyVI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int [ dimension of variable ]\n @vio in\n @endvar\n @var vname_to\n @vdesc name of variable to copy boundaries to\n @vtype const char *\n @vio in\n @endvar\n @var vname_from\n @vdesc name of variable to copy boundaries from\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndCopyVI
\n -1 if invalid variable names are given\n @endreturndesc\n@@*/\nint BndCopyVN(const cGH *GH, const int *stencil, const char *vname_to,\n const char *vname_from) {\n int vi_to, vi_from, num_vars, retval;\n int i, dim;\n int *boundary_widths;\n\n vi_to = CCTK_VarIndex(vname_to);\n vi_from = CCTK_VarIndex(vname_from);\n num_vars = CCTK_NumVars();\n\n /* Set up boundary_widths array */\n dim = CCTK_GroupDimFromVarI(vi_to);\n boundary_widths = malloc(2 * dim * sizeof(int));\n for (i = 0; i < 2 * dim; i += 2) {\n boundary_widths[i] = stencil[i / 2];\n }\n\n if (vi_to >= 0 && vi_to < num_vars && vi_from >= 0 && vi_from < num_vars) {\n retval = BndCopyVI(GH, boundary_widths, vi_to, vi_from);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable names '%s' and/or '%s' in BndCopyVN\", vname_to,\n vname_from);\n retval = -1;\n }\n\n free(boundary_widths);\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndCopyVN)(int *ierr, const cGH **GH,\n const int *stencil,\n TWO_FORTSTRINGS_ARGS) {\n TWO_FORTSTRINGS_CREATE(vname_to, vname_from)\n *ierr = BndCopyVN(*GH, stencil, vname_to, vname_from);\n free(vname_to);\n free(vname_from);\n}\n\n/********************************************************************\n ********************* Local Routines *************************\n ********************************************************************/\n\n/* maximum dimension we can deal with */\n#define MAXDIM 3\n\n/* macro to compute the linear index of a 3D point */\n#define INDEX_3D(ash, i, j, k) ((i) + (ash)[0] * ((j) + (ash)[1] * (k)))\n\n/*@@\n @routine COPY_BOUNDARY\n @date Sat 20 Jan 2001\n @author Thomas Radke\n @desc\n Macro to apply copy boundary conditions to a variable\n Currently it is limited up to 3D variables only.\n @enddesc\n\n @var doBC\n @vdesc flag telling whether to apply boundary conditions or not\n @vtype int\n @vio in\n @endvar\n @var iend, jend, kend\n @vdesc upper ranges for the loopers\n @vtype int\n @vio in\n @endvar\n @var ii, jj, kk\n @vdesc indices of the current grid point\n @vtype int\n @vio in\n @endvar\n@@*/\n#define COPY_BOUNDARY(doBC, iend, jend, kend, ii, jj, kk) \\\n { \\\n if (doBC) { \\\n for (k = 0; k < kend; k++) { \\\n for (j = 0; j < jend; j++) { \\\n for (i = 0; i < iend; i++) { \\\n int _index; \\\n \\\n _index = INDEX_3D(ash, ii, jj, kk) * vtypesize; \\\n memcpy((char *)GH->data[var_to][timelvl_to] + _index, \\\n (char *)GH->data[var_from][timelvl_from] + _index, \\\n vtypesize); \\\n } \\\n } \\\n } \\\n } \\\n }\n\n/*@@\n @routine ApplyBndCopy\n @date Thu Mar 2 11:02:10 2000\n @author Gerd Lanfermann\n @desc\n Apply copy boundary conditions to a group of grid functions\n given by their indices\n This routine is called by the various BndCopyXXX wrappers.\n\n Although it is currently limited to handle 1D, 2D, or 3D\n variables only it can easily be extended for higher dimensions\n by adapting the appropriate macros.\n @enddesc\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var width_dir\n @vdesc boundary width in direction dir\n @vtype CCTK_INT\n @vio in\n @endvar\n @var in_widths\n @vdesc boundary widths for all directions\n @vtype CCTK_INT [ dimension of variable(s) ]\n @vio in\n @endvar\n @var dir\n @vdesc direction to copy boundaries (0 for copying all directions)\n @vtype int\n @vio in\n @endvar\n @var first_var_to\n @vdesc index of first variable to copy boundaries to\n @vtype int\n @vio in\n @endvar\n @var first_var_from\n @vdesc index of first variable to copy boundaries from\n @vtype int\n @vio in\n @endvar\n @var num_vars\n @vdesc number of variables\n @vtype int\n @vio in\n @endvar\n\n @calls CCTK_GroupIndexFromVarI\n CCTK_GroupDimI\n CCTK_VarTypeI\n CCTK_GroupStaggerDirArrayGI\n COPY_BOUNDARY\n @history\n @hdate Sat 20 Jan 2001\n @hauthor Thomas Radke\n @hdesc Merged separate routines for 1D, 2D, and 3D\n into a single generic routine\n @endhistory\n\n @returntype int\n @returndesc\n 0 for success\n -1 if dimension is not supported\n -2 if direction parameter is invalid\n -3 if boundary width array parameter is NULL\n @endreturndesc\n@@*/\nstatic int ApplyBndCopy(const cGH *GH,\n CCTK_INT width_dir, const CCTK_INT *in_widths,\n int dir, CCTK_INT faces,\n int first_var_to, int first_var_from, int num_vars) {\n int i, j, k;\n int timelvl_to, timelvl_from;\n int gindex, gdim;\n int var_to, var_from, vtypesize;\n int doBC[2 * MAXDIM], ash[MAXDIM], lsh[MAXDIM];\n CCTK_INT widths[2 * MAXDIM];\n CCTK_INT symtable;\n CCTK_INT symbnd[2 * MAXDIM];\n CCTK_INT is_physical[2 * MAXDIM];\n CCTK_INT ierr;\n\n /* get the group index of the target variable */\n gindex = CCTK_GroupIndexFromVarI(first_var_to);\n\n /* get the number of dimensions and the size of the variable's type */\n gdim = CCTK_GroupDimI(gindex);\n vtypesize = CCTK_VarTypeSize(CCTK_VarTypeI(first_var_to));\n\n /* make sure we can deal with this number of dimensions */\n if (gdim > MAXDIM) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Variable dimension of %d not supported\", gdim);\n return (-1);\n }\n\n /* check the direction parameter */\n if (abs(dir) > gdim) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"ApplyBndCopy: direction %d greater than dimension %d\", dir,\n gdim);\n return (-2);\n }\n\n /* set up stencil width array */\n if (dir) {\n widths[2 * (abs(dir) - 1)] = width_dir;\n widths[2 * (abs(dir) - 1) + 1] = width_dir;\n } else if (in_widths) {\n memcpy(widths, in_widths, 2 * gdim * sizeof *widths);\n } else {\n CCTK_WARN(1, \"ApplyBndCopy: NULL pointer passed for boundary width \"\n \"array\");\n return (-3);\n }\n\n /* sanity check on width of boundary, */\n BndSanityCheckWidths(GH, first_var_to, gdim, widths, \"Copy\");\n\n /* initialize arrays for variables with less dimensions than MAXDIM\n so that we can use the INDEX_3D macro later on */\n for (i = gdim; i < MAXDIM; i++) {\n ash[i] = 1;\n lsh[i] = 1;\n }\n\n /* get the current timelevel */\n timelvl_to = 0;\n timelvl_from = 0;\n\n /* see if we have a physical boundary */\n symtable = SymmetryTableHandleForGrid(GH);\n if (symtable < 0)\n CCTK_WARN(0, \"internal error\");\n ierr = Util_TableGetIntArray(symtable, 2 * gdim, symbnd, \"symmetry_handle\");\n if (ierr != 2 * gdim)\n CCTK_WARN(0, \"internal error\");\n for (i = 0; i < 2 * gdim; i++) {\n is_physical[i] = symbnd[i] < 0;\n }\n\n /* now loop over all variables */\n for (var_to = first_var_to, var_from = first_var_from;\n var_to < first_var_to + num_vars; var_to++, var_from++) {\n /* Apply condition if:\n + boundary is a physical boundary\n + boundary is an outer boundary\n + have enough grid points\n */\n for (i = 0; i < 2 * gdim; i++) {\n doBC[i] = is_physical[i] && (faces == CCTK_ALL_FACES || (faces & (1<cctk_ash[i];\n lsh[i] = GH->cctk_lsh[i];\n doBC[i * 2] &= GH->cctk_lsh[i] > widths[i * 2] && GH->cctk_bbox[i * 2];\n doBC[i * 2 + 1] &=\n GH->cctk_lsh[i] > widths[i * 2 + 1] && GH->cctk_bbox[i * 2 + 1];\n if (dir != 0) {\n doBC[i * 2] &= (dir < 0 && (i + 1 == abs(dir)));\n doBC[i * 2 + 1] &= (dir > 0 && (i + 1 == abs(dir)));\n }\n }\n\n /* now copy the boundaries face by face */\n if (gdim > 0) {\n /* lower x */\n COPY_BOUNDARY(doBC[0], widths[0], lsh[1], lsh[2], i, j, k);\n /* upper x */\n COPY_BOUNDARY(doBC[1], widths[1], lsh[1], lsh[2], lsh[0] - i - 1, j, k);\n }\n if (gdim > 1) {\n /* lower y */\n COPY_BOUNDARY(doBC[2], lsh[0], widths[2], lsh[2], i, j, k);\n /* upper y */\n COPY_BOUNDARY(doBC[3], lsh[0], widths[3], lsh[2], i, lsh[1] - j - 1, k);\n }\n if (gdim > 2) {\n /* lower z */\n COPY_BOUNDARY(doBC[4], lsh[0], lsh[1], widths[4], i, j, k);\n /* upper z */\n COPY_BOUNDARY(doBC[5], lsh[0], lsh[1], widths[5], i, j, lsh[2] - k - 1);\n }\n }\n\n return (0);\n}\n", "FlatBoundary.c": "/*@@\n @file FlatBoundary.c\n @date Mon Mar 15 15:09:00 1999\n @author Gerd Lanfermann\n @desc\n Routines for applying flat boundary conditions\n @enddesc\n @history\n @hdate Tue 10 Apr 2001\n @hauthor Thomas Radke\n @hdesc BC routines generalized for applying to arbitrary CCTK data types\n @endhistory\n @version $Id$\n@@*/\n\n/*#define DEBUG_BOUNDARY*/\n\n#include \n#include \n\n#include \"cctk.h\"\n#include \"util_Table.h\"\n#include \"util_ErrorCodes.h\"\n#include \"cctk_Parameters.h\"\n#include \"cctk_FortranString.h\"\n\n#include \"Boundary.h\"\n\n/* the rcs ID and its dummy function to use it */\nstatic const char *rcsid = \"$Header$\";\nCCTK_FILEVERSION(CactusBase_Boundary_FlatBoundary_c);\n\nstatic int ApplyBndFlat(const cGH *GH,\n CCTK_INT width_dir, const CCTK_INT *in_widths,\n int dir, CCTK_INT faces,\n int first_var, int num_vars);\nstatic int OldApplyBndFlat(const cGH *GH, int stencil_dir,\n const int *stencil_alldirs, int dir, int first_var,\n int num_vars);\n\n/********************************************************************\n ******************** External Routines ************************\n ********************************************************************/\n/*@@\n @routine BndFlat\n @date 13 Feb 2003\n @author David Rideout\n @desc\n Top level function which is registered as handling\n the Flat boundary condition\n @enddesc\n @calls ApplyBndFlat\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var num_vars\n @vdesc number of variables passed in through var_indices[]\n @vtype CCTK_INT\n @vio in\n @endvar\n @var var_indices\n @vdesc array of variable indicies to which to apply this boundary\n condition\n @vtype CCTK_INT *\n @vio in\n @endvar\n @var faces\n @vdesc array of set of faces to which to apply the bc\n @vtype CCTK_INT\n @vio in\n @endvar\n @var widths\n @vdesc array of boundary widths for each variable\n @vtype CCTK_INT\n @vio in\n @endvar\n @var table_handles\n @vdesc array of table handles which hold extra arguments\n @vtype CCTK_INT\n @vio in\n @endvar\n @returntype CCTK_INT\n @returndesc\n return code of @seeroutine ApplyBndFlat\n -21 error reading boundary width array from table\n -22 wrong size boundary width array in table\n @endreturndesc\n@@*/\nCCTK_INT BndFlat(const cGH *GH, CCTK_INT num_vars, CCTK_INT *vars,\n CCTK_INT *faces, CCTK_INT *widths, CCTK_INT *tables) {\n int i, j, k, gi, gdim, max_gdim, err, retval;\n\n /* variables to pass to ApplyBndFlat */\n CCTK_INT *width_alldirs; /* width of boundary in all directions */\n int dir; /* direction in which to apply bc */\n\n retval = 0;\n width_alldirs = NULL;\n max_gdim = 0;\n\n /* loop through variables, j at a time */\n for (i = 0; i < num_vars; i += j) {\n /* find other adjacent vars which are selected for identical bcs */\n j = 1;\n /* Since GFs are allowed to have different staggering, the best we\n can do is find variables of the same group which are selected\n for identical bcs. If all GFs had the same staggering then we\n could groups many GFs together. */\n gi = CCTK_GroupIndexFromVarI(vars[i]);\n while (i + j < num_vars && vars[i + j] == vars[i] + j &&\n CCTK_GroupIndexFromVarI(vars[i + j]) == gi &&\n tables[i + j] == tables[i] && faces[i + j] == faces[i] &&\n widths[i + j] == widths[i]) {\n ++j;\n }\n\n dir = 0; /* apply bc to all faces */\n\n /* Determine boundary width on all faces */\n /* allocate memory for buffer */\n gdim = CCTK_GroupDimI(gi);\n if (gdim > max_gdim) {\n width_alldirs =\n (CCTK_INT *)realloc(width_alldirs, 2 * gdim * sizeof(CCTK_INT));\n max_gdim = gdim;\n }\n\n /* fill it with values, either from table or the boundary_width\n parameter */\n if (widths[i] < 0) {\n err = Util_TableGetIntArray(tables[i], 2 * gdim, width_alldirs,\n \"BOUNDARY_WIDTH\");\n if (err < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Error %d when reading boundary width array from table \"\n \"for %s\",\n err, CCTK_VarName(vars[i]));\n return -21;\n } else if (err != 2 * gdim) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Boundary width array for %s has %d elements, but %d \"\n \"expected\",\n CCTK_VarName(vars[i]), err, 2 * gdim);\n return -22;\n }\n } else {\n for (k = 0; k < 2 * gdim; ++k) {\n width_alldirs[k] = widths[i];\n }\n }\n\n /* Apply the boundary condition */\n if ((retval = ApplyBndFlat(GH, 0, width_alldirs, dir, faces[i], vars[i],\n j)) < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"ApplyBndFlat() returned %d\", retval);\n }\n }\n free(width_alldirs);\n\n return retval;\n}\n\n/* prototypes for external C routines are declared in header Boundary.h\n here only follow the fortran wrapper prototypes */\nvoid CCTK_FCALL CCTK_FNAME(BndFlatDirGI)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, const int *gi);\nvoid CCTK_FCALL CCTK_FNAME(BndFlatGI)(int *ierr, const cGH **GH,\n const int *stencil, const int *gi);\nvoid CCTK_FCALL CCTK_FNAME(BndFlatDirGN)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, ONE_FORTSTRING_ARG);\nvoid CCTK_FCALL CCTK_FNAME(BndFlatGN)(int *ierr, const cGH **GH,\n const int *stencil, ONE_FORTSTRING_ARG);\nvoid CCTK_FCALL CCTK_FNAME(BndFlatDirVI)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, const int *vi);\nvoid CCTK_FCALL CCTK_FNAME(BndFlatVI)(int *ierr, const cGH **GH,\n const int *stencil, const int *vi);\nvoid CCTK_FCALL CCTK_FNAME(BndFlatDirVN)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, ONE_FORTSTRING_ARG);\nvoid CCTK_FCALL CCTK_FNAME(BndFlatVN)(int *ierr, const cGH **GH,\n const int *stencil, ONE_FORTSTRING_ARG);\n\n/********************************************************************\n ******************** Internal Routines ************************\n ********************************************************************/\n\n/*@@\n @routine BndFlatDirGI\n @date Sun Jan 21 2001\n @author Gabrielle Allen\n @desc\n Apply flat boundary conditions by group index in given direction\n @enddesc\n @calls ApplyBndFlat\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to apply boundaries\n @vtype int\n @vio in\n @endvar\n @var gi\n @vdesc index of group to apply boundaries to\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndFlat
\n -1 if invalid group index was given\n @endreturndesc\n@@*/\nint BndFlatDirGI(const cGH *GH, int stencil_size, int dir, int gi) {\n int first_vi, retval;\n\n first_vi = CCTK_FirstVarIndexI(gi);\n if (first_vi >= 0) {\n retval = ApplyBndFlat(GH, stencil_size, NULL, dir, CCTK_ALL_FACES, first_vi,\n CCTK_NumVarsInGroupI(gi));\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group index %d in BndFlatDirGI\", gi);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndFlatDirGI)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, const int *gi) {\n *ierr = BndFlatDirGI(*GH, *stencil_size, *dir, *gi);\n}\n\n/*@@\n @routine BndFlatGI\n @date Thu Mar 2 11:11:40 2000\n @author Gerd Lanfermann\n @desc\n Apply flat boundary conditions by group index\n @enddesc\n @calls ApplyBndFlat\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int [ dimension of group ]\n @vio in\n @endvar\n @var gi\n @vdesc index of group to apply boundaries to\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndFlat
\n -1 if invalid group index was given\n @endreturndesc\n@@*/\nint BndFlatGI(const cGH *GH, const int *stencil, int gi) {\n int first_vi, retval;\n\n first_vi = CCTK_FirstVarIndexI(gi);\n if (first_vi >= 0) {\n retval =\n OldApplyBndFlat(GH, -1, stencil, 0, first_vi, CCTK_NumVarsInGroupI(gi));\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group index %d in BndFlatGI\", gi);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndFlatGI)(int *ierr, const cGH **GH,\n const int *stencil, const int *gi) {\n *ierr = BndFlatGI(*GH, stencil, *gi);\n}\n\n/* ===================================================================== */\n\n/*@@\n @routine BndFlatDirGN\n @date Sun Jan 21 2001\n @author Gabrielle Allen\n @desc\n Apply flat boundary conditions by group name in given direction\n @enddesc\n @calls BndFlatDirGI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to apply boundaries\n @vtype int\n @vio in\n @endvar\n @var gn\n @vdesc name of group to apply boundaries to\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndFlatDirGI
\n -1 if invalid group name was given\n @endreturndesc\n@@*/\nint BndFlatDirGN(const cGH *GH, int stencil_size, int dir, const char *gn) {\n int gi, retval;\n\n gi = CCTK_GroupIndex(gn);\n if (gi >= 0) {\n retval = BndFlatDirGI(GH, stencil_size, dir, gi);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group name '%s' in BndFlatDirGN\", gn);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndFlatDirGN)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, ONE_FORTSTRING_ARG) {\n ONE_FORTSTRING_CREATE(gn)\n *ierr = BndFlatDirGN(*GH, *stencil_size, *dir, gn);\n free(gn);\n}\n\n/*@@\n @routine BndFlatGN\n @date Thu Mar 2 11:11:40 2000\n @author Gerd Lanfermann\n @desc\n Apply flat boundary conditions by group name\n @enddesc\n @calls BndFlatGI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int [ dimension of group ]\n @vio in\n @endvar\n @var gn\n @vdesc name of group to apply boundaries to\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndFlatGI
\n -1 if invalid group name was given\n @endreturndesc\n@@*/\nint BndFlatGN(const cGH *GH, const int *stencil, const char *gn) {\n int gi, retval;\n\n gi = CCTK_GroupIndex(gn);\n if (gi >= 0) {\n retval = BndFlatGI(GH, stencil, gi);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group name '%s' in BndFlatGN\", gn);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndFlatGN)(int *ierr, const cGH **GH,\n const int *stencil, ONE_FORTSTRING_ARG) {\n ONE_FORTSTRING_CREATE(gn)\n *ierr = BndFlatGN(*GH, stencil, gn);\n free(gn);\n}\n\n/* ===================================================================== */\n\n/*@@\n @routine BndFlatDirVI\n @date Sun Jan 21 2001\n @author Gabrielle Allen\n @desc\n Apply flat boundary conditions by variable index\n in given direction\n @enddesc\n @calls ApplyBndFlat\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to apply boundaries\n @vtype int\n @vio in\n @endvar\n @var vi\n @vdesc index of variable to apply boundaries to\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndFlat
\n -1 if invalid variable index was given\n @endreturndesc\n@@*/\nint BndFlatDirVI(const cGH *GH, int stencil_size, int dir, int vi) {\n int retval;\n\n if (vi >= 0 && vi < CCTK_NumVars()) {\n retval = ApplyBndFlat(GH, stencil_size, NULL, dir, CCTK_ALL_FACES, vi, 1);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable index %d in BndFlatDirVI\", vi);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndFlatDirVI)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, const int *vi) {\n *ierr = BndFlatDirVI(*GH, *stencil_size, *dir, *vi);\n}\n\n/*@@\n @routine BndFlatVI\n @date Thu Mar 2 11:11:40 2000\n @author Gerd Lanfermann\n @desc\n Apply flat boundary conditions by variable index\n @enddesc\n @calls ApplyBndFlat\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int [ dimension of variable ]\n @vio in\n @endvar\n @var vi\n @vdesc index of variable to apply boundaries to\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndFlat
\n -1 if invalid variable index was given\n @endreturndesc\n@@*/\nint BndFlatVI(const cGH *GH, const int *stencil, int vi) {\n int retval;\n\n if (vi >= 0 && vi < CCTK_NumVars()) {\n retval = OldApplyBndFlat(GH, -1, stencil, 0, vi, 1);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable index %d in BndFlatVI\", vi);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndFlatVI)(int *ierr, const cGH **GH,\n const int *stencil, const int *vi) {\n *ierr = BndFlatVI(*GH, stencil, *vi);\n}\n\n/* ======================================================================= */\n\n/*@@\n @routine BndFlatDirVN\n @date Sun Jan 21 2001\n @author Gabrielle Allen\n @desc\n Apply flat boundary conditions by variable name\n in given direction\n @enddesc\n @calls BndFlatDirVI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_size\n @vdesc stencil size in this direction\n @vtype int\n @vio in\n @endvar\n @var dir\n @vdesc direction to apply boundaries\n @vtype int\n @vio in\n @endvar\n @var vn\n @vdesc name of variable to apply boundaries to\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndFlatDirVI
\n -1 if invalid variable name was given\n @endreturndesc\n@@*/\nint BndFlatDirVN(const cGH *GH, int stencil_size, int dir, const char *vn) {\n int vi, retval;\n\n vi = CCTK_VarIndex(vn);\n if (vi >= 0) {\n retval = BndFlatDirVI(GH, stencil_size, dir, vi);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable name '%s' in BndFlatDirVN\", vn);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndFlatDirVN)(int *ierr, const cGH **GH,\n const int *stencil_size,\n const int *dir, ONE_FORTSTRING_ARG) {\n ONE_FORTSTRING_CREATE(vn)\n *ierr = BndFlatDirVN(*GH, *stencil_size, *dir, vn);\n free(vn);\n}\n\n/*@@\n @routine BndFlatVN\n @date Thu Mar 2 11:11:40 2000\n @author Gerd Lanfermann\n @desc\n Apply flat boundary conditions by variable name\n @enddesc\n @calls BndFlatVI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width\n @vtype int [ dimension of variable ]\n @vio in\n @endvar\n @var vn\n @vdesc name of variable to apply boundaries to\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndFlatVI
\n -1 if invalid variable name was given\n @endreturndesc\n@@*/\nint BndFlatVN(const cGH *GH, const int *stencil, const char *vn) {\n int vi, retval;\n\n vi = CCTK_VarIndex(vn);\n if (vi >= 0) {\n retval = BndFlatVI(GH, stencil, vi);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable name '%s' in BndFlatVN\", vn);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndFlatVN)(int *ierr, const cGH **GH,\n const int *stencil, ONE_FORTSTRING_ARG) {\n ONE_FORTSTRING_CREATE(vn)\n *ierr = BndFlatVN(*GH, stencil, vn);\n free(vn);\n}\n\n/********************************************************************\n ********************* Local Routines *************************\n ********************************************************************/\n\n/* maximum dimension we can deal with */\n#define MAXDIM 3\n\n/* macro to compute the linear index of a 3D point */\n#define INDEX_3D(ash, i, j, k) ((i) + (ash)[0] * ((j) + (ash)[1] * (k)))\n\n/*@@\n @routine FLAT_BOUNDARY\n @date Tue 10 Apr 2001\n @author Thomas Radke\n @desc\n Macro to apply flat boundary conditions to a variable\n Currently it is limited up to 3D variables only.\n @enddesc\n\n @var doBC\n @vdesc flag telling whether to apply boundary conditions or not\n @vtype int\n @vio in\n @endvar\n @var iend, jend, kend\n @vdesc upper ranges for the loopers\n @vtype int\n @vio in\n @endvar\n @var ii_to, jj_to, kk_to\n @vdesc indices of the current grid point to copy to\n @vtype int\n @vio in\n @endvar\n @var ii_from, jj_from, kk_from\n @vdesc indices of the current grid point to copy from\n @vtype int\n @vio in\n @endvar\n@@*/\n#define FLAT_BOUNDARY(doBC, iend, jend, kend, ii_to, jj_to, kk_to, ii_from, \\\n jj_from, kk_from) \\\n { \\\n if (doBC) { \\\n for (k = 0; k < kend; k++) { \\\n for (j = 0; j < jend; j++) { \\\n for (i = 0; i < iend; i++) { \\\n int _index_to, _index_from; \\\n \\\n _index_to = INDEX_3D(ash, ii_to, jj_to, kk_to) * vtypesize; \\\n _index_from = \\\n INDEX_3D(ash, ii_from, jj_from, kk_from) * vtypesize; \\\n memcpy((char *)GH->data[var][timelvl] + _index_to, \\\n (char *)GH->data[var][timelvl] + _index_from, vtypesize); \\\n } \\\n } \\\n } \\\n } \\\n }\n\n/*@@\n @routine ApplyBndFlat\n @date Jul 5 2000\n @author Gabrielle Allen, Gerd Lanfermann\n @desc\n Apply flat boundary conditions to a group of grid functions\n given by their indices\n This routine is called by the various BndFlatXXX wrappers.\n\n Although it is currently limited to handle 1D, 2D, or 3D\n variables only it can easily be extended for higher dimensions\n by adapting the appropriate macros.\n @enddesc\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var width_dir\n @vdesc boundary width in direction dir\n @vtype CCTK_INT\n @vio in\n @endvar\n @var in_widths\n @vdesc boundary widths for all directions\n @vtype CCTK_INT [ dimension of variable(s) ]\n @vio in\n @endvar\n @var dir\n @vdesc direction to set boundaries (0 for setting all directions)\n @vtype int\n @vio in\n @endvar\n @var first_var\n @vdesc index of first variable to apply boundaries to\n @vtype int\n @vio in\n @endvar\n @var num_vars\n @vdesc number of variables\n @vtype int\n @vio in\n @endvar\n\n @calls CCTK_GroupIndexFromVarI\n CCTK_GroupDimI\n CCTK_VarTypeI\n CCTK_GroupStaggerDirArrayGI\n FLAT_BOUNDARY\n @history\n @hdate Tue 10 Apr 2001\n @hauthor Thomas Radke\n @hdesc Merged separate routines for 1D, 2D, and 3D\n into a single generic routine\n @endhistory\n\n @returntype int\n @returndesc\n 0 for success\n -1 if dimension is not supported\n -2 if direction parameter is invalid\n -3 if boundary width array parameter is NULL\n @endreturndesc\n@@*/\nstatic int ApplyBndFlat(const cGH *GH,\n CCTK_INT width_dir, const CCTK_INT *in_widths,\n int dir, CCTK_INT faces,\n int first_var, int num_vars) {\n int i, j, k;\n int var, vtypesize, gindex, gdim, timelvl;\n int doBC[2 * MAXDIM], ash[MAXDIM], lsh[MAXDIM];\n CCTK_INT widths[2 * MAXDIM];\n CCTK_INT symtable;\n CCTK_INT symbnd[2 * MAXDIM];\n CCTK_INT is_physical[2 * MAXDIM];\n CCTK_INT ierr;\n\n /* get the group index of the variables */\n gindex = CCTK_GroupIndexFromVarI(first_var);\n\n /* get the number of dimensions and the size of the variables' type */\n gdim = CCTK_GroupDimI(gindex);\n vtypesize = CCTK_VarTypeSize(CCTK_VarTypeI(first_var));\n\n /* make sure we can deal with this number of dimensions */\n if (gdim > MAXDIM) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"ApplyBndFlat: Variable dimension of %d not supported\", gdim);\n return (-1);\n }\n\n /* check the direction parameter */\n if (abs(dir) > gdim) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"ApplyBndFlat: direction %d greater than dimension %d\", dir,\n gdim);\n return (-2);\n }\n\n /* set up boundary width array */\n if (dir) {\n widths[2 * (abs(dir) - 1)] = width_dir;\n widths[2 * (abs(dir) - 1) + 1] = width_dir;\n } else if (in_widths) {\n memcpy(widths, in_widths, 2 * gdim * sizeof *widths);\n } else {\n CCTK_WARN(1, \"ApplyBndFlat: NULL pointer passed for boundary width \"\n \"array\");\n return (-3);\n }\n\n /* initialize arrays for variables with less dimensions than MAXDIM\n so that we can use the INDEX_3D macro later on */\n for (i = gdim; i < MAXDIM; i++) {\n ash[i] = 1;\n lsh[i] = 1;\n }\n\n /* get the current timelevel */\n timelvl = 0;\n\n /* see if we have a physical boundary */\n symtable = SymmetryTableHandleForGrid(GH);\n if (symtable < 0)\n CCTK_WARN(0, \"internal error\");\n ierr = Util_TableGetIntArray(symtable, 2 * gdim, symbnd, \"symmetry_handle\");\n if (ierr != 2 * gdim)\n CCTK_WARN(0, \"internal error\");\n for (i = 0; i < 2 * gdim; i++) {\n is_physical[i] = symbnd[i] < 0;\n }\n\n /* sanity check on width of boundary, */\n BndSanityCheckWidths(GH, first_var, gdim, widths, \"Flat\");\n\n /* now loop over all variables */\n for (var = first_var; var < first_var + num_vars; var++) {\n /* Apply condition if:\n + boundary is a physical boundary\n + boundary is an outer boundary\n + have enough grid points\n */\n for (i = 0; i < 2 * gdim; i++) {\n doBC[i] = is_physical[i] && (faces == CCTK_ALL_FACES || (faces & (1<cctk_ash[i];\n lsh[i] = GH->cctk_lsh[i];\n doBC[i * 2] &= GH->cctk_lsh[i] > widths[i * 2] && GH->cctk_bbox[i * 2];\n doBC[i * 2 + 1] &=\n GH->cctk_lsh[i] > widths[i * 2 + 1] && GH->cctk_bbox[i * 2 + 1];\n if (dir != 0) {\n doBC[i * 2] &= (dir < 0 && (i + 1 == abs(dir)));\n doBC[i * 2 + 1] &= (dir > 0 && (i + 1 == abs(dir)));\n }\n }\n\n /* now apply the boundaries face by face */\n if (gdim > 0) {\n#ifdef DEBUG_BOUNDARY\n if (doBC[0]) {\n printf(\"Boundary: Applying lower x flat boundary condition\\n\");\n }\n if (doBC[1]) {\n printf(\"Boundary: Applying upper x flat boundary condition\\n\");\n }\n#endif /* DEBUG_BOUNDARY */\n /* lower x */\n FLAT_BOUNDARY(doBC[0], widths[0], lsh[1], lsh[2], i, j, k, widths[0], j,\n k);\n /* upper x */\n FLAT_BOUNDARY(doBC[1], widths[1], lsh[1], lsh[2], lsh[0] - i - 1, j, k,\n lsh[0] - widths[1] - 1, j, k);\n }\n if (gdim > 1) {\n#ifdef DEBUG_BOUNDARY\n if (doBC[2]) {\n printf(\"Boundary: Applying lower y flat boundary condition\\n\");\n }\n if (doBC[3]) {\n printf(\"Boundary: Applying upper y flat boundary condition\\n\");\n }\n#endif /* DEBUG_BOUNDARY */\n /* lower y */\n FLAT_BOUNDARY(doBC[2], lsh[0], widths[2], lsh[2], i, j, k, i, widths[2],\n k);\n /* upper y */\n FLAT_BOUNDARY(doBC[3], lsh[0], widths[3], lsh[2], i, lsh[1] - j - 1, k, i,\n lsh[1] - widths[3] - 1, k);\n }\n if (gdim > 2) {\n#ifdef DEBUG_BOUNDARY\n if (doBC[4]) {\n printf(\"Boundary: Applying lower z flat boundary condition\\n\");\n }\n if (doBC[5]) {\n printf(\"Boundary: Applying upper z flat boundary condition\\n\");\n }\n#endif /* DEBUG_BOUNDARY */\n /* lower z */\n FLAT_BOUNDARY(doBC[4], lsh[0], lsh[1], widths[4], i, j, k, i, j,\n widths[4]);\n /* upper z */\n FLAT_BOUNDARY(doBC[5], lsh[0], lsh[1], widths[5], i, j, lsh[2] - k - 1, i,\n j, lsh[2] - widths[5] - 1);\n }\n }\n\n return (0);\n}\n\n/*@@\n @routine OldApplyBndFlat\n @date 5 May 2003\n @author David Rideout\n @desc\n The new boundary API expects a 2d-element array for the\n boundary_widths (d=dimension of grid variable), while\n the old API expects a d-element array. This function\n converts the old array to the new format.\n @enddesc\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil_dir\n @vdesc stencil width in direction dir\n @vtype int\n @vio in\n @endvar\n @var stencil_alldirs\n @vdesc stencil widths for all directions\n @vtype int [ dimension of variable(s) ]\n @vio in\n @endvar\n @var dir\n @vdesc direction to set boundaries (0 for setting all directions)\n @vtype int\n @vio in\n @endvar\n @var first_var\n @vdesc index of first variable to apply boundaries to\n @vtype int\n @vio in\n @endvar\n @var num_vars\n @vdesc number of variables\n @vtype int\n @vio in\n @endvar\n\n @calls CCTK_GroupIndexFromVarI\n CCTK_GroupDimI\n ApplyBndFlat\n @history\n @returntype int\n @returndesc\n returncode from @seeroutine ApplyBndFlat\n @endreturndesc\n@@*/\n\nint OldApplyBndFlat(const cGH *GH, int stencil_dir, const int *stencil_alldirs,\n int dir, int first_var, int num_vars) {\n int dim, i, retval;\n CCTK_INT *boundary_widths;\n static int warned;\n\n /* Convert stencil_alldirs to new format */\n dim = CCTK_GroupDimFromVarI(first_var);\n boundary_widths = malloc(2 * dim * sizeof(CCTK_INT));\n for (i = 0; i < 2 * dim; ++i) {\n boundary_widths[i] = stencil_alldirs[i / 2];\n }\n\n /* Bug people for using the old interface */\n if (!warned) {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Copied older d-element array of boundary widths into the \"\n \"newer 2d-element format. Please use the new boundary \"\n \"interface to avoid this.\");\n warned = 1;\n }\n\n /* Call ApplyBnd... with new boundary width array */\n retval =\n ApplyBndFlat(GH, stencil_dir, boundary_widths, dir, CCTK_ALL_FACES,\n first_var, num_vars);\n\n free(boundary_widths);\n return retval;\n}\n", "RobinBoundary.c": "/*@@\n @file RobinBoundary.c\n @date July 6th 2000\n @author Miguel Alcubierre, Gabrielle Allen, Gerd Lanfermann\n @desc\n Routines for Robin boundary conditions\n @enddesc\n @history\n @hdate Tue 10 Apr 2001\n @hauthor Thomas Radke\n @hdesc BC routines generalized for applying to arbitrary CCTK data types\n @endhistory\n @version $Id$\n@@*/\n\n#include \n#include \n#include \n#include \n\n#include \"cctk.h\"\n#include \"util_Table.h\"\n#include \"util_ErrorCodes.h\"\n#include \"cctk_Parameters.h\"\n#include \"cctk_FortranString.h\"\n\n#include \"Boundary.h\"\n\n/* the rcs ID and its dummy function to use it */\nstatic const char *rcsid = \"$Header$\";\nCCTK_FILEVERSION(CactusBase_Boundary_RobinBoundary_c);\n\nstatic int ApplyBndRobin(const cGH *GH, const CCTK_INT *stencil, CCTK_REAL finf,\n int npow, int first_var, int num_vars);\nstatic int OldApplyBndRobin(const cGH *GH, const int *stencil, CCTK_REAL finf,\n int npow, int first_var, int num_vars);\n\n/********************************************************************\n ******************** External Routines ************************\n ********************************************************************/\n/*@@\n @routine BndRobin\n @date 14 Feb 2003\n @author David Rideout\n @desc\n Top level function which is registered as handling\n this boundary condition\n @enddesc\n @calls ApplyBndRobin\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var num_vars\n @vdesc number of variables passed in through var_indices[]\n @vtype CCTK_INT\n @vio in\n @endvar\n @var var_indices\n @vdesc array of variable indicies to which to apply this boundary\n condition\n @vtype CCTK_INT *\n @vio in\n @endvar\n @var faces\n @vdesc array of set of faces to which to apply the bc\n @vtype CCTK_INT\n @vio in\n @endvar\n @var widths\n @vdesc array of boundary widths for each variable\n @vtype CCTK_INT\n @vio in\n @endvar\n @var table_handles\n @vdesc array of table handles which hold extra arguments\n @vtype CCTK_INT\n @vio in\n @endvar\n @returntype CCTK_INT\n @returndesc\n return code of @seeroutine ApplyBndRobin\n -21 error reading boundary width array from table\n -22 wrong size boundary width array in table\n @endreturndesc\n@@*/\n\nCCTK_INT BndRobin(const cGH *GH, CCTK_INT num_vars, CCTK_INT *vars,\n CCTK_INT *faces, CCTK_INT *widths, CCTK_INT *tables) {\n int i, j, k, gi, err, gdim, max_gdim, retval;\n\n /* variables to pass to ApplyBndRobin */\n CCTK_INT *width_alldirs; /* width of boundary in all directions */\n CCTK_REAL finf; /* value of function at infinity */\n CCTK_INT npow; /* decay rate */\n\n#ifdef DEBUG\n printf(\n \"BndRobin(): got passed GH=%p, num_vars=%d, vars[0]=%d, tables[0]=%d\\n\",\n (const void *)GH, num_vars, vars[0], tables[0]);\n#endif\n\n retval = 0;\n width_alldirs = NULL;\n max_gdim = 0;\n\n /* loop through variables, j at a time */\n for (i = 0; i < num_vars; i += j) {\n /* find other adjacent vars which are selected for identical bcs */\n j = 1;\n /* Since GFs are allowed to have different staggering, the best we\n can do is find variables of the same group which are selected\n for identical bcs. If all GFs had the same staggering then we\n could groups many GFs together. */\n gi = CCTK_GroupIndexFromVarI(vars[i]);\n while (i + j < num_vars && vars[i + j] == vars[i] + j &&\n CCTK_GroupIndexFromVarI(vars[i + j]) == gi &&\n tables[i + j] == tables[i] && faces[i + j] == faces[i] &&\n widths[i + j] == widths[i]) {\n ++j;\n }\n\n /* Check to see if faces specification is valid */\n if (faces[i] != CCTK_ALL_FACES) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Faces specification %d for Robin boundary conditions on \"\n \"%s is not implemented yet. \"\n \"Applying Robin bcs to all (external) faces.\",\n (int)faces[i], CCTK_VarName(vars[i]));\n }\n\n /* Set up default arguments for ApplyBndRobin */\n finf = 0;\n npow = 1;\n\n /* Look on table for possible non-default arguments\n * (If any of these table look-ups fail, the value will be unchanged\n * from its default value)\n */\n /* Asymptotic value of function at infinity */\n err = Util_TableGetReal(tables[i], &finf, \"FINF\");\n if (err == UTIL_ERROR_BAD_HANDLE) {\n CCTK_VWarn(5, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid table handle passed for Robin boundary \"\n \"conditions for %s. Using all default values.\",\n CCTK_VarName(vars[i]));\n } else {\n /* Decay power */\n Util_TableGetInt(tables[i], &npow, \"DECAY_POWER\");\n }\n\n /* Determine boundary width on all faces */\n /* allocate memory for buffer */\n gdim = CCTK_GroupDimI(gi);\n if (gdim > max_gdim) {\n width_alldirs =\n (CCTK_INT *)realloc(width_alldirs, 2 * gdim * sizeof(CCTK_INT));\n max_gdim = gdim;\n }\n\n /* fill it with values, either from table or the boundary_width\n parameter */\n if (widths[i] < 0) {\n err = Util_TableGetIntArray(tables[i], 2 * gdim, width_alldirs,\n \"BOUNDARY_WIDTH\");\n if (err < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Error %d when reading boundary width array from table \"\n \"for %s\",\n err, CCTK_VarName(vars[i]));\n return -21;\n } else if (err != 2 * gdim) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Boundary width array for %s has %d elements, but %d \"\n \"expected\",\n CCTK_VarName(vars[i]), err, 2 * gdim);\n return -22;\n }\n } else {\n for (k = 0; k < 2 * gdim; ++k) {\n width_alldirs[k] = widths[i];\n }\n }\n\n /* Apply the boundary condition */\n if ((retval = ApplyBndRobin(GH, width_alldirs, finf, npow, vars[i], j)) <\n 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"ApplyBndRobin() returned %d\", retval);\n }\n }\n#ifdef DEBUG\n printf(\"BndRobin(): returning %d\\n\", retval);\n#endif\n free(width_alldirs);\n\n return retval;\n}\n\n/* prototypes for external C routines are declared in header Boundary.h\n here only follow the fortran wrapper prototypes */\nvoid CCTK_FCALL CCTK_FNAME(BndRobinGI)(int *ierr, const cGH **GH,\n const int *stencil,\n const CCTK_REAL *finf, const int *npow,\n const int *gi);\nvoid CCTK_FCALL CCTK_FNAME(BndRobinGN)(int *ierr, const cGH **GH,\n const int *stencil,\n const CCTK_REAL *finf, const int *npow,\n ONE_FORTSTRING_ARG);\nvoid CCTK_FCALL CCTK_FNAME(BndRobinVI)(int *ierr, const cGH **GH,\n const int *stencil,\n const CCTK_REAL *finf, const int *npow,\n const int *vi);\nvoid CCTK_FCALL CCTK_FNAME(BndRobinVN)(int *ierr, const cGH **GH,\n const int *stencil,\n const CCTK_REAL *finf, const int *npow,\n ONE_FORTSTRING_ARG);\n\n/********************************************************************\n ******************** Internal Routines ************************\n ********************************************************************/\n\n/*@@\n @routine BndRobinGI\n @date Tue Jul 18 18:08:28 2000\n @author Gerd Lanfermann\n @desc\n Apply Robin boundary conditions by group index\n @enddesc\n @calls ApplyBndRobin\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width array\n @vtype int [ dimension of group ]\n @vio in\n @endvar\n @var finf\n @vdesc value of f at infimum\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var npow\n @vdesc power of decay rate\n @vtype int\n @vio in\n @endvar\n @var gi\n @vdesc index of group to apply boundary conditions to\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndRobin\n -1 if invalid group index was given\n @endreturndesc\n@@*/\nint BndRobinGI(const cGH *GH, const int *stencil, CCTK_REAL finf, int npow,\n int gi) {\n int first_vi, retval;\n\n first_vi = CCTK_FirstVarIndexI(gi);\n if (first_vi >= 0) {\n retval = OldApplyBndRobin(GH, stencil, finf, npow, first_vi,\n CCTK_NumVarsInGroupI(gi));\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group index %d in BndFlatGI\", gi);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndRobinGI)(int *ierr, const cGH **GH,\n const int *stencil,\n const CCTK_REAL *finf, const int *npow,\n const int *gi) {\n *ierr = BndRobinGI(*GH, stencil, *finf, *npow, *gi);\n}\n\n/*@@\n @routine BndRobinGN\n @date Tue Jul 18 18:08:28 2000\n @author Gerd Lanfermann\n @desc\n Apply Robin boundary conditions by group name\n @enddesc\n @calls BndRobinGI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width array\n @vtype int [ dimension of group ]\n @vio in\n @endvar\n @var finf\n @vdesc value of f at infimum\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var npow\n @vdesc power of decay rate\n @vtype int\n @vio in\n @endvar\n @var gname\n @vdesc name of group to apply boundary conditions to\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndRobinGI
\n -1 if invalid group index was given\n @endreturndesc\n@@*/\nint BndRobinGN(const cGH *GH, const int *stencil, CCTK_REAL finf, int npow,\n const char *gname) {\n int gi, retval;\n\n gi = CCTK_GroupIndex(gname);\n if (gi >= 0) {\n retval = BndRobinGI(GH, stencil, finf, npow, gi);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid group name '%s' in BndRobinGN\", gname);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndRobinGN)(int *ierr, const cGH **GH,\n const int *stencil,\n const CCTK_REAL *finf, const int *npow,\n ONE_FORTSTRING_ARG) {\n ONE_FORTSTRING_CREATE(gname)\n *ierr = BndRobinGN(*GH, stencil, *finf, *npow, gname);\n free(gname);\n}\n\n/*@@\n @routine BndRobinVI\n @date Tue Jul 18 18:08:28 2000\n @author Gerd Lanfermann\n @desc\n Apply Robin boundary conditions by variable index\n @enddesc\n @calls ApplyBndRobin\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width array\n @vtype int [ dimension of variable ]\n @vio in\n @endvar\n @var finf\n @vdesc value of f at infimum\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var npow\n @vdesc power of decay rate\n @vtype int\n @vio in\n @endvar\n @var vi\n @vdesc index of variable to apply boundary conditions to\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine ApplyBndRobin
\n -1 if invalid group index was given\n @endreturndesc\n@@*/\nint BndRobinVI(const cGH *GH, const int *stencil, CCTK_REAL finf, int npow,\n int vi) {\n int retval;\n\n if (vi >= 0 && vi < CCTK_NumVars()) {\n retval = OldApplyBndRobin(GH, stencil, finf, npow, vi, 1);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"BndRobinVI: Invalid variable index %d\", vi);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndRobinVI)(int *ierr, const cGH **GH,\n const int *stencil,\n const CCTK_REAL *finf, const int *npow,\n const int *vi) {\n *ierr = BndRobinVI(*GH, stencil, *finf, *npow, *vi);\n}\n\n/*@@\n @routine BndRobinVN\n @date Tue Jul 18 18:08:28 2000\n @author Gerd Lanfermann\n @desc\n Apply Robin boundary conditions by variable name\n @enddesc\n @calls BndRobinVI\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var stencil\n @vdesc stencil width array\n @vtype int [ dimension of variable ]\n @vio in\n @endvar\n @var finf\n @vdesc value of f at infimum\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var npow\n @vdesc power of decay rate\n @vtype int\n @vio in\n @endvar\n @var vname\n @vdesc name of variable to apply boundary conditions to\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine BndRobinVI
\n -1 if invalid group index was given\n @endreturndesc\n@@*/\nint BndRobinVN(const cGH *GH, const int *stencil, CCTK_REAL finf, int npow,\n const char *vname) {\n int vi, retval;\n\n vi = CCTK_VarIndex(vname);\n if (vi >= 0) {\n retval = BndRobinVI(GH, stencil, finf, npow, vi);\n } else {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Invalid variable name '%s' in BndRobinVN\", vname);\n retval = -1;\n }\n\n return (retval);\n}\n\nvoid CCTK_FCALL CCTK_FNAME(BndRobinVN)(int *ierr, const cGH **GH,\n const int *stencil,\n const CCTK_REAL *finf, const int *npow,\n ONE_FORTSTRING_ARG) {\n ONE_FORTSTRING_CREATE(vname)\n *ierr = BndRobinVN(*GH, stencil, *finf, *npow, vname);\n free(vname);\n}\n\n/********************************************************************\n ********************* Local Routines *************************\n ********************************************************************/\n\n/* maximum dimension we can deal with */\n#define MAXDIM 3\n\n/* macro to compute x*x */\n#define SQR(x) ((x) * (x))\n\n/*@@\n @routine SET_LINEAR_INDICES\n @date Thu 7 June 2001\n @author Thomas Radke\n @desc\n Macro to set the linear indices for the source and destination\n element of the current grid variable\n @enddesc\n\n @var i\n @vdesc x index to use\n @vtype int\n @vio in\n @endvar\n@@*/\n#define SET_LINEAR_INDICES(i) \\\n { \\\n dst = CCTK_GFINDEX3D(GH, i, j, k); \\\n src = CCTK_GFINDEX3D(GH, (i) + dx, j + dy, k + dz); \\\n distance = dist[abs(dx) + 2 * abs(dy) + 4 * abs(dz)]; \\\n }\n\n/*@@\n @routine ROBIN_BOUNDARY_TYPED_3D\n @date Thu 7 June 2001\n @author Thomas Radke\n @desc\n Macro to apply Robin boundary conditions to a 3D variable\n of given datatype\n @enddesc\n\n @var cctk_type\n @vdesc CCTK datatype of the variable\n @vtype \n @vio in\n @endvar\n@@*/\n#define ROBIN_BOUNDARY_TYPED_3D(cctk_type) \\\n { \\\n cctk_type *data; \\\n double u_src, u_dst, aux; \\\n \\\n /* avoid the else branch with the expensive sqrt() operation if possible \\\n */ \\\n if (abs(dx) + abs(dy) + abs(dz) == 1) { \\\n u_dst = fabs((double)(dx ? x[dst] : (dy ? y[dst] : z[dst]))); \\\n u_src = fabs((double)(dx ? x[src] : (dy ? y[src] : z[src]))); \\\n } else { \\\n u_dst = sqrt(SQR(dx * x[dst]) + SQR(dy * y[dst]) + SQR(dz * z[dst])); \\\n u_src = sqrt(SQR(dx * x[src]) + SQR(dy * y[src]) + SQR(dz * z[src])); \\\n } \\\n \\\n aux = decay * distance * (u_src + u_dst) / SQR(r[src] + r[dst]); \\\n \\\n data = (cctk_type *)GH->data[var][0]; \\\n data[dst] = \\\n (cctk_type)((2 * aux * finf + data[src] * (1 - aux)) / (1 + aux)); \\\n }\n\n/*@@\n @routine ROBIN_BOUNDARY\n @date Thu 7 June 2001\n @author Thomas Radke\n @desc\n Macro to apply Robin boundary conditions to a variable\n of a given datatype in all directions\n Currently it is limited up to 3D variables only.\n @enddesc\n @calls SET_LINEAR_INDICES\n ROBIN_BOUNDARY_TYPED_3D\n\n @var cctk_type\n @vdesc CCTK datatype of the variable\n @vtype \n @vio in\n @endvar\n@@*/\n#define ROBIN_BOUNDARY(cctk_type) \\\n { \\\n int i, j, k; \\\n int dx, dy, dz; \\\n int src, dst; \\\n double distance; \\\n \\\n /* check the dimensionality */ \\\n if (gdim != 3) { \\\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING, \\\n \"ApplyBndRobin: variable dimension of %d not supported\", \\\n gdim); \\\n return (-5); \\\n } \\\n \\\n if (in_widths[0] == 2 || in_widths[1] == 2 || in_widths[2] == 2) { \\\n /* outermost loop over almost all z points */ \\\n for (k = 1; k < GH->cctk_lsh[2] - 1; k++) { \\\n dz = 0; \\\n if (k == 1 && doBC[4]) { \\\n dz = +1; \\\n } else if (k == GH->cctk_lsh[2] - 2 && doBC[5]) { \\\n dz = -1; \\\n } \\\n \\\n /* middle loop over all y points */ \\\n for (j = 1; j < GH->cctk_lsh[1] - 1; j++) { \\\n dy = 0; \\\n if (j == 1 && doBC[2]) { \\\n dy = +1; \\\n } else if (j == GH->cctk_lsh[1] - 2 && doBC[3]) { \\\n dy = -1; \\\n } \\\n \\\n /* lower x */ \\\n dx = 0; \\\n if (doBC[0]) { \\\n dx = +1; \\\n } \\\n if (dx || dy || dz) { \\\n SET_LINEAR_INDICES(1); \\\n ROBIN_BOUNDARY_TYPED_3D(cctk_type); \\\n } \\\n \\\n /* lower/upper y and/or z */ \\\n if (dy || dz) { \\\n dx = 0; \\\n SET_LINEAR_INDICES(2); \\\n for (i = 2; i < GH->cctk_lsh[0] - 2; i++, src++, dst++) { \\\n ROBIN_BOUNDARY_TYPED_3D(cctk_type); \\\n } \\\n } \\\n \\\n /* upper x */ \\\n dx = 0; \\\n if (doBC[1]) { \\\n dx = -1; \\\n } \\\n if (dx || dy || dz) { \\\n SET_LINEAR_INDICES(GH->cctk_lsh[0] - 2); \\\n ROBIN_BOUNDARY_TYPED_3D(cctk_type); \\\n } \\\n } \\\n } \\\n } \\\n \\\n /* outermost loop over all z points */ \\\n for (k = 0; k < GH->cctk_lsh[2]; k++) { \\\n dz = 0; \\\n if (k == 0 && doBC[4]) { \\\n dz = +1; \\\n } else if (k == GH->cctk_lsh[2] - 1 && doBC[5]) { \\\n dz = -1; \\\n } \\\n \\\n /* middle loop over all y points */ \\\n for (j = 0; j < GH->cctk_lsh[1]; j++) { \\\n dy = 0; \\\n if (j == 0 && doBC[2]) { \\\n dy = +1; \\\n } else if (j == GH->cctk_lsh[1] - 1 && doBC[3]) { \\\n dy = -1; \\\n } \\\n \\\n /* lower x */ \\\n dx = 0; \\\n if (doBC[0]) { \\\n dx = +1; \\\n } \\\n if (dx || dy || dz) { \\\n SET_LINEAR_INDICES(0); \\\n ROBIN_BOUNDARY_TYPED_3D(cctk_type); \\\n } \\\n \\\n /* lower/upper y and/or z */ \\\n if (dy || dz) { \\\n dx = 0; \\\n SET_LINEAR_INDICES(1); \\\n for (i = 1; i < GH->cctk_lsh[0] - 1; i++, src++, dst++) { \\\n ROBIN_BOUNDARY_TYPED_3D(cctk_type); \\\n } \\\n } \\\n \\\n /* upper x */ \\\n dx = 0; \\\n if (doBC[1]) { \\\n dx = -1; \\\n } \\\n if (dx || dy || dz) { \\\n SET_LINEAR_INDICES(GH->cctk_lsh[0] - 1); \\\n ROBIN_BOUNDARY_TYPED_3D(cctk_type); \\\n } \\\n } \\\n } \\\n }\n\n/*@@\n @routine ApplyBndRobin\n @date Tue Jul 18 18:08:28 2000\n @author Gerd Lanfermann\n @desc\n Apply Robin boundary conditions to a group of grid functions\n given by their indices\n This routine is called by the various BndRobinXXX wrappers.\n\n Although it is currently limited to handle 3D variables only\n it can easily be extended for higher dimensions\n by adapting the appropriate macros.\n @enddesc\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var in_widths\n @vdesc boundary width array\n @vtype CCTK_INT [ dimension of variable ]\n @vio in\n @endvar\n @var finf\n @vdesc value of f at infinity\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var npow\n @vdesc power of decay rate\n @vtype int\n @vio in\n @endvar\n @var first_var\n @vdesc index of first variable to apply boundary conditions to\n @vtype int\n @vio in\n @endvar\n @var num_vars\n @vdesc number of variables\n @vtype int\n @vio in\n @endvar\n\n @calls CCTK_VarTypeI\n CCTK_GroupDimFromVarI\n ROBIN_BOUNDARY\n @history\n @hdate Tue 10 Apr 2001\n @hauthor Thomas Radke\n @hdesc Merged separate routines for 1D, 2D, and 3D\n into a single generic routine\n @endhistory\n\n @returntype int\n @returndesc\n 0 for success\n -1 if variable dimension is not supported\n -2 if NULL pointer passed as boundary width array\n -3 if stencil width is other than 1\n -4 if variable type is not supported\n -5 if variable dimension is other than 3D\n -6 if no coordinate information is available\n @endreturndesc\n@@*/\nstatic int ApplyBndRobin(const cGH *GH, const CCTK_INT *in_widths,\n CCTK_REAL finf, int npow, int first_var,\n int num_vars) {\n int var, vtype, dim, gdim;\n int doBC[2 * MAXDIM];\n CCTK_INT symtable;\n CCTK_INT symbnd[2 * MAXDIM];\n CCTK_INT is_physical[2 * MAXDIM];\n CCTK_INT ierr;\n char coord_system_name[20];\n double decay;\n const CCTK_REAL *x, *y, *z, *r;\n double dist[8];\n\n /* get the number of dimensions and the variables' type */\n gdim = CCTK_GroupDimI(CCTK_GroupIndexFromVarI(first_var));\n vtype = CCTK_VarTypeI(first_var);\n\n /* make sure we can deal with this number of dimensions */\n if (gdim > MAXDIM) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"ApplyBndRobin: Variable dimension of %d not supported\", gdim);\n return (-1);\n }\n\n /* check the boundary width */\n if (!in_widths) {\n CCTK_WARN(1, \"ApplyBndRobin: NULL pointer passed for boundary width \"\n \"array\");\n return (-2);\n }\n\n for (dim = 0; dim < 2 * gdim; dim++) {\n if (in_widths[dim] != 1 && in_widths[dim] != 2) {\n CCTK_WARN(1, \"ApplyBndRobin: Stencil width must be 1 or 2 \"\n \"for Robin boundary conditions\");\n return (-3);\n }\n }\n\n /* sanity check on width of boundary, */\n BndSanityCheckWidths(GH, first_var, gdim, in_widths, \"Robin\");\n\n /* Robin boundaries need the underlying grid coordinates */\n sprintf(coord_system_name, \"cart%dd\", gdim);\n if (CCTK_CoordSystemHandle(coord_system_name) < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"ApplyBndRobin: Couldn't get coordinates from '%s'\",\n coord_system_name);\n return (-6);\n }\n x = GH->data[CCTK_CoordIndex(-1, \"x\", coord_system_name)][0];\n y = GH->data[CCTK_CoordIndex(-1, \"y\", coord_system_name)][0];\n z = GH->data[CCTK_CoordIndex(-1, \"z\", coord_system_name)][0];\n\n sprintf(coord_system_name, \"spher%dd\", gdim);\n if (CCTK_CoordSystemHandle(coord_system_name) < 0) {\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"ApplyBndRobin: Couldn't get coordinates from '%s'\",\n coord_system_name);\n return (-6);\n }\n r = GH->data[CCTK_CoordIndex(-1, \"r\", coord_system_name)][0];\n\n /* see if we have a physical boundary */\n symtable = SymmetryTableHandleForGrid(GH);\n if (symtable < 0)\n CCTK_WARN(0, \"internal error\");\n ierr = Util_TableGetIntArray(symtable, 2 * gdim, symbnd, \"symmetry_handle\");\n if (ierr != 2 * gdim)\n CCTK_WARN(0, \"internal error\");\n for (dim = 0; dim < 2 * gdim; dim++) {\n is_physical[dim] = symbnd[dim] < 0;\n }\n\n /* get the decay rate as a double */\n decay = (double)npow;\n\n /* precompute the distance to all 8 neighbors in a 3D grid */\n dist[0] = 0; /* not used */\n dist[1] = GH->cctk_delta_space[0] / GH->cctk_levfac[0];\n dist[2] = GH->cctk_delta_space[1] / GH->cctk_levfac[1];\n dist[3] = sqrt(SQR(dist[1]) + SQR(dist[2]));\n dist[4] = GH->cctk_delta_space[2] / GH->cctk_levfac[2];\n dist[5] = sqrt(SQR(dist[1]) + SQR(dist[4]));\n dist[6] = sqrt(SQR(dist[2]) + SQR(dist[4]));\n dist[7] = sqrt(SQR(dist[1]) + SQR(dist[2]) + SQR(dist[4]));\n\n /* now loop over all variables */\n for (var = first_var; var < first_var + num_vars; var++) {\n /* Apply condition if:\n + boundary is a physical boundary\n + boundary is an outer boundary\n + have enough grid points\n */\n for (dim = 0; dim < 2 * gdim; dim++) {\n doBC[dim] = is_physical[dim];\n }\n for (dim = 0; dim < gdim; dim++) {\n doBC[dim * 2] &= GH->cctk_lsh[dim] > 1 && GH->cctk_bbox[dim * 2];\n doBC[dim * 2 + 1] &= GH->cctk_lsh[dim] > 1 && GH->cctk_bbox[dim * 2 + 1];\n }\n\n switch (vtype) {\n case CCTK_VARIABLE_REAL:\n ROBIN_BOUNDARY(CCTK_REAL);\n break;\n\n#ifdef HAVE_CCTK_REAL4\n case CCTK_VARIABLE_REAL4:\n ROBIN_BOUNDARY(CCTK_REAL4);\n break;\n#endif\n\n#ifdef HAVE_CCTK_REAL8\n case CCTK_VARIABLE_REAL8:\n ROBIN_BOUNDARY(CCTK_REAL8);\n break;\n#endif\n\n#ifdef HAVE_CCTK_REAL16\n case CCTK_VARIABLE_REAL16:\n ROBIN_BOUNDARY(CCTK_REAL16);\n break;\n#endif\n\n default:\n CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"ApplyBndRobin: Unsupported variable type %d for \"\n \"variable '%s'\",\n CCTK_VarTypeI(var), CCTK_VarName(var));\n return (-4);\n }\n }\n\n return (0);\n}\n\n/*@@\n @routine OldApplyBndRobin\n @date 5 May 2003\n @author David Rideout\n @desc\n The new boundary API expects a 2d-element array for the\n boundary_widths (d=dimension of grid variable), while\n the old API expects a d-element array. This function\n converts the old array to the new format.\n @enddesc\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @var in_widths\n @vdesc boundary width array\n @vtype int [ dimension of variable ]\n @vio in\n @endvar\n @var finf\n @vdesc value of f at infinity\n @vtype CCTK_REAL\n @vio in\n @endvar\n @var npow\n @vdesc power of decay rate\n @vtype int\n @vio in\n @endvar\n @var first_var\n @vdesc index of first variable to apply boundary conditions to\n @vtype int\n @vio in\n @endvar\n @var num_vars\n @vdesc number of variables\n @vtype int\n @vio in\n @endvar\n\n @calls CCTK_GroupIndexFromVarI\n ApplyBndRobin\n @returntype int\n @returndesc\n returncode from @seeroutine ApplyBndRobin\n @endreturndesc\n@@*/\nstatic int OldApplyBndRobin(const cGH *GH, const int *in_widths, CCTK_REAL finf,\n int npow, int first_var, int num_vars) {\n int i, dim, retval;\n CCTK_INT *boundary_widths;\n static int warned;\n\n /* Convert stencil_alldirs to new format */\n dim = CCTK_GroupDimFromVarI(first_var);\n boundary_widths = malloc(2 * dim * sizeof(CCTK_INT));\n for (i = 0; i < 2 * dim; ++i) {\n boundary_widths[i] = in_widths[i / 2];\n }\n\n /* Bug people for using the old interface */\n if (!warned) {\n CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Copied older d-element array of boundary widths into the \"\n \"newer 2d-element format. Please use the new boundary \"\n \"interface to avoid this.\");\n warned = 1;\n }\n\n /* Call ApplyBnd... with new boundary width array */\n retval = ApplyBndRobin(GH, boundary_widths, finf, npow, first_var, num_vars);\n\n free(boundary_widths);\n return retval;\n}\n" }, "test": {}, "doc": { "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{Boundary Conditions}\n\\author{Miguel Alcubierre \\\\ Gabrielle Allen \\\\ Gerd Lanfermann \\\\ David Rideout}\n\\date{$ $Date$ $}\n\n\\maketitle\n\n% Do not delete next line\n% START CACTUS THORNGUIDE\n\n\\begin{abstract}\nProvides a generic interface to boundary conditions, and provides a\nset of standard boundary conditions for one, two, and three\ndimensional grid variables.\n\\end{abstract}\n\n\n\\section{Introduction}\n\nThis thorn provides a generic method for registering routines to perform\nboundary conditions, and selecting variables to have these boundary\nconditions applied to them. In addition, it provides abstraction\nwhich allows all considerations of symmetry to be separated from\nthose of physical boundary conditions.\nThe general idea is that codes which use boundary conditions, be they\nphysical or symmetry conditions, need not know anything about the\nthorns which provide them.\n\nThis thorn also contains some standard boundary conditions, most of which \ncan be used with any spatial dimension and data type.\n\n\\subsection{Local and non-local boundary conditions}\n\nBoundary conditions can be \\emph{local}, meaning that the boundary\npoint can be updated based on data in its immediate vicinity, or\n\\emph{non-local}, meaning that the new value on the boundary depends\non data from a remote region of the computational domain (for a parallel \nsimulation this data could for example be physically located on several different processors). An example\nof the latter is a ``rotating'' symmetry condition, which arises\ne.g.~when one uses a quadrant to simulate a physical domain which\npossesses a rotational symmetry.\n\n\\subsection{Symmetry and physical boundary conditions}\n\n\\emph{Symmetry} boundary conditions are those that arise by viewing\nthe computational domain as a subregion of some larger domain which\npossesses symmetries. These symmetries allow a simulation of the\nsubregion to act as an effective simulation of the larger encompassing\ndomain, because the latter can be inferred from the former via the\nsymmetry. For example, one can often simulate a rotating star by\n`slicing' the space in half through the equatorial plane, simulating\nonly one half, and placing a reflection boundary condition at this\nplane. The symmetry can be regarded as a property of the\nunderlying computational grid upon which the simulation takes place.\n\nIt is often possible to describe the symmetry of a physical problem in\nterms of multiple `simpler' symmetries. Going back to the rotating\nstar example, we can note that there is also a rotational symmetry\nabout the axis of the star. Thus it is sufficient to simulate only\nthe upper half of a $\\phi=\\mbox{const}$ plane of the star, since\nrotational symmetry will recover half of the star from the single\nplane, and the reflection symmetry can recover the other half of the\nstar. To do this we use two symmetry boundary conditions, one for the\nrotational symmetry and one for the reflection symmetry. At the edges\nand corner grid points there will be two symmetry boundary conditions\nactive, which illustrates a general point about symmetry boundary\nconditions, namely that there can be any number of them active at any\ngiven grid point. In addition symmetry boundary conditions are often\nnon-local, for example a periodic boundary condition which applies in\nsimulating plasma in a tokamak.\n\n\\emph{Physical} boundary conditions are motivated by the physics of\nthe quantity that the grid variable represents, such as one which\nallows outgoing waves of a scalar field to propagate off the grid, but\ndoes not allow ingoing waves or reflections. Usually the same\nphysical boundary condition is applied to all external boundaries of\nthe computational domain, however this is not always the case.\nCurrently thorn \\texttt{Boundary} allows a separate boundary condition to be\napplied to each face of the domain, however this is only implemented\nat the moment using the older deprecated interface. Face specific\ncalls will be available using the current interface shortly. It is\nalso possible that one will want to use different physical boundary\nconditions at different regions of a face, and support for this can be\nadded if necessary. Usually physical boundary conditions are local.\nA non-local physical boundary condition may arise e.g.~from a need to\nsolve an elliptic equation at the boundary. As opposed to symmetry\nboundary conditions, it only makes sense to have a single physical\nboundary condition active at a given grid point.\\footnote{It is\npossible that one may wish to modify the value of the field at the\nboundary, after a physical boundary condition has already been\napplied. For example, one may wish to add a small amount of noise at\nthe boundary to test code\nstability. This added `term' is not a physical boundary condition in\nitself, however, and this cannot be registered as such. To implement\nsuch a scheme one would treat the noise in a manner similar to\nsymmetry boundary conditions, scheduling a routine during\n\\texttt{BoundaryConditions} (see below), after \\texttt{Boundary\\_ApplyPhysicalBCs},\nwhich gets the list of selected variables and adds noise to their\nboundaries as desired.}\n\nTo summarize, a `physics' thorn, such as a spacetime evolution thorn,\nknows only about physical boundary conditions. Symmetry boundary\nconditions are aspects of the grid and are managed by other thorns.\n\n\n\\section{The generic boundary interface}\n\nThe implementation \\texttt{Boundary} provides a number of aliased\nfunctions%\\footnote{See appendix \\ref{apx:fn_aliasing} for some notes\n%on using aliased functions.}\n, which allow application thorns to\nregister routines which provide a particular physical boundary\ncondition, and also to select variables or groups of variables to have\nboundary conditions applied to whenever the \\texttt{ApplyBCs} schedule\ngroup is scheduled (see section \\ref{Boundary/sec:schedule_groups}). In addition,\nan aliased function is provided which returns a list of grid variables\nselected for a boundary condition (see appendix \\ref{Boundary/apx:symmetry}).\n\n\\subsection{Boundary condition registration}\n\\label{Boundary/sec:bc_registration}\n\nTo register a routine to provide some physical boundary condition, use\n\\begin{verbatim}\nBoundary_RegisterPhysicalBC(CCTK_POINTER cctkGH, \n phys_bc_fn_ptr function_pointer, \n CCTK_STRING bc_name)\n\\end{verbatim}\nwhere\n\n\\begin{tabular}{ll}\n\\texttt{cctkGH} & pointer to the grid hierarchy\\\\\n\\texttt{function\\_pointer} & pointer to the function providing the\nboundary condition\\\\\n\\texttt{bc\\_name} & name of boundary condition\n\\end{tabular}\n\nThe function pointer takes arguments\n\\begin{verbatim}\n(CCTK_POINTER cctkGH, CCTK_INT num_vars, CCTK_INT *var_indices, \n CCTK_INT *faces, CCTK_INT *widths, CCTK_INT *table_handles)\n\\end{verbatim}\n(this defines the type \\texttt{phys\\_bc\\_fn\\_ptr}, above) where\n\n\\begin{tabular}{ll}\n\\texttt{cctkGH} & pointer to the grid hierarchy\\\\\n\\texttt{num\\_vars} & number of entries passed in the following three arrays\\\\\n\\texttt{var\\_indices} & array of \\texttt{num\\_vars} variable indices selected for this boundary condition\\\\\n\\texttt{faces} & array of \\texttt{num\\_vars} faces specifications\n(see section \\ref{Boundary/sec:faces})\\\\\n\\texttt{widths} & array of \\texttt{num\\_vars} boundary widths (see below)\\\\\n\\texttt{table\\_handles} & array of \\texttt{num\\_vars} table handles%, which hold extra arguments for each application of the boundary condition to a grid variable\n\\end{tabular}\n\nThe table handles hold extra arguments for each application of the boundary condition.\nThe four arrays are sorted first on table handle, and then on\nvariable index. This way variables which have precisely the same\nboundary condition are grouped together, and within this grouping\nvariables are sorted by index, so that variable groups are stored\ntogether. In many cases this sorting will allow a more efficient\nimplementation of the boundary condition. (At the moment it is not\nclear how face information should be considered in the sorting, so it\nis not.) A null pointer can be passed for \\texttt{function\\_pointer},\nin which case no routine is executed when\n\\texttt{Boundary\\_ApplyPhysicalBCs} is called (see section\n\\ref{Boundary/sec:schedule_groups}).\n\n\\subsection{Boundary condition selection}\n\nTo select a grid variable to have a boundary condition applied to it,\nuse one of the following aliased functions:\n\\begin{verbatim}\nBoundary_SelectVarForBC(CCTK_POINTER cctkGH,\n CCTK_INT faces,\n CCTK_INT boundary_width,\n CCTK_INT table_handle, \n CCTK_STRING var_name, \n CCTK_STRING bc_name)\n\nBoundary_SelectVarForBCI(CCTK_POINTER cctkGH,\n CCTK_INT faces,\n CCTK_INT boundary_width,\n CCTK_INT table_handle, \n CCTK_INT var_index, \n CCTK_STRING bc_name)\n\nBoundary_SelectGroupForBC(CCTK_POINTER cctkGH,\n CCTK_INT faces,\n CCTK_INT boundary_width,\n CCTK_INT table_handle, \n CCTK_STRING group_name, \n CCTK_STRING bc_name)\n\nBoundary_SelectGroupForBCI(CCTK_POINTER cctkGH,\n CCTK_INT faces,\n CCTK_INT boundary_width,\n CCTK_INT table_handle, \n CCTK_INT group_index, \n CCTK_STRING bc_name)\n\\end{verbatim}\nwhere\n\n\\begin{tabular}{ll}\n\\texttt{cctkGH} & pointer to the grid hierarchy\\\\\n\\texttt{faces} & set of faces to which to apply the boundary condition\\\\\n\\texttt{boundary\\_width} & width (in grid points) of the boundaries\\\\\n\\texttt{table\\_handle} & handle for table which holds extra arguments for the boundary condition\\\\\n\\texttt{var\\_name} & name of the grid variable\\\\\n\\texttt{bc\\_name} & name of the boundary condition\\\\\n\\texttt{var\\_index} & index of grid variable\\\\\n\\texttt{group\\_name} & name of group of grid variables\\\\\n\\texttt{group\\_index} & index of group of grid variables\n\\end{tabular}\n\nEach of these functions returns 0 for success, or one of the negative error\ncodes below something went wrong.\n\n\\begin{tabular}{|r|l|}\n\\hline\n\\multicolumn{1}{|l|}{\\textbf{error code}} & \\textbf{description} \\\\\n\\hline\n{\\tt -2} & no such physical boundary condition registered \\\\\n{\\tt -3} & faces already selected for bc \\\\\n{\\tt -5} & new value for GH passed in \\\\\n{\\tt -6} & invalid group name or index \\\\\n{\\tt -7} & invalid variable index \\\\\n{\\tt -8} & group has zero vars \\\\\n{\\tt -11} & invalid variable name \\\\\n\\hline\n\\end{tabular}\n\n\\verb|Boundary_SelectVarForBC()| and \\verb|Boundary_SelectVarForBCI()|\nselect a single grid variable for a boundary condition,\nusing either the variable name or index respectively.\n\\verb|Boundary_SelectGroupForBC()| and \\verb|Boundary_SelectGroupForBCI()|\nselect an entire variable group, using either its name or index.\n\nEach of these functions takes a faces specification, a boundary width,\nand a table handle as additional arguments.\nThe faces specification is a single integer which identifies a set of\nfaces to which to apply the boundary condition. See section\n\\ref{Boundary/sec:faces} for details. The boundary width is the thickness,\nin grid points, of the boundaries. \n\nThe table handle identifies a table which\nholds extra arguments for the particular boundary condition that is\nrequested. \nFor example, if a negative value is passed for the boundary width, then the\nboundary condition will look in this table for a $2d$-element integer\narray, which holds the width of each face of the boundary (for a $d$\ndimensional grid variable). (The first element of the array holds the\nwidth of the `-x' face, the second the `+x' face, the third the `-y'\nface, etc.)\n\nIn some cases the table handle is required, so the boundary condition,\nwhen it is called within the \\texttt{BoundaryConditions} schedule\ngroup (see section \\ref{Boundary/sec:schedule_groups}), will return\nan error code. However, in most cases it is optional. If one uses\nan invalid table handle here (such as -1), commonly used default\nvalues will be assumed for all arguments (besides the explicit faces\nspecification and boundary widths). Note that you, the user, will\nbe creating the table, so you may choose whatever options (such as\ncase sensitivity) you like. The case of the keys for which the\nboundary conditions implemented in this thorn search are as given\nin the documentation, which is currently all capitals. To be safe\nyou may choose to create case-insensitive tables, however case\nsensitive tables are slightly faster.\n\nThe name of the boundary condition must match that with which the\nboundary condition providing function was registered. These names are\ncase insensitive. See section \\ref{Boundary/sec:provided_bcs} for a list of\nboundary conditions provided by thorn \\texttt{Boundary}.\n\n\n\\subsection{Schedule groups}\n\\label{Boundary/sec:schedule_groups}\n\nImplementation \\texttt{Boundary} creates two schedule groups\n\\begin{verbatim}\nApplyBCs\n\\end{verbatim}\nand\n\\begin{verbatim}\nBoundaryConditions in ApplyBCs BEFORE Boundary_ClearSelection\n\\end{verbatim}\nand schedules two functions \\texttt{Boundary\\_ApplyPhysicalBCs} in\n\\texttt{BoundaryConditions} and \\texttt{Boundary\\_ClearSelection} in\n\\texttt{ApplyBCs}. \\texttt{Boundary\\_ApplyPhysicalBCs} goes through\nthe list of all selected grid variables, and calls the registered\nfunction corresponding to the requested boundary condition on each.\n\\texttt{Boundary\\_ClearSelection} clears the list of selected grid\nvariables. A thorn which wishes to have boundary conditions applied\nsimply schedules \\texttt{ApplyBCs} at the appropriate point. Please\nschedule it as e.g.~\\verb|_ApplyBCs|, to make each instance\nof it unique.\n\\texttt{Boundary\\_ClearSelection} ensures that each boundary condition\ngets executed exactly once for each selected grid variable.\n\n\n\\subsection{Faces}\n\\label{Boundary/sec:faces}\n\nThe computational domain is assumed to be in the shape of a\n$n$-dimensional `rectangle', which has $2n$ $n-1$ dimensional faces. (Usually $n$\nis three.) Each of these $2n$ faces is assigned a specific bit in a\nword, so that arbitrary subsets can be compactly expressed as a\nbitwise-or of these individual bits. Macros defining this mapping of\nsubsets to bits will be provided.\nFor the moment there is only\n\\texttt{CCTK\\_ALL\\_FACES}, which corresponds to the set of all faces\nof the domain. If you need face specific calls immediately, please\nuse the old interface for now. \n\nThe mapping of bits to faces will likely be the same as that used for\nthe (optional) \\texttt{BOUNDARY\\_WIDTH} array. Precisely, the rule is as\nfollows. For a $d$ dimensional grid variable, label the elements or\nbits by integers $i$ from $0$ to $2d-1$. Element or bit $i$ gets\nmapped to face $(-)^{i+1}e_{\\lfloor i\\rfloor}$, where ${}_{\\lfloor\n\\rfloor}$ designates the `floor' function (greatest integer less than\nits argument), and $e_j$ represents the `$j$-direction' on the grid.\n\n\n\\section{Provided boundary conditions}\n\\label{Boundary/sec:provided_bcs}\nThorn \\texttt{Boundary} also provides seven standard boundary\nconditions, which can be applied to one, two, or three dimensional\ngrid variables. The boundary conditions available are\n\\begin{itemize}\n\\item Scalar\n\\item Flat \n\\item Radiation \n\\item Copy\n\\item Robin\n\\item Static\n\\item None\n\\end{itemize}\n\nRegistration for each of these can be switched off by setting any of\nthe following parameters to ``no'' (each defaults to ``yes'')\n\\begin{itemize}\n\\item \\texttt{register\\_scalar}\n\\item \\texttt{register\\_flat}\n\\item \\texttt{register\\_radiation}\n\\item \\texttt{register\\_copy}\n\\item \\texttt{register\\_robin}\n\\item \\texttt{register\\_static}\n\\item \\texttt{register\\_none}\n\\end{itemize}\nThis is useful if you have your own implementation of one of these\nboundary conditions, which you would like to use instead.\n\n\n\\subsection{General Comments}\n\n%All the boundary conditions here optionally take a stencil\n%size as an argument. The stencil size is used to determine how many\n%points at the boundary should be updated with a boundary condition.\n%For example, a stencil size of two in each direction means that the\n%points at the boundary, as well as the points one in from the boundary\n%will be set by the boundary condition. These boundary points are part\n%of the total number of grid points that you have specified in the\n%beginning of the run. The stencil size is expressed by an array of\n%$n$ integers for an $n$-dimensional grid variable. In the future this\n%will be increased to $2n$ integers, so that one can have a different\n%stencil size on the `plus' and `minus' faces.\nNote that the number of boundary zones, as expressed in the\n\\texttt{boundary\\_width} argument or the \\texttt{BOUNDARY\\_WIDTH}\narray, is taken from the total number of grid points presented by\nCactus through \\texttt{cctk\\_lsh}, etc. \n%In this sense they do not\n%somehow `lie outside the grid', as `external ghostzones'.\n\nFor the moment, these boundary routines may not work properly on\ngrid arrays. \nPlease contact\\\\ \\texttt{cactusmaint@cactuscode.org} if\nyou run into trouble.\n\n\\subsubsection{Old interface}\n\nThe old, direct function call interface to these boundary conditions\nis still available, and is documented here, though it is deprecated\nand will be removed at some point in the future. It is provided for a\nnumber of reasons, the most significant of which is to provide\ncompatibility with existing codes. Another reason why you might\nchoose to use the old interface is if you have difficulty doing your\niterations with the Cactus scheduler, and thus have trouble scheduling\nthe \\texttt{ApplyBCs} schedule group everywhere you need boundary\nconditions applied. A third reason may be that you need face specific\ncalls immediately.\n\nYou should not run into any special difficulty mixing the old and new\ninterface, just be aware of the order in which boundary conditions, and\ncode that depends upon them, are executed.\n\nNote that if you choose to use the old interface for some boundary\nconditions, then the symmetry conditions will not know to apply\nthemselves to those grid variables for which you use the old\ninterface. To get around this difficulty, simply select these grid\nvariables for the ``None'' boundary condition, and be sure that\n\\texttt{ApplyBCs} is scheduled in an appropriate place.\n\nAll routines can be called by\n\\begin{itemize}\n\\item{\\em variable name}: ({\\tt : }) Suffix:\n{\\tt VN}; apply the boundary condition to the variable with the\nspecified name.\n\\item{\\em group name}: ({\\tt :}) Suffix:\n{\\tt GN}; apply the boundary condition to all variables in the group.\n\\item{\\em variable index}: Suffix: {\\tt VI}; apply the boundary\ncondition to the variable with the specified variable index.\n\\item{\\em group index}: Suffix: {\\tt GI} apply the boundary\ncondition to all variables in the group with the specified group index.\n\\end{itemize}\n\nFor the boundary conditions in individual coordinate directions, use\\\\\n\\begin{tabular}{ll}\n{\\tt dir=-1} & to apply at $x=x_{min}$ \\\\\n{\\tt dir= 1} & to apply at $x=x_{max}$ \\\\\n{\\tt dir=-2} & to apply at $y=y_{min}$ \\\\\n{\\tt dir= 2} & to apply at $y=y_{max}$ \\\\\n{\\tt dir=-3} & to apply at $z=z_{min}$ \\\\\n{\\tt dir= 3} & to apply at $z=z_{max}$ \\\\\n\\end{tabular} \n\nPrototypes for each of the functions described for the old interface\nare included in the header file \\texttt{Boundary.h}. Please add\n\\begin{verbatim}\nuses include header: Boundary.h\n\\end{verbatim}\nto your thorn's \\texttt{interface.ccl} to use this header file in your C/C++\nsource files.\n\n\\section{Scalar Boundary Condition}\n\nA scalar boundary condition means that the value of the given \nfield or fields at the boundary is set to a given scalar value, for \nexample zero. The scalar boundary condition is registered under the name ``Scalar''.\n\n\\subsection{Additional arguments}\n\nA table passed to the scalar boundary condition may contain the\nfollowing additional arguments:\\\\[1mm]\n\\begin{tabular}{|l|l|l|l|}\n\\hline\n\\textbf{key} & \\textbf{variable type} & \\textbf{description} & \\textbf{default value}\\\\\n\\hline\nSCALAR & CCTK\\_REAL & the scalar value & 0.0\\\\\nBOUNDARY\\_WIDTH & CCTK\\_INT array & stencil width for each face & n/a\\\\\n\\hline\n\\end{tabular}\n\n\\subsection{Old interface}\n\n\\subsubsection*{Calling from C:}\n\n{\\bf All Coordinate Directions:}\n\\begin{verbatim}\nint ierr = BndScalarVN(cGH *cctkGH, int *stencil_size, \n CCTK_REAL var0, char *variable_name)\nint ierr = BndScalarGN(cGH *cctkGH, int *stencil_size, \n CCTK_REAL var0, char *group_name)\nint ierr = BndScalarVI(cGH *cctkGH, int *stencil_size, \n CCTK_REAL var0, int group_index)\nint ierr = BndScalarGI(cGH *cctkGH, int *stencil_size, \n CCTK_REAL var0, int variable_index)\n\\end{verbatim}\n\n\\noindent\n{\\bf Individual Coordinate Directions:}\n\\begin{verbatim}\nint ierr = BndScalarDirVN(cGH *cctkGH, int stencil, int dir,\n CCTK_REAL var0, char *variable_name)\nint ierr = BndScalarDirGN(cGH *cctkGH, int stencil, int dir,\n CCTK_REAL var0, char *group_name)\nint ierr = BndScalarDirVI(cGH *cctkGH, int stencil, int dir,\n CCTK_REAL var0, int group_index)\nint ierr = BndScalarDirGI(cGH *cctkGH, int stencil, int dir,\n CCTK_REAL var0, int variable_index)\n\\end{verbatim}\n\n\\subsubsection*{Calling from Fortran:}\n{\\bf All Coordinate Directions:}\n\\begin{verbatim}\ncall BndScalarVN(ierr, cctkGH, stencil_size, var0, variable_name)\ncall BndScalarGN(ierr, cctkGH, stencil_size, var0, group_name)\ncall BndScalarVI(ierr, cctkGH, stencil_size, var0, variable_index)\ncall BndScalarGI(ierr, cctkGH, stencil_size, var0, group_index)\n\\end{verbatim}\n\n\\noindent\n{\\bf Individual Coordinate Directions:}\n\\begin{verbatim}\ncall BndScalarDirVN(ierr, cctkGH, stencil, dir, var0, variable_name)\ncall BndScalarDirGN(ierr, cctkGH, stencil, dir, var0, group_name)\ncall BndScalarDirVI(ierr, cctkGH, stencil, dir, var0, variable_index)\ncall BndScalarDirGI(ierr, cctkGH, stencil, dir, var0, group_index)\n\\end{verbatim}\nwhere\n\n{\\tt\n\\begin{tabular}{ll}\ninteger & ierr \\\\\nCCTK\\_POINTER & cctkGH\\\\\ninteger & dir\\\\\ninteger & stencil\\\\\ninteger & stencil\\_size(dim)\\\\\nCCTK\\_REAL & var0 \\\\\ncharacter*(*) & variable\\_name\\\\\ncharacter*(*) & group\\_name\\\\\ninteger & variable\\_index\\\\\ninteger & group\\_index\n\\end{tabular}\n}\n\n\\subsubsection*{Arguments}\n\\begin{tabular}{ll}\n\\texttt{ierr} & Return value, negative value indicates the\nboundary condition was not successfully applied\\\\\n{\\tt cctkGH} & Grid hierarchy pointer\\\\\n{\\tt var0} & Scalar value to apply (For a complex grid function, this is the real part, \\\\\n& the imaginary part is set to zero.)\\\\\n{\\tt dir} & Coordinate direction in which to apply boundary condition\\\\\n{\\tt stencil\\_size} & Array with dimension of the grid function, containing the stencil width\\\\\n{\\tt variable\\_name} & Name of the variable\\\\\n{\\tt group\\_name} & Name of the group\\\\\n{\\tt variable\\_index} & Variable index\\\\\n{\\tt group\\_index} & Group index\n\\end{tabular}\n\n\n\\section{Flat Boundary Condition}\n\nA flat boundary condition means that the value of the given \nfield or fields at the boundary is copied from the value one grid point in,\nin any direction. For example, for a stencil width of one, the\nboundary value of phi {\\tt phi(nx,j,k)}, on the positive x-boundary will\nbe copied from {\\tt phi(nx-1,j,k)}. The flat boundary condition is registered under the name ``Flat''.\n\n\\subsection{Additional arguments}\n\nA table passed to the flat boundary condition may contain the\nfollowing additional arguments:\\\\[1mm]\n\\begin{tabular}{|l|l|l|l|}\n\\hline\n\\textbf{key} & \\textbf{variable type} & \\textbf{description} & \\textbf{default value}\\\\\n\\hline\nBOUNDARY\\_WIDTH & CCTK\\_INT array & stencil width for each face & n/a\\\\\n\\hline\n\\end{tabular}\n\n\\subsection{Old interface}\n\n\\subsubsection*{Calling from C:}\n\n{\\bf All Coordinate Directions:}\n\\begin{verbatim}\nint ierr = BndFlatVN(cGH *cctkGH, int *stencil_size, char *variable_name)\nint ierr = BndFlatGN(cGH *cctkGH, int *stencil_size, char *group_name)\nint ierr = BndFlatVI(cGH *cctkGH, int *stencil_size, int variable_index)\nint ierr = BndFlatGI(cGH *cctkGH, int *stencil_size, int group_index)\n\\end{verbatim}\n\n\\noindent\n{\\bf Individual Coordinate Directions:}\n\\begin{verbatim}\nint ierr = BndFlatDirVN(cGH *cctkGH, int stencil, int dir, char *variable_name)\nint ierr = BndFlatDirGN(cGH *cctkGH, int stencil, int dir, char *group_name)\nint ierr = BndFlatDirVI(cGH *cctkGH, int stencil, int dir, int variable_index)\nint ierr = BndFlatDirGI(cGH *cctkGH, int stencil, int dir, int group_index)\n\\end{verbatim}\n\n\\subsubsection*{Calling from Fortran:}\n\n{\\bf All Coordinate Directions:}\n\\begin{verbatim}\ncall BndFlatVN(ierr, cctkGH, stencil_array, variable_name)\ncall BndFlatGN(ierr, cctkGH, stencil_array, group_name)\ncall BndFlatVI(ierr, cctkGH, stencil_array, variable_index)\ncall BndFlatGI(ierr, cctkGH, stencil_array, group_index)\n\\end{verbatim}\n\n\\noindent\n{\\bf Individual Coordinate Directions:}\n\\begin{verbatim}\ncall BndFlatDirVN(ierr, cctkGH, stencil, dir, variable_name)\ncall BndFlatDirGN(ierr, cctkGH, stencil, dir, group_name)\ncall BndFlatDirVI(ierr, cctkGH, stencil, dir, variable_index)\ncall BndFlatDirGI(ierr, cctkGH, stencil, dir, group_index)\n\\end{verbatim}\nwhere\n\n{\\tt\n\\begin{tabular}{ll}\ninteger & ierr \\\\\nCCTK\\_POINTER & cctkGH\\\\\ninteger & dir\\\\\ninteger & stencil\\\\\ninteger & stencil\\_array(dim)\\\\\ncharacter*(*) & variable\\_name\\\\\ncharacter*(*) & group\\_name\\\\\ninteger & variable\\_index\\\\\ninteger & group\\_index\n\\end{tabular}\n}\n\n\\subsubsection*{Arguments}\n\\begin{tabular}{ll}\n{\\tt ierr} & Return value, negative value indicates the\nboundary condition was not successfully applied\\\\\n{\\tt cctkGH} & Grid hierarchy pointer\\\\\n{\\tt dir} & Coordinate direction in which to apply boundary condition\\\\\n{\\tt stencil\\_size} & Array with dimension of the grid function, containing the stencil width\\\\\n{\\tt variable\\_name} & Name of the variable\\\\\n{\\tt group\\_name} & Name of the group\\\\\n{\\tt variable\\_index} & Variable index\\\\\n{\\tt group\\_index} & Group index\\\\\n\\end{tabular}\n\n\n\\section{Radiation Boundary Condition}\n\nThis is a two level scheme. Grid functions are given for the current time \nlevel (to which the BC is applied) as well as grid functions from a past\ntimelevel which are needed for constructing the boundary condition.\nThe grid function of the past time level needs to have the same\ngeometry. \nCurrently radiative boundary\nconditions can only be applied with a stencil width of one in each\ndirection. \n\nThe radiative boundary condition that is implemented is\n\\begin{equation}\n\\label{Boundary/eq:eqrad}\nf = f_0 + \\frac{u(r-vt)}{r}+\\frac{h(r+vt)}{r}\n\\end{equation}\nThat is, outgoing radial waves with a $1/r$\nfall off, and the correct asymptotic value $f_0$ are assumed, including\nthe possibility of incoming waves\n(these incoming waves should be modeled somehow).\n\nCondition~\\ref{Boundary/eq:eqrad} above leads to the differential equation:\n\\begin{equation}\n\\frac{x^i}{r}\\frac{\\partial f}{\\partial t}\n+ v \\frac{\\partial f}{\\partial x^i}\n+\\frac{v x^i}{r^2} (f-f_0)\n= H \\frac{v x^i}{r^2} \n\\end{equation}\nwhere $x^i$ is the normal direction to the given boundaries,\nand $H = 2 dh(s)/ds$.\n\nAt a given boundary only the derivatives in the normal direction are \nconsidered. Notice that $u(r-vt)$ has disappeared, but we still do \nnot know the value of $H$.\n\nTo get $H$ we do the following: The expression is evaluated one \npoint in from the boundary and solved for $H$ there. Now we need a way of \nextrapolating $H$ to the boundary. For this, assume that \n$H$ falls off as a power law:\n\\begin{equation}\nH = \\frac{k}{r^n} \\qquad \\mbox{which gives} \\qquad d_i H = - n \\frac{H}{r}\n\\end{equation}\nThe value of $n$ is defined by the parameter {\\tt radpower}.\nIf this parameter is negative, $H$ is forced to be zero (this\ncorresponds to pure outgoing waves and is the default).\n\nThe observed behavior is the following: Using $H=0$\nis very stable, but has a very bad initial transient. Taking\n$n$ to be 0 or positive improves the initial behavior considerably,\nbut introduces a drift that can kill an evolution at very late\ntimes. Empirically, the best value found so far is $n=2$, for\nwhich the initial behavior is very nice, and the late time drift \nis quite small.\n\nAnother problem with this condition is that it does not\nuse the physical characteristic speed, but rather it assumes\na wave speed of $v$, so the boundaries should be out in\nthe region where the characteristic speed is constant.\nNotice that this speed does not have to be 1.\n\nThe radiation boundary condition is registered under the name ``Radiation''.\n\n\n\\subsection{Additional arguments}\n\nA table passed to the radiative boundary condition may contain the\nfollowing additional arguments:\\\\[1mm]\n\\begin{tabular}{|l|l|l|l|}\n\\hline\n\\textbf{key} & \\textbf{variable type} & \\textbf{description} & \\textbf{default value}\\\\\n\\hline\nLIMIT & CCTK\\_REAL & $f_0$ & 0.0\\\\\nPREVIOUS\\_TIME\\_LEVEL & CCTK\\_INT or CCTK\\_STRING & GV which holds the & Cactus previous time level\\\\\n&& previous time level&\\\\\nSPEED & CCTK\\_REAL & wave speed $v$& 1.0\\\\\nBOUNDARY\\_WIDTH & CCTK\\_INT array & stencil width for each face & n/a\\\\\n\\hline\n\\end{tabular}\n\\\\[1mm] The default behavior is to use the Cactus previous time level,\nas defined in the \\texttt{interface.ccl} file, for the grid variable\nrequested for the radiative boundary condition. The\n``PREVIOUS\\_TIME\\_LEVEL''\nkey is provided for backward compatibility only, and will be\ndeprecated in the future. The corresponding value may be either a\n\\texttt{CCTK\\_INT}, which will be interpreted as the index of a grid\nvariable holding the previous time level, or a \\texttt{CCTK\\_STRING},\ninterpreted as holding the name. Note that this will not work when\nselecting an entire variable group (with more than one member) with\none call to \\texttt{Boundary\\_SelectGroupForBC*}, as each member will\nhave a separate previous time level, and thus require a separate\ntable. Please make your life easier by using Cactus time levels\\ldots\n\n\n\\subsection{Old interface}\n\n\\subsubsection*{Calling from C:}\n\n{\\bf All Coordinate Directions:}\n\\begin{verbatim}\nint ierr = BndRadiativeVN(cGH *cctkGH, int *stencil_size, \n CCTK_REAL limit, CCTK_REAL speed, \n char *variable_name, char *variable_name_past)\nint ierr = BndRadiativeGN(cGH *cctkGH, int *stencil_size, \n CCTK_REAL limit, CCTK_REAL speed, \n char *group_name, char *group_name_past)\nint ierr = BndRadiativeVI(cGH *cctkGH, int *stencil_size, \n CCTK_REAL limit, CCTK_REAL speed, \n int variable_index, int variable_index_past)\nint ierr = BndRadiativeGI(cGH *cctkGH, int *stencil_size, \n CCTK_REAL limit, CCTK_REAL speed, \n int group_index, int group_index_past)\n\\end{verbatim}\n\n\\noindent\n{\\bf Individual Coordinate Directions:}\n\\begin{verbatim}\nint ierr = BndRadiativeDirVN(cGH *cctkGH, int stencil, int dir,\n CCTK_REAL limit, CCTK_REAL speed, \n char *variable_name, char *variable_name_past)\nint ierr = BndRadiativeDirGN(cGH *cctkGH, int *stencil, int dir, \n CCTK_REAL limit, CCTK_REAL speed, \n char *group_name, char *group_name_past)\nint ierr = BndRadiativeDirVI(cGH *cctkGH, int *stencil, int dir, \n CCTK_REAL limit, CCTK_REAL speed, \n int variable_index, int variable_index_past)\nint ierr = BndRadiativeDirGI(cGH *cctkGH, int *stencil, int dir, \n CCTK_REAL limit, CCTK_REAL speed, \n int group_index, int group_index_past)\n\\end{verbatim}\n\n\\subsubsection*{Calling from Fortran:}\n\n{\\bf All Coordinate Directions:}\n\\begin{verbatim}\ncall BndRadiativeVN(ierr, cctkGH, stencil_size, speed, limit, \n variable_name, variable_name_past)\ncall BndRadiativeGN(ierr, cctkGH, stencil_size, speed, limit, \n group_name, group_name_past)\ncall BndRadiativeVI(ierr, cctkGH, stencil_size, speed, limit, \n variable_index, variable_index_past)\ncall BndRadiativeGI(ierr, cctkGH, stencil_size, speed, limit, \n group_index, group_index_past)\n\\end{verbatim}\n\n\\noindent\n{\\bf Individual Coordinate Directions:}\n\\begin{verbatim}\ncall BndRadiativeDirVN(ierr, cctkGH, stencil, dir, speed, limit, \n variable_name, variable_name_past)\ncall BndRadiativeDirGN(ierr, cctkGH, stencil, dir, speed, limit, \n group_name, group_name_past)\ncall BndRadiativeDirVI(ierr, cctkGH, stencil, dir, speed, limit, \n variable_index, variable_index_past)\ncall BndRadiativeDirGI(ierr, cctkGH, stencil, dir, speed, limit, \n group_index, group_index_past)\n\\end{verbatim}\nwhere\n\n{\\tt\n\\begin{tabular}{ll}\ninteger & ierr \\\\\nCCTK\\_POINTER & cctkGH\\\\\ninteger & dir\\\\\ninteger & stencil\\\\\ninteger & stencil\\_array(dim)\\\\\ncharacter*(*) & variable\\_name\\\\\ncharacter*(*) & group\\_name\\\\\ninteger & variable\\_index\\\\\ninteger & group\\_index\\\\\nCCTK\\_REAL&speed\\\\\nCCTK\\_REAL&limit\\\\\n\\end{tabular}\n}\n\n\\subsubsection*{Arguments}\n\\begin{tabular}{ll}\n{\\tt ierr} & return value, operation failed when return\nvalue {\\em negative}\\\\\n{\\tt cctkGH} & grid hierarchy pointer\\\\\n{\\tt stencil\\_size(dim)} & array of size {\\tt dim}\n(dimension of the grid function).\\\\\n& To how many points from the outer boundary to apply the boundary condition. \\\\\n{\\tt speed} & wave speed used for boundary condition ($v$)\\\\\n{\\tt limit} & asymptotic value of function at infinity ($f_0$)\\\\\n{\\tt variable\\_name} & the name of the grid function\n\tto which the boundary condition will be applied\\\\\n{\\tt variable\\_name\\_past} & The name of the grid function containing the values on the past time level,\\\\\n& needed to calculate the boundary condition.\\\\\n{\\tt group\\_name} & the name of the group to which the boundary condition will be applied\\\\\n{\\tt group\\_name\\_past} & is the name of the group containing the grid functions on the past time level,\\\\\n& needed to calculate the boundary condition.\\\\\n{\\tt variable\\_index} & the index of the grid function to which the boundary condition will be applied\\\\\n{\\tt variable\\_index\\_past} & the index of the grid function containing the values on the past time level,\\\\\n& needed to calculate the boundary condition.\\\\\n{\\tt group\\_index} & the index of the group to which the boundary condition will be applied\\\\\n{\\tt group\\_index\\_past} & the index of the group containing the values on the past time level,\\\\\n& needed to calculate the boundary condition.\\\\\n\\end{tabular}\n\n\n\\section{Copy Boundary Condition}\n\nThis is a two level scheme. Copy the boundary values from a different\ngrid function, for example the previous timelevel. The two grid\nfunctions (or groups of grid functions) must have the same geometry.\nThe copy boundary condition is registered under the name ``Copy''.\n\n\\subsection{Additional arguments}\n\nThe ``COPY\\_FROM'' argument for the copy boundary condition is\nrequired, so a valid table handle is required as well. The keys read are \n\\\\[1mm]\n\\begin{tabular}{|l|l|l|l|}\n\\hline\n\\textbf{key} & \\textbf{variable type} & \\textbf{description} & \\textbf{default value}\\\\\n\\hline\nCOPY\\_FROM & CCTK\\_INT or CCTK\\_STRING & GV to copy from & \\emph{no default}\\\\\nBOUNDARY\\_WIDTH & CCTK\\_INT array & stencil width for each face & n/a\\\\\n\\hline\n\\end{tabular}\n\\\\[1mm]\n(The \\texttt{BOUNDARY\\_WIDTH} table entry is only necessary if\nthe \\texttt{boundary\\_width} parameter is negative.)\n\n\n\\subsection{Old interface}\n\n\\subsubsection*{Calling from C:}\n\\begin{verbatim}\nint ierr = BndCopyVN(cGH *cctkGH, int *stencil_size, \n char *variable_name_to, char *variable_name_from)\nint ierr = BndCopyGN(cGH *cctkGH, int *stencil_size, \n char *group_name_to, char *group_name_from)\nint ierr = BndCopyVI(cGH *cctkGH, int *stencil_size, \n int variable_index_to, int variable_index_from)\nint ierr = BndCopyGI(cGH *cctkGH, int *stencil_size, \n int group_index_to, int group_index_from)\n\\end{verbatim}\n\n\\subsubsection*{Calling from Fortran:}\n\\begin{verbatim}\ncall BndCopyVN(ierr, cctkGH, stencil_size, variable_name_to, \n variable_name_from)\ncall BndCopyVN(ierr, cctkGH, stencil_size, group_name_to, \n group_name_from)\ncall BndCopyVN(ierr, cctkGH, stencil_size, variable_index_to, \n variable_index_from)\ncall BndCopyVN(ierr, cctkGH, stencil_size, group_index_to, \n group_index_from)\n\\end{verbatim}\nwhere\n\n\\begin{tabular}{ll}\n{\\tt integer ierr} & return value, operation failed when return\nvalue {\\em negative}\\\\\n{\\tt CCTK\\_POINTER cctkGH} & grid hierarchy pointer\\\\\n{\\tt integer stencil\\_size(dim)} & array of size {\\tt dim} (dimension of the grid function). To how many points \\\\\n& from the outer boundary to apply the boundary condition. \\\\\n\n{\\tt character*(*) variable\\_name\\_to} & the name of the grid function\n\tto which the boundary condition\\\\\n& will be applied by copying to.\\\\\n{\\tt character*(*) variable\\_name\\_from} & the name of the grid function\n containing the values to copy from.\\\\\n\n{\\tt character*(*) group\\_name\\_to} & the name of the group\n\tto which the boundary condition\\\\\n& will be applied by copying to.\\\\\n{\\tt character*(*) group\\_name\\_from} & the name of the group\n containing the the values to copy from.\\\\\n\n{\\tt integer variable\\_index\\_to} & the index of the grid function\n\tto which the boundary condition\\\\\n& will be applied by copying to.\\\\\n{\\tt integer variable\\_index\\_from} & the index of the grid function\n containing the the values to copy from.\\\\\n\n{\\tt integer group\\_index\\_to} & the index of the group\n\tto which the boundary condition\\\\\n& will be applied by copying to.\\\\\n{\\tt integer group\\_index\\_from} & the index of the group\n containing the the values to copy from.\n\\end{tabular}\n\n\n\\section{Robin Boundary Condition}\n\nThis boundary condition has not yet been implemented in \nindividual coordinate directions.\nThe Robin boundary condition is:\n\\begin{equation}\nf(r) = f_0 + \\frac{k}{r^n}\n\\end{equation}\nwith $k$ a constant, $n$ the decay rate and $f_0$ the value at infinity. This implies:\n\\begin{equation}\n\\frac{\\partial f}{\\partial r} = - n \\frac{k}{r^{n+1}}\n\\end{equation}\nor\n\\begin{equation}\n\\frac{\\partial f}{\\partial r} = - n \\frac{(f-f_0)}{r}\n\\end{equation}\nConsidering now a given Cartesian direction $x$ we get:\n\\begin{equation}\n\\frac{\\partial f}{\\partial x} =\n\\frac{\\partial f}{\\partial r} \n\\frac{\\partial r}{\\partial x} = \\frac{x}{r}\\frac{\\partial f}{\\partial r}\n\\end{equation}\nwhich implies\n\\begin{equation}\n\\frac{\\partial f}{\\partial x} = - n (f-f_0)\\frac{x}{r^2}\n\\end{equation}\nThe equations are then finite differenced around the grid point $i+1/2$:\n\\begin{equation}\nf_{i+1} - f_i = - n \\Delta x \\left( \\frac{1}{2}(f_{i+1}+f_i) - f_0\\right) \\frac{x_{i+1/2}}{r^2_{i+1/2}}\n\\end{equation}\nor\n\\begin{equation}\nf_{i+1}-f_i = -n \\Delta x ( (f_{i+1}+f_i)-2 f_0)\\frac{x_{i+1}+x_i}{(r_{i+1}+r_i)^2}\n\\end{equation}\nAnd this is then solved either for $f_i$ or $f_{i+1}$ depending on which side are\nwe looking at.\n\nThe Robin boundary condition is registered under the name ``Robin''.\n\n\n\\subsection{Additional arguments}\n\nA table passed to the Robin boundary condition may contain the\nfollowing additional arguments:\\\\[1mm]\n\\begin{tabular}{|l|l|l|l|}\n\\hline\n\\textbf{key} & \\textbf{variable type} & \\textbf{description} & \\textbf{default value}\\\\\n\\hline\nFINF & CCTK\\_REAL & $f_0$ & 0\\\\\nDECAY\\_POWER & CCTK\\_INT & $n$ & 1\\\\\nBOUNDARY\\_WIDTH & CCTK\\_INT array & stencil width for each face & n/a\\\\\n\\hline\n\\end{tabular}\n\n\n\\subsection{Old interface}\n\n\\subsubsection*{Calling from C:}\n\n{\\bf All Coordinate Directions:}\n\\begin{verbatim}\nint ierr = BndRobinVN(cGH *cctkGH, int *stencil_size, \n CCTK_REAL finf, int npow, char *variable_name)\nint ierr = BndScalarGN(cGH *cctkGH, int *stencil_size, \n CCTK_REAL finf, int npow, char *group_name)\nint ierr = BndScalarVI(cGH *cctkGH, int *stencil_size, \n CCTK_REAL finf, int npow, int group_index)\nint ierr = BndScalarGI(cGH *cctkGH, int *stencil_size, \n CCTK_REAL finf, int npow, int variable_index)\n\\end{verbatim}\n\n\n\\subsubsection*{Calling from Fortran:}\n{\\bf All Coordinate Directions:}\n\\begin{verbatim}\ncall BndRobinVN(ierr, cctkGH, stencil_size, finf, npow, variable_name)\ncall BndRobinGN(ierr, cctkGH, stencil_size, finf, npow, group_name)\ncall BndRobinVI(ierr, cctkGH, stencil_size, finf, npow, variable_index)\ncall BndRobinGI(ierr, cctkGH, stencil_size, finf, npow, group_index)\n\\end{verbatim}\nwhere\n\n{\\tt\n\\begin{tabular}{ll}\ninteger & ierr \\\\\nCCTK\\_POINTER & cctkGH\\\\\ninteger & stencil\\_size(dim)\\\\\nCCTK\\_REAL & finf \\\\\ninteger & npow \\\\\ncharacter*(*) & variable\\_name\\\\\ncharacter*(*) & group\\_name\\\\\ninteger & variable\\_index\\\\\ninteger & group\\_index\\\\\n\\end{tabular}\n}\n\n\\subsubsection*{Arguments}\n\\begin{tabular}{ll}\n{\\tt ierr} & Return value, negative value indicates the\nboundary condition was not successfully applied\\\\\n{\\tt cctkGH} & Grid hierarchy pointer\\\\\n{\\tt finf} & Scalar value at infinity\\\\\n{\\tt npow} & Decay rate ($n$ in discussion above)\\\\\n{\\tt stencil\\_size} & Array with dimension of the grid function, containing the stencil width to apply the boundary at\\\\\n{\\tt variable\\_name} & Name of the variable\\\\\n{\\tt group\\_name} & Name of the group\\\\\n{\\tt variable\\_index} & Variable index\\\\\n{\\tt group\\_index} & Group index\n\\end{tabular}\n\n\n\\section{Static Boundary Condition}\n\nThe static boundary condition ensures that the boundary values do not\nevolve in time, by copying their values from previous timelevels. The\nstatic boundary condition is registered under the name ``Static''.\n\n\\subsection{Additional arguments}\n\nA table passed to the static boundary condition may contain the\nfollowing additional arguments:\\\\[1mm]\n\\begin{tabular}{|l|l|l|l|}\n\\hline\n\\textbf{key} & \\textbf{variable type} & \\textbf{description} & \\textbf{default value}\\\\\n\\hline\nBOUNDARY\\_WIDTH & CCTK\\_INT array & stencil width for each face & n/a\\\\\n\\hline\n\\end{tabular}\n\n\n\\subsection{Old interface}\n\n\\subsubsection*{Calling from C:}\n\n{\\bf All Coordinate Directions:}\n\\begin{verbatim}\nint ierr = BndStaticVN(cGH *cctkGH, int *stencil_size, char *variable_name)\nint ierr = BndStaticGN(cGH *cctkGH, int *stencil_size, char *group_name)\nint ierr = BndStaticVI(cGH *cctkGH, int *stencil_size, int variable_index)\nint ierr = BndStaticGI(cGH *cctkGH, int *stencil_size, int group_index)\n\\end{verbatim}\n\n\\noindent\n{\\bf Individual Coordinate Directions:}\n\\begin{verbatim}\nint ierr = BndStaticDirVN(cGH *cctkGH, int stencil, int dir, char *variable_name)\nint ierr = BndStaticDirGN(cGH *cctkGH, int stencil, int dir, char *group_name)\nint ierr = BndStaticDirVI(cGH *cctkGH, int stencil, int dir, int variable_index)\nint ierr = BndStaticDirGI(cGH *cctkGH, int stencil, int dir, int group_index)\n\\end{verbatim}\n\n\\subsubsection*{Calling from Fortran:}\n\n{\\bf All Coordinate Directions:}\n\\begin{verbatim}\ncall BndStaticVN(ierr, cctkGH, stencil_array, variable_name)\ncall BndStaticGN(ierr, cctkGH, stencil_array, group_name)\ncall BndStaticVI(ierr, cctkGH, stencil_array, variable_index)\ncall BndStaticGI(ierr, cctkGH, stencil_array, group_index)\n\\end{verbatim}\n\n\\noindent\n{\\bf Individual Coordinate Directions:}\n\\begin{verbatim}\ncall BndStaticDirVN(ierr, cctkGH, stencil, dir, variable_name)\ncall BndStaticDirGN(ierr, cctkGH, stencil, dir, group_name)\ncall BndStaticDirVI(ierr, cctkGH, stencil, dir, variable_index)\ncall BndStaticDirGI(ierr, cctkGH, stencil, dir, group_index)\n\\end{verbatim}\nwhere\n\n{\\tt\n\\begin{tabular}{ll}\ninteger & ierr \\\\\nCCTK\\_POINTER & cctkGH\\\\\ninteger & dir\\\\\ninteger & stencil\\\\\ninteger & stencil\\_array(dim)\\\\\ncharacter*(*) & variable\\_name\\\\\ncharacter*(*) & group\\_name\\\\\ninteger & variable\\_index\\\\\ninteger & group\\_index\\\\\n\\end{tabular}\n}\n\n\\subsubsection*{Arguments}\n\\begin{tabular}{ll}\n{\\tt ierr} & Return value, negative value indicates the\nboundary condition was not successfully applied\\\\\n{\\tt cctkGH} & Grid hierarchy pointer\\\\\n{\\tt dir} & Coordinate direction in which to apply boundary condition\\\\\n{\\tt stencil\\_size} & Array with dimension of the grid function, containing the stencil width to apply the boundary at\\\\\n{\\tt variable\\_name} & Name of the variable\\\\\n{\\tt group\\_name} & Name of the group\\\\\n{\\tt variable\\_index} & Variable index\\\\\n{\\tt group\\_index} & Group index\\\\\n\\end{tabular}\n\n\n\\section{None Boundary Condition}\n\nThe ``None'' boundary condition does just that, nothing. It is\nprovided to inform the boundary implementation of grid variables which\nshould have symmetry boundary conditions applied to them, but do not\nhave their physical boundary conditions applied using a properly\nregistered function.\n\n\\subsection{Additional arguments}\n\nThe none boundary condition will ignore all arguments passed to it.\n(Notably, when registering variables/groups for this boundary condition,\nthe \\verb|boundary_width| and \\verb|table_handle| arguments are unused,\nand may be passed as dummy values.)\n\n\n\\subsection{Old interface}\n\nThere is no old interface to this boundary condition.\n\n\n\\section{Appendix: Symmetry and non-local boundary conditions}\n\\label{Boundary/apx:symmetry}\n\nAn additional aliased function is provided to allow one to retrieve a\nlist of grid variables which are selected for any particular boundary\ncondition, or the entire list of selected grid variables (regardless of\nselected boundary condition). This is needed to write a thorn which\nprovides a symmetry boundary condition, or a non-local boundary\ncondition, as either of these need to schedule a routine in the\n\\texttt{BoundaryConditions} schedule group to execute their condition\non the list of selected variables\\footnote{The consistency of the\nsymmetry conditions scheduled in \\texttt{BoundaryConditions} will be\ntreated in an upcoming ``Symmetry'' implementation}. (A symmetry\nboundary condition will need the entire list of selected variables,\nwhile the non-local physical condition will only need the list of\nvariables which request that particular boundary condition.)\n\n\\begin{verbatim}\nint Boundary_SelectedGVs(CCTK_POINTER cctkGH, \n CCTK_INT array_size,\n CCTK_POINTER var_indices,\n CCTK_POINTER faces,\n CCTK_POINTER boundary_widths,\n CCTK_POINTER table_handles,\n CCTK_STRING bc_name)\n\\end{verbatim}\n\\begin{tabular}{ll}\n\\texttt{cctkGH} & pointer to the grid hierarchy\\\\\n\\texttt{array\\_size} & size of arrays pointed to by the next three arguments\\\\\n\\texttt{var\\_indices} & array of integers into which the selected variables' grid variable indices will be placed\\\\\n\\texttt{faces} & array of integers into which the faces specification for each selected grid variable will be placed\\\\\n\\texttt{boundary\\_widths} & array of integers which holds the \\texttt{boundary\\_width} parameter for each selected GV\\\\\n\\texttt{table\\_handles} & array of integers into which the table handle for each selected grid variable will be placed\\\\\n\\texttt{bc\\_name} & name of boundary condition\n\\end{tabular}\n\nThis function places a list of up to \\texttt{array\\_size} grid\nvariable indices, sorted as described in section\n\\ref{Boundary/sec:bc_registration}, into the array \\texttt{var\\_indices}. The\ncorresponding (up to \\texttt{array\\_size}) faces specifications,\nboundary widths, and table handles are placed into the arrays\n\\texttt{faces}, \\texttt{boundary\\_widths}, and\n\\texttt{table\\_handles}, respectively. (If the list contains\n$n<$\\texttt{array\\_size} elements, then only $n$ elements are placed\ninto the arrays \\texttt{var\\_indices}, \\texttt{faces},\n\\texttt{boundary\\_widths}, and \\texttt{table\\_handles}.) To retrieve\na list of all selected grid variables (for all boundary conditions),\npass a null pointer for \\texttt{bc\\_name}. The return value is the\nnumber elements of the requested list, so\n\\texttt{Boundary\\_SelectedGVs} can be called first with\n\\texttt{var\\_indices} equal to zero to determine how much memory to\nallocate for the arrays \\texttt{var\\_indices}, \\texttt{faces},\n\\texttt{boundary\\_widths}, and \\texttt{table\\_handles}.\n\nA non-local boundary condition must register a null pointer as its\nproviding function in\\\\ \\texttt{Boundary\\_RegisterPhysicalBC}, so that\nits name exists in the database of available boundary conditions, yet\nno extra routine is called when \\texttt{Boundary\\_ApplyPhysicalBCs} is\nexecuted.\n\n% Do not delete next line\n% END CACTUS THORNGUIDE\n\n\\end{document}\n% LocalWords: ApplyBCs cctkGH bc num ApplyPhysicalBCs BoundaryConditions cctk\n% LocalWords: ClearSelection VN GN dir ierr nam nx timelevel vt dh ds radpower\n% LocalWords: GV ccl SelectGroupForBC FINF finf npow timelevels SelectedGVs\n% LocalWords: RegisterPhysicalBC Alcubierre Gerd Lanfermann const\n" } }