Augh, Physics

(← Return to Comfortably Numb)
Filed under: misc, software by tamber
21 Gorffennaf 2013 @ 23:05

This is the first 'official' mention of some code I've been working on -- in bits and pieces -- for a while now; it's a rather dumb calculator for engine stuff. No, I don't really know what -- if anything -- it's good for.

Anyway!

If you feed it the values for the number of cylinders, the total engine capacity, the desired cylinder bore, and geometric compression ratio -- as well as a couple of other optional values, such as rod-length -- it should spit out a list of info the volume per cylinder, how much distance there is between the piston crown and the cylinder head at BDC, the clearance volume at TDC, the stroke length, and -- if you didn't specify a rod length -- how long your rod would have to be to get the given rod/stroke ratio.

It's also supposed to calculate piston velocities and acceleration, and -- at some point -- how much force the piston, rings, etc are applying to the rod (Obviously, you'd have to feed in the weight values, or approximations thereof.); but the math on that is coming out incredibly strangely.

I'm getting values like `-059.8979128782034.34925709080.0665` for piston acceleration. Now, correct me if I'm wrong, but I'm pretty sure you're only allowed one decimal point in a number.

EDIT: Turned out to be a screwy format specifier; forgot to add commas between the values, so it ran them together. Unfortunately, that uncovered some more bizarreness; which looks like it's going to be even more painful to fix.

Apparently, I have a piston travelling away from TDC at 128782 m/s. That'd be 128 kilometers per second. I may only be an amateur mechanic, but I'm pretty sure that would end badly for everyone.

So I think I'll have to tear it back to bits and double-check all my math code, and try to get that working. I don't expect it will be easy, because the math involved is rather scary.

Other than the aforementioned screwiness with the calculations for the physics, there are a few other caveats; for one, it assumes that the combustion chamber is a perfect cylinder, terminating at the deck of the block. (So the head is effectively a flat plate with valves in it.)

This kills the crab most likely isn't true for any practical engine; but I haven't got around to rejigging the code to compensate for that. I think it should be easy; it certainly will be compared to the scary maths for the piston motion.

Example

(calculate :cylinders 2 :capacity 800 :bore 87
:rod-length 90 :rpm 3600 :cr 9.5)

The above calculates bits of information for an engine that displaces 800cc in 2 cylinders of 87mm bore, using a 90mm long rod (for sake of argument, let's just say you have a box of them just laying around, so you decided to use those), at a compression-ratio of 9.5:1.

What it squeezes out is the following:

=== Output ===
Num. Cylinders:                         2
Total volume:                           800.0cc
Volume per cylinder:                    400.0cc
Compression ratio:                      9.5:1
Cylinder length (BDC):                  67.287mm
Clearance volume:                       42.105cc
Stroke length:                          60.204mm
Crank throw:                            30.102mm
Rod length:                             90.000mm
Rod/Stroke ratio:                       1.495

Yes, it repeats some of the info back at you, and also does some really simple math to give you some stuff you could probably figure out yourself; but you're already using a computer, why not let it do the work for you?

(You could also let it calculate how long your rod would have to be -- steady now -- to reach the specified rod-stroke ratio; but that's not really something I expect you'll really be thinking about doing unless you have a real specific need for a certain R/S ratio, and chances are it'll give you a measurement that's a pig to get a rod made to. :) )

So, uh...

I don't really know if it'd be at all useful to anyone; it's really nothing more than a toy. If you could think of something that could be added that might make it useful to you, then lemme know! (Email me at tamber@furryhelix.co.uk, start the subject with "engine.lisp")

I can't promise to implement all suggestions, and I work on in whenever I'm in the mood to, so it might take some time; but it'd be neat for it to be useful to someone, somewhere.

At some point, once I've got the worst of the bugs worked out, I'll munge it into something more usable by other people. (Since I'm fairly sure the number of people who are interested in something like this, and have SBCL installed, is fairly low.)

You can grab the file from here.. You'll need a common-lisp implementation to use it for now. SBCL works fairly well.