Page 1 of 1

Working with faces in .bas file

Posted: Mon Jan 13, 2020 4:22 am
by aortizb
Hello, I am trying to code in the .bas file so that I can get some info printed to a calculation file. I give an example below. I am not sure whether this can be done in GiD, though. I tried but I didn't get it right.

Say, we have this mesh of 4-node quadrilaterals:
6------------5------------4
|............|............|
|............|............|
|............|............|
1------------2------------3

1) Assume the faces are numbered globally as follows:
Face # node1 node2
1 1 2
2 2 3
3 6 1
4 2 5
5 3 4
6 5 6
7 4 5

2) The connectivity in terms of these global face numbers is:
Element # Face1 Face2 Face3 Face4
1 1 4 6 3
2 2 5 7 4

What code should I provide in the .bas file to print something like 1) and 2) above to a calculation file?

Thanks,
Alejandro.

Re: Working with faces in .bas file

Posted: Tue Jan 14, 2020 7:42 pm
by escolano
GiD mesh data structures are not oriented to faces, the faces of the elements doesn't exists or have an identifier number.

To write what you want you must do it with some Tcl scripting procedure that get the information of GiD (nodes and elements with some "GiD_Info Mesh ... " command) and reorder it as you want:
A-enumerate all faces and remove duplicates (considering equal the face A->B than the B->A), and assign them a face id 1,2,...
B-traverse the elements and for each one of its faces identify by its nodes your face id.

You can invoke from the .bas file a
*tcl(my_proc)
that will print in the .dat output file the string returned by the Tcl procedure my_proc
(to avoid create a big string with big meshes is also possible with some trick to directly print in the .bas opened file from the Tcl procedure)

Re: Working with faces in .bas file

Posted: Tue Jan 14, 2020 8:11 pm
by escolano
The Tcl procedure could be this (save it in a file named <problemtype>.tcl to be automatically sourced)

Code: Select all

proc MyGetEdgesFromQuadrilaterals { } {
    set info_mesh [GiD_Info mesh Elements quadrilateral -sublist]
    #use and face_id array to avoid repeated and store an id
    foreach item $info_mesh {
        set connectivities [lrange $item 1 end-1]
        foreach face_local_nodes {{0 1} {1 2} {2 3} {3 0}} {
            lassign $face_local_nodes a b
            set node_a [lindex $connectivities $a] 
            set node_b [lindex $connectivities $b] 
            set key [list $node_a $node_b]
            set key_swap [list $node_b $node_a]
            if { ![info exists face_id($key)] && ![info exists face_id($key_swap)] } {
                set face_id($key) 0
            }     
        }
    }
    
    set counter 0
    set ret "Face # node1 node2\n"
    foreach key [array names face_id] {
        set face_id($key) [incr counter]
        append ret "$counter $key\n"
    }
    append ret "Element # Face1 Face2 Face3 Face4\n"
    set counter 0
    foreach item $info_mesh {
        set connectivities [lrange $item 1 end-1]
        set face_ids [list]
        foreach face_local_nodes {{0 1} {1 2} {2 3} {3 0}} {
            lassign $face_local_nodes a b
            set node_a [lindex $connectivities $a] 
            set node_b [lindex $connectivities $b] 
            set key [list $node_a $node_b]
            if { [info exists face_id($key)] } {
                set id $face_id($key)
            } else {
                set key_swap [list $node_b $node_a]
                set id $face_id($key_swap)
            }
            lappend face_ids $id            
        }
        append ret "[incr counter] $face_ids\n"
    }
    return $ret
}
And then your .bas file could be like this

Code: Select all

...

*tcl(MyGetEdgesFromQuadrilaterals)

...

Re: Working with faces in .bas file

Posted: Wed Jan 15, 2020 4:06 pm
by aortizb
Dear Enrique:

Thank you very much! That worked through smoothly. I used to perform this edge search on my own codes after reading the mesh. Now, I can make it in one shot from the .bas file.

Best,
Alejandro.