Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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 GiD for the current active units for the different magnitudes: F for Force, L for LenghtLength, M for Mass

Code Block
languagetcl
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.

Code Block
languagetcl
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

Code Block
set condition_name "frameData"

...


# If we want this output format "element_id connectivity_x connectivity_y connectivity_z"
set condition_formats [list {"%5d" "element" "id"} {"%5d" "element" "connectivities"}]
# If we want this output format with element id and properties
set condition_formats [list {"%1d" "element" "id"} {"%13.5e" "property" "Ax"} {"%13.5e" "property" "Asy"} ... {"%13.5e" "material" "Density"}]

...


# To get the number of elements
set formats [customlib::GetElementsFormats $condition_name $condition_formats]

...


set number_of_elements [GiD_WriteCalculationFile elements -count -elemtype Linear $formats]

...


# To write the connectivities
customlib::WriteConnectivities $condition_name

...

 $condition_formats "" active
  • Contraints

    Constraints

This is the way we get the number of nodes assigned to a condition called 'constraints' in the spd.

Code Block
languagetcl
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 finally we get the current value with get_domnode_attribute.

Code Block
languagetcl
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"

Code Block
languagetcl
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.

Code Block
languagetcl
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 splitting a node from another (x1, y1; x2, y2; ...)

  • Write coordinates:
    Example:

    Code Block
    languagematlab
    %
    % Coordinates
    %
    global coordinates
    coordinates = [
      0.00 , 0.00;
      0.50 , 0.00;
      2.50 , 1.00  ];


    Code:

    Code Block
    languagetcl
        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:

    Code Block
    languagematlab
    %
    % Elements
    %
    global elements
    elements = [
        1,   2,   7 ;
        2,   3,   8 ;
       18,  17,  12 ];


    Code:

    Code Block
    languagetcl
        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:

    Code Block
    languagematlab
    %
    % Point loads
    %
    pointload = [
    6, 2, -1.0 ;
    12, 2, -1.0 ;
    18, 2, -1.0 ];


    Code:
    spd

    Code Block
    languagexml
    <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

Code Block
languagetcl
# Point load
    set root [customlib::GetBaseRoot]
    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 "\] ; "