|
|
3 |
| Structural Analysis Programming Course (2) |
|
|
In the previous online seminar, we explained not only the basics of structural analysis programming but also an overview and usage methods of the FRAME in-plane SDK. This time, we will explain a sample program that uses the functions provided by the FRAME in-plane SDK to actually input calculation conditions and output the calculation results to a text file.
|
The sample program for the FRAME surface-mount SDK consists of the following files. Please note that to run this sample program, you will also need the 2 files "FrameSDK.DLL" and "FrameSDKHeader.pas," which are included with the FRAME surface-mount SDK.
| ■ Table 1: Structure of Sample Files for the FRAME-side SDK |
| FrameSample.dpr |
Sample program project files |
| FileUtil.pas |
File input/output classes |
| InputDataSample.txt |
Sample input data |
| OutputSample.F11〜.F71 |
Sample output of calculation results |
| SampleMain.pas |
Main form (source code section) |
| SampleMain.dfm |
Main form (source code section) |
|
Functions to use and methods for importing |
|
The FRAME internal SDK provides only 3 functions. Furthermore, the FrameCalc function is the only one that actually provides calculation functionality. The process for using the FRAME internal SDK involves first setting the input conditions within a structure of type FR_SDK_MAINDATA, and then passing a pointer to this structure to the FrameCalc function. The calculation results are obtained by dereferencing the return value, which is of type Pointer.
| ■ Table 2: Functions provided by the FRAME-side SDK |
| FrameCalc function |
It executes the surface mesh analysis calculation and returns the execution results. |
| FrameResMemFree function |
Release the memory allocated for the calculation result area.
Normally, it is called after the FrameCalc function. |
| FrameErr function |
Obtain detailed information about errors that occur during the calculation of the FrameCalc function. |
In this sample program, the necessary components are imported collectively within the FrameSDKHeader.pas file, so I will provide a brief explanation of those entries. By consolidating the import statements into a single file, it becomes easier to use similar functionality in other applications; you only need to add this .pas file to the "uses" section along with the DLL.
■FrameSDKHeader.pas
unit FrameSDKHeader;
:
(Omitted)
:
implementation
// Frame Calc
function FrameCalc ( lpszFramePath : PChar;
lpstAgInData : PFR_SDK_MAINDATA ) : Pointer; stdcall;
external 'FrameSDK.dll';
// Free the Result Data Area
procedure FrameResMemFree ( lpstAgOutData : Pointer ) ;
stdcall;
external 'FrameSDK.dll';
// Get Error Information
function FrameErr ( lpErrMsg : PPChar ) : Integer ;
stdcall;
external 'FrameSDK.dll';
end;
|
The above example shows how the 3 functions mentioned previously are imported from FrameSDK.dll, but it differs from the typical way of declaring functions within an application in that it includes "stdcall" and "external." "stdcall" refers to a calling convention, which specifies the order in which parameters are passed to a routine and the method for handling exceptions. The "external" declaration specifies the object file or library name that contains the external routine (function) being called.
|
Sample program screen layout |
|
The screen layout of the sample program is shown in the figure below. Events are configured for each TButton component.
 |
| (1)ButtonFrameDir |
: |
TButton |
|
(6)EditFileOut |
: |
TEdit |
| (2)EditFrameDir |
: |
TEdit |
|
(7)ButtonCalc |
: |
TButton |
| (3)ButtonFileIn |
: |
TButton |
|
(8)OpenDialogFrameDir |
: |
TOpenDialog |
| (4)EditFileIn |
: |
TEdit |
|
(9)OpenDialogFileIn |
: |
TOpenDialog |
| (5)ButtonFileOut |
: |
TButton |
|
(10)SaveDialogFileOut |
: |
TSaveDialog |
■ Figure 1: Functions provided by the SDK within the FRAME plane |
(1) Regarding the buttons numbered (5) and below, clicking them executes either an OpenDialog or a SaveDialog. The OpenDialog prompts the user to specify the installation folder of the FRAME application, the filename of the input data, and the filename for saving the calculation results. The SaveDialog also prompts for the filename to save the calculation results. Upon confirmation, the values entered are assigned to the corresponding Edit fields numbered (2) through (6).
|
Contents of the input data file |
|
Here, we will describe the general format of the input data file used in the sample program, as well as the Delphi classes used for reading the data.
 |
| ■ Figure 2: Example of input data model (BOX Culvert, structural diagram, load conditions, and support conditions) |
■ Example input data (inputDataSample.txt)
FRAME-02
TITLE FrameSDKSample
CONTROL1: Fixing point, component material, cross-section, C-shaped bracket, spring, support C, support point
6 7 1 2 1 0
1 0
CONTROL2: Load, Combination, Extraction, Double, Rigid S, Rigid B.
3 2 1 0 0 0
CONTROL3, Rina, Mmax, landing point, surcharge, pre-order
1 0 0 0 0
POINT
6
1
0.0000 4.0000
2
5.0000 4.0000
3
10.0000 4.0000
4
0.0000 0.0000
5
5.0000 0.0000
6
10.0000 0.0000
:
(Omitted)
:
END
|
The contents of the input data file begin with a start card (FRAME-02), and then values are defined sequentially, including the title (TITLE), control data (CONTROL1 to CONTROL3), coordinate data (POINT), material data, and cross-section data. Values are separated by half-width spaces. To read this data line by line and split each line into columns, the Textfile variable and the TStringList class are used.
Textfile variables are used to load a file into memory and read it line by line, while TStringList is utilized to further split each line into columns.
For specific usage examples, I will explain them while showing you the actual code below.
■TFrameFileClass.LoadFromFile(FileUtils.pas)
57 function TFrameFileClass.LoadFromFile( FileName:string;
var FrameData: FR_SDK_MAINDATA ):boolean;
58 var
59 i : integer;
60 j : Integer;
61 txtfile : TextFile;
62 Line : String;
63 Title : String;
64 Fields : TStringList;
65 begin
66 Result := False;
67 Fields := TStringList.Create;
68 AssignFile( txtfile, FileName );
69 Reset( txtfile );
70 try
71 // FRAME-02
72 Readln( txtfile, Line
);
73
74 // TITLE
75 Readln( txtfile, Line
);
76 Title := Copy( Line,
11, 40 );
77 StrCopy( FrameData.aszCalcTitle, PAnsiChar(Title) );
:
:
(Omitted)
:
:
109 // POINT
110 Readln( txtfile, Line
);
111 SetLength( NodeData,
FrameData.nNodeCnt );
112 for i := 0 to FrameData.nNodeCnt-1
do
113 begin
114
Readln( txtfile, Line );
115
Fields.CommaText := Line;
116 NodeData[i].nNodeNo := StrToInt(Fields.Strings[0]);
117 NodeData[i].dbXPoint :=
StrToFloatDef(Fields.Strings[1], 0.000 );
118 NodeData[i].dbYPoint :=
StrToFloatDef(Fields.Strings[2], 0.000 );
119 end;
120 FrameData.lpNode :=
@NodeData[0];
:
:
(Omitted)
:
:
330 Result := True;
331 finally
332 CloseFile( txtfile );
333 Fields.Free;
334 end;
335 end;
|
• Variables defined within the LoadFromFile function
| Variable name |
Type |
Uses |
| i, j |
Integer |
Loop variables |
| txtfile |
TextFile |
This function is used to read an input data file line by line |
| Line |
AnsiString |
A string used to store data for a single line |
| Title |
AnsiString |
A string to store the title |
| Fields |
TStringList |
Used to split lines |
Within the LoadFromFile function, the following variables are defined.
These variables are commonly used during the reading process, starting from the "FRAME-02" card in the input data file and continuing until the "END" card.
■Explanation for each line
From the code mentioned earlier, I will take title data and coordinate data as examples to explain the processing involved.
First, lines 68 to 69 use the AssignFile procedure to associate the txtfile variable with the input data file. All subsequent operations on the txtfile variable are performed on the input data file specified by FileName. Next, the Reset procedure opens the file. At this time, the file position is set to the beginning of the file. Starting from line 73, the file is read 1 line at a time using the Readln procedure.
When the `Readln` procedure is called, a single line of text from the current position is stored in the string variable specified as the second argument (in this case, `Line`).
Since the file pointer has moved to the beginning of the next line, when the Readln procedure is called again, the Line variable will contain the data from the next line.
In this way, we will only use the Readln procedure to extract each line of data.
Next, the title data is read. Due to the format of the input file, characters from the 11th to the 50th position (40 characters) on each line are designated as the title. Therefore, the `Copy` function is used to read characters from the 11th position up to the 40th character.
| Title := Copy( Line, 11, 40 ); |
Next, we read in the coordinate data. At this point, when the `Readln` procedure is executed on line 110, the variable `Line` contains the value "POINT 6".
Regarding the number "6," it represents a grade point, but this information is already defined in the control data section of the input data file, specifically in rows 3-4, before the coordinate data. Therefore, the sample data uses this information, and here, it is simply skipped over.
| SetLength( NodeData, FrameData.nNodeCnt
); |
Furthermore, the `SetLength` function is used to dynamically allocate the number of elements (length) for the array `NodeData`, and regarding `NodeData`, it is declared as follows in the private section of the `TFrameFileClass`:
| NodeData
: array of FR_SDK_NODE; |
The `NodeData` is declared as a dynamic array of the `FR_SDK_NODE` structure type. At line 119, a `for` loop begins, iterating through the number of grid points and setting the grid point information within each structure element.
for i := 0 to FrameData.nNodeCnt-1 do
begin
Readln( txtfile, Line );
Fields.CommaText := Line;
NodeData[i].nNodeNo := StrToInt(Fields.Strings[0]);
NodeData[i].dbXPoint := StrToFloat(Fields.Strings[1]);
NodeData[i].dbYPoint := StrToFloat(Fields.Strings[2]);
end;
FrameData.lpNode := @NodeData[0]; |
Here, the `Readln` procedure stores 1 line of characters in the `Line` variable. At this point, the `Line` variable contains a value such as the following.
• The result of executing `Readln` on line 121
| Line = "
1 0.0000 4.0000" |
At this point, the value stored in the Line variable is just a single string. To break this down into 3 values: "1", "0.0000", and "4.0000", we use the CommaText property of the TStringList class. When you assign a string to the CommaText property, it automatically sets the Strings property, which is an array of strings, using spaces or commas as delimiters.
• The result of assigning a value to the CommaText variable on line 122
Fields.Strings[0] = "1"
Fields.Strings[1] = "0.0000"
Fields.Strings[2] = "4.0000"
|
From this point onward, the string values stored in the Strings property of the Fields object are cast to numeric types using functions such as StrToInt andStrToFloat, then set as member variables of the NodeData record. The NodeData record is then stored within the FrameData record, completing the process of reading grid data.
|
Output the calculation results to a file |
|
This document explains an example of how to output calculation results received from the FrameCalc function to a text file.
Here, instead of reading data from an input file, we will write to a text file by referencing the values of pointers.
This explanation describes the process of calculating and outputting the results for displacement due to stress concentrations (under basic load cases) to a file, using the following format.
■ Example of calculation results output for grid point displacement (under basic load cases)
Grid point displacement
CASE 1 6
1 -0.013
-1.071 -0.186
2 -0.049
-0.963 0.000
3 -0.085
-1.071 0.186
4 0.000
-1.016 0.197
5 -0.049
-0.842 0.000
6 -0.099
-1.016 -0.197
Grid point displacement
CASE 2 6
1 -0.109
-0.259 -0.083
2 -0.110
-0.133 0.089
3 -0.110
0.015 0.032
4 0.000
-0.247 0.112
5 0.001
-0.113 -0.004
6 0.001
0.016 0.019
:
:
(Omitted)
|
In the sample program, functions are divided according to the output file. The calculation results for grid point displacements, which we will discuss in this section, are output within the ResultSetF21ToFile procedure inside the TFrameFileClass class. FrameResData is a pointer variable of type PFR_SDK_MAINRES that stores the calculated results from the FrameCalc function, and it is defined in the private section of the class.
■TFrameFileClass.ResultSetF21ToFile(FileUtil.pas)
procedure TFrameFileClass.ResultSetF21ToFile;
var
i, j : Integer;
outputSL : TStringList;
F21DIS : PFR_SDK_F21DIS;
F21NodeDis : PFR_SDK_NODEDIS;
begin
outputSL := TStringList.Create;
F21DIS := FrameResData.lpF21Dis;
try
for i := 0 to FrameResData.nF21DisCnt-1
do
begin
outputSL.Add('Grid point displacement');
outputSL.Add(
Format( 'CASE %4d %4d',
[F21DIS^.nFndmntlLdCaseNo, F21DIS^.nNodeCnt ] ) );
F21NodeDis := F21DIS^.lpNodeDis;
for j := 0 to F21DIS^.nNodeCnt-1
do
begin
outputSL.Add( Format(
'%5d %14.3f %14.3f %14.3f',
[ F21NodeDis^.nNodeNo,
F21NodeDis^.dbHorzDsplcmnt,
F21NodeDis^.dbVertDsplcmnt,
F21NodeDis^.dbRevDsplcmnt
] ) );
Inc( F21NodeDis
);
end;
Inc( F21DIS
);
end;
outputSL.SaveToFile( ChangeFileExt( FFileName, '.F21' ) );
finally
outputSL.Free;
end;
end;
|
The data pointed to by the pointer FrameResData, which is a record type, contains the calculation results for grid point displacements. These results can be obtained by referencing the lpF21Dis field within that record, which itself is a pointer to another record of the same type. The key point here is that FrameResData only provides the address of the grid point data, and when actually accessing the data for each grid point, a different pointer variable named F21DIS, of the same type, is used.
First, a pointer to the grid point displacement data within FrameResData is assigned to F21DIS. At this point, the grid point information for the first load case is stored in the memory location referenced by F21DIS. F21DIS contains header information such as the load case number and the number of grid points, and the grid point displacements are stored at the memory location pointed to by the pointer lpNodeDis within the record referenced by F21DIS. Similarly, a pointer variable of the same type, F21NodeDis, is created, and on line 444, the value of lpNodeDis is assigned to it.
At this point, the F21NodeDis variable contains the displacement information for the first grid point of load case 1. Subsequently, a loop using a "for" statement can be used to iterate through all the grid points, and the displacement data for all grid points in load case 1 can be accessed from F21NodeDis. However, F21NodeDis is not an array-type pointer.
Now, how do we access the calculation results for the remaining degree points?
Inside the for loop, the `Inc` procedure is performed on the pointer `F21NodeDis`. The `Inc` procedure is commonly used to increment numerical values; however, when a pointer is specified as an argument, the position of the pointer moves by the size of the pointer's data type. A memory area for the number of grid points is allocated for `F21NodeDis`, and performing the `Inc` procedure moves the pointer's position to the beginning of the next element. Consequently, when `F21NodeDis` is referenced after the `Inc` procedure, it retrieves the displacement information for the next grid point.
Furthermore, the values of the record's member variables are extracted from the pointer, formatted using the Format function, and then stored 1 line at a time in an instance class called OutputSL, which is a TStringList. To write each line, the Add function of the TStringList class is used, and finally, the SaveToFile function of the TStringList class is also used to output the data to a file.
The next online seminar will be "Structural Analysis Programming Course (3)". We plan to explain the development of Delphi programs using automation for architectural structural analysis (Mutiframe). We look forward to your continued interest.
Announcement of paid seminars
| Introduction to Programming for Engineers Seminar CPD accredited: 6.2 points |
| • Date and time |
June 3, 2011 (Friday), 9:30 AM to 4:30 PM |
| • Course fees |
Price for 1 person: 15,750 yen (including tax) |
| • This is the main venue |
FORUM8 Tokyo headquarters, GT Tower seminar room
※TV conferencing systemThe event will be held simultaneously in Tokyo, Osaka, Nagoya, and Fukuoka |
|
|
| (Featured in the "Shinryoku no Go" issue of Up&Coming '11) |
 |
|







>> Product comprehensive catalog

>> Premium membership services
>> Financial support
| Recently released products |
|
|
|