Developing a module to convert OpenFOAM computational meshes to the msh format

The paper reveals the features of developing an application for conversion of computational meshes built in OpenFOAM to the msh format applied for numerical simulation of continuum mechanics (CM) problems with the ANSYS FLUENT platform. Some companies apply this platform in parallel with OpenFOAM that requires a mesh conversion module. Although there are program tools capable to solve this problem, their application involves some difficulties, mainly the necessity to pay for a license, absence of complete documentation, paid technical support. Thus, the described problem is actual and its solution – developing a conversion module – is the study purpose. The article discloses features of the OpenFOAM utility for conversion, a list of technologies to develop a module, module action, results of its performance test using a CM problem. The study findings are statements of scientific novelty and expected practical significance.


Introduction
The present paper involves the results of the study in enhancing a base graphical environment [1] used for simulating CM problems with OpenFOAM [2]. The application base version provides executing only some tasks of preprocessing, solving and postprocessing, that is not enough to cover the whole list of CM problems, therefore the application source code was subsequently enhanced by creating and integrating modules for operation with other OpenFOAM utilities [3,4].
Within the study it is proposed by analogy to complete a graphical interface [1] with a program module for operation with the foamMeshToFluent utility that provides conversion of the OpenFOAM mesh to the msh format applied for operation with ANSYS FLUENT [5].
For numerical simulations companies apply different program complexes, among which ANSYS and OpenFOAM are widely used. The first one has been used since 1970 and proved to be a universal system for numerical simulations of CM problems: linear and nonlinear, stationary and nonstationary spatial problems of deformable solids mechanics, problems of fluid and gas mechanics. Examples of setting up numerical experiments using the OpenFOAM are presented in publications [6][7][8][9].
The ANSYS system is a program product requiring the purchase of a license and payment for technical support services. It forces some companies to choose open source software, such as OpenFOAM. The options of this platform are enhanced and at present it is practically as good as ANSYS.
As the OpenFOAM user interacts with the platform by means of a command line, i.e. without a traditional graphical user's interface, some companies do not totally switch to OpenFOAM and in some cases use the ANSYS system. However, the OpenFOAM and ANSYS platforms are different software To convert the OpenFOAM mesh to the msh format the specialists can use third-party graphical environments for OpenFOAM, in particular Salome, Helyx-OS, Visual-CFD, but operation with them requires the purchase of a license and payment for consulting and adjustment, besides, the documentation on these products includes only a short description of their options and does not promote complete understanding, so developing a module for conversion of meshes is still acute.

Purpose of the foamMeshToFluent utility
As was mentioned above, an alternative to the OpenFOAM platform is a line of ANSYS program complexes. First, this concerns the ANSYS FLUENT platform applied in design and technological divisions of machine-building enterprises. It is a flagship ANSYS product to study flows of fluid and gas with due account of turbulence, interphase interaction, chemical reactions, combustion and aeroacoustic effects.
The main shortcoming of the ANSYS program products is a need to pay for the license. Some companies, in particular which have not switched totally to OpenFOAM, can use the applications in parallel. For example, ANSYS FLUENT can be used to postprocess the cases simulated with the OpenFOAM environment. This task is complex as the OpenFOAM mesh format can't be integrated to FLUENT. The foamMeshToFluent utility is used for the mesh adaptation and conversion to the format used in FLUENT. The conversion is controlled with dictionary files controlDict and foamDataToFluentDict located in folder constant. The features of the first dictionary file were analyzed by the author in [1]. A respective electronic screen widget was developed for the file and a program code was prepared to record and recover screen-defined parameters.
The correctness and accuracy of the initial mesh generated in OpenFOAM is checked with the ParaView visualization tool, then the mesh parameters can be corrected and the generation can be repeated. The accuracy of the computational mesh converted to the FLUENT format is provided with the foamMeshToFluent utility responsible for the conversion. The final results of the numerical simulation are displayed with the FLUENT software package.
The foamDataToFluentDict dictionary file includes records in the form of parameternumerical parameter mark. This mark is necessary for the FLUENT postprocessor to interpret correctly the defined parameters [10].
The OpenFOAM parameters versus the respective ANSYS FLUENT marks are given in table 1. The example of the foamDataToFluentDict completed dictionary file is presented in figure 1.

Setting goals and problems
The present study is intended to provide access for the user of the graphical interface [1] to operation with the foamMeshToFluent utility via a familiar window interface. To convert computational meshes generated in OpenFOAM to the format applied in ANSYS FLUENT the specialist should prepare the foamDataToFluentDict dictionary file used to define parameters for connectivity of two mesh formats. Without the graphical environment built in OpenFOAM the user has to manually create and fill in the dictionary file. This process is featured by high labour intensity and risks of errors.
The goal of the study is to upgrade the application source code [1] with regard to modification of the graphical component and program scripts. From the documentation available to the OpenFOAM user, the author has learnt the features of the foamMeshToFluent utility and rules of preparing the foamDataToFluentDict dictionary file. As the application [1] has a module principle, the present work is directed to develop a program module and integrate it to the application source code.
The user should have the opportunity to operate with the specified utility and the respective dictionary file as usual, i.e. via a graphical interface. Therefore, it is required to enlarge a list of options available to the user in the graphical environment [1] and perform the following tasks: • prepare a program code responsible for the generation of the electronic screen structure for the foamDataToFluentDict dictionary file and for the file creation and completion based on the screen-defined parameters; • prepare validators for types of the screen-defined parameters; • implement a mechanism of preparing a new foamDataToFluentDict dictionary file and modifying the existing one; • implement interface control elements to start up the OpenFOAM foamMeshToFluent utility.

Development tools
Success in the application development depends much on the selected stack of technologies, primarily a programming language for logics of the program operation, additional libraries, frameworks, development environment. As well as the base graphical environment [1] proposed by the author, the presented program module for operation with the foamMeshToFluent utility was developed with the Python tools and the graphical componentwith the PyQt library tools [11].
In the popularity rating of programming languages (TIOBE rating) the Python language came second as of August 2021 [12]. It is a popular tool to implement the logics of desktop and web applications that provides a powerful complex of built-in functions and classes and permits to attach third-party libraries. The PyQt library components are successfully integrated to the Python programs and permit to create familiar electronic screens.

Module operation
Before operation with the foamDataToFluent utility it is necessary to perform the most important phase of preprocessinggeneration of the computational mesh. A base computational mesh is generated with standard OpenFOAM utilities, e.g. blockMesh, snappyHexMesh, foamyQuadMesh [3]. Then an additional OpenFOAM utility can be applied to modify the computational mesh [4]. The foamMeshToFluent utility is recommended to be used after generating the base mesh.
If required, the specialist can return to previous phases and correct the mesh model, for example. The necessity of corrections is defined from the analysis of the mesh model visualized in ParaView. The mesh converted to the msh format is applied later on in ANSYS FLUENT, e.g. when postproccesing the numerical simulation.

Study results
The result of the study performed by the author is the enhanced source code of the base graphical environment [1]. The modified application version is available at the GitHub platform for hosting IT projects [13]. The enhanced graphical environment gives the user an opportunity to prepare the foamDataToFluentDict dictionary file and start up the foamMeshToFluent utility via a familiar window interface. The source code of the program module under study has built-in scripts to generate and display the graphical application component (interface), scripts to fill in the foamDataToFluentDict dictionary file and validators to control parameters input via the interface. The modified version of the graphical environment can be used by the specialists of different machine-building branches who operate with the OpenFOAM and ANSYS FLUENT program complexes. Figure 2 present the results of the module operation using a training task included in the OpenFOAM distributive. This CM problem is called as elbow and corresponds to the numerical simulation of incompressible flow with the icoFoam solver. Using this solver, the user can set the kinematic viscosity. The icoFoam solver is used primarily in experiments involving water, since it is not highly compressible.

Conclusions
The present paper continues a cycle of the studies started in 2016 and described in [1,3,4]. The author modified the base graphical environment providing to the specialist an opportunity to operate with the foamMeshToFluent utility via familiar electronic screens. The study performed by the author resulted in the following solved problems: • electronic screens were developed to edit internal dictionary files defining operation parameters of pre-and postprocessing utilities, the foamMeshToFluent utility in this case; • the algorithm was developed for generation and realization of the bash script providing a program start of the OpenFOAM foamMeshToFluent utility; • the validators were developed for types of the screen-defined parameters.
The author developed and applied the following program algorithms: • serialization of the foamDataToFluentDict parameters defined via the respective electronic screen. The author proposed to use the SQLite database engine [14] for serialization. It is proposed to create a separate table for the foamDataToFluentDict file to save and recover screen-defined parameters of the mesh conversion; • completeness check of the case internal files. The check of availability of the foamDataToFluentDict dictionary file in the case directory for operation with the foamMeshToFluent utility is provided for; • a mechanism to prepare several versions of the foamDataToFluentDict internal file with parameters defining the mesh conversion properties. It permits to account for several adjustment options at a time for a case.