Saving the current mesh data to a file
io.saveMeshFile(mesh, fileName, fileType, nodeValues, elementValues, options) |
Description: | Saves data from the given mesh to a new file. The node and element data to be saved can be defined by the nodeValues and elementValues parameters. The unit in which each value will be saved can also be controled by the same parameters, with automatic conversions when needed. The options table controls several aspects of the saving operation. The saving of multiple node data and data associated with cells and Gauss points, along with some of the available options, are not supported by every file format. See the format documentation. If there is an error saving the data (an invalid file format or path, for example), a Lua error will be raised. |
Parameters: | mesh | The mesh. Accepts either a mesh name or a mesh object. |
fileName | The name of the file 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. |
fileType | A string defining the desired file format. |
nodeValues | A string defining the name of the node value (node attribute or state variable) to be saved, or a table with a name list. Can be nil. Optionally, value names can have a suffix surrounded by () with the desired unit (ex: "T(K)" would ask for a temperature value named T, with values converted, if needed, to Kelvin degrees). To choose the unit in which node coordinates are exported, the name "coordinate" followed by a unit can be included as the first name on the list. |
elementValues | A string defining the name of the element value (property, cell attribute or Gauss attribute) to be saved or a table with a name list. Can be nil. Optionally, value names can have a suffix surrounded by () with the desired unit (ex: "rho(g/cm3)" would ask for a density value named rho, with values converted, if needed, to g/cm3). |
options | An optional table with a set of save options. When filling this table, keep in mind that only options different from the default are needed and that not every option is available for every file format. |
Returns: | Nothing. |
Examples:
-- Save temperature node data, converted to Celsius, to the result file using medit format.
-- Also saves material index information.
io.saveMeshFile('myMeshName', 'resultFile.mesh', 'medit', 'T(degC)', nil, {materialPropertySet = 'MatSet'})
-- Save displacement and pressure node data, together with the stress at Gauss points, to the result
-- file using the neutral file format. The file will be saved on the same directory of the simualtion file.
local m = modelData:mesh('myMeshName')
io.saveMeshFile(m, '$SIMULATIONDIR/resultFile.pos', 'nf', {'u', 'P'}, {'S'})
Saving temporal mesh data to a file
Saving multiple mesh states to a single file can be done using the Neutral file format. Normally, the saving process will be integrated with the global simulation loop, associating each saved state to a time step. The following code fragment illustrates how this can be done:
-- Creates the result file, specifying the data set that should be saved at each time step
local file = io.prepareMeshFile('meshName', 'filename.pos', 'nf', {'u', 'P'}, {'S'})
-- Simulation loop
while time <= lastTime do
...
-- Save current time step data
io.addResultToMeshFile(file, time)
end
-- Close the result file
io.closeMeshFile(file)
io.prepareMeshFile(mesh, fileName, fileType, nodeValues, elementValues, options) |
Description: | Prepares to save data from the given mesh to a new file, receiving the same parameters as a call to io .saveMeshFile() , and returning a handle object. The handle should be passed in subsequent calls to io .addResultToMeshFile() for saving mesh states to the file, following the layout defined by the prepare call.
The node and element data to be saved can be defined by the nodeValues and elementValues parameters. The unit in which each value will be saved can also be controled by the same parameters, with automatic conversions when needed. The options table controls several aspects of the saving operation. If there is an error saving the data (an invalid file format or path, for example), a Lua error will be raised. |
Parameters: | mesh | The mesh. Accepts either a mesh name or a mesh object. |
fileName | The name of the file 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. |
fileType | A string defining the desired file format. |
nodeValues | A string defining the name of the node value (node attribute or state variable) to be saved, or a table with a name list. Can be nil. Optionally, value names can have a suffix surrounded by () with the desired unit (ex: "T(K)" would ask for a temperature value named T, with values converted, if needed, to Kelvin degrees). To choose the unit in which node coordinates are exported, the name "coordinate" followed by a unit can be included as the first name on the list. |
elementValues | A string defining the name of the element value (property, cell attribute or Gauss attribute) to be saved or a table with a name list. Can be nil. Optionally, value names can have a suffix surrounded by () with the desired unit (ex: "rho(g/cm3)" would ask for a density value named rho, with values converted, if needed, to g/cm3). |
options | An optional table with a set of save options. When filling this table, keep in mind that only options different from the default are needed and that not every option is available for every file format. |
Returns: | The file handle object. |
io.addResultToMeshFile(fileHandle, time) |
Description: | Saves the current data to the prepared file, using as source the mesh and data layout provided as parameters to the previous call to io .prepareMeshFile() that returned the given file handle. |
Parameters: | fileHandle | The file handle returned by a previous call to io .prepareMeshFile() . |
time | The time that will be associated with the current saved state. |
Returns: | Nothing. |
io.closeMeshFile(fileHandle) |
Description: | Closes the prepared file. This is important to guarantee that all the file contents was written to it, but will be done automatically if the GeMA simulation finishes normally. |
Parameters: | fileHandle - The file handle returned by a previous call to io .prepareMeshFile() . |
Returns: | Nothing. |
io.tempMeshFile(fileHandle) |
Description: | Saving data to some file types require the use of intermediate temporary files (that happends, for example, when saving multiple data to a Neutral file). If that is the case, this function returns the name of the temporary file in use. |
Parameters: | fileHandle - The file handle returned by a previous call to io .prepareMeshFile() . |
Returns: | The name of the temporary file in use or nil if there is none. |