GiD - The personal pre and post processor

Writing the calculation files

Once a geometry is created and properties from the tree assigned, it is time to write the input file for the cmas2d solver.


For this example we will need to write the following information in the 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: GiD_Event_AfterWriteCalculationFile. After a few check of the environment, 'Cmas2d::AfterWriteCalculationFile $filename ' is called (It is defined in scripts/writing.tcl).


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 for an integer node id and two reals x, y (z is omitted)

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 active


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

COPYRIGHT © 2022 · GID · CIMNE