createModel Method
Creates a model object.
The model is a container object. All the modeling entities are stored in this container object. The model object is provided to the optimizer to do the optimization.
Example
The createModel method for the FourBar class relies on two helper functions, make_cylinder to create cylinders and make_joint to create joints. These simplify modeling.
def createModel (self):
#------------------------------------------
def make_cylinder (a, b, r, rho, label):
r2 = r*r
h2 = (a[0]-b[0])**2 + (a[1]-b[1])**2 +
(a[2]-b[2])**2
h = math.sqrt(h2)
mass = math.pi * r2 * h * rho
ixx = iyy = mass * (3 * r2 + h2) / 12
izz = mass * r2 / 2
qploc = (a+b)/2
xploc = qploc + [0,0,1]
cyl = Part (mass=mass,
ip=[ixx, iyy, izz],
label=label)
cyl.cm = Marker (body=cyl, qp=qploc, zp=b
xp=xploc, label=label + " CM")
cyl.gcm = Marker (body=cyl, qp=a, zp=b,
xp=xploc, label=label + "_Cyl CM")
cyl.gra = Graphics (type="CYLINDER",
cm=cyl.gcm, radius=r, length=h,
seg=40, label=label + " Cylinder")
cyl.req = Request (type="DISPLACEMENT",
i=cyl.cm,
comment=label + " CM displacement",
label=label + " CM displacement")
return cyl
#-----------------------------------------------
def make_joint (p2, p1, loc, loc2, jtype, pt):
if jtype == "UNIVERSAL":
ux = Vector(1,0,0) # Global X
uz = Vector(0,0,1) # Global Z
xiloc = loc + ux # Xi along global X
ziloc = loc + uz # Zi along global Z
xjloc = loc + uz # Xj along global Z
ubc = (loc-loc2).normalize()
zixbc = uz.cross (ubc).normalize ()
zjloc = pc+zixbc
mi = Marker (body=p2, qp=loc, zp=ziloc,
xp=xiloc, label="UNIV@ C I")
mj = Marker (body=p1, qp=loc, zp=zjloc,
xp=xjloc, label="UNIVL@ C J")
else:
xploc = loc + [1,0,0]
zploc = loc + [0,0,1]
mi = Marker (body=p2, qp=loc, zp=zploc,
xp=xploc, label=jtype+"@"+pt+" I")
mj = Marker (body=p1, qp=loc, zp=zploc,
xp=xploc, label=jtype+"@"+pt+" J")
joint = Joint (type=jtype, i=mi, j=mj,
label=jtype+"@"+pt)
return joint
m = Model (output="test-4bar")
units = Units (mass="KILOGRAM",
length="MILLIMETER",
time="SECOND",
force="NEWTON")
grav = Accgrav (jgrav=-9800)
H3dOutput (grasave=True)
# define the design variables
m.ax = ax = Dv (label="XA", b=self.ax,
blimit=self.ax_lim)
m.ay = ay = Dv (label="YA", b=self.ay,
blimit=self.ay_lim)
m.bx = bx = Dv (label="XB", b=self.bx,
blimit=self.bx_lim)
m.by = by = Dv (label="YB", b=self.by,
blimit=self.by_lim)
m.cx = cx = Dv (label="XC", b=self.cx,
blimit=self.cx_lim)
m.cy = cy = Dv (label="YC", b=self.cy,
blimit=self.cy_lim)
m.dx = dx = Dv (label="XD", b=self.dx,
blimit=self.dx_lim)
m.dy = dy = Dv (label="YD", b=self.dy,
blimit=self.dy_lim)
rad, rho = 10, 7.8e-6
pa = Point(ax,ay,0)
pb = Point(bx,by,0)
pc = Point(cx,cy,0)
pd = Point(dx,dy,0)
#Ground
p1 = Part (ground=True)
oxyz = Marker (body=p1, label="Global CS")
#crank, coupler, follower parts
m.crank = p2 = make_cylinder (pa, pb, rad,
rho, "Crank")
m.coupler = p3 = make_cylinder (pb, pc, rad,
rho, "Coupler")
m.follower = p4 = make_cylinder (pc, pd, rad,
rho, "Follower")
m.coupler.azMarker = Marker (part=p3,
qp=p3.cm.qp)
#Joints + motion @A to drive system
ja = make_joint (p2, p1, pa, None,
"REVOLUTE", "A")
jb = make_joint (p3, p2, pb, None,
"SPHERICAL", "B")
jc = make_joint (p4, p3, pc, pb ,
"UNIVERSAL", "C")
jd = make_joint (p1, p4, pd, None,
"REVOLUTE", "D")
m.j1mot = Motion (joint=ja, jtype="ROTATION",
dtype="DISPLACEMENT",
function="360d*time")
self.mbsModel = m
return m