Fluid simulation method and system based on Taichi and Pytorch

By using Taichi and Pytorch methods in fluid simulation, a complete framework from data set generation, model construction and training to fluid animation generation was built, which solved the problem of low fluid simulation accuracy in the existing technology and significantly improved the simulation accuracy.

CN119903747AActive Publication Date: 2025-04-29XIAMEN UNIV
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202510015142.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-06
Publication Date
2025-04-29
Estimated Expiration
2045-01-06

AI Technical Summary

Technical Problem

In the prior art, the fluid simulation accuracy is low, and there is a lack of a perfect framework that includes data set generation, model construction and training, and fluid animation generation.

Method used

Using the fluid simulation method based on Taichi and Pytorch, a fluid data set is generated through the Taichi framework construction fluid simulation algorithm, and a fluid simulation model composed of multi-layer perception mechanism is built using Pytorch to train the data set, generate a fluid particle position sequence and render it into fluid animation.

Benefits of technology

It realizes a complete framework from fluid data set generation, model construction and training, and fluid animation generation, and improves the accuracy of fluid simulation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119903747A_ABST
    Figure CN119903747A_ABST
Patent Text Reader

Abstract

The invention provides a fluid simulation method and system based on Taichi and Pytorch in the technical field of fluid simulation, and the method comprises the following steps: S1, generating a fluid data set comprising a plurality of fluid motion tracks based on a fluid simulation algorithm constructed by a Taichi framework; s2, building a fluid simulation model composed of a plurality of layers of perception mechanisms through Pytorch; s3, converting each fluid motion track in the fluid data set into a corresponding Torch tensor to obtain a tensor data set, and training a fluid simulation model through the tensor data set; s4, acquiring an initial state of a fluid, and inputting the initial state of the fluid into the trained fluid simulation model for forward simulation to obtain a fluid particle position sequence; and S5, converting the fluid particle position sequence into a fluid model sequence, and rendering the fluid model sequence into a fluid animation to complete fluid simulation. The method has the advantage that the fluid simulation precision is greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of fluid simulation technology, and in particular to a fluid simulation method and system based on Taichi and Pytorch. Background Art

[0002] Fluid simulation is to simulate the actual flow of fluids. Fluid simulation plays an important role in product design optimization, process control optimization, environmental protection and disaster response, aerospace, automotive engineering, hydropower, meteorology, etc. Although the fluid simulation method based on deep learning is developing rapidly, there is no complete framework that includes data set generation, model building and training, and fluid animation generation, which makes the accuracy of fluid simulation unsatisfactory.

[0003] Therefore, how to provide a fluid simulation method and system based on Taichi and Pytorch to improve the accuracy of fluid simulation has become a technical problem that needs to be solved urgently. Summary of the invention

[0004] The technical problem to be solved by the present invention is to provide a fluid simulation method and system based on Taichi and Pytorch to improve the accuracy of fluid simulation.

[0005] In a first aspect, the present invention provides a fluid simulation method based on Taichi and Pytorch, comprising the following steps:

[0006] Step S1, generating a fluid data set including a plurality of fluid motion trajectories based on a fluid simulation algorithm constructed based on the Taichi framework;

[0007] Step S2: Using Pytorch, build a fluid simulation model consisting of a multi-layer sensor;

[0008] Step S3, converting each fluid motion trajectory in the fluid data set into a corresponding Torch tensor to obtain a tensor data set, and training the fluid simulation model through the tensor data set;

[0009] Step S4, obtaining the initial state of the fluid, inputting the initial state of the fluid into the trained fluid simulation model for forward simulation, and obtaining a fluid particle position sequence;

[0010] Step S5: converting the fluid particle position sequence into a fluid model sequence, and rendering the fluid model sequence into a fluid animation to complete the fluid simulation.

[0011] Further, in step S1, the fluid simulation algorithm is a position-based fluid simulation algorithm;

[0012] The fluid motion trajectory includes at least the fluid position, the fluid position correction value, the fluid particle radius and the number of fluid particles; the fluid position correction value is calculated based on the law of conservation of density;

[0013] In step S2, the fluid simulation model is used to constrain and update the fluid position.

[0014] Furthermore, the step S3 is specifically as follows:

[0015] Reading each fluid motion trajectory in the fluid data set as Numpy data through Numpy, and then converting each Numpy data into a corresponding Torch tensor to obtain a tensor data set, and dividing the tensor data set into a training set, a validation set, and a test set based on a preset ratio;

[0016] The fluid simulation model is trained by the training set until the preset convergence condition is met, and then the trained fluid simulation model is verified by the verification set, and the verified fluid simulation model is tested by the test set, and the model parameters of the fluid simulation model after the test are saved.

[0017] Furthermore, the step S4 is specifically as follows:

[0018] The initial state of the fluid including at least the fluid position, the radius of the fluid particles and the number of the fluid particles is obtained, and the initial state of the fluid is converted into a Torch tensor and input into the trained fluid simulation model for forward simulation to obtain a fluid particle position sequence.

[0019] Furthermore, the step S5 is specifically as follows:

[0020] The Stop Motion Obj plug-in is used through the Blender engine to convert the fluid particle position sequence into a fluid model sequence carrying vertex information, vertex normal information and face index, and the fluid model sequence is rendered as a fluid animation to complete the fluid simulation.

[0021] In a second aspect, the present invention provides a fluid simulation system based on Taichi and Pytorch, comprising the following modules:

[0022] The fluid data set construction module is used to generate a fluid data set including several fluid motion trajectories based on the fluid simulation algorithm built on the Taichi framework;

[0023] The fluid simulation model building module is used to build a fluid simulation model composed of a multi-layer perceptron through Pytorch;

[0024] A fluid simulation model training module, used for converting each fluid motion trajectory in the fluid data set into a corresponding Torch tensor to obtain a tensor data set, and training the fluid simulation model through the tensor data set;

[0025] A forward simulation module is used to obtain the initial state of the fluid, input the initial state of the fluid into the trained fluid simulation model for forward simulation, and obtain a fluid particle position sequence;

[0026] The fluid animation generation module is used to convert the fluid particle position sequence into a fluid model sequence, and render the fluid model sequence into a fluid animation to complete the fluid simulation.

[0027] Further, in the fluid data set construction module, the fluid simulation algorithm is a position-based fluid simulation algorithm;

[0028] The fluid motion trajectory includes at least the fluid position, the fluid position correction value, the fluid particle radius and the number of fluid particles; the fluid position correction value is calculated based on the law of conservation of density;

[0029] In the fluid simulation model building module, the fluid simulation model is used to constrain and update the fluid position.

[0030] Furthermore, the fluid simulation model training module is specifically used for:

[0031] Reading each fluid motion trajectory in the fluid data set as Numpy data through Numpy, and then converting each Numpy data into a corresponding Torch tensor to obtain a tensor data set, and dividing the tensor data set into a training set, a validation set, and a test set based on a preset ratio;

[0032] The fluid simulation model is trained by the training set until the preset convergence condition is met, and then the trained fluid simulation model is verified by the verification set, and the verified fluid simulation model is tested by the test set, and the model parameters of the fluid simulation model after the test are saved.

[0033] Furthermore, the forward simulation module is specifically used for:

[0034] The initial state of the fluid including at least the fluid position, the radius of the fluid particles and the number of the fluid particles is obtained, and the initial state of the fluid is converted into a Torch tensor and input into the trained fluid simulation model for forward simulation to obtain a fluid particle position sequence.

[0035] Furthermore, the fluid animation generation module is specifically used for:

[0036] The Stop Motion Obj plug-in is used through the Blender engine to convert the fluid particle position sequence into a fluid model sequence carrying vertex information, vertex normal information and face index, and the fluid model sequence is rendered as a fluid animation to complete the fluid simulation.

[0037] The advantages of the present invention are:

[0038] The fluid simulation algorithm constructed by the Taichi framework generates a fluid data set including several fluid motion trajectories; then, a fluid simulation model composed of a multi-layer perceptron is built through Pytorch, and each fluid motion trajectory in the fluid data set is converted into a corresponding Torch tensor to obtain a tensor data set, and the fluid simulation model is trained through the tensor data set; then the initial state of the fluid is obtained, and the initial state of the fluid is input into the trained fluid simulation model for forward simulation to obtain a fluid particle position sequence; finally, the fluid particle position sequence is converted into a fluid model sequence, and the fluid model sequence is rendered into a fluid animation to complete the fluid simulation; that is, a complete framework is constructed from fluid data set generation, fluid simulation model construction and training, and fluid animation generation, and because the Taichi framework has high performance and flexibility, it is compatible with Python and can be well combined with deep learning. The fluid simulation model is used to constrain and update the fluid position to ensure the rationality of fluid particle motion. The fluid model sequence carries vertex information, vertex normal information, and face index to ensure rendering accuracy, which ultimately greatly improves the accuracy of fluid simulation. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] The present invention will be further described below in conjunction with embodiments with reference to the accompanying drawings.

[0040] Figure 1 It is a flow chart of a fluid simulation method based on Taichi and Pytorch of the present invention.

[0041] Figure 2 It is a structural schematic diagram of a fluid simulation system based on Taichi and Pytorch in the present invention.

[0042] Figure 3 It is a schematic diagram of the fluid animation of the present invention. DETAILED DESCRIPTION

[0043] The technical solution in the embodiments of the present application has the following overall idea: constructing a complete framework from fluid data set generation, fluid simulation model construction and training, and fluid animation generation. Since the Taichi framework has high performance and flexibility, it is compatible with Python and can be well combined with deep learning. The fluid simulation model is used to constrain and update the fluid position to ensure the rationality of the fluid particle movement. The fluid model sequence carries vertex information, vertex normal information and face index to ensure the rendering accuracy, so as to improve the fluid simulation accuracy.

[0044] Please refer to Figures 1 to 3 As shown, a preferred embodiment of the fluid simulation method based on Taichi and Pytorch of the present invention comprises the following steps:

[0045] Step S1, generating a fluid data set including a plurality of fluid motion trajectories based on a fluid simulation algorithm constructed based on the Taichi framework;

[0046] The Taichi framework is suitable for fields such as physical simulation and machine learning. It has high performance and flexibility. It is compatible with Python and can be well combined with deep learning. The fluid motion trajectory is in txt format;

[0047] Step S2: Using Pytorch, build a fluid simulation model consisting of a multi-layer perceptron (MLP);

[0048] Step S3, converting each fluid motion trajectory in the fluid data set into a corresponding Torch tensor to obtain a tensor data set, and training the fluid simulation model through the tensor data set;

[0049] Step S4, obtaining the initial state of the fluid, inputting the initial state of the fluid into the trained fluid simulation model for forward simulation, and obtaining a fluid particle position sequence;

[0050] Step S5: converting the fluid particle position sequence into a fluid model sequence, and rendering the fluid model sequence into a fluid animation to complete the fluid simulation.

[0051] In the step S1, the fluid simulation algorithm is a position-based fluid simulation algorithm (Position Based Fluid Simulation, PBF);

[0052] The fluid motion trajectory includes at least the fluid position, the fluid position correction value, the fluid particle radius and the number of fluid particles; the fluid position correction value is calculated based on the law of conservation of density;

[0053] In step S2, the fluid simulation model is used to constrain and update the fluid position.

[0054] The step S3 is specifically as follows:

[0055] Reading each fluid motion trajectory in the fluid data set as Numpy data through Numpy, and then converting each Numpy data into a corresponding Torch tensor to obtain a tensor data set, and dividing the tensor data set into a training set, a validation set, and a test set based on a preset ratio;

[0056] Since the fluid simulation model (neural network) cannot directly recognize text files (fluid data sets), it is necessary to use Numpy to read the text files, convert them into Numpy data (digital fluid position sequence), and use Torch to convert the Numpy data into Torch tensors for recognition by the fluid simulation model. Numpy data is a three-dimensional variable, each of which is the position information of all fluid particles in each frame, for example ((0.2, 0.5, 0.3), (0.4, 0.7, 0.8)) means that the position of the first fluid particle is x = 0.2, y = 0.5, z = 0.3, and the position of the second fluid particle is x = 0.4, y = 0.7, z = 0.8.

[0057] The fluid simulation model is trained by the training set until the preset convergence condition is met, and then the trained fluid simulation model is verified by the verification set, and the verified fluid simulation model is tested by the test set, and the model parameters of the fluid simulation model after the test are saved as a pth file.

[0058] The step S4 is specifically as follows:

[0059] The initial state of the fluid including at least the fluid position, the radius of the fluid particles and the number of the fluid particles is obtained, and the initial state of the fluid is converted into a Torch tensor and input into the trained fluid simulation model for forward simulation to obtain a fluid particle position sequence.

[0060] The step S5 is specifically as follows:

[0061] The Stop Motion Obj plug-in is used through the Blender engine to convert the fluid particle position sequence into a fluid model sequence carrying vertex information, vertex normal information and face index, and the fluid model sequence is rendered as a fluid animation (video file) to complete the fluid simulation.

[0062] Blender is widely used in animation, modeling, rendering and other fields. Stop Motion OBJ is a plug-in designed for Blender that allows a series of OBJ format mesh files to be imported as animation frames.

[0063] A preferred embodiment of a fluid simulation system based on Taichi and Pytorch of the present invention includes the following modules:

[0064] The fluid data set construction module is used to generate a fluid data set including several fluid motion trajectories based on the fluid simulation algorithm built on the Taichi framework;

[0065] The Taichi framework is suitable for fields such as physical simulation and machine learning. It has high performance and flexibility. It is compatible with Python and can be well combined with deep learning. The fluid motion trajectory is in txt format;

[0066] The fluid simulation model building module is used to build a fluid simulation model composed of a multi-layer perceptron (MLP) through Pytorch;

[0067] A fluid simulation model training module, used for converting each fluid motion trajectory in the fluid data set into a corresponding Torch tensor to obtain a tensor data set, and training the fluid simulation model through the tensor data set;

[0068] A forward simulation module is used to obtain the initial state of the fluid, input the initial state of the fluid into the trained fluid simulation model for forward simulation, and obtain a fluid particle position sequence;

[0069] The fluid animation generation module is used to convert the fluid particle position sequence into a fluid model sequence, and render the fluid model sequence into a fluid animation to complete the fluid simulation.

[0070] In the fluid data set construction module, the fluid simulation algorithm is a position-based fluid simulation algorithm (Position Based Fluid Simulation, PBF);

[0071] The fluid motion trajectory includes at least the fluid position, the fluid position correction value, the fluid particle radius and the number of fluid particles; the fluid position correction value is calculated based on the law of conservation of density;

[0072] In the fluid simulation model building module, the fluid simulation model is used to constrain and update the fluid position.

[0073] The fluid simulation model training module is specifically used for:

[0074] Reading each fluid motion trajectory in the fluid data set as Numpy data through Numpy, and then converting each Numpy data into a corresponding Torch tensor to obtain a tensor data set, and dividing the tensor data set into a training set, a validation set, and a test set based on a preset ratio;

[0075] Since the fluid simulation model (neural network) cannot directly recognize text files (fluid data sets), it is necessary to use Numpy to read the text files, convert them into Numpy data (digital fluid position sequence), and use Torch to convert the Numpy data into Torch tensors for recognition by the fluid simulation model. Numpy data is a three-dimensional variable, each of which is the position information of all fluid particles in each frame, for example ((0.2, 0.5, 0.3), (0.4, 0.7, 0.8)) means that the position of the first fluid particle is x = 0.2, y = 0.5, z = 0.3, and the position of the second fluid particle is x = 0.4, y = 0.7, z = 0.8.

[0076] The fluid simulation model is trained by the training set until the preset convergence condition is met, and then the trained fluid simulation model is verified by the verification set, and the verified fluid simulation model is tested by the test set, and the model parameters of the fluid simulation model after the test are saved as a pth file.

[0077] The forward simulation module is specifically used for:

[0078] The initial state of the fluid including at least the fluid position, the radius of the fluid particles and the number of the fluid particles is obtained, and the initial state of the fluid is converted into a Torch tensor and input into the trained fluid simulation model for forward simulation to obtain a fluid particle position sequence.

[0079] The fluid animation generation module is specifically used for:

[0080] The Stop Motion Obj plug-in is used through the Blender engine to convert the fluid particle position sequence into a fluid model sequence carrying vertex information, vertex normal information and face index, and the fluid model sequence is rendered as a fluid animation (video file) to complete the fluid simulation.

[0081] Blender is widely used in animation, modeling, rendering and other fields. Stop Motion OBJ is a plug-in designed for Blender that allows a series of OBJ format mesh files to be imported as animation frames.

[0082] In summary, the advantages of the present invention are:

[0083] The fluid simulation algorithm constructed by the Taichi framework generates a fluid data set including several fluid motion trajectories; then, a fluid simulation model composed of a multi-layer perceptron is built through Pytorch, and each fluid motion trajectory in the fluid data set is converted into a corresponding Torch tensor to obtain a tensor data set, and the fluid simulation model is trained through the tensor data set; then the initial state of the fluid is obtained, and the initial state of the fluid is input into the trained fluid simulation model for forward simulation to obtain a fluid particle position sequence; finally, the fluid particle position sequence is converted into a fluid model sequence, and the fluid model sequence is rendered into a fluid animation to complete the fluid simulation; that is, a complete framework is constructed from fluid data set generation, fluid simulation model construction and training, and fluid animation generation, and because the Taichi framework has high performance and flexibility, it is compatible with Python and can be well combined with deep learning. The fluid simulation model is used to constrain and update the fluid position to ensure the rationality of fluid particle motion. The fluid model sequence carries vertex information, vertex normal information, and face index to ensure rendering accuracy, which ultimately greatly improves the accuracy of fluid simulation.

[0084] Although the specific implementation modes of the present invention are described above, those skilled in the art should understand that the specific implementation modes described are only illustrative and are not intended to limit the scope of the present invention. Equivalent modifications and changes made by those skilled in the art in accordance with the spirit of the present invention should be included in the scope of protection of the claims of the present invention.

Claims

1. A fluid simulation method based on Taichi and Pytorch, characterized in that: The steps include: Step S1, generating a fluid data set including a plurality of fluid motion trajectories based on a fluid simulation algorithm constructed based on the Taichi framework; Step S2: Using Pytorch, build a fluid simulation model consisting of a multi-layer sensor; Step S3, converting each fluid motion trajectory in the fluid data set into a corresponding Torch tensor to obtain a tensor data set, and training the fluid simulation model through the tensor data set; Step S4, obtaining the initial state of the fluid, inputting the initial state of the fluid into the trained fluid simulation model for forward simulation, and obtaining a fluid particle position sequence; Step S5: converting the fluid particle position sequence into a fluid model sequence, and rendering the fluid model sequence into a fluid animation to complete the fluid simulation.

2. A fluid simulation method based on Taichi and Pytorch as claimed in claim 1, characterized in that: In the step S1, the fluid simulation algorithm is a position-based fluid simulation algorithm; The fluid motion trajectory includes at least the fluid position, the fluid position correction value, the fluid particle radius and the number of fluid particles; the fluid position correction value is calculated based on the law of conservation of density; In step S2, the fluid simulation model is used to constrain and update the fluid position.

3. The fluid simulation method based on Taichi and Pytorch as claimed in claim 1, characterized in that: The step S3 is specifically as follows: Reading each fluid motion trajectory in the fluid data set as Numpy data through Numpy, and then converting each Numpy data into a corresponding Torch tensor to obtain a tensor data set, and dividing the tensor data set into a training set, a validation set, and a test set based on a preset ratio; The fluid simulation model is trained by the training set until the preset convergence condition is met, and then the trained fluid simulation model is verified by the verification set, and the verified fluid simulation model is tested by the test set, and the model parameters of the fluid simulation model after the test are saved.

4. The fluid simulation method based on Taichi and Pytorch as claimed in claim 1, characterized in that: The step S4 is specifically as follows: The initial state of the fluid including at least the fluid position, the radius of the fluid particles and the number of the fluid particles is obtained, and the initial state of the fluid is converted into a Torch tensor and input into the trained fluid simulation model for forward simulation to obtain a fluid particle position sequence.

5. The fluid simulation method based on Taichi and Pytorch as claimed in claim 1, characterized in that: The step S5 is specifically as follows: The Stop Motion Obj plug-in is used through the Blender engine to convert the fluid particle position sequence into a fluid model sequence carrying vertex information, vertex normal information and face index, and the fluid model sequence is rendered as a fluid animation to complete the fluid simulation.

6. A fluid simulation system based on Taichi and Pytorch, characterized by: Includes the following modules: The fluid data set construction module is used to generate a fluid data set including several fluid motion trajectories based on the fluid simulation algorithm built on the Taichi framework; The fluid simulation model building module is used to build a fluid simulation model composed of a multi-layer perceptron through Pytorch; A fluid simulation model training module, used for converting each fluid motion trajectory in the fluid data set into a corresponding Torch tensor to obtain a tensor data set, and training the fluid simulation model through the tensor data set; A forward simulation module is used to obtain the initial state of the fluid, input the initial state of the fluid into the trained fluid simulation model for forward simulation, and obtain a fluid particle position sequence; The fluid animation generation module is used to convert the fluid particle position sequence into a fluid model sequence, and render the fluid model sequence into a fluid animation to complete the fluid simulation.

7. A fluid simulation system based on Taichi and Pytorch as claimed in claim 6, characterized in that: In the fluid data set construction module, the fluid simulation algorithm is a position-based fluid simulation algorithm; The fluid motion trajectory includes at least the fluid position, the fluid position correction value, the fluid particle radius and the number of fluid particles; the fluid position correction value is calculated based on the law of conservation of density; In the fluid simulation model building module, the fluid simulation model is used to constrain and update the fluid position.

8. A fluid simulation system based on Taichi and Pytorch as claimed in claim 6, characterized in that: The fluid simulation model training module is specifically used for: Reading each fluid motion trajectory in the fluid data set as Numpy data through Numpy, and then converting each Numpy data into a corresponding Torch tensor to obtain a tensor data set, and dividing the tensor data set into a training set, a validation set, and a test set based on a preset ratio; The fluid simulation model is trained by the training set until the preset convergence condition is met, and then the trained fluid simulation model is verified by the verification set, and the verified fluid simulation model is tested by the test set, and the model parameters of the fluid simulation model after the test are saved.

9. A fluid simulation system based on Taichi and Pytorch as claimed in claim 6, characterized in that: The forward simulation module is specifically used for: The initial state of the fluid including at least the fluid position, the radius of the fluid particles and the number of the fluid particles is obtained, and the initial state of the fluid is converted into a Torch tensor and input into the trained fluid simulation model for forward simulation to obtain a fluid particle position sequence.

10. The fluid simulation system based on Taichi and Pytorch as claimed in claim 6, characterized in that: The fluid animation generation module is specifically used for: The Stop Motion Obj plug-in is used through the Blender engine to convert the fluid particle position sequence into a fluid model sequence carrying vertex information, vertex normal information and face index, and the fluid model sequence is rendered as a fluid animation to complete the fluid simulation.

Citation Information

Patent Citations

  • Data-driven coal supercritical water hydrogen production reactor multiphase flow prediction method

    CN115186575A

  • Circuit board device thermal analysis method and device based on target detection

    CN118070748A

  • Liquid rocket engine system simulation method based on intelligent reduced-order model

    CN118378550A

  • Optimization method and device for the chamber partition structure of a vertically slotted fish ladder

    DE102024103246A1

  • Method for simulating fluid and apparatus executing the method

    KR1020170074031A