Task: Implement InitSymBound.cc for CactusWave/WaveToyCXX thorn

thorn_name: CactusWave/WaveToyCXX
src_filename: InitSymBound.cc
interface: # Interface definition for thorn WaveToyCXX
# $Header$

implements: wavetoy
inherits: grid

USES INCLUDE: Symmetry.h
 
public:

cctk_real scalarevolve type = GF Timelevels=3
{
  phi
} "The evolved scalar field"

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 WaveToyCXX
# $Header$

STORAGE: scalarevolve[3]

schedule WaveToyCXX_Startup at STARTUP
{
  LANG: C
} "Register banner"

schedule WaveToyCXX_InitSymBound at BASEGRID
{
  LANG: C
} "Schedule symmetries"

schedule WaveToyCXX_Evolution as WaveToy_Evolution at EVOL
{
  LANG: C
  SYNC: scalarevolve
} "Evolution of 3D wave equation"

schedule WaveToyCXX_Boundaries as WaveToy_Boundaries at EVOL AFTER WaveToy_Evolution
{
  LANG: C
  OPTIONS: level
} "Boundaries of 3D wave equation"
  
schedule GROUP ApplyBCs as WaveToyCXX_ApplyBCs at EVOL after WaveToy_Boundaries
{
} "Apply boundary conditions"

schedule WaveToyCXX_Boundaries as WaveToy_Boundaries at POSTRESTRICT
{
  LANG: C
  OPTIONS: level
} "Boundaries of 3D wave equation"
  
schedule GROUP ApplyBCs as WaveToyCXX_ApplyBCs at POSTRESTRICT after WaveToy_Boundaries
{
} "Apply boundary conditions"

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

restricted:
 
KEYWORD bound "Type of boundary condition to use"
{
  "none"      :: "Apply no boundary condition"
  "flat"      :: "Flat (von Neumann, n grad phi = 0) boundary condition"
  "static"    :: "Static (Dirichlet, dphi/dt=0) boundary condition"
  "radiation" :: "Radiation boundary condition"
  "robin"     :: "Robin (phi(r) = C/r) boundary condition"
  "zero"      :: "Zero (Dirichlet, phi=0) boundary condition"
} "none"


configuration: # Configuration definition for thorn CactusWave/WaveToyCXX
# $Header$

REQUIRES CartGrid3D

context: WaveToy.cc:
```
 /*@@
   @file    WaveToy.cc
   @date
   @author  Tom Goodale
   @desc
            Evolution routines for the wave equation solver
   @enddesc
   @version $Id$
 @@*/

#include <stddef.h>

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

#define val(gridfunc,i,j,k)  gridfunc[CCTK_GFINDEX3D(cctkGH,i,j,k)]

 /*@@
   @routine    WaveToyC_Evolution
   @date
   @author     Tom Goodale
   @desc
               Evolution for the wave equation
   @enddesc
@@*/

extern "C" void  WaveToyCXX_Evolution(CCTK_ARGUMENTS)
{
  DECLARE_CCTK_ARGUMENTS;

  // Set up shorthands

  CCTK_REAL dx = CCTK_DELTA_SPACE(0);
  CCTK_REAL dy = CCTK_DELTA_SPACE(1);
  CCTK_REAL dz = CCTK_DELTA_SPACE(2);
  CCTK_REAL dt = CCTK_DELTA_TIME;

  CCTK_REAL dx2 = dx*dx;
  CCTK_REAL dy2 = dy*dy;
  CCTK_REAL dz2 = dz*dz;
  CCTK_REAL dt2 = dt*dt;

  CCTK_REAL dx2i = 1.0/dx2;
  CCTK_REAL dy2i = 1.0/dy2;
  CCTK_REAL dz2i = 1.0/dz2;

  CCTK_REAL factor = 2*(1 - (dt2)*(dx2i + dy2i + dz2i));

  int istart = 1;
  int jstart = 1;
  int kstart = 1;

  int iend = cctk_lsh[0]-1;
  int jend = cctk_lsh[1]-1;
  int kend = cctk_lsh[2]-1;

  //
  // Do the evolution
  //

  for (int k=kstart; k<kend; k++)
  {
    for (int j=jstart; j<jend; j++)
    {
      for (int i=istart; i<iend; i++)
      {
        int vindex = CCTK_GFINDEX3D(cctkGH,i,j,k);

        phi[vindex] =
	  factor*phi_p[vindex] - phi_p_p[vindex]
	  + dt2 *
	  ( (  val( phi_p, i+1,j  ,k  ) + val( phi_p, i-1,j  ,k)   )*dx2i
	    +( val( phi_p, i  ,j+1,k  ) + val( phi_p, i  ,j-1,k)   )*dy2i
	    +( val( phi_p, i  ,j  ,k+1) + val( phi_p, i  ,j,  k-1) )*dz2i
	    );
      }
    }
  }
}

 /*@@
   @routine    WaveToyC_Boundaries
   @date
   @author     Tom Goodale
   @desc
               Boundary conditions for the wave equation
   @enddesc
@@*/

extern "C" void WaveToyCXX_Boundaries(CCTK_ARGUMENTS)
{
  DECLARE_CCTK_ARGUMENTS;
  DECLARE_CCTK_PARAMETERS;

  const char *bctype;


  bctype = NULL;
  if (CCTK_EQUALS(bound,"flat") || CCTK_EQUALS(bound,"static") ||
      CCTK_EQUALS(bound,"radiation") || CCTK_EQUALS(bound,"robin") ||
      CCTK_EQUALS(bound,"none"))
  {
    bctype = bound;
  }
  else if (CCTK_EQUALS(bound,"zero"))
  {
    bctype = "scalar";
  }

  // Uses all default arguments, so invalid table handle -1 can be passed
  if (bctype && Boundary_SelectVarForBC (cctkGH, CCTK_ALL_FACES, 1, -1,
                                         "wavetoy::phi", bctype) < 0)
  {
    CCTK_WARN (0,"WaveToyCXX_Boundaries: Error selecting boundary condition");
  }
}

```

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

# Source files in this directory
SRCS = WaveToy.cc  InitSymBound.cc Startup.cc

# Subdirectories containing source files
SUBDIRS = 


```

Startup.cc:
```
 /*@@
   @file      Startup.c
   @date      
   @author    Gabrielle Allen
   @desc 
              Register banner 
   @enddesc 
   @version $Header$
 @@*/

#include "cctk.h"

 /*@@
   @routine    WaveToyCXX_Startup
   @date       
   @author     Gabrielle Allen
   @desc 
   
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
extern "C" int WaveToyCXX_Startup(void)
{
   CCTK_RegisterBanner("WaveToyC++: Evolutions of a Scalar Field");
   return 0;
}

```


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

1. Purpose

not documented

```

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

```tex
=== documentation.tex ===
% *======================================================================*
%  Cactus Thorn template for ThornGuide documentation
%  Author: Ian Kelley
%  Date: Sun Jun 02, 2002
%  $Header$                                                             
%
%  Thorn documentation in the latex file doc/documentation.tex 
%  will be included in ThornGuides built with the Cactus make system.
%  The scripts employed by the make system automatically include 
%  pages about variables, parameters and scheduling parsed from the 
%  relevent thorn CCL files.
%  
%  This template contains guidelines which help to assure that your     
%  documentation will be correctly added to ThornGuides. More 
%  information is available in the Cactus UsersGuide.
%                                                    
%  Guidelines:
%   - Do not change anything before the line
%       % BEGIN CACTUS THORNGUIDE",
%     except for filling in the title, author, date etc. fields.
%   - You can define your own macros are OK, but they must appear after
%     the BEGIN CACTUS THORNGUIDE line, and do not redefine standard 
%     latex commands.
%   - To avoid name clashes with other thorns, 'labels', 'citations', 
%     'references', and 'image' names should conform to the following 
%     convention:          
%       ARRANGEMENT_THORN_LABEL
%     For example, an image wave.eps in the arrangement CactusWave and 
%     thorn WaveToyC should be renamed to CactusWave_WaveToyC_wave.eps
%   - Graphics should only be included using the graphix package. 
%     More specifically, with the "includegraphics" command. Do
%     not specify any graphic file extensions in your .tex file. This 
%     will allow us (later) to create a PDF version of the ThornGuide
%     via pdflatex. |
%   - References should be included with the latex "bibitem" command.  
%   - For the benefit of our Perl scripts, and for future extensions, 
%     please use simple latex.     
%
% *======================================================================* 
% 
% Example of including a graphic image:
%    \begin{figure}[ht]
% 	\begin{center}
%    	   \includegraphics[width=6cm]{MyArrangement_MyThorn_MyFigure}
% 	\end{center}
% 	\caption{Illustration of this and that}
% 	\label{MyArrangement_MyThorn_MyLabel}
%    \end{figure}
%
% Example of using a label:
%   \label{MyArrangement_MyThorn_MyLabel}
%
% Example of a citation:
%    \cite{MyArrangement_MyThorn_Author99}
%
% Example of including a reference
%   \bibitem{MyArrangement_MyThorn_Author99}
%   {J. Author, {\em The Title of the Book, Journal, or periodical}, 1 (1999), 
%   1--16. {\tt http://www.nowhere.com/}}
%
% *======================================================================* 

% If you are using CVS use this line to give version information
% $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{} 

% 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 us:
%    \date{$ $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}

\end{abstract}

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

\section{Introduction}

\section{Physical System}

\section{Numerical Implementation}

\section{Using This Thorn}

\subsection{Obtaining This Thorn}

\subsection{Basic Usage}

\subsection{Special Behaviour}

\subsection{Interaction With Other Thorns}

\subsection{Support and Feedback}

\section{History}

\subsection{Thorn Source Code}

\subsection{Thorn Documentation}

\subsection{Acknowledgements}


\begin{thebibliography}{9}

\end{thebibliography}

% Do not delete next line
% END CACTUS THORNGUIDE

\end{document}

```



Reference solution:
src_code:  /*@@
   @file    InitSymBound.c
   @date    
   @author  Gabrielle Allen
   @desc
            Sets the symmetries for Wave Toy
   @enddesc
   @version $Header$
 @@*/

#include "cctk.h"
#include "cctk_Arguments.h"
#include "Symmetry.h"

 /*@@
   @routine    WaveToyC_InitSymBound
   @date      
   @author     Gabrielle Allen
   @desc 
               Sets the symmetries for Wave Toy
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/

extern "C" void WaveToyCXX_InitSymBound(CCTK_ARGUMENTS)
{
  DECLARE_CCTK_ARGUMENTS;
    
  int sym[3];

  sym[0] = 1;
  sym[1] = 1;
  sym[2] = 1;

  SetCartSymVN(cctkGH, sym,"wavetoy::phi");

  return;
}