CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ANSYS Meshing & Geometry (https://www.cfd-online.com/Forums/ansys-meshing/)
-   -   [ANSYS Meshing] Script for Ansys meshing (https://www.cfd-online.com/Forums/ansys-meshing/148812-script-ansys-meshing.html)

Riadh February 20, 2015 03:30

Script for Ansys meshing
 
Hi

I am working on the optimization of a heat transfer system. I will couple an optimization code (developed in matlab) with a heat transfer system model (developed in ansys workbench). I have already developed a Workbench journal code to automatically carry out the process of fluid flow simulation with FLUENT. However, the Ansys meshing is not accessible through the Workbench journal code. I have to develop a jScript code to modify the mesh parameters (sizing, inflation), but i didn't find any information in Ansys meshing guide.

Could you help me please to develop this JScript code. Could you send me an exemple if you have?

Best Regards

Kapi February 22, 2015 20:00

Hi Riadh,

Welcome to forum.

You have to create a .JS file for mesh which you can access from the .WBJN file.
In that .js file you can make function for sizing or inflation like this...
For sizing:

Code:

ds.Script.doInsertMeshSize(); // command for adding new Sizing Function
        ListView.ActivateItem("Scoping Method");
        ListView.ItemValue = "Named Selection";
        ListView.ActivateItem("Named Selection");
        ListView.ItemValue = "All_EDGE_Name";
        ListView.ActivateItem("Type");
        ListView.ItemValue = "Element Size";
        ListView.ActivateItem("Element Size");
        ListView.ItemValue = "0.0003";
        ListView.ActivateItem("Behavior");
        ListView.ItemValue = "Hard";
        ListView.ActivateItem("Bias Type");
        ListView.ItemValue = "No Bias";

This is for edge sizing, you can modify to suit your need for body or face sizing as well.
the function and its parameters can be accessed my "Listview" once you have the function by which it is called. In this case it was "DoInsertMeshSize()"


Similarly For Inflation you have the below function and you can add its parameters by "Listview" just like above depending upon your requirement.
Code:

ds.Script.doInsertInflation();

You can search CFDonline and check Ansys Portal as well for such codes.

Hope it helps
Cheers
KAPI

Riadh February 23, 2015 07:54

1 Attachment(s)
Dear Kapi

Thank you for your reply, it is very helpful!!

I am looking if there is a command to expand the Sizing group of controls (clicking the “+” sign to the left of the word Sizing) and change for example the Curvature Normal Angle (see attached figure).

I tried ListView.ActivateItem("Sizing") but i didn't work.

Best Regards!

Kapi February 23, 2015 17:58

Hi Riadh,

What you are asking is global Sizing under mesh.

What I told you in previous post is actually Sizing function which you can get by right click mesh and it will open up different functions which you can add to your geometry like Sizing, methods, inflation and things ( Mesh>Insert>Sizing)

If you are looking for localized sizing function then please insert sizing function rather than changing the global sizing and use the code which I gave you.

ps: to get into Mesh global setting you cannot use Listview, you need different function.

Cheers
KAPI

Riadh February 23, 2015 19:00

Dear Kapi

I agree with you, actually I am looking for the function which changes the global sizing (not the localized sizing function).

Do you know this function, it's the last command i need.


Riadh

Kapi February 24, 2015 17:12

Hi Riadh,

Yes I can help you with global function as well.
Basically for global changes, you need to function called "meshGroup"
It helps in listing all the global properties of mesh.

The below code changes global mesh minimum sizing and Maximum sizing.

Code:

meshGroup.MinSizeSF = 0.01;
meshGroup.MaxSizeSF = 0.25;

You can use "meshGroup...." and specify what you want to change in the global settings according to your geometry/Mesh

Hope it helps complete your project.

Have a good one!

Cheers
KAPI

samiam April 4, 2016 11:17

I know this thread is over a year old but I did find a way in 16.1 to use ListView for setting global mesh parameters. By searching through various .js files and Ans.Common.ControlsCOM.dll, I found that you need to select the group first and then use the 'Expand' property. Then you can just use ListView.ActivateItem and ListView.ItemValue like usual.

In this example I changed the Physics Preference, Relevance Center, Max Face Size, and Growth Rate options. It looks like ListView.FindGroup(n) returns the groups in the order that they appear ('Display' first, 'Defaults' second, 'Sizing' third, and so on). I hope this can be of help to someone.

Code:

//Get DesignSpace object
var DS = WB.AppletList.Applet("DSApplet").App;

//Get 'Mesh' control group
var Mesh_Mod = DS.Tree.FirstActiveBranch.MeshControlGroup;

//Get the ListView object so we can change the setting for the mesh sizing
var ListView = DS.Script.lv;

//Select 'Mesh' from the tree
DS.Script.SelectItems(""+Mesh_Mod.ID);

//Set global mesh options
//Set options in 'Defaults' group
var lGroupDefaults = ListView.FindGroup(2); //Get the 'Defaults' group
lGroupDefaults.Expand = 1; //Expand group
ListView.ActivateItem("Physics Preference"); //Set 'Physics Preference' option to 'CFD'
ListView.ItemValue = "CFD";
lGroupDefaults.Expand = 0; //Collapse group

//Set options in 'Sizing' group
var lGroupSizing = ListView.FindGroup(3);
lGroupSizing.Expand = 1; //Expand
//Set sizing options
ListView.ActivateItem("Relevance Center");
ListView.ItemValue = "Fine";
ListView.ActivateItem("Max Face Size");
ListView.ItemValue = "1e-04";
ListView.ActivateItem("Growth Rate");
ListView.ItemValue = "1.05";
lGroupSizing.Expand = 0; //Collapse

~Sam

giacoppo November 30, 2016 03:40

mesh a geometry via script sizing and worksheet for multizone
 
Dear All
Due to your knowledge in anys and scripting I suppose you are the right person to ask this question...
I'm trying to automate the meshing of a geometry by using a conformal mesh.
To do so manually, I sliced the domain into several blocks.
1)Defined several named selection 'via worksheet options"
2)defined several sizing controls referred to previuos defined named selection.
3)Applied Multizone Method to all bodies
4) Defined a worksheet for meshing in precise order

Any suggestion on how to do the same via scripting?
Kind regards

UchihaMadara January 4, 2018 10:43

Does anyone know how to get all the functions that can be added after Ds.Script?

kirakbabu March 21, 2018 11:03

Quote:

Originally Posted by UchihaMadara (Post 676938)
Does anyone know how to get all the functions that can be added after Ds.Script?

You can use debugger like Visual studio to get all the functions that are loaded.Usually all the functions are located in DSPages/Scripts folder.

michal28 September 11, 2018 12:06

Calling Js File from Workbench file
 
Once you have developed the .JS file for controlling your meshing parameter how do I call it from the workbench file or the ANSYS command window?

Does anyone have an example of there workbench code?

michal28 January 9, 2019 17:06

I know this post is old but did you ever work out this process ?


All times are GMT -4. The time now is 06:15.