Package: objectgmsh
objectmshObject oriented Gmsh modeling.Project descriptionThis tool provides some utilities for thegmsh python APIthat are especially helpful when you're working on complex geometries using the Open CASCADE kernel.The project is developed and maintained by theModel experiments groupat the Leibniz Institute for Crystal Growth (IKZ).ReferencingIf you use this code in your research, please cite our article:TODOInstallationThe latest release can be installed using pip:pip install objectgmshBasic principleobjectgmsh bases on aModelclass implementing an interface to the main Gmsh functionality, and aShapeclass used to access information about the geometry, e.g., the IDs of the interface between two bodies. Furthermore, several classes for simplified control of mesh sizes are provided.objectgmsh is just a wrapper for the gmsh python API, and all gmsh commands are still working "as usual". However, in complex geometries, it highly reduces the modelling effort.Example2D modeling & meshingMesh of a simple 2D axisymmetric Czochralski crystal growth model:importgmshfromobjectgmshimportModel,Shape,MeshControlConstant,MeshControlExponential,cut# dimensionscruc_r=0.06# crucible radiuscruc_h=0.03# crucible heightcruc_hi=0.015# crucible height insidemelt_r=0.025# melt radiusmelt_h=0.01# melt heightcrys_r=0.005# crystal radiuscrys_h=0.1# crystal heightocc=gmsh.model.occmodel=Model()# main bodiescrystal=Shape(model,2,"crystal",[occ.addRectangle(0,0,0,crys_r,crys_h)])melt=Shape(model,2,"melt",[occ.addRectangle(0,-melt_h,0,melt_r,melt_h)])crucible=occ.addRectangle(0,-melt_h-(cruc_h-cruc_hi),0,cruc_r,cruc_h)crucible_hole=occ.addRectangle(0,-melt_h,0,melt_r,cruc_hi)cut([(2,crucible)],[(2,crucible_hole)])crucible=Shape(model,2,"crucible",[crucible])# create connection between the shapescrystal.set_interface(melt)melt.set_interface(crucible)# detect boundariesbnd_crystal_out=Shape(model,1,"bnd_crystal_out",[crystal.top_boundary,crystal.right_boundary])bnd_melt=Shape(model,1,"bnd_melt_surf",melt.get_boundaries_in_box([crys_r,melt_r],[0,0]))surfs=[crucible.get_boundaries_in_box([melt_r,melt_r],[0,cruc_hi-melt_h],one_only=True),crucible.top_boundary,crucible.right_boundary,]bnd_crucible_outside=Shape(model,1,"bnd_crucible_outside",surfs)bnd_crucible_bottom=Shape(model,1,"bnd_crucible_bottom",[crucible.bottom_boundary])if_crystal_melt=Shape(model,1,"if_crystal_melt",crystal.get_interface(melt))# add physical groupsmodel.make_physical()# set mesh constraintsmodel.deactivate_characteristic_length()MeshControlConstant(model,0.005,[crucible,melt])MeshControlConstant(model,0.0025,[crystal])MeshControlExponential(model,if_crystal_melt,0.001,exp=1.7,shapes=[crystal,melt,crucible])# create mesh, show, exportmodel.generate_mesh()model.show()model.write_msh("crystal-growth-2D.msh")A similar but more complex example can be foundhere.3D modeling & meshingMesh of a simple 3D Czochralski crystal growth model:importgmshfromobjectgmshimport(Model,Shape,MeshControlConstant,MeshControlExponential,cut,rotate,)fromobjectgmsh.objectsimportMeshControlLinear# dimensionscruc_r=0.06# crucible radiuscruc_h=0.03# crucible heightcruc_hi=0.015# crucible height insidemelt_r=0.025# melt radiusmelt_h=0.01# melt heightcrys_r=0.005# crystal radiuscrys_h=0.1# crystal heightocc=gmsh.model.occmodel=Model()# main bodiescrystal=Shape(model,3,"crystal",[rotate(occ.addRectangle(0,0,0,crys_r,crys_h))])melt=Shape(model,3,"melt",[rotate(occ.addRectangle(0,-melt_h,0,melt_r,melt_h))])crucible=occ.addRectangle(0,-melt_h-(cruc_h-cruc_hi),0,cruc_r,cruc_h)crucible_hole=occ.addRectangle(0,-melt_h,0,melt_r,cruc_hi)cut([(2,crucible)],[(2,crucible_hole)])crucible=Shape(model,3,"crucible",[rotate(crucible)])# create connection between the shapescrystal.set_interface(melt)melt.set_interface(crucible)# set mesh sizescrystal.mesh_size=0.0025melt.mesh_size=0.005crucible.mesh_size=0.01# detect boundariesbnd_crystal_out=Shape(model,2,"bnd_crystal_out",[xforxincrystal.boundariesifxnotincrystal.get_interface(melt)],)bnd_melt=Shape(model,2,"bnd_melt_surf",[xforxinmelt.boundariesifxnotinmelt.get_interface(crystal)+melt.get_interface(crucible)],)bnd_crucible_bottom=Shape(model,2,"bnd_crucible_bottom",[crucible.bottom_boundary])bnd_crucible_outside=Shape(model,2,"bnd_crucible_outside",[xforxincrucible.boundariesifxnotincrucible.get_interface(melt)+bnd_crucible_bottom.geo_ids],)if_crystal_melt=Shape(model,2,"if_crystal_melt",crystal.get_interface(melt))if_crucible_melt=Shape(model,2,"if_crucible_melt",crucible.get_interface(melt))# add physical groupsmodel.make_physical()# set mesh constraintsmodel.deactivate_characteristic_length()model.set_const_mesh_sizes()MeshControlExponential(model,if_crystal_melt,0.001,exp=1.7,fact=2)# refinement at crystallization frontMeshControlLinear(model,if_crucible_melt,melt.mesh_size,crucible.mesh_size)# create mesh, show, exportmodel.generate_mesh(3)model.show()model.write_msh("crystal-growth-3D.msh")DocumentationThe code is documented using docstrings. A more extensive documentation using sphinx is under construction.SupportIn case of questions just open an issue or contact Arved Enders-Seidlitz.AcknowledgementsThis projecthas received funding from the European Research Council (ERC) under the European Union's Horizon 2020 research and innovation programme (grant agreement No 851768).ContributionAny help to improve this package is very welcome!