% /*@@ % @file ThornWriters.tex % @date 27 Jan 1999 % @author Gabrielle Allen, Tom Goodale, Gerd Lanfermann % @desc % Thorn writer's guide part of the Cactus User's Guide % @enddesc % @version $Header$ % @@*/ \begin{cactuspart}{2}{Application thorn writing}{$RCSfile$}{$Revision$} \renewcommand{\thepage}{\Alph{part}\arabic{page}} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \chapter{Thorn concepts} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Arrangements} Thorns are grouped into {\em arrangements}. This is a logical grouping of thorns which is purely for organisational purposes. For example, you might wish to keep all your initial data thorns in one arrangement, and all your evolution thorns in another arrangement, or you may want to have separate arrangements for your developmentsl, private and shared thorns. The arrangements live in the {\tt arrangements} directory off the main Cactus directory. Arrangement names must be unique, and cannot sta with a `\#', or finish with `\~{}' or `.bak'. Inside a arrangement directory there are directories for each thorn belonging to the arrangement. Thorn names have the same restrictions as arrangement names, with the addition that a thorn cannot be called `doc'. This name is reserved for arrangement documentation. \section{Implementations} \label{sec:im} One of the key concepts for thorns is the concept of the {\bf implementation}. Relationships between thorns are all based upon relationship between the {\bf implementations} they provide. In principle it should be possible to swap one thorn providing an implementation with another thorn providing that implementation, without affecting any other thorn. An {\bf implementation} defines a group of variables and parameters which are used to implement some functionality. For example the thorn {\tt CactusPUGH/PUGH} provides the implementation {\it driver}. This implementation is responsible for providing memory for grid variables and for communication. Another thorn can also implement {\tt driver}, and both thorns can be compiled in {\em at the same time}. At runtime, the user can decide which thorn providing {\tt driver} is used. No other thorn should be affected by this choice. When a thorn decides it needs access to a variable or a parameter provided by another thorn, it defines a relationship between itself and the other thorn's {\bf implementation}, not explicitly with the other {\bf thorn}. This allows the transparent replacement, at compile or runtime, of one thorn with another thorn providing the same functionality as seen by the other thorns. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \chapter{Anatomy of a thorn} \label{sec:anofath} \section{thorns} \label{sec:th} A thorn consists of a subdirectory of a arrangement containing three administrative files \begin{Lentry} \item[{\tt interface.ccl}] the cactus interface, which defines the grid functions, variables, etc. See \ref{sec:in}. \item[{\tt param.ccl}] the parameters introduced by this thorn, and the parameters needed from other thorns. See \ref{sec:pa}. \item[{\tt schedule.ccl}] scheduling information for routines called by the flesh. See \ref{sec:sc} \end{Lentry} Thorns can also contain \begin{itemize} \item a subdirectory called {\tt src}, which should hold source files and compilation instructions for the thorn \item a subdirectory {\tt src/include} for include files \item a {\tt README} containing a brief description of the thorn \item a {\tt doc} directory for documentation \item a {\tt par} directory for example parameter files \item a {\tt test} subdirectory may also be added, to hold the thorn's testsuite. See \ref{sec:adatesu} for details. \end{itemize} \section{Creating a thorn} To simplify the creation of a thorn, a make target {\tt gmake newthorn} has been provided. When this is run: \begin{enumerate} \item{} You will be prompted for the name of the new thorn. \item{} You will be prompted for the name of the arrangement you would like to include your thorn in. Either enter a new arrangement name or pick one from the list of available arrangements that are shown. \end{enumerate} \section{Configuring your thorn} The interaction of a thorn with the flesh and other thorns is controlled by various configuration files. These consist of: \begin{Lentry} \item [{\tt interface.ccl}] This defines the {\bf implementation} (Section~\ref{sec:im}) the thorn provides, and the variables the thorn needs, along with their visibility to other implementations. \item [{\tt param.ccl}] This defines the parameters that are used to control the thorn, along with their visibility to other implementations. \item [{\tt schedule.ccl}] This defines which functions from the thorn are called and when they are called. It also handles memory and communication assigment for grid variables. \end{Lentry} \subsection{General syntax of CCL files} CCL {\bf Cactus Configuration Language} files are simple text files used to define configuration information for a thorn. CCL files are case independent, and may contain comments introduced by the `\#' character, which indicates that the rest of the line is a comment. \subsection{The {\tt interface.ccl}} The {\tt interface.ccl} file is used to declare the implementation provided by the thorn, and to define the variables provided by it. The implementation is declared by a single line at the top of the file \begin{verbatim} implements: \end{verbatim} Where {\tt } can be any combination of alphanumeric characters and underscores, and is case independent. There are three different access levels available for variables \begin{Lentry} \item[{\tt Public}] Can be `inherited' by other implementations (see below). \item[{\tt Protected}] Can be shared with other implementations which declare themselves to be friends of this one (see below). \item[{\tt Private}] Can only be seen by this thorn. \end{Lentry} Corresponding to the first two access levels there are two relationship statements that can be used to get variables from other thorns. \begin{Lentry} \item [{\tt Inherits: }] This gets all {\tt Public} variables from implementation {\tt }, and all variables that {\tt } has in turn inherited. An implementation may inherit from any number of thorns. \item [{\tt Friend: }] This gets all {\tt Protected} variables from implementation {\tt }, but, unlike {\tt inherits} it also pushes its own implementations {\tt Protected} variables onto implementation {\tt }. This keyword is used to define a group of implementations which all end up with the same {\tt Protected} variables. \end{Lentry} So, for example, an interface.ccl starting \begin{verbatim} implements: wavetoy inherits: grid friend: wave_extract \end{verbatim} declares that the thorn provides an implementation called `wavetoy', gets all the {\tt public} variables declared by an implementation called `grid', and shares all {\tt protected} variables with {\tt wave\_extract} and its friends. For convenience variables are placed in groups of homogeneous variables. Currently, names of groups and variables must be distinct. The group has several attributes: \begin{Lentry} \item [{\tt variable type}] e.g. REAL, INT, COMPLEX \item [{\tt name}] The name of the group \item [{\tt group type}] This indicates the kind of variables help by the group (each group can only hold one kind of variable). \begin{Lentry} \item [{\tt SCALAR}] This is a single number. \item [{\tt GF}] This is an array with the default grid size (a {\it grid function}). \item [{\tt ARRAY}] This is an array of any size. \end{Lentry} \item [{\tt Dim}] This is the dimension of the arrays in a group. (Meaningless for scalars.) This defaults to 3 \item [{\tt Size}] This is the grid size of the arrays in a group, which must be a comma-separated list of {\tt Dim} parameters. The grid size cannot be specified for grid functions, which take the default grid size. \item [{\tt Ghostsize}] This is the number of ghostzones used for the arrays in a group, which must be a comma-separated list of {\tt Dim} parameters. The ghostsize cannot be specified for grid functions, whose ghostsize is specified by a driver thorn. \item [{\tt TimeLevels}] This is the number of timelevels the group has. This defaults to 1. \item [{\tt stagger}] This attribute defines the stagger for a grid function. Specify a string of length {\tt Dim}, where each character indicates the type of staggering in that direction (yxz ordered). If you use default staggering ({\tt MMM}), you can ommit this attribute. \begin{Lentry} \item[{\tt M}] no staggering (``minus'' face, relative to default gridpoint). \item[{\tt C}] center staggering \item[{\tt P}] full staggering by one grid spacing (``plus'' face, relative to default) \end{Lentry} For a full discussion on staggering refer to \ref{sec:staggercode}. \end{Lentry} A group specification consists of the variable type, followed by the name of the group, then a space separated list of the form `attribute = value' . Then a brace delimited block containing a comma or newline separated list of variables in the group. A description of the group may be included on the line with the closing brace. For example, for a group of 5 grid functions on a 3D grid, with 3 timelevels: \begin{verbatim} REAL fields type=GF TimeLevels=3 Dim=3 stagger=MCM { phi a,b,c,d } "Wave fields" \end{verbatim} or, for a group consisting of just one 2D array of integers, \begin{verbatim} INT afields type=ARRAY size=xsize,ysize ghostsize=gxsize,gysize { anarray } "My 2D arrays" \end{verbatim} where {\tt xsize}, {\tt ysize}, {\tt gxsize}, {\tt gysize} are all parameters defined in the thorns {\tt param.ccl}. defines a group of real grid functions of dimension 3 each of which exists on three time levels. The staggering of this group is of type {\tt MCM}: no staggering {\tt M} in the first and third dimension, center staggering {\tt C} for the second dimension. By default all groups are {\tt private}, to change this an access specification of the form {\tt public:} or {\tt protected:} (or {\tt private:} to change it back) may be placed on a line by itself. This changes the access level for any group defined in the file from that point on. All variables seen by any one thorn must have distinct names. \subsection{The {\tt param.ccl}} Users control the operation of thorns via parameters given in a file at runtime. The {\tt param.ccl} is used to specify the parameters used to control an individual thorn, and to specify the values these parameters are allowed to take. When the code is run it reads a parameter file and sets the parameters if they fall within the allowed values. If a parameter is not assigned in a parameter file, it is given its default value. There are three access levels available for parameters: \begin{Lentry} \item [{\tt Global}] These parameters are seen by all thorns. \item [{\tt Restricted}] These parameters may be used by other implementations if they so desire. \item [{\tt Private}] These are only seen by this thorn. \end {Lentry} A parameter specification consists of: \begin{itemize} \item the parameter type (each may have an optional {\t CCTL\_} in front) \begin{Lentry} \item [{\tt REAL}] \item [{\tt INT}] \item [{\tt KEYWORD}] A distinct string with only a few known allowed values. \item [{\tt STRING}] An arbitrary string, which must conform to a given regular expression. \item [{\tt BOOLEAN}] A boolean type which can take values 1, `t', `true', `yes' or 0, `f', `false', `no'. \end{Lentry} \item a {\tt description} of the parameter \item an allowed value block This consists of a brace delimited block of lines describing the allowed values of the parameter. Each range may have a description associated with it by placing a :: on the line and putting the description afterwards. \item the default value This must be one of the allowed values. \end{itemize} For the numeric types {\tt INT} and {\tt REAL}, a range consists of a string of the forms lower-bound:upper-bound:step where a missing number or a \* denotes anything (i.e. infinite bounds or an infinitesimal step). For example \begin{verbatim} REAL Coeff "Important coefficient" { 0:3.14 :: "Range has to be from zero to Pi, default is zero" } 0.0 #No need to define a range for BOOLEAN BOOLEAN nice "Nice weather ?" { }"yes" # A example for a set of keywords and its default (which has to be # defined in the body) KEYWORD confused "Are we getting confused ?" { "yes" :: "absolutely positively" "perhaps" :: "we are not sure" "never" :: "never" } "never" \end{verbatim} defines a REAL parameter, a BOOLEAN parameter, and a KEYWORD. By default all parameters are {\tt private}, to change this an access specification of the form {\tt global:} or {\tt restricted:} (or {\tt private:} to change it back) may be placed on a line by itself. This changes the access level for any parameter defined in the file from that point on. To access {\tt restricted} parameters from another implementation, a line containing {\tt shares: } declares that all parameters mentioned in the file from now until the next access specification originate in implementation {\tt }. In contrast to parameter declarations in other access blocks, the default value must be omitted - it is impossible to set the default value of any parameter not originating in this thorn. For example, the following block adds possible values to the keyword {\tt initial\_data} originally defined in the implementation {\tt einstein}. \begin{verbatim} shares:einstein KEYWORD initial_data "" { "bl_bh" :: "Brill Lindquist black holes" "misner_bh" :: "Misner black holes" "schwarzschild" :: "One Schwarzshild black hole" } \end{verbatim} Note that you must compile at least one thorn which implements {\tt einstein}. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{The {\tt schedule.ccl}} By default no routine of a thorn will be run. The {\tt schedule.ccl} file defines those that should be run and when they should be run. The specification of this is via a schedule block which consists of lines of the form \begin{verbatim} schedule at