def write_out(self):
    (name, extn) = os.path.splitext(self.outf)
    parallel = (extn == '.pvtu')
    parts = defaultdict(list)
    for (mk, sk) in zip(self.mesh_inf, self.soln_inf):
        prt = mk.split('_')[(- 1)]
        pfn = ('{0}_{1}.vtu'.format(name, prt) if parallel else self.outf)
        parts[pfn].append((mk, sk))
    write_s_to_fh = (lambda s: fh.write(s.encode('utf-8')))
    for (pfn, misil) in parts.items():
        with open(pfn, 'wb') as fh:
            write_s_to_fh('<?xml version="1.0" ?>\n<VTKFile byte_order="LittleEndian" type="UnstructuredGrid" version="0.1">\n<UnstructuredGrid>\n')
            off = 0
            for (mk, sk) in misil:
                off = self._write_serial_header(fh, mk, off)
            write_s_to_fh('</UnstructuredGrid>\n<AppendedData encoding="raw">\n_')
            for (mk, sk) in misil:
                self._write_data(fh, mk, sk)
            write_s_to_fh('\n</AppendedData>\n</VTKFile>')
    if parallel:
        with open(self.outf, 'wb') as fh:
            write_s_to_fh('<?xml version="1.0" ?>\n<VTKFile byte_order="LittleEndian" type="PUnstructuredGrid" version="0.1">\n<PUnstructuredGrid>\n')
            self._write_parallel_header(fh)
            for pfn in parts:
                write_s_to_fh('<Piece Source="{0}"/>\n'.format(os.path.basename(pfn)))
            write_s_to_fh('</PUnstructuredGrid>\n</VTKFile>\n')
def write_out(self):
    (name, extn) = os.path.splitext(self.outf)
    parallel = (extn == '.pvtu')
    parts = defaultdict(list)
    for (mk, sk) in zip(self.mesh_inf, self.soln_inf):
        prt = mk.split('_')[(- 1)]
        pfn = ('{0}_{1}.vtu'.format(name, prt) if parallel else self.outf)
        parts[pfn].append((mk, sk))
    write_s_to_fh = (lambda s: fh.write(s.encode('utf-8')))
    for (pfn, misil) in parts.items():
        with open(pfn, 'wb') as fh:
            write_s_to_fh('<?xml version="1.0" ?>\n<VTKFile byte_order="LittleEndian" type="UnstructuredGrid" version="0.1">\n<UnstructuredGrid>\n')
            off = 0
            for (mk, sk) in misil:
                off = self._write_serial_header(fh, mk, off)
            write_s_to_fh('</UnstructuredGrid>\n<AppendedData encoding="raw">\n_')
            for (mk, sk) in misil:
                self._write_data(fh, mk, sk)
            write_s_to_fh('\n</AppendedData>\n</VTKFile>')
    if parallel:
        with open(self.outf, 'wb') as fh:
            write_s_to_fh('<?xml version="1.0" ?>\n<VTKFile byte_order="LittleEndian" type="PUnstructuredGrid" version="0.1">\n<PUnstructuredGrid>\n')
            self._write_parallel_header(fh)
            for pfn in parts:
                write_s_to_fh('<Piece Source="{0}"/>\n'.format(os.path.basename(pfn)))
            write_s_to_fh('</PUnstructuredGrid>\n</VTKFile>\n')