Exporting databases

VisIt can save the data from a plot to a new database using Export database. Exporting a database saves all of the data that was used to generate the plot. This includes internal data that is normally removed by the face list filter before rendering.

You might want to use export database if you plan to:

  • Save results of a complex calculation so you can reuse the results without having to recalculate
  • Analyze some VisIt data in another application


Supported export formats

VisIt can read many dozens of file formats via its database plugins. Only a handful of database plugins implement a write capability that is used by VisIt's export database functionality. The following table lists the plugins that can export data as well as the supported data types for a plugin. Not all plugins can support certain data types due to file format limitations or limitations in the writing capability of a given database plugin. The following table can help you decide which plugin would be best at exporting your data:

Plugin Meshes:         Scalars Vectors Tensors
  Rectilinear Curvilinear Unstructured AMR Points      
BOV X         X X  
FieldView XDB X X X     X X  
Image X         X  
RAW     X          
STL X X X          
Silo X X X   X X X X
Sim1Writer Only works with simulation codes and the behavior depends on the functions implemented in the simulation.
SimV2 Only works with simulation codes and the behavior depends on the functions implemented in the simulation.
Tecplot X X X   X X X  
VTK X X X   X X X X
Xmdv         X X X  
XYZ     X(polydata vertices only)     X("element" array only)    

Exporting databases in Python

The following example shows how to export a database from Python and save the data to a set of VTK files. Exporting databases is done by first creating plots, setting up an ExportDBAttributes object, and finally passing that object to the ExportDatabase function.

The ExportDBAttributes object contains the name of the plugin that to which you want your data saved (db_type), the name of the exported file (filename), and the list of variables to export (variables). The list of variables that you export should at least contain the "default" variable, which is the plotted variable. The variables list can also include other variables that you wish to export. If the variables are expressions, they need not have been calculated. In that case, VisIt will calculate the expressions before exporting them but your export operation will take longer.

# Set up a visualization
OpenDatabase("/usr/local/apps/visit/data/wave*.silo database")
AddPlot("Pseudocolor", "pressure")
DrawPlots()

# Define an expression that takes some effort to calculate
DefineVectorExpression("vec", "curl(gradient(pressure))")

# Now, export the plotted variable and the expression
for i in range(TimeSliderGetNStates()):
    # Change time states
    SetTimeSliderState(i)
    DrawPlots()

    # Export the database
    dbAtts = ExportDBAttributes()
    dbAtts.db_type = "VTK"
    dbAtts.filename = "file%04d" % i
    # Tuple of variables to export. "default" means the plotted variable.
    # Note that we're also exporting the vector expression "vec"
    dbAtts.variables = ("default", "vec")
    ExportDatabase(dbAtts)

Setting export options in Python

Some database plugins support options that can help the plugin read or write its data. To get a Python dictionary of the supported database options, if any, use the GetExportOptions() function in Python.

# Get the list of export options. Note that this cannot be done until
# a database has been opened since the database export options are not
# known to VisIt until then.

# Get the export options for the VTK writer
opts = GetExportOptions("VTK")
print opts

Output of the "print opts" operation:

{'Binary format': 0}

Now that we know how to get the dictionary of supported options, let's set the options to export our data as a set of binary VTK files.

# Code to set up plots and the dbAtts export options omitted...

# Get the supported options and turn on the "Binary format" option.
opts = GetExportOptions("VTK")
opts['Binary format'] = 1

# Export all time states as binary VTK files
for i in range(TimeSliderGetNStates()):
   SetTimeSliderState(i)
   DrawPlots()
   # Pass the opts as a second argument to ExportDatabase
   ExportDatabase(dbAtts, opts)

Exporting databases from the GUI

Databases can be exported in the GUI by using the Export database window, available in the File->Export database menu.

Exporting databases from a simulation

Exporting databases is possible from simulations for both interactive-style connections and batch-only connections.

Interactive Simulations

VisIt's database export capability is available even within simulations instrumented using libsim for interactive connections. Exporting data within a simulation can be useful if you want to use VisIt's export formats instead of writing output routines to save simulation data to files. To export data from a simulation, you must first have created a plot via the VisIt GUI. After that, you can pass Python function calls for exporting data to the VisItExecuteCommand function. This is best done in your routine that simulates a time step.

char ecmd[1000], dig[3], *ptr;
const char *cmd = "def do_export(val):\n"
                  "    d = ExportDBAttributes()\n"
                  "    d.db_type=\"VTK\"\n"
                  "    d.dirname=\"/where/you/want/your/files/to/go/\"\n"
                  "    d.filename=\"export%02d\" % val\n"
                  "    d.variables=(\"var1\",\"var2\")\n"
                  "    ExportDatabase(d)\n"
                  "do_export(XX)\n";
strcpy(ecmd, cmd);
sprintf(dig, "%02d", sim->saveCounter++);
ptr = strstr(ecmd, "XX");
ptr[0] = dig[0];
ptr[1] = dig[1];

VisItExecuteCommand(ecmd);

Batch Simulations

More recent versions of VisIt provide explicit batch support for setting up plots, saving images, and exporting databases all from within libsim itself. The new functions allow a simulation to set up plots and export databases all without connections to an interactive VisIt GUI. Oftentimes, it is desirable to save out extracted surfaces from the running simulation.

  • Note the new libsim functions are for batch-only
  • These "extract" helper functions can be found in the VisIt repository: (extract.c) (extract.h)
static const char *exportFormat = "FieldViewXDB_1.0";

/* Use libsim calls to export the current plots to a file. */
static int export_visit(const char *filebase, const char **extractvars)
{
    int retval = -1;
    const char *var = NULL;
    visit_handle vars = VISIT_INVALID_HANDLE;
    if(VisIt_NameList_alloc(&vars))
    {
        VisIt_NameList_addName(vars, "default");
        while((var = *extractvars++) != NULL)
            VisIt_NameList_addName(vars, var);
        
        if(VisItExportDatabase(filebase, exportFormat, vars) == VISIT_OKAY)
            retval = 0;
        else
            retval = -2;
    }

    VisIt_NameList_free(vars);

    return retval;
}

/* Use libsim calls to make a VisIt plot and slice it. */
int extract_slice_origin_normal(const char *filebase,
                                const double *origin,
                                const double *normal,
                                const char **extractvars)
{
    int retval = -1;
    if(filebase == NULL || origin == NULL || normal == NULL || extractvars == NULL)
        return retval;

    if(VisItAddPlot("Pseudocolor", extractvars[0]) == VISIT_OKAY)
    {
        if(VisItAddOperator("Slice", 0) == VISIT_OKAY)
        {
            VisItSetOperatorOptionsI("originType", 0); // point intercept
            VisItSetOperatorOptionsDv("originPoint", origin, 3);
            VisItSetOperatorOptionsDv("normal", normal, 3);
            VisItSetOperatorOptionsB("project2d", 0);


            if(VisItDrawPlots() == VISIT_OKAY)
            {
                retval = export_visit(filebase, extractvars);
            }
        }

        VisItDeleteActivePlots();
    }

    return retval;
}

int
main(int argc, char *argv[])
{
    /* All instrumentation ommitted. */

    /* Extract a surface of a slice through the simulation's data. */
    const char *extractvars[] = {"q", "xc", "radius", NULL};
    double origin[] = {5., 5., 5.}, normal[] = {0., 0.707, 0.707};
    extract_slice_origin_normal("slice.xdb", origin, normal, extractvars);

    return 0;

}