GiD - The personal pre and post processor
Customization
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 was chosen, and 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.
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).
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.
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 of the object.
Finally, the results generated by the calculating module will be read and visualized in GiD Post-process.
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 the results in the results file. This module may be programmed in the language of your choice, 'C' is 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.
Example: cmas2d_customlib
Let's see our example: the cmas2d_customlib problemtype. You can see it's files on the example's problemtype folder (<GiD>\problemtypes\Examples\cmas2d_customlib.gid)
Inside it's folder, we can find the following files:
- cmas2d_customlib.xml
Defines some information about the problemtype, such as the name, the minimum GiD version, a description, etc.
- cmas2d_customlib_default.spd
Defines the tree interface.
- cmas2d_customlib.tcl
Contains tcl code to process some GiD events, and the functions to write the input file.
- cmas2d_customlib.win.bat | cmas2d_customlib.unix.bat
Script that launches the solver.
It's time to load the problemtype. Go to Data->Problemtype->Examples->cmas2d_customlib. The first you can see is a window like this:
This window helps you to generate a random 4 sided surface. For this example let's click Random surface and get an auto-generated surface. You can click continue and create your own surface. This is the surface I'll work with:
After this, let's open the properties tree. Go to Data->Data tree.
Interface definition
In this section, we are going to prepare the interface definition document, called cmas2d_customlib_default.spd.
This is a file in XML format and contains all the definition of all the data necessary for the analysis.
First of all, let's see the final result:
Step by step. The first we see is Units. It's useful to set a global criteria, such as the geometry units, or the default units system.
The next is Point Weight, to assign concentrated mass to a group that contains points. It's spd code is:
<condition n="Point_Weight" pn="Point Weight" ov="point" ovm="node" icon="constraints" help="Concentrated mass"> <value n="Weight" pn="Weight" v="0.0" unit_magnitude="M" units="kg" help="Specify the weight that you want to apply"/> </condition>
Let's introduce some concepts. The 'condition' tag is used to assign properties to groups. The properties are defined in the 'value' tags inside the 'condition'. For example, there is a property called 'Weight'. We can specify over which geometry entity will be assigned (point, line, surface and/or volume) in the 'ov' field of the condition. For further information, check the customLib description of fields in the Customization Manual.
When we 'double click' on Point Weight, we can see this window, to assign a weight to a group, that can be created by clicking on the Select button. This will allow us to select some points in the geometry. Now assign a 25 kg point load to a point of the geometry.
- Write '25' in the Weight field
- Click on 'select' button and select one (or more) point.
- Press ESC to stop selecting. A group name will be generated.
- Click OK
Then we find 'Properties', a folder or 'container', that contains 'Shells' and 'Materials'. It's code is:
<container n="Properties" pn="Properties" un="Properties" icon="shells" help="Define your materials database and apply them to the surfaces of your problem"> <condition n="Shells" pn="Shells" ov="surface" ovm="element" icon="shells" help="Select your material and the surfaces related to it"> <value n="material" pn="Material" editable='0' help="Choose a material from the database" values_tree='[GetMaterialsList]'> <edit_command n="Edit materials" pn="Edit materials" icon="material" proc='EditDatabaseList'/> </value> </condition> <include path="xml/materials.xml"/> </container>
There is a 'container', another 'condition' called Shells, and a special 'value' called material. In this section, we want to assign a material from the database to a surface (see 'ov' field on the condition). NOTE: As you can see, there is an include to a file. The customLib library allows splitting the spd in different slices. You can find the materials database on that file in the problemtype folder.
By 'double clicking' on Shells, we get a window like this:
- Select a material from the list.
- Select the surface
- Press ESC
- Click OK
Your tree should look like this:
Writing the calculation files
Once created a geometry and assigned properties in the tree, it is time to write the input file.
For this example we will need to write the following information in a file:
- Number of elements and nodes of the model
- Coordinates of the nodes of the mesh
- Connectivities of the elements
- Number of materials used
- Density of each material used
- Number of point conditions
- Weight assigned to each point
Let's open the cmas2d_customlib.tcl file and see how are we processing the event of GiD that is called when the user wants to calculate, AfterWriteCalcFileGIDProject. After a few check of the environment, 'Cmas2d::WriteCalculationFile $filename' is called (It is defined in the end of the same file).
TCL note: $filename is the content of variable filename, to define ret variable as "-cancel-" you must use "set ret -cancel-" and to use it "$ret"
First we need to do in this function is to call some initialization procedures:
To open the file for writing:
customlib::InitWriteFile $filename
To initialize the material's database, indicating which 'conditions' have materials assigned.
customlib::InitMaterials [list "Shells"] active
Then we write some headers and to write the number of elements and nodes, we call some GiD_Info Functions:
customlib::WriteString "[GiD_Info Mesh NumElements] [GiD_Info Mesh NumNodes]"
To write the nodes and their coordinates we need to prepare the format and call WriteCoordinates:
customlib::WriteCoordinates "%5d %14.5e %14.5e%.0s\n"
As we can see, the format is prepared to write 2D coordinates (X & Y).
Next we need to write are the connectivities of the elements. For each element, we want to write it's id, it's nodes, and the material id that we assigned. In order to do this, again we prepare the parameters for the function WriteConnectivities:
set elements_conditions [list "Shells"]
set element_formats [list {"%10d" "element" "id"} {"%10d" "element" "connectivities"} {"%10d" "material" "MID"}]
customlib::WriteConnectivities $elements_conditions $element_formats
Then, the material's block. To get and write the number of materials, there is a function, GetNumberOfMaterials:
set num_materials [customlib::GetNumberOfMaterials used]
customlib::WriteString "NÂș Materials= $num_materials"
And, to write the material information, again, we need to prepare the parameters to print the material's id and it's density, and call the function WriteMaterials
customlib::WriteMaterials [list {"%4d" "material" "MID"} {"%13.5e" "material" "Density"}] used
It is time to write the point weights. To get the number of nodes where we are applying the weights, we need to specify which is the condition we are writing, and call GetNumberOfNodes:
set condition_list [list "Point_Weight"]
set number_of_conditions [customlib::GetNumberOfNodes $condition_list]
And foreach node with a Point_Weight condition assigned, we need to print the node id and the assigned weight.
set condition_list [list "Point_Weight"]
set condition_formats [list {"%1d" "node" "id"} {"%13.5e" "property" "Weight"}]
customlib::WriteNodes $condition_list $condition_formats
Finally, all we need to do is to close the writing file
customlib::EndWriteFile
To test this on your example, you just need to Save your model (ctrl + s), Mesh it (ctrl + g), and calculate (F5). You can see the result of the writing process opening the file {modelname}.dat on the model folder.
Solver execution
At this point, we have generated a .dat file, containing the input data for the solver. It's time to launch it. In order to do it, we should have a .bat file (One for Windows and another for Unix based systems.
This script should delete the output files of previous executions (if exist) and launch the solver executable.
Check cmas2d_customlib.win.bat and cmas2d_customlib.unix.bat for more information.
The solver is located in the exec folder of the problem type. For this example, you can access to de cmas2d.c source file, and there are some compiled versions, for the common architectures.
Results
After the execution, the solver has generated some files:
- {projectname}.err : With the error information (If necessary).
- {projectname}.log : With some 'log' information.
- {projectname}.post.res : With the result data.
Access the .post.res file to see the format, and check the documentation about the Postprocess data files in the Customization manual.
It's time to change to postprocess and see our results. Go to View results in the menu, contour fill > DISTANCE CENTER
You should see something like this, but adapted to your generated geometry:
Extra: Wizard problemtype example
The current course focuses on a 'tree distribution' of the information. There is another example that implements a 'wizard distribution', based on this tree one. You can find the wizard one on our Github site.
COPYRIGHT © 2022 · GID · CIMNE