From: Yoann Audouin Date: Thu, 26 Aug 2021 10:57:34 +0000 (+0200) Subject: Correction for QuadraticToLinear to handle Float and Long variable + adding test X-Git-Tag: V9_8_0a1~1^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e3456fdca0a2b66bd7b9baaceacfa8d104be3c0b;p=tools%2Fparavisaddons_common.git Correction for QuadraticToLinear to handle Float and Long variable + adding test --- diff --git a/src/CTestTestfileInstall.cmake.in b/src/CTestTestfileInstall.cmake.in index f7ceff2..e44b116 100644 --- a/src/CTestTestfileInstall.cmake.in +++ b/src/CTestTestfileInstall.cmake.in @@ -26,3 +26,4 @@ SUBDIRS(ElectromagnetismRotation) SUBDIRS(ElectromagnetismStreamTraceur) SUBDIRS(ElectromagnetismVecteur) SUBDIRS(ContactReader) +SUBDIRS(QuadraticToLinear) diff --git a/src/QuadraticToLinear/CMakeLists.txt b/src/QuadraticToLinear/CMakeLists.txt index b9a9435..39f03dc 100644 --- a/src/QuadraticToLinear/CMakeLists.txt +++ b/src/QuadraticToLinear/CMakeLists.txt @@ -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 index 0000000..6710874 --- /dev/null +++ b/src/QuadraticToLinear/Test/CMakeLists.txt @@ -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 index 0000000..4f07a6d --- /dev/null +++ b/src/QuadraticToLinear/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_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 index 0000000..89aaa13 --- /dev/null +++ b/src/QuadraticToLinear/Test/test_QuadraticToLinear.py @@ -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 index b02b1e6..0000000 --- a/src/QuadraticToLinear/TestCase.py +++ /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) diff --git a/src/QuadraticToLinear/plugin/QuadraticToLinearModule/vtkQuadraticToLinear.cxx b/src/QuadraticToLinear/plugin/QuadraticToLinearModule/vtkQuadraticToLinear.cxx index 4f86402..043bdfd 100644 --- a/src/QuadraticToLinear/plugin/QuadraticToLinearModule/vtkQuadraticToLinear.cxx +++ b/src/QuadraticToLinear/plugin/QuadraticToLinearModule/vtkQuadraticToLinear.cxx @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -175,6 +176,48 @@ vtkSmartPointer Reduce(const int *new2Old, int newNbPts, vtkDataAr throw MZCException(oss.str()); } } + else if (vtkFloatArray::SafeDownCast(array)) + { + vtkSmartPointer ret(vtkSmartPointer::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 ret(vtkSmartPointer::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 ret(vtkSmartPointer::New());