Exemple #1
0
/*@@
   @routine    IOBasic_ScalarOutputGH
   @date       Sat March 6 1999
   @author     Gabrielle Allen
   @desc
               Loops over all variables and outputs them if necessary
   @enddesc
   @calls      IOBasic_TimeForScalarOutput
               IOBasic_WriteScalarGS
               IOBasic_WriteScalarGA

   @var        GH
   @vdesc      Pointer to CCTK GH
   @vtype      const cGH *
   @vio        in
   @endvar

   @returntype int
   @returndesc
               the number of variables which were output at this iteration
               (or 0 if it wasn't time to output yet)
   @endreturndesc
@@*/
int IOBasic_ScalarOutputGH (const cGH *GH)
{
  int i, vindex, retval;
  const char *name;
  iobasicGH *myGH;


  /* Get the GH extensions for IOBasic */
  myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");

  CheckSteerableParameters (myGH);

  /* Return if no output is required */
  if (myGH->outScalar_every <= 0)
  {
    return (0);
  }

  /* Loop over all variables */
  for (vindex = retval = 0; vindex < CCTK_NumVars (); vindex++)
  {
    /* Is it time for output ? */
    if (! IOBasic_TimeForScalarOutput (GH, vindex))
    {
      continue;
    }

    /* Get the variable name for this index (for filename) */
    name = CCTK_VarName (vindex);

#ifdef IOBASIC_DEBUG
    printf("\nIn IOBasic_ScalarOutputGH\n----------------\n");
    printf("  Index = %d\n",vindex);
    printf("  Variable = -%s-\n",name);
    printf("  Last output iteration was = %d\n",myGH->outScalar_last[vindex]);
#endif

    /* Make the IO call */
    if (CCTK_GroupTypeFromVarI (vindex) == CCTK_SCALAR)
    {
      i = IOBasic_WriteScalarGS (GH, vindex, name);
    }
    else
    {
      i = IOBasic_WriteScalarGA (GH, vindex, name);
    }
    if (i == 0)
    {
      /* Register GF as having 0D output this iteration */
      myGH->outScalar_last [vindex] = GH->cctk_iteration;
      retval++;
    }
  } /* end of loop over all variables */

  return (retval);
}
Exemple #2
0
/*@@
   @routine    IOASCII_Output1DGH
   @date       Sat March 6 1999
   @author     Gabrielle Allen
   @desc
               Loops over all variables and outputs them if necessary
   @enddesc
   @calls      IOASCII_TimeFor1D
               IOASCII_Write1D

   @var        GH
   @vdesc      Pointer to CCTK GH
   @vtype      const cGH *
   @vio        in
   @endvar

   @returntype int
   @returndesc
               the number of variables which were output at this iteration
               (or 0 if it wasn't time to output yet)
   @endreturndesc
@@*/
int IOASCII_Output1DGH (const cGH *GH)
{
  int vindex, retval;
  asciiioGH *myGH;
  const char *name;


  /* Get the GH extensions for IOASCII */
  myGH = (asciiioGH *) CCTK_GHExtension (GH, "IOASCII");

  CheckSteerableParameters (myGH);

  /* Return if no output is required */
  if (myGH->out1D_every <= 0)
  {
    return (0);
  }

  /* Loop over all variables */
  for (vindex = retval = 0; vindex < CCTK_NumVars (); vindex++)
  {
    /* Check if this variable should be output */
    if (! IOASCII_TimeFor1D (GH, vindex))
    {
       continue;
    }

    /* Get the variable name for this index (for filename) */
    name = CCTK_VarName (vindex);

#ifdef IO_DEBUG
    printf ("\nIn IOASCII Output1DGH\n---------------------\n");
    printf ("  Index = %d\n", vindex);
    printf ("  Variable = -%s-\n", name);
    printf ("  On iteration %d\n", GH->cctk_iteration);
    printf ("  Last output iteration was = %d\n", myGH->out1D_last[vindex]);
#endif

    /* Make the IO call */
    if (IOASCII_Write1D (GH, vindex, name) == 0)
    {
      /* Register variable as having 1D output this iteration */
      myGH->out1D_last[vindex] = GH->cctk_iteration;
      retval++;
    }
  } /* end of loop over all variables */

  return (retval);
}
Exemple #3
0
/* check if steerable parameters have changed */
static void CheckSteerableParameters (asciiioGH *myGH)
{
  int i, num_vars, out_old, times_set;
  int verboselength;
  char *fullname, *msg;
  static int out1D_vars_lastset = -1;
  DECLARE_CCTK_PARAMETERS


  out_old = myGH->out1D_every;

  /* How often to output */
  myGH->out1D_every = out_every > 0 ? out_every : -1;
  if (out1D_every > 0)
  {
    myGH->out1D_every = out1D_every;
  }

  /* Report if frequency changed */
  if (myGH->out1D_every != out_old)
  {
    if (CCTK_Equals (newverbose, "standard") ||
        CCTK_Equals (newverbose, "full"))
    {
      CCTK_VInfo (CCTK_THORNSTRING, "IOASCII_1D: Output every %d iterations",
                  myGH->out1D_every);
    }
  }

  /* re-parse the 'out1D_vars' parameter if it was changed */
  times_set = CCTK_ParameterQueryTimesSet ("out1D_vars", CCTK_THORNSTRING);
  if (times_set != out1D_vars_lastset)
  {
    num_vars = CCTK_NumVars ();
    memset (myGH->do_out1D, 0, num_vars);
    CCTK_TraverseString (out1D_vars, SetOutputFlag, myGH->do_out1D,
                         CCTK_GROUP_OR_VAR);

    if (CCTK_Equals (newverbose, "standard") ||
        CCTK_Equals (newverbose, "full"))
    {

      /* Count the length of the string */
      verboselength = 0;
      for (i = 0; i < num_vars; i++)
      {
        if (myGH->do_out1D[i])
        {
          fullname = CCTK_FullName (i);
          verboselength += strlen(fullname)+1;
          free (fullname);
        }
      }
      verboselength += strlen("IOASCII_1D: Output requested for ");
      msg = (char *)malloc((verboselength+1)*sizeof(char));

      sprintf(msg,"IOASCII_1D: Output requested for ");
      for (i = 0; i < num_vars; i++)
      {
        if (myGH->do_out1D[i])
        {
          fullname = CCTK_FullName (i);
          sprintf (msg, "%s %s",msg,fullname);
          free (fullname);
        }
      }
      if (msg)
      {
        CCTK_INFO (msg);
        free (msg);
      }
    }

    /* Save the last setting of 'out1D_vars' parameter */
    out1D_vars_lastset = times_set;
  }

  USE_CCTK_PARAMETERS; }
Exemple #4
0
/* check if steerable parameters have changed */
static void CheckSteerableParameters (iobasicGH *myGH)
{
  int i, num_vars, out_old;
  int times_set;
  char *fullname, *msg, *oldmsg;
  static int outScalar_vars_lastset = -1;
  DECLARE_CCTK_PARAMETERS


  /* How often to output */
  out_old = myGH->outScalar_every;
  myGH->outScalar_every = out_every > 0 ? out_every : -1;
  if (outScalar_every > 0)
  {
    myGH->outScalar_every = outScalar_every;
  }

  if (myGH->outScalar_every != out_old)
  {
    if (CCTK_Equals (newverbose, "standard") ||
        CCTK_Equals (newverbose, "full"))
    {
      CCTK_VInfo (CCTK_THORNSTRING, "Scalar: Output every %d iterations",
                  myGH->outScalar_every);
    }
  }

  /* re-parse the 'outScalar_vars' parameter if it was changed */
  times_set = CCTK_ParameterQueryTimesSet ("outScalar_vars", CCTK_THORNSTRING);
  if (times_set != outScalar_vars_lastset)
  {
    num_vars = CCTK_NumVars ();
    memset (myGH->do_outScalar, 0, num_vars);
    CCTK_TraverseString (outScalar_vars, SetOutputFlag, myGH->do_outScalar,
                         CCTK_GROUP_OR_VAR);

    if (myGH->outScalar_every &&
        (CCTK_Equals (newverbose, "standard") ||
         CCTK_Equals (newverbose, "full")))
    {
      msg = NULL;
      for (i = 0; i < num_vars; i++)
      {
        if (myGH->do_outScalar[i])
        {
          fullname = CCTK_FullName (i);
          if (! msg)
          {
            Util_asprintf (&msg, "Scalar: Output requested for %s", fullname);
          }
          else
          {
            oldmsg = msg;
            Util_asprintf (&msg, "%s %s", oldmsg, fullname);
            free (oldmsg);
          }
          free (fullname);
        }
      }
      if (msg)
      {
        CCTK_INFO (msg);
        free (msg);
      }
    }

    /* Save the last setting of 'outScalar_vars' parameter */
    outScalar_vars_lastset = times_set;
  }

  USE_CCTK_PARAMETERS; }
Exemple #5
0
 /*@@
   @routine    CactusDefaultSetupGH
   @date       Tue Sep 29 15:06:22 1998
   @author     Tom Goodale
   @desc
               Default cactus SetupGH routine.
   @enddesc
   @calls      CCTK_MaxDim
               CCTK_NumVars
               CCTK_NumTimeLevelsFromVarI
               CCTK_NumGroups
               CCTKi_SetupGHExtensions

   @var        config
   @vdesc      Pointer to flesh configuration environment
   @vtype      tFleshConfig *
   @vio        in
   @endvar
   @var        convergence_level
   @vdesc      convergence leve of new cGH
   @vtype      int
   @vio        in
   @endvar

   @returntype cGH *
   @returndesc
               the pointer to the new cGH structure,
               or NULL if memory allocation failed
   @endreturndesc
@@*/
cGH *CactusDefaultSetupGH(tFleshConfig *config, int convergence_level)
{
  cGH *thisGH;
  int n_groups;
  int n_variables;
  int variable;
  int ntimelevels;
  int cctk_dim;


  /* Put this in for the moment until parameter stuff is done. */
  if(convergence_level > 0)
  {
    return (NULL);
  }

  /* Initialise this since it is used later and in exceptional
   * circumstances might not be initialsed beforehand.
   */

  variable = -1;

  /* Create a new Grid Hierarchy */
  thisGH = (cGH *)malloc(sizeof(cGH));

  if(thisGH)
  {
    thisGH->cctk_dim = CCTK_MaxDim();

    /* Need this to be at least one otherwise the memory allocation will fail. */
    cctk_dim = thisGH->cctk_dim;
    if(thisGH->cctk_dim == 0) cctk_dim = 1;
    thisGH->cctk_iteration    = 0;
    thisGH->cctk_gsh          = (int *)malloc(cctk_dim*sizeof(int));
    thisGH->cctk_lsh          = (int *)malloc(cctk_dim*sizeof(int));
    thisGH->cctk_lbnd         = (int *)malloc(cctk_dim*sizeof(int));
    thisGH->cctk_ubnd         = (int *)malloc(cctk_dim*sizeof(int));

    thisGH->cctk_lssh         = (int *)malloc(CCTK_NSTAGGER*cctk_dim*sizeof(int));
    thisGH->cctk_to           = (int *)malloc(cctk_dim*sizeof(int));
    thisGH->cctk_from         = (int *)malloc(cctk_dim*sizeof(int));
    thisGH->cctk_bbox         = (int *)malloc(2*cctk_dim*sizeof(int));
    thisGH->cctk_nghostzones  = (int *)malloc(2*cctk_dim*sizeof(int));
    thisGH->cctk_levfac       = (int *)malloc(cctk_dim*sizeof(int));
    thisGH->cctk_delta_space  = (CCTK_REAL *)malloc(cctk_dim*sizeof(CCTK_REAL));
    /* FIXME : Next line goes when coords are done properly */
    thisGH->cctk_origin_space = (CCTK_REAL *)malloc(cctk_dim*sizeof(CCTK_REAL));

    thisGH->cctk_delta_time = 1;
    thisGH->cctk_convlevel = 0;

    n_variables = CCTK_NumVars();

    /* Allocate memory for the variable data pointers.
     * Note we want at least one to prevent memory allocattion from failing !
     */
    thisGH->data = (void ***)malloc((n_variables ? n_variables:1)*sizeof(void **));

    if(thisGH->data)
    {
      for(variable = 0; variable < n_variables; variable++)
      {
        ntimelevels = CCTK_NumTimeLevelsFromVarI(variable);

        thisGH->data[variable] = (void **)calloc(ntimelevels, sizeof(void *));
        if(thisGH->data[variable] == NULL)
        {
          break;
        }
      }
    }

    thisGH->extensions = NULL;

    /* Allocate memory for the group data pointers.
     * Note we want at least one to prevent memory allocattion from failing !
     */
    n_groups = CCTK_NumGroups();
    thisGH->GroupData = (cGHGroupData *)malloc((n_groups ? n_groups:1)*sizeof(cGHGroupData));

  }

  if(thisGH &&
     thisGH->cctk_gsh &&
     thisGH->cctk_lsh &&
     thisGH->cctk_lbnd &&
     thisGH->cctk_ubnd &&
     thisGH->cctk_lssh &&
     thisGH->cctk_from &&
     thisGH->cctk_to &&
     thisGH->cctk_bbox &&
     thisGH->cctk_nghostzones &&
     thisGH->cctk_levfac &&
     thisGH->cctk_delta_space &&
     thisGH->cctk_origin_space &&
     thisGH->data &&
     variable == n_variables &&
     thisGH->GroupData)
  {
    /* Traverse list of GH setup routines. */
    CCTKi_SetupGHExtensions(config, convergence_level, thisGH);
  }
  else
  {
    /* FIXME: should free potentially allocated memory for this GH */
    thisGH = NULL;
  }

  return (thisGH);
}