I'm trying to script a Python code to run in Abaqus. I want to simulate 3 layer springs with 3 different opening angles between their "wings". I added a for loop to the code so everything gets done for each angle. I also added a line to get different part names for every spring with each angle. But my problem is, that at the end when I let the code run in Abaqus I only get a part named "spring_160deg". I think the other two parts are getting overwritten somewhere in my code.
Can someone tell me where I make a mistake?
Thanks in advance!
My code looks like this:
# ---------------------------------------------------------------------------------------------------------
# Step 1: Import statements for this program
# ---------------------------------------------------------------------------------------------------------
from abaqus import *
from abaqusConstants import*
from caeModules import*
import os
import numpy as np
import math
session.journalOptions.setValues(replayGeometry=COORDINATE, recoverGeometry=COORDINATE)
DIR0 = os.path.abspath('')
TOL = 1e-6
# Step 2: Parameters used for the geometry, material, load and mesh of the rubber metal spring (N/mm/s-System is used)
# ---------------------------------------------------------------------------------------------------------
t1 = 5 # Layer thickness of the lower and upper metal layer [mm]
t2 = 10 # Layer thickness of the rubber [mm]
L = 70 # Length of the "wings" of the metal rubber spring [mm]
winkel = [120, 140, 160] # Angles of the rubber metal spring versions [Degree]
e1 = 210000 # E-Modulus of the metal layers [MPa]
e2 = 5.5 # E-Modulus of the rubber [MPa]
v1 = 0.3 # Poisson's ratio of the metal layers []
v2 = 0.49 # Poisson's ratio of the rubber []
c = 1 # Length of the crack [mm]
C10 = 0.7083 # Coefficient for "MR" Material
C01 = 0.1417 # Coefficient for "MR" Material
D = 0.03565 # Coefficient for "MR" Material
mesh_size = 1.7 # Size of the mesh
xKraft = [10,20,30,40,50] # The x-Part of the force that is used to test the spring
yKraft = [10,20,30,40,50] # The y-Part of the force that is used to test the spring
crack_pos = 'bottom' # Use phrases "top" or "bottom" for the area of the crack
job_name = 'Crack' # This is the name of the odb file
# Model functions
# ---------------------------------------------------------------------------------------------------------
def make_geometry(model, geomPar, crack_pos, mesh_size) :
t1, t2, L, w, c = geomPar
a = w * (pi / 180)
#draw the sketch
part_name = 'spring_{}deg'.format(w)
# Step 1: The important Points of the geometry are created here and used later
# M = Middle
M0 = (0.0, 0.0)
M1 = (0, t1/cos(90*(pi/180)-(a/2)))
M2 = (0, (t1+t2)/cos(90*(pi/180)-(a/2)))
M3 = (0, (2*t1+t2)/cos(90*(pi/180)-(a/2)))
# R = Right
R0 = (L*cos(90*(pi/180)-(a/2)), L*sin(90*(pi/180)-(a/2)))
R1 = (L*cos(90*(pi/180)-(a/2))-t1*sin(90*(pi/180)-(a/2)),
L*sin(90*(pi/180)-(a/2))+t1*cos(90*(pi/180)-(a/2)))
R2 = (L*cos(90*(pi/180)-(a/2))-t1*sin(90*(pi/180)-(a/2))-t2*sin(90*(pi/180)-(a/2)),
L*sin(90*(pi/180)-(a/2))+t1*cos(90*(pi/180)-(a/2))+t2*cos(90*(pi/180)-(a/2)))
R3 = (L*cos(90*(pi/180)-(a/2))-2*t1*sin(90*(pi/180)-(a/2))-t2*sin(90*(pi/180)-(a/2)),
L*sin(90*(pi/180)-(a/2))+2*t1*cos(90*(pi/180)-(a/2))+t2*cos(90*(pi/180)-(a/2)))
# L = Left
L0 = (-L*cos(90*(pi/180)-(a/2)), L*sin(90*(pi/180)-(a/2)))
L1 = (-L*cos(90*(pi/180)-(a/2))+t1*sin(90*(pi/180)-(a/2)),
L*sin(90*(pi/180)-(a/2))+t1*cos(90*(pi/180)-(a/2)))
L2 = (-L*cos(90*(pi/180)-(a/2))+t1*sin(90*(pi/180)-(a/2))+t2*sin(90*(pi/180)-(a/2)),
L*sin(90*(pi/180)-(a/2))+t1*cos(90*(pi/180)-(a/2))+t2*cos(90*(pi/180)-(a/2)))
L3 = (-L*cos(90*(pi/180)-(a/2))+2*t1*sin(90*(pi/180)-(a/2))+t2*sin(90*(pi/180)-(a/2)),
L*sin(90*(pi/180)-(a/2))+2*t1*cos(90*(pi/180)-(a/2))+t2*cos(90*(pi/180)-(a/2)))
# C = Crack
# on the bottom of the rubber layer
C1 = (L*cos(90*(pi/180)-(a/2))-t1*sin(90*(pi/180)-(a/2))-c*cos(90*(pi/180)-(a/2)),
L*sin(90*(pi/180)-(a/2))+t1*cos(90*(pi/180)-(a/2))-c*sin(90*(pi/180)-(a/2)))
C11 = (L*cos(90*(pi/180)-(a/2))-t1*sin(90*(pi/180)-(a/2))-(c/2)*cos(90*(pi/180)-(a/2)),
L*sin(90*(pi/180)-(a/2))+t1*cos(90*(pi/180)-(a/2))-(c/2)*sin(90*(pi/180)-(a/2)),
0)
# on top of the rubber layer
C2 = (L*cos(90*(pi/180)-(a/2))-t1*sin(90*(pi/180)-(a/2))-t2*sin(90*(pi/180)-(a/2))-c*cos(90*(pi/180)-(a/2)),
L*sin(90*(pi/180)-(a/2))+t1*cos(90*(pi/180)-(a/2))+t2*cos(90*(pi/180)-(a/2))-c*sin(90*(pi/180)-(a/2)))
C22 = (L*cos(90*(pi/180)-(a/2))-t1*sin(90*(pi/180)-(a/2))-t2*sin(90*(pi/180)-(a/2))-(c/2)*cos(90*(pi/180)-(a/2)),
L*sin(90*(pi/180)-(a/2))+t1*cos(90*(pi/180)-(a/2))+t2*cos(90*(pi/180)-(a/2))-(c/2)*sin(90*(pi/180)-(a/2)),
0)
# Points on the lines for the creation of the sets
R00 = ((L/2)*cos(90*(pi/180)-(a/2)), (L/2)*sin(90*(pi/180)-(a/2)), 0)
L00 = (-(L/2)*cos(90*(pi/180)-(a/2)), (L/2)*sin(90*(pi/180)-(a/2)), 0)
R33 = ((L/2)*cos(90*(pi/180)-(a/2))-2*t1*sin(90*(pi/180)-(a/2))-t2*sin(90*(pi/180)-(a/2)),
(L/2)*sin(90*(pi/180)-(a/2))+2*t1*cos(90*(pi/180)-(a/2))+t2*cos(90*(pi/180)-(a/2)),
0)
L33 = (-(L/2)*cos(90*(pi/180)-(a/2))+2*t1*sin(90*(pi/180)-(a/2))+t2*sin(90*(pi/180)-(a/2)),
(L/2)*sin(90*(pi/180)-(a/2))+2*t1*cos(90*(pi/180)-(a/2))+t2*cos(90*(pi/180)-(a/2)),
0)
# Points in the middle of the faces
M00 = (0, (t1/cos(90*(pi/180)-(a/2)))/2, 0)
M11 = (0, t1/cos(90*(pi/180)-(a/2))+(t2/cos(90*(pi/180)-(a/2)))/2, 0)
M22 = (0, (t1+t2)/cos(90*(pi/180)-(a/2))+(t1/cos(90*(pi/180)-(a/2)))/2, 0)
# Step 2: Draw the sketch for the model
# ---------------------------------------------------------------------------------------------------------
s = model.ConstrainedSketch(name=part_name, sheetSize=200.0)
s.Line(point1=M0, point2=R0)
s.Line(point1=R0, point2=R1)
s.Line(point1=R1, point2=R2)
s.Line(point1=R2, point2=R3)
s.Line(point1=R3, point2=M3)
s.Line(point1=M3, point2=L3)
s.Line(point1=L3, point2=L2)
s.Line(point1=L2, point2=L1)
s.Line(point1=L1, point2=L0)
s.Line(point1=L0, point2=M0)
# Step 3: Create the part
# ---------------------------------------------------------------------------------------------------------
p = model.Part(name=part_name, dimensionality=TWO_D_PLANAR, type=DEFORMABLE_BODY)
p.BaseShell(sketch=s)
# Step 4: Create Sets, Partitions, Surfaces and Reference Points
# ---------------------------------------------------------------------------------------------------------
profile_name = 'profile_{}deg'.format(w)
p.Set(name='all', faces=p.faces[:])
p.Set(name='top', edges=p.edges.findAt((R33,), (L33,)))
p.Set(name='bottom', edges=p.edges.findAt((R00,), (L00,)))
rp = p.ReferencePoint(point=(0, 2 * t1 + t2 + 20, 0))
p.Set(name='RP', referencePoints=(p.referencePoints[rp.id],))
# Create the partition of the layers
p = model.parts[part_name]
s = model.ConstrainedSketch(name=profile_name, sheetSize=264.1, gridSpacing=6.6)
s.setPrimaryObject(option=SUPERIMPOSE)
p.projectReferencesOntoSketch(sketch=s, filter=COPLANAR_EDGES)
s.Line(point1=L1, point2=M1)
s.Line(point1=L2, point2=M2)
if crack_pos == 'bottom':
s.Line(point1=M2, point2=R2)
s.Line(point1=M1, point2=C1)
s.Line(point1=C1, point2=R1)
else:
s.Line(point1=M1, point2=R1)
s.Line(point1=M2, point2=C2)
s.Line(point1=C2, point2=R2)
p.PartitionFaceBySketch(faces=p.faces, sketch=s)
s.unsetPrimaryObject()
del mdb.models['Model-1'].sketches[profile_name]
if crack_pos == 'bottom':
p.Set(name='bottom-crack', edges=p.edges.findAt((C11,)))
else:
p.Set(name='top-crack', edges=p.edges.findAt((C22,)))
p.Set(name='rubber', faces=p.faces.findAt((M11,)))
p.Set(name='metal', faces=p.faces.findAt((M00,), (M22,)))
# Create the partition left and right
p = model.parts[part_name]
s = model.ConstrainedSketch(name=profile_name, sheetSize=264.1, gridSpacing=6.6)
s.setPrimaryObject(option=SUPERIMPOSE)
p.projectReferencesOntoSketch(sketch=s, filter=COPLANAR_EDGES)
# Lines for Partition
s.Line(point1=M0, point2=M3)
p.PartitionFaceBySketch(faces=p.faces, sketch=s)
s.unsetPrimaryObject()
del mdb.models['Model-1'].sketches[profile_name]
# Step 5: Create the mesh
# ---------------------------------------------------------------------------------------------------------
p.seedPart(size=mesh_size)
p.generateMesh()
return p
def make_sections(model, p, matPar) :
e1, v1, C10, C01, D = matPar
# Create Material, create and assign sketchOptions
# Step 1: Assign Material Properties to the different layers/sets
# ---------------------------------------------------------------------------------------------------------
ste = model.Material(name='Steel')
ste.Elastic(table=((e1, v1),))
rub = model.Material(name='Rubber')
rub.Hyperelastic(materialType=ISOTROPIC, testData=OFF, type=MOONEY_RIVLIN, volumetricResponse=VOLUMETRIC_DATA,
table=((C10, C01, D),))
model.HomogeneousSolidSection(name='Steel-Plates', material='Steel', thickness=None)
p.SectionAssignment(region=p.sets['metal'], sectionName='Steel-Plates', thicknessAssignment=FROM_SECTION)
model.HomogeneousSolidSection(name='Rubber-Layer', material='Rubber', thickness=None)
p.SectionAssignment(region=p.sets['rubber'], sectionName='Rubber-Layer', thicknessAssignment=FROM_SECTION)
return
# One function for the whole model (create, run, evaluate)
def spring_model(geomPar, matPar, mesh_size, crack_pos):
t1, t2, L, w, c = geomPar
e1, v1, C10, C01, D = matPar
# Step 1: Sanity check for the variables
# ---------------------------------------------------------------------------------------------------------
if t1 < 0:
raise ValueError('The thickness of the metal layer must be positive')
if t2 < 0:
raise ValueError('The thickness of the rubber layer must be positive')
if L < 0:
raise ValueError('The length of the spring must be positive')
if w <= 90 or w >= 180:
raise ValueError('The angle between the two wings of the spring must be between 90 and 180 degrees')
if e1 < 0:
raise ValueError('The E-Modulus of the metal layers must be positive')
if e2 < 0:
raise ValueError('The E-Modulus of the rubber layer must be positive')
if v1 <= 0 or v1 >= 0.5:
raise ValueError('The Poissons ratio of the metal layers must be placed between 0 and 0.5')
if v2 <= 0 or v2 >= 0.5:
raise ValueError('The Poissons ratio of the rubber layer must be placed between 0 and 0.5')
# reset the model
Mdb()
model = mdb.models['Model-1']
# make the parts, mesh it and return it
p = make_geometry(model, geomPar, crack_pos, mesh_size)
# make materials and sections
make_sections(model, p, matPar)
return model
for w in winkel:
geomPar = (t1, t2, L, w, c)
matPar = (e1, v1, C10, C01, D)
model = spring_model(geomPar, matPar, mesh_size, crack_pos)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744868412a4598110.html
评论列表(0条)