outfile = "projectile_length_results.txt"
-- I tried to make the data easy to import into Excel.
-- The format uses tabs (\t) to separate the output columns.
-- By default this is Excel's column separator.
-- I ended up reformatting the summaries anyway into a square table.
radius = 2.25
incr_length = 2
num_trials = 20
handle = openfile(outfile, "a")
write(handle, "\nSolving solid cylindrical projectile of various lengths \n")
write(handle, "Projectile: \n")
write(handle, " radius is ", radius, "mm \n")
write(handle, " length varies: 1,", 1+incr_length, ", ", 1+2*incr_length, ", ... \n")
max_length = 1 + num_trials*incr_length
write(handle, " up to maximum length of ", max_length, "mm\n")
write(handle, "Coil: \n")
write(handle, " 20mm long \n")
write(handle, " 3mm inside radius \n")
write(handle, " 6mm outside radius \n")
write(handle, "Note: \n")
write(handle, " In Excel click on Data... Get External Data... Import text file...\n")
write(handle, " then choose this text file (", outfile, ")\n")
write(handle, " and click Finish. \n")
write(handle, " This data is tab delimited which is its default import format.\n")
closefile(handle)
-- Save the model as "temp.fem" so it cannot affect our carefully
-- prepared starting model. This prevents losing your work if you
-- get a runaway solution that you have to kill in Task Manager.
save_femm_file("temp.fem")
-- Set edit mode in preparation for moving a group of points.
seteditmode("group")
r2 = radius * radius
pi = 3.1415926535
-- Amount to increase projectile length
for i=0,num_trials-1 do
-- Announce the new projectile's size
handle = openfile(outfile, "a")
write(handle, "\n")
write(handle, "Projectile length\t", (1 + i*incr_length), "\tmm\n")
write(handle, "Volume\t",(pi * r2 * (1 + i*incr_length)), "\tmm3\n")
write(handle, "\n")
closefile(handle)
-- Measure the force at 40 positions for each projectile.
for n=1,40 do
showmesh()
analyse()
-- Pass current position into post-processor
handle = openfile("tempfile","w")
pos = n-41
write(handle, pos)
closefile(handle)
runpost("projectile_length_post.lua")
-- Move the projectile further into coil
-- Projectile is composed of three groups and
-- order of movement is important to avoid overlap
selectgroup(1)
move_translate(0, 1)
selectgroup(2)
move_translate(0, 1)
selectgroup(3)
move_translate(0, 1)
end
-- Move projectile back to starting point.
-- The centerpoint moves back to same spot, and the top
-- and bottom ends are moved out by half the increment size.
selectgroup(3)
move_translate(0, -40 - incr_length/2)
selectgroup(2)
move_translate(0, -40)
selectgroup(1)
move_translate(0, -40 + incr_length/2)
end
messagebox("All done.")