File Formats

 
Extended VTK format: *.vti, *.vtu

Ready's file format is an extended version of VTK's format, which uses XML. These are the Ready-specific XML elements, in alphabetical order:

<add>
<circle>
<constant>
<description>
<divide>
<everywhere>
<formula>
<gaussian>
<initial_pattern_generator>
<kernel>
<linear_gradient>
<multiply
<other_chemical>
<overlay>
<overwrite>
<param>
<parameter>
<perlin_noise>
<pixel>
<point3d>
<radial_gradient>
<RD>
<rectangle>
<render_settings>
<rule>
<sine>
<subtract>
<white_noise>

Here is a simple example of a *.vti file:

<?xml version="1.0"?>
<VTKFile type="ImageData" version="0.1" byte_order="LittleEndian" compressor="vtkZLibDataCompressor">

  <RD format_version="2">

    <rule type="formula" name="Schlogl">
      <param name="timestep">  0.1  </param>
      <formula number_of_chemicals="1">
        delta_a = laplacian_a + a - a*a*a;
      </formula>
    </rule>

    <initial_pattern_generator apply_when_loading="true">
      <overlay chemical="a">
        <overwrite />
        <white_noise low="-0.1" high="0.1" />
        <everywhere />
      </overlay>
    </initial_pattern_generator>

    <render_settings>
        <low value="-1.0" />
        <high value="1.0" />
        <contour_level value="0" />
    </render_settings>

  </RD>

  <ImageData WholeExtent="0 127 0 63 0 0" Origin="0 0 0" Spacing="1 1 1">
    <Piece Extent="0 127 0 63 0 0">
      <PointData>
        <DataArray type="Float32" Name="a" format="appended" RangeMin="0" RangeMax="0" offset="0" />
      </PointData>
      <CellData>
      </CellData>
    </Piece>
  </ImageData>
  <AppendedData encoding="base64">
    _AQAAAACAAAAAAAAANAAAAA==eJztwQEBAAAAgJD+r+4ICgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYgAAAAQ==
  </AppendedData>
</VTKFile>

This is the standard VTK format but with an RD element (inside the VTKFile element) that contains all the Ready-specific data.

Ready supports mesh-based systems as well (*.vtu) - these have UnstructuredGrid instead of ImageData sections. Both can be read as the standard VTK format, for example in ParaView.

The following sections describe the Ready-specific XML elements.

<RD>

Specifies the current rule and information about the pattern.

Attributes:

Contains:

<description>

A description of the pattern.

Contains:

Plain text. HTML can also be used but must be XML-escaped as in the table below. See the description in munafo_glider.vti for an example.

<>"&'
&lt;&gt;&quot;&amp;&apos;

<rule>

Attributes:

Contains:

<param>

A parameter of the rule. Most rules require one or more named parameters, such as timestep.

Attributes:

Contains:

The value of this parameter.

<formula>

Attributes:

Contains:

An OpenCL kernel snippet, where the chemicals are named a, b, c, etc.

The formula can specify the rate of change of each chemical (delta_a, delta_b, etc.), typically using the Laplacian of each (laplacian_a, etc.). Example: delta_a = laplacian_a;

Alternatively the formula can write directly into the chemicals. Example: a = x_pos;

For a list of the keywords you can use, see Writing new rules.

In the kernel section below, the "delta_a = ..." lines show how the formula might be inserted at that location in a full kernel.

See the pattern files for more examples.

<kernel>

Attributes:

Contains:

A full OpenCL kernel, as plain text. Below is an example kernel that works on a 2-chemical image. Arrays a_in and b_in contain the current state of the chemicals a and b, and a_out and b_out should get written with the new values.


__kernel void rd_compute(__global float4 *a_in,__global float4 *b_in,__global float4 *a_out,__global float4 *b_out)
{
    const int x = get_global_id(0);   // returns the x-coordinate of this kernel call
    const int y = get_global_id(1);
    const int z = get_global_id(2);
    const int X = get_global_size(0);   // returns the x size of the image
    const int Y = get_global_size(1);
    const int Z = get_global_size(2);
    const int i_here = X*(Y*z + y) + x;   // use this to get the array index of cell x,y,z

    float4 a = a_in[i_here];   // this kernel processes 4 floats at once, stored in a float4 type
    float4 b = b_in[i_here];

    // parameters:
    float timestep = 1.0f;

    // update step:
    float delta_a = 0.0f;
    float delta_b = 0.0f;
    delta_a = 0.1f;    // formula line
    delta_b = -0.2f;   // formula line
    a_out[x] = a + timestep * delta_a;
    b_out[x] = b + timestep * delta_b;
}

Below is an example that works on 2-chemical meshes. The cells can have different numbers of neighbors but for efficiency we pass in fixed-length arrays: neighbor_indices contains the index of each neighbor, neighbor_weights contains a normalized weight (non-zero for valid neighbors), while max_neighbors contains the size of the arrays. The code below shows how we can compute a Laplacian from this input.


__kernel void rd_compute(__global float *a_in,__global float *b_in,__global float *a_out,__global float *b_out,
                         __global int* neighbor_indices,__global float* neighbor_weights,const int max_neighbors)
{
    const int x = get_global_id(0);
    float a = a_in[x];   // this kernel processes single floats
    float b = b_in[x];
    float laplacian_a = 0.0f;
    float laplacian_b = 0.0f;
    int offset = x * max_neighbors;
    for(int i=0;i<max_neighbors;i++)
    {
        laplacian_a += a_in[neighbor_indices[offset+i]] * neighbor_weights[offset+i];
        laplacian_b += b_in[neighbor_indices[offset+i]] * neighbor_weights[offset+i];
    }
    laplacian_a -= a;
    laplacian_b -= b;
    // scale the Laplacians to be more similar to the 2D square grid version, so the same parameters work
    laplacian_a *= 4.0f;
    laplacian_b *= 4.0f;

    // parameters:
    float timestep = 1.0f;
    float D_a = 0.082f;
    float D_b = 0.041f;
    float k = 0.06f;
    float F = 0.035f;

    // update step (Gray-Scott)
    float delta_a = 0.0f;
    float delta_b = 0.0f;
    delta_a = D_a * laplacian_a - a*b*b + F*(1.0f-a);    // formula line
    delta_b = D_b * laplacian_b + a*b*b - (F+k)*b;       // formula line
    a_out[x] = a + timestep * delta_a;
    b_out[x] = b + timestep * delta_b;
}

See the pattern files for more examples.

<initial_pattern_generator>

The initial pattern generator is a way to describe typical reaction-diffusion starting conditions. The Schlogl rule (edit/open), for example, can be initialized with low-amplitude random noise.

Attributes:

Contains:

<overlay>

Each overlay in the initial_pattern_generator changes the values of a single chemical. Overlays apply in the order given in the file.

Attributes:

Contains:

  1. operation (required) : one of overwrite, add, subtract, multiply or divide.
  2. fill (required) : one of constant, white_noise, perlin_noise, other_chemical, linear_gradient, radial_gradient, gaussian, sine or parameter.
  3. shape (required) : one or more of everywhere, rectangle, circle or pixel. Any cell with a centroid inside the shape will be affected.

<overwrite>

Specifies that this overlay should overwrite any existing values.

<add>

Specifies that this overlay should add to the existing values.

<subtract>

Specifies that this overlay should subtract from the existing values.

<multiply>

Specifies that this overlay should multiply the existing values.

<divide>

Specifies that this overlay should divide the existing values.

<constant>

Specifies that the values in this overlay are constant.

Attributes:

<white_noise>

Specifies that the values in this overlay are spatially-uncorrelated random values from a flat distribution between low and high.

Attributes:

<perlin_noise>

Specifies that the values in this overlay are generated by Perlin noise.

Attributes:

<other_chemical>

Specifies that the values in this overlay are given by the current value of a different chemical.

Attributes:

<linear_gradient>

Specifies that the values in this overlay vary linearly from val1 at the start to val2 at the end.

Attributes:

Contains:

<radial_gradient>

Specifies that the values in this overlay vary linearly from val1 at points near the center to val2 at points near the edge.

Attributes:

Contains:

<gaussian>

Specifies a Gaussian distribution with given width and height.

Attributes:

.

Contains:

<sine>

Specifies that the values in this overlay vary as a sine wave.

Attributes:

Contains:

<parameter>

Specifies that the values in this overlay are given by the current value of a named parameter.

Attributes:

<everywhere>

Specifies that the overlay applies everywhere.

<rectangle>

Specifies that the overlay applies to an axis-aligned rectangle. For a 1D image, only the x-coordinate is considered. For a 2D image, only x and y are considered.

Contains:

<circle>

Specifies that the overlay applies to a circle (sphere). For a 1D image, only the x-coordinate is considered. For a 2D image, only x and y are considered.

Attributes:

Contains:

<pixel>

Specifies that the overlay applies to a single pixel in the image. For meshes, any cell with a centroid inside the pixel will be affected. For a 1D image, only the x-coordinate is considered. For a 2D image, only x and y are considered.

Attributes:

<point3d>

A location in space. Coordinates are in the range from zero to one and are given as a proportion of the overall size. For images the size is the number of pixels in each direction. For meshes the size is given by the spatial range of the point coordinates in each direction.

Attributes:

<render_settings>

The render settings specify how the system should be shown on screen. Contains one or more of the elements listed below. Default values are shown to illustrate the format.