Some students may encounter situations when operating APDL where they need to read or import large arrays. However, if using the conventional *Vwrite or *Vread methods, problems are highly likely to occur – either ANSYS crashes or the person crashes. Today, Shuige will introduce a method using the matrix toolkit in APDL, which is simple, fast, and free from format troubles when reading or writing! As for how large an array needs to be to be considered a large array? In APDL, Shuige suggests that if any dimension of the array exceeds 10000, it can be classified as a large array, and the method in this article can be adopted!
For the matrix toolkit and related function index, refer to the following article:
APDL Matrix Operations Introduction and Common Matrix Function Index
The main commands used for import and export are
*DMAT: Create matrix, can create from file data;
*EXPORT: Export matrix, can convert matrix object to ordinary array object, or export array to file.
I. Data Export
First generate a 10000*10 random array, use *DMAT to convert the ordinary array object to a matrix object, then use the *EXPORT command to convert it to CSV data.
The code is as follows:
finish
clear
/prep7
*dim,AA,array,10000,10
*do,i,1,10000
*do,j,1,10
AA(i,j)=rand(1,10)
*enddo
*enddo
*Dmat,AA_Math,D,import,APDL,AA
*export,AA_Math,CSV,Mytest
In the working folder, you can find the Mytest file. This file cannot specify an extension, so you can manually add .csv, then open it with Excel. Of course, you can also directly use UE or Matlab to read the data.

Manually add the .csv extension, then open with Excel.

Data verification:
To verify whether the data was exported correctly, now randomly check one data point. First, obtain a data point in APDL, for example:
dd=AA(8645,6)$*status,dd
Its value is:

In Excel, find the corresponding position, its value is as shown below:

The two are consistent.
II. Data Import
Unlike data export, APDL’s matrix toolkit cannot directly read CSV files and requires certain format processing. Shuige recommends using the toolkit’s proprietary MMF format. The MMF format is as follows:

The first 6 lines are comment lines. Line 7 specifies the number of rows and columns when importing data into the array. The following is single-column data, arranged in row-first then column order.
The usage method is as follows:
Now assume we need to read a 20000*30 array into APDL.
First, use Matlab to generate 20000*30 random array data, and export it to a file TestB in row-first then column order.

The Matlab code is as follows:
% Generate 20000x30 random array
A = rand(20000, 30);
% Convert matrix to a single-column matrix, 20000*30 rows, 1 column
A_col = reshape(A, [], 1);
% Specify output file name
filename = 'TestB.txt';
% Open file for writing
fileID = fopen(filename, 'w');
% Check if file opened successfully
if fileID == -1
error('Failed to open file for writing.');
end
% Write data, each value followed by a space
fprintf(fileID, '%.6f\n', A_col);
% Close file
fclose(fileID);
Open TestB.txt, manually add the following information. Of course, if it’s batch processing, you can use Matlab or Python to handle this process.

In APDL, first use *DMAT to read the MMF format file, then use *EXPORT to convert it to an APDL array.
The APDL code is as follows:
*DMAT,BB_MATH,D,import,MMF,testB
*export,BB_Math,APDL,BB
Data verification, click Parameters>Array>Define, as shown below.

Data has been read successfully, now verify a single data point.
dd=BB(15869,26)
*Status,DD
Then obtain the data at that position in Matlab. Screenshots of both are shown below.

The values match, indicating successful reading!
Using the above method, for arrays of this tens-of-thousands level, APDL reading takes only about 3 seconds, far more efficient than *Vread or *Mread!
If you find this useful, feel free to repost and share!









No comments yet