From: ageay Date: Wed, 15 Jun 2011 09:44:47 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: V5_1_6rc1~11 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=446d3d6ae8ede1870b200b8dc21da2ebe3b891d0;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/INTERP_KERNELTest/MeshTestToolkit.txx b/src/INTERP_KERNELTest/MeshTestToolkit.txx index f90feb499..89b82ad67 100644 --- a/src/INTERP_KERNELTest/MeshTestToolkit.txx +++ b/src/INTERP_KERNELTest/MeshTestToolkit.txx @@ -24,7 +24,7 @@ #include "MeshTestToolkit.hxx" #include "MEDMEM_Mesh.hxx" -#include "Interpolation3DSurf.txx" +#include "Interpolation3DSurf.hxx" #include "Interpolation2D.txx" #include "Interpolation3D.txx" diff --git a/src/ParaMEDMEM_Swig/Makefile.am b/src/ParaMEDMEM_Swig/Makefile.am index c65f7eace..e032967a0 100644 --- a/src/ParaMEDMEM_Swig/Makefile.am +++ b/src/ParaMEDMEM_Swig/Makefile.am @@ -1,62 +1,63 @@ -# 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 diff --git a/src/ParaMEDMEM_Swig/ParaMEDMEM.i b/src/ParaMEDMEM_Swig/ParaMEDMEM.i new file mode 100644 index 000000000..9effbf415 --- /dev/null +++ b/src/ParaMEDMEM_Swig/ParaMEDMEM.i @@ -0,0 +1,261 @@ +// 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 + +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;igetGlobalNumberingFace(); + int size=self->getFaceMesh()->getNumberOfCells(); + PyObject *ret=PyList_New(size); + for(int i=0;igetGlobalNumberingNode(); + int size=self->getCellMesh()->getNumberOfNodes(); + PyObject *ret=PyList_New(size); + for(int i=0;i 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 ); + + } + %} + diff --git a/src/ParaMEDMEM_Swig/ParaMEDMEM.py b/src/ParaMEDMEM_Swig/ParaMEDMEM.py deleted file mode 100644 index 207d94468..000000000 --- a/src/ParaMEDMEM_Swig/ParaMEDMEM.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- 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 * diff --git a/src/ParaMEDMEM_Swig/ParaMEDMEM.typemap b/src/ParaMEDMEM_Swig/ParaMEDMEM.typemap new file mode 100644 index 000000000..9f5a35314 --- /dev/null +++ b/src/ParaMEDMEM_Swig/ParaMEDMEM.typemap @@ -0,0 +1,84 @@ +// 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; + +// 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 C++ object */ +%define TYPEMAP_INPUT_SET_BY_VALUE( TYPE ) +{ + /* typemap in for set */ + /* 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 +{ + TYPEMAP_INPUT_SET_BY_VALUE( int ) +} +%typecheck(SWIG_TYPECHECK_POINTER) std::set { + $1 = PyList_Check($input) ? 1 : 0; +} diff --git a/src/ParaMEDMEM_Swig/libParaMEDMEM_Swig.i b/src/ParaMEDMEM_Swig/libParaMEDMEM_Swig.i deleted file mode 100644 index 21ccd0aa8..000000000 --- a/src/ParaMEDMEM_Swig/libParaMEDMEM_Swig.i +++ /dev/null @@ -1,261 +0,0 @@ -// 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 - -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;igetGlobalNumberingFace(); - int size=self->getFaceMesh()->getNumberOfCells(); - PyObject *ret=PyList_New(size); - for(int i=0;igetGlobalNumberingNode(); - int size=self->getCellMesh()->getNumberOfNodes(); - PyObject *ret=PyList_New(size); - for(int i=0;i 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 ); - - } - %} - diff --git a/src/ParaMEDMEM_Swig/libParaMEDMEM_Swig.typemap b/src/ParaMEDMEM_Swig/libParaMEDMEM_Swig.typemap deleted file mode 100644 index f73253e4b..000000000 --- a/src/ParaMEDMEM_Swig/libParaMEDMEM_Swig.typemap +++ /dev/null @@ -1,84 +0,0 @@ -// 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; - -// 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 C++ object */ -%define TYPEMAP_INPUT_SET_BY_VALUE( TYPE ) -{ - /* typemap in for set */ - /* 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 -{ - TYPEMAP_INPUT_SET_BY_VALUE( int ) -} -%typecheck(SWIG_TYPECHECK_POINTER) std::set { - $1 = PyList_Check($input) ? 1 : 0; -} diff --git a/src/ParaMEDMEM_Swig/test_InterpKernelDEC.py b/src/ParaMEDMEM_Swig/test_InterpKernelDEC.py index 2a9a77d29..e227588a3 100755 --- a/src/ParaMEDMEM_Swig/test_InterpKernelDEC.py +++ b/src/ParaMEDMEM_Swig/test_InterpKernelDEC.py @@ -1,25 +1,25 @@ #!/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 diff --git a/src/ParaMEDMEM_Swig/test_NonCoincidentDEC.py b/src/ParaMEDMEM_Swig/test_NonCoincidentDEC.py index 256a0a3ce..f6a278111 100755 --- a/src/ParaMEDMEM_Swig/test_NonCoincidentDEC.py +++ b/src/ParaMEDMEM_Swig/test_NonCoincidentDEC.py @@ -1,22 +1,22 @@ #!/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 * diff --git a/src/ParaMEDMEM_Swig/test_StructuredCoincidentDEC.py b/src/ParaMEDMEM_Swig/test_StructuredCoincidentDEC.py new file mode 100755 index 000000000..856622bb5 --- /dev/null +++ b/src/ParaMEDMEM_Swig/test_StructuredCoincidentDEC.py @@ -0,0 +1,128 @@ +#!/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() diff --git a/src/ParaMEDMEM_Swig/test_StructuredCoincodentDEC.py b/src/ParaMEDMEM_Swig/test_StructuredCoincodentDEC.py deleted file mode 100755 index 95a184e98..000000000 --- a/src/ParaMEDMEM_Swig/test_StructuredCoincodentDEC.py +++ /dev/null @@ -1,128 +0,0 @@ -#!/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()