# -*- 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"""importosimportnumpyasnpfromMuscat.Bridges.CGNSBridgeimportMeshToCGNSfromMuscat.IO.WriterBaseimportWriterBaseasWriterBasefromMuscat.IO.IOFactoryimportRegisterWriterClassimportCGNS.MAPasCGM
[docs]classCGNSWriter(WriterBase):"""Class to writes a CGNS file on disk"""def__init__(self):super().__init__()self.canHandleTemporal=Trueself.canHandleAppend=Falsedef__str__(self):res="CGNSWriter"returnres
[docs]defWrite(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) """fromcopyimportdeepcopynewPyTree=MeshToCGNS(mesh,deepcopy(outputPyTree),updateZone=updateZone)iffileNameisNone:fileName=self.fileNameCGM.save(fileName,newPyTree)
[docs]defCheckIntegrity(GUI:bool=False):fromMuscat.Helpers.IO.TemporaryDirectoryimportTemporaryDirectorytempdir=TemporaryDirectory.GetTempPath()importMuscat.TestDataasMuscatTestDataimportMuscat.IO.UtReaderasURreader=UR.UtReader()reader.SetFileName(MuscatTestData.GetTestDataPath()+"UtExample/cube.ut")reader.ReadMetaData()reader.atIntegrationPoints=FalsemyMesh=reader.Read()myMesh.nodeFields["Nodes arange"]=np.arange(myMesh.GetNumberOfNodes(),dtype=float)myMesh.elemFields["Element arange"]=np.arange(myMesh.GetNumberOfElements(),dtype=float)fromMuscat.Containers.TagsimportTags################################### EXEMPLE SYNTAXE DU WRITERimportMuscat.IO.CGNSWriterasCWCgW=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