Processing the overlay of geometry segments in solving hydrophysics problems by the finite difference method

. The article deals with issues related to increasing the efficiency of working with data on the geometry of the computational domain when solving hydrophysics problems using the finite difference method. The model problem is a system of equations of the pollutant distribution, including the oil and its refined products, in the computational domain – Azov Sea. To describe the computational domain, a model of a two-dimensional computational grid is used, which is used in the implementation of numerical calculations. Class diagrams are presented for describing the geometry of the object under study, as well as its constituent segments. In order to improve the performance of calculations, an algorithm for combining geometry segments was developed, in which the original algorithm was divided into separate fragments by introducing a number of conditional structures. As a result of experimental data processing, regression equations were obtained that describe the dependence of the algorithm execution time on the number of joins. The developed algorithm and class library make it possible to work with the description of the geometry of the object under study as a set of parameterized primitives and reduce the time spent on the formation of the description of the computational domain by up to 27%.


Introduction
At present, the assessment of the hydrodynamic impact on bank protection structures and coastal structures installed on the bottom surface of river systems is the most important urgent task.When constructively transforming the morphometry of the riverbed and floodplain, one should take into account the dynamics of the processes of bank formation, and study the formation of the bottom profile in the coastal zone of the reservoir under the influence of currents.To determine the dynamics and trends of phenomena that occur in channel systems and predict possible interference with the ecosystem, it becomes necessary to develop algorithms and programs for numerically solving the problems of matter transfer in channel systems, including channel processes in river sections with complex channel and floodplain morphometry.With their use, an important scientific and practical task of assessing the impact of the planned construction on the flooding of floodplain territories and erosion of the riverbed will be solved.
To predict the state of shallow water bodies, when designing coastal engineering structures, mathematical models are built that take into account the unique features of the studied water body -climatic factors, hydrodynamic regimes and the complex geometry of the computational area.Among the works of Russian scientists devoted to the study and forecast of aquatic ecosystems, one can single out the works of Marchuk G.I. [1], Matishov G.G. [2,3], Sukhinov A.I. [4,5], Tyutyunov Yu.V. [6], Yakusheva E.V. [7], Ilyicheva V.G. and others.Leading foreign research centers and organizations are developing models, software systems and information systems for monitoring and predicting the state of water bodies: Sweden's Meteorological and Hydrological Institute; Center for Water Re-search; National Oceanic and Atmospheric Administration; Center for Ecology and Hydrology [8,9].
Existing software systems that allow modeling hydrodynamic processes (SALMO, CHARISMA, Mars3d, CHTDM, CARDINAL, PHOENICS, Ecointegrator, etc.) do not take into account the spatially inhomogeneous movement of the aquatic environment, do not have the necessary accuracy for modeling the vortex structures of flows, are not conservative, do not take into account the complex shape of the bottom and coast relief, evaporation, river runoff, salinity, temperature and other factors, and also show instability with significant depth differences and changes in the density of the aquatic environment [10][11][12][13].

Material and methods
Let's consider the complete 2D system of equations of the pollutant distribution, including the oil and its refined products, in the computational domain -Azov Seawith the side surface  , the water undisturbed surface 0  in the Cartesian coordinate system for the axes Oy , Ox , directed to the north and east, respectively.The model is based on the researches [3,4,[14][15][16] and has the following form: (x, y, t), where u , v are components of the water flow velocity vector; i  is the decomposition coefficient of i-th impurity; f is a chemical and biological source (the runoff); i  are diffusion coefficients in the horizontal direction; i S is the concentration of i-th impurity,
The model includes pollutants whose concentration in the Azov Sea, according to the analysis of scientific publications and environmental databases, exceeds the maximum permissible concentration (MPC) [10].This model takes into account the water flow movement; microturbulent diffusion; interaction of pollutants and plankton; biogenic, temperature and oxygen regimes; the influence of salinity.
Let's define the initial conditions: 0 (x, y,0) S (x, y), 1,6.The computational domain G it is a closed area bounded by the undisturbed water surface 0  and the coastline  for Let n U is the component of the water flow velocity vector, normal to the boundary  , n is the external normal vector to the  .Then the boundary conditions for the model (1) will have the form: We took into account the water exchange with the Black Sea, the flow of the Don River, the complex shape of the coastline, and the bottom relief at setting the boundary conditions.
Let's take the calculation area G with the following parameters: x l is the characteristic dimension along the axis Ox , y l -along the axis Oy .Let us compare the specified area with a uniform computational grid of the following form: where x h , y h are steps of the computational grid in the corresponding spatial directions; x n , y n are number of nodes of the computational grid in the corresponding spatial directions.
Let us represent the set of nodes of the computational grid in the form , , where , i j q is the grid node.

Calculation
Modeling of hydrophysical processes is carried out by the finite difference method [13][14][15][16][17], while software implementation of the description of the geometric shape of the object under study and boundary conditions is required.In the case of studying the process of spreading pollutants over the water surface, it is necessary to take into account the geometry of objects of complex shape, which include coastal engineering structures that are part of the coastline.The solution of this problem can cause significant difficulties.The generally accepted approach to describing the geometry of an object of complex shape under study is the approach in which the geometric parameters of the object are specified directly by using one of the geometry description formats: STL, COLLADA, IGES, STEP, VRML/X3D.The listed formats are convenient for transferring data between applications, however, when modeling by the finite difference method, they require complex transformations.
Solving optimization engineering problems requires not only a more convenient way to describe the geometry, but also the possibility of simply varying various parameters, which requires detailed work with the original geometry model and building on its basis a whole set of geometries with small changes.
The approach proposed in the article and the algorithm implemented on its basis make it possible to work with the geometry of the object under study as with a set of two-dimensional geometric primitives that can be superimposed on each other.The absence of dependencies of the geometric dimensions of the primitives from each other allows you to quickly and accurately describe the object and proceed directly to modeling.A distinctive feature of the proposed approach is that geometric primitives can be of two types: a continuous medium and a cutout.In the developed class library, they are heirs of the abstract class 2 Geometry DPrimitive (Fig. 1), containing data on the coordinates of the offset of primitives relative to the geometry placement point ( _ 0 dS ), the type of primitives ( primitiveType ) and the "cut" property flag ( _ isCavity ).Behavior details are described in derived classes.In particular, the class 2 Geometry DPrimitiveRectangle (Fig. 1) models a rectangle.When applying the computational grid, the problem arises of correctly determining the characteristics of each node, i.e. it is necessary to determine whether the node is internal, boundary or fictitious.In the general case, the algorithm for solving this problem has asymptotic complexity 2 ( ) O n .The algorithm proposed by us allows us to reduce it by one order due to the transition to the description of the geometric segments of the body under study, located on the secant straight lines of the computational grid (geometry segments).
We represent the geometry segment as a tuple x - start and end coordinates of geometry segment, _ gridSegmentType -geometry segment type (0boundary segment, 1internal segment), _ isFillBottom -filling of the space under the segment (0empty from below, 1filled from below), _ isCavity -flag of belonging of a segment to a geometric primitive that is a cutout (0continuous medium, 1cutout).To work with a segment in an object-oriented programming style, a universal class has been developed GeometryPrimitiveSegment T üþ , where T -the data type of the start and end coordinates of the segment.For the convenience of working with the geometry segment type, an enumeration has been created GridSegmentTypeEnum from two elements: Boundary -boundary segment and Internal -internal segment (Fig. 2).

Fig. 2. Geometry segment class diagram.
Let's introduce the notation: 11 k -coordinate of the beginning of the first segment, 12 k - coordinate of the end of the first segment, 21 k -coordinate of the beginning of the second segment, 22 k -the coordinate of the end of the second segment.Let's introduce boolean variables:  J k k =þ; K -type of the first segment; L -type of the second segment; M -filling of space under the first segment; N -filling of the space under the second segment; O - the second segment is a cutout.
The introduced logical variables allow using the algebra of logic to describe all possible combinations of overlapping geometry segments: 1) end-to-end, the second segment is located to the right of the first: H ; 2) end-to-end, the second segment is located to the left of the first: G ; 3) full overlay: B E ù ; 4) second segment inside the first: A F ù 11) overlap on the right: A D I ùù; 12) there is no intersection, the second segment is located to the right of the first: I ; 13) there is no intersection, the second segment is located to the left of the first: J .
Along with the option of overlapping segments, the model must take into account all possible combinations of segment types and infills.By filling we mean the presence of a layer of material on the previous cut (filling from below) or on the next one (filling from above).The presence of filling at the top and bottom indicates that the segment is internal.This implies the requirement to check the correctness of the data: the inner layer cannot be filled from below.
Four combinations of geometry segment types are possible: boundaryboundary Similarly, it is required to take into account four options for the combination of fillings of the merged geometry segments: top It is assumed that the first segment must necessarily be an object, therefore, it is only necessary to check the second object for the set "Cut" property, i.e. there are two optionsno ( ) O , yes ( ) O .All possible combinations of groups of segments were found in the basis of the original calculation algorithm, the structural linear function.In order to calculate the results of the calculations of the original algorithm, they were divided into separate fragments by introducing conditional structures.
Here is a fragment of an improved algorithm for combining geometry segments: 3) Checking the correctness of the data.If the result of evaluating the expression L N K M ù ú ù is true, so there is an error in the input and an exception is thrown.4) Search for an overlay option in accordance with the logical expression given in Table 1. 5) If the overlay option is not found, then there is an error in the input data and an exception is thrown.Further actions are performed for the found overlay option.For example, overlay option No. 1 is described.For other options, the actions are similar and differ only in combinations of logical conditions.6) If the first segment is boundary ( ) K , then go to step 7, otherwise go to step 14.

Results and discussion
Solving the problem of the distribution of pollutants over the water surface requires a detailed description of the coastline geometry.When modeling the process of spreading pollutants, it is necessary to take into account not only the natural geometry of the coastline of a reservoir, but also the presence of artificial structures and buildings.
A team of authors has developed an algorithm for describing artificial structures as a set of geometric primitives, the combination of which, together with a natural coastline, makes it possible to describe the complex geometry of the coastline for the problem described above.
Comparison of the performance of the conventional and proposed algorithms was performed on a personal computer with an Intel Core i5-6600 3.3 GHz processor and 32 GB of DDR4 RAM.The initial data were randomly generated objects of geometry segments, which were then combined.The comparison results are shown in As a result of experimental data processing, regression equations were obtained that describe the dependence of the algorithm execution time on the number of joins: The proposed algorithm allows increasing performance by 14% to 27% and has a parallelization resource, which allows it to be used in building software systems for solving problems of mathematical physics and computer-aided design systems.?@>екти@>ва=ия.

Conclusions
When modeling the process of spreading pollutants over the water surface, the computational domain was described in the form of a two-dimensional computational grid.The description of the geometry of the coastline takes into account the geometric characteristics of artificial structures.
The article presents class diagrams for describing the geometry of the object under study, as well as its constituent segments.In order to improve the performance of calculations, an algorithm for combining geometry segments was developed, in which the original algorithm was divided into separate fragments by introducing a number of conditional structures.
The use of the modified algorithm makes it possible to reduce the calculation time when combining geometry segments by up to 27% and has a parallelization resource, which allows it to be used in the construction of software systems for solving problems of mathematical physics and computer-aided design systems.

Fig. 1 .
Fig. 1.Class diagram for describing the geometry of the object under study.

; 5 )
the second segment overlaps the first: C D ù ; 6) the left sides of both segments are aligned, the length of the second segment is less than the length of the first: B F ù ; 7) the left sides of both segments are aligned, the length of the second segment is greater than the length of the first: B D ù ; 8) alignment on the right, the length of the second segment is less than the length of the first: A E ù ; 9) alignment on the right, the length of the second segment is greater than the length of the first: C E ù ; 10) overlap on the left: C F ù ; the improved algorithm.Smaller values of the coefficients of the regression equation for the improved algorithm indicate its greater computational efficiency.

Table 1 Table 1 .
Performance comparison results of the original and improved algorithms for merging geometry segments.