7/29/2019 Advanced Problemtype Creation
1/50
GiD Course 2010: AdvancedProblemtype creation
7/29/2019 Advanced Problemtype Creation
2/50
Table of Contents
ii
Chapters Pag.
1 Advanced Problemtype creation 1
1.1 Introduction 1
1.1.1 Interaction of GiD with the calculating module 1
1.1.2 Basic or Toolkit 3
1.2 Implementation using basic integration scheme 4
1.2.1 Creating the General File 4
1.2.2 Creating the Materials File 5
1.2.3 Creating the Conditions File 6
1.2.4 Creating the Data Format File (Template file) 7
1.2.5 Creating the Execution file of the Calculating Module 121.2.6 Creating the Execution File for the Problem Type 13
1.3 Implementation using advanced integration toolkit 14
1.3.1 Word Reference in spd document 15
1.3.2 Units 17
1.3.3 Materials 18
1.3.4 Conditions 19
1.3.5 Procs 21
1.3.6 Others 23
1.3.7 Data Format File 24
1.4 Extensions, example with CompasLIB 29
1.5 Using the problemtype with an example 33
1.5.1 Executing the calculation with a concentrated weight 36
1.6 Aditional information 38
1.6.1 The main program 38
7/29/2019 Advanced Problemtype Creation
3/50
1 Advanced Problemtype creation
1
This tutorial takes you through the steps involved in defining a problem type using GiD. A problem type
is a set of files configured by a solver developer so that the program can prepare data to be analyzed.
A simple example has been chosen which takes us through all the associated configuration files while
using few lines of code. Particular emphasis is given to the calculation of the centers of mass for
two-dimensional surfaces ? a simple formulation both conceptually and numerically.
By the end of the example, you should be able to create a calculating module that will interpret the mesh
generated in GiD Preprocess. The module will calculate values for each element of the mesh and store
the values in a file in such a way as they can be read by GiD Post-process.
1.1 Introduction
Our aim is to solve a problem that involves calculating the center of gravity (center of mass) of a 2D
object. To do this, we need to develop a calculating module that can interact with GiD.
The problem: calculate the center of mass.
The center of mass (XCM,YCM) of a two-dimensional body is defined as
where (x,y) is the density of the material at point (x,y) and S is the surface of the body; mi are
concentrated masses applied on the point (xi,yi).
To solve the problem numerically, the integrals will be transformed into sums:
Each of the N elements is treated as concentrated weight whose mass is defined as the product of the
(surface) density and the area of the element.
1.1.1 Interaction of GiD with the calculating module
GiD Preprocess makes a discretization of the object under study and generates a mesh of elements,
each one of which is assigned a material and some conditions. This preprocessing information in GiD
(mesh, materials, and conditions) enables the calculating module to generate results. For the present
example, the calculating module will find the distance of each element relative to the center of mass ofthe object.
Finally, the results generated by the calculating module will be read and visualized in GiD Post-process.
7/29/2019 Advanced Problemtype Creation
4/50
2 GiD Course 2010: Advanced Problemtype creation
Diagram of the workflow
GiD must adapt these data to deal with them. Materials, boundary and/or load conditions, and general
problem data must be defined.
The calculating module (in this example cmas2d.exe) solves the equations in the problem and saves theresults in the results file. This module may be programmed in the language of your choice, 'C' in used in
this example
GiD Post-process reads the following files generated by the calculating module:
project_name.post.res: results file.
Each element of the mesh corresponds to a value.
project_name.post.msh: file containing the post-process mesh. If this file does not exist, GiD uses the
preprocess mesh also for postprocess.
7/29/2019 Advanced Problemtype Creation
5/50
3Interaction of GiD with the calculating module
Diagram depicting the files system
1.1.2 Basic or Toolkit
Basic Integration
Every GiD user can develop a customized preprocess module within a short time, even without any
knowledge in programming languages.
Only a couple of text files should be written describing the user's problem properties (like conditions or
materials) using an easy keyword system and GiD will create automatically the corresponding windows,
with this keyword system which is described in the GiD documentation, all the information required for a
particular problem type can be specified:
Conditions parameters and dependencies
Material properties
General data and interval data
Symbols to draw conditions nicely
Definition of used unit system
Other configuration parameters (version, icons, password)
Format of the analysis file needed by the simulation executable
Batch file to launch the calculation and, eventually, previous necessary operating GiD will create
automatically windows like the shown ones allowing the end user to manage the data of the problem,
assign or modify conditions, draw properties over model, etc. in a really easy way.
After the definition of the problem, GiD will write all the conditions, materials and mesh information using
the previously specified format.
7/29/2019 Advanced Problemtype Creation
6/50
4 GiD Course 2010: Advanced Problemtype creation
CompassLIB toolkit
This toolkit is developed by Compass IS, and offers an alternative to the classical process of simulations
integration in GiD.
The description of the properties and data needed by the analysis problem is performed using a XMLtree (graphical part) and a Tcl file which access all the nodal and elemental information during the
writing process of the analysis file. Due to the complexity of these file, a minimum of knowledge in
programming languages is required.
Tcl is the scripting language used in GiD. On the other hand, this method offers a lot more possibilities,
including an appealing view of the managed data, not only to the developer but also to the final user.
With this toolkit, the problem and group data are always displayed during preprocess, on the left side of
the graphical window.
This facilities the management of the analysis properties to the end users.
Groups are defined by their mesh elements or geometry entities, and they can be created and edited in
an easy way with help of a groups edition window.
1.2 Implementation using basic integration scheme
Using the Basic Problemtypes scheme
GiD configuration is accomplished through text formatted files. The following files are required:
.prb: configuration of the general parameter (not associated to entities)
.mat: configuration of materials and their properties
.cnd: configuration of the conditions imposed on the calculation
.bas: (template file) the file for configuring the format of the interchange file that mediates between GiD
data and the calculating module. The file for interchanging the data exported by GiD has the extension
.dat. This file stores the geometric and physical data of the problem.
.bat: the file that can be executed called from GiD. This file initiates the calculating module.
Creating the Subdirectory for the Problem Type
Create the subdirectory "cmas2d.gid". This subdirectory has a .gid extension and will contain all the
configuration files and calculating module files (.prb, .mat, .cnd, .bas, .bat, .exe).
NOTE: If you want the problem type to appear in the GiD Data?Problem type menu, create the
subdirectory within "problemtypes", located in the GiD folder ? for instance,
C:\GiD\Problemtypes\cmas2d.gid
1.2.1 Creating the General File
Create the "cmas2d.prb" file. This file contains general information for the calculating module, such as
the units system for the problem, or the type of resolution algorithm chosen.
Enter the parameters of the general conditions in "cmas2d.prb" using the following format:
PROBLEM DATA
7/29/2019 Advanced Problemtype Creation
7/50
5Creating the General File
QUESTION: Name of the parameter. If the name is followed by the #CB# instruction, the parameter is
displayed as a combo box. The options in the menu must then be entered between parentheses and
separated by commas.
For example, Unit_System#CB#(SI,CGS,User).
VALUE: The default value of the parameter.
END GENERAL DATA
In GiD, the information in the "cmas2d.prb" file is managed in the problem data window, which is located
in Data?Problem Data.
The GiD Problem Data window, for configuring of
the general conditions of the cmas2d module
PROBLEM DATA
QUESTION: Unit_System#CB#(SI,CGS,User)
VALUE: SI
QUESTION: Title
VALUE: Default_title
END GENERAL DATA
1.2.2 Creating the Materials File
Create the materials file "cmas2d.mat". This file stores the physical properties of the material under
study for the problem type. In this case, defining the density will be enough.
Enter the materials in the "cmas2d.mat" file using the following format:
MATERIAL: Name of the material (without spaces)
QUESTION: Property of the material. For this example, we are interested in the density of the material.
VALUE: Value of the property
HELP: A help text (optional field)
END MATERIAL
In GiD, the information in "cmas2d.mat" file is managed in the materials window, located in
Data->Materials.
7/29/2019 Advanced Problemtype Creation
8/50
6 GiD Course 2010: Advanced Problemtype creation
The GiD Materials window, for assigning materials
MATERIAL: Air
QUESTION: Density
VALUE: 1.01
HELP: material density
END MATERIAL
MATERIAL: Steel
QUESTION: Density
VALUE: 7850
HELP: material density
END MATERIAL
MATERIAL: Aluminium
QUESTION: Density
VALUE: 2650
HELP: material density
END MATERIAL
1.2.3 Creating the Conditions File
Create the "cmas2d.cnd" file, which specifies the boundary and/or load conditions of the problem type in
question. In the present case, this file is where the concentrated weights on specific points of the
geometry are indicated.
Enter the boundary conditions using the following format:
CONDITION: Name of the condition
CONDTYPE: Type of entity which the condition is to be applied to. This includes the parameters "over
points", "over lines", "over surfaces", "over volumes or "over layers". In this example the condition is
applied "over points.
CONDMESHTYPE: Type of entity of the mesh where the condition is to be applied. The possible
parameters are "over nodes", "over body elements" or "over face elements. In this example, the
condition is applied on nodes.
QUESTION: Name of the parameter of the condition
VALUE: Default value of the parameter
7/29/2019 Advanced Problemtype Creation
9/50
7Creating the Conditions File
END CONDITION
In GiD, the information in the "cmas2d.cnd" file is managed in the conditions window, which is found in
Data? Conditions.
The GiD Conditions window, for assigning the
cmas2d boundary and load conditions
CONDITION: Point-Weight
CONDTYPE: over points
CONDMESHTYPE: over nodes
QUESTION: Weight
VALUE: 0.0
HELP: Concentrated mass
END CONDITION
1.2.4 Creating the Data Format File (Template file)
Create the "cmas2d.bas" file. This file will define the format of the .dat text file created by GiD. It will
store the geometric and physical data of the problem. The .dat file will be the input to the calculating
module.
NOTE: It is not necessary to have all the information registered in only one .bas file. Each .bas file has acorresponding .dat file.
Write the "cmas2d.bas" file as follows:
The format of the .bas file is based on commands. Text not preceded by an asterisk is reproduced
exactly the same in the .dat file created by GiD. A text preceded by an asterisk is interpreted as a
command.
Example:
.bas file .dat file
7/29/2019 Advanced Problemtype Creation
10/50
8 GiD Course 2010: Advanced Problemtype creation
%%%%
Problem
Size %%%%
Number of
Elements &
Nodes:
*nelem
*npoin
? %%%% Problem Size
%%%%
Number of Elements &
Nodes:
5379 4678
The contents of the "cmas2d.bas" file must be the following:
.bas file
==================================================================
General Data File
==================================================================
Title: *GenData(Title)
%%%%%%%%%%%%%%%%%% Problem Size %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Number of Elements & Nodes:
*nelem *npoin
In this first part of "cmas2d.bas" file, general information on the project is obtained.
*nelem: returns the total number of elements of the mesh.
*npoin: returns the total number of nodes of the mesh.
Coordinates:
Node X Y
*loop nodes
*format "%5i%14.5e%14.5e"
*NodesNum *NodesCoord(1,real) *NodesCoord(2,real)
*end nodes
This command provides a rundown of all the nodes of the mesh, listing their identifiers and coordinates.
*loop, *end: commands used to indicate the beginning and the end of the loop. The command
*loop receives a parameter.
*loop nodes: the loop iterates on nodes
*loop elems: the loop iterates on elements
*loop materials: the loop iterates on assigned materials
*format: the command to define the printing format. This command must be followed by a numerical
format expressed in C syntax.
7/29/2019 Advanced Problemtype Creation
11/50
9Creating the Data Format File (Template file)
*NodesNum: returns the identifier of the present node
*NodesCoord: returns the coordinates of the present node
*NodesCoord (n, real): returns the x, y or z coordinate in terms of the value n:
n=1 returns the x coordinate
n=2 returns the y coordinate
n=3 returns the z coordinate
Connectivities:
Element Node(1) Node(2) Node(3) Material
*set elems(all)
*loop elems
*format "%10i%10i%10i%10i%10i"
*ElemsNum *ElemsConec *ElemsMat
*end elems
This provides a rundown of all the elements of the mesh and a list of their identifiers, the nodes that form
them, and their assigned material.
*set elems(all): the command to include all element types of the mesh when making the loop.
*ElemsNum: returns the identifier of the present element
*ElemsConec: returns the nodes of an element in a counterclockwise order
*ElemsMat: returns the number of the assigned material of the present element
Begin Materials
N Materials= *nmats
This gives the total number of materials in the project
*nmats: returns the total number of materials
Mat. Density
*loop materials
*format "%4i%13.5e"
*set var PROP1(real)=Operation(MatProp(Density, real))
*MatNum *PROP1
*end
This provides a rundown of all the materials in the project and a list of the identifiers and densities for
each one.
*MatProp (density, real): returns the value of the property "density" of the material in a "real" format.
7/29/2019 Advanced Problemtype Creation
12/50
10 GiD Course 2010: Advanced Problemtype creation
*Operation (expression): returns the result of an arithmetic expression. This operation must be
expressed in C.
*Set var PROP1(real)=Operation(MatProp(Density, real)): assigns the value returned by MatProp
(which is the value of the density of the material) to the variable PROP1 (a "real" variable).
*PROP1: returns the value of the variable PROP1.
*MatNum: returns the identifier of the present material.
Point conditions
*Set Cond Point-Weight *nodes
*set var NFIX(int)=CondNumEntities(int)
Concentrate Weights
*NFIX
This provides the number of entities with a particular condition.
*Set Cond Point-Weight *nodes: this command enables you to select the condition to work with from
that moment on. For the present example, select the condition "Point-Weight".
*CondNumEntities(int): returns the number of entities with a certain condition.
*Set var NFIX(int)= CondNumEntities(int): assigns the value returned by the command
CondNumEntities to the NFIX variable (an "int" variable).
*NFIX: returns the value of the NFIX variable.
Potentials Prescrits:
Node Tipus
Valor/Etiqueta
*loop nodes *OnlyInCond
*NodesNum *cond(1)
*end
This provides a rundown of all the nodes with the condition "Point-Weight" with a list of their identifiers
and the first "weight" field of the condition in each case.
*loop nodes *OnlyInCond: executes a loop that will provide a rundown of only the nodes with this
condition.
*cond(1): returns the number 1 field of a condition previously selected with the *set cond command. The
field of the condition may also be selected using the name of the condition, for example cond(weight).
cmas2d.bas
==================================================================
7/29/2019 Advanced Problemtype Creation
13/50
11Creating the Data Format File (Template file)
General Data File
==================================================================
%%%%%%%%%%%%%%%%%% Problem Size
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Number of Elements & Nodes:
*nelem *npoin
%%%%%%%%%%%%%%%%%%% Mesh Database
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Coordinates:
Node X Y
*set elems(all)
*loop nodes
*format "%5i%14.5e%14.5e"
*NodesNum *NodesCoord(1,real) *NodesCoord(2,real)
*end nodes
.................................................................
Connectivities:
Element Node(1) Node(2) Node(3) Material
*loop elems
*format "%10i%10i%10i%10i%10i"
*ElemsNum *ElemsConec *ElemsMat
*end elems
.................................................................
Begin Materials
N Materials= *nmats
Mat. Density
.................................................................
*loop materials
*format "%4i%13.5e"
*set var PROP1(real)=Operation(MatProp(Density, real))
*MatNum *PROP1
*end
.................................................................
Point conditions
7/29/2019 Advanced Problemtype Creation
14/50
12 GiD Course 2010: Advanced Problemtype creation
*Set Cond Point-Weight *nodes
*set var NFIX(int)=CondNumEntities(int)
Concentrated Weights
*NFIX
.................................................................
Potentials Prescrits:
Node Tipus
Valor/Etiqueta
*Set Cond Point-Weight *nodes
*loop nodes *OnlyInCond
*NodesNum *cond(1)
*end
.................................................................
1.2.5 Creating the Execution file of the Calculating Module
Create the file "cmas2d.c". This file contains the code for the execution program of the calculating
module. This execution program reads the problem data provided by GiD, calculates the coordinates of
the center of mass of the object and the distance between each element and this point. These results
are saved in a text file with the extension .post.res.
Compile and link the "cmas2d.c" file in order to obtain the executable cmas2d.exe file.
The calculating module (cmas2d.exe) reads and generates the files described below.
cmas2d.c solver structure
7/29/2019 Advanced Problemtype Creation
15/50
13Creating the Execution file of the Calculating Module
NOTE: The "cmas2d.c" code is explained in the appendix.
1.2.6 Creating the Execution File for the Problem Type
Create the "cmas2d.win.bat" file. This file connects the data file(s) (.dat) to the calculating module (the
cmas2d.exe program). When the GiD Calculate option is selected, it executes the .bat file for the
problem type selected.
When GiD executes the .bat file, it transfers three parameters in the following way:
(parameter 3) / *.bat (parameter 2) / (parameter 1)
parameter 1: project name
parameter 2: project directory
parameter 3: Problem type location directory
NOTE: The .win.bat fiile as used in Windows is explained below; the shell script for UNIX systems is
also included with the documentation of this tutorial.
rem OutputFile: %2\%1.log
A comment line such as "rem OutputFile: file_name.log" means that the contents of the file indicated will
be shown if the user clicks Output View in Calculate?Calculate window.
In this example the .log file is shown. This file contains the coordinates of the center of mass.
The Process window.
rem ErrorFile: %2\%1.err
A comment line such as "rem ErrorFile: file_name.err" means that the indicated file will contain the
errors (if any). If the .err file is present at the end of the execution, a window comes up showing the
error. The absence of the .err file indicates that the calculation is considered satisfactory.
GiD automatically deletes the .err files before initiating a calculation to avoid confusion.
del %2\%1.log
del %2\%1.post.res
7/29/2019 Advanced Problemtype Creation
16/50
14 GiD Course 2010: Advanced Problemtype creation
This deletes results files from any previous calculations to avoid confusion.
%3\cmas2d.exe %2\%1
This executing the cmas2d.exe and provide the .dat as input file file.
1.3 Implementation using advanced integration toolkit
The new Problem Type structure
Introduction
In order to add conditions, general data, or units information to the problemtype, it is necessary to
modify file {PROBLEMTYPE}_default.spd. This is a file in XML format. This file contains all the
definition of all the data necessary for the analysis.
A description of the file follows:
The XML tree below contains the definition of all the data (except the geometry), necessary for a
computer simulation analysis. It contains all the data that must be filled by the user in order to perform
the analysis
Main conventions
We call 'field' to the 'Element name' in TDOM terminology and parameter to the 'attribute' in TDOM
terminology. All data is contained in fields and parameters and there is no data as text leaf of a element.
All parameters that must contain a list of values, like the 'ov' or 'values' fields, contain a comma
separated list of these values. It must be taken care that no one of the individual values can contain a
comma in its name
All parameters can contain a literal value or: {xpath expression} or [TCL command]. In the first case, an
Xpath search is performed in the tree and the result is substituted in the parameter when necessary. In
the second case, the TCL command between brackets is executed when necessary and the return
value is replaced inside the parameter. Typically, the TCL procs defined with the field 'proc' are used.
Example:
7/29/2019 Advanced Problemtype Creation
17/50
15Implementation using advanced integration toolkit
set problemtypes [split [$domNode selectNodes string(@pt)] ,]
set pt [$domNode selectNodes {string(/*/blockdata[@n='general_data']/
container[@n='problem']/value[@n='problemtype']/@v)}]
if { $pt eq "" } { error "error: pt cannot be void" }
if { [lsearch -exact $problemtypes $pt] != -1 } {
return normal
} else { return hidden }
]]>
Starting the file
We start with a definition of the spd, it will be writte on utf-8
Then a tag of problem type name its open and will
be finished at the end of the file with
Then we define the group types that our problem type uses, basically there are 2 types and defining this
2 types almost all problem types will work
normal group of entities without any condition applied
Boundary Condition group of entities with a condition over points, lines, surface or volumens
1.3.1 Word Reference in spd document
Here you can find the definition of all tags and parameters of the spd file
Description of the main fields
blockdata: Represents a set of properties with some kind of relationship. It contains several
'values' fields with the actual data. It can also contain other 'blockdata' and 'condition' fields If it has
the 'sequence' parameter activated, it is possible for the user to create consecutive repetitions of the
full block data in order to represent, for example, loadcases with all its conditions inside.
7/29/2019 Advanced Problemtype Creation
18/50
16 GiD Course 2010: Advanced Problemtype creation
condition: It contains values and it can be applied to groups. For every applied group, a dependent
set of values will be created that belong to that group for this condition.
container: Is is a simple way for grouping data for better visualization
value: The main unit to store data. One or several of them are contained inside any of the
previous field.dependencies: When one 'value' changes its value, the 'dependencies' permmit to force a change in
other values.
value: It allows to define a condition to execute a dependencie.
att, atti, i=1,2: Indicates to which attributes of a node affect a change in one value.
v,vi, i=1,2: Indicates the new value for atti, i=1,2. It can be normal, hidden or disabled.
default: Default value for the condition. It permmits to execute a dependencie.
condition: Allows to define the condition in order to execute a dependencie. .
actualize: Permits to actualize the specified field.
check: Boolean value that permits the user changes the data tree showed information,
depending on the dependencie value specified.
proc: Permits to define a TCL proc. The code will recieve an implicit argument with name 'domNode'
that represents the TDOM node in the calling field context.
units_system: All the units can belong to one of the units systems or not specify it, that means that
the unit belongs to any of them. All units used in a problem must belong to the same unit system
unit_magnitude: Every magnitude that can contain several units
units: every unit inside a magnitude
factor: It is the factor that permmits: 1 unit=factor*unit(SI) example: 1mm=10e-3 m
Every property that needs it, contains its magnitude and units. Example:
Description of main parameters
n: Name used to reference the field, especially when writing the .dat file
pn: Label that will be visualized by the user (can be translated)
dict: name-show name pairs that affect current leaf of the tree and that can be translated
values: Finite number of values that the user can apply to the property
editable: Boolean value that permits or not to the user to edit the property
v: The value or default value for a 'value' field
help: Permits to create a popup help for the fields
state: Can be: normal or disabled. It permmits to define a Tcl function.
active: Can be 0 or 1
sequence: Permits a 'blockdata' field to by duplicated and copied by the user in order to create
several sets of something. Like several loadcases with its 'value' and 'condition' included
sequence_type: For blockdata. Can be:
any The list can be void (this is the default)
non_void_disabled At least there needs to be one element. It can be disabled.
non_void_deactivated At least there needs to be one element. It can be deactivated.editable_name: can be '' or 'unique'. Unique means that it is not possible to use the same name ('pn'
field), for two different 'sequence' 'blockdata'
7/29/2019 Advanced Problemtype Creation
19/50
17Word Reference in spd document
is_value: This is a simplification for 'condition' fields that should have a unique 'value' field inside with
the same name. If this flag is set to '1', it is not necessary to define the 'value' field but works as if it
were defined
ov, ovi, i=1,2: Indicates to which entity types can a 'condition' be applied. Can be one or several of:
point,line,surface,surface_as_volume,volume.ov_default: Indicates the default entity type which a 'condition' can be applied.
ovm, ovmi, i=1,2: Indicates to which entity can a 'condition' be applied. It can be element, node, face
element or void.
function: Contains a Tcl command, which is executed when is called. It permmits to create or edit a
function for a determined field.
function_func: Permits to define a TCL function.
edit_command: Permits to call a TCL proc when necessary.
icon: Permits to put an image in the conditions menu.
fieldtype: Permits to introduce a text. It can be
longtext: A text box is created.
actualize_tree: Allows to actualize all the input dates in data tree.
actualize: Permits to actualize a specified field in data tree.
1.3.2 Units
There is an initial units definition section that include all the relevant units for the problem.
7/29/2019 Advanced Problemtype Creation
20/50
18 GiD Course 2010: Advanced Problemtype creation
1.3.3 Materials
Let's define Materials that we need in our problem type
Remmember that with basic integration we have put
MATERIAL: Air
QUESTION: Density
VALUE: 1.01
HELP: material density
END MATERIAL
Now in xml scheme we are going to use the following
blockdata: Represents a set of properties with some kind of relationship. It contains several 'values'
fields with the actual data. It can also contain other 'blockdata' and 'condition' fields If it has the
'sequence' parameter activated, it is possible for the user to create consecutive repetitions of the full
block data in order to represent, for example, loadcases with all its conditions inside.
value: The main unit to store data. One or several of them are contained inside any of the previous
field.
Repite the same blockdata for the other two materials, changing only the name and the v parameters
Finally, just for visual appeal, we are going to put all materials inside a container called 'Materials'
7/29/2019 Advanced Problemtype Creation
21/50
19Materials
So finally all the definition of Materials states like this:
container: Is is a simple way for grouping data for better visualization
1.3.4 Conditions
Until now we have just defined a "data base" of material
Now we are going to enable the application of a material to a surface, and after meshing this condition
will be applied over mesh elements
To do this we need the following
7/29/2019 Advanced Problemtype Creation
22/50
20 GiD Course 2010: Advanced Problemtype creation
proc='edit_database_list'/>
condition: It contains values and it can be applied to groups. For every applied group, a dependent set
of values will be created that belong to that group for this condition.
edit_command: Permits to call a TCL proc when necessary.
Here there are 2 tcl procs involved, the first one "give_materials_list" to get a complet list of the
materials defined
and the second "edit_database_list" to modify the material base directly by the user while using the
problem type
In Procs part we will see them.
We want to create another condition that will be aplied over geometric points and consequently over
mesh nodes called "Point Weight"
This is even much easy
Finally for organization propouse, we are going to create a Properties container that will contain the
Shell Condition and also all material database
So Finally our spd file will look
[Units part]
[Point Weight Condition]
[Shell Condition]
[Materals Database]
7/29/2019 Advanced Problemtype Creation
23/50
21Conditions
1.3.5 Procs
As we have seen when user wants to applie a shell there is an execution to a tcl function
[give_material_list] here you will find the code that is executed
this functions, give a list of a database also the function to edit a database is given and we think that
them could be really useful to develop a problem type, just coping them you can have this functionality,
but any functionality is possible by programing it with tcl
7/29/2019 Advanced Problemtype Creation
24/50
22 GiD Course 2010: Advanced Problemtype creation
]]>
7/29/2019 Advanced Problemtype Creation
25/50
23Procs
]]>
1.3.6 Others
Other info, transaltion, frame width and Internal data it's posible
Don't forget to close the file with
7/29/2019 Advanced Problemtype Creation
26/50
24 GiD Course 2010: Advanced Problemtype creation
1.3.7 Data Format File
With this example you will see that writte the data format file with CompassLIB is really similar to with
basic sheme, just compare the to versions, and you will see that with write_calc_data function you can
acces to the same information so is just a matter of give to the calculate mode what it needs
Here all write_calc_data possibilities:
write_calc_data
init|end|puts|coordinates|all_connectivities|connectivities|nodes|elements|has_elements
?-elemtype ? ?-localaxes ""? ?-elements_faces all|elements|faces?
?-number_ranges ? ?-unique? ?-multiple? ?-all_entities? ?-do_subst? ?-sorted?
?-count? ?-return? ?-print_faces_conecs ? -connec_ordering? corner_face_corner_face
init To open the calculation fileend To close the calculation file
puts ?-nonewline? Print the string in the calculation file.
-nonewline avoid the carriage return.
coordinates ?-count? ?-return? Print for each
node of the mesh. If a %.0s is specified then the corresponding value is not
printed. Format must be a "C-like" format for an integer an three doubles.
If -count is specified then only return the number of entities, without print.
If -return is specified then return the string, without print.
all_connectivities ?-elemtype ? ?-count? ?-return? Print the
element number and its connectivities for each element of type of the mesh (all
types if -elemtype is not set)
can
be:Linear|Triangle|Quadrilateral|Tetrahedra|Hexahedra|Prism|OnlyPoints|Pyramid|Sphere
If -count is specified then only return the number of entities, without print.
If -return is specified then return the complete string, without print.
connectivities|nodes|elements|has_elements To get entities information related to groups:
connectivities, nodes ,elements, of if exists some element of the specified group
can be: Linear| Triangle| Quadrilateral| Tetrahedra| Hexahedra| Prism|
OnlyPoints| Pyramid| Sphere
A -localaxes can be set in order to write local coordinate axes, where
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 write_calc_data 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 31][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
7/29/2019 Advanced Problemtype Creation
27/50
25Data Format File
order to replace the previous formulas in the write_calc_data.
A-elements_faces can be set to specify any type, body elements (elements) or
face elements ( faces). Therefore, it considers element connectivities or face
elements connectivities.
A -unique can be set to specify that each entity should be written once.A -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 write_calc_data function requires
-multiple flag.
A -all_entities can be set to specify that all entities should be considered.
A -do_subst can be set to replace formulas.
A -number_ranges can be set to group entities using a groups dictionary.
is a dictionary of number of ranges
A -sorted can be set to apply a string ordering.
A -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.
A -connec_ordering can be set to specify a connectivities ordering as corner-middle
edge-corner (corner_face_corner_face).
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.
Here the file scripts/b_writecalcfile.tcl
package require ncgi
namespace eval b_write_calc_file {
variable doc
}
proc b_write_calc_file::writeCalcFile { _doc file } {
variable doc
set doc $_doc
set root [$doc documentElement]
write_calc_data init $file
write_ouptut_file $root
write_calc_data end
}
# proc b_write_calc_file::get_value { name } {
# variable doc
7/29/2019 Advanced Problemtype Creation
28/50
26 GiD Course 2010: Advanced Problemtype creation
#
# set node [$doc selectNodes [format_xpath {//value[@n=%s]} $name]]
# return [get_domnode_attribute $node v]
# }
################################################################################
# CODE TO PRINT THE OUTPUT FILE (OLD .BAS)
################################################################################
proc b_write_calc_file::write_ouptut_file { root } {
write_calc_data puts -nonewline
"=================================================================="
write_calc_data puts -nonewline " General Data File"
write_calc_data puts -nonewline "
=================================================================="
write_calc_data puts -nonewline " %%%%%%%%%%%%%%%%%% Problem Size
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
write_calc_data puts -nonewline " Number of Elements & Nodes:"
write_calc_data puts -nonewline " [GiD_Info Mesh NumElements] [GiD_Info
Mesh NumNodes]"
write_calc_data puts -nonewline " %%%%%%%%%%%%%%%%%%% Mesh Database
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
#################### COORDINATES ############################
write_calc_data puts -nonewline " Coordinates:"
write_calc_data puts -nonewline " Node X Y"
# Geometry factor (here the geometry unit selected by the user is
converted to 'cm')
set units_length [gid_groups_conds::give_active_unit L]
set xp [format_xpath {/*/units/unit_magnitude[@n="L"]/unit[@n=%s]} "m"]
set node [gid_groups_conds::give_node_xpath $xp]
set L_geom_fac [get_domnode_attribute $node factor]
# We call C functions from the COMPASSLIB to print everything related
with nodes or elements
write_calc_data coordinates -factor $L_geom_fac " %5d %14.5E %14.5E%.0s"
#################### CONNECTIVITIES ############################
write_calc_data puts -nonewline "
7/29/2019 Advanced Problemtype Creation
29/50
27Data Format File
................................................................."
write_calc_data puts -nonewline " Connectivities:"
write_calc_data puts -nonewline " Element Node(1) Node(2) Node(3)
Material"
set xp1 {container[@n="Properties"]/condition[@n="Shells"]/group}
set xp2 ".//value\[@n='Material']"
# We will save a TCL dictionary with the information from our materials
set mat_dict ""
set material_number 0
set formats ""
foreach gNode [$root selectNodes $xp1] {
set valueNode [$gNode selectNodes $xp2]
set material_name [get_domnode_attribute $valueNode v]
if { ![dict exists $mat_dict $material_name] } {
incr material_number
set mid $material_number
#We also save the density of the material by checking the material
database
set xp3 {/*/container[@n="Properties"]/container[@n="materials"]//}
append xp3 [format_xpath {blockdata[@n="Material" and
@name=%s]/value[@n="Density"]} $material_name]
set valueNode [$root selectNodes $xp3]
# All the introduced values are translated to 'm' and 'kg' with the help
of this function
set density [gid_groups_conds::convert_value_to_default $valueNode]
dict set mat_dict $material_name MID $material_number
dict set mat_dict $material_name DENSITY [format "%13.5E" $density]
} else {
set mid [dict get $mat_dict $material_name MID]
}
set f { %10d %10d %10d %10d [format "%10d" $mid]}
set f [subst $f]
dict set formats [$gNode @n] $f
}
7/29/2019 Advanced Problemtype Creation
30/50
28 GiD Course 2010: Advanced Problemtype creation
if {$material_number=="0"} {
error [= "Remember to define your surface/s as shell/s"]
}
if {[write_calc_data has_elements -elemtype "Triangle" $formats]} {
write_calc_data connectivities -do_subst -elemtype "Triangle" $formats
} else {
error [= "Only Triangle elements are allowed in this version of the
problemtype"]
}
#################### MATERIALS ############################
write_calc_data puts -nonewline "
................................................................."
write_calc_data puts -nonewline " Begin Materials"
write_calc_data puts -nonewline " N Materials= $material_number"
write_calc_data puts -nonewline " Mat. Density"
write_calc_data puts -nonewline "
................................................................."
# We print all the material data directly from the saved dictionary
foreach material [dict keys $mat_dict] {
write_calc_data puts -nonewline " [format "%4d" [dict get $mat_dict
$material MID]] [dict get $mat_dict $material DENSITY]"
}
#################### CONCENTRATE WEIGHTS ############################
write_calc_data puts -nonewline "
................................................................."
write_calc_data puts -nonewline " Point Conditions"
set xp1 {condition[@n="Point_Weight"]/group}
set xp2 {.//value[@n="Weight"]}
set formats ""
foreach gNode [$root selectNodes $xp1] {
set valueNode [$gNode selectNodes $xp2]
set weight [gid_groups_conds::convert_value_to_default $valueNode]
set f { %d [format "%13.5E" $weight]}
set f [subst $f]
7/29/2019 Advanced Problemtype Creation
31/50
29Data Format File
dict set formats [$gNode @n] $f
}
write_calc_data puts -nonewline " Concentrate Weights"
write_calc_data puts -nonewline " [write_calc_data nodes -count
$formats]"
write_calc_data puts -nonewline "
................................................................."
write_calc_data puts -nonewline " Potencials Prescrits:"
write_calc_data puts -nonewline " Node Tipus"
write_calc_data puts -nonewline " Valor/Etiqueta"
write_calc_data nodes -do_subst $formats
write_calc_data puts -nonewline "
................................................................."
}
1.4 Extensions, example with CompasLIB
Here is when some programing level in tcl is needed, when you are doing a problem type with
CompassLIB you need to include the file problem_type_name.tcl in our case
cmas2d_CompassLIB.tcl you only need to remplace "cmas2d_CompassLIB" by your problem type
name and everything will work just modifying the spd file.
But it is possible to modify behaibour or anything you want by modifiing this file.
Here we copy from the customization manual tcl/tk extensions -> events procedures to help to
understand this part:
The structure of problem_type_name.tcl can optionally implement some of
these Tcl prototype procedures (and other user-defined procedures). The
procedures listed below are automatically called by GiD. Their syntax
corresponds to standard Tcl/Tk language:
InitGIDProject: will be called when the problem type is selected. It receives
the dir argument, which is the absolute path to the problem_type_name.gid
directory, which can be useful inside the routine to locate some
alternative files.
BeforeInitGIDPostProcess: will be called just before changing from pre to
postprocess, and before read any postprocess file (this event can be used
for example to check the results file existence and/or rename files). It
has no arguments. If it returns -cancel- as a value then the swapping to
postprocess mode will be cancelled.InitGIDPostProcess: will be called when postprocessing starts. It has no
arguments.
EndGIDProject: will be called when this project is about to be closed. It
7/29/2019 Advanced Problemtype Creation
32/50
30 GiD Course 2010: Advanced Problemtype creation
has no arguments.
EndGIDPostProcess : will be called when you leave Postprocess and open
Preprocess. It has no arguments.
AfterOpenFile: will be called after a geometry or mesh file is read
inside GiD. It receives as arguments:filename: the full name of the file that has been read;
format: ACIS_FORMAT, CGNS_FORMAT, DXF_FORMAT,
GID_BATCH_FORMAT, GID_GEOMETRY_FORMAT, GID_MESH_FORMAT,
IGES_FORMAT, NASTRAN_FORMAT, PARASOLID_FORMAT,
RHINO_FORMAT, SHAPEFILE_FORMAT, STL_FORMAT, VDA_FORMAT,
VRML_FORMAT or 3DSTUDIO_FORMAT;
error: boolean 0 or 1 to indicate an error when reading.
AfterSaveImage: will be called after a picture or model is saved to
disk. It receives as arguments:
filename: the full name of the file that has been saved;
format: eps, ps, tif, bmp, ppm, gif, png, jpg, tga, wrl
LoadGIDProject: will be called when a GiD project or problem type is loaded.
It receives the argument filespd, which is the path of the file which is
being opened, but with the extension .spd (specific problemtype data). This
path can be useful if you want to write specific information about the
problem type in a new file.
SaveGIDProject: will be called when the currently open file is saved to
disk. It receives the argument filespd, which is the path of the file being
saved, but with the extension .spd (specific problemtype data). This path
can be useful if you want to write specific information about the problem
type in a new file.
LoadResultsGIDPostProcess: will be called when a results file is opened in
GiD Postprocess. It receives one argument, the name of the file being
opened without its extension.
BeforeMeshGeneration: will be called before the mesh generation. It receives
the mesh size desired by the user as the elementsize argument. This event
can typically be used to assign some condition automatically.
AfterMeshGeneration: will be called after the mesh generation. It receives asits fail argument a true value if the mesh is not created.
AfterRenumber: will be called after renumber the geometry or the mesh
(to update for example fields storing entity identifiers)
useof : could be GEOMETRYUSE or MESHUSE
leveltype: the kind of entity that was renumbered.
Geometry: must be ALL_LT.
Mesh: could be NODE_LT or ELEM_LT.
renumeration:
Geometry: four sublists with the old and new idenfiers for points,
lines, surfaces and volumes.
Mesh: a sublist with the old and new identifiers for nodes or elements.
7/29/2019 Advanced Problemtype Creation
33/50
31Extensions, example with CompasLIB
SelectGIDBatFile: must be used to switch the default batch file for
special cases.
This procedure must return as a value the alternative pathname of the batch
file. For example it is used as a trick to select a different analysis from
a list of batch calculation files.
BeforeRunCalculation: will be called before running the analysis. It
receives several arguments:
batfilename: the name of the batch file to be run;
basename: the short name model;
dir: the full path to the model directory;
problemtypedir: the full path to the Problem
Types directory;
gidexe: the full path to gid;
args: an optional list with other arguments.
AfterRunCalculation: will be called just after the analysis finishes.
If it returns nowindow as a value then the window that inform about the
finished process will not be opened.
It receives as arguments:
basename: the short name model;
dir: the full path to the model directory;
problemtypedir: the full path to the Problem Types
directory;
where: must be local or remote (remote if it was
run in a server machine, using ProcServer);
error: returns 1 if an calculation error was
detected;
errorfilename: an error filename with some
error explanation, or nothing if everything
was ok.
ChangedLanguage: will be called when you change the current language. The
argument is the new language (en, es, ...). It is used, for example, to
update problem type customized menus, etc.
BeforeWriteCalcFileGIDProject : will be called just before writing the
calculation file. It is useful for validating some parameters.
If it returns -cancel- as a value then nothing will be written.
file: the name of the output calculation file.
AfterWriteCalcFileGIDProject : will be called just after writing the
calculation file and before the calculation process. It is useful for
renaming files, or cancelling the analysis.
If it returns -cancel- as a value then the calculation is not invoked.
file: the name of the output calculation file error: an error code if
there is some problem writing the output calculation file.
7/29/2019 Advanced Problemtype Creation
34/50
32 GiD Course 2010: Advanced Problemtype creation
BeforeTransformProblemType: will be called just before transforming a
model from a problem type to a new problem type version. If it
returns -cancel- as a value then the transformation will not be invoked.
file: the name of the model to be transformed;
oldproblemtype: the name of the previous problem type;newproblemtype: the name of the problem type to be
transformed.
AfterTransformProblemType : will be called just after transforming a
model from a problem type to a new problem type version. If must
return 1 if there were changes, 0 else.
file: the name of the model to be transformed;
oldproblemtype: the name of the previous problem type;
newproblemtype: the name of the problem type to be
transformed.
LoadFileInGidUnknowExtension: will be called when you drop a file with
an unknown extension, then the problem type can try to read it.
filename: the name of dropped file.
TclCalcModelBoundaries: will be called when recalculating the bounding
box, for example when user select "zoom frame"
useof: can be "GEOMETRYUSE", "MESHUSE", "POSTUSE" or "GRAFUSE".
This procedure must return xmin ymin zmin xmax ymax zmaz of the
bounding box of the entities directly managed by the problemtype (this
entities must be directly drawn with the drawopengl command).
If "" is returned instead "xmin ymin zmin xmax ymax zmaz" then any
additional bounding box is considered.
AfterChangeBackground: will be called just after change some background
property, like color, direction or image.
BeforeCopy/Move AfterCopy/Move: will be called just before or after use
copy or move tools.
useof : could be GEOMETRYUSE or MESHUSE
transformation : could be ROTATION, TRANSLATION, MIRROR, SCALE,
OFFSET, SWEEP or ALIGN
AfterCreatePoint/Line/Surface/Volume : will be called just after create the
entity, providing its number
BeforeDeletePoint/Line/Surface/Volume : will be called just before delete the
entity, providing its number
AfterCreateLayer: will be called just after create the layer 'name'
AfterRenameLayer: will be called just after the layer 'oldname' has been
renamed to 'newname'
BeforeDeleteLayer: will be called just before delete the layer 'name'
AfterChangeLayer: will be called just after change some property of the
layer 'name'
'property' could be ON, OFF, FROZEN, UNFROZEN, ALPHA ,
COLOR
7/29/2019 Advanced Problemtype Creation
35/50
33Extensions, example with CompasLIB
whit RRR, GGG, BBB, AAA from 0 to 255
AfterSetLayerToUse: will be called when setting 'name' as current layer to
use
AfterChangeLicenceStatus : will be called when the licence status of GiD
changes. Possible status could be "academic", "professional" or
"temporallyprofessional"
If you open the code of "cmas2d_CompassLIB.tcl" you will see some examples of how this functions are
implemented in CompassLIB
1.5 Using the problemtype with an example
In order to understand the way the calculating module works, simple problems with limited practical use
have been chosen. Although these problems do not exemplify the full potential of the GiD program, the
user may intuit their answers and, therefore, compare the predicted results with those obtained in thesimulations.
Create a surface, for example from the menu Geometry->Create->Object->Polygon
Create a polygon with 5 sides, centered in the (0,0,0) and located in the XY plane (normal = 0,0,1) and
whit radius=1.0
Surface used for this example
7/29/2019 Advanced Problemtype Creation
36/50
34 GiD Course 2010: Advanced Problemtype creation
With Basic Integration With CompassLIB
Load the problemtype: menu Data->Problem
type->cmas2d.
Choose Data->Materials. The materials
window is opened. From the Materials menu in
this window, choose the option Air.
Material window
Click Assign?Surfaces and select the surface.
Press ESC when this step is finished.
Load the problemtype: menu Data->Problem
type->cmas2d_CompassLIB.
Choose Data->Data(Internal). The tree will be
displayed, go to Properties->Shells Doble click
on Shells and a bellow frame will be open to
apply the condition
Apply Shell window
From the Material menu, choose the option Air.
Click Select and select the surface. Press End
when this step is finished.
A Group containig the surface selected will be
created automatically, you can alwais acces to
this group and change the condition applied
Choose the Mesh?Generate option.
A window appears in which to enter the maximum element size for the mesh to be generated. Accept
the default value and click OK. The mesh will be obtained.
Now the calculation may be initiated, but first the model must be saved ( Files->Save ), use
'example_cmas2d' as name for the model.
Choose the Calculate option from the Calculate menu to start the calculation module.
Wait until a box appears indicating the calculation has finished.
7/29/2019 Advanced Problemtype Creation
37/50
35Using the problemtype with an example
Process information box
Choose the option Files?Postprocess.
From the Windows menu, choose the 'View results' option. A window appears from which to visualize
the results. By default when changing to postprocesses mode no results is visualized.
From the View combo box in the View Results window, choose the Contour Fill option. A set of available
results (only one for this case) are displayed.
The View Results window.
Now choose the MC-DISTANCE result and click Apply. A graphic representation of the calculation is
obtained.
7/29/2019 Advanced Problemtype Creation
38/50
36 GiD Course 2010: Advanced Problemtype creation
Visualizing the distance (MC-DISTANCE) from the center of mass of the object to each element, for an
object of homogeneous material
The results shown on the screen reproduce those we anticipated at the outset of the problem: the center
of mass of an object made of homogeneous material coincides with its geometric center. The .log file
will provide the exact coordinates of this point.
1.5.1 Executing the calculation with a concentrated weight
Executing the calculation for an object of heterogeneous material and subject to external point-weight
Choose the Files?preprocess option (to go back to preprocess).
7/29/2019 Advanced Problemtype Creation
39/50
37Executing the calculation with a concentrated weight
With Basic Integration With CompassLIB
Choose the Data?Conditions option. A window
is opened in which the conditions of the
problem should be entered.
Since the condition to be entered acts over
points, select over points from the Type menu in
the Conditions window.
The Condition Window
Enter the value 1e3 in the Weight box. Click
Assign and select the upper corner point. Press
ESC when this step is finished.
If you don't have the tree view available, choose
the Data?Data(internal) option. From The tree
double click on Point Weight.
Apply Point Weight window
Enter the value 1e3 in the Weight box. Click
Select and select the upper corner point. Press
End when this step is finished.
A Group containing the point selected will be
created automatically, you can always access
to this group and change the condition applied.
Choose Mesh?Generate.
A window appears in which to enter the
element size for the mesh to be generated.
click OK.
Choose the Calculate option from the
Calculate menu, thus executing the
calculating module.
Choose the Files?Postprocess option.
Visualize the new results.
Visualization of the distance from the mass center to each element, for an object of heterogeneous
material subject to point weight
Now the condition is external point-weight. As anticipated, the new center of mass is displaced toward
the point under weight.
7/29/2019 Advanced Problemtype Creation
40/50
38 GiD Course 2010: Advanced Problemtype creation
1.6 Aditional information
NOTE: In this example, a code for the program will be developed in C. Nevertheless, any programming
language may be used.
The code of the program that calculates the center of mass (cmas2d.c) is as follows:
The cmas2d.c file
#include
#include
#include
#include
#define MAXMAT 1000
#define MAXCND 1000
char projname[1024];
int i, ielem, inod, icnd;
double *x, *y;
int *N, *imat;
int nodc[MAXCND];
double rho[MAXMAT], wval[MAXCND];
int Nelem, Nnod, Nmat, Ncnd;
double x_CG, y_CG;
void input(void);
void calculate(void);
void output(void);
Declaration of variables and constants used in the program.
void main (int argc, char *argv[]) {
strcpy (projname, argv[1]);
input();
calculate();
output();
}
1.6.1 The main programThe main program is called from the cmas2d.win.bat file and has as parameter the name of the project.
This name is stored in the variable projname.
7/29/2019 Advanced Problemtype Creation
41/50
39The main program
The main program calls the input (), calculate () and output () functions.
The input function reads the .dat file generated by GiD. The .dat file contains information about the
mesh. The calculate function read and processes the data and generates the results. The output
function creates the results file.
void input () {
char filename[1024], fileerr[1024], sau1[1024], sau2[1024];
FILE *fp, *ferr;
int aux,j, error=0;
void jumpline (FILE*);
strcpy(filename, projname);
strcat(filename,".dat");
fp=fopen(filename,"r");
The first part of the input function links the project name with the .dat extension, thus obtaining the name
of the file that is to be read. This file is opened in order to be read.
The jumpline(FILE*) function is declared. This function simply reads a line from the file that it receives as
a parameter, It is used to jump lines of the text when reading the .dat file.
for (i=0; i
7/29/2019 Advanced Problemtype Creation
42/50
40 GiD Course 2010: Advanced Problemtype creation
and the materials corresponding to each element (pointer imat).
In case of error (insufficient memory), a file is created with the extension .err. This file contains
information about the error and the program is aborted.
The next six lines are jumped over.
/* reading the coordinates */
for (inod=1; inod
7/29/2019 Advanced Problemtype Creation
43/50
41The main program
fscanf (fp, "%d %lf", &aux, &rho[i]);
/* reading conditions*/
for (i=0; i
7/29/2019 Advanced Problemtype Creation
44/50
42 GiD Course 2010: Advanced Problemtype creation
mat= imat[ielem];
x_num+= rho[mat]*v*x_CGi;
y_num+= rho[mat]*v*y_CGi;
den+= rho[mat]*v;
}
/* puntual weights */
for(icnd=1;icnd
7/29/2019 Advanced Problemtype Creation
45/50
43The main program
fplog=fopen(filename,"w");
fprintf(fplog, "CMAS2D routine to calculate the mass center ");
fprintf(fplog, "project: %s ", projname);
fprintf(fplog, "mass center: %lf %lf ", x_CG, y_CG);
fclose(fplog);
Creating the .log file: the .log extension is added to the project name and a file is created that will
contain the numerical value of the position of the center of mass, which in turn is stored in the x_CG and
y y_CG variables of the program.
Creating the .post.res file. The output data (results) are stored in this file.
The format of the .post.res file is explaned in the GiD help, see section
Posprocess data files ->Postprocess results format.
/* writing .post.res */
strcpy(filename,projname);
strcat(filename,".post.res");
fp=fopen(filename,"w");
fprintf(fp,"GiD Post Results File 1.0 ");
fprintf(fp,"Result MC-DISTANCE \"LOAD ANALYSIS\" 1 Scalar OnNodes ");
fprintf(fp,"ComponentNames MC-DISTANCE ");
fprintf(fp,"Values ");
for(inod=1;inod
7/29/2019 Advanced Problemtype Creation
46/50
44 GiD Course 2010: Advanced Problemtype creation
int i, ielem, inod, icnd;
double *x, *y;
int *N, *imat;
int nodc[MAXCND];
double rho[MAXMAT], wval[MAXCND];
int Nelem, Nnod, Nmat, Ncnd;
double x_CG, y_CG;
void input(void);
void calculate(void);
void output(void);
void main (int argc, char *argv[]) {
strcpy (projname, argv[1]);
input();
calculate();
output();
}
void input () {
char filename[1024], fileerr[1024], sau1[1024], sau2[1024];
FILE *fp, *ferr;
int aux,j, error=0;
void jumpline (FILE*);
strcpy(filename, projname);
strcat(filename,".dat");
fp=fopen(filename,"r");
for (i=0; i
7/29/2019 Advanced Problemtype Creation
47/50
45The main program
fprintf(ferr, "***** ERROR: Not enough memory. ***** ");
fprintf(ferr, "(Try to calculate with less elements) ");
fclose(ferr);
exit(1);
}
for (i=0; i
7/29/2019 Advanced Problemtype Creation
48/50
46 GiD Course 2010: Advanced Problemtype creation
fscanf (fp, "%d %lf", &nodc[icnd], &wval[icnd]);
jumpline (fp);
}
fclose (fp);
}
void calculate () {
double v;
int n1, n2, n3;
int mat;
double x_CGi, y_CGi;
double x_num=0, y_num=0, den=0;
for(ielem=1;ielem
7/29/2019 Advanced Problemtype Creation
49/50
47The main program
void output() {
char filename[1024];
FILE *fp, *fplog;
double v;
/* writing log information file */
strcpy(filename, projname);
strcat(filename,".log");
fplog=fopen(filename,"w");
fprintf(fplog, "CMAS2D routine to calculate the mass center ");
fprintf(fplog, "project: %s ", projname);
fprintf(fplog, "mass center: %lf %lf ", x_CG, y_CG);
fclose(fplog);
/* writing .post.res */
strcpy(filename,projname);
strcat(filename,".post.res");
fp=fopen(filename,"w");
fprintf(fp,"GiD Post Results File 1.0 ");
fprintf(fp,"Result MC-DISTANCE \"LOAD ANALYSIS\" 1 Scalar OnNodes ");
fprintf(fp,"ComponentNames MC-DISTANCE ");
fprintf(fp,"Values ");
for(inod=1;inod
7/29/2019 Advanced Problemtype Creation
50/50
48 GiD Course 2010: Advanced Problemtype creation
fgets(buffer,1024,filep);
}