Skip to content

Utilities for manipulating Mathematica ElementMesh objects

License

Notifications You must be signed in to change notification settings

c3m-labs/MeshTools

Repository files navigation

MeshTools

releases SemVer 2.0.0

MeshTools is a Mathematica package for creating and manipulating meshes for finite element method (ElementMesh objects). It helps you to do the following tasks:

  • Create structured mesh in 2D or 3D
  • Split, transform and merge meshes
  • Convert triangular to quadrilateral mesh
  • Create high quality mesh on basic geometric shapes

niceExample

Installation

MeshTools package requires Mathematica version 11. or later.

The package is released in the .paclet file format that contains the code, documentation and other necessary resources. Download the latest .paclet file from the repository "releases" page to your computer and install it by evaluating the following command in the Mathematica:

(* This built-in package is usually loaded automatically at kernel startup. *)
Needs["PacletManager`"]

(* Path to .paclet file downloaded from repository "releases" page. *)
PacletInstall["full/path/to/MeshTools-X.Y.Z.paclet"]

This will permanently install the MeshTools package to $UserBasePacletsDirectory. To update the documentation it may be necessary to restart Mathematica. Mathematica will always use the latest installed version of package and all installed versions can be enumerated by evaluating PacletFind["MeshTools"]. You can get more detailed information about the package with PacletInformation["MeshTools"]. All versions can be uninstalled with:

PacletUninstall["MeshTools"]

Alternative method of installation for Mathematica version 12.0+ is to use ResourceFunction["GitHubInstall"] from Wolfram Function Repository. Note that you need to be logged in with (free) Wolfram Account to use it.

ResourceFunction["GitHubInstall"]["c3m-labs", "MeshTools"]

Try it online

You can try the package even without installation by going to Wolfram Programming Lab and clicking "Start programming now". This will open a new notebook in Cloud environment where you should evaluate the following to load the package.

Get["http://raw.githubusercontent.com/c3m-labs/MeshTools/master/MeshTools/MeshTools.wl"]

You will not be able to access documentation, but it is helpful to list all available functions. Then you can also try the usage example from the section below.

Information["MeshTools`*"]

Usage

After installing the package, load it in the Mathematica session with Needs. To access the documentation, open the notebook interface help viewer and search for "MeshTools".

Example of extruded mesh

Needs["MeshTools`"]

(* Create MeshRegion object from Graphics. *)
region = DiscretizeGraphics[
  Text[Style["\[Pi]", FontWeight -> "Bold"]],
  _Text,
  MaxCellMeasure -> 1/10
]

(* Convert MeshRegion object to ElementMesh object and smoothen mesh (improve quality). *)
meshTri = SmoothenMesh@ToElementMesh[region, "MeshOrder" -> 1]
meshTri["Wireframe"]

screenshot1

(* Convert triangular mesh to quadrilateral and smoothen it again. *)
meshQuad = SmoothenMesh@TriangleToQuadMesh@meshTri
meshQuad["Wireframe"]

screenshot2

(* Extrude 2D quadrilateral mesh to 3D hexahedral mesh (with 8 layers). *)
mesh3D = ExtrudeMesh[meshQuad, 1, 8];
mesh3D["Wireframe"["MeshElementStyle" -> FaceForm@LightBlue]]

screenshot3

(* Inspect the minimal, average and maximal quality of 3D mesh. *)
Through[{Min, Mean, Max}@Flatten[mesh3D["Quality"]]]
(* {0.47, 0.91, 0.99} *)

Contributing and feedback

Please use the repository "issues" page to submit bugs or feature ideas. If you find this package useful, feel free to send us feedback by email to github(at)c3m.si.

Pull requests to this repository are welcome. For major changes, please open an issue first to discuss what you would like to change. Instructions on building the .paclet file from source code can be found in CONTRIBUTING.md file.

License

MIT