Compatibility API¶
This page documents the original mutable parser-oriented model returned by gmshparser.parse(). It remains supported for existing applications. New code should normally use gmshparser.read() and the modern API.
Mesh¶
gmshparser.mesh.Mesh
¶
Mesh is the main compatibility class of the package.
Source code in gmshparser/mesh.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 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 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 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
ascii_ = True
instance-attribute
¶
element_entities_ = {}
instance-attribute
¶
element_physical_tags_ = {}
instance-attribute
¶
entity_physical_tags_ = {}
instance-attribute
¶
max_element_tag_ = 0
instance-attribute
¶
max_node_tag_ = 0
instance-attribute
¶
min_element_tag_ = 0
instance-attribute
¶
min_node_tag_ = 0
instance-attribute
¶
name_ = 'New Mesh'
instance-attribute
¶
node_entities_ = {}
instance-attribute
¶
number_of_element_entities_ = 0
instance-attribute
¶
number_of_elements_ = 0
instance-attribute
¶
number_of_node_entities_ = 0
instance-attribute
¶
number_of_nodes_ = 0
instance-attribute
¶
periodic_links_ = {}
instance-attribute
¶
physical_names_ = {}
instance-attribute
¶
precision_ = 8
instance-attribute
¶
version_ = None
instance-attribute
¶
version_major_ = None
instance-attribute
¶
version_minor_ = None
instance-attribute
¶
__init__()
¶
Source code in gmshparser/mesh.py
__str__()
¶
Source code in gmshparser/mesh.py
_normalize_tags(tags)
staticmethod
¶
add_element_block(dimension, entity_tag, element_type, elements)
¶
Build and store one compatibility element block from raw records.
Source code in gmshparser/mesh.py
add_element_entity(element_entity)
¶
Add an element block without overwriting other element types.
Source code in gmshparser/mesh.py
add_entity_physical_tags(dimension, tag, physical_tags)
¶
Add physical tags assigned to one elementary entity.
Source code in gmshparser/mesh.py
add_node_block(dimension, entity_tag, parametric_coordinate_count, nodes)
¶
Build and store one compatibility node block from raw records.
Source code in gmshparser/mesh.py
add_node_entity(node_entity)
¶
add_periodic_link(dimension, entity_tag, master_entity_tag, affine_transform, node_pairs)
¶
Store one periodic slave-to-master entity relation.
Source code in gmshparser/mesh.py
get_ascii()
¶
get_element_entities()
¶
get_element_entity(dim, tag, element_type=None)
¶
Get one element block by entity and optionally element type.
The two-argument form is retained for compatibility and succeeds when
exactly one element type exists for (dim, tag). Mixed entities require
element_type to avoid returning an arbitrary block.
Source code in gmshparser/mesh.py
get_element_physical_tags(element_tag)
¶
get_entity_physical_assignments()
¶
get_entity_physical_tags(dimension, tag)
¶
Return physical tags assigned to one elementary entity.
get_max_element_tag()
¶
get_max_node_tag()
¶
get_min_element_tag()
¶
get_min_node_tag()
¶
get_name()
¶
get_node_entities()
¶
get_node_entity(dim, tag)
¶
get_number_of_element_entities()
¶
get_number_of_elements()
¶
get_number_of_node_entities()
¶
get_number_of_nodes()
¶
get_periodic_link(dimension, entity_tag)
¶
Return (master_tag, affine_transform, node_pairs) for an entity.
get_periodic_links()
¶
Return periodic relations in parser order.
Source code in gmshparser/mesh.py
get_physical_name(dimension, tag)
¶
get_physical_names()
¶
get_precision()
¶
get_version()
¶
get_version_major()
¶
get_version_minor()
¶
has_element_entity(dim, tag, element_type=None)
¶
Return whether an element block exists for an entity.
When element_type is omitted, this reports whether any element block
exists for (dim, tag). Supplying it checks one exact block.
Source code in gmshparser/mesh.py
has_node_entity(dim, tag)
¶
has_periodic_link(dimension, entity_tag)
¶
Return whether a periodic relation exists for one slave entity.
set_ascii(is_ascii)
¶
set_element_physical_tags(element_tag, physical_tags)
¶
Store physical tags carried directly by one legacy element record.
Source code in gmshparser/mesh.py
set_entity_physical_tags(dimension, tag, physical_tags)
¶
Replace physical tags assigned to one elementary entity.
Source code in gmshparser/mesh.py
set_max_element_tag(max_element_tag)
¶
set_max_node_tag(max_node_tag)
¶
set_min_element_tag(min_element_tag)
¶
set_min_node_tag(min_node_tag)
¶
set_name(name)
¶
set_number_of_element_entities(number_of_element_entities)
¶
set_number_of_elements(number_of_elements)
¶
set_number_of_node_entities(number_of_node_entities)
¶
set_number_of_nodes(number_of_nodes)
¶
set_physical_name(dimension, tag, name)
¶
Store a physical group name without changing the legacy object model.
set_precision(precision)
¶
set_version(version)
¶
Set the MSH format version.
The compatibility mesh mirrors MSH entity blocks and exposes explicit get_*, set_*, and add_* methods.
import gmshparser
mesh = gmshparser.parse("mesh.msh")
print(mesh.get_name())
print(mesh.get_version())
print(mesh.get_ascii())
print(mesh.get_number_of_nodes())
print(mesh.get_number_of_elements())
Node blocks and nodes¶
gmshparser.node_entity.NodeEntity
¶
NodeEntity class holds nodes for one block.
Source code in gmshparser/node_entity.py
dimension_ = -1
instance-attribute
¶
nodes_ = {}
instance-attribute
¶
number_of_nodes_ = -1
instance-attribute
¶
number_of_parametric_coordinates_ = -1
instance-attribute
¶
tag_ = -1
instance-attribute
¶
__init__()
¶
add_node(node)
¶
get_dimension()
¶
get_node(tag)
¶
get_nodes()
¶
get_number_of_nodes()
¶
get_number_of_parametric_coordinates()
¶
get_tag()
¶
set_dimension(dimension)
¶
set_number_of_nodes(number_of_nodes)
¶
set_number_of_parametric_coordinates(npar)
¶
gmshparser.node.Node
¶
Node.
Source code in gmshparser/node.py
for entity in mesh.get_node_entities():
print(entity.get_dimension(), entity.get_tag())
for node in entity.get_nodes():
print(node.get_tag(), node.get_coordinates())
Legacy node coordinate tuples may contain Cartesian coordinates followed by parametric coordinates.
Element blocks and elements¶
gmshparser.element_entity.ElementEntity
¶
ElementEntity class holds elements for one block.
Source code in gmshparser/element_entity.py
dimension_ = -1
instance-attribute
¶
element_type_ = -1
instance-attribute
¶
elements_ = {}
instance-attribute
¶
number_of_elements_ = -1
instance-attribute
¶
tag_ = -1
instance-attribute
¶
__init__()
¶
__str__()
¶
Source code in gmshparser/element_entity.py
add_element(element)
¶
get_dimension()
¶
get_element(tag)
¶
get_element_type()
¶
get_elements()
¶
get_number_of_elements()
¶
get_tag()
¶
set_dimension(dimension)
¶
set_element_type(element_type)
¶
set_number_of_elements(number_of_elements)
¶
gmshparser.element.Element
¶
Element.
Source code in gmshparser/element.py
Element blocks are identified by dimension, elementary entity tag, and element type. Existing two-argument lookup remains available when an entity contains one element type:
For a mixed entity, provide the element type explicitly:
from gmshparser import ElementType
triangles = mesh.get_element_entity(2, 1, ElementType.TRIANGLE)
quadrangles = mesh.get_element_entity(2, 1, ElementType.QUADRANGLE)
The two-argument form raises KeyError for an ambiguous mixed entity rather than returning an arbitrary block.
Format versions¶
gmshparser.version_manager.MshFormatVersion
¶
Bases: Enum
Enumeration of supported MSH format versions.
Source code in gmshparser/version_manager.py
MSH_1_0 = (1, 0)
class-attribute
instance-attribute
¶
MSH_2_0 = (2, 0)
class-attribute
instance-attribute
¶
MSH_2_1 = (2, 1)
class-attribute
instance-attribute
¶
MSH_2_2 = (2, 2)
class-attribute
instance-attribute
¶
MSH_4_0 = (4, 0)
class-attribute
instance-attribute
¶
MSH_4_1 = (4, 1)
class-attribute
instance-attribute
¶
major = major
instance-attribute
¶
minor = minor
instance-attribute
¶
version_number
property
¶
Return version as float (e.g., 4.1).
__init__(major, minor)
¶
__repr__()
¶
gmshparser.version_manager.VersionManager
¶
Manager for MSH format version detection and validation.
Source code in gmshparser/version_manager.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 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 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 | |
RECOGNIZED_VERSIONS = [MshFormatVersion.MSH_1_0, MshFormatVersion.MSH_2_0, MshFormatVersion.MSH_2_1, MshFormatVersion.MSH_2_2, MshFormatVersion.MSH_4_0, MshFormatVersion.MSH_4_1]
class-attribute
instance-attribute
¶
SUPPORTED_VERSIONS = [MshFormatVersion.MSH_1_0, MshFormatVersion.MSH_2_0, MshFormatVersion.MSH_2_1, MshFormatVersion.MSH_2_2, MshFormatVersion.MSH_4_0, MshFormatVersion.MSH_4_1]
class-attribute
instance-attribute
¶
get_supported_versions_list()
classmethod
¶
Get list of supported version strings.
Returns:
| Type | Description |
|---|---|
List[str]
|
List of supported version strings |
Source code in gmshparser/version_manager.py
get_version_enum(major, minor)
classmethod
¶
Get MshFormatVersion enum from major and minor version numbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
major
|
int
|
Major version number |
required |
minor
|
int
|
Minor version number |
required |
Returns:
| Type | Description |
|---|---|
MshFormatVersion
|
Version enum if found |
Raises:
| Type | Description |
|---|---|
ValueError
|
If version is not recognized |
Source code in gmshparser/version_manager.py
is_supported(version)
classmethod
¶
Check if a version is supported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
MshFormatVersion
|
Version to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if version is supported |
Source code in gmshparser/version_manager.py
is_version_1(version)
classmethod
¶
Check if version is in the 1.x series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
MshFormatVersion
|
Version to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if version is 1.x |
Source code in gmshparser/version_manager.py
is_version_2(version)
classmethod
¶
Check if version is in the 2.x series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
MshFormatVersion
|
Version to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if version is 2.x |
Source code in gmshparser/version_manager.py
is_version_4(version)
classmethod
¶
Check if version is in the 4.x series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
MshFormatVersion
|
Version to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if version is 4.x |
Source code in gmshparser/version_manager.py
parse_version(version_str)
staticmethod
¶
Parse version string to major and minor version numbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version_str
|
str
|
Version string (e.g., "4.1" or "2.2") |
required |
Returns:
| Type | Description |
|---|---|
Tuple[int, int]
|
Tuple of (major, minor) version numbers |
Raises:
| Type | Description |
|---|---|
ValueError
|
If version string cannot be parsed |
Source code in gmshparser/version_manager.py
validate_version(version_str)
classmethod
¶
Parse and validate a version string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version_str
|
str
|
Version string to validate |
required |
Returns:
| Type | Description |
|---|---|
MshFormatVersion
|
Validated version enum |
Raises:
| Type | Description |
|---|---|
ValueError
|
If version is not recognized or not supported |
Source code in gmshparser/version_manager.py
These classes support parser version detection and validation. The modern application model exposes the smaller immutable gmshparser.api.Version value.
Migration¶
Equivalent modern access is flatter:
modern = gmshparser.read("mesh.msh")
print(modern.name)
print(modern.version)
print(len(modern.nodes))
print(len(modern.elements))
See Migrating from the Compatibility API for a method-by-method mapping.