Task: Implement SourceData.F90 for CactusWave/IDScalarWaveElliptic thorn

thorn_name: CactusWave/IDScalarWaveElliptic
src_filename: SourceData.F90
interface: # Interface definition for thorn IDScalarWaveElliptic
# $Header$

implements: IDScalarWaveElliptic
inherits: Grid WaveToy EllBase IDScalarWave

USES INCLUDE HEADER: EllBase.h
private:

cctk_real ellcoeffs type = GF
{
  Mcoeff,Ncoeff
} "Coefficients of the elliptic equation"

cctk_real outvars type = GF
{
  temp
} "Temporary vars"

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

schedule UniformCharge in WaveToy_InitialData
{
  STORAGE:       wavetoy::scalarevolve[3],ellcoeffs,outvars
  LANG:          Fortran
} "Initial data (Uniform Charge) for 3D wave equation"

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

shares: idscalarwave

EXTENDS KEYWORD initial_data 
{
  "charge"      :: "Uniformly charged sphere"
}


private:

REAL radius "Radius of uniformly charged sphere"
{
 0:* :: "Anything"
} 1.0

REAL charge "Charge of uniformly charged sphere"
{
 0:* :: "Anything"
} 1.0

BOOLEAN output_tmp "Output intermediate variables"
{
} "no"

STRING solver "Name of elliptic solver"
{
.* :: "Anything"
} "sor"

INT sor_maxit "Maximum number of iterations for SOR solve"
{
 1:* :: "Positive"
} 100

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

# Source files in this directory
SRCS = SourceData.F90

# Subdirectories containing source files
SUBDIRS = 


```


combined_doc_context: ## README (README):
```
Cactus Code Thorn IDScalarWaveElliptic
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      SourceData.F90
   @date      
   @author    Gabrielle Allen
   @desc 
              Elliptic initial data for wave equation

              Originally written in F77 fixed format. Converted to F90
              free format by Peter Diener.
   @enddesc 
   @version $Header$
 @@*/

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

#include "EllBase.h"

subroutine UniformCharge(CCTK_ARGUMENTS)

! Find static field for a uniformly charge sphere
!
! That is, solve Nabla^2 phi = - 4 pi rho
! where rho = Q/(4/3 * Pi * R^3)
! where Q is the total charge and R is the sphere radius

  implicit none

  DECLARE_CCTK_ARGUMENTS
  DECLARE_CCTK_PARAMETERS
  DECLARE_CCTK_FUNCTIONS

  CCTK_REAL pi
  CCTK_REAL AbsTol(3), RelTol(3)
  CCTK_REAL charge_factor

  integer iphi,iMcoeff,iNcoeff
  integer ierr
  CCTK_INT length

  character*30 fsolver
  character*200 infoline

! Get variable indices for all grid functions

  call CCTK_VarIndex (iMcoeff,  "idscalarwaveelliptic::Mcoeff")
  if (iMcoeff .lt. 0) then
    call CCTK_WARN(0,"Grid variable index for Mcoeff not found")
  end if

  call CCTK_VarIndex (iNcoeff,  "idscalarwaveelliptic::Ncoeff")
  if (iNcoeff .lt. 0) then
    call CCTK_WARN(0,"Grid variable index for Ncoeff not found")
  end if

  call CCTK_VarIndex (iphi,"wavetoy::phi")
  if (iphi .lt. 0) then
    call CCTK_WARN(0,"Grid variable index for iphi not found")
  end if


! Set up all coefficients and initial guess for solution

  pi = 4.0d0*atan(1.0d0)
  charge_factor = 4.0d0*pi*charge*3.0d0/(4.0d0*pi*radius**3)

  phi = 0.0d0
  Mcoeff = 0.0d0
  
  where ( r <= radius )
    Ncoeff = charge_factor
  elsewhere
    Ncoeff = 0.0d0
  end where

! Set tolerance for stopping elliptic solve

  AbsTol(1)=1.0d-5
  AbsTol(2)=1.0d-5
  AbsTol(3)=1.0d-5

  RelTol(1)=-1
  RelTol(2)=-1
  RelTol(3)=-1

! Set any options needed for the elliptic solve

  call Ell_SetStrKey (ierr, "yes", "EllLinFlat::Bnd::Robin")
  call Ell_SetRealKey(ierr, 0.0d0, "EllLinFlat::Bnd::Robin::inf")
  call Ell_SetIntKey (ierr, 1,     "EllLinFlat::Bnd::Robin::falloff")

! Set parameters for specific solvers
  if (CCTK_EQUALS(solver,"sor")) then
    call Ell_SetIntKey(ierr, sor_maxit,"Ell::SORmaxit")
  end if
     
  call CCTK_FortranString(length,solver,fsolver)
  write(infoline,'("Going into elliptic solver ",A)') fsolver
  call CCTK_INFO(infoline)

! Call elliptic solver to fill out phi

  call Ell_LinFlatSolver( &
         ierr, &
         cctkGH, & 
         iphi,  &
         iMcoeff, iNcoeff, &
         AbsTol, RelTol, &
         fsolver)

  if (ierr .eq. ELL_SUCCESS) then
    call CCTK_INFO("Leaving elliptic solver: solve successful")
  else if (ierr .eq. ELL_NOCONVERGENCE) then
    call CCTK_INFO("Leaving elliptic solver: solver failed to converge")
  else if (ierr .eq. ELL_NOSOLVER) then
    call CCTK_INFO("Elliptic solver not found")
  else 
    write(infoline,'("Leaving elliptic solver: solve failed (Error ",I3,")")') ierr
    call CCTK_INFO(infoline)
  end if

! Set up last timestep ... assume (first order) time symmetry

  phi_p = phi

! Output exact solution if required

  if (output_tmp .eq. 1) then

    where ( r .ge. radius )
      temp = charge / r
    elsewhere
      temp = charge/(2.0d0*radius**3)*(3.0d0*radius**2-r**2)
    end where

    call CCTK_OutputVarAsByMethod(ierr,cctkGH, &
            "idscalarwaveelliptic::temp", &
            "IOASCII_1D","phi_exact")
  end if      

  return
end