Detailed example - Template file creation

Below is an example of how to create a Template file, step by step.

Note that this is a real file and as such has been written to be compatible with a particular solver program. This means that some or all of the commands used will be non-standard or incompatible with the solver that another user may be using.

The solver for which this example is written treats a line inside the calculation input file as a comment if it is prefixed by a $ sign. In the case of other solvers, another convention may apply.

Of course, the real aim of this example is familiarize you with the commands GiD uses. What follows is the universal method of accessing GiD's internal database, and then outputting the desired data to the solver.

It is assumed that files with the .bas extension will be created inside the working directory where the problem type file is located. The filename must be problem_type_name.bas for the first file and any other name for the additional .bas files. Each .bas file will be read by GiD and translated to a .dat file.

It is very important to remark that any word in the .bas file having no meaning as a GiD compilation command or not belonging to any command instructions (parameters), will be written verbatim to the output file.

First, we create the header that the solver needs in this particular case.

It consists of the name of the solver application and a brief description of its behaviour.

$-----------------------------------------------------

CALSEF: PROGRAM FOR STRUCTURAL ANALYSIS

What follows is a commented line with the ECHO ON command. This, when uncommented, is useful if you want to monitor the progress of the calculation. While this particular command may not be compatible with your solver, a similar one may exist.

$-----------------------------------------------------

$ ECHO ON

The next line specifies the type of calculation and the materials involved in the calculation; this is not a GiD related command either.

$-----------------------------------------------------

ESTATICO-LINEAL, EN SOLIDOS

As you can see, a commented line with dashes is used to separate the different parts of the file, thus improving the readability of the text.

The next stage involves the initialization of some variables. The solver needs this to start the calculation process.

The following assignments take the first (parameter (1)) and second (parameter (2)) fields in the general problem, as the number of problems and the title of the problem.

The actual position of a field is determined by checking its order in the problem file, so this process requires you to be precise.

Assignment of the first (1) field of the Problem data file, with the command *GenData(1):

$-----------------------------------------------------

$ NUMBER OF PROBLEMS: NPROB = *GenData(1)

$-----------------------------------------------------

Assignment of the second (2) field assignment, *GenData(2):

$ TITLE OF THE PROBLEM: TITULO= *GenData(2)

$-----------------------------------------------------

The next instruction states the field where the starting time is saved. In this case, it is at the 10th position of the general problem data file, but we will use another feature of the *GenData command, the parameter of the command will be the name of the field.

This method is preferable because if the list is shifted due to a field deing added or subtracted, you will not lose the actual position. This command accepts an abbreviation, as long as there is no conflict with any other field name.

$-----------------------------------------------------

$ TIME OF START: TIME= *GenData(Starting_time)

$-----------------------------------------------------

Here comes the initialization of some general variables relevant to the project in question - the number of points, the number of elements or the number of materials.

The first line is a description of the section.

$ DIMENSIONS OF THE PROBLEM:

The next line introduces the assignments.

DIMENSIONS :

This is followed by another line which features the three variables to be assigned. NPNOD gets, from the *npoin function, the number of nodes for the model; NELEM gets, from *nelem, either the total number of elements in the model or the number of elements for every kind of element; and NMATS is initialized with the number of materials:

NPNOD= *npoin, NELEM= *nelem, NMATS= *nmats, \

In the next line, NNODE gets the maximum number of nodes per element and NDIME gets the variable *ndime. This variable must be a number that specifies whether all the nodes are on the plane whose Z values are equal to 0 (NDIME=2), or if they are not (NDIME=3):

NNODE= *nnode, NDIME= *ndime, \

The following lines take data from the general data fields in the problem file. NCARG gets the number of charge cases, NGDLN the number of degrees of freedom, NPROP the properties number, and NGAUSS the gauss number; NTIPO is assigned dynamically:

NLOAD= *GenData(Load_Cases), *\

You could use NGDLN= *GenData(Degrees_Freedom), *\, but because the length of the argument will exceed one line, we have abbreviated its parameter (there is no conflict with other question names in this problem file) to simplify the command.

NGDLN= *GenData(Degrees_Fre), *\

NPROP= *GenData(Properties_Nbr), \

NGAUS= *GenData(Gauss_Nbr) , NTIPO= *\

Note that the last assignment is ended with the specific command *\ to avoid line feeding. This lets you include a conditional assignment of this variable, depending on the data in the General data problem.

Within the conditional a C format-like strcmp instruction is used. This instruction compares the two strings passed as a parameter, and returns an integer number which expresses the relationship between the two strings. If the result of this operation is equal to 0, the two strings are identical; if it is a positive integer, the first argument is greater than the second, and if it is a negative integer, the first argument is smaller than the second.

The script checks what problem type is declared in the general data file, and then it assigns the coded number for this type to the NTIPO variable:

*if(strcmp(GenData(Problem_Type),"Plane-stress")==0)

1 *\

*elseif(strcmp(GenData(Problem_Type),"Plane-strain")==0)

2 *\

*elseif(strcmp(GenData(Problem_Type),"Revol-Solid")==0)

3 *\

*elseif(strcmp(GenData(Problem_Type),"Solid")==0)

4 *\

*elseif(strcmp(GenData(Problem_Type),"Plates")==0)

5 *\

*elseif(strcmp(GenData(Problem_Type),"Revol-Shell")==0)

6 *\

*endif

You have to cover all the cases within the if sentences or end the commands with an elseif you do not want unpredictable results, like the next line raised to the place where the parameter will have to be:

$ Default Value:

*else

0*\

*endif

In our case this last rule has not been followed, though this can sometimes be useful, for example when the problem file has been modified or created by another user and the new specification may differ from the one we expect.

The next assignment is formed by a string compare conditional, to inform the solver about a configuration setting.

First is the output of the variable to be assigned.

, IWRIT= *\

Then there is a conditional where the string contained in the value of the Result_File field is compred with the string "Yes". If the result is 0, then the two strings are the same, while the output result 1 is used to declare a boolean TRUE.

*if(strcmp(GenData(Result_File),"Yes")==0)

1 ,*\

Then we compare the same value string with the string "No", to check the complementary option. If we find that the strings match, then we output a 0.

*elseif(strcmp(GenData(Result_File),"No")==0)

0 ,*\

*endif

The second to last assignment is a simple output of the solver field contents to the INDSO variable:

INDSO= *GenData(Solver) , *\

The last assignment is a little more complicated. It requires the creation of some internal values, with the aid of the *set cond command.

The first step is to set the conditions so we can access its parameters. This setting may serve for several loops or instructions, as long as the parameters needed for the other blocks of instructions are the same.

This line sets the condition Point-Constraints as an active condition. The *nodes modifier means that the condition will be listed over nodes. The *or(... modifiers are necessary when an entity shares some conditions because it belongs to two or more elements.

As an example, take a node which is part of two lines, and each of these lines has a different condition assigned to it. This node, a common point of the two lines, will have these two conditions in its list of properties. So declaring the *or modifiers, GiD will decide which condition to use, from the list of conditions of the entity.

A first instruction will be as follows, where the parameters of the *or commands are an integer - (1, and (3, in this example - and the specification int, which forces GiD to read the condition whose number position is the integer.

In our case, we find that the first (1) field of the condition file is the X-constraint, and the third (3) is the Y-constraint:

GiD still has no support for substituting the condition's position in the file by its corresponding label, in contrast to case for the fields in the problem data file, for which it is possible.

*Set Cond Surface-Constraints *nodes *or(1,int) *or(3,int)

Now we want to complete the setting of the loop, with the addition of new conditions.

*Add Cond Line-Constraints *nodes *or(1,int) *or(3,int)

*Add Cond Point-Constraints *nodes *or(1,int) *or(3,int)

Observe the order in which the conditions have been included: firstly, the surface constraints with the *Set Cond command, since it is the initial sentence; then the pair of *Add Cond sentences, the line constraints; and finally, the point constraints sentence. This logical hierarchy forces the points to be the most important items.

Last of all, we set a variable with the number of entities assigned to this particular condition.

Note that the execution of this instruction is only possible if a condition has been set previously.

NPRES= *CondNumEntities

To end this section, we put a separator in the output file:

$-----------------------------------------------------

Thus, after the initialization of these variables, this part of the file ends up as:

$ DIMENSIONS OF THE PROBLEM:

DIMENSIONES :

NPNOD= *npoin, NELEM= *nelem, NMATS= *nmats, \

NNODE= *nnode, NDIME= *ndime, \

NCARG= *GenData(Charge_Cases), *\

NGDLN= *GenData(Degrees_Fre), *\

NPROP= *GenData(Properties_Nbr), \

NGAUS= *GenData(Gauss_Nbr) , NTIPO= *\

*if(strcmp(GenData(Problem_Type),"Tens-Plana")==0)

1 *\

*elseif(strcmp(GenData(Problem_Type),"Def-Plana")==0)

2 *\

*elseif(strcmp(GenData(Problem_Type),"Sol-Revol")==0)

3 *\

*elseif(strcmp(GenData(Problem_Type),"Sol-Tridim")==0)

4 *\

*elseif(strcmp(GenData(Problem_Type),"Placas")==0)

5 *\

*elseif(strcmp(GenData(Problem_Type),"Laminas-Rev")==0)

6 *\

*endif

, IWRIT= *\

*if(strcmp(GenData(Result_File),"Yes")==0)

1 ,\

*elseif(strcmp(GenData(Result_File),"No")==0)

0 ,\

*endif

INDSO= *GenData(Solver) , *\

*Set Cond Surface-Constraints *nodes *or(1,int) *or(3,int)

*Add Cond Line-Constraints *nodes *or(1,int) *or(3,int)

*Add Cond Point-Constraints *nodes *or(1,int) *or(3,int)

NPRES=*CondNumEntities

$-----------------------------------------------------

After creating or reading our model, and once the mesh has been generated and the conditions applied, we can export the file (project_name.dat) and send it to the solver.

The command to create the .dat file can be found on the File -> Export -> Calculation File GiD menu. It is also possible to use the keyboard shortcut Ctrl-x Ctrl-c.

These would be the contents of the project_name.dat file:

$-----------------------------------------------------

CALSEF: PROGRAM FOR STRUCTURAL ANALYSIS

$-----------------------------------------------------

$ECHO ON

$-----------------------------------------------------

LINEAR-STATIC, SOLIDS

$-----------------------------------------------------

$NUMBER OF PROBLEMS:

NPROB = 1

$-----------------------------------------------------

$ PROBLEM TITLE

TITLE= Title_name

$-----------------------------------------------------

$DIMENSIONS OF THE PROBLEM

DIMENSIONS :

NPNOD= 116 , NELEM= 176 , NMATS= 0 , \

NNODE= 3 , NDIME= 2 , \

NCARG= 1 , NGDLN= 1 , NPROP= 5 , \

NGAUS= 1 , NTIPO= 1 , IWRIT= 1 , \

INDSO= 10 , NPRES= 0

$-----------------------------------------------------

This is where the calculation input begins.

A) Elements, materials and connectivities listing

Now we want to output the desired results to the output file. The first line should be a title or a label as this lets the solver know where a loop section begins and ends. The end of this block of instructions will be signalled by the line END_GEOMETRY.

GEOMETRY

The next two of lines give the user information about what types of commands follow.

Firstly, a title for the first subsection, ELEMENTAL CONNECTIVITIES:

$ ELEMENTAL CONNECTIVITIES

followed by a header that preceeds the output list:

$ ELEM. MATER. CONNECTIVITIES

The next part of the code concerns the elements of the model with the inclusion of the *loop instruction, followed in this case by the elems argument.

*loop elems

For each element in the model, GiD will output: its element number, by the action of the *elemsnum command, the material assigned to this element, using the *elemsmat command, and the connectivities associated to the element, with the *elemsConec command:

*elemsnum *elemsmat *elemsConec

*end elems

You can use the swap parameter if you are working with quadratic elements and if the listing mode of the nodes is non-hierarchical (by default, corner nodes are listed first and mid nodes afterwards):

*elemsnum *elemsmat *elemsConec(swap)

*end elems

B) Formatted nodes and coordinates listing

As with the previous section, this block of code begins with a title for the subsection:

$ NODAL COORDINATES

followed by the header of the output list:

$ NODE COORD.-X COORD.-Y COORD.-Z

Now GiD will trace all the nodes of the model:

*loop nodes

For each node in the model, GiD will generate and output its number, using *NodesNum, and its coordinates, using *NodesCoord.

The command executed before the output *format will force the resulting output to follow the guidelines of the specified formatting.

In this example below, the *format command gets a string parameter with a set of codes: %6i specifies that the first word in the list is coded as an integer and is printed six points from the left; the other three codes, all %15.5f, order the printing of a real number, represented in a floating point format, with a distance of 15 spaces between columns (the number will be shifted to have the last digit in the 15th position of the column) and the fractional part of the number will be represented with five digits.

Note that this is a C language format command.

*format "%6i%15.5f%15.5f%15.5f"

*NodesNum *NodesCoord

*end nodes

At the end of the section the end marker is added, which in this solver example is as follows:

END_GEOMETRY

The full set of commands to make this part of the output is shown in the following lines.

GEOMETRY

$ ELEMENT CONNECTIVITIES

$ ELEM. MATER. CONNECTIVITIES

*loop elems

*elemsnum *elemsmat *elemsConec

*end elems

$ NODAL COORDINATES

$ NODE COORD.-X COORD.-Y COORD.-Z

*loop nodes

*format "%6i%15.5f%15.5f%15.5f"

*NodesNum *NodesCoord

*end

END_GEOMETRY

The result of the compilation is output to a file (project_name.dat) to be processed by the solver program.

The first part of the section:

$-----------------------------------------------------

GEOMETRY

$ ELEMENT CONNECTIVITIES

$ ELEM. MATER. CONNECTIVITIES

1 1 73 89 83

2 1 39 57 52

3 1 17 27 26

4 5 1 3 5

5 5 3 10 8

6 2 57 73 67

. . . . .

. . . . .

. . . . .

176 5 41 38 24

And the second part of the section:

$ NODAL COORDINATES

$ NODE COORD.-X COORD.-Y COORD.-Z

1 5.55102 5.51020

2 5.55102 5.51020

3 4.60204 5.82993

4 4.60204 5.82993

5 4.88435 4.73016

6 4.88435 4.73016

. . .

. . .

. . .

116 -5.11565 3.79592

END_GEOMETRY

If the solver module you are using needs a list of the nodes that have been assigned a condition, for example, a neighborhood condition, you have to provide it as is explained in the next example.

C) Nodes listing declaration

First, we set the necessary conditions, as was done in the previous section.

*Set Cond Surface-Constraints *nodes *or(1,int) *or(3,int)

*Add Cond Line-Constraints *nodes *or(1,int) *or(3,int)

*Add Cond Point-Constraints *nodes *or(1,int) *or(3,int)

NPRES=*CondNumEntities

After the data initialization and declarations, the solver requires a list of nodes with boundary conditions and the fields that have been assigned.

In this example, all the selected nodes will be output and the 3 conditions will also be printed. The columns will be output with no apparent format.

Once again, the code begins with a subsection header for the solver program and a commentary line for the user:

BOUNDARY CONDITIONS

$ RESTRICTED NODES

Then comes the first line of the output list, the header:

$ NODE CODE PRESCRIPTED VALUES

The next part the loop instruction, in this case over nodes, and with the specification argument *OnlyInCond, to iterate only over the entities that have the condition assigned. This is the condition that has been set on the previous lines.

*loop nodes *OnlyInCond

The next line is the format command, followed by the lines with the commands to fill the fields of the list.

*format "%5i%1i%1i%f%f"

*NodesNum *cond(1,int) *cond(3,int) *\

The *format command influence also includes the following two if sentences. If the degrees of freedom field contains an integer equal or greater than 3, the number of properties will be output.

*if(GenData(Degrees_Freedom_Nodes,int)>=3)

*cond(5,int) *\

*endif

And if the value of the same field is equal to 5 the output will be a pair of zeros.

*if(GenData(Degrees_Free,int)==5)

0 0 *\

*endif

The next line ouputs the values contained in the second and fourth fields, both real numbers.

*cond(2,real) *cond(4,real) *\

In a similar manner to the previous if sentences, here are some lines of code which will output the sixth condition field value if the number of degrees of freedom is equal or greater than three, and will output a pair of zeros if it is equal to five.

*if(GenData(Degrees_Free,int)>=3)

*cond(6,real) *\

*endif

*if(GenData(Degrees_Free,int)==5)

0.0 0.0 *\

*endif

Finally, to end the section, the *end command closes the previous *loop. The last line is the label of the end of the section.

*end

END_BOUNDARY CONDITIONS

$-------------------------------------------------------

The full set of commands included in this section are as follows:

BOUNDARY CONDITIONS

$ RESTRICTED NODES

$ NODE CODE PRESCRIPTED VALUES

*loop nodes *OnlyInCond

*format "%5i%1i%1i%f%f"

*NodesNum *cond(1,int) *cond(3,int) *\

*if(GenData(Degrees_Free,int)>=3)

*cond(5,int) *\

*endif

*if(GenData(Degrees_Free,int)==5)

0 0 *\

*endif

*cond(2,real) *cond(4,real) *\

*if(GenData(Degrees_Free,int)>=3)

*cond(6,real) *\

*endif

*if(GenData(Degrees_Free,int)==5)

0.0 0.0 *\

*endif

*end

END_BOUNDARY CONDITIONS

$-----------------------------------------------------

D) Materials listing declaration

This section deals with outputting a materials listing.

As before, the first lines must be the title of the section and a commentary:

MATERIAL PROPERTIES

$ MATERIAL PROPERTIES FOR MULTILAMINATE

Next there is the loop sentence, this time concerning materials:

*loop materials

Then comes the line where the number of the material and its different properties are output:

*matnum() *MatProp(1) *MatProp(2) *MatProp(3) *MatProp(4)

Finally, the end of the section is signalled:

*end materials

END_MATERIAL PROPERTIES

$-----------------------------------------------------

The full set of commands is as follows:

MATERIAL PROPERTIES

$ MATERIAL PROPERTIES FOR MULTILAMINATE

*loop materials

*matnum() *MatProp(1) *MatProp(2) *MatProp(3) *MatProp(4)

*end materials

END_MATERIAL PROPERTIES

$-----------------------------------------------------

The next section deals wth generating an elements listing.

E) Elements listing declaration

First, we set the loop to the interval of the data.

*loop intervals

The next couple of lines indicate the starting of one section and the title of the example, taken from the first field in the interval data with an abbreviation on the label. They are followed by a comment explaining the type of data we are using.

LOADS

TITLE: *IntvData(Charge_case)

$ LOAD TYPE

We begin by setting the condition as before. If one condition is assigned twice or more to the same element without including the *CanRepeat parameter in the *Set Cond, the condition will appear once; if the *CanRepeat parameter is present then the number of conditions that will appear is the number of times it was assigned to the condition.

*Set Cond Face-Load *elems *CanRepeat

Then, a condition checks if any element exists in the condition.

*if(CondNumEntities(int)>0)

Next is a title for the next section, followed by a comment for the user.

DISTRIBUTED ON FACES

$ LOADS DISTRIBUTED ON ELEMENT FACES

We assign the number of nodes to a variable.

$ NUMBER OF NODES BY FACE NODGE = 2

$ LOADED FACES AND FORCE VALUES

*loop elems *OnlyInCond

ELEMENT=*elemsnum(), CONNECTIV *globalnodes

*cond(1) *cond(1) *cond(2) *cond(2)

*end elems

END_DISTRIBUTED ON FACES

*endif

The final section deals with outputting a list of the nodes and their conditions.

F) Nodes and its conditions listing declaration

As for previous sections, the first thing to do set the conditions.

*Set Cond Point-Load *nodes

As in the previous section, the next loop will only be executed if there is a condition in the selection.

*if(CondNumEntities(int)>0)

Here begins the loop over the nodes.

PUNCTUAL ON NODES

*loop nodes *OnlyInCond

*NodesNum *cond(1) *cond(2) *\

The next *if sentences determine the output writing of the end of the line.

*if(GenData(Degrees_Free,int)>=3)

*cond(3) *\

*endif

*if(GenData(Degrees_Free,int)==5)

0 0 *\

*endif

*end nodes

To end the section, once again you have to include the end label and the closing *endif.

END_PUNCTUAL ON NODES

*endif

Finally, a message is written if the value of the second field in the interval data section inside the problem file is equal to "si" (yes).

*if(strcasecmp(IntvData(2),"Si")==0)

SELF_WEIGHT

*endif

To signal the end of this part of the forces section, the following line is entered.

END_LOADS

Before the end of the section it remains to tell the solver what the postprocess file will be. This information is gathered from the *IntvData command. The argument that this command receives (3) specifies that the name of the file is in the third field of the loop iteration of the interval.

$-----------------------------------------------------

$POSTPROCESS FILE FEMV = *IntvData(3)

To end the forces interval loop the *end command is entered.

$-----------------------------------------------------

*end nodes

Finally, the complete file is ended with the sentence required by the solver.

END_CALSEF $-----------------------------------------------------

The preceding section is compiled completely into the following lines:

*Set Cond Point-Load *nodes

*if(CondNumEntities(int)>0)

PUNCTUAL ON NODES

*loop nodes *OnlyInCond

*NodesNum *cond(1) *cond(2) *\

*if(GenData(Degrees_Free,int)>=3)

*cond(3) *\

*endif

*if(GenData(Degrees_Free,int)==5)

0 0 *\

*endif

*end

END_PUNCTUAL ON NODES

*endif

*if(strcasecmp(IntvData(2),"Si")==0)

SELF_WEIGHT

*endif

END_LOADS

$-----------------------------------------------------

$POSTPROCESS FILE

FEMV = *IntvData(3)

$-----------------------------------------------------

*end nodes

END_CALSEF

$-----------------------------------------------------

This is the end of the template file example.