GeMA
The GeMA main application
VtkLib
vtk-logo.png

VtkLib is responsible for exporting mesh data to VTK file format. This file format is widely used to describe simulation results and can be visualized using the Paraview application. The exportation is done by calling the vtkLib.saveMeshFile() function. This function generates ASCII files for multi states and multi data simulations, limited to scalar data for now (multidimensional data is splitted and saved as several scalar components). The basic usage of the function saves the current state of the data in a .vtu file for cell mesh or a .vtp file for node mesh. In multi states mode, the function output is a collection of state files referenced in the .pvd collection file. The latter associates each state file (.vtu or .vtp) to its corresponding simulation time.

Important: Please rememeber that the library must be loaded, before the first call to one of its exported methods, by a call to dofile("$SCRIPTS/vtkLib.lua").

vtkLib.saveMeshFile(meshId, nodeValues, gaussValues, output, options)
Description: Saves data from the given mesh to a Vtk file(s). The node and gauss data to be saved can be specified in the nodeValues and gaussValues parameters.
Parameters: meshId The mesh name.
nodeValues A table defining the name list of the node values (node attribute or state variable) to be saved. Only scalar values are supported. Can be nil.
gaussValues A table defining the name list of the gauss values (gauss attribute) to be saved. Only scalar values are supported. Can be nil.
output The base name of the file(s) that will be created. If a file extension is not present on the name, it will be added. If a file with the same name already exists, it will be replaced. The file name can include path macros.
options An optional table with flags controlling the function behavior:
- allStates Optional flag controlling the history data to be saved. When set to false or nil, only the current data will be saved (default mode). When set to true and the data has multiple history states, tries to save them all. No effect if parameter state is not nil.
- state The state id to be saved during the progressive saving mode. If this optional parameter is filled, it means that we are in a progressive saving mode simulation loop.
Important Note: during a simulation loop, the first state value should be equal to 1, the nth step to n, etc (see example below).
- stateTime The state time associated to the given state in progressive saving mode.
Returns: Nothing.

Examples:

dofile('$SCRIPTS/vtkLib.lua')
-- Save temperature node data to the result file.
vtkLib.saveMeshFile('myMeshName', {'T'}, nil, 'resultFile')
-- Save displacement and pressure node data, together with the stress at Gauss points,
-- to the result file. The file will be saved on the same directory of the simualtion file.
vtkLib.saveMeshFile('myMeshName', {'u', 'P'}, {'S'}, '$SIMULATIONDIR/resultFile')

Progressive saving mode

This mode is usefull when running a transient simulation in which data is not saved on memory at each step. If the user wants to save the intermediary results computed along the simulation he should follow the instructions shown in the example below.

dofile('$SCRIPTS/vtkLib.lua')
local times = { ... }
-- Simulation loop
for i=1, #times do
...
-- Save current time step data
vtkLib.saveMeshFile('mesh', {'u', 'P'}, {'S'}, 'filename', {state = i, stateTime = times[i]})
end