MADNESS  0.10.1
Collaboration diagram for Input/Output:
Moving functions to/from disk
It takes at most a couple of lines of code to move a function to/from disk. The example program trunk/src/examples/functionio.cc shows how to do this, and the critical lines are
ParallelOutputArchive out(world, filename);
out & f & g & h;
ParallelInputArchive in(world, filename);
in & f & g & h;
double(* f)(const coord_3d &)
Definition: derivatives.cc:54
static const char * filename
Definition: legendre.cc:96
double h(const coord_1d &r)
Definition: testgconv.cc:68
double g(const coord_1d &r)
Definition: testgconv.cc:49
Here, f, g, and h are MADNESS functions of any type (they need not have the same type or dimension).

MADNESS has a generic mechanism for (de)serializing objects from directional streams, called archives, that avoids confusion with the STL stream concept. Anything can be written to and read from an archive, though user-defined types usually need a little additional code to enable this (see trunk/src/madness/world/archive.h for documentation). Most archives are sequential objects accessible only to a single process and it makes little sense to write a potentially large function that is distributed across the entire parallel computer to such an archive. For that reason, functions must be written to/from a parallel archive that performs efficient parallel I/O.

Large amounts of data (more than a few gigabytes) will benefit from increasing the number of processors actually doing disk I/O (refer to the relevant parallel archive class for more info).

Plotting

MADNESS can presently generate uniform grids in formats suitable for several visualization software packages. The following are explicitly supported:

Note
The program mraplot can be used to generate plots from functions stored on disk.

OpenDX

OpenDX is an open source visualization software based on IBM's Visualization Data Explorer (www.opendx.org). Please refer to the OpenDX manual for its use. An example configuration file (vizit.cfg) and a network file (vizit.net) can be found in the trunk/src/apps/moldft/ directory. Here are some details on creating your own DX files.

Given any MADNESS function f, you can write to disk a uniform grid over the entire simulation volume with

plotdx(f, "f.dx");
void plotdx(const Function< T, NDIM > &f, const char *filename, const Tensor< double > &cell=FunctionDefaults< NDIM >::get_cell(), const std::vector< long > &npt=std::vector< long >(NDIM, 201L), bool binary=true)
Writes an OpenDX format file with a cube/slice of points on a uniform grid.
Definition: mraimpl.h:3448

Additional arguments permit us to change the plot volume (default is the entire simulation volume), the number of points (default is 201) and binary/text format (default is binary). This is a collective operation.

Visualizing this with OpenDX is straightforward, but depends on the number of dimensions. The easiest way is to start OpenDX, click "Import Data ...", enter your filename, and click "Visualize Data". However, you will want to learn how to build your own networks. To display an iso-surface of 3D data, start the visual editor and connect

file-selector --> import --> isosurface --> image

Enter your name in the file-selector, and you should see the picture. You can adjust the isosurface value in the isosurface control or by connecting it to an interactor. Have fun!

VTK format and Paraview

MADNESS can export MADNESS functions to the serial vtkStructuredGrid (.vts) file format, which can be ready by several post-processing visualization packages such as Paraview. To write this data file, you must first define four quantities:

  1. a filename (filename),
  2. the lower (plotlo) bound of Cartesian coordinates in each dimension to plot,
  3. the corresponding upper (plothi) bound,
  4. the number of points (npts) in each dimension to evaluate.
Note
At this time, MADNESS evaluates the functions at equally spaced points between plotlo and plothi.

After the above four quantities have been defined, three functions must be called:

Note
Currently, the function evaluation in plotvtk_data is done in serial.

An example of code for plotting two two-dimensional functions u and v in a $[0,1]^{2}$ box with 101 points is as follows:

char filename[100];
sprintf(filename, output.vts); // Defines the filename
Vector<double, 2> plotlo, plothi; // Box dimensions
Vector<long, 2> npts; // Num points in each dim
for(int i = 0; i < 2; ++i)
{
plotlo[i] = 0.0;
plothi[i] = 1.0;
npts[i] = 101;
}
plotvtk_begin(world, filename, plotlo, plothi, npts);
plotvtk_data(u, u, world, filename, plotlo, plothi, npts);
plotvtk_data(v, v, world, filename, plotlo, plothi, npts);
plotvtk_end<3>(world, filename);
static const double v
Definition: hatom_sf_dirac.cc:20
void plotvtk_data(const T &function, const char *fieldname, World &world, const char *filename, const Vector< double, NDIM > &plotlo, const Vector< double, NDIM > &plothi, const Vector< long, NDIM > &npt, bool binary=false)
Definition: funcplot.h:225
void plotvtk_begin(World &world, const char *filename, const Vector< double, NDIM > &plotlo, const Vector< double, NDIM > &plothi, const Vector< long, NDIM > &npt, bool binary=false)
Definition: funcplot.h:146
double u(const double x, const double expnt)
Definition: testperiodic.cc:56
Note
  • An arbitrary number of MADNESS files may be written to a single file. Two are shown above for demonstrative purposes; however, plotvtk_data may be called multiple times between plotvtk_begin and plotvtk_end function calls.
  • For time-dependent simulations, the above code can be included within the time step loop. The user should then consider appending the filename with the timestep number and create Ntimestep files, each containing one increment of time.

To visualize your functions, Paraview has been extensively tested, although other external visualization packages may also be compatible with the vts file format. Paraview is an open-source visualization application that is freely downloadable. For information about how to download, install and use Paraview, please consult their webpage at http://www.paraview.org.

Line plots

With a single function call, up to three functions can be simultaneously evaluated at points along a line with the values printed to a file suitable for use by any standard 2D graphics or spreadsheet software. For example, to plot one 4D function (f) along a line between $(0,0,0,1)$ and $(0,1,0,2)$ with 101 points

coord_3d lo, hi;
lo[3]=1.0; hi[1]=1.0; hi[2]=2.0;
plot_line("plot.txt", 101, lo, hi, f);
static double lo
Definition: dirac-hatom.cc:23
Vector< double, 3 > coord_3d
Definition: funcplot.h:1042
void plot_line(World &world, const char *filename, int npt, const Vector< double, NDIM > &lo, const Vector< double, NDIM > &hi, const opT &op)
Generates ASCII file tabulating f(r) at npoints along line r=lo,...,hi.
Definition: funcplot.h:438

To plot two functions (f and g) you would use instead

plot_line("plot.txt", 101, lo, hi, f, g);

With gnuplot, you can plot the data as follows

gnuplot -persist -e 'set style data lines; plot "plot.txt"'

Previous: MADNESS functions; Next: Load and memory balancing