def write(filename, mesh):
if mesh.points.shape[<NUM_LIT:1>] == <NUM_LIT:2>:<EOL><INDENT>logging.warning(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL>mesh.points = numpy.column_stack(<EOL>[mesh.points[:, <NUM_LIT:0>], mesh.points[:, <NUM_LIT:1>], numpy.zeros(mesh.points.shape[<NUM_LIT:0>])]<EOL>)<EOL><DEDENT>opener = gzip.open if filename.endswith("<STR_LIT>") else open<EOL>with opener(filename, "<STR_LIT:wb>") as fh:<EOL><INDENT>fh.write(<EOL>"<STR_LIT:\n>".join(<EOL>[<EOL>"<STR_LIT:!>",<EOL>"<STR_LIT>".format(__version__),<EOL>"<STR_LIT>".format(__website__),<EOL>"<STR_LIT:!>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>" "<STR_LIT:!>",<EOL>"<STR_LIT:!>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT:!>" "<STR_LIT:\n>",<EOL>]<EOL>).encode("<STR_LIT:utf-8>")<EOL>)<EOL>fh.write("<STR_LIT>".encode("<STR_LIT:utf-8>"))<EOL>for k, x in enumerate(mesh.points):<EOL><INDENT>fh.write(<EOL>"<STR_LIT>".format(<EOL>k + <NUM_LIT:1>, x[<NUM_LIT:0>], x[<NUM_LIT:1>], x[<NUM_LIT:2>]<EOL>).encode("<STR_LIT:utf-8>")<EOL>)<EOL><DEDENT>meshio_to_permas_type = {<EOL>"<STR_LIT>": (<NUM_LIT:1>, "<STR_LIT>"),<EOL>"<STR_LIT>": (<NUM_LIT:2>, "<STR_LIT>"),<EOL>"<STR_LIT>": (<NUM_LIT:3>, "<STR_LIT>"),<EOL>"<STR_LIT>": (<NUM_LIT:4>, "<STR_LIT>"),<EOL>"<STR_LIT>": (<NUM_LIT:4>, "<STR_LIT>"),<EOL>"<STR_LIT>": (<NUM_LIT:8>, "<STR_LIT>"),<EOL>"<STR_LIT>": (<NUM_LIT:6>, "<STR_LIT>"),<EOL>"<STR_LIT>": (<NUM_LIT:5>, "<STR_LIT>"),<EOL>}<EOL>num_ele = <NUM_LIT:0><EOL>for meshio_type, cell in mesh.cells.items():<EOL><INDENT>numcells, num_local_nodes = cell.shape<EOL>permas_type = meshio_to_permas_type[meshio_type]<EOL>fh.write("<STR_LIT>".encode("<STR_LIT:utf-8>"))<EOL>fh.write(<EOL>"<STR_LIT>".format(<EOL>permas_type[<NUM_LIT:1>], permas_type[<NUM_LIT:1>]<EOL>).encode("<STR_LIT:utf-8>")<EOL>)<EOL>for k, c in enumerate(cell):<EOL><INDENT>form = "<STR_LIT>" + "<STR_LIT:U+0020>".join(num_local_nodes * ["<STR_LIT>"]) + "<STR_LIT:\n>"<EOL>fh.write(form.format(k + num_ele + <NUM_LIT:1>, *(c + <NUM_LIT:1>)).encode("<STR_LIT:utf-8>"))<EOL><DEDENT>num_ele += numcells<EOL><DEDENT>fh.write("<STR_LIT>".encode("<STR_LIT:utf-8>"))<EOL>fh.write("<STR_LIT>".encode("<STR_LIT:utf-8>"))<EOL>fh.write("<STR_LIT>".encode("<STR_LIT:utf-8>"))<EOL>elem_3D = ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]<EOL>elem_2D = ["<STR_LIT>", "<STR_LIT>"]<EOL>elem_1D = ["<STR_LIT>", "<STR_LIT>"]<EOL>fh.write("<STR_LIT>".encode("<STR_LIT:utf-8>"))<EOL>fh.write("<STR_LIT>".encode("<STR_LIT:utf-8>"))<EOL>fh.write("<STR_LIT>".encode("<STR_LIT:utf-8>"))<EOL>for meshio_type, cell in mesh.cells.items():<EOL><INDENT>permas_type = meshio_to_permas_type[meshio_type]<EOL>if permas_type[<NUM_LIT:1>] in elem_3D:<EOL><INDENT>fh.write(<EOL>"<STR_LIT>".format(<EOL>permas_type[<NUM_LIT:1>]<EOL>).encode("<STR_LIT:utf-8>")<EOL>)<EOL><DEDENT>elif permas_type[<NUM_LIT:1>] in elem_2D:<EOL><INDENT>fh.write(<EOL>(<EOL><NUM_LIT:12> * "<STR_LIT:U+0020>"<EOL>+ "<STR_LIT>".format(<EOL>permas_type[<NUM_LIT:1>], permas_type[<NUM_LIT:1>]<EOL>)<EOL>).encode("<STR_LIT:utf-8>")<EOL>)<EOL><DEDENT>else:<EOL><INDENT>assert permas_type[<NUM_LIT:1>] in elem_1D<EOL><DEDENT><DEDENT>fh.write("<STR_LIT>".encode("<STR_LIT:utf-8>"))<EOL>fh.write("<STR_LIT>".encode("<STR_LIT:utf-8>"))<EOL>for meshio_type, cell in mesh.cells.items():<EOL><INDENT>permas_type = meshio_to_permas_type[meshio_type]<EOL>if permas_type[<NUM_LIT:1>] in elem_2D:<EOL><INDENT>fh.write(<EOL>(<NUM_LIT:12> * "<STR_LIT:U+0020>" + "<STR_LIT>".format(permas_type[<NUM_LIT:1>])).encode("<STR_LIT:utf-8>")<EOL>)<EOL><DEDENT><DEDENT>fh.write(<EOL>
Writes PERMAS dat files, cf.
    http://www.intes.de # PERMAS-ASCII-file-format