An OpenFOAM acceleration method, device, equipment and medium based on linear matrix solution

By setting up a matrix conversion system in OpenFOAM, converting the LDU format matrix into CSR format, and performing iterative calculations on the DCU, the problems of low linear matrix solution performance and large storage space in OpenFOAM are solved, and the computing efficiency is improved.

CN115509536BActive Publication Date: 2025-05-06NORTHWEST UNIV
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211137364.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-19
Publication Date
2025-05-06
Estimated Expiration
2042-09-19

AI Technical Summary

Technical Problem

In OpenFOAM, linear matrix solution performance is low and the storage space occupies a large amount, resulting in low computing efficiency.

Method used

By setting the LDU→CSR matrix conversion system in OpenFOAM, compiling the relevant code in DCU, converting the LDU format matrix into a CSR format matrix, and iterating on the DCU to calculate the matrix, and finally converting the result back to the LDU format.

Benefits of technology

Through matrix format conversion, storage space is saved, and computing efficiency is improved in iterative computing, significantly improving the solution performance of OpenFOAM.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115509536B_ABST
    Figure CN115509536B_ABST
Patent Text Reader

Abstract

The invention belongs to the field of computational fluid dynamics, and specifically relates to an OpenFOAM acceleration method, device, equipment and medium based on linear matrix solution. After OpenFOAM reads grid information to generate an LDU matrix, the invention adds a matrix format conversion operation, and compiles related code programs so that the algorithm can run on a DCU acceleration card. Then, the DCU runs an OpenFOAM example, and the original LDU matrix format is converted into a CSR matrix format that can be calculated by the DCU. Compared with a traditional dense storage method, the CSR format saves a lot of space. Finally, the DCU kernel is called to iteratively calculate the matrix, and after the calculation is completed, the result is converted back into an LDU matrix recognized by OpenFOAM, so that a lot of calculation time is saved in the solution process, thereby improving the solution performance of OpenFOAM, and also provides a reference for people on GPU acceleration performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of computational fluid dynamics, and in particular relates to an OpenFOAM acceleration method, device, equipment and medium based on linear matrix solution. Background Art

[0002] OpenFOAM is an object-oriented CFD library written in C++. Similar to other commercial software such as Fluent and CFX, it includes a series of pre-processing tools, partial differential equation solvers and post-processing tools, and provides a solver framework, including grid generation, finite volume discretization method, linear equation system solving, data structure and input and output processing. The problems solved involve engineering, science and other fields, and can solve complex flows such as chemical reactions, turbulence, heat transfer, and transmission, as well as solid dynamics and electromagnetics.

[0003] The linear solution performance in OpenFOAM is also a hot topic of concern. In OpenFOAM, the matrices obtained by discretizing the physical model through the finite volume method are stored in an LDU format. The advantage of this format is that for sparse matrices, most of the zero elements do not occupy additional storage space, which is more space-saving, especially when the non-zero elements are symmetrically distributed relative to the diagonal. However, while the LDU matrix saves space, it also brings the problem of low access efficiency, especially in the iterative solution process of the linear matrix system, due to a large number of matrix-vector multiplication operations, it is necessary to frequently access the matrix elements, thus forming a performance bottleneck. Studies have shown that the most computationally intensive part of the example running process is the solution of the linear equation system, which accounts for about 80% of the entire program execution. The powerful computing power of heterogeneous acceleration program algorithms, especially intensive algorithms, are not yet mature, and the solution efficiency in the existing technology is low, and the storage space is large. Summary of the invention

[0004] In order to overcome the shortcomings of the prior art, the purpose of the present invention is to provide an OpenFOAM acceleration method, device, equipment and medium based on linear matrix solution to solve the problems of low solution efficiency and large storage space occupation in the prior art.

[0005] In order to achieve the above object, the present invention adopts the following technical solutions:

[0006] In a first aspect, the present invention provides an OpenFOAM acceleration method based on linear matrix solving, comprising:

[0007] Step 1: Read the mesh information in OpenFOAM and generate a matrix in LDU format; set up the LDU→CSR matrix conversion system and compile the relevant code in DCU;

[0008] Step 2: Run the OpenFOAM example through DCU, read the example grid information, convert the original LDU format matrix into a CSR format matrix, and complete the matrix-to-vector conversion;

[0009] Step 3: The CPU copies the incoming data and transfers the copied data on the CPU side to the DCU memory, calling the DCU kernel to iteratively calculate the matrix, and outputs the CSR format data after convergence;

[0010] Step 4: Convert the output CSR format data back into LDU format data recognized by OpenFOAM, and pass the calculation results back to OpenFOAM.

[0011] Furthermore, the relevant code is compiled in the DCU as follows:

[0012] Write pseudocode for LDU→CSR format conversion, convert this pseudocode into HIP code, and write the solver using HIP code and integrate it into DCU.

[0013] Furthermore, the matrix in the LDU format is the OpenFOAM data storage format, a library reference is added to the OpenFOAM example file controlDict file, and the DCU solver is used in the example file fvSolution file to solve various physical quantities.

[0014] Furthermore, the step 2 specifically includes:

[0015] Run the OpenFOAM example and call the DCU accelerator card. After importing the grid, OpenFOAM stores the corresponding LDU format data according to the grid; the diagonal elements and the upper and lower triangle elements are stored in three vectors lduMatrix.diag(), lduMatrix.upper(), and lduMatrix.lower() respectively, and the index values ​​of the upper and lower triangle elements share two index vectors; upperAddr stores the row index of the upper triangle elements and expresses the column index of the corresponding elements of the lower triangle. lowerAddr can express both the column index of the upper triangle elements and the row index of the lower triangle elements; the format conversion code is used to convert the LDU format data into data stored in the CSR format; the CSR format mainly uses three arrays to represent the content of the matrix, where Value is the value of the non-zero element in the matrix, Col_Index stores the column index of the non-zero element, and Row_Offsets stores the index of the first non-zero element in each row in Value, calculates the row index of each non-zero element, and locates the non-zero element.

[0016] Furthermore, the matrix-vector conversion is specifically as follows: first traverse the order of the LDU matrix and the number of lower triangular and upper triangular elements, calculate the number of non-zero elements in each row, insert the lower triangular matrix elements, diagonal matrix elements and upper triangular matrix elements in order, calculate the matrix value and its corresponding index value for each matrix element, and return the newly generated CSR format matrix.

[0017] Furthermore, the step 3 specifically includes:

[0018] After the format conversion is completed, the solver in the DCU accelerator card is called to solve. The solver is modified on the DCU according to the PCG or PBiCG algorithm in OpenFOAM, and the converted CSR format is used for calculation. After the calculation is completed, the CSR format data is output and the DCU memory is released.

[0019] Furthermore, in step 4, the calculation results are transmitted back to OpenFOAM and then viewed through a post-processing tool, such as Paraview or Tecplot.

[0020] In a second aspect, the present invention provides an OpenFOAM acceleration device based on linear matrix solving, comprising:

[0021] The matrix generation and matrix conversion system setting module is used to read the mesh information in OpenFOAM and generate the matrix in LDU format; set up the LDU→CSR matrix conversion system and compile the relevant code in DCU;

[0022] The example grid information reading module and matrix-vector conversion module are used to run the OpenFOAM example through DCU, read the example grid information, convert the original LDU format matrix into the CSR format matrix, and complete the matrix-vector conversion;

[0023] The matrix iterative calculation and CSR format data output module is used to copy the incoming data through the CPU, transfer the copied data on the CPU side to the DCU memory, call the DCU kernel to iteratively calculate the matrix, and output the CSR format data after convergence;

[0024] The matrix format reconversion and viewing module is used to convert the output CSR format data into LDU format data recognized by OpenFOAM, and transmit the calculation results back to OpenFOAM.

[0025] In a third aspect, the present invention provides a computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements any of the above-mentioned OpenFOAM acceleration methods based on linear matrix solving when executing the computer program.

[0026] In a fourth aspect, the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the OpenFOAM acceleration method based on linear matrix solution as described in any one of the above items is implemented.

[0027] The present invention has at least the following beneficial effects:

[0028] After OpenFOAM reads the grid information to generate the LDU matrix, the present invention adds a matrix format conversion operation, and by compiling the relevant code program, the algorithm can be run on the DCU acceleration card, and then the OpenFOAM example is run through the DCU to convert the original LDU matrix format into the CSR matrix format that the DCU can calculate. The use of the CSR format saves a lot of space compared to the traditional dense storage method; finally, the DCU kernel is called to iteratively calculate the matrix, and after the calculation is completed, the result is converted back into the LDU matrix recognized by OpenFOAM, which saves a lot of calculation time in the solution process, thereby improving the solution performance of OpenFOAM, and also provides a reference for people on GPU acceleration performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] The accompanying drawings constituting a part of the present invention are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the accompanying drawings:

[0030] Figure 1 The flow chart of the OpenFOAM linear matrix solution structure design of the present invention;

[0031] Figure 2 Compile the structure diagram of the OpenFOAM DCU solver of the present invention;

[0032] Figure 3 The figure is a configuration method diagram of the OpenFOAM example solver of the present invention;

[0033] Figure 4 This is the LDU→CSR matrix conversion format diagram of the present invention;

[0034] Figure 5 The schematic diagram of the module of an OpenFOAM acceleration device based on linear matrix solution of the present invention is shown in FIG. DETAILED DESCRIPTION

[0035] The present invention will be described in detail below with reference to the accompanying drawings and in combination with embodiments. It should be noted that the embodiments and features in the embodiments of the present invention can be combined with each other without conflict.

[0036] The following detailed description is an exemplary description, which is intended to provide further detailed description of the present invention. Unless otherwise specified, all technical terms used in the present invention have the same meaning as those generally understood by those skilled in the art to which the present invention belongs. The terms used in the present invention are only for describing specific embodiments, and are not intended to limit the exemplary embodiments according to the present invention.

[0037] Example 1

[0038] like Figure 1 As shown, an OpenFOAM acceleration method based on linear matrix solution includes:

[0039] Step 1: Read the mesh information into OpenFOAM and generate a matrix in LDU format; set up the LDU→CSR matrix conversion system and compile the relevant code in the DCU (Deep Computing Unit).

[0040] HIP code writing is done in the DCU solver.

[0041] Compile related code, unlike pure CPU programs, DCU extension acceleration methods need to utilize the computing power of DCU devices, and must be compiled by a specific compiler to produce executable instructions for the DCU device. Therefore, the OpenFOAM DCU solver integrates a cross-framework hybrid compilation model. Figure 2 As shown, the DCU solver package extended from the OpenFOAM standard solver base class lduMatrix::solver is compiled using Wmake in the OpenFOAM framework, and the DCU accelerated HIP method used by the solver is compiled using hipcc.

[0042] Write the HIP code for format conversion in the DCU accelerator card, and write the LDU→CSR pseudo code. Specifically, first traverse the order of the LDU matrix and the number of lower and upper triangular elements, calculate the number of non-zero elements in each row, and then insert the lower triangular matrix elements, diagonal matrix elements, and upper triangular matrix elements in order, calculate the matrix value and its corresponding index value for each matrix element, and then return the newly generated CSR format matrix. The pseudo code of LDU→CSR is:

[0043] for i=0to nonZeroTriangleElementNumber:

[0044] lowerRowIndex=lowerAddr[i];

[0045] upperRowIndex=upperAddr[i];

[0046] rowOffsets[lowerRowIndex+1]++;

[0047] rowOffsets[upperRowIndex+1]++;

[0048] / / Update rowOffsets

[0049] rowOffsets[0]=0;

[0050] for i=0 to rowNumber:

[0051] rowOffsets[i+1]+=rowOffsets[i];

[0052] / / First insert lower triangle elements

[0053] for i=0 to nonZeroTriangleElementNumber:

[0054] rowIndex=upperAddr[i]

[0055] colIndex=lowerAddr[i]

[0056] offSets=rowOffsets[row]++;

[0057] Value[offSets]=lower[i];

[0058] ColIndex[offsets]=colIndex;

[0059] / / Secondly insert diagonal elements

[0060] for i=0 to rowNumber:

[0061] offSets=rowOffsets[i]++;

[0062] Value[offSets]=diag[i];

[0063] ColIndex[offSets]=i;

[0064] / / Thirdly insert upper triangle elements

[0065] for i=0 to nonZeroTriangleElementNumber:

[0066] rowIndex = lowerAddr[i];

[0067] colIndex = upperAddr[i];

[0068] offSets = rowOffsets[i];

[0069] Value[offSets] = upper[i];

[0070] This pseudo code is converted into HIP code, and the solver is written in HIP code and integrated into DCU.

[0071] DCU is an accelerator card specifically designed for AI and deep learning. Similar to GPU, HIP is the programming language on the DCU accelerator card.

[0072] Step 2: Run the OpenFOAM example through DCU, read the example grid information, convert the original LDU format matrix into a CSR format matrix, and complete the matrix-to-vector conversion.

[0073] The LDU format matrix is ​​mainly the OpenFOAM data storage format. OpenFOAM implements an lduMatrix class to represent the LDU matrix. The CSR format is more common in sparse matrices. It only saves the non-zero elements in the sparse matrix and the column index values ​​corresponding to the non-zero elements and the position offset of the first non-zero element in each row among all non-zero elements. This storage method saves a lot of space compared to the traditional dense storage method.

[0074] like Figure 3 As shown, add a library reference in the OpenFOAM example file controlDict file, and use the DCU solver in the example file fvSolution file to solve various physical quantities.

[0075] Run the OpenFOAM example and call the DCU heterogeneous accelerator card. After importing the grid, OpenFOAM will store the corresponding LDU format data according to the grid, where the diagonal elements and the upper and lower triangle elements are stored in three vectors (lduMatrix.diag(), lduMatrix.upper(), lduMatrix.lower()), and the index values ​​of the upper and lower triangle elements share two index vectors, where upperAddr stores the row index of the upper triangle elements and expresses the column index of the corresponding elements of the lower triangle. lowerAddr can express both the column index of the upper triangle elements and the row index of the lower triangle elements. The format conversion code can be used to convert LDU format data into data stored in CSR format; the CSR format mainly uses three arrays to represent the contents of the matrix, where Value is the value of the non-zero elements in the matrix, Col_Index stores the column index of the non-zero element, and Row_Offsets stores the index of the first non-zero element in each row in Value. According to this value, the row index of each non-zero element can be calculated to correctly locate the non-zero element, such as Figure 4 shown.

[0076] Step 3: The CPU copies the incoming data and transfers the copied data on the CPU side to the DCU memory. The DCU kernel iteration is called to start calculating the matrix to determine whether the convergence criteria are met. If not, the kernel is returned to continue iterating. If convergence is achieved, the CSR format data is output and the DCU memory is released.

[0077] After the format conversion is completed, the solver in the DCU heterogeneous accelerator card is called to solve. The solver is mainly modified on the DCU based on the original PCG, PBiCG and other algorithms in OpenFOAM, and the converted CSR format is used for calculation to save calculation time. After the calculation is completed, the CSR format data is output and the DCU memory is released.

[0078] The kernel iteration is a solver that runs on the DCU. The algorithm is modified based on the original iterative algorithms such as PCG and PBiCG in OpenFOAM so that it can run on the DCU.

[0079] Step 4: Convert the output CSR format data back into LDU format data recognized by OpenFOAM, and transfer the calculation results back to OpenFOAM to view the results through the post-processing tool.

[0080] The processing tools are: Paraview, Tecplot and other third-party tools.

[0081] Convert the CSR format data back into the original LDU format data in OpenFOAM. Since the LDU matrix format in OpenFOAM is a format unique to OpenFOAM, it needs to be converted again during data output.

[0082] Example 2

[0083] like Figure 5 As shown, an OpenFOAM acceleration device based on linear matrix solution includes:

[0084] The matrix generation and matrix conversion system setting module is used to read the mesh information in OpenFOAM and generate the matrix in LDU format; set up the LDU→CSR matrix conversion system and compile the relevant code in DCU;

[0085] The example grid information reading module and matrix-vector conversion module are used to run the OpenFOAM example through DCU, read the example grid information, convert the original LDU format matrix into the CSR format matrix, and complete the matrix-vector conversion;

[0086] The matrix iterative calculation and CSR format data output module is used to copy the incoming data through the CPU, transfer the copied data on the CPU side to the DCU memory, call the DCU kernel to iteratively calculate the matrix, and output the CSR format data after convergence;

[0087] The matrix format reconversion and viewing module is used to convert the output CSR format data into LDU format data recognized by OpenFOAM, and transmit the calculation results back to OpenFOAM.

[0088] Example 3

[0089] The present invention provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements an OpenFOAM acceleration method based on linear matrix solving as described in Example 1 when executing the computer program.

[0090] Example 4

[0091] The present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and is characterized in that when the computer program is executed by a processor, an OpenFOAM acceleration method based on linear matrix solution described in Example 1 is implemented.

[0092] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0093] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0094] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0095] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0096] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the relevant field should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents. Any modification or equivalent replacement that does not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.

Claims

1. An OpenFOAM acceleration method based on linear matrix solving, characterized in that: include: Step 1: Read the mesh information into OpenFOAM and generate a matrix in LDU format; Set up the LDU→CSR matrix conversion system and compile related codes in DCU; Step 2: Run the OpenFOAM example through DCU, read the example grid information, convert the original LDU format matrix into a CSR format matrix, and complete the matrix-to-vector conversion; Step 3: The CPU copies the incoming data and transfers the copied data on the CPU side to the DCU memory, calling the DCU kernel to iteratively calculate the matrix, and outputs the CSR format data after convergence; Step 4: Convert the output CSR format data back into LDU format data recognized by OpenFOAM, and pass the calculation results back to OpenFOAM.

2. The OpenFOAM acceleration method based on linear matrix solving according to claim 1, characterized in that: The relevant code compiled in DCU is: Write pseudocode for LDU→CSR format conversion, convert this pseudocode into HIP code, and write the solver using HIP code and integrate it into DCU.

3. The OpenFOAM acceleration method based on linear matrix solving according to claim 1, characterized in that: The matrix in the LDU format is the OpenFOAM data storage format. A library reference is added to the OpenFOAM example file controlDict file, and the DCU solver is used in the example file fvSolution file to solve various physical quantities.

4. The OpenFOAM acceleration method based on linear matrix solving according to claim 1, characterized in that: The step 2 specifically includes: Run the OpenFOAM example and call the DCU accelerator card. After importing the grid, OpenFOAM stores the corresponding LDU format data according to the grid; the diagonal elements and the upper and lower triangle elements are stored in three vectors lduMatrix.diag(), lduMatrix.upper(), and lduMatrix.lower() respectively, and the index values ​​of the upper and lower triangle elements share two index vectors; upperAddr stores the row index of the upper triangle elements and expresses the column index of the corresponding elements of the lower triangle. lowerAddr can express both the column index of the upper triangle elements and the row index of the lower triangle elements; the format conversion code is used to convert the LDU format data into data stored in the CSR format; the CSR format mainly uses three arrays to represent the content of the matrix, where Value is the value of the non-zero element in the matrix, Col_Index stores the column index of the non-zero element, and Row_Offsets stores the index of the first non-zero element in each row in Value, calculates the row index of each non-zero element, and locates the non-zero element.

5. The OpenFOAM acceleration method based on linear matrix solution according to claim 4, characterized in that: The matrix-to-vector conversion is specifically as follows: first, traverse the order of the LDU matrix and the number of lower and upper triangular elements, calculate the number of non-zero elements in each row, insert the lower triangular matrix elements, diagonal matrix elements, and upper triangular matrix elements in order, calculate the matrix value and its corresponding index value for each matrix element, and return the newly generated CSR format matrix.

6. The OpenFOAM acceleration method based on linear matrix solving according to claim 1, characterized in that: The step 3 specifically includes: After the format conversion is completed, the solver in the DCU accelerator card is called to solve. The solver is modified on the DCU according to the PCG or PBiCG algorithm in OpenFOAM, and the converted CSR format is used for calculation. After the calculation is completed, the CSR format data is output and the DCU memory is released.

7. The OpenFOAM acceleration method based on linear matrix solving according to claim 1, characterized in that: In step 4, the calculation results are transmitted back to OpenFOAM and then viewed through a post-processing tool, such as Paraview or Tecplot.

8. An OpenFOAM acceleration device based on linear matrix solving, characterized in that: include: Matrix generation and matrix conversion system setting module, used to read mesh information into OpenFOAM and generate LDU format matrix; Set up the LDU→CSR matrix conversion system and compile related codes in DCU; The example grid information reading module and matrix-vector conversion module are used to run the OpenFOAM example through DCU, read the example grid information, convert the original LDU format matrix into the CSR format matrix, and complete the matrix-vector conversion; The matrix iterative calculation and CSR format data output module is used to copy the incoming data through the CPU, transfer the copied data on the CPU side to the DCU memory, call the DCU kernel to iteratively calculate the matrix, and output the CSR format data after convergence; The matrix format reconversion and viewing module is used to convert the output CSR format data into LDU format data recognized by OpenFOAM, and transmit the calculation results back to OpenFOAM.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, an OpenFOAM acceleration method based on linear matrix solution as described in any one of claims 1 to 7 is implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, an OpenFOAM acceleration method based on linear matrix solution as described in any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Method for accelerating OpenFOAM solver PCG by using GPU

    CN115270054A