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).
First we need to do in this function is to call some initialization procedures:
To open the file for writting:
To initialize the material's database, indicating wich 'conditions' have materials assigned.
Then we write some headers and to write the number of elements and nodes, we call some GiD_Info Functions:
To write the nodes and their coordinates we need to prepare the format and call WriteCoordinates:
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:
Then, the material's block. To get and write the number of materials, there is a function, GetNumberOfMaterials:
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
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 writting, and call GetNumberOfNodes:
And foreach node with a Point_Weight condition asigned, we need to print the node id and the asigned weight.
Finally, all we need to do is to close the writting file