Unfortunately, there are complications in using variables inside Specify blocks. Consider this simple example:
Parameter cellsize 5e-9
Specify Oxs_RectangularMesh:BadExample {
comment {NOTE: THIS DOESN'T WORK!!!}
cellsize {$cellsize $cellsize $cellsize}
atlas :atlas
}
This doesn't work, because the curly braces used to set off the
Specify initialization string also inhibit variable substitution.
There are several ways to work around this, but the easiest is usually
to embed the initialization string inside a subst (substitution)
command:
Parameter cellsize 5e-9
Specify Oxs_RectangularMesh:GoodExample [subst {
comment {NOTE: This works.}
cellsize {$cellsize $cellsize $cellsize}
atlas :atlas
}]
Here the square brackets, ``['' and ``]'',
cause Tcl to perform command substitution, i.e.,
execute the string inside the square brackets as a Tcl command, in this case the subst command. See the Tcl documentation for subst for details, but the default
usage illustrated above performs variable, command and
backslash substitutions on the argument string.
One more example, this time involving both variable and command substitution:
set pi [expr {4*atan(1.0)}]
set mu0 [expr {4*$pi*1e-7}]
Specify Oxs_UZeeman [subst {
comment {Set units to mT}
Hscale [expr {0.001/$mu0}]
Hrange {
{ 0 0 0 10 0 0 2 }
{ 10 0 0 -10 0 0 2 }
}
}]
Note that the subst command is evaluated at global scope, so that
the global variable mu0 is directly accessible.