GenericModel

The GenericModel is the base class for other, more specific classes which aim to mesh models using the Gmsh- Python-API. In addition to the methods defined within the Gmsh-Python-API, this class provides methods for all basic steps of a model generation using Gmsh: some of these methods are only placeholders here and - if required - have to be specified/overwritten for the more specialized models.

Class Definition

class gmshModel.Model.GenericModel.GenericModel(dimension=None, gmshConfigChanges={})[source]

Bases: object

Generic class for meshing models generated using the Gmsh-Python-API

This class provides the basic mesh generation framework for Gmsh. It implements the methods for:

  1. Setting up a geometry using basic geometric entities and boolean operations

  2. Adding the geometric objects to Gmsh, performing the boolean operations, defining physical groups

  3. creating a mesh with user-defined refinement fields

  4. saving and visualizing the mesh

Some of the methods used within the framework are only defined as placeholder methods here and have to be specified in detail within the child classes.

Attributes:

dimension: int

dimension of the model instance

modelName: string

name of the Gmsh model and default name for all resulting files

gmshConfigChanges: dict

dictionary for user updates of the default Gmsh configuration

geometricObjects: list

list containing the instances of geometric objects used for the model geometry creation

groups: dict

dictionary with group information for the model entities

booleanOperations: list

list with dictionaries defining the individual boolean operations to perform for the model generation

physicalGroups: list

list with dictionary defining which Gmsh entities are defined as physical groups (e.g. different materials)

refinementFields: list

list of dictionaries defining the refinement fields that have to be added to the Gmsh model

backgroundField: int

number of the field that has to be used as the background field/mesh for the mesh generation

addGeometricObject(objClassString, **objData)[source]

Method to add one of the objects that are defined within the class geometricObjects and its child classes to the Gmsh model.

Parameters:

objClass: class

class the geometric object is defined in

objData: keyworded object data

enumeration of keyworded arguments needed for the creation of the new geometric object of class objectClass

addGeometricObjectsToGmshModel()[source]

Method to add Gmsh representations of the gmshModels geometric objects

addPhysicalGroupsToGmshModel()[source]

Method to add defined physical groups to the Gmsh model

addRefinementFieldsToGmshModel()[source]

Method to add defined refinement fields to the Gmsh model

close()[source]

Gmsh finalization method

The Gmsh-Python-API has to be finalized for a proper termination of the model.

createGmshModel(**geometryOptions)[source]

Method to create the Gmsh Model and provide necessary information to it

This method contains the basic Gmsh model creation steps: after geoetric objects are defined, boolean operations are performed to generate the final geometry. Parts of the geometry are combined to physical groups in order to be able to assign, e.g., material parameters to them. If required, a periodicity constraint is finally added to the model.

Parameters:

geometryOptions: key-value pairs of options

key-value pairs of options required for the geometry generation process

createMesh(threads=None, refinementOptions={})[source]

Method to generate the model mesh

This method contains the basic mesh generation steps for a Gmsh model: refinement fields are calculated with user-defined options and added to the model. Afterwards, a background field is specified and used for the mesh size computation within Gmsh. Finally, the mesh is created.

Parameters:

threads: int

number of threads to use for the mesh generation

refinementOptions: dict

dictionary with user-defined options for the refinement field calculations

defineBooleanOperations()[source]

Placeholder method for the definition of necessary boolean Operations. Has to be specified in child classes

defineGeometricObjects(**options)[source]

Placeholder method for the definition of geometric objects. Has to be specified in child classes

definePhysicalGroups()[source]

Placeholder method to define required physical groups. Has to be specified in child classes

defineRefinementFields()[source]

Placeholder method to define/compute refinement fields for the mesh generation. Has to be specified in child classes

getBoundaryEntities()[source]

Method to get the entities on the boundary of the Gmsh model

getGmshOption(optionName)[source]

Method to get the value of a Gmsh configuratio option with known name

Parameters:

optionName: string

name of the option

getIDsFromTags(tags)[source]

Interfacing method to get Gmsh entity IDs from given list of Gmsh entityTags

Parameters:

tags: (list of) tuples

list of Gmsh entity tag tuples tags=(entityDimension, entityID)

initializeGmsh(gmshConfigChanges={})[source]

Gmsh initialization method

This method initializes the Gmsh-Python-API and adds it to the GmshModel

Parameters:

gmshConfigChanges: dict

dictionary with Gmsh configuration options that have to be set

classmethod load(fileName)[source]

Method to load an existing GmshModel object

Objects that have been saved to a binary file using the pickle module can be reloaded here.

performBooleanOperationsForGmshModel()[source]

Method to perform defined boolean operations for the Gmsh model

saveGeometry(file=None)[source]

Method to save the generated geometry into a geometry file

This method allows to store geometry information into “.step” or “.brep”- files.

saveMesh(file=None)[source]

Method to save the generated mesh into a mesh file

After the mesh is generated, it has to be saved into a usable file format. Here, all meshes that are supported by the meshio library, can be used to save the mesh. If meshio is not available, the mesh format is restricted

saveModel(file=None)[source]

Method to save the complete model into a pickle object

In order to be able to reuse generated models, the whole model can be saved. Within this method, the pickle module is used to save the model to a binary file.

setGmshOption(optionName=None, optionValue=None)[source]

Method to set a Gmsh configuration option

Parameters:

optionName: string

name of the option to set

optionValue: int/float/string

value of the option to set

setupPeriodicity()[source]

Placeholder method to set up periodicity constraints for RVEs. Has to be specified in child classes, if required

showModelInGmsh()[source]

Method to open the complete model in Gmsh

updateGmshConfiguration(configurationUpdate)[source]

Method to update the Gmsh configuration options with a dictionary of updated options

Parameters:

configurationUpdate: dict

dictionary of configuration options to be updated

visualizeGeometry()[source]

Method to visualize the Gmsh model geometry using pythonocc

visualizeMesh()[source]

Method to visualize the generated mesh using pyvista and vtk