]> SALOME platform Git repositories - tools/paravisaddons_common.git/commitdiff
Salome HOME
Correction for QuadraticToLinear to handle Float and Long variable + adding test
authorYoann Audouin <yoann.audouin@edf.fr>
Thu, 26 Aug 2021 10:57:34 +0000 (12:57 +0200)
committerYoann Audouin <yoann.audouin@edf.fr>
Thu, 26 Aug 2021 10:57:34 +0000 (12:57 +0200)
src/CTestTestfileInstall.cmake.in
src/QuadraticToLinear/CMakeLists.txt
src/QuadraticToLinear/Test/CMakeLists.txt [new file with mode: 0644]
src/QuadraticToLinear/Test/CTestTestfileInstall.cmake [new file with mode: 0644]
src/QuadraticToLinear/Test/test_QuadraticToLinear.py [new file with mode: 0644]
src/QuadraticToLinear/TestCase.py [deleted file]
src/QuadraticToLinear/plugin/QuadraticToLinearModule/vtkQuadraticToLinear.cxx

index f7ceff259ba2bdc40497e03cc1397757c22d1ecc..e44b1160b8422976c98275aaab77f774cf584f2e 100644 (file)
@@ -26,3 +26,4 @@ SUBDIRS(ElectromagnetismRotation)
 SUBDIRS(ElectromagnetismStreamTraceur)
 SUBDIRS(ElectromagnetismVecteur)
 SUBDIRS(ContactReader)
+SUBDIRS(QuadraticToLinear)
index b9a94350c108ade3a28b04afbc8e00f1ef107e8c..39f03dc42f9fb6c33bc5932b939921208aa08129 100644 (file)
@@ -21,6 +21,10 @@ cmake_minimum_required(VERSION 3.8)
 project(QuadraticToLinearPlugin)
 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/QuadraticToLinear/Test/CMakeLists.txt b/src/QuadraticToLinear/Test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6710874
--- /dev/null
@@ -0,0 +1,39 @@
+# 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_QuadraticToLinear_src
+  test_QuadraticToLinear.py
+  )
+
+SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env)
+
+ADD_TEST(QuadraticToLinear python test_QuadraticToLinear.py)
+SET_TESTS_PROPERTIES(QuadraticToLinear PROPERTIES ENVIRONMENT "${tests_env}")
+
+#INSTALL(TARGETS test_QuadraticToLinear DESTINATION ${PARAVISADDONS_COMMON_INSTALL_BINS})
+
+# Application tests
+
+SET(TEST_INSTALL_DIRECTORY ${PARAVISADDONS_COMMON_INSTALL_TESTS}/QuadraticToLinear)
+INSTALL(FILES ${test_QuadraticToLinear_src} DESTINATION ${TEST_INSTALL_DIRECTORY})
+
+INSTALL(FILES CTestTestfileInstall.cmake
+        DESTINATION ${TEST_INSTALL_DIRECTORY}
+        RENAME CTestTestfile.cmake)
diff --git a/src/QuadraticToLinear/Test/CTestTestfileInstall.cmake b/src/QuadraticToLinear/Test/CTestTestfileInstall.cmake
new file mode 100644 (file)
index 0000000..4f07a6d
--- /dev/null
@@ -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_QuadraticToLinear
+)
+
+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/QuadraticToLinear/Test/test_QuadraticToLinear.py b/src/QuadraticToLinear/Test/test_QuadraticToLinear.py
new file mode 100644 (file)
index 0000000..89aaa13
--- /dev/null
@@ -0,0 +1,137 @@
+# 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 MEDLoader import *
+import numpy as np
+
+fname="quadratic.med"
+meshName="mesh"
+coo=DataArrayDouble([(0,-1,0),(1,-1,0),(2,-1,0),#0->3
+                     (-1,0,0),(0,0,0),(1,0,0),(2,0,0),#3->7
+                     (2,1,0),(1,1,0),(0,1,0),#7->10
+                     (-1,0,1),(0,0,1),(1,0,1),#10->13
+                     (0,1,1),(1,1,1)#
+                 ])
+m0=MEDCouplingUMesh(meshName,3) ; m0.setCoords(coo)
+m0.allocateCells()
+m0.insertNextCell(NORM_TETRA4,[5,6,7,12])
+m0.insertNextCell(NORM_PENTA6,[3,9,4,10,13,11])
+m0.insertNextCell(NORM_HEXA8,[4,9,8,5,11,13,14,12]) ; m0.zipCoords()
+m0.convertLinearCellsToQuadratic()
+#
+m1=MEDCouplingUMesh(meshName,2) ; m1.setCoords(coo)
+m1.allocateCells()
+m1.insertNextCell(NORM_TRI3,[3,4,0])
+m1.insertNextCell(NORM_QUAD4,[0,4,5,1]) ; m1.zipCoords()
+m1.convertLinearCellsToQuadratic()
+#
+m2=MEDCouplingUMesh(meshName,1) ; m2.setCoords(coo)
+m2.allocateCells()
+m2.insertNextCell(NORM_SEG2,[1,2]) ; m2.zipCoords()
+m2.convertLinearCellsToQuadratic()
+#
+coos=[m0.getCoords(),m1.getCoords(),m2.getCoords()]
+ncoos=[len(cooElt) for cooElt in coos]
+arr=DataArrayDouble.Aggregate(coos)
+a,b=arr.findCommonTuples(1e-12)
+o2n,newNbNodes=DataArrayInt.ConvertIndexArrayToO2N(len(arr),a,b)
+newArr=arr[o2n.invertArrayO2N2N2O(newNbNodes)]
+#
+m0.renumberNodesInConn(o2n) ; m0.setCoords(newArr)
+m1.renumberNodesInConn(o2n[sum(ncoos[:1]):]) ; m1.setCoords(newArr)
+m2.renumberNodesInConn(o2n[sum(ncoos[:2]):]) ; m2.setCoords(newArr)
+a,b=newArr.areIncludedInMe(coo,1e-12)
+assert(a) ; b.sort()
+nodeIdsNotLinear=b.buildComplement(len(newArr))
+#
+mm=MEDFileUMesh()
+mm[0]=m0 ; mm[-1]=m1 ; mm[-2]=m2
+mm.write(fname,2)
+
+#
+centerOfCloud=[newArr[:,i].accumulate(0)/len(newArr) for i in range(newArr.getNumberOfComponents())]
+farr=(newArr-centerOfCloud).magnitude()
+farr[nodeIdsNotLinear]=0.
+zeMax=farr.getMaxValue()[0]
+#
+
+fieldName="FieldDouble"
+ff=MEDFileField1TS()
+f=MEDCouplingFieldDouble(ON_NODES) ; f.setMesh(m0) ; f.setArray(farr) ; f.setName(fieldName) ; f.setTime(0.,0,0)
+ff.setFieldNoProfileSBT(f)
+ff.write(fname,0)
+
+fieldName="FieldFloat"
+ff=MEDFileFloatField1TS()
+farr = DataArrayFloat(np.ones((len(farr)), dtype=np.float32))
+f=MEDCouplingFieldFloat(ON_NODES) ; f.setMesh(m0) ; f.setArray(farr) ; f.setName(fieldName) ; f.setTime(0.,0,0)
+ff.setFieldNoProfileSBT(f)
+ff.write(fname,0)
+
+fieldName="FieldInt32"
+ff=MEDFileInt32Field1TS()
+farr = DataArrayInt32(np.ones((len(farr)), dtype=np.int32))
+f=MEDCouplingFieldInt32(ON_NODES) ; f.setMesh(m0) ; f.setArray(farr) ; f.setName(fieldName) ; f.setTime(0.,0,0)
+ff.setFieldNoProfileSBT(f)
+ff.write(fname,0)
+
+fieldName="FieldInt64"
+ff=MEDFileInt64Field1TS()
+farr = DataArrayInt64(np.ones((len(farr)), dtype=np.int64))
+f=MEDCouplingFieldInt64(ON_NODES) ; f.setMesh(m0) ; f.setArray(farr) ; f.setName(fieldName) ; f.setTime(0.,0,0)
+ff.setFieldNoProfileSBT(f)
+ff.write(fname,0)
+
+
+
+
+
+
+
+#fieldName="FieldDouble"
+#f=MEDCouplingFieldDouble(ON_NODES, ONE_TIME) ; f.setMesh(m0) ; f.setArray(farr) ; f.setName(fieldName) ; f.setTime(0.,0,0)
+#farr-=zeMax ; farr.abs() ; farr[nodeIdsNotLinear]=0.
+#farr.reverse()
+#WriteFieldUsingAlreadyWrittenMesh(fname, f)
+#
+#fieldName="FieldFloat"
+#farr = DataArrayFloat(np.ones((len(farr)), dtype=np.float32))
+#f=MEDCouplingFieldFloat(ON_NODES, ONE_TIME) ; f.setMesh(m0) ; f.setArray(farr) ; f.setName(fieldName) ; f.setTime(0.,0,0)
+#WriteFieldUsingAlreadyWrittenMesh(fname, f)
+#
+#fieldName="FieldInt32"
+#farr = DataArrayInt32(np.ones((len(farr)), dtype=np.int32))
+#f=MEDCouplingFieldInt32(ON_NODES, ONE_TIME) ; f.setMesh(m0) ; f.setArray(farr) ; f.setName(fieldName) ; f.setTime(0.,0,0)
+#WriteFieldUsingAlreadyWrittenMesh(fname, f)
+
+#fieldName="FieldInt64"
+#farr = DataArrayInt64(np.ones((len(farr)), dtype=np.int64))
+#f=MEDCouplingFieldInt64(ON_NODES, ONE_TIME) ; f.setMesh(m0) ; f.setArray(farr) ; f.setName(fieldName) ; f.setTime(0.,0,0)
+#WriteField(fname, f, True)
+
+from paraview.simple import *
+
+quadraticmed = MEDReader(registrationName=fname, FileName=fname)
+quadraticmed.AllArrays = ['TS0/mesh/ComSup0/FieldDouble@@][@@P1', 'TS0/mesh/ComSup0/FieldFloat@@][@@P1', 'TS0/mesh/ComSup0/FieldInt32@@][@@P1']
+quadraticmed.AllTimeSteps = ['0000']
+
+quadraticmed.UpdatePipeline()
+
+quadraticToLinear1 = QuadraticToLinear(registrationName='QuadraticToLinear1', Input=quadraticmed)
+quadraticToLinear1.UpdatePipeline()
diff --git a/src/QuadraticToLinear/TestCase.py b/src/QuadraticToLinear/TestCase.py
deleted file mode 100644 (file)
index b02b1e6..0000000
+++ /dev/null
@@ -1,80 +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 MEDLoader import *
-
-fname="quadratic.med"
-meshName="mesh"
-coo=DataArrayDouble([(0,-1,0),(1,-1,0),(2,-1,0),#0->3
-                     (-1,0,0),(0,0,0),(1,0,0),(2,0,0),#3->7
-                     (2,1,0),(1,1,0),(0,1,0),#7->10
-                     (-1,0,1),(0,0,1),(1,0,1),#10->13
-                     (0,1,1),(1,1,1)#
-                 ])
-m0=MEDCouplingUMesh(meshName,3) ; m0.setCoords(coo)
-m0.allocateCells()
-m0.insertNextCell(NORM_TETRA4,[5,6,7,12])
-m0.insertNextCell(NORM_PENTA6,[3,9,4,10,13,11])
-m0.insertNextCell(NORM_HEXA8,[4,9,8,5,11,13,14,12]) ; m0.zipCoords()
-m0.convertLinearCellsToQuadratic()
-#
-m1=MEDCouplingUMesh(meshName,2) ; m1.setCoords(coo)
-m1.allocateCells()
-m1.insertNextCell(NORM_TRI3,[3,4,0])
-m1.insertNextCell(NORM_QUAD4,[0,4,5,1]) ; m1.zipCoords()
-m1.convertLinearCellsToQuadratic()
-#
-m2=MEDCouplingUMesh(meshName,1) ; m2.setCoords(coo)
-m2.allocateCells()
-m2.insertNextCell(NORM_SEG2,[1,2]) ; m2.zipCoords()
-m2.convertLinearCellsToQuadratic()
-#
-coos=[m0.getCoords(),m1.getCoords(),m2.getCoords()]
-ncoos=[len(cooElt) for cooElt in coos]
-arr=DataArrayDouble.Aggregate(coos)
-a,b=arr.findCommonTuples(1e-12)
-o2n,newNbNodes=DataArrayInt.ConvertIndexArrayToO2N(len(arr),a,b)
-newArr=arr[o2n.invertArrayO2N2N2O(newNbNodes)]
-#
-m0.renumberNodesInConn(o2n) ; m0.setCoords(newArr)
-m1.renumberNodesInConn(o2n[sum(ncoos[:1]):]) ; m1.setCoords(newArr)
-m2.renumberNodesInConn(o2n[sum(ncoos[:2]):]) ; m2.setCoords(newArr)
-a,b=newArr.areIncludedInMe(coo,1e-12)
-assert(a) ; b.sort()
-nodeIdsNotLinear=b.buildComplement(len(newArr))
-#
-mm=MEDFileUMesh()
-mm[0]=m0 ; mm[-1]=m1 ; mm[-2]=m2
-mm.write(fname,2)
-
-#
-centerOfCloud=[newArr[:,i].accumulate(0)/len(newArr) for i in xrange(newArr.getNumberOfComponents())]
-farr=(newArr-centerOfCloud).magnitude()
-farr[nodeIdsNotLinear]=0.
-zeMax=farr.getMaxValue()[0]
-#
-fieldName="Field"
-ff=MEDFileField1TS()
-f=MEDCouplingFieldDouble(ON_NODES) ; f.setMesh(m0) ; f.setArray(farr) ; f.setName(fieldName) ; f.setTime(0.,0,0)
-ff.setFieldNoProfileSBT(f)
-ff.write(fname,0)
-farr-=zeMax ; farr.abs() ; farr[nodeIdsNotLinear]=0.
-farr.reverse() ; f.setTime(1.,1,0)
-ff.setFieldNoProfileSBT(f)
-ff.write(fname,0)
index 4f86402c451c6af63430da0c126036d2bd194420..043bdfda2a662286c5e7c06c997210e172186aef 100644 (file)
@@ -32,6 +32,7 @@
 #include <vtkDataSetAttributes.h>
 #include <vtkDemandDrivenPipeline.h>
 #include <vtkDoubleArray.h>
+#include <vtkLongArray.h>
 #include <vtkExecutive.h>
 #include <vtkFloatArray.h>
 #include <vtkInEdgeIterator.h>
@@ -175,6 +176,48 @@ vtkSmartPointer<vtkDataArray> Reduce(const int *new2Old, int newNbPts, vtkDataAr
       throw MZCException(oss.str());
     }
   }
+  else if (vtkFloatArray::SafeDownCast(array))
+  {
+    vtkSmartPointer<vtkFloatArray> ret(vtkSmartPointer<vtkFloatArray>::New());
+    zeRet = ret;
+    ret->SetNumberOfComponents(nbOfCompo);
+    ret->SetNumberOfTuples(newNbPts);
+    vtkFloatArray *array1(vtkFloatArray::SafeDownCast(array));
+    if (array1)
+    {
+      const float *inpCoords(array1->GetPointer(0));
+      float *outCoords(ret->GetPointer(0));
+      for (int i = 0; i < newNbPts; i++, outCoords += nbOfCompo)
+        std::copy(inpCoords + new2Old[i] * nbOfCompo, inpCoords + (new2Old[i] + 1) * nbOfCompo, outCoords);
+    }
+    else
+    {
+      std::ostringstream oss;
+      oss << "Only Float array managed for the moment in input !" << array->GetName();
+      throw MZCException(oss.str());
+    }
+  }
+  else if (vtkLongArray::SafeDownCast(array))
+  {
+    vtkSmartPointer<vtkLongArray> ret(vtkSmartPointer<vtkLongArray>::New());
+    zeRet = ret;
+    ret->SetNumberOfComponents(nbOfCompo);
+    ret->SetNumberOfTuples(newNbPts);
+    vtkLongArray *array1(vtkLongArray::SafeDownCast(array));
+    if (array1)
+    {
+      const long *inpCoords(array1->GetPointer(0));
+      long *outCoords(ret->GetPointer(0));
+      for (int i = 0; i < newNbPts; i++, outCoords += nbOfCompo)
+        std::copy(inpCoords + new2Old[i] * nbOfCompo, inpCoords + (new2Old[i] + 1) * nbOfCompo, outCoords);
+    }
+    else
+    {
+      std::ostringstream oss;
+      oss << "Only Long array managed for the moment in input !" << array->GetName();
+      throw MZCException(oss.str());
+    }
+  }
   else if (vtkIntArray::SafeDownCast(array))
   {
     vtkSmartPointer<vtkIntArray> ret(vtkSmartPointer<vtkIntArray>::New());