printing tcl return arguments with floating precision (Old problem type)

Moderator: GiD Team

jbaiges
Posts: 6
Joined: Thu Dec 11, 2014 12:02 pm

printing tcl return arguments with floating precision (Old problem type)

Postby jbaiges » Mon Feb 24, 2020 4:34 pm

Hello,
We are using a very simple tcl function to evaluate functions of the coordinates:

Code: Select all

proc EvalDirichletCondition { value x y z } {
    set result 0.0
    if { [catch { set result [format "%14.6f" [expr $value]] }]!=0} {
   WarnWinText "Error in Dirichlet boundary conditions!"
    }
    return $result
}


Then we call this function on the .fix file:

Code: Select all

*Set Cond PLCD_Initial_Velocity_2D *nodes
*loop nodes *OnlyInCond
*set var x =NodesCoord(1)
*set var y =NodesCoord(2)
*set var z =NodesCoord(3)
[b]*format "%i %i%i %i %i"[/b]
*NodesNum *tcl(FemussEvalDirichletCondition *cond(Value_velocity_x)  *x   *y   *z) *tcl(FemussEvalDirichletCondition *cond(Value_velocity_y)  *x   *y   *z) 
*end


We would like to write the result of the evaluation in a Scientific notation, however when we change the %i to %15.8e, for instance, we obtain the following error:

Error in base file ...: Bad integer format

Thank you for your help on this,

Kind regards,
Joan
User avatar
escolano
Posts: 1610
Joined: Thu Sep 18, 2014 3:31 pm

Re: printing tcl return arguments with floating precision (Old problem type)

Postby escolano » Thu Feb 27, 2020 8:23 pm

first, the .tcl code is calling
FemussEvalDirichletCondition
but your proc is called
EvalDirichletCondition

I assume that it has been a mistake writting the question in this forum,
in any case check that you are calling the proc that do you really want

It seems that EvalDirichletCondition expects as value argument a formulae in Tcl syntax, and, based on x y z arguments

Do you have an example of the formula that are you using in your case?

About format, the syntax of the Tcl format is the same as C syntax, and also the syntax of the .bas format

%i or %d is for an integer number, probably the result of the operation will be a real number, it's not? (off course depends of your formulae)
then
set result [format "%14.6f" [expr $value]]
seems ok
or you can avoid the format instruction, and left the default Tcl precision
set result [expr $value]

but the return value of a tcl procedure is an string, it doesn't matter if it represent a number.
and *tcl(xxx) will directly print this string to the output file

I am not sure if the *tcl calls are taken into account for the format
then in the .bas side probably you must replace
*format "%i %i%i %i %i"
by
*format "%i %s %s %f %f %f"
or maybe
*format "%i %f %f %f"
or better delete this *format line that is expensive (must be evaluated each loop), and left the default .bas formats (or use *informat and *realformat to set its values at the begin)

Return to “Customization”

Who is online

Users browsing this forum: No registered users and 3 guests