Abaqus Surface getSequenceFromMask - python

I am writing script in Abaqus, where I crush circle and square with cut circle (like cheese). I need to put Contact between parts so I need Surface.
macro manager generates:
s1 = a.instances['kolo-1'].edges
side1Edges1 = s1.getSequenceFromMask(mask=('[#1 ]', ), )
a.Surface(side1Edges=side1Edges1 , name='kolkoSurf')
The problem is: getSequenceFromMask(mask=('[#1 ]', ), )
How to get this #1? Can I replace it? I searched little and there were some ideas to use: 'find', 'face', 'COORDS' but I cannot manage it.
Please help me. I dream to get an simple example how to extract this Surface using X, Y or anyway.
BR,
Wonman

You recorded the above journal using the macro manager with default journal options. Therefore, the variable side1Edges1 is defined in your journal using the getSequenceFromMask()-method. This method is the recording of the selection you performed by clicking the GUI during the recording. This means you clicked the GUI to select an edge and the result is the getSequenceFromMask()-method acting on s1 which is a set of all edges of the instance 'kolo-1'.
According to Abaqus Scripting Reference Guide 6.14 - 7.2.2 the method getSequenceFromMask() is highly efficient when a large number of objects are involved. However, this is not very helpful if your trying to customize your journal file to select another geometry element to work with. There are two solutions:
Solution: Paste the command
session.journalOptions.setValues(replayGeometry=COORDINATE, recoverGeometry=COORDINATE)
into the Abaqus command line at the bottom of Abaqus CAE to set the members replayGeometry and recoverGeometry of your JournalOptions object to COORDINATE and repeat the recording of your journal.
You can, most of the time, omit clicking the GUI again by executing your old journal after issuing the command above.
You can then save your project, preferably with a new name, and use the newly created journal.
In the new journal the command getSequenceFromMask(mask=('[#1 ]', ), ) will by replaced by a selection based on coordinates to represent your recorded GUI-click.
You can then modify the coordinates in order to customize your journal file and to select the edge you like to use in subsequent modeling steps.
Solution: Define side1Edges1 using variables you defined from Scratch in the preceding lines of your python script. I recommend using the journal file as a blueprint in which all click-events have to be replaced using well known variables, defined by yourself. For example, define a list of points myPoints = [(0,0), (0,1) ] using your own logic and then use these points as arguments of the methods e.g. myLine = mySketch.Line(point1=myPoints[0], point2=myPoints[1]), constructing new variables like myLine for the usage in subsequent modeling steps.
To get a basic understanding of the modeling workflow using the Abaqus Python API, i can recommend
Puri, G. M., 2011. Python scripts for Abaqus : learn by example, 1st Edition, also it is hardly available in most universities.
Looking at the Abaqus Benchmark Guide can be helpful, as some newer Benchmarks contain Python scripts (e.g. Fracture Mechanics).

I suppose you are creating an edge based surface. There are many ways to do it, easiest one is
Create an assembly based set ("setName") of those edges for which you want to create surface.
instance=mdb.rootAssembly.instances["InstanceName"]
set_for_surface=instance.sets["setName"].edges
assembly.Surface(side1Edges=set_for_surface, name="surf_name")
Have look at findAt() or selecting region by bounding box "getBoundingBox()". See this SO answer, which is somewhat similar.
Edit: If the set is an assembly based set, access it directly from assembly not instance. Then, use the same procedure.
mdb.rootAssembly.sets['Set_name'].edges

Late to answer but i found simpler way to select all the edges by giving coordinates:
p = mdb.models['Model-1'].parts['Part-1']
e = p.edges
edges = e.getByBoundingBox(x1,y1,z1,x2,y2,z2)
p.Set(edges=edges, name='AllPartSet')
x, y and z are two coordinates for making a box.

Related

Abaqus: parametric geometry/assembly in Inputfile or Python script?

i want to do something as a parametric study in Abaqus, where the parameter i am changing is a part of the assembly/geometry.
Imagine the following:
A cube is hanging on 8 ropes. Each two of the 8 ropes line up in one corner of a room. the other ends of the ropes merge with the room diagonal of the cube. It's something like a cable-driven parallel robot/rope robot.
Now, i want to calculate the forces in the ropes in different positions of the cube, while only 7 of the 8 ropes are actually used. That means i have 8 simulations for each position of my cube.
I wrote a matlab script to generate the nodes and wires of the cube in different positions and angle of rotations so i can copy them into an input file for Abaqus.
Since I'm new to Abaqus scripting etc, i wonder which is the best way to make this work.
would you guys generate 8 input files for one position of the cube and calculate
them manually or is there a way to let abaqus somehow iterate different assemblys?
I guess i should wright a python script, but i don't know how to make the ropes the parameter that is changing.
Any help is appreciated!
Thanks, Tobi
In case someon is interested, i was able to do it the following way:
I created a model in abaqus till the point, i could have started the job. Then i took the .jnl file (which is created automaticaly by abaqus) and saved it as a .py file. Then i modified this script by defining every single point as a variable and every wire for the parts as tuples, consisting out of the variables. Than i made for loops and for every 9 cases unique wire definitions, which i called during the loop. During the loop also the constraints were changed and the job were started. I also made a field output request for the endnodes of the ropes (representing motors) for there coordinates and reaction force (the same nodes are the bc pinned)
Then i saved the fieldoutput in a certain simple txt file which i was able to analyse via matlab.
Then i wrote a matlab script which created the points, attached them to the python script, copied it to a unique directory and even started the job.
This way, i was able to do geometric parametric studies in abaqus using matlab and python.
Code will be uploaded soon

Display GTFS - Routes on a Map without Shapes

I try to consume some GTFS Feeds and work with them.
I created a MySQL Database and a Python Script, which downloads GTFS - Files and import them in the right tables.
Now I am using the LeafLet Map - Framework, to display the Stops on the map.
The next step is to display the routes of a bus or tram line on the map.
In the GTFS - Archive is no shapes.txt.
Is there a way to display the routes without the shapes.txt ?
Thanks!
Kali
You will have to generate your own shape using underlying street data or public transit lines. See detailed post by Anton Dubrau (he is an angel for writing this blog post).
https://medium.com/transit-app/how-we-built-the-worlds-prettiest-auto-generated-transit-maps-12d0c6fa502f
Specifically:
Here’s an example. In the diagram below, we have a trip with three
stops, and no shape information whatsoever. We extract the set of
tracks the trip uses from OSM (grey lines). Our matching algorithm
then finds a trajectory (black line) that follows the OSM, while
minimizing its length and the errors to the stops (e1, e2, e3).
The only alternative to using shapes.txt would be to use the stops along the route to define shapes. The laziest way would be to pick a single trip for that route, get the set of stops from stop_times.txt, and then get the corresponding stop locations from stops.txt.
If you wanted or needed to, you could get a more complete picture by finding the unique ordered sets of stops among all of the trips on that route, and define a shape for each ordered set in the same way.
Of course, these shapes would only be rough estimates because you don't have any information about the path taken by the vehicles between stops.

is there a way to copy a filter from one layer to another layer using python

i'm using python-fu, i want to copy the filter iwarp i added to one layer to another layer i just added to the document.
my code:
document = gimp.image_list()[0]
layer_with_filter = document.layers[0]
layer_without_filter = document.layers[3]
i dont find a way to see using:
dir(layer_with_filter)
if there is an effect or filter added to that layer, is it posible to know that or does the change with filter happens somewhere else?
thanks
No, that is not possible.
You can, through Python, execute almost all the filters with arbitrary values you put on the Python side. But there is no way to either tell GIMP to repeat a filter with previous values , or retrieve values used in a filter operation on the Python side.
I-Warp specially is not even usable in a programmatic way, as it relies on live interaction with the plug-in window to create the distortion map - o you are out of luck there.
However, any thing that can be done with the "IWarp" plug-in, could be done with the "Displace" plug-in (check Filters->Map->Displace...) that one is usable programatically, and you could apply the effect of one application of displacement to other layers using Python. However, "Displace" requires two intermediate layers indicating the offset to be used for each pixel on the original image. These two layers are combined as a 2D field, where the value of each pixel (~ its brightness) indicates one coordinate of an offset where the target pixel will be placed. Internally, that is what IWarp does - however, the displacement map itself is created by its "internal tools" such as grow, shrink, move... - and there is no programmatic way to retrieve the displacement map used by IWarp so that it could be pasted in a ayer and used with the Displacement filter. But if you really need this feature, that might be the easiest way to go: modify the source code (in C) of the IWarp filter to add a button to "save the displacement map" in it - it could them create two new layers suitable to be used by the displacement filter.
Back to the subject of programmatically repeating other filters: the development branch of GIMP - GIMP 2.9 had switched most filters to a complete new framework using GEGL (the Generic Graphic Library) - the new engine for all pixel manipulation in GIMP. However, the Python bindings had not been updated yet to be able to take advantage of these new filters. When they finally are, it may well be possible a call to retrieve the last used values can be made existent.
And, again specially for IWarp, the filter has been promoted, in the development version, to a fully interactive tool, and there is no mechanism to retrieve the resulting of interaction of the tool with one layer to "replay" that on other layer.

Abaqus: script to select elements on a surface

I am trying write an Abaqus/Python script that will select all the elements that "belong" to a certain face. I.e. taking all the elements that have a connection to one face of a meshed cube (I will calculate the total force acting on that face for force-displacement or stress-strain curves later).
If I do it using the GUI I get:
mdb.models['Model-1'].rootAssembly.Set(elements=
mdb.models['Model-1'].rootAssembly.instances['Part-1-1'].elements.getSequenceFromMask(
mask=('[#0:5 #fff80000 #ff #f #ffe00000 #f000000f #3f',
' #0:6 #fffe #c0003f00 #3 #3fff8 #ffc00 ]', ), ), name='Set-1')
But, getSequenceFromMask does not work in a general case. I tried using findat with no luck.
Is there a way to do that?
define a face set on the part or assembly:
part.Set('facename',faces=part.faces.findAt(((1,0,0),),))
where (1,0,0) is a coordinate anywhere on the face. (Don't use a point on a edge/corner though)
then after meshing you can access the elements attached to that face, something like:
instance.sets['facename'].elements
note if you want to get those elements on the odb after running an analysis it is a little different:
instance.elementSets['FACENAME'].elements
note that the set name is upcased on the odb..
One can select an specific element from its label by using:
mdb.models['model-name'].parts['part_name'].elements.getFromLabel(lable=element_id)
This way it is not necessary to have information about the coordinate of the element. Only the element id is enough to access to it.
You are apparently using a Macro in order to get the location of your surface in order to pick the set using Python. The issue is: the Macro facility uses getSequenceFromMask() by default and isn't very user-friendly...
Fortunately, this default option can be changed! One just needs to run the following line of code:
session.journalOptions.setValues(replayGeometry=COORDINATE,recoverGeometry=COORDINATE)
Now when you record a macro using the MacroManager, you get findAt() which is what you want.
Extra TIP:
You can include this piece of code in the onCaeStartup() function in your custom_v6.env file. It will then run every time you open CAE.
C:\Program Files\Dassault Systemes\SimulationServices\V6R2018x\win_b64\SMA\site\custom_v6.env
I had this issue myself a few days ago. Maybe I'm wrong but as far as I know, there is no way to directly select particular elements. You can select them with a "Bounding Box" or a "Bounding Sphere" or you can get them by your parts/ instances faces and cells. If you need to select the elements in a more specific way then you can get them by the nodes with which they are connected. You can use the "findAt" command with these nodes and get the elements by the "getElements()" command.
That is how I solved it and it works pretty fine. If there are other ways to solve that I will be happy to hear them because this is sometimes really frustrating.
Cheers

Best data structure for finding nearby xyz points by distance?

I'm working on Python, but I suppose that doesn't affect the question itself.
I'm working on a game, and I need to store entities, each of which has an [x,y,z] in the world. I need to be able to run a "All entities within X euclidean distance of point Y".
These entities will be moving fairly often.
What would be the most efficient way to store the entities to make this as fast as possible?
As an alternative to what has been suggested already, if you don't need an exact distance, you could also use spatial hashing, which is quite easy to implement.
In summary, you have to think of your world as a grid where each cell in the grid would correspond to one bucket in the hash table. Since your entities are moving often, on each new frame you could clear and reconstruct the whole table and put the entities to their corresponding bucket depending on their position. Then, for any given entity you could just check the cells nearby and get the entities lists.
You can use a kd-tree (link has photo and code and examples) or an octree (this link is a C++ class template which you can use). Real-usage can be seen in this open-source game engine

Categories

Resources