Press "Enter" to skip to content

Efficient FE Modelling: Appendix

The whole original input file of chapter 7:

*Heading
** plate with hole model, SI units
*Preprint, echo=NO, model=NO, history=NO, contact=NO
**
*Part, name=plate
*Node
      1,           0.,           5.
      2,           0.,          20.
      3,  0.975451589,   4.90392637
      4,    2.7778511,   4.15734816
      5,   3.53553391,   3.53553391
      6,   4.15734816,    2.7778511
      7,   4.90392637,  0.975451589
      8,           5.,           0.
      9,          20.,           0.
     10,          20.,          20.
     11,           0.,         8.75
     12,           0.,         12.5
     13,           0.,        16.25
     14,   1.91341722,   4.61939764
     15,   4.61939764,   1.91341722
     16,   17.8756886,           0.
     17,   15.9219751,           0.
     18,   14.1251621,           0.
     19,   12.4726467,           0.
     20,   10.9528408,           0.
     21,   9.55508804,           0.
     22,   8.26958656,           0.
     23,   7.08732033,           0.
     24,           6.,           0.
     25,          20.,          16.
     26,          20.,          12.
     27,          20.,           8.
     28,          20.,           4.
     29,           4.,          20.
     30,           8.,          20.
     31,          12.,          20.
     32,          16.,          20.
     33,   4.61048985,   4.27207041
     34,   5.21953821,    3.3241663
     35,   5.65414333,   2.24666381
     36,   3.76305604,    5.0720458
     37,    2.9698534,   5.98835516
     38,   9.52673054,    1.3621918
     39,   10.8648214,   1.28821659
     40,   12.2752504,   1.49624527
     41,   13.7877016,    1.8428328
     42,   15.4558372,   2.21547365
     43,   17.4501019,   2.73403955
     44,   5.91304588,   1.13274133
     45,   4.68926382,   5.76015615
     46,    6.4430089,   3.80565119
     47,   5.95787334,   5.26839066
     48,   6.80666494,   2.51488447
     49,   4.42414665,   6.79759693
     50,   8.23377609,    1.3453728
     51,   9.59390545,   2.90512729
     52,   10.7518759,    2.3682847
     53,   11.7106466,   2.94118524
     54,   14.5212259,   4.29937983
     55,   8.08390808,   2.67795062
     56,   7.78504944,   3.97590899
     57,   7.77411175,   5.33681679
     58,   6.10621023,   6.95071125
     59,   1.94550073,   7.10477209
     60,    11.838357,    5.2793541
     61,   7.02121258,   1.25902271
     62,   10.0063887,   6.35130978
     63,     8.010355,   6.83067751
     64,   9.39275265,   4.97939444
     65,   6.02029657,   8.60703278
     66,   3.87908149,   8.27187824
     67,   8.93236446,   3.98667765
     68,   8.23227215,   8.46074009
     69,   8.32474804,   10.2367725
     70,   10.6257029,   8.00327873
     71,   16.7049828,   6.19563103
     72,   13.6436939,   9.75342178
     73,   10.8004723,   10.1224651
     74,   5.94967222,   10.5041113
     75,   13.4720745,   6.85688591
     76,   3.24529791,   13.0592442
     77,   8.33017063,   11.9740849
     78,   16.8983517,   9.04143524
     79,   8.14096928,   15.8777552
     80,   16.4028816,   16.3181858
     81,   12.5486145,   16.4053078
     82,   13.2811871,   13.0176907
     83,   16.7287922,   12.6320887
     84,   3.71863937,    16.398428
     85,   3.26978445,   10.2153568
     86,   16.1973763,   4.55466032
     87,   13.0253439,   3.65237355
     88,   6.37839174,   12.9158268
     89,   10.1812487,   12.8076839
     90,   10.6965008,   4.08778143
*Element, type=CPS4R
 1, 36, 37, 14,  4
 2,  4,  5, 33, 36
 3, 57, 47, 46, 56
 4, 34, 33,  5,  6
 5,  6, 15, 35, 34
 6,  8, 24, 44,  7
 7, 85, 76, 12, 11
 8, 37, 59,  3, 14
 9, 45, 36, 33, 47
10, 47, 33, 34, 46
11,  9, 28, 43, 16
12, 43, 42, 17, 16
13, 41, 40, 19, 18
14, 40, 39, 20, 19
15, 39, 38, 21, 20
16, 39, 40, 53, 52
17, 46, 34, 35, 48
18, 22, 21, 38, 50
19, 44, 35, 15,  7
20, 25, 10, 32, 80
21, 52, 51, 38, 39
22,  2, 13, 84, 29
23, 77, 88, 74, 69
24, 69, 74, 65, 68
25, 82, 83, 80, 81
26, 45, 47, 58, 49
27, 61, 50, 55, 48
28, 36, 45, 49, 37
29,  1,  3, 59, 11
30, 90, 51, 52, 53
31, 18, 17, 42, 41
32, 87, 41, 42, 54
33, 86, 71, 75, 54
34, 44, 24, 23, 61
35, 23, 22, 50, 61
36, 60, 62, 64, 90
37, 49, 66, 59, 37
38, 35, 44, 61, 48
39, 67, 51, 90, 64
40, 51, 55, 50, 38
41, 48, 55, 56, 46
42, 53, 40, 41, 87
43, 54, 75, 60, 87
44, 71, 86, 43, 28
45, 63, 57, 64, 62
46, 68, 63, 62, 70
47, 58, 47, 57, 63
48, 63, 68, 65, 58
49, 66, 49, 58, 65
50, 66, 65, 74, 85
51, 87, 60, 90, 53
52, 60, 75, 70, 62
53, 68, 70, 73, 69
54, 57, 56, 67, 64
55, 59, 66, 85, 11
56, 67, 56, 55, 51
57, 69, 73, 89, 77
58, 80, 83, 26, 25
59, 29, 84, 79, 30
60, 73, 72, 82, 89
61, 71, 28, 27, 78
62, 75, 71, 78, 72
63, 70, 75, 72, 73
64, 30, 79, 81, 31
65, 76, 85, 74, 88
66, 84, 76, 88, 79
67, 13, 12, 76, 84
68, 89, 82, 81, 79
69, 78, 27, 26, 83
70, 80, 32, 31, 81
71, 83, 82, 72, 78
72, 86, 54, 42, 43
73, 79, 88, 77, 89
*Node
     91,           0.,          20.,           0.
*Nset, nset=plate-RefPt_, internal
91,
*Nset, nset=RP
 91,
*Nset, nset=y_sym
  8,  9, 16, 17, 18, 19, 20, 21, 22, 23, 24
*Elset, elset=y_sym
  6, 11, 12, 13, 14, 15, 18, 31, 34, 35
*Nset, nset=x_sym
  1,  2, 11, 12, 13
*Elset, elset=x_sym
  7, 22, 29, 67
*Nset, nset=top
  2, 10, 29, 30, 31, 32
*Elset, elset=top
 20, 22, 59, 64, 70
*Nset, nset=all, generate
  1,  90,   1
*Elset, elset=all, generate
  1,  73,   1
** Section: steel
*Solid Section, elset=all, material=steel
,
*End Part
**
*Assembly, name=Assembly
*Instance, name=plate-1, part=plate
*End Instance
**
*Surface, type=NODE, name=plate-1_top_CNS_, internal
plate-1.top, 1.
** Constraint: couple_top_uy
*Coupling, constraint name=couple_top_uy, ref node=plate-1.RP, surface=plate-1_top_CNS_
*Kinematic
2, 2
*End Assembly
**
*Material, name=steel
*Elastic
210000., 0.3
*Plastic
  500.,0.
**
** Name: x_sym Type: Displacement/Rotation
*Boundary
plate-1.x_sym, 1, 1
** Name: y_sym Type: Displacement/Rotation
*Boundary
plate-1.y_sym, 2, 2
** ----------------------------------------------------------------
*Step, name=pull_y, nlgeom=YES
*Static
1., 1., 1e-05, 1.
**
*Boundary
plate-1.RP, 1, 1
plate-1.RP, 2, 2, 0.08
plate-1.RP, 6, 6
**
*Output, field, variable=PRESELECT
*Output, history, variable=PRESELECT
** print node and element results into dat-file
*NODE PRINT
U, RF,
*EL PRINT
S, COORD, PEEQ,
*End StepCode language: plaintext (plaintext)

II) The model_plate.py file using functions

# Plate with hole model for Abaqus/Python course, MP, 09-2020

from abaqus import *
from abaqusConstants import *
from caeModules import *
import os
import numpy as np
session.journalOptions.setValues(replayGeometry=COORDINATE,
		                         recoverGeometry=COORDINATE)
DIR0 = os.path.abspath('')
TOL = 1e-6

# Model functions
# ------------------------------------------------------

def make_geometry(model,(b,h,radius),mesh_size):
    # draw the sketch
    s = model.ConstrainedSketch(name='plate', sheetSize=200.0)
    s.ArcByCenterEnds(center=(0,0), point1=(0,radius), point2=(radius,0),
                    direction=CLOCKWISE)
    s.Line(point1=(radius,0), point2=(b/2.,0))
    s.Line(point1=(b/2.,0), point2=(b/2.,h/2.))
    s.Line(point1=(b/2.,h/2.), point2=(0,h/2.))
    s.Line(point1=(0,radius), point2=(0,h/2.))

    # create the part
    p = model.Part(name='plate', dimensionality=TWO_D_PLANAR, type=DEFORMABLE_BODY)
    p.BaseShell(sketch=s)

    # create sets, surfaces, and reference point
    p.Set(name='all', faces=p.faces[:])
    p.Set(name='x_sym', edges=p.edges.getByBoundingBox(xMax=TOL))
    p.Set(name='y_sym', edges=p.edges.getByBoundingBox(yMax=TOL))
    p.Set(name='top', edges=p.edges.getByBoundingBox(yMin=h/2.-TOL))

    rp = p.ReferencePoint(point=(0,h/2,0))
    p.Set(name='RP', referencePoints=(p.referencePoints[rp.id],))
    # meshing
    p.seedPart(size=mesh_size)
    p.generateMesh()
    return p

def make_sections(model, p, (E,nu,sy)):
    # create material, create and assign sketchOptions
    mat = model.Material(name='steel')
    mat.Elastic(table=((E_steel, nu_steel), ))
    mat.Plastic(table=((sy_steel, 0.0), ))

    model.HomogeneousSolidSection(name='steel', material='steel', thickness=None)

    p.SectionAssignment(region=p.sets['all'], sectionName='steel',
                        thicknessAssignment=FROM_SECTION)
    return

def make_assembly(model,p):
    # assembly
    a = model.rootAssembly
    inst = a.Instance(name='plate-1', part=p, dependent=ON)
    # constraint
    model.Coupling(name='couple_top', controlPoint=inst.sets['RP'],
                surface=inst.sets['top'], influenceRadius=WHOLE_SURFACE,
                couplingType=KINEMATIC, u1=OFF, u2=ON, ur3=OFF)
    return inst

def make_boundaries(model,inst,uy):
    # step and hostory output
    step = model.StaticStep(name='pull', previous='Initial', maxNumInc=1000,
                            initialInc=0.1, minInc=1e-08, maxInc=0.1, nlgeom=ON)

    model.HistoryOutputRequest(name='H-Output-2', createStepName='pull',
                            variables=('U2', 'RF2'), region=inst.sets['RP'])

    # boundaries and load
    model.DisplacementBC(name='x_sym', createStepName='Initial',
                        region=inst.sets['x_sym'], u1=0)
    model.DisplacementBC(name='y_sym', createStepName='Initial',
                        region=inst.sets['y_sym'], u2=0)
    model.DisplacementBC(name='pull', createStepName='pull',
                        region=inst.sets['RP'], u1=0, u2=uy, ur3=0)
    return

def run_model(model,job_name):
    # create and run job
    job = mdb.Job(name=job_name, model='Model-1', type=ANALYSIS,
                resultsFormat=ODB)
    job.submit(consistencyChecking=OFF)
    job.waitForCompletion()
    return

def evaluate_image(job_name):
    # open the odb
    odb = session.openOdb(job_name+'.odb')
    vp = session.viewports['Viewport: 1']
    vp.setValues(displayedObject=odb)
    # Change size of viewport (e.g. 300x200 pixel)
    vp.restore()
    # position of the viwport
    vp.setValues(origin=(50,-50))
    vp.setValues(width=150, height=200)
    # set up in Abaqus Viewer, recorded, and copied here
    """
    session.View(name='User-1', nearPlane=24.242, farPlane=39.003, width=7.2278,
        height=9.3665, projection=PERSPECTIVE, cameraPosition=(2.5, 5, 31.623),
        cameraUpVector=(0, 1, 0), cameraTarget=(2.5, 5, 0),
        viewOffsetX=-1.3504, viewOffsetY=0.25069, autoFit=OFF)
    # load the defined view
    vp.view.setValues(session.views['User-1'])
    """
    # for a changing plate size, take an automatic front view
    vp.view.setValues(session.views['Front'])
    # view the right filed output
    vp.odbDisplay.display.setValues(plotState=(CONTOURS_ON_DEF, ))
    vp.odbDisplay.setPrimaryVariable(variableLabel='S',
        outputPosition=INTEGRATION_POINT,
        refinement=(INVARIANT, 'Mises'),)
    # change the legend and what is displayed
    vp.viewportAnnotationOptions.setValues(legendFont=
        '-*-verdana-medium-r-normal-*-*-140-*-*-p-*-*-*')
    vp.viewportAnnotationOptions.setValues(triad=OFF, state=OFF,
        legendBackgroundStyle=MATCH,annotations=OFF,compass=OFF,
        title=OFF)
    # print viewport to png file
    session.printOptions.setValues(reduceColors=False, vpDecorations=OFF)
    session.pngOptions.setValues(imageSize=(1500, 2000))
    session.printToFile(fileName=job_name+'_mises', format=PNG,
                canvasObjects=(vp,))
    odb.close()
    return

def evaluate_ho_path(job_name):
    # open the odb
    odb = session.openOdb(job_name+'.odb')
    vp = session.viewports['Viewport: 1']
    vp.setValues(displayedObject=odb)
    # evaluate the history output
    # ------------------------------------------------------
    step = odb.steps['pull']
    # select the history region with the name starting with 'Node '
    hr_rp = [i for i in step.historyRegions.values()
            if i.name.startswith('Node ')][0]
    # get vertical dispacement and reaction force data
    # ((t,u),...), ((t,rf),...)
    res_u = np.array(hr_rp.historyOutputs['U2'].data)
    res_rf = np.array(hr_rp.historyOutputs['RF2'].data)
    # only take the second colum of data and stack those columns
    res_u_f = np.column_stack((res_u[:,1],res_rf[:,1]))
    # write u-rf data to file
    np.savetxt(job_name+'_res_u_f.dat',res_u_f)
    # evaluate the stresses along path (y=0)
    # ------------------------------------------------------
    # create path from coordinates
    pth = session.Path(name='Path-1', type=POINT_LIST,
                    expression=((radius,0,0), (b/2.,0,0)))
    # field output to be evaluated along path
    vp.odbDisplay.setPrimaryVariable(variableLabel='S',
        outputPosition=INTEGRATION_POINT,refinement=(COMPONENT, 'S22'))
    # output for 20 eqiuidistant points over path
    # shape: path over DEFORMED or UNDEFORMED geometry
    n_points = 20
    # get vertical stress S22 over X_COORDINATE
    xy = session.XYDataFromPath(name='XYData-1', path=pth,
        includeIntersections=False, shape=UNDEFORMED,
        projectOntoMesh=False, pathStyle=UNIFORM_SPACING,
        numIntervals=n_points, projectionTolerance=0,
        labelType=X_COORDINATE)
    # write results to file
    np.savetxt(job_name+'_res_s22_path.dat',xy.data)
    odb.close()
    return

# one funtion for the whole plate model (create, run, evaluate)
def plate_model(job_name,(b,h,radius),(E,nu,sy),uy,mesh_size):
    # check parameters for errors
    if radius >= b/2:
        raise ValueError('width b too small for hole radius')
    if radius >= h/2:
        raise ValueError('height h too small for hole radius')
    # reset model
    Mdb()
    model = mdb.models['Model-1']
    # make the parts, mesh it and return it
    p = make_geometry(model,(b,h,radius),mesh_size)
    # make materials and sections
    make_sections(model,p,(E,nu,sy))
    # make the assembly & constraint
    inst = make_assembly(model,p)
    # create step and boundaries
    make_boundaries(model,inst,uy)
    # save the model
    mdb.saveAs(job_name)
    # run the model
    run_model(model,job_name)
    # evaluate: create image
    evaluate_image(job_name)
    # evaluate: history output and path
    evaluate_ho_path(job_name)
    return model

# parameters for geometry, material, load and mesh (N-mm-s)
# ------------------------------------------------------
b = 16.               # width of the plate (mm)
h = 20.               # height of the plate (mm)
radius = 4.5          # radius of the hole (mm)
uy = 0.08             # vertical displacement of the top (mm)
E_steel = 210000.     # Young's modulus of steel (MPa)
nu_steel = 0.3        # Poisson's ratio of steel (1)
sy_steel = 500.       # yield stress of steel (MPa)
mesh_size = 0.3       # edge length of the mesh (mm)


# run the model function
# ------------------------------------------------------

plate_model('plate-test',(b,h,radius),(E_steel,nu_steel,sy_steel),
            uy,mesh_size)Code language: Python (python)