Task: Implement Boundary.c for CactusWave/WaveToyExtra thorn

thorn_name: CactusWave/WaveToyExtra
src_filename: Boundary.c
interface: # Interface definition for thorn WaveToyExtra
# $Header$

implements: wavetoyextra
inherits: wavetoy

CCTK_INT FUNCTION Boundary_SelectVarForBC(CCTK_POINTER_TO_CONST IN GH, \
  CCTK_INT IN faces, CCTK_INT IN boundary_width, CCTK_INT IN table_handle, \
  CCTK_STRING IN var_name, CCTK_STRING IN bc_name)

REQUIRES FUNCTION Boundary_SelectVarForBC

schedule: # Schedule definitions for thorn WaveToyExtra
# $Header$


schedule WaveToyExtra_Boundary at EVOL AFTER WaveToy_Evolution BEFORE WaveToy_Boundaries
{
  LANG: C
} "Additional boundary conditions for 3D wave equation"

schedule WaveToyExtra_Boundary at POSTRESTRICT BEFORE WaveToy_Boundaries
{
  LANG: C
} "Additional boundary conditions for 3D wave equation"
  
schedule WaveToyC_Terminate at TERMINATE
{
  LANG: C
} "Tidy up"

param: # Parameter definitions for thorn WaveToyExtra
# $Header$

SHARES: wavetoy

EXTENDS KEYWORD bound
{
  "custom" :: "custom boundary condition"
}

private: 

STRING custom_bound "Custom boundary condition to use"
{
 .* :: "Any valid boundary condition"
} ""

STRING custom_options "Table string for custom boundary condition"
{
 .* :: "Any valid table string"
} ""

context: make.code.defn:
```
# Main make.code.defn file for thorn WaveToyExtra
# $Header$

# Source files in this directory
SRCS = Boundary.c

# Subdirectories containing source files
SUBDIRS = 


```


combined_doc_context: ## README (README):
```
Cactus Code Thorn WaveToyExtra
Author(s)    : Cactus team
Maintainer(s): Cactus team
Licence      : LGPL
--------------------------------------------------------------------------

1. Purpose

Additional functionality for the WaveToy example

- custom boundary conditions

```

## Documentation (.tex files):
Files: documentation.tex

```tex
=== documentation.tex ===
% $Header$

\documentclass{article}

% Use the Cactus ThornGuide style file
% (Automatically used from Cactus distribution, if you have a 
%  thorn without the Cactus Flesh download this from the Cactus
%  homepage at www.cactuscode.org)
\usepackage{../../../../doc/latex/cactus}

\begin{document}

% The author of the documentation
\author{Cactus Maintainers \textless cactusmaint@cactuscode.org\textgreater}

% The title of the document (not necessarily the name of the Thorn)
\title{}

% the date your document was last changed, if your document is in CVS, 
% please use:
\date{$ $Date$ $}

\maketitle

% Do not delete next line
% START CACTUS THORNGUIDE

% Add all definitions used in this documentation here 
%   \def\mydef etc

% Add an abstract for this thorn's documentation
\begin{abstract}
Advanced features for WaveToy
\end{abstract}

% The following sections are suggestive only.
% Remove them or add your own.

\section{Introduction}

This thorn contains enhancements to the standard WaveToy thorns for 
modelling 3D scalar fields. WaveToy is primarily intended as a 
example thorn and for that reason is deliberately kept as simple
as practical, with more advanced features included here instead. 
Currently this thorn shows how more flexible boundaries can be 
used with WaveToy or other thorns.

\section{Boundary Conditions}

This thorn provides the infrastructure to use any registered 
external boundary condition with WaveToy, with any choice of options. 

% Do not delete next line
% END CACTUS THORNGUIDE

\end{document}

```



Reference solution:
src_code: /*@@
   @file      Boundary.c
   @date      Friday 18th July 2003
   @author    Gabrielle Allen
   @desc
              Use any provided boundary condition with WaveToy
   @enddesc
   @version   $Id$
 @@*/

#include "cctk.h"
#include "cctk_Arguments.h"
#include "cctk_Parameters.h"

#include "util_Table.h"

static const char *rcsid = "$Header$";

CCTK_FILEVERSION(CactusWave_WaveToyExtra_Boundary_c);

/********************************************************************
 *********************     Local Data Types   ***********************
 ********************************************************************/

/********************************************************************
 ********************* Local Routine Prototypes *********************
 ********************************************************************/

/********************************************************************
 ********************* Other Routine Prototypes *********************
 ********************************************************************/

void WaveToyExtra_Boundary(CCTK_ARGUMENTS);

/********************************************************************
 *********************     Local Data   *****************************
 ********************************************************************/

static int handle=-1;

/********************************************************************
 *********************     External Routines   **********************
 ********************************************************************/

 /*@@
   @routine    WaveToyC_Boundary
   @date       Friday 18th July 2003
   @author     Gabrielle Allen
   @desc 
               Mark wavetoy variables for custom boundary condition
   @enddesc 
   @history 
   @endhistory 
@@*/

void WaveToyExtra_Boundary(CCTK_ARGUMENTS)
{
  DECLARE_CCTK_ARGUMENTS;
  DECLARE_CCTK_PARAMETERS;

  CCTK_INT ierr=0;

  if (CCTK_EQUALS(bound,"custom"))
  {
    if (!CCTK_EQUALS(custom_options,""))
    {
      if (handle == -1)
      {
        handle = Util_TableCreateFromString(custom_options);
        if (handle < 0)
        {
          CCTK_VWarn(0,__LINE__,__FILE__,CCTK_THORNSTRING,
                     "WaveToyC_Boundaries: Error creating table for "
                     "boundary condition %s",custom_bound);
        }
      }
    }
    ierr = Boundary_SelectVarForBC(cctkGH, CCTK_ALL_FACES, 1, handle, 
                                   "wavetoy::phi",custom_bound);  
  }    

  if (ierr < 0) 
  {
    CCTK_VWarn(0,__LINE__,__FILE__,CCTK_THORNSTRING,
               "WaveToyC_Boundaries: Error selecting boundary "
               "condition %s",bound);
  }

  return;
}


 /*@@
   @routine    WaveToyC_Terminate
   @date       Friday 18th July 2003
   @author     Gabrielle Allen
   @desc 
               Tidy up wavetoy
   @enddesc 
   @history 
   @endhistory 
@@*/
void WaveToyC_Terminate(CCTK_ARGUMENTS)
{
  Util_TableDestroy(handle);
}