Skip to content

Commit

Permalink
Merge pull request nschloe#206 from nschloe/more-test-files
Browse files Browse the repository at this point in the history
More test files
  • Loading branch information
nschloe authored Mar 7, 2018
2 parents b45e06f + d507cc2 commit 4d69ff6
Show file tree
Hide file tree
Showing 28 changed files with 538 additions and 571 deletions.
14 changes: 6 additions & 8 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
[MESSAGES CONTROL]

disable=
duplicate-code,
fixme,
invalid-name,
too-many-locals,
locally-disabled,
missing-docstring,
no-member,
too-many-arguments,
too-many-branches,
too-many-locals,
too-many-statements,
no-member,
bad-continuation,
unused-argument,
too-many-branches,
duplicate-code,
fixme,
wildcard-import,
locally-disabled
76 changes: 37 additions & 39 deletions meshio/ansys_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def _read_points(f, line, first_point_index_overall, last_point_index):
# read point data
total_bytes = dim * bytes_per_item * num_points
pts = numpy.fromstring(
f.read(total_bytes), dtype=dtype
).reshape((num_points, dim))
f.read(total_bytes), dtype=dtype
).reshape((num_points, dim))

# make sure that the data set is properly closed
_skip_close(f, 2)
Expand All @@ -104,14 +104,14 @@ def _read_cells(f, line):
element_type = a[4]

element_type_to_key_num_nodes = {
0: ('mixed', None),
1: ('triangle', 3),
2: ('tetra', 4),
3: ('quad', 4),
4: ('hexahedron', 8),
5: ('pyra', 5),
6: ('wedge', 6),
}
0: ('mixed', None),
1: ('triangle', 3),
2: ('tetra', 4),
3: ('quad', 4),
4: ('hexahedron', 8),
5: ('pyra', 5),
6: ('wedge', 6),
}

key, num_nodes_per_cell = \
element_type_to_key_num_nodes[element_type]
Expand Down Expand Up @@ -157,10 +157,10 @@ def _read_cells(f, line):
total_bytes = \
bytes_per_item * num_nodes_per_cell * num_cells
data = numpy.fromstring(
f.read(total_bytes),
count=(num_nodes_per_cell*num_cells),
dtype=dtype
).reshape((num_cells, num_nodes_per_cell))
f.read(total_bytes),
count=(num_nodes_per_cell*num_cells),
dtype=dtype
).reshape((num_cells, num_nodes_per_cell))

# make sure that the data set is properly closed
_skip_close(f, 2)
Expand All @@ -186,11 +186,11 @@ def _read_faces(f, line):
element_type = a[4]

element_type_to_key_num_nodes = {
0: ('mixed', None),
2: ('line', 2),
3: ('triangle', 3),
4: ('quad', 4)
}
0: ('mixed', None),
2: ('line', 2),
3: ('triangle', 3),
4: ('quad', 4)
}

key, num_nodes_per_cell = \
element_type_to_key_num_nodes[element_type]
Expand Down Expand Up @@ -326,10 +326,10 @@ def read(filename):
elif re.match('(|20|30)10', index):
# points
pts, first_point_index_overall, last_point_index = \
_read_points(
f, line, first_point_index_overall,
last_point_index
)
_read_points(
f, line, first_point_index_overall,
last_point_index
)

if pts is not None:
points.append(pts)
Expand Down Expand Up @@ -384,15 +384,13 @@ def read(filename):
return points, cells, point_data, cell_data, field_data


def write(
filename,
points,
cells,
point_data=None,
cell_data=None,
field_data=None,
write_binary=True,
):
def write(filename,
points,
cells,
point_data=None,
cell_data=None,
field_data=None,
write_binary=True):
point_data = {} if point_data is None else point_data
cell_data = {} if cell_data is None else cell_data
field_data = {} if field_data is None else field_data
Expand Down Expand Up @@ -433,13 +431,13 @@ def write(

# Write cells
meshio_to_ansys_type = {
'triangle': 1,
'tetra': 2,
'quad': 3,
'hexahedron': 4,
'pyra': 5,
'wedge': 6,
}
'triangle': 1,
'tetra': 2,
'quad': 3,
'hexahedron': 4,
'pyra': 5,
'wedge': 6,
}
first_index = 0
binary_dtypes = {
# numpy.int16 is not allowed
Expand Down
57 changes: 23 additions & 34 deletions meshio/dolfin_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,7 @@ def read(filename):
return points, cells, point_data, cell_data, field_data


def _write_mesh(
filename,
points,
cell_type,
cells
):
def _write_mesh(filename, points, cell_type, cells):
stripped_cells = {cell_type: cells[cell_type]}

dolfin = ET.Element(
Expand All @@ -136,19 +131,19 @@ def _write_mesh(
discarded_cells = list(cells.keys())
discarded_cells.remove(cell_type)
logging.warning(
'DOLFIN XML can only handle one cell type at a time. '
'Using %s, discarding %s.',
cell_type, ', '.join(discarded_cells)
)
'DOLFIN XML can only handle one cell type at a time. '
'Using %s, discarding %s.',
cell_type, ', '.join(discarded_cells)
)

dim = 2 if all(points[:, 2] == 0) else 3

mesh = ET.SubElement(
dolfin,
'mesh',
celltype=meshio_to_dolfin_type[cell_type],
dim=str(dim)
)
dolfin,
'mesh',
celltype=meshio_to_dolfin_type[cell_type],
dim=str(dim)
)
vertices = ET.SubElement(mesh, 'vertices', size=str(len(points)))

for k, point in enumerate(points):
Expand Down Expand Up @@ -192,23 +187,19 @@ def _numpy_type_to_dolfin_type(dtype):
return None


def _write_cell_data(
filename,
dim,
cell_data
):
def _write_cell_data(filename, dim, cell_data):
dolfin = ET.Element(
'dolfin',
nsmap={'dolfin': 'https://fenicsproject.org/'}
)

mesh_function = ET.SubElement(
dolfin,
'mesh_function',
type=_numpy_type_to_dolfin_type(cell_data.dtype),
dim=str(dim),
size=str(len(cell_data))
)
dolfin,
'mesh_function',
type=_numpy_type_to_dolfin_type(cell_data.dtype),
dim=str(dim),
size=str(len(cell_data))
)

for k, value in enumerate(cell_data):
ET.SubElement(
Expand All @@ -223,14 +214,12 @@ def _write_cell_data(
return


def write(
filename,
points,
cells,
point_data=None,
cell_data=None,
field_data=None
):
def write(filename,
points,
cells,
point_data=None,
cell_data=None,
field_data=None):
logging.warning(
'Dolfin\'s XML is a legacy format. Consider using XDMF instead.'
)
Expand Down
29 changes: 14 additions & 15 deletions meshio/exodus_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ def write(filename,
cells,
point_data=None,
cell_data=None,
field_data=None
):
field_data=None):
import netCDF4

point_data = {} if point_data is None else point_data
Expand Down Expand Up @@ -163,17 +162,17 @@ def write(filename,

# points
coor_names = rootgrp.createVariable(
'coor_names', 'S1', ('num_dim', 'len_string'),
)
'coor_names', 'S1', ('num_dim', 'len_string'),
)
coor_names.set_auto_mask(False)
coor_names[0, 0] = 'X'
coor_names[1, 0] = 'Y'
coor_names[2, 0] = 'Z'
data = rootgrp.createVariable(
'coord',
numpy_to_exodus_dtype[points.dtype],
('num_dim', 'num_nodes')
)
'coord',
numpy_to_exodus_dtype[points.dtype],
('num_dim', 'num_nodes')
)
data[:] = points.T

# cells
Expand All @@ -189,8 +188,8 @@ def write(filename,
rootgrp.createDimension(dim2, values.shape[1])
dtype = numpy_to_exodus_dtype[values.dtype]
data = rootgrp.createVariable(
'connect{}'.format(k+1), dtype, (dim1, dim2)
)
'connect{}'.format(k+1), dtype, (dim1, dim2)
)
data.elem_type = meshio_to_exodus_type[key]
# Exodus is 1-based
data[:] = values + 1
Expand All @@ -203,8 +202,8 @@ def write(filename,
rootgrp.createDimension('num_nod_var', num_nod_var)
# set names
point_data_names = rootgrp.createVariable(
'name_nod_var', 'S1', ('num_nod_var', 'len_string')
)
'name_nod_var', 'S1', ('num_nod_var', 'len_string')
)
point_data_names.set_auto_mask(False)
for k, name in enumerate(point_data.keys()):
for i, letter in enumerate(name):
Expand All @@ -215,9 +214,9 @@ def write(filename,
first_key = list(point_data.keys())[0]
dtype = numpy_to_exodus_dtype[point_data[first_key].dtype]
node_data = rootgrp.createVariable(
'vals_nod_var', dtype,
('time_step', 'num_nod_var', 'num_nodes')
)
'vals_nod_var', dtype,
('time_step', 'num_nod_var', 'num_nodes')
)
for k, (name, data) in enumerate(point_data.items()):
node_data[0, k] = data

Expand Down
Loading

0 comments on commit 4d69ff6

Please sign in to comment.