From: YOANN AUDOUIN Date: Thu, 1 Apr 2021 08:01:34 +0000 (+0200) Subject: [test] Adding test for ElectromagnetismVecteur X-Git-Tag: V9_8_0a1~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=121b317a9d96738b242a7d3af93a6959fdedee79;p=tools%2Fparavisaddons_common.git [test] Adding test for ElectromagnetismVecteur --- diff --git a/src/ElectromagnetismStreamTraceur/scripts/generate.py b/src/ElectromagnetismStreamTraceur/scripts/generate.py deleted file mode 100644 index e340760..0000000 --- a/src/ElectromagnetismStreamTraceur/scripts/generate.py +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright (C) 2021 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 medcoupling import * - -arr = DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10]) -m = MEDCouplingCMesh() -m.setCoords(arr,arr,arr) -m = m.buildUnstructured() -#m.simplexize(0) -m.changeSpaceDimension(3,0.) -m.setName("mesh") -f = MEDCouplingFieldDouble(ON_CELLS) -f.setMesh(m) -f.setName("field") -arrf = DataArrayDouble(10*10*10,3) -arrf[:,0] = 1 ; arrf[:,1] = 0 ; arrf[:,2] = 0 -f.setArray( arrf ) -f.getArray().setInfoOnComponents(["X","Y","Z"]) -f.checkConsistencyLight() -f.write("test.med") -f2 = f.deepCopy() -arrf2 = DataArrayDouble(10*10*10,3) -arrf2[:,0] = 0 ; arrf2[:,1] = 1 ; arrf2[:,2] = 0 -f2.setArray( arrf2 ) -f2.setName("field2") -WriteFieldUsingAlreadyWrittenMesh("test.med",f2) diff --git a/src/ElectromagnetismStreamTraceur/scripts/test_stream.py b/src/ElectromagnetismStreamTraceur/scripts/test_stream.py deleted file mode 100644 index 7d76a70..0000000 --- a/src/ElectromagnetismStreamTraceur/scripts/test_stream.py +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2021 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 paraview.simple import * -#### disable automatic camera reset on 'Show' -paraview.simple._DisableFirstRenderCameraReset() - -def MyAssert(clue): - if not clue: - raise RuntimeError("Assertion failed !") - -testmed = MEDReader(FileName='test.med') -testmed.AllArrays = ['TS0/mesh/ComSup0/field@@][@@P0', 'TS0/mesh/ComSup0/field2@@][@@P0', 'TS0/mesh/ComSup0/mesh@@][@@P0'] -testmed.AllTimeSteps = ['0000'] -streamTraceur1 = LigneDeChamp(Input=testmed,SeedType='Point Source') -streamTraceur1.SeedType.Radius = 1 -streamTraceur1.SeedType.Center = [ 7.23,7.26,3.42 ] -streamTraceur1.Vectors = ['CELLS', "field"] #OrientationArray -streamTraceur1.UpdatePipeline() -ds0 = servermanager.Fetch(streamTraceur1) -MyAssert(ds0.GetNumberOfCells()==200) diff --git a/src/ElectromagnetismVecteur/CMakeLists.txt b/src/ElectromagnetismVecteur/CMakeLists.txt index fc12318..396e01c 100644 --- a/src/ElectromagnetismVecteur/CMakeLists.txt +++ b/src/ElectromagnetismVecteur/CMakeLists.txt @@ -21,6 +21,10 @@ cmake_minimum_required(VERSION 3.8) project(ElectromagnetismVecteur) find_package(ParaView REQUIRED) +IF(PARAVISADDONS_COMMON_BUILD_TESTS) + ADD_SUBDIRECTORY(Test) +ENDIF(PARAVISADDONS_COMMON_BUILD_TESTS) + include(GNUInstallDirs) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") diff --git a/src/ElectromagnetismVecteur/Test/CMakeLists.txt b/src/ElectromagnetismVecteur/Test/CMakeLists.txt new file mode 100644 index 0000000..b687152 --- /dev/null +++ b/src/ElectromagnetismVecteur/Test/CMakeLists.txt @@ -0,0 +1,37 @@ +# Copyright (C) 2012-2020 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) + +SET(test_maxwell_vecteur_0_src + test_maxwell_vecteur_0.py + ) + +SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env) + +ADD_TEST(ElectromagnetismVecteur python test_maxwell_vecteur_0.py) +SET_TESTS_PROPERTIES(ElectromagnetismVecteur PROPERTIES ENVIRONMENT "${tests_env}") + +# Application tests + +SET(TEST_INSTALL_DIRECTORY ${PARAVISADDONS_COMMON_INSTALL_TESTS}/ElectromagnetismVecteur) +INSTALL(FILES ${test_maxwell_vecteur_0_src} DESTINATION ${TEST_INSTALL_DIRECTORY}) + +INSTALL(FILES CTestTestfileInstall.cmake + DESTINATION ${TEST_INSTALL_DIRECTORY} + RENAME CTestTestfile.cmake) diff --git a/src/ElectromagnetismVecteur/Test/CTestTestfileInstall.cmake b/src/ElectromagnetismVecteur/Test/CTestTestfileInstall.cmake new file mode 100644 index 0000000..6a350ee --- /dev/null +++ b/src/ElectromagnetismVecteur/Test/CTestTestfileInstall.cmake @@ -0,0 +1,31 @@ +# Copyright (C) 2015-2020 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_maxwell_vecteur_0 +) + +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/ElectromagnetismVecteur/Test/test_maxwell_vecteur_0.py b/src/ElectromagnetismVecteur/Test/test_maxwell_vecteur_0.py new file mode 100644 index 0000000..2bb33b4 --- /dev/null +++ b/src/ElectromagnetismVecteur/Test/test_maxwell_vecteur_0.py @@ -0,0 +1,73 @@ +from paraview.simple import * +paraview.simple._DisableFirstRenderCameraReset() +from vtk.util import numpy_support +import numpy as np +import medcoupling as mc + +def MyAssert(clue): + if not clue: + raise RuntimeError("Assertion failed !") + +fileName = "MaxwellVecteur.med" + +# on genere un use case + +arr = mc.DataArrayDouble([0,1,2]) +m = mc.MEDCouplingCMesh() +m.setCoords(arr,arr) +m = m.buildUnstructured() +m.changeSpaceDimension(3,0.) +m.setName("mesh") +f = mc.MEDCouplingFieldDouble(mc.ON_CELLS) +f.setMesh(m) +f.setName("field") +f.setArray( mc.DataArrayDouble([(1,1,0), (2,-2,0), (-3,3,0), (-4,-4,0)]) ) +f.getArray().setInfoOnComponents(["X","Y","Z"]) +f.checkConsistencyLight() +f.write(fileName) +f2 = f.deepCopy() +f2.setArray( mc.DataArrayDouble([(1,0,0), (0,-2,0), (-3,0,0), (0,4,0)]) ) +f2.setName("field2") +mc.WriteFieldUsingAlreadyWrittenMesh(fileName,f2) + +# fin de la generation du fichier MED on attaque le test a proprement parler + +testmed = MEDReader(FileName=fileName) +testmed.AllArrays = ['TS0/mesh/ComSup0/field@@][@@P0', 'TS0/mesh/ComSup0/field2@@][@@P0', 'TS0/mesh/ComSup0/mesh@@][@@P0'] +testmed.AllTimeSteps = ['0000'] + +vecteur1 = Vecteur(Input=testmed) +fieldName = "field" +colorFieldName = vecteur1.GetProperty("ColorArrayName") +vecteur1.OrientationArray = ['POINTS', fieldName] +vecteur1.ScaleFactor = 0.1 +vecteur1.UpdatePipeline() + +ds0 = servermanager.Fetch(vecteur1) +MyAssert(ds0.GetNumberOfBlocks()==1) +ds0 = ds0.GetBlock(0) + +arr = numpy_support.vtk_to_numpy(ds0.GetPointData().GetArray(fieldName)) +arr2 = numpy_support.vtk_to_numpy(ds0.GetPointData().GetArray(fieldName)) +MyAssert( np.all(np.isclose(arr,arr2,0,1e-12)) ) # on check que la couleur est aligné sur le field selectionné +MyAssert( np.all(np.isclose(arr[-1],np.array([-4.,-4.,0.]),0,1e-12)) ) +MyAssert( arr.shape==(20,3) ) # 20 == 4 * 5 . Une fleche c est 5 points (3 pour la tete et 2 pour la tige). 4 fleches car 4 cells + +fieldName = "field2" +vecteur1.OrientationArray = ['POINTS', fieldName] +vecteur1.UpdatePipeline() +ds0 = servermanager.Fetch(vecteur1).GetBlock(0) +arr = numpy_support.vtk_to_numpy(ds0.GetPointData().GetArray(fieldName)) +arr2 = numpy_support.vtk_to_numpy(ds0.GetPointData().GetArray(fieldName)) +MyAssert( np.all(np.isclose(arr,arr2,0,1e-12)) )# on check que la couleur est aligné sur le field selectionné +MyAssert( np.all(np.isclose(arr[-1],np.array([0.,4.,0.]),0,1e-12)) ) +MyAssert( arr.shape==(20,3) ) +# on check la gueule des fleches notamment le fait que comme demandé on n'a pas de scale array avec des fleches de meme tailles bien qu avec des magnitudes differentes +pts = numpy_support.vtk_to_numpy(ds0.GetPoints().GetData()) +pts_ref = np.array([[0.45, 0.5, 0], [0.55, 0.5, 0], [0.52, 0.49, 0], [0.55, 0.5, 0], [0.52, 0.51, 0], [1.5, 0.55, 0.], [1.5, 0.45, 0.], [1.51, 0.48, 0.], [1.5, 0.45, 0.], [1.49, 0.48, 0.], [0.55, 1.5, 0.], [0.45, 1.5, 0.],[0.48, 1.49, 0.], [0.45, 1.5, 0.], [0.48, 1.51, 0.], [1.5, 1.45, 0.], [1.5, 1.55, 0.], [1.49, 1.52, 0.], [1.5, 1.55, 0.], [1.51, 1.52, 0.]], dtype = np.float32) +MyAssert( np.all(np.isclose(pts,pts_ref,0,1e-12)) ) +vecteur1.ScaleFactor = 1.0 +vecteur1.UpdatePipeline() +ds0 = servermanager.Fetch(vecteur1).GetBlock(0) +pts = numpy_support.vtk_to_numpy(ds0.GetPoints().GetData()) +pts_ref_1 = np.array([(0, 0.5, 0), (1, 0.5, 0), (0.7, 0.4, 0), (1, 0.5, 0), (0.7, 0.6, 0), (1.5, 1, 0), (1.5, 0, 0), (1.6, 0.3, 0), (1.5, 0, 0), (1.4, 0.3, 0), (1, 1.5, 0), (0, 1.5, 0), (0.3, 1.4, 0), (0, 1.5, 0), (0.3, 1.6, 0), (1.5, 1, 0), (1.5, 2, 0), (1.4, 1.7, 0), (1.5, 2, 0), (1.6, 1.7, 0)],dtype=np.float32) diff --git a/src/ElectromagnetismVecteur/scripts/generate.py b/src/ElectromagnetismVecteur/scripts/generate.py deleted file mode 100644 index bf04b7c..0000000 --- a/src/ElectromagnetismVecteur/scripts/generate.py +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (C) 2021 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 medcoupling import * - -arr = DataArrayDouble([0,1,2]) -m = MEDCouplingCMesh() -m.setCoords(arr,arr) -m = m.buildUnstructured() -#m.simplexize(0) -m.changeSpaceDimension(3,0.) -m.setName("mesh") -f = MEDCouplingFieldDouble(ON_CELLS) -f.setMesh(m) -f.setName("field") -f.setArray( DataArrayDouble([(1,1,0), (2,-2,0), (-3,3,0), (-4,-4,0)]) ) -f.getArray().setInfoOnComponents(["X","Y","Z"]) -f.checkConsistencyLight() -f.write("test.med") -f2 = f.deepCopy() -f2.setArray( DataArrayDouble([(1,0,0), (0,-2,0), (-3,0,0), (0,4,0)]) ) -f2.setName("field2") -WriteFieldUsingAlreadyWrittenMesh("test.med",f2)