Internally, BlasterSim simulate blasters using control volumes with arbitrary flow connections between control volumes. This allows BlasterSim to simulates spring and pneumatic blasters with the same core simulation code. This also allows simulating more atypical blasters without major code changes.
An isolated control volume numbered is shown in figure 2.1. A single flow connection to the control volume numbered is shown with mass flow rate , a projectile/plunger labeled p with mass , a spring with stiffness , mass , and spring precompression (see figure 1.2 for a graphical definition), cross-sectional area , projectile/plunger position and velocity , and gas mass and energy .
The integers and will be used as indices for control volumes.
Gas mass and energy as chosen as these are conserved variables and it is believed that using conserved variables will lead to better conservation properties in the numerical methods.
A control volume represented like this can be used to represent a variety of scenarios relevant to gas gun interior ballistics, including:
a barrel, where p represents the projectile, represents the projectile location, and and are set to zero;
a plunger tube for springers where p represents the plunger head, and represents the plunger head location;
a constant volume chamber for pneumatics where p represents a solid wall, is set to infinity, and and are set to zero;
a piston tube used in HPA Nerf blasters similar to a plunger tube; and
a constant pressure atmosphere where is arbitrary, and and are set to zero.
The gas mass could be composed of multiple species in BlasterSim. At the moment, the pneumatic and springer modes of BlasterSim use only dry air, but humidity and alternative gases are intended to be added in the future. For completeness, this guide will be written as if multiple gas species are present. The mass fraction and gas species index which identifies the gas are used.
In the typeset math in this documentation, when there are separate intensive and extensive versions of the same quantity, the two will be distinguished by making the extensive version uppercase and the intensive version lowercase. For example, internal energy per unit mass is and internal energy is . Note that this convention is not followed in the typeset math when it is conventional to make an extensive quantity lowercase (like mass ) or an intensive quantity uppercase (like ), only when there are separate intensive and extensive versions of the same quantity. This capitalization convention is not followed in BlasterSim’s source code. See § 4.3 for a discussion of the capitalization convention followed in the source code. Because each variable in BlasterSim’s source code is given a unit (see § 3.1.3), whether a quantity is extensive or intensive can be determined from the units for that quantity, if unclear.
| (2.1) |
| (2.2) |
| (2.3) |
| (2.4) |
| (2.5) |
| (2.6) |
| (2.7) |
Beater [1, ch. 5]
Valves do not open instantaneously, and sometimes slow opening has a significant impact on performance. BlasterSim models how far a valve is open with a prescribed valve opening model. is the valve opening fraction, which is how open the valve is. is fully closed and is fully open. The specific equation BlasterSim uses is
| (2.8) |
for . For , . is the initial (time zero) valve opening fraction (useful when a valve isn’t used like in a springer). is the initial valve opening rate. is the valve opening time, the time it takes for the valve to fully open (reach ).
This equation may seem overly complicated, but is the simplest polynomial equation that satisfies a few constraints:
| (set initial valve opening fraction) | (2.9) | ||||
| (set initial valve opening rate) | (2.10) | ||||
| (2.11) | |||||
| (needed for automatic differentiation) | (2.12) |
When the valve is fully open, no longer changes with time, so its derivative is zero. Consequently, the last constraint listed is needed to match the derivative at , which is necessary for automatic differentiation. See § 2.2.2 for more about automatic differentiation in BlasterSim. The last constraint prevents a simple linear model () from being used.
Note that to ensure monotonicity of (in other words, avoid oscillations of the valve opening fraction), must satisfy the inequality .
The pneumatic and springer cases will now be discussed, with the subscript dropped for simplicity as there is only one flow restriction in both cases.
For pneumatics, and . The second condition approximates a simple linear model. In the future may become an input parameter if deemed necessary to improve accuracy. The SpudFiles Wiki [11] gives some estimated opening times:
Burst disks: likely under 1 ms
Pilot-operated valves (like QEVs, “back-pressure tanks”, “cores”): 3–5 ms
Ball valves: about 100 ms if hand activated
These values are recommended as starting points only. For modeling any particular blaster, it is better to try to independently determine the valve opening time through something like high speed video.
For springers, and . As there is no valve in a springer, this simply sets the flow restriction to always be open.
This simple valve opening model is most accurate for manually operated valves. More detailed modeling of pilot-operated valves could make determining the valve opening time unnecessary, but this alternative valve opening model has not yet been added to BlasterSim.
| (2.13) | ||||
| (2.14) |
When a spring is present, the effective mass of the plunger factors in the spring mass. The spring is not moving at a uniform velocity as one end is stationary, so it would be incorrect to add all the spring mass to the effective mass. The effective mass equation used is
| (2.15) |
where as suggested by Ruby [9] for a stiff spring.
Note that the variable in equation 2.14 internally in BlasterSim differs from x as printed by BlasterSim in the CSV output. To ease understanding for users of BlasterSim, x in the CSV output is defined as the distance between the projectile/plunger location and the minimum location like the end of the plunger tube. Mathematically, .
Consider a projectile/plunger p with both static and dynamic friction. BlasterSim uses an effective friction pressure defined to oppose the direction of motion. Using a pressure instead of force allows for more familiar units and is conventional in spud guns. The maximum static friction pressure is and the magnitude of the dynamic friction pressure is . When static friction is active, the actual static friction force is just enough force to equilibrate the forces so that p doesn’t move (where ; see equation 2.14), until the force exceeds the maximum static friction force. In other words, the actual static friction pressure is the minimum of the equilibrium pressure or the maximum static friction pressure, and in the direction of the equilibrium pressure. Mathematically, this can be stated as
| (2.16) |
The actual dynamic friction pressure is , taking into account both the magnitude of the dynamic friction pressure and the direction.
The effective friction pressure then will switch between static and dynamic friction depending on the velocity:
| (2.17) |
BlasterSim does not use this model because it is not smooth. Smooth functions are useful for automatic differentiation (see § 2.2.2) and beneficial for numerical stability. Also, the use of strict floating point equality in the branch can lead to numerical reproducibility issues. BlasterSim uses a smoothed version of this model which avoids these problems.
To create a smoothed version of equation 2.17, it’s helpful to first rewrite equation 2.17 in terms of the function:
| (2.18) |
The smooth approximation to equation 2.17 will be made by noting that
| (2.19) |
where is a small velocity scale over which the function changes from -1 to 1.
Consequently, the function implemented in cva.f90 as p_f is
| (2.20) |
In equation 2.20, instead of a single , two different velocity scales and are used to allow for finer control. Note that contrary to the non-smooth model (equation 2.17), the absolute value of equation 2.20 is not guaranteed to be at most or . To avoid the magnitude of the friction pressure from going above what a user likely intended, is made much smaller than . The bounds violation comes from both terms changing at the same time, so it is believed making the two scales very different so that one finishes changing sooner than the other will avoid this problem.
Making a smooth approximation for is more difficult. Rather than replacing a single part of equation 2.16, an new function was constructed that does not resemble equation 2.16 algebraically but takes similar values. A piecewise function is implemented in cva.f90 as p_f0 so that the actual static friction pressure equals the equilibrium pressure for small values of :
| (2.21) |
where is chosen to be a somewhat arbitrary fraction of and
| (2.22) |
defined in this way will exactly balance static friction up to an equilibrium pressure of , and smoothly transition to the maximum static friction after that.
Note that despite the appearance of and , equation 2.21 is continuous and has continuous derivatives as those terms only become discontinuous at and do not appear in the branch where .
Equation 2.22 can be derived starting with a function written in the following form:
| (2.23) |
and finding the values of the coefficients , , and that satisfy the following constraints:
| (continuity of value) | (2.24) | ||||
| (continuity of derivative) | (2.25) | ||||
| (maximum static friction pressure) | (2.26) |
When the plunger impacts the end of the plunger tube, the plunger tube will rebound. The amount of rebound can be controlled through the coefficient of restitution, [2, pp. 524–525], which varies between 0 and 1. The velocity of the plunger before impact, , is related to the velocity of the plunger after impact, :
| (2.27) |
The negative sign shows that the plunger will change from moving towards the end of the plunger tube to moving away from the end of the plunger tube.
The amount of energy dissipated in the impact, is tracked in BlasterSim for each control volume:
| (2.28) |
Tracking the total amount of energy dissipated in impact can be useful to improve blaster longevity.
If the coefficient of restitution is zero so that the plunger velocity after impact is zero, BlasterSim applies an approximation for the moment. The plunger will become immobile after impact. This approximation is a simple way to prevent simulation progress from stalling. After impact, the plunger tube is located at the end of the plunger tube. If the coefficient of restitution is zero, then the plunger will initially have zero velocity after impact. However, the force on the plunger will push it past the end of the plunger tube in the simulation. BlasterSim simply identifies when the plunger moves past the end of the plunger tube and picks a time step to exactly hit the end of the plunger tube. BlasterSim at the moment does not additionally apply an extra force to prevent the plunger from moving if it is at the end of the plunger tube, which would be more physically realistic. Consequently, to prevent the plunger tube from moving, it is made immobile in this situation. In the future, if desirable, BlasterSim could apply a force when the plunger is at the end of the plunger tube to keep the plunger stationary. The difference with the force is that it might be possible for the force to be overcome by the pressure inside the plunger, making the plunger start moving again. Making the plunger immobile prevents that motion, but is a reasonable approximation for springers. It would not be a reasonable approximation when simulating the full cycle of a HPA blaster using an air cylinder. It is likely that coefficients of restitution that are too small may have similar stalling problems that this approximation will not handle properly.