Output

In addition to writing simple output into an arbitrary data file (.dat, .txt, .gnu, …) by using the C++ std::ofstream method, Kaskade provides functionalities to write data into the following file formats:

file format software
vtu/vtk Paraview
marc MSC Marc/Mentat (commercial)
m Matlab (commercial) / Octave

Graphical output

VTK/VTU

The file format .vtu (as well as .vtk) is used by the Visualization Toolkit for unstructured grids and relies on XML. Some graphic programs like Paraview can read and display .vtu and .vtk data. These files can be written and read by Kaskade 7 in ASCII or binary format (see section Geometry). For further evaluation of the results, Kaskade 7 offers as well the possibility to write simulated values into a .vtk file in order to view them later. It is possible to export scalar as well as vectorial results, whereby a VariableSet vars must be provided. Next to the VariableSet we also have to provide a filename as string and IoOptions.

#include "io/vtk.hh"
#include "io/vtkreader.hh"

writeVTK(vars, filename, IoOptions());

Note that Paraview can create a time line implicitly from numbered files. For easy creation of numbered file names as time series, it is possible to use paddedString:

for (int step=0; step<N; ++step) 
  writeVTK(vars,filename+paddedString(step,4),IoOptions());

Another option for writing time series and visualizing them as animation in Paraview is provided by class TimeSeriesVTKWriter (see doxygen documentation):

TimeSeriesVTKWriter tvtk(filename,IoOptions());
for (int step=0; step<N; ++step)
  tvtk.add(step,vars);

Additional data such as material data, e.g. from geometries consisting of different materials with different parameters, can be as well written into the .vtk file. Assume a P0 space is created as material space and the material is created or read in from a geometry, then:

P0Space p0Space(gridManager,gridManager.grid().leafGridView(),0);
using Material = P0Space::Element_t<1>;
Material material(p0Space);
[...]
writeVTK(material,filename,IoOptions(),"Materials");

Amira

The file format .am is used by the commercial software Amira for visualizing and processing data from scientific computations. The functionality depends on the not freely available libamiramesh library and may be somewhat unstable. These files can be written and read by Kaskade 7 in ASCII or binary format (see section Geometry). A gridView (here: the leaf grid view) and a VariableSet vars must be provided. Next to the VariableSet we also have to provide a filename as string and IoOptions.

Amira .am support is deprecated and will be removed in Kaskade 7.9. Use VTK/VTU output for new projects.

#include "io/amira.hh"
#include "io/amirameshreader.hh"

writeAMIRAFile(gridManager.grid().leafGridView(),vars,filename,IoOptions());

Additional data such as material data, e.g. from geometries consisting of different materials with different parameters, can be as well written into the .am file. With material being a FunctionSpaceElement, the underlying data has to be accessed and provided by its coefficients:

P0Space p0Space(gridManager,gridManager.grid().leafGridView(),0);
using Material = P0Space::Element_t<1>;
Material material(p0Space);
[...]
writeAMIRAFile(gridManager.grid().leafGridView(),vars,filename,IoOptions(),material.coefficients());

Data processing

Matlab

In Kaskade 7, it is possible to export the system matrix and the right-hand side to Matlab (or any other matrix and vector). This is particularly interesting for debugging, as the structure of the matrix can be viewed visually. Exporting is done by the function writeToMatlab. For an assembler A containing the matrix and right-hand side, the call is

#include "io/matlab.hh"

writeToMatlab(A, filename, precision);

The precision argument is optional and defaults to 16 digits. A NumaBCRSMatrix can be exported as well; in that case the overload also takes an output path:

writeToMatlab(A, basename, outPath, precision);

It is also possible to write a matrix A as NumaBCRSMatrix together with a vector b as Dune::BlockVector:

#include "io/matlab.hh"

writeToMatlab(A, b, filename, precision);

The content of the resulting file is a Matlab function that can be executed, showing a sparse matrix A and a right hand side b. The file extension .m is appended automatically.

General data output

As usual, data output can be written into an arbitrary data file (.dat, .txt, .gnu, …) by using the C++ std::ofstream method. For example, the results of a calculation over time at a certain point could be written as follows into a .dat file:

static std::ofstream sampleOut("output.dat"); // create data file and open output stream
for (int i=0; i<maxNum; ++i)
  sampleOut << time[i] << ' ' << value[i] << std::endl;

The written data can now be further processed with gnuplot, Matlab, python or another software.

Conversion to other file formats

Marc

This creates an input file for the Marc finite element solver by MSC Software (MSC Marc/Mentat). The created file is intended for heat simulations (not mechanics), and provides dummy thermal material parameters which need to be fixed before submitting the file to Marc. The underlying grid must contain just one type of cell.

#include "io/marcwriter.hh"

P0Space p0Space(gridManager,gridManager.grid().leafGridView(),0);
using Material = P0Space::Element_t<1>;
Material material(p0Space);

writeMarc(material,"filename");
writeMarc(material,"filename-mm","",1000,IoOptions());

The writeMarc method writes grid and material IDs given as FE function to a Marc input file. It is possible to provide a scaling factor for the geometry, such that lengths and positions are scaled by that factor, as well as the usual IoOptions.

Input and output options

With class IoOptions (see doxygen documentation) it is possible to specify details for output, such as

  • format (ascii, binary),
  • precision, i.e. number of digits in ascii mode,
  • data mode (conforming, nonconforming), i.e. continuous or discontinuous representation of point and cell data,
  • polynomial order (0, 1 or 2),
  • info (verbosity of informational messages).

The default state when instantiating IoOptions() is: format = ascii, precision = 6 digits, data mode = inferred, order = 1 and info = none. The inferred data mode lets the writer choose a conforming or nonconforming representation based on the continuity of the function. Otherwise, desired options may be set directly by

IoOptions().setOrder(1).setPrecision(7).setDataMode(IoOptions::nonconforming)

or by creating an options object:

IoOptions options;
options.order = 1;
options.precision = 7;
options.dataMode = IoOptions::nonconforming;

Page last modified: 2026-11-10