{ "info": { "author": "Tristan de Lataillade", "author_email": "delataillade.tristan@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# py2gmsh\n\nPython wrappers to create gmsh files with object-oriented syntax.\n\nThe wrappers are made closest to actual gmsh syntax for .geo files, with the\naddition of convenience tools, object-oriented syntax for easy manipulation and\nextra functionalities.\n\n## Installation\n\nWhen pip is present in your python installation, simply:\n```\npip install py2gmsh\n```\n\n## Usage\n\n### Creating a simple geo file\n\nThe following example shows how a simple geometry can created using a syntax\nclose to the one used in .geo files\n\n```python\nfrom py2gmsh import (Mesh, Entity, Field)\n\n# create Mesh class instance\nmy_mesh = Mesh()\n\n# create points\np1 = Entity.Point([0., 0., 0.])\n# add point to mesh\nmy_mesh.addEntity(p1)\n#create more points\np2 = Entity.Point([1., 0., 0.])\nmy_mesh.addEntity(p2)\np3 = Entity.Point([1., 1., 0.])\nmy_mesh.addEntity(p3)\n# entities can also directly be added to a mesh:\np4 = Entity.Point([0., 1., 0.], mesh=my_mesh)\n\n# create curves\nl1 = Entity.Curve([p1, p2])\nl2 = Entity.Curve([p2, p3])\nl3 = Entity.Curve([p3, p4])\nl4 = Entity.Curve([p4, p1])\n# entities can also be added in a batch\nmy_mesh.addEntities([l1, l2, l3, l4])\n\n# create curveloop\nll1 = Entity.CurveLoop([l1, l2, l3, l4], mesh=my_mesh)\n\n# create surface\ns1 = Entity.PlaneSurface([ll1], mesh=my_mesh)\n\n# create fields\nf1 = Field.MathEval(mesh=my_mesh)\ngrading = 1.1\nhe = 0.005\nf1.F = '(abs(y-0.5)*({grading}-1)+{he})/{grading}'.format(grading=grading,\n he=he)\n# create minimum field\nfmin = Field.Min(mesh=my_mesh)\nfmin.FieldsList = [f1] # could add more fields in the list if necessary\n\n# set the background field as minimum field\nmy_mesh.setBackgroundField(fmin)\n\n# set max element size\nmy_mesh.Options.Mesh.CharacteristicLengthMax = 0.1\n\n# adding Coherence option\nmy_mesh.Coherence = True\n\n# write the geofile\nmy_mesh.writeGeo('my_mesh.geo')\n```\n\nThe .geo file `my_mesh.geo` can be opened directly in the gmsh GUI for visualisation and meshing. Alternatively, running gmsh to create a .msh file gives the following result for my_mesh.msh:\n\n```\n>> gmsh my_mesh.geo -2 -o my_mesh.msh\n```\n
\n
\n