Selection methods

The process of selecting and bookkeeping enteties, is a significant part of the task of scripting. The process involves typically

  • Use available knowledge such as parameters and informations in the objects to select the relevant enteties
  • Store the items in named Sets or Surfaces for later use and reference

Selecting faces

Consider the plate with a hole having the following parameters:

>>> prt = mdb.models['M1'].parts['P1']
>>> L, b, h, r, cx, cy = 100, 50, 5, 10, 30, 20

How can the faces labeled 1-4 in the figure be identified and selected? There are in fact many alternatives, and which one to choose depends very much on the wider strategy of selecting geometrical enteties. Some examples are:

Using the method faces.getByBoundingBox()

>>> faces_zmax = prt.faces.getByBoundingBox(zMin=h-0.001, zMax=h+0.001)
>>> 
>>> [f.index for f in faces_zmax]
[5, 6, 13, 22]

The selection seems about right, there are 4 faces in the array. Selecting only the face labeled '1' can be done by the same method, now from the new array:

>>> faces1 = faces_zmax.getByBoundingBox(xMin=-0.001, xMax=cx+0.001, yMin=-0.001, yMax=cy+0.001)
>>> [f.index for f in faces1]
[22]

Finally, creating a set containing all four faces as well as a set for the single face:

>>> prt.Set(name='faces-zmax', faces=faces_zmax)
>>> prt.Set(name='face-zmax-1', faces=faces1)
>>>

2 Utilizing the property pointOn

Every geometrical items have this propery which represents one ore more points on or in the specific geometry item. For instance,

>>> prt.faces[0].pointOn
((60.0, 20.0, 1.666667),)
>>> prt.edges[0].pointOn
((85.0, 20.0, 0.0),)

The property is a tuple of tuples, and the first one (pointOn[0]) is always different from empty.

All face indices are

>>> [f.index for f in prt.faces]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
>>>

Adding conditions consistent with faces on the top (z=h):

>>> [f.index for f in prt.faces if f.pointOn[0][2]==h]
[5, 6, 13, 22]

...and more conditions consistent with the face labeled '2':

>>> [f.index for f in prt.faces if f.pointOn[0][2]==h and f.pointOn[0][0]>cx and f.pointOn[0][1]<cy]
[5]

Finally, creating a set:

>>> prt.Set(name='face-zmax-2', faces=prt.faces[5:6])

Geometrical tolerance

The plate with a hole was made in such a way that the coordinates of every vertices have values being precise to the extent that they could have been represented by integers:

>>> [v.pointOn[0] for v in prt.vertices]
[(100.0, 20.0, 0.0), (40.0, 20.0, 0.0), (40.0, 20.0, 5.0), (100.0, 20.0, 5.0), (0.0, 20.0, 5.0), (20.0, 20.0, 5.0), 
 (20.0, 20.0, 0.0), (0.0, 20.0, 0.0), (30.0, 30.0, 0.0), (30.0, 50.0, 0.0), (100.0, 50.0, 0.0), (100.0, 0.0, 5.0), 
 (100.0, 0.0, 0.0), (30.0, 30.0, 5.0), (30.0, 10.0, 5.0), (30.0, 0.0, 5.0), (30.0, 50.0, 5.0), (0.0, 50.0, 5.0), 
 (0.0, 0.0, 0.0), (0.0, 0.0, 5.0), (30.0, 10.0, 0.0), (30.0, 0.0, 0.0), (100.0, 50.0, 5.0), (0.0, 50.0, 0.0)]

Solid brick Consider the plane shell model created through the sketch illustrated in the figure to the right.

There are 4 vertices having the following coordinates:

>>> prt = mdb.models['M1'].parts['P2']
>>> [v.pointOn[0] for v in prt.vertices]
[(0.0, 15.0, 0.0), (0.0, 0.0, 0.0), 
 (70.0, 0.0, 0.0), (70.0, 27.342889, 0.0)]

The y-coordinate of the vertice at the upper right corner is

>>> y_geom = prt.vertices[3].pointOn[0][1]
>>> y_geom
27.342889

The value can easilly be computed:

>>> y_computed = 15.0+70.0*tan(radians(10))
>>> y_computed
27.3428886495925

The computed value is however not precisely equal to the the actual value in pointOn[0][1] and the selection will fail:

>>> [v.index for v in prt.vertices if v.pointOn[0][1] == y_computed]
[]

The following method will be used extensively on the abaqus scripting web site: An appropriate geometrical tolerance for the model is defined, and the criteria for geometrical match is decided by a custom function isapprox(val1,val2,tol) as demonstrated below:

>>> def isapprox(val1,val2,tol=1E-3): return True if abs(val1-val2) < tol else False
>>> isapprox(y_computed, y_geom)
True
>>> [v.index for v in prt.vertices if isapprox(v.pointOn[0][1], y_computed)]
[3]

Custom tools for selecting entities

Examples of custom tools to simplify the task of selection enteties:

See also Write you own modules.

Sets

Sets in a part are stored in the repository mdb.models[modelname].parts[partname].sets.

A set in a part can be created by the constructor mdb.models[modelname].parts[partname].Set(...), taking different arguments dependent on the types of items for the set.

Solid brick

Consider the solid brick part to the right, created by Script-1a from Assembly, Instances

>>> prt = mdb.models['M1'].parts['Brick']

A set containing for instance all vertices is

>>>prt.Set(name='vertices-all', vertices = prt.vertices)

A set may also contain a mix of different types of items, for instance:

>>>prt.Set(name='all-vertices-and-one-random-face', 
           vertices = prt.vertices, faces = prt.faces[2:3])

Note that the arguments vertices, faces, edges, and cells requires sequences of correct type. For example, a list of edges generated by the following method,

>>> edgesAtX0 = [e for e in prt.edges if e.pointOn[0][0] == 0.0]

is just a list:

>>> type(edgesAtX0)
<type 'list'>

and the following attempt to create a set fails:

>>> prt.Set(name='edges-at-x0', edges=edgesAtX0)
Feature creation failed.

The sequence must rather be an EdgeArray:

>>> from part import EdgeArray
>>> edgesAtX0 = EdgeArray(edgesAtX0)
>>> type(edgesAtX0)
<type 'EdgeArray'>
>>> prt.Set(name='edges-at-x0', edges=edgesAtX0)
mdb.models['M1'].parts['Brick'].sets['edges-at-x0']

Note that the assembly has no sets:

>>> ass = mdb.models['M1'].rootAssembly
>>> print ass.sets
{}

However, the sets of the instances can be accessed:

>>> for iname in ass.instances.keys():
...     print ass.instances[iname].sets.keys()
... 
['all-vertices-and-one-random-face', 'edges-at-x0', 'test', 'vertices-all']
['all-vertices-and-one-random-face', 'edges-at-x0', 'test', 'vertices-all']
['all-vertices-and-one-random-face', 'edges-at-x0', 'test', 'vertices-all']
['all-vertices-and-one-random-face', 'edges-at-x0', 'test', 'vertices-all']

A new set in the assembly can be created from the sets in the instances:

>>> setsFromInstances = [i.sets['edges-at-x0'] for i in ass.instances.values()]
>>> ass.SetByBoolean(name = 'edges-at-x0', sets=tuple(setsFromInstances), operation = UNION)
>>> len(ass.sets['edges-at-x0'].edges)
16

Region

The purpose of the Region object is to provide a link between an attribute and the entities to which the attribute is applied. For example, a boundary condition (BC) is applied to one or more Region objects; each Region object in turn is associated with a picked Set or Surface or with a named Set or Surface.

Example: A boundary conditon shall be applied to the previous assembly, on the edges in the set edges-at-x0. In this case, the region is just the set:

region = ass.instances['Brick-0'].sets['edges-at-x0']
mod.EncastreBC(name='BC-1', createStepName='Initial', region=region, localCsys=None)

A boundary condition can however not be assigned to the geometry directly. For example, adding a BC to one of the faces in one of the instances:

>>> mod = mdb.models['M1']
>>> ass = mod.rootAssembly
>>> face = ass.instances['Brick-0'].faces[3:4]
>>> mod.EncastreBC(name='BC-2', createStepName='Initial', region=face)
TypeError: region; found GeomSequence, expecting Region

The solution is to create a region using regionToolset.Region():

>>> from regionToolset import Region
>>> region = Region(faces=face)
>>> mod.EncastreBC(name='BC-2', createStepName='Initial', region=region)
mdb.models['M1'].boundaryConditions['BC-2']

Surfaces

TODO

TOC Next Prev

Disclaimer:This site is designed for educational purposes only. There are most likely errors, mistakes, typos, and poorly crafted statements that are not detected yet... www.ntnu.edu/employees/nils.p.vedvik

Copyright 2024, All rights reserved