Source code for Muscat.IO.UniversalWriter

# -*- coding: utf-8 -*-
#
# This file is subject to the terms and conditions defined in
# file 'LICENSE.txt', which is part of this source code package.
#

"""Universal file writer
"""


[docs]def InitAllWriters(): from Muscat.IO.IOFactory import InitAllWriters as IAW IAW()
[docs]def WriteMesh(filename, outmesh, binary=None, writer=None): # pragma: no cover from Muscat.IO.IOFactory import CreateWriter if writer is None: writer = CreateWriter("." + filename.split(".")[-1]) writer.SetFileName(filename) if not (binary is None): writer.SetBinary(binary) writer.Open() PointFields = None PointFieldsNames = None if hasattr(outmesh, "nodeFields"): PointFieldsNames = list(outmesh.nodeFields.keys()) PointFields = list(outmesh.nodeFields.values()) CellFields = None CellFieldsNames = None if hasattr(outmesh, "elemFields"): CellFieldsNames = list(outmesh.elemFields.keys()) CellFields = list(outmesh.elemFields.values()) writer.Write(outmesh, PointFieldsNames=PointFieldsNames, PointFields=PointFields, CellFieldsNames=CellFieldsNames, CellFields=CellFields) writer.Close()
[docs]def CheckIntegrity(GUI: bool = False) -> str: from Muscat.Helpers.CheckTools import MustFailFunction from Muscat.IO.IOFactory import CreateWriter, RegisterWriterClass InitAllWriters() print(CreateWriter(".geof")) print(CreateWriter(".msh")) print(CreateWriter(".mesh")) print(CreateWriter(".xdmf")) MustFailFunction(CreateWriter, "toto") # normally this class must have the same API as # from Muscat.IO.WriterBase import WriterBase as WriterBase class MyCustomWriter(WriterBase): pass RegisterWriterClass(".myDummyExtension", MyCustomWriter, withError=False) print(CreateWriter(".myDummyExtension")) return "ok"
if __name__ == "__main__": print((CheckIntegrity())) # pragma: no cover