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
data gnuplot
am Amira (commercial)
marc MSC Marc/Mentat (commercial)
m Matlab (commercial)

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<1>::type;
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.

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

writeAMIRAFile(gridManager.grid().leafView(),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<1>::type;
Material material(p0Space);
[...]
writeAMIRAFile(gridManager.grid().leafView(),vars,filename,IoOptions(),material.coefficients());

Gnuplot

For instant visualization or creating figures for publications with gnuplot, Kaskade 7 provides the possibility to directly write output into a data file with ending .data. This file can be instantly processed by a predefined gnuplot script file of the same name:

#include "io/gnuplot.hh"

writeGnuplotFile(x,"filename"); // write gnuplot output and call gnuplot script file

Options can be provided, too, otherwise the default options setting from IoOptions is used.

Afterwards, the script filename.gnu is executed if it exists. This script processes the visualization of the previously created data. Instead of calling gnuplot and plotting commands manually one after another, the script file allows for a sequence of commands to draw a figure. There are tutorials available online for creation of such scripts. An example can be found in the tutorial for time-dependent equations. Documentation and FAQ for gnuplot can be found on the gnuplot website www.gnuplot.info.

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. The function is passed an Assembler A or a NumaBCRSMatrix A, originating from an assembled finite element system, and the file name. The number of valid decimal digits written for each scalar is a default value (here: 16 digits) and may be omitted here, but may as well be defined by variable precision by the user.

#include "io/matlab.hh"

writeToMatlab(A, filename, precision);

It is as well possible to write any other 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;
end

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<1>::type;
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 (only relevant for gnuplot output, defines type of info messages).

The default state when instantiating IoOptions() is: format = ascii, precision = 6 digits, data mode = conforming, order = 1 and info = none. 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: 2022-01-11 21:22:05 +0100 CET