Full text
Universidade do Minho Escola de Engenharia Departamento de Informática Bruna Vieira Cruz Simulating Buoyancy July 2023
Universidade do Minho Escola de Engenharia Departamento de Informática Bruna Vieira Cruz Simulating Buoyancy Master dissertation Integrated Master’s in Informatics Engineering Dissertation supervised by António José Borba Ramires Fernandes July 2023
COPYRIGHT AND TERMS OF USE FOR THIRD PARTY WORK This dissertation reports on academic work that can be used by third parties as long as the internationally accepted standards and good practices are respected concerning copyright and related rights. This work can thereafter be used under the terms established in the license below. Readers needing authorization conditions not provided for in the indicated licensing should contact the author through the RepositóriUM of the University of Minho. LICENSE GRANTED TO USERS OF THIS WORK: CC BY https://creativecommons.org/licenses/by/4.0/
ACKNOWLEDGEMENTS To begin with, I would like to thank my supervisor António José Borba Ramires Fernandes for proposing the theme of this dissertation and guiding me throughout it. I would like to thank the University of Minho, more specifically the Department of Informatics for providing the conditions and the professors that allowed me to take this course and the Department of Mathematics for providing me with the necessary conditions to write the dissertation. Finally, I would like to thank my boyfriend and my friends for all the emotional support they gave me throughout this dissertation and for always being there when I needed it most. i
STATEMENT OF INTEGRITY I hereby declare having conducted this academic work with integrity. I confirm that I have not used plagiarism or any form of undue use of information or falsification of results along the process leading to its elaboration. I further declare that I have fully acknowledged the Code of Ethical Conduct of the University of Minho. ii
ABSTRACT The simulation of object buoyancy is a very interesting topic that involves a lot of research in the area of fluid dynamics. To better understand how the simulation of floating objects is done, it is necessary to distill the articles found to make a simple simulation that still covers the main characteristics of the simulation. In this sense, the research required to develop the algorithm is focused on the main dynamic characteristics of the object’s movement in the water, that is, the main forces that are applied. Although this type of simulation is widely used, as in video games, articles that address this topic in a simple way that can be easily adapted in a simulation are quite scarce in terms of the physics involved or focus on how to start and don’t develop much further. In this sense, there are few techniques or methods of implementation, most of which are focused on minimizing the costs of these same techniques and still providing a simulation as realistic as possible. Faced with this problem, the objective is to have a robust algorithm and be as realistic as possible, being able to demonstrate a good representation of the buoyancy of objects according to their mass and the forces that are exerted. To accomplish this objective, an algorithm was adapted from Kerner (2015) and Kerner (2016). Each added force contributes to a better representation of reality making the algorithm more realistic. With this accomplished, it is implemented in shaders and tested with multiple objects simultaneously for performance analysis, being possible to observe the capacity of the algorithm. The simulation made in this dissertation was tested in terms of performance and time spent on GPU, by the number of boats and by the number of triangles in the mesh of the boat. K E Y W O R D S Buoyancy, Performance, Scalability, Torque iii
RESUMO A simulação de flutuação de objetos é um tema bastante interessante que envolve imensa pesquisa na área de dinâmica de fluidos. De forma a compreender melhor como é feita a simulação de objetos a flutuar é necessário destilar os artigos encontrados para fazer uma simulação simples que ainda assim abranja as caracteristicas principais da simulação. Neste sentido, a pesquisa necessária para a elaboração do algoritmo será focada nas principais características dinâmicas do movimento do objeto na água, ou seja, nas principais forças que são aplicadas. Apesar deste tipo de simulação ser muito utilizado como, por exemplo, em videojogos, os artigos que abordam este tema de forma simples e que podem ser facilmente adaptados numa simulação são bastante escassos em termos de física envolvida ou simplesmente se focam em como começar e não são muito desenvolvidos. Neste sentido, existem poucas técnicas ou métodos de implementação, sendo a maior parte focada em minimizar os custos dessas mesmas técnicas e mesmo assim proporcionar uma simulação o mais realista possível. Considerando este problema, o objetivo será ter um algoritmo focado na simplicidade, mas que seja o mais robusto e realista possível, podendo demonstrar uma boa representação da flutuabilidade de objetos consoante a sua massa e as forças que são exercidas. Para cumprir tal objetivo foi adaptado um algoritmo a partir de Kerner (2015)eKerner (2016). Cada força adicionada contribui para uma melhor representação da realidade tornando o algoritmo mais realista. Com isto realizado, este será implementando em shaders e testado com vários objetos em simultâneo para uma análise de desempenho, sendo assim possível observar a capacidade do algoritmo implementado. A simulação feita nesta dissertação foi testada em termos de desempenho e tempo gasto em GPU, tendo em atenção o número de barcos e o número de triângulos na mesh do barco. PA L AV R A S -C H AV E Flutuabilidade, Performance, Escalabilidade, Torque iv
CONTENTS I INTRODUCTORY MATERIAL 1INTRODUCTION 1 1.1 Context 1 1.2 Objectives 2 1.3 Methodology 2 1.4 Overview 3 2S TAT E O F T H E A R T 4 2.1 Buoyancy Concept 5 2.2 Determining the submerged surface 6 2.3 Hydrostatic Forces 9 2.3.1 Buoyancy 10 2.3.2 Torque 11 2.3.2.1 Computing the triangle center 11 2.3.2.2 Computing the application point 12 2.4 Hydrodynamic Forces 15 2.4.1 Damping Forces 16 2.4.2 Drag Equation 16 2.4.3 Triangle’s velocity for Hydrodynamic forces 17 2.4.4 Viscous Water Resistance 19 2.4.5 Pressure Drag Forces 21 2.4.6 Slamming Forces 23 2.5 Challenges 25 II CORE OF THE DISSERTATION 3IMPLEMENTATION 28 3.1 General Algorithm 29 3.2 Cut Algorithm 31 3.3 Forces Calculation 37 3.3.1 Hydrostatic Forces Calculation 38 3.3.2 Hydrodynamic Forces Calculation 40 v
CONTENTS vi 3.4 Forces Sum 43 3.5 Forces Application 44 4TESTS AND RESULTS 49 4.1 Tests 49 4.2 Visual Results 53 5CONCLUSIONS AND FUTURE WORK 58 5.1 Conclusions 58 5.2 Future work 59 III APPENDICES A S U P P O R T W O R K 63 B LISTINGS 64
Part I INTRODUCTORY MATERIAL
1 INTRODUCTION The simulation of floating objects is mainly based on the interaction of the boat with the water and vice versa. A boat is a watercraft of a large range of types and sizes. The type and size vary with their intended purpose. But the question is how they float. The ability of an object to float depends on the gravitational force and the buoyancy force. If the gravitational force is less than the buoyancy force then the object floats, otherwise sinks. A boat floats because the displaced water weighs more than the boat’s weight. Buoyancy is an upward force exerted by a fluid that opposes the weight of a submerged object. This force, as the Archimedes principle (Ray and Rodriguez,2018) explains, is equivalent to the weight of the displaced fluid. In simulations, to calculate all the forces that act in the boat we have to determine the submerged surface and divide all the forces into two groups, the hydrostatic forces, and the hydrodynamic forces. Hydrostatic forces are those exerted by the water on the object, whereas hydrodynamic forces are the dynamic forces caused by the movement of the object in relation to water. The main motivation was the development of a model which captures the major dynamic traits of boats in the water, but avoids the complexity and expensive fluid dynamics computation, focusing on obtaining a better performance per boat and constituting a model robust enough to adapt to a large number of boats and different types of water. 1.1 CONTEXT The simulation of floating things is widely used in video games. Video games have unique constraints when it comes to simulating vehicles, making it necessary and interesting to write about the subject. Often, the dynamics used to simulate boats are not fully understood. The models or theories are too complex or require very expensive simulation methods that are very difficult to control for their application in video games and have a complex adaptation to the needs of both programmers and players. The solution used for the simulation of object buoyancy, based on Kerner (2015) and Kerner (2016), is focused on performing calculations in a heuristic way with several simplifications along the algorithm in order to avoid complex and expensive calculations in terms of the fluid dynamics involved. In this sense, the main forces that act on the object are calculated in order to provide a simplified model but to still capture the main dynamic characteristics of the object in the water. 1
1.2. Objectives 2 When an object is submerged in a fluid, the fluid exerts a force on the surface of the object due to its pressure. In this sense, the force can increase with increasing pressure and/or with increasing depth. The increase in force with depth is very relevant for buoyancy because the buoyancy force is related to an imbalance in the vertical component of hydrostatic forces on the surface of the object. 1.2 OBJECTIVES The main aim of this dissertation is to implement an algorithm in order to simplify the simulation of a maximum number of boats floating at the same time in the most realistic way possible, depending on the available resources. There is also the aim of monitoring the performance of the algorithm and understanding what can influence the intended realism and what makes the algorithm maintain or not the performance when simulating several boats at the same time. In order to achieve the aim mentioned, the article cited on Lesek (2016) in which 1000 boats are put to float was consulted. This article concluded it is tough to keep up the performance of an algorithm that puts so many boats to float because the shader receives more data and needs more CPU and GPU resources. Despite that, the algorithm must be robust in dealing with adverse atmospheric conditions, as waves with different amplitudes and frequencies, and maintain performance. The goal is to implement the simulation in the GPU level in Shaders. This solution was analyzed in terms of performance and time spent on the GPU. 1.3 METHODOLOGY Since articles referring to the realistic simulation of floating objects are scarce, this dissertation’s contribution focuses on distilling the articles found (Ray and Rodriguez,2018;Bourg and Bywalec,2013;Batchelor,2000; Todd,1957;Williams,2006;Kerner,2015,2016) and showing only what is necessary to get objects to float in the simplest and most realistic way possible. Furthermore, this dissertation presents a GPU implementation of the simulation. In order to implement the algorithm and to write this dissertation, the articles present in the bibliography were analyzed, being made a general observation of the existing projects related to the simulation of objects’ buoyancy and the related fluid dynamics. In this way, it was possible to make the state of the art of this theme, also aiming to find realistic models of boats and to study in more detail the surrounding physics with the interaction of the boat with the water. The main algorithm can be divided into three initial components: • Creation of a cutting algorithm to distinguish the triangles that are submerged and those that are not with the objective of determining the forces that act in them. This algorithm has to cut the triangles so that those that are only partially submerged give way to triangles totally submerged or not submerged.
1.4. Overview 3 • Calculation of the hydrostatic forces in the fully submerged triangles and their application to the object. These forces are the forces exerted by the water’s drive on the object. • Calculation of the hydrodynamic forces in the fully submerged triangles and their application in the object. These forces are the forces exerted by the movement of the object over water. With the implementation of the initial algorithm carried out, it was tested with several models to verify if the behavior of the objects fits with reality so that the algorithm can be further improved. Having already improved the algorithm, the implementation has been tested to the limits of the computer used with several objects simultaneously for performance analysis, this allowed observing the robustness and capacity of the implemented algorithm. 1.4 OV E RV I E W This dissertation is divided into 5 chapters, which are summarized below, excluding the introduction. • State of the art - this chapter clusters all items found around the floating object simulation. Topics such as discovering the submerged surface of the boat, hydrostatic forces, and hydrodynamic forces are treated. • Implementation - this chapter details the implementation made based on the information present in the articles found. • Tests and Results - this chapter shows the tests and results made during implementation. • Conclusions and Future Work - this chapter presents the conclusions drawn from the completion of the dissertation and the work that can be done in the future to improve the implementation.
2 S TAT E O F T H E A R T There are very few resources that discuss boat physics simulation. Maybe one of the reasons for this scarcity is the excess of simplifications and shortcuts made to run these simulations in a realistic way. This state of the art is mostly based on Kerner (2015) and Kerner (2016) because these articles use a clear and simplified approach that can be adapted into an algorithm that does this type of simulation. With the objective to make objects float in a mesh of water, the structure of the algorithm can be outlined as shown in Kerner (2015). The main algorithm can be broadly divided into three parts: • Determine the submerged surface; • Calculate and apply the hydrostatic forces; • Calculate and apply the hydrodynamic forces. Since we opted for the surface method discussed in Section 2.1 to determine the submerged surface and considering the boat is represented by a triangular mesh, the first part of the algorithm is based on a solution found in Halbert (2016) that takes into account all cases of intersection between the water surface and a triangle and is explained in Section 2.2. The second part of the algorithm calculates two forces, the buoyancy force which is a linear force and consists of the sum of all buoyancy forces acting on each fully submerged triangle and the torque which is the rotational equivalent of linear force (Section 2.3). The last part of the algorithm calculates three forces, the viscous water resistance which occurs when water flows across a surface; the pressure drag force is perpendicular to the surface, which is different from the viscous water resistance that instead is tangent to the surface and the slamming force that mainly captures the impact on fluids from sudden accelerations or penetrations, which are almost like rigid collisions (Section 2.4). This chapter starts by introducing the concept of buoyancy in Section 2.1, determines the submerged surface in Section 2.2, deals with hydrostatic forces in Section 2.3, thus establishing a basis for calculating all other forces involved in the model, deals with the dynamic forces caused by the movement of the boat in the water in Section 2.4 and finally, in Section 2.5, talks about the challenges present in the implementation. 4
2.1. Buoyancy Concept 5 2.1 B U OYA N C Y C O N C E P T Before discussing the main algorithm, the question of buoyancy is introduced. To compute this force, it is necessary to calculate the magnitude and its point of application in a partially submerged body. When an object is submerged in a fluid, a force is exerted by the fluid on the surface of the object due to the pressure from the fluid. The greater the pressure, the greater the force exerted. This force exists regardless of having water particles moving in the fluid or if the boat stays still, so it is called a hydrostatic force. Water pressure increases with depth, and a greater depth implies a greater amount of water pressing down with its weight. The pressure at a certain point in the water only depends on its depth as shown in Figure 1. Figure 1: Diagram that describes the pressure applied at points in different depths. The increasing force with depth is very important for buoyancy, which is calculated from the vertical component of the hydrostatic forces of the body’s surface. If we consider the forces as vectors, we have 3 components, which can be divided into 2 horizontal components and 1 vertical component. According to Archimedes’ principle (Ray and Rodriguez (2018)), the horizontal components of the water pressures on unit areas of the boat’s sides, act in opposite horizontal directions at the same depth. Since the magnitudes of the hydrostatic forces are the same but have opposite directions, the horizontal component of these forces cancels each other out. However, for a generic object, the vertical component of hydrostatic forces does not cancel out, because surfaces where the normal is pointing downwards are at greater depths than surfaces in which the normal is pointing upwards. The resulting force is pointing in the opposite direction of gravity and its magnitude is equal to the weight of the volume of the submerged part of the body as if it were filled with water. In addition, it is also necessary to find the point of application of the buoyancy force, which is the center of mass of the submerged volume. There are two methods for calculating the buoyancy forces, the volumetric method and the surface method. The first is to evaluate the submerged volume and determine the centroid, and the second determines the submerged surface and computes the force to be applied on the submerged surface. Both methods should produce the same result when calculating the force applied to the object.
2.2. Determining the submerged surface 6 In the volumetric method, it is necessary to close the submerged hull surface to form a closed volume, because by definition volume is the space occupied within the boundaries of an object in three-dimensional space. Since the shape of the boat can be complex, the volume of the boat can be difficult to calculate. In the volumetric method, as shown in Kerner (2015), it is suggested to use simple volume primitives to approximate the volume of the boat. Using these primitives, it is possible, at least in theory, to make approximations to the submerged volume as precise as floating point operations allow. In Kerner (2015) is shown an example that uses spheres to calculate the volume of the object, but significant gaps between the spheres can occur as seen in Figure 2. The presence of gaps leads to noticeable deformities in buoyancy. Figure 2: Approximating the volume of a boat with spheres. Source: Kerner (2015). The volume of the body could also be voxelized. The voxels intercepted by the water could be further voxelized in order to achieve arbitrary precision. Considering the surface method, assuming the object is modeled by triangles, the hydrostatic pressure forces in each triangle of the submerged surface are calculated and their impulses are added around the body’s center of gravity. Both methods have their pros and cons. The surface method was selected for this work since it has better support in the literature, like Kerner (2015). 2.2 DETERMINING THE SUBMERGED SURFACE Since the main objective of this section is to calculate the submerged surface, it is assumed that the boat is an approximation based on a triangular mesh of the hull. Within this set of triangles, there are triangles that are fully submerged, triangles that are completely out of the water, and others that intersect the waterline as shown in Figure 3. For the last ones, it is necessary to determine the submerged part of them. For this, we must start by calculating the height at which the vertices of the triangle are located to determine the points of intersection with the water. It is assumed that there is a function f(x,z), where xand zare the horizontal coordinates of the vertex in question and this function returns the height of the water. On a traditional height map, the height map
2.2. Determining the submerged surface 7 consists of a rectangular area subdivided into bands that form lines and columns, intersecting in square cells as shown in Figure 4. Figure 3: In the figure are shown 4 simplified cases of triangle intersections with the water patch. (a) (b) Figure 4: A water patch and the water line (cyan) seen from different perspectives. Source: Kerner (2015). There are several ways for a surface to divide a triangle. For example, it can cut the triangle in several places; the surface can pass through the center of the triangle without crossing any edges or submerging any vertices. These cases can even be found in relatively calm waters, requiring proper handling in a way that does not cause unrealistic discontinuities in the amount of surface considered submerged. Triangles, where all vertices are above the water, are considered to be entirely out of the water. If only one or two vertices are submerged, the triangle is cut in a submerged region and in a non-submerged region as shown in Figure 3. If the submerged region is not a triangle, it is necessary to continue triangulating it. It is assumed that the water surface cuts the edge only once between a submerged vertex and a vertex out of the water. With this assumption, in Figure 5 we have some examples of cases not accurately intersected and which are not considered in the algorithm.
2.2. Determining the submerged surface 8 Figure 5: In the figure are shown three examples of cases mishandled by the optimized algorithm. The red areas denote triangles that should have been considered underwater, yet were missed. To simulate the object buoyancy, it is necessary to determine which triangles are present in the mesh that are submerged and which are not (assuming that the mesh is composed only of triangles) in order to apply correctly the forces exerted. (a) (b) Figure 6: Simplified triangle cutting in the possible cases. In Figure 6a is shown a simplified triangle cutting when only one vertex is out of the water and in Figure 6b is shown another triangle cutting when two vertices are out of water. This algorithm starts by determining the vertices of each triangle that are below the water plane, then rearranges the vertices of the triangle according to the height in relation to the water surface (called H, M and L the highest, mid and lower points). Then it checks how many vertices of a given triangle are submerged, and depending on the case, a cutting strategy for that same triangle is performed. We refer to the heights of these points as hH,hMand hL. We first consider the case where H is above the water but M and L are under (Figure 6a). So hL≤0and hM≤0but hH≥0.
2.3. Hydrostatic Forces 9 We assume that the water cuts the edge HM at a point IMand the edge HL at a point ILand we assume that the edge ML is fully submerged. We can parameterize the location of the intersection points by Equation 1 and Equation 2. −−→ MIM=tM −−→ MH (1) −→ LIL=tL −→ LH (2) We use the heights above water to find a suitable value of tMand tLin Equation 3 and Equation 4. tM=−hM (hH−hM)(3) tL=−hL (hH−hL)(4) In the second case, we consider the case where H and M are above the water but L is under (Figure 6b). So hH≥0and hM≥0but hL≤0. We assume that the water cuts the edge HL at a point JHand the edge ML at a point JM. We can parameterize the location of the intersection points by Equation 5 and Equation 6. −−→ LJM=tM −→ LM (5) −→ LJH=tH −→ LH (6) We use the heights above water to find a suitable value of tMand tHin Equation 7 and Equation 8. tM=−hL (hM−hL)(7) tH=−hL (hH−hL)(8) 2.3 HYDROSTATIC FORCES From the list of fully submerged triangles, it is possible to calculate the hydrostatic forces. These forces are necessary for the buoyancy force acting on the object. The buoyancy force is defined by the sum of all hydrostatic forces acting on each submerged triangle. This section is divided into two parts, in Section 2.3.1 the buoyancy force is calculated and applied and in Section 2.3.2 the same process happens to the torque.
2.4. Hydrodynamic Forces 16 2.4.1 Damping Forces When hydrostatic forces are applied to the object, it is necessary to avoid having it bouncing uncontrollably. A possible solution is to add damping forces, both for linear and angular forces. Based on the list of submerged triangles, determined in the cutting algorithm, we can obtain from the ratio between the submerged area and the total surface area of the boat, a simplistic measure of how much the boat is submerged, as shown in Equation 27. rs=Ssubmerged Stotal (27) Using rs, it is possible to create a linear damping force given by Equation 28, and a quadratic damping force given by Equation 29 with a velocity ~ vand the damping coefficient given by Cdamp. ~ Fdamp =−Cdamprs~ v(28) ~ Fdamp =−Cdamprsv2~ v ||~ v|| (29) The formula used was given by Equation 28. However, the formula that is going to be used is not of great importance, as the important thing is to damp a lot, with a constant Cdamp sufficiently big. These damping forces are replaced by 3 forces that constitute the hydrodynamic forces (each of them is described in Section 2.4): • Viscous Water Resistance; • Pressure Drag; • Slamming Force. Each of the hydrodynamic forces is added to the final model, as they are more realistic and precise than the damping forces. 2.4.2 Drag Equation The term "Drag" quoted in detail in Batchelor (2000) means any force that resists movement, but can be caused by different physical phenomena. It can have several causes, such as: • Friction on the surface of the body in motion; • Pressure on the surface; • Dissipating energy in the creation of waves.
2.4. Hydrodynamic Forces 17 The larger the surface in contact with the fluid, the greater the resistance. This is because there is more area for the fluid to interact with the submerged body. In parallel, the greater the density, the greater the mass that exists per unit volume of the fluid. The drag equation, in fluid dynamics, as shown in Kerner (2016) is given by Equation 30. R=1 2ρCSV2(30) Where Rin Equation 30 is the magnitude of the resistance force, ρis the density of the fluid, Cis the resistance coefficient in question, Sis the boat area in contact with water and Vis the speed of the body. From the formula in Equation 30, we can conclude that if Cwere constant, the resistance would be proportional to V2. This would happen if Cwas independent of velocity V, which is not, since Cis dependent on velocity and other variables. When talking about the wave resistance of certain boats at moderate speeds, Ccan change abruptly in relation to V.Cbecomes a function of V4, making the power law of the drag equation not quadratic, but a function of V6. The variation of Cis important to understand the nature of a given hydrodynamic resistance. In Figure 11, the first graph shows us chosen coefficients that may vary or not with the velocity. In the second graph, we observe that the difference between the chosen coefficients represented by green and red produces a very similar Reynolds number. As suggested in Todd (1957) and shown in Equation 31, it is possible to express Cas a function of flow velocity and “fluid path length”, when the Reynolds number Rnreferenced in Equation 32 is introduced. In Equation 31,constant and Xare constants dependent on the force to be calculated. C(Rn) = constant (log10 Rn−X)2(31) Rn=VL ν(32) Where Vin Equation 32 is the velocity of the body, Lis the length the fluid has to travel across the surface (the length of the largest side of the boat) and νis the viscosity of the fluid (this value can vary with temperature, at 20ºC is 0.000001 and at 30ºC is 0.0000008). The difference between the value of νto salt water and fresh water is minimal, so an approximation of the value is used. Ccan be expressed as a function of Rn. It is noticed that the length Ldepends on the application and that Cis also affected by the length that the fluid must travel, in addition to being affected by the velocity of the body in relation to the fluid. 2.4.3 Triangle’s velocity for Hydrodynamic forces All hydrodynamic forces in the model are calculated from some values and vectors related to the submerged triangles of the boat’s hull. The boat data structure consists of Nttriangles, a center of gravity G, a linear velocity −→ VGand an angular velocity −→ ΩG. Each triangle Tb jof the boat, j∈[0, Nt], can be submerged, creating one or two triangles TS.
2.4. Hydrodynamic Forces 18 Figure 11: The upper graph represents the drag coefficient as a function of speed V , where R(N) is the magnitude of the resistance force. In the bottom graph, the force is generated as a function of V . Two of the drag coefficients are constant, represented by the colors blue and red. The third coefficient represented by the green color varies with velocity and additionally, the drag force is a function of V2 . Source: Kerner (2016). The submerged triangle TS ihas a center of application in Ciand the normal ~ nipointing outward, its velocity given by ~ viin Equation 33. In Equation 33, we can conclude that this velocity is different from the linear velocity of the object because this velocity depends on linear velocity and angular velocity as well as the center of the triangle itself. ~ vi=−→ VG+−→ ΩG×−→ GCi(33) The velocity represented in Equation 33 is referred to as the point velocity of the triangle, measured at its center, in global coordinates. The direction of the point’s velocity is given by ~ uiin Equation 34. ~ ui=~ vi k~ vik(34)
2.4. Hydrodynamic Forces 19 From Equation 34, it is possible to introduce the scalar product given by Equation 35. cos θi=~ ui·~ ni(35) Since ~ nipoints outward, cos θiis positive if the triangle is pushed towards the water and negative otherwise. Some useful quantities on each submerged triangle are represented in Figure 12. Figure 12: Representation of some quantities on each submerged triangle. Source Kerner (2016). 2.4.4 Viscous Water Resistance Viscous resistance occurs when water flows over a surface. Because there is a strong interaction between the water that is close to the hull and the surface of the hull, there is a layer of water that attaches to the surface and moves with the boat. If the distance between the water and the hull increases, the water adheres less and less. Each of these layers of water at a certain distance from the surface interacts with the ones immediately before and immediately after, this intensity of interaction is called viscosity. The more viscous a fluid, the more it will stick to the surface and be dragged along with it. Over the years, several experiments have been carried out to measure resistance to viscous water. One example consisted of a smooth flat plate being dragged underwater. If this plate is thin and dragged along its length, the measured force is basically given by the resistance to viscous water. In 1957, the ITTC agreed that the formula given by Equation 36 was a good approximation of the data collected. This formula is called the ITTC 1957 model-ship correlation line and was not derived analytically from the first principles, but is a regression function that fits the data for practical purposes. CF(Rn) = 0.075 (log10 Rn−2)2(36)
2.4. Hydrodynamic Forces 20 In the built model, a formula is needed that can be applied to each of the triangles to calculate the viscous friction. Being a complicated thing to do, often developers prefer to resort to measured resistance, rather than analytical formulas. As the viscosity of the fluid is not the only parameter that influences the size of the force, we have to take into account parameters such as the roughness of the surface itself. If this surface is rougher, it will interact more visibly with a thicker layer of water than a very smooth surface. It is very important to take into account the flow around the surface. This flow is considered to be laminar in the front of the boat, that is, ordered and the layers at increasing distances from the surface flow parallel to each other with different speeds, due to the influence that the velocity of one layer has on the other, all of this because there is viscosity. As the time that the fluid flows through a surface increases, the flow is greater and more layers begin to mix. When the different layers mix without rest, the amount of fluid accelerated on the surface increases and gives rise to greater resistance. Therefore, we should expect more resistance to viscous friction at the back of the boat than at the front. The last thing to take into account when calculating this force is the shape of the boat. Since the boat is not perfectly flat, the fluid must travel a greater distance and the relative velocity of the fluid is generally greater than the velocity of the boat. Pressure changes on the surface of the boat affect resistance due to the shape of the boat. To circumvent the difficult assessment of the exact influence of all the factors mentioned above, some marine engineers assume that, at a constant low velocity, most of the forces acting on a boat are the result of viscous resistance. Therefore, the viscous resistance of a reference plate dragged under the water at the same low velocity is measured. Assuming that the reference plate is a flat plate with an area equivalent to the surface of the submerged part of the boat’s hull, the resistance of this same plate is multiplied by 1+k(a value greater than 1 resulting from all factors that increase the resistance). Since CT0is the total resistance coefficient measured for a small velocity, and CF0is the viscous resistance of the reference plate in the same Reynolds number,kis determined in such a way that Equation 37 make sense. CT0= (1+k)CF0(37) The values 1+kdetermined by the formula vary between 1.22 and 1.65. It is also assumed that the real coefficient of resistance to viscous friction CFr is multiplied by this same factor 1+kacross the range of Reynolds numbers, from low to high velocity given by Equation 38. CFr(Rn) = (1+k)CF(Rn)(38) Where CFr is given by Equation 38.
2.4. Hydrodynamic Forces 21 In the model in question, we have to apply Equation 38 for the viscous resistance of a flat plate to each of the triangles, thus resulting in the viscous frictional force in the submerged triangle TS igiven by Equation 39. ~ Fvi =1 2ρ0.075 (log10 Rn−2)2Sivf i ~ vf i =1 2ρCFSivf i ~ vf i (39) Where ~ vf i in Equation 39 is the relative flow velocity at the center of the triangle. Since the flow velocity calculated from Equation 40 for a triangle almost facing forward would be very small and with the scalar product close to 1, Equation 40 is used to provide the tangential direction of flow ~ uf i (Equation 41) and multiplies by the velocity viin Equation 42. ~ vki= (~ vi−~ vi·~ ni)(40) ~ uf i =~ vki k~ vkik(41) ~ vf i =vi~ uf i (42) To obtain a stronger viscous resistance at the rear of the boat, since the flow is greater at this location, a single value of Equation 38 was calculated, but a factor-dependent triangle 1+kiis included for triangles where the flow is laminar, the kiis in the range [-1,0]. For triangles located near the rear, kiis equal to 1 or 2. The integration of all factors 1+kiresults in factor 1+kof the boat given by Equation 43. 1+k=∑i(1+ki)Si ∑iSi (43) When a boat is sailing in a straight line through calm waters, viscous resistance is the main force acting on the boat. In this case, the boat has most of the surface out of the water, but with a large part of the bottom touching the water. The pressure resistance would be very small, but significant water resistance is still necessary. If the boat is 2 or 3 times longer without changing its face area, it is necessary for the resistance to increase, and this is possible with the viscous resistance calculated in Equation 39 because it accumulates in the triangles of the hull tangential to velocity. 2.4.5 Pressure Drag Forces As soon as the boat and the surrounding water are observed by Kerner (2016), it was concluded that the energy is dissipated in a way that goes beyond the viscous resistance. As observed in the same article, the waves created by the boat and with the deduction of how much resistance was applied to the boat from the Newtonian reaction and action principle, the resistance of the wave pattern was obtained. However, the slopes of the waves created in this way are considered small, simplifying the calculation and allowing the production of a manageable formula.
2.4. Hydrodynamic Forces 22 Since, near the boat, the slope of the waves cannot be considered small and the waves break, they give rise to a resistance called wave breaking resistance. Thus, depending on the model chosen to capture this resistance, it may be necessary to distinguish yet another resistance that comes into contact with water in a violent way so that the water becomes spray, being quite complicated to be implemented in a simulation. A solution to simplify the implementation of these forces would be not to capture different components by categorizing and evaluating them, but to solve the Navier-Stokes equation numerically. However, it would be a bad idea in terms of the model’s performance and complexity. In this way, a very simple force called pressure drag force was introduced, which captures the necessary resistance. In short, attempts have been made to capture the forces that allow a boat to turn and the sliding forces that push the boat out of the water. Pressure drag, as opposed to viscous water resistance, acts along the normal surface. This can be divided into a pressure drag for positive cos θivalues and a suction drag for negative cos θivalues. The pressure drag is represented by Equation 44. ~ FDi =−(CPD1 vi vr +CPD2(vi vr )2)Si(cos θi)fp~ nii f cos θi>0(44) Where fpin Equation 44 is the falling power of the opposite scalar product, CPD1and CPD2are the linear and quadratic pressure drag coefficients and vris a reference velocity. The reference velocity has the function of facilitating the adjustment of the drag coefficients, the term velocity being equal to 1. The falling force controls the speed or slowness that the drag drops when the normal transition of the triangle changes from parallel velocity to the velocity of the point when the drag force must reach its peak intensity, and then to one perpendicular to it when the drag strength must disappear. In this sense, the suction drag can be represented by Equation 45. ~ FDi = (CSD1 vi vr +CSD2(vi vr )2)Si(cos θi)fS~ nii f cos θi<0(45) Where fSin Equation 45 is the suction drop power, CSD1and CSD2are linear and quadratic suction drag coefficients and vris the same reference velocity. A better turning behavior was observed with values of fpand fSless than 1, due to the angle θibeing close to 90 degrees, the cosine being close to 0, and increasing almost linearly. It was also observed that it was a very slow process, so a small boat slip angle would not cause enough side drag to slow the boat and help it to turn. On the other hand, in the values of fPand fS≤0.5, the lateral drag increases close to 90 degrees and the boat’s turning radius improves a lot. CPD1,CPD2,CSD1and CSD2are coefficients that can be modified as we please since the formulas are used as a simplified approximation of the real behavior and not in physics. As the drag force is normal on the surface of the boat, if the boat has sufficient propulsion to fight the force that opposes its acceleration, the hydrodynamic pressure increases at the bottom of the boat, lifting it up. As it increases, the amount of resistance created by friction and drag forces decreases.
2.4. Hydrodynamic Forces 23 2.4.6 Slamming Forces With viscous resistance and resistance to pressure drag, it is already possible to observe a more realistic model of a boat, although the boat can still penetrate the water more than acceptable and the overall response becomes deficient in rigidity. Instead of modifying the drag forces, it was decided in Kerner (2016) to introduce another force that would capture the violence of the fluid’s response to sudden accelerations or penetrations. Collisions that are very rigid are difficult to model using a force dependent on the depth of penetration or displacement when using a discrete integration scheme. As it was important that this force was arbitrarily rigid and the theory of impact forces very complex, the problem was shortened and this is resolved with a perfectly rigid response, where this rigidity was reduced as needed. The process started with the assessment of the intensity of the collision with the water. If it is too violent, a stop motion force is applied entirely, and the boat stops as if it has hit the ground. Otherwise, that is, if the collision is of low intensity, none of the movement’s stopping forces are applied. Between these two cases, several transition functions were combined: • Linear; • Power Functions; • Sigmoid; • Step. These forces can be applied to triangles that penetrate violently, rather than being applied to other parts of the boat, to ensure that the rigid response is located where expected. Thus, one can begin by defining the impact force as a force proportional to the area of the triangle in which it is applied. One of the precautions to be taken is in the case of the most extreme impact, where the sum of the impact forces in all the submerged triangles should be just enough to stop the movement of the boat completely, not exceeding this so that the boat does not jump out of the water. Another challenge is that the force must be present only when there is a change in submersion or velocity, but it must be null if its state is stationary. This means that we must make differences frame by frame to measure the submerged quantity of a part of a boat in the previous stage and compare it with the current stage. As it is impossible to differentiate frame by frame, due to the different number of submerged triangles in each frame, we can follow the boat’s original triangles and calculate for each frame how much they are submerged. To do this, it is necessary to prepare a double buffer of submerged surface areas [Asubmerged j(t− dt),Asubmerged j(t)]. Considering a triangle of the boat Tb j. If STotal is the total area of the boat, Sb jthe surface area of the triangle Tb j,Asubmerged j(t−dt)the area of the surface that was submerged in the previous step and Asubmerged j(t)the area submerged in the current step, then it is possible to express the volume of water swept by a time interval in
2.4. Hydrodynamic Forces 24 the last integration step as shown in Equation 46 and the volume of water swept by a time interval in the current step as shown in Equation 47. dVswept j(t−dt) = Asubmerged j(t−dt)~ vi(t−dt)(46) dVswept j(t) = Asubmerged j(t)~ vi(t)(47) Taking the difference, dividing by the area of the boat’s triangle under consideration and dividing by dt, the equivalent of acceleration is obtained, as expressed in Equation 48. ~ Γj(t) = Vswept j(t)−Vswept j(t−dt) Sb jdt (48) If the triangle is completely submerged in both stages of integration, we obtain Equation 49. ~ Γj(t) = Sb j~ vi(t)−Sb j~ vi(t−dt) Sb jdt =~ vi(t)−~ vi(t−dt) dt (49) However, if the triangle is completely submerged in the current integration step, but is completely out of the water in the previous step, we obtain Equation 50. ~ Γj(t) = Sb j~ vi(t)−~ 0 Sb jdt =~ vi(t) dt (50) Thus, we have an amount that captures the acceleration to which a triangle is subjected when the submerged area does not change, but becomes very large when the triangle submerges quickly. The magnitude Γjof the vector calculated in Equation 50 is the perfect candidate for determining whether impact forces should be applied to the triangle or not. If the triangle moves away from the water, no impact force is applied. That is, when the product rises between the normal of the triangle pointing outward ~ niand the velocity ~ viis negative. When this product is positive, a maximum acceleration of Γmax is introduced in which the full motion stop force is applied and below which a power function is used to more or less smoothly increase the impact force, as shown in Equation 51. ~ Fslamming j=clamp(Γj Γmax , 0, 1)pcos θj~ Fstopping j(51) Where ~ Fstopping jin Equation 51 is the force needed to stop the movement and pis the force used to increase the impact force. A value of 1 causes the impact force to appear gradually. A value of 2 or more, however, does not visibly affect the boat below Γmax and only appears close to that limit, thus obtaining a realistic rigid
2.5. Challenges 25 non-linear stop. One of the things that still needs to be defined is the stop expression ~ Fstopping jwhich is defined by Equation 52. ~ Fstopping j=mvj 2Asubmerged j Stotal (52) The expression in Equation 52 is divided by Stotal to ensure that the sum of all impact forces does not reverse the movement of the boat. Assuming that all faces on one side reach Γmax and the boat moves without rotation, which means that ~ vj=~ v. In this case, we would have the total impact force given by Equation 53. ~ Fslamming =∑ submerged cos θjm~ v2Asubmerged j Stotal =2∑Asubmerged jcos θj Stotal m~ v(53) Where Asubmerged jcos θjin Equation 53 is the surface area of the submerged part of a triangle projected in a plane perpendicular to the velocity ~ v. Since the boat is a closed surface, the maximum surface area of this projection is half of Stotal, thus ending with a maximum of m~ v. With that, we can conclude that the maximum impact force will only interrupt the boat’s movement. As there are several forces to be applied to the body, the velocity must be measured before the impact force is applied. Any resistive force that depends on the velocity must be calculated and applied after the impact force, as it is necessary to use the velocity measured after the impact force is applied to the body. The exponent pin Equation 51 affects the dynamic behavior of the boat. The impact forces play an important role because, without these forces, a boat at speed can reach an oscillatory behavior in which it tilts up and down repeatedly, instead of stabilizing with a certain angle of inclination. Therefore, it is possible to adjust the p values balanced by pressure drag forces that can improve or completely eliminate the problem, providing a more realistic and dynamic simulation. 2.5 CHALLENGES With the implementation of a simulation that supports a large number of boats floating at the same time, several problems arise, among them, the interaction of the boat with the water, the scalability of the algorithm and the stability of the vessel. One of the challenges that arises is the challenge of avoiding situations where small changes in the height of the vertices introduce large sudden changes in the submerged area. This problem occurs because the triangles below and above the water are not being cut accurately. This problem can cause the body to jump suddenly or sink noticeably, this happens only with the introduction of instability in buoyancy. The problem of scalability of the algorithm arises with the need to expand the algorithm to support different types of water, from the calmest to the most agitated and with the need to complicate the boat model or even increase the number of boats. For this to happen, it is necessary that the algorithm is scalable so that the movement of the boat model does not become unstable and very oscillating.
3.2. Cut Algorithm 32 Figure 14: Simplified triangle cutting when only 1 of the vertices is totally submerged. Where JM is the point where the vector between M and L intersects the water and JH is the point where the vector between Hand Lintersects the water. 3vec3 L <- verify wich is the lowest vertice 4vec3 M <- verify wich is the medium vertice 5vec3 H <- verify wich is the highest vertice 6 7float hH <- returns the height of H; 8float hM <- returns the height of M; 9float hL <- returns the height of L; 10 11 float tH = (-hL) / (hH - hL); 12 vec3 JH = L + (tH *(H - L)); 13 14 float tM = (-hL) / (hM - hL); 15 vec3 JM = L + (tM *(M - L)); 16 17 vec3 vertexPos = H; 18 vertex[idx] = vec4(vertexPos,1.0); 19 colour = vec3(1.0, 1.0, 1.0); 20 color[idx] = vec4(colour,1.0); 21 EmitVertex(); 22 23 vertexPos = M; 24 vertex[idx+1] = vec4(vertexPos,1.0); 25 colour = vec3(1.0, 1.0, 1.0); 26 color[idx+1] = vec4(colour,1.0); 27 EmitVertex(); 28 29 vertexPos = JM; 30 vertex[idx+2] = vec4(vertexPos,1.0);
3.2. Cut Algorithm 33 31 colour = vec3(1.0, 1.0, 1.0); 32 color[idx+2] = vec4(colour,1.0); 33 EmitVertex(); 34 35 EndPrimitive(); 36 37 vertexPos = JM; 38 vertex[idx+3] = vec4(vertexPos,1.0); 39 colour = vec3(1.0, 1.0, 1.0); 40 color[idx+3] = vec4(colour,1.0); 41 EmitVertex(); 42 43 vertexPos = JH; 44 vertex[idx+4] = vec4(vertexPos,1.0); 45 colour = vec3(1.0, 1.0, 1.0); 46 color[idx+4] = vec4(colour,1.0); 47 EmitVertex(); 48 49 vertexPos = H; 50 vertex[idx+5] = vec4(vertexPos,1.0); 51 colour = vec3(1.0, 1.0, 1.0); 52 color[idx+5] = vec4(colour,1.0); 53 EmitVertex(); 54 55 EndPrimitive(); 56 57 vertexPos = JM; 58 vertex[idx+6] = vec4(vertexPos,1.0); 59 colour = vec3(0.0, 0.0, 1.0); 60 color[idx+6] = vec4(colour,1.0); 61 EmitVertex(); 62 63 vertexPos = L; 64 vertex[idx+7] = vec4(vertexPos,1.0); 65 colour = vec3(0.0, 0.0, 1.0); 66 color[idx+7] = vec4(colour,1.0); 67 EmitVertex(); 68 69 vertexPos = JH; 70 vertex[idx+8] = vec4(vertexPos,1.0); 71 colour = vec3(0.0, 0.0, 1.0); 72 color[idx+8] = vec4(colour,1.0); 73 EmitVertex(); 74 75 EndPrimitive(); 76 } 77 break;
3.2. Cut Algorithm 34 78 ... Listing 3.4: Specification of the case where 1 vertex of the triangle are submerged in cutting algorithm. In the case where 2 vertices are submerged, it is also necessary to divide the triangle into 3 smaller triangles as shown in Figure 15. Where 2 of these triangles are submerged and only 1 triangle is not submerged. This division is done in Listing 3.5. Figure 15: Simplified triangle cutting when 2 of the vertices are totally submerged. Where IM is the point where the vector between H and M intersects the water and IL is the point where the vector between H and Lintersects the water. 1... 2case 2: { 3vec3 L <- verify which is the lowest vertice 4vec3 M <- verify which is the medium vertice 5vec3 H <- verify which is the highest vertice 6 7float hH <- returns the height of H; 8float hM <- returns the height of M; 9float hL <- returns the height of L; 10 11 float tL = (-hL) / (hH - hL); 12 vec3 IL = L + (tL *(H - L)); 13 14 float tM = (-hM) / (hH - hM); 15 vec3 IM = M + (tM *(H - M)); 16 17 vec3 vertexPos = H; 18 vertex[idx] = vec4(vertexPos,1.0); 19 colour = vec3(1.0, 1.0, 1.0);
3.2. Cut Algorithm 35 20 color[idx] = vec4(colour,1.0); 21 EmitVertex(); 22 23 vertexPos = IM; 24 vertex[idx+1] = vec4(vertexPos,1.0); 25 colour = vec3(1.0, 1.0, 1.0); 26 color[idx+1] = vec4(colour,1.0); 27 EmitVertex(); 28 29 vertexPos = IL; 30 vertex[idx+2] = vec4(vertexPos,1.0); 31 colour = vec3(1.0, 1.0, 1.0); 32 color[idx+2] = vec4(colour,1.0); 33 EmitVertex(); 34 35 EndPrimitive(); 36 37 vertexPos = IM; 38 vertex[idx+3] = vec4(vertexPos,1.0); 39 colour = vec3(0.0, 0.0, 1.0); 40 color[idx+3] = vec4(colour,1.0); 41 EmitVertex(); 42 43 vertexPos = M; 44 vertex[idx+4] = vec4(vertexPos,1.0); 45 colour = vec3(0.0, 0.0, 1.0); 46 color[idx+4] = vec4(colour,1.0); 47 EmitVertex(); 48 49 vertexPos = L; 50 vertex[idx+5] = vec4(vertexPos,1.0); 51 colour = vec3(0.0, 0.0, 1.0); 52 color[idx+5] = vec4(colour,1.0); 53 EmitVertex(); 54 55 EndPrimitive(); 56 57 vertexPos = IM; 58 vertex[idx+6] = vec4(vertexPos,1.0); 59 colour = vec3(0.0, 0.0, 1.0); 60 color[idx+6] = vec4(colour,1.0); 61 EmitVertex(); 62 63 vertexPos = L; 64 vertex[idx+7] = vec4(vertexPos,1.0); 65 colour = vec3(0.0, 0.0, 1.0); 66 color[idx+7] = vec4(colour,1.0);
3.2. Cut Algorithm 36 67 EmitVertex(); 68 69 vertexPos = IL; 70 vertex[idx+8] = vec4(vertexPos,1.0); 71 colour = vec3(0.0, 0.0, 1.0); 72 color[idx+8] = vec4(colour,1.0); 73 EmitVertex(); 74 75 EndPrimitive(); 76 } 77 break; 78 ... Listing 3.5: Specification of the case where 2 vertices of the triangle are submerged in cutting algorithm. Considering the cut algorithm presented in Listing 3.3 and Section 2.2, we started by implementing the algorithm for simple objects like cubes, spheres and torus. This algorithm allows the set of triangles in the model to be divided into two smaller sets, which are the set of submerged triangles and the set of non-submerged triangles, as shown in Figure 16. With these sets defined, it is possible to calculate the forces that are exerted on each triangle that are specified in Section 3.3. Figure 16: Results obtained from the application of the cutting algorithm. The submerged part of the boat is represented by the color blue and the not submerged part of the boat is represented by the color white. To implement the cutting algorithm mentioned in Section 2.2, it is necessary to use the texture created to store the wave heights in order to have access to them to cut the object’s triangles. The texture integration and the distance to the surface are done as shown in Listing B.1. Since calculations are performed with points in global space and not local space, it is not necessary to do any additional calculations for model transformations before calculating the distance between each point and the water surface. When initializing the buffers, it is important to pay attention to the "usage" parameter of the glBu f f erData function in OpenGL, otherwise, garbage can be written in the buffer. We need to verify the frequency of access (modification and usage) and the nature of that access.
3.3. Forces Calculation 37 In order to know which boat we are cutting, an index passed from OpenGL to the shader is used. In addition to the SSBOs that store the vertices and their colors, the SSBO that stores the position of each object and the SSBO that stores the current angular displacement of each object are needed, these SSBOs are initialized with the initial position and the null angle, respectively. These variables are used to determine the exact position of each vertex at each frame in global space. All shader SSBOs that make the cutting algorithm are passed to another shader, the shader that calculates the forces. 3.3 FORCES CALCULATION The calculation of the forces consists of the calculation of buoyancy force, torque, viscous water resistance, pressure drag force and slamming force for each of the triangles as shown in Listing 3.6. We can divide the calculation of the forces into the hydrostatic forces calculation (Section 3.3.1) and the calculation of the hydrodynamic forces (Section 3.3.2). When added to the hydrostatic forces, the hydrodynamic forces caused the boat to become unstable. This problem was solved when these forces were also added to the torque calculation. 1... 2layout (std430, binding = 2) buffer forces{ 3vec4 force[]; 4}; 5 6layout (std430, binding = 3) buffer position{ 7vec4 boat_position; 8}; 9 10 layout (std430, binding = 4) buffer velocity{ 11 vec4 boat_velocity; 12 }; 13 14 layout (std430, binding = 5) buffer angular_velocity{ 15 vec4 angular_boat_velocity; 16 }; 17 18 layout (std430, binding = 6) buffer angular_position{ 19 vec4 boat_theta; 20 }; 21 22 layout (std430, binding = 7) buffer torques{ 23 vec4 torque[]; 24 }; 25 26 layout (std430, binding = 9) buffer boats_mass{ 27 float boat_mass[];
3.3. Forces Calculation 38 28 }; 29 30 layout (std430, binding = 10) buffer boats_ATotal{ 31 float boat_ATotal[]; 32 }; 33 34 layout (std430, binding = 11) buffer boats_length{ 35 float boat_length[]; 36 }; 37 38 // compute all forces 39 40 void main(){ 41 ... 42 triangle = {A,B,C}; 43 if(color[triangle] == blue_color){ 44 F = buoyancy_force(triangle) + 45 viscous_water_resistance(triangle, resistance_coefficient) + 46 pressure_drag_forces(triangle) + 47 slamming_force(triangle); 48 T = triangle_torque(triangle,boat_position,F); 49 } 50 force[j] = vec4(F,0); 51 torque[j] = vec4(T,0); 52 } Listing 3.6: Specification of the calculation of the forces of a triangle. 3.3.1 Hydrostatic Forces Calculation As we can see in Section 2.3.1, we start by calculating the buoyancy force based on Equation 54. Where in Listing 3.7,DENS correspond to ρ, that is, the density of the fluid, Gis the gravity constant and h_center is the distance between the center of the triangle and the water surface. The distance of a vertex to the water surface is calculated in Listing B.1, the calculation of triangle centroid is shown in Listing B.2, the triangle normal is calculated in Listing B.3 and the triangle area is in Listing B.4. ~ Fi=−ρghcenter~ niA4i(54) 1vec3 buoyancy_force(vec3 A, vec3 B, vec3 C){ 2float h_center = dist_surface(t_center(A,B,C)); 3vec3 F = G *h_center *DENS *area(A,B,C) *normal(A,B,C); 4F.x = 0.0; 5F.z = 0.0; 6return F;
3.3. Forces Calculation 39 7} Listing 3.7: Specification of the calculation of buoyancy force of a triangle. In order to calculate the torque of a triangle, we use Equation 55. Where in Listing 3.8,ris calculated based on Section 2.3.2.1, that is, the torque is applied to the triangle center and f orce_iis the total linear force exerted on the boat, that is, the sum between the buoyancy, gravity, and hydrodynamic forces. The triangle centroid is calculated in Listing B.2. τi=ri×~ Fi(55) 1vec3 triangle_torque(vec3 A, vec3 B, vec3 C, vec3 center_of_mass, vec3 force_i) { 2vec3 r = t_center(A, B, C) - center_of_mass; 3return cross(r, force_i); 4} Listing 3.8: Specification of the calculation of torque of a triangle. As soon as the implementation of Section 2.3 to calculate the hydrostatic forces started, the problem of the boat’s stabilization was increasingly noticed, being the model very unstable. Kerner (2015) had an error in the calculation of the buoyancy force, where the area of each triangle was not used to calculate this same force applied to the triangle. This directly affects the calculation of the total force, as one of the forces used is weight and when the area of each triangle is not used, the mass of the object is not evenly distributed. The torque depends on the buoyancy force applied to each triangle to be calculated, as shown in Section 2.3.2.1. The residual torque occurred due to very large approach errors that have accumulated over time. As one of the goals is to have a realistic model, torque can only occur if there are forces that do not cancel out, which happens when the water has a ripple or, in a simpler case, it is slightly inclined. In this sense, there are two methods to calculate the center of application of the torque: • The method in Section 2.3.2.1 which calculates the center of the triangle instead of the center of buoyancy; • The method in Section 2.3.2.2 that calculates the center of application of the force in the triangle, that is, the point at which the forces cancel each other out. To carry out the method in Section 2.3.2.2, each triangle of the set of submerged triangles was divided into two distinct triangles. For each triangle, the application center was calculated and an auxiliary function was performed to calculate the force exerted in each of the triangles. Finally, the forces of each of these small triangles were added. This process was done for all triangles of the model, thus making the weighted sum of the centroids of the small triangles calculated in order to obtain the center of application of the torque in the submerged triangle. For the implementation of torque, both methods were tested. Since the first method is simpler to implement and is more accurate in the area of the object, this one was chosen to avoid approximation errors in the areas required in the calculation of forces.
3.3. Forces Calculation 40 To calculate the torque, it was necessary to use the center of each triangle to construct the vector between this center and the boat’s center of mass. With this vector, the cross product between the total forces applied to the boat and the vector was made, and thus the torque value was obtained. After applying the hydrostatic forces to the boat it was noticed that the boat became very unstable (shown in Figure 17), in order to avoid approach errors it was introduced a threshold and the damping forces were calculated in order to avoid oscillations in the object and to simulate the interaction of the water with the boat. These forces were later removed and replaced by forces corresponding to the interaction of the water with the boat, that is, the hydrodynamic forces. Figure 17: Results obtained from CPU implementation with hydrostatic forces and without threshold. After a few seconds of floating on waves, the boat sinks and becomes very unstable, which did not happen in still water. The submerged part of the boat is represented by the color blue and the not submerged part of the boat is represented by the color white. 3.3.2 Hydrodynamic Forces Calculation With the hydrostatic forces calculated we have to calculate the hydrodynamic forces as shown in Section 2.4. To calculate the first hydrodynamic force, that is, the viscous water resistance of a triangle (Section 2.4.4), we use Equation 56. Where in Listing 3.9,DENS correspond to ρ,C f is the resistance coefficient, v_f_magnitude is the magnitude of ~ vf i and v_fcorrespond to the relative flow velocity at the center of the triangle. The triangle normal is calculated in Listing B.3, the triangle area is shown in Listing B.4, the norm of a vector is shown in Listing B.5, triangle velocity is shown in Listing B.8 and resistance coefficient is calculated in Listing B.9. In order to calculate the Viscous Water Resistance of each triangle, it is necessary to calculate the Reynolds coefficient mentioned in Equation 36, the area of the triangle to which the force is applied, the relative velocity of the flow at the center of the triangle given by Equation 42 and the magnitude of this same velocity. ~ Fvi =1 2ρ0.075 (log10 Rn−2)2Sivf i ~ vf i =1 2ρCFSivf i ~ vf i (56)
3.3. Forces Calculation 41 1vec3 viscous_water_resistance(vec3 A, vec3 B, vec3 C, float Cf){ 2vec3 n = normal(A, B, C); 3float w_magnitude = norm(triangle_velocity(A, B, C)); 4float n_magnitude = norm(n); 5float m = (n_magnitude == 0) ? 1.0 : 1.0/n_magnitude; 6vec3 v_tangent = m *cross(normal(A, B, C), m *cross(triangle_velocity(A, B, C), normal(A, B, C))); 7float v_tangent_magnitude = norm(v_tangent); 8float m_vel = (v_tangent_magnitude == 0.0) ? 1.0 : 1.0/v_tangent_magnitude; 9vec3 tangential_dir = m_vel *v_tangent; 10 vec3 v_f = w_magnitude *tangential_dir; 11 float v_f_magnitude = norm(v_f); 12 vec3 viscous_force = 0.5 *DENS *Cf *area(A, B, C) *v_f_magnitude *v_f; 13 return viscous_force; 14 } Listing 3.9: Specification of the calculation of viscous water resistance of a triangle. As soon as the Viscous Water Resistance has been calculated, we need to calculate the pressure drag forces (Section 2.4.5). The pressure drag forces are calculated depending on the value of the cosine of the angle between the triangle velocity vector and the triangle normal. If this cosine is positive, the pressure coefficients are used, otherwise, the suction coefficients are used. In this way, it is necessary to calculate the area of each triangle, the normal of each triangle, the cosine of the angle between the triangle velocity vector and the triangle normal, the pressure and suction coefficients and the ratio between the triangle velocity and a reference speed, to obtain the pressure drag forces. In the calculation of these forces, we have 2 cases of study, where the cos θof the triangle value can result in 2 situations. The first situation happens when cos θis positive and we can use Equation 57 and the second happens when cos θis negative and we can use Equation 58. Where in Listing 3.10,C_PD1and C_PD2 are the pressure drag coefficients, C_SD1and C_SD2are the suction drag coefficients, vis the ratio between triangle velocity and the reference velocity, f_Pis the falling power of the opposite scalar product and f_Sis the suction drop power. The calculation of the triangle normal is shown in Listing B.3, the triangle area is in Listing B.4,cos θis calculated in Listing B.6 and we can see the calculation of the triangle velocity in Listing B.8. ~ FDi =−(CPD1 vi vr +CPD2(vi vr )2)Si(cos θi)fp~ nii f cos θi>0(57) ~ FDi = (CSD1 vi vr +CSD2(vi vr )2)Si(cos θi)fS~ nii f cos θi<0(58) 1vec3 pressure_drag_forces(vec3 A, vec3 B, vec3 C) { 2float a = pow(triangle_velocity(A, B, C), 2); 3float v = a < 0 ? 0 : sqrt(a); 4float v_ref = v; 5v==0?1:v/v_ref;
3.5. Forces Application 48 Listing 3.16: Specification of the new angular velocity of the boat. With the calculation of the boat’s angular velocity, we can calculate the boat’s angular displacement, that is, the angle of rotation of the boat with Equation 65. Where in Listing 3.17,theta is the actual angular displacement, d_tis the time interval, wis the actual angular velocity and new_wis the new angular velocity. ~ θ=~ θi+1 2~ ωt(65) 1vec3 next_a_position(vec3 theta, vec3 w, vec3 new_w, float d_t) { 2return theta + 0.5 *d_t *(w + new_w); 3} Listing 3.17: Specification of the new angular displacement of the boat. As a final step, all vertices were translated to a new position and the function that calculated the new position and the new velocity was divided into 2 functions. For memory accesses to be synchronized, it is necessary to use the glMemoryBarrier function in OpenGL in each access made.
4 TESTS AND RESULTS The tests and results that are performed throughout this chapter are made in Microsoft Visual Studio 2019 using OpenGL, C++ and GLSL 4.6 as programming languages. The models used in the tests were made in Blender and their inertia was given by Meshlab. The computer used has an Intel Core i7-10750H 2.60GHz processor, an NVIDIA GeForce GTX 1660 Ti graphics card and a refresh rate of 144Hz. 4.1 T E S T S In this section, tests are presented in terms of performance and GPU time referring to the implementation of buoyancy in different boats. The model for this implementation can be rendered in 2 different ways, instantiated and non-instantiated. To render the model in an instantiated way it was necessary to use a variable called gl_InstanceID in a vertex shader to know the current instance and each information type of the boats was stored in one buffer per type, for example, all vertices of all boats were stored in one buffer. In a non-instantiated way, the models were rendered in an iterative cycle, where the current index was passed to the shader as the current object index and all main buffers only contain the information of one object. The index here only serves to traverse the buffers that contain auxiliary variables for the calculations, such as mass, inertia, total area, boat length, actual velocity, actual position of the center of mass, angular velocity and angular displacement. The first tests were done with boats of 7 kg of mass and approximately 12 m3of volume with 64 triangles each rendered without instances, that is, in an iterative way and each buffer has only the information of one boat. The fps and the time spent on the GPU were measured from the rendering of the waves until the moment when the boats are rendered with the respective forces applied. First, the heights of the waves are saved in a texture and then passed to a shader that renders them on the screen. Then, the cycle that renders the boats start and within this cycle, the cutting algorithm is made, the force buffers are initiated with 0’s, the forces are stored and summed with the reduce technique, the forces are applied to the current boat and the next iteration of the cycle is executed. The results of the non-instantiated rendering are shown in Table 2. The tests performed in addition to considering the performance in fps, concern the execution time of the entire algorithm in GPU in the two models rendering cases. 49
4.1. Tests 50 Number of boats Performance (fps) Time spent on the GPU (ms) 1 143.88(±0.062) 0.9994(±0.013) 50 143.622(±0.47) 4.86(±0.089) 100 91.6(±1.67) 9.88(±0.13) 200 48.38(±0.24) 19.38(±0.31) 400 25.5(±0.1) 38.66(±0.51) 800 12.98(±0.045) 76.1(±0.5) Table 2: Performance analysis of boats and time spent on the GPU in a non-instantiated way. Tests were carried out with the same boats as in the tests shown in Table 2, but with instances. The structure of the buffers started to contain the information of all the instantiated boats, with these buffers having a variable size depending on the number of boats to be rendered. The results are shown in Table 3. Number of boats Performance (fps) Time spent on the GPU (ms) 1 143.99(±0.074) 1.4(±0.086) 50 93.4(±3.65) 8(±2.35) 100 66.4(±1.52) 15.8(±2.39) 200 34.78(±1.81) 28.6(±1.52) 400 17.6(±1.14) 53.2(±5.26) 800 8.8(±0.45) 126.8(±7.95) Table 3: Performance analysis of boats and time spent on the GPU in an instantiated way. In the graph shown in Figure 19, it can be seen, marked in blue, that a better performance is obtained with boats rendered without instances and in orange, it is observed that the performance is worse with boats rendered with instances. Figure 19: Relationship between increasing the number of boats rendered and performance.
4.1. Tests 51 In the graph shown in Figure 20, it can be seen, marked in blue, that less time is spent on GPU with rendered boats without instances and in orange, it is observed that more time is spent on GPU with rendered boats with instances. Furthermore, we can see that the non-instantiated version is linear with the number of boats as expected. Figure 20: Relationship between increasing the number of boats rendered and time spent on the GPU. In order to test the performance with the increasing complexity of the boats, the same tests as in Table 2 were carried out, that is, 5 measurements of the performance and time spent on the GPU were made and the mean and standard deviation were calculated for 4 boats with a different number of triangles. The boats as 64, 256, 576, and 7744 triangles, respectively. The results can be seen in Table 4. Number of triangles Number of boats Measurement units 64 256 576 7744 1fps 143.88(±0.062) 143.962(±0.063) 143.99 114.6(±3.44) ms 0.9994(±0.013) 0.904(±0.0089) 1.01(±0.014) 8.46(±1.46) 50 fps 143.622(±0.47) 143.934(±0.0767) 138.326(±0.217) 53.026(±0.21) ms 4.86(±0.089) 5.434(±0.012) 6.486(±0.0219) 17.074(±0.128) 100 fps 91.6(±1.67) 86.9(±0.312) 72.812(±0.158) 27.578(±0.044) ms 9.88(±0.13) 10.862(±0.102) 13.124(±0.074) 34.772(±0.07) 200 fps 48.38(±0.24) 44.506(±0.113) 37.388(±0.063) 14.074(±0.049) ms 19.38(±0.31) 21.724(±0.105) 26.118(±0.15) 69.468(±0.158) 400 fps 25.5(±0.1) 22.624(±0.0709) 18.948(±0.046) 7.134(±0.022) ms 38.66(±0.51) 43.718(±0.222) 52.194(±0.44) 138.566(±0.317) 800 fps 12.98(±0.045) 11.424(±0.054) 9.588(±0.043) 3.566(±0.017) ms 76.1(±0.5) 86.872(±0.46) 103.624(±0.24) 278.834(±0.505) Table 4: Performance and time spent on the GPU analysis of different boats in the same conditions.
4.1. Tests 52 In the graph shown in Figure 21, it can be seen that the complexity of the boat does not influence the performance of the algorithm when the number of triangles is very low, but the performance decreases as the number of triangles increases a lot. It can also be observed that the performance of the algorithm decreases a lot as the number of boats rendered increases. Figure 21: Relationship between increasing the number of boats rendered and their complexity and performance obtained. In the graph shown in Figure 22, it can be seen that the complexity of the boat has little influence on the time spent on GPU when the number of triangles is very low, but the time spent on GPU increases a lot when the number of triangles also increases a lot. It can also be observed that the time spent on the GPU is more influenced by the number of boats rendered. Figure 22: Relationship between increasing the number of boats rendered and their complexity and time spent on the GPU.
4.2. Visual Results 53 4.2 VISUAL RESULTS In this section, the results regarding the implementation of buoyancy in different boats are presented. The results of the implemented algorithm can be seen in Figure 23,Figure 24,Figure 25,Figure 26 and Figure 27 in different positions, tested in gerstner waves. The boats that were tested have 64, 256, 576, 2800 and 7744 triangles, respectively. With the implementation of the algorithm in Chapter 3 we can observe that the model is stable and can go up and down a wave depending on the forces that interact with it. The results show 4 boat models rendered smoothly in a non-instantiated way. (a) (b) (c) Figure 23: Results obtained from a boat with 64 triangles in different positions of the wave with amplitude and frequency equal to 0.8.
4.2. Visual Results 54 (a) (b) (c) Figure 24: Results obtained from a boat with 256 triangles in different positions of the wave with amplitude equal to 0.5 and frequency equal to 0.8.
4.2. Visual Results 55 (a) (b) (c) Figure 25: Results obtained from a boat with 576 triangles in different positions of the wave with amplitude equal to 1.0 and frequency equal to 0.5.
4.2. Visual Results 56 (a) (b) (c) Figure 26: Results obtained from a boat with 2800 triangles in different positions of the wave with amplitude equal to 1.0 and frequency equal to 0.5.
4.2. Visual Results 57 (a) (b) (c) Figure 27: Results obtained from a boat with 7744 triangles in different positions of the wave with amplitude equal to 0.5 and frequency equal to 0.8.
B LISTINGS uniform sampler2D texUnit; ... vec4 points_plane(vec3 a, vec3 b, vec3 c) { vec3 normal = normal(a,b,c); float d = -(normal.x *a.x + normal.y *a.y + normal.z *a.z); return vec4(normal.x, normal.y, normal.z, d); } vec4 plane_in(vec2 xz){ float i = floor(xz.x); float j = floor(xz.y); float xmax = i + 1; float xmin = i; float zmax = j + 1; float zmin = j; float quad_level = (xz.y-j) - (xz.x-i); vec4 pl; vec3 A, B, C; if (quad_level < 0) { //first triangle A = vec3(xmin, texture(texUnit, grid_coord(vec2(i,j))).r,zmin); B = vec3(xmin, texture(texUnit, grid_coord(vec2(i,j+1))).r,zmax); C = vec3(xmax, texture(texUnit, grid_coord(vec2(i+1,j))).r,zmin); } else { //second triangle A = vec3(xmax, texture(texUnit, grid_coord(vec2(i+1,j+1))).r,zmax); B = vec3(xmax, texture(texUnit, grid_coord(vec2(i+1,j))).r,zmin); C = vec3(xmin, texture(texUnit, grid_coord(vec2(i,j+1))).r,zmax); } 64
65 pl = points_plane(A, B, C); return pl; } float apply(vec4 pl, vec3 a){ return (a.x *pl.x) + (a.y *pl.y) + (a.z *pl.z) + pl.w; } float dist_surface(vec3 a){ vec2 xz = vec2(a.x,a.z); vec4 pl = plane_in(xz); float res = apply(pl, a); return res; } Listing B.1: Calculation of distance between a vertice of the boat and the surface of water. Where texUnit is the texture previously mentioned, quad_level is the value that identifies which of the triangles of the plane where the vertex of the object is located, x is the x coordinate of the vertex, y is the vertex coordinate, xmin is the the minimum coordinate on the x’s axis, ymin is the the minimum coordinate on the y’s axis and grid_coord is the coordinates in the grid. As the heights are stored in the channel r of the texture to access the height of the points it is necessary to access this channel. vec3 t_center(vec3 A, vec3 B, vec3 C) { return (A + B + C) / 3.0; } Listing B.2: Calculation of the triangle centroid. Where A, B and C are the vertices of the triangle. vec3 normal(vec3 A, vec3 B, vec3 C) { vec3 U = B - A; vec3 V = C - A; vec3 N = cross(U, V); if(N == vec3(0.0)) return vec3(0.0); else return normalize(N); } Listing B.3: Calculation of the triangle normal. Where A, B and C are the vertices of the triangle. float area(vec3 A, vec3 B, vec3 C) { return norm(cross(B - A, C - A)) / 2; } Listing B.4: Calculation of the triangle area. Where A, B and C are the vertices of the triangle.
66 float norm(vec3 a) { return sqrt(a.x *a.x + a.y *a.y + a.z *a.z); } Listing B.5: Calculation of the norm of an vector a. float cos_theta(vec3 A, vec3 B, vec3 C) { vec3 normalized_triangle_vel = normalize(triangle_velocity(A, B, C)); return dot(normalized_triangle_vel, normal(A, B, C)); } Listing B.6: Calculation of the cos_theta of a triangle. Where A, B and C are the vertices of the triangle. float submerged_triangle_area(vec3 A, vec3 B, vec3 C) { float submerged_triangle_area; if (cos_theta(A, B, C) < 0) { submerged_triangle_area = 0.0; } else{ submerged_triangle_area = area(A, B, C); } return submerged_triangle_area; } Listing B.7: Calculation of the submerged area of a triangle. Where A, B and C are the vertices of the triangle. vec3 triangle_velocity(vec3 A, vec3 B, vec3 C){ vec3 v_B = boat_velocity; vec3 omega_B = angular_boat_velocity; vec3 r_BA = t_center(A, B, C) - boat_position; vec3 v_A = v_B + cross(omega_B, r_BA); return v_A; } Listing B.8: Calculation of the triangle velocity at the center. Where A, B and C are the vertices of the triangle. float reynolds_number(vec3 v) { float nu = 0.000001; //Reynolds number float velocity = norm(v); float Rn = (velocity *boat_length) / nu; return Rn; }
67 float resistance_coefficient(float Rn){ float Cf = 0.075f / pow((log10(Rn) - 2.0f), 2.0f); return Cf; } Listing B.9: Calculation of the resistance coefficient from reynolds number. vec3 translate(vec3 trans, vec3 a){ vec3 result = a + trans; return result; } vec3 rotate(vec3 rot, vec3 a){ float d = norm(rot); float c = cos(d); float s = sin(d); float x=(d==0?0:rot.x/d); float y=(d==0?0:rot.y/d); float z=(d==0?0:rot.z/d); float xx = x *x; float xy = x *y; float xz = x *z; float yy = y *y; float yz = y *z; float zz = z *z; mat3 m_rot = mat3(xx + (1 - xx) *c, xy *(1-c)+z*s, xz *(1 - c) - y *s, xy *(1-c)-z*s, yy + (1 - yy) *c, yz *(1 - c) + x *s, xz *(1-c)+y*s, yz *(1-c)-x*s, zz + (1 - zz) *c); a = translate(-boat_position, a); a = m_rot *a; a = translate(boat_position, a); return a; } Listing B.10: Linear transformations applied to a vertex of the boat. Where trans is the vector of the transformation translation, rot is the vector of the transformation rotation, d is the angle of rotation, boatposition is the position of the center of mass of the boat.