GiD - The personal pre and post processor

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 necessary, to use other Tcl commands to get mesh, groups and other data and reorder the information in order to be written.

Note: To print mesh nodes or elements by layers it exists other specialized command: GiD_EntitiesLayers print <layer> nodes|elements ?-element_type <types_allowed>? ?-offset_element_num <offset>? ?-factor <factor>? <format> <channel>


GiD_WriteCalculationFile init|end|puts|coordinates|all_connectivities|connectivities|nodes|elements|has_elements

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

To open for writing 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 implicitly 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.e
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 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 then 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? ?-factor <factor>?<groupsDict>


To get entities information related to groups: connectivities, nodes, elements of the group names specified in the <groupsDict> dictionary
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. If -factor <factor> is provided the coordinates are multiplied by this real number (used for units)
for elements it prints the element number (for element faces prints element number 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.
    • <groupsDict> is a dictionary (list of pairs key value), with key=group_name and value=format

if key is "" then is considered like a wildcard and match all entities that are not matched by other keys.

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


Example: to print the element id of the triangle elements belonging to $group_name

GiD_WriteCalculationFile elements -elemtype Triangle [dict create $group_name "element id:%d node ids:%d %d %d\n"]



Example: to print the faces of tetrahedra belonging to $group_name, printing its 3 face node ids (the %.0s is to not print the tetrahedra id)

GiD_WriteCalculationFile elements -elemtype Tetrahedra -elements_faces faces -print_faces_conecs [dict create $group_name "%.0snode ids: %d %d %d\n"]


Example: to print the faces of tetrahedra belonging to $group_name, printing the tetrahedra id and the local face index (0 to 4)

GiD_WriteCalculationFile elements -elemtype Tetrahedra -elements_faces faces [dict create $group_name "element id:%d face index:%d\n"]


Example: to print node id and the local axes (as 3 euler angles) of the nodes belonging to $group_name that have local axis assigned.

GiD_WriteCalculationFile nodes -return -localaxes [dict create $group_name "%d Euler1=%.15g Euler2=%.15g Euler3=%.15g\n"] {}


COPYRIGHT © 2022 · GID · CIMNE