readmultvector, readcae: why are they 2?
readmultvector, readcae: why are they 2?
Altair Compose, an for Math, Scripting, Data processing and visualization, has a built-in suite of Altair’s results readers under the CAE Reader Library that can be used to extract data from CAE/Test result files.
The CAE reader library has over 20 functions in which 2 are used to extract multiple vectors of data from a given CAE/Test result file in CAE Reader library, namely - readmultvector, readcae
Why are they 2 functions for the same purpose (readmultvector vs readcae)? Which one do we use and when?
I will try to break it down based on 2 key factors.
- Syntax differences
- Speed/Performance
We will take the same sample results file from the above paper ‘bezel.h3d’ to compare the 2 functions.
The Bezel.h3d results file consists of:
Subcase | Type | Request | Component | Time step |
4 | 6 | # Nodes: 236 # Elements: 198 | Displacement: 4 (X, Y, Z, MAG) Stress: 21 different result components (von-mises, P1, P2, P3,XX,YY,ZZ,XY,YZ,ZX etc) for Z1,Z2,mid layers
| 1 |
- Syntax difference: Passing the arguments
The readmultvector function is used to extract the multiple vectors of data for the given range of Request/Component/Timestep information of a results file and arguments to this function are to be passed as ‘strings’ or ‘int’ datatypes.
This function supports multiple syntaxes and required arguments to be passed in a specific format;
readmultvectors(filename, subcase, type, startRequest, endRequest, startComponent, endComponent, timeRange)
this extracts data of specific ‘Subcase’, ‘Type’, range of request (Nodes/elements) between startRequest and endRequest, range of Component between startComponent, endComponent and for a given timeRange.
readcae function is also used to extract multiple vectors of data for a given/specified/range of Request/Component/Timestep information of a results file and these are parsed to the function as ‘strings’ or ‘int’ or ‘cell’ datatypes.
readcae(filename, subcase, datatype, request, component, time, outputType)
where request/component in above syntax can be in a matrix format:
[] - Extract all requests.
[i:j] - Extract ith to jth index (inclusive).
[i,j,k,l] - Extract the specified request indices.
Or
Cell supported format:
{} -Extract all requests.
{i,j,k,l} -Extract the specified indices.
{'req1','req2','req3'} -Extract the specified requests.
You can specify what output type you want to have from readcae function as the last argument ‘outputType’.
For more info go to the online help:
- Speed/Performance
There are multiple syntaxes that go along with both the functions so let’s take the most commonly used syntax for extracting different portions of data for comparison.
Let us compare the performance of both the functions with a use-case of extracting Von-mises stresses for elements having odd numbered Id’s.
First, let’s extract the von-mises stress using readmultvectors,
As readmultvector function extracts the data for a given range of request/component between start and end, we must create a variable which has a list of elements having odd numbered id’s and parse it to the readmultvector function.
tic
result_file = 'bezel.h3d';
%Extract Request (Node)list from result file
req = getreqlist('bezel.h3d',2,'Element Stresses (2D & 3D) (2D)');
for i = 1:numel(req)
%data_test(i,1) = req{i};
temp = strsplit(req{i},'E');
elementid(i,1) = str2num(temp{2});
end
x = find(mod(elementid,2) == 1);
for i = 1:numel(x)
element_extract{i,1} = ['E',num2str(elementid(x(i)))];
end
for i = 1: numel(element_extract)
output1(i,1)=readmultvectors(result_file,2,'Element Stresses (2D & 3D) (2D)',element_extract{i},element_extract{i},'vonMises (Z1)','vonMises (Z1)',1);
end
toc
The time taken for the above script to extract the Von-mises Stress for odd element numbers from the result file is 0.039 seconds. Most of the elapsed time is taken for executing readmultvectors function in “for” loop to extract result for each element at a time.
Now, let us extract the same results using readcae function,
As readcae function can take matrix of indices that is of interest as argument. We can parse the matrix of elements which have odd numbered id’s to the function,
tic
result_file = 'bezel.h3d';
%Extract Request (Node)list from result file
req = getreqlist('bezel.h3d',2,'Element Stresses (2D & 3D) (2D)');
% get element numbers
for i = 1:numel(req)
%data_test(i,1) = req{i};
temp = strsplit(req{i},'E');
elementid(i,1) = str2num(temp{2});
end
%find the element numbers which has odd numbering
x = find(mod(elementid,2) == 1);
output = readcae(result_file,2,'Element Stresses (2D & 3D) (2D)',[x(1):x(end)],'vonMises (Z1)',[],1);
toc
The time taken to extract the Von-mises Stress for odd element numbers from the result file using readcae function is 0.022 seconds.
In this simple use-case, with readcae function we achieve a 40% of performance boost. Major contribution for this performance improvement compared to readmultvectors function is because readcae function avoids the “for” loop to extract the results.
With the ease of parsing the required inputs to the function and performance that it brings to the table, for me, readcae is a go-to function for most of the use-cases, so give it a try for your Use-case !
Comments
-
Thanks for sharing! There is also a useful explanation about the different ways to import CAE data at the 3rd module of the Signal Processing video training using Altair Compose:
Regards,
Roberta
1