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] How to get vertex location from script? (https://www.cfd-online.com/Forums/ansys-meshing/127496-how-get-vertex-location-script.html)

AdamAL December 12, 2013 11:28

How to get vertex location from script?
 
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

macfly December 13, 2013 14:55

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.

AdamAL January 3, 2014 06:41

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 January 3, 2014 07:18

[solved]
 
1 Attachment(s)
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.


All times are GMT -4. The time now is 18:10.