Parsers API¶
AbstractParser¶
Base class for all parsers.
gmshparser.abstract_parser.AbstractParser
¶
Bases: object
AbstractParser is a superclass of all other parsers.
All other parsers must inheric AbstractParser and implement their own
static methods parse and get_section_name.
The first argument of the parse is a mutable mesh object, which
parser modifies in-place. The second argument is io, where parser reads
the text file line by line using readline(). Parser must stop reading the
file to the section end mark, e.g. $EndNodes in the case of parser
which is responsible to parse nodes, starting from a section start mark
$Nodes.
Another must-to-implement static method is get_section_name(), which
must return the name of the line where this parser should activate. For
example, if the section name is $Nodes, then get_section_name()
must return string $Nodes.
Source code in gmshparser/abstract_parser.py
MeshFormatParser¶
Parses $MeshFormat section.
NodesParser¶
Parses $Nodes section (MSH 2.x and 4.x).
ElementsParser¶
Parses $Elements section (MSH 2.x and 4.x).
V1 Parsers¶
NodesParserV1¶
Parses $NOD section (MSH 1.0).
ElementsParserV1¶
Parses $ELM section (MSH 1.0).
MainParser¶
Coordinates all parsers and handles version detection.
gmshparser.main_parser.MainParser
¶
Bases: AbstractParser
The main parser class, using other parsers.
This parser automatically detects the MSH format version and selects the appropriate parsers for that version.
Source code in gmshparser/main_parser.py
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 | |
__init__(parsers=None)
¶
Initialize the main parser.
Parameters¶
parsers : list, optional List of parser classes to use. If None, parsers will be selected automatically based on the detected version.
Source code in gmshparser/main_parser.py
parse(mesh, io)
¶
Parse the mesh file.
The parser first reads the MeshFormat section to detect the version, then selects the appropriate parsers for that version.
For MSH 1.0 files (which don't have $MeshFormat), version is detected from the $NOD section name.
Parameters¶
mesh : Mesh Mesh object to populate io : TextIO Input stream to read from
Raises¶
ValueError If the version is not supported or if parsing fails