"""
Script to reproduce the rigid multi-body mechanism.
The script creates an ABAQUS/Standard and an ABAQUS/Explicit
model that can be submitted for analysis.
The script reads an ACIS sat file and does not partition the model.
As a result the script can safely use the indices of vertices,
edges, faces, and cells and does not require the findAt() command.
"""

from abaqus import *
from abaqusConstants import *
from driverUtils import executeOnCaeStartup

executeOnCaeStartup()

# Create the model database.

Mdb()

mechanismModel = mdb.Model(name='abaqusStandard')

# Import the assembly from a .sat file (rigmultimech.sat).

import part
import regionToolset

acisFile = mdb.openAcis(
    'rigmultimech.sat')

# Create the parts.
# Create a reference point on each part.
# Create a display name for the reference point and a name for
# the Feature manager.

# The small disk.

smallDisk = mechanismModel.PartFromGeometryFile(name='smallDisk',
    geometryFile=acisFile, bodyNum=9, dimensionality=THREE_D,
    type=DEFORMABLE_BODY)
e = smallDisk.edges
smallDiskReferencePoint = smallDisk.ReferencePoint(
    point=smallDisk.InterestingPoint(edge=e[49], rule=MIDDLE))
smallDisk.features.changeKey('RP', 'smallDiskRefPt')
smallDisk.regenerate()

# The disk link.

diskLink = mechanismModel.PartFromGeometryFile(name='diskLink',
    geometryFile=acisFile, bodyNum=8, dimensionality=THREE_D,
    type=DEFORMABLE_BODY)
e = diskLink.edges
diskLinkReferencePoint = diskLink.ReferencePoint(
    point=diskLink.InterestingPoint(edge=e[8], rule=MIDDLE))
diskLink.features.changeKey('RP', 'diskLinkRefPt')
diskLink.regenerate()

# The large disk.

largeDisk = mechanismModel.PartFromGeometryFile(name='largeDisk',
    geometryFile=acisFile, bodyNum=7, dimensionality=THREE_D,
    type=DEFORMABLE_BODY)
e = largeDisk.edges
largeDiskReferencePoint = largeDisk.ReferencePoint(
    point=largeDisk.InterestingPoint(edge=e[65], rule=MIDDLE))
largeDisk.features.changeKey('RP', 'largeDiskRefPt')
largeDisk.regenerate()

# The round rod.

roundRod = mechanismModel.PartFromGeometryFile(name='roundRod',
    geometryFile=acisFile, bodyNum=3, dimensionality=THREE_D,
    type=DEFORMABLE_BODY)
e = roundRod.edges
roundRodReferencePoint = roundRod.ReferencePoint(
    point=roundRod.InterestingPoint(edge=e[39], rule=MIDDLE))
roundRod.features.changeKey('RP', 'roundRodRefPt')
roundRod.regenerate()

# The round sleeve.

roundSleeve = mechanismModel.PartFromGeometryFile(name='roundSleeve',
    geometryFile=acisFile, bodyNum=4, dimensionality=THREE_D,
    type=DEFORMABLE_BODY)
e = roundSleeve.edges
roundSleeveReferencePoint = roundSleeve.ReferencePoint(
    point=roundSleeve.InterestingPoint(edge=e[116], rule=CENTER))
roundSleeve.features.changeKey('RP', 'roundSleeveRefPt')
roundSleeve.regenerate()

# The square sleeve.

squareSleeve = mechanismModel.PartFromGeometryFile(name='squareSleeve',
    geometryFile=acisFile, bodyNum=5, dimensionality=THREE_D,
    type=DEFORMABLE_BODY)
e = squareSleeve.edges
squareSleeveDatum = squareSleeve.DatumPointByMidPoint(
    point1=squareSleeve.InterestingPoint(edge=e[82], rule=MIDDLE),
    point2=squareSleeve.InterestingPoint(edge=e[60], rule=MIDDLE))
squareSleeve.features.changeKey('Datum pt-1', 'squareSleeveDatumPt')
squareSleeveReferencePoint = squareSleeve.ReferencePoint(
    point=squareSleeve.datums[squareSleeveDatum.id])
squareSleeve.features.changeKey('RP', 'squareSleeveRefPt')
squareSleeve.regenerate()

# The square rod.

squareRod = mechanismModel.PartFromGeometryFile(name='squareRod',
    geometryFile=acisFile, bodyNum=6, dimensionality=THREE_D,
    type=DEFORMABLE_BODY)
e = squareRod.edges
squareRodDatum1 = squareRod.DatumPointByMidPoint(
    point1=squareRod.InterestingPoint(edge=e[1], rule=MIDDLE),
    point2=squareRod.InterestingPoint(edge=e[5], rule=MIDDLE))
squareRod.features.changeKey('Datum pt-1', 'squareRodDatum1Pt')
squareRodDatum2 = squareRod.DatumPointByMidPoint(
    point1=squareRod.InterestingPoint(edge=e[3], rule=MIDDLE),
    point2=squareRod.InterestingPoint(edge=e[8], rule=MIDDLE))
squareRod.features.changeKey('Datum pt-1', 'squareRodDatum2Pt')
squareRodDatum3 = squareRod.DatumPointByMidPoint(
    point1=squareRod.datums[squareRodDatum1.id],
    point2=squareRod.datums[squareRodDatum2.id])
squareRod.features.changeKey('Datum pt-1', 'squareRodDatum3Pt')
squareRodReferencePoint = squareRod.ReferencePoint(
    point=squareRod.datums[squareRodDatum3.id])
squareRod.features.changeKey('RP', 'squareRodRefPt')
squareRod.regenerate()

# The sliding block.

slidingBlock = mechanismModel.PartFromGeometryFile(name='slidingBlock',
    geometryFile=acisFile, bodyNum=2, dimensionality=THREE_D,
    type=DEFORMABLE_BODY)
e = slidingBlock.edges
slidingBlockReferencePoint = slidingBlock.ReferencePoint(
    point=slidingBlock.InterestingPoint(edge=e[0], rule=CENTER))
slidingBlock.features.changeKey('RP', 'slidingBlockRefPt')
slidingBlock.regenerate()

# The race way.

raceWay = mechanismModel.PartFromGeometryFile(name='raceWay',
    geometryFile=acisFile, dimensionality=THREE_D, type=DEFORMABLE_BODY)
v = raceWay.vertices
raceWayReferencePoint = raceWay.ReferencePoint(point=v[10])
raceWay.features.changeKey('RP', 'raceWayRefPt')
raceWay.regenerate()

import material

# Create a dummy material.

material = mechanismModel.Material('Mat')
material.Density(table=((0.020734, ), ))
material.Elastic(table=((30000000.0, 0.3), ))

import section

# Create a solid section.

mechanismModel.HomogeneousSolidSection(name='SOLID',
    material='Mat')

# Create a shell section.

mechanismModel.HomogeneousShellSection(name='SHELL',
    material='Mat', thickness=0.75)

# Assign sections to the parts.

region = regionToolset.Region(cells=smallDisk.cells)
smallDisk.SectionAssignment(region=region, sectionName='SOLID')
f = smallDisk.faces
faces = f[16:17]+f[52:53]
region = regionToolset.Region(faces=faces)
smallDisk.SectionAssignment(region=region, sectionName='SHELL')

region = regionToolset.Region(cells=diskLink.cells)
diskLink.SectionAssignment(region=region, sectionName='SOLID')
f = diskLink.faces
faces = f[0:2]+f[14:15]+f[16:17]
region = regionToolset.Region(faces=faces)
diskLink.SectionAssignment(region=region, sectionName='SHELL')

region = regionToolset.Region(cells=largeDisk.cells)
largeDisk.SectionAssignment(region=region, sectionName='SOLID')
f = largeDisk.faces
faces = f[32:33]+f[52:53]
region = regionToolset.Region(faces=faces)
largeDisk.SectionAssignment(region=region, sectionName='SHELL')

region = regionToolset.Region(cells=roundRod.cells)
roundRod.SectionAssignment(region=region, sectionName='SOLID')

region = regionToolset.Region(cells=roundSleeve.cells)
roundSleeve.SectionAssignment(region=region, sectionName='SOLID')

region = regionToolset.Region(cells=squareSleeve.cells)
squareSleeve.SectionAssignment(region=region, sectionName='SOLID')

region = regionToolset.Region(cells=squareRod.cells)
squareRod.SectionAssignment(region=region, sectionName='SOLID')

region = regionToolset.Region(cells=slidingBlock.cells)
slidingBlock.SectionAssignment(region=region, sectionName='SOLID')

region = regionToolset.Region(cells=raceWay.cells)
raceWay.SectionAssignment(region=region, sectionName='SOLID')

# Assign the root assembly to a variable.

import assembly

mechanismAssembly = mechanismModel.rootAssembly
globalCsys=mechanismAssembly.DatumCsysByDefault(name='globalCsys',
    coordSysType=CARTESIAN)

# Create instances of all the parts.
# Create additional reference points where needed.
# Create a display name for the reference point and a name for
# the Feature manager.

# The small disk.

smallDiskInstance = mechanismAssembly.Instance(
    name='smallDiskInstance', part=smallDisk, dependent=OFF)

# The disk link.

diskLinkInstance = mechanismAssembly.Instance(
    name='diskLinkInstance', part=diskLink, dependent=OFF)

# The large disk.

largeDiskInstance = mechanismAssembly.Instance(
    name='largeDiskInstance', part=largeDisk, dependent=OFF)

# The round rod.

roundRodInstance = mechanismAssembly.Instance(
    name='roundRodInstance', part=roundRod, dependent=OFF)
v1 = roundRodInstance.vertices
roundRodReferencePoint1 = mechanismAssembly.ReferencePoint(point=v1[5])
mechanismAssembly.features.changeKey('RP-1', 'roundRodRefPt1')

# The round sleeve.

roundSleeveInstance = mechanismAssembly.Instance(
    name='roundSleeveInstance', part=roundSleeve, dependent=OFF)

# The square sleeve.

squareSleeveInstance = mechanismAssembly.Instance(
    name='squareSleeveInstance', part=squareSleeve, dependent=OFF)
v1 = squareSleeveInstance.vertices
squareSleeveInstanceDatum1 = mechanismAssembly.DatumPointByMidPoint(
    point1=v1[36], point2=v1[33])
mechanismAssembly.features.changeKey('Datum pt-1', 'squareSleeveDatum1Pt')
squareSleeveReferencePoint1 = mechanismAssembly.ReferencePoint(
    point=mechanismAssembly.datums[squareSleeveInstanceDatum1.id])
mechanismAssembly.features.changeKey('RP-1', 'squareSleeveRefPt1')

# The square rod.

squareRodInstance = mechanismAssembly.Instance(
    name='squareRodInstance', part=squareRod, dependent=OFF)

# The sliding block.

slidingBlockInstance = mechanismAssembly.Instance(
    name='slidingBlockInstance', part=slidingBlock, dependent=OFF)

# The raceway.

raceWayInstance = mechanismAssembly.Instance(
    name='raceWayInstance', part=raceWay, dependent=OFF)

# Create a step for the ABAQUS/Standard model.

import step

standardStep = mechanismModel.ImplicitDynamicsStep(initialInc=0.00018,
    maxNumInc=10000, name='Step-1', nlgeom=ON, noStop=OFF, nohaf=ON,
    hafTolMethod=VALUE,
    previous='Initial', timeIncrementationMethod=FIXED, timePeriod=0.18)

# Request U, V, and A field output.

mechanismModel.fieldOutputRequests['F-Output-1'].setValues(variables=(
    'U', 'V', 'A'), frequency=10)
standardStep.Restart(frequency=0, overlay=OFF)

# Create rigid body constraints for each instance.

import interaction

# The small disk.

f1 = smallDiskInstance.faces
faces1 = f1[16:17]+f1[52:53]
bodyRegion=regionToolset.Region(faces=faces1,
    cells=smallDiskInstance.cells)
verts1 = smallDiskInstance.vertices[30:31]
tieRegion=regionToolset.Region(vertices=verts1)
refPoints1 = (smallDiskInstance.referencePoints[smallDiskReferencePoint.id], )
refPointRegion=regionToolset.Region(referencePoints=refPoints1)
mechanismModel.RigidBody(name='SD', refPointRegion=refPointRegion,
    bodyRegion=bodyRegion, tieRegion=tieRegion)
v1 = smallDiskInstance.vertices

# The disk link.

f1 = diskLinkInstance.faces
faces1 = f1[0:2]+f1[14:15]+f1[16:17]
bodyRegion=regionToolset.Region(faces=faces1,
    cells=diskLinkInstance.cells)
v1 = diskLinkInstance.vertices
verts1 = v1[1:2]+v1[5:6]
tieRegion = regionToolset.Region(vertices=verts1)
refPoints1 = (diskLinkInstance.referencePoints[diskLinkReferencePoint.id], )
refPointRegion = regionToolset.Region(referencePoints=refPoints1)
mechanismModel.RigidBody(name='DL', refPointRegion=refPointRegion,
    bodyRegion=bodyRegion, tieRegion=tieRegion)

# The large disk.

f1 = largeDiskInstance.faces
faces1 = f1[32:33]+f1[52:53]
bodyRegion=regionToolset.Region(faces=faces1,
    cells=largeDiskInstance.cells)
refPoints1 = (largeDiskInstance.referencePoints[largeDiskReferencePoint.id], )
refPointRegion=regionToolset.Region(referencePoints=refPoints1)
refPoints1 = (mechanismAssembly.referencePoints[roundRodReferencePoint1.id], )
v2 = largeDiskInstance.vertices
verts2 = v2[37:38]
tieRegion=regionToolset.Region(vertices=verts2, referencePoints=refPoints1)
mechanismModel.RigidBody(name='LD', refPointRegion=refPointRegion,
    bodyRegion=bodyRegion, tieRegion=tieRegion)

# The round rod.

bodyRegion=regionToolset.Region(cells=roundRodInstance.cells)
v1 = roundRodInstance.vertices
verts1 = v1[5:6]+v1[24:25]
tieRegion=regionToolset.Region(vertices=verts1)
refPoints1 = (roundRodInstance.referencePoints[roundRodReferencePoint.id], )
refPointRegion=regionToolset.Region(referencePoints=refPoints1)
mechanismModel.RigidBody(name='RR', refPointRegion=refPointRegion,
    bodyRegion=bodyRegion, tieRegion=tieRegion)

# The round sleeve.

bodyRegion=regionToolset.Region(cells=roundSleeveInstance.cells)
v1 = roundSleeveInstance.vertices
verts1 = v1[44:45]
tieRegion=regionToolset.Region(vertices=verts1)
refPoints1 = (
    roundSleeveInstance.referencePoints[roundSleeveReferencePoint.id], )
refPointRegion=regionToolset.Region(referencePoints=refPoints1)
mechanismModel.RigidBody(name='RS', refPointRegion=refPointRegion,
    bodyRegion=bodyRegion, tieRegion=tieRegion)

# The square sleeve.

bodyRegion=regionToolset.Region(cells=squareSleeveInstance.cells)
refPoints1 = (
    mechanismAssembly.referencePoints[squareSleeveReferencePoint1.id], )
tieRegion=regionToolset.Region(referencePoints=refPoints1)
refPoints1 = (
    squareSleeveInstance.referencePoints[squareSleeveReferencePoint.id], )
refPointRegion=regionToolset.Region(referencePoints=refPoints1)
mechanismModel.RigidBody(name='SS', refPointRegion=refPointRegion,
    bodyRegion=bodyRegion, tieRegion=tieRegion)

# The square rod.

bodyRegion=regionToolset.Region(cells=squareRodInstance.cells)
refPoints1 = (
    squareRodInstance.referencePoints[squareRodReferencePoint.id], )
refPointRegion=regionToolset.Region(referencePoints=refPoints1)
mechanismModel.RigidBody(name='SR', refPointRegion=refPointRegion,
    bodyRegion=bodyRegion)

# The sliding block.

bodyRegion=regionToolset.Region(cells=slidingBlockInstance.cells)
refPoints1 = (
    slidingBlockInstance.referencePoints[slidingBlockReferencePoint.id], )
refPointRegion=regionToolset.Region(referencePoints=refPoints1)
mechanismModel.RigidBody(name='SB', refPointRegion=refPointRegion,
    bodyRegion=bodyRegion)

# The raceway.

bodyRegion=regionToolset.Region(cells=raceWayInstance.cells)
refPoints1 = (raceWayInstance.referencePoints[raceWayReferencePoint.id], )
refPointRegion=regionToolset.Region(referencePoints=refPoints1)
mechanismModel.RigidBody(name='RW', refPointRegion=refPointRegion,
    bodyRegion=bodyRegion)

# Create the datum coordinate systems used for the connector orientations.

v1 = smallDiskInstance.vertices
minusxzyDatumCsys = mechanismAssembly.DatumCsysByThreePoints(
    name='minusxzy', origin=v1[29], point1=v1[32], point2=v1[30],
    coordSysType=CARTESIAN)
v1 = diskLinkInstance.vertices
diskLinkDatumCsys = mechanismAssembly.DatumCsysByThreePoints(
    name='diskLinkDatumCsys', origin=v1[4], point1=v1[9], point2=v1[0],
    coordSysType=CARTESIAN)
v1 = raceWayInstance.vertices
zxyDatumCsys = mechanismAssembly.DatumCsysByThreePoints(
    name='zxy', origin=v1[13], point1=v1[12],
    coordSysType=CARTESIAN, line2=(0.0, 0.0, 625.0))
zyminusxDatumCsys = mechanismAssembly.DatumCsysByThreePoints(
    name='zyminusx', origin=v1[0], point1=v1[6],
    coordSysType=CARTESIAN, line2=(0.0, 16.0, 0.0))

# Create the various connectors.
# Create a UJOINT between the small disk and the disk link.

mechanismModel.ConnectorSection(name='UJOINT', assembledType=UJOINT,
    translationalType=NONE, rotationalType=NONE)
point1 = smallDiskInstance.vertices[30]
point2 = diskLinkInstance.vertices[5]
orient1 = mechanismAssembly.datums[minusxzyDatumCsys.id]
orient2 = mechanismAssembly.datums[diskLinkDatumCsys.id]

connectorWires = mechanismAssembly.WirePolyLine(points=((point1, point2), ), mergeType=IMPRINT, meshable=OFF)
wireSet = mechanismAssembly.Set(name='SD-DL_CnSet', edges=mechanismAssembly.getFeatureEdges(connectorWires.name))
connectorSectionAssignment = mechanismAssembly.SectionAssignment(region=wireSet, sectionName='UJOINT')
connectorOrientation = mechanismAssembly.ConnectorOrientation(region=connectorSectionAssignment.getSet(), localCsys1=orient1, localCsys2=orient2)

# Create a UJOINT between the large disk and the disk link.

a = mechanismAssembly
point1 = diskLinkInstance.vertices[1]
point2 = largeDiskInstance.vertices[37]
orient1 = mechanismAssembly.datums[diskLinkDatumCsys.id]
orient2 = mechanismAssembly.datums[minusxzyDatumCsys.id]
connectorWires = mechanismAssembly.WirePolyLine(points=((point1, point2), ), mergeType=IMPRINT, meshable=OFF)
wireSet = mechanismAssembly.Set(name='DL-LD_CnSet', edges=mechanismAssembly.getFeatureEdges(connectorWires.name))
connectorSectionAssignment = mechanismAssembly.SectionAssignment(region=wireSet, sectionName='UJOINT')
connectorOrientation = mechanismAssembly.ConnectorOrientation(region=connectorSectionAssignment.getSet(), localCsys1=orient1, localCsys2=orient2)

# Create a JOIN between the large disk and the round rod.

mechanismModel.ConnectorSection(name='JOIN', assembledType=NONE,
    translationalType=JOIN, rotationalType=NONE)
point1 = mechanismAssembly.referencePoints[roundRodReferencePoint1.id]
point2 = roundRodInstance.vertices[5]
connectorWires = mechanismAssembly.WirePolyLine(points=((point1, point2), ), mergeType=IMPRINT, meshable=OFF)
wireSet = mechanismAssembly.Set(name='LD-RR_CnSet', edges=mechanismAssembly.getFeatureEdges(connectorWires.name))
connectorSectionAssignment = mechanismAssembly.SectionAssignment(region=wireSet, sectionName='JOIN')
connectorOrientation = mechanismAssembly.ConnectorOrientation(region=connectorSectionAssignment.getSet())

# Create a TRANSLATOR between the square rod and the square sleeve.

mechanismModel.ConnectorSection(name='TRANSLATOR',
    assembledType=TRANSLATOR, translationalType=NONE, rotationalType=NONE)
point1 = squareRodInstance.referencePoints[squareRodReferencePoint.id]
point2 = squareSleeveInstance.referencePoints[squareSleeveReferencePoint.id]
orient1=mechanismAssembly.datums[globalCsys.id]
connectorWires = mechanismAssembly.WirePolyLine(points=((point1, point2), ), mergeType=IMPRINT, meshable=OFF)
wireSet = mechanismAssembly.Set(name='SR-SS_CnSet', edges=mechanismAssembly.getFeatureEdges(connectorWires.name))
connectorSectionAssignment = mechanismAssembly.SectionAssignment(region=wireSet, sectionName='TRANSLATOR')
connectorOrientation = mechanismAssembly.ConnectorOrientation(region=connectorSectionAssignment.getSet(), localCsys1=orient1)

# Create a CYLINDRICAL between the round rod and the round sleeve.

mechanismModel.ConnectorSection(name='CYLINDRICAL',
    assembledType=CYLINDRICAL, translationalType=NONE, rotationalType=NONE)
point1 = roundRodInstance.referencePoints[roundRodReferencePoint.id]
point2 = roundSleeveInstance.referencePoints[roundSleeveReferencePoint.id]
orient1 = mechanismAssembly.datums[zxyDatumCsys.id]
connectorWires = mechanismAssembly.WirePolyLine(points=((point1, point2), ), mergeType=IMPRINT, meshable=OFF)
wireSet = mechanismAssembly.Set(name='RR-RS_CnSet', edges=mechanismAssembly.getFeatureEdges(connectorWires.name))
connectorSectionAssignment = mechanismAssembly.SectionAssignment(region=wireSet, sectionName='CYLINDRICAL')
connectorOrientation = mechanismAssembly.ConnectorOrientation(region=connectorSectionAssignment.getSet(), localCsys1=orient1)

# Create a HINGE between the round sleeve and the square sleeve.

mechanismModel.ConnectorSection(name='HINGE', assembledType=HINGE,
    translationalType=NONE, rotationalType=NONE)
point1 = roundSleeveInstance.vertices[44]
point2 = mechanismAssembly.referencePoints[squareSleeveReferencePoint1.id]
orient1 = mechanismAssembly.datums[zyminusxDatumCsys.id]
connectorWires = mechanismAssembly.WirePolyLine(points=((point1, point2), ), mergeType=IMPRINT, meshable=OFF)
wireSet = mechanismAssembly.Set(name='RS-SS_CnSet', edges=mechanismAssembly.getFeatureEdges(connectorWires.name))
connectorSectionAssignment = mechanismAssembly.SectionAssignment(region=wireSet, sectionName='HINGE')
connectorOrientation = mechanismAssembly.ConnectorOrientation(region=connectorSectionAssignment.getSet(), localCsys1=orient1)

# Create a HINGE between the sliding block and the round rod.

point1 = roundRodInstance.vertices[24]
point2 = slidingBlockInstance.referencePoints[slidingBlockReferencePoint.id]
orient1 = mechanismAssembly.datums[zyminusxDatumCsys.id]
connectorWires = mechanismAssembly.WirePolyLine(points=((point1, point2), ), mergeType=IMPRINT, meshable=OFF)
wireSet = mechanismAssembly.Set(name='SB-RR_CnSet', edges=mechanismAssembly.getFeatureEdges(connectorWires.name))
connectorSectionAssignment = mechanismAssembly.SectionAssignment(region=wireSet, sectionName='HINGE')
connectorOrientation = mechanismAssembly.ConnectorOrientation(region=connectorSectionAssignment.getSet(), localCsys1=orient1)

# Create a PLANAR between the raceway and the sliding block.

mechanismModel.ConnectorSection(name='PLANAR', assembledType=PLANAR,
    translationalType=NONE, rotationalType=NONE)
point1 = raceWayInstance.referencePoints[raceWayReferencePoint.id]
point2 = slidingBlockInstance.referencePoints[slidingBlockReferencePoint.id]
orient1 = mechanismAssembly.datums[globalCsys.id]
connectorWires = mechanismAssembly.WirePolyLine(points=((point1, point2), ), mergeType=IMPRINT, meshable=OFF)
wireSet = mechanismAssembly.Set(name='RW-SB_CnSet', edges=mechanismAssembly.getFeatureEdges(connectorWires.name))
connectorSectionAssignment = mechanismAssembly.SectionAssignment(region=wireSet, sectionName='PLANAR')
connectorOrientation = mechanismAssembly.ConnectorOrientation(region=connectorSectionAssignment.getSet(), localCsys1=orient1)

# Create the boundary conditions.
# The small disk is allowed to move only in U3 and UR3.

import load

refPoints1 = (
    smallDiskInstance.referencePoints[smallDiskReferencePoint.id], )
refPointRegion = regionToolset.Region(referencePoints=refPoints1)
mechanismModel.DisplacementBC(name='SD-BC1', createStepName='Initial',
    region=refPointRegion, u1=SET, u2=SET, u3=UNSET, ur1=SET, ur2=SET,
    ur3=UNSET, amplitude=UNSET, distributionType=UNIFORM, localCsys=None)

# The small disk is given a rotational velocity in the first step.

mechanismModel.SmoothStepAmplitude(
    name='AMP', data=((0.0, 0.0),(0.00375, 23.26),(3.0, 23.26)),
    timeSpan=STEP)

mechanismModel.VelocityBC(name='SD-BC2', createStepName='Step-1',
    region=refPointRegion, v1=UNSET, v2=UNSET, v3=UNSET, vr1=UNSET,
    vr2=UNSET, vr3=5.0, amplitude='AMP', distributionType=UNIFORM,
    localCsys=None)

# The large disk is allowed to only rotate in UR3.

refPoints1 = (
    largeDiskInstance.referencePoints[largeDiskReferencePoint.id], )
refPointRegion=regionToolset.Region(referencePoints=refPoints1)
mechanismModel.DisplacementBC(name='LD-BC', createStepName='Initial',
    region=refPointRegion, u1=SET, u2=SET, u3=SET, ur1=SET, ur2=SET,
    ur3=UNSET, amplitude=UNSET, distributionType=UNIFORM, localCsys=None)

# The raceway is fixed.

refPoints1 = (
    raceWayInstance.referencePoints[raceWayReferencePoint.id], )
refPointRegion=regionToolset.Region(referencePoints=refPoints1)
mechanismModel.DisplacementBC(name='RW-BC', createStepName='Initial',
    region=refPointRegion, u1=SET, u2=SET, u3=SET, ur1=SET, ur2=SET,
    ur3=SET, amplitude=UNSET, distributionType=UNIFORM, localCsys=None)

# The square rod can move in U3 only.

refPoints1 = (
    squareRodInstance.referencePoints[squareRodReferencePoint.id], )
refPointRegion=regionToolset.Region(referencePoints=refPoints1)
region = regionToolset.Region(referencePoints=refPoints1)
mechanismModel.DisplacementBC(name='SR-BC', createStepName='Initial',
    region=refPointRegion, u1=SET, u2=SET, u3=UNSET, ur1=SET, ur2=SET,
    ur3=SET, amplitude=UNSET, distributionType=UNIFORM, localCsys=None)

# Mesh the part instances.

import mesh

f1 = largeDiskInstance.faces
f2 = diskLinkInstance.faces
f3 = smallDiskInstance.faces
regions =(f1[32], f1[52], f2[0], f2[1], f2[14], f2[16], f3[16], f3[52])
mechanismAssembly.setMeshControls(regions=regions, technique=STRUCTURED)

partInstances =(raceWayInstance, slidingBlockInstance,
    roundRodInstance, roundSleeveInstance,
    squareSleeveInstance, squareRodInstance,
    largeDiskInstance, diskLinkInstance,
    smallDiskInstance, )
mechanismAssembly.seedPartInstance(regions=partInstances, size=5.0)
mechanismAssembly.generateMesh(regions=partInstances)

# Create an ABAQUS/Standard job.

import job

mdb.Job(name='multimechstd', model='abaqusStandard',
    description='Rigid multi-body mechanism example', echoPrint=OFF,
    modelPrint=OFF, contactPrint=OFF, historyPrint=OFF)

# Create a model for an ABAQUS/Explicit analysis.
# Copy the ABAQUS/Standard model.

explicitMechanismModel = mdb.Model(
    'abaqusExplicit', mdb.models['abaqusStandard'])

# Delete the step.

del explicitMechanismModel.steps['Step-1']

# Create an explicit, dynamics step.

explicitMechanismModel.ExplicitDynamicsStep(
    name='Step-1',previous='Initial',
    timePeriod=0.18, timeIncrementationMethod=FIXED_USER_DEFINED_INC,
    userDefinedInc=0.00018, massScaling=PREVIOUS_STEP)
explicitMechanismModel.steps['Step-1'].Restart(
    numberIntervals=1, overlay=OFF, timeMarks=OFF)

# Request U, V, and A field output.

explicitMechanismModel.fieldOutputRequests['F-Output-1'].setValues(
    variables=('U', 'V', 'A'), numIntervals=300)
explicitMechanismAssembly = explicitMechanismModel.rootAssembly

# The small disk instance is given an initial rotational velocity.

refPoints1 = (
    smallDiskInstance.referencePoints[smallDiskReferencePoint.id], )
refPointRegion = regionToolset.Region(referencePoints=refPoints1)
region = regionToolset.Region(referencePoints=refPoints1)
explicitMechanismModel.VelocityBC(name='SD-BC2', createStepName='Step-1',
    region=refPointRegion, v1=UNSET, v2=UNSET, v3=UNSET, vr1=UNSET,
    vr2=UNSET, vr3=5.0, amplitude='AMP', localCsys=None,
    distributionType=UNIFORM)

# Create an ABAQUS/Explicit job.

mdb.Job(name='multimechxpl', model='abaqusExplicit', type=ANALYSIS,
    explicitPrecision=DOUBLE, nodalOutputPrecision=SINGLE, description='',
    userSubroutine='', numCpus=1, scratch='', echoPrint=OFF,
    modelPrint=OFF, contactPrint=OFF, historyPrint=OFF)

