The command called GiD_WriteCalculationFile facilitate the creation of the output calculation file.

Note: This command is provided to allow efficiency and relative flexibility writing the mesh and tree data related to groups, traversing the data structures without the cost of create a serialized copy in memory.

It is not compulsory to use this command, it is possible, and sometimes necesary, to use other Tcl commands to get mesh, groups and other data and reorder the information in order to be written.

GiD_WriteCalculationFile init|end|puts|coordinates|all_connectivities|connectivities|nodes|elements|has_elements ?-elemtype <etype>? ?-localaxes <formatLADict> ""? ?-elements_faces all|elements|faces? ?-number_ranges <NRDict>? ?-unique? ?-multiple? ?-all_entities? ?-do_subst? ?-sorted? ?-count? ?-return? ?-print_faces_conecs ? -connec_ordering? corner_face_corner_face <groupsDict>

  • GiD_WriteCalculationFile init ?-mode append? ?-encoding external|utf-8? <filename>

To open for writting the calculation file.

Before to print any information to the file it must be opened with this command. Next prints of GiD_WriteCalculationFile will use implicilty this opened channel.

GiD internal strings are utf-8 codified,

-encoding external : (default) strings to print are converted to the current external encoding.

-encoding utf-8: strings are not converted.

It returns an file identifier that could be used with with 'GiD_File fprintf', but must not be used with Tcl standard print commands like 'puts' or 'write'

Example:

set file_id [GiD_WriteCalculationFile init -mode append {c:/temp/my output.dat}]

lassign {1.5 2.3} x y

GiD_File fprintf $file_id "x=%15.5f y=%15.5f" $x $y

  • GiD_WriteCalculationFile end

To close the calculation file

Example:

GiD_WriteCalculationFile end

  • GiD_WriteCalculationFile puts ?-nonewline? <string>

Print the string in the calculation file and a carriage return

  • -nonewline avoid the carriage return.

Example:

GiD_WriteCalculationFile puts "hello world"

  • GiD_WriteCalculationFile coordinates ?-count? ?-return? ?-factor <factor>? <format>

This command must be used to print all nodes of the mesh. It prints <num> <x> <y> <z> for each node.

<format> must be a "C-like" format for an integer an three doubles.

Are only printed the values with supplied format, e.g. if the format is "%d %f" only the node number and its x will be printed.

If a %.0s is specified then the corresponding value is not printed (trick to avoid print some values)

  • If -count is specified then only return the number of entities, without print.
  • If -return is specified then return the string, without print.
  • If -factor <factor> is set the the coordinates will be scaled by the <factor> (that must be a real number, 1.0 by default). It is used aid to write the mesh based on the declared mesh unit and the current reference length unit.

Example:

set num_coordinates [GiD_WriteCalculationFile coordinates -count ""] ;#with -count the format doesn't matter, "" could be used

GiD_WriteCalculationFile puts "num coordinates: $num_coordinates"

set unit_origin [gid_groups_conds::give_mesh_unit]

set unit_destination [gid_groups_conds::give_active_unit L]

set mesh_factor [gid_groups_conds::convert_unit_value L 1.0 m mm]

GiD_WriteCalculationFile coordinates -factor $mesh_factor "%d %g %g %g"

  • GiD_WriteCalculationFile all_connectivities ?-elemtype <etype>? ?-count? ?-return? ?-connec_ordering corners_faces|corner_face_corner_face? <format>

This command must be used to print all elements of the mesh. It prints the element number and its connectivities for each element of type <etype> of the mesh (all types if -elemtype is not set)

<format> must be an integer for the element id and as much integers as connectivities to be printed.

  • <etype> can be: Linear|Triangle|Quadrilateral|Tetrahedra|Hexahedra|Prism|Point|Pyramid|Sphere|Circle
  • If -count is specified then only return the number of entities, without print.
  • If -return is specified then return the complete string, without print.
  • for quadratic elements the order of nodes could be specified with -connec_ordering corners_faces|corner_face_corner_face

by default the order is corners_faces (first are printed the corners and then the quadratic nodes)

Example:

GiD_WriteCalculationFile all_connectivities -elemtype Triangle "id: %d connectivities: %d %d %d"

  • GiD_WriteCalculationFile connectivities|nodes|elements|has_elements ?-elemtype <etype>? ?-localaxes <groupsLADict>? ?-elements_faces all | elements | faces? ?-number_ranges <NRDict>? ?-count? ?-unique? ?-error_if_repeated? ?-multiple? ?-all_entities? ?-print_faces_conecs? ?-sorted? ?-do_subst? ?-connec_ordering? ?-return? <groupsDict>

To get entities information related to groups: connectivities, nodes, elements of the group names specified in the dictionary

<groupsDict> is a dictionary (list of pairs key value), with key=group_name and value=format

for connectivities it prints the element number and its connectivities

for nodes it prints the node number and optionally (if the provided format expect it) its x y z real coordinates

for elements it prints the element number (for element faces prints element numer and face number, element from 1, face from 0)

  • -elemtype <etype> can be: Linear|Triangle|Quadrilateral|Tetrahedra|Hexahedra|Prism|Point|Pyramid|Sphere|Circle
  • -localaxes can be set in order to write local coordinate axes, where <formatLADict> is a dictionary (list of pairs key-value), with key equal to LA_name and value equal to a format, which could be for instance {%d[euler_angles matrix/matrixT "%g%g%g%g%g%g%g%g%g"]}. The euler_angles is a function and matrix or matrixT its argument in order to remark that its rotation matrix or its transposed matrix should be written. A format equal to "" should be specified at the end of the GiD_WriteCalculationFile function. The EAmat function permits to have more control about the rotation matrix related to the euler angles using for instance the format {%d[EAmat 1 1][EAmat 2 1][EAmat 3 1][EAmat 1 2][EAmat 2 2][EAmat 3 2][EAmat 1 3][EAmat 2 3][EAmat 3 3]} to write the directions of the local coordinate systems. The three angles giving the rotation matrix are called Euler angles.

A -do_subst flag should be required in order to replace the previous formulas in the GiD_WriteCalculationFile.

<groupsLADict> is a dictionary (list of pairs key value) of local axes, with key=LA_name and value=format

  • -elements_faces can be set to specify any type (all), body elements (elements) or face elements (faces). Therefore, it considers element connectivities or face elements connectivities.
  • -unique can be set to specify that each entity should be written once.
  • -multiple can be used in order to consider a list of variables containing a dictionary value (list of pairs key value). It is known that "dict set dictionary key value" command takes the name of a variable containing a dictionary value and places an updated dictionary value in that variable, containing a mapping from the given key to the given value. It should be noted that when multiple keys are present, this operation creates or updates a chain of nested dictionaries and the GiD_WriteCalculationFile function requires -multiple flag.
  • -all_entities can be set to specify that all entities should be considered.
  • -do_subst can be set to replace formulas.
  • -number_ranges can be set to print the list of entities, in case of consecutive ids, with a compressed notation n_start:n_end (meaning n_start,n_start+1,..., n_end) group entities using a groups dictionary.

<NRDict> is a dictionary with key the format associated to a group name in <groupsDict> and value another format with and extra integer, typically the first format prefixed by "%d:"

  • -sorted can be set to apply a string ordering.
  • -print_faces_conecs can be set to print face element connectivities. A -elements_faces of face elements should be specified when a -print_faces_conecs is used.
  • -connec_ordering can be set to specify a connectivities ordering as corner-middle edge-corner (corner_face_corner_face), default is first all corner nodes (corners_faces)
  • If -count is specified then only the number of entities is returned, without print.
  • If -return is specified then the complete string is returned, without print.

Example: to print the id and connectivities of the triangle elements of the groups named $group_a or $group_b

set format_by_group [dict create $group_a "A: %d - %d %d %d" $group_b "B: %d - %d %d %d"]

GiD_WriteCalculationFile connectivities -elemtype Triangle $format_by_group

Example: to print the node id of the nodes belonging to $group_name and a text with the group name

set format_by_group [dict create $group_name "%d of group $group_name"]

GiD_WriteCalculationFile nodes $format_by_group

or to print also its x y z coordinates:

set format_by_group [dict create $group_name "%d of group $group_name with coordinates %g %g %g"]

GiD_WriteCalculationFile nodes $format_by_group

or as a trick to avoid printing the z coordinate could use "%.0s" to jump this extra argument

set format_by_group [dict create $group_name "%d of group $group_name with coordinates %g %g %.0s"]

GiD_WriteCalculationFile nodes $format_by_group

Functions to convert between different unit types

There are a couple of functions that are essential when writing the input file for the calculation. These functions permit the treatment of the units, and facilitates the conversion from one measurement to another. They are the following:

  • gid_groups_conds::give_mesh_unit

This function provides the mesh unit.

  • gid_groups_conds::set_mesh_unit unit

This function imposes a mesh unit, where the argument is as follows:

unit - A text string, denoting the unit that you want to apply as mesh unit.

  • gid_groups_conds::convert_value_to nodeObject to_unit

This function converts the value of a nodeObject from the current unit for the original number to another unit, where the arguments are as follows:

nodeObject - DOM node object chosen.

to_unit - A text string, denoting the unit that you want to convert the original number to.

  • gid_groups_conds::convert_value_to_active nodeObject

This function converts the value of a nodeObject from the current unit type to the general active unit selected in the GUI. The argument is as follows:

nodeObject - DOM node object chosen.

  • gid_groups_conds::convert_unit_value magnitude value unit_from to_unit

This function converts a number from one unit type to another unit type, for the same magnitude. It receives as arguments:

magnitude - Unit definition, it is the name 'n' of the physical quantity (eg. "L" for Length)

value - The number to be converted.

unit_from - A text string, denoting the unit for the original number.

to_unit - A text string, denoting the unit that you want to convert the original number to.

  • gid_groups_conds::convert_value_to_printable_unit nodeObject

This function returns a text string, denoting the current unit of the node. It receives as argument:

nodeObject - DOM node object chosen.

  • gid_groups_conds::give_unit_factor magnitude unit

This function returns the conversion factor for the unit given. The arguments are as follows:

magnitude - Unit definition, it is the name 'n' of the physical quantity (eg. "L" for Length)

unit - A text string, denoting the unit chosen to obtain the conversion factor.

  • gid_groups_conds::convert_v_to_default value magnitude unit_from

This function converts a number from one unit type to the unit type by default, for the same magnitude. It receives as arguments:

value - The number to be converted.

magnitude - Unit definition, it is the name 'n' of the physical quantity (eg. "L" for Length)

unit_from - A text string, denoting the unit for the original number.

  • gid_groups_conds::give_active_units_system

This function returns a string list, where the first item is the units system.

  • gid_groups_conds::give_active_unit magnitude

This function returns the active unit for a given magnitude. It receives as argument:

magnitude - Unit definition, it is the name 'n' of the physical quantity (eg. "L" for Length)