CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ANSA (https://www.cfd-online.com/Forums/ansa/)
-   -   Ansa scripting (https://www.cfd-online.com/Forums/ansa/216649-ansa-scripting.html)

manonB April 15, 2019 07:53

Ansa scripting
 
Hi everyone!

I'm new to scripts with Ansa (and to python) and I am having some difficulties trying to deal with the geometry I created. (I am working with Abaqus deck)

1) Would someone know how to get some kind of list of the nodes and also get their coordinates. I want that because I am trying to get the nodes IDs and coordinates to write that in a mesh format that Ansa doesn't support yet (.mail Format).

2) with the function GetEntityType I am just able to determine that my entities are "SOLID". What could I do in order to know exactly what elements I have ? Like HEXA, PENTA... or more specifically C3D8, C3D6 from Abaqus

3) My last question is about the sets.
If I use CollectEntities with "SETS", the result is that I have a list of 1 set that I defined for my BCs. Is there any way to know which elements are in my set (get their IDs).

Sorry to ask so many different questions but I am really not able to do that and the documentation doesn't really help...

Thank you a lot in advance if you can help me!

Manon

rmaries April 16, 2019 03:04

1.

Code:

import os
import ansa
from ansa import constants
from ansa import base

def nodes_list(node):
        coord = base.GetEntityCardValues(constants.ABAQUS, node, ('X','Y','Z'))
        return [node._id, coord['X'], coord['Y'], coord['Z']]

This above code will take node as input and return a python list contains node id, x, y, z

rmaries April 16, 2019 04:02

2. My idea is to collect element and check for its type. I checked with ansa scripts folder, they have also used the same method.

In the below code they collect the elements and check whether it is a quad element. You can follow similar way to find other elements.

Code:

def _coreFunction(TopWindow, data):
        warpLimit = float(guitk.BCLineEditGetText(data[0]))
        quadsToSplit = []
        shells = base.CollectEntities(deck, None, 'SHELL', filter_visible = True)
        for shell in shells:
                type = base.GetEntityCardValues(deck, shell, ['type'])['type']
                if type == 'QUAD':
                        qual = base.ElementQuality(shell, 'warping')
                        if qual > warpLimit:
                                quadsToSplit.append(shell)


rmaries April 16, 2019 04:06

3. You can collect elements in a set with base.collectentities

Code:

base.CollectEntities(constants.ABAQUS, set_list[0], __ELEMENTS__)
This above function will collect all the elements in set_list[0]

manonB April 16, 2019 07:25

Hi rmaries! Thanks a lot for your replies!

I managed to find a solution to get the coordinates. It's almost the same as you. I used the .get_entity_values function.
Just this morning I was able to find the elements types by determining how many nodes are contained in a solid entity.

The only Thing that still doesn't work it to get the elements contained in a set. I did the same Thing as you but I doesn't work. I get an empty list as a result...
My code is:
sets=base.CollectEntities(deck, None,"SET")
print(sets)
set_elems_shell=base.CollectEntities(deck, sets, 'SHELL')
set_elems=base.CollectEntities(deck,sets,'__ELEMEN TS__')
print(set_elems_shell)
print(set_elems)

and the result is :
[<Entity: 0x000000000EF25D98: type: 3105(3105,PAMGROUP) id:1>]
[]
[]

I tried with SHELL and with ELEMENTS but every time it's the same.

If you have an idea of what I did wrong, I'm all ears!

Thanks again

Manon

rmaries April 16, 2019 07:46

did you define deck?

'SHELL' attribute changes according to deck value.

In __ELEMENTS__ you typed above, I found the space between N and T.

Also it depends what is contained in your sets. If your set doesn't contain any element or pid, it will return you empty list

manonB April 16, 2019 08:17

Yes sorry my deck ist constants.ABAQUS
And the space must have poped up when I pasted the code, I don't have it in my script.

My set is a Group of 44 elements

manonB April 16, 2019 08:20

Thank you a lot! You made me realize that I don't have elements in my set but SOLIDFACET so now I can get their IDs ! :)


All times are GMT -4. The time now is 08:40.