Skip to content

Instantly share code, notes, and snippets.

@jstults
Created December 21, 2012 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jstults/4353059 to your computer and use it in GitHub Desktop.
Save jstults/4353059 to your computer and use it in GitHub Desktop.
generate octet truss array with varying member radius, and generate a part based on a variable density solution from ToPy
#
# http://www.variousconsequences.com/2012/12/octet-truss-for-topology-optimization.html
#
import scipy as sp
import cPickle
import octet
if __name__ == "__main__":
import os
# Path to the mged executables:
MGED_PATH = "~/brlcad/.build/bin/"
r = sp.linspace(0.4, 1.545, 11)
length = 8.0
unit = sp.sqrt(8.0**2 + 8.0**2)
parts = ""
array_u = "r array"
for i,ri in enumerate(r):
parts = parts + octet.octet_prim("op%s"%i, sp.array([i*sp.sqrt(length**2 + length**2),0,0]), length, ri).mged_string()
array_u = array_u + " u " + "op%s"%i
array_u = array_u + "\n"
fout = open("array.mged","w")
fout.write(parts)
fout.write(array_u)
fout.close()
#
# this takes too much memory
#
# fin = open("desvars.pkl","r")
# dogleg = cPickle.load(fin)
# fin.close()
# fin = open("volfrac_poly.pkl","r")
# pvf = cPickle.load(fin)
# fin.close()
# parts = ""
# dogleg_u = "r dogleg"
# ni,nj,nk = dogleg.shape
# r = sp.zeros(dogleg.shape)
# count = -1
# # for i,di in enumerate(dogleg):
# for i in xrange(ni):
# for j in xrange(nj):
# for k in xrange(nk):
# count = count + 1
# if dogleg[i,j,k] == dogleg.min(): # void
# pass
# else:
# if dogleg[i,j,k] == 1.0: # solid cube
# parts = parts + "in op%s rpp %g %g %g %g %g %g\n"%(count,i*unit,i*unit+unit,j*unit,j*unit+unit,k*unit,k*unit+unit)
# else: # octet truss for intermediate densities
# r[i,j,k] = sp.polyval(pvf, dogleg[i,j,k])
# parts = parts + octet.octet_prim("op%s"%count, sp.array([i*unit,j*unit,k*unit]), length, r[i,j,k]).mged_string()
# dogleg_u = dogleg_u + " u " + "op%s"%count
# fout = open("dogleg.mged","w")
# fout.write(parts)
# fout.write(dogleg_u)
# fout.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment