Scripted finite element rapid modeling method for underground water model
By using scripted finite element method, combined with Python programming and OpenGeoSys software, rapid modeling of groundwater was achieved, solving the problems of low efficiency and large computational load of traditional methods, and realizing an efficient and flexible modeling process.
Patent Information
- Application Number
- CN202511815584.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-04
- Publication Date
- 2026-03-06
AI Technical Summary
Traditional groundwater modeling methods are inefficient and struggle to handle complex hydrogeological conditions. Furthermore, existing software is computationally intensive and time-consuming, making it difficult to meet the needs of rapid modeling.
The scripted finite element method is adopted, using the Python programming language to edit scripts, referencing the anaflow, Matplotlib and ogs5py libraries, to automatically configure groundwater model parameters, and call OpenGeoSys software for modeling, realizing full automation from geometric construction to result extraction.
It enables rapid, efficient, and flexible modeling of groundwater models, allowing for quick addition or modification of physical fields and generation of multiple comparison charts. This significantly improves the efficiency and repeatability of model building and is suitable for handling complex boundary conditions.
Smart Images

Figure CN121615415A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a method for modeling groundwater models, specifically a script-based finite element rapid modeling method for groundwater models. Background Technology
[0002] Establishing groundwater models can accurately reflect the evolution of groundwater systems, reveal the processes of coupling multiple physical fields, and provide a strong basis for the management and development of groundwater resources. Traditional groundwater modeling methods include analytical methods and the finite element method (FEM), using software such as Modflow, COMSOL, and OpenGeoSys. When using these software programs, the typical modeling process involves manually drawing the geometric model in the UI, manually setting boundary conditions, manually meshing, and manually adjusting model parameters—each step requiring manual operation. If boundary conditions or parameters are changed during modeling, remodeling is necessary, and modeling becomes difficult when different physical fields are coupled, leading to inefficiency. Analytical methods combined with traditional software can only handle simplified boundary conditions and geometries, making it difficult to simulate heterogeneous and anisotropic media, and unable to handle complex hydrogeological conditions. The FEM combined with traditional software involves large computational loads, long processing times, and complex mesh generation. Currently, the severe situation of groundwater pollution and the expanding development and utilization of underground resources have led to a continuously increasing demand for rapid modeling. Traditional manual modeling methods are no longer sufficient to meet the needs for efficient, flexible, and repeatable modeling. Summary of the Invention
[0003] Purpose of the invention: The purpose of this invention is to provide a scripted finite element rapid modeling method for groundwater models to meet the needs of efficient, flexible, and repeatable modeling.
[0004] Technical solution: The present invention provides a script-based finite element rapid modeling method for groundwater models, comprising:
[0005] S1: Edit the script using a programming language, referencing the anaflow library, the Matplotlib plotting library, and the ogs5py library;
[0006] S2: Configure the parameters of the target groundwater model via script, including hydrogeological parameters, time distribution, grid angular and radial distribution;
[0007] S3: Determine the physical field process type of the target groundwater model (single or multiple fields). Based on the single or multiple field coupling process of the groundwater and the parameters configured in step S2, perform the following operations through the script: establish the mesh and define the geometric objects; define the boundary conditions, initial conditions, and source and sink terms; define the medium properties; define the numerical solver, the format of the output results, and the time step; the format of the output results is tec, vtk, or vtu.
[0008] S4: Automatically create the target groundwater model by calling the OpenGeoSys software input file through the script; automatically create the target groundwater model.
[0009] S5: Set the data type of the observation points as needed, edit the variables to be output and their types, then verify the model by comparing with the analytical solution, and draw a graph showing the change in the variable relationship between the simulation results and the analytical solution;
[0010] S6: Visualize the script's output.
[0011] Furthermore, in step S1, the programming language used is Python.
[0012] Furthermore, in step S2, the hydrogeological parameters include water storage coefficient, hydraulic conductivity, and permeability coefficient.
[0013] Furthermore, in step S2, the radial distribution configuration of the grid includes determining the sequence of the total grid, the range size, the number of radial points, and the radial distribution type of the grid; the angular distribution configuration of the grid includes discretization in terms of angle.
[0014] Further, in step S3, the establishment of the mesh and definition of the geometric object includes: generating a one-dimensional, two-dimensional or three-dimensional mesh as needed, and determining the mesh division in different directions; defining the geometric object and generating a radial geometric object with the same dimensions as the target groundwater model.
[0015] Furthermore, in step S3, the definition of boundary conditions, initial conditions, and source / sink terms all include: physical field process type, main variables, boundary objects, and variable types.
[0016] Furthermore, in step S3, if the output is point data, monitoring well data, or change curves, select the TEC format; if the output is a complete grid or a visualization of 2D / 3D field variables, select the VTU or VTK format.
[0017] Furthermore, step S5 includes: calling Theis analytical solution for comparison and verification, and calling the plt function in the Matplotlib plotting library to draw a variable relationship graph comparing the simulation results and the analytical solution.
[0018] Furthermore, in step S5, if the output result is in the format of vtu, it is not necessary to set the data type of the observation points or edit the variables to be output and their types. It is also not necessary to call the plt function in the Matplotlib plotting library to draw the variable relationship graph comparing the simulation results and the analytical solution.
[0019] Furthermore, in step S6, the script output results are opened with Tecplot software if they are in Tec format, and with Paraview software if they are in VTK or VTU format.
[0020] Beneficial Effects: Compared with existing technologies, this invention has the following significant advantages: This invention combines the finite element method with scripting. By constructing a unified script structure, scripted description language, and automatic solution process, it can automate the entire process of groundwater modeling, from geometric construction, mesh generation, parameter assignment, solution configuration to simulation operation and result extraction, without relying on a graphical interface. This invention can quickly add new physical fields, modify parameters, rapidly build models, and automatically solve them. It can generate multiple comparison charts, flexibly handle complex boundary conditions, and has batch calculation capabilities. It can solve the problem of long processing times caused by large computational loads, significantly improving the efficiency and repeatability of model construction, and providing a basis for groundwater research and engineering development. Attached Figure Description
[0021] Figure 1 This is a schematic diagram of the vertical interface of the pumping test in an embodiment of the present invention;
[0022] Figure 2 This is a schematic diagram of a two-dimensional radial model of a pumping test in an embodiment of the present invention;
[0023] Figure 3 This is a flowchart of a scripted finite element rapid modeling method for groundwater models provided in an embodiment of the present invention;
[0024] Figure 4 This is a visual diagram of the script output results in an embodiment of the present invention;
[0025] Figure 5 This is a comparison chart of the simulation results drawn by the script and the analytical solution in an embodiment of the present invention. Detailed Implementation
[0026] The invention will now be further described with reference to the accompanying drawings.
[0027] like Figure 3 As shown, this embodiment of the invention provides a scripted finite element rapid modeling method for groundwater models, including the following steps:
[0028] S1: Edit the script using Python, referencing the anaflow library, the Matplotlib plotting library, and the ogs5py library.
[0029] Anaflow is a Python library for analytical solutions of groundwater. It contains a large number of classic analytical solutions for groundwater, which can be selected according to needs, such as the Theis solution (for unsteady pumping) and the Thiem solution (for steady pumping). The Matplotlib plotting library provides various plotting functions, such as plot() for line plots, scatter() for scatter plots, and imshow() for image plotting, which can be selected as needed.
[0030] S2: Configure the parameters of the target groundwater model through the script, including hydrogeological parameters, time distribution, grid angular and radial distribution. Other parameters need to be configured according to the needs of the actual problem (e.g., pumping test requires pumping well location and pumping rate).
[0031] Hydrogeological parameters include water storage coefficient, hydraulic conductivity, and permeability coefficient, which are used to define the properties of the medium, fluid properties, or solid properties.
[0032] Configure the radial and angular distributions of the mesh, as well as the temporal distribution, for subsequent mesh, geometry, and time step generation. The radial distribution configuration determines the overall mesh sequence, extent size, number of radial points, and the type of radial distribution. The angular distribution configuration includes angular discretization.
[0033] Other parameters required by the project are also used for defining subsequent medium properties, fluid properties, or solid properties, as well as generating geometry. These other parameters include concentration, temperature, flow rate, stress, and pumping well location.
[0034] S3: Determine the physical field process type of the target groundwater model (single or multiple fields). Based on the single or multiple field coupling process of the groundwater and the parameters configured in step S2, perform the following operations through the script: establish the mesh and define the geometric objects; define boundary conditions, initial conditions, and source and sink terms; define the porous medium properties, fluid properties, or solid properties in the model (select the properties to be defined according to the actual problem); define the numerical solver, the format of the output results, and the time step; the output results are in the format of tec, vtk, or vtu.
[0035] The type of physical field process in a single or multiple field model needs to be determined by the user. The boundary conditions, initial conditions, source and sink terms, numerical solver, and time step of the model must be related to the determined physical field process and be consistent throughout the process.
[0036] Establish a mesh and define geometric objects, including: generating a one-dimensional, two-dimensional, or three-dimensional mesh as needed, and determining the mesh division in different directions; defining geometric objects and generating radial geometric objects with the same dimensions as the target groundwater model.
[0037] Defining boundary conditions, initial conditions, and source / sink terms includes: physical process type, main variables, boundary objects, and variable types. At this point, the initial definition of the OGS input file is complete.
[0038] If the output is point data, monitoring well data, or change curves, select the TEC format; if the output is a complete grid or a visualization of 2D / 3D field variables, select the VTU or VTK format.
[0039] S4: Automatically create the target groundwater model by calling the OpenGeoSys software via script, inputting the target groundwater model.
[0040] This process is based on code implementation, with the code model.write_input() automatically writing the input to the ogs5py input file and the code model.run_model() automatically building the model.
[0041] S5: Users can set the data type of observation points according to the project requirements, edit the variables to be output and their types, call the Theis analytical solution for comparison and verification, and call the plt function in the Matplotlib plotting library to draw a variable relationship graph comparing the simulation results and the analytical solution. If the output format is vtu, it is not necessary to set the data type of observation points or edit the variables to be output and their types, nor is it necessary to call the plt function in the Matplotlib plotting library to draw a variable relationship graph comparing the simulation results and the analytical solution.
[0042] S6: Visualize the script's output. If the script output is in Tecplot format, open it with Tecplot; if it's in VTK or VTU format, open it with Paraview.
[0043] Here is a specific example.
[0044] like Figure 1 The diagram shows a schematic of the vertical interface of a pumping test, where the pumping well extracts groundwater from the aquifer; the observation well is located near the pumping well and is used to monitor changes in the aquifer water level during pumping. Figure 2 The image shows a schematic diagram of a two-dimensional radial model for a pumping test. The central black dot represents the pumping well, and the red dot on the right represents the observation well. Concentric circles and radial lines represent the radial grid of groundwater flow. The modeling process is as follows:
[0045] (1) The script is written in Python. First, it references relevant modules, the Matplotlib plotting library, and key functions from the ogs5py library. Establishing the pumping test model requires a specialized library for groundwater flow analysis, which provides multiple analytical solutions. The steps are as follows:
[0046] Include the anaflow library, Matplotlib's pyplot library, and the OGS, generate_time, and specialrange libraries from ogs5py. If a "Module Not Found Error" occurs when running the program, you also need to include sys to ensure that the current script can successfully import any Python modules located in the src folder of the parent directory of the current directory.
[0047] (2) Determine the required parameters, such as time distribution, water storage coefficient, and hydraulic conductivity, and establish the groundwater pumping test model. This requires determining the location of the observation well, the angle division of the two-dimensional radial model, the water storage coefficient, the hydraulic conductivity, and the pumping rate. The steps are as follows:
[0048] The function specialrange() is used to assign the parameter time, which is the time series, ranging from 0 to 3600s, divided into 50 points, and distributed in the form of cub (cub function distribution); the parameter rad is determined, which is the radius series, ranging from 0 to 1000m, divided into 100 points, and distributed in the same way as above; the parameter obs is determined to be rad
[21] , and the 22nd radius point is taken as the location of the observation well; the parameter angles is determined to be 32, that is, the circumference is divided into 32 angles, which is used for finite element mesh generation, so that the model can simulate groundwater flow in the angular direction; the water storage coefficient is determined to be 1e-3, the water conductivity coefficient is determined to be 1e-4, and the pumping or injection rate is -1e-3; finally, the OGS model object model is determined, and the function OGS() is used to determine the root directory task_root and the model name task_id, and the root directory of the project task is edited to pump_test, and the file name is model.
[0049] (3) Users need to determine the physical field process type of the single or multiple fields of the model themselves. According to the single or multiple field coupling process of groundwater, set PCS_TYPE in model.pcs.add_block() to "GROUNDWATER_FLOW" and NUM_TYPE to "NEW", that is, the physical process is groundwater flow. Then complete the following steps:
[0050] 1. Determine the 2D radial-angular finite element mesh. Set "radial", "dim", "rad", and "angles" in `model.msh.generate()`. This generates a 2D radial mesh. The radial and angular meshes are divided according to the previous parameters "rad" and "angles". A 2D radially symmetric mesh is generated. Rings are continuously added according to the parameter "rad". The angular circumference is divided into 32 sectors. Define the model geometry. Set "radial", "dim", "rad_out", and "angles" in `model.gli.generate()`. This generates the radial geometry. Determine the last point of the outer boundary with a radius of "rad". Divide the circumference into 32 angles. Determine the positions of the pumping well and observation well. Set `[x,y,z],"pwell"` or "owell"` in `model.gli.add_points()` to determine the specific locations.
[0051] 2. Define boundary conditions, initial conditions, and source / sink terms. The physical process for boundary conditions is saturated groundwater flow, the main variable in the simulation is the head, the geometric object acting is a line segment, and the condition distribution type is constant. The physical process for initial conditions is saturated groundwater flow, the main variable in the simulation is the head, the geometric object acting is the entire domain, and the condition distribution type is constant. The physical process for source / sink terms is saturated groundwater flow, the main variable in the simulation is the head, the geometric object acting is a point, i.e., a pumping well, at which a fixed flow rate (rate) is applied. The steps are as follows:
[0052] S1: Determine the boundary conditions. Set PCS_TYPE, PRIMARY_VARIABLE, GEO_TYPE, and DIS_TYPE in model.bc.add_block(). Here, the groundwater flow process acts on the boundary conditions. The initial variable is the water head. The geometric object type of the boundary conditions is a polyline, i.e., the boundary line. A constant boundary condition with a water head of 0 is applied.
[0053] S2: Determine the initial conditions, set PCS_TYPE, PRIMARY_VARIABLE, GEO_TYPE and DIS_TYPE in model.ic.add_block(). The first two parameters are set as above. The geometry type of the initial conditions is a face, i.e. the entire model domain, and a constant initial condition with an initial head of 0 is applied.
[0054] S3: Determine the source and sink terms, set PCS_TYPE, PRIMARY_VARIABLE, GEO_TYPE and DIS_TYPE in model.st.add_block(). The first two parameters are set as above. The geometric objects of the source and sink terms are similar to points, i.e. pumping wells, and a constant flux boundary with a flow rate of rate is applied.
[0055] 3. Define the properties of the porous medium, fluid properties, or solid properties in the model. This model is a two-dimensional planar model. Define the water storage characteristics of the material (the water storage coefficient is a fixed value), and define the permeability characteristics of the medium (here, it is isotropic, and the permeability coefficient is determined). The steps are as follows:
[0056] Determine the medium parameters and set GEOMETRY_DIMENSION, STORAGE and PERMEABILITY_TENSOR in model.mmp.add_block(). Here the model is two-dimensional, the water storage coefficient is the same as in step (1) and is a fixed value, and the water conductivity coefficient is the same as in step (1) and is isotropic permeability.
[0057] 4. Define the numerical solver settings, output format, and time step in the model. When setting up the numerical solver, determine that the physical process is saturated groundwater flow. Crucially, determine the solution method used to control the system of equations. The model output also defines the physical process as saturated groundwater flow, the output node variables as head, the output objects (points) as observation wells, and the output file format as TECPLOT. The time step is set to be automatically generated according to the parameter `time`. The steps are as follows:
[0058] S1: Determine the solver settings, set PCS_TYPE and LINEAR_SOLVER in model.num.add_block(), the physical process is groundwater flow, the solver is linear, the solver type is 2, the preprocessor is 5, the convergence accuracy is 1e-14, the maximum number of iterations is 1000, the damping coefficient is 1.0, the output step size is 100, and the solver output options are 4.
[0059] S2: Determine the output settings, set PCS_TYPE, NOD_VALUES, GEO_TYPE and DAT_TYPE in model.out.add_block(), the physical process is the groundwater flow process, the output variable is the head, the output location type is the observation well, and the output format is tec.
[0060] S3: Determine the time step setting, and set PCS_TYPE in model.tim.add_block() to the groundwater flow process. The `generate_time(time)` function automatically generates a time series based on the previously defined `time`.
[0061] (4) The input file for the target groundwater model is automatically generated by calling the OpenGeoSys software via script, and the model is automatically generated. The steps are as follows:
[0062] Set `model.write_input()` to write input data into the model, preparing for model calculation; set `model.run_model()` to run the model calculation and save the result to a variable; set `print("success:", success)` to print whether the model calculation was successful.
[0063] (5) Users set the data type of observation points according to the needs of the project problem, edit the variables to be output and their types, and then verify the model by comparing the analytical solution. They also draw a graph showing the change in the variable relationship between the simulation results and the analytical solution. The steps are as follows:
[0064] 1. Input model.readtec_point() to read the head and time data output by the model, especially the data related to groundwater flow (GROUNDWATER_FLOW). Its function is to find the .tec file in the current model output directory, identify which "POINT" output types, and then read the data and return a dictionary structure of data, which will be used to assign values to the time and head variables below.
[0065] 2. Set point["owell"]["TIME"] to extract the time series data at the owell observation well from the model output data and save it to the variable time. Set point["owell"]["HEAD"] to extract the head data at the owell observation well from the model output data and save it to the variable head.
[0066] 3. Set ana.theis(), which is calculated based on Theis solution, to represent the water level change at a certain point in a homogeneous, isotropic, and horizontal aquifer at a certain time step.
[0067] 4. Set `plt.scatter()` to plot the simulated head data as a scatter plot; set `plt.figure()` to specify the plotting window size; set `plt.plot()` to plot the theoretical solution (head change); set `plt.xlabel()` and `plt.ylabel()` to add labels below the X and Y axes, with the X-axis representing time (s) and the Y-axis representing head (m); set `plt.legend()` to add a legend to the plot to easily distinguish different data lines; set `plt.tight_layout()` to automatically adjust subplot parameters to ensure reasonable spacing between subplots; set `plt.show()` to display the currently plotted graph; and set `model.msh.show()` to display the model's grid structure.
[0068] Figure 5 The image shown is a comparison chart between the simulation results generated by the script and the analytical solution.
[0069] (6) The script output is a .tec file, which can be opened with Tecplot. The result is as follows: Figure 4 As shown.
[0070] The above steps are for reference only when using a pumping test. If used for modeling other projects, adjustments need to be made based on the specific project. Subsequent plt functions plot the XY coordinate system relationship between head and time.
Claims
1. A scripting finite element fast modeling method of groundwater model, characterized in that, The method comprises the following steps: S1: editing a script through a programming language, referencing an anaflow library, a Matplotlib drawing library and an ogs5py library; S2: configuring parameters of a target groundwater model through the script, including hydrogeological parameters, time distribution, grid angle distribution and radial distribution; S3: determining a type of a physical field process of a single field or multiple fields of the target groundwater model, and according to a single field or multiple field coupling process of the groundwater and the parameters configured in step S2, performing the following operations through the script: establishing a grid and defining a geometric object; defining a boundary condition, an initial condition and a source-sink term; defining a medium property; defining a numerical solver, a format of output results and a time step; and outputting the format of the results as tec, vtk or vtu; S4: automatically establishing an input file of the target groundwater model and automatically establishing the target groundwater model through the script calling the OpenGeoSys software; S5: setting a data type of an observation point according to a need, editing a variable to be output and a type thereof, and then comparing and verifying the model through a analytical solution and drawing a variable relationship change graph of the simulation results and the analytical solution; S6: visualizing output results of the script.
2. The scripting finite element quick modeling method of groundwater model according to claim 1, wherein, In step S1, the programming language is Python.
3. The scripting-based fast finite element modeling method of groundwater modeling according to claim 1, wherein, In step S2, the hydrogeological parameters include a storage coefficient, a hydraulic conductivity and a permeability coefficient.
4. The scripting-based fast finite element modeling method of groundwater modeling according to claim 1, wherein, In step S2, the grid radial distribution configuration includes determining a sequence of a total grid, a range size, a number of points in a radial direction and a grid radial distribution type; and the grid angle distribution configuration includes discretization in an angle.
5. The scripting based fast finite element modeling method for groundwater modeling according to claim 1, wherein, In step S3, the establishing of the grid and the defining of the geometric object include: generating a one-dimensional, two-dimensional or three-dimensional grid according to a need, and determining grid division in different directions; and defining a geometric object to generate a radial geometric object with the same dimension as the target groundwater model.
6. The method of claim 1, wherein, In step S3, the defining of the boundary condition, the initial condition and the source-sink term all include: a type of a physical field process, a main variable, a boundary object and a variable type.
7. The method of claim 1, wherein, In step S3, if point data, monitoring well data or a change curve is output, a tec format is selected; and if a complete grid or a 2D / 3D field variable output is visualized, a vtu or vtk format is selected.
8. The scripting based fast finite element modeling method of groundwater modeling according to claim 1, wherein, Step S5 includes: calling a Theis analytical solution for comparison and verification, and calling a plt function in the Matplotlib drawing library to draw a variable relationship graph of the simulation results and the analytical solution.
9. The scripted finite element rapid modeling method of groundwater modeling of claim 8, wherein, In step S5, if the format of the output results is vtu, the data type of the observation point and the variable to be output can not be edited, and the plt function in the Matplotlib drawing library can not be called to draw the variable relationship graph of the simulation results and the analytical solution.
10. The method of claim 1, wherein, In step S6, the output results of the script, if being a tec format file, are opened by using Tecplot software; and if being a vtk or vtu format file, are opened by using Paraview software.