Skip to content

Stat File and Utilities

Tim Greaves edited this page Jun 6, 2014 · 4 revisions

The Stat File

The stat file contains diagnostics such as the max, min L2 norm and integral values of the fields. The information in the .stat file can be read into python with stat parser. It may be useful to use the interactive ipython shell when you first do this. To read in the information, type:

import fluidity_tools
stat = fluidity_tools.stat_parser("filename.stat")

You can find out which fields are contained in a state Fluid via:

stat["Fluid"].keys()

You can type

stat["Fluid"]["Velocity%magnitude"]

where Velocity%magnitude is one of the keys obtained above. This obtains all the values saved for velocity magnitude (usually max, min, L2 norm and integral). You can then select one of these:

stat["Fluid"]["Velocity%magnitude"]["max"]

The “max” statistics of a field “Velocity%magnitude” in this state can be plotted via the following python script:

from matplotlib import pylab
time = stat["ElapsedTime"]["value"] 
max_speed = stat["Fluid"]["Velocity%magnitude"]["max"]
pylab.plot(time, max_speed)
pylab.xlabel("Time")
pylab.ylabel("Max Speed")
pylab.show()

Another example of a script that plots multiple values from different directories:

import pylab
import Numeric
import fluidity_tools
from numpy import shape
labels=["200km 1:1000","20km 1:100","2km 1:10", "200m 1:1" ]
dirs=["x-200km","x-20km", "x-2km", "x-200m"]
for i in range (0,4):
    stat = fluidity_tools.stat_parser("../../"+(dirs[i])+"/unstruc-test/avlesen-diagnostic.steady_state")
    w=stat["BoussinesqFluid"]["Velocity%3"]
    t=stat["ElapsedTime"]
    print "error in w for 200km", w["error"][len(w["error"])-1]
    pylab.plot(t["value"],Numeric.log(w["error"]),label=labels[i])
pylab.ylabel("log (error in w)")
pylab.legend()
pylab.savefig("log_graph.png")
pylab.show() 

statplot

Statplot is a python function in the tools directory. To use it type:

{FLUIDITY PATH}/tools/statplot file.stat

This allows you to plot the quantities saved in the stat file. Simply choose the quantities you wish to plot from the drop down menu.

Statplot example

Monitoring a run

Fluidity produces a .stat file as a run is progressing. It is possible to visualise this file using statplot. To do this, open the .stat file in statplot (the command line below assumes you are in a test, within the test directory)

../../tools/statplot foo.stat

This should produce a window like this:

Statplot example

Once statplot has loaded the window there are a number of options available, including

  • Refreshing the plot
  • Using a scatter plot, rather than line drawing
  • Zooming in
  • Changing the plot to a log plot

Refreshing the plot can be done by pressing "r" or "R". Using "R" will keep the current data bounds. The type of plot can be selected by using either "l" (lower-case L) for a line-plot or "s" for a scatter plot. Individual axes can be switched from linear to log scale (and back again) by pressing "x" or "y". Finally, you can quit statplot by pressing "q".

Each field recorded in the .stat file can be visualised by selecting the appropriate field from the right-hand drop-down list. For each field you will find a minimum, maximum, L2 norm and integral value. This selects which value is plotted on the y-axis. You can also change which variable is plotted on the x-axis by selecting a field form the left-hand drop-down list.

There are also controls to zoom in and out, pan and export the plot. The controls are highlighted on the figure below and are (from left to right): Reset view, return to previous view, go to next view, pan plot, zoom in, configure subplots (not relevant here) and save plot.

Statplot example

Fluidity tools

fluidity_tools is a python module which (among other things) implements parsers for .stat files. This enables users to analyse scalar diagnostic values in python. In particular, matplotlib can be used to plot values from .stat files.

fluidity_tools is a python module so run python:

ipython -pylab

of course you can also use fluidity tools within a python script.

The .stat file is read by a stat_parser so, if we assume that we have a project called cdisk then at the python prompt type:

from fluidity_tools import stat_parser
stat=stat_parser("cdisk.stat")

stat is now a tree of dictionaries containing scalar information the tree is as follows:

--- dt --- value
 |
 |- ElapsedTime --- value
 |
 |- material_phase_name_a --- Speed --- max 
 |     |                       |
 |     |                       |- min
 |     |                       |
 |     |                       \- l2norm
 |     |
 |     |--------------------- Pressure --- max
 |     |                       |
 |     |                       |- min
 |     |                       |
 |     |                       |- l2norm
 |     |                       |
 |     |                       \- integral
 |     |
 |     |--------------------- Temperature --- ...
 |     .
 |     .
 |     .
 |- material_phase_name_b --- ...
       |
       .
       .
       .

For example, the vector of time values at each timestep is

stat["ElapsedTime"]["value"] 

material_phase_name above refers to the name of whichever material_phase the field you wish to examine is in when the problem has been run with new options. We can examine the list of fields in material_phase_a with:

stat["BoussinesqFluid"].keys()

So if we want to plot maximum speed against time we would type:

pylab.plot(stat["ElapsedTime"]["value"], stat["BoussinesqFluid"]["Velocity%magnitude"]["max"])
pylab.xlabel("Time")
pylab.ylabel("Max Speed")
pylab.show()

If run using legacy code then the "1" above refers to the first phase. For most of us there will always only be one phase. We can examine the list of fields in phase 1 with:

stat["1"].keys()

So if we want to plot maximum speed against time we would type:

plot(stat["ElapsedTime"]["value"], stat["1"]["Speed"]["max"])
xlabel("Time")
ylabel("Max Speed")

Using VTK to generate scatter plots

Gareth has added something to the vtkdiagnostic which allows you to save fluidity data as stdout. This means that you can grab the positions of the nodes, velocity vectors, and scalar data, and look at it elsewhere (e.g. in matlab!). Below are a couple of shell scripts which use this progam to loop through a time series of fluidity output.

A sample script for running vtkdiagnostic on serial results

#!/bin/bash

vtkdiagnostic="/home/lucy/fluidity/source/bin/vtkdiagnostic-i686-linux-gnu"
diagnosticArguments1=" --node-positions"
diagnosticArguments2=" --vtk-arrays=Velocity"
diagnosticArguments3=" --vtk-arrays=Temperature"

dumpname="HF_comp_CON_8000"

startdumpnumber=1
enddumpnumber=48
dumpnumber=${startdumpnumber}
for ((dumpnumber=$startdumpnumber; dumpnumber <= $enddumpnumber; dumpnumber++))
do
    fl2vtu ${dumpname} ${dumpnumber}
        outputFile1="${dumpname}_${dumpnumber}_nodes.dat"
        outputFile2="${dumpname}_${dumpnumber}_velocity.dat"
        outputFile3="${dumpname}_${dumpnumber}_temps.dat"

          $vtkdiagnostic --input ${dumpname}_${dumpnumber}.vtu \
            $diagnosticArguments1 \
         >> ${outputFile1}

     $vtkdiagnostic --input ${dumpname}_${dumpnumber}.vtu \
            $diagnosticArguments2 \
         >> ${outputFile2}  	  

     $vtkdiagnostic --input ${dumpname}_${dumpnumber}.vtu \
            $diagnosticArguments3 \
         >> ${outputFile3}
done

A sample script for running vtkdiagnostic on parallel results

#!/bin/bash

vtkdiagnostic="/home/lucy/fluidity/source/bin/vtkdiagnostic-i686-linux-gnu"
diagnosticArguments1=" --node-positions"
diagnosticArguments2=" --vtk-arrays=Velocity"
diagnosticArguments3=" --vtk-arrays=Temperature"

dumpname="HF_comp_COM_8000-G"

startdumpnumber=1
enddumpnumber=48
dumpnumber=${startdumpnumber}

for ((dumpnumber=$startdumpnumber; dumpnumber <= $enddumpnumber; dumpnumber++))
do
    fl2vtu ${dumpname} ${dumpnumber}
        startPartition=0
        endPartition=3
        outputFile1="${dumpname}_${dumpnumber}_nodes.dat"
        outputFile2="${dumpname}_${dumpnumber}_velocity.dat"
        outputFile3="${dumpname}_${dumpnumber}_temps.dat"

        for ((partition=$startPartition; partition <= $endPartition; partition++))
        do
        $vtkdiagnostic --input ${dumpname}_${dumpnumber}_${partition}.vtu \
            $diagnosticArguments1 \
         >> ${outputFile1}

     $vtkdiagnostic --input ${dumpname}_${dumpnumber}_${partition}.vtu \
            $diagnosticArguments2 \
         >> ${outputFile2}

     $vtkdiagnostic --input ${dumpname}_${dumpnumber}_${partition}.vtu \
            $diagnosticArguments3 \
         >> ${outputFile3}

        done
    done
Clone this wiki locally