CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ANSA (https://www.cfd-online.com/Forums/ansa/)
-   -   Ansa Script (https://www.cfd-online.com/Forums/ansa/111581-ansa-script.html)

LLevente October 13, 2016 03:02

Batch Meshing
 
Hi guys,

in my new workplace I have to use ANSA (only Ansys programs). I've never used this program, in the last 1,5 week I made more tutorials. I have to use in the future the scripts, and I am trying to make some scripts.

The help of the sripting in ANSA is very helpful, and with the examples in the help I could make some easy scripts, and they work. :)

But I had a question. I made a small script for the batch meshing. This make a new mesh scenario, and made some filters. It's ok, the program make the scenario and the filters, but don't click on the "Apply" button. (If I open the window, and I click on the "Apply", the filter works.)
I found some function to apply something, but don't work, because the object is not right.

Code:

import ansa
from ansa import batchmesh
from ansa import base
from ansa import mesh
from ansa import guitk

What's the problem?

def batch_meshing():
       
        mesh.EraseMesh()
        scenario = batchmesh.GetNewMeshingScenario('Meshing_Scenario', 'PIDS')
               
        filter = batchmesh.AddFilterToScenario('Id', 'equals',' 1', scenario, match='any', case_sensitive='yes', filter_name='Szuro')
        filter = batchmesh.AddFilterToScenario('Id', 'equals',' 6', scenario, match='any', case_sensitive='yes', filter_name='Szuro')
        filter = batchmesh.AddFilterToScenario('Id', 'equals', '7', scenario, match='any', case_sensitive='yes', filter_name='Szuro')

        ansa.guitk.BCListViewFilterApply(filter)
       
       
        batchmesh.RunAllMeshingScenarios(60)
       
batch_meshing()

The trouble would be with this line: ansa.guitk.BCListViewFilterApply(filter)

Any ideas?
Thanks, guys!

Levente

LLevente October 13, 2016 05:08

Batch Meshing - again
 
Hallo,

I didn't write, that I use ANSA 17.0.0.

Of course I have an other option to mesh with batch.

Code:

import ansa
from ansa import batchmesh
from ansa import base
from ansa import mesh
from ansa import guitk

def batch_meshing():
       
        mesh.EraseMesh()
        scenario = batchmesh.GetNewMeshingScenario('Meshing_Scenario', 'PIDS')
        PID1 = base.GetEntity( ansa.constants.FLUENT, "__PROPERTIES__", 6)
        PID2 = base.GetEntity( ansa.constants.FLUENT, "__PROPERTIES__", 5)
        PID3 = base.GetEntity( ansa.constants.FLUENT, "__PROPERTIES__", 8)
       
       
       
        ansa.batchmesh.AddPartToMeshingScenario(PID1, scenario)
        ansa.batchmesh.AddPartToMeshingScenario(PID2, scenario)
        ansa.batchmesh.AddPartToMeshingScenario(PID3, scenario)
       

        batchmesh.RunAllMeshingScenarios(60)
       
batch_meshing()

It works, and can be more than enough. :)

But if somebody knows the answer for my previous question, I would be happy, if (s)he would tell it. :)

Have a nice scripting! :)
Levente

vangelis October 13, 2016 05:52

Just to mention that in v17 there is a new Tutorial under the CFD category called scripting automation. Have you checked it out?
It may not answer your specific question, but could sure help.

LLevente October 13, 2016 07:03

Hi,

thanks for your answer.

I have used for help mostly the script help in the v17 Ansa. (Where I can write the scripts, in the "Output window".)

I saw also this tutorial (about a drone), what you say. And also the Scripts_Collection_Catalogue.pdf, but they couldn't help me. :(

I found earlier in the folder of Ansa an other folder named "scripts", where there are more folders, and in the folders a lot of scripts. I saw some scripts in the "CFD" and "Mesh" folders, but they couldn't help in this problem.

After these I registered here. :) (Earlier I read only this page for Icem.)

So, the second version, that I wrote today, worked in this geometry, but later I will get difficultier geometries (with more 100 faces), and I can't write every PID ID-s, but a filter can be good, if I give the keywords well. (I can choose more faces with one line in the script with a filter.)

And an other question.

In this line I use "ansa.constants.FLUENT" as deck (?). What's this?

Code:

PID1 = base.GetEntity( ansa.constants.FLUENT, "__PROPERTIES__", 6)
Why do I need exactly this expression? What do I give here?
(I can write other words too instead of FLUENT. Note: I will use Star CCM+.)

Thank you!
Levente

greg.cfd October 14, 2016 04:08

Hi,

After creating your filters in ANSA scripting you can apply them by using the batchmesh.DistributeAllItemsToScenarios() script function. It is the same as clicking the "Autoload" button in the Batch Mesh Manager window.

The following code will create the three filters and apply them.

Code:

import ansa from ansa import batchmesh
 from ansa import base
 from ansa import mesh
 from ansa import guitk
 
 def batch_meshing():
   
        mesh.EraseMesh()
        scenario = batchmesh.GetNewMeshingScenario('Meshing_Scenario', 'PIDS')
       
        filter = batchmesh.AddFilterToScenario('Id', 'equals',' 1', scenario,  match='any', case_sensitive='yes', filter_name='Szuro')
        filter = batchmesh.AddFilterToScenario('Id', 'equals',' 6', scenario, match='any', case_sensitive='yes', filter_name='Szuro')
        filter = batchmesh.AddFilterToScenario('Id', 'equals', '7', scenario,    match='any', case_sensitive='yes', filter_name='Szuro')
 

        batchmesh.DistributeAllItemsToScenarios()
   
   
        batchmesh.RunAllMeshingScenarios(60)


   
 batch_meshing()

The ansa.guitk.BCListViewFilterApply(filter) script function that you tried, can be safely removed, as it is used only when creating Graphical User Interfaces in ANSA scripting and does not have to do with Batch Mesh filters.

Regarding your question about the "ansa.constants.FLUENT" expression. This is used to define the Deck that you will be working on.

Each ANSA entity is being identified by a corresponding keyword. For example the keyword for faces is "FACE" and it is common for all decks.

However, other entities, such as shell PIDs, have different keywords for different decks. For OpenFOAM, the keyword is "SHELL_PROPERTY", but for Nastran deck for example, the keyword is "PSHELL".

As in many functions you need to define this keyword in order to interact with ANSA entities (collect them, manipulate them etc), the deck must also be defined.

The important thing is to be consistent throughout your code. If you will be using one deck, you need to make sure that you always use that deck's keywords.

ANSA entities' keywords can be found by opening any entity's card (Press F12 to open the database browser, then double click on an entity, e.g. PROPERTY, to open its card, and see the entity's keywords inside brackets).

Hope this helps.

Please let me know if you face any other issues with your code.
Best regards,
Grigoris

LLevente October 14, 2016 07:36

Hi greg,

thank you for your answer!

The script works. :) I looked for this line. :)

And everything is clear, I understood this "decking".

Thanks again!
Levente

Sujahid basha April 20, 2017 08:24

Does ANSA scripting support Multiprocessing
 
I have been trying alot ways to get the Multiprocessing code to execute in ansa but no luck; could any help me out how to use multiprocessing module in ansa using python, by which it will help to reduce the execution time a lot ..just for eg. i have a list with 10000 items and i want to divide the list and run the logic further in different processes (Threading will also do)...

Kcm155 February 21, 2019 04:09

help on scripting
 
Hello ;

currently , i have some projects with ANSA, and i am trying to automate some operations using python,
I wonder if you have some free script that I can use to fit my needs,
and I'll be grateful if you have a script which can read coordinate from an xlsx file and generates SPRING (im working with Deck>PAMCRASH)

you can find below the current script, till now i have succeeded to:
- read & create POINTS from (csv) file
- create NODES and SPRINGS from those nodes
but i can't find the link between the two parts ( i need to convert the POINTS from csv file to NODES or Create PRINGS from POINTS directly)
************************************************** **
import ansa
from ansa import *
def main():
# import csv file and create POINTS
file = 'C:/Users/ejjed/Desktop/Scripting/Test.csv'
list_points = ansa.base.ImportCSVFileCreatePoints( file )
# create set-NODES
vals = {'Name':'new set'}
set = base.CreateEntity(constants.NASTRAN, "SET", vals)
# create NODES
nodes_list = []
for i in range(5):
vals = { "X": i*50, "Y": i*50, "Z": i*50 }
n = base.CreateEntity(constants.PAMCRASH, "NODE",vals)
base.AddToSet(set, nodes_list)
# create SPRING from NODES
vals_property = {"IDPRT":111, "Name": "new property"}
property =base.CreateEntity(constants.PAMCRASH,"PART_SPRING ",vals_property)
vals_element = {"M":1,"IPART":111,"N1":1,"N2":5,}
SpringEle = base.CreateEntity(constants.PAMCRASH, "SPRING",vals_element)
************************************************** **
cordially


All times are GMT -4. The time now is 04:52.