Package: pymedit
PyMeditPyMeditis a python package which allows to process triangle and tetrahedral meshes
in the INRIA.meshfile format (see e.g. the reference documentations of Cecile
Dobrzynskihere).A finite element mesh generated by pymedit.examples.generate3DMeshFeaturesProvidesMeshandMesh3Dclasses for reading and writing meshes in ASCII or
binary.meshand.meshbformatProvides classes for reading and writing solution files in ASCII or binary.solor.solbformats:P1Function,P1Function3D,P0Function,P0Function3D,P1Vector,P1Vector3DConnectivity accessible from user friendly attributes:.triangles,.tetrahedra,.vertices, and so onElementary operations implemented efficiently with vectorized operations (trunc,trunc3DMesh,connectedComponents,connectedComponents3Detc...)Tunable verbosity via thedebugattributeInterface with theMmgandadvectandmshdistof
theISCD toolboxfor convenient remeshing,
advection or signed distance function computation in python2D plots withmatplotliband 3D plots withmeditGeneration of 3D mesh with tagged triangles
withgenerate3DMeshand export to VTK withsaveToVtk(requirespyfreefemand
a recent installation ofFreeFEM)InstallationWith pippipinstallpymeditManual installationClone this repository and use the commandpip install -e DIRwhereDIRis the
path topymeditto install it into
your python environment.Running examplesExamples are available in the folderexamplesand can be run from the command
line withpython-mpymedit.examples.ex0
python-mpymedit.examples.mesh
python-mpymedit.examples.P1
python-mpymedit.examples.P0
python-mpymedit.examples.iscd2d
python-mpymedit.examples.mesh3D
python-mpymedit.examples.P1_3D
python-mpymedit.examples.iscd3d
python-mpymedit.examples.generate3DMeshUse--debug nwithnan integer for more verbose outputs.You can test everything
at once withpython-mpymedit.examples.test_allCheck in particular the filespymedit/examples/iscd2d.pyandpymedit/examples/iscd3d.pyfor examples of use ofmmg2d,mmg3d,advectandmshdist.RequirementsRuns with python 3.6 and the following libraries:numpy (>=1.12.1)scipy (>=0.19.1)cvxopt (>=1.2.1)colored (>=1.3.93)(for colored output)Extra dependencies:For usingsavetovtk, a recent version ofFreeFEM(>=4.0) should be available from the
command line.For usingmmg2d,mmg3d,advect,mshdist, the related software should be
available from the command line, seeMmgandtheISCD toolbox.xdotoolis required for passing key press inputs to medit vizualization softwarePlots in 3D are available ifmeditis available from the command
lineQuick exampleFilepymedit/examples/ex0.pyimportnumpyasnpfrompymeditimportcube,mmg3d,P1Function3D,trunc3DMeshM=cube(30,30,30)M.plot("Initial mesh",keys="bceZZZZ")#keys are for setting the medit windowM.debug=4# For debugging and mmg3d output# Setting a P1 level set functionphi=lambdax:np.cos(10*x[0])*np.cos(10*x[1])*np.cos(10*x[2])-0.3phiP1=P1Function3D(M,phi)# Remesh according to the level setnewM=mmg3d(M,0.02,0.05,1.3,sol=phiP1,ls=True)# Trunc the negative subdomain of the level setMf=trunc3DMesh(newM,3)Mf.plot(title="Plotting Truncated mesh",keys="bceZZZZ")Mf.save("Thf.meshb")#Saving in binary formatRunning the script should produce the following imageand the following output:$ python -m pymedit.examples.ex0
Initial mesh
Saved /tmp/tmpreyvbp8j/Th.solb in 0.00s.
Saved /tmp/tmpreyvbp8j/Th.solb
mmg3d_O3 -nr -hmin 0.02 -hmax 0.05 -hgrad 1.3 -hausd 0.002 -ls -sol /tmp/tmpreyvbp8j/Th.solb /tmp/tmpreyvbp8j/Th.meshb                                                                                                                  
  -- MMG3D, Release 5.4.3 (Feb. 26, 2020) 
     Copyright (c) Bdx INP/CNRS/Inria/UPMC, 2004-
     Apr  6 2020 18:56:14
     git branch: develop
     git commit: b1b0331db11598ff548b382ce036465f49c883c1
     git date:   2020-04-01 20:50:37 +0200


  -- INPUT DATA
  %% /tmp/tmpreyvbp8j/Th.meshb OPENED
  %% /tmp/tmpreyvbp8j/Th.solb OPENED
  -- DATA READING COMPLETED.     0.139s

  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
   MODULE MMG3D: 5.4.3 (Feb. 26, 2020)
  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
     git branch: develop
     git commit: b1b0331db11598ff548b382ce036465f49c883c1
     git date:   2020-04-01 20:50:37 +0200


  -- MMG3DLS: INPUT DATA
  --  INPUT DATA COMPLETED.     0.000s

  -- PHASE 1 : ISOSURFACE DISCRETIZATION

  -- MESH QUALITY  162000
     BEST   0.657267  AVRG.   0.657267  WRST.   0.657267 (3394)
  -- PHASE 1 COMPLETED.     0.281s

  -- PHASE 2 : ANALYSIS
  -- PHASE 2 COMPLETED.     4.095s

  -- PHASE 3 : MESH IMPROVEMENT
  *** Manifold implicit surface.
                           14606 splitted,    16006 collapsed,    43043 swapped, 6 iter.

  -- GRADATION : 1.300000 (2.300000)
                             387 splitted,     1965 collapsed,     2536 swapped, 6 iter.
        34173 splitted,    22422 collapsed,    85225 swapped,   348982 moved, 7 iter. 
  *** Manifold implicit surface.
  -- PHASE 3 COMPLETED.     22.502s

  -- MESH QUALITY  302987
     BEST   0.999087  AVRG.   0.789762  WRST.   0.243372 (108431)

  -- MESH PACKED UP
     NUMBER OF VERTICES      54729   CORNERS       44
     NUMBER OF TETRAHEDRA   302987
     NUMBER OF EDGES          1282   RIDGES      1282
     NUMBER OF TRIANGLES     27447

   MMG3DLS: ELAPSED TIME  27.035s

  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
   END OF MODULE MMG3D
  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&


  -- WRITING DATA FILE /tmp/tmpreyvbp8j/Th.o.meshb
  %% /tmp/tmpreyvbp8j/Th.o.meshb OPENED
  %% /tmp/tmpreyvbp8j/Th.o.sol OPENED
  -- WRITING COMPLETED

   ELAPSED TIME  27.256s

Finished in (27.26s)
Loading /tmp/tmpreyvbp8j/Th.o.meshb
Creating empty mesh
Truncating mesh from region 3
Added 1155 edges
Truncated mesh in 0.42s.
Plotting Truncated mesh
medit /tmp/tmpc35iy48n/Th.meshb
Wrote Thf.meshb in 0.18s.
Saved Thf.meshb