I/O

API

int CCTK_VarIndex(const char *varname)

Get the index for a variable.

Discussion:

The variable name should be the given in its fully qualified form, that is <implementation>::<variable> for PUBLIC or PROTECTED variables and <thorn>::<variable> for PRIVATE variables.

Parameters:
  • varname (char) – The name of the variable.
Error:
  • -1 - no variable of this name exists
  • -2 - no failed to catch error code from Util_SplitString
  • -3 - given full name is in wrong format
  • -4 - memory allocation failed
>>> index = CCTK_VarIndex("evolve::phi");
>>> index = CCTK_VarIndex("evolve::vect[0]");
int CCTK_GroupIndexFromVarI(int varindex)

Given a variable index, returns the index of the associated group

Parameters:
  • varindex (int) – The index of the variable
Result:

groupindex (int) - The index of the group

>>> index = CCTK_VarIndex("evolve::phi");
>>> groupindex = CCTK_GroupIndexFromVarI(index);
char CCTK_FullName(int index)

Given a variable index, returns the full name of the variable

Discussion:

The full variable name is in the form <implementation>::<variable> for PUBLIC or PROTECTED variables and <thorn>::<variable> for PRIVATE variables.

Parameters:
  • index (int) – The variable index
Result:

implementation (char) - The full variable name

>>> name = CCTK_FullName(index);
int CCTK_VarTypeI(int index)

Provides variable type index from the variable index

Discussion:

The variable type index indicates the type of the variable. Either character, int, complex or real. The group type can be checked with the Cactus provided macros for CCTK_VARIABLE_INT, CCTK_VARIABLE_REAL, CCTK_VARIABLE_COMPLEX or CCTK_VARIABLE_CHAR.

Parameters:
  • index (int) – The variable index
Result:

type (int) - The variable type index

>>> vtype = CCTK_VarTypeI(index);
>>> if (vtype == CCTK_VARIABLE_REAL) {
>>>     /* Here goes your code */
>>> }
int CCTK_GroupTypeI(int group)

Provides a group type index given a group index

Discussion:

A group type index indicates the type of variables in the group. The group type can be checked with the Cactus provided macros for CCTK_SCALAR, CCTK_GF, CCTK_ARRAY.

Parameters:
  • group (int) – Group index.
Error:

-1 - the given group index is invalid.

>>> gtype = CCTK_GroupTypeI(gindex);
>>> if (gtype == CCTK_GF) {
>>>     /* Here goes your code */
>>> }
void CCTK_VarDataPtrI(const cGH * cctkGH, int timelevel, int index)

Returns the data pointer for a grid variable from the variable index.

Parameters:
  • cctkGH – pointer to CCTK grid hierarchy
  • timelevel (int) – The timelevel of the grid variable
  • index (int) – The index of the variable
>>> CCTK_REAL *data = NULL;
>>> vindex = CCTK_VarIndex("evolve::phi");
>>> data = (CCTK_REAL*) CCTK_VarDataPtrI(cctkGH, 0, vindex);
CCTK_GroupData(int group_index, cGroup* group_data_buffer)

Given a group index, returns information about the group and its variables.

Discussion:

The cGroup structure contains (at least) the following members:

  • grouptype (int) - group type
  • vartype (int) - variable type
  • disttype (int) - distribution type
  • dim (int) - dimension (rank) of the group
  • numvars (int) - number of variables in the group
  • numtimelevels (int) - declared number of time levels for this group’s variables
  • vectorgroup (int) - 1 if this is a vector group,0 if it’s not
  • vectorlength (int) - vector length of group (i.e. number of vector elements)
  • tagstable (int) - handle to the group’s tags table
Parameters:
  • group_index (int) – The group index for which the information is desired
  • group_data_buffer (int) – Pointer to a cGroup structure in which the information should be stored.
Error:

-1 - group index is invalid. -2 - group_data_buffer is NULL.

>>> cGroup group_info;
>>> int group_index = CCTK_GroupIndex("BSSN_MoL::ADM_BSSN_metric");
>>> CCTK_GroupData(group_index, &group_info);
>>> CCTK_VINFO("Dim: %d, numvars: %d", group_info.dim, group_info.numvars);
int CCTK_OutputVarAs(const cGH *cctkGH, const char *variable, const char *alias)

Output a single variable as an alias by all I/O methods.

Discussion:

If the appropriate file exists the data is appended, otherwise a new file is created. Uses alias as the name of the variable for the purpose of constructing a filename.

Parameters:
  • cctkGH – pointer to CCTK grid hierarchy
  • variable (char) – full name of variable to output
  • alias (char) – alias name to base the output filename on
Result:

istat (int) - the number of IO methods which did output of variable

Error:

negative - if no IO methods were registered

>>> CCTK_OutputVarAs(cctkGH, "HydroBase::rho", "rho");
int CCTK_OutputVarAsByMethod(const cGH *cctkGH, const char *variable, const char *method, const char *alias)

Output a variable variable using the method method if it is registered. Uses alias as the name of the variable for the purpose of constructing a filename. If the appropriate file exists the data is appended, otherwise a new file is created.

Parameters:
  • cctkGH – pointer to CCTK grid hierarchy
  • variable (char) – full name of variable to output
  • method (char) – method to use for output
  • alias (char) – alias name to base the output filename on
Result:

istat (int) - zero for success

Error:

negative - indicating some error

int CCTK_OutputVarByMethod(const cGH *cctkGH, const char *variable, const char *method)

Output a variable variable using the IO method method if it is registered. If the appropriate file exists the data is appended, otherwise a new file is created.

Parameters:
  • cctkGH – pointer to CCTK grid hierarchy
  • variable (char) – full name of variable to output
  • method (char) – method to use for output
Result:

istat (int) - zero for success

Error:

negative - indicating some error