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/)
-   -   [ICEM] Scripting - how to get the number of a point via x-location (https://www.cfd-online.com/Forums/ansys-meshing/126458-scripting-how-get-number-point-via-x-location.html)

Saphyra November 18, 2013 08:28

Scripting - how to get the number of a point via x-location
 
Hi everyone,

I've just started to use ICEM CFD, so I'm sorry, if my question is too simple. But to be honest, after using ANSYS APDL for a long time, the coding in ICEM CFD is a little bit confusing. Right now I'm trying to script automated meshing of different airfoils with different amount of formatted data points. At some point of the process, I have to split my block while selecting one point at the trailing edge. Of course, if I have a different amount of formatted data points, the numbering of the two points on the trailing edge will change. Now my question: how can I get the number of one of these two points, to save it in a parameter - so that I can access it in my script later (without always changing the point number in the script file)? Since the y-location of the trailing edge changes, it should be somehow possible to select a point just via x-location if there aren't any other points in the y-axis, right? Summing up, I'm searching for a command equal to the *get-command in ANSYS APDL. ^ ^

Thanks for your help.

Yours sincerely,
Saphy

stuart23 November 19, 2013 06:28

Try:

foreach test_point [ic_geo_get_objects point _PART_NAME_] {if {[ic_geo_get_point_location $test_point] _COORD_INDEX_] == _COORD_VALUE_} {[ic_hex_split_grid _BLOCK_INDICIES_ ; break}}

Replace:

_PART_NAME_ with the part that you want to search for the point in. If the point could be in any part, replace with "" (ie 2 double quotation marks)

_COORD_INDEX_ with the index your searching. Ie if you want to find a point where x = 7.5, replace with 0. If your searching for a Y value, replace with 1. And if your searching for a Z value....... You guessed it! Replace with 2.

_COORD_VALUE_ with the coordinate value you are searching for ie if you want X = 7.5, replace with 7.5

_BLOCK_INDICIES_ with the two verticies you wish to split between. As you are creating your blocking in batch, the two verticies you are splitting between will be persistant.

Note, this script will only search for the first instance of a point that matches the condition. If instead you want to split at ALL points with an X value of 0, remove the break after the split.

For your example, if you wanted to split at a point in part GEOM where X=0, and the split goes between verts 67 & 89:

foreach test_point [ic_geo_get_objects point GEOM] {if {[ic_geo_get_point_location $test_point] 0] == 0} {[ic_hex_split_grid 67 89 ; break}}


EASY!

TclTk programming is EXTREAMLY powerful. People have even programmed up custom interfaces for ICEM so that they can perform all their custom functions using ICEM's powerful geom, hexa and unstructured tools without loading the ICEM GUI.

Stu

AdamAL November 19, 2013 06:50

Quote:

People have even programmed up custom interfaces for ICEM
Interesting - do you know of any that are publicly available?

/adam

stuart23 November 19, 2013 06:55

Double Post, Sorry!

Saphyra November 19, 2013 08:03

Oh, that looks great! I will try it out later, when I'm at my work station. But just by looking at it - is it right, that you create a for-loop through an array filled with all of the points of my geometry. Then you ask, if there is a point, which has the wanted coordinate value in the wanted xyz-direction, and to split the block at this particular point or to stop the if-command, if there isn't?

I hope, I did understand the code right. But let me ask you - are there missing brackets in the code after the ic_hex_split_grid-command (just before the semikolon) and also before the ic_geo_get_point_location-command? And can you recommend a link or whatsoever, where I can find a tutorial for TclTk? Actually TclTk seems really powerful and just with the ICEM-Programmer's guide not everything - especially the basics - is understandable. With my little knowledge about it I was just able to count all of my points, and to calculate the point name (p_count/2-1). But this would be extremely bad regarding that sometimes the point numbering isn't equal in the airfoil data. Therefore I should learn more about TclTk I guess. :)

Thank you so much for your help!

Saphyra November 19, 2013 15:37

Ok, I implemented the code in my scripting replay file, while adding some extra brackets to supress other warnings like "missing bracket". But actually I do get the following additional error warning:

Quote:

Error in replay of foreach test_point [ic_geo_get_objects point PNTS] {if {[[ic_geo_get_point_location $test_point] 0] == 1} {[ic_hex_split_grid 33 35] ; break}}:
invalid command name "0 0 0"
What did I do wrong?

macfly November 19, 2013 19:07

Instead of searching for a point, just create one where you want to split the block and then delete it! Here is the code that I suggest, run it and see what it does:
Code:

# draw a cube
ic_undo_group_begin
ic_geo_new_family GEOM
ic_boco_set_part_color GEOM
ic_vid_object box8 GEOM 00 {0 0 0} 1 1 1
ic_set_dormant_pickable point 0 {}
ic_set_dormant_pickable curve 0 {}
ic_undo_group_end

# initialize blocking
ic_undo_group_begin
ic_geo_new_family BLOCKING
ic_boco_set_part_color BLOCKING
ic_hex_initialize_blocking {} BLOCKING 0 101
ic_hex_switch_blocking root
ic_hex_unblank_blocks
ic_hex_multi_grid_level 0
ic_hex_projection_limit 0
ic_hex_default_bunching_law default 2.0
ic_hex_floating_grid off
ic_hex_transfinite_degree 1
ic_hex_unstruct_face_type one_tri
ic_hex_set_unstruct_face_method uniform_quad
ic_hex_set_n_tetra_smoothing_steps 20
ic_hex_set_mesh_params BLOCKING GEOM -version 110
ic_hex_error_messages off_minor
ic_hex_switch_blocking root
ic_undo_group_end

# cut blocking at x,y,z = 0.5,0,0
ic_undo_group_begin
set vertex1 [ic_hex_vertex_number { 1 1 1 }]
set vertex2 [ic_hex_vertex_number { 2 1 1 }]
ic_point {} POINT split_point 0.5,0,0
ic_hex_split_grid $vertex1 $vertex2 split_point m BLOCKING
ic_delete_geometry point names split_point 0 1
ic_undo_group_end

some comments
- you have to keep track of the blocking index as you cut the blocking and look for vertex numbers with ic_hex_vertex_number, it's easy
- I'm not sure if ic_undo_group_begin/end are of any use!

stuart23 November 21, 2013 06:48

Hey Saphyra,

You didn't do anything wrong. I somehow screwed up copy-pasting the code from ICEM into this forum....

Quote:

foreach test_point [ic_geo_get_objects point ""] {if {[lindex [ic_geo_get_point_location $test_point] 2] == 1} {ic_hex_split_grid 21 22 $test_point; break}}
Generically, following the same substitutions as above:

Quote:

foreach test_point [ic_geo_get_objects point _PART_NAME_] {if {[lindex [ic_geo_get_point_location $test_point] _COORD_INDEX_] == _COORD_VALUE_} {ic_hex_split_grid _BLOCK_INDICIES_ $test_point; break}}

stuart23 November 21, 2013 07:02

Quote:

Originally Posted by Saphyra (Post 462533)
Oh, that looks great! I will try it out later, when I'm at my work station. But just by looking at it - is it right, that you create a for-loop through an array filled with all of the points of my geometry. Then you ask, if there is a point, which has the wanted coordinate value in the wanted xyz-direction, and to split the block at this particular point or to stop the if-command, if there isn't?

I hope, I did understand the code right. But let me ask you - are there missing brackets in the code after the ic_hex_split_grid-command (just before the semikolon) and also before the ic_geo_get_point_location-command? And can you recommend a link or whatsoever, where I can find a tutorial for TclTk? Actually TclTk seems really powerful and just with the ICEM-Programmer's guide not everything - especially the basics - is understandable. With my little knowledge about it I was just able to count all of my points, and to calculate the point name (p_count/2-1). But this would be extremely bad regarding that sometimes the point numbering isn't equal in the airfoil data. Therefore I should learn more about TclTk I guess. :)

Thank you so much for your help!

Saphyra,

Your understanding is 99% correct. Instead of the break referring to the if command, it breaks the foreach loop so that it does not continue to look for more points. This is to stop the code from trying to split the block a second time after it has already been split. It is not possible to perform a split twice anyway though, because there will no longer be a single edge that joins vertices 21 & 22 (or whatever you specified) as you will have already split that edge. Therefore the break is just there for programming best practices and to stop an error being displayed in the case that it did find two points.

For a great Tcltk reference, I would recommend http://www2.tcl.tk . They have a great function help resource, and I think there might be some tutorials, defiantly bookmark the site!

In ICEM, try using Replay Control to record what you want to do if you don't know how to do it. That way you have a basis, rather than coding from scratch.

Tcltk is a very easy language to understand, as the syntax is so straightforward. It is very high level, which makes it very easy to use (for example, the foreach function; easy to understand and implement). It is also used in many different programs, so the time you spend learning it for ICEM will pay off in other areas.


Stu

Saphyra November 22, 2013 21:32

Thank you so much for your help. The new code worked out very well, so that I could also implement other codes, just like searching for the point with the maximum y-location on the profile without knowing the exact y-value etc. You're right, TclTk becomes easier the more you work with it. But for one problem I didn't find the solution yet. For example if I want to change the mesh parameters with the bigeometric mesh law, the code is something like:

Code:

ic_hex_set_mesh 11 13 n 10 h1 0.0001 h2 0 r1 1.2 r2 2 lmax 0 default unlocked
In this case I fixed the spacing as well as the ratio for the starting point and because it was an easy geometry, ICEM CFD didn't have to recalculate the remaining two parameters. But sometimes the replay file contains selfcalculated values for spacing and ratio for the ending point, which could be for example a floating point number like 0.0389287 instead of a 0 or 2 like in the code above. How can I suppress these internal calculated numbers? The reason I'm asking is that I want to create a fully parameterized script for generating 3D meshes for different profiles. That's why I don't want to use codes which contain problem specific values. Thanks again!


All times are GMT -4. The time now is 19:56.