aboutsummaryrefslogtreecommitdiff
path: root/src/GHExtension.c
blob: 0633017b3ba4b6cec3d91d88e87ec829fb1762a9 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
 /*@@
   @file      GHExtension.c
   @date      Fri May 21 1999
   @author    Thomas Radke
   @desc 
   IOFlexIO GH extension stuff.
   @enddesc 
   @history
   @hauthor Thomas Radke @hdate May 21 1999
   @hdesc Just copied from thorn IO.
   @endhistory
 @@*/

/*#define DEBUG_IO*/

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "cctk.h"
#include "cctk_parameters.h"
#include "cctk_ParameterFunctions.h"
#include "CactusPUGH/PUGH/src/include/pugh.h"
#include "CactusBase/IOUtil/src/ioGH.h"
#include "ioFlexGH.h"


/* local function prototypes */
void SetupSliceCenter (cGH *GH);


void *IOFlexIO_SetupGH (tFleshConfig *config, int convergence_level, cGH *GH)
{
  DECLARE_CCTK_PARAMETERS
  int i, numvars;
  flexioGH *newGH;

  numvars = CCTK_NumVars ();

  newGH = (flexioGH *) malloc (sizeof (flexioGH));
  newGH->do_out2D = (char *) malloc (numvars * sizeof (char));
  newGH->do_out3D = (char *) malloc (numvars * sizeof (char));
  newGH->out2D_last = (int *) malloc (numvars * sizeof (int));
  newGH->out3D_last = (int *) malloc (numvars * sizeof (int));

  newGH->IEEEfname_3D = (char **) malloc (numvars * sizeof (char **));

  for (i = 0; i < numvars; i++)
    newGH->IEEEfname_3D [i] = (char *) malloc (512 * sizeof (char));
  newGH->IEEEfile_3D = (IOFile *) malloc (numvars * sizeof (IOFile));

  return (newGH);

  USE_CCTK_PARAMETERS

}

int IOFlexIO_InitGH (cGH *GH)
{
  DECLARE_CCTK_PARAMETERS
  int i;
  ioGH *ioUtilGH;
  flexioGH *myGH; 
  t_param_prop *param_prop;


  /* get the handles for IOUtil and IOFlexIO extensions */
  ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")];
  myGH = (flexioGH *) GH->extensions [CCTK_GHExtensionHandle ("IOFlexIO")];

  /* How often to output */
  myGH->out2D_every = out_every > 0 ? out_every : -1;
  myGH->out3D_every = out_every > 0 ? out_every : -1;
  if (out2D_every > 0)
    myGH->out2D_every = out2D_every;
  if (out3D_every > 0)
    myGH->out3D_every = out3D_every;

  ParseVarsForOutput (out2D_vars, myGH->do_out2D);
  ParseVarsForOutput (out3D_vars, myGH->do_out3D);

  /* Check whether "outdir2D" and/or "outdir3D" was set.
     If so take these dirs otherwise default to "IO::outdir" */
  param_prop = CCTK_ParameterInfo ("outdir2D", CCTK_THORNSTRING);
  if (param_prop && param_prop->n_set > 0)
    myGH->outdir2D = strdup (outdir2D);
  else
    myGH->outdir2D = strdup (outdir);

  param_prop = CCTK_ParameterInfo ("outdir3D", CCTK_THORNSTRING);
  if (param_prop && param_prop->n_set > 0)
    myGH->outdir3D = strdup (outdir3D);
  else
    myGH->outdir3D = strdup (outdir);

  /* Create the output directories */
  if (CCTK_MyProc (GH) == 0) {
    if (CCTK_mkdir (myGH->outdir2D) != 0)
      CCTK_WARN (2,"Problem creating IO 2D directory");
    if (CCTK_mkdir (myGH->outdir3D) != 0)
      CCTK_WARN (2,"Problem creating IO 3D directory");
  }

  for (i=0; i<CCTK_NumVars(); i++)
    myGH->out2D_last [i] = myGH->out3D_last [i] = -1;

  myGH->out3d_reuse_filehandles = out3d_reuse_filehandles;

  /* Only have reuse for chunked data */
  if (myGH->out3d_reuse_filehandles && ioUtilGH->unchunked) {
    CCTK_WARN (2, "Cannot reuse handles with unchunked data. "
                  "Ignoring parameter 'out3d_reuse_filehandles'");
    myGH->out3d_reuse_filehandles = 0;
  }

  /* Only have reuse if not one file per slice */
  if (myGH->out3d_reuse_filehandles && out3D_septimefiles) {
    CCTK_WARN (2, "Cannot reuse handles with 'out3D_septimefiles = yes'. "
                  "Ignoring parameter 'out3d_reuse_filehandles'");
    myGH->out3d_reuse_filehandles = 0;
  }

  myGH->filenameList2D = NULL;
  myGH->fileList_3D = NULL;

  /* set up 2D planes to plot */
  SetupSliceCenter (GH);

  /* create timers if timing info was requested */
  if (print_timing_info) {
    myGH->dumpVarsTimer = CCTK_TimerCreateI ();
    myGH->dumpParamsTimer = CCTK_TimerCreateI ();
    myGH->checkpointTotalTimer = CCTK_TimerCreateI ();
    myGH->recoverVarsTimer = CCTK_TimerCreateI ();
    myGH->recoverParamsTimer = CCTK_TimerCreateI ();
    myGH->recoverTotalTimer = CCTK_TimerCreateI ();

    if (myGH->dumpVarsTimer < 0)
      CCTK_WARN (1, "Could not create timer ! Timing info on dumping datasets "
                    "will not be available.");
    if (myGH->dumpParamsTimer < 0)
      CCTK_WARN (1, "Could not create timer ! Timing info on dumping parameters"
                    " will not be available.");
    if (myGH->checkpointTotalTimer < 0)
      CCTK_WARN (1, "Could not create timer ! Timing info on total checkpoint "
                    "time will not be available.");

    if (myGH->recoverVarsTimer < 0)
      CCTK_WARN (1, "Could not create timer ! Timing info on recovering "
                     "datasets will not be available.");
    if (myGH->recoverParamsTimer < 0)
      CCTK_WARN (1, "Could not create timer ! Timing info on recovering "
                    " parameters will not be available.");
    if (myGH->recoverTotalTimer < 0)
      CCTK_WARN (1, "Could not create timer ! Timing info on total recovery "
                    "time will not be available.");

    CCTK_TimerResetI (myGH->checkpointTotalTimer);
    CCTK_TimerResetI (myGH->recoverTotalTimer);
  }

  return (0);

  USE_CCTK_PARAMETERS

}


#if 0
int IOFlexIO_Terminate (cGH *GH)
{
  DECLARE_CCTK_PARAMETERS

  if (print_timing_info) {
    CCTK_TimerDestroyI (myGH->dumpVarsTimer);
    CCTK_TimerDestroyI (myGH->dumpParamsTimer);
    CCTK_TimerDestroyI (myGH->checkpointTotalTimer);
    CCTK_TimerDestroyI (myGH->recoverVarsTimer);
    CCTK_TimerDestroyI (myGH->recoverParamsTimer);
    CCTK_TimerDestroyI (myGH->recoverTotalTimer);
  }

  return (0);

  USE_CCTK_PARAMETERS

}
#endif


/****************************************************************************/
/* local routines                                                           */
/****************************************************************************/
void SetupSliceCenter (cGH *GH)
{
  DECLARE_CCTK_PARAMETERS
  int dim;
  int slice_center;
  pGH *pughGH;
  flexioGH *myGH;


  /* Get the handles for PUGH IOFlexIO extensions */
  pughGH = (pGH *) GH->extensions [CCTK_GHExtensionHandle ("PUGH")];
  myGH = (flexioGH *) GH->extensions [CCTK_GHExtensionHandle ("IOFlexIO")];

  slice_center=1;
  if (   CCTK_Equals (domain, "octant")
      || CCTK_Equals (domain, "quadrant")
      || CCTK_Equals (domain, "bitant"))
    slice_center=0;

  if (slice_center)
  {
    /* For NONE octant mode: the center for slicings */
    /* is moved to the center index */
    /* (unless nx,ny,nz=1) */

    for (dim = 0; dim < GH->cctk_dim; dim++)
      if (pughGH->lnsize [dim] == 1)
        myGH->sp2xyz [dim] = 0;
      else
        myGH->sp2xyz [dim] = pughGH->nsize [dim]/2 -
                            pughGH->lb [pughGH->myproc][dim];

  }

  /* for octant mode, the slicing center is the index 1 or zero*/
  else

  {
    for (dim = 0; dim < GH->cctk_dim; dim++)
      if (pughGH->lnsize [dim] == 1)
        myGH->sp2xyz [dim] = 0;
      else
        myGH->sp2xyz [dim] = 1 - pughGH->lb [pughGH->myproc][dim];
  }

  /* In quadrant mode x and y are like full, but z is like octant */
  if (CCTK_Equals (domain, "quadrant")) {
    if (pughGH->lnsize [2] == 1)
      myGH->sp2xyz[2] = 0;
    else
      myGH->sp2xyz[2] = pughGH->lnsize [2]/2 - pughGH->lb [pughGH->myproc][2];
  }

  if (CCTK_Equals (domain, "bitant")) {
    if (pughGH->lnsize [0] == 1)
      myGH->sp2xyz[0] = 0;
    else
      myGH->sp2xyz[0] = myGH->sp2xyz[0]/2 - pughGH->lb [pughGH->myproc][0];

    if (pughGH->lnsize [1] == 1)
      myGH->sp2xyz[1] = 0;
    else
      myGH->sp2xyz[1] = pughGH->lnsize [1]/2 - pughGH->lb [pughGH->myproc][1];
  }

  USE_CCTK_PARAMETERS

}