From 9ffe8108c5ea9781f572fa6b26e1ee13ec0f3b0c Mon Sep 17 00:00:00 2001 From: Christophe Bourcier Date: Fri, 26 May 2023 14:48:43 +0200 Subject: [PATCH] Fix the filter ELGA field to surface (cell averaged) and add a test --- CTestTestfileInstall.cmake | 1 + src/Plugins/GaussToCell/plugin/CMakeLists.txt | 4 + .../GaussToCellModule/vtkGaussToCell.cxx | 2 +- .../GaussToCell/plugin/Test/CMakeLists.txt | 38 +++++++++ .../plugin/Test/CTestTestfileInstall.cmake | 31 +++++++ .../{script => plugin/Test}/PG_3D.med | Bin .../plugin/Test/test_GaussToCell.py | 79 ++++++++++++++++++ src/Plugins/GaussToCell/plugin/Test/tests.set | 27 ++++++ 8 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 src/Plugins/GaussToCell/plugin/Test/CMakeLists.txt create mode 100644 src/Plugins/GaussToCell/plugin/Test/CTestTestfileInstall.cmake rename src/Plugins/GaussToCell/{script => plugin/Test}/PG_3D.med (100%) create mode 100644 src/Plugins/GaussToCell/plugin/Test/test_GaussToCell.py create mode 100644 src/Plugins/GaussToCell/plugin/Test/tests.set diff --git a/CTestTestfileInstall.cmake b/CTestTestfileInstall.cmake index 1bb7e38f..7c4715b2 100644 --- a/CTestTestfileInstall.cmake +++ b/CTestTestfileInstall.cmake @@ -20,3 +20,4 @@ SUBDIRS(MEDReader) SUBDIRS(MEDWriter) SUBDIRS(VoroGauss) +SUBDIRS(GaussToCell) diff --git a/src/Plugins/GaussToCell/plugin/CMakeLists.txt b/src/Plugins/GaussToCell/plugin/CMakeLists.txt index 53ecae5d..7bc8eb30 100644 --- a/src/Plugins/GaussToCell/plugin/CMakeLists.txt +++ b/src/Plugins/GaussToCell/plugin/CMakeLists.txt @@ -59,3 +59,7 @@ install(TARGETS GaussToCellPlugin LIBRARY DESTINATION lib/paraview ARCHIVE DESTINATION lib/paraview ) + +IF(SALOME_BUILD_TESTS) + ADD_SUBDIRECTORY(Test) +ENDIF(SALOME_BUILD_TESTS) diff --git a/src/Plugins/GaussToCell/plugin/GaussToCellModule/vtkGaussToCell.cxx b/src/Plugins/GaussToCell/plugin/GaussToCellModule/vtkGaussToCell.cxx index 2232ad95..115ee536 100644 --- a/src/Plugins/GaussToCell/plugin/GaussToCellModule/vtkGaussToCell.cxx +++ b/src/Plugins/GaussToCell/plugin/GaussToCellModule/vtkGaussToCell.cxx @@ -90,7 +90,7 @@ vtkStandardNewMacro(vtkGaussToCell) vtkInformationDoubleVectorKey *GetMEDReaderMetaDataIfAny() { - static const char ZE_KEY[]="vtkMEDReader::GAUSS_DATA"; + static const char ZE_KEY[]="vtkFileSeriesGroupReader::GAUSS_DATA"; MEDCoupling::GlobalDict *gd(MEDCoupling::GlobalDict::GetInstance()); if(!gd->hasKey(ZE_KEY)) return 0; diff --git a/src/Plugins/GaussToCell/plugin/Test/CMakeLists.txt b/src/Plugins/GaussToCell/plugin/Test/CMakeLists.txt new file mode 100644 index 00000000..3f5d70f6 --- /dev/null +++ b/src/Plugins/GaussToCell/plugin/Test/CMakeLists.txt @@ -0,0 +1,38 @@ +# Copyright (C) 2012-2022 CEA/DEN, EDF R&D +# +# 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 : Yoann Audouin (EDF) + +INCLUDE(tests.set) + +SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env) + +FOREACH(tfile ${TEST_NAMES}) + SET(TEST_NAME ${COMPONENT_NAME}_${tfile}) + ADD_TEST(${TEST_NAME} python ${CMAKE_CURRENT_SOURCE_DIR}/${tfile}.py) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES ENVIRONMENT "${tests_env}") +ENDFOREACH() + +# Application tests + +SET(TEST_INSTALL_DIRECTORY ${SALOME_INSTALL_SCRIPT_SCRIPTS}/test/GaussToCell) +INSTALL(FILES ${all_src} tests.set DESTINATION ${TEST_INSTALL_DIRECTORY}) + +INSTALL(FILES CTestTestfileInstall.cmake + DESTINATION ${TEST_INSTALL_DIRECTORY} + RENAME CTestTestfile.cmake) diff --git a/src/Plugins/GaussToCell/plugin/Test/CTestTestfileInstall.cmake b/src/Plugins/GaussToCell/plugin/Test/CTestTestfileInstall.cmake new file mode 100644 index 00000000..e3f1dad1 --- /dev/null +++ b/src/Plugins/GaussToCell/plugin/Test/CTestTestfileInstall.cmake @@ -0,0 +1,31 @@ +# Copyright (C) 2015-2022 CEA/DEN, EDF R&D +# +# 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 +# + +SET(COMPONENT_NAME PARAVIS) + +INCLUDE(tests.set) + +FOREACH(tfile ${TEST_NAMES}) + SET(TEST_NAME ${COMPONENT_NAME}_${tfile}) + ADD_TEST(${TEST_NAME} python ${tfile}.py) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES + LABELS "${COMPONENT_NAME}" + TIMEOUT ${TIMEOUT} + ) +ENDFOREACH() diff --git a/src/Plugins/GaussToCell/script/PG_3D.med b/src/Plugins/GaussToCell/plugin/Test/PG_3D.med similarity index 100% rename from src/Plugins/GaussToCell/script/PG_3D.med rename to src/Plugins/GaussToCell/plugin/Test/PG_3D.med diff --git a/src/Plugins/GaussToCell/plugin/Test/test_GaussToCell.py b/src/Plugins/GaussToCell/plugin/Test/test_GaussToCell.py new file mode 100644 index 00000000..8436def8 --- /dev/null +++ b/src/Plugins/GaussToCell/plugin/Test/test_GaussToCell.py @@ -0,0 +1,79 @@ +# Copyright (C) 2017-2022 CEA/DEN, EDF R&D +# +# 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 + +from os import path, remove +#### import the simple module from the paraview +from paraview.simple import * +#from pvsimple import * +from vtk.util import numpy_support +import numpy as np + +from medcoupling import * +import MEDLoader as ml +from MEDLoader import * + +import inspect +data_dir = os.path.dirname(inspect.getfile(lambda: None)) + +def MyAssert(clue): + if not clue: + raise RuntimeError("Assertion failed !") + + +def test_fields(result, ref, field_name): + """ + Test fields content of result from VoroGauss filter + """ + ds0 = servermanager.Fetch(result) + block = ds0.GetBlock(0) + + data = numpy_support.vtk_to_numpy(block.GetCellData().GetArray(field_name)) + + MyAssert(np.allclose(data, ref)) + + +### +# Test of PG_3D.med +### +# create a new 'MED Reader' +file_name = os.path.join(data_dir, "PG_3D.med") +pG_3Dmed = MEDReader(registrationName='PG_3D.med', FileNames=file_name) +pG_3Dmed.FieldsStatus = ['TS0/Extruded/ComSup0/Extruded@@][@@P0', + 'TS0/Extruded/ComSup0/MyFieldPG@@][@@GAUSS'] +print("Testing {}".format(file_name)) +pG_3Dmed.UpdatePipeline() + +fields = [('MyFieldPG_avg', + list(range(3, 445, 7)) + ), + ('MyFieldPG_min', + list(range(0, 442, 7)) + ), + ('MyFieldPG_max', + list(range(6, 448, 7)) + ) + ] + +# create a new 'ELGA field To Surface' +eELGAfieldToSurfacecellaveraged1 = ELGAfieldToSurfacecellaveraged(registrationName='ELGAfieldToSurface2', Input=pG_3Dmed) +eELGAfieldToSurfacecellaveraged1.UpdatePipeline() + +for field_name, ref in fields: + print(" ~> Field check for field {}".format(field_name)) + test_fields(eELGAfieldToSurfacecellaveraged1, np.array(ref), field_name) + diff --git a/src/Plugins/GaussToCell/plugin/Test/tests.set b/src/Plugins/GaussToCell/plugin/Test/tests.set new file mode 100644 index 00000000..50749259 --- /dev/null +++ b/src/Plugins/GaussToCell/plugin/Test/tests.set @@ -0,0 +1,27 @@ +# Copyright (C) 2012-2022 CEA/DEN, EDF R&D +# +# 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 +# + +SET(TEST_NAMES + test_GaussToCell + ) + +SET(all_src + PG_3D.med + test_GaussToCell.py + ) -- 2.30.2