Output and Visualisation

Simulation output comes in three kinds:

  • Raw data of both Mesh and Simulation. Every save interval, both the Mesh and the state are written to disc. Mesh information is written in three files: vert####.dat, containing vertex coordinates, tria####.dat, containing triangle information (vertices and edges), and edge####.dat, containing edge information (triangles). Here and in the following, #### stands for a four-digit number, e.g. 0001, 0199. The state vector is written in four files dens####.dat, containing the density, momx####.dat containing the x-momentum, momy####.dat containing the y-momentum and ener####.dat containing the total energy.
  • Fine grain global data in simulation.dat. Every fine grain save interval, a new line is added to this ASCII file, containing global simulation quantities (simulation time plus other quantities that might be interesting to monitor).
  • When desired, Astrix can output legacy VTK files for easy visualisation for example with the open source package VisIt (available from https://wci.llnl.gov/simulation/computer-codes/visit)

All raw data files are binary files. The format for each is as follows:

  • vert####.dat: three 4 byte integers specifying the number of spatial dimensions (fixed to two for now), the size of each element (can be 4 byte float or 8 byte double), and the total number of vertices Nv. These are followed by the actual data: Nv x coordinates followed by Nv y coordinates.
  • tria####.dat: a 4 byte integer specifying the total number of triangles Nt. This is followed by Nt integers specifying the first vertex for each triangle, followed by Nt integers specifying the second vertex for each triangle, followed by Nt integers specifying the third vertex for each triangle. After this, the edges for every triangle: three sets of Nt integers specifying the first, second and third edge for every triangle.
  • edge####.dat: a 4 byte integer specifying the total number of edges Ne. This is followed by Ne integers specifying the first neighbouring triangle, followed by Ne integers specifying the second neighbouring triangle. These entries can be -1 if the edge happens to have only one neighbouring triangle.
  • dens####.dat (and similar for the other state vector files): a 4 byte integer specifying the size of the output (can be float or double), a float or double specifying the current simulation time, followed by an 4 byte integer specifying the number of time steps taken so far. Then the actual data follows for each vertex a double or a float.

Constructing periodic meshes from the raw outputs can be tricky. A python script to read raw data files into a format that can be used for example with matplotlib is provided in the Astrix/python/astrix/ directory. The module readfiles contains a function readall that reads in both Mesh and Simulation data. Provided Astrix/python/ is in your PYTHONPATH environmental variable, this function can be used for plotting as follows:

import numpy as np
import matplotlib.pyplot as plt
import astrix.readfiles as a

# Read in data
coords, triang, state = a.readall("path/to/data/", 0)

# Vertex coordinates
x = coords[:, 0]
y = coords[:, 1]

# Density
d = state[:, 0]

# Contour levels
levels = np.linspace(np.min(d), np.max(d), 100)

fig = plt.figure(figsize=(5.5, 5.5))
ax = fig.add_subplot(1, 1, 1)

# Plot triangulation
ax.triplot(x, y, triang, 'k-')
# Contour plot density
ax.tricontourf(x, y, triang, d, levels=levels, cmap=cm.bwr)

plt.show()

The complete content of the astrix.readfiles module is given below. In most cases, the readall function is all that is required.

astrix.readfiles.CanVertexBeTranslatedX(a, N)[source]

Check whether a vertex is a periodic x vertex.

For a mesh that is periodic in x, some triangles ‘wrap around’ and therefore need to look at the other side of the mesh for the coordinates of one of their vertices. This function checks if this is the case for vertex a.

Parameters:
  • a (int) – Vertex input to consider.
  • N (int) – Total number of vertices in Mesh
Returns:

1 if a can be found one period away towards positive x, -1 if a can be found one period away towards negative x, and zero otherwise.

Return type:

int

astrix.readfiles.CanVertexBeTranslatedY(a, N)[source]

Check whether a vertex is a periodic y vertex.

For a mesh that is periodic in y, some triangles ‘wrap around’ and therefore need to look at the other side of the mesh for the coordinates of one of their vertices. This function checks if this is the case for vertex a.

Parameters:
  • a (int) – Vertex input to consider.
  • N (int) – Total number of vertices in Mesh
Returns:

1 if a can be found one period away towards positive y, -1 if a can be found one period away towards negative y, and zero otherwise.

Return type:

int

astrix.readfiles.GetCoordinates(a, vertX, vertY, Px, Py)[source]

Get coordinates of vertex number a.

For a mesh that is periodic in x, some triangles ‘wrap around’ and therefore need to look at the other side of the mesh for the coordinates of one of their vertices. This function gets the ‘proper’ coordinates of vertex a.

Parameters:
  • a (int) – Vertex input to consider.
  • vertX (ndarray) – array of vertex x coordinates
  • vertY (ndarray) – array of vertex y coordinates
  • Px (float) – Period in x
  • Py (float) – Period in y
Returns:

x and y coordinate of vertex a.

Return type:

float, float

astrix.readfiles.readState(read_direc, read_indx, nVertex)[source]

Reads in simulation data from Astrix simulation at specified time.

Read the simulation output (i.e. the state at every vertex) contained in directory read_direc at snapshot read_indx.

Parameters:
  • read_direc (string) – Directory containing Astrix output.
  • read_indx (int) – Output number to read.
  • nVertex (int) – total number of vertices in Mesh
Returns:

four arrays containing density, x-velocity, y-velocity and total energy

Return type:

ndarray, ndarray, ndarray, ndarray

astrix.readfiles.readTriangle(read_direc, read_indx)[source]

Reads in triangle data from Astrix simulation at specified time.

Read the triangle output (i.e. the vertices belonging to every triangle) contained in directory read_direc at snapshot read_indx. Note that in case of periodic meshes, the entries may be smaller than zero or larger than the number of vertices.

Parameters:
  • read_direc (string) – Directory containing Astrix output.
  • read_indx (int) – Output number to read.
Returns:

a connectivity array of length 3 times the number of triangles. The first three entries represent the first triangle, etc.

Return type:

ndarray

astrix.readfiles.readVertex(read_direc, read_indx)[source]

Reads in vertex data from Astrix simulation at specified time.

Read the vertex output contained in directory read_direc at snapshot read_indx.

Parameters:
  • read_direc (string) – Directory containing Astrix output.
  • read_indx (int) – Output number to read.
Returns:

x-coordinates of the vertices; y-coordinates of the vertices

Return type:

ndarray, ndarray

astrix.readfiles.readall(read_direc, read_indx, Px=1.0, Py=1.0)[source]

Reads in data from Astrix simulation at specified time.

Read the simulation output contained in directory read_direc at snapshot read_indx. If the mesh is periodic in x or y or both, the periods must be supplied as Px and Py so that we can create the full mesh.

Parameters:
  • read_direc (string) – Directory containing Astrix output.
  • read_indx (int) – Output number to read.
  • Px (float) – Optional distance in x over which the mesh is periodic.
  • Py (float) – Optional distance in y over which the mesh is periodic.
Returns:

Coordinates (x,y) of the vertices as a (Nv, 2) array, where Nv is the number of vertices; triangulation as a (Nt, 3) array, where Nt is the number of triangles; state as a (Nv, 4) array, containing density, two velocities and the total energy.

Return type:

ndarray(Nv,2), ndarray(Nt,3), ndarray(Nv,4)