]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Swig addition.
authorageay <ageay>
Wed, 11 Mar 2009 17:24:40 +0000 (17:24 +0000)
committerageay <ageay>
Wed, 11 Mar 2009 17:24:40 +0000 (17:24 +0000)
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py [new file with mode: 0644]
src/MEDCoupling_Swig/MEDCouplingTypemaps.i [new file with mode: 0644]
src/MEDCoupling_Swig/Makefile.am [new file with mode: 0644]
src/MEDCoupling_Swig/libMEDCoupling_Swig.i [new file with mode: 0644]
src/ParaMEDMEM_Swig/Makefile.am
src/ParaMEDMEM_Swig/libParaMEDMEM_Swig.i
src/ParaMEDMEM_Swig/libParaMEDMEM_Swig.typemap
src/ParaMEDMEM_Swig/test_IntersectionDEC.py
src/ParaMEDMEM_Swig/test_StructuredCoincodentDEC.py

diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py
new file mode 100644 (file)
index 0000000..66c9167
--- /dev/null
@@ -0,0 +1,61 @@
+from libMEDCoupling_Swig import *
+import unittest
+
+class MEDCouplingBasicsTest(unittest.TestCase):
+    def testMesh(self):
+        tab4=[1, 2, 8, 7, 2, 3, 9, 8, 3,
+              4, 10, 9, 4, 5, 11, 10, 5,
+              0, 6, 11, 0, 1, 7, 6 ]
+        nbOfNodes=12
+        nbOfCells=6
+        coords=[ 0.024155, 0.04183768725682622, -0.305, 0.04831000000000001, -1.015761910347357e-17,
+                 -0.305, 0.09662000000000001, -1.832979297858306e-18, -0.305, 0.120775, 0.04183768725682623,
+                 -0.305, 0.09662000000000001, 0.08367537451365245, -0.305, 0.04831000000000001, 0.08367537451365246,
+                 -0.305, 0.024155, 0.04183768725682622, -0.2863, 0.04831000000000001, -1.015761910347357e-17, -0.2863, 
+                 0.09662000000000001, -1.832979297858306e-18, -0.2863, 0.120775, 0.04183768725682623, -0.2863, 0.09662000000000001,
+                 0.08367537451365245, -0.2863, 0.04831000000000001, 0.08367537451365246, -0.2863 ]
+        mesh=MEDCouplingUMesh.New()
+        mesh.setMeshDimension(2)
+        mesh.allocateCells(8);
+        mesh.setName("mesh1")
+        self.failUnless(mesh.getName()=="mesh1")
+        for i in range(nbOfCells):
+            mesh.insertNextCell(NORM_QUAD4,4,tab4[4*i:4*(i+1)]);
+            pass
+        mesh.finishInsertingCells()
+        self.failUnless(mesh.getNumberOfCells()==nbOfCells)
+        self.failUnless(mesh.getNodalConnectivity().getNbOfElems()==30)
+        self.failUnless(mesh.getNodalConnectivityIndex().getNbOfElems()==nbOfCells+1)
+        myCoords=DataArrayDouble.New()
+        myCoords.setValues(coords,nbOfNodes,3);
+        self.failUnless(myCoords.getIJ(3,2)==-0.305)
+        mesh.setCoords(myCoords);
+        mesh.checkCoherency();
+        self.failUnless(mesh.getAllTypes()==[4])
+        myFalseConn=DataArrayInt.New()
+        myFalseConn.setValues(tab4,6,4)
+        self.failUnless(myFalseConn.getIJ(1,1)==3)
+        #
+        field=MEDCouplingFieldDouble.New(ON_CELLS)
+        field.setMesh(mesh)
+        myCoords=DataArrayDouble.New()
+        sampleTab=[]
+        for i in range(nbOfCells*9):
+            sampleTab.append(float(i))
+        myCoords.setValues(sampleTab,nbOfCells,9);
+        field.setArray(myCoords)
+        self.failUnless(3==mesh.getSpaceDimension())
+        field.checkCoherency()
+        mesh2=mesh.clone(False)
+        mesh3=mesh.clone(True)
+        mesh3=0
+        mesh2=0
+        ## deep full recursively copy of field -> both field and mesh underneath copied
+        field2=field.clone(True)
+        field2.setMesh(field.getMesh().clone(True))
+        pass
+    def setUp(self):
+        pass
+    pass
+
+unittest.main()
diff --git a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i
new file mode 100644 (file)
index 0000000..c3a33b1
--- /dev/null
@@ -0,0 +1,128 @@
+//  Copyright (C) 2007-2008  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
+//
+
+static PyObject* convertMesh(ParaMEDMEM::MEDCouplingMesh* mesh, int owner)
+{
+  PyObject *ret;
+  if(dynamic_cast<ParaMEDMEM::MEDCouplingUMesh *>(mesh))
+    ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,owner);
+  return ret;
+}
+
+static PyObject *convertIntArrToPyList(const int *ptr, int size)
+{
+  PyObject *ret=PyList_New(size);
+  for(int i=0;i<size;i++)
+    PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
+  return ret;
+}
+
+static int *convertPyToNewIntArr(PyObject *pyLi, int size)
+{
+  if(PyList_Check(pyLi))
+    {
+      int *tmp=new int[size];
+      for(int i=0;i<size;i++)
+        {
+          PyObject *o=PyList_GetItem(pyLi,i);
+          if(PyInt_Check(o))
+            {
+              int val=(int)PyInt_AS_LONG(o);
+              tmp[i]=val;
+            }
+          else
+            {
+              PyErr_SetString(PyExc_TypeError,"list must contain integers only");
+              return NULL;
+            }
+        }
+      return tmp;
+    }
+  else
+    {
+      PyErr_SetString(PyExc_TypeError,"convertPyToNewIntArr : not a list");
+      return 0;
+    }
+}
+
+static int *convertPyToNewIntArr2(PyObject *pyLi)
+{
+  if(PyList_Check(pyLi))
+    {
+      int size=PyList_Size(pyLi);
+      int *tmp=new int[size];
+      for(int i=0;i<size;i++)
+        {
+          PyObject *o=PyList_GetItem(pyLi,i);
+          if(PyInt_Check(o))
+            {
+              int val=(int)PyInt_AS_LONG(o);
+              tmp[i]=val;
+            }
+          else
+            {
+              PyErr_SetString(PyExc_TypeError,"list must contain integers only");
+              return NULL;
+            }
+        }
+      return tmp;
+    }
+  else
+    {
+      PyErr_SetString(PyExc_TypeError,"convertPyToNewIntArr : not a list");
+      return 0;
+    }
+}
+
+static PyObject *convertDblArrToPyList(const double *ptr, int size)
+{
+  PyObject *ret=PyList_New(size);
+  for(int i=0;i<size;i++)
+    PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
+  return ret;
+}
+
+static double *convertPyToNewDblArr2(PyObject *pyLi)
+{
+  if(PyList_Check(pyLi))
+    {
+      int size=PyList_Size(pyLi);
+      double *tmp=new double[size];
+      for(int i=0;i<size;i++)
+        {
+          PyObject *o=PyList_GetItem(pyLi,i);
+          if(PyFloat_Check(o))
+            {
+              double val=PyFloat_AS_DOUBLE(o);
+              tmp[i]=val;
+            }
+          else
+            {
+              PyErr_SetString(PyExc_TypeError,"list must contain floats only");
+              return NULL;
+            }
+        }
+      return tmp;
+    }
+  else
+    {
+      PyErr_SetString(PyExc_TypeError,"convertPyToNewIntArr : not a list");
+      return 0;
+    }
+}
diff --git a/src/MEDCoupling_Swig/Makefile.am b/src/MEDCoupling_Swig/Makefile.am
new file mode 100644 (file)
index 0000000..6fe19c2
--- /dev/null
@@ -0,0 +1,52 @@
+#  MED MEDMEM_SWIG : binding of C++ implementation and Python
+#
+#  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+#  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+# 
+#  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 $(top_srcdir)/adm_local/unix/make_common_starter.am
+
+lib_LTLIBRARIES = _libMEDCoupling_Swig.la
+
+salomeinclude_HEADERS =  \
+       libMEDCoupling_Swig.i
+
+SWIG_DEF = libMEDCoupling_Swig.i
+
+SWIG_FLAGS = @SWIG_FLAGS@ -I$(srcdir)
+
+dist__libMEDCoupling_Swig_la_SOURCES   = libMEDCoupling_Swig.i
+nodist__libMEDCoupling_Swig_la_SOURCES = libMEDCoupling_Swig_wrap.cxx
+libMEDCoupling_Swig.py: libMEDCoupling_Swig_wrap.cxx
+
+libMEDCoupling_Swig_wrap.cxx: $(SWIG_DEF)
+       $(SWIG) $(SWIG_FLAGS) -I$(srcdir)/../MEDCoupling -I$(srcdir)/../INTERP_KERNEL/Bases -o $@  $<
+
+_libMEDCoupling_Swig_la_CPPFLAGS = $(CORBA_CXXFLAGS) $(CORBA_INCLUDES) $(PYTHON_INCLUDES) \
+       $(MED2_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \
+       -I$(srcdir)/../MEDCoupling -I$(srcdir)/../INTERP_KERNEL -I$(srcdir)/../INTERP_KERNEL/Bases
+
+_libMEDCoupling_Swig_la_LDFLAGS  = -module $(MED2_LIBS) $(HDF5_LIBS) $(PYTHON_LIBS) $(MPI_LIBS) \
+       ../MEDCoupling/libmedcoupling.la ../INTERP_KERNEL/libinterpkernel.la
+
+CLEANFILES = libMEDCoupling_Swig_wrap.cxx libMEDCoupling_Swig.py
+
+nodist_salomescript_DATA= libMEDCoupling_Swig.py
+
+dist_salomescript_DATA= MEDCouplingBasicsTest.py
diff --git a/src/MEDCoupling_Swig/libMEDCoupling_Swig.i b/src/MEDCoupling_Swig/libMEDCoupling_Swig.i
new file mode 100644 (file)
index 0000000..afd7ae2
--- /dev/null
@@ -0,0 +1,179 @@
+//  Copyright (C) 2007-2008  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
+//
+%module libMEDCoupling_Swig
+
+%{
+#include "MemArray.hxx"
+#include "MEDCouplingUMesh.hxx"
+#include "MEDCouplingField.hxx"
+#include "MEDCouplingFieldDouble.hxx"
+#include "MEDCouplingTypemaps.i"
+
+using namespace ParaMEDMEM;
+using namespace INTERP_KERNEL;
+%}
+
+%typemap(out) ParaMEDMEM::MEDCouplingMesh*
+{
+  $result=convertMesh($1,$owner);
+}
+
+%newobject ParaMEDMEM::DataArrayDouble::New;
+%newobject ParaMEDMEM::DataArrayInt::New;
+%newobject ParaMEDMEM::MEDCouplingUMesh::New;
+%newobject ParaMEDMEM::MEDCouplingFieldDouble::New;
+%newobject ParaMEDMEM::MEDCouplingUMesh::clone;
+%newobject ParaMEDMEM::DataArrayDouble::deepCopy;
+%newobject ParaMEDMEM::DataArrayDouble::performCpy;
+%newobject ParaMEDMEM::DataArrayInt::deepCopy;
+%newobject ParaMEDMEM::DataArrayInt::performCpy;
+%newobject ParaMEDMEM::MEDCouplingFieldDouble::clone;
+%newobject ParaMEDMEM::MEDCouplingUMesh::buildPartOfMySelf;
+%newobject ParaMEDMEM::MEDCouplingUMesh::zipCoordsTraducer;
+%feature("unref") DataArrayDouble "$this->decrRef();"
+%feature("unref") MEDCouplingUMesh "$this->decrRef();"
+%feature("unref") DataArrayInt "$this->decrRef();"
+%feature("unref") MEDCouplingFieldDouble "$this->decrRef();"
+
+%ignore ParaMEDMEM::TimeLabel::operator=;
+%ignore ParaMEDMEM::MemArray::operator=;
+%ignore ParaMEDMEM::MemArray::operator[];
+
+%nodefaultctor;
+%include "TimeLabel.hxx"
+%include "RefCountObject.hxx"
+%include "MEDCouplingMesh.hxx"
+%include "MemArray.hxx"
+%include "MEDCouplingMesh.hxx"
+%include "NormalizedUnstructuredMesh.hxx"
+%include "MEDCouplingField.hxx"
+
+namespace ParaMEDMEM
+{
+  class MEDCouplingUMesh : public ParaMEDMEM::MEDCouplingMesh
+  {
+  public:
+    static MEDCouplingUMesh *New();
+    MEDCouplingUMesh *clone(bool recDeepCpy) const;
+    void updateTime();
+    void checkCoherency() const throw(INTERP_KERNEL::Exception);
+    void setMeshDimension(unsigned meshDim);
+    void allocateCells(int nbOfCells);
+    void setCoords(DataArrayDouble *coords);
+    DataArrayDouble *getCoords() const;
+    void finishInsertingCells();
+    void setConnectivity(DataArrayInt *conn, DataArrayInt *connIndex, bool isComputingTypes=true);
+    DataArrayInt *getNodalConnectivity() const;
+    DataArrayInt *getNodalConnectivityIndex() const;
+    INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const;
+    int getNumberOfNodesInCell(int cellId) const;
+    bool isStructured() const;
+    int getNumberOfCells() const;
+    int getNumberOfNodes() const;
+    int getSpaceDimension() const;
+    int getMeshDimension() const;
+    int getMeshLength() const;
+    //tools
+    void zipCoords();
+    DataArrayInt *zipCoordsTraducer();
+    void getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const;
+    MEDCouplingUMesh *buildPartOfMySelf(const int *start, const int *end, bool keepCoords) const;
+    %extend {
+      void insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, PyObject *li)
+      {
+        int *tmp=convertPyToNewIntArr(li,size);
+        self->insertNextCell(type,size,tmp);
+        delete [] tmp;
+      }
+      PyObject *getAllTypes() const
+      {
+        std::set<INTERP_KERNEL::NormalizedCellType> result=self->getAllTypes();
+        std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator iL=result.begin();
+        PyObject *res = PyList_New(result.size());
+        for (int i=0;iL!=result.end(); i++, iL++)
+          PyList_SetItem(res,i,PyInt_FromLong(*iL));
+        return res;
+      }
+    }
+  };
+}
+
+%extend ParaMEDMEM::DataArrayDouble
+ {
+   void setValues(PyObject *li, int nbOfTuples, int nbOfElsPerTuple)
+   {
+     double *tmp=convertPyToNewDblArr2(li);
+     self->useArray(tmp,true,CPP_DEALLOC,nbOfTuples,nbOfElsPerTuple);
+   }
+
+   PyObject *getValues()
+   {
+     const double *vals=self->getPointer();
+     return convertDblArrToPyList(vals,self->getNbOfElems());
+   }
+ };
+
+%extend ParaMEDMEM::DataArrayInt
+ {
+   void setValues(PyObject *li, int nbOfTuples, int nbOfElsPerTuple)
+   {
+     int *tmp=convertPyToNewIntArr2(li);
+     self->useArray(tmp,true,CPP_DEALLOC,nbOfTuples,nbOfElsPerTuple);
+   }
+
+   PyObject *getValues()
+   {
+     const int *vals=self->getPointer();
+     return convertIntArrToPyList(vals,self->getNbOfElems());
+   }
+ };
+
+%include "MEDCouplingField.hxx"
+
+namespace ParaMEDMEM
+{
+  class MEDCouplingFieldDouble : public ParaMEDMEM::MEDCouplingField
+  {
+  public:
+    static MEDCouplingFieldDouble *New(TypeOfField type);
+    MEDCouplingFieldDouble *clone(bool recDeepCpy) const;
+    void checkCoherency() const throw(INTERP_KERNEL::Exception);
+    double getIJ(int tupleId, int compoId) const;
+    void setArray(DataArrayDouble *array);
+    DataArrayDouble *getArray() const { return _array; }
+    void applyLin(double a, double b, int compoId);
+    int getNumberOfComponents() const;
+    int getNumberOfTuples() const throw(INTERP_KERNEL::Exception);
+    void updateTime();
+    %extend {
+      void setValues(PyObject *li)
+      {
+        if(self->getArray()!=0)
+          {
+            double *tmp=convertPyToNewDblArr2(li);
+            int nbTuples=self->getArray()->getNumberOfTuples();
+            int nbOfCompo=self->getArray()->getNumberOfComponents();
+            self->getArray()->useArray(tmp,true,CPP_DEALLOC,nbTuples,nbOfCompo);
+          }
+        else
+          PyErr_SetString(PyExc_TypeError,"setValuesCpy : field must contain an array behind");
+      }
+    }
+  };
+}
index 7c0d356d7251210d0be1f3b9fc05c9d61e2a105b..e41cf767237db8529584ce786a3621392498b191 100644 (file)
@@ -29,7 +29,8 @@ salomeinclude_HEADERS =  \
 
 SWIG_DEF = libParaMEDMEM_Swig.i
 
-SWIG_FLAGS = @SWIG_FLAGS@ -I$(srcdir) $(MPI_INCLUDES) -I$(srcdir)/../MEDMEM_SWIG
+SWIG_FLAGS = @SWIG_FLAGS@ -I$(srcdir) $(MPI_INCLUDES)  -I$(srcdir)/../ParaMEDMEM -I$(srcdir)/../MEDCoupling -I$(srcdir)/../MEDCoupling_Swig \
+       -I$(srcdir)/../INTERP_KERNEL -I$(srcdir)/../INTERP_KERNEL/Bases -I$(srcdir)/../ParaMEDMEM/MEDLoader
 
 dist__libParaMEDMEM_Swig_la_SOURCES   = libParaMEDMEM_Swig.i
 nodist__libParaMEDMEM_Swig_la_SOURCES = libParaMEDMEM_Swig_wrap.cxx
@@ -40,13 +41,13 @@ libParaMEDMEM_Swig_wrap.cxx: $(SWIG_DEF)
 
 _libParaMEDMEM_Swig_la_CPPFLAGS = $(CORBA_CXXFLAGS) $(CORBA_INCLUDES) $(PYTHON_INCLUDES) \
        $(MED2_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \
-       -I$(srcdir)/../MEDMEM -I$(srcdir)/../MEDWrapper/V2_1/Core -I$(srcdir)/../INTERP_KERNEL \
-       $(MPI_INCLUDES) -I$(srcdir)/../ParaMEDMEM -I$(srcdir)/../MEDMEM_SWIG -I$(srcdir)/../INTERP_KERNEL/Bases \
-       -I$(srcdir)/../MEDCoupling
+       -I$(srcdir)/../INTERP_KERNEL \
+       $(MPI_INCLUDES) -I$(srcdir)/../ParaMEDMEM -I$(srcdir)/../MEDCoupling_Swig -I$(srcdir)/../INTERP_KERNEL/Bases \
+       -I$(srcdir)/../MEDCoupling -I$(srcdir)/../ParaMEDMEM/MEDLoader
 
 _libParaMEDMEM_Swig_la_LDFLAGS  = -module $(MED2_LIBS) $(HDF5_LIBS) $(PYTHON_LIBS) $(MPI_LIBS) \
-       ../MEDMEM/libmedmem.la ../INTERP_KERNEL/libinterpkernel.la \
-       ../ParaMEDMEM/libparamedmem.la 
+       ../MEDCoupling/libmedcoupling.la ../INTERP_KERNEL/libinterpkernel.la \
+       ../ParaMEDMEM/libparamedmem.la ../ParaMEDMEM/MEDLoader/libparamedmemmedloader.la
 
 if MED_ENABLE_KERNEL
   _libParaMEDMEM_Swig_la_CPPFLAGS += ${KERNEL_CXXFLAGS}
index 435b7ead466b08a46e4b0c855d2ac847bdeabe0e..8bd9bca8ee26efb3bf19e7895b3fd8a37f6eab46 100644 (file)
 %module libParaMEDMEM_Swig
 
 %include "libParaMEDMEM_Swig.typemap"
-%include "../MEDMEM_SWIG/libMEDMEM_Swig.i"
+%include "libMEDCoupling_Swig.i"
 
 %{
-#include <CommInterface.hxx>
-#include <ProcessorGroup.hxx>
-#include <Topology.hxx>
-#include <MPIProcessorGroup.hxx>
-#include <DEC.hxx>
-#include <IntersectionDEC.hxx>
-#include <NonCoincidentDEC.hxx>
-#include <StructuredCoincidentDEC.hxx>
-#include <ParaMESH.hxx>
-#include <UnstructuredParaSUPPORT.hxx>
-#include <StructuredParaSUPPORT.hxx>
-#include <ParaFIELD.hxx>
-#include <ICoCoMEDField.hxx>
+#include "CommInterface.hxx"
+#include "ProcessorGroup.hxx"
+#include "Topology.hxx"
+#include "MPIProcessorGroup.hxx"
+#include "DEC.hxx"
+#include "IntersectionDEC.hxx"
+#include "NonCoincidentDEC.hxx"
+#include "StructuredCoincidentDEC.hxx"
+#include "ParaMESH.hxx"
+#include "ParaFIELD.hxx"
+#include "ICoCoMEDField.hxx"
+
+#include "MEDLoader.hxx"
 
 #include <mpi.h>
 
 using namespace ParaMEDMEM;
 using namespace ICoCo;
-
- enum mpi_constants { mpi_comm_world, mpi_comm_self, mpi_double, mpi_int };
-
+      
+enum mpi_constants { mpi_comm_world, mpi_comm_self, mpi_double, mpi_int };
 %}
 
+%newobject MEDLoader::ReadUMeshFromFile;
 
-class CommInterface {
-public:
-  CommInterface();
-};
-
-class ProcessorGroup {
-public:
-  %extend {
-  // avoid error when SWIG creates a default constructor of an abstract class
-  ProcessorGroup() { return NULL; }
-  }
-};
-
-class MPIProcessorGroup: public ProcessorGroup {
-public:
-  MPIProcessorGroup(const CommInterface& interface);
-  MPIProcessorGroup(const CommInterface& interface, set<int> proc_ids);
-  MPIProcessorGroup(const CommInterface& interface,int pstart, int pend);
-
-  int translateRank(const ProcessorGroup* group, int rank) const;
-  ProcessorGroup* createComplementProcGroup() const;
-  ProcessorGroup* fuse (const ProcessorGroup&) const;
+%include "ComponentTopology.hxx"
+%include "CommInterface.hxx"
+%include "ProcessorGroup.hxx"
+%include "DECOptions.hxx"
+%include "ParaMESH.hxx"
+%include "ParaFIELD.hxx"
+%include "MPIProcessorGroup.hxx"
+%include "DEC.hxx"
+%include "IntersectionDEC.hxx"
+%include "StructuredCoincidentDEC.hxx"
 
-  bool containsMyRank() const;
-  int myRank() const;
-};
+%rename(ICoCoMEDField) ICoCo::MEDField;
+%include "ICoCoMEDField.hxx"
 
-%rename(ICoCo_MEDField) ICoCo::MEDField;
-namespace ICoCo {
-class Field {
-}; 
+%nodefaultctor;
 
-class MEDField: public Field {
-public:
- MEDField(ParaMESH* mesh, ParaFIELD* field);
-};
+namespace MEDLoader
+{
+  ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, const char *meshName=0, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception);
 }
 
-class DEC {
-public:
-  %extend {
-  // avoid error when SWIG creates a default constructor of an abstract class
-  DEC() { return NULL; };
-  }
-  void recvData();
-  void sendData();
-  void synchronize();
-
-  void attachLocalField(FIELD<double>*      field, const char* method="P0");
-  void attachLocalField(const ParaFIELD*    field, const char* method="P0");
-  void attachLocalField(const ICoCo::Field* field, const char* method="P0");
-
-  void renormalizeTargetField();
-};
-
-
-typedef enum{WithoutTimeInterp,LinearTimeInterp} TimeInterpolationMethod;
-
-typedef enum{Native,PointToPoint} AllToAllMethod;
-
-class IntersectionDEC: public DEC { 
-public:
-
-  IntersectionDEC(ProcessorGroup& local_group, ProcessorGroup&  distant_group);
-  
-  void recvData();
-  void recvData( double time );
-
-  void sendData();
-  void sendData( double time, double deltatime );
-
-  void setTimeInterpolationMethod(TimeInterpolationMethod it);
-  TimeInterpolationMethod getTimeInterpolationMethod();
-
-  void setAsynchronous( bool dr);
-  bool getAsynchronous();
-
-  AllToAllMethod getAllToAllMethod();
-  void setAllToAllMethod(AllToAllMethod sp);
-
-  bool getForcedRenormalization();
-  void setForcedRenormalization( bool dr);
-};
-
-
-
 /* This object can be used only if MED_ENABLE_FVM is defined*/
 #ifdef MED_ENABLE_FVM
-class NonCoincidentDEC: public DEC {
+class NonCoincidentDEC : public DEC
+{
 public:
   NonCoincidentDEC(ProcessorGroup& source, ProcessorGroup& target);
 };
 #endif
 
-
-class StructuredCoincidentDEC: public DEC {
-public:
-  StructuredCoincidentDEC(ProcessorGroup& source, ProcessorGroup& target);
-  void prepareSourceDE();
-  void prepareTargetDE();
-};
-
-
-class ParaMESH {
-public:
-  ParaMESH(driverTypes driver_type, const char* file_name, const ProcessorGroup& group);
-  ParaMESH(MESH& subdomain_mesh, const ProcessorGroup& proc_group, const char* name);
-
-  void write(driverTypes driverType, const char* fileName="");
-  MESH* getMesh() const;
-};
-
-
-
-class ParaSUPPORT {
-public:
-  %extend {
-  // avoid error when SWIG creates a default constructor of an abstract class
-  ParaSUPPORT() { return NULL; }
-
-  PyObject* getGlobalNumbering() {
-    const int * numIndex = self->getGlobalNumbering();
-    int aSize = self->getSupport()->getNumberOfElements(999);
-    TYPEMAP_OUTPUT_ARRAY(numIndex, aSize, PyInt_FromLong, ParaSUPPORT::getGlobalNumbering);
-  }
+%extend ParaMEDMEM::ParaMESH
+{
+  PyObject *getGlobalNumberingCell2() const
+  {
+    const int *tmp=self->getGlobalNumberingCell();
+    int size=self->getCellMesh()->getNumberOfCells();
+    PyObject *ret=PyList_New(size);
+    for(int i=0;i<size;i++)
+      PyList_SetItem(ret,i,PyInt_FromLong(tmp[i])); 
+    return ret;
   }
-};
-
-
-class UnstructuredParaSUPPORT: public ParaSUPPORT {
-public:
-  UnstructuredParaSUPPORT(const ParaMESH* const mesh, const SUPPORT* support );
-  UnstructuredParaSUPPORT(const ParaMESH* const mesh, const medEntityMesh entity);
-  UnstructuredParaSUPPORT(const SUPPORT* support, const ProcessorGroup& group);
-};
-
-class StructuredParaSUPPORT: public ParaSUPPORT {
-public:
-  StructuredParaSUPPORT(const ParaGRID* const grid, const medEntityMesh entity);
-  StructuredParaSUPPORT(const ParaMESH* const mesh, const medEntityMesh entity);
-};
-
-class ComponentTopology {
-public:
-  ComponentTopology();
-  ComponentTopology(int nb_comp);
-  ComponentTopology(int nb_comp, int nb_blocks);
-  ComponentTopology(int nb_comp, ProcessorGroup* group);
-
-  int nbComponents();
-  int nbLocalComponents();
-};
-
-
-class ParaFIELD {
-public:
-  ParaFIELD(const ParaSUPPORT* support,
-            const ComponentTopology& component_topology);
 
-  ParaFIELD(driverTypes driver_type,
-            const char* file_name, 
-           const char* driver_name,
-            const ComponentTopology& component_topology);
-
-  ParaFIELD(FIELDDOUBLE* field, const ProcessorGroup& group);
-
-  void write(driverTypes driverType, 
-             const char* fileName="", 
-             const char* meshName="");
-
-  FIELDDOUBLE* getField() const;
+  PyObject *getGlobalNumberingFace2() const
+  {
+    const int *tmp=self->getGlobalNumberingFace();
+    int size=self->getFaceMesh()->getNumberOfCells();
+    PyObject *ret=PyList_New(size);
+    for(int i=0;i<size;i++)
+      PyList_SetItem(ret,i,PyInt_FromLong(tmp[i])); 
+    return ret;
+  }
 
-  double getVolumeIntegral(int icomp) const;
-};
+  PyObject *getGlobalNumberingNode2() const
+  {
+    const int *tmp=self->getGlobalNumberingNode();
+    int size=self->getCellMesh()->getNumberOfNodes();
+    PyObject *ret=PyList_New(size);
+    for(int i=0;i<size;i++)
+      PyList_SetItem(ret,i,PyInt_FromLong(tmp[i])); 
+    return ret;
+  }
+}
 
 //=============================================================================================
 // Interface for MPI-realization-specific constants like MPI_COMM_WORLD.
@@ -238,60 +126,67 @@ enum mpi_constants { mpi_comm_world, mpi_comm_self, mpi_double, mpi_int };
 // Map mpi_comm_world and mpi_comm_self -> MPI_COMM_WORLD and MPI_COMM_SELF
 %typemap(in) MPI_Comm
 { 
-  switch (PyInt_AsLong($input)) {
-  case mpi_comm_world: $1 = MPI_COMM_WORLD; break;
-  case mpi_comm_self:  $1 = MPI_COMM_SELF;  break;
-  default:
-    PyErr_SetString(PyExc_TypeError,"unexpected value of MPI_Comm");
-    return NULL;
-  }
+  switch (PyInt_AsLong($input))
+    {
+    case mpi_comm_world: $1 = MPI_COMM_WORLD; break;
+    case mpi_comm_self:  $1 = MPI_COMM_SELF;  break;
+    default:
+      PyErr_SetString(PyExc_TypeError,"unexpected value of MPI_Comm");
+      return NULL;
+    }
 }
 // Map mpi_double and mpi_int -> MPI_DOUBLE and MPI_INT
 %typemap(in) MPI_Datatype
 { 
-  switch (PyInt_AsLong($input)) {
-  case mpi_double:     $1 = MPI_DOUBLE;     break;
-  case mpi_int:        $1 = MPI_INT;        break;
-  default:
-    PyErr_SetString(PyExc_TypeError,"unexpected value of MPI_Datatype");
-    return NULL;
-  }
+  switch (PyInt_AsLong($input))
+    {
+    case mpi_double:     $1 = MPI_DOUBLE;     break;
+    case mpi_int:        $1 = MPI_INT;        break;
+    default:
+      PyErr_SetString(PyExc_TypeError,"unexpected value of MPI_Datatype");
+      return NULL;
+    }
 }
 // The following code gets inserted into the result python file:
 // create needed python symbols
 %pythoncode %{
-  MPI_COMM_WORLD = mpi_comm_world
-  MPI_COMM_SELF  = mpi_comm_self
-  MPI_DOUBLE     = mpi_double
-  MPI_INT        = mpi_int
+MPI_COMM_WORLD = mpi_comm_world
+MPI_COMM_SELF  = mpi_comm_self
+MPI_DOUBLE     = mpi_double
+MPI_INT        = mpi_int
 %}
 //=============================================================================================
 
 // ==============
 // MPI_Comm_size
 // ==============
-%inline %{ PyObject* MPI_Comm_size(MPI_Comm comm) {
-  int res = 0;
-  int err = MPI_Comm_size(comm, &res);
-  if ( err != MPI_SUCCESS ) {
-    PyErr_SetString(PyExc_RuntimeError,"Erorr in MPI_Comm_size()");
-    return NULL;
-  }
-  return PyInt_FromLong( res );
-} %}
+%inline %{ PyObject* MPI_Comm_size(MPI_Comm comm)
+  {
+    int res = 0;
+    int err = MPI_Comm_size(comm, &res);
+    if ( err != MPI_SUCCESS )
+      {
+        PyErr_SetString(PyExc_RuntimeError,"Erorr in MPI_Comm_size()");
+        return NULL;
+      }
+    return PyInt_FromLong( res );
+  } %}
 
 // ==============
 // MPI_Comm_rank
 // ==============
-%inline %{ PyObject* MPI_Comm_rank(MPI_Comm comm) {
-  int res = 0;
-  int err = MPI_Comm_rank(comm, &res);
-  if ( err != MPI_SUCCESS ) {
-    PyErr_SetString(PyExc_RuntimeError,"Erorr in MPI_Comm_rank()");
-    return NULL;
-  }
-  return PyInt_FromLong( res );
-} %}
+%inline %{ PyObject* MPI_Comm_rank(MPI_Comm comm)
+  {
+    int res = 0;
+    int err = MPI_Comm_rank(comm, &res);
+    if ( err != MPI_SUCCESS )
+      {
+        PyErr_SetString(PyExc_RuntimeError,"Erorr in MPI_Comm_rank()");
+        return NULL;
+      }
+    return PyInt_FromLong( res );
+  } 
+  %}
 
 int MPI_Init(int *argc, char ***argv );
 int MPI_Barrier(MPI_Comm comm);
@@ -301,61 +196,73 @@ int MPI_Finalize();
 // MPI_Bcast
 // ==========
 
-%inline %{ PyObject* MPI_Bcast(PyObject* buffer, int nb, MPI_Datatype type, int root, MPI_Comm c) {
-  // buffer must be a list
-  if (!PyList_Check(buffer)) {
-    PyErr_SetString(PyExc_TypeError, "buffer is expected to be a list");
-    return NULL;
-  }
-  // check list size
-  int aSize = PyList_Size(buffer);
-  if ( aSize != nb ) {
-    PyErr_SetString(PyExc_ValueError, MEDMEM::STRING("buffer is expected to be of size ")<<nb);
-    return NULL;
-  }
-  // allocate and fill a buffer
-  void* aBuf = 0;
-  int* intBuf = 0;
-  double* dblBuf = 0;
-  if ( type == MPI_DOUBLE ) {
-    aBuf = (void*) ( dblBuf = new double[ nb ] );
-    for ( int i = 0; i < aSize; ++i )
-      dblBuf[i] = PyFloat_AS_DOUBLE( PyList_GetItem( buffer, i ));
-  }
-  else if ( type == MPI_INT ) {
-    aBuf = (void*) ( intBuf = new int[ nb ] );
-    for ( int i = 0; i < aSize; ++i )
-      intBuf[i] = int( PyInt_AS_LONG( PyList_GetItem( buffer, i )));
-  }
-  else {
-    PyErr_SetString(PyExc_TypeError, "Only MPI_DOUBLE and MPI_INT supported");
-    return NULL;
-  }
-  // call MPI_Bcast
-  int err = MPI_Bcast(aBuf, nb, type, root, c);
-  // treat error
-  if ( err != MPI_SUCCESS ) {
-    PyErr_SetString(PyExc_RuntimeError,"Erorr in MPI_Bcast()");
-    delete [] intBuf; delete [] dblBuf;
-    return NULL;
-  }
-  // put recieved data into the list
-  int pyerr = 0;
-  if ( type == MPI_DOUBLE ) {
-    for ( int i = 0; i < aSize && !pyerr; ++i )
-      pyerr = PyList_SetItem(buffer, i, PyFloat_FromDouble( dblBuf[i] ));
-    delete [] dblBuf;
-  }
-  else {
-    for ( int i = 0; i < aSize && !pyerr; ++i )
-      pyerr = PyList_SetItem(buffer, i, PyInt_FromLong( intBuf[i] ));
-    delete [] intBuf;
-  }
-  if ( pyerr ) {
-    PyErr_SetString(PyExc_RuntimeError, "Error of PyList_SetItem()");
-    return NULL;
-  }
-  return PyInt_FromLong( err );
+%inline %{ PyObject* MPI_Bcast(PyObject* buffer, int nb, MPI_Datatype type, int root, MPI_Comm c)
+  {
+    // buffer must be a list
+    if (!PyList_Check(buffer))
+      {
+        PyErr_SetString(PyExc_TypeError, "buffer is expected to be a list");
+        return NULL;
+      }
+    // check list size
+    int aSize = PyList_Size(buffer);
+    if ( aSize != nb )
+      {
+        std::ostringstream stream; stream << "buffer is expected to be of size " << nb;
+        PyErr_SetString(PyExc_ValueError, stream.str().c_str());
+        return NULL;
+      }
+    // allocate and fill a buffer
+    void* aBuf = 0;
+    int* intBuf = 0;
+    double* dblBuf = 0;
+    if ( type == MPI_DOUBLE )
+      {
+        aBuf = (void*) ( dblBuf = new double[ nb ] );
+        for ( int i = 0; i < aSize; ++i )
+          dblBuf[i] = PyFloat_AS_DOUBLE( PyList_GetItem( buffer, i ));
+      }
+    else if ( type == MPI_INT )
+      {
+        aBuf = (void*) ( intBuf = new int[ nb ] );
+        for ( int i = 0; i < aSize; ++i )
+          intBuf[i] = int( PyInt_AS_LONG( PyList_GetItem( buffer, i )));
+      }
+    else
+      {
+        PyErr_SetString(PyExc_TypeError, "Only MPI_DOUBLE and MPI_INT supported");
+        return NULL;
+      }
+    // call MPI_Bcast
+    int err = MPI_Bcast(aBuf, nb, type, root, c);
+    // treat error
+    if ( err != MPI_SUCCESS )
+      {
+        PyErr_SetString(PyExc_RuntimeError,"Erorr in MPI_Bcast()");
+        delete [] intBuf; delete [] dblBuf;
+        return NULL;
+      }
+    // put recieved data into the list
+    int pyerr = 0;
+    if ( type == MPI_DOUBLE )
+      {
+        for ( int i = 0; i < aSize && !pyerr; ++i )
+          pyerr = PyList_SetItem(buffer, i, PyFloat_FromDouble( dblBuf[i] ));
+        delete [] dblBuf;
+      }
+    else
+      {
+        for ( int i = 0; i < aSize && !pyerr; ++i )
+          pyerr = PyList_SetItem(buffer, i, PyInt_FromLong( intBuf[i] ));
+        delete [] intBuf;
+      }
+    if ( pyerr )
+      {
+        PyErr_SetString(PyExc_RuntimeError, "Error of PyList_SetItem()");
+        return NULL;
+      }
+    return PyInt_FromLong( err );
 
-} %}
+  }
+  %}
 
index a9006136565e671273c96559568caad1c8d91694..cd6dc1f4bcd0164cb6db3382dfc345a848af7d4c 100644 (file)
@@ -1,3 +1,7 @@
+%include std_set.i
+%include std_string.i
+
+%template() std::set<int>;
 
 // Creates "int *argc, char ***argv" parameters from input list
 %typemap(in) (int *argc, char ***argv) {
@@ -34,7 +38,7 @@
   if (PyList_Check($input))
   {
     int size = PyList_Size($input);
-    set< TYPE > tmpSet;
+    std::set< TYPE > tmpSet;
 
     for (int i=0; i < size; i++)
     {
 }
 %enddef
 
-%typemap(in) set<int>
+%typemap(in) std::set<int>
 { 
   TYPEMAP_INPUT_SET_BY_VALUE( int ) 
 }
-%typecheck(SWIG_TYPECHECK_POINTER) set<int> {
+%typecheck(SWIG_TYPECHECK_POINTER) std::set<int> {
   $1 = PyList_Check($input) ? 1 : 0;
 }
index c36cb6cf0aac03d1222db4715f636ab377c7bb56..0b0c070d89b4004064cb5c4de7bb4223a8ff2bcf 100755 (executable)
 # 
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 # 
-from ParaMEDMEM import *
+from libParaMEDMEM_Swig import *
 import sys, os
-
-# testIntersectionDEC_2D
-
-MPI_Init(sys.argv)
-
-size = MPI_Comm_size(MPI_COMM_WORLD)
-rank = MPI_Comm_rank(MPI_COMM_WORLD)
-if size != 5:
-    raise RuntimeError, "Expect MPI_COMM_WORLD size == 5"
-
-nproc_source = 3
-procs_source = range( nproc_source )
-procs_target = range( size - nproc_source + 1, size)
-
-interface = CommInterface()
-
-target_group = MPIProcessorGroup(interface, procs_target)
-source_group = MPIProcessorGroup(interface, procs_source)
-
-dec = IntersectionDEC(source_group, target_group)
-
-mesh       =0
-support    =0
-paramesh   =0
-parafield  =0
-parasupport=0
-icocofield =0
-
-data_dir = os.environ['MED_ROOT_DIR']
-tmp_dir  = os.environ['TMP']
-
-if not tmp_dir or len(tmp_dir)==0:
-    tmp_dir = "/tmp"
+import unittest
+import math
+
+class ParaMEDMEMBasicsTest(unittest.TestCase):
+    def testIntersectionDEC_2D(self):
+        MPI_Init(sys.argv)
+        size = MPI_Comm_size(MPI_COMM_WORLD)
+        rank = MPI_Comm_rank(MPI_COMM_WORLD)
+        if size != 5:
+            raise RuntimeError, "Expect MPI_COMM_WORLD size == 5"
+        print rank
+        nproc_source = 3
+        procs_source = range( nproc_source )
+        procs_target = range( size - nproc_source + 1, size)
+        
+        interface = CommInterface()
+        target_group = MPIProcessorGroup(interface, procs_target)
+        source_group = MPIProcessorGroup(interface, procs_source)
+        dec = IntersectionDEC(source_group, target_group)
+        
+        mesh       =0
+        support    =0
+        paramesh   =0
+        parafield  =0
+        icocofield =0
+        data_dir = os.environ['MED_ROOT_DIR']
+        tmp_dir  = os.environ['TMP']
+        
+        if not tmp_dir or len(tmp_dir)==0:
+            tmp_dir = "/tmp"
+            pass
+        
+        filename_xml1 = os.path.join(data_dir, "share/salome/resources/med/square1_split")
+        filename_xml2 = os.path.join(data_dir, "share/salome/resources/med/square2_split")
+        
+        MPI_Barrier(MPI_COMM_WORLD)
+        if source_group.containsMyRank():
+            filename = filename_xml1 + str(rank+1) + ".med"
+            meshname = "Mesh_2_" + str(rank+1)
+            mesh=ReadUMeshFromFile(filename,meshname,0)
+            paramesh=ParaMESH(mesh,source_group,"source mesh")
+            comptopo = ComponentTopology()
+            parafield = ParaFIELD(ON_CELLS,paramesh, comptopo)
+            nb_local=mesh.getNumberOfCells()
+            value = [1.0]*nb_local
+            parafield.getField().setValues(value)
+            icocofield = ICoCoMEDField(paramesh,parafield)
+            dec.setMethod("P0")
+            dec.attachLocalField(icocofield)
+            pass
+        else:
+            filename = filename_xml2 + str(rank - nproc_source + 1) + ".med"
+            meshname = "Mesh_3_" + str(rank - nproc_source + 1)
+            mesh=ReadUMeshFromFile(filename,meshname,0)
+            paramesh=ParaMESH(mesh,target_group,"target mesh")
+            comptopo = ComponentTopology()
+            parafield = ParaFIELD(ON_CELLS,paramesh, comptopo)
+            nb_local=mesh.getNumberOfCells()
+            value = [0.0]*nb_local
+            parafield.getField().setValues(value)
+            icocofield = ICoCoMEDField(paramesh,parafield)
+            dec.setMethod("P0")
+            dec.attachLocalField(icocofield)
+            pass
+        
+        if source_group.containsMyRank():
+            field_before_int = parafield.getVolumeIntegral(0)
+            dec.synchronize()
+            dec.setForcedRenormalization(False)
+            dec.sendData()
+            dec.recvData()
+            field_after_int=parafield.getVolumeIntegral(0);
+            self.failUnless(math.fabs(field_after_int-field_before_int)<1e-8)
+            pass
+        else:
+            dec.synchronize()
+            dec.setForcedRenormalization(False)
+            dec.recvData()
+            dec.sendData()
+            pass
+        ## end
+        interface = 0
+        target_group = 0
+        source_group = 0
+        dec = 0
+        mesh       =0
+        support    =0
+        paramesh   =0
+        parafield  =0
+        icocofield =0
+        MPI_Barrier(MPI_COMM_WORLD)
+        MPI_Finalize()
+        pass
     pass
 
-filename_xml1 = os.path.join(data_dir, "share/salome/resources/med/square1_split")
-filename_xml2 = os.path.join(data_dir, "share/salome/resources/med/square2_split")
-
-MPI_Barrier(MPI_COMM_WORLD)
-
-if source_group.containsMyRank():
-
-    filename = filename_xml1 + str(rank+1) + ".med"
-    meshname = "Mesh_2_" + str(rank+1)
-
-    mesh = MESH(MED_DRIVER, filename, meshname)
-    support = SUPPORT(mesh, "all elements", MED_CELL)
-    paramesh = ParaMESH(mesh, source_group, "source mesh")
-
-    parasupport = UnstructuredParaSUPPORT( support, source_group)
-    comptopo = ComponentTopology()
-
-    parafield = ParaFIELD(parasupport, comptopo)
-
-    nb_local = support.getNumberOfElements(MED_ALL_ELEMENTS);
-
-    value = [1.0]*nb_local
-
-    parafield.getField().setValue(value)
-    icocofield = ICoCo_MEDField(paramesh,parafield)
-    dec.attachLocalField(icocofield,'P0')
-    pass
-
-if target_group.containsMyRank():
-
-    filename = filename_xml2 + str(rank - nproc_source + 1) + ".med"
-    meshname = "Mesh_3_" + str(rank - nproc_source + 1)
-
-    mesh = MESH(MED_DRIVER, filename, meshname)
-    support = SUPPORT(mesh, "all elements", MED_CELL)
-    paramesh = ParaMESH(mesh, target_group, "target mesh")
-
-    parasupport = UnstructuredParaSUPPORT( support, target_group)
-    comptopo = ComponentTopology()
-    parafield = ParaFIELD(parasupport, comptopo)
-
-    nb_local = support.getNumberOfElements(MED_ALL_ELEMENTS)
-    value = [0.0]*nb_local
-
-    parafield.getField().setValue(value)
-    icocofield = ICoCo_MEDField(paramesh,parafield)
-
-    dec.attachLocalField(icocofield, 'P0')
-    pass
-
-if source_group.containsMyRank():
-    field_before_int = parafield.getVolumeIntegral(1)
-    dec.synchronize()
-    print "DEC usage"
-    dec.setForcedRenormalization(False)
-
-    dec.sendData()
-    print "writing 1"
-    paramesh.write(MED_DRIVER,"./sourcesquareb");
-    filename = "./sourcesquareb_" + str(source_group.myRank()+1)
-    parafield.write(MED_DRIVER, "./sourcesquareb", "boundary");
-
-    print "b dec.recvData()"
-    dec.recvData()
-    print "writing 2"
-    paramesh.write(MED_DRIVER, "./sourcesquare")
-    parafield.write(MED_DRIVER, "./sourcesquare", "boundary")
-
-    filename = "./sourcesquare_" + str(source_group.myRank()+1)
-    field_after_int = parafield.getVolumeIntegral(1)
-    print "field_before_int", field_before_int,"field_after_int", field_after_int
-
-    pass
-
-if target_group.containsMyRank():
-    dec.synchronize()
-    print "TARGET: after dec.synchronize()"
-    dec.setForcedRenormalization(False)
-
-    dec.recvData()
-    paramesh.write(0, "./targetsquareb")
-    parafield.write(0, "./targetsquareb", "boundary")
-    dec.sendData();
-    paramesh.write(0, "./targetsquare")
-    parafield.write(0, "./targetsquare", "boundary")
-    pass
-
-
-MPI_Barrier(MPI_COMM_WORLD)
-MPI_Finalize()
-print "### End of testIntersectionDEC_2D"
+unittest.main()
index c60831c1f5ae173b5d17c5c454c12e93c7d4f4df..fea118e61fe2c5e02b1de2305023d8a93eb3879f 100755 (executable)
 # 
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 # 
-from ParaMEDMEM import *
+from libParaMEDMEM_Swig import *
 import sys, os
+import unittest
+import math
+
+class ParaMEDMEMBasicsTest2(unittest.TestCase):
+    def testStructuredCoincidentDEC(self):
+        MPI_Init(sys.argv)
+        #
+        size = MPI_Comm_size(MPI_COMM_WORLD)
+        rank = MPI_Comm_rank(MPI_COMM_WORLD)
+        #
+        if size < 4:
+            raise RuntimeError, "Expect MPI_COMM_WORLD size >= 4"
+        #
+        interface = CommInterface()
+        #
+        self_group   = MPIProcessorGroup(interface, rank, rank)
+        target_group = MPIProcessorGroup(interface, 3, size-1)
+        source_group = MPIProcessorGroup(interface, 0, 2)
+        #
+        mesh      = 0
+        support   = 0
+        paramesh  = 0
+        parafield = 0
+        comptopo  = 0
+        icocofield= 0
+        #
+        data_dir = os.environ['MED_ROOT_DIR']
+        tmp_dir  = os.environ['TMP']
+        if tmp_dir == '':
+            tmp_dir = "/tmp"
+            pass
+        
+        filename_xml1    = data_dir + "/share/salome/resources/med/square1_split"
+        filename_2       = data_dir + "/share/salome/resources/med/square1.med"
+        filename_seq_wr  = tmp_dir + "/"
+        filename_seq_med = tmp_dir + "/myWrField_seq_pointe221.med"
+        
+        dec = StructuredCoincidentDEC(source_group, target_group)
+        MPI_Barrier(MPI_COMM_WORLD)
+        if source_group.containsMyRank():
+            filename = filename_xml1 + str(rank+1) + ".med"
+            meshname = "Mesh_2_" + str(rank+1)
+            mesh=ReadUMeshFromFile(filename,meshname,0)
+            paramesh=ParaMESH(mesh,source_group,"source mesh")
+            comptopo=ComponentTopology(6)
+            parafield=ParaFIELD(ON_CELLS,paramesh,comptopo)
+            nb_local=mesh.getNumberOfCells()
+            global_numbering=paramesh.getGlobalNumberingCell2()
+            value = []
+            for ielem in range(nb_local):
+                for icomp in range(6):
+                    value.append(global_numbering[ielem]*6.0+icomp);
+                    pass
+                pass
+            parafield.getField().setValues(value)
+            icocofield = ICoCoMEDField(paramesh,parafield)
+            dec.setMethod("P0")  
+            dec.attachLocalField(icocofield)      
+            dec.synchronize()
+            dec.sendData()
+            pass
 
-MPI_Init(sys.argv)
-
-size = MPI_Comm_size(MPI_COMM_WORLD)
-rank = MPI_Comm_rank(MPI_COMM_WORLD)
-    
-if size < 4:
-    raise RuntimeError, "Expect MPI_COMM_WORLD size >= 4"
-    
-interface = CommInterface()
-    
-self_group   = MPIProcessorGroup(interface, rank, rank)
-target_group = MPIProcessorGroup(interface, 3, size-1)
-source_group = MPIProcessorGroup(interface, 0, 2)
-
-mesh      = 0
-support   = 0
-paramesh  = 0
-parafield = 0
-
-data_dir = os.environ['MED_ROOT_DIR']
-tmp_dir  = os.environ['TMP']
-if tmp_dir == '':
-    tmp_dir = "/tmp"
-    pass
-
-filename_xml1    = data_dir + "/share/salome/resources/med/square1_split"
-filename_2       = data_dir + "/share/salome/resources/med/square1.med"
-filename_seq_wr  = tmp_dir + "/"
-filename_seq_med = tmp_dir + "/myWrField_seq_pointe221.med"
-
-dec = StructuredCoincidentDEC(source_group, target_group)
-MPI_Barrier(MPI_COMM_WORLD)
-    
-if source_group.containsMyRank():
-    filename = filename_xml1 + str(rank+1) + ".med"
-    meshname = "Mesh_2_" + str(rank+1)
-
-    mesh     = MESH(MED_DRIVER, filename, meshname)
-    support  = SUPPORT(mesh, "all elements", MED_CELL)
-    paramesh = ParaMESH(mesh, source_group, "source mesh")
-
-    parasupport = UnstructuredParaSUPPORT( support, source_group);
-    comptopo    = ComponentTopology(6)
-    parafield   = ParaFIELD(parasupport, comptopo)
-
-    nb_local = support.getNumberOfElements(MED_ALL_ELEMENTS);
-    global_numbering = parasupport.getGlobalNumbering()
-
-    value = []
-    for ielem in range(nb_local):
-        for icomp in range(6):
-            value.append(global_numbering[ielem]*6.0+icomp);
+        if target_group.containsMyRank():
+            meshname2 = "Mesh_2"
+            mesh=ReadUMeshFromFile(filename_2, meshname2,0)
+            paramesh=ParaMESH(mesh, self_group, "target mesh")
+            comptopo=ComponentTopology(6,target_group)
+            parafield=ParaFIELD(ON_CELLS,paramesh, comptopo)
+            nb_local=mesh.getNumberOfCells()
+            value = [0.0]*(nb_local*comptopo.nbLocalComponents())
+            parafield.getField().setValues(value)
+            icocofield = ICoCoMEDField(paramesh,parafield)
+            dec.setMethod("P0")
+            dec.attachLocalField(icocofield)
+            dec.synchronize()
+            dec.recvData()
+            recv_value = parafield.getField().getArray().getValues()
+            for i in range(nb_local):
+                first=comptopo.firstLocalComponent()
+                for icomp in range(comptopo.nbLocalComponents()):
+                    self.failUnless(math.fabs(recv_value[i*comptopo.nbLocalComponents()+icomp]-
+                                              (float)(i*6+icomp+first))<1e-12)
+                    pass
+                pass
             pass
+        comptopo=0
+        interface = 0
+        mesh       =0
+        support    =0
+        paramesh   =0
+        parafield  =0
+        icocofield =0
+        dec=0
+        self_group =0
+        target_group = 0
+        source_group = 0
+        MPI_Barrier(MPI_COMM_WORLD)
+        MPI_Finalize()
+        print "End of test StructuredCoincidentDEC"
         pass
 
-    parafield.getField().setValue(value)
-    icocofield = ICoCo_MEDField(paramesh,parafield)
-    dec.attachLocalField(icocofield)
-    dec.synchronize()
-    dec.sendData()
-    pass
-
-if target_group.containsMyRank():
-
-    meshname2 = "Mesh_2"
-    mesh      = MESH(MED_DRIVER, filename_2, meshname2)
-    support   = SUPPORT(mesh, "all elements", MED_CELL)
-
-    paramesh    = ParaMESH(mesh, self_group, "target mesh")
-    parasupport = UnstructuredParaSUPPORT( support, self_group)
-    comptopo    = ComponentTopology(6, target_group)
-    parafield   = ParaFIELD(parasupport, comptopo)
-
-    nb_local  = support.getNumberOfElements(MED_ALL_ELEMENTS)
-    value = [0.0]*(nb_local*comptopo.nbLocalComponents())
-
-    parafield.getField().setValue(value)
-    icocofield = ICoCo_MEDField(paramesh,parafield)
-
-    dec.attachLocalField(icocofield)
-    dec.synchronize()
-    dec.recvData()
-
-    recv_value = parafield.getField().getValue()
-    pass
-
-MPI_Finalize()
-
-print "End of test StructuredCoincidentDEC"
+    
+unittest.main()