Source code for Muscat.IO.CGNSWriter

# -*- 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.
#

"""CGNS file writer
"""
import os
import numpy as np

from Muscat.Bridges.CGNSBridge import MeshToCGNS
from Muscat.IO.WriterBase import WriterBase as WriterBase
from Muscat.IO.IOFactory import RegisterWriterClass
import CGNS.MAP as CGM


[docs] class CGNSWriter(WriterBase): """Class to writes a CGNS file on disk""" def __init__(self): super().__init__() self.canHandleTemporal = True self.canHandleAppend = False def __str__(self): res = "CGNSWriter" return res
[docs] def Write(self, mesh, fileName=None, outputPyTree=None, PointFields=None, PointFieldsNames=None, GridFieldsNames=None, GridFields=None, updateZone=False): """Function to write a CGNS File on disk Parameters ---------- mesh : Mesh support of the data to be written fileName : str filename of the file to be read outpuPyTree : list existing pyTree in which the data structure in mesh will be appended updateZone : bool or str, only with outputPyTree if False: data are added to a new CGNS base if True: all zones pre existing in outPyTree base are updated (replace all structured zones with one unstructured zone, or update unique zone) if zoneName: only zone with zoneName is updated (for unstructured multi zones computation) """ from copy import deepcopy newPyTree = MeshToCGNS(mesh, deepcopy(outputPyTree), updateZone=updateZone) if fileName is None: fileName = self.fileName CGM.save(fileName, newPyTree)
[docs] def CheckIntegrity(GUI: bool = False): from Muscat.Helpers.IO.TemporaryDirectory import TemporaryDirectory tempdir = TemporaryDirectory.GetTempPath() import Muscat.TestData as MuscatTestData import Muscat.IO.UtReader as UR reader = UR.UtReader() reader.SetFileName(MuscatTestData.GetTestDataPath() + "UtExample/cube.ut") reader.ReadMetaData() reader.atIntegrationPoints = False myMesh = reader.Read() myMesh.nodeFields["Nodes arange"] = np.arange(myMesh.GetNumberOfNodes(), dtype=float) myMesh.elemFields["Element arange"] = np.arange(myMesh.GetNumberOfElements(), dtype=float) from Muscat.Containers.Tags import Tags ################################## # EXEMPLE SYNTAXE DU WRITER import Muscat.IO.CGNSWriter as CW CgW = CW.CGNSWriter() print(CgW) CgW.Write(mesh=myMesh, fileName=tempdir + os.sep + "toto.cgns") ################################## return "ok"
RegisterWriterClass(".cgns", CGNSWriter) if __name__ == "__main__": print(CheckIntegrity(GUI=True)) # pragma: no cover