aboutsummaryrefslogtreecommitdiff
path: root/src/CopyBoundary.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/CopyBoundary.c')
-rw-r--r--src/CopyBoundary.c176
1 files changed, 167 insertions, 9 deletions
diff --git a/src/CopyBoundary.c b/src/CopyBoundary.c
index 9be745a..864a490 100644
--- a/src/CopyBoundary.c
+++ b/src/CopyBoundary.c
@@ -17,6 +17,9 @@
#include <string.h>
#include "cctk.h"
+#include "cctk_Faces.h"
+#include "util_Table.h"
+#include "util_ErrorCodes.h"
#include "cctk_FortranString.h"
#include "Symmetry.h"
@@ -24,12 +27,175 @@
/* the rcs ID and its dummy function to use it */
static const char *rcsid = "$Header$";
-CCTK_FILEVERSION(CactusBase_Boundary_CopyBoundary_c)
+CCTK_FILEVERSION(CactusBase_Boundary_CopyBoundary_c);
+
+static int ApplyBndCopy (const cGH *GH,
+ int stencil_dir,
+ const int *stencil_alldirs,
+ int dir,
+ int first_var_to,
+ int first_var_from,
+ int num_vars);
/********************************************************************
******************** External Routines ************************
********************************************************************/
+
+/*@@
+ @routine BndCopy
+ @date 13 Feb 2003
+ @author David Rideout
+ @desc
+ Top level function which is registered as handling
+ the Copy boundary condition
+ @enddesc
+ @calls ApplyBndCopy
+ @var GH
+ @vdesc Pointer to CCTK grid hierarchy
+ @vtype const cGH *
+ @vio in
+ @endvar
+ @var num_vars
+ @vdesc number of variables passed in through var_indices[]
+ @vtype int
+ @vio in
+ @endvar
+ @var var_indices
+ @vdesc array of variable indicies to which to apply this boundary
+ condition
+ @vtype int *
+ @vio in
+ @endvar
+ @var faces
+ @vdesc array of set of faces to which to apply the bc
+ @vtype int
+ @vio in
+ @endvar
+ @var table_handles
+ @vdesc array of table handles which hold extra arguments
+ @vtype int
+ @vio in
+ @endvar
+ @returntype int
+ @returndesc
+ return code of @seeroutine ApplyBndScalar
+ -11 invalid table handle
+ -12 no "COPY FROM" key in table
+ @endreturndesc
+@@*/
+
+int BndCopy(const cGH *GH, int num_vars, int *vars, int *faces, int *tables)
+{
+ int i, j, k, gdim, max_gdim, err, value_type, value_size, retval;
+ char *copy_from_name;
+
+ /* variables to pass to ApplyBndCopy */
+ /*int stencil_dir;*/ /* width of stencil in direction dir, not needed */
+ int *stencil_alldirs; /* width of stencil in all directions */
+ int dir; /* direction in which to apply bc */
+ int copy_from; /* variable (index) from which to copy the boundary data */
+
+ retval = 0; stencil_alldirs = NULL;
+
+ /* loop through variables, j at a time */
+ for (i=0; i<num_vars; i+=j) {
+
+ /* find other adjacent vars which are selected for identical bcs */
+ j=1;
+ while (i+j<num_vars && vars[i+j]==vars[i]+j && tables[i+j]==tables[i] &&
+ faces[i+j]==faces[i])
+ {
+ ++j;
+ }
+
+ /* Check to see if faces specification is valid */
+ if (faces[i] != CCTK_ALL_FACES)
+ {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Faces specification %d for Copy boundary conditions on "
+ "%s is not implemented yet. "
+ "Applying radiative bcs to all (external) faces.", faces[i],
+ CCTK_VarName(vars[i]));
+ }
+ dir = 0; /* apply bc to all faces */
+
+ /* Set up default arguments for ApplyBndCopy */
+ /* Allocate memory and populate stencil width array */
+ gdim = CCTK_GroupDimFromVarI(vars[i]);
+ if (!stencil_alldirs)
+ {
+ stencil_alldirs = (int *) malloc(gdim*sizeof(int));
+ max_gdim = gdim;
+ } else if (gdim > max_gdim)
+ {
+ realloc(stencil_alldirs, gdim*sizeof(int));
+ max_gdim = gdim;
+ }
+ for (k=0; k<gdim; ++k)
+ {
+ stencil_alldirs[k] = 1;
+ }
+
+ /* Look on table for copy-from variable and possible non-default arguments
+ */
+ /* Stencil width array */
+ err = Util_TableGetIntArray(tables[i], gdim, stencil_alldirs,
+ "STENCIL WIDTH");
+ if (err == UTIL_ERROR_BAD_HANDLE)
+ {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Invalid table handle passed for Copy boundary "
+ "conditions for %s. Name or index of variable to copy from "
+ "must be provided via key \"COPY FROM\". Aborting.",
+ CCTK_VarName(vars[i]));
+ return -11;
+ } else
+ {
+ if (Util_TableQueryValueInfo(tables[i], &value_type, &value_size,
+ "COPY FROM"))
+ {
+ if (value_type==CCTK_VARIABLE_STRING)
+ {
+ copy_from_name = (char *) malloc(value_size*sizeof(char));
+ Util_TableGetString(tables[i], value_size, copy_from_name,
+ "COPY FROM");
+ copy_from = CCTK_VarIndex(copy_from_name);
+ free(copy_from_name);
+ } else if (value_type==CCTK_VARIABLE_INT)
+ {
+ Util_TableGetInt(tables[i], &copy_from,
+ "COPY FROM");
+ } else
+ {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Invalid data type for key \"COPY FROM\" "
+ "Please use CCTK_STRING for the variable name, "
+ "or CCTK_INT for the variable index.");
+ }
+ } else
+ {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "No key \"COPY FROM\" provided in table. Please enter the "
+ "name or index of variable to copy from into the table "
+ "under this key. Aborting.");
+ return -12;
+ }
+ }
+
+ if (!retval && (retval = ApplyBndCopy(GH, 0, stencil_alldirs, dir,
+ vars[i], copy_from, j)) < 0)
+ {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "ApplyBndCopy() returned %d", retval);
+ }
+ }
+ free(stencil_alldirs);
+
+ return retval;
+}
+
+
/* prototypes for external C routines are declared in header Boundary.h
here only follow the fortran wrapper prototypes */
void CCTK_FCALL CCTK_FNAME (BndCopyDirVI)
@@ -85,14 +251,6 @@ void CCTK_FCALL CCTK_FNAME (BndCopyGN)
/********************************************************************
******************** Internal Routines ************************
********************************************************************/
-static int ApplyBndCopy (const cGH *GH,
- int stencil_dir,
- const int *stencil_alldirs,
- int dir,
- int first_var_to,
- int first_var_from,
- int num_vars);
-
/*@@
@routine BndCopyDirVI