'''
-----------------------------------------------------------------------------
 Stress driving Symmetric sub model of a conical crack in a block modeled using
 continuum elements (C3D20R).

 First the global model job is completed. The *.odb file from the global
 model is used to drive this sub model.

 Global model scripts to be run:
 SymmConeCrackGl_model.py and SymmConeCrackGl_job.py
-----------------------------------------------------------------------------
'''

from abaqus import *
import testUtils
testUtils.setBackwardCompatibility()
from abaqusConstants import *

import part, material, section, assembly, step, interaction
import regionToolset, displayGroupMdbToolset as dgm, mesh, load, job
import inpReader

#----------------------------------------------------------------------------

# Copy the global model into a new model

Mdb()
globalModelName = 'SymmConeCrackOrphan'
openMdb(globalModelName)
originalModel = 'SymmConeCrackGl'
subModelName = 'SymmConeCrackSubSb_near'
subOrphanModelName = 'SymmConeCrackSubOrSb_near'
myModel = mdb.Model(name=subModelName)

myModel = (mdb.Model(name=subModelName,
    objectToCopy=mdb.models[originalModel]))
    
# Add density to the material definition, for inertia relief

myModel.materials['LinearElastic'].Density(table=((1.0, ), ))

# Create a new viewport in which to display the model
# and the results of the analysis.

myAssembly = myModel.rootAssembly
myViewport = session.viewports['Viewport: 1']
myViewport.setValues(displayedObject=myAssembly)
myViewport.makeCurrent()
myViewport.maximize()

#---------------------------------------------------------------------------

# Edit the model attributes to refer to the global model ODB file
# to drive the sub model.

myModel.setValues(description='Symmetric submodel of a cone crack', 
    globalJob='SymmConeCrackOrphan.odb')

#---------------------------------------------------------------------------


# Create the sub model section of the global model

subModelDepth = 24.

# Create a sketch for the base feature

mySubBlockSketch = myModel.Sketch(name='subBlockProfile',sheetSize=200.0)
mySubBlockSketch.sketchOptions.setValues(viewStyle=REGULAR)
mySubBlockSketch.setPrimaryObject(option=STANDALONE)

mySubBlockSketch.rectangle(point1=(0.0, 0.0), point2=(42.0, -subModelDepth))
mySubBlock = myModel.Part(name='subBlock', dimensionality=THREE_D, 
    type=DEFORMABLE_BODY)
mySubBlock.BaseSolidExtrude(sketch=mySubBlockSketch, depth=42.0)
mySubBlockSketch.unsetPrimaryObject()
myViewport.setValues(displayedObject=mySubBlock)
#del myModel.sketches['subBlockProfile']

#---------------------------------------------------------------------------

# Create an assembly

# Delete the existing instance

myViewport.setValues(displayedObject=myAssembly)
del myAssembly.features['partitionedBlock-1']

# Create an instance of the block

myAssembly1 = myModel.rootAssembly
myAssembly1.Instance(name='subBlock-1', part=mySubBlock,
    dependent=OFF)
p = myModel.parts['symmCone']

# Create an instance of the cone

myAssembly1.Instance(name='symmCone-2', part=p,
    dependent=OFF)
cone = myAssembly1.instances['symmCone-2']
cone.translate(vector=(0.0,0.0,42.0))

# Merge the cone with the block keeping intersecting
# boundaries ON.

myAssembly1.PartFromBooleanMerge(name='subBlockwithCrack', instances=(
    myAssembly1.instances['subBlock-1'],
    myAssembly1.instances['symmCone-2'],), 
    keepIntersections=ON, domain=GEOMETRY)
mySubBlockwithCrack = myModel.parts['subBlockwithCrack']
myAssembly1.Instance(name='subBlockwithCrack-1',
    part=mySubBlockwithCrack, dependent=OFF)

myAssembly = myModel.rootAssembly
myAssembly.suppressFeatures(('subBlock-1', 'symmCone-2',))

# Create an instance of the inner tube

myAssembly1 = myModel.rootAssembly
p = myModel.parts['innerTube']
innerTube = myAssembly1.Instance(name='innerTube-2', part=p,
    dependent=OFF)

# Create an instance of the outer tube

p = myModel.parts['outerTube']
outerTube = myAssembly1.Instance(name='outerTube-2', part=p,
    dependent=OFF)

# Translate both inner and outer tubes

innerTube.translate(vector=(-2.82201799706172e-07,
    2.82201799706172e-07, 42.0))
outerTube.translate(vector=(-2.82201799706172e-07,
    2.82201799706172e-07, 42.0))

# Merge the inner and outer tubes with the block keeping intersecting
# boundaries ON.

myAssembly1.PartFromBooleanMerge(name='subPartitionedBlock',
    instances=(myAssembly1.instances['subBlockwithCrack-1'],
    myAssembly1.instances['innerTube-2'], 
    myAssembly1.instances['outerTube-2'], ),
    keepIntersections=ON, domain=GEOMETRY)

mySubPartitionedBlock = myModel.parts['subPartitionedBlock']
myAssembly1.Instance(name='subPartitionedBlock-1',
    part=mySubPartitionedBlock, dependent=OFF)

# Suppress the instances

myAssembly = myModel.rootAssembly
myAssembly.suppressFeatures(('subBlockwithCrack-1',
    'innerTube-2', 'outerTube-2', ))

#---------------------------------------------------------------------------

# In the part module, create additional partitions
# on the part

myFinalSubBlock = myModel.parts['subPartitionedBlock']
myViewport.setValues(displayedObject=myFinalSubBlock)

pickedCells = myFinalSubBlock.cells
v1 = myFinalSubBlock.vertices.findAt((20.606602,-10.606602,42.))
v2 = myFinalSubBlock.vertices.findAt((0.,-10.606602,42.))
v3 = myFinalSubBlock.vertices.findAt((0.,-10.606602,21.393398))

myFinalSubBlock.PartitionCellByPlaneThreePoints(point1=v1,
    point2=v2, point3=v3, cells=pickedCells)

#---------------------------------------------------------------------------

# In the assembly module, create the remaining partitions
# using the merge/cut option

myAssembly1 = myModel.rootAssembly
myAssembly1.regenerate()

myAssembly = myModel.rootAssembly
myViewport.setValues(displayedObject=myAssembly)

p = myModel.parts['lowerInnerShell']
LIShell = myAssembly1.Instance(name='lowerInnerShell-2',
    part=p, dependent=OFF)
p = myModel.parts['lowerOuterShell']
LOShell = myAssembly1.Instance(name='lowerOuterShell-2',
    part=p, dependent=OFF)
p = myModel.parts['upperOuterShell']
UOShell = myAssembly1.Instance(name='upperOuterShell-2',
    part=p, dependent=OFF)

LIShell.translate(vector=
    (-2.82201799706172e-07,2.82201799706172e-07,42.0))
LOShell.translate(vector=
    (-2.82201799706172e-07, 2.82201799706172e-07, 42.0))
UOShell.translate(vector=
    (-2.82201799706172e-07, 2.82201799706172e-07, 42.0))

myAssembly1.PartFromBooleanMerge(name='subFinalBlock',
    instances=(myAssembly1.instances['subPartitionedBlock-1'],
    myAssembly1.instances['lowerInnerShell-2'], 
    myAssembly1.instances['lowerOuterShell-2'],
    myAssembly1.instances['upperOuterShell-2'], ), 
    keepIntersections=ON, domain=GEOMETRY)

mySubFinalBlock = myModel.parts['subFinalBlock']
myAssembly1.Instance(name='subFinalBlock-1',
    part=mySubFinalBlock, dependent=OFF)

myAssembly = myModel.rootAssembly
myAssembly.suppressFeatures(('subPartitionedBlock-1',
    'lowerInnerShell-2', 'lowerOuterShell-2',
    'upperOuterShell-2', ))

myViewport.setValues(displayedObject=mySubFinalBlock)

pickedCells = mySubFinalBlock.cells
v1 = mySubFinalBlock.vertices.findAt((33.606602,-18.606602,42.))
v2 = mySubFinalBlock.vertices.findAt((10.9878,-18.606602,42.))
v3 = mySubFinalBlock.vertices.findAt((0.,-18.606602,31.0122))

mySubFinalBlock.PartitionCellByPlaneThreePoints(point1=v1,
    point2=v2, point3=v3, cells=pickedCells)

#---------------------------------------------------------------------------

# Sketch the partitions on the face of the block

f1 = mySubFinalBlock.faces.findAt((21.,-21.303301,42.))
e1 = mySubFinalBlock.edges.findAt((42,-21.303301,42.))
t = mySubFinalBlock.MakeSketchTransform(sketchPlane=f1, sketchUpEdge=e1, 
    sketchPlaneSide=SIDE1, origin=(21.0, -21.303301, 42.0))

mySketch = myModel.Sketch(name='partitionProfile', sheetSize=84.68, 
    gridSpacing=2.11, transform=t)
mySketch.setPrimaryObject(option=SUPERIMPOSE)

mySubFinalBlock.projectReferencesOntoSketch(sketch=mySketch,
    filter=COPLANAR_EDGES)
mySketch.Line(point1=(-10.0122002822018,2.6966992822018),
    point2=(-10.0122002822018,21.3-subModelDepth))
mySketch.Line(point1=(12.6066017177982,2.6966992822018),
    point2=(12.6066017177982,21.3-subModelDepth))

f = mySubFinalBlock.faces
pickedFaces = f[f1.index:(f1.index+1)]
mySubFinalBlock.PartitionFaceBySketch(sketchUpEdge=e1,
    faces=pickedFaces, sketch=mySketch)
mySketch.unsetPrimaryObject()
del myModel.sketches['partitionProfile']

# Sweep the above created edges to partition the block

pickedCells = mySubFinalBlock.cells
partitionEdge1 = mySubFinalBlock.edges.findAt((10.9878,-21.303301,42.))
pickedEdges1 = (partitionEdge1, )
sweepPath1 = mySubFinalBlock.edges.findAt((7.769548,-18.606602,34.230452))
mySubFinalBlock.PartitionCellBySweepEdge(sweepPath=sweepPath1,
    cells=pickedCells, edges=pickedEdges1)

pickedCells = mySubFinalBlock.cells
partitionEdge2 = mySubFinalBlock.edges.findAt((33.606602,-21.303301,42.))
pickedEdges2 = (partitionEdge2, )
sweepPath2 = mySubFinalBlock.edges.findAt((23.763456,-18.606602,18.236544))
mySubFinalBlock.PartitionCellBySweepEdge(sweepPath=sweepPath2,
    cells=pickedCells, edges=pickedEdges2)

#---------------------------------------------------------------------------

# Assign material properties

# Create a set for the cracked block

c = mySubFinalBlock.cells
mySubFinalBlock.Set(cells=c, name='subAll')

region = mySubFinalBlock.sets['subAll']
mySubFinalBlock.SectionAssignment(region=region,
    sectionName='SolidHomogeneous')

myAssembly.regenerate()
myAssembly = myModel.rootAssembly
myViewport.setValues(displayedObject=myAssembly)

#---------------------------------------------------------------------------

# In the assembly module, position the submodel in the
# correct position with respect to the global model

myAssembly1 = myModel.rootAssembly
p =  myModel.parts['partitionedBlock']
myAssembly1.Instance(name='partitionedBlock-1',
    part=p, dependent=OFF)

mySubFinalBlockIns = myAssembly1.instances['subFinalBlock-1']
mySubFinalBlockIns.translate(vector=(0.0,0.0,258.0))

myAssembly = myModel.rootAssembly
del myAssembly.features['partitionedBlock-1']

# Delete all the sets/boundary conditions/jobs
# created for the global model.

del myAssembly.sets['Cone']
del myAssembly.sets['XFace']
del myAssembly.sets['ZFace']
del myAssembly.sets['bottomFace']
del myAssembly.sets['crackLine']
del myAssembly.sets['seamCrackFaces']
del myAssembly.surfaces['topConeFace']
del myModel.steps['ApplyLoad']
del myAssembly.engineeringFeatures.cracks['Crack']
del myModel.boundaryConditions['XFixed']
del myModel.boundaryConditions['ZFixed']
del myModel.boundaryConditions['baseFixed']
del mdb.jobs['SymmConeCrackGl']
del mdb.jobs['SymmConeCrackOrphan']

#---------------------------------------------------------------------------

# Create a step for applying a load

myModel.StaticStep(name='subApplyLoad', previous='Initial',
    description='Apply load on the submodel')

#-------------------------------------------------------------------------

# Create all the necessary sets

# Create a set for the cone

cells1 = mySubFinalBlockIns.cells.findAt(((5.0,-5.0,294.0),),
    ((15.0,-8.0,292.0),), ((14.465002,-10.55,285.534998),),)
myAssembly.Set(cells=cells1, name='subCone')

# Create a set for the seam crack faces

faces1 = mySubFinalBlockIns.faces.findAt(
    ((9.571068,-3.535534,290.428932),),
    ((13.246068,-8.732769,286.753932),),
    ((14.496068,-10.500536,285.503932),),)
myAssembly.Set(faces=faces1, name='subSeamFaces')

# Create a set for the crack line

e1 = mySubFinalBlockIns.edges.findAt((14.571068,-10.606602,285.428932))
e = mySubFinalBlockIns.edges
edges1 = e[e1.index:(e1.index+1)]
myAssembly.Set(edges=edges1, name='subCrackLine')

# Create a surface set for the loading the face of the cone crack

s1 = mySubFinalBlockIns.faces.findAt((3.535534,0.,296.464466))
s = mySubFinalBlockIns.faces
side1Faces1 = s[s1.index:(s1.index+1)]
myAssembly.Surface(side1Faces=side1Faces1, name='subLoadFace')

#-------------------------------------------------------------------------


# Create interaction properties

# Assign seam crack properties

pickedRegions = myAssembly.sets['subSeamFaces']
myAssembly.engineeringFeatures.assignSeam(regions=pickedRegions)

# Create the contour integral definition for the crack

crackFront = crackTip = myAssembly.sets['subCrackLine']
v1 = mySubFinalBlockIns.vertices.findAt((10.,0.,300.))
v2 = mySubFinalBlockIns.vertices.findAt((20.606602,-10.606602,300.))
myAssembly.engineeringFeatures.ContourIntegral(name='Crack',
    symmetric=OFF, crackFront=crackFront, crackTip=crackTip, 
    extensionDirectionMethod=Q_VECTORS, qVectors=((v1, v2),), 
    midNodePosition=0.27, collapsedElementAtTip=SINGLE_NODE)

#-------------------------------------------------------------------------

# Create loads and boundary conditions 

# Create a set for the X face of the block

facesX = mySubFinalBlockIns.faces.findAt(((0.,-5.303301,261.18139),),
    ((0.,-21.303301,262.050257),), ((0.,-14.606602,261.686598),),
   ((0.,-21.303301,277.611853),), ((0.,-16.900594,277.463371),),
    ((0.,-12.900594,277.328471),), ((0.,-8.384776,277.176175),),
    ((0.,-3.081476,276.997321),), ((0.,-14.606602,294.699408),),
    ((0.,-5.303301,294.890862),), ((0.,-21.303301,294.561596),),
    ((0.,-9.461745,282.723851),), ((0.,-10.661698,279.393398),),
    ((0.,-10.5354,279.393398),), ((0.,-10.577109,279.4646),),)
myAssembly.Set(faces=facesX, name='subXFace')

# Create a set for the Z face of the block

facesZ = mySubFinalBlockIns.faces.findAt(((17.983835,-8.838835,300.),),
    ((22.536628,-16.900594,300.),), ((22.671529,-12.900594,300.),),
    ((22.823825,-8.384777,300.),), ((23.002679,-3.081476,300.),),
    ((22.388147,-21.303301,300.),), ((38.81861,-5.303301,300.),),
    ((38.313402,-14.606602,300.),), ((37.949743,-21.303301,300.),),
    ((5.438404,-21.303301,300.),), ((5.109137,-5.303301,300.),),
    ((5.300592,-14.606602,300.),), ((20.614087,-10.577911,300.),),
    ((20.534347,-10.576673,300.),), ((20.606602,-10.643926,300.),),)
myAssembly.Set(faces=facesZ, name='subZFace')


# Create a set for the driven boundary faces of the sub model
drivenfaces = mySubFinalBlockIns.faces.findAt(((32.881728,-24.,267.118272),),
    ((3.884774,-24.,296.115226),), ((15.766502,-24.,284.233498),),
    ((23.11,-21.303301,258.),), ((23.11,-14.606602,258.),),
    ((23.11,-5.303301,258.),), ((42.,-21.303301,279.),),
    ((42.,-5.303301,279.),), ((42.,-14.606602,279.),),)
myAssembly.Set(faces=drivenfaces, name='drivenBoundary')
myAssembly.Surface(side1Faces=drivenfaces, name='drivenBoundary')



# Apply the load

region = myAssembly.surfaces['subLoadFace']
myModel.Pressure(name='subPrLoad', createStepName='subApplyLoad',
    region=region, distributionType=UNIFORM, 
    magnitude=10.0)

# Submodel loads

region = myAssembly.surfaces['drivenBoundary']
myModel.SubmodelSB(name='submodelTraction', 
    createStepName='subApplyLoad', region=region, globalStep='1', 
    globalIncrement=0, globalDrivingRegion='', absoluteExteriorTolerance=0.0, 
    exteriorTolerance=0.05)

myModel.InertiaRelief(name='inertiaReliefVertical', 
    createStepName='subApplyLoad', u1=0, u2=1, u3=0, ur1=0, ur2=0, ur3=0, 
    localCoordinates=None)

# Apply the boundary conditions

# Fix the model in the Z direction

region = myAssembly.sets['subZFace']
myModel.DisplacementBC(name='subZFixed', createStepName='Initial',
    region=region, u3=0.0, distributionType=UNIFORM,
    localCsys=None)

# Fix the model in the X direction

region = myAssembly.sets['subXFace']
myModel.DisplacementBC(name='subXFixed', createStepName='Initial',
    region=region, u1=0.0, distributionType=UNIFORM, localCsys=None)

#---------------------------------------------------------------------------

# Create a mesh 

# Assign meshing controls to the respective regions

pickedRegions = mySubFinalBlockIns.cells.findAt(
    ((20.492795,-10.559461,300.),), ((20.606602,-10.703926,300.),),
    ((20.650536,-10.500536,300.),),)
myAssembly.setMeshControls(regions=pickedRegions,
    elemShape=WEDGE, technique=SWEEP)

# All the remaining cells will be meshed with hex elements using
# structured meshing. This is also the default.

elemType1 = mesh.ElemType(elemCode=C3D20R, elemLibrary=STANDARD, 
    kinematicSplit=AVERAGE_STRAIN, secondOrderAccuracy=OFF, 
    hourglassControl=STIFFNESS, distortionControl=OFF)
elemType2 = mesh.ElemType(elemCode=C3D15, elemLibrary=STANDARD)
elemType3 = mesh.ElemType(elemCode=C3D10M, elemLibrary=STANDARD)
cells1 = mySubFinalBlockIns.cells
pickedRegions =(cells1, )
myAssembly.setElementType(regions=pickedRegions,
    elemTypes=(elemType1, elemType2, elemType3))

# inner tube seeds

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((0.,-10.606602,279.325073),), ((0.,-10.606602,279.456902),),
    ((0.,-10.561698,279.438302),), ((20.486602,-10.606602,300.),),
    ((20.666602,-10.606602,300.),), ((20.553569,-10.553569,300.),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=1, constraint=FIXED)

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((20.329438,-10.491797,300.),), ((0.,-10.491797,279.670562),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=3, constraint=FIXED)

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((0.,-10.329438,279.278593),), ((20.721407,-10.329438,300.),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=9, constraint=FIXED)

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((0.,-10.906602,279.393398),), ((20.606602,-10.906602,300.),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=12, constraint=FIXED)

####

# outer tube seeds

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((0.,-10.606602,276.743398),), ((23.256602,-10.606602,300.),),
    ((17.956602,-10.606602,300.),), ((0.,-8.732769,281.267231),),
    ((18.732769,-8.732769,300.),), ((0.,-10.606602,282.043398),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=12, constraint=FIXED)

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((0.,-8.693185,284.012796),), ((15.987204,-8.693185,300.),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=3, constraint=FIXED)

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((0.,-5.987204,277.479981),), ((22.520019,-5.987204,300.),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=9, constraint=FIXED)

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((0.,-15.606602,279.393398),), ((20.606602,-15.606602,300.),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=12, constraint=FIXED)

####

# inner and outer tube swept edge seeds

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((14.7832,-10.606602,285.2168),), ((14.571068,-10.606602,285.428932),),
    ((14.421068,-10.39447,285.578932),),
    ((14.358936,-10.606602,285.641064),),
    ((18.106602,-10.606602,281.893398),),
    ((11.035534,-10.606602,288.964466),),
    ((12.071068,-7.071068,287.928932),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=38, constraint=FIXED)

####

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((23.763456,-18.606602,276.236544),),
    ((7.769548,-18.606602,292.230452),),
    ((25.606602,0.,274.393398),),
    ((7.071068,0.,292.928932),), ((7.769548,-24.,292.230452),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=38, constraint=FIXED)

####

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((0.,0.,276.893398),), ((23.106602,0.,300.),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=9, constraint=FIXED)

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((0.,-18.606602,277.702799),),
    ((22.297201,-18.606602,300.),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=12, constraint=FIXED)

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((0.,-5.303301,269.090097),), ((30.909903,-5.303301,300.),),
    ((42.,-5.303301,300.),), ((0.,-3.535534,286.464466),),
    ((0.,-5.303301,258.),), ((42.,-5.303301,258.),),
    ((13.535534,-3.535534,300.),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=5, constraint=FIXED)

pickedEdges = mySubFinalBlockIns.edges.findAt(((0.,-5.303301,300.),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=6, constraint=FIXED)

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((0.,-14.606602,270.393398),), ((0.,-14.606602,258.),),
    ((0.,-14.606602,286.702799),), ((29.606602,-14.606602,300.),),
    ((13.297201,-14.606602,300.),), ((42.,-14.606602,300.),),
    ((0.,-14.606602,300.),), ((42.,-14.606602,258.),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=4, constraint=FIXED)

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((0.,-18.606602,262.196699),), ((0.,-24.,262.196699),),
    ((37.803301,-24.,300.),), ((37.803301,-18.606602,300.),),
    ((0.,-10.606602,266.196699),), ((33.803301,-10.606602,300.),),
    ((39.106602,0.,300.),), ((0.,0.,260.893398),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=3, constraint=FIXED)

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((21.,-18.606602,258.),), ((21.,-24.,258.),),
    ((21.,-10.606602,258.),), ((21.,0.,258.),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=18, constraint=FIXED)

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((42.,-18.606602,279.),), ((42.,-10.606602,279.),),
    ((42.,-24.,279.),), ((42.,0.,279.),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=22, constraint=FIXED)

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((0.,-21.303301,266.393398),),
    ((33.606602,-21.303301,300.),),
    ((0.,-21.303301,258.),),
    ((0.,-21.303301,289.0122),),
    ((10.9878,-21.303301,300.),),
    ((42.,-21.303301,300.),),
    ((0.,-21.303301,300.),),
    ((42.,-21.303301,258.),),)
myAssembly.seedEdgeBySize(edges=pickedEdges,
    size=2.7, constraint=FIXED)

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((5.4939,-24.,300.),), ((5.4939,-18.606602,300.),),
    ((7.803301,-10.606602,300.),), ((5.,0.,300.),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=20, constraint=FIXED)

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((5.4939,-24.,300.),), ((5.4939,-18.606602,300.),),
    ((7.803301,-10.606602,300.),), ((5.,0.,300.),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=20, constraint=FIXED)

pickedEdges = mySubFinalBlockIns.edges.findAt(
    ((0.,-24.,294.5061),), ((0.,-18.606602,294.5061),),
    ((0.,-10.606602,292.196699),), ((0.,0.,295.),),)
myAssembly.seedEdgeByNumber(edges=pickedEdges,
    number=20, constraint=FIXED)

partInstances = (mySubFinalBlockIns, )
myAssembly.generateMesh(regions=partInstances)

#---------------------------------------------------------------------------

# Request history output for the crack

myModel.historyOutputRequests.changeKey(fromName='H-Output-1',
    toName='JInt')
myModel.historyOutputRequests['JInt'].setValues(contourIntegral='Crack',
    numberOfContours=5)
myModel.HistoryOutputRequest(name='StressInt',
    createStepName='subApplyLoad', contourIntegral='Crack',
    numberOfContours=5, contourType=K_FACTORS)
myModel.HistoryOutputRequest(name='TStr',
    createStepName='subApplyLoad', contourIntegral='Crack',
    numberOfContours=5, contourType=T_STRESS)

#---------------------------------------------------------------------------

# Create a job and write an input file to get the orphan mesh

mdb.Job(name=subModelName, model=subModelName, type=ANALYSIS, 
    description='Create the job to get an orphan mesh of the submodel')
mdb.jobs[subModelName].writeInput()

#---------------------------------------------------------------------------

# Import the input file so that there is an orphan mesh
# This orphan mesh will be used to edit the q vectors

mdb.ModelFromInputFile(name=subOrphanModelName, 
    inputFileName='SymmConeCrackSubSb_near.inp')
modelName = subOrphanModelName
myModel = mdb.models[modelName]
myAssembly = myModel.rootAssembly
myViewport.setValues(displayedObject=myAssembly)
myViewport.makeCurrent()

#---------------------------------------------------------------------------

# Edit the model attributes to refer to the global model ODB file
# to drive the sub model.

myModel.setValues(description='Symmetric submodel of a cone crack', 
    globalJob='SymmConeCrackOrphan.odb')

#---------------------------------------------------------------------------

# Delete the history output and the boundary conditions

del myModel.historyOutputRequests['Crack-1']
del myModel.historyOutputRequests['Crack-2']
del myModel.historyOutputRequests['Crack-3']
#del myModel.boundaryConditions['Disp-BC-3']
#del myModel.boundaryConditions['Disp-BC-4']

# Rename the load and boundary conditions

myModel.boundaryConditions.changeKey(fromName='Disp-BC-1', toName='subXFixed')
myModel.boundaryConditions.changeKey(fromName='Disp-BC-2', toName='subZFixed')
#myModel.boundaryConditions.changeKey(fromName='Sub-BC-1', toName='submodelBC')
myModel.loads.changeKey(fromName='SURFFORCE-1', toName='subPrLoad')
myModel.loads.changeKey(fromName='SUBMODELDS-1', toName='submodelTraction')

myModel.boundaryConditions['subXFixed'].reset('subApplyLoad')
myModel.boundaryConditions['subZFixed'].reset('subApplyLoad')

#---------------------------------------------------------------------------

# Recreate interaction properties

del myAssembly.engineeringFeatures.cracks['JINT_CRACK']
del myAssembly.engineeringFeatures.cracks['STRESSINT_CRACK']
myAssembly.engineeringFeatures.cracks.changeKey(fromName='TSTR_CRACK',
    toName='Crack')

# Edit the q vector definition

n1 = ((17.071068,-7.071068,300.),
      (17.067421,-7.071068,299.647186),
      (17.056484,-7.071068,299.294525),
      (17.038261,-7.071068,298.942169),
      (17.012762,-7.071068,298.590271),
      (16.979994,-7.071068,298.238983),
      (16.939972,-7.071068,297.888428),
      (16.892714,-7.071068,297.538788),
      (16.83824,-7.071068,297.190186),
      (16.776573,-7.071068,296.842804),
      (16.707741,-7.071068,296.496765),
      (16.631771,-7.071068,296.152191),
      (16.548698,-7.071068,295.809296),
      (16.458553,-7.071068,295.46817),
      (16.36138,-7.071068,295.128998),
      (16.257217,-7.071068,294.791901),
      (16.146111,-7.071068,294.457031),
      (16.028105,-7.071068,294.124542),
      (15.903255,-7.071068,293.794525),
      (15.77161,-7.071068,293.467194),
      (15.633228,-7.071068,293.142639),
      (15.488169,-7.071068,292.821014),
      (15.336493,-7.071068,292.502441),
      (15.178267,-7.071068,292.187073),
      (15.013556,-7.071068,291.875061),
      (14.842431,-7.071068,291.566528),
      (14.664968,-7.071068,291.261566),
      (14.481239,-7.071068,290.960358),
      (14.291326,-7.071068,290.662994),
      (14.095306,-7.071068,290.369659),
      (13.893267,-7.071068,290.080414),
      (13.685291,-7.071068,289.79538),
      (13.471471,-7.071068,289.51474),
      (13.251896,-7.071068,289.238556),
      (13.02666,-7.071068,288.96698),
      (12.795859,-7.071068,288.700104),
      (12.559592,-7.071068,288.43808),
      (12.317961,-7.071068,288.180969),
      (12.071068,-7.071068,287.928925),
      (11.819017,-7.071068,287.682037),
      (11.561919,-7.071068,287.440399),
      (11.299882,-7.071068,287.204132),
      (11.033018,-7.071068,286.973328),
      (10.761441,-7.071068,286.748108),
      (10.485267,-7.071068,286.528534),
      (10.204614,-7.071068,286.314697),
      (9.919601,-7.071068,286.10672),
      (9.630352,-7.071068,285.904694),
      (9.336989,-7.071068,285.708679),
      (9.039638,-7.071068,285.518768),
      (8.738424,-7.071068,285.335022),
      (8.433478,-7.071068,285.157562),
      (8.12493,-7.071068,284.98645),
      (7.812912,-7.071068,284.821747),
      (7.497555,-7.071068,284.663513),
      (7.178996,-7.071068,284.511841),
      (6.85737,-7.071068,284.36676),
      (6.532815,-7.071068,284.228394),
      (6.205469,-7.071068,284.096741),
      (5.875473,-7.071068,283.971893),
      (5.542967,-7.071068,283.853882),
      (5.208093,-7.071068,283.742798),
      (4.870994,-7.071068,283.638611),
      (4.531815,-7.071068,283.541443),
      (4.1907,-7.071068,283.451294),
      (3.847794,-7.071068,283.368225),
      (3.503245,-7.071068,283.292267),
      (3.1572,-7.071068,283.223419),
      (2.809805,-7.071068,283.161743),
      (2.461211,-7.071068,283.1073),
      (2.111565,-7.071068,283.060028),
      (1.761018,-7.071068,283.02002),
      (1.409718,-7.071068,282.987244),
      (1.057815,-7.071068,282.961731),
      (705.461E-03,-7.071068,282.943512),
      (352.806E-03,-7.071068,282.932587),
      (0.,-7.071068,282.928925))

n2 = ((20.606602,-10.606602,300.),
      (20.6022,-10.606602,299.574127),
      (20.588999,-10.606602,299.148438),
      (20.567001,-10.606602,298.723114),
      (20.536221,-10.606602,298.298309),
      (20.496666,-10.606602,297.874268),
      (20.448355,-10.606602,297.451111),
      (20.39131,-10.606602,297.029053),
      (20.325554,-10.606602,296.608276),
      (20.251116,-10.606602,296.188934),
      (20.168028,-10.606602,295.77121),
      (20.076324,-10.606602,295.355286),
      (19.976046,-10.606602,294.941376),
      (19.867233,-10.606602,294.529602),
      (19.749933,-10.606602,294.120178),
      (19.624197,-10.606602,293.713287),
      (19.49008,-10.606602,293.309052),
      (19.347635,-10.606602,292.907684),
      (19.196926,-10.606602,292.509338),
      (19.038017,-10.606602,292.114197),
      (18.870975,-10.606602,291.722412),
      (18.695873,-10.606602,291.334198),
      (18.512785,-10.606602,290.949646),
      (18.321789,-10.606602,290.56897),
      (18.122965,-10.606602,290.192352),
      (17.916401,-10.606602,289.819885),
      (17.702183,-10.606602,289.451782),
      (17.480402,-10.606602,289.088196),
      (17.251156,-10.606602,288.729248),
      (17.01454,-10.606602,288.375122),
      (16.770657,-10.606602,288.02597),
      (16.519609,-10.606602,287.681946),
      (16.261505,-10.606602,287.34317),
      (15.996453,-10.606602,287.009796),
      (15.724569,-10.606602,286.681976),
      (15.445969,-10.606602,286.359833),
      (15.160769,-10.606602,286.043518),
      (14.869094,-10.606602,285.733185),
      (14.571068,-10.606602,285.428925),
      (14.266817,-10.606602,285.13092),
      (13.956471,-10.606602,284.839233),
      (13.640164,-10.606602,284.554047),
      (13.318031,-10.606602,284.275421),
      (12.990209,-10.606602,284.00354),
      (12.656837,-10.606602,283.738495),
      (12.318058,-10.606602,283.480377),
      (11.974018,-10.606602,283.22934),
      (11.624864,-10.606602,282.985474),
      (11.270743,-10.606602,282.74884),
      (10.911808,-10.606602,282.519592),
      (10.548211,-10.606602,282.297821),
      (10.180109,-10.606602,282.083588),
      (9.807658,-10.606602,281.877045),
      (9.431018,-10.606602,281.678223),
      (9.050349,-10.606602,281.487213),
      (8.665814,-10.606602,281.304138),
      (8.277577,-10.606602,281.129028),
      (7.885805,-10.606602,280.961975),
      (7.490664,-10.606602,280.80307),
      (7.092323,-10.606602,280.652374),
      (6.690953,-10.606602,280.509918),
      (6.286724,-10.606602,280.375793),
      (5.87981,-10.606602,280.250061),
      (5.470384,-10.606602,280.132751),
      (5.058622,-10.606602,280.023956),
      (4.644698,-10.606602,279.923676),
      (4.228791,-10.606602,279.83197),
      (4.228791,-10.606602,279.83197),
      (3.811077,-10.606602,279.748871),
      (3.391735,-10.606602,279.674438),
      (2.970945,-10.606602,279.608704),
      (2.548885,-10.606602,279.551636),
      (2.125736,-10.606602,279.503326),
      (1.701679,-10.606602,279.463776),
      (1.276896,-10.606602,279.433014),
      (851.567E-03,-10.606602,279.411011),
      (425.875E-03,-10.606602,279.397797),
      (0.,-10.606602,279.393402))

myAssembly.engineeringFeatures.cracks['Crack'].setValues(symmetric=OFF,
    extensionDirectionMethod=Q_VECTORS, qVectors=((n1[0],n2[0]),
    (n1[1],n2[1]), (n1[2],n2[2]), (n1[3],n2[3]), (n1[4],n2[4]),
    (n1[5],n2[5]), (n1[6],n2[6]), (n1[7],n2[7]), (n1[8],n2[8]),
    (n1[9],n2[9]), (n1[10],n2[10]), (n1[11],n2[11]), (n1[12],n2[12]),
    (n1[13],n2[13]), (n1[14],n2[14]), (n1[15],n2[15]), (n1[16],n2[16]),
    (n1[17],n2[17]), (n1[18],n2[18]), (n1[19],n2[19]), (n1[20],n2[20]),
    (n1[21],n2[21]), (n1[22],n2[22]), (n1[23],n2[23]), (n1[24],n2[24]),
    (n1[24],n2[24]), (n1[25],n2[25]), (n1[26],n2[26]), (n1[27],n2[27]),
    (n1[28],n2[28]), (n1[29],n2[29]), (n1[30],n2[30]), (n1[31],n2[31]),
    (n1[32],n2[32]), (n1[33],n2[33]), (n1[34],n2[34]), (n1[35],n2[35]),
    (n1[36],n2[36]), (n1[37],n2[37]), (n1[38],n2[38]), (n1[39],n2[39]),
    (n1[40],n2[40]), (n1[41],n2[41]), (n1[42],n2[42]), (n1[43],n2[43]),
    (n1[44],n2[44]), (n1[45],n2[45]), (n1[46],n2[46]), (n1[47],n2[47]),
    (n1[48],n2[48]), (n1[49],n2[49]), (n1[50],n2[50]), (n1[51],n2[51]),
    (n1[52],n2[52]), (n1[53],n2[53]), (n1[54],n2[54]), (n1[55],n2[55]),
    (n1[56],n2[56]), (n1[57],n2[57]), (n1[58],n2[58]), (n1[59],n2[59]),
    (n1[60],n2[60]), (n1[61],n2[61]), (n1[62],n2[62]), (n1[63],n2[63]),
    (n1[64],n2[64]), (n1[65],n2[65]), (n1[66],n2[66]), (n1[67],n2[67]),
    (n1[68],n2[68]), (n1[69],n2[69]), (n1[70],n2[70]), (n1[71],n2[71]),
    (n1[72],n2[72]), (n1[73],n2[73]), (n1[74],n2[74]), (n1[75],n2[75])))

#---------------------------------------------------------------------------

# Create history output

myModel.HistoryOutputRequest(name='JInt', createStepName='subApplyLoad',
    contourIntegral='Crack', numberOfContours=5)
myModel.HistoryOutputRequest(name='StressInt', createStepName='subApplyLoad',
    contourIntegral='Crack', numberOfContours=5, contourType=K_FACTORS)
myModel.HistoryOutputRequest(name='TStr', createStepName='subApplyLoad',
    contourIntegral='Crack', numberOfContours=5, 
    contourType=T_STRESS)

#---------------------------------------------------------------------------

# Create a job and submit it for analysis

mdb.Job(name=modelName, model=modelName,
        type=ANALYSIS, description='Submit the modified job')
mdb.jobs[modelName].writeInput()
mdb.saveAs(pathName=modelName)

#---------------------------------------------------------------------------











                                        
    











