Modern API¶
The modern API is available through gmshparser.read() and gmshparser.api. It is immutable, tag-addressable, and intended for application code.
Top-level gmshparser.parse() continues to return the compatibility model. gmshparser.api.parse() is the modern alias.
Entry points¶
gmshparser.api.read(source, *, name=None)
¶
Read a path or text stream into the modern API.
Top-level :func:gmshparser.parse intentionally retains the mutable
compatibility API. Within :mod:gmshparser.api, :func:parse is an alias
for this modern reader.
Source code in gmshparser/api.py
gmshparser.api.parse(source, *, name=None)
¶
Parse into the modern model inside the explicit gmshparser.api namespace.
Key types¶
The module defines these tuple aliases:
type EntityKey = tuple[int, int]
type PhysicalGroupKey = tuple[int, int]
type PeriodicLinkKey = tuple[int, int]
Each key is (dimension, tag).
Mesh and metadata¶
gmshparser.api.Mesh
dataclass
¶
A read-only, Pythonic representation of a parsed Gmsh mesh.
Source code in gmshparser/api.py
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 | |
__str__ = __repr__
class-attribute
instance-attribute
¶
bounds
property
¶
Axis-aligned (minimum, maximum) Cartesian coordinates.
curves
property
¶
One-dimensional entities.
data_size
instance-attribute
¶
dimension
property
¶
Highest entity dimension present in the mesh.
element_types
property
¶
Element types present in the mesh.
elements
instance-attribute
¶
entities
instance-attribute
¶
is_ascii
instance-attribute
¶
name
instance-attribute
¶
nodes
instance-attribute
¶
periodic_links = field(default_factory=(lambda: PeriodicLinkCollection(())))
class-attribute
instance-attribute
¶
physical_groups
instance-attribute
¶
points
property
¶
Zero-dimensional entities.
surfaces
property
¶
Two-dimensional entities.
version
instance-attribute
¶
volumes
property
¶
Three-dimensional entities.
__init__(name, version, is_ascii, data_size, nodes, elements, entities, physical_groups, periodic_links=(lambda: PeriodicLinkCollection(()))())
¶
__repr__()
¶
Source code in gmshparser/api.py
entity(dimension, tag)
¶
from_legacy(mesh)
classmethod
¶
Build the modern model from the compatibility model.
Source code in gmshparser/api.py
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 | |
periodic_link(dimension, tag)
¶
physical_group(name_or_tag, *, dimension=None)
¶
Return a physical group by name or by tag and dimension.
Source code in gmshparser/api.py
Mesh.from_legacy() explicitly converts an existing compatibility mesh. Normal new code should call read() directly.
gmshparser.api.Version
dataclass
¶
A semantic MSH format version such as 4.1.
Source code in gmshparser/api.py
Element topology¶
gmshparser.api.ElementType
¶
Bases: IntEnum
Numeric element types from the Gmsh MSH specification.
Unknown numeric values remain representable as TYPE_<id> pseudo-members.
Their topology metadata is None and parsers reject them when metadata is
required to interpret a flat element record.
Source code in gmshparser/element_types.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
FIFTH_ORDER_LINE = 28
class-attribute
instance-attribute
¶
FIFTH_ORDER_TETRAHEDRON = 31
class-attribute
instance-attribute
¶
FIFTH_ORDER_TRIANGLE = 25
class-attribute
instance-attribute
¶
FIFTH_ORDER_TRIANGLE_INCOMPLETE = 24
class-attribute
instance-attribute
¶
FOURTH_ORDER_HEXAHEDRON = 93
class-attribute
instance-attribute
¶
FOURTH_ORDER_LINE = 27
class-attribute
instance-attribute
¶
FOURTH_ORDER_TETRAHEDRON = 30
class-attribute
instance-attribute
¶
FOURTH_ORDER_TRIANGLE = 23
class-attribute
instance-attribute
¶
FOURTH_ORDER_TRIANGLE_INCOMPLETE = 22
class-attribute
instance-attribute
¶
HEXAHEDRON = 5
class-attribute
instance-attribute
¶
LINE = 1
class-attribute
instance-attribute
¶
POINT = 15
class-attribute
instance-attribute
¶
PRISM = 6
class-attribute
instance-attribute
¶
PYRAMID = 7
class-attribute
instance-attribute
¶
QUADRANGLE = 3
class-attribute
instance-attribute
¶
SECOND_ORDER_HEXAHEDRON = 12
class-attribute
instance-attribute
¶
SECOND_ORDER_HEXAHEDRON_INCOMPLETE = 17
class-attribute
instance-attribute
¶
SECOND_ORDER_LINE = 8
class-attribute
instance-attribute
¶
SECOND_ORDER_PRISM = 13
class-attribute
instance-attribute
¶
SECOND_ORDER_PRISM_INCOMPLETE = 18
class-attribute
instance-attribute
¶
SECOND_ORDER_PYRAMID = 14
class-attribute
instance-attribute
¶
SECOND_ORDER_PYRAMID_INCOMPLETE = 19
class-attribute
instance-attribute
¶
SECOND_ORDER_QUADRANGLE = 10
class-attribute
instance-attribute
¶
SECOND_ORDER_QUADRANGLE_INCOMPLETE = 16
class-attribute
instance-attribute
¶
SECOND_ORDER_TETRAHEDRON = 11
class-attribute
instance-attribute
¶
SECOND_ORDER_TRIANGLE = 9
class-attribute
instance-attribute
¶
TETRAHEDRON = 4
class-attribute
instance-attribute
¶
THIRD_ORDER_HEXAHEDRON = 92
class-attribute
instance-attribute
¶
THIRD_ORDER_LINE = 26
class-attribute
instance-attribute
¶
THIRD_ORDER_TETRAHEDRON = 29
class-attribute
instance-attribute
¶
THIRD_ORDER_TRIANGLE = 21
class-attribute
instance-attribute
¶
THIRD_ORDER_TRIANGLE_INCOMPLETE = 20
class-attribute
instance-attribute
¶
TRIANGLE = 2
class-attribute
instance-attribute
¶
dimension
property
¶
Topological dimension, or None for an unknown type.
family
property
¶
Topological family, or None for an unknown type.
info
property
¶
Registered topology metadata, or None for an unknown type.
is_complete
property
¶
Whether all interior high-order nodes are present, or None.
is_high_order
property
¶
Whether this is a registered second- or higher-order element.
is_known
property
¶
Whether topology metadata is registered for this numeric type.
is_linear
property
¶
Whether this is a registered first-order element.
node_count
property
¶
Required number of nodes, or None for an unknown type.
order
property
¶
Polynomial order, or None for an unknown type.
primary_node_count
property
¶
Number of first-order corner nodes, or None when unknown.
_missing_(value)
classmethod
¶
Source code in gmshparser/element_types.py
gmshparser.api.ElementFamily
¶
Bases: StrEnum
Topological family of a Gmsh element.
Source code in gmshparser/element_types.py
HEXAHEDRON = 'hexahedron'
class-attribute
instance-attribute
¶
LINE = 'line'
class-attribute
instance-attribute
¶
POINT = 'point'
class-attribute
instance-attribute
¶
PRISM = 'prism'
class-attribute
instance-attribute
¶
PYRAMID = 'pyramid'
class-attribute
instance-attribute
¶
QUADRANGLE = 'quadrangle'
class-attribute
instance-attribute
¶
TETRAHEDRON = 'tetrahedron'
class-attribute
instance-attribute
¶
TRIANGLE = 'triangle'
class-attribute
instance-attribute
¶
gmshparser.api.ElementTypeInfo
dataclass
¶
Static topology metadata for one numeric Gmsh element type.
Source code in gmshparser/element_types.py
complete = True
class-attribute
instance-attribute
¶
dimension
instance-attribute
¶
family
instance-attribute
¶
is_high_order
property
¶
Whether this is a second- or higher-order element.
is_linear
property
¶
Whether this is a first-order element.
name
instance-attribute
¶
node_count
instance-attribute
¶
order
instance-attribute
¶
primary_node_count
instance-attribute
¶
__init__(name, family, dimension, order, node_count, primary_node_count, complete=True)
¶
ElementType is an IntEnum: known Gmsh IDs have descriptive names, while unknown numeric IDs remain representable as TYPE_<id> pseudo-members. Topology metadata is None for unknown values.
Collections¶
All modern collections preserve parser order. Node and element collections index by original Gmsh tag. Entity, physical-group, and periodic-link collections use (dimension, tag) keys.
gmshparser.api.NodeCollection
¶
Bases: _TaggedCollection[Node]
All nodes in a mesh, entity, physical group, or filtered selection.
Source code in gmshparser/api.py
coordinates
property
¶
Cartesian coordinates in collection order.
by_entity(dimension, tag)
¶
where(*, dimension=None, entity_tag=None, entity=None, parametric=None, physical_tag=None)
¶
Return nodes matching the supplied metadata.
Source code in gmshparser/api.py
gmshparser.api.ElementCollection
¶
Bases: _TaggedCollection[Element]
All elements in a mesh, entity, physical group, or filtered selection.
Source code in gmshparser/api.py
types
property
¶
Element types present in the collection.
by_entity(dimension, tag)
¶
by_type(element_type)
¶
where(*, element_type=None, dimension=None, entity_tag=None, entity=None, physical_tag=None)
¶
Return elements matching the supplied metadata.
Source code in gmshparser/api.py
gmshparser.api.EntityCollection
¶
Immutable entities keyed by (dimension, tag).
Source code in gmshparser/api.py
__slots__ = ('_items', '_by_key')
class-attribute
instance-attribute
¶
_by_key = {(entity.key): entity for entity in (self._items)}
instance-attribute
¶
_items = tuple(items)
instance-attribute
¶
keys
property
¶
Entity keys in parser order.
__contains__(value)
¶
__eq__(other)
¶
__getitem__(key)
¶
__hash__()
¶
__init__(items)
¶
__iter__()
¶
__len__()
¶
__repr__()
¶
by_dimension(dimension)
¶
get(key, default=None)
¶
where(*, dimension=None, element_type=None, has_nodes=None, has_elements=None, physical_tag=None)
¶
Return entities matching dimension, contents, or element type.
Source code in gmshparser/api.py
gmshparser.api.PhysicalGroupCollection
¶
Physical groups keyed by (dimension, tag) and unambiguous names.
Source code in gmshparser/api.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | |
__slots__ = ('_items', '_by_key', '_by_name')
class-attribute
instance-attribute
¶
_by_key = {(group.key): group for group in (self._items)}
instance-attribute
¶
_by_name = {}
instance-attribute
¶
_items = tuple(items)
instance-attribute
¶
keys
property
¶
Physical group keys in parser order.
names
property
¶
Declared physical group names in parser order.
__contains__(value)
¶
__getitem__(key)
¶
Source code in gmshparser/api.py
__init__(items)
¶
Source code in gmshparser/api.py
__iter__()
¶
__len__()
¶
__repr__()
¶
by_dimension(dimension)
¶
get(key, default=None)
¶
Return a physical group, or default only when the key is absent.
Ambiguous names still raise :class:KeyError; callers must use the
explicit (dimension, tag) key in that case.
Source code in gmshparser/api.py
where(*, dimension=None)
¶
Return physical groups of the selected dimension.
gmshparser.api.PeriodicLinkCollection
¶
Immutable periodic links keyed by their slave (dimension, tag).
Source code in gmshparser/api.py
__slots__ = ('_items', '_by_key')
class-attribute
instance-attribute
¶
_by_key = {(link.key): link for link in (self._items)}
instance-attribute
¶
_items = tuple(items)
instance-attribute
¶
keys
property
¶
Slave entity keys in parser order.
__contains__(value)
¶
__eq__(other)
¶
__getitem__(key)
¶
__hash__()
¶
__init__(items)
¶
__iter__()
¶
__len__()
¶
__repr__()
¶
by_dimension(dimension)
¶
get(key, default=None)
¶
where(*, dimension=None)
¶
Return links for one topological dimension.
Value objects¶
gmshparser.api.Node
dataclass
¶
An immutable mesh node.
coordinates always contains the Cartesian (x, y, z) values.
Additional coordinates from parametric MSH node blocks are available in
parametric_coordinates.
Source code in gmshparser/api.py
coordinates
instance-attribute
¶
dimension
instance-attribute
¶
entity_key
property
¶
Owning entity as (dimension, tag).
entity_tag
instance-attribute
¶
is_parametric
property
¶
Whether the node carries parametric coordinates.
parametric_coordinates = ()
class-attribute
instance-attribute
¶
physical_tags = ()
class-attribute
instance-attribute
¶
tag
instance-attribute
¶
x
property
¶
X coordinate.
y
property
¶
Y coordinate.
z
property
¶
Z coordinate.
__init__(tag, coordinates, dimension, entity_tag, parametric_coordinates=(), physical_tags=())
¶
gmshparser.api.Element
dataclass
¶
An immutable element with direct references to its nodes.
Source code in gmshparser/api.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
connectivity
property
¶
Alias for :attr:node_tags.
dimension
instance-attribute
¶
element_type
instance-attribute
¶
entity_key
property
¶
Owning entity as (dimension, tag).
entity_tag
instance-attribute
¶
expected_node_count
property
¶
Registered connectivity size, or None when the type is unknown.
family
property
¶
Topological element family, or None when the type is unknown.
info
property
¶
Registered topology metadata for this element type.
is_complete
property
¶
Whether all interior high-order nodes are present, or None.
is_high_order
property
¶
Whether this is a registered second- or higher-order element.
is_linear
property
¶
Whether this is a registered first-order element.
node_tags
property
¶
Connectivity as original Gmsh node tags.
nodes
instance-attribute
¶
order
property
¶
Polynomial order, or None when the type is unknown.
physical_tags = ()
class-attribute
instance-attribute
¶
primary_node_count
property
¶
Number of first-order corner nodes, or None when unknown.
tag
instance-attribute
¶
type
property
¶
Compatibility alias for :attr:element_type.
type_id
property
¶
Raw numeric Gmsh element type.
__init__(tag, element_type, nodes, dimension, entity_tag, physical_tags=())
¶
__iter__()
¶
gmshparser.api.Entity
dataclass
¶
A unified Gmsh entity containing both nodes and elements.
Source code in gmshparser/api.py
dimension
instance-attribute
¶
element_types
property
¶
Element types assigned to this entity.
elements
instance-attribute
¶
has_parametric_nodes
property
¶
Whether any node carries parametric coordinates.
key
property
¶
Entity key as (dimension, tag).
nodes
instance-attribute
¶
physical_tags = ()
class-attribute
instance-attribute
¶
tag
instance-attribute
¶
__init__(dimension, tag, nodes, elements, physical_tags=())
¶
gmshparser.api.PhysicalGroup
dataclass
¶
A named or anonymous physical group and its resolved mesh contents.
Source code in gmshparser/api.py
gmshparser.api.PeriodicLink
dataclass
¶
A periodic slave entity and its master-node correspondence.
Source code in gmshparser/api.py
affine_transform = ()
class-attribute
instance-attribute
¶
dimension
instance-attribute
¶
entity_tag
instance-attribute
¶
key
property
¶
Slave entity key as (dimension, tag).
master_entity_tag
instance-attribute
¶
master_node_tags
property
¶
Master node tags in file order.
node_pairs = ()
class-attribute
instance-attribute
¶
slave_node_tags
property
¶
Slave node tags in file order.