]> SALOME platform Git repositories - modules/med.git/commitdiff
Salome HOME
End of reorganization of MEDCoupling wrapper for Renumber
authorageay <ageay>
Tue, 24 Sep 2013 09:51:07 +0000 (09:51 +0000)
committerageay <ageay>
Tue, 24 Sep 2013 09:51:07 +0000 (09:51 +0000)
src/CMakeLists.txt
src/RENUMBER_Swig/CMakeLists.txt [new file with mode: 0644]
src/RENUMBER_Swig/MEDRenumber.i [new file with mode: 0644]
src/RENUMBER_Swig/MEDRenumberCommon.i [new file with mode: 0644]
src/RENUMBER_Swig/MEDRenumberTest.py [new file with mode: 0644]

index e140bfc6a3bc078545970cba681e31a6a984aa73..3ed0f1d4f02718b249ada71217f7622e1f864063 100644 (file)
@@ -28,6 +28,9 @@ IF(NOT SALOME_MED_MICROMED)
   ADD_SUBDIRECTORY(MEDLoader)
   IF(SALOME_MED_ENABLE_RENUMBER)
     ADD_SUBDIRECTORY(RENUMBER)
+    IF(SALOME_MED_ENABLE_PYTHON)
+      ADD_SUBDIRECTORY(RENUMBER_Swig)
+    ENDIF(SALOME_MED_ENABLE_PYTHON)
   ENDIF(SALOME_MED_ENABLE_RENUMBER)
   IF(SALOME_MED_ENABLE_PARTITIONER)
     ADD_SUBDIRECTORY(MEDPartitioner)
diff --git a/src/RENUMBER_Swig/CMakeLists.txt b/src/RENUMBER_Swig/CMakeLists.txt
new file mode 100644 (file)
index 0000000..70d49b6
--- /dev/null
@@ -0,0 +1,64 @@
+# Copyright (C) 2012-2013  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.
+#
+# 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
+#
+
+INCLUDE(${SWIG_USE_FILE})
+
+ADD_DEFINITIONS(${PYTHON_DEFINITIONS})
+
+SET_SOURCE_FILES_PROPERTIES(MEDRenumber.i PROPERTIES CPLUSPLUS ON)
+SET_SOURCE_FILES_PROPERTIES(MEDRenumber.i PROPERTIES SWIG_DEFINITIONS "-shadow")
+IF(NUMPY_FOUND)
+  SET(SWIG_MODULE_MEDRenumber_EXTRA_FLAGS -DWITH_NUMPY -DWITHOUT_AUTOFIELD)
+ELSE(NUMPY_FOUND)
+  SET(SWIG_MODULE_MEDRenumber_EXTRA_FLAGS -DWITHOUT_AUTOFIELD)
+ENDIF(NUMPY_FOUND)
+
+SET (MEDRenumber_SWIG_DPYS_FILES
+    MEDRenumberCommon.i)   
+
+INCLUDE_DIRECTORIES(
+  ${PYTHON_INCLUDE_DIRS}
+  ${PTHREAD_INCLUDE_DIR} # pthread dependancy due to python2.7 library
+  ${CMAKE_CURRENT_SOURCE_DIR}
+  ${CMAKE_CURRENT_BINARY_DIR}
+  ${CMAKE_CURRENT_SOURCE_DIR}/../RENUMBER
+  ${CMAKE_CURRENT_SOURCE_DIR}/../MEDCoupling_Swig
+  ${CMAKE_CURRENT_SOURCE_DIR}/../MEDCoupling
+  ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL
+  ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/Bases
+  ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/Geometric2D
+  ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/ExprEval
+  ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/GaussPoints
+  )
+
+SWIG_ADD_MODULE(MEDRenumber python MEDRenumber.i)
+SWIG_LINK_LIBRARIES(MEDRenumber ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} renumbercpp)
+
+IF(WIN32)
+  SET_TARGET_PROPERTIES(_MEDRenumber PROPERTIES DEBUG_OUTPUT_NAME _MEDRenumber_d)
+ENDIF(WIN32)
+INSTALL(TARGETS ${SWIG_MODULE_MEDRenumber_REAL_NAME} DESTINATION ${SALOME_INSTALL_PYTHON})
+
+SET(PYFILES_TO_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/MEDRenumber.py)
+INSTALL_AND_COMPILE_PYTHON_FILE("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_SCRIPT_PYTHON})
+
+INSTALL(FILES MEDRenumber.i MEDRenumberCommon.i DESTINATION ${SALOME_INSTALL_HEADERS})
+INSTALL(FILES MEDRenumberTest.py DESTINATION ${SALOME_INSTALL_SCRIPT_PYTHON})
+
+ADD_TEST(MEDRenumberTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MEDRenumberTest.py)
diff --git a/src/RENUMBER_Swig/MEDRenumber.i b/src/RENUMBER_Swig/MEDRenumber.i
new file mode 100644 (file)
index 0000000..483fddb
--- /dev/null
@@ -0,0 +1,128 @@
+// Copyright (C) 2007-2013  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.
+//
+// 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
+//
+
+%include "MEDRenumberCommon.i"
+
+%pythoncode %{
+def ParaMEDMEMDataArrayDoubleIadd(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayDouble____iadd___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleIsub(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayDouble____isub___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleImul(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayDouble____imul___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleIdiv(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayDouble____idiv___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleIpow(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayDouble____ipow___(self, self, *args)
+def ParaMEDMEMDataArrayIntIadd(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayInt____iadd___(self, self, *args)
+def ParaMEDMEMDataArrayIntIsub(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayInt____isub___(self, self, *args)
+def ParaMEDMEMDataArrayIntImul(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayInt____imul___(self, self, *args)
+def ParaMEDMEMDataArrayIntIdiv(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayInt____idiv___(self, self, *args)
+def ParaMEDMEMDataArrayIntImod(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayInt____imod___(self, self, *args)
+def ParaMEDMEMDataArrayIntIpow(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayInt____ipow___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleTupleIadd(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayDoubleTuple____iadd___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleTupleIsub(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayDoubleTuple____isub___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleTupleImul(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayDoubleTuple____imul___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleTupleIdiv(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayDoubleTuple____idiv___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleIadd(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayIntTuple____iadd___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleIsub(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayIntTuple____isub___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleImul(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayIntTuple____imul___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleIdiv(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayIntTuple____idiv___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleImod(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayIntTuple____imod___(self, self, *args)
+%}
+
+%pythoncode %{
+DataArrayDouble.__iadd__=ParaMEDMEMDataArrayDoubleIadd
+DataArrayDouble.__isub__=ParaMEDMEMDataArrayDoubleIsub
+DataArrayDouble.__imul__=ParaMEDMEMDataArrayDoubleImul
+DataArrayDouble.__idiv__=ParaMEDMEMDataArrayDoubleIdiv
+DataArrayDouble.__ipow__=ParaMEDMEMDataArrayDoubleIpow
+
+DataArrayInt.__iadd__=ParaMEDMEMDataArrayIntIadd
+DataArrayInt.__isub__=ParaMEDMEMDataArrayIntIsub
+DataArrayInt.__imul__=ParaMEDMEMDataArrayIntImul
+DataArrayInt.__idiv__=ParaMEDMEMDataArrayIntIdiv
+DataArrayInt.__imod__=ParaMEDMEMDataArrayIntImod
+DataArrayInt.__ipow__=ParaMEDMEMDataArrayIntIpow
+
+DataArrayDoubleTuple.__iadd__=ParaMEDMEMDataArrayDoubleTupleIadd
+DataArrayDoubleTuple.__isub__=ParaMEDMEMDataArrayDoubleTupleIsub
+DataArrayDoubleTuple.__imul__=ParaMEDMEMDataArrayDoubleTupleImul
+DataArrayDoubleTuple.__idiv__=ParaMEDMEMDataArrayDoubleTupleIdiv
+
+DataArrayIntTuple.__iadd__=ParaMEDMEMDataArrayIntTupleIadd
+DataArrayIntTuple.__isub__=ParaMEDMEMDataArrayIntTupleIsub
+DataArrayIntTuple.__imul__=ParaMEDMEMDataArrayIntTupleImul
+DataArrayIntTuple.__idiv__=ParaMEDMEMDataArrayIntTupleIdiv
+DataArrayIntTuple.__imod__=ParaMEDMEMDataArrayIntTupleImod
+
+del ParaMEDMEMDataArrayDoubleIadd
+del ParaMEDMEMDataArrayDoubleIsub
+del ParaMEDMEMDataArrayDoubleImul
+del ParaMEDMEMDataArrayDoubleIdiv
+del ParaMEDMEMDataArrayIntIadd
+del ParaMEDMEMDataArrayIntIsub
+del ParaMEDMEMDataArrayIntImul
+del ParaMEDMEMDataArrayIntIdiv
+del ParaMEDMEMDataArrayIntImod
+del ParaMEDMEMDataArrayDoubleTupleIadd
+del ParaMEDMEMDataArrayDoubleTupleIsub
+del ParaMEDMEMDataArrayDoubleTupleImul
+del ParaMEDMEMDataArrayDoubleTupleIdiv
+del ParaMEDMEMDataArrayIntTupleIadd
+del ParaMEDMEMDataArrayIntTupleIsub
+del ParaMEDMEMDataArrayIntTupleImul
+del ParaMEDMEMDataArrayIntTupleIdiv
+del ParaMEDMEMDataArrayIntTupleImod
+%}
diff --git a/src/RENUMBER_Swig/MEDRenumberCommon.i b/src/RENUMBER_Swig/MEDRenumberCommon.i
new file mode 100644 (file)
index 0000000..b099f70
--- /dev/null
@@ -0,0 +1,92 @@
+// Copyright (C) 2007-2013  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.
+//
+// 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 : Anthony Geay (CEA/DEN)
+
+%module MEDRenumber
+
+%include std_vector.i
+%include std_string.i
+
+%{
+#include "MEDCouplingMemArray.hxx"
+#include "MEDCouplingAutoRefCountObjectPtr.hxx"
+#include "MEDCouplingDataArrayTypemaps.i"
+
+#include "RenumberingFactory.hxx"
+#include "RENUMBER_Renumbering.hxx"
+
+using namespace ParaMEDMEM;
+using namespace INTERP_KERNEL;
+ using namespace MED_RENUMBER;
+%}
+
+%template(ivec) std::vector<int>;
+%template(dvec) std::vector<double>;
+%template(svec) std::vector<std::string>;
+
+#ifdef WITH_NUMPY
+%init %{ import_array(); %}
+#endif
+
+%feature("autodoc", "1");
+%feature("docstring");
+
+%newobject MED_RENUMBER::RenumberingFactory;
+
+%nodefaultctor;
+
+%rename (InterpKernelException) INTERP_KERNEL::Exception;
+
+%include "MEDCouplingRefCountObject.i"
+%include "MEDCouplingMemArray.i"
+
+class Renumbering
+{
+public:
+  %extend
+  {
+    virtual PyObject *renumber(const ParaMEDMEM::DataArrayInt *graph, const ParaMEDMEM::DataArrayInt *index_graph) throw(INTERP_KERNEL::Exception)
+    {
+      if(!graph || !index_graph)
+        throw INTERP_KERNEL::Exception("wrap of Renumbering::renumber : One of the input arrays is NULL !");
+      if(!graph->isAllocated() || !index_graph->isAllocated())
+        throw INTERP_KERNEL::Exception("wrap of Renumbering::renumber : One of the input arrays is not allocated !");
+      ParaMEDMEM::DataArrayInt *out0(0),*out1(0);
+      self->renumber(graph->begin(),index_graph->begin(),index_graph->getNumberOfTuples()-1,out0,out1);
+      PyObject *ret=PyTuple_New(2);
+      PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(out0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+      PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(out1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+      return ret;
+    }
+  }
+  virtual ~Renumbering();
+};
+
+namespace MED_RENUMBER
+{
+  Renumbering *RenumberingFactory(const std::string& s) throw(INTERP_KERNEL::Exception);
+}
+
+%pythoncode %{
+import os
+__filename=os.environ.get('PYTHONSTARTUP')
+if __filename and os.path.isfile(__filename):
+  execfile(__filename)
+  pass
+%}
diff --git a/src/RENUMBER_Swig/MEDRenumberTest.py b/src/RENUMBER_Swig/MEDRenumberTest.py
new file mode 100644 (file)
index 0000000..1539adf
--- /dev/null
@@ -0,0 +1,20 @@
+from MEDRenumber import *
+import unittest
+
+class MEDRenumberTest(unittest.TestCase):
+    def test1(self):
+        from MEDCoupling import MEDCouplingCMesh
+        ren=RenumberingFactory("BOOST")
+        arr=DataArrayDouble(10) ; arr.iota()
+        c=MEDCouplingCMesh() ; c.setCoords(arr,arr)
+        m=c.buildUnstructured()
+        a,b=m.computeNeighborsOfCells()
+        n2o,o2n=ren.renumber(a,b)
+        self.assertTrue(o2n.isEqual(DataArrayInt([0,2,5,9,14,20,27,35,44,1,4,8,13,19,26,34,43,52,3,7,12,18,25,33,42,51,59,6,11,17,24,32,41,50,58,65,10,16,23,31,40,49,57,64,70,15,22,30,39,48,56,63,69,74,21,29,38,47,55,62,68,73,77,28,37,46,54,61,67,72,76,79,36,45,53,60,66,71,75,78,80])))
+        pass
+
+    def setUp(self):
+        pass
+    pass
+
+unittest.main()