Showing posts with label gaming. Show all posts
Showing posts with label gaming. Show all posts

Monday, 7 July 2025

A Simplified Immersed Boundary Method using Ray Casting

     Yours truly is an avid gamer, @fadoobaba (YouTube). The ray casting algorithm๐Ÿ›ธ; a fundamental ๐Ÿงฑ technique used in video game ๐ŸŽฎ development and computer graphics, has been implemented within the finite difference method ๐Ÿ code yours truly has been developing. In abundant spare time, of course๐Ÿ˜ผ. In this post, this method is explained. For details about ray casting using matplotlib.path, refer to here. For validation of the code, refer to here, backwards-facing step, curved boundaries, here (moving cylinder) and here.

NOTE: This method requires a GPU, if dear readers don't have a GPU then please stop being peasants... ๐Ÿ™‰

     If you plan to use these codes in your scholarly work, do cite this blog as:

     Fahad Butt (2025). S-IBM (https://fluiddynamicscomputer.blogspot.com/2025/07/a-simplified-immersed-boundary-method.html), Blogger. Retrieved Month Date, Year

     The first step is to setup the polygon ๐Ÿ . The polygon = cp.column_stack((x1, y1)) statement is used to combine x1 and y1 into a single array representing the polygon vertices. The following statements are used to store the x and y coordinates of the polygon vertices and nvert is the total number of vertices.

px = polygon[:, 0]

py = polygon[:, 1]

nvert = len(polygon)

     The boolean masks ๐Ÿ‘บ are then initialized. The following arrays track whether a grid point is inside the polygon based on horizontal and vertical ray intersections. False = outside ❌, True = inside ✅. Then a loop is implemented to for each edge ๐Ÿ“ of the polygon, defined by vertices i (current) and j (previous), with % nvert ensuring the polygon is closed (last vertex connects back to the first). (xi, yi) and (xj, yj) define the current edge and previous edge.

horizontal_inside = cp.zeros_like(test_x, dtype=bool) 

vertical_inside = cp.zeros_like(test_x, dtype=bool) 

for i in range(nvert):

    j = (i - 1) % nvert

xi, yi = px[i], py[i]

xj, yj = px[j], py[j]

     A check ⁉️ is performed to ensure a ray crosses the polygon edge once. cond1 statement checks if the test point lies between the y-values of the edge's endpoints i.e., a ray could cross it. intersect_x finds where the edge crosses a horizontal line at test_y. cond2 checks if the intersection lies to the right of the test point. ^= is XOR toggles the "inside" state each time the ray crosses an edge. The addition of small term ~1e-16 prevents division by zero for horizontal edges. Similar method is applied to verify the points using vertical ray. cond3 checks if the edge crosses a vertical ray (top to bottom) from (test_x, test_y). slope1 and intersect_y computes where the vertical ray at x=test_x intersects the edge. A point is inside only if both horizontal and vertical rays classify it as inside. A point is considered inside the foil only if both ray checks are true. curve is the 2D boolean mask of grid points inside the foil body.

cond1 = ((yi > test_y) != (yj > test_y))

slope = (xj - xi) / (yj - yi + 1e-16)

intersect_x = slope * (test_y - yi) + xi

cond2 = test_x < intersect_x 

horizontal_inside ^= cond1 & cond2

cond3 = ((xi > test_x) != (xj > test_x))

slope1 = (yj - yi) / (xj - xi + 1e-16)

intersect_y = slope1 * (test_x - xi) + yi

cond4 = test_y < intersect_y

vertical_inside ^= cond3 & cond4

inside = horizontal_inside & vertical_inside

curve = inside.reshape(X.T.shape)

     Using both horizontal and vertical rays reduces false positives (e.g., near sharp corners). The & ensures only points unambiguously inside are marked. Within Fig. 1, the points on the shape boundary, points inside ๐Ÿชฐ and outside ๐ŸŒ the shape boundary are shown. A point is a boundary if it is inside the body, but any of its neighbors is outside. Following statements are used to mark the boundary of the object. Boundary detects the "skin" of the body for applying no-slip, force, or stress conditions.

interior = curve[1:-1, 1:-1]

right = curve[2:, 1:-1]

left = curve[:-2, 1:-1]

top = curve[1:-1, 2:]

bottom = curve[1:-1, :-2]

boundary = interior & ~(right & left & top & bottom)

     The statements boundary_indices = cp.where(boundary_mask) ... valid_right = (boundary_indices[0] + 1 < X.shape[0]) & (~curve[right_neighbors]) ... etc. extract boundary indices and their valid neighbors i.e. these lines extract the (i, j) grid indices of the surface and locate which neighbor cells are valid fluid neighbors (outside the body and within domain bounds). These are needed to compute normals or apply boundary conditions via interpolation or extrapolation from the fluid.
Fig. 1, Mesh cells


     For validation of the results from present simulations, the case of flow around a circular cylinder is selected. Fig. 1 shows the results from the code at Re 200. The drag coefficient obtained from this code is 1.396 while from the literature, the value is at 1.4 [1]. The lift coefficient from the code is at 0.000134. Within Fig. 2, top row shows u and v velocity components and bottom row shows pressure and vorticity.


Fig. 2, The flow-field

     For the second an more complex validation case, a swimming fish is simulated. The lift and drag coefficients obtained from the simulation are compared with experimental results. The drag coefficient from the current code is at 0.342 while from the published literature, the value is at 0.348. Maximum lift coefficient is at 7.243 and 8 from the present code as compared to the published literature [2]. Within Fig. 3 the u and v velocities, pressure and velocity streamlines are shown for St = 0.8 and Reynolds number of 500. The computational mesh near the fish is shown in Fig. 4. Within Fig.4, a zoomed in view towards the right shows the mesh at the trailing edge of the fish.


Fig.3, Post-processing of results

Fig. 4, The mesh

     This method allows handling arbitrary deforming / non-deforming shapes on a fixed Cartesian grid. In summary, the method has the following steps.

1. Generate polygon shape (e.g., airfoil, cylinder)

2. Flatten mesh for vectorized testing

3. Use ray casting to check if points are inside shape

4. Build a boolean mask of body region

5. Identify surface (boundary) points

6. Extract boundary indices for physics coupling


References

     [1] Braza M, Chassaing P, Minh HH. Numerical study and physical analysis of the pressure and velocity fields in the near wake of a circular cylinder. Journal of Fluid Mechanics. 1986;165:79-130. doi:10.1017/S0022112086003014

     [2] Fulong ShiJianjian XinChuanzhong OuZhiwei LiXing ChangLing Wan; Effects of the Reynolds number and attack angle on wake dynamics of fish swimming in oblique flows. Physics of Fluids 1 February 2025; 37 (2): 025205 doi.org/10.1063/5.0252506

     Thank you for reading! If you want to hire me as a post-doc researcher in the fields of thermo-fluids and / or fracture mechanics, do reach out!

Thursday, 21 December 2017

Coffee Lake Configurations for Computational Fluid Dynamics and Gaming with no Mechanical Storage, Pakistani Market Prices.

     These setups feature no mechanical hard drive(s).

Estimated price PKR 205,000.

     For the processor, choose the Intel Core i7-8700 for PKR 43,000. Motherboard of choice should be the Gigabyte Z370 AORUS Gaming 3 for PKR 20,500. For memory, go with the Corsair Vengeance LPX 1x16GB DDR4-3000 for PKR 23,000. Samsung 850 EVO 1TB SSD for PKR 39,500 should be the only storage option. The Gigabyte GV-N1080WF3OC-8GD GeForce GTX 1080 for PKR 68,500 graphics card. The Corsair Carbide SPEC-04 Casing for PKR 5,500. Powering the whole thing should be at least a Thermaltake Lite-Power 550W PSU for PKR 4,400.

Estimated price PKR 157,000.

     For the processor, choose the Intel Core i7-8700 for PKR 43,000. Motherboard of choice should be the Gigabyte Z370 AORUS Gaming 3 for PKR 20,500. For memory, go with the Corsair Vengeance LPX 1x16GB DDR4-3000 for PKR 23,000. Samsung 850 EVO 1TB SSD for PKR 39,500 should be the only storage option. The Asus PH-GTX1050TI-4G GTX 1050Ti for PKR 21,300 graphics card. The Corsair Carbide SPEC-04 Casing for PKR 5,500. Powering the whole thing should be at least a Thermaltake Lite-Power 550W PSU for PKR 4,400.

Estimated price PKR 167,500.

     For the processor, choose the Intel Core i5-8700 for PKR 23,000. Motherboard of choice should be the Gigabyte Z370 AORUS Gaming 3 for PKR 20,500. For memory, go with the Corsair Vengeance LPX 1x16GB DDR4-3000 for PKR 23,000. Western Digital Green 240GB and Blue 500GB SSD for PKR 9,500 and PKR 17,500 should be the storage options. The Gigabyte GV-N1080WF3OC-8GD GeForce GTX 1070Ti for PKR 64,000 graphics card. The Corsair Carbide SPEC-04 Casing for PKR 5,500. Powering the whole thing should be at least a Thermaltake Lite-Power 550W PSU for PKR 4,400.

Estimated price PKR 137,000.

     For the processor, choose the Intel Core i5-8700 for PKR 23,000. Motherboard of choice should be the Gigabyte Z370 AORUS Gaming 3 for PKR 20,500. For memory, go with the Corsair Vengeance LPX 1x16GB DDR4-3000 for PKR 23,000. Western Digital Blue 500GB SSD for PKR 17,500 should be the storage option. The Asus STRIX-GTX1060-DC2O6G GTX 1060 for PKR 43,000 graphics card. The Corsair Carbide SPEC-04 Casing for PKR 5,500. Powering the whole thing should be at least a Thermaltake Lite-Power 550W PSU for PKR 4,400.

Estimated price PKR 106,000.

     For the processor, choose the Intel Core i3-8100 for PKR 14,500. Motherboard of choice should be the Gigabyte Z370 AORUS Gaming 3 for PKR 20,500. For memory, go with the Corsair Vengeance LPX 1x16GB DDR4-3000 for PKR 23,000. Western Digital Blue 500GB SSD for PKR 17,500 should be the storage option. The Asus PH-GTX1050TI-4G GTX 1050Ti for PKR 21,300 graphics card. The Corsair Carbide SPEC-04 Casing for PKR 5,500. Powering the whole thing should be at least a Thermaltake Lite-Power 450W PSU for PKR 3,800.

     Only the first configuration is suitable for both gaming and computational fluid dynamics (CFD). If you need a system for CFD alone, then the second configuration will be sufficient, all other configurations can be referred to as general purpose gaming PCs.

Monday, 7 October 2013

Entry Level CPU Build Guide for Word Processing and Browsing; for October 2013 (Pakistan Market Prices and Parts Availability)

 
 
This is the least expensive, the most basic build guide, based on the parts available in Pakistan. This build is recommended for casual users and students wanting a basic computer for Microsoft® Office work. And for those who run games on consoles.

CPU

Intel® Pentium™ G-2020 Processor (3M Cache, up to 2.90 GHz) ~6,500 PKR, It has 2 cores and no HT technology, will perform everyday tasks like charm! It will struggle a with the running games at medium-low resolution. Just recommended for word processing and Internet.

Motherboard

Intel® Desktop Board DH61CR ~5,500 PKR, using 3rd party mother boards is not recommended in Pakistan because of no-warranty issues. Most of the importers buy from Intel and they come with warranty, others simply don't. This board supports 4 3 GB/s SATA, USB and PCI-e 2.1.

PSU + Case + Extra Fan

~3,000 PKR. For this build you can go for the built in 300 Watt power supply that comes with you casing, but due to large time spent gaming and/or rendering and due to hot temperature in Pakistan, the system heats up pretty bad, so be SURE to buy and add an extra 90 mm fan.

RAM

Kingston® KVR16N11/2 2 GB DDR 3 1600 MHz, ~2,000PKR  x1, as RAM is expensive these days, was at around half the price last year, so go for 1 DIMM 2 GB memory. (capacity of the recommended motherboard is 8GBx2 = 16 GB maximum).

HD

Seagate® Barracuda™ 7200 rpm 32 MB Cache 500 GB ~6,500 PKR. Buy the smallest/cheapest capacity/price available because most of us pre own portable hard drives anyway, use them for backup.

Optical Drive

Yeah, it was something too, something dinosaurs used! NOT recommended. Just wastage of money! We use USB ports to install any of the current OS, obviously. but of you don't have the ability to install the OS from USB port, or are afraid to make changes to your BIOS, please buy yourself a Super Drive.

WIFI

TP Link® WN722N ~1,000 PKR, it is a must as most of us have WIFI routers these days, so to get internet to your desktop, you will have to use this or a ~2,500 PKR 50+ meter LAN cable. The choice is yours! This isn't even a hard one!
This all adds up to 27,000 PKR without Graphics Card, Keyboard, Mouse, Speakers and a Monitor which most of us pre own and do not change for ~8-10 years.
If you are buying everything from start, add ~2,500 PKR for keyboard and mouse, and ~12,000 for 900p monitor (Dell® or HP® only because of warranty issues).

 
 
For suggestions, send an email to fadoobaba@live.com , tweet @fadoobaba, PM at https://www.facebook.com/ThreeDimensionalDesign or https://grabcad.com/fahad.rafi.butt or comment with your contact details and I will contact you!. Thank you for reading!

Do comment and share!

Haswell Powered CPU Build Guide for Low End Gaming, Word Processing and Browsing; for October 2013 (Pakistan Market Prices and Parts Availability)

This build is recommended for casual CAD users, rendering at very high resolution will take lot of time on this build, nearly impossible and very casual gamers.

CPU

Intel® Core™ i3-4130 Processor (3M Cache, up to 3.40 GHz) ~15,000 PKR, average rendering performance, it will stay for 3 years easy! It has 2 cores and HT technology, will perform everyday tasks and simple CAD tasks like charm! It will struggle a bit with the rendering software and large CAD assemblies, and of course running games at high resolution.

Motherboard

Intel® Desktop Board DB85FL ~10,000 PKR, using 3rd party mother boards is not recommended in Pakistan because of no-warranty issues. Most of the importers buy from Intel and they come with warranty, others simply don't. This board supports 4 6 GB/s SATA, USB and PCI-e 3.0.

PSU + Case + Extra Fan

~3,000 PKR. For this build you can go for the built in 300 Watt power supply that comes with you casing, but due to large time spent gaming and/or rendering and due to hot temperature in Pakistan, the system heats up pretty bad, so be SURE to buy and add an extra 120 mm fan.

RAM

Kingston® KVR16N11/4 4 GB DDR 3 1600 MHz, ~4,000PKR  x1, as RAM is expensive these days, was at around half the price last year, so go for 1 DIMM 4 GB memory. I don't recommend buying 2x DIMM of 2GB capacity, because if you want to upgrade to full capacity later (and most of you will, that's why one buys a Desktop and not a Craptop), (capacity of the recommended motherboard is 8GBx4 = 32 GB maximum) it will not use up extra DIMM slot.

HD

Seagate® Barracuda™ 7200 rpm 32 MB Cache 500 GB ~6,500 PKR. Buy the smallest/cheapest capacity/price available because most of us pre own portable hard drives anyway, use them for backup.

Optical Drive

Yeah, it was something too, something dinosaurs used! NOT recommended. Just wastage of money! We use USB ports to install any of the current OS, obviously. but of you don't have the ability to install the OS from USB port, or are afraid to make changes to your BIOS, please buy yourself a Super Drive.

WIFI

TP Link® WN722N ~1,000 PKR, it is a must as most of us have WIFI routers these days, so to get internet to your desktop, you will have to use this or a ~2,500 PKR 50+ meter LAN cable. The choice is yours! This isn't even a hard one!
This all adds up to 40,000 PKR without Graphics Card, Keyboard, Mouse, Speakers and a Monitor which most of us pre own and do not change for ~8-10 years.
If you are buying everything from start, add ~2,500 PKR for keyboard and mouse, and ~12,000 for 900p monitor (Dell® or HP® only because of warranty issues).

 
For suggestions, send an email to fadoobaba@live.com , tweet @fadoobaba, PM at https://www.facebook.com/ThreeDimensionalDesign or https://grabcad.com/fahad.rafi.butt or comment with your contact details and I will contact you!. Thank you for reading!

Do comment and share!
 

Haswell Powered CPU Build Guide for Medium Gaming and Entry Level CAD; for October 2013 (Pakistan Market Prices and Parts Availability)

 
This build is recommended for regular CAD users, rendering at very high resolutionwill take lot of time on this build. and casual gamers (which most of us are).

CPU

Intel® Core™ i5-4670 Processor (6M Cache, up to 3.50 GHz) ~22,000 PKR, exceptional value for money, average rendering performance, it will stay for 4 years easy! It has 4 cores and no HT technology, but will perform everyday gaming and CAD tasks like charm!

Motherboard

Intel® Desktop Board DB85FL ~11,000 PKR, using 3rd party mother boards is not recommended in Pakistan because of no-warranty issues. Most of the importers buy from Intel and they come with warranty, others simply don't. This board supports 4 6 GB/s SATA, USB and PCI-e 3.0.

GPU

MSI® NVidia™ GeForce GT 640 GDDR3 2 GB ~10,000 PKR, great value for money too, will easily run all existing games (~30 fps), and all to be released games at low-medium settings at a minimum of ~30 fps for at least 2 more years.

PSU + Case + Extra Fan

Corsair® VS 450 400 Watt PSU + Casing ~5,000 PKR (after the price for built-in PSU is subtracted). In Rendering, the CPU goes to full power and beyond (Intel® Turbo Boost) so power consumption increases, same applies to GPU when gaming, you will probably use 300 Watt maximum, but as PSU gets older (after 3-4 years minimum) the output wattage decrease, so to make up for that, initially buy a slightly larger wattage PSU. Also due to large time spent gaming and/or rendering, the system heats up pretty bad, so be SURE to buy and add an extra 90 mm fan.

RAM

Kingston® KVR16N11/8 8 GB DDR 3 1600 MHz, ~8,000PKR  x1, as RAM is expensive these days, was at around half the price last year, so go for 1 DIMM 8 GB memory. I don't recommend buying 2x DIMM of 4GB capacity, because if you want to upgrade to full capacity later (and most of you will, that's why one buys a Desktop and not a Craptop), (capacity of the recommended motherboard is 8GBx4 = 32 GB maximum) it will not use up extra DIMM slot.

HD

Seagate® Barracuda™ 7200 rpm 32 MB Cache 500 GB ~6,500 PKR. I don't recommend buying a hard disk anymore because it will slow your system down, buy a 180 GB SSD instead. Believe me, 180 GB is enough space, most of us pre own Portable HD anyway, so use that for back up. If you want a HD buy the smallest/cheapest capacity/price available.

Optical Drive

Yeah, it was something too, something dinosaurs used! NOT recommended. Just wastage of money! We use USB ports to install any of the current OS, obviously.

WIFI

TP Link® WN722N ~1,000 PKR, it is a must as most of us have WIFI routers these days, so to get internet to your desktop, you will have to use this or a ~2,500 PKR 50+ meter LAN cable. The choice is yours! This isn't even a hard one!
This all adds up to 70,000 PKR without SSD, Keyboard, Mouse, Speakers and a Monitor which most of us pre own and do not change for ~8-10 years.
If you are buying everything from start, add ~2,500 PKR for keyboard and mouse, and ~12,000 for 900p monitor (Dell® or HP® only because of warranty issues).

 
For suggestions, send an email to fadoobaba@live.com , tweet @fadoobaba, PM at https://www.facebook.com/ThreeDimensionalDesign or https://grabcad.com/fahad.rafi.butt or comment with your contact details and I will contact you!. Thank you for reading!

Do comment and share!

Haswell Powered CPU Build Guide for Hi-End Gaming and CAD; for October 2013 (Pakistan Market Prices and Parts Availability)

 
This build is recommended for those who use CAD software daily and render their models as well at a high resolution. And do PC gaming as well.

CPU

Intel® Core™ i7-4770 Processor (8M Cache, up to 3.90 GHz) ~34,000 PKR, exceptional value for money, excellent render performance, it will stay for 5 years easy! Comes with 8 cores! Do I need say more? :)

Motherboard

Intel® Desktop Board DH87MC ~12,000 PKR, using 3rd party mother boards is not recommended in Pakistan because of no-warranty issues. Most of the importers buy from Intel and they come with warranty, others simply don't. This board supports 6 6 GB/s SATA, USB and PCI-e 3.0.

GPU

MSI® NVidia™ GeForce GTX 650 GDDR5 2 GB ~15,000 PKR, great value for money too, will easily run all existing games (50+ fps), and all to be released games at maximum settings at a minimum of ~30 fps for at least 2 more years. And lets face it, AMD is crap! ;)

PSU + Case + Extra Fan

Corsair® VS 500 500 Watt PSU + Casing ~6,000 PKR (after the price for built-in PSU is subtracted). In Rendering, the CPU goes to full power and beyond (Intel® Turbo Boost) so power consumption increases, same applies to GPU when gaming, you will probably use 400 Watt maximum, but as PSU gets older (after 3-4 years minimum) the output wattage decrease, so to make up for that, initially buy a slightly larger wattage PSU. Also due to large time spent gaming and/or rendering, the system heats up pretty bad, so be SURE to buy and add an extra 120 mm fan.

RAM

Kingston® KVR16N11/8 8 GB DDR 3 1600 MHz, ~8,000PKR  x1, as RAM is expensive these days, was at around half the price last year, so go for 1 DIMM 8 GB memory. I don't recommend buying 2x DIMM of 4GB capacity, because if you want to upgrade to full capacity later (and most of you will, that's why one buys a Desktop and not a Craptop), (capacity of the recommended motherboard is 8GBx4 = 32 GB maximum) it will not use up extra DIMM slot.

HD

Seagate® Barracuda™ 7200 rpm 32 MB Cache 500 GB ~6,500 PKR. I don't recommend buying a hard disk anymore because it will slow your system down, buy a 180 GB SSD instead. Believe me, 180 GB is enough space, most of us pre own Portable HD anyway, so use that for back up. If you want a HD buy the smallest/cheapest capacity/price available.

SSD

Kingston® SV300S37A/60G 60 GB ~6,500PKR. This 6GB/s SSD boots Microsoft's® Windows™ 8.1 RTM in 10 seconds ONLY! Get the point I was making earlier? Go for Kingston because warranty issues, again importers do not buy from Intel in case of SSD, but from Corsair and Kingston.

Optical Drive

Yeah, it was something too, something dinosaurs used! NOT recommended. Just wastage of money! We use USB ports to install any of the current OS, obviously.

WIFI

TP Link® WN722N ~1,000 PKR, it is a must as most of us have WIFI routers these days, so to get internet to your desktop, you will have to use this or a ~2,500 PKR 50+ meter LAN cable. The choice is yours! This isn't even a hard one!
This all adds up to 89,000 PKR without Keyboard, Mouse, Speakers and a Monitor which most of us pre own and do not change for ~8-10 years. And with 60 GB SSD and 500 GB HD.
If you are buying everything from start, add ~2,500 PKR for keyboard and mouse, and ~12,000 for 900p monitor (Dell® or HP® only because of warranty issues).

 

For suggestions, send an email to fadoobaba@live.com , tweet @fadoobaba, PM at https://www.facebook.com/ThreeDimensionalDesign or https://grabcad.com/fahad.rafi.butt or comment with your contact details and I will contact you!. Thank you for reading!

Do comment and share!