Use a regex to find the number of nodes from element name

Closes #177998

authorDenis Laxalde <denis.laxalde@logilab.fr>
changesetb97fbb21a227
branchdefault
phasepublic
hiddenno
parent revision#ee654a4f71be Add a __pkginfo__.py (closes #127412)
child revision#566befe060af Move __pkginfo__.py at project's root, #f135dd39ec15 Move __pkginfo__.py at project's root
files modified by this revision
libmed/mesh.py
# HG changeset patch
# User Denis Laxalde <denis.laxalde@logilab.fr>
# Date 1379672700 -7200
# Fri Sep 20 12:25:00 2013 +0200
# Node ID b97fbb21a2273a27365323d2908e241d272063fa
# Parent ee654a4f71be661c705dc17dcb4a0ce4d39b9d47
Use a regex to find the number of nodes from element name

Closes #177998

diff --git a/libmed/mesh.py b/libmed/mesh.py
@@ -17,21 +17,22 @@
1  # with python-libmed.  If not, see <http://www.gnu.org/licenses/>.
2 
3  """
4  MED: Meshes definition and handling interface.
5  """
6 +import re
7 +
8  from base import MEDFileComponents
9  import _mesh
10  from _utils import MEDError
11 
12  def nnodes_elements(etype):
13      """ Number of nodes by element type. """
14 -    try:
15 -        return {'quad4': 4,
16 -                'tria3': 3,
17 -                'hexa8': 8}[etype.lower()]
18 -    except KeyError:
19 +    m = re.match(r'[a-z]+(\d+)', etype)
20 +    if m:
21 +        return int(m.group(1))
22 +    else:
23          raise ValueError('Unsupported element type %s' % etype)
24 
25  class MEDMesh(MEDFileComponents):
26      """
27      Mesh in a MED file.