#include "MeshTestToolkit.hxx"
#include "MEDMEM_Mesh.hxx"
-#include "Interpolation3DSurf.txx"
+#include "Interpolation3DSurf.hxx"
#include "Interpolation2D.txx"
#include "Interpolation3D.txx"
-# Copyright (C) 2007-2010 CEA/DEN, EDF R&D
+# Copyright (C) 2007-2011 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 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.
+# 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
+# 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
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
# MED MEDMEM_SWIG : binding of C++ implementation and Python
#
include $(top_srcdir)/adm_local/unix/make_common_starter.am
-lib_LTLIBRARIES = _libParaMEDMEM_Swig.la
+salomepython_PYTHON = ParaMEDMEM.py
+salomepyexec_LTLIBRARIES = _ParaMEDMEM.la
salomeinclude_HEADERS = \
- libParaMEDMEM_Swig.i
+ ParaMEDMEM.i
-SWIG_DEF = libParaMEDMEM_Swig.i libParaMEDMEM_Swig.typemap
+SWIG_DEF = ParaMEDMEM.i ParaMEDMEM.typemap
SWIG_FLAGS = @SWIG_FLAGS@ -I$(srcdir) $(MPI_INCLUDES) -I$(srcdir)/../ParaMEDMEM -I$(srcdir)/../MEDCoupling -I$(srcdir)/../MEDCoupling_Swig \
-I$(srcdir)/../MEDLoader/Swig -I$(srcdir)/../INTERP_KERNEL -I$(srcdir)/../INTERP_KERNEL/Bases -I$(srcdir)/../ParaMEDLoader \
-I$(srcdir)/../MEDLoader
-dist__libParaMEDMEM_Swig_la_SOURCES = $(SWIG_DEF)
-nodist__libParaMEDMEM_Swig_la_SOURCES = libParaMEDMEM_Swig_wrap.cxx
-libParaMEDMEM_Swig.py: libParaMEDMEM_Swig_wrap.cxx
+dist__ParaMEDMEM_la_SOURCES = $(SWIG_DEF)
+nodist__ParaMEDMEM_la_SOURCES = ParaMEDMEM_wrap.cxx
+ParaMEDMEM.py : ParaMEDMEM_wrap.cxx
-libParaMEDMEM_Swig_wrap.cxx: $(SWIG_DEF)
+ParaMEDMEM_wrap.cxx: $(SWIG_DEF)
$(SWIG) $(SWIG_FLAGS) -o $@ $<
-_libParaMEDMEM_Swig_la_CPPFLAGS = $(PYTHON_INCLUDES) \
+_ParaMEDMEM_la_CPPFLAGS = $(PYTHON_INCLUDES) \
$(MED2_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \
-I$(srcdir)/../INTERP_KERNEL \
$(MPI_INCLUDES) -I$(srcdir)/../ParaMEDMEM -I$(srcdir)/../MEDCoupling_Swig -I$(srcdir)/../INTERP_KERNEL/Bases \
-I$(srcdir)/../MEDCoupling -I$(srcdir)/../ParaMEDLoader -I$(srcdir)/../MEDLoader -I$(srcdir)/../MEDLoader/Swig
-_libParaMEDMEM_Swig_la_LDFLAGS = -module $(MED2_LIBS) $(HDF5_LIBS) $(PYTHON_LIBS) $(MPI_LIBS) \
+_ParaMEDMEM_la_LDFLAGS = -module $(MED2_LIBS) $(HDF5_LIBS) $(PYTHON_LIBS) $(MPI_LIBS) \
../MEDCoupling/libmedcoupling.la ../INTERP_KERNEL/libinterpkernel.la \
../ParaMEDMEM/libparamedmem.la ../ParaMEDLoader/libparamedloader.la
if MED_ENABLE_KERNEL
- _libParaMEDMEM_Swig_la_CPPFLAGS += ${KERNEL_CXXFLAGS}
- _libParaMEDMEM_Swig_la_LDFLAGS += ${KERNEL_LDFLAGS} -lSALOMELocalTrace
+ _ParaMEDMEM_la_CPPFLAGS += ${KERNEL_CXXFLAGS}
+ _ParaMEDMEM_la_LDFLAGS += ${KERNEL_LDFLAGS} -lSALOMELocalTrace
endif
-CLEANFILES = libParaMEDMEM_Swig_wrap.cxx libParaMEDMEM_Swig.py
+CLEANFILES = ParaMEDMEM_wrap.cxx ParaMEDMEM.py
dist_salomescript_DATA= test_InterpKernelDEC.py \
test_NonCoincidentDEC.py \
- test_StructuredCoincodentDEC.py \
- ParaMEDMEM.py libParaMEDMEM_Swig.py
+ test_StructuredCoincidentDEC.py \
+ ParaMEDMEM.py
--- /dev/null
+// Copyright (C) 2007-2011 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 ParaMEDMEM
+
+%include "ParaMEDMEM.typemap"
+%include "MEDCoupling.i"
+%include "MEDLoader.i"
+
+%{
+#include "CommInterface.hxx"
+#include "ProcessorGroup.hxx"
+#include "Topology.hxx"
+#include "MPIProcessorGroup.hxx"
+#include "DEC.hxx"
+#include "InterpKernelDEC.hxx"
+#include "NonCoincidentDEC.hxx"
+#include "StructuredCoincidentDEC.hxx"
+#include "ParaMESH.hxx"
+#include "ParaFIELD.hxx"
+#include "ICoCoMEDField.hxx"
+#include "ComponentTopology.hxx"
+
+#include <mpi.h>
+
+using namespace ParaMEDMEM;
+using namespace ICoCo;
+
+enum mpi_constants { mpi_comm_world, mpi_comm_self, mpi_double, mpi_int };
+%}
+
+%include "CommInterface.hxx"
+%include "ProcessorGroup.hxx"
+%include "DECOptions.hxx"
+%include "ParaMESH.hxx"
+%include "ParaFIELD.hxx"
+%include "MPIProcessorGroup.hxx"
+%include "ComponentTopology.hxx"
+%include "DEC.hxx"
+%include "InterpKernelDEC.hxx"
+%include "StructuredCoincidentDEC.hxx"
+
+%rename(ICoCoMEDField) ICoCo::MEDField;
+%include "ICoCoMEDField.hxx"
+
+%nodefaultctor;
+
+/* This object can be used only if MED_ENABLE_FVM is defined*/
+#ifdef MED_ENABLE_FVM
+class NonCoincidentDEC : public DEC
+{
+public:
+ NonCoincidentDEC(ProcessorGroup& source, ProcessorGroup& target);
+};
+#endif
+
+%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;
+ }
+
+ 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;
+ }
+
+ 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.
+//
+// Type and values of constants like MPI_COMM_WORLD depends on MPI realization
+// and usually such constants actually are macros. To have such symbols in python
+// and translate them into correct values we use the following technique.
+// We define some constants (enum mpi_constants) and map them into real MPI values
+// using typemaps, and we create needed python symbols equal to 'mpi_constants'
+// via %pythoncode directive.
+
+// Constants corresponding to similar MPI definitions
+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;
+ }
+}
+// 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;
+ }
+}
+// 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_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 );
+ } %}
+
+// ==============
+// 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 );
+ }
+ %}
+
+int MPI_Init(int *argc, char ***argv );
+int MPI_Barrier(MPI_Comm comm);
+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 )
+ {
+ 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 );
+
+ }
+ %}
+
+++ /dev/null
-# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2010 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
-#
-
-from libParaMEDMEM_Swig import *
--- /dev/null
+// Copyright (C) 2007-2011 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 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) {
+ int i;
+ if (!PyList_Check($input)) {
+ PyErr_SetString(PyExc_ValueError, "Expecting a list");
+ return NULL;
+ }
+ int aSize = PyList_Size($input);
+ $1 = &aSize;
+ char** aStrs = (char **) malloc((aSize+1)*sizeof(char *));
+ for (i = 0; i < aSize; i++) {
+ PyObject *s = PyList_GetItem($input,i);
+ if (!PyString_Check(s)) {
+ free(aStrs);
+ PyErr_SetString(PyExc_ValueError, "List items must be strings");
+ return NULL;
+ }
+ aStrs[i] = PyString_AsString(s);
+ }
+ aStrs[i] = 0;
+ $2 = &aStrs;
+}
+
+%typemap(freearg) (int *argc, char ***argv) {
+ if ($2) free(*($2));
+}
+
+/* MACRO: IN typemap for std::set<TYPE> C++ object */
+%define TYPEMAP_INPUT_SET_BY_VALUE( TYPE )
+{
+ /* typemap in for set<TYPE> */
+ /* Check if is a list */
+ if (PyList_Check($input))
+ {
+ int size = PyList_Size($input);
+ std::set< TYPE > tmpSet;
+
+ for (int i=0; i < size; i++)
+ {
+ PyObject * tmp = PyList_GetItem($input,i);
+ TYPE elem = PyInt_AsLong(tmp);
+ tmpSet.insert(elem);
+ }
+ $1 = tmpSet;
+ }
+ else
+ {
+ PyErr_SetString(PyExc_TypeError,"not a list");
+ return NULL;
+ }
+}
+%enddef
+
+%typemap(in) std::set<int>
+{
+ TYPEMAP_INPUT_SET_BY_VALUE( int )
+}
+%typecheck(SWIG_TYPECHECK_POINTER) std::set<int> {
+ $1 = PyList_Check($input) ? 1 : 0;
+}
+++ /dev/null
-// Copyright (C) 2007-2010 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 libParaMEDMEM_Swig
-
-%include "libParaMEDMEM_Swig.typemap"
-%include "libMEDCoupling_Swig.i"
-%include "libMEDLoader_Swig.i"
-
-%{
-#include "CommInterface.hxx"
-#include "ProcessorGroup.hxx"
-#include "Topology.hxx"
-#include "MPIProcessorGroup.hxx"
-#include "DEC.hxx"
-#include "InterpKernelDEC.hxx"
-#include "NonCoincidentDEC.hxx"
-#include "StructuredCoincidentDEC.hxx"
-#include "ParaMESH.hxx"
-#include "ParaFIELD.hxx"
-#include "ICoCoMEDField.hxx"
-#include "ComponentTopology.hxx"
-
-#include <mpi.h>
-
-using namespace ParaMEDMEM;
-using namespace ICoCo;
-
-enum mpi_constants { mpi_comm_world, mpi_comm_self, mpi_double, mpi_int };
-%}
-
-%include "CommInterface.hxx"
-%include "ProcessorGroup.hxx"
-%include "DECOptions.hxx"
-%include "ParaMESH.hxx"
-%include "ParaFIELD.hxx"
-%include "MPIProcessorGroup.hxx"
-%include "ComponentTopology.hxx"
-%include "DEC.hxx"
-%include "InterpKernelDEC.hxx"
-%include "StructuredCoincidentDEC.hxx"
-
-%rename(ICoCoMEDField) ICoCo::MEDField;
-%include "ICoCoMEDField.hxx"
-
-%nodefaultctor;
-
-/* This object can be used only if MED_ENABLE_FVM is defined*/
-#ifdef MED_ENABLE_FVM
-class NonCoincidentDEC : public DEC
-{
-public:
- NonCoincidentDEC(ProcessorGroup& source, ProcessorGroup& target);
-};
-#endif
-
-%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;
- }
-
- 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;
- }
-
- 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.
-//
-// Type and values of constants like MPI_COMM_WORLD depends on MPI realization
-// and usually such constants actually are macros. To have such symbols in python
-// and translate them into correct values we use the following technique.
-// We define some constants (enum mpi_constants) and map them into real MPI values
-// using typemaps, and we create needed python symbols equal to 'mpi_constants'
-// via %pythoncode directive.
-
-// Constants corresponding to similar MPI definitions
-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;
- }
-}
-// 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;
- }
-}
-// 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_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 );
- } %}
-
-// ==============
-// 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 );
- }
- %}
-
-int MPI_Init(int *argc, char ***argv );
-int MPI_Barrier(MPI_Comm comm);
-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 )
- {
- 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 );
-
- }
- %}
-
+++ /dev/null
-// Copyright (C) 2007-2010 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 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) {
- int i;
- if (!PyList_Check($input)) {
- PyErr_SetString(PyExc_ValueError, "Expecting a list");
- return NULL;
- }
- int aSize = PyList_Size($input);
- $1 = &aSize;
- char** aStrs = (char **) malloc((aSize+1)*sizeof(char *));
- for (i = 0; i < aSize; i++) {
- PyObject *s = PyList_GetItem($input,i);
- if (!PyString_Check(s)) {
- free(aStrs);
- PyErr_SetString(PyExc_ValueError, "List items must be strings");
- return NULL;
- }
- aStrs[i] = PyString_AsString(s);
- }
- aStrs[i] = 0;
- $2 = &aStrs;
-}
-
-%typemap(freearg) (int *argc, char ***argv) {
- if ($2) free(*($2));
-}
-
-/* MACRO: IN typemap for std::set<TYPE> C++ object */
-%define TYPEMAP_INPUT_SET_BY_VALUE( TYPE )
-{
- /* typemap in for set<TYPE> */
- /* Check if is a list */
- if (PyList_Check($input))
- {
- int size = PyList_Size($input);
- std::set< TYPE > tmpSet;
-
- for (int i=0; i < size; i++)
- {
- PyObject * tmp = PyList_GetItem($input,i);
- TYPE elem = PyInt_AsLong(tmp);
- tmpSet.insert(elem);
- }
- $1 = tmpSet;
- }
- else
- {
- PyErr_SetString(PyExc_TypeError,"not a list");
- return NULL;
- }
-}
-%enddef
-
-%typemap(in) std::set<int>
-{
- TYPEMAP_INPUT_SET_BY_VALUE( int )
-}
-%typecheck(SWIG_TYPECHECK_POINTER) std::set<int> {
- $1 = PyList_Check($input) ? 1 : 0;
-}
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2010 CEA/DEN, EDF R&D
+# Copyright (C) 2007-2011 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 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.
+# 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
+# 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
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-from libParaMEDMEM_Swig import *
+from ParaMEDMEM import *
import sys, os
import unittest
import math
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2010 CEA/DEN, EDF R&D
+# Copyright (C) 2007-2011 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 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.
+# 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
+# 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
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
from ParaMEDMEM import *
--- /dev/null
+#!/usr/bin/env python
+# -*- coding: iso-8859-1 -*-
+# Copyright (C) 2007-2011 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
+#
+
+from ParaMEDMEM 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=MEDLoader.ReadUMeshFromFile(filename,meshname,0)
+ paramesh=ParaMESH(mesh,source_group,"source mesh")
+ comptopo=ComponentTopology(6)
+ parafield=ParaFIELD(ON_CELLS,NO_TIME,paramesh,comptopo)
+ parafield.getField().setNature(ConservativeVolumic)
+ 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(mesh,parafield.getField())
+ dec.setMethod("P0")
+ dec.attachLocalField(parafield)
+ dec.synchronize()
+ dec.sendData()
+ pass
+
+ if target_group.containsMyRank():
+ meshname2 = "Mesh_2"
+ mesh=MEDLoader.ReadUMeshFromFile(filename_2, meshname2,0)
+ paramesh=ParaMESH(mesh, self_group, "target mesh")
+ comptopo=ComponentTopology(6,target_group)
+ parafield=ParaFIELD(ON_CELLS,NO_TIME,paramesh, comptopo)
+ parafield.getField().setNature(ConservativeVolumic)
+ nb_local=mesh.getNumberOfCells()
+ value = [0.0]*(nb_local*comptopo.nbLocalComponents())
+ parafield.getField().setValues(value)
+ icocofield = ICoCoMEDField(mesh,parafield.getField())
+ dec.setMethod("P0")
+ dec.attachLocalField(parafield)
+ 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
+
+
+unittest.main()
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2010 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
-#
-
-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=MEDLoader.ReadUMeshFromFile(filename,meshname,0)
- paramesh=ParaMESH(mesh,source_group,"source mesh")
- comptopo=ComponentTopology(6)
- parafield=ParaFIELD(ON_CELLS,NO_TIME,paramesh,comptopo)
- parafield.getField().setNature(ConservativeVolumic)
- 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(mesh,parafield.getField())
- dec.setMethod("P0")
- dec.attachLocalField(parafield)
- dec.synchronize()
- dec.sendData()
- pass
-
- if target_group.containsMyRank():
- meshname2 = "Mesh_2"
- mesh=MEDLoader.ReadUMeshFromFile(filename_2, meshname2,0)
- paramesh=ParaMESH(mesh, self_group, "target mesh")
- comptopo=ComponentTopology(6,target_group)
- parafield=ParaFIELD(ON_CELLS,NO_TIME,paramesh, comptopo)
- parafield.getField().setNature(ConservativeVolumic)
- nb_local=mesh.getNumberOfCells()
- value = [0.0]*(nb_local*comptopo.nbLocalComponents())
- parafield.getField().setValues(value)
- icocofield = ICoCoMEDField(mesh,parafield.getField())
- dec.setMethod("P0")
- dec.attachLocalField(parafield)
- 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
-
-
-unittest.main()