Tcl constraints

At present constraints are interpreted as Tcl code. This may change in future to Python or whatever implementation language we are using, so if you are programming Tcl constraints directly, be prepared to update your constraints as program versions change. You should probably be using constraints syntax instead.

The usual Tcl syntax applies to constraints.

    # comment
    set VAR [expr {EXPRESSION}]
    if { EXPRESSION } {
        STATEMENTS
    } else {
        STATEMENTS
    }
    foreach VAR { LIST } {
        STATEMENTS
    }
    while { EXPRESSION } {
        STATEMENTS
    }

We define a function [range 1 $n] which returns a list of numbers from one to n. This is useful when operating on every layer.

Layer parameters are referenced using:

    gmlayer set PAR VALUE

If no VALUE is given, the layer parameter PAR is returned, otherwise the layer parameter PAR is updated with VALUE and VALUE is returned.

The following are valid parameters for reflfit:

    ntl - number of top layers
    nml - number of middle layers
    nbl - number of bottom layers
    nmr - number of repeats
    bk  - background 
    bi  - beam intensity
    vqc - vacuum scattering length density (16 pi N b units)
    tdi troi tmui tqci for i in 1 to 9
    mdi mroi mmui mqci for i in 1 to 9
    bdi broi bmui bqci for i in 1 to 9

The following are valid parameters for reflpol:

    nl  - number of layers
    bk  - background
    bi  - beam intensity
    vqc - vacuum scattering length density (16 pi N b units)
    di  roi mui qci for i > 0
    dmi rmi thi qmi for i > 0

Example 1:

    # set depth of layer T2 to be equal to layer M1
    gmlayer set td2 [gmlayer set md1]

Example 2:

    # set roughness to 1/2 the layer depth for all layers
    foreach i [range 1 [gmlayer set ntl]] { 
	gmlayer set tro$i [expr {[gmlayer set td$i]/2}]
    }
    foreach i [range 1 [gmlayer set nml]] { 
	gmlayer set mro$i [expr {[gmlayer set md$i]/2}]
    }
    foreach i [range 1 [gmlayer set nbl]] { 
	gmlayer set bro$i [expr {[gmlayer set bd$i]/2}]
    }

Example 3:

    # set the total depth of the middle layers to be equal
    # to the total depth of the top layers while preserving
    # the relative depths of the middle layers
    set sumt 0
    foreach i [range 1 [gmlayer set ntl]] {
        set sumt [expr {$sumt + [gmlayer set td$i]}]
    }
    set summ 0
    foreach i [range 1 [gmlayer set nml]] {
        set summ [expr {$summ + [gmlayer set md$i]}]
    }
    set scale [expr {$sumt/$summ}]
    foreach i [range 1 [gmlayer set nml]] {
        gmlayer set tm$i [expr {[gmlayer set tm$i]*$scale}]
    }

2004-05-18


Browse Index