Versions Compared

Key

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

Special Tcl commands>Print>File
GiD_File fopen|fclose|fprintf|fflush|list
To allow print data from a Tcl procedure with standard fprintf command, specially to write the calculation file from Tcl or a mix of .bas template and Tcl procedures

    • GiD_File fopen <filename> ?<access>?

Open a file named <filename> for writting access. By default access is "w", but is possible to use "a" to append to a previous file (and "wb" or "ab" to open the file in binary mode). It returns a long integer <file_id> representing the channel

    • GiD_File fclose <file_id>

Close a channel

    • GiD_File fprintf -nonewline <file_id> <format> ?<arg>? ... ?<arg>?

Print data from a Tcl procedure in a file opened with GiD_File fopen and returns the number of printed characters.
(a .bas template implictly open/close a file with this command, and the file_id could be send to a tcl procedure as a parameter with the *FileId template keyword)
<file_id> must be a valid file descriptor, that could be obtained in a .bas template with the *FileId command (or with GiD_File fopen)
<format> must be a valid C/C++ format, according with the arguments
return

    • GiD_File fflush <file_id>

Force unwritten buffered data to be written to the file

    • GiD_File list

It returns a list of currently open file_ids
Example:
.bas file:
Number of points and lines: *tcl(MyMethod *FileId)
.tcl file:
proc MyMethod { channel } {
GiD_File fprintf -nonewline $channel {%d %d} [GiD_Info Geometry NumPoints] [GiD_Info Geometry NumLines]
}
Special Tcl commands>Print>WriteCalculationFile
GiD_WriteCalculationFile
The command called GiD_WriteCalculationFile facilitate the creation of the output calculation file.
See also Writing the input file for calculation
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.

...

  • 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 and 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.

...

  • 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>

...

    • -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.
    • <groupsDict> is a dictionary (list of pairs key value), with key=group_name and value=format

...