Search

CN-121981022-A - Method for calculating field volume integral in OpenFOAM unsteady simulation result

CN121981022ACN 121981022 ACN121981022 ACN 121981022ACN-121981022-A

Abstract

The invention discloses a method for calculating field volume integral in an OpenFOAM unsteady simulation result, which comprises the steps of firstly setting a current working root directory of the OpenFOAM, reading grid files stored in a discrete mode by the OpenFOAM and creating an example grid, accessing a time control function, reading time information, creating a global blank file under the working root directory, storing a calculation result of volume integral, writing a time variable name and a variable name corresponding to the physical volume integral to be calculated by a program in the first row of the global blank file, sequentially reading field volume data required by calculating the physical volume integral, defining and calculating the physical quantity concerned and an intermediate physical quantity through a regular expression, defining a concerned region, calculating the product of the physical quantity concerned and the corresponding grid volume, writing the calculation result according to a time sequence, and finishing result output by traversing all moments. The invention can automatically process the multi-time data in batches, greatly reduces the manual operation cost and realizes the efficient acquisition of the field volume integral time evolution rule.

Inventors

  • HUANG ZHIWEI
  • ZHANG CHI

Assignees

  • 上海交通大学

Dates

Publication Date
20260505
Application Date
20260407

Claims (10)

  1. 1. A method for calculating field volume integral in OpenFOAM unsteady simulation results, comprising the steps of: S1, setting a current working root directory of OpenFOAM, reading a grid file of the OpenFOAM, which carries node coordinates, a grid cell owner, adjacent grid cells, a grid surface and boundary condition definition information, and creating an example grid; s2, accessing a time control function of an OpenFOAM standard, and reading time information of numerical simulation corresponding to all time folders under a working root directory; s3, creating a global blank file under the working root directory, and storing the calculation result of volume integral of a specific physical quantity in a specific calculation area at each moment; s4, writing a time variable name and a variable name corresponding to the physical quantity volume integral to be calculated by the program in the first row of the global blank file; S5, sequentially reading field quantity data which are independently stored in the time folder by using an OpenFOAM standard output file and are required for calculating the volume integral of the physical quantity; S6, defining and calculating physical quantities of interest and other intermediate physical quantities required for calculating the physical quantities through regular expressions; s7, defining an integration area of interest, traversing all grids according to grid numbers, and sequentially calculating the product of the physical quantity of interest and the corresponding grid volume; And S8, writing the calculation result of volume integration of the physical quantity concerned on the specific area in the global file according to the time sequence, and completing result output at all times.
  2. 2. The method for calculating field volume integral in an OpenFOAM unsteady simulation result according to claim 1, wherein in S1, the grid file is generated by an OpenFOAM self-contained blockMesh tool or is converted into an OpenFOAM local file format after being imported by a third party software.
  3. 3. The method for calculating the field volume integral in the OpenFOAM unsteady simulation result according to claim 2, wherein in S1, the example grid is a one-dimensional grid, a two-dimensional grid or a three-dimensional grid, wherein the one-dimensional grid is a structured grid, and the two-dimensional grid or the three-dimensional grid adopts a structured or unstructured grid; the computing grid is a static grid or a dynamic grid, if the computing uses the static grid, a unique set of grids is read in at one time at the initial moment and multiplexed in the whole course, and if the computing uses the dynamic grid, the grids under the corresponding time folders are sequentially read according to time.
  4. 4. A method for calculating field volume integral in OpenFOAM unsteady simulation result according to claim 3, wherein in S2, a time object runTime is constructed by accessing createtime.h header file, the object is initialized by analyzing controlDict control dictionary, the simulation time step is controlled from initial time to final time, and each time of simulation result output is determined; the specific time is designated by adding options, the specific time comprises a constant option, the constant option comprises a constant/catalog under a root catalog, the final time is designated by a LATESTTIME option, the 0 time is excluded by a noZero option, and the specific time is selected by a time option matching time list.
  5. 5. The method for calculating field volume integral in OpenFOAM unsteady simulation result according to claim 4, wherein in S3, the format of the global blank file comprises dat data format and other formats read by the adaptive data post-processing software; if the volume integral of a plurality of physical quantities in the same area is calculated at the same time, the sequence of the physical quantities is not limited at all, wherein the plurality of physical quantities in the same area comprise a total heat release rate, a heat release rate in a premixed combustion mode and a heat release rate in a supersonic combustion mode; If the volume integral of a plurality of physical quantities in different areas is calculated, the number of the created global blank files is the same as the number of the target areas so as to store the calculation result of the volume integral of the physical quantity under the corresponding areas, wherein the plurality of physical quantities in different areas comprise the total heat release rate of the whole combustion chamber, the total mass of fuel of the combustion chamber section after the fuel inlet and the total mass of the product.
  6. 6. The method for calculating field volume integral in OpenFOAM unsteady simulation result according to claim 5, wherein in S4, the name of the physical quantity variable for calculating volume integral in hydrogen combustion simulation comprises total hydrogen heat release rate Heat release rate of hydrogen premixed combustion Ultrasonic combustion heat release rate of hydrogen Total mass of hydrogen in combustion chamber And the total mass of water produced by the combustion of hydrogen in the combustion chamber ; The variable names are separated by a space to adapt to the data post-processing software to identify different variable names, and the physical quantity to be subjected to volume integration comprises a scalar, a vector and a tensor, and if the physical quantity is the vector or the tensor, the variable names corresponding to the components are defined in the first line of the file.
  7. 7. The method for calculating field volume integral in OpenFOAM unsteady simulation result according to claim 6, wherein in S5, reading and writing of files are carried out through a file reading and writing mechanism IOdictionary of OpenFOAM standard, and the files are read and written only and not for field volume data stored in each time folder; Other intermediate physical quantities required for calculating the physical quantity of interest are scalar, vector, and tensor, and the field quantity type is specified and limited by volScalarField, volVectorField and volTensorField entry keys in IOdictionary; traversing all calculation moments under the working root directory by adopting forAll loop functions of the OpenFOAM standard, reading field quantity data required in each time folder, and assuming common reading Each time, each time read The total number of the read files is ; The number of stored field amounts to be read, the number of intermediate or final field amounts to be calculated, the number of time folders to be read, and the time distribution of the time folders are not limited and do not require equal intervals.
  8. 8. The method for calculating the field volume integral in the OpenFOAM unsteady state simulation result according to claim 7, wherein S6 is specifically: Creating physical field quantities of interest through the file read-write mechanism IOdictionary class of the OpenFOAM standard, declaring the types thereof as scalar fields, vector fields and tensor fields through volScalarField, volVectorField and volTensorField, respectively; the temporary field file is not read or written, and the data is obtained by field quantity operation of the OpenFOAM standard from the field quantity data known in the step S5.
  9. 9. The method for calculating the field volume integral in the OpenFOAM unsteady state simulation result according to claim 8, wherein S7 is specifically: Traversing all grid cells in an OpenFOAM embedded standard forAll loop for each moment, and screening a physical area by adding if judgment conditions, wherein the screening conditions comprise range definition based on grid center coordinates; For a static grid, the data written into the field quantity file at each moment has the same organization structure, and all the moments store the product of the physical quantity concerned and the grid volume of the unit into a temporary field quantity file according to a fixed grid numbering sequence; For the dynamic grid, the data written into the temporary field quantity file at each moment has different grid structures, and the data is calculated in an adapting way according to the grid topological structure at the current moment.
  10. 10. The method for calculating the field volume integral in the OpenFOAM unsteady state simulation result according to claim 9, wherein in S8, the field volume or the list is summed by a global summing function gSum of the OpenFOAM standard; Outputting a gSum summation result once at each moment in each cycle, and inserting a next blank new row at the same time, and starting from the initial moment, sequentially increasing to the final moment according to time until the program finishes running; if the volume integral of a plurality of physical quantities of different areas is calculated in S3, the results of the different areas are written into the corresponding files; And outputting a global data file containing the calculation results of the volume integral of the specific physical quantity in the specific area at each moment after the program operation is finished, and analyzing the evolution rule of the volume integral of the physical quantity along with time to monitor the overall combustion performance and the combustion chamber performance of the hydrogen.

Description

Method for calculating field volume integral in OpenFOAM unsteady simulation result Technical Field The invention relates to the technical field of post-processing of computational fluid dynamics data, in particular to a method for calculating field volume integral in an OpenFOAM unsteady simulation result. Background With the rapid development of computer hardware and software technology, computational fluid dynamics (CFD: computational Fluid Dynamics) has been widely used in various fields such as aerospace, weapon industry, marine, energy power, vehicle traffic, reworking machinery, electronic and electric appliances, etc. OpenFOAM, an object-oriented open source CFD software package, has a convenient modular design, a strong multi-physical field coupling, flexible code customization and efficient parallel computing capability, and has recently received extensive attention from academia and industry. Compared with common CFD commercial software such as ANSYS Fluent, STAR-CD, STAR-CCM+, CFX and the like, the algorithm is closed, the copyright is expensive, the OpenFOAM source code is completely opened, and additional software cost is not required to be paid. Meanwhile, the device supports a polyhedral grid, can process complex geometric configuration, and has strong simulation and analysis capability aiming at the problems of flow, combustion, heat transfer and other various multi-physical field coupling. After numerical simulation with OpenFOAM, data processing and result analysis need to be performed, and it is often necessary to quantify the overall physical effects over the entire computational domain or within specific local areas. For example, in the fields of aerodynamics and hydrodynamics, in the external flow fields of automobiles and airplanes, the component design is optimized by calculating the resultant force of pressure difference resistance and viscous resistance suffered by a virtual control body surrounding a specific component (such as a rearview mirror and a wing), the overall combustion performance and the combustion chamber performance are evaluated by calculating the total heat release rate of fuel combustion in a combustion chamber or the heat release rates in different combustion modes for heat transfer and energy analysis, and when multiphase flow problems are studied, the mass, momentum and energy exchange rate between two phases in a phase interface area with active chemical reaction are calculated, and the spatial distribution of the two phases and the flow morphology of the system are predicted. These research requirements can be essentially attributed to the volumetric integration of field variables (e.g., pressure, heat release rate, two-phase exchange volume) within a selected three-dimensional spatial region (i.e., control volume). However, in the current standard post-processing flow of OpenFOAM, there are significant inconveniences and limitations to implementing the above functions. The built-in postProcess tool of OpenFOAM and functionObject (e.g., FIELDAVERAGE, for) are capable of performing some predefined integration calculations, but only specify the integration region prior to calculation. When a new area is analyzed, the calculation needs to be carried out again, and direct support for carrying out general field volume integration on the user-defined area is lacking. And the method only supports volume integral of basic field quantity, does not support volume integral of derivative field quantity which needs to be calculated through regular expression of other field quantity, and can only carry out manual post-processing on complex physical quantity. This process is time consuming, labor intensive and error prone. For example, in simulating the unstable combustion of hydrogen, the heat release rate of hydrogen in the combustion chamber in the supersonic combustion mode is calculated. The simulation result does not directly output the field quantity, and volume integration is needed after a series of calculation. The volume integral of the physical quantity cannot be obtained through the self-contained post-processing method of OpenFOAM, so that analysis and research on the hydrogen supersonic combustion mode are limited. In addition, in modeling complex unsteady combustion problems, openFOAM will output a large amount of field data including mach number, pressure, heat release rate, and mass fraction of components over the entire computational domain, which are stored in separate files distributed under different time folders. Assuming that 2000 times are output in total in a certain calculation, if the evolution rule of the supersonic combustion heat release rate with time is to be obtained, the 2000 times need to be processed respectively. This requires a lot of manual operations or script support, is inefficient and is prone to error. Therefore, a need exists for a native solution that can directly interface with the output results of the OpenFOAM common solve