From: abn Date: Wed, 21 Aug 2019 13:17:44 +0000 (+0200) Subject: Modification and swigg-ing of MEDField for ICoCo interface. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e8f7d17cb449e8cc5284edde5510e86696671c57;p=tools%2Fmedcoupling.git Modification and swigg-ing of MEDField for ICoCo interface. --- diff --git a/src/ICoCo/ICoCoMEDField.cxx b/src/ICoCo/ICoCoMEDField.cxx index c0db2f93c..965ed06c2 100644 --- a/src/ICoCo/ICoCoMEDField.cxx +++ b/src/ICoCo/ICoCoMEDField.cxx @@ -18,10 +18,7 @@ // #include "ICoCoMEDField.hxx" -//#include "ProcessorGroup.hxx" -#include "MEDCouplingUMesh.hxx" #include "MEDCouplingFieldDouble.hxx" -#include "NormalizedUnstructuredMesh.hxx" namespace ICoCo { @@ -36,7 +33,7 @@ namespace ICoCo if(_field) _field->incrRef(); } - MEDField::MEDField(const MEDField& field):_field(field.getField()) + MEDField::MEDField(const MEDField& field):_field(field.getMCField()) { if(_field) _field->incrRef(); @@ -53,10 +50,20 @@ namespace ICoCo { if (_field) _field->decrRef(); - - _field=field.getField(); + + _field=field.getMCField(); if(_field) _field->incrRef(); return *this; } + + void MEDField::setMCField(MEDCoupling::MEDCouplingFieldDouble * f) + { + if(_field) + _field->decrRef(); + _field = f; + if(f) + _field->incrRef(); + } + } diff --git a/src/ICoCo/ICoCoMEDField.hxx b/src/ICoCo/ICoCoMEDField.hxx index a33d3a8ed..e460e85fa 100644 --- a/src/ICoCo/ICoCoMEDField.hxx +++ b/src/ICoCo/ICoCoMEDField.hxx @@ -36,8 +36,9 @@ namespace ICoCo MEDField(const MEDField& field); MEDField& operator=(const MEDField& field); virtual ~MEDField(); - MEDCoupling::MEDCouplingFieldDouble *getField() const { return _field; } - const MEDCoupling::MEDCouplingMesh *getMesh() const { return _field->getMesh(); } + MEDCoupling::MEDCouplingFieldDouble *getMCField() const { return _field; } + void setMCField(MEDCoupling::MEDCouplingFieldDouble * f); + private: MEDCoupling::MEDCouplingFieldDouble *_field; }; diff --git a/src/ICoCo/Swig/ICoCoMEDField.i b/src/ICoCo/Swig/ICoCoMEDField.i new file mode 100644 index 000000000..dad8b1ace --- /dev/null +++ b/src/ICoCo/Swig/ICoCoMEDField.i @@ -0,0 +1,42 @@ +// Copyright (C) 2017-2019 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 : Adrien Bruneton (CEA) + + +%{ +#include "ICoCoMEDField.hxx" + +using namespace MEDCoupling; +%} + +namespace ICoCo +{ + class MEDField + { + public: + MEDField(); + MEDField(MEDCoupling::MEDCouplingFieldDouble* field); + MEDField(const MEDField& field); + MEDField& operator=(const MEDField& field); + MEDCoupling::MEDCouplingFieldDouble *getMCField() const; + void setMCField(MEDCoupling::MEDCouplingFieldDouble * f); + }; +} + + diff --git a/src/MEDCoupling/CMakeLists.txt b/src/MEDCoupling/CMakeLists.txt index 04e0b5b3e..42395cf21 100644 --- a/src/MEDCoupling/CMakeLists.txt +++ b/src/MEDCoupling/CMakeLists.txt @@ -89,7 +89,7 @@ ADD_LIBRARY(medcouplingremapper ${medcouplingremapper_SOURCES}) TARGET_LINK_LIBRARIES(medcouplingremapper medcouplingcpp) INSTALL(TARGETS medcouplingremapper EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${MEDCOUPLING_INSTALL_LIBS}) -FILE(GLOB medcoupling_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx") +FILE(GLOB medcoupling_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx" "${CMAKE_CURRENT_SOURCE_DIR}/../ICoCo/*.hxx") FILE(GLOB medcoupling_HEADERS_TXX "${CMAKE_CURRENT_SOURCE_DIR}/*.txx") FILE(GLOB icoco_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/../ICoCo/*.hxx") INSTALL(FILES ${medcoupling_HEADERS_HXX} ${medcoupling_HEADERS_TXX} ${icoco_HEADERS_HXX} MEDCouplingNatureOfFieldEnum DESTINATION ${MEDCOUPLING_INSTALL_HEADERS}) diff --git a/src/MEDCoupling_Swig/CMakeLists.txt b/src/MEDCoupling_Swig/CMakeLists.txt index 8dd9feb7f..89f92135f 100644 --- a/src/MEDCoupling_Swig/CMakeLists.txt +++ b/src/MEDCoupling_Swig/CMakeLists.txt @@ -36,7 +36,9 @@ SET (MEDCoupling_SWIG_DPYS_FILES MEDCouplingMemArray.i MEDCouplingFieldDiscretization.i MEDCouplingFinalize.i - MEDCouplingTypemaps.i) + MEDCouplingTypemaps.i + ../ICoCo/Swig/ICoCoMEDField.i +) SET (MC_pyTestFiles ${ALL_TESTS} @@ -56,6 +58,7 @@ SET (MC_Swig_interf MEDCouplingTypemaps.i MEDCouplingDataArrayTypemaps.i MEDCouplingDataArrayTraits.hxx + ../ICoCo/Swig/ICoCoMEDField.i ) INCLUDE_DIRECTORIES( @@ -70,6 +73,8 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/Geometric2D ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/ExprEval ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/GaussPoints + ${CMAKE_CURRENT_SOURCE_DIR}/../ICoCo + ${CMAKE_CURRENT_SOURCE_DIR}/../ICoCo/Swig ${PROJECT_BINARY_DIR}/doc ) diff --git a/src/MEDCoupling_Swig/ICoCoMEDFieldTest.py b/src/MEDCoupling_Swig/ICoCoMEDFieldTest.py new file mode 100755 index 000000000..63210af2f --- /dev/null +++ b/src/MEDCoupling_Swig/ICoCoMEDFieldTest.py @@ -0,0 +1,79 @@ +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2007-2019 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 +# + + +import sys +if sys.platform == "win32": + from MEDCouplingCompat import * +else: + from medcoupling import * + +import unittest + +class ICoCoMEDFieldTest(unittest.TestCase): + def generate_fields(self): + ## Dummy MCFieldDouble + msh = MEDCouplingCMesh() + msh.setCoords(DataArrayDouble([0.,1.,2.])) + msh = msh.buildUnstructured() + f1 = MEDCouplingFieldDouble(ON_CELLS, ONE_TIME) + f1.setMesh(msh) + f1.setArray(DataArrayDouble([0.,1.,2.,3.])) + + f2 = f1.deepCopy() + da = f2.getArray() + da += 3.0 + da2 = f2.getArray() + return f1, f2 + + def test1(self): + f1, f2 = self.generate_fields() + mf = MEDField() + mfd = mf.getMCField() + self.assertTrue(mfd is None) + mf.setMCField(f1) + f11 = mf.getMCField() + self.assertEqual(f1.getHiddenCppPointer(), f11.getHiddenCppPointer()) # strictly the same + mf.setMCField(f2) + f22 = mf.getMCField() + self.assertEqual(f2.getHiddenCppPointer(), f22.getHiddenCppPointer()) # strictly the same + + mf = MEDField(f1) # ctor with MC object + mfd = mf.getMCField() + self.assertEqual(mfd.getHiddenCppPointer(), f1.getHiddenCppPointer()) # strictly the same + + mf.setMCField(None) + mfd = mf.getMCField() + self.assertTrue(mfd is None) + + mf.setMCField(f2) + f22 = mf.getMCField() + self.assertEqual(f2.getHiddenCppPointer(), f22.getHiddenCppPointer()) # strictly the same + + mf2 = MEDField(mf) # copy ctor + f22 = mf2.getMCField() + self.assertEqual(f2.getHiddenCppPointer(), f22.getHiddenCppPointer()) # strictly the same + + mf2 = mf # assignement op + f22 = mf2.getMCField() + self.assertEqual(f2.getHiddenCppPointer(), f22.getHiddenCppPointer()) # strictly the same + +if __name__ == '__main__': + unittest.main() diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index 57ae1cd48..9f44e9e4a 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -24,6 +24,7 @@ #endif %include "MEDCouplingCommon.i" +%include "ICoCoMEDField.i" %pythoncode %{ def MEDCouplingDataArrayDoubleIadd(self,*args): diff --git a/src/MEDCoupling_Swig/tests.set b/src/MEDCoupling_Swig/tests.set index 6fd1864ed..78e3b6448 100644 --- a/src/MEDCoupling_Swig/tests.set +++ b/src/MEDCoupling_Swig/tests.set @@ -28,6 +28,7 @@ SET(BASE_TESTS MEDCouplingExamplesTest.py MEDCouplingRemapperTest.py UsersGuideExamplesTest.py + ICoCoMEDFieldTest.py ) # if numpy is used diff --git a/src/PyWrapping/CMakeLists.txt b/src/PyWrapping/CMakeLists.txt index 56c928ff3..2a93dac76 100644 --- a/src/PyWrapping/CMakeLists.txt +++ b/src/PyWrapping/CMakeLists.txt @@ -53,6 +53,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../MEDPartitioner ${CMAKE_CURRENT_SOURCE_DIR}/../MEDPartitioner_Swig ${CMAKE_CURRENT_SOURCE_DIR}/../ICoCo + ${CMAKE_CURRENT_SOURCE_DIR}/../ICoCo/Swig ${CMAKE_CURRENT_SOURCE_DIR}/../ParaMEDMEM ${CMAKE_CURRENT_SOURCE_DIR}/../ParaMEDMEM_Swig ${PROJECT_BINARY_DIR}/doc diff --git a/src/PyWrapping/medcoupling.i b/src/PyWrapping/medcoupling.i index 72032a3a4..4bf4ab1bf 100644 --- a/src/PyWrapping/medcoupling.i +++ b/src/PyWrapping/medcoupling.i @@ -30,6 +30,8 @@ %include "MEDCouplingRemapperCommon.i" +%include "ICoCoMEDField.i" + #ifdef WITH_MED_FILE %include "MEDLoaderCommon.i" #endif