

# type: custom properties name: beam variable height

# This example defines a beam where one of its dimensions,
# widthY, changes depending on the position inside the beam
# it is necessary to apply to the same line in the geometry
# two conditions: "Rectangular section" with an arbitrary widthY
# and "Custom property", with the TCL code below

# Note that both, the function that retrieve data, like "coords"
# and the function that updates the properties "updateprops"
# are expressed in the units assigned to the "Custom properties"

# to discover other properties names, use "updateprops help"
# and execute the program

set x [expr {0.5*(coords(1,1)+coords(2,1))}]
set xc [expr {abs($x-3500)/3500}]
set widthY [expr {500-250*$xc}]
dict set pdict widthY $widthY
dict set pdict widthZ 125
updateprops $pdict


# type: custom loads name: punctual load middle line

# this example applies a punctual load in the middle of a line
# it is not necessary that there exists a node in the place where
# the load is applied

# Note that both, the function that retrieve data, like "coords"
# and the function that adds the load "add_to_load_vector"
# are expressed in the units assigned to the "Custom loads"

# In this case, Fy=-1e4 and application point is x=0.0

if { ![info exists carga_puntual_en_linea] } {
    set x1 [coords 1 1]
    set x2 [coords 2 1]
    if { (0 >= $x1-epsilon() && 0 <= $x2+epsilon()) || \
	(0 >= $x2-epsilon() && 0 <= $x1+epsilon()) } {
	set f1 [expr {facLoad()*-1e4*($x2-0)/double($x2-$x1)}]
	set f2 [expr {facLoad()*-1e4*(0-$x1)/double($x2-$x1)}]
	add_to_load_vector [conec 1] [list 0 $f1 0 0 0 0]
	add_to_load_vector [conec 2] [list 0 $f2 0 0 0 0]
	set carga_puntual_en_linea 1 
    }
}

# type: custom loads name: Hydrostatic pressure

# this example applies a triangular pressure in a mesh
# of triangles. The pressure is 0.0 at z=10.0 and above
# it is (10.0-z)*1e4 below

# Note that both, the function that retrieve data, like "coords"
# and the function that adds the load "addload"
# are expressed in the units assigned to the "Custom loads"

foreach "zmin zmax" [list 1e20 -1e20] break
for { set i 1 } { $i <= 3 } { incr i } {
    if { coords($i,3) < $zmin } { set zmin [coords $i 3] }
    if { coords($i,3) > $zmax } { set zmax [coords $i 3] }
}

set p_zmin [expr {($zmin<10.0)?(10.0-$zmin)*1e4:0.0}]
set p_zmax [expr {($zmax<10.0)?(10.0-$zmax)*1e4:0.0}]

addload -local triangular_pressure \
    [list 0.0 0.0 $p_zmin] [list 0.0 0.0 $p_zmax] \
    [list 0.0 0.0 $zmin] [list 0.0 0.0 $zmax]


# type: custom constraints name: line variable imposed displacement

# This example defines a line where the constraint applied
# (in this case, the imposed displac.), changes depending on 
# the position inside the line


set x1n1 [coords 1 1]
set x1n2 [coords 2 1]

set x [expr {0.5*($x1n1+$x1n2)}]

set k1 0.1
set ki [expr {$k1+$x}]
addconstraint fixed [list 0 1 0 0 0 0] [list 0.0 $ki 0.0 0.0 0.0 0.0]


# type: custom constraints name: line variable stiffness coef.

# This example defines a line where the constraint applied
# (in this case, the elastic stiffness coef.), changes depending on 
# the position inside the line


set x1n1 [coords 1 1]
set x1n2 [coords 2 1]

set x [expr {0.5*($x1n1+$x1n2)}]

if {$x > 0.5} {
    set k1 1.0e1
    set ki [expr {$k1*($x+0.2e1)/0.2e1}]
    addconstraint elastic [list 0 1 0 0 0 0] [list 0.0 $ki 0.0 0.0 0.0 0.0]
}




