Commands used in the .bas file

Single value return commands

When writing a command, it is generally not case-sensitive (unless explicitly mentioned), and even a mixture of uppercase and lowercase will not affect the results.

Note: Using this command without any argument will print all fields

Note: Using this command without any argument will print all fields

If the argument is 0, it returns the material's name.

Note: Using this command without any argument will print all fields

Caution: If there are materials with different numbers of fields, you must ensure not to print non-existent fields using conditionals.

Example:

*loop elements

*elemsnum *elemsmat *elemsmatprop(young)

*end elements

Note: Using this command without any argument will print all fields

*NodesNum : This returns the node's number.

*MatNum : This returns the material's number.

*ElemsMat : This returns the number of the material assigned to the element.

All of these commands must be within a proper loop (see *loop ) and change automatically for each iteration. They are considered as integers and cannot carry any argument. The number of materials will be reordered numerically, beginning with number 1 and increasing up to the number of materials assigned to any entity.

*LayerName : This returns the layer's name.

*LayerColorRGB : This returns the layer's color in RGB (three integer numbers between 0 and 256). If parameter (1), (2) or (3) is specified, the command returns only the value of one color. RED is 1, GREEN is 2 and BLUE is 3.

The commands *LayerName , *LayerNum and *LayerColorRGB must be inside a loop over layers; you cannot use these commands in a loop over nodes or elements.

Example:

*loop layers

*LayerName *LayerColorRGB

*Operation(LayerColorRGB(1)/255.0) *Operation(LayerColorRGB(2)/255.0) *Operation(LayerColorRGB(3)/255.0)

*end layers

*NodesLayerName : This returns the layer's name. It must be used in a loop over nodes.

*ElemsLayerNum : This returns the layer's number. It must be used in a loop over elems.

*ElemsLayerName : This returns the layer's name. It must be used in a loop over elems.

The valid C-functions that can be used are:

The following are valid examples of operations:

*operation(4*elemsnum+1)

*operation(8*(loopvar-1)+1)

Note: There cannot be blank spaces between the commands and the parentheses that include the parameters.

Note: Commands inside *operation do not need * at the beginning.

Example:

*set var t0=clock

*loop nodes

*nodescoord

*end nodes

*set var t1=clock

ellapsed time=*operation((t1-t0)/1000.0) seconds

Example:

*Units(LENGTH)

Example:

*BasicUnit(LENGTH)

Example:

*FactorUnit(PRESSURE)

Multiple values return commands

These commands return more than one value in a prescribed order, writing them one after the other. All of them except LocalAxesDef are able to return one single value when a numerical argument giving the order of the value is added to the command. In this way, these commands can appear within an expression. Neither LocalAxesDef nor the rest of the commands without the numerical argument can be used inside expressions. Below, a list of the commands with the appropriate description is displayed.

If *NodesCoord receives an integer argument (from 1 to 3) inside a loop of nodes, this argument indicates which coordinate must be written: x, y or z. Inside a loop of nodes:

*NodesCoord writes three or two coordinates depending on how many dimensions there are.

*NodesCoord(1) writes the x coordinate of the actual node of the loop.

*NodesCoord(2) writes the y coordinate of the actual node of the loop.

*NodesCoord(3) writes the z coordinate of the actual node of the loop.

If the argument real is given, the coordinates will be treated as real numbers.

Example: using *NodesCoord inside a loop of nodes

Coordinates:

Node X Y

*loop nodes

*format "%5i%14.5e%14.5e"

*NodesNum *NodesCoord(1,real) *NodesCoord(2,real)

*end nodes

This command effects a rundown of all the nodes in the mesh, listing their identifiers and coordinates (x and y ).

The contents of the project_name.dat file could be something like this:

Coordinates:

Node X Y

1 -1.28571e+001 -1.92931e+000

2 -1.15611e+001 -2.13549e+000

3 -1.26436e+001 -5.44919e-001

4 -1.06161e+001 -1.08545e+000

5 -1.12029e+001 9.22373e-002

...

*NodesCoord can also be used inside a loop of elements. In this case, it needs an additional argument that gives the local number of the node inside the element. After this argument it is also possible to give which coordinate has to be written: x, y or z.

Inside a loop of elements:

*NodesCoord(4) writes the coordinates of the 4th node of the actual element of the loop.

*NodesCoord(5,1) writes the x coordinate of the 5th node of the actual element of the loop.

*NodesCoord(5,2) writes the y coordinate of the 5th node of the actual element of the loop.

*NodesCoord(5,3) writes the z coordinate of the 5th node of the actual element of the loop.

If *ElemsConec receives an integer argument (begining from 1), this argument indicates which element connectity must be written:

*loop elems

all conectivities: *elemsconec

first conectivity *elemsconec(1)

*end elems

Note: In the first versions of GiD, the optional parameter of the last command explained was invert instead of swap, as it is now. It was changed due to technical reasons. If you have an old .bas file prior to this specification, which contains this command in its previous form, when you try to export the calculation file, you will be warned about this change of use. Be aware that the output file will not be created as you expect.

So, the local numeration of the faces is:

Triangle: 1-2 2-3 3-1

Quadrilateral: 1-2 2-3 3-4 4-1

Tetrahedra: 1-2-3 2-4-3 3-4-1 4-2-1

Hexahedra: 1-2-3-4 1-4-8-5 1-5-6-2 2-6-7-3 3-7-8-4 5-8-7-6

Prism: 1-2-3 1-4-5-2 2-5-6-3 3-6-4-1 4-5-6

Pyramid: 1-2-3-4 1-5-2 2-5-3 3-5-4 4-5-1

Example:

*loop elems

*ElemsNnode

*end elems

Example:

*loop elems

*ElemsNnodeFace

*end elems

Example:

*loop elems

*ElemsNnodeFaceCurt

*end elems

Note: This command is only available in GiD version 9 or later.

Note: This command is only available in GiD version 8.1.1b or later.

If *ElemsNormal receives an integer argument (from 1 to 3) this argument indicates which coordinate of the normal must be written: x, y or z.

Example:

*loop localaxes

*format "%10.4lg %10.4lg %10.4lg"

x'=*LocalAxesDef(1) *LocalAxesDef(4) *LocalAxesDef(7)

*format "%10.4lg %10.4lg %10.4lg"

y'=*LocalAxesDef(2) *LocalAxesDef(5) *LocalAxesDef(8)

*format "%10.4lg %10.4lg %10.4lg"

z'=*LocalAxesDef(3) *LocalAxesDef(6) *LocalAxesDef(9)

*end localaxes

Rotation of a vector expressed in terms of euler angles.

Example:

*LocalAxesDefCenter

*LocalAxesDefCenter(1) *LocalAxesDefCenter(2) *LocalAxesDefCenter(3)

Specific commands

Example:

*include includes\execntrlmi.h

Note: The *.bas extension cannot be used for the slave file to avoid multiple output files.

Example:

*MessageBox error: Quadrilateral elements are not permitted.

This window appears if the command MessageBox is executed.

Example:

WarningBox Warning: Exist Bad elements. A STL file is a collection of triangles bounding a volume.

The following commands must be written at the beginning of a line and the rest of the line will serve as their modifiers. No additional text should be written.

The variables that are available for *loop are the following:

After the command *loop:

- If the variable is elems or nodes, you can include one of the modifiers: *all , *OnlyInCond or *OnlyInLayer . The first one signifies that the iteration is going to be performed over all the entities; the *OnlyInCond modifier implies that the iteration will only take place over the entities that satisfy the relevant condition. This condition must have been previously defined with *set cond. *OnlyInLayer implies that the iteration will only take place over the entities that are in the specified layer; layers must be specified with the command *set Layer. By default, it is assumed that the iteration will affect all the entities.

- If the variable is material you can include the modifier *NotUsed to make a loop over those materials that are defined but not used.

- If the variable is conditions you must include one of the modifiers: *Nodes , *BodyElements , *FaceElements or *Layers , to do the loop on the conditions defined over this kind of mesh entity.

- If the variable is layers you can include modifiers: OnlyInCond if before was set a condition defined 'over layers'

Example 1:

*loop nodes

*format "%5i%14.5e%14.5e"

*NodesNum *NodesCoord(1,real) *NodesCoord(2,real)

*end node s

This command carries out a rundown of all the nodes of the mesh, listing their identifiers and coordinates (x and y coordinates).

Example 2:

*Set Cond Point-Weight *nodes

*loop nodes OnlyInCond

*NodesNum *cond(1)

*end

This carries out a rundown of all the nodes assigned the condition "Point-Weight" and provides a list of their identifiers and the first "weight" field of the condition in each case.

Example 3:

*Loop Elems

*ElemsNum *ElemsLayerNum

*End Elems

This carries out a rundown of all the elements and provides a list of their identifier and the identifier of the layer to which they belong.

Example 4:

*Loop Layers

*LayerNum *LayerName *LayerColorRGB

*End Layers

This carries out a rundown of all the layers and for each layer it lists its identifier and name.

Example 5:

*Loop Conditions OverFaceElements

*CondName

*Loop Elems OnlyInCond

*elemsnum *condelemface *cond

*End Elems

*End Conditions

This carries out a rundown of all conditions defined to be applied on the mesh 'over face elements', and for each condition it lists its name and for each element where this condition is applied are printed the element number, the marked face and the condition field values.

The following are valid examples of the use of the conditionals:

*if((fabs(loopvar)/4)<1.e+2)

*if((p3<p2)||p4)

*if((strcasecmp(cond(1),"XLoad")==0)&&(cond(2)!=0))

The first example is a numerical example where the condition is satisfied for the values of the loop under 400, while the other two are logical operators; in the first of these two, the condition is satisfied when p3<p2 or p4 is different from 0, and in the second, when the first field of the condition is called XLoad (with this particular writing) and the second is not null.

If the checked condition is true, GiD will write all the lines until it finds the corresponding *else, *elseif or *endif (*end is equivalent to *endif after *if). *else or *elseif are optional and require the writing of all the lines until the corresponding *endif, but only when the condition given by *if is false. If either *else or *elseif is present, it must be written between *if and *endif. The conditionals can be nested among them.

The behaviour of *elseif is identical to the behaviour of *else with the addition of a new condition:

*if(GenData(31,int)==1)

...(1)

*elseif(GenData(31,int)==2)

...(2)

*else

...(3)

*endif

In the previous example, the body of the first condition (written as 1) will be written to the data file if GenData(31,int) is 1, the body of the second condition (written as 2) will be written to the data file if GenData(31,int) is 2, and if neither of these is true, the body of the third condition (written as 3) will be written to the data file.Note: A conditional can also be written in the middle of a line. To do this, begin another line and write the conditional by means of the command *\ .

*for(varname=expr.1;varname<=expr.2;varname=varname+1)

*end for

The meaning of this statement is the execution of a controlled loop, since varname is equal to expr.1 until it is equal to expr.2, with the value increasing by 1 for each step. varname is any name and expr.1 and expr.2 are arithmetical expressions or numbers whose only restrictions are to express the range of the loop.

The command *break inside a *loop or *for block, will finish the execution of the loop and will continue after the *end line.

Example:

*for(i=1;i<=5;i=i+1)

variable i=*i

*end for

It is not necessary to write these commands in lowercase, so *Set will also be valid in all the examples.

*set cond. : In the case of the conditions, GiD allows the combination of a group of them via the use of *add cond. When a specific condition is about to be used, it must first be defined, and then this definition will be used until another is defined. If this feature is performed inside a loop over intervals, the corresponding entities will be chosen. Otherwise, the entities will be those referred to in the first interval.

It is done in this way because when you indicate to the program that a condition is going to be used, GiD creates a table that lets you know the number of entities over which this condition has been applied. It is necessary to specify whether the condition takes place over the *nodes , over the *elems or over *layers to create the table.

So, a first example to check the nodes where displacement constraints exist could be:

*Set Cond Volu-Cstrt *nodes

*Add Cond Surf-Cstrt *nodes

*Add Cond Line-Cstrt *nodes

*Add Cond Poin-Cstrt *nodes

These let you apply the conditions directly over any geometric entity.

*Set Layer "layer name" *elems|nodes

*Add Layer "layer name"

*Remove Layer "layer name"

This command sets a group of nodes. In the following loops over nodes/elements with the modifier *OnlyInLayer, the iterations will only take place over the nodes/elements of that group.

Example 1:

*set Layer example_layer_1 *elems

*loop elems *OnlyInLayer

Nº:*ElemsNum Name of Layer:*ElemsLayerName Nº of Layer :*ElemsLayerNum

*end elems

Example 2:

*loop layers

*set Layer *LayerName *elems

*loop elems *OnlyInLayer

Nº:*ElemsNum Name of Layer:*ElemsLayerName Nº of Layer :*ElemsLayerNum

*end elems

*end layers

In this example the command *LayerName is used to get the layer name.

There are some modifiers available to point out particular specifications of the conditions.

If the command *CanRepeat is added after *nodes or *elems in *Set cond , one entity can appear several times in the entities list. If the command *NoCanRepeat is used, entities will appear only once in the list. By default, *CanRepeat is off except where one condition has the *CanRepeat flag already set.

A typical case where you would not use *CanRepeat might be:

*Set Cond Line-Constraints *nodes

In this case, when two lines share one endpoint, instead of two nodes in the list, only one is written.

A typical situation where you would use *CanRepeat might be:

*Set Cond Line-Pressure *elems *CanRepeat

In this case, if one triangle of a quadrilateral has more than one face in the marked boundary then we want this element to appear several times in the elements list, once for each face.

Other modifiers are used to inform the program that there are nodes or elements that can satisfy a condition more than once (for instance, a node that belongs to a certain number of lines with different prescribed movements) and that have to appear unrepeated in the data input file, or, in the opposite case, that have to appear only if they satisfy more than one condition. These requirements are achieved with the commands *or(i,type) and *and(i,type) , respectively, after the input of the condition, where i is the number of the condition to be considered and type is the type of the variable (integer or real).

For the previous example there can be nodes or elements in the intersection of two lines or maybe belonging to different entities where the same condition had been applied. To avoid the repetition of these nodes or elements, GiD has the modifier *or, and in the case where two or more different values were applied over a node or element, GiD only would consider one, this value being different from zero. The reason for this can be easily understood by looking at the following example. Considering the previous commands transformed as:

*Set Cond Volu-Cstrt *nodes *or(1,int) *or(2,int)

*Add Cond Surf-Cstrt *nodes *or(1,int) *or(2,int)

*Add Cond Line-Cstrt *nodes *or(1,int) *or(2,int)

*Add Cond Poin-Cstrt *nodes *or(1,int) *or(2,int)

where *or(1,int) means the assignment of that node to the considered ones satisfying the condition if the integer value of the first condition's field is different from zero, and (*or(2,int) means the same assignment if the integer value of the second condition's field is different from zero). Let us imagine that a zero in the first field implies a restricted movement in the direction of the X-axis and a zero in the second field implies a restricted movement in the direction of the Y-axis. If a point belongs to an entity whose movement in the direction of the X-axis is constrained, but whose movement in the direction of the Y-axis is released and at the same time to an entity whose movement in the direction of the Y-axis is constrained, but whose movement in the direction of the X-axis is released, GiD will join both conditions at that point, appearing as a fixed point in both directions and as a node satisfying the four expressed conditions that would be counted only once.

The same considerations explained for adding conditions through the use of *add cond apply to elements, the only difference being that the command is *add elems. Moreover, it can sometimes be useful to remove sets of elements from the ones assigned to the specific conditions. This can be done with the command *remove elems. So, for instance, GiD allows combinations of the type:

*Set Cond Dummy *elems

*Set elems(All)

*Remove elems(Linear)

To indicate that all dummy elements apart from the linear ones will be considered, as well as:

*Set Cond Dummy *elems

*Set elems(Hexahedra)

*Add elems(Tetrahedra)

*Add elems(Quadrilateral)

*Add elems(Triangle)

The format for *set var differs from the syntax for the other two *set commands. Its syntax is as follows:

*Set var varname = expression

where varname is any name and expression is any arithmetical expression, number or command, where the latter must be written without * and must be defined as Int or Real.

A Tcl procedure can also be called, but it must return a numerical result.The following are valid examples for these assignments:

*Set var ko1=cond(1,real)

*Set var ko2=2

*Set var S1=CondNumEntities

*Set var p1=elemsnum()

*Set var b=operation(p1*2)

*tcl(proc MultiplyByTwo { x } { return [expr {$x*2}] })*\

*Set var a=tcl(MultiplyByTwo *p1)

The integer definition of *intformat and the real number definition of *realformat remain unchanged until another definition is provided via *intformat and *realformat, respectively. The argument of these two commands is composed of a unique field. This is the reason why the *intformat and *realformat commands are usually invoked in the initial stages of the .bas file, to set the format configuration of the integer or real numbers to be output during the rest of the process.

The *format command can include several field definitions in its argument, mixing integer and real definitions, but it will only affect the line that follows the command's instance one. Hence, the *format command is typically used when outputting a listing, to set a temporary configuration.

In the paragraphs that follow, there is an explanation of the C format specification, which refers to the field specifications to be included in the arguments of these commands. Keep in mind that the type of argument that the *format command expects may be composed of several fields, and the *intformat and *realformat commands' arguments are composed of an unique field, declared as integer and real, respectively, all inside double quotes:

A format specification, which consists of optional and required fields, has the following form: %[flags][width][.precision]type The start of a field is signaled by the percentage symbol (% ). Each field specification is composed of: some flags, the minimum width, a separator point, the level of precision of the field, and a letter which specifies the type of the data to be represented. The field type is the only one required.

The most common flags are:

- To left align the result

+ To prefix the numerical output with a sign (+ or -)

# To force the real output value to contain a decimal point.

The most usual representations are integers and floats. For integers the letters d and i are available, which force the data to be read as signed decimal integers, and u for unsigned decimal integers.

For floating point representation, there are the letters e, f and g, these being followed by a decimal point to separate the minimum width of the number from the figure giving the level of precision.The number of digits after the decimal point depends on the requested level of precision.

Note: The standard width specification never causes a value to be truncated. A special command exists in GiD: *SetFormatForceWidth, which enables this truncation to a prescribed number of digits.

For string representations, the letter s must be used. Characters are printed until the precision value is reached.

The following are valid examples of the use of format :

*Intformat "%5i"

With this sentence, usually located at the start of the file, the output of an integer quantity is forced to be right aligned on the fifth column of the text format on the right side. If the number of digits exceeds five, the representation of the number is not truncated.

*Realformat "%10.3e"

This sentence, which is also frequently located in the first lines of the template file, sets the output format for the real numbers as exponential with a minimum of ten digits, and three digits after the decimal point.

*format "%10i%10.3e%10i%15.6e"

This complex command will specify a multiple assignment of formats to some output columns. These columns are generated with the line command that will follow the format line. The subsequent lines will not use this format, and will follow the general settings of the template file or the general formats: *IntFormat, *RealFormat.

*SetFormatForceWidth is a special command that allows a figure to be truncated if the number of characters to print exceeds the specified width.

*SetFormatStandard changes to the default state, with truncation disabled.

For example:

*SetFormatForceWidth

*set var num=-31415.16789

*format "%8.3f"

*num

*SetFormatStandard

*format "%8.3f"

*num

Output:

-31415.1

-31415.168

The first number is truncated to 8 digits, but the second number, printed with "C" standard, has 3 numbers after the decimal point, but more than 8 digits.

Example: In this example the *Tcl command is used to call a Tcl function defined in the problem type .tcl file. That function can receive a variable value as its argument with *variable. It is also possible to assign the returned value to a variable, but the Tcl procedure must return a numerical value.

In the .bas file:

*set var num=1

*tcl(WriteSurfaceInfo *num)

*set var num2=tcl(MultiplyByTwo *num)

In the .tcl file:

proc WriteSurfaceInfo { num } {

return [GiD_Info list_entities surfaces $num]

}

proc MultiplyByTwo { x } {

return [expr {$x*2}]

}