This functions are based on the implementation of a problemtype for the Frame3DD solver, but can be useful to anyone.
Basic and advanced tcl commands for writing the input file - example
How to write a string.
See how we print the units, we are asking gid for the current active units for the different magnitudes: F for Force, L for Lenght, M for Mass
customlib::WriteString "Input Data file for Frame3DD - 3D structural frame analysis ([gid_groups_conds::give_active_unit F],[gid_groups_conds::give_active_unit L],[gid_groups_conds::give_active_unit M])"
Nodes in the mesh
See how we get the number of nodes of the whole mesh. Also notice the way we are passing the writing format for the coordinates.
customlib::WriteString "" customlib::WriteString "[GiD_Info Mesh NumNodes] # number of nodes" customlib::WriteString "#.node x y z r" customlib::WriteString "# [gid_groups_conds::give_active_unit L] [gid_groups_conds::give_active_unit L] [gid_groups_conds::give_active_unit L] [gid_groups_conds::give_active_unit L]" customlib::WriteString "" customlib::WriteCoordinates "%5d %14.5e %14.5e %14.5e 0.0\n"
Elements assigned to the condition that assigns a material
set condition_name "frameData" set condition_formats [list {"%1d" "element" "id"} {"%13.5e" "property" "Ax"} {"%13.5e" "property" "Asy"} ... {"%13.5e" "material" "Density"}] set formats [customlib::GetElementsFormats $condition_name $condition_formats] set number_of_elements [GiD_WriteCalculationFile elements -count -elemtype Linear $formats] customlib::WriteConnectivities $condition_name $formats "" active
Contraints
This is the way we get the number of nodes assigned to a condition called 'constraints' in the spd.
set constraints_list [list "constraints"] set number_of_constraints [customlib::GetNumberOfNodes $constraints_list]
Basic data
This is the way we access to the data in the tree. Notice that we are building what we call xpath, that is a kind of path in the spd, from the root to the item we want.
Then we get the xml node from the document using selectNodes, and finaly we get the current value with get_domnode_attribute
set document [$::gid_groups_conds::doc documentElement] set xpath "/frame3dd_data/container\[@n = 'extraOptions' \]/value\[@n = 'shear_deformation' \]" set xml_node [$document selectNodes $xpath] set shear_deformation [get_domnode_attribute $xml_node v] customlib::WriteString "$shear_deformation # 1=Do, 0=Don't include shear deformation effects"
Single load case
This is the way we get the number of elements assigned to a condition, and then print the element id and the properties assigned to it.
set condition_name "line_Uniform_load"
set condition_name "line_Uniform_load" set condition_formats [list {"%1d" "element" "id"} {"%13.5e" "property" "Load_x"} {"%13.5e" "property" "Load_y"} {"%13.5e" "property" "Load_z"}] set formats [customlib::GetElementsFormats $condition_name $condition_formats] set number_of_elements [GiD_WriteCalculationFile elements -count -elemtype Linear $formats] customlib::WriteConnectivities $condition_name $formats "" active
Several load cases
For the several load case, we will need to iterate over the xml nodes corresponding to the blockdatas that define each load case.
For each load case, we need to print all the loads information, so we need to know if a load has any group assigned.
If so, we'll need to know how many elements are involved, and print them with the properties of the load.
set xpath "/frame3dd_data/container\[@n = 'staticCases' \]/blockdata" set xml_nodes [$document selectNodes $xpath] foreach load_case $xml_nodes { set xpath "./condition\[@n = 'uniformLoad' \]/group" set groups [$load_case selectNodes $xpath] set number_of_elements 0 set formats_dict [dict create ] foreach group $groups { set group_name [get_domnode_attribute $group n] set Ux_node [$group selectNodes "./value\[@n = 'Ux'\]"] set Ux_value [get_domnode_attribute $Ux_node v] set Uy_node [$group selectNodes "./value\[@n = 'Uy'\]"] set Uy_value [get_domnode_attribute $Uy_node v] set Uz_node [$group selectNodes "./value\[@n = 'Uz'\]"] set Uz_value [get_domnode_attribute $Uz_node v] set format "%5d $Ux_value $Uy_value $Uz_value" set formats_dict [dict merge $formats_dict [dict create $group_name $format]] } set number_of_elements [GiD_WriteCalculationFile elements -count -elemtype Linear $formats_dict] if {$number_of_elements > 0} { GiD_WriteCalculationFile elements -elemtype Linear $formats_dict } }
Alternatives
In this section, we will write the coordinates, connectivites, and conditions assuming that the input can be different, such as the one in Matfem . In some codes, like matfem, the input file into the solver is not written in a text file, but in a "code like file". The coordinates section in the matfem solver is a matlab array, with a single comma splitting x and y (x, y) and a semicolon spliting a node from another (x1, y1; x2, y2; ...)
Write coordinates:
Example:% % Coordinates % global coordinates coordinates = [ 0.00 , 0.00; 0.50 , 0.00; 2.50 , 1.00 ];
Code:customlib::WriteString "%" customlib::WriteString "% Coordinates" customlib::WriteString "%" customlib::WriteString "global coordinates" set nodes [GiD_Mesh list node] customlib::WriteString "coordinates = \[" for {set i 0} {$i < [llength $nodes]} {incr i} { set node [lindex $nodes $i] lassign [GiD_Mesh get node $node coordinates] x y z if {$i < [expr [llength $nodes] -1] } {set end ";"} {set end ""} customlib::WriteString "$x , $y $end" } customlib::WriteString "\] ; "
Write elements:
Example:% % Elements % global elements elements = [ 1, 2, 7 ; 2, 3, 8 ; 18, 17, 12 ];
Code:customlib::WriteString "%" customlib::WriteString "% Elements" customlib::WriteString "%" customlib::WriteString "global elements" set elements_t [GiD_Mesh list -element_type Triangle element] set elements_q [GiD_Mesh list -element_type Quadrilateral element] customlib::WriteString "elements = \[" for {set i 0} {$i < [llength $elements_t] } {incr i} { set element [lindex $elements_t $i] lassign [GiD_Mesh get element $element connectivities] c1 c2 c3 if {$i < [expr [llength $elements_t] -1] } {set end ";"} {set end ""} customlib::WriteString "$c1 , $c2 , $c3 $end" } for {set i 0} {$i < [llength $elements_q] } {incr i} { set element [lindex $elements_q $i] lassign [GiD_Mesh get element $element connectivities] c1 c2 c3 c4 if {$i < [expr [llength $elements_q] -1] } {set end ";"} {set end ""} customlib::WriteString "$c1 , $c2 , $c3 , $c4 $end" } customlib::WriteString "\] ; "
Conditions
Example:% % Point loads % pointload = [ 6, 2, -1.0 ; 12, 2, -1.0 ; 18, 2, -1.0 ];
Code:
spd<condition n="PuntualLoads" pn="Load" ov="point" ovm="node" icon="moad"> <value n="x-force" pn="Force X" v="0.0" units="N" unit_magnitude="F" /> <value n="y-force" pn="Force Y" v="0.0" units="N" unit_magnitude="F" /> </condition>
tcl
# Point load customlib::WriteString "" customlib::WriteString "%" customlib::WriteString "% Point loads" customlib::WriteString "%" customlib::WriteString "pointload = \[" set displacement_fix_nodes [$root selectNodes "*/condition\[@n='PuntualLoads'\]/group"] foreach node $displacement_fix_nodes { set group [$node @n] set val_x [get_domnode_attribute [$node selectNodes "./value\[@n='x-force'\]"] v] set val_y [get_domnode_attribute [$node selectNodes "./value\[@n='y-force'\]"] v] set fix_x [expr $val_x == 0.0 ? "false" : "true"] set fix_y [expr $val_y == 0.0 ? "false" : "true"] set nodes [GiD_EntitiesGroups get $group nodes] set num_nodes [objarray length $nodes] for {set i 0} {$i < $num_nodes} {incr i} { set node_id [objarray get $nodes $i] if {$i < [expr $num_nodes -1] } {set end ";"} {set end ""} if {$fix_x eq "true" && $fix_y eq "true"} {set end ";" } if {$fix_x eq "true"} { customlib::WriteString "$node_id , 1 , $val_x $end" } if {$i < [expr $num_nodes -1] } {set end ";"} {set end ""} if {$fix_y eq "true"} { customlib::WriteString "$node_id , 2 , $val_y $end" } } } customlib::WriteString "\] ; "