aboutsummaryrefslogtreecommitdiff
path: root/doc/documentation.tex
blob: c83f3f0035f7779a6ad3d446098005a511a2cda0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
\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/ThornGuide/cactus}

\begin{document}

\title{PUGHReduce}
\author{Gabrielle Allen, Thomas Radke}
\date{$ $Date$ $}
\maketitle

% Do not delete next line
% START CACTUS THORNGUIDE

\begin{abstract}
Reductions operations which are performed using the PUGH driver
\end{abstract}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Purpose}
%
This thorn registers a number of reduction operators with the flesh. The
reductions are performed using internals of the PUGH driver, so that this
thorn can only be used when {\tt CactusPUGH/PUGH} is active.\\

The reduction operations this thorn registers are\\

\begin{tabular}{|l|l|l|}
\hline
Reduction Operator & Calculates & By \\
\hline
{\tt average$^*$}   & the average of a grid variable & $ \sum{ GV }/n $ \\
{\tt minimum$^*$}   & the minimum of a grid variable & $ \min{ GV } $ \\
{\tt maximum$^*$}   & the maximum of a grid variable & $ \max{ GV } $ \\
{\tt sum$^*$}       & the sum of the elements of a grid variable & $ \sum{ GV } $ \\
{\tt norm1}         & the L1 norm of a grid variable & $ \left(\Sigma | GV | \right)/n $ \\
{\tt norm2}         & the L2 norm of a grid variable & $ \sqrt{(\Sigma GV^2)/n} $ \\
{\tt norm\_inf}     & the Inf norm of a grid variable & $ \max{| GV |} $ \\
\hline
\end{tabular}\\

In the formulas $GV$ is the grid variable to be reduced, and $n$ denotes the
number of its elements. Reduction operators marked with $^*$ cannot be applied
to grid variables of complex datatype.
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Examples}
%
The following C example illustrates how the get the maximum value of a grid
function.
%
\begin{verbatim}
  int vindex;             /* grid variable index */
  CCTK_REAL result;       /* resulting reduction value */
  int target_proc;        /* processor to hold the result */
  int reduction_handle;   /* handle for reduction operator */
  char *reduction_name;   /* reduction operator to use */


  /* want to get the maximum for the wavetoy grid function */
  reduction_name = "maximum";
  vindex = CCTK_VarIndex ("wavetoy::phi");

  /* the reduction result will be obtained by processor 0 only */
  target_proc = 0;

  /* get the handle for the given reduction operator */
  reduction_handle = CCTK_ReductionHandle (reduction_name);
  if (reduction_handle >= 0)
  {
    /* now do the reduction using the flesh's generic reduction API
      (passing in one input, expecting one output value of REAL type) */
    if (CCTK_Reduce (cctkGH, target_proc, reduction_handle,
                     1, CCTK_VARIABLE_REAL, &result, 1, vindex) == 0)
    {
      if (CCTK_MyProc (cctkGH) == target_proc)
      {
        printf ("%s reduction value is %f\n", reduction_name, result);
      }
    }
    else
    {
      CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                  "%s reduction failed", reduction_name);
    }
  }
  else
  {
    CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                "Invalid reduction operator '%s'", reduction_name);
  }
\end{verbatim}

% Do not delete next line
% END CACTUS THORNGUIDE

\end{document}