aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrideout <rideout@6a38eb6e-646e-4a02-a296-d141613ad6c4>2002-12-29 17:03:37 +0000
committerrideout <rideout@6a38eb6e-646e-4a02-a296-d141613ad6c4>2002-12-29 17:03:37 +0000
commit8f154b55e17ffe1a01b8388751827d0cccdc475b (patch)
treefd5f8ff4c6fe7ea94ec38574a1a66fab9366feeb
parent6723531f97ceaa24d9dc246bc07d65ff8acd09ad (diff)
Implementation of new boundary condition spec described on the
cactuscode.org development web page. Registers a routine implementing radiative boundary conditions under the boundary condition name "Radiative". The registered routine is a wrapper for the existing radiative boundary conditions. For the moment this uses hard-wired parameters, and calls BndRadiativeVI() sequentially on each variable requested for radiative boundary conditions. git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/Boundary/trunk@186 6a38eb6e-646e-4a02-a296-d141613ad6c4
-rw-r--r--interface.ccl30
-rw-r--r--schedule.ccl25
-rw-r--r--src/Boundary.c945
-rw-r--r--src/Boundary.h5
-rw-r--r--src/RadiationBoundary.c86
-rw-r--r--src/Register.c88
-rw-r--r--src/make.code.defn4
7 files changed, 1180 insertions, 3 deletions
diff --git a/interface.ccl b/interface.ccl
index e8bcdb5..7950d1d 100644
--- a/interface.ccl
+++ b/interface.ccl
@@ -7,3 +7,33 @@ inherits: grid
INCLUDES HEADER: Boundary.h in Boundary.h
USES INCLUDE HEADER: Symmetry.h
+
+
+# Implementation of new boundary spec:
+
+CCTK_INT FUNCTION Boundary_RegisterPhysicalBC CCTK_POINTER GH, \
+ CCTK_FPOINTER function_pointer, CCTK_STRING bc_name
+PROVIDES FUNCTION Boundary_RegisterPhysicalBC WITH \
+ Boundary_Boundary_RegisterPhysicalBC
+USES FUNCTION Boundary_RegisterPhysicalBC
+
+CCTK_INT FUNCTION Boundary_SelectVarForBC CCTK_POINTER GH, \
+ CCTK_INT table_handle, CCTK_STRING var_name, CCTK_STRING bc_name
+CCTK_INT FUNCTION Boundary_SelectVarForBCI CCTK_POINTER GH, \
+ CCTK_INT table_handle, CCTK_INT var_index, CCTK_STRING bc_name
+CCTK_INT FUNCTION Boundary_SelectGroupForBC CCTK_POINTER GH, \
+ CCTK_INT table_handle, CCTK_STRING group_name, CCTK_STRING bc_name
+CCTK_INT FUNCTION Boundary_SelectGroupForBCI CCTK_POINTER GH, \
+ CCTK_INT table_handle, CCTK_INT group_index, CCTK_STRING bc_name
+PROVIDES FUNCTION Boundary_SelectVarForBC WITH Boundary_Boundary_SelectVarForBC
+PROVIDES FUNCTION Boundary_SelectVarForBCI WITH \
+ Boundary_Boundary_SelectVarForBCI
+PROVIDES FUNCTION Boundary_SelectGroupForBC WITH \
+ Boundary_Boundary_SelectGroupForBC
+PROVIDES FUNCTION Boundary_SelectGroupForBCI WITH \
+ Boundary_Boundary_SelectGroupForBCI
+
+CCTK_INT FUNCTION Boundary_SelectedGVs CCTK_POINTER GH, \
+ CCTK_INT array_size, CCTK_POINTER var_indicies, CCTK_POINTER table_handles, \
+ CCTK_STRING bc_name
+PROVIDES FUNCTION Boundary_SelectedGVs WITH Boundary_Boundary_SelectedGVs
diff --git a/schedule.ccl b/schedule.ccl
index 1af3345..d5cbca8 100644
--- a/schedule.ccl
+++ b/schedule.ccl
@@ -1,2 +1,27 @@
# Schedule definitions for thorn Boundary
# $Header$
+
+schedule Boundary_RegisterBCs at CCTK_BASEGRID
+{
+ lang: C
+} "Register boundary conditions that this thorn provides"
+
+# New boundary infrastructure:
+
+schedule GROUP ApplyBCs
+{
+} "Apply boundary conditions"
+
+schedule GROUP BoundaryConditions in ApplyBCs BEFORE Boundary_ClearSelection
+{
+} "Execute all boundary conditions"
+
+schedule Boundary_ApplyPhysicalBCs in BoundaryConditions
+{
+ LANG: C
+} "Apply all requested physical boundary conditions"
+
+schedule Boundary_ClearSelection in ApplyBCs
+{
+ LANG: C
+} "Unselect all grid variables for boundary conditions"
diff --git a/src/Boundary.c b/src/Boundary.c
new file mode 100644
index 0000000..0907d91
--- /dev/null
+++ b/src/Boundary.c
@@ -0,0 +1,945 @@
+ /*@@
+ @file Boundary.c
+ @date Sat Oct 26 22:39:40 CEST 2002
+ @author David Rideout
+ @desc
+ Implements the new boundary specification.
+ @enddesc
+ @version $Header$
+ @@*/
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "cctk.h"
+#include "cctk_Arguments.h"
+#include "util_Table.h"
+#include "util_String.h"
+
+static const char *rcsid = "$Header$";
+
+CCTK_FILEVERSION(CactusBase_Boundary_Boundary_c);
+
+/********************************************************************
+ ********************* Local Data Types ***********************
+ ********************************************************************/
+/*#define DEBUG 1*/
+#ifdef STRBUFFSIZE
+Size of string buffers. Max length of variable name is 28+32+2.
+#else
+#define STRBUFFSIZE 63
+#endif
+
+/* pointer to function which implements the boundary condition: */
+typedef int (*phys_bc_fn_ptr)(const cGH *, int, int *, int *);
+
+/* Linked list for holding variables selected for a bc:
+ * Entries are sorted in the order they appear in struct BCVAR,
+ * i.e. the var_index varies most rapidly, and bc_name least rapidly.
+ */
+struct BCVAR
+{
+ struct BCVAR *next_entry;
+ char *bc_name;
+ /* CCTK_FPOINTER bc_fn_pointer; // store fn pointers, since they are
+ easier to sort? */
+ int table;
+ int var_index;
+};
+
+/*
+ * Linked list of pointers to the
+ * first entry marked for bc 'A', the first marked for bc 'B', etc.
+ * This will speed both adding entries and retreiving them. One could
+ * also provide a pointer to the first entry with bc 'B', table handle
+ * 12. For now, since usually all bcs are marked for the same bc, I
+ * won't bother to implement this.
+ *
+ * Here is also recorded how many of each bc type have
+ * been selected so far, so that the GetSelectedBCs doesn't have to be
+ * run through twice; once simply to get the number of selected vars!
+ *
+ * Could also save a string comparison at each iteration of
+ * Boundary_Boundary_SelectedGVs() if we also store and manage bcdata->stop.
+ */
+struct BCDATA
+{
+ struct BCDATA *next;
+ const char *bc_name; /* name of bc */
+ struct BCVAR *start; /* start of this bc in BCVAR list */
+ int num; /* number of entries for this bc in BCVAR list */
+};
+
+/********************************************************************
+ ********************* Local Routine Prototypes *********************
+ ********************************************************************/
+
+int entry_less_than(struct BCVAR *new, struct BCVAR *current);
+
+/********************************************************************
+ ***************** Aliased Routine Prototypes ***********************
+ ********************************************************************/
+
+CCTK_INT Boundary_Boundary_RegisterPhysicalBC(CCTK_POINTER GH,
+ CCTK_FPOINTER fn_pointer,
+ CCTK_STRING bc_name);
+CCTK_INT Boundary_Boundary_SelectVarForBC(CCTK_POINTER GH,
+ CCTK_INT table_handle,
+ CCTK_STRING var_name,
+ CCTK_STRING bc_name);
+CCTK_INT Boundary_Boundary_SelectVarForBCI(CCTK_POINTER GH,
+ CCTK_INT table_handle,
+ CCTK_INT var_index,
+ CCTK_STRING bc_name);
+CCTK_INT Boundary_Boundary_SelectGroupForBC(CCTK_POINTER GH,
+ CCTK_INT table_handle,
+ CCTK_STRING group_name,
+ CCTK_STRING bc_name);
+CCTK_INT Boundary_Boundary_SelectGroupForBCI(CCTK_POINTER GH,
+ CCTK_INT table_handle,
+ CCTK_INT group_index,
+ CCTK_STRING bc_name);
+CCTK_INT Boundary_Boundary_SelectedGVs(CCTK_POINTER GH, CCTK_INT array_size,
+ CCTK_POINTER var_indices,
+ CCTK_POINTER table_handles,
+ CCTK_STRING bc_name);
+
+/********************************************************************
+ ***************** Scheduled Routine Prototypes *********************
+ ********************************************************************/
+
+void Boundary_ApplyPhysicalBCs(CCTK_ARGUMENTS);
+void Boundary_ClearSelection(void);
+
+/********************************************************************
+ ********************* Other Routine Prototypes *********************
+ ********************************************************************/
+
+/********************************************************************
+ ********************* Local Data *****************************
+ ********************************************************************/
+
+/* Table for holding function pointers associated with each boundary condition:
+ * This table has
+ * key = boundary condition name (eg "Radiative")
+ * value = a CCTK_FPOINTER pointing to a function to implement that BC
+ */
+static int physbc_table_handle = -1;
+
+/* Linked list for storing selected vars data */
+static struct BCVAR *selections_list = NULL;
+
+/* Linked list for storing data associated with selections list itself */
+static struct BCDATA *bcdata_list = NULL;
+
+
+/********************************************************************
+ ********************* Aliased Routines **********************
+ ********************************************************************/
+
+ /*@@
+ @routine Boundary_Boundary_RegisterPhysicalBC
+ @date Sun Nov 3 19:51:37 CET 2002
+ @author David Rideout
+ @desc
+ Used to register physical boundary conditions with the boundary
+ thorn.
+ @enddesc
+ @calls
+ @history
+ @endhistory
+ @var GH
+ @vdesc cctkGH *
+ @vtype CCTK_POINTER
+ @vio in
+ @endvar
+ @var fn_pointer
+ @vdesc pointer to function which implements boundary condition bc_name
+ @vtype CCTK_FPOINTER
+ @vio in
+ @endvar
+ @var bc_name
+ @vdesc name of boundary condition
+ @vtype CCTK_STRING
+ @vio in
+ @endvar
+ @returntype CCTK_INT
+ @returndesc
+ 0 success
+ -1 error creating table to hold bcs
+ -2 duplicate registration of bc_name
+ -3 error adding bc to table
+ @endreturndesc
+@@*/
+CCTK_INT Boundary_Boundary_RegisterPhysicalBC(CCTK_POINTER GH,
+ CCTK_FPOINTER fn_pointer,
+ CCTK_STRING bc_name)
+{
+ int retval;
+
+ /* Ignore GH for now */
+ GH = GH;
+
+ /* Check input arguments */
+ if (!fn_pointer)
+ {
+ CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Null pointer passed to Boundary_RegisterPhysicalBC. "
+ "Is this intentional?");
+ }
+
+ /* Create the registered routines table if necessary */
+ if (physbc_table_handle == -1)
+ {
+ physbc_table_handle = Util_TableCreate(UTIL_TABLE_FLAGS_DEFAULT);
+ if (physbc_table_handle<0)
+ {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Error creating table to hold registered physical boundary "
+ "conditions");
+ retval = -1;
+ }
+ }
+
+ /* Check if boundary condition has already been registered under this name */
+ if (Util_TableGetFnPointer(physbc_table_handle, NULL, bc_name)>=0)
+ {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "There already exists a physical boundary condition "
+ "registered under the name \"%s\"", bc_name);
+ retval = -2;
+ } else
+ {
+ /* Add boundary condition to table */
+ if (Util_TableSetFnPointer(physbc_table_handle, fn_pointer, bc_name)<0)
+ {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Error adding boundary condition to table");
+ retval = -3;
+ }
+ retval = 0;
+ }
+
+ return retval;
+}
+
+ /*@@
+ @routine Boundary_Boundary_SelectVarForBC
+ @date Sun Nov 3 19:51:37 CET 2002
+ @author David Rideout
+ @desc
+ Used to select a Cactus variable to have boundary
+ conditions applied, using its variable name.
+ @enddesc
+ @calls
+ @history
+ @endhistory
+ @var GH
+ @vdesc cctkGH *
+ @vtype CCTK_POINTER
+ @vio in
+ @endvar
+ @var table_handle
+ @vdesc handle of table which holds arguments to be passed to bc
+ @vtype CCTK_INT
+ @vio in
+ @endvar
+ @var var_name
+ @vdesc name of variable to which to apply bc
+ @vtype CCTK_STRING
+ @vio in
+ @endvar
+ @var bc_name
+ @vdesc name of bc to apply
+ @vtype CCTK_STRING
+ @vio in
+ @endvar
+ @returntype CCTK_INT
+ @returndesc
+ 0 success
+ -3 invalid variable name
+ or the returncode of @seeroutine Boundary_Boundary_SelectVarForBCI
+ @endreturndesc
+@@*/
+CCTK_INT Boundary_Boundary_SelectVarForBC(CCTK_POINTER GH,
+ CCTK_INT table_handle,
+ CCTK_STRING var_name,
+ CCTK_STRING bc_name)
+{
+ int retval, var_index;
+
+ retval = 0;
+
+ var_index = CCTK_VarIndex(var_name);
+ if (var_index<0) {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Invalid variable name");
+ retval = -3;
+ } else
+ {
+ retval = Boundary_Boundary_SelectVarForBCI(GH, table_handle, var_index,
+ bc_name);
+ }
+
+ return retval;
+}
+
+ /*@@
+ @routine Boundary_Boundary_SelectVarForBCI
+ @date Sun Nov 3 19:51:37 CET 2002
+ @author David Rideout
+ @desc
+ Used to select a Cactus variable to have boundary
+ conditions applied, using its var index.
+ @enddesc
+ @calls
+ @history
+ @endhistory
+ @var GH
+ @vdesc cctkGH *
+ @vtype CCTK_POINTER
+ @vio in
+ @endvar
+ @var table_handle
+ @vdesc handle of table which holds arguments to be passed to bc
+ @vtype CCTK_INT
+ @vio in
+ @endvar
+ @var var_index
+ @vdesc index of variable to which to apply bc
+ @vtype CCTK_INT
+ @vio in
+ @endvar
+ @var bc_name
+ @vdesc name of bc to apply
+ @vtype CCTK_STRING
+ @vio in
+ @endvar
+ @returntype CCTK_INT
+ @returndesc
+ 0 success
+ -1 error allocating memory for new entry in selected variables database
+ -2 no such physical boundary condition registered
+ -4 error allocating memory for new entry in 'bcdata' database
+ -5 error allocating memory for new entry in 'bcdata' database
+ @endreturndesc
+@@*/
+CCTK_INT Boundary_Boundary_SelectVarForBCI(CCTK_POINTER GH,
+ CCTK_INT table_handle,
+ CCTK_INT var_index,
+ CCTK_STRING bc_name)
+{
+ int retval;
+ struct BCVAR *new_entry;
+ struct BCVAR *current;
+ struct BCVAR *previous;
+ struct BCDATA *current_bcdata;
+
+ retval = 0;
+ current = NULL;
+ previous = NULL;
+
+#ifdef DEBUG
+ printf("Boundary_Boundary_SelectVarForBCI: called with table_handle=%d, var_index=%d, bc_name=%s\n", table_handle, var_index, bc_name);
+#endif
+
+ /* Ignore GH */
+ GH = GH;
+
+ /* Has some function implementing bc_name been registered? */
+ if (!Util_TableQueryValueInfo(physbc_table_handle, NULL, NULL,
+ bc_name))
+ {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "There is no function implementing the physical boundary "
+ "condition %s", bc_name);
+ retval = -2;
+ }
+
+ /* allocate memory for new entry in database */
+ new_entry = (struct BCVAR *) malloc(sizeof(struct BCVAR));
+ if (!new_entry)
+ {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Unable to allocate memory for entry into "
+ "'selected for bcs' database");
+ retval = -1;
+ }
+#ifdef DEBUG
+ printf("Boundary_Boundary_SelectVarForBCI: new entry in list will be stored at %p\n", new_entry);
+#endif
+
+ /* populate new entry with data */
+ new_entry -> bc_name = Util_Strdup(bc_name);
+ new_entry -> table = table_handle;
+ new_entry -> var_index = var_index;
+#ifdef DEBUG
+ printf("Boundary_Boundary_SelectVarForBCI: sucessfully stored data in new entry\n");
+#endif
+
+ /* Use bcdata list to jump to appropriate 'sector' of selections list */
+ for (current_bcdata = bcdata_list;
+ current_bcdata;
+ current_bcdata = current_bcdata->next)
+ {
+#ifdef DEBUG
+ printf("Boundary_Boundary_SelectVarForBCI: looping through bcdata list, at current_bcdata=%p\n",current_bcdata);
+#endif
+
+ if (CCTK_Equals(current_bcdata->bc_name,bc_name))
+ {
+ current = bcdata_list->start;
+ }
+ }
+
+ if (!current && current_bcdata) /* bc_name was not found in bcdata_list,
+ and bc_data list exists */
+ {
+ /* new bc_name. Add entry to bcdata list. */
+ bcdata_list = (struct BCDATA *) malloc(sizeof(struct BCDATA));
+ if (!bcdata_list) {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Unable to allocate memory for internal 'bcdata' list");
+ retval = -4;
+ } else
+ {
+ current_bcdata->next = bcdata_list;
+ bcdata_list->next = NULL;
+ bcdata_list->bc_name = bc_name;
+ bcdata_list->start = selections_list; /* start it at the beginning of
+ selections list for now */
+ bcdata_list->num = 0; /* This gets incremented after the for(;;) loop
+ below */
+ }
+ } else
+ {
+ /* bc_name does not appear in bcdata_list, so start at beginning */
+ current = selections_list;
+ }
+
+ /* enter into correct location in linked list */
+ for (; /* starting value for current is selected using the bcdata
+ list, above */
+ current && entry_less_than(new_entry,current);
+ previous = current, current = current->next_entry)
+ {
+ }
+
+ /* check to see if this is the first entry */
+ if (selections_list)
+ {
+ /* enter new_entry here */
+ if (previous)
+ {
+ /* previous==NULL if this is put in the front of a one entry list */
+ previous->next_entry = new_entry;
+ }
+ new_entry->next_entry = current;
+ if (!previous)
+ {
+ /* previous==NULL ==> never got to for(;;) increment step ==>
+ goes in front of bcdata->start for this bc_name */
+ bcdata_list->start = new_entry;
+ bcdata_list->num++;
+ }
+ } else
+ {
+#ifdef DEBUG
+ printf("Boundary_Boundary_SelectVarForBCI: starting new selections list\n");
+#endif
+
+ /* first entry */
+ new_entry-> next_entry = NULL;
+ selections_list = new_entry;
+
+ /* create bcdata list too */
+ bcdata_list = (struct BCDATA *) malloc(sizeof(struct BCDATA));
+ if (!bcdata_list)
+ {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Unable to allocate memory for internal 'bcdata' list");
+ retval = -5;
+ }
+ bcdata_list->next = NULL;
+ bcdata_list->bc_name = bc_name;
+ bcdata_list->start = new_entry;
+ bcdata_list->num = 1; /* This is incremented upon creation, since we
+ are about to exit this function() */
+ }
+
+ return retval;
+}
+
+ /*@@
+ @routine Boundary_Boundary_SelectGroupForBC
+ @date Thu Dec 26 21:45:34 CET 2002
+ @author David Rideout
+ @desc
+ Used to select a Cactus variable group to have boundary
+ conditions applied, using the group name.
+ @enddesc
+ @calls
+ @history
+ @endhistory
+ @var GH
+ @vdesc cctkGH *
+ @vtype CCTK_POINTER
+ @vio in
+ @endvar
+ @var table_handle
+ @vdesc handle of table which holds arguments to be passed to bc
+ @vtype CCTK_INT
+ @vio in
+ @endvar
+ @var group_name
+ @vdesc name of group to which to apply bc
+ @vtype CCTK_STRING
+ @vio in
+ @endvar
+ @var bc_name
+ @vdesc name of bc to apply
+ @vtype CCTK_STRING
+ @vio in
+ @endvar
+ @returntype CCTK_INT
+ @returndesc
+ 0 success
+ -6 invalid group name
+ or the returncode of @seeroutine Boundary_Boundary_SelectGroupForBCI
+ @endreturndesc
+@@*/
+CCTK_INT Boundary_Boundary_SelectGroupForBC(CCTK_POINTER GH,
+ CCTK_INT table_handle,
+ CCTK_STRING group_name,
+ CCTK_STRING bc_name) {
+ int retval, gi;
+
+ retval = 0;
+
+ /* get group index */
+ gi = CCTK_GroupIndex(group_name);
+ if (!gi)
+ {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Invalid group name %s\n", group_name);
+ retval = -6;
+ } else
+ {
+ /* call Boundary_Boundary_SelectGroupForBCI() */
+ retval = Boundary_Boundary_SelectGroupForBCI(GH, table_handle, gi,
+ bc_name);
+ }
+
+ return retval;
+}
+
+ /*@@
+ @routine Boundary_Boundary_SelectGroupForBCI
+ @date Thu Dec 26 21:45:34 CET 2002
+ @author David Rideout
+ @desc
+ Used to select a Cactus variable group to have boundary
+ conditions applied, using the group index.
+ @enddesc
+ @calls
+ @history
+ @endhistory
+ @var GH
+ @vdesc cctkGH *
+ @vtype CCTK_POINTER
+ @vio in
+ @endvar
+ @var table_handle
+ @vdesc handle of table which holds arguments to be passed to bc
+ @vtype CCTK_INT
+ @vio in
+ @endvar
+ @var group_index
+ @vdesc index of group to which to apply bc
+ @vtype CCTK_INT
+ @vio in
+ @endvar
+ @var bc_name
+ @vdesc name of bc to apply
+ @vtype CCTK_STRING
+ @vio in
+ @endvar
+ @returntype CCTK_INT
+ @returndesc
+ 0 success
+ -7 invalid group index
+ or the returncode of @seeroutine Boundary_Boundary_SelectVarForBCI
+ @endreturndesc
+@@*/
+CCTK_INT Boundary_Boundary_SelectGroupForBCI(CCTK_POINTER GH,
+ CCTK_INT table_handle,
+ CCTK_INT group_index,
+ CCTK_STRING bc_name) {
+ int num_vars, vi, max_vi, retval;
+
+ /* Get var indices from group name */
+ num_vars = CCTK_NumVarsInGroupI(group_index);
+ if (num_vars<0)
+ {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Invalid variable index");
+ retval = -7;
+ }
+
+ /* loop over variables in group */
+ vi = CCTK_FirstVarIndexI(group_index);
+ max_vi = vi + num_vars;
+ for (; vi<max_vi; ++vi)
+ {
+ retval = Boundary_Boundary_SelectVarForBCI(GH, table_handle, vi, bc_name);
+ }
+
+ return retval;
+}
+
+ /*@@
+ @routine Boundary_Boundary_SelectedGVs
+ @date Sun Nov 3 19:51:37 CET 2002
+ @author David Rideout
+ @desc
+ Returns list of variable indices and table handles of
+ variables selected for boundary conditions.
+ @enddesc
+ @calls
+ @history
+ @endhistory
+ @var GH
+ @vdesc cctkGH *
+ @vtype CCTK_POINTER
+ @vio in
+ @endvar
+ @var array_size
+ @vdesc size of arrays to which var_indices and table_handles point
+ @vtype CCTK_INT
+ @vio in
+ @endvar
+ @var var_indices
+ @vdesc array into which selected variable indices will be placed
+ @vtype CCTK_INT
+ @vio out
+ @endvar
+ @var table_handles
+ @vdesc array into which table_handles for variables selected for bc
+ will be placed
+ @vtype CCTK_INT
+ @vio out
+ @endvar
+ @var bc_name
+ @vdesc name of bc for which to get the selected vars,
+ NULL returns all selected vars for all bcs
+ @vtype CCTK_STRING
+ @vio in
+ @endvar
+ @returntype CCTK_INT
+ @returndesc
+ number of variables selected for bc_name
+ @endreturndesc
+@@*/
+CCTK_INT Boundary_Boundary_SelectedGVs(CCTK_POINTER GH,
+ CCTK_INT array_size,
+ CCTK_POINTER var_indices,
+ CCTK_POINTER table_handles,
+ CCTK_STRING bc_name) {
+ int retval;
+ struct BCVAR *current;
+ struct BCDATA *current_bcdata;
+
+ current = NULL;
+ retval = 0;
+
+ /* Ignore GH */
+ GH = GH;
+
+#ifdef DEBUG
+ printf("Boundary_Boundary_SelectedGVs: called with bc_name=\"%s\" array_size=%d\n", bc_name, array_size);
+#endif
+ if (bc_name)
+ {
+ /* If bc_name is non-NULL, use bcdata list to find starting point */
+ for (current_bcdata = bcdata_list;
+ current_bcdata;
+ current_bcdata = current_bcdata->next)
+ {
+
+#ifdef DEBUG
+ printf("Boundary_Boundary_SelectedGVs: looping through bcdata list\n"
+ " current_bcdata->bc_name=\"%s\"\n",
+ current_bcdata->bc_name);
+#endif
+
+ if (CCTK_Equals(current_bcdata->bc_name,bc_name))
+ {
+
+#ifdef DEBUG
+ printf("Boundary_Boundary_SelectedGVs: strings match, using this start value\n");
+#endif
+ /* If bc_name matches, use this entry to set current */
+ current = current_bcdata->start;
+ break;
+ }
+ }
+#ifdef DEBUG
+ printf("Boundary_Boundary_SelectedGVs: initializing current to %p\n",
+ current);
+#endif
+ /* Do we want to return an error code if an 'invalid' bc_name is used?
+ * if (!current)
+ * {
+ * CCTK_VWarn(2, __LINE__, __FILE__, CCTK_THORNSTRING,
+ * "No variables are marked for boundary condition %s", bc_name);
+ * retval = -1;
+ * }
+ */
+ } else
+ {
+ /* If bc_name is NULL then start from the beginning */
+ current = selections_list;
+ }
+
+ /* If current is still NULL, bc_name did not match any entry in the
+ * bcdata list, i.e. no variables were selected for this bc.
+ */
+ if (current)
+ {
+ /* loop through selections list, grabbing entries with bc_name, or
+ * all if bc_name==NULL
+ *
+ * could save a string comparison at each iteration if we also
+ * stored bcdata->end
+ */
+ for (;
+ current;
+ current = current->next_entry)
+ {
+ if (!bc_name || CCTK_Equals(current->bc_name, bc_name))
+ {
+ if (retval < array_size)
+ {
+ ((int *) table_handles)[retval] = current->table;
+ ((int *) var_indices)[retval] = current->var_index;
+ }
+ ++retval;
+ } else if (retval)
+ {
+ /* can stop looking if we are past the relevant section of the
+ list */
+ break;
+ }
+ }
+ }
+
+ return retval;
+}
+
+
+/********************************************************************
+ ********************* Scheduled Routines **********************
+ ********************************************************************/
+
+ /*@@
+ @routine Boundary_ApplyPhysicalBCs
+ @date Sun Nov 3 19:51:37 CET 2002
+ @author David Rideout
+ @desc
+ This will apply all requested physical boundary conditions.
+ @enddesc
+ @calls
+ @history
+ @endhistory
+ @var CCTK_ARGUMENTS
+ @vdesc Cactus argument list
+ @vtype CCTK_*
+ @vio in
+ @endvar
+ @returntype void
+ @returndesc
+ @endreturndesc
+@@*/
+
+void Boundary_ApplyPhysicalBCs(CCTK_ARGUMENTS) {
+ DECLARE_CCTK_ARGUMENTS;
+ phys_bc_fn_ptr bc_fn;
+ int num_vars, *vars, *tables, err, max_num_vars;
+ struct BCDATA *current_bcdata;
+
+ max_num_vars = 0;
+
+ /* Step through each requested physical boundary condition */
+ for (current_bcdata = bcdata_list;
+ current_bcdata;
+ current_bcdata = current_bcdata->next)
+ {
+#ifdef DEBUG
+ printf("Boundary_ApplyPhysicalBCs: current_bcdata %p holds: next=%p bc_name=%s start=%p num=%d\n",
+ current_bcdata, current_bcdata->next, current_bcdata->bc_name,
+ current_bcdata->start, current_bcdata->num);
+#endif
+
+ /* Allocate memory to hold selected bcs */
+ num_vars = current_bcdata->num;
+ if (num_vars > max_num_vars) {
+ max_num_vars = num_vars;
+ vars = (int *) malloc(num_vars*sizeof(int));
+ tables = (int *) malloc(num_vars*sizeof(int));
+ }
+
+ /* get selected vars for this bc_name*/
+ err = Boundary_Boundary_SelectedGVs(cctkGH, num_vars, vars, tables,
+ current_bcdata->bc_name);
+ if (err<0) /* This is a redundant test for now, Boundary_Boundary_SelectedGVs never returns <0 */
+ {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Error in Boundary_SelectedGVs for %s boundary condition",
+ current_bcdata->bc_name);
+ } else if (err != num_vars)
+ {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Boundary_SelectedGVs returned %d selected variables for "
+ "\"%s\" boundary condition, but %d expected\n", err,
+ current_bcdata->bc_name, num_vars);
+ }
+
+ /* Get the fn ptr for the bc*/
+#ifdef DEBUG
+ printf("Boundary_ApplyPhysicalBCs: current_bcdata->bc_name=\"%s\"\n",
+ current_bcdata->bc_name);
+#endif
+ err = Util_TableGetFnPointer(physbc_table_handle, (CCTK_FPOINTER *)&bc_fn,
+ current_bcdata->bc_name);
+ if (err<0)
+ {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Boundary_ApplyPhysicalBCs: Util_TableGetFnPointer "
+ "returned %d", err);
+ }
+
+ /* Apply bc to vi */
+#ifdef DEBUG
+ printf("Attempting to call boundary condition!\n"
+ "Using function pointer %p with arguments %p, %d, vars, tables\n",
+ (void *) bc_fn, (const void *) cctkGH, num_vars);
+#endif
+ err = (*bc_fn)(cctkGH, num_vars, vars, tables);
+ if (err<0)
+ {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Function associated with boundary condition %s returned %d",
+ current_bcdata->bc_name, err);
+ }
+ }
+
+ /* Free data */
+ free(vars);
+ free(tables);
+}
+
+ /*@@
+ @routine Boundary_ClearSelection
+ @date Sun Nov 3 19:51:37 CET 2002
+ @author David Rideout
+ @desc
+ Clears all boundary condition selections.
+ @enddesc
+ @calls
+ @history
+ @endhistory
+@@*/
+
+void Boundary_ClearSelection(void) {
+ struct BCVAR *current, *next;
+ struct BCDATA *current_bcdata, *next_bcdata;
+
+ /* Free selections list */
+ next = selections_list;
+ for (current = selections_list; next; current = next) {
+ next = current->next_entry;
+ free(current->bc_name);
+ free(current);
+ }
+ selections_list = NULL;
+
+ /* Free bcdata list */
+#ifdef DEBUG
+ printf("Boundary_ClearSelection: looping through bcdata list for freeing\n");
+#endif
+ next_bcdata = bcdata_list; /* simply so that it will be non-NULL */
+ for (current_bcdata = bcdata_list; next_bcdata; current_bcdata = next_bcdata)
+ {
+ next_bcdata = current_bcdata->next;
+ /* free(current_bcdata->bc_name); Must one free this? */
+#ifdef DEBUG
+ printf("Boundary_ClearSelection: freeing %p\n",current_bcdata);
+#endif
+ free(current_bcdata);
+ }
+ bcdata_list = NULL;
+}
+
+/********************************************************************
+ ********************* Local Routines *************************
+ ********************************************************************/
+
+ /*@@
+ @routine entry_less_than
+ @date Sun Nov 3 19:51:37 CET 2002
+ @author David Rideout
+ @desc
+ Sorts entries in selections list
+ @enddesc
+ @calls
+ @history
+ @endhistory
+ @var new
+ @vdesc new entry to be inserted into selections list
+ @vtype struct BCVAR *
+ @vio in
+ @endvar
+ @var current
+ @vdesc entry in selections list to which to compare new
+ @vtype struct BCVAR *
+ @vio in
+ @endvar
+ @returntype CCTK_INT
+ @returndesc
+ -1 new equals current
+ 0 new 'greater than' current
+ 1 new 'less than' current
+ 2 new and current have same bc_name, but new has smaller table
+ handle
+ 3 new and current have same bc_name and table handle, but new
+ has smaller variable index
+ @endreturndesc
+@@*/
+int entry_less_than(struct BCVAR *new, struct BCVAR *current) {
+ int retval;
+
+ /* can assume both arguments are valid (non-null) */
+ /* Perhaps this can be done more intelligently... */
+ retval = Util_StrCmpi(new->bc_name, current->bc_name);
+ if (retval < 0) {
+ retval = 1; /* new < current */
+ } else if (retval>0) {
+ retval = 0;
+ } else if (new->table < current->table) {
+ retval = 2;
+ } else if (new->table > current->table) {
+ retval = 0;
+ } else if (new->var_index < current->var_index) {
+ retval = 3;
+ } else if (new->var_index > current->var_index) {
+ retval = 0;
+ } else {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Duplicate entry %s marked for boundary condition %s, "
+ "with table handle %d\n", CCTK_VarName(new->var_index),
+ new->bc_name, new->table);
+ retval = -1;
+ }
+
+ return retval;
+}
diff --git a/src/Boundary.h b/src/Boundary.h
index 44527a0..f43e9e0 100644
--- a/src/Boundary.h
+++ b/src/Boundary.h
@@ -130,6 +130,11 @@ int BndStaticVN (const cGH *GH,
/* Radiative boundaries */
+
+/* prototype for routine registed as providing radiative boundary conditions */
+int BndRadiative(const cGH *GH, int num_vars, int *var_indicies,
+ int *table_handle);
+
int BndRadiativeDirGI (const cGH *GH,
int stencil_size,
int dir,
diff --git a/src/RadiationBoundary.c b/src/RadiationBoundary.c
index 8cd220d..4eb2e5f 100644
--- a/src/RadiationBoundary.c
+++ b/src/RadiationBoundary.c
@@ -79,12 +79,93 @@
/* the rcs ID and its dummy function to use it */
static const char *rcsid = "$Header$";
-CCTK_FILEVERSION(CactusBase_Boundary_RadiationBoundary_c)
-
+CCTK_FILEVERSION(CactusBase_Boundary_RadiationBoundary_c);
/********************************************************************
******************** External Routines ************************
********************************************************************/
+
+/*@@
+ @routine BndRadiative
+ @date 6 Nov 2002
+ @author David Rideout
+ @desc
+ Top level function which is registered as handling
+ this boundary condition
+ @enddesc
+ @calls BndRadiativeVI, for the moment
+ @history
+ Perliminary version for testing, simply calls BndRadiativeVI
+ with hardwired arguments
+ @endhistory
+ @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 table_handles
+ @vdesc array of table handles which hold extra arguments
+ @vtype int
+ @vio in
+ @endvar
+ @returntype int
+ @returndesc
+ return code of @seeroutine BndRadiativeVI <BR>
+ |= -16 if valid table handle passed
+ @endreturndesc
+@@*/
+
+int BndRadiative(const cGH *GH, int num_vars, int *var_indices,
+ int *table_handles)
+{
+ int i, retval=0;
+ int sw[3] = {1,1,1};
+
+#ifdef DEBUG
+ printf("BndRadiative(): got passed GH=%p, num_vars=%d, var_indices[0]=%d, table_handles[0]=%d\n", (const void *) GH, num_vars, var_indices[0], table_handles[0]);
+#endif
+
+ /* loop through each variable (Is there some way to take advantage
+ of knowing the entire list of variables ahead of time?) */
+ for (i=0; i<num_vars; ++i) {
+
+ /* Check the input arguments */
+ if (table_handles[i]>=0) {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Ignoring table handle %d, because parameters are simply "
+ "hardwired at the moment. Please complain.", i);
+ retval |= -16;
+ }
+
+ /* hardwiring: stencil width
+ constant var0 = 0.0
+ wave speed = 1.0
+ same var for from and to */
+ if ((retval = BndRadiativeVI(GH, sw, 0., 1., var_indices[i],
+ var_indices[i])) < 0) {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "BndRadiativeVI() returned %d", retval);
+ }
+ }
+#ifdef DEBUG
+ printf("BndRadiative(): returning %d\n",retval);
+#endif
+
+ 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 (BndRadiativeDirGI)
@@ -153,6 +234,7 @@ void CCTK_FCALL CCTK_FNAME (BndRadiativeVN)
TWO_FORTSTRING_ARG);
+
/********************************************************************
******************** Internal Routines ************************
********************************************************************/
diff --git a/src/Register.c b/src/Register.c
new file mode 100644
index 0000000..976743e
--- /dev/null
+++ b/src/Register.c
@@ -0,0 +1,88 @@
+ /*@@
+ @file Register.c
+ @date Sat Oct 26 22:39:40 CEST 2002
+ @author David Rideout
+ @desc
+ Register implemented boundary conditions.
+ @enddesc
+ @version $Header$
+ @@*/
+
+#include "cctk.h"
+#include "cctk_Arguments.h"
+#include "util_Table.h"
+#include "Boundary.h"
+
+static const char *rcsid = "$Header$";
+
+CCTK_FILEVERSION(CactusBase_Boundary_Register_c);
+
+/********************************************************************
+ ********************* Local Data Types ***********************
+ ********************************************************************/
+
+/********************************************************************
+ ********************* Local Routine Prototypes *********************
+ ********************************************************************/
+
+void Boundary_RegisterBCs(CCTK_ARGUMENTS);
+
+/********************************************************************
+ ***************** Aliased Routine Prototypes *********************
+ ********************************************************************/
+
+/********************************************************************
+ ***************** Scheduled Routine Prototypes *********************
+ ********************************************************************/
+
+/********************************************************************
+ ********************* Other Routine Prototypes *********************
+ ********************************************************************/
+
+/********************************************************************
+ ********************* Local Data *****************************
+ ********************************************************************/
+
+/********************************************************************
+ ********************* Aliased Routines **********************
+ ********************************************************************/
+
+/********************************************************************
+ ********************* Scheduled Routines **********************
+ ********************************************************************/
+
+ /*@@
+ @routine Boundary_RegisterBCs
+ @date Sun Nov 3 19:51:37 CET 2002
+ @author David Rideout
+ @desc
+ Register all boundary conditions implemented by this thorn.
+ @enddesc
+ @calls
+ @history
+ @endhistory
+ @var CCTK_ARGUMENTS
+ @vdesc Cactus argument list
+ @vtype CCTK_*
+ @vio in
+ @endvar
+ @returntype void
+ @returndesc
+ @endreturndesc
+@@*/
+
+void Boundary_RegisterBCs(CCTK_ARGUMENTS) {
+ int err;
+
+ err = Boundary_RegisterPhysicalBC(cctkGH, (CCTK_FPOINTER) &BndRadiative,
+ "Radiative");
+ if (err) {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Boundary_RegisterPhysicalBC(cctkGH, &BndRadiative, "
+ "\"Radiative\") returned %d", err);
+ }
+}
+
+/********************************************************************
+ ********************* Local Routines *************************
+ ********************************************************************/
diff --git a/src/make.code.defn b/src/make.code.defn
index 7692d77..2f59ce1 100644
--- a/src/make.code.defn
+++ b/src/make.code.defn
@@ -7,4 +7,6 @@ SRCS = ScalarBoundary.c\
CopyBoundary.c\
FlatBoundary.c\
RadiationBoundary.c\
- RobinBoundary.c
+ RobinBoundary.c\
+ Boundary.c\
+ Register.c