Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

How To Make $1,000,000 With C++ (No, REALLY!)

how to legally make $1000000 with C++

Do you want to win a US$1,000,000 prize? The Millennium Prize Problems are seven mathematics problems laid out by the Clay Mathematics Institute in 2000. They’re not easy – a correct solution to anyone resulted in a US$1,000,000 prize being awarded by the institute. One of the problems to be solved is Navier-Stokes Equations. Do you want to learn how to Solve Navier-Stokes Equations? We will try to give an example in C++, compile it and run it using the C++ compiler; Maybe this example can be a beginning, and by using math and C++ you can solve the problem there, and you may earn that price!

Navier-Stokes Equations

The Navier–Stokes Equations, also known as N-S Equations, Momentum Equations, named after French engineer and physicist Claude-Louis Navier and Anglo-Irish physicist and mathematician George Gabriel Stokes. NS Equations describes the physics of many phenomena of scientific and engineering interest. These equations can be used to model the air flow around a wing, airflow around the CPU or GPU, weather, ocean currents, water flow in a pipe and other fluid flows around objects or fluid flow inside objects can be calculated and simulated. These kind of analysis helps to the design of aircraft and cars, the study of blood flow, the design of power stations, the analysis of pollution, design of heat-sinks and many other things. These equations can be used

The N-S Equations are developed mathematically to express the conservation of momentum and the conservation of mass for Newtonian fluids. These equations are good to analyze fluid flows by an equation of state relating velocity, pressure, temperature, viscosity and density. These equations comes from the Isaac Newton’s second law, applied to fluid motion, together with the assumption that the stress in the fluid is the sum of a diffusing viscous and pressure terms.

The Conservation of Mass

For the Net Mass Transfer From the Faces, for a control volume in x, y, z cartesian coordinates these equations can be written as below

The Conservation of Momentum

The conservation of momentum states the amount of momentum remains constant (conserved); momentum is neither created nor destroyed, but only changed through the action of forces as described by Newton’s Laws of Motion

Here we would like to summarize basics here. We highly recommend you Fluid Mechanics books to get more information about this theory. The Conversion of Momentum equation for a control volume of a fluid can be written as below;

Conservation of Momentum = Net Mass Transfer From the Faces + Mass Change in Control Volume by The Time

In motion, fluid is being under stresses and torsions. For a control volume in x,y,z cartesian coordinates, these equations can be written as below,

N-S Equations (Momentum Equations) For The Incompressible Flow with Constant Viscosity

For example, for a Constant Viscosity (i.e. water) and if we assume that it is Incompressible, Navier-Stokes also called Momentum Equations can be written as below,

2 Dimensional Incompressible Flow Example with Constant Viscosity

2D Dimensionless N-S Equations (Momentum Equations) For The Incompressible Flow with Constant Viscosity

If we consider that our problem in 2 Dimension, NS Equations above can be written in dimensionless form if put dimensionless form of each parameter. Thus, for example Momentum Equation in X direction can be written as below,

2D Rectangular Channel Flow Model

For a 2 dimensional rectangular channel flow we can model a 2D grid flow as below,

Here, pressure nodes will be on the top of each grid nodes,

and the velocity nodes u and v will be between these pressure nodes as below,

Each Velocity and Pressure nodes can be modeled as below with it’s adjacent nodes.

Finally, with this all models, a N-S Equation can be written as below,

This final formula in rectangle is a 5 diagonal matrix form and it can be solved by the SOR iteration method as we described in this Solve MILLIONS of Unknowns In Equations – We Show You How! post. SOR Iteration Method also can be solved as a Multi-Thread application as given figure below, each lines or group of lines can be threaded.

To solve these kind of matrixes we can use this struct below,

[crayon-672a3b7987a39975872384/]

Simply this SOR Iteration Method can be written in C++ as below,

[crayon-672a3b7987a48425663996/]

By using these equations methods we can obtain exact u v velocity parameters in x and y directions on each node in that time. Thus, we can display and simulate fluid flow in C++ Builder by drawing into a canvas or canvas of a bitmap. Let’s see how we can draw velocity vectors.

Visualization of 2D Velocity Vectors with (u,v) parameters

We can draw velocity vectors by using their dx, dy and dz divergence in X, Y and Z directions. Here below we used u for the dx and and v for the dy.

[crayon-672a3b7987a4a964132130/]

Here below is an old application example developed by me for the master thesis, which runs on the latest RAD Studio 10.4 (after 20+ years with few changes) . This shows how those procedures can be used to display velocity of fluid in a rectangular channel flow. This is a uniform fluid flow example in a rectangular duct.

Here is a result that shows a fluid flow in rectangular duck over a rectangular 2D object. After a while, results goes to display vortexes at around the object or at around the spaces at the back.

Now it is your turn 🙂 You can Win $1M! 😀 You can develop your own analyze applications with C++ Builder by using VCL or FMX frameworks and you can display your data. FMX has more options like using alpha colors, using opacity that may result better graphics. You can also add gradient colors these vectors to show their magnitude.

C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. There is a free C++ Builder Community Edition for students, beginners and startups, it can be downloaded from here. Professional developers can use the Professional, Architect or Enterprise versions of C++ Builder which has a trial version and can be downloaded from here.

Exit mobile version