COMSOL text mesh (.mphtxt)
The COMSOL Multiphysics .mphtxt text mesh format (as handled by FEconv). ASCII, storing a version, tag/type name tables and one or more mesh objects; comments run from # to end of line.
| Format name | mphtxt |
| Extensions | .mphtxt |
| Read / Write | ✓ / ✓ |
| Extra dependencies | — |
Reading & writing
python
import meshioplusplus
mesh = meshioplusplus.read("mesh.mphtxt")
meshioplusplus.mphtxt.write("out.mphtxt", mesh)write takes no keyword arguments.
File structure
The whole file (after stripping #-comments) is read as a flat token stream:
- Version major, version minor (2 ints, discarded).
n_tagslength-prefixed tag-name strings (discarded).n_typeslength-prefixed type-name strings — this count is also the number of "object" records that follow.- For each object (only the first is actually parsed — the reader
breaks after it):- 3 ints (object type indices, discarded), a class-name string (expected
"Mesh"), an object-version int,sdim(spatial dimension),n_points,lowest(the file's lowest node index — normally 1, but not assumed to be). n_points * sdimfloats — node coordinates, row-major(n_points, sdim).n_eltypeselement-type blocks, each:- a COMSOL type-name string (
"tet","tri2", …); n_nodes,n_elem;n_elem * n_nodesints — connectivity, shifted by-lowestto become 0-based;n_par_per,n_par, thenn_par * n_par_perdiscarded parameter tokens;n_geom, thenn_geomints — one geometric entity index per element →cell_data["mphtxt:geom"];n_ud, thenn_ud * 2discarded up/down-pair ints.
- a COMSOL type-name string (
- 3 ints (object type indices, discarded), a class-name string (expected
Cell types
Hybrid (multi-type) meshes are supported. COMSOL ↔ meshio++ type map:
| COMSOL | meshio++ | COMSOL | meshio++ |
|---|---|---|---|
vtx | vertex | ||
edg | line | edg2 | line3 |
tri | triangle | tri2 | triangle6 |
quad | quad | quad2 | quad9 |
tet | tetra | tet2 | tetra10 |
prism | wedge | prism2 | wedge18 |
pyr | pyramid | ||
hex | hexahedron | hex2 | hexahedron27 |
Node-order permutation (COMSOL ↔ meshio++, self-inverse swaps — identity for every other type):
| type | permutation |
|---|---|
quad | [0, 1, 3, 2] |
hexahedron | [0, 1, 3, 2, 4, 5, 7, 6] |
Data mapping
cell_data["mphtxt:geom"]— per-element geometric entity index, one array per cell block.
Quirks & limitations
- Only the first mesh object in the file is read; subsequent objects are ignored entirely — a hard limitation for multi-mesh
.mphtxtfiles. - Element parameter values (
n_par) and up/down topology-linking pairs (n_ud) are always discarded on read and always written as empty/zero on write — any parametrization or entity-linking data COMSOL stores there does not round-trip. - The connectivity shift uses the file's actual
lowestvalue (not a hardcoded1), so files with an unusual lowest-index convention are handled correctly. - Unsupported cell types on write: the Python writer
warns and skips them; the C++ writer raisesWriteError, which forces the Python fallback.
Notes
- Fully handled by the C++ core.
- No reference fixture exists under
tests/meshes/mphtxt/; tests round-trip linear, second-order, and hybrid (tri_quad_mesh) meshes.