GiD - The personal pre and post processor

Tcl Mesh plug-in

This is a particular case of a Tcl plug-in to generate the mesh from geometric entities.

It is a special case, because it require that GiD invoke our procedures while meshing, and provide the input of each geometric entity, and store the generated mesh, and it require also to offer this new algorithm as possible meshing method, and handle its generic parameters with the model and in preferences.

GiD nowadays is ready to implement only plugins of volume mesher of spheres (and circles for surfaces), other cases must be implemented in a similar way in the future… 

An example of mesh plug-in is the 'granular' mesher to generate spheres or circles.

it is implemented by the files of the folder <GiD>\plugins\Mesh\Spheres

GiD mesh plug-in mechanism:

1-Register the meshing procedure

To register a new sphere volume mesher this proc must be called

proc GiD_RegisterPluginGenerateSphereMesh { value procedure label require_tetrahedra }
  • value is an integer that identify the value of the mesher (a GiD variable store the kind of sphere mesher to be used)
    the value 0 is reserved for the GiD inner sphere mesher
    the value 1 is used for the “Granular” mesher
    other values must be used for future sphere meshers…
  • procedure is a tcl procedure that will be called by GiD when meshing each volume (in case that was marked to be meshed with spheres). This procedure must have this prototype:
proc procname { id_entity input_mesh input_boundary_parts size } {
    ...
    return [list $nodes_coordinates $element_radius $output_boundary_parts]
}


id_entity is the id of the volume that will be meshed
input_mesh defines the input mesh: nodes coordinates and elements (if require_tetrahedra ==0 the triangles of the boundary that define the volume)
== [list [GiD_Info Mesh Nodes 1 end -array] [GiD_Info Mesh Elements Triangle 1 end -array]]
input_boundary_parts allow define parts of the boundary associated to each surface of the volume, to allow classify the output spheres mesh related to these surfaces, to apply boundary conditions, layers, groups, materials…
size is the general mesh size asked by the user

The procedure inside must do what he want, in this case write the information in a temporary file, and start sphere_mesher.exe, the is the really sphere mesher, read its results in another auxiliary file, and finally return the data as three items, to define the sphere centers, its radius, and possible extra classification of parts.

return [list $nodes_coordinates $element_radius $output_boundary_parts]

  • label is the string that will identify the mesher in GiD windows (Utilities->Preferences… Meshing->Sphere/Circle)
  • require_tetrahedra must be 0 or 1 (0 if the input of the mesher are the triangles closing the volume to be meshed with spheres, 1 if it require the tetrahedra filling the volume)


The file Spheres.tcl do this:

#register the procedure Spheres::GenerateSpheres as GiD-Tcl event to generate the mesh when the value of SphereMesher is 1 (showed with label $info_plugin(Name))
GiD_RegisterPluginGenerateSphereMesh 1 Spheres::GenerateSpheres $info_plugin(Name) 0


and define the procedure that somehow do the mesh, and return it in the format expected by GiD

proc Spheres::GenerateSpheres { id_entity input_mesh input_boundary_parts size } {
    ...
    return [list $nodes_coordinates $element_radius $output_boundary_parts]
}

Then the registered name "Granular" appear as a meshing method to generate circles and/or spheres in the preferences window


A new meshing method is offered


2- Mesh parameters


Usually the mesher will require some general parameters, and several copies of these parameters must be handled by GiD.
A copy of values is used to fill the Utilities->Preferences... Meshing window
Another copy of values is used the model, and saved/restored with it in disk
A third copy is used while meshing, with the values of one of them: from current preferences or from the previous values of the model

To handle several copies Granular.tcl uses the package TclOO to define a class with the variables required for the mesher.
This class is named SphereMeshVariables and must be derived from GiDMeshVariables

# class that store the mesher variables derived from GiDMeshVariables
package require TclOO

if { [info commands SphereMeshVariables] != "" } {   
    SphereMeshVariables destroy ;#to protect of multiple source
}

oo::class create SphereMeshVariables {
    superclass GiDMeshVariables
    #variables showed in preferences:
    variable MinRadiusFactor MaxRadiusFactor PartSizeDist
    variable DistributionParam,StandarDeviation DistributionParam,Scale DistributionParam,Width 
    variable Random BoundaryTolerance
    #variables hidden in preferences:
    variable ParticleType
    variable Seed Advanced Priority
    variable HighPorosity Porosity
    
    constructor { owner } {
        next $owner ;#to invoke the parent constructor                                
    }
    
    method GetDefault { key } {        
        if { $key == "ParticleType" } {
            set value 1      
        } elseif { $key == "MaxRadiusFactor" } {
            set value 1.2
        } elseif { $key == "MinRadiusFactor" } {
            set value 0.8
        } elseif { $key == "PartSizeDist" } {
            set value 0
        } elseif { $key == "DistributionParam,StandarDeviation" } {
            set value 0.1
        } elseif { $key == "DistributionParam,Scale" } {
            set value 1.0
        } elseif { $key == "DistributionParam,Width" } {
            set value 1.0               
        } elseif { $key == "Random" } {
            set value 0       
        } elseif { $key == "Seed" } {
            set value 1
        } elseif { $key == "Priority" } {
            set value 0
        } elseif { $key == "BoundaryTolerance" } {
            set value 1.0
        } elseif { $key == "Advanced" } {
            set value 0
        } elseif { $key == "HighPorosity" } {
            set value 0
        } elseif { $key == "Porosity" } {
            set value 0.95
        } else {
            set value 0
            WarnWinText "SphereMeshVariables::GetDefault. Unexpected key $key"
        }        
        return $value
    }

    method IsValid {} {
        set valid 1
        if { $ParticleType != 1 } {
            set valid 0
        } elseif { $MinRadius <= 0 } {
            set valid 0
        }
        return $valid
    }    
    export GetDefault IsValid
}


And this class is declared (registered) to GiD as 'mesh variables'

#to register this class as a inner mesher and handle its variables (used copy in the model, in preferences and the ones to use meshing)
GiD_RegisterPluginMeshVariablesClass SphereMeshVariables


The values that are required by the mesher are the ones of 'MESHING'. The object with these values is obtained with

set obj [PluginMeshVariablesClass_GetClassObject SphereMeshVariables MESHING]

(the values of 'PREFERENCES' and 'MODEL' are handled internally by GiD to save/restore values with the model and with the user preferences)


To define how to show in Utilities->Preferences... Meshing these mesh variables a XML file SpheresPreferences.xml was created with this content:

<group name='mesher_granular' label='Granular'>
  <labelframe name='sphere_and_circle_main_options' label='Sphere and circle main options'>
    <entry name='boundary_flag' variable='BoundaryTolerance' variablemanager='Spheres::VariableManager' label='Boundary tolerance factor' help='Factor to select spheres close to the boundary to apply conditions' validation='IsFloatingPointPositive'/>
    <comboboxframe name='distribution_type' variable='PartSizeDist' variablemanager='Spheres::VariableManager' label='Distribution type' help='Type of distribution'>
      <option value='0' label='Gauss' setactivate='distribution_standardeviation min_radius_factor max_radius_factor'/>
      <option value='1' label='Exponential' setactivate='distribution_scale min_radius_factor max_radius_factor'/>
      <option value='3' label='Cauchy' setactivate='distribution_scale min_radius_factor max_radius_factor'/>
      <option value='5' label='Flat' setactivate='min_radius_factor max_radius_factor'/>
      <option value='6' label='Constant'/>
      <entry name='distribution_standardeviation' variable='DistributionParam,StandarDeviation' variablemanager='Spheres::VariableManager' label='Standard deviation' help='Standar deviation of the gaussian distribution' validation='IsFloatingPointPositive'/>
      <entry name='distribution_scale' variable='DistributionParam,Scale' variablemanager='Spheres::VariableManager' label='Scale' help='?' validation='IsFloatingPointPositive'/>
      <entry name='min_radius_factor' variable='MinRadiusFactor' variablemanager='Spheres::VariableManager' label='Minimum radius factor' help='Minimum radius=min_factor*mean_radius' validation='IsFloatingPointPositive'/>
      <entry name='max_radius_factor' variable='MaxRadiusFactor' variablemanager='Spheres::VariableManager' label='Maximum radius factor' help='Maximum radius=max_factor*mean_radius, max_factor>=1' validation='IsFloatingPointPositive'/>
    </comboboxframe>
  </labelframe>
  <checkbuttonframe variable='Advanced' variablemanager='Spheres::VariableManager' label='Advanced options'>
    <checkbutton name='random' variable='Random' variablemanager='Spheres::VariableManager' label='Random mesh' help='Allow Random Generator Seed'/>
    <radiobuttonframe name='prioritize_boundary_or_distribution' label='Prioritize' variable='Priority' variablemanager='Spheres::VariableManager' help=''>
      <option value='0' label='Boundary fitting' help='Prioritize boundary fitting'/>
      <option value='1' label='Size distribution' help='Prioritize size distribution'/>
    </radiobuttonframe>
    <checkbuttonframe variable='HighPorosity' variablemanager='Spheres::VariableManager' label='High porosity'>
      <scale variable="Porosity" variablemanager='Spheres::VariableManager' whenreadvar="FormatG" from="0.94" to="0.998" resolution="0.001" showvalue="0" showbuttons="1" needsredraw="1" help="This option gives the porosity needed to achieve">
        <entry width="6" state="readonly" validation="IsFloatingPoint"/>
      </scale>
    </checkbuttonframe>
  </checkbuttonframe>
</group>


Spheres::VariableManager is a procedure used in this xml to allow set/get/reset these variables in a predefined way

proc Spheres::VariableManager { operation var {value ""} } {
    return [PluginMeshVariablesClass_VariableManager SphereMeshVariables $operation $var $value]
}

This new tab is created from the xml definition to represent the parameters required by this meshing algorithm

Parameters of the new meshing method

3- User feedback

Advance bar:


To update a progress bar while meshing the granular procedure is invoking

GiD_ProgressInMeshing $entity_type $id_entity $factor $num_elements $num_elements


this update the GiD progress bar, and allow the user stop the meshing (the procedure must stop its work if the user ask it)
the percent of mesh done could be passed from sphere_mesher.exe in a simple way using an extra file

Error messages:
In case of detect errors, the procedure registered to mesh, instead of return a list of three items, could return a single item with the error message (provided in an error file written by the mesher).
GiD will finally show the error message in its own standard window.


COPYRIGHT © 2022 · GID · CIMNE