From 319801e3b9b48c53a142998fa6459a42a057293c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Fri, 2 Feb 2018 13:19:07 +0100 Subject: [PATCH 1/3] make sure to write gmsh region data --- meshio/gmsh_io.py | 60 ++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/meshio/gmsh_io.py b/meshio/gmsh_io.py index 143cf1e24..2b44096ed 100644 --- a/meshio/gmsh_io.py +++ b/meshio/gmsh_io.py @@ -263,9 +263,9 @@ def _read_cells(f, cells, int_size, is_ascii): has_additional_tag_data = True output_cell_tags[key] = {} if cell_tags[key].shape[1] > 0: - output_cell_tags[key]['physical'] = cell_tags[key][:, 0] + output_cell_tags[key]['gmsh:physical'] = cell_tags[key][:, 0] if cell_tags[key].shape[1] > 1: - output_cell_tags[key]['geometrical'] = cell_tags[key][:, 1] + output_cell_tags[key]['gmsh:geometrical'] = cell_tags[key][:, 1] return has_additional_tag_data, output_cell_tags @@ -436,7 +436,7 @@ def _write_nodes(fh, points, write_binary): return -def _write_elements(fh, cells, write_binary): +def _write_elements(fh, cells, tag_data, write_binary): # write elements fh.write('$Elements\n'.encode('utf-8')) # count all cells @@ -445,33 +445,16 @@ def _write_elements(fh, cells, write_binary): consecutive_index = 0 for cell_type, node_idcs in cells.items(): - # if cell_type in cell_data and cell_data[cell_type]: - # for key in cell_data[cell_type]: - # # assert data consistency - # assert len(cell_data[cell_type][key]) == len(node_idcs) - # # TODO assert that the data type is int - - # # if a tag is present, make sure that there are 'physical' and - # # 'geometrical' as well. - # if 'physical' not in cell_data[cell_type]: - # cell_data[cell_type]['physical'] = \ - # numpy.ones(len(node_idcs), dtype=numpy.int32) - # if 'geometrical' not in cell_data[cell_type]: - # cell_data[cell_type]['geometrical'] = \ - # numpy.ones(len(node_idcs), dtype=numpy.int32) - - # # 'physical' and 'geometrical' go first; this is what the gmsh - # # file format prescribes - # keywords = list(cell_data[cell_type].keys()) - # keywords.remove('physical') - # keywords.remove('geometrical') - # sorted_keywords = ['physical', 'geometrical'] + keywords - # fcd = numpy.column_stack([ - # cell_data[cell_type][key] for key in sorted_keywords - # ]) - # else: - # no cell data - fcd = numpy.empty([len(node_idcs), 0], dtype=numpy.int32) + tags = [] + for key in ['gmsh:physical', 'gmsh:geometrical']: + try: + tags.append(tag_data[cell_type][key]) + except KeyError: + pass + fcd = numpy.concatenate([tags]).T + + if not fcd: + fcd = numpy.empty((len(node_idcs), 0), dtype=numpy.int32) if write_binary: # header @@ -592,11 +575,24 @@ def write( if field_data: _write_physical_names(fh, field_data) + # Split the cell data: gmsh:physical and gmsh:geometrical are tags, the + # rest is actual cell data. + tag_data = {} + other_data = {} + for cell_type, a in cell_data.items(): + tag_data[cell_type] = {} + other_data[cell_type] = {} + for key, data in a.items(): + if key in ['gmsh:physical', 'gmsh:geometrical']: + tag_data[cell_type][key] = data + else: + other_data[cell_type][key] = data + _write_nodes(fh, points, write_binary) - _write_elements(fh, cells, write_binary) + _write_elements(fh, cells, tag_data, write_binary) for name, dat in point_data.items(): _write_data(fh, 'NodeData', name, dat, write_binary) - cell_data_raw = raw_from_cell_data(cell_data) + cell_data_raw = raw_from_cell_data(other_data) for name, dat in cell_data_raw.items(): _write_data(fh, 'ElementData', name, dat, write_binary) From bcbc183625e0059b992a7fdfb19787ab6ae1e030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Fri, 2 Feb 2018 13:26:06 +0100 Subject: [PATCH 2/3] version bump --- meshio/__about__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meshio/__about__.py b/meshio/__about__.py index 706f1a9aa..cf0c0a8d4 100644 --- a/meshio/__about__.py +++ b/meshio/__about__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -__version__ = '1.11.6' +__version__ = '1.11.7' __author__ = u'Nico Schlömer' __author_email__ = 'nico.schloemer@gmail.com' __copyright__ = \ From d4d147f4aa172254c3a295d976f84eaf991c7a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Fri, 2 Feb 2018 13:34:00 +0100 Subject: [PATCH 3/3] pylint fix --- meshio/gmsh_io.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/meshio/gmsh_io.py b/meshio/gmsh_io.py index 2b44096ed..590daa1e3 100644 --- a/meshio/gmsh_io.py +++ b/meshio/gmsh_io.py @@ -453,7 +453,8 @@ def _write_elements(fh, cells, tag_data, write_binary): pass fcd = numpy.concatenate([tags]).T - if not fcd: + # pylint: disable=len-as-condition + if len(fcd) == 0: fcd = numpy.empty((len(node_idcs), 0), dtype=numpy.int32) if write_binary: