From e3456fdca0a2b66bd7b9baaceacfa8d104be3c0b Mon Sep 17 00:00:00 2001 From: Yoann Audouin Date: Thu, 26 Aug 2021 12:57:34 +0200 Subject: [PATCH] Correction for QuadraticToLinear to handle Float and Long variable + adding test --- src/CTestTestfileInstall.cmake.in | 1 + src/QuadraticToLinear/CMakeLists.txt | 4 ++ src/QuadraticToLinear/Test/CMakeLists.txt | 39 +++++++++++ .../Test/CTestTestfileInstall.cmake | 31 +++++++++ .../test_QuadraticToLinear.py} | 65 +++++++++++++++++-- .../vtkQuadraticToLinear.cxx | 43 ++++++++++++ 6 files changed, 179 insertions(+), 4 deletions(-) create mode 100644 src/QuadraticToLinear/Test/CMakeLists.txt create mode 100644 src/QuadraticToLinear/Test/CTestTestfileInstall.cmake rename src/QuadraticToLinear/{TestCase.py => Test/test_QuadraticToLinear.py} (54%) 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/TestCase.py b/src/QuadraticToLinear/Test/test_QuadraticToLinear.py similarity index 54% rename from src/QuadraticToLinear/TestCase.py rename to src/QuadraticToLinear/Test/test_QuadraticToLinear.py index b02b1e6..89aaa13 100644 --- a/src/QuadraticToLinear/TestCase.py +++ b/src/QuadraticToLinear/Test/test_QuadraticToLinear.py @@ -18,6 +18,7 @@ # from MEDLoader import * +import numpy as np fname="quadratic.med" meshName="mesh" @@ -64,17 +65,73 @@ 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())] +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="Field" + +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) -farr-=zeMax ; farr.abs() ; farr[nodeIdsNotLinear]=0. -farr.reverse() ; f.setTime(1.,1,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/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()); -- 2.39.2