A flood evolution analysis method based on instant compiling technology
By utilizing just-in-time compilation technology and the Taichi framework in a Python environment, the code for solving shallow water equations is translated into machine code, achieving efficient parallel acceleration of flood evolution analysis. This solves the problem of low efficiency of interpreted languages in flood analysis and improves the efficiency and readability of flood analysis.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NANJING INST OF GEOGRAPHY & LIMNOLOGY
- Filing Date
- 2026-01-21
- Publication Date
- 2026-04-17
AI Technical Summary
In existing technologies, interpreted languages are difficult to achieve efficient parallel acceleration in flood evolution analysis, while compiled languages are difficult to learn, resulting in low efficiency in flood analysis.
We employ just-in-time (JIT) compilation technology to write shallow water equation solution code in Python environment, and then use the Taichi framework to translate it into machine code. This allows us to accelerate computation using CPU or GPU, achieving parallel accelerated solution based on the Harten-Lax-van Leer contact (HLLC) algorithm.
It achieves efficient parallel acceleration of Python code on different hardware platforms, improves the efficiency of flood evolution analysis, and makes it easier for professionals to quickly master flood analysis methods.
Smart Images

Figure CN121543518B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computational fluid dynamics technology, specifically relating to a flood evolution analysis method based on just-in-time compilation technology. Background Technology
[0002] Shallow water equations are mathematical models describing shallow water flow and are an important mathematical model in hydraulics. They characterize changes in water depth, velocity, and discharge on a horizontal scale that is much larger than the vertical scale of water movement, and are a crucial method for simulating flood evolution. With the development of computer technology and computational fluid dynamics, the discrete solution of shallow water equations has evolved from CPU serial computation to CPU parallel computation. With the advent of GPU acceleration technology, the solution of shallow water equations is currently moving towards GPU acceleration, enabling faster solutions to shallow water equations with massive grid numbers. Currently, the discrete solution of shallow water equations is still mainly based on compiled languages such as Fortran and C++. In terms of achieving parallel acceleration, these languages are more difficult to learn than interpreted languages, hindering the rapid adoption of flood evolution analysis by relevant professionals.
[0003] While interpreted languages are easier to read and understand, their runtime code parsing makes them slower than compiled languages for complex calculations. Just-In-Time (JIT) compilation is a technique to improve the efficiency of interpreted programs. It converts bytecode into machine code at runtime, increasing execution speed and allowing interpreted languages like Python to combine the readability and ease of learning of interpreted languages with the high performance of compiled languages. Furthermore, code written using JIT compilation can achieve parallel acceleration based on different hardware such as CPUs or GPUs without modifying the computational parts of the code. Therefore, JIT compilation has significant potential applications in flood evolution analysis. Summary of the Invention
[0004] Purpose of the invention: To address the technical problems and deficiencies in existing technologies, this invention provides a flood evolution analysis method based on just-in-time compilation technology, enabling efficient flood evolution analysis that supports different hardware platforms.
[0005] Technical Solution: To achieve the above-mentioned objectives, the present invention adopts the following technical solution: a flood evolution analysis method based on just-in-time compilation technology, comprising the following steps:
[0006] S1, Initialize the hardware acceleration environment;
[0007] S2 sets the total simulation time and single-step calculation step size for the flood case.
[0008] S3, Load the flood simulation grid topology;
[0009] S4, load the initial water level and initial flow velocity of the flood case grid;
[0010] S5, loading the roughness field of the flood simulation mesh;
[0011] S6, Load the boundary conditions for the flood simulation;
[0012] S7. An acceleration program based on the Harten-Lax-van Leer contact (HLLC) algorithm for updating shallow water equation state variables was written in the Taichi framework and Python environment. The acceleration program was translated into binary instructions using Taichi just-in-time compilation technology, and then the update of shallow water equation state variables based on the HLLC algorithm was accelerated by CPU or GPU to quickly solve the shallow water equation and complete the simulation of flood evolution.
[0013] Furthermore, the shallow water equation has the following mathematical expression:
[0014] ,
[0015] ,
[0016] ,
[0017] In the formula, For water depth; For time; for The horizontal velocity component averaged along the vertical line; for The horizontal velocity component averaged along the vertical line; and respectively along and The underwater slope in the direction of the direction; and respectively along and Friction gradient in the direction; This is the acceleration due to gravity.
[0018] Furthermore, in step S7, the HLLC-based algorithm is used to update the state variables of the shallow water equation using the following formula:
[0019] ,
[0020] In the formula, State variables correspond to the flow velocity in the x or y direction after depth integration in the shallow water equations, or the water depth; n represents the grid number; superscript and These represent the current and next moments in time, respectively; This indicates the step size for single-step calculation; The volume of a quadrilateral grid cell; Represents the transformation matrix; Indicates the grid number. Normal flux of each edge; For the first The area of each grid cell face; This represents the average value of the source terms for the grid cells.
[0021] Furthermore, the hardware acceleration environment described in step S1 includes a hardware acceleration platform and data precision. The hardware acceleration platform can be selected from CPU, GPU or CUDA, and the integer or floating-point variables in the data precision include 32-bit or 64-bit.
[0022] Furthermore, the total simulation time mentioned in step S2 is the simulation time corresponding to the flood simulation; the single-step calculation step size is the time corresponding to the state variable update during each iteration of the flood simulation.
[0023] Furthermore, in step S3, the mesh topology structure adopts a quadrilateral mesh to adapt to the real physical region, and records the coordinate information of the four mesh nodes of the quadrilateral mesh and the information of adjacent edges between meshes. The information of adjacent edges between meshes includes the mesh number of the edge adjacent to the target mesh.
[0024] Furthermore, the initial flow velocity of the mesh mentioned in step S4 includes the initial flow velocity in the x and y directions.
[0025] Furthermore, the grid roughness field mentioned in step S5 includes the roughness value in each grid cell that reflects the magnitude of the resistance encountered by the water flow process at each grid location.
[0026] Furthermore, the boundary conditions described in step S6 include changes in water level or flow rate at the grid edges of the grid cells.
[0027] Beneficial effects: Compared with existing technologies, this invention uses the highly interpretable Python language to write the solution code for shallow water equations. Through Taichi just-in-time compilation technology, the discrete code of shallow water equations based on Python is compiled into machine code, making its running efficiency comparable to that of compiled languages. The method can achieve parallel accelerated computing based on different hardware platforms such as CPU, GPU, and CUDA without modifying the code. It has the advantages of high readability and high running efficiency, thus making it easy for professionals in the field of hydraulics to quickly master flood analysis methods and achieve simple and efficient simulation of flood evolution. Attached Figure Description
[0028] Figure 1This is a flowchart illustrating the flood evolution analysis method based on just-in-time compilation technology described in this invention.
[0029] Figure 2 This is a schematic diagram of the digital elevation of Chongming Island according to an embodiment of the present invention.
[0030] Figure 3 This is a schematic diagram of the mesh topology structure described in an embodiment of the present invention.
[0031] Figure 4 yes Figure 3 Enlarged view of the grid topology in the area highlighted in red.
[0032] Figure 5 A schematic diagram of the boundary conditions described in an embodiment of the present invention.
[0033] Figure 6 This invention provides an hourly comparison of water depth from 0 to 5 hours after a simulated dam breach on Chongming Island. Detailed Implementation
[0034] The present invention will be further illustrated below with reference to the accompanying drawings and specific embodiments. It should be understood that these embodiments are for illustrative purposes only and are not intended to limit the scope of the invention. After reading this invention, any modifications of the invention in various equivalent forms by those skilled in the art will fall within the scope defined by the appended claims.
[0035] The core of this invention lies in: developing an accelerated program based on the Harten-Lax-van Leer contact (HLLC) algorithm for updating state variables in shallow water equations using the Taichi framework and Python environment. The Python source code is translated into binary instructions using Taichi just-in-time compilation technology, and the update of state variables in shallow water equations based on the HLLC algorithm is accelerated by CPU or GPU, enabling rapid solution of the shallow water equations and simulation of flood evolution. The technical solution of this invention is specifically illustrated through the following embodiments:
[0036] This invention provides a flood evolution analysis method and system based on just-in-time compilation technology, such as... Figure 1 As shown, it includes the following steps:
[0037] S1 initializes the hardware acceleration environment;
[0038] S2 specifies the simulation time and iteration step size for the computational example;
[0039] S3 loads the example mesh topology;
[0040] S4 loads the initial water level and initial flow velocity of the example grid;
[0041] S5 loading example mesh roughness field;
[0042] S6 reads the boundary conditions of the calculation example;
[0043] S7 combines the finite volume method and the Harten-Lax-van Leer contact (HLLC) algorithm to discretize shallow water equations;
[0044] S8 uses just-in-time compilation technology to compile discrete solution code for shallow water equations, achieving parallel acceleration.
[0045] In this embodiment of the invention, the algorithm for shallow water is calculated using the following formula:
[0046] ,
[0047] ,
[0048] ,
[0049] In the formula, For water depth; For time; for The horizontal velocity component averaged along the vertical line; for The horizontal velocity component that is averaged along the vertical line. , For and , respectively along and The underwater slope and friction slope in the direction; It is the acceleration due to gravity; , respectively along and Wind stress in the direction.
[0050] In this embodiment of the invention, the hardware acceleration environment includes a hardware acceleration platform and data precision. The hardware acceleration platform can be selected from CPU, GPU or CUDA, and the integer or floating-point variables in the data precision can be selected from 32-bit or 64-bit.
[0051] In this embodiment of the invention, the simulation time and iteration step size respectively represent the simulation time corresponding to the simulation of a specific example and the duration of the shallow water equation state variable update for each iteration.
[0052] In this embodiment of the invention, the grid topology records the coordinates of each node of the quadrilateral grid and the adjacent edge relationships between the quadrilateral grids. The adjacent edge information between grids includes the grid number of the edge adjacent to the target grid.
[0053] In this embodiment of the invention, the initial field record of the grid hydrodynamic field records the initial water level and the initial flow velocity in the x and y directions for each quadrilateral grid in the specific calculation case.
[0054] In this embodiment of the invention, the grid roughness field records the roughness value of each quadrilateral grid in a specific calculation case, reflecting the resistance to water flow at each grid location.
[0055] In this embodiment of the invention, the case boundary conditions represent the change law of shallow water equation variables at the case grid boundary over time, which is used to drive the update of shallow water equation variable values for all grids.
[0056] In this embodiment of the invention, the Harten-Lax-van Leer contact (HLLC) algorithm is used to discretize and solve the shallow water equation after volume integration. The algorithm expression is as follows:
[0057] ,
[0058] In the formula, State variables correspond to the flow velocity in the x or y direction after depth integration in the shallow water equations, or the water depth; n represents the grid number; superscript and These represent the current and next moments in time, respectively; This indicates the step size for single-step calculation; The volume of a quadrilateral grid cell; Represents the transformation matrix; Indicates the grid number. Normal flux of each edge; For the first The area of each grid cell face; This represents the average value of the source terms for the grid cells.
[0059] In this embodiment of the invention, the just-in-time compilation technology uses the open-source Taichi framework in the Python environment to compile Python code in just-in-time, thereby achieving parallel acceleration.
[0060] Example
[0061] Combination Figure 1 This embodiment uses a simulated dam breach on Chongming Island as an example for detailed explanation. Chongming Island, located at the mouth of the Yangtze River, is a typical alluvial island situated in a typical plain tidal river network region. Its flat terrain and complex river network make it susceptible to the combined effects of typhoons, torrential rains, high tides, floods, and waterlogging. Under the influence of rising sea levels and extreme weather, Chongming Island's water security faces serious threats, making accurate simulation of its flood risk crucial. This embodiment selects a location on Chongming Island where a dam breach occurs to simulate the evolution of its flood. Figure 2This is a digital elevation information map of Chongming Island, whose elevation is mainly between 0 and 5 meters, while the surrounding dikes are mainly at an elevation of 8 meters. Specific breach locations are shown in the image. Figure 2 As indicated by the middle arrow, the breach width is 90 m. Based on... Figure 1 The flowchart in this embodiment shows the specific setup steps as follows:
[0062] (1) The hardware acceleration environment is set to implement parallel acceleration based on CUDA, and the precision of both integer and floating-point types is 32 bits.
[0063] (2) To simulate the effect of flood evolution over one day when the Chongming Island dam breaks, the simulation time of the model is set to 1 day (i.e. 86400 seconds). Given that the grid resolution is 10 m, the time step is 0.30 seconds.
[0064] (3) Load the Chongming Island grid topology structure, which records the coordinate information of each quadrilateral grid node and the topological relationship between grids. The grid information contains 13,244,968 grids and 13,259,205 grid nodes. A specific schematic diagram is shown below. Figure 3 and 4 As shown.
[0065] (4) Load the mesh roughness field. In this embodiment, all mesh roughness values are 0.02.
[0066] (5) Load the initial hydrodynamic force for each grid. The initial water level of each grid is set to 2.5 m, and the flow velocity in the x and y directions is set to 0.
[0067] (6) The boundary conditions are based on a 24-hour tidal process, reflecting a dam break starting from 5.0 m. The schematic diagram of the boundary conditions is shown below. Figure 5 As shown.
[0068] (7) The Taichi framework based on the Python environment performs just-in-time compilation of the code.
[0069] (8) Parallel acceleration solution of shallow water equations, from the occurrence of dam failure to the propagation of the dam-break flood within 5 hours, the results are as follows: Figure 6 As shown. In this embodiment, the effective grid size is on the order of 13 million, the grid size is 10 m, and the corresponding area is on the order of 13 million km². 2 According to the efficiency requirements in the "Technical Requirements for Flood Risk Mapping and Special Assessment" (Table 1), the simulation time for a 24-hour flood in this embodiment based on the present invention shall not exceed 130 minutes (calculated according to requirement 1). The hardware used in this embodiment is an RTX 4090 graphics card, and the simulation time for 24 hours is 30 minutes, which is significantly lower than the maximum allowable calculation time (130 minutes) in the "Technical Requirements for Flood Risk Mapping and Special Assessment".
[0070] Table 1. Computational efficiency requirements for different mesh sizes at the million-scale level.
[0071] Serial Number Effective grid number Average grid size Corresponding area (quadrilateral grid) The flood lasted for a long time Reference value for calculation time 1 1 million 10 m <![CDATA[100 km 2 ]]> 24 hours 10 minutes 2 1 million 50 m <![CDATA[100 km 2 ]]> 24 hours 3 minutes 3 1 million 100 m <![CDATA[100 km 2 ]]> 24 hours 2 minutes 4 1 million 200 m <![CDATA[100 km 2 ]]> 24 hours 1 minute
[0072] In summary, the flood evolution analysis method and system proposed in this invention, based on just-in-time compilation technology, has the advantages of strong code interpretability and high efficiency in solving shallow water equations. This makes it easier for professionals in the field of hydraulics to quickly master flood analysis methods and achieve simple and efficient simulation of flood evolution.
[0073] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A flood evolution analysis method based on just-in-time compilation technology, characterized in that... Includes the following steps: S1, Initialize the hardware acceleration environment; S2 sets the total simulation time and single-step calculation step size for the flood case. S3, Load the flood simulation grid topology; S4, load the initial water level and initial flow velocity of the flood case grid; S5, loading the roughness field of the flood simulation mesh; S6, Load the boundary conditions for the flood simulation; S7. An acceleration program based on the Harten-Lax-van Leer contact algorithm for updating shallow water equation state variables was written in the Taichi framework and Python environment. The acceleration program was translated into binary instructions using Taichi just-in-time compilation technology. Then, the update of shallow water equation state variables based on the HLLC algorithm was accelerated by CPU or GPU to quickly solve the shallow water equation and complete the simulation of flood evolution. The shallow water equation has the following mathematical expression: , , , In the formula, For water depth; For time; for The horizontal velocity component averaged along the vertical line; for The horizontal velocity component averaged along the vertical line; and respectively along and The underwater slope in the direction of the direction; and respectively along and Friction gradient in the direction; It is the acceleration due to gravity; The Harten-Lax-van Leer contact algorithm described in step S7 updates the state variables of the shallow water equation using the following formula: , In the formula, These are state variables, corresponding to the flow velocity or water depth in the x or y direction after the depth integral in the shallow water equation; the subscript n indicates the grid number; the superscript... and These represent the current and next moments in time, respectively; This indicates the step size for single-step calculation; The volume of a quadrilateral grid cell; Represents the transformation matrix; Indicates the grid number. Normal flux of each edge; For the first The area of each grid cell face; This represents the average source term value of the grid cells; The hardware acceleration environment described in step S1 includes a hardware acceleration platform and data precision. The hardware acceleration platform can be selected from CPU, GPU or CUDA. The integer or floating-point variables in the data precision include 32-bit or 64-bit. The mesh topology structure described in step S3 adopts a quadrilateral mesh to adapt to the real physical region, and records the coordinate information of the four mesh nodes of the quadrilateral mesh and the information of adjacent edges between meshes. The information of adjacent edges between meshes includes the mesh number of the edge adjacent to the target mesh.
2. The flood evolution analysis method based on just-in-time compilation technology according to claim 1, characterized in that: The total simulation time mentioned in step S2 is the simulation time corresponding to the flood simulation; the single-step calculation step size is the time corresponding to the state variable update during each iteration of the flood simulation.
3. The flood evolution analysis method based on just-in-time compilation technology according to claim 1, characterized in that: The initial flow velocity of the mesh mentioned in step S4 includes the initial flow velocity in the x and y directions.
4. The flood evolution analysis method based on just-in-time compilation technology according to claim 1, characterized in that: The grid roughness field mentioned in step S5 includes the roughness value of each grid cell, which reflects the magnitude of the resistance encountered by the water flow process at each grid location.
5. The flood evolution analysis method based on just-in-time compilation technology according to claim 1, characterized in that: The boundary conditions mentioned in step S6 include changes in water level or flow rate at the grid edges of the grid cells.
Citation Information
Patent Citations
Web end real-time interaction flood routing simulation visualization method
CN110555234A
Local adaptive multi-time step length non-uniform grid flood simulation system and method
CN116502483A