Fluid Stream Simulator V2.0

Guides and discussions about building water blasters and other water warfare devices such as water balloon launchers.
Post Reply
User avatar
Chief
Posts: 48
Joined: Mon Dec 03, 2012 1:08 pm
Location: I live on the battle field!
WWN League Team: Catskill Mountain SEALs

Fluid Stream Simulator V2.0

Post by Chief » Sun Nov 17, 2024 10:22 am

Hello everyone!

I am starting this thread to accumulate feedback/ideas for a fluid simulator program I started development on earlier this year. This is a continuation of a brief discussion on the office Discord, but for anyone unfamiliar; The simulator is a JavaScript web application with the intent of calculating and visualizing fluid stream performance based on various parameters like water pressure, nozzle diameter, etc... I will link the GitHub page and source code below.

I will refer to the program in its current state as "V1". V1 may seem fairly accurate at first glance, however, as some have rightly pointed out, it is flawed and incomplete. Admittedly, I originally just made V1 to impress my coworkers, so I cut corners and faked results in areas where I did not fully understand the physics. The goal with V2 is to flesh out a fully (or at least mostly) accurate and functional program.

I have linked a Figjam board for planning out V2 (Figjam is a virtual white border app by the company Figma). I would love to hear any initial thoughts or suggestions. If anyone wants to contribute to the Figjam board, feel free to request edit access.



Some points for discussion:

- Inputs: What inputs would be useful? (see my current list in the "Inputs" section in Figjam)

- Calculations: Currently, I have a Bernoulli equation to get the initial velocity leaving the nozzle (x-axis), a drag equation to calculate water drop deceleration (x-axis), and a hacked-up version of Newton's gravity equations for calculating the water drop fall rate (y-axis). I am not confident this is the best approach. This is where I need the most help. Feedback is welcome!

- Outputs: What data would be useful? (see my current list in the "Outputs" section in Figjam)

- Features: Currently, the program's main area focus is the nozzle component of homemades, however, I wonder if other aspects of homemade construction could benefit from a simulator. This is more of a long-grass/wishlist for future versions.



Links:
V1 demo: https://kspangdg.github.io/water-stream-sim/
V1 source code: https://github.com/kspangdg/water-stream-sim
Figjam board: https://www.figma.com/board/WdIcVdrpUne ... NkGugLlR-1

Thanks in advance for any input!

User avatar
Chief
Posts: 48
Joined: Mon Dec 03, 2012 1:08 pm
Location: I live on the battle field!
WWN League Team: Catskill Mountain SEALs

Re: Fluid Stream Simulator V2.0

Post by Chief » Fri Nov 29, 2024 9:03 am

Quick update:

I pushed a few UI updates. Nothing has changed under the hood, but the v1 link I posted will look a little different visually now.

SSCBen
Posts: 1632
Joined: Sun Jul 04, 2004 4:15 pm
Contact:

Re: Fluid Stream Simulator V2.0

Post by SSCBen » Fri Nov 29, 2024 2:22 pm

Sorry for the delay. I've been busier than I had hoped. As I said on Discord, I need to make a Python implementation that you can convert to JS. It'll probably take a day or two for me to get it right, maybe more. I'm on leave from work right now but have some more pressing priorities. I'll get back to you on Dec. 8 with an update.

The approach I'll use will have a lot of different knobs to turn. Particularly important are the breakup length and maximum droplet size to handle the effects of different nozzle shapes beyond the nozzle diameter. Simulating the effect of the nozzle shape itself on the breakup length and droplet sizes unfortunately is not feasible so these will have to be found from empirical data.

User avatar
Chief
Posts: 48
Joined: Mon Dec 03, 2012 1:08 pm
Location: I live on the battle field!
WWN League Team: Catskill Mountain SEALs

Re: Fluid Stream Simulator V2.0

Post by Chief » Thu Dec 05, 2024 3:54 pm

No worries, there is no rush. I am a bit busy with the holidays as well.

Feel free to add or subtract as many different knobs/sliders as you see fit. I left the previous ones to help me create the styles/UI, but with the assumption that we would change them with the new calculations. Thanks again! I look forward to it.

SSCBen
Posts: 1632
Joined: Sun Jul 04, 2004 4:15 pm
Contact:

Re: Fluid Stream Simulator V2.0

Post by SSCBen » Sun Jan 19, 2025 4:54 pm

I haven't had as much time as I wanted to work on this, but I knocked out something very basic today. Simple forward Euler time stepping (which is inaccurate but fine for a demo). It passes a spot check, but I haven't done any detailed tests.

I think we can start with this. See if you can make sense of my code. If not, I'll help you out when I have the time.

For clarity, some of the equations come from my dissertation. That might be a good reference if you want something with actual pictures and math, though I don't know how familiar you are with differential equations.

Code: Select all

# MIT License
# 
# Copyright (c) 2025 Ben Trettel
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

#import unittest

# numerical parameters
dt  = 1.0e-4 # s, time step
n_d = 1000   # number of droplets

def avg_x_b_s(Tubar_0, We_l0):
    # breakup length, trettel_turbulent_2020 eq. 3.28
    return 3.61 * Tubar_0**-0.275 * We_l0**0.334

class Droplet:
    def __init__(self, rho_w, Ubar_0, d_0, sigma, Tubar_0, D_max_s, h_0, theta_0):
        import random
        from math import cos, sin, pi
        
        We_l0 = rho_w*Ubar_0**2*d_0/sigma
        
        # Each droplet has a randomly generated size and breakup time.
        # This is definitely simplified over reality but should be reasonable to start.
        self.d   = D_max_s * d_0 * random.random() # m, droplet diameter
        self.t_b = (d_0 * avg_x_b_s(Tubar_0, We_l0) / Ubar_0) * (1.0 + sigma_b*2.0*(random.random() - 0.5)) # s, breakup time
        
        self.x = 0.0 # m/s, droplet x location
        self.y = h_0 # m/s, droplet y location
        
        self.u = Ubar_0*cos(theta_0) # m/s, droplet x velocity
        self.v = Ubar_0*sin(theta_0) # m/s, droplet y velocity
        
        self.m_d = (pi/6.0)*rho_w*self.d**3 # kg, mass of droplet
        self.a_d = (pi/4.0)*self.d**2       # m2, droplet projected area

if __name__ == "__main__":
    from math import pi, sqrt
    
    # physical parameters
    D_max_s = 0.7     # D_max/d_0, trettel_turbulent_2020 p. 198 (corrected)
    C_d     = 0.42    # drag coefficient, loth_quasi-steady_2008
    alpha   = 0.05    # entrainment coefficient, trettel_turbulent_2020 p. 179
    sigma_b = 0.13190 # breakup length standard deviation (conductivity_plots.m, trettel_turbulent_2020 p. 177)
    
    rho_w   = 1000.0  # kg/m3, mass density of water
    sigma   = 72.8e-3 # N/m, surface tension of water
    rho_g   = 1.293   # kg/m3, mass density of air
    g       = 9.81    # m/s2, gravitational acceleration
    
    h_0     = 1.5     # m, firing height
    theta_0 = 35.0*(pi/180.0) # radians, firing angle above horizontal
    Tubar_0 = 0.01    # dimensionless, turbulence intensity
    d_0     = 0.00635 # m, nozzle diameter
    Q       = 100     # mL/s, flow rate
    
    A_0    = (pi/4.0)*d_0**2 # m2, nozzle area
    Ubar_0 = (Q*1.0e-6)/A_0  # m/s, jet velocity
    
    # Create droplets at initial conditions
    ds = []
    for i_d in range(n_d):
        ds.append(Droplet(rho_w, Ubar_0, d_0, sigma, Tubar_0, D_max_s, h_0, theta_0))
    
    # time stepping
    t = 0.0
    any_droplets_above_ground = True
    while any_droplets_above_ground:
        t = t + dt
        any_droplets_above_ground = False
        
        for i, d in enumerate(ds):
            # Update list elements in place for simplicity.
            # I will want to change that later for better time integration schemes.
            #print(t, d.x, d.y, d.u, d.v)
            
            ds[i].x = d.x + dt*d.u
            ds[i].y = d.y + dt*d.v
            
            if t > d.t_b:
                u_g     = alpha*d.u # estimate of gas x velocity
                v_g     = alpha*d.v # estimate of gas y velocity
                rel_u   = d.u - u_g
                rel_v   = d.v - v_g
                rel_vel = sqrt(rel_u**2 + rel_v**2)
                drag_x  = -0.5*rho_g*C_d*d.a_d*rel_vel*rel_u/d.m_d
                drag_y  = -0.5*rho_g*C_d*d.a_d*rel_vel*rel_v/d.m_d
            else:
                drag_x = 0.0
                drag_y = 0.0
            
            ds[i].u = d.u + dt*drag_x
            ds[i].v = d.v + dt*(-g + drag_y)
            
            if not any_droplets_above_ground:
                if ds[i].y > 0.0:
                    any_droplets_above_ground = True

User avatar
Chief
Posts: 48
Joined: Mon Dec 03, 2012 1:08 pm
Location: I live on the battle field!
WWN League Team: Catskill Mountain SEALs

Re: Fluid Stream Simulator V2.0

Post by Chief » Wed Feb 26, 2025 8:15 am

Thank you so much for writing this! I'm sorry for my delayed response. I moved to PA this month and am wrapping up some large projects at work.

I plan to work on this later next month. By then, things should have slowed down. I will let you know if I have any questions. I am excited to see the new calculations in action!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest