Two-dimensional mesh generator in generalized coordinates implemented in Python

Through mathematical models, it is possible to turn a problem of the physical domain into the computational domain. In this context, the paper presents a two-dimensional mesh generator in generalized coordinates, which uses the Parametric Linear Spline method and partial differential equations. The generator is automated and able to treat real complex domains. The code was implemented in Python, applying the Numpy and Matplotlib libraries to matrix manipulations and graphical plots, respectively. Applications are made for monoblock meshes (two-dimensional shape of a bottle) and multi-block meshes (geometry of Igapó I lake, Londrina, Paraná, Brazil).

READ FULL TEXT VIEW PDF
POST COMMENT

Comments

There are no comments yet.

Authors

page 1

page 2

page 3

page 4

09/09/2021

Geometrical discretisations for unfitted finite elements on explicit boundary representations

Unfitted (also known as embedded or immersed) finite element approximati...
06/26/2014

3D Texture Coordinates on Polygon Mesh Sequences

A method for creating 3D texture coordinates for a sequence of polygon m...
05/18/2020

Fast variable density node generation on parametric surfaces with application to mesh-free methods

Domain discretization is considered a dominant part of solution procedur...
02/23/2021

PEMesh: a Graphical Framework for the Analysis of the InterplayBetween Geometry and PEM Solvers

Partial differential equations can be solved on general polygonal and po...
08/24/2021

Full waveform inversion using triangular waveform adapted meshes

In this article, continuous Galerkin finite elements are applied to perf...
12/10/2021

The 3D Motorcycle Complex for Structured Volume Decomposition

The so-called motorcycle graph has been employed in recent years for var...
03/13/2021

Optimal Dual Schemes for Adaptive Grid Based Hexmeshing

Hexahedral meshes are an ubiquitous domain for the numerical resolution ...
This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

The modeling and simulation of natural phenomena using differential equations is an important tool for science. However, to represent physical structures, that is, the domain to be studied in a computational environment, the use of simpler data organization structures, such as matrices and vectors, tend not to be able to realistically represent the object of study. Thus, different techniques have been used for the representation of domains, such as structured and unstructured meshes, generalized or hybrid meshes, among other techniques, that have advantages and disadvantages in terms of flexibility and ability to represent objects under study (THOMPSON et al., 1977; THOMPSON et al., 1985; THOMPSONet al., 1998; MALISKA, 2004; CIRILO et al. 2006; KOOMULLIL et al, 2008; LAIPING et al., 2013; SAITA et al., 2017; BELINELLI et al, 2020).

In this work, we looked for a simplified way to build a structured mesh for a complex domain, which was possible through a change in the coordinate system. This process allowed to convert a complex domain into a set of easily manipulated data (MALISKA, 2004). Mathematically, any geometry, described in Cartesian system, can be transformed into a generalized system, allowing better adaptation in computational modeling (CIRILO et al. 2006; MALISKA, 2004; ROMEIRO et al., 2011; PARDO et al., 2012; SAITA et al., 2017; ROMEIRO et al., 2017; CIRILO et al., 2018).

In this context, this work describes the creation and implementation of a two-dimensional mesh generator using transformation metrics in generalized coordinates. This procedure generates a domain mapped for mathematical manipulations, which describes any physical object, from a finite set of points. The mesh generator is encoded in Python and uses the libraries numpy and matplotlib for manipulations and operations on matrices and graphical plots, respectively (CAI et al., 2005; SCIPY-NUMPY, 2020; SCIPY-MATPLOTLIB,2020).

The work is structured as shown below. Initially, transformation metrics are described in generalized coordinate theory. Then the mesh generator is developed. Finally, some examples of meshes obtained by the generator are presented.

2 Generalized Coordinate

For a computational methodology to be applied to a physical problem, it is necessary to discretize the domain of the problem, that is, to build a computational mesh that can represent the studied geometry and, thus, obtain the values of interest.

The discretization of the physical domain can be carried out according to a structured or unstructured mesh. Unstructured meshes are more adaptable than structured meshes, especially in problems with complex geometries (MALISKA, 2004; FORTUNA, 2012). However, the major disadvantage of unstructured meshes is the difficulty of ordering the elements, which implies a variation in the size of the diagonals of the coefficient matrix and the additional cost of using memory, making it difficult to apply numerical methods to obtain the solution of linear systems. Therefore, the domain discretization in this work will be performed using structured meshes.

As for the coordinate system, in general, the problem domain is discretized according to the Cartesian coordinate system because it is simpler. However, for problems with complex geometry, it is convenient to adopt another coordinate system, due to the fact that the Cartesian coordinate system leads to a poor adaptation of the border, since the physical domain does not always coincide with the domain of the Cartesian mesh. To solve the problem, the generalized coordinate system will be used. In generalized coordinates, the computational mesh coincides with the geometry of the problem and computational treatment becomes more appropriate. Other reasons that justify the use of generalized coordinates in the discretization of computational meshes are the simplicity in programming computational codes to solve complex problems and the ease in developing generic methodologies.

In the following, some important concepts about generalized coordinate theory will be presented

2.1 Transformation Metrics

The Cartesian system is called the physical domain and the generalized system is called the transformed domain or computational domain.

The transformation from a non-trivial geometry described in a Cartesian coordinate system to a generalized coordinate system involves transformation metrics, or mathematical relations, that can accurately describe the transformed data.

The mapping of irregular or regular geometries written in Cartesian coordinates , Fig. 1a, is performed numerically for regular geometries written in generalized coordinate system , Fig. 1b.

(a) Cartesian coordinate
(b) Generalized coordinate
Figura 1: Coordinate systems

Since the transformed domain is regular, for convenience, unitary normalization of elementary volumes is assumed, that is, . In this way, even if in the physical plane the coordinated lines assume arbitrary spacing, in the computational plane the dimensions are fixed to the unit.

To obtain the system, the following generating equations are used

(1)
(2)

The transformation metrics, based on differentials of the Eqs. (1) and (2), are

(3)
(4)

or, in the matrix form

(5)

which can also be written as

(6)

where , , , and denoting partial derivatives, and represent, respectively, the differentials in the transformed and physical domain, while is the transformation matrix between the domains.

Starting from the assumption that it is possible to find a representation in a Cartesian coordinate system for a model described in generalized coordinates, then we admit the existence of the inverse of the equations Eqs. (1) and (2), so

(7)
(8)

and from differentials of Eqs. (7) and (8) we have

(9)

which can also be written as

(10)

where , , , and denoting partial derivatives and is the transformation matrix between the physical and transformed domains.

Replacing Eq. (6) in Eq. (10), we get , so that , or equivalent . Thus, the matrix becomes

(11)

where is called Jacobian of transformation (MALISKA, 2004).

2.2 Two-dimensional Mesh Generation

In this work, we opted for the use of elliptical partial differential equations (EPDE) as a method of generating two-dimensional meshes, since their solutions do not generate null Jacobian, and the lines or never intersect (THOMPSON, 1985; MALISKA, 2004). Thus, the governing equations for the generation of two-dimensional meshes in a domain, for example the domain illustrated in Fig. 2a, are

(12)
(13)

whose boundary conditions of the type Dirichlet are expressed by in (left border), in (right border); in (lower border) and in (upper border). In particular, in Fig. 2a were used and , where is the number of lines from and is the number of lines from .

(a) Predefined points
(b) Mesh in generalized coordinates
Figura 2: Example of mesh in generalized coordinates

Solving the equations (12) and (13), in relation to the coordinates, using the transformation metrics of the system, then the coordinated lines can be generated in the directions and , inside the computational mesh, Fig. 2b, as in any other geometry, through the equations

(14)
(15)

where and are the Cartesian coordinates of the physical domain, and are the generalized coordinates of the computational domain, and are the source functions, is the Jacobian of transformation, and

(16)
(17)
(18)

The numerical solution of elliptical EDPs (14) and (15), subject to initial and boundary conditions, provide the lines and , which generate the computational mesh (DE BORTOLI, 2000, MALISKA, 2004; CIRILO et al., 2006; FORTUNA, 2012). For convenience, Eqs. (14) and (15) can be written using a generic variable as

(19)

To approximate the derivatives in Eq. (19), the finite difference method is used. The mesh nodes are labeled by the cardinal points (center), (east), (west), (north), (south), (northwest ), (southwest), (southeast) and (northeast), as in Fig. 3.

Source: The Authors

Figura 3: Index labeling

Approximating the derivative terms of Eq. ( Ref eq27) by means of central differences, around , we obtain

(20)

and regrouping the terms

(21)

Thus, the numerical solution of the two-dimensional mesh generation equations, Eqs. (14) and (15), written according to the generic variable, Eq. (21), is given by

(22)

where

(23)

with derivatives present in approximated by central differences.

Next, the mesh generator in generalized coordinates is presented.

3 Mesh Generator in Generalized Coordinate

For the creation of an automated procedure for mapping a geometry in Cartesian coordinates, through a generalized coordinate system, we chose to use the programming language Python.

The reason for this choice is due to the fact that Python is a general, free, open, and multiplatform language, which can allow the creation of extensions of the developed application, such as, for example, a graphical interface module, among others.

Regarding performance, it is necessary to use extra libraries, specific to numerical computing applications, to achieve satisfactory results at run time. Because it is a scripting language, that is, interpreted, the performance of an application written in Python tends to be inferior when compared to a compiled language, as is the case of the Fortran language. In Python, the tools available for matrix manipulation and linear algebra are limited and not optimized for the type of application that was intended to be developed. However, because the adopted language is modular, it is possible to use routines and libraries in compiled languages, in order to optimize more complex operations, such as those used for domain transformations (CAI et al., 2005).

For the creation of the mesh generator, the following libraries were used:

  • Numpy - library dedicated to matrix and algebraic operations in general (SCIPY-NUMPY, 2020);

  • Matplotlib - library used to generate graphs and manipulate data in graphical form (SCIPY-MATPLOTLIB, 2020).

The additional modules employed are also free for use.

3.1 Description of the Algorithm Developed

For the definition and creation of a geometry mapped in generalized coordinates, it starts from a initial set of points that describe the border, that is, the physical contour. In this work, the Parametric Linear Spline method was chosen to interpolate the set of border points under study. Parametric Linear Spline equations (BURDEN et al., 2015) are

(24)
(25)

, where interpolating spline curve and is the interpolated variable.

Having obtained the interpolating lines of the border, Eqs. (24) and (25), the number of partitions desired for each border must be defined.

Then, points of the Splines curves are selected, which define the new border of the approximate geometry. To do this, an approach is used to position the points by weighted average of the components of the border, ie

(26)
(27)

where , , , , e .

The values of , , , and indicate the weights on the left/right borders in , top/bottom in , left/right in and top/bottom in , respectively. The percentage weights in Eqs. (26) and (27) can better adjust the distribution of points in the domain, avoiding concentrations of points. In this way, the arrangement of the internal points is influenced by the edges.

Finally, on the set of ordered pairs, the resolution of the equation (

22) is applied.

In summary, the implemented algorithm can be illustrated in this way:

Step 1. Reading the input data: Read the number of partitions from the physical and transformed planes, the weights for calculating the weighted average and the border points.

Step 2. Border interpolation: Define the border using the Parametric Linear Spline method and the border points previously read.

Step 3. Calculate the points of the Spline lines, using the weighted average formulas, and define the new border points.

Step 4. Application of transformation metrics: On the generated data, apply the transformation metrics to obtain the interior mesh curves.

The next two sections are intended to exemplify and test the algorithm. In the first applications, monoblock meshes are built (3 applications). Following a multiblock mesh is obtained. The multiblock technique consists of dividing the physical domain into parts and, on each of the parts, applying the generation of meshes in generalized coordinates. Such a procedure allows to better capture the complexity of the geometry compared to the strategy employed on a single block (CIRILO, 2006; PARDO et al., 2012, SAITA et al., 2017).

3.2 Monoblock Mesh Generation

As a first application of the mesh generation algorithm, the set of input data presented in Table 1 was used. The weighted values for , 1 and 3 are omitted, since they are known for complementarity, that is, e .

Number of partitions () Number of partitions () Weighted average
Input data Refinement 1 Refinement 2 Weights ()
Tabela 1: Input data of a Rectangular Geometry with Cutout

Given the set of predefined points, Fig. 4a, the number of partitions and the weights at the borders, Table 1, then the border geometry is obtained by Parametric Spline Linear interpolation. In sequence, the algorithm calculates the new border points, using the given refinement. In this way, the algorithm starts to solve the transformation metrics, finally generating the mesh in generalized coordinates. Figs. 4b and 4c present the meshes in generalized coordinates, according to the refinements described in Table 1.

(a) Predefined points
(b) Refinement 1
(c) Refinement 2
Figura 4: Rectangular Geometry with Cutout

As a second application, a mesh in a doubly-connected domain was generated. The set of input data is shown in Table 2.

Number of partitions () Number of partitions () Weighted average
Input data Refinement 1 Refinement 2 Weights ()
Tabela 2: Input data of a Doubly-Connected Geometry

In this application, the left/right border corresponds to the line segment that joins the two circles, while the upper/lower border corresponds to the two circles, as shown in Fig 5a. From the set of points given in Fig. 5a and the input data in Table 2, the algorithm constructs the meshes shown in Figs. 5b and 5c, according to the refinements described in Table 2.

(a) Predefined points
(b) Refinement 1
(c) Refinement 2
Figura 5: Doubly-Connected Geometry

The latest generation of monoblock mesh is shaped like a bottle, as illustrated in Fig. 6. The set of input data is explained in Table 3.

Number of partitions () Number of partitions () Weighted average
Input data Refinement 1 Refinement 2 Weights ()
Tabela 3: Input data of a Bottle Geometry

Using the set of predefined points, Fig. 6a, and the input data in Table 3, the meshes in generalized coordinates are generated, as shown in Fig. 6b and Fig. 6c, according to the refinements described in Table 3.

(a) Predefined points
(b) Refinement 1
(c) Refinement 2
Figura 6: Bottle Geometry

automated mesh generator In the applications presented for monoblock meshes, the automated mesh generator precisely built the geometry in the physical domain.

3.3 Multiblock Mesh Generation

In order to show a more complex application, points from the contour of Lake Igapó I, located in Londrina, Paraná, Brazil, were collected. The points were obtained from satellite images offered by the Google Earth software (GOOGLE, 2020). The generated mesh has the same scale as the physical domain.

Unlike previous applications, in addition to generating the monoblock meshes (now called monobloc sub-meshes), in this application the sub-meshes must be connected. The multiblock mesh algorithm uses the monoblock mesh generator as a subroutine of the multiblock algorithm.

In summary, the multiblock algorithm can be illustrated in this way:

Step 1. Loop condition: If there is a monoblock input file being passed as an argument, perform step 2. Otherwise, perform step 4.

Step 2. Monoblock mesh generation: Use the data present in the input file to generate the monoblock mesh.

Step 3. Plot the monoblock mesh: Use the results of the monoblock mesh generator algorithm to plot the monoblock mesh, and return to step 1.

Step 4. Plot the multiblock mesh: Show all monoblock meshes generated in a single multiblock mesh.

For the geometry of Lago Igapo, it is considered that it consists of three blocks, Lake Igapó I (main block) and its two tributaries (two other blocks). The set of predefined points are given in Fig. 7a. The input data are presented in Table 4. As for the weighted average, the percentage weights ( e ), in and , were all chosen as .

Monoblock Number of partitions () Number of partitions ()
Name Input data Refinement 1 Refinement 2
Principal
Tributary 1
Tributary 2
Tabela 4: Input data of Igapó I Lake

After executing the multiblock mesh algorithm, the meshes were obtained in generalized coordinates as shown in Figs. 7b and 7c, according to the refinements of Table 4.

(a) Predefined points
(b) Refinement 1
(c) Refinement 2
Figura 7: Igapó I Lake Geometry

Again, the automated mesh generator accurately represented the physical domain of Igapó I lake, located in Londrina, Paraná, Brazil.

4 Final Considerations

In this work, using the generalized coordinate method, a mesh generator in Python was created and implemented. This automated mesh generator allowed the reproduction of complex geometries with several mesh refinements, as shown by the applications presented.

Specifically, as original contributions to this work, we highlight two aspects:

1- Parameterized Linear Spline. The use of the Parameterized Linear Spline method to obtain points at the border of the physical domain, given predefined points, allows the construction of the internal mesh in generalized coordinate, with the desired refinement, in a simple and fast way.

2- Python language. The Python programming language and the libraries used make it possible to optimize the algorithm, to facilitate the visualization of the meshes, and the portability of the application in different software architectures, such as Linux and Windows.

Referências

BELINELLI, E.O.; NATTI, P.L.; ROMEIRO, N.M.L.; CIRILO, E.R.; FANTIN, L.H.; OLIVEIRA, K.B.; CANTERI, M.G.; NATTI, E.R.T. Geração de malha para descrever a dispersão da ferrugem da soja no Paraná. In: Júlio Cesar Ribeiro. (Org.). Ciências Exatas e da Terra: Conhecimentos Estratégicos para o Desenvolvimento do País. 1ed.: Atena Editora, 2020, v. , p. 225-239.

BURDEN, R.L., FAIRES, J.D., BURDEN, A.M. Numerical Analysis. Boston: Cengage Learning, 2015.

CAI, X., LANGTANGEN, H. P., MOE, H. On the performance of the Python programming language for serial and parallel scientific computations. Scientific Programming, vol. 13, n. 1, pp. 31-56, 2005.

CIRILO, E.R.; DE BORTOLI, A.L. Cubic splines for trachea and bronchial tubes grid generation. Semina: Exact and Technological Sciences, v. 27, p.147-155, 2006.

CIRILO, E. R. ; BARBA, A. N. D. ; NATTI, P. L. ; ROMEIRO, N. M. L. . A numerical model based on the curvilinear coordinate system for the MAC method simplified. SEMINA. CIÊNCIAS EXATAS E TECNOLÓGICAS (ONLINE), v. 39, p. 87, 2018.

DE BORTOLI, A. L. Introdução à dinâmica de fluidos computacional. Porto Alegre: Editora da UFRG, 2000.

FORTUNA, A.O. Computational techniques for fluid dynamics: Basic concepts and applications. São Paulo: EDUSP, 2012.

GOOGLE. Google Earth. Disponível em: <https://www.google.com/earth/>. Acessed in oct. 2020.

KOOMULLIL, R.; SONI B.; SINGH R. A comprehensive generalized mesh system for CFD applications. Mathematics and Computers in Simulation, vol. 78, pp. 605-617, 2008.

LAIPING, Z.; ZHONG, Z.; XINGHUA, C., XITHAMES, H. A 3D hybrid grid generation technique and a multigrid/parallel algorithm based on anisotropic agglomeration approach. Chinese Journal of Aeronautics, vol. 26, n.1, pp. 47-62, 2013.

MALISKA, C. R. Transferência de calor e mecânica dos fluidos computacional. São Paulo: LTC, 2004.

PARDO, S.R.; NATTI, P.L.; ROMEIRO, N.M.L.; CIRILO, E.R. A transport modeling of the carbon-nitrogen cycle at Igapó I Lake-Londrina, Paraná State, Brazil. Acta Scientiarum. Technology, v. 34, p. 217-226, 2012.

ROMEIRO, N.L.M.; CASTRO, R.G.S.; CIRILO, E.R.; NATTI, P.L. Local calibration of coliforms parameters of water quality problem at Igapó I Lake - Londrina, Paraná, Brazil. Ecological Modelling, v. 222, p. 1888-1896, 2011.

ROMEIRO, N.L.M.; MANGILI, F.B.; COSTANZI, R.N.; CIRILO, E.R.; NATTI, P.L. Numerical simulation of BOD5 dynamics in Igapó I lake, Londrina, Paraná, Brazil: Experimental measurement and mathematical modeling. Semina: Exact and Technological Sciences, v. 38, p. 50-58, 2017.

SAITA, T.M.; NATTI, P.L.; CIRILO, E.R.; ROMEIRO, N.L.M.; CANDEZANO, M.A.C.; ACUNA, R.A.B.; MORENO, L.C.G. Simulação numérica da dinâmica de coliformes fecais no lago Luruaco, Colômbia. Trends in Applied and Computational Mathematics, v. 18, p. 435-447, 2017.

SCIPY-NUMPY. In <http://www.numpy.org/>. Acessed in oct. 2020.

SCIPY-MATPLOTLIB. In <http://matplotlib.org/>. Acessed in oct. 2020.

THOMPSON, J. F.; THAMES, F. C.; MASTIN, C. W. TOMCAT - A Code for Numerical Generation of Boundary Fitted Curvilinear Coordinate Systems on Fields Containing Any Number of Arbitrary Two-Dimensional Bodies. Journal of Computational Physics, vol. 24, pp. 274-302, 1977.

THOMPSON, J. F.; WARSI, Z. U. A.; MASTIN, C. W. Numerical grid generation: foundations and applications. New York: Elsevier Science Publishing, 1985.

THOMPSON, J.F.; SONI, B.K.; WEATHERILL, N.P. Handbook of Grid Generation. Florida: CRC Press, 1998.