Contents     Functions         Previous Next     PDF Index

v_handle, sdthdf

Purpose

Class constructor for variable handle objects.

Description

The Structural Dynamics Toolbox supports variable handle objects, which act as pointers to variables that are actually stored as global variables, user data of graphical objects, or in files. This latter application may become very useful when handling very large models. sdthdfindeed allows RAM unloading by keeping data on drive while using a pointed to it. A trade-off between data access performance (limited to your drive I/O performance) and amount of free memory will occur.

Some supported file formats are MATLAB 6 .mat files, MATLAB >7.3 HDF based .mat files, NASTRAN .op2, ABAQUS .fil ...

v_handle objects are used to

v_handle objects essentially behave like global variables with the notable exception that a clear command only deletes the handle and not the pointed data.

Only advanced programmers should really need access to the internal structure of v_handle.

hdf Commands

The new hdf5 file format, supported by MATLAB since version 7.3, allows very efficient data access from files. Partial loading is possible, as well as data location by pointers. sdthdfallows the user to unload RAM by saving specific data to dedicated files, and to optimize file loading using pointers. To be able to use these functionalities, the file must have been saved in hdf5 format, which is activated in MATLAB using the -v7.3 option of the save function.

The following commands are supported.

hdfreadref

This command handles partial data loading, depending on the level specified by the user.

For unloaded data, a v_handlepointer respecting the data structure and names is generated, so that the access is preserved. Further hdfreadref application to this specific data can be done later.

By default, the full file is loaded. Command option -level allows specifying the desired loading level. For structured data, layers are organized in which substructures are leveled. This command allows data loading until a given layer. Most common levels used are given in the folling list

It takes in argument either a file, or a data structure containing hdf5 v_handlepointers. In the case where a file is specified, the user can precise the data to be loaded, by giving its named preceded by a slash /, substructure names can also be specified giving the name path to the variable to be loaded with a succession of slashes.

% To load an hdf5 file
r1=sdthdf('hdfreadref','my_file.mat');
% To load it using \vhandle pointers
r1=sdthdf('hdfreadref-level0',my_file.mat');
% To load a specified variable
r2=sdthdf('hdfreadref-level0','my_file.mat','/var2');
% To load a specified sub data
r3=sdthdf('hdfreadref-level1','my_file.mat','/var2/subvar1');
% To load a subdata from a previously loaded pointer
r4=sdthdf('hdfreadref',r2.subvar1);

hdfdbsave

This command handles partial data saving to a temporary file. It is designed to unload large numerical data, such as sparse matrices, or deformation fields. Command option -struct however allows to save more complex data structures.

The function takes in argument the data to save and a structure with a field Dbfile containing the temporary file path (string). The function outputs the v_handleto the saved data. The v_handlehas the same data structure than the original. The v_handledata can be recovered by hdfreadref.

opt.Dbfile=nas2up('tempname_DB.mat');
r1=sdthdf('hdfdbsave',r1,opt);
r2=sdthdf('hdfdbsave-struct',r2,opt);

hdfmodelsave

This command handles similar saving strategy than hdfdbsave but is designed to integrate feplotmodels in hdf5 format. The file linked to the model is not supposed to be temporary, and data names are linked to an SDT model data structure, which are typically in the model stack. The variable data names, must be of format field_name to store model.field in hdf5 format.

For model stack entries, the name must be of the type Stack_type_name to store cf.Stack'type','name'.

The function takes in argument the data base file, the feplot handle and the data name, which will be interpreted to be found in the feplotmodel. The data will be replaced by v_handlepointers in the feplotmodel. Data can be reloaded with command hdfmodel

sdthdf('hdfmodelsave','my_file.mat',cf,'Stack_type_name');

hdfmodel

This command loads v_handledata pointers in the feplotmodel at locations where hdf5 data have been saved. This command works from the hdf file side, and loads all the data contained with standard names in the feplotmodel. See hdfmodelsave for more information on the standard data names. Commando option -check only loads the data contained in the hdf file that is already instanced in the feplotmodel.

sdthdf('hdfmodel','my_file.mat',cf);

hdfclose

Handling hdf5 files in data structures can become very complex when multiple handles are generated in multiple data. This command thus aims to force a file to be closed.

sdthdf('hdfclose','my_file.mat');

A lower level closing call allows clearing the hdf5 librairies, when needed,

sdthdf('hdfH5close')

Example

Here is an example of offload to HDF5 based mat files, and how to access the data afterwards.

fname=fullfile(sdtdef('tempdir'),'ubeam_Stack_SE.mat');
fname2=fullfile(sdtdef('tempdir'),'ubeam_model.mat');
model=demosdt('demoubeam');cf=feplot;
cf.mdl=fe_case(cf.mdl,'assemble -matdes 2 1 NoT -SE');
cf.Stack{'curve','defR'}=fe_eig(cf.mdl,[5 50 1e3]);

% save(off-load) some stack entries to a file
sdthdf('hdfmodelsave',fname,cf,'Stack_curve_defR')
% save model but not the off-loaded entries
fecom('save',fname2);

cf=fecom('load',fname2); % reload the model
sdthdf('hdfmodel',fname,cf); % reload pointers to the entries
cf.Stack{'defR'}

For MATLAB >7.3 HDF based .mat files, you can open a v_handle pointer to a variable in the file using

fname=fullfile(sdtdef('tempdir'),'ubeam_Stack_SE.mat');
var=sdthdf('hdfreadref -level0',fname,'Stack_curve_defR')

See also

SDT handle


©1991-2011 by SDTools
Previous Up Next