From 4e4a0ba037e51125e33845148f9d99fb8061eedd Mon Sep 17 00:00:00 2001 From: eap Date: Wed, 17 Dec 2008 10:46:41 +0000 Subject: [PATCH] Move from ParaMED_Swig --- src/ParaMEDMEM_Swig/Makefile.am | 62 ++++ src/ParaMEDMEM_Swig/ParaMEDMEM.py | 20 ++ src/ParaMEDMEM_Swig/libParaMED_Swig.i | 328 ++++++++++++++++++ src/ParaMEDMEM_Swig/libParaMED_Swig.typemap | 61 ++++ src/ParaMEDMEM_Swig/test_IntersectionDEC.py | 148 ++++++++ src/ParaMEDMEM_Swig/test_NonCoincidentDEC.py | 143 ++++++++ .../test_StructuredCoincodentDEC.py | 112 ++++++ 7 files changed, 874 insertions(+) create mode 100644 src/ParaMEDMEM_Swig/Makefile.am create mode 100644 src/ParaMEDMEM_Swig/ParaMEDMEM.py create mode 100644 src/ParaMEDMEM_Swig/libParaMED_Swig.i create mode 100644 src/ParaMEDMEM_Swig/libParaMED_Swig.typemap create mode 100755 src/ParaMEDMEM_Swig/test_IntersectionDEC.py create mode 100755 src/ParaMEDMEM_Swig/test_NonCoincidentDEC.py create mode 100755 src/ParaMEDMEM_Swig/test_StructuredCoincodentDEC.py diff --git a/src/ParaMEDMEM_Swig/Makefile.am b/src/ParaMEDMEM_Swig/Makefile.am new file mode 100644 index 000000000..1bcc2a00a --- /dev/null +++ b/src/ParaMEDMEM_Swig/Makefile.am @@ -0,0 +1,62 @@ +# 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 = _libParaMED_Swig.la + +salomeinclude_HEADERS = \ + libParaMED_Swig.i + +SWIG_DEF = libParaMED_Swig.i + +SWIG_FLAGS = @SWIG_FLAGS@ -I$(srcdir) $(MPI_INCLUDES) -I$(srcdir)/../MEDMEM_SWIG + +dist__libParaMED_Swig_la_SOURCES = libParaMED_Swig.i +nodist__libParaMED_Swig_la_SOURCES = libParaMED_Swig_wrap.cxx +libParaMED_Swig.py: libParaMED_Swig_wrap.cxx + +libParaMED_Swig_wrap.cxx: $(SWIG_DEF) + $(SWIG) $(SWIG_FLAGS) -o $@ $< + +_libParaMED_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 + +_libParaMED_Swig_la_LDFLAGS = -module $(MED2_LIBS) $(HDF5_LIBS) $(PYTHON_LIBS) $(MPI_LIBS) \ + ../MEDMEM/libmedmem.la ../INTERP_KERNEL/libinterpkernel.la \ + ../ParaMEDMEM/libparamedmem.la + +if MED_ENABLE_KERNEL + _libParaMED_Swig_la_CPPFLAGS += ${KERNEL_CXXFLAGS} + _libParaMED_Swig_la_LDFLAGS += ${KERNEL_LDFLAGS} -lSALOMELocalTrace +endif + +CLEANFILES = libParaMED_Swig_wrap.cxx libParaMED_Swig.py + +nodist_salomescript_DATA= libParaMED_Swig.py + +dist_salomescript_DATA= test_intersectiondec.py \ + test_noncoincidentdec.py \ + test_structuredcoincodentdec.py \ + ParaMEDMEM.py \ No newline at end of file diff --git a/src/ParaMEDMEM_Swig/ParaMEDMEM.py b/src/ParaMEDMEM_Swig/ParaMEDMEM.py new file mode 100644 index 000000000..57bb0b4e3 --- /dev/null +++ b/src/ParaMEDMEM_Swig/ParaMEDMEM.py @@ -0,0 +1,20 @@ +# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG +# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT +# 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 libParaMED_Swig import * diff --git a/src/ParaMEDMEM_Swig/libParaMED_Swig.i b/src/ParaMEDMEM_Swig/libParaMED_Swig.i new file mode 100644 index 000000000..119de1bca --- /dev/null +++ b/src/ParaMEDMEM_Swig/libParaMED_Swig.i @@ -0,0 +1,328 @@ +// Copyright (C) 2005 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 +// +%module libParaMED_Swig + +%include "libParaMED_Swig.typemap" +%include "../MEDMEM_SWIG/libMEDMEM_Swig.i" + +%{ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace ParaMEDMEM; +using namespace ICoCo; +%} + + +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 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; + + bool containsMyRank() const; + int myRank() const; +}; + +%rename(ICoCo_MEDField) ICoCo::MEDField; +namespace ICoCo { +class Field { +}; + +class MEDField: public Field { +public: + MEDField(ParaMESH* mesh, ParaFIELD* field); +}; +} + +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* 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 { +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); + } + } +}; + + +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; + + double getVolumeIntegral(int icomp) const; +}; + + +// MPI realization specific definition !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +//#ifdef MPICH2 +// MPICH2 +typedef int MPI_Datatype; +typedef int MPI_Comm; +#define MPI_COMM_WORLD 0x44000000 +#define MPI_COMM_SELF 0x44000001 +#define MPI_DOUBLE 0x4c00080b +#define MPI_INT 0x4c000405 + +//#endif +// END OF MPI realization specific definition !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +// ============== +// 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 ) { + PyErr_SetString(PyExc_ValueError, MEDMEM::STRING("buffer is expected to be of size ")< 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); + 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) set +{ + TYPEMAP_INPUT_SET_BY_VALUE( int ) +} +%typecheck(SWIG_TYPECHECK_POINTER) set { + $1 = PyList_Check($input) ? 1 : 0; +} diff --git a/src/ParaMEDMEM_Swig/test_IntersectionDEC.py b/src/ParaMEDMEM_Swig/test_IntersectionDEC.py new file mode 100755 index 000000000..c36cb6cf0 --- /dev/null +++ b/src/ParaMEDMEM_Swig/test_IntersectionDEC.py @@ -0,0 +1,148 @@ +#!/usr/bin/env python + +# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG +# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT +# 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 + +# 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" + 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" diff --git a/src/ParaMEDMEM_Swig/test_NonCoincidentDEC.py b/src/ParaMEDMEM_Swig/test_NonCoincidentDEC.py new file mode 100755 index 000000000..03e50b762 --- /dev/null +++ b/src/ParaMEDMEM_Swig/test_NonCoincidentDEC.py @@ -0,0 +1,143 @@ +#!/usr/bin/env python + +# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG +# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT +# 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 + +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) + +source_mesh= 0 +target_mesh= 0 +parasupport= 0 +mesh = 0 +support = 0 +field = 0 +paramesh = 0 +parafield = 0 +icocofield = 0 + +dec = NonCoincidentDEC(source_group, target_group) + +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_xml2 = 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 + +field_before_int = [0.0] +field_after_int = [0.0] + +if source_group.containsMyRank(): + + field_before_int = [parafield.getVolumeIntegral(1)] + MPI_Bcast(field_before_int, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); + dec.synchronize() + print "DEC usage" + dec.setForcedRenormalization(False) + + dec.sendData() + pass + +if target_group.containsMyRank(): + + MPI_Bcast(field_before_int, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD) + dec.synchronize() + dec.setForcedRenormalization(False) + dec.recvData() + field_after_int = [parafield.getVolumeIntegral(1)] + pass + +MPI_Bcast(field_before_int, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD) +MPI_Bcast(field_after_int , 1, MPI_DOUBLE, size-1, MPI_COMM_WORLD) + +epsilon = 1e-6 +if abs(field_before_int[0] - field_after_int[0]) > epsilon: + print "Field before is not equal field after: %s != %s"%\ + (field_before_int[0],field_after_int[0]) + pass + + +MPI_Barrier(MPI_COMM_WORLD) +MPI_Finalize() +print "# End of testNonCoincidentDEC" diff --git a/src/ParaMEDMEM_Swig/test_StructuredCoincodentDEC.py b/src/ParaMEDMEM_Swig/test_StructuredCoincodentDEC.py new file mode 100755 index 000000000..c60831c1f --- /dev/null +++ b/src/ParaMEDMEM_Swig/test_StructuredCoincodentDEC.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python + +# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG +# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT +# 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 + +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); + pass + 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" -- 2.39.2