Current location - Training Enrollment Network - Mathematics courses - How to check the calculation accuracy in ansys?
How to check the calculation accuracy in ansys?
Secondary development and development of ANSYS based on VC++6.0

Realization of interaction analysis in ANSYS

1 overview

ANSYS is a powerful finite element analysis software, which can realize multi-field and multi-field coupling analysis. It is an integrated large-scale finite element analysis software, which realizes the unified database of pre-and post-processing, solution and multi-field analysis. Support network floating of heterogeneous and heterogeneous platforms. The user interface is unified, and all data files are compatible in different kinds and platforms. Powerful parallel computing functions support distributed parallelism and memory-based parallelism. The software has the following features:

(1) Complete pretreatment function

ANSYS not only provides powerful tools for solid modeling and mesh generation, but also has special data interfaces for some large-scale general finite element software familiar to users (such as MSC/NSSTRAN, ALGOR, ABAQUS, etc.). ), and allow to read the finite element model data, even the material characteristics and boundary conditions from these programs, in order to complete the preliminary modeling work in ANSYS. In addition, there are nearly 200 kinds of element types in ANSYS, and these rich element characteristics enable users to conveniently and accurately establish a simulation calculation model reflecting the actual structure.

(2) Powerful solver

ANSYS provides the analysis of various physical fields, and it is the only finite element software that can integrate structure, heat, electromagnetism, fluid and acoustics. In addition to the conventional static and dynamic analysis of linear and nonlinear structures, it can also solve the dynamic analysis, structural nonlinearity and nonlinear buckling analysis of highly nonlinear structures. The provided solver is suitable for different problems and different hardware configurations.

(3) convenient post-processor

The post-processing of ANSYS is divided into general post-processing module (POST 1) and time course post-processing module (POST26). Post-processing results may include displacement, temperature, stress, strain, velocity and heat flow. The output form can be graphic display and data list.

(4) A variety of practical secondary development tools.

ANSYS not only has perfect analysis function, but also provides a variety of practical tools for users to carry out secondary development. Such as macro, Parametric Design Language (APDL), User Interface Design Language (UIDL) and User Programming Features (UPFs). Among them, APDL (ANSYS Parametric Design Language) is a parametric design interpretation language very similar to Fortran77, and its core content is macros, parameters, loop commands and conditional statements. Some general tasks can be automatically completed by establishing parametric models. UIDL (User Interface Design Language) is a language that ANSYS provides users with special programming interface design. It allows users to change some items in the graphical user interface (GUI) of ANSYS, and provides a powerful tool that allows users to flexibly use and organize the design of the GUI of ANSYS according to their personal preferences. UPFs (User Programmable Feature) provides a set of Fortran77 functions and routines to extend or modify the functions of the program. This technology fully shows the openness of ANSYS. Users can not only use it to cut the ANSYS program into any organizational form they need (such as defining a new material, a new element or giving a new yield criterion), but also write their own optimization algorithm and realize it by calling the whole ANSYS as a subroutine.

In view of the above characteristics, in recent years, ANSYS software has been widely used in engineering construction and scientific research at home and abroad. However, most of these applications are limited to the direct use of ANSYS software for practical engineering analysis, and the use of secondary development tools provided by ANSYS for finite element software design is rarely involved. In this paper, the secondary development function of ANSYS software is used for the first time, with VC++6.0 as the tool, ANSYS is secondary developed with APDL language, and the frame-tube structure-pile-raft foundation-soil interaction system and seismic response analysis program are compiled.

2 planning objectives

Aiming at a practical engineering problem, APDL language provided by ANSYS can encapsulate ANSYS software. APDL language is a parametric design language provided by ANSYS software, and its full name is ANSYS parametric design language. APDL language can be used for more efficient analysis and calculation, and can be easily used for automation (loops, branches, macros and other structures). In addition, it is an effective parametric modeling method. The system encapsulated by APDL language can only require the operator to input preprocessing parameters, and then automatically run ANSYS to solve the problem. However, macros written entirely by APDL still have weaknesses. For example, it is difficult to control the process of a program with APDL. Although it provides loop statements and conditional judgment statements, generally speaking, it is difficult to write a well-structured program. Although the interface input of parameters is provided, the function is not too strong and the interaction is not smooth enough. In view of this situation, the finite element analysis program of frame-tube structure-pile-raft foundation-soil interaction (LWS program for short) is developed by VC++6.0.

The design goal of this program is to package ANSYS with VC++6.0. Using VC++6.0, the interaction of frame-tube structure, pile-raft foundation and soil is simulated by ANSYS. Users only need to input seismic wave, calculation time step, damping ratio and other physical performance parameters. And the system can automatically call ANSYS calculation program, automatically perform grid division, ground motion loading and automatic solution. Due to the friendly, convenient and easy-to-use man-machine interface developed in the foreground, the system encapsulates the complex and difficult-to-understand and master ANSYS command stream in the background. Therefore, the program design can enable the engineering designers who have never studied ANSYS software seriously to use the system for finite element analysis of structural seismic performance, and has strong ability to deal with practical problems.

When the user inputs the calculation parameters, he can call the ANSYS command in the background to calculate, and ANSYS will return the calculation results to the user for post-processing.

The main principles and functions of programming are as follows:

(1) convenience principle, that is, the program module should have a good user interface and ease of use. The foreground design of the program adopts the standard graphical user interface (GUI) provided by Windows, and users can use it without special training. At the same time, the program should have good fault tolerance and error correction ability to avoid losses caused by improper user operation.

(2) The program system can provide users with the following functions:

① Allow users to input specific calculation parameters according to actual calculation conditions, including seismic wave selection, calculation time step, seismic wave amplitude modulation, etc.

② After inputting various parameters, users can modify, add and delete the input data before calculation to ensure that the input parameters are correct.

(3) Users can call ANSYS command stream in the background through the interface to calculate, and get the final calculation result file for users to post-process and analyze the results.

④ Users can add new functions or new secondary development to realize program upgrade.

(3) The program should be portable and independent of specific hardware devices. As long as ANSYS and VC++6.0 can be installed, the system can be used to ensure the universality of the program.

(4) The program code should be open and reusable. In this way, in the further design, designers can be guaranteed to modify and expand the code conveniently; At the same time, a certain design interface is provided, so that new designers can carry out new development according to the interface, and there is no need to make major modifications to the program to meet new special requirements.

The development platform of the program is Microsoft VC++6.0 and ANSYS6. 1, and it is programmed based on WindowsXP. The program is realized by using the Windows programming interface MFC provided by Microsoft and the ANSYS/Multiphysics products of ANSYS Company, and using the object-oriented programming method.

3 Main modules and program design

As shown in Figure 3-2, the main modules of the program are: user interface module, ANSYS calculation module, VC call interface module and VC post-processing module, which are discussed as follows:

3. 1 ANSYS module

In order to meet the special needs of users, ANSYS established an open architecture and provided secondary development interfaces APDL, UIDL and UPFs (user programming function). Among them, ANSYS interface allows users to connect their own VC code to ANSYS, or call ANSYS as a subroutine, which makes ANSYS have special functions.

The ANSYS module in this paper is developed with APDL language. The above-mentioned secondary development adopts parametric design method. Parameters are APDL variables (they are more like FORTRAN variables than FORTRAN parameters), so there is no need to explicitly declare parameter types, and all numerical variables are stored as double-precision numbers. Used but undeclared parameters are given a "minimum value" close to 0. Parametric design method is adopted in the secondary development, which enhances the readability and portability of the program. Users can automatically call the ANSYS module by changing the parameter values without knowing the specific structure of the program.

3.2 VC call module

VC calling module plays an important role in this system. It accepts the input of user interface and creates a process to call ANSYS module for calculation. When calling ANSYS in VC program, there are two tasks that must be completed. One is to enable the interface program to modify the command stream file path and file name of ANSYSB, which can be realized by registry programming; The second is to be able to run ANSYSB application in the interface program, which involves the programming of the creation process. Here are their specific implementations.

1. Registry Programming

After running ANSYS installation program on Windows(98/NT/2000/XP) system, some information, such as initial working path, file name, etc. , which is recorded in the registry of Windows system. The program of calling ANSYS calculation module with VC platform must specify the running directory of ANSYS software and the program path of ANSYS module developed with APDL language, so that the batch program of ANSYS software can read the command stream file from the given path. To modify these registry information in the interface program, you can use the registry editing API (application programming interface) function provided by Windows [30, 365, 438+0], which is realized as follows:

HKEY· SUBE; //Define subitems

Long lRet

char RegPath[200]= " SoftWare \ \ ANSYS,Inc . \ \ ANSYS \ \ ANSYS 6. 1 \ \ 0 ";

LRet=RegOpenKeyEx(HKEY current user, RegPath, 0, KEY_ALL_ACCESS, & amphsubkey); //Open subkey

if(lRet! =ERROR_SUCCESS) returns;

lRet=RegSetValueEx(hSubKey," Extension ",0,REG_SZ,(LPBYTE)"txt ",3); //Set the file extension read by ANSYS batch program.

if(lRet! =ERROR_SUCCESS) returns;

lRet=RegSetValueEx(hSubKey," Jobname ",0,REG_SZ,(LP byte)" ZHY ");

//Specify the file name of ANSYS module.

if(lRet! =ERROR_SUCCESS) returns;

LRet=RegSetValueEx(hSubKey, "WorkingDirectory", 0, REG_SZ, (LP byte)" E:\ \ LWS \ \ workspace ",16);

if(lRet! =ERROR_SUCCESS) returns; //Wrong key value returned.

RegCloseKey(hSubKey); //Close the subitem

After completing the above settings, run the ANSYS batch program, and the interface will become as shown in Figure 3-3.

As can be seen from the figure, the working path e of ANSYS module e: \ \ lws \ \ workspace, initial file name ZHY, ANSYS program file name ZHY.txt, and calculation result output file name ZHY.out have all automatically appeared in the input box of ANSYS batch processing program. down ANSYS can automatically read the command stream from ZHY.txt for calculation and output the results to ZHY.out file. If you want to change the path or file name of ANSYS module, you only need to modify the above program slightly.

2. Multi-process programming

In this paper, ANSYS is encapsulated in VC platform, and it is hoped that the interaction between the system and users will be handled in the foreground, while the calculation of ANSYS will be carried out in the background. This requires the system to be concurrent, so the multi-process programming mechanism is introduced. A process is an instance of a running program, which is dynamic, concurrent, independent, asynchronous and structured. Processes in the system dynamically emerge and die, and multiple processes run concurrently, executing their respective corresponding program segments and working for their respective goals. A program can contain multiple processes.

Figure 3-3 ANSYS batch operation interface

In VC++6.0, you can use the CreateProcess function to create a process to execute other programs, and you can set the priority of the process. The prototype of the CreateProcess function is:

Boolean creation process (

LPCTSTR lpAppliciatonName

LPTSTR lpCommandLine

LP security _ ATTRIBUTES lpProcessAttributes

LP security _ ATTRIBUTES lpThreadAttributes

Boer Bingley Tandel

DWORD dwCreationFlags

LPVOID lpEnvironment

LPCTSTR lpCurrentDirectory

LPSTARTUPINFO lpStartupInfo

LP process _ INFORMATION LP process INFORMATION

);

When the system calls CreateProcess, a process kernel object is created with an initial usage count of 1. The process kernel object is not the process itself, but a smaller data structure used by the operating system to manage the process. Then, the system creates a virtual address space for the new process, and loads the code and data of the executable file or any necessary DLL file into the address space of the process. Next, the system creates a thread kernel object for the main thread of the new process (its usage count is 1). Like the process kernel object, the thread kernel object is a small data structure used by the operating system to manage threads. By executing the C/C++ runtime startup code, the main thread starts to run, and finally the WinMain, wWinMain, main or wmain functions are called. If the system successfully creates a new process and a main thread, CreateProcess returns True.

The PszApplicationName and pszCommandLine parameters are used to set the name of the executable file to be used by the new process and the command line string to be passed to the new process respectively. The parameter of PszApplicationName can be NULL, which means that the system will use the full path to view executable files and will not search these directories; If the parameter is not NULL, you can pass the address to the name string of the runnable file contained in the pszApplicationName parameter. When the system finds the executable file, it creates a new process and maps the code and data of the executable file to the address space of the new process.

PsaProcess and psaThread parameters set the required security for process objects and thread objects respectively. You can pass NULL for these parameters, in which case the system will assign default security descriptors to these objects; You can also specify two SECURITY_ATTRIBUTES structures and initialize them to create your own security permissions and assign them to process objects and thread objects. Another reason for using the SECRURITY_ATTRIBUTES structure for the psaProcess and psaThread parameters is that any child process generated by the parent process can inherit either of these two object handles in the future. This program does not need to create other processes except the process of calling ANSYS calculation module. Therefore, the parameters of psaProcess and psaThread are NULL. Similarly, the binheritHandles parameter is FALSE.

The fdwCreate parameter is used to identify this flag so as to specify how to create a new process. The fdwCreate parameter can also be used to set the priority, but it should not be done for most applications, because the system will give the new process a default priority.

The PszCurDir parameter allows the parent process to set the current drive and directory of the child process. If this parameter is empty, the working directory of the new process will be the same as the directory of the application that generated the new process; If it is not empty, it must point to a string ending in 0, which contains the required working drive and working directory. This parameter can be selected as blank in the project.

The PsiStartInfo parameter is used to point to the STARTUPINFO structure. When Windows creates a new process, it will use the relevant members of the structure. Most applications will require the generated application to use only the default values. At least initialize all members in the structure to zero, and then set cb(cb is a member of the STARTUPINFO structure) to the size of the structure. For other specific members of STARTUPINFO structure, please refer to the help system MSDN of VC++6.0.

The PpiProcInfo parameter is used to point to the PROCESS_INFORMATION structure that you must specify. CreateProcess initializes the members of this structure before returning. The form of this structure is as follows:

Typedef structure _ procedure _ information {

Handling hProcess

Handling hThread

DWORD dwProcessId

DWORD dwThreadId

} process _ information;

CreateProcess opens the Process object and the thread object before returning, and puts the process-related handle of each object into the hProcess and hThread members of the PROCESS_INFORMATION structure.

To sum up, the key steps of the project creation process are as follows:

STARTUPINFO StartupInfo

PROCESS _ INFORMATION ProcessInfo;

memset(& amp; StartupInfo,0,sizeof(startup info)); //Allocate memory

startup info . CB = sizeof(startup info); //initialization

startup info . dw flags = STARTF _ USESHOWWINDOW;

startup info . wshowindow = SW _ show maximized;

If (! * CreateProcess(NULL,d:\\ProgramFiles\\Ansys

Inc \ \ ANSYS 6 1 \ \ bin \ \ Intel \ \ AnsysB ",NULL,NULL,FALS E,0,NULL,NULL & amp; StartupInfo。 ProcessInfo))

{

AfxMessageBox ("Error!" );

GetLastError();

}//Create process

3. Termination of the process

There are four ways to terminate the process: ① the main thread entry point function returns; ② One thread in the process calls the ExitProcess function; ③ A thread in another process calls the TerminateProcess function; (4) All threads in the process automatically stop running (this situation generally does not happen). In this paper, the first method is used to terminate the created process, that is, when the ANSYS calculation is completed, it returns through the function.

In WindowsXP system, if the ANSYS batch program runs, the window title will display "ANSYS completed". The program development of this paper can terminate the process of system creation through this feature. When the ANSYS calculation module is finished running, a message box will pop up, prompting that ANSYS has been calculated and can be post-processed.

User interface module

The user interface module mainly completes the interaction between the system and users. The user interface module includes two parts: calculation parameter input and program call. The main functions of the calculation parameter input part are to input seismic wave data, amplitude modulation, time step and so on. The calculation input consists of a dialog box. The interface of the calculation parameter input dialog box is as follows:

Figure 3-4 Calculation Parameter Input Interface

The program has set the input range of each parameter. If the parameter entered by the user exceeds this setting, the system will pop up a dialog box to remind the user that the input is wrong and needs to be re-entered. ANSYS program is called through the menu. The menu was not activated at first, but after inputting the parameters needed for 3D numerical simulation, the message activation menu was obtained. The advantage of this design is that it can remind users to input and check the relevant parameters used for three-dimensional numerical simulation, and prevent users from calling ANSYS directly to calculate without inputting parameters, which will cause errors.

The program design adopts the method of reading and writing files, inserts the input calculation parameters into ANSYS calculation module, and carries out secondary development with APDL language. The parametric design of ANSYS calculation module can be numerically simulated according to the input parameters.

3.3.4 Secondary Development of ANSYS Post-processing Module

ANSYS software provides two post-processors, which can post-process the results in time history.

And general post-processing. For the seismic response analysis of the interaction system, the simulation results can be output and transformed in the form of stress diagram, isoline (surface) and animation. POST 1 universal post-processor can be used to observe the whole model or some simulation results of the model at a certain moment, and can display the stress diagram and displacement deformation diagram of the structure under the action of earthquake; POST26, the post-processor of time history, is used to check the functional relationship between the analysis results of the specified points in the model and time, and can display the time history curve of each node variable in the model. So for most post-processing analysis, we can directly use the post-processor of ANSYS. However, because ANSYS is a general software, it is powerless or inconvenient for post-processing analysis in some special fields, so it needs secondary development to reduce post-processing work and improve post-processing efficiency.

In the seismic response analysis of interaction system, we sometimes pay attention not only to the time-history curve of each physical quantity, but also to its distribution in the height direction of the structure (such as interlayer displacement, interlayer shear force, interlayer acceleration response, etc.). The secondary development to solve this problem needs to combine the seismic response analysis characteristics of the interaction system.

Analysis of (1) physical quantity

In the time-history analysis of seismic response, we are concerned with the time-history of floor displacement, acceleration, column stress and strain, shear wall stress and strain, and also need to analyze the changes of floor displacement and floor acceleration. Considering that this paper will calculate a variety of working conditions, this program has written a post-processing program for common variables, which is universal and greatly improves the post-processing efficiency.

(2) Project implementation

Based on the above analysis, this program calls ANSYS through the interface program, reads the written post-processing command stream, reads the result database calculated by ANSYS, generates the result files of various variables, and then uses the post-processing module of this program to read and draw, and generates the result diagram. This process is realized by VC programming, and the algorithm flow chart of VC programming is shown in the post-processing module of Figure 3-2. (repost)

I have written down your serial number, and I will make it for you when it is adopted.