Challenge

Creating macro for performing quality criteria checks for 2-D and 3-D elements in Hypermesh using TCL/TK

AIM: To create a macro for Hypermesh using TCL/TK to create a GUI for element quality check of 2D and 3D elements.

PROCEDURE:

The macro created should have the following features:

1. Button for each criteria

2. Entry box to accept quality criteria value

3. Button presses should highlight failed elements with temporary nodes

The code prepared is shown below:

proc warpage {a} {
	*clearmarkall 1; *clearmarkall 2
	*createmark elems 1 "displayed"
	*createmark elems 2 
	if {[hm_marklength elems 1] !=0} {*elementtestwarpage elems 1 $a 2 2 0 "2D Warpage"
	*maskentitymark elems 2 0
	*maskreverse elems 
	*createmark nodes 1 "displayed"
	*nodemarkaddtempmark 1
	*unmaskall2}}

proc min_len_2d {b} {
	*clearmarkall 1; *clearmarkall 2
	*createmark elems 1 "displayed"
	*createmark elems 2 
	if {[hm_marklength elems 1] !=0} {*elementtestlength elems 1 $b 2 1 2 0 "Minimum edge length"
	if {[hm_marklength elems 2] !=0} {
	*maskentitymark elems 2 0
	*maskreverse elems 
	*createmark nodes 1 "displayed"
	*nodemarkaddtempmark 1
	*unmaskall2}}}

proc min_len_3d {b} {
	*clearmarkall 1; *clearmarkall 2
	*createmark elems 1 "displayed"
	*createmark elems 2 
	if {[hm_marklength elems 1] !=0} {*elementtestlength elems 1 $b 2 1 4 0 "Minimum edge length"
	if {[hm_marklength elems 2] !=0} {
	*maskentitymark elems 2 0
	*maskreverse elems 
	*createmark nodes 1 "displayed"
	*nodemarkaddtempmark 1
	*unmaskall2}}}

proc max_len_2d {c} {
	*clearmarkall 1; *clearmarkall 2
	*createmark elems 1 "displayed"
	*createmark elems 2 
	if {[hm_marklength elems 1] !=0} {*elementtestlength elems 1 $c 2 0 2 0 "Maximum edge length"
	if {[hm_marklength elems 2] !=0} {
	*maskentitymark elems 2 0
	*maskreverse elems 
	*createmark nodes 1 "displayed"
	*nodemarkaddtempmark 1
	*unmaskall2}}}

proc aspect {d} {
	*clearmarkall 1; *clearmarkall 2
	*createmark elems 1 "displayed"
	*createmark elems 2 
	if {[hm_marklength elems 1] !=0} {*elementtestaspect elems 1 $d 2 2 0 "Aspect Ratio"
	if {[hm_marklength elems 2] !=0} {
	*maskentitymark elems 2 0
	*maskreverse elems 
	*createmark nodes 1 "displayed"
	*nodemarkaddtempmark 1
	*unmaskall2}}}

proc skew_2d {e} {
	*clearmarkall 1; *clearmarkall 2
	*createmark elems 1 "displayed"
	*createmark elems 2 
	if {[hm_marklength elems 1] !=0} {*elementtestskew elems 1 $e 2 2 0 "2D Skew"
	if {[hm_marklength elems 2] !=0} {
	*maskentitymark elems 2 0
	*maskreverse elems 
	*createmark nodes 1 "displayed"
	*nodemarkaddtempmark 1
	*unmaskall2}}}

proc skew_3d {e} {
	*clearmarkall 1; *clearmarkall 2
	*createmark elems 1 "displayed"
	*createmark elems 2 
	if {[hm_marklength elems 1] !=0} {*elementtestskew elems 1 $e 2 4 0 "Volumetric Skew"
	*maskentitymark elems 2 0
	*maskreverse elems 
	*createmark nodes 1 "displayed"
	*nodemarkaddtempmark 1
	*unmaskall2}}


proc jacobian {f} {
	*clearmarkall 1; *clearmarkall 2
	*createmark elems 1 "displayed"
	*createmark elems 2 
	if {[hm_marklength elems 1] !=0} {*elementtestjacobian elems 1 $f 2 2 0 "Jacobian"
	if {[hm_marklength elems 2] !=0} {
	*maskentitymark elems 2 0
	*maskreverse elems 
	*createmark nodes 1 "displayed"
	*nodemarkaddtempmark 1
	*unmaskall2}}}

proc min_tria_2d {g} {
	*clearmarkall 1; *clearmarkall 2
	*createmark elems 1 "displayed"
	*createmark elems 2 
	if {[hm_marklength elems 1] !=0} {*elementtestinterangle elems 1 $g 1 2 1 2 0 "Minimum length Tria"
	if {[hm_marklength elems 2] !=0} {
	*maskentitymark elems 2 0
	*maskreverse elems 
	*createmark nodes 1 "displayed"
	*nodemarkaddtempmark 1
	*unmaskall2}}}

proc min_tria_3d {g} {
	*clearmarkall 1; *clearmarkall 2
	*createmark elems 1 "displayed"
	*createmark elems 2 
	if {[hm_marklength elems 1] !=0} {*elementtestinterangle elems 1 $g 1 2 1 4 0 "Minimum length Tria"
	if {[hm_marklength elems 2] !=0} {
	*maskentitymark elems 2 0
	*maskreverse elems 
	*createmark nodes 1 "displayed"
	*nodemarkaddtempmark 1
	*unmaskall2}}}

proc max_tria_2d {h} {
	*clearmarkall 1; *clearmarkall 2
	*createmark elems 1 "displayed"
	*createmark elems 2 
	if {[hm_marklength elems 1] !=0} {*elementtestinterangle elems 1 $h 1 2 0 2 0 "Maximum length Tria"
	if {[hm_marklength elems 2] !=0} {
	*maskentitymark elems 2 0
	*maskreverse elems 
	*createmark nodes 1 "displayed"
	*nodemarkaddtempmark 1
	*unmaskall2}}}

proc max_tria_3d {h} {
	*clearmarkall 1; *clearmarkall 2
	*createmark elems 1 "displayed"
	*createmark elems 2 
	if {[hm_marklength elems 1] !=0} {*elementtestinterangle elems 1 $h 1 2 0 4 0 "Maximum length Tria"
	if {[hm_marklength elems 2] !=0} {
	*maskentitymark elems 2 0
	*maskreverse elems 
	*createmark nodes 1 "displayed"
	*nodemarkaddtempmark 1
	*unmaskall2}}}


proc min_quad_2d {i} {
	*clearmarkall 1; *clearmarkall 2
	*createmark elems 1 "displayed"
	*createmark elems 2 
	if {[hm_marklength elems 1] !=0} {*elementtestinterangle elems 1 $i 0 2 1 2 0 "Minimum quad length"
	if {[hm_marklength elems 2] !=0} {
	*maskentitymark elems 2 0
	*maskreverse elems 
	*createmark nodes 1 "displayed"
	*nodemarkaddtempmark 1
	*unmaskall2}}}


proc min_quad_3d {i} {
	*clearmarkall 1; *clearmarkall 2
	*createmark elems 1 "displayed"
	*createmark elems 2 
	if {[hm_marklength elems 1] !=0} {*elementtestinterangle elems 1 $i 0 2 1 4 0 "Minimum quad length"
	if {[hm_marklength elems 2] !=0} {
	*maskentitymark elems 2 0
	*maskreverse elems 
	*createmark nodes 1 "displayed"
	*nodemarkaddtempmark 1
	*unmaskall2}}}


proc max_quad_2d {j} {
	*clearmarkall 1; *clearmarkall 2
	*createmark elems 1 "displayed"
	*createmark elems 2 
	if {[hm_marklength elems 1] !=0} {*elementtestinterangle elems 1 $j 0 2 0 2 0 "Maximum quad length"
	if {[hm_marklength elems 2] !=0} {
	*maskentitymark elems 2 0
	*maskreverse elems 
	*createmark nodes 1 "displayed"
	*nodemarkaddtempmark 1
	*unmaskall2}}}

proc max_quad_3d {j} {
	*clearmarkall 1; *clearmarkall 2
	*createmark elems 1 "displayed"
	*createmark elems 2 
	if {[hm_marklength elems 1] !=0} {*elementtestinterangle elems 1 $j 0 2 0 4 0 "Maximum quad length"
	if {[hm_marklength elems 2] !=0} {
	*maskentitymark elems 2 0
	*maskreverse elems 
	*createmark nodes 1 "displayed"
	*nodemarkaddtempmark 1
	*unmaskall2}}}


proc tet_collapse {k} {
	*clearmarkall 1; *clearmarkall 2
	*createmark elems 1 "displayed"
	*createmark elems 2 
	if {[hm_marklength elems 1] !=0} {*elementtesttetracollapse elems 1 $k 2 0 "Tet Collapse"
	if {[hm_marklength elems 2] !=0} {
	*maskentitymark elems 2 0
	*maskreverse elems 
	*createmark nodes 1 "displayed"
	*nodemarkaddtempmark 1
	*unmaskall2}}}

set win .window
catch {destroy $win}
toplevel $win -class TopClass
wm title $win "Element quality check"
wm geometry $win 820x560+200+200
wm resizable $win 0 0
wm deiconify $win 

set min_2d 2
set max_2d 8
set asp 5
set warp 30
set sk_2d 45
set jacob 0.6
set min_tria_2 20
set max_tria_2 120 
set min_quad_2 45
set max_quad_2 135
set min_3d 2
set sk_3d 45
set min_tria_3 20
set max_tria_3 120
set min_quad_3 45
set max_quad_3 135
set tet 0.15

label $win.01 -text "2D Element Quality" -bg grey -font {times 20 bold}
place $win.01 -x 10 -y 10 -width 400 -height 32

label $win.02 -text "3D Element Quality" -bg grey -font {times 20 bold}
place $win.02 -x 410 -y 10 -width 400 -height 32

button $win.03 -text "Min Edge Length" -font {times 10 bold} -command {min_len_2d $min_2d}
place $win.03 -x 10 -y 60 -width 140 -height 32

entry $win.04 -textvariable min_2d -font {times 10 bold} 
place $win.04 -x 160 -y 60 -width 140 -height 32

button $win.05 -text "Max Edge Length" -font {times 10 bold} -command {max_len_2d $max_2d}
place $win.05 -x 10 -y 110 -width 140 -height 32

entry $win.06 -textvariable max_2d -font {times 10 bold} 
place $win.06 -x 160 -y 110 -width 140 -height 32

button $win.07 -text "Warpage" -font {times 10 bold} -command {warpage $warp}
place $win.07 -x 10 -y 160 -width 140 -height 32

entry $win.08 -textvariable warp -font {times 10 bold} 
place $win.08 -x 160 -y 160 -width 140 -height 32

button $win.09 -text "Aspect Ratio" -font {times 10 bold} -command {aspect $asp}
place $win.09 -x 10 -y 210 -width 140 -height 32

entry $win.10 -textvariable asp -font {times 10 bold} 
place $win.10 -x 160 -y 210 -width 140 -height 32

button $win.11 -text "2D Skew" -font {times 10 bold} -command {skew_2d $sk_2d}
place $win.11 -x 10 -y 260 -width 140 -height 32

entry $win.12 -textvariable sk_2d -font {times 10 bold} 
place $win.12 -x 160 -y 260 -width 140 -height 32

button $win.13 -text "Jacobian" -font {times 10 bold} -command {jacobian $jacob}
place $win.13 -x 10 -y 310 -width 140 -height 32

entry $win.14 -textvariable jacob -font {times 10 bold} 
place $win.14 -x 160 -y 310 -width 140 -height 32

button $win.15 -text "Min Tria Angle" -font {times 10 bold} -command {min_tria_2d $min_tria_2}
place $win.15 -x 10 -y 360 -width 140 -height 32

entry $win.16 -textvariable min_tria_2 -font {times 10 bold} 
place $win.16 -x 160 -y 360 -width 140 -height 32

button $win.17 -text "Max Tria Angle" -font {times 10 bold} -command {max_tria_2d $max_tria_2}
place $win.17 -x 10 -y 410 -width 140 -height 32

entry $win.18 -textvariable max_tria_2 -font {times 10 bold} 
place $win.18 -x 160 -y 410 -width 140 -height 32

button $win.19 -text "Min Quad Angle" -font {times 10 bold} -command {min_quad_2d $min_quad_2}
place $win.19 -x 10 -y 460 -width 140 -height 32

entry $win.20 -textvariable min_quad_2 -font {times 10 bold} 
place $win.20 -x 160 -y 460 -width 140 -height 32

button $win.21 -text "Max Quad Angle" -font {times 10 bold} -command {max_quad_2d $max_quad_2}
place $win.21 -x 10 -y 510 -width 140 -height 32

entry $win.22 -textvariable max_quad_2 -font {times 10 bold} 
place $win.22 -x 160 -y 510 -width 140 -height 32

button $win.23 -text "Min Edge Length" -font {times 10 bold} -command {min_len_3d $min_3d}
place $win.23 -x 450 -y 60 -width 140 -height 32

entry $win.24 -textvariable min_3d -font {times 10 bold} 
place $win.24 -x 600 -y 60 -width 140 -height 32

button $win.25 -text "3D Skew" -font {times 10 bold} -command {skew_3d $sk_3d}
place $win.25 -x 450 -y 110 -width 140 -height 32

entry $win.26 -textvariable sk_3d -font {times 10 bold} 
place $win.26 -x 600 -y 110 -width 140 -height 32

button $win.27 -text "Min Tria Angle" -font {times 10 bold} -command {min_tria_3d $min_tria_3}
place $win.27 -x 450 -y 160 -width 140 -height 32

entry $win.28 -textvariable min_tria_3 -font {times 10 bold} 
place $win.28 -x 600 -y 160 -width 140 -height 32

button $win.29 -text "Max Tria Angle" -font {times 10 bold} -command {max_tria_3d $max_tria_3}
place $win.29 -x 450 -y 210 -width 140 -height 32

entry $win.30 -textvariable max_tria_3 -font {times 10 bold} 
place $win.30 -x 600 -y 210 -width 140 -height 32

button $win.31 -text "Min Quad Angle" -font {times 10 bold} -command {min_quad_3d $min_quad_3}
place $win.31 -x 450 -y 260 -width 140 -height 32

entry $win.32 -textvariable min_quad_3 -font {times 10 bold} 
place $win.32 -x 600 -y 260 -width 140 -height 32

button $win.33 -text "Max Quad Angle" -font {times 10 bold} -command {max_quad_3d $max_quad_3}
place $win.33 -x 450 -y 310 -width 140 -height 32

entry $win.34 -textvariable max_quad_3 -font {times 10 bold} 
place $win.34 -x 600 -y 310 -width 140 -height 32

button $win.35 -text "Tet Collapse" -font {times 10 bold} -command {tet_collapse $tet}
place $win.35 -x 450 -y 360 -width 140 -height 32

entry $win.36 -textvariable tet -font {times 10 bold} 
place $win.36 -x 600 -y 360 -width 140 -height 32

The breakdown of the code is given below:

proc warpage {a} {
	*clearmarkall 1; *clearmarkall 2
	*createmark elems 1 "displayed"
	*createmark elems 2 
	if {[hm_marklength elems 1] !=0} {*elementtestwarpage elems 1 $a 2 2 0 "2D Warpage"
	*maskentitymark elems 2 0
	*maskreverse elems 
	*createmark nodes 1 "displayed"
	*nodemarkaddtempmark 1
	*unmaskall2}}

A procedure named "warpage" is created which accepts an input variable "a" through which the quality criteria value will be added. A mark is created for displayed elements. If the mark is not empty, then using *elementtestwarpage command the warpage quality is tested for all elements in the mark. Then the elements that fail are masked and the mask is reversed. Therefore only the failed elements are displayed. All displayed nodes which belong exclusively to the failed elements are added to a mark and by using command *nodemarkaddtempmark temporary nodes are added to the nodes belonging to the failed elements. Then all elements are unmasked.

This procedure is created for all important quality criteria checks such as aspect ratio, minimum edge length, etc.

set win .window
catch {destroy $win}
toplevel $win -class TopClass
wm title $win "Element quality check"
wm geometry $win 820x560+200+200
wm resizable $win 0 0
wm deiconify $win 

A window with variable name "win" is created with title "Element quality check" and dimensions 820x560.

set min_2d 2
set max_2d 8
set asp 5
set warp 30
set sk_2d 45
set jacob 0.6
set min_tria_2 20
set max_tria_2 120 
set min_quad_2 45
set max_quad_2 135
set min_3d 2
set sk_3d 45
set min_tria_3 20
set max_tria_3 120
set min_quad_3 45
set max_quad_3 135
set tet 0.15

In this part, default values are given for the various quality criteria variables which will be used to call their respective procedures in the next part of the code:

button $win.03 -text "Min Edge Length" -font {times 10 bold} -command {min_len_2d $min_2d}
place $win.03 -x 10 -y 60 -width 140 -height 32

entry $win.04 -textvariable min_2d -font {times 10 bold} 
place $win.04 -x 160 -y 60 -width 140 -height 32

A button is created with text "Min Edge Length". If the button is pressed then the command will call for the procedure to detect minimum edge length. An entry is placed to the right of the button where the user can enter quality criteria value. Similarly, buttons and entry boxes are created for all quality criteria.

The GUI is shown below:

An example is given below:

The elements in white colour are failing the given warpage criteria. When the macro is performed over this component, temporary nodes are created on the failed elements so that it is easier to notice.

CONCLUSION: The required macro for performing quality criteria checks in Hypermesh was successfully created using TCL/TK.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.