CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Pointwise & Gridgen

Another scripting Problem

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

Reply
 
LinkBack Thread Tools Display Modes
Old   June 20, 2014, 07:22
Post Another scripting Problem
  #1
Member
 
Vanessa Herwig
Join Date: May 2014
Posts: 36
Rep Power: 3
v_herw is on a distinguished road
Hi,

i need a bit of help. I scripted a mesh and now i wanted to divide the script into procedures to have a nicer overview over the script. the problem now is that i need in several procedures different Cons/Doms. I wanted to create a procedure where i define all of these parameters to get them later in the procedures.

My script:
Code:
# PROCEDURE TO SET UP ALL PARAMETER
# -----------------------------------------------
proc PARAMETER {} {
	
# SET THE CONS/DOMS OF THE LAST SECTION
	global CN(1)
	set CN(1) [pw::GridEntity getByName "TopUpperCon"]
	global CN(2)
	set CN(2) [pw::GridEntity getByName "TopLowerCon"]
	global CN(3)
	
	set CN(3) [pw::GridEntity getByName "TopTeCon"]	
	global DM(2)
	set DM(2) [pw::GridEntity getByName "TopBlLowerDom"]
	global DM(3)
	set DM(3) [pw::GridEntity getByName "TopBlUpperDom"]
	global DM(4)
	set DM(4) [pw::GridEntity getByName "BottomBlUpperDom"]
	global DM(5)
	set DM(5) [pw::GridEntity getByName "UpperBlDom"]

}
But this won't work - i get the following fault:

Code:
Script: ----- TCL TRACE -----
Script: bad variable name "CN(1)": upvar won't create a scalar variable that looks like an array element
Script:     while executing
Script: "global CN(1)"
Script:     (procedure "PARAMETER" line 22)
Script:     invoked from within
Script: "PARAMETER"
Script:     (file "C:\xxxxxxxxxxxx.glf" line 161)
is there any opportunity to make the parameters "global"??

Thank you very much for your help
v_herw is offline   Reply With Quote

Old   June 22, 2014, 14:18
Default
  #2
Senior Member
 
John Chawner
Join Date: Mar 2009
Location: Fort Worth, Texas, USA
Posts: 219
Rep Power: 9
jchawner is on a distinguished road
Variable scope is a feature of Tcl, not Glyph. Therefore, you can find many online resources such as this one: https://www.tcl.tk/man/tcl8.5/tutorial/Tcl13.html

This page includes the ability to make variables global in scope. However, in general, global variables are bad practice. I would recommend passing variables to a proc via its parameter list instead.

I hope this helps.
__________________
John Chawner / jrc@pointwise.com / www.pointwise.com
Blog: http://blog.pointwise.com/
on Twitter: @jchawner
jchawner is offline   Reply With Quote

Old   June 23, 2014, 11:49
Default
  #3
Member
 
David Garlisch
Join Date: Jan 2013
Location: Pointwise HQ
Posts: 76
Rep Power: 4
dgarlisch is on a distinguished road
To answer your question directly, the error is caused by using the array subscript in the global statement.

I did not test this, but your proc should look like:

Code:
proc PARAMETER {} {
  global CN
  set CN(1) [pw::GridEntity getByName "TopUpperCon"]
  set CN(2) [pw::GridEntity getByName "TopLowerCon"]
  set CN(3) [pw::GridEntity getByName "TopTeCon"]	
  set DM(2) [pw::GridEntity getByName "TopBlLowerDom"]
  set DM(3) [pw::GridEntity getByName "TopBlUpperDom"]
  set DM(4) [pw::GridEntity getByName "BottomBlUpperDom"]
  set DM(5) [pw::GridEntity getByName "UpperBlDom"]
}
HOWEVER, I agree wholeheartedly with John.

Using global variables is a bad* programming practice in general. However, for "quick and dirty" scripts that will be used once and then thrown away, globals may be the easiest way to get things done quickly.


* There are always exceptions to the rules! (bad != NEVER)
dgarlisch is offline   Reply With Quote

Reply

Tags
global, glyph, parameter, script

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
UDF compiling problem Wouter Fluent UDF and Scheme Programming 6 June 6, 2012 04:43
Gambit - meshing over airfoil wrapping (?) problem JFDC FLUENT 1 July 11, 2011 05:59
natural convection problem for a CHT problem Se-Hee CFX 2 June 10, 2007 06:29
Adiabatic and Rotating wall (Convection problem) ParodDav CFX 5 April 29, 2007 19:13
Is this problem well posed? Thomas P. Abraham Main CFD Forum 5 September 8, 1999 14:52


All times are GMT -4. The time now is 06:00.