From 7bcde23fdec1c8f344ca3cee4e86d4bed5b4770d Mon Sep 17 00:00:00 2001 From: Christophe Bourcier Date: Thu, 23 May 2024 16:35:42 +0200 Subject: [PATCH] [#spns_40523] improve test of .mesh format writing --- src/MEDLoader/MeshFormatWriter.cxx | 12 +-- src/MEDLoader/Swig/MEDWriterTest1.py.txt | 64 ---------------- ...riterTest1.py => MeshFormatWriterTest1.py} | 73 ++++++------------- src/MEDLoader/Swig/tests.set | 1 + 4 files changed, 31 insertions(+), 119 deletions(-) delete mode 100644 src/MEDLoader/Swig/MEDWriterTest1.py.txt rename src/MEDLoader/Swig/{MEDWriterTest1.py => MeshFormatWriterTest1.py} (53%) diff --git a/src/MEDLoader/MeshFormatWriter.cxx b/src/MEDLoader/MeshFormatWriter.cxx index 439cfa730..1ac57b20f 100644 --- a/src/MEDLoader/MeshFormatWriter.cxx +++ b/src/MEDLoader/MeshFormatWriter.cxx @@ -76,12 +76,12 @@ void MeshFormatWriter::setMEDFileDS(MEDCoupling::MEDFileData* mfd) if (fields) { - for (int i = 0; igetNumberOfFields(); i++ ) - { - MEDCoupling::MEDFileAnyTypeFieldMultiTS* field = fields->getFieldAtPos(i); - MEDCoupling::MEDFileFieldMultiTS * f = dynamic_cast(field); - _fields.push_back(f); - } + for (int i = 0; igetNumberOfFields(); i++ ) + { + MEDCoupling::MEDFileAnyTypeFieldMultiTS* field = fields->getFieldAtPos(i); + MEDCoupling::MEDFileFieldMultiTS * f = dynamic_cast(field); + _fields.push_back(f); + } } } diff --git a/src/MEDLoader/Swig/MEDWriterTest1.py.txt b/src/MEDLoader/Swig/MEDWriterTest1.py.txt deleted file mode 100644 index 6593a2e4b..000000000 --- a/src/MEDLoader/Swig/MEDWriterTest1.py.txt +++ /dev/null @@ -1,64 +0,0 @@ -# -*- coding: iso-8859-1 -*- -# Copyright (C) 2007-2024 CEA, EDF -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# Author : Anthony Geay (CEA/DEN) - -from MEDLoader import * -import unittest -from MEDLoaderDataForTest import MEDLoaderDataForTest,WriteInTmpDir - - -class MEDWriterTest1(unittest.TestCase): - @WriteInTmpDir - def testMesh1D(self): - # setup - mesh=MEDLoaderDataForTest.build1DMesh_1(); - mesh.checkConsistencyLight(); - - meshMEDFile = MEDFileUMesh() - meshMEDFile.setMeshAtLevel(0,mesh) - # create groups - grp0 = DataArrayInt([0,1]) - grp0.setName("grp0") - grp1 = DataArrayInt([0,1,2]) - grp1.setName("grp1") - grp2 = DataArrayInt([1,2,3]) - grp2.setName("grp2") - meshMEDFile.setGroupsAtLevel(0,[grp0,grp1,grp2]) - - ms=MEDFileMeshes() - ms.pushMesh(meshMEDFile) - - medFileData = MEDFileData() - medFileData.setMeshes(ms) - - tmpMeshWriter = MeshFormatWriter() - tmpMeshWriter.setMeshFileName("Meshfile") - tmpMeshWriter.setMEDFileDS(medFileData) - - - # meshMEDFile.write("/tmp/Mesh2.med",2) - # # Read MEDFile and test equality - # meshMEDFileRead = MEDFileMesh.New("/tmp/Mesh2.med") - # # assert groups - # self.assertEqual(meshMEDFileRead.getGroupArr(0,"grp0").getValues(), [0,1]); - - -if __name__ == '__main__': - unittest.main() \ No newline at end of file diff --git a/src/MEDLoader/Swig/MEDWriterTest1.py b/src/MEDLoader/Swig/MeshFormatWriterTest1.py similarity index 53% rename from src/MEDLoader/Swig/MEDWriterTest1.py rename to src/MEDLoader/Swig/MeshFormatWriterTest1.py index 807c0c87c..a94d592b7 100644 --- a/src/MEDLoader/Swig/MEDWriterTest1.py +++ b/src/MEDLoader/Swig/MeshFormatWriterTest1.py @@ -21,41 +21,11 @@ from MEDLoader import * import unittest from MEDLoaderDataForTest import MEDLoaderDataForTest,WriteInTmpDir - -class MEDWriterTest1(unittest.TestCase): - @WriteInTmpDir - def testMesh1D(self): - # setup - mesh=MEDLoaderDataForTest.build1DMesh_1(); - mesh.checkConsistencyLight(); - meshMEDFile = MEDFileUMesh() - meshMEDFile.setMeshAtLevel(0, mesh) - # create groups - grp0 = DataArrayInt([0, 1]) - grp0.setName("grp0") - grp1 = DataArrayInt([0, 1, 2]) - grp1.setName("grp1") - meshMEDFile.setGroupsAtLevel(0,[grp0, grp1]) - # write mesh file - ms=MEDFileMeshes() - ms.pushMesh(meshMEDFile) - medFileData = MEDFileData() - medFileData.setMeshes(ms) - tmpMeshWriter = MeshFormatWriter() - tmpMeshWriter.setMeshFileName("Meshfile") - tmpMeshWriter.setMEDFileDS(medFileData) - meshMEDFile.write("/tmp/Mesh1D.med",2) - # Read MEDFile and test equality - meshMEDFileRead = MEDFileMesh.New("/tmp/Mesh1D.med") - # assert groups - self.assertEqual(meshMEDFileRead.getGroupArr(0,"grp0").getValues(), [0, 1]) - self.assertEqual(meshMEDFileRead.getGroupArr(0,"grp1").getValues(), [0, 1, 2]) - -class MEDWriterTest2(unittest.TestCase): +class MeshFormatWriterTest2(unittest.TestCase): @WriteInTmpDir def testMesh2D(self): # setup - mesh=MEDLoaderDataForTest.build2DCurveMesh_1(); + mesh=MEDLoaderDataForTest.build2DMesh_2(); mesh.checkConsistencyLight(); meshMEDFile = MEDFileUMesh() meshMEDFile.setMeshAtLevel(0, mesh) @@ -65,22 +35,24 @@ class MEDWriterTest2(unittest.TestCase): grp1 = DataArrayInt([0, 1, 3, 2]) grp1.setName("grp1") meshMEDFile.setGroupsAtLevel(0,[grp0, grp1]) + # TODO: build 1D mesh and create groups of edges (in this 1D mesh) # write mesh file ms=MEDFileMeshes() ms.pushMesh(meshMEDFile) medFileData = MEDFileData() medFileData.setMeshes(ms) tmpMeshWriter = MeshFormatWriter() - tmpMeshWriter.setMeshFileName("Meshfile") + # TODO: remove /tmp here when the test is finalized + tmpMeshWriter.setMeshFileName("/tmp/Mesh2D.mesh") tmpMeshWriter.setMEDFileDS(medFileData) - meshMEDFile.write("/tmp/Mesh2D.med",2) - # Read MEDFile and test equality - meshMEDFileRead = MEDFileMesh.New("/tmp/Mesh2D.med") - # assert groups - self.assertEqual(meshMEDFileRead.getGroupArr(0,"grp0").getValues(), [0, 3]) - self.assertEqual(meshMEDFileRead.getGroupArr(0,"grp1").getValues(), [0, 1, 2, 3]) + tmpMeshWriter.write() + # TODO read .mesh file and test equality + #meshMEDFileRead = MEDFileMesh.New("/tmp/Mesh2D.med") + ## assert groups + #self.assertEqual(meshMEDFileRead.getGroupArr(0,"grp0").getValues(), [0, 3]) + #self.assertEqual(meshMEDFileRead.getGroupArr(0,"grp1").getValues(), [0, 1, 2, 3]) -class MEDWriterTest3(unittest.TestCase): +class MeshFormatWriterTest3(unittest.TestCase): @WriteInTmpDir def testMesh3D(self): # setup @@ -94,23 +66,26 @@ class MEDWriterTest3(unittest.TestCase): grp1 = DataArrayInt([0, 5, 7, 8]) grp1.setName("grp1") meshMEDFile.setGroupsAtLevel(0,[grp0, grp1]) + # TODO: build skin mesh (2D mesh) and create groups of faces (in this 2D mesh) # write mesh file ms=MEDFileMeshes() ms.pushMesh(meshMEDFile) medFileData = MEDFileData() medFileData.setMeshes(ms) tmpMeshWriter = MeshFormatWriter() - tmpMeshWriter.setMeshFileName("Meshfile") + # TODO: remove /tmp here when the test is finalized + tmpMeshWriter.setMeshFileName("/tmp/Mesh3D.mesh") tmpMeshWriter.setMEDFileDS(medFileData) - meshMEDFile.write("/tmp/Mesh3D.med",2) - # Read MEDFile and test equality - meshMEDFileRead = MEDFileMesh.New("/tmp/Mesh3D.med") - # assert groups - self.assertEqual(meshMEDFileRead.getGroupArr(0,"grp0").getValues(), [0, 1]) - self.assertEqual(meshMEDFileRead.getGroupArr(0,"grp1").getValues(), [0, 5, 7, 8]) - + tmpMeshWriter.write() + # TODO read .mesh file and test equality + #meshMEDFileRead = MEDFileMesh.New("/tmp/Mesh3D.med") + ## assert groups + #self.assertEqual(meshMEDFileRead.getGroupArr(0,"grp0").getValues(), [0, 1]) + #self.assertEqual(meshMEDFileRead.getGroupArr(0,"grp1").getValues(), [0, 5, 7, 8]) +# TODO: fix quadratic elements writing TRI6, QUAD8 and so on +# and add specific test cases if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() diff --git a/src/MEDLoader/Swig/tests.set b/src/MEDLoader/Swig/tests.set index fb403aa4e..2e58e3739 100644 --- a/src/MEDLoader/Swig/tests.set +++ b/src/MEDLoader/Swig/tests.set @@ -22,6 +22,7 @@ SET(BASE_TESTS MEDLoaderTest4.py MEDLoaderExamplesTest.py UsersGuideExamplesTest_ML.py + MeshFormatWriterTest1.py ) # if numpy is used -- 2.39.2