CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > ANSYS Meshing & Geometry

[ICEM] How to get vertex location from script?

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree3Likes
  • 1 Post By AdamAL
  • 2 Post By AdamAL

Reply
 
LinkBack Thread Tools Display Modes
Old   December 12, 2013, 12:28
Default How to get vertex location from script?
  #1
New Member
 
Adam Læssøe
Join Date: Nov 2013
Posts: 29
Rep Power: 3
AdamAL is on a distinguished road
As the title says.

How can I get the location ({x y z}) of a vertex?

I have found
Code:
ic_hex_point_location mypt04
But that only works for points, not vertices.

I can do it through the GUI, by:

[Left panel]>[Right click "Vertices"]>[Show vertex info]>[selection of vertex from screen]

But that operation is not recorded by the record replay function.

Any help is greatly appreciated.

/adam
liujing020277 likes this.
AdamAL is offline   Reply With Quote

Old   December 13, 2013, 15:55
Default
  #2
Senior Member
 
François Grégoire
Join Date: Jan 2010
Location: Laval University, Canada
Posts: 366
Rep Power: 8
macfly is on a distinguished road
I was looking for the same thing a few weeks ago and I never found a way in the scriting guide... I worked my way around with ic_hex_vertex_number { i j k } and another approach for blocking, cutting blocking, etc.

Keep us posted if you find the function.
macfly is offline   Reply With Quote

Old   January 3, 2014, 07:41
Default
  #3
New Member
 
Adam Læssøe
Join Date: Nov 2013
Posts: 29
Rep Power: 3
AdamAL is on a distinguished road
Initially I worked around it by calculating where I had put each split and so on. After a while this became very annoying, so yesterday I made my own workaround.

The workaround requires to save the blocking (that you want to 'query') to file. In the blocking file, the coordinates of the vertices are also recorded, so using the vertex's ijk, I search through the entire blocking file.

Now, there are some shortcomings:
  1. The current file has to be saved. If iterating this could lead to many file-writes => slow
  2. Each time the function is called, the full blk is read again, again => slow (this could be fixed fairly easily if it's a problem for you - see comment in code)
  3. The blk format is completely undocumented, so there is absolutely no guarantee that the naive logic I have implemented would always find the right place in the file. My geometry (on which i have tested) is very simple. If you find bugs and/or fixes please write back. In short the logic is:
    • Read blocking file to memory;
    • Get i,j,k of vertex;
    • Find the line containing the string (tcl definition): "\{ $i $j $k \}";
    • Split the line (by space (default));
    • Return the first three items on the line (assuming they are the location).

There are two functions defined below, the first is a small helper routine to read a file into a variable using only one line. The second (get_vertex_location_from_blk) is where the parsing is done.

Code:
# Read a file
proc read_whole_file {file_name} {
	set fp [open "$file_name" r]
	set file_data [read $fp]
	close $fp
	return $file_data
}

# Read vertex location from file.
# © Adam Andersen Læssøe, Jan, 2014
# Feel free to use or expand in any way you want, but provide credit.
# Returns -1 if unsucsessful
proc get_vertex_location_from_blk {vertex_number blk_file} {
	# In the sample file I looked at the ijk was only present on the line also specifying the coordinates.
	set ijk [ic_hex_vertex_ijk $vertex_number]
	# Wrap in braces to ensure uniqueness (the ijk might have some 'modifier' like "17:1")
	set ijk "\{ $ijk \}"
	# Read in the whole file. Carefull: if this is to be iterated over, it may become slow. 
	# Consider rewriting to suit your needs, eg. by supplying the data as an input parameter, so it at least only has to read once.
	# file data
	set fd [read_whole_file $blk_file]
	set fd [split $fd "\n"]
	set n_lines [llength $fd]
	# set have_found_ijk 0
	set i 0
	while {[expr $i<$n_lines]} {
		# line data
		set ld [lindex $fd $i]
		#mess [lindex $fd $i]
		if {[string first $ijk $ld]!="-1"} {
			# Below two lines do not work. ICEM throws: 'Error: wrong # args: should be "try"'
			#try {return [lindices $ld {0 1 2}]} 
			#on error {} {return -2}
			# Be naive and hope for the best (could raise out of range exception)
			return [lindices $ld {0 1 2}]
		}
		incr i
	}
	return -1
}
AdamAL is offline   Reply With Quote

Old   January 3, 2014, 08:18
Default [solved]
  #4
New Member
 
Adam Læssøe
Join Date: Nov 2013
Posts: 29
Rep Power: 3
AdamAL is on a distinguished road
Well isn't that just typical?! Cleaning up my open text tabs (using Sublime Text - awesome!), I came upon one I had forgot:

A list of commands that can be used in ICEM (to get it in ugly form type: info commands (and wait a while)).

Searching that list for location - lo and behold - was:

Code:
ic_hex_get_node_location
And sure enough, using:

Code:
ic_hex_get_node_location $my_vertex_unmber
got me the location.

For your investigative pleasure, I have also attached the command list sorted alphabetically.
Attached Files
File Type: txt List of ICEM tcl commands.txt (40.4 KB, 16 views)
macfly and evan247 like this.
AdamAL is offline   Reply With Quote

Reply

Tags
icem, scripting, tcl, vertex

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ill defined primitive entry 'boundary' francisco.angel OpenFOAM Pre-Processing 6 December 10, 2013 12:45
Mesh Refinement Luiz Eduardo Bittencourt Sampaio (Sampaio) OpenFOAM Mesh Utilities 41 January 17, 2013 03:43
Include list of points Hikachu OpenFOAM Native Meshers: blockMesh 0 June 20, 2011 09:03
my stl surface is seen as just a line rcastilla OpenFOAM Meshing & Mesh Conversion 2 January 6, 2010 02:30
NACA0012 geometry/design software needed Franny Main CFD Forum 13 July 7, 2007 15:57


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