From 7397d214566df4186ee52c642e3e6aa54c2595a3 Mon Sep 17 00:00:00 2001 From: imn Date: Tue, 19 May 2015 14:59:01 +0300 Subject: [PATCH] [EDF7690]: Creating joints with medpartitioner in the MEDCoupling API --- src/CMakeLists.txt | 3 + src/MEDCoupling/CMakeLists.txt | 1 + src/MEDCoupling/MEDCouplingSkyLineArray.cxx | 46 ++ src/MEDCoupling/MEDCouplingSkyLineArray.hxx | 47 ++ src/MEDCoupling/MEDCouplingUMesh.cxx | 11 + src/MEDCoupling/MEDCouplingUMesh.hxx | 2 + src/MEDCoupling_Swig/MEDCouplingCommon.i | 17 + src/MEDLoader/CMakeLists.txt | 1 + src/MEDLoader/MEDFileData.cxx | 39 +- src/MEDLoader/MEDFileData.hxx | 5 + src/MEDLoader/MEDFileJoint.cxx | 745 ++++++++++++++++++ src/MEDLoader/MEDFileJoint.hxx | 170 ++++ src/MEDLoader/MEDFileMesh.cxx | 21 +- src/MEDLoader/MEDFileMesh.hxx | 5 + src/MEDLoader/Swig/MEDLoaderCommon.i | 259 ++++++ src/MEDLoader/Swig/MEDLoaderTest3.py | 81 ++ src/MEDPartitioner/CMakeLists.txt | 2 + .../MEDPARTITIONER_MEDPartitioner.cxx | 184 +++++ .../MEDPARTITIONER_MEDPartitioner.hxx | 60 ++ .../MEDPARTITIONER_MeshCollection.cxx | 2 +- .../MEDPARTITIONER_MeshCollection.hxx | 2 + .../MEDPARTITIONER_MeshCollectionDriver.cxx | 9 +- .../MEDPARTITIONER_ParallelTopology.cxx | 2 +- src/MEDPartitioner/MEDPARTITIONER_Utils.cxx | 1 + src/MEDPartitioner/MEDPARTITIONER_Utils.hxx | 1 + src/MEDPartitioner/medpartitioner.cxx | 4 + src/MEDPartitioner_Swig/CMakeLists.txt | 76 ++ .../CTestTestfileInstall.cmake | 21 + src/MEDPartitioner_Swig/MEDPartitioner.i | 140 ++++ .../MEDPartitionerCommon.i | 81 ++ src/MEDPartitioner_Swig/MEDPartitionerTest.py | 44 ++ 31 files changed, 2075 insertions(+), 7 deletions(-) create mode 100644 src/MEDCoupling/MEDCouplingSkyLineArray.cxx create mode 100644 src/MEDCoupling/MEDCouplingSkyLineArray.hxx create mode 100644 src/MEDLoader/MEDFileJoint.cxx create mode 100644 src/MEDLoader/MEDFileJoint.hxx create mode 100644 src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx create mode 100644 src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx create mode 100644 src/MEDPartitioner_Swig/CMakeLists.txt create mode 100644 src/MEDPartitioner_Swig/CTestTestfileInstall.cmake create mode 100644 src/MEDPartitioner_Swig/MEDPartitioner.i create mode 100644 src/MEDPartitioner_Swig/MEDPartitionerCommon.i create mode 100644 src/MEDPartitioner_Swig/MEDPartitionerTest.py diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c4296a583..d3d23be80 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -34,6 +34,9 @@ IF(NOT SALOME_MED_MICROMED) ENDIF(SALOME_MED_ENABLE_RENUMBER) IF(SALOME_MED_ENABLE_PARTITIONER) ADD_SUBDIRECTORY(MEDPartitioner) + IF(SALOME_MED_ENABLE_PYTHON) + ADD_SUBDIRECTORY(MEDPartitioner_Swig) + ENDIF(SALOME_MED_ENABLE_PYTHON) ENDIF(SALOME_MED_ENABLE_PARTITIONER) IF(SALOME_BUILD_TESTS) ADD_SUBDIRECTORY(INTERP_KERNELTest) diff --git a/src/MEDCoupling/CMakeLists.txt b/src/MEDCoupling/CMakeLists.txt index 085f40422..014f69a41 100644 --- a/src/MEDCoupling/CMakeLists.txt +++ b/src/MEDCoupling/CMakeLists.txt @@ -59,6 +59,7 @@ SET(medcoupling_SOURCES MEDCouplingAMRAttribute.cxx MEDCouplingMatrix.cxx MEDCouplingPartDefinition.cxx + MEDCouplingSkyLineArray.cxx ) SET(medcouplingremapper_SOURCES diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.cxx b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx new file mode 100644 index 000000000..5b1293a9d --- /dev/null +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx @@ -0,0 +1,46 @@ +// Copyright (C) 2007-2015 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, or (at your option) any later version. +// +// 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 "MEDCouplingSkyLineArray.hxx" + +#include + +using namespace ParaMEDMEM; + +MEDCouplingSkyLineArray::MEDCouplingSkyLineArray() +{ +} + +MEDCouplingSkyLineArray::MEDCouplingSkyLineArray(const MEDCouplingSkyLineArray &myArray) +{ + _index=myArray._index; + _value=myArray._value; +} + +MEDCouplingSkyLineArray::~MEDCouplingSkyLineArray() +{ +} + +MEDCouplingSkyLineArray::MEDCouplingSkyLineArray(const MEDCouplingAutoRefCountObjectPtr& index, const MEDCouplingAutoRefCountObjectPtr& value) +{ + _index=index; + _value=value; +} + + diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.hxx b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx new file mode 100644 index 000000000..1e6eb99f4 --- /dev/null +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx @@ -0,0 +1,47 @@ +// Copyright (C) 2007-2015 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, or (at your option) any later version. +// +// 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 +// + +#ifndef __PARAMEDMEM_MEDCOUPLINGSKYLINEARRAY_HXX__ +#define __PARAMEDMEM_MEDCOUPLINGSKYLINEARRAY_HXX__ + +#include "MEDCoupling.hxx" +#include "MEDCouplingMesh.hxx" +#include "MEDCouplingMemArray.hxx" +#include "MEDCouplingAutoRefCountObjectPtr.hxx" +#include + +namespace ParaMEDMEM +{ +class DataArrayInt; + class MEDCOUPLING_EXPORT MEDCouplingSkyLineArray + { + private: + MEDCouplingAutoRefCountObjectPtr _index; + MEDCouplingAutoRefCountObjectPtr _value; + public: + MEDCouplingSkyLineArray(); + MEDCouplingSkyLineArray( const MEDCouplingSkyLineArray &myArray ); + MEDCouplingSkyLineArray( const MEDCouplingAutoRefCountObjectPtr& index, const MEDCouplingAutoRefCountObjectPtr& value ); + ~MEDCouplingSkyLineArray(); + + int getNumberOf() const { return _index->getNbOfElems(); } + int getLength() const { return _value->getNbOfElems(); } + }; +} +# endif diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index f213a9d42..acc8aaf85 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -8651,6 +8651,17 @@ DataArrayInt *MEDCouplingUMesh::buildUnionOf3DMesh() const return ret.retn(); } +/*! + * generate graph. + * + * \return sky line array + */ +MEDCouplingSkyLineArray *MEDCouplingUMesh::generateGraph() const +{ + MEDCouplingSkyLineArray* ret=new MEDCouplingSkyLineArray(_nodal_connec_index, _nodal_connec); + return ret; +} + /*! * This method put in zip format into parameter 'zipFrmt' in full interlace mode. * This format is often asked by INTERP_KERNEL algorithms to avoid many indirections into coordinates array. diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index a3972a295..16079ddf1 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -24,6 +24,7 @@ #include "MEDCoupling.hxx" #include "MEDCouplingPointSet.hxx" #include "MEDCouplingMemArray.hxx" +#include "MEDCouplingSkyLineArray.hxx" #include "CellModel.hxx" @@ -270,6 +271,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *buildUnionOf2DMesh() const; MEDCOUPLING_EXPORT DataArrayInt *buildUnionOf3DMesh() const; MEDCOUPLING_EXPORT DataArrayInt *orderConsecutiveCells1D() const; + MEDCOUPLING_EXPORT MEDCouplingSkyLineArray *generateGraph() const; private: MEDCouplingUMesh(); MEDCouplingUMesh(const MEDCouplingUMesh& other, bool deepCopy); diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 6926805ae..74ef456fa 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -44,6 +44,7 @@ #include "MEDCouplingAMRAttribute.hxx" #include "MEDCouplingMatrix.hxx" #include "MEDCouplingPartDefinition.hxx" +#include "MEDCouplingSkyLineArray.hxx" #include "MEDCouplingTypemaps.i" #include "InterpKernelAutoPtr.hxx" @@ -308,6 +309,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingUMesh::ComputeRangesFromTypeDistribution; %newobject ParaMEDMEM::MEDCouplingUMesh::buildUnionOf2DMesh; %newobject ParaMEDMEM::MEDCouplingUMesh::buildUnionOf3DMesh; +%newobject ParaMEDMEM::MEDCouplingUMesh::generateGraph; %newobject ParaMEDMEM::MEDCouplingUMesh::orderConsecutiveCells1D; %newobject ParaMEDMEM::MEDCouplingUMesh::getBoundingBoxForBBTreeFast; %newobject ParaMEDMEM::MEDCouplingUMesh::getBoundingBoxForBBTree2DQuadratic; @@ -1136,6 +1138,20 @@ namespace ParaMEDMEM static bool AreAlmostEqual(const std::vector& v1, const std::vector& v2, double eps); }; } +namespace ParaMEDMEM +{ + class MEDCouplingSkyLineArray + { + public: + MEDCouplingSkyLineArray() throw(INTERP_KERNEL::Exception); + MEDCouplingSkyLineArray( const MEDCouplingSkyLineArray &myArray ) throw(INTERP_KERNEL::Exception); + MEDCouplingSkyLineArray( const MEDCouplingAutoRefCountObjectPtr& index, const MEDCouplingAutoRefCountObjectPtr& value ) throw(INTERP_KERNEL::Exception); + ~MEDCouplingSkyLineArray() throw(INTERP_KERNEL::Exception); + + int getNumberOf() const throw(INTERP_KERNEL::Exception); + int getLength() const throw(INTERP_KERNEL::Exception); + }; +} %include "MEDCouplingFieldDiscretization.i" @@ -1781,6 +1797,7 @@ namespace ParaMEDMEM DataArrayInt *convertNodalConnectivityToStaticGeoTypeMesh() const throw(INTERP_KERNEL::Exception); DataArrayInt *buildUnionOf2DMesh() const throw(INTERP_KERNEL::Exception); DataArrayInt *buildUnionOf3DMesh() const throw(INTERP_KERNEL::Exception); + MEDCouplingSkyLineArray *generateGraph() const throw(INTERP_KERNEL::Exception); DataArrayInt *orderConsecutiveCells1D() const throw(INTERP_KERNEL::Exception); DataArrayDouble *getBoundingBoxForBBTreeFast() const throw(INTERP_KERNEL::Exception); DataArrayDouble *getBoundingBoxForBBTree2DQuadratic(double arcDetEps=1e-12) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/CMakeLists.txt b/src/MEDLoader/CMakeLists.txt index 5b8d96c09..40538ed30 100644 --- a/src/MEDLoader/CMakeLists.txt +++ b/src/MEDLoader/CMakeLists.txt @@ -62,6 +62,7 @@ SET(medloader_SOURCES MEDFileBasis.cxx MEDFileMeshLL.cxx MEDFileField.cxx + MEDFileJoint.cxx MEDFileParameter.cxx MEDFileData.cxx MEDFileFieldOverView.cxx diff --git a/src/MEDLoader/MEDFileData.cxx b/src/MEDLoader/MEDFileData.cxx index b9a6a20ba..324c729d8 100644 --- a/src/MEDLoader/MEDFileData.cxx +++ b/src/MEDLoader/MEDFileData.cxx @@ -43,8 +43,11 @@ MEDFileData *MEDFileData::deepCpy() const MEDCouplingAutoRefCountObjectPtr params; if((const MEDFileParameters *)_params) params=_params->deepCpy(); + MEDCouplingAutoRefCountObjectPtr joints; + if((const MEDFileJoints *)_joints) + joints=_joints->deepCpy(); MEDCouplingAutoRefCountObjectPtr ret=MEDFileData::New(); - ret->_fields=fields; ret->_meshes=meshes; ret->_params=params; + ret->_fields=fields; ret->_meshes=meshes; ret->_params=params; ret->_joints=joints; return ret.retn(); } @@ -59,6 +62,7 @@ std::vector MEDFileData::getDirectChildrenWithNull() co ret.push_back((const MEDFileFields *)_fields); ret.push_back((const MEDFileMeshes *)_meshes); ret.push_back((const MEDFileParameters *)_params); + ret.push_back((const MEDFileJoints *)_joints); return ret; } @@ -81,6 +85,12 @@ MEDFileParameters *MEDFileData::getParams() const return const_cast(static_cast(_params)); } +/** Return a borrowed reference (caller is not responsible for object destruction) */ +MEDFileJoints *MEDFileData::getJoints() const +{ + return const_cast(static_cast(_joints)); +} + void MEDFileData::setFields(MEDFileFields *fields) { if(fields) @@ -102,6 +112,13 @@ void MEDFileData::setParams(MEDFileParameters *params) _params=params; } +void MEDFileData::setJoints(MEDFileJoints *joints) +{ + if(joints) + joints->incrRef(); + _joints=joints; +} + int MEDFileData::getNumberOfFields() const { const MEDFileFields *f=_fields; @@ -126,6 +143,14 @@ int MEDFileData::getNumberOfParams() const return p->getNumberOfParams(); } +int MEDFileData::getNumberOfJoints() const +{ + const MEDFileJoints *p=_joints; + if(!p) + throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfJoints : no joints set !"); + return p->getNumberOfJoints(); +} + std::string MEDFileData::simpleRepr() const { std::ostringstream oss; @@ -154,6 +179,14 @@ std::string MEDFileData::simpleRepr() const } else oss << "No params set !!!\n"; + oss << "Joints part :\n*************\n\n"; + const MEDFileJoints *tmp4=_joints; + if(tmp4) + { + tmp4->simpleReprWithoutHeader(oss); + } + else + oss << "No joints set !!!\n"; return oss.str(); } @@ -229,6 +262,7 @@ try _fields=MEDFileFields::New(fileName); _meshes=MEDFileMeshes::New(fileName); _params=MEDFileParameters::New(fileName); + _joints=MEDFileJoints::New(fileName); } catch(INTERP_KERNEL::Exception& e) { @@ -248,4 +282,7 @@ void MEDFileData::write(const std::string& fileName, int mode) const const MEDFileParameters *ps=_params; if(ps) ps->writeLL(fid); + const MEDFileJoints *js=_joints; + if(js) + js->write(fid); } diff --git a/src/MEDLoader/MEDFileData.hxx b/src/MEDLoader/MEDFileData.hxx index ce7a2ea36..4c585f1ce 100644 --- a/src/MEDLoader/MEDFileData.hxx +++ b/src/MEDLoader/MEDFileData.hxx @@ -25,6 +25,7 @@ #include "MEDFileParameter.hxx" #include "MEDFileField.hxx" #include "MEDFileMesh.hxx" +#include "MEDFileJoint.hxx" namespace ParaMEDMEM { @@ -42,12 +43,15 @@ namespace ParaMEDMEM MEDLOADER_EXPORT MEDFileFields *getFields() const; MEDLOADER_EXPORT MEDFileMeshes *getMeshes() const; MEDLOADER_EXPORT MEDFileParameters *getParams() const; + MEDLOADER_EXPORT MEDFileJoints *getJoints() const; MEDLOADER_EXPORT void setFields(MEDFileFields *fields); MEDLOADER_EXPORT void setMeshes(MEDFileMeshes *meshes); MEDLOADER_EXPORT void setParams(MEDFileParameters *params); + MEDLOADER_EXPORT void setJoints(MEDFileJoints *joints); MEDLOADER_EXPORT int getNumberOfFields() const; MEDLOADER_EXPORT int getNumberOfMeshes() const; MEDLOADER_EXPORT int getNumberOfParams() const; + MEDLOADER_EXPORT int getNumberOfJoints() const; MEDLOADER_EXPORT std::string simpleRepr() const; // MEDLOADER_EXPORT bool changeMeshNames(const std::vector< std::pair >& modifTab); @@ -62,6 +66,7 @@ namespace ParaMEDMEM MEDCouplingAutoRefCountObjectPtr _fields; MEDCouplingAutoRefCountObjectPtr _meshes; MEDCouplingAutoRefCountObjectPtr _params; + MEDCouplingAutoRefCountObjectPtr _joints; }; } diff --git a/src/MEDLoader/MEDFileJoint.cxx b/src/MEDLoader/MEDFileJoint.cxx new file mode 100644 index 000000000..4f1cd0fc2 --- /dev/null +++ b/src/MEDLoader/MEDFileJoint.cxx @@ -0,0 +1,745 @@ +// Copyright (C) 2007-2015 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, or (at your option) any later version. +// +// 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 "MEDFileJoint.hxx" +#include "MEDFileUtilities.hxx" +#include "MEDLoader.hxx" +#include "MEDLoaderBase.hxx" + +#include "InterpKernelAutoPtr.hxx" + +#include + +extern med_geometry_type typmai3[34]; + +using namespace ParaMEDMEM; + +std::size_t MEDFileJointCorrespondence::getHeapMemorySizeWithoutChildren() const +{ + return sizeof(MEDCouplingAutoRefCountObjectPtr); +} + +std::vector MEDFileJointCorrespondence::getDirectChildrenWithNull() const +{ + return std::vector(); +} +MEDFileJointCorrespondence::MEDFileJointCorrespondence() +{ +} +/*! + * Returns a new MEDFileJointCorrespondence. + * \param [in] loc_ent_type - the local entity type of correspondence. + * \param [in] loc_geo_type - the local geometry type of correspondence. + * \param [in] rem_ent_type - the remote entity type of correspondence. + * \param [in] rem_geo_type - the remote geometry type of correspondence. + * \param [in] num_entity - the number of entity. + * \param [in] correspondence - correspondence. + * \return MEDFileJointCorrespondence * - a new instance of MEDFileJointCorrespondence. + * \throw If the file is not readable. + * \throw If there is no mesh with given attributes in the file. + * \throw If the mesh in the file is of a not supported type. + */ +MEDFileJointCorrespondence::MEDFileJointCorrespondence(TypeOfField loc_ent_type, INTERP_KERNEL::NormalizedCellType loc_geo_type, + TypeOfField rem_ent_type, INTERP_KERNEL::NormalizedCellType rem_geo_type, + DataArrayInt* correspondence) +{ + med_entity_type _cur_loc_ent_type; + med_entity_type _cur_rem_ent_type; + med_geometry_type _cur_loc_geo_type; + med_geometry_type _cur_rem_geo_type; + + _cur_loc_ent_type = ConvertIntoMEDFileType(loc_ent_type,loc_geo_type,_cur_loc_geo_type); + _cur_rem_ent_type = ConvertIntoMEDFileType(rem_ent_type,rem_geo_type,_cur_rem_geo_type); + + MEDFileJointCorrespondence::setLocalEntityType(_cur_loc_ent_type); + MEDFileJointCorrespondence::setRemoteEntityType(_cur_rem_ent_type); + MEDFileJointCorrespondence::setLocalGeometryType(_cur_loc_geo_type); + MEDFileJointCorrespondence::setRemoteGeometryType(_cur_rem_geo_type); + MEDFileJointCorrespondence::setCorrespondence(correspondence); +} + +MEDFileJointCorrespondence *MEDFileJointCorrespondence::New(TypeOfField loc_ent_type, INTERP_KERNEL::NormalizedCellType loc_geo_type, + TypeOfField rem_ent_type, INTERP_KERNEL::NormalizedCellType rem_geo_type, + DataArrayInt* correspondence) +{ + return new MEDFileJointCorrespondence(loc_ent_type, loc_geo_type, rem_ent_type, rem_geo_type, correspondence); +} + + +MEDFileJointCorrespondence *MEDFileJointCorrespondence::New() +{ + return new MEDFileJointCorrespondence(); +} + +med_entity_type MEDFileJointCorrespondence::ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType) +{ + switch(ikType) + { + case ON_CELLS: + medfGeoType=typmai3[(int)ikGeoType]; + return MED_CELL; + case ON_NODES: + medfGeoType=MED_NONE; + return MED_NODE; + case ON_GAUSS_NE: + medfGeoType=typmai3[(int)ikGeoType]; + return MED_NODE_ELEMENT; + case ON_GAUSS_PT: + medfGeoType=typmai3[(int)ikGeoType]; + return MED_CELL; + default: + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::ConvertIntoMEDFileType : unexpected entity type ! internal error"); + } + return MED_UNDEF_ENTITY_TYPE; +} + +/*! + * Writes \a this joint into a MED file specified by its name. + * \param [in] fileName - the MED file name. + * \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics. + * \param [in] order - order. + * \param [in] iteration - iteration. + * - 2 - erase; an existing file is removed. + * - 1 - append; same data should not be present in an existing file. + * - 0 - overwrite; same data present in an existing file is overwritten. + * \throw If the mesh name is not set. + * \throw If \a mode == 1 and the same data is present in an existing file. + */ +void MEDFileJointCorrespondence::write(const std::string& fileName, int mode, const std::string& localMeshName, const std::string& jointName, int order, int iteration) const +{ + med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod); + std::ostringstream oss; oss << "MEDFileJointCorrespondence : error on attempt to write in file : \"" << fileName << "\""; + MEDFileUtilities::CheckMEDCode(fid,fid,oss.str()); + writeLL(fid, localMeshName, jointName, order, iteration); +} + +void MEDFileJointCorrespondence::writeLL(med_idt fid, const std::string& localMeshName, const std::string& jointName, int order, int iteration) const +{ + if((const DataArrayInt *)_correspondence) + MEDsubdomainCorrespondenceWr(fid, localMeshName.c_str(), jointName.c_str(), order, iteration, + getLocalEntityType(), getLocalGeometryType(), getRemoteEntityType(), + getRemoteGeometryType(), _correspondence->getNbOfElems()/2, _correspondence->getConstPointer()); +} +void MEDFileJointCorrespondence::setCorrespondence(DataArrayInt *corr) +{ + _correspondence=DataArrayInt::New(); + _correspondence->alloc(corr->getNbOfElems(),1); + int *cPtr=_correspondence->getPointer(); + int *corPtr= corr->getPointer(); + for(int i=0;igetNbOfElems();i++) + cPtr[i]=corPtr[i]; +} +/*! + * Checks if \a this and another mesh are equal. + * \param [in] other - the mesh to compare with. + * \param [in,out] what - the string returning description of unequal data. + * \return bool - \c true if the meshes are equal, \c false, else. + */ +bool MEDFileJointCorrespondence::isEqual(const MEDFileJointCorrespondence *other, std::string& what) const +{ + if(_loc_ent_type!=other->_loc_ent_type) + { + what="Local entity type differ !"; + return false; + } + if(_rem_ent_type!=other->_rem_ent_type) + { + what="Remote entity type differ !"; + return false; + } + if(_loc_geo_type!=other->_loc_geo_type) + { + what="Local geometry type differ !"; + return false; + } + if(_rem_geo_type!=other->_rem_geo_type) + { + what="Remote geometry type differ !"; + return false; + } + if(_correspondence!=other->_correspondence) + { + what="Correspondence differ !"; + return false; + } + return true; +} + +MEDFileJointCorrespondence *MEDFileJointCorrespondence::deepCpy() const +{ + MEDCouplingAutoRefCountObjectPtr ret=new MEDFileJointCorrespondence(*this); + return ret.retn(); +} + +MEDFileJointCorrespondence *MEDFileJointCorrespondence::shallowCpy() const +{ + MEDCouplingAutoRefCountObjectPtr ret=new MEDFileJointCorrespondence(*this); + return ret.retn(); +} + +/*! + * Returns a string describing \a this mesh. This description includes the correspondence and + * the number correspondence. + * \return std::string - the joint information string. + */ +std::string MEDFileJointCorrespondence::simpleRepr() const +{ + std::ostringstream oss; + oss << "(*************************************)\n(* JOINT_CORRESPOND INFORMATION: *)\n(*************************************)\n"; + oss << "- Local entity type of the correspondence : <<" << getLocalEntityType() << ">>\n"; + oss << "- Local geometry type of the correspondence : <<" << getLocalGeometryType() << ">>\n"; + oss << "- Remote entity type of the correspondence : <<" << getRemoteEntityType() << ">>\n"; + oss << "- Remote geometry type of the correspondence : <<" << getRemoteGeometryType() << ">>\n"; + oss << "- Number entity of the correspondence : <<" << getCorrespondence()->getNumberOfTuples() << ">>\n"; + +const DataArrayInt* tmp=getCorrespondence(); + oss << "- Correspondence : <<"; + for(const int *it=tmp->begin();it!=tmp->end();it++) + oss<< *it << " "; + oss << std::endl; + return oss.str(); +} + + +MEDFileJointOneStep::MEDFileJointOneStep():_order(-1),_iteration(-1) +{ +} + +std::size_t MEDFileJointOneStep::getHeapMemorySizeWithoutChildren() const +{ + return _correspondences.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr); +} + +std::vector MEDFileJointOneStep::getDirectChildrenWithNull() const +{ + return std::vector(); +} + +MEDFileJointOneStep *MEDFileJointOneStep::New() +{ + return new MEDFileJointOneStep(); +} + +MEDFileJointOneStep *MEDFileJointOneStep::New(const std::string& fileName, const std::string& mName, const std::string& jointName, int num) +{ + return new MEDFileJointOneStep(fileName, mName, jointName, num); +} +/*! + * Returns a new MEDFileJointOneStep. + * \param [in] fileName - the name of MED file to read. + * \param [in] mName - the name of the mesh to read. + * \param [in] dt - the number of a time step. + * \param [in] it - the number of an iteration. + * \return MEDFileMesh * - a new instance of MEDFileJointOneStep. + * \throw If the file is not readable. + * \throw If there is no mesh with given attributes in the file. + * \throw If the mesh in the file is of a not supported type. + */ +MEDFileJointOneStep::MEDFileJointOneStep(const std::string& fileName, const std::string& mName, const std::string& jointName, int num) +{ + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(), MED_ACC_RDONLY); + int order, iteration, ncorrespondence; + MEDsubdomainComputingStepInfo(fid, mName.c_str(), jointName.c_str(), num, &order, &iteration, &ncorrespondence); + MEDFileJointOneStep::setOrder(order); + MEDFileJointOneStep::setIteration(iteration); + for(int cur_it = 1; cur_it <= ncorrespondence; ++cur_it) { + int num_entity; + med_entity_type loc_ent_type, rem_ent_type; + med_geometry_type loc_geo_type, rem_geo_type; + MEDsubdomainCorrespondenceSizeInfo(fid, mName.c_str(), jointName.c_str(), order, iteration, cur_it, + &loc_ent_type, &loc_geo_type, &rem_ent_type, &rem_geo_type, &num_entity); + if ( num_entity > 0 ) { + MEDCouplingAutoRefCountObjectPtr correspondence=DataArrayInt::New(); + correspondence->alloc(num_entity*2, 1); + MEDsubdomainCorrespondenceRd(fid, mName.c_str(), jointName.c_str(), order, iteration, loc_ent_type, + loc_geo_type, rem_ent_type, rem_geo_type, correspondence->getPointer()); + MEDFileJointCorrespondence *cor=MEDFileJointCorrespondence::New(); + cor->setLocalEntityType(loc_ent_type); + cor->setRemoteEntityType(rem_ent_type); + cor->setLocalGeometryType(loc_geo_type); + cor->setRemoteGeometryType(rem_geo_type); + cor->setCorrespondence(correspondence); + _correspondences.push_back(cor); + } + } +} + +/*! + * Writes \a this joint into a MED file specified by its name. + * \param [in] fileName - the MED file name. + * \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics. + * - 2 - erase; an existing file is removed. + * - 1 - append; same data should not be present in an existing file. + * - 0 - overwrite; same data present in an existing file is overwritten. + * \throw If the mesh name is not set. + * \throw If \a mode == 1 and the same data is present in an existing file. + */ +void MEDFileJointOneStep::write(const std::string& fileName, int mode, const std::string& localMeshName, const std::string& jointName) const +{ + med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod); + std::ostringstream oss; oss << "MEDFileJointOneStep : error on attempt to write in file : \"" << fileName << "\""; + MEDFileUtilities::CheckMEDCode(fid,fid,oss.str()); + writeLL(fid, localMeshName, jointName); +} + +void MEDFileJointOneStep::writeLL(med_idt fid, const std::string& localMeshName, const std::string& jointName) const +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_correspondences.begin();it!=_correspondences.end();it++) { + (*it)->writeLL(fid, localMeshName, jointName, getOrder(), getIteration()); + } +} + +void MEDFileJointOneStep::pushCorrespondence(MEDFileJointCorrespondence* correspondence) +{ + if(!correspondence) + throw INTERP_KERNEL::Exception("MEDFileJointCorrespondence::pushCorrespondence : invalid input pointer ! should be different from 0 !"); + _correspondences.push_back(correspondence); +} +/*! + * Checks if \a this and another mesh are equal. + * \param [in] other - the mesh to compare with. + * \param [in,out] what - the string returning description of unequal data. + * \return bool - \c true if the meshes are equal, \c false, else. + */ +bool MEDFileJointOneStep::isEqual(const MEDFileJointOneStep *other, std::string& what) const +{ + if(_order!=other->_order) + { + what="Orders differ !"; + return false; + } + if(_iteration!=other->_iteration) + { + what="Iterations differ !"; + return false; + } + return true; +} + +MEDFileJointOneStep *MEDFileJointOneStep::deepCpy() const +{ + std::vector< MEDCouplingAutoRefCountObjectPtr > correspondences(_correspondences.size()); + std::size_t i=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_correspondences.begin();it!=_correspondences.end();it++,i++) + if((const MEDFileJointCorrespondence *)*it) + correspondences[i]=(*it)->deepCpy(); + MEDCouplingAutoRefCountObjectPtr ret= new MEDFileJointOneStep; + ret->_correspondences=correspondences; + return ret.retn(); +} + +MEDFileJointOneStep *MEDFileJointOneStep::shallowCpy() const +{ + MEDCouplingAutoRefCountObjectPtr ret=new MEDFileJointOneStep(*this); + return ret.retn(); +} + +/*! + * Returns a string describing \a this mesh. This description includes the correspondence and + * the number correspondence. + * \return std::string - the joint information string. + */ +std::string MEDFileJointOneStep::simpleRepr() const +{ + std::ostringstream oss; + oss << "(*************************************)\n(* JOINT_ONE_STEP INFORMATION: *)\n(*************************************)\n"; + oss << "- Number of the correspondence : <<" << _correspondences.size() << ">>\n"; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_correspondences.begin();it!=_correspondences.end();it++) { + oss << (*it)->simpleRepr(); + } + return oss.str(); +} + +std::size_t MEDFileJoint::getHeapMemorySizeWithoutChildren() const +{ + return _joint.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr); +} + +std::vector MEDFileJoint::getDirectChildrenWithNull() const +{ + return std::vector(); +} + +MEDFileJoint *MEDFileJoint::New() +{ + return new MEDFileJoint(); +} + +MEDFileJoint *MEDFileJoint::New(const std::string& fileName, const std::string& mName, int curJoint) +{ + return new MEDFileJoint(fileName,mName,curJoint); +} + +MEDFileJoint::MEDFileJoint() +{ +} + +/*! + * Returns a new MEDFileJoint holding the mesh data that has been read from a given MED + * file. The mesh to load is specified by its name and numbers of a time step and an + * iteration. + * \param [in] fileName - the name of MED file to read. + * \param [in] mName - the name of the mesh to read. + * \param [in] num - the number of current joint. + * \return MEDFileJoint * - a new instance of MEDFileJoint. + * \throw If the file is not readable. + * \throw If there is no mesh with given attributes in the file. + * \throw If the mesh in the file is of a not supported type. + */ +MEDFileJoint::MEDFileJoint(const std::string& fileName, const std::string& mName, int curJoint) +{ + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY); + INTERP_KERNEL::AutoPtr joint_name=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr desc_name=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); + INTERP_KERNEL::AutoPtr rem_mesh_name=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + int domain_number=0, nstep=0, nocstpncorrespondence=0; + MEDsubdomainJointInfo(fid,mName.c_str(), curJoint, joint_name, desc_name, &domain_number,rem_mesh_name, + &nstep, &nocstpncorrespondence); + MEDFileJoint::setLocalMeshName(mName); + MEDFileJoint::setRemoteMeshName(MEDLoaderBase::buildStringFromFortran(rem_mesh_name,MED_NAME_SIZE)); + MEDFileJoint::setDescription(MEDLoaderBase::buildStringFromFortran(desc_name,MED_COMMENT_SIZE)); + MEDFileJoint::setJointName(MEDLoaderBase::buildStringFromFortran(joint_name,MED_NAME_SIZE)); + MEDFileJoint::setDomainNumber(domain_number); + for(int cur_step=1; cur_step <= nstep; ++cur_step) { + MEDFileJointOneStep *cor=MEDFileJointOneStep::New(fileName, mName.c_str(), getJointName(), cur_step); + _joint.push_back(cor); + } +} + +/*! + * Writes \a this joint into a MED file specified by its name. + * \param [in] fileName - the MED file name. + * \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics. + * - 2 - erase; an existing file is removed. + * - 1 - append; same data should not be present in an existing file. + * - 0 - overwrite; same data present in an existing file is overwritten. + * \throw If the mesh name is not set. + * \throw If \a mode == 1 and the same data is present in an existing file. + */ +void MEDFileJoint::write(const std::string& fileName, int mode) const +{ + med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod); + std::ostringstream oss; oss << "MEDFileJoint : error on attempt to write in file : \"" << fileName << "\""; + MEDFileUtilities::CheckMEDCode(fid,fid,oss.str()); + write(fid); +} + +void MEDFileJoint::write(med_idt fid) const +{ + MEDsubdomainJointCr(fid,getLocalMeshName().c_str(),getJointName().c_str(),getDescription().c_str(),getDomainNumber(),getRemoteMeshName().c_str()); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_joint.begin();it!=_joint.end();it++) { + (*it)->writeLL(fid, getLocalMeshName(),getJointName()); + } +} + +void MEDFileJoint::pushStep(MEDFileJointOneStep* step) +{ + if(!step) + throw INTERP_KERNEL::Exception("MEDFileJoint::pushStep : invalid input pointer ! should be different from 0 !"); + _joint.push_back(step); +} + +/*! + * Checks if \a this and another mesh are equal. + * \param [in] other - the mesh to compare with. + * \param [in,out] what - the string returning description of unequal data. + * \return bool - \c true if the meshes are equal, \c false, else. + */ +bool MEDFileJoint::isEqual(const MEDFileJoint *other, std::string& what) const +{ + if(_loc_mesh_name!=other->_loc_mesh_name) + { + what="Local mesh names differ !"; + return false; + } + if(_joint_name!=other->_joint_name) + { + what="Joint names differ !"; + return false; + } + if(_desc_name!=other->_desc_name) + { + what="Description names differ !"; + return false; + } + if(_rem_mesh_name!=other->_rem_mesh_name) + { + what="Remote mesh names differ !"; + return false; + } + if(_domain_number!=other->_domain_number) + { + what="Domain numbers differ !"; + return false; + } + return true; +} + +MEDFileJoint *MEDFileJoint::deepCpy() const +{ + std::vector< MEDCouplingAutoRefCountObjectPtr > joint(_joint.size()); + std::size_t i=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_joint.begin();it!=_joint.end();it++,i++) + if((const MEDFileJointOneStep *)*it) + joint[i]=(*it)->deepCpy(); + MEDCouplingAutoRefCountObjectPtr ret=MEDFileJoint::New(); + ret->_joint=joint; + return ret.retn(); +} + +MEDFileJoint *MEDFileJoint::shallowCpy() const +{ + MEDCouplingAutoRefCountObjectPtr ret=new MEDFileJoint(*this); + return ret.retn(); +} + +bool MEDFileJoint::changeJointNames(const std::vector< std::pair >& modifTab) +{ + for(std::vector< std::pair >::const_iterator it=modifTab.begin();it!=modifTab.end();it++) + { + if((*it).first==_joint_name) + { + _joint_name=(*it).second; + return true; + } + } + return false; +} + +/*! + * Returns a string describing \a this mesh. This description includes the correspondence and + * the number correspondence. + * \return std::string - the joint information string. + */ +std::string MEDFileJoint::simpleRepr() const +{ + std::ostringstream oss; + oss << "(*************************************)\n(* JOINT INFORMATION: *)\n(*************************************)\n"; + oss << "- Local Mesh name : <<" << getLocalMeshName() << ">>\n"; + oss << "- Remote Mesh name : <<" << getRemoteMeshName() << ">>\n"; + oss << "- Description : <<" << getDescription() << ">>\n"; + oss << "- Joint name : <<" << getJointName() << ">>\n"; + oss << "- Domain number : <<" << getJointName() << ">>\n"; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_joint.begin();it!=_joint.end();it++) { + oss << (*it)->simpleRepr(); + } + return oss.str(); +} + +MEDFileJoints *MEDFileJoints::New() +{ + return new MEDFileJoints; +} + +MEDFileJoints *MEDFileJoints::New(const std::string& fileName) +{ + return new MEDFileJoints(fileName); +} + +void MEDFileJoints::write(med_idt fid) const +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_joints.begin();it!=_joints.end();it++) { + (*it)->write(fid); + } +} + +void MEDFileJoints::write(const std::string& fileName, int mode) const +{ + med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod); + std::ostringstream oss; oss << "MEDFileJoints : error on attempt to write in file : \"" << fileName << "\""; + MEDFileUtilities::CheckMEDCode(fid,fid,oss.str()); + write(fid); +} + +int MEDFileJoints::getNumberOfJoints() const +{ + return _joints.size(); +} + +/** Return a borrowed reference (caller is not responsible) */ +MEDFileJoint *MEDFileJoints::getJointAtPos(int i) const +{ + const MEDFileJoint *ret; + if(i<0 || i>=(int)_joints.size()) + { + std::ostringstream oss; oss << "MEDFileJoints::getMeshAtPos : invalid mesh id given in parameter ! Should be in [0;" << _joints.size() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + int cur=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_joints.begin();it!=_joints.end();it++,cur++) + { + if (cur == i) + ret=(*it); + } + return const_cast(ret); +} + + +/** Return a borrowed reference (caller is not responsible) */ +MEDFileJoint *MEDFileJoints::getJointWithName(const std::string& jname) const +{ + std::vector js=getJointsNames(); + std::vector::iterator it=std::find(js.begin(),js.end(),jname); + if(it==js.end()) + { + std::ostringstream oss; oss << "MEDFileJoints::getJointWithName : Joint \"" << jname << "\" does not exist in this ! Existing are : "; + std::copy(js.begin(),js.end(),std::ostream_iterator(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return getJointAtPos((int)std::distance(js.begin(),it)); +} + +std::vector MEDFileJoints::getJointsNames() const +{ + std::vector ret(_joints.size()); + int i=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_joints.begin();it!=_joints.end();it++,i++) + { + const MEDFileJoint *f=(*it); + if(f) + { + ret[i]=f->getJointName(); + } + else + { + std::ostringstream oss; oss << "MEDFileJoints::getJointsNames : At rank #" << i << " joint is not defined !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + return ret; +} + +bool MEDFileJoints::changeJointNames(const std::vector< std::pair >& modifTab) +{ + bool ret=false; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_joints.begin();it!=_joints.end();it++) + { + MEDFileJoint *cur(*it); + if(cur) + ret=cur->changeJointNames(modifTab) || ret; + } + return ret; +} + +void MEDFileJoints::resize(int newSize) +{ + _joints.resize(newSize); +} + +void MEDFileJoints::pushJoint(MEDFileJoint *joint) +{ + if(!joint) + throw INTERP_KERNEL::Exception("MEDFileJoints::pushJoint : invalid input pointer ! should be different from 0 !"); + _joints.push_back(joint); +} + +void MEDFileJoints::setJointAtPos(int i, MEDFileJoint *joint) +{ + if(!joint) + throw INTERP_KERNEL::Exception("MEDFileJoints::setJointAtPos : invalid input pointer ! should be different from 0 !"); + if(i>=(int)_joints.size()) + _joints.resize(i+1); + _joints[i]=joint; +} + +void MEDFileJoints::destroyJointAtPos(int i) +{ + if(i<0 || i>=(int)_joints.size()) + { + std::ostringstream oss; oss << "MEDFileJoints::destroyJointAtPos : Invalid given id in input (" << i << ") should be in [0," << _joints.size() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + _joints.erase(_joints.begin()+i); +} + +void MEDFileJoints::loadFromFile(const std::string& fileName) +{ + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY); + std::vector ms=MEDLoader::GetMeshNames(fileName); + for(std::vector::const_iterator it=ms.begin();it!=ms.end();it++) { + int num_joint=MEDnSubdomainJoint(fid,(*it).c_str()); + for(int i = 1; i <= num_joint; i++) + _joints.push_back(MEDFileJoint::New(fileName,(*it),i)); + } +} + +MEDFileJoints::MEDFileJoints() +{ +} + +MEDFileJoints::MEDFileJoints(const std::string& fileName) +try +{ + loadFromFile(fileName); +} +catch(INTERP_KERNEL::Exception& /*e*/) +{ +} + +MEDFileJoints *MEDFileJoints::deepCpy() const +{ + std::vector< MEDCouplingAutoRefCountObjectPtr > joints(_joints.size()); + std::size_t i=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_joints.begin();it!=_joints.end();it++,i++) + if((const MEDFileJoint *)*it) + joints[i]=(*it)->deepCpy(); + MEDCouplingAutoRefCountObjectPtr ret=MEDFileJoints::New(); + ret->_joints=joints; + return ret.retn(); +} + +std::size_t MEDFileJoints::getHeapMemorySizeWithoutChildren() const +{ + return _joints.capacity()*(sizeof(MEDCouplingAutoRefCountObjectPtr)); +} + +std::vector MEDFileJoints::getDirectChildrenWithNull() const +{ + std::vector ret; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_joints.begin();it!=_joints.end();it++) + ret.push_back((const MEDFileJoint *)*it); + return ret; +} + +std::string MEDFileJoints::simpleRepr() const +{ + std::ostringstream oss; + oss << "(*****************)\n(* MEDFileJoints *)\n(*****************)\n\n"; + simpleReprWithoutHeader(oss); + return oss.str(); +} + +void MEDFileJoints::simpleReprWithoutHeader(std::ostream& oss) const +{ + int nbOfJoints=getNumberOfJoints(); + oss << "There are " << nbOfJoints << " joints with the following names : \n"; + std::vector jns=getJointsNames(); + for(int i=0;i >::const_iterator it=_joints.begin();it!=_joints.end();it++) { + oss << (*it)->simpleRepr(); + } +} diff --git a/src/MEDLoader/MEDFileJoint.hxx b/src/MEDLoader/MEDFileJoint.hxx new file mode 100644 index 000000000..add3b7cd4 --- /dev/null +++ b/src/MEDLoader/MEDFileJoint.hxx @@ -0,0 +1,170 @@ +// Copyright (C) 2007-2015 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, or (at your option) any later version. +// +// 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 +// + +#ifndef __MEDFILEJOINT_HXX__ +#define __MEDFILEJOINT_HXX__ + +#include "MEDLoaderDefines.hxx" +#include "MEDFileUtilities.hxx" +#include "MEDCouplingMemArray.hxx" +#include "MEDCouplingAutoRefCountObjectPtr.hxx" + +namespace ParaMEDMEM +{ +class MEDFileJointCorrespondence : public RefCountObject, public MEDFileWritable +{ +public: + MEDLOADER_EXPORT static MEDFileJointCorrespondence *New(); + MEDLOADER_EXPORT static MEDFileJointCorrespondence *New(TypeOfField loc_ent_type, INTERP_KERNEL::NormalizedCellType loc_geo_type, + TypeOfField rem_ent_type, INTERP_KERNEL::NormalizedCellType rem_geo_type, + DataArrayInt* correspondence); + MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; + MEDLOADER_EXPORT std::vector getDirectChildrenWithNull() const; + MEDLOADER_EXPORT MEDFileJointCorrespondence *deepCpy() const; + MEDLOADER_EXPORT MEDFileJointCorrespondence *shallowCpy() const; + MEDLOADER_EXPORT bool isEqual(const MEDFileJointCorrespondence *other, std::string& what) const; + MEDLOADER_EXPORT void setLocalEntityType(med_entity_type type) { _loc_ent_type=type; } + MEDLOADER_EXPORT med_entity_type getLocalEntityType() const { return _loc_ent_type; } + MEDLOADER_EXPORT void setRemoteEntityType(med_entity_type type) { _rem_ent_type=type; } + MEDLOADER_EXPORT med_entity_type getRemoteEntityType() const { return _rem_ent_type; } + MEDLOADER_EXPORT void setLocalGeometryType(med_geometry_type type) { _loc_geo_type=type; } + MEDLOADER_EXPORT med_geometry_type getLocalGeometryType() const { return _loc_geo_type; } + MEDLOADER_EXPORT void setRemoteGeometryType(med_geometry_type type) { _rem_geo_type=type; } + MEDLOADER_EXPORT med_geometry_type getRemoteGeometryType() const { return _rem_geo_type; } + MEDLOADER_EXPORT void setCorrespondence(DataArrayInt *corr); + MEDLOADER_EXPORT const DataArrayInt *getCorrespondence() const { return _correspondence; } + MEDLOADER_EXPORT void write(const std::string& fileName, int mode, const std::string& localMeshName, const std::string& jointName, int order, int iteration) const; + + static med_entity_type ConvertIntoMEDFileType(TypeOfField ikType, INTERP_KERNEL::NormalizedCellType ikGeoType, med_geometry_type& medfGeoType); + MEDLOADER_EXPORT std::string simpleRepr() const; + MEDLOADER_EXPORT void writeLL(med_idt fid, const std::string& localMeshName, const std::string& jointName, int order, int iteration) const; +private: + MEDFileJointCorrespondence(); + MEDFileJointCorrespondence(TypeOfField loc_ent_type, INTERP_KERNEL::NormalizedCellType loc_geo_type, + TypeOfField rem_ent_type, INTERP_KERNEL::NormalizedCellType rem_geo_type, + DataArrayInt* correspondence); +private: + med_entity_type _loc_ent_type; + med_entity_type _rem_ent_type; + med_geometry_type _loc_geo_type; + med_geometry_type _rem_geo_type; + MEDCouplingAutoRefCountObjectPtr _correspondence; +}; + +class MEDFileJointOneStep : public RefCountObject, public MEDFileWritable +{ +public: + MEDLOADER_EXPORT static MEDFileJointOneStep *New(); + MEDLOADER_EXPORT static MEDFileJointOneStep *New(const std::string& fileName, const std::string& mName, const std::string& jointName, int number); + MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; + MEDLOADER_EXPORT std::vector getDirectChildrenWithNull() const; + MEDLOADER_EXPORT MEDFileJointOneStep *deepCpy() const; + MEDLOADER_EXPORT MEDFileJointOneStep *shallowCpy() const; + MEDLOADER_EXPORT bool isEqual(const MEDFileJointOneStep *other, std::string& what) const; + MEDLOADER_EXPORT void setOrder(int order) { _order=order; } + MEDLOADER_EXPORT int getOrder() const { return _order; } + MEDLOADER_EXPORT void setIteration(int it) { _iteration=it; } + MEDLOADER_EXPORT int getIteration() const { return _iteration; } + MEDLOADER_EXPORT void pushCorrespondence(MEDFileJointCorrespondence* correspondence); + + MEDLOADER_EXPORT void write(const std::string& fileName, int mode, const std::string& localMeshName, const std::string& jointName) const; + + MEDLOADER_EXPORT std::string simpleRepr() const; + MEDLOADER_EXPORT void writeLL(med_idt fid, const std::string& localMeshName, const std::string& jointName) const; +private: + MEDFileJointOneStep(); + MEDFileJointOneStep(const std::string& fileName, const std::string& mName, const std::string& jointName, int number); +protected: + int _order; + int _iteration; +private: + std::vector > _correspondences; +}; + class MEDFileJoint : public RefCountObject, public MEDFileWritable + { + public: + MEDLOADER_EXPORT static MEDFileJoint *New(); + MEDLOADER_EXPORT static MEDFileJoint *New(const std::string& fileName, const std::string& mName, int num); + MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; + MEDLOADER_EXPORT std::vector getDirectChildrenWithNull() const; + MEDLOADER_EXPORT MEDFileJoint *deepCpy() const; + MEDLOADER_EXPORT MEDFileJoint *shallowCpy() const; + MEDLOADER_EXPORT bool isEqual(const MEDFileJoint *other, std::string& what) const; + MEDLOADER_EXPORT void setLocalMeshName(const std::string& name) { _loc_mesh_name=name; } + MEDLOADER_EXPORT std::string getLocalMeshName() const { return _loc_mesh_name; } + MEDLOADER_EXPORT void setRemoteMeshName(const std::string& name) { _rem_mesh_name=name; } + MEDLOADER_EXPORT std::string getRemoteMeshName() const { return _rem_mesh_name; } + MEDLOADER_EXPORT void setDescription(const std::string& name) { _desc_name=name; } + MEDLOADER_EXPORT std::string getDescription() const { return _desc_name; } + MEDLOADER_EXPORT void setJointName(const std::string& name) { _joint_name=name; } + MEDLOADER_EXPORT std::string getJointName() const { return _joint_name; } + MEDLOADER_EXPORT bool changeJointNames(const std::vector< std::pair >& modifTab); + MEDLOADER_EXPORT void setDomainNumber(const int& number) { _domain_number=number; } + MEDLOADER_EXPORT int getDomainNumber() const { return _domain_number; } + MEDLOADER_EXPORT void pushStep(MEDFileJointOneStep* step); + + MEDLOADER_EXPORT void write(const std::string& fileName, int mode) const; + MEDLOADER_EXPORT void write(med_idt fid) const; + + MEDLOADER_EXPORT std::string simpleRepr() const; + private: + MEDFileJoint(); + MEDFileJoint(const std::string& fileName, const std::string& mName, int num); + private: + std::string _loc_mesh_name; + std::string _joint_name; + std::string _desc_name; + int _domain_number; + std::string _rem_mesh_name; + std::vector< MEDCouplingAutoRefCountObjectPtr > _joint; + }; + + class MEDFileJoints : public RefCountObject, public MEDFileWritable + { + public: + MEDLOADER_EXPORT static MEDFileJoints *New(); + MEDLOADER_EXPORT static MEDFileJoints *New(const std::string& fileName); + MEDLOADER_EXPORT MEDFileJoints *deepCpy() const; + MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; + MEDLOADER_EXPORT std::vector getDirectChildrenWithNull() const; + MEDLOADER_EXPORT std::string simpleRepr() const; + MEDLOADER_EXPORT void simpleReprWithoutHeader(std::ostream& oss) const; + MEDLOADER_EXPORT void write(const std::string& fileName, int mode) const; + MEDLOADER_EXPORT void write(med_idt fid) const; + MEDLOADER_EXPORT int getNumberOfJoints() const; + MEDLOADER_EXPORT MEDFileJoint *getJointAtPos(int i) const; + MEDLOADER_EXPORT MEDFileJoint *getJointWithName(const std::string& jname) const; + MEDLOADER_EXPORT std::vector getJointsNames() const; + MEDLOADER_EXPORT bool changeJointNames(const std::vector< std::pair >& modifTab); + // + MEDLOADER_EXPORT void resize(int newSize); + MEDLOADER_EXPORT void pushJoint(MEDFileJoint *joint); + MEDLOADER_EXPORT void setJointAtPos(int i, MEDFileJoint *joint); + MEDLOADER_EXPORT void destroyJointAtPos(int i); + private: + ~MEDFileJoints() { } + void loadFromFile(const std::string& fileName); + MEDFileJoints(); + MEDFileJoints(const std::string& fileName); + private: + std::vector< MEDCouplingAutoRefCountObjectPtr > _joints; + }; +} + +#endif diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index f90a4603a..e0e7503da 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -2259,6 +2259,16 @@ void MEDFileUMesh::loadPartUMeshFromFile(med_idt fid, const std::string& mName, dispatchLoadedPart(fid,loaderl2,mName,mrs); } +void MEDFileUMesh::setJoints(const std::string& fileName) +{ + _joints=MEDFileJoints::New(fileName); +} + +void MEDFileUMesh::writeJoints(const std::string& fileName, int mode) +{ + _joints->write(fileName,mode); +} + /*! * This method loads \b all \b the \b mesh \a mName in the file with \a fid descriptor. * @@ -2278,7 +2288,6 @@ void MEDFileUMesh::loadUMeshFromFile(med_idt fid, const std::string& mName, int } loaderl2.loadAll(fid,mid,mName,dt,it,mrs); dispatchLoadedPart(fid,loaderl2,mName,mrs); - } void MEDFileUMesh::dispatchLoadedPart(med_idt fid, const MEDFileUMeshL2& loaderl2, const std::string& mName, MEDFileMeshReadSelector *mrs) @@ -6125,6 +6134,16 @@ std::vector MEDFileMeshes::getMeshesNames() const } return ret; } +/*const MEDFileJoints* MEDFileMeshes::getJoints() const +{ + const MEDFileJoints *ret=_joints; + if(!ret) + { + std::ostringstream oss; oss << "MEDFileMeshes::getJoints : joints is not defined !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return ret; +}*/ bool MEDFileMeshes::changeNames(const std::vector< std::pair >& modifTab) { diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 6b18dc34c..5dd49cc2d 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -26,6 +26,7 @@ #include "MEDFileUtilities.hxx" #include "MEDCouplingPartDefinition.hxx" #include "MEDFileMeshReadSelector.hxx" +#include "MEDFileJoint.hxx" #include #include @@ -291,6 +292,9 @@ namespace ParaMEDMEM std::vector< MEDCouplingAutoRefCountObjectPtr >& bigArraysI, MEDCouplingAutoRefCountObjectPtr& bigArrayD); MEDLOADER_EXPORT void unserialize(std::vector& tinyDouble, std::vector& tinyInt, std::vector& tinyStr, std::vector< MEDCouplingAutoRefCountObjectPtr >& bigArraysI, MEDCouplingAutoRefCountObjectPtr& bigArrayD); + MEDLOADER_EXPORT MEDFileJoints *getJoints() {return _joints;} + MEDLOADER_EXPORT void setJoints(const std::string& fileName); + MEDLOADER_EXPORT void writeJoints(const std::string& fileName, int mode); private: MEDLOADER_EXPORT ~MEDFileUMesh(); void writeLL(med_idt fid) const; @@ -317,6 +321,7 @@ namespace ParaMEDMEM MEDCouplingAutoRefCountObjectPtr _name_coords; mutable MEDCouplingAutoRefCountObjectPtr _rev_num_coords; MEDCouplingAutoRefCountObjectPtr _part_coords; + MEDCouplingAutoRefCountObjectPtr _joints; }; class MEDFileStructuredMesh : public MEDFileMesh diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 122db995c..5bf0c6a85 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -27,6 +27,7 @@ %{ #include "MEDLoader.hxx" +#include "MEDFileJoint.hxx" #include "MEDFileMesh.hxx" #include "MEDFileField.hxx" #include "MEDFileParameter.hxx" @@ -176,6 +177,7 @@ using namespace ParaMEDMEM; %newobject ParaMEDMEM::MEDFileData::getMeshes; %newobject ParaMEDMEM::MEDFileData::getFields; %newobject ParaMEDMEM::MEDFileData::getParams; +%newobject ParaMEDMEM::MEDFileData::getJoints; %newobject ParaMEDMEM::MEDFileParameterDouble1TS::New; %newobject ParaMEDMEM::MEDFileParameterDouble1TS::deepCpy; @@ -189,6 +191,21 @@ using namespace ParaMEDMEM; %newobject ParaMEDMEM::MEDFileParameters::getParamWithName; %newobject ParaMEDMEM::MEDFileParameters::__getitem__; +%newobject ParaMEDMEM::MEDFileJointCorrespondence::New; +%newobject ParaMEDMEM::MEDFileJointCorrespondence::deepCpy; +%newobject ParaMEDMEM::MEDFileJointCorrespondence::shallowCpy; +%newobject ParaMEDMEM::MEDFileJointOneStep::New; +%newobject ParaMEDMEM::MEDFileJointOneStep::deepCpy; +%newobject ParaMEDMEM::MEDFileJointOneStep::shallowCpy; +%newobject ParaMEDMEM::MEDFileJoint::New; +%newobject ParaMEDMEM::MEDFileJoint::deepCpy; +%newobject ParaMEDMEM::MEDFileJoint::shallowCpy; +%newobject ParaMEDMEM::MEDFileJoints::New; +%newobject ParaMEDMEM::MEDFileJoints::deepCpy; +%newobject ParaMEDMEM::MEDFileJoints::getJointAtPos; +%newobject ParaMEDMEM::MEDFileJoints::getJointWithName; +%newobject ParaMEDMEM::MEDFileJoints::__getitem__; + %newobject ParaMEDMEM::SauvWriter::New; %newobject ParaMEDMEM::SauvReader::New; %newobject ParaMEDMEM::SauvReader::loadInMEDFileDS; @@ -217,6 +234,10 @@ using namespace ParaMEDMEM; %feature("unref") MEDFileParameterDouble1TS "$this->decrRef();" %feature("unref") MEDFileParameterMultiTS "$this->decrRef();" %feature("unref") MEDFileParameters "$this->decrRef();" +%feature("unref") MEDFileJointCorrespondence "$this->decrRef();" +%feature("unref") MEDFileJointOneStep "$this->decrRef();" +%feature("unref") MEDFileJoint "$this->decrRef();" +%feature("unref") MEDFileJoints "$this->decrRef();" %feature("unref") MEDFileData "$this->decrRef();" %feature("unref") SauvReader "$this->decrRef();" %feature("unref") SauvWriter "$this->decrRef();" @@ -474,7 +495,245 @@ namespace ParaMEDMEM } } }; + class MEDFileJointCorrespondence : public RefCountObject, public MEDFileWritable + { + public: + static MEDFileJointCorrespondence *New() throw(INTERP_KERNEL::Exception); + static MEDFileJointCorrespondence *New(TypeOfField loc_ent_type, INTERP_KERNEL::NormalizedCellType loc_geo_type, + TypeOfField rem_ent_type, INTERP_KERNEL::NormalizedCellType rem_geo_type, + DataArrayInt* correspondence) throw(INTERP_KERNEL::Exception); + std::size_t getHeapMemorySizeWithoutChildren() const; + std::vector getDirectChildrenWithNull() const; + MEDFileJointCorrespondence *deepCpy() const; + MEDFileJointCorrespondence *shallowCpy() const; + void setLocalEntityType(med_entity_type type); + med_entity_type getLocalEntityType() const; + void setRemoteEntityType(med_entity_type type); + med_entity_type getRemoteEntityType() const; + void setLocalGeometryType(med_geometry_type type); + med_geometry_type getLocalGeometryType() const; + void setRemoteGeometryType(med_geometry_type type); + med_geometry_type getRemoteGeometryType() const; + void setCorrespondence(DataArrayInt *corr); + const DataArrayInt *getCorrespondence() const; + void write(const std::string& fileName, int mode, const std::string& localMeshName, const std::string& jointName, int order, int iteration) const; + std::string simpleRepr() const; + void writeLL(med_idt fid, const std::string& localMeshName, const std::string& jointName, int order, int iteration) const; + %extend + { + MEDFileJointCorrespondence() + { + return MEDFileJointCorrespondence::New(); + } + MEDFileJointCorrespondence(TypeOfField loc_ent_type, INTERP_KERNEL::NormalizedCellType loc_geo_type, + TypeOfField rem_ent_type, INTERP_KERNEL::NormalizedCellType rem_geo_type, + DataArrayInt* correspondence) throw(INTERP_KERNEL::Exception) + { + return MEDFileJointCorrespondence::New(loc_ent_type, loc_geo_type, rem_ent_type, rem_geo_type, correspondence); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->simpleRepr(); + } + + PyObject *isEqual(const MEDFileJointCorrespondence *other) const throw(INTERP_KERNEL::Exception) + { + std::string what; + bool ret0=self->isEqual(other,what); + PyObject *res=PyList_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyList_SetItem(res,0,ret0Py); + PyList_SetItem(res,1,PyString_FromString(what.c_str())); + return res; + } + + } +}; + + class MEDFileJointOneStep : public RefCountObject, public MEDFileWritable + { + public: + static MEDFileJointOneStep *New() throw(INTERP_KERNEL::Exception); + static MEDFileJointOneStep *New(const std::string& fileName, const std::string& mName, const std::string& jointName, int number) throw(INTERP_KERNEL::Exception); + std::size_t getHeapMemorySizeWithoutChildren() const; + std::vector getDirectChildrenWithNull() const; + MEDFileJointOneStep *deepCpy() const; + MEDFileJointOneStep *shallowCpy() const; + bool isEqual(const MEDFileJointOneStep *other, std::string& what) const; + void setOrder(int order); + int getOrder() const; + void setIteration(int it); + int getIteration() const; + void pushCorrespondence(MEDFileJointCorrespondence* correspondence); + void write(const std::string& fileName, int mode, const std::string& localMeshName, const std::string& jointName) const; + std::string simpleRepr() const; + void writeLL(med_idt fid, const std::string& localMeshName, const std::string& jointName) const; + %extend + { + MEDFileJointOneStep() + { + return MEDFileJointOneStep::New(); + } + + MEDFileJointOneStep(const std::string& fileName, const std::string& mName, const std::string& jointName, int number) throw(INTERP_KERNEL::Exception) + { + return MEDFileJointOneStep::New(fileName,mName,jointName,number); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->simpleRepr(); + } + + PyObject *isEqual(const MEDFileJointOneStep *other) const throw(INTERP_KERNEL::Exception) + { + std::string what; + bool ret0=self->isEqual(other,what); + PyObject *res=PyList_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyList_SetItem(res,0,ret0Py); + PyList_SetItem(res,1,PyString_FromString(what.c_str())); + return res; + } + } + }; + class MEDFileJoint : public RefCountObject, public MEDFileWritable + { + public: + static MEDFileJoint *New() throw(INTERP_KERNEL::Exception); + static MEDFileJoint *New(const std::string& fileName, const std::string& mName, int num) throw(INTERP_KERNEL::Exception); + std::size_t getHeapMemorySizeWithoutChildren() const; + std::vector getDirectChildrenWithNull() const; + MEDFileJoint *deepCpy() const; + MEDFileJoint *shallowCpy() const; + bool isEqual(const MEDFileJoint *other, std::string& what) const; + void setLocalMeshName(const std::string& name); + std::string getLocalMeshName() const; + void setRemoteMeshName(const std::string& name); + std::string getRemoteMeshName() const; + void setDescription(const std::string& name); + std::string getDescription() const; + void setJointName(const std::string& name); + std::string getJointName() const; + bool changeJointNames(const std::vector< std::pair >& modifTab); + void setDomainNumber(const int& number); + int getDomainNumber() const; + void pushStep(MEDFileJointOneStep* step); + void write(const std::string& fileName, int mode) const; + void write(med_idt fid) const; + std::string simpleRepr() const; + %extend + { + MEDFileJoint() + { + return MEDFileJoint::New(); + } + + MEDFileJoint(const std::string& fileName, const std::string& mName, int num) throw(INTERP_KERNEL::Exception) + { + return MEDFileJoint::New(fileName,mName,num); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->simpleRepr(); + } + + PyObject *isEqual(const MEDFileJoint *other) const throw(INTERP_KERNEL::Exception) + { + std::string what; + bool ret0=self->isEqual(other,what); + PyObject *res=PyList_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyList_SetItem(res,0,ret0Py); + PyList_SetItem(res,1,PyString_FromString(what.c_str())); + return res; + } + } + }; + + class MEDFileJoints : public RefCountObject, public MEDFileWritable + { + public: + static MEDFileJoints *New() throw(INTERP_KERNEL::Exception); + static MEDFileJoints *New(const std::string& fileName) throw(INTERP_KERNEL::Exception); + MEDFileJoints *deepCpy() const; + std::size_t getHeapMemorySizeWithoutChildren() const; + std::vector getDirectChildrenWithNull() const; + std::string simpleRepr() const; + void simpleReprWithoutHeader(std::ostream& oss) const; + void write(const std::string& fileName, int mode) const; + void write(med_idt fid) const; + int getNumberOfJoints() const; + std::vector getJointsNames() const; + bool changeJointNames(const std::vector< std::pair >& modifTab); + void resize(int newSize); + void pushJoint(MEDFileJoint *joint); + void setJointAtPos(int i, MEDFileJoint *joint); + void destroyJointAtPos(int i); + %extend + { + MEDFileJoints() + { + return MEDFileJoints::New(); + } + + MEDFileJoints(const std::string& fileName) + { + return MEDFileJoints::New(fileName); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->simpleRepr(); + } + MEDFileJoint *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + if(PyInt_Check(obj)) + { + MEDFileJoint *ret=self->getJointAtPos(InterpreteNegativeInt((int)PyInt_AS_LONG(obj),self->getNumberOfJoints())); + if(ret) + ret->incrRef(); + return ret; + } + else if(PyString_Check(obj)) + { + MEDFileJoint *ret=self->getJointWithName(PyString_AsString(obj)); + if(ret) + ret->incrRef(); + return ret; + } + else + throw INTERP_KERNEL::Exception("MEDFileJoints::__getitem__ : only integer or string with meshname supported !"); + } + + int __len__() const throw(INTERP_KERNEL::Exception) + { + return self->getNumberOfJoints(); + } + + MEDFileJoint *getJointAtPos(int i) const throw(INTERP_KERNEL::Exception) + { + MEDFileJoint *ret=self->getJointAtPos(i); + if(ret) + ret->incrRef(); + return ret; + } + + MEDFileJoint *getJointWithName(const std::string& paramName) const throw(INTERP_KERNEL::Exception) + { + MEDFileJoint *ret=self->getJointWithName(paramName); + if(ret) + ret->incrRef(); + return ret; + } + } + }; class MEDFileMesh : public RefCountObject, public MEDFileWritable { public: diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 3a8a1daf1..186774c89 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -4180,5 +4180,86 @@ class MEDLoaderTest(unittest.TestCase): self.assertEqual(fs2[0].getTimeSteps(),[(i,0,float(i)) for i in xrange(nbPdt)]) pass pass + def testMEDFileJoint1(self): + fileName="Pyfile88.med" + coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)]) + coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"]) + mm=MEDFileUMesh() + mm.setCoords(coo) + mm.setName("maa1") + mm.setDescription("un maillage") + mm.write(fileName,2) + first_correspond=MEDFileJointCorrespondence(ON_NODES,NORM_MAXTYPE,ON_NODES,NORM_MAXTYPE,DataArrayInt([1,2,3,4,5,6,7,8])) + second_correspond=MEDFileJointCorrespondence(ON_CELLS,NORM_MAXTYPE,ON_CELLS,NORM_MAXTYPE,DataArrayInt([9,10,11,12])) + one_step_joint=MEDFileJointOneStep() + one_joint=MEDFileJoint() + one_step_joint.pushCorrespondence(first_correspond) + one_step_joint.pushCorrespondence(second_correspond) + one_joint.pushStep(one_step_joint) + one_joint.setLocalMeshName("maa1") + one_joint.setRemoteMeshName("maa1") + one_joint.setDescription("joint_description") + one_joint.setJointName("joint_1") + one_joint.setDomainNumber(1) + joints=MEDFileJoints(fileName) + joints.pushJoint(one_joint); + joints.write(fileName,0) + # + pass + def testMEDFileJoint2(self): + fileNameRd="Pyfile88.med" + fileNameWr="Pyfile89.med" + coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)]) + coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"]) + mm=MEDFileUMesh() + mm.setCoords(coo) + mm.setName("maa1") + mm.setDescription("un maillage") + mm.write(fileNameWr,2) + joints=MEDFileJoints(fileNameRd) + joints.destroyJointAtPos(0) + first_correspond=MEDFileJointCorrespondence(ON_NODES,NORM_MAXTYPE,ON_NODES,NORM_MAXTYPE,DataArrayInt([13,14,15,16])) + second_correspond=MEDFileJointCorrespondence(ON_CELLS,NORM_MAXTYPE,ON_CELLS,NORM_MAXTYPE,DataArrayInt([17,18])) + one_step_joint=MEDFileJointOneStep() + two_step_joint=MEDFileJointOneStep() + one_joint=MEDFileJoint() + two_joint=MEDFileJoint() + one_step_joint.pushCorrespondence(first_correspond) + one_joint.pushStep(one_step_joint) + two_step_joint.pushCorrespondence(first_correspond) + two_step_joint.pushCorrespondence(second_correspond) + two_joint.pushStep(two_step_joint) + one_joint.setLocalMeshName("maa1") + one_joint.setRemoteMeshName("maa1") + one_joint.setDescription("joint_description_1") + one_joint.setJointName("joint_1") + one_joint.setDomainNumber(1) + two_joint.setLocalMeshName("maa1") + two_joint.setRemoteMeshName("maa1") + two_joint.setDescription("joint_description_2") + two_joint.setJointName("joint_2") + two_joint.setDomainNumber(2) + joints.pushJoint(one_joint) + joints.pushJoint(two_joint) + joints.write(fileNameWr,0) + # + #mm=MEDFileMesh.New(fileNameWr) + #self.assertEqual(mm.getName(),"maa1") + pass + def testMEDFileJoint3(self): + fileNameRd="splitted_blade1.med" + fileNameWr="Pyfile90.med" + coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)]) + coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"]) + mm=MEDFileUMesh() + mm.setCoords(coo) + mm.setName("Fuse_1_1") + mm.setDescription("un maillage") + mm.write(fileNameWr,2) + joints=MEDFileJoints(fileNameRd) + joints.write(fileNameWr,0) + #mm=MEDFileMesh.New(fileNameWr) + #self.assertEqual(mm.getName(),"maa1") + pass unittest.main() diff --git a/src/MEDPartitioner/CMakeLists.txt b/src/MEDPartitioner/CMakeLists.txt index d6003437c..9deaf3afc 100644 --- a/src/MEDPartitioner/CMakeLists.txt +++ b/src/MEDPartitioner/CMakeLists.txt @@ -80,6 +80,7 @@ SET(medpartitionercpp_HEADERS_HXX MEDPARTITIONER_ConnectZone.hxx MEDPARTITIONER_SkyLineArray.hxx MEDPARTITIONER_Topology.hxx + MEDPARTITIONER_MEDPartitioner.hxx ) SET(medpartitionercpp_SOURCES @@ -95,6 +96,7 @@ SET(medpartitionercpp_SOURCES MEDPARTITIONER_ConnectZone.cxx MEDPARTITIONER_SkyLineArray.cxx MEDPARTITIONER_metis.c + MEDPARTITIONER_MEDPartitioner.cxx ) SET(medpartitionercpp_LDFLAGS diff --git a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx new file mode 100644 index 000000000..34fcf174b --- /dev/null +++ b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx @@ -0,0 +1,184 @@ +// Copyright (C) 2007-2015 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, or (at your option) any later version. +// +// 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 "MEDPARTITIONER_MEDPartitioner.hxx" +#include "MEDPARTITIONER_MeshCollection.hxx" +#include "MEDPARTITIONER_Topology.hxx" +#include "MEDPARTITIONER_ParaDomainSelector.hxx" +#include "MEDPARTITIONER_ParallelTopology.hxx" +#include "MEDPARTITIONER_Utils.hxx" +#include "MEDPARTITIONER_Graph.hxx" +#include "MEDPARTITIONER_MetisGraph.hxx" +#include "MEDPARTITIONER_ScotchGraph.hxx" +#include "MEDCouplingUMesh.hxx" + +#include +#include + +MEDPARTITIONER::MEDPartitioner *MEDPARTITIONER::MEDPartitioner::New(const std::string& filename, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory) +{ + return new MEDPartitioner(filename,ndomains,library,creates_boundary_faces, create_joints, mesure_memory); +} + +MEDPARTITIONER::MEDPartitioner *MEDPARTITIONER::MEDPartitioner::New(const ParaMEDMEM::MEDFileData* filedata, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory) +{ + return new MEDPartitioner(filedata,ndomains,library,creates_boundary_faces, create_joints, mesure_memory); +} + +MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const std::string& filename, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory) +{ + ParaDomainSelector parallelizer(mesure_memory); + _input_collection=new MeshCollection(filename,parallelizer); + parallelizer.evaluateMemory(); + createPartitionCollection(ndomains, library, creates_boundary_faces, create_joints, mesure_memory); +} + +MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const ParaMEDMEM::MEDFileData* filedata, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory) +{ + _input_collection=new MeshCollection(); + for (int i=0; igetMeshes()->getNumberOfMeshes(); i++) + { + ParaMEDMEM::MEDFileUMesh *mfm = dynamic_cast(filedata->getMeshes()->getMeshAtPos(i)); + std::vector nonEmpty=mfm->getNonEmptyLevels(); + try + { + (_input_collection->getMesh()).push_back(mfm->getLevel0Mesh(false)); + //reading families groups + ParaMEDMEM::DataArrayInt* cellIds(mfm->getFamilyFieldAtLevel(0)->deepCpy()); + (_input_collection->getCellFamilyIds()).push_back(cellIds); + } + catch(...) + { + (_input_collection->getMesh()).push_back(CreateEmptyMEDCouplingUMesh()); // or 0 if you want tests; + ParaMEDMEM::DataArrayInt* empty=ParaMEDMEM::DataArrayInt::New(); + empty->alloc(0,1); + (_input_collection->getCellFamilyIds()).push_back(empty); + } + try + { + if (nonEmpty.size()>1 && nonEmpty[1]==-1) + { + (_input_collection->getFaceMesh()).push_back(mfm->getLevelM1Mesh(false)); + //reading families groups + ParaMEDMEM::DataArrayInt* faceIds(mfm->getFamilyFieldAtLevel(-1)->deepCpy()); + (_input_collection->getFaceFamilyIds()).push_back(faceIds); + } + else + { + throw INTERP_KERNEL::Exception("no faces"); + } + } + catch(...) + { + (_input_collection->getFaceMesh()).push_back(CreateEmptyMEDCouplingUMesh()); // or 0 if you want test; + ParaMEDMEM::DataArrayInt* empty=ParaMEDMEM::DataArrayInt::New(); + (_input_collection->getFaceFamilyIds()).push_back(empty); + } + //reading groups + _input_collection->getFamilyInfo()=mfm->getFamilyInfo(); + _input_collection->getGroupInfo()=mfm->getGroupInfo(); + mfm->decrRef(); + } + std::vector cellglobal; + std::vector nodeglobal; + std::vector faceglobal; + int size = (_input_collection->getMesh()).size(); + cellglobal.resize(size); + nodeglobal.resize(size); + faceglobal.resize(size); + + for ( int idomain = 0; idomain < size; ++idomain ) + { + cellglobal[idomain]=0; + faceglobal[idomain]=0; + nodeglobal[idomain]=0; + if ( (_input_collection->getMesh())[idomain] && (_input_collection->getMesh())[idomain]->getNumberOfNodes() > 0 ) + _input_collection->setNonEmptyMesh(idomain); + } + + ParallelTopology* aPT = new ParallelTopology((_input_collection->getMesh()), (_input_collection->getCZ()), cellglobal, nodeglobal, faceglobal); + _input_collection->setTopology(aPT); + + createPartitionCollection(ndomains, library, creates_boundary_faces, create_joints, mesure_memory); +} + +void MEDPARTITIONER::MEDPartitioner::createPartitionCollection(int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory) +{ + ParallelTopology* aPT = (ParallelTopology*) _input_collection->getTopology(); + std::auto_ptr< Topology > new_topo; + if (library == "metis") + new_topo.reset( _input_collection->createPartition(ndomains,MEDPARTITIONER::Graph::METIS)); + else + new_topo.reset(_input_collection->createPartition(ndomains,MEDPARTITIONER::Graph::SCOTCH)); + _output_collection=new MeshCollection(*_input_collection,new_topo.get(),false,false); +} + +void MEDPARTITIONER::MEDPartitioner::Write(const std::string& filename) +{ + _output_collection->write(filename); +} + +ParaMEDMEM::MEDFileData* MEDPARTITIONER::MEDPartitioner::getMEDFileData() +{ + return convertToMEDFileData(_output_collection); +} + +ParaMEDMEM::MEDFileData* MEDPARTITIONER::MEDPartitioner::convertToMEDFileData(MeshCollection* collection) +{ + ParaMEDMEM::MEDFileData* newdata=ParaMEDMEM::MEDFileData::New(); + for (int i=0; i<(collection->getMesh()).size(); i++) + { + ParaMEDMEM::MEDFileUMesh *mfm = ParaMEDMEM::MEDFileUMesh::New(); + mfm->setMeshAtLevel(0,(collection->getMesh())[i]); + mfm->setMeshAtLevel(-1,(collection->getFaceMesh())[i]); + mfm->setFamilyFieldArr(0,(collection->getCellFamilyIds())[i]); + mfm->setFamilyFieldArr(-1,(collection->getFaceFamilyIds())[i]); + mfm->setFamilyInfo(collection->getFamilyInfo()); + mfm->setGroupInfo(collection->getGroupInfo()); + } + return newdata; +} + +MEDPARTITIONER::Graph* MEDPARTITIONER::MEDPartitioner::Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, Graph::splitter_type split, int* edgeweight) +{ + MEDPARTITIONER::SkyLineArray* r=0; + MEDPARTITIONER::Graph* cellGraph = 0; + switch (split) + { + case Graph::METIS: + if ( !cellGraph ) + { + #ifdef MED_ENABLE_METIS + cellGraph=new METISGraph(r,edgeweight); + #endif + } + if ( !cellGraph ) + throw INTERP_KERNEL::Exception("MeshCollection::createPartition : PARMETIS/METIS is not available. Check your products, please."); + break; + case Graph::SCOTCH: + #ifdef MED_ENABLE_SCOTCH + cellGraph=new SCOTCHGraph(r,edgeweight); + #else + throw INTERP_KERNEL::Exception("MeshCollection::createPartition : SCOTCH is not available. Check your products, please."); + #endif + break; + } + return cellGraph; + +} diff --git a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx new file mode 100644 index 000000000..24df096f9 --- /dev/null +++ b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx @@ -0,0 +1,60 @@ +// Copyright (C) 2007-2015 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, or (at your option) any later version. +// +// 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 +// + +#ifndef __MEDPARTITIONER_MEDPARTITIONER_HXX__ +#define __MEDPARTITIONER_MEDPARTITIONER_HXX__ + +#include "MEDFileData.hxx" +#include "MEDCouplingSkyLineArray.hxx" +#include "MEDPARTITIONER_Graph.hxx" + +#include +#include + +namespace ParaMEDMEM +{ + class DataArrayInt; + class MEDFileData; +} + +namespace MEDPARTITIONER +{ + class Topology; + class MeshCollection; + class ParaDomainSelector; + class Graph; + + class MEDPartitioner + { + public: + static MEDPartitioner *New(const std::string& filename, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false); + static MEDPartitioner *New(const ParaMEDMEM::MEDFileData* filedata, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false); + void Write(const std::string& filename); + ParaMEDMEM::MEDFileData* getMEDFileData(); + MEDPARTITIONER::Graph* Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, Graph::splitter_type split, int* edgeweight=0); + private: + MEDPartitioner(const std::string& filename, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory); + MEDPartitioner(const ParaMEDMEM::MEDFileData* filedata, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory); + ParaMEDMEM::MEDFileData *convertToMEDFileData(MeshCollection* meshcollection); + void createPartitionCollection(int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory); + MeshCollection* _input_collection; + MeshCollection* _output_collection; + }; +} +#endif diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx index 8678cf786..a5a4efcb0 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx @@ -1904,7 +1904,7 @@ MEDPARTITIONER::Topology* MEDPARTITIONER::MeshCollection::createPartition(int nb buildParallelCellGraph(array,edgeweights); else buildCellGraph(array,edgeweights); - + Graph* cellGraph = 0; switch (split) { diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.hxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.hxx index 04a7083b2..3fae6277f 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.hxx @@ -131,6 +131,8 @@ namespace MEDPARTITIONER void setName(const std::string& name) { _name=name; } void setDomainNames(const std::string& name); + void setNonEmptyMesh(int number) { _i_non_empty_mesh=number;} + //getting/setting the description of the global mesh std::string getDescription() const { return _description; } void setDescription(const std::string& name) { _description=name; } diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx index 7c0358e56..253322795 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx @@ -27,6 +27,7 @@ #include "MEDCouplingFieldDouble.hxx" #include "MEDLoader.hxx" #include "MEDFileMesh.hxx" +#include "MEDFileJoint.hxx" #include #include @@ -60,6 +61,7 @@ int MeshCollectionDriver::readSeq(const char* filename, const char* meshname) MyGlobals::_File_Names[0]=std::string(filename); ParaMEDMEM::MEDFileUMesh* mfm=ParaMEDMEM::MEDFileUMesh::New(filename,meshname); + mfm->setJoints(std::string(filename)); //puts the only mesh in the mesh vector (_collection->getMesh()).push_back(mfm->getLevel0Mesh(false)); (_collection->getFaceMesh()).push_back(mfm->getLevelM1Mesh(false)); @@ -144,7 +146,6 @@ void MeshCollectionDriver::readSubdomain(std::vector& cellglobal, //reading groups _collection->getFamilyInfo()=mfm->getFamilyInfo(); _collection->getGroupInfo()=mfm->getGroupInfo(); - mfm->decrRef(); std::vector localInformation; @@ -165,7 +166,6 @@ void MeshCollectionDriver::readSubdomain(int idomain) ParaMEDMEM::MEDFileUMesh* mfm=ParaMEDMEM::MEDFileUMesh::New(file,meshname); std::vector nonEmpty=mfm->getNonEmptyLevels(); - try { (_collection->getMesh())[idomain]=mfm->getLevel0Mesh(false); @@ -270,7 +270,10 @@ void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfile // boundaryMesh->decrRef(); // } ParaMEDMEM::MEDFileUMesh* mfm=ParaMEDMEM::MEDFileUMesh::New(distfilename, _collection->getMesh(idomain)->getName()); - + if (MyGlobals::_Create_Joints) { + mfm->setJoints( MyGlobals::_File_Names[0]); + mfm->writeJoints(distfilename,0); + } mfm->setFamilyInfo(_collection->getFamilyInfo()); mfm->setGroupInfo(_collection->getGroupInfo()); diff --git a/src/MEDPartitioner/MEDPARTITIONER_ParallelTopology.cxx b/src/MEDPartitioner/MEDPARTITIONER_ParallelTopology.cxx index 658379ac2..d445d3032 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_ParallelTopology.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_ParallelTopology.cxx @@ -278,7 +278,7 @@ ParallelTopology::ParallelTopology(Graph* graph, Topology* oldTopology, int nb_d _nb_domain=nb_domain; _mesh_dimension=mesh_dimension; - + if (MyGlobals::_Verbose>200) std::cout << "proc " << MyGlobals::_Rank << " : new topology oldNbDomain " << oldTopology->nbDomain() << " newNbDomain " << _nb_domain << std::endl; diff --git a/src/MEDPartitioner/MEDPARTITIONER_Utils.cxx b/src/MEDPartitioner/MEDPARTITIONER_Utils.cxx index ae6174557..861da009d 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_Utils.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_Utils.cxx @@ -45,6 +45,7 @@ int MEDPARTITIONER::MyGlobals::_World_Size=-1; int MEDPARTITIONER::MyGlobals::_Randomize=0; int MEDPARTITIONER::MyGlobals::_Atomize=0; int MEDPARTITIONER::MyGlobals::_Creates_Boundary_Faces=0; +int MEDPARTITIONER::MyGlobals::_Create_Joints=0; std::vector MEDPARTITIONER::MyGlobals::_File_Names; std::vector MEDPARTITIONER::MyGlobals::_Mesh_Names; std::vector MEDPARTITIONER::MyGlobals::_Field_Descriptions; diff --git a/src/MEDPartitioner/MEDPARTITIONER_Utils.hxx b/src/MEDPartitioner/MEDPARTITIONER_Utils.hxx index f0a1b8270..64fc0c2b9 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_Utils.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_Utils.hxx @@ -127,6 +127,7 @@ namespace MEDPARTITIONER static int _Randomize; static int _Atomize; static int _Creates_Boundary_Faces; + static int _Create_Joints; static int _Is0verbose; //trace cout if rank 0 and verbose static std::vector _File_Names; //on [iold] static std::vector _Mesh_Names; //on [iold] diff --git a/src/MEDPartitioner/medpartitioner.cxx b/src/MEDPartitioner/medpartitioner.cxx index cb6452057..48b90a7d4 100644 --- a/src/MEDPartitioner/medpartitioner.cxx +++ b/src/MEDPartitioner/medpartitioner.cxx @@ -73,6 +73,7 @@ int main(int argc, char** argv) MyGlobals::_World_Size=1; MyGlobals::_Rank=0; MyGlobals::_Creates_Boundary_Faces=0; + MyGlobals::_Create_Joints=0; // Primitive parsing of command-line options string desc ("Available options of medpartitioner V1.0:\n" @@ -86,6 +87,7 @@ int main(int argc, char** argv) "\t--split-method= : name of the splitting library (metis/scotch), default is metis\n" #endif "\t--creates-boundary-faces : creates boundary faces mesh in the output files\n" + "\t--creates-joints : creates joints in the output files\n" "\t--dump-cpu-memory : dumps passed CPU time and maximal increase of used memory\n" ); @@ -111,6 +113,7 @@ int main(int argc, char** argv) else if (TestArg(argv[i],"--split-method",value)) library=value; else if (TestArg(argv[i],"--ndomains",value)) ndomains=atoi(value.c_str()); else if (TestArg(argv[i],"--creates-boundary-faces",value)) MyGlobals::_Creates_Boundary_Faces=1; + else if (TestArg(argv[i],"--create-joints",value)) MyGlobals::_Create_Joints=1; else if (TestArg(argv[i],"--dump-cpu-memory",value)) mesure_memory=true; else { @@ -151,6 +154,7 @@ int main(int argc, char** argv) cout << " split-method = " << library << endl; cout << " ndomains = " << ndomains << endl; cout << " creates_boundary_faces = " << MyGlobals::_Creates_Boundary_Faces << endl; + cout << " create-joints = " << MyGlobals::_Create_Joints<< endl; cout << " dump-cpu-memory = " << mesure_memory<< endl; cout << " verbose = " << MyGlobals::_Verbose << endl; } diff --git a/src/MEDPartitioner_Swig/CMakeLists.txt b/src/MEDPartitioner_Swig/CMakeLists.txt new file mode 100644 index 000000000..05c8140f0 --- /dev/null +++ b/src/MEDPartitioner_Swig/CMakeLists.txt @@ -0,0 +1,76 @@ +# Copyright (C) 2012-2015 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, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +INCLUDE(${SWIG_USE_FILE}) + +ADD_DEFINITIONS(${PYTHON_DEFINITIONS}) + +SET_SOURCE_FILES_PROPERTIES(MEDPartitioner.i PROPERTIES CPLUSPLUS ON) +SET_SOURCE_FILES_PROPERTIES(MEDPartitioner.i PROPERTIES SWIG_DEFINITIONS "-shadow") +SET(SWIG_MODULE_MEDPartitioner_EXTRA_FLAGS "${SWIG_EXTRA_FLAGS_FOR_NUMPYANDSCIPY};-DWITHOUT_AUTOFIELD") + +SET (MEDPartitioner_SWIG_DPYS_FILES + MEDPartitionerCommon.i) + +INCLUDE_DIRECTORIES( + ${PYTHON_INCLUDE_DIRS} + ${PTHREAD_INCLUDE_DIR} # pthread dependancy due to python2.7 library + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${MEDFILE_INCLUDE_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR}/../MEDPartitioner + ${CMAKE_CURRENT_SOURCE_DIR}/../MEDCoupling_Swig + ${CMAKE_CURRENT_SOURCE_DIR}/../MEDCoupling + ${CMAKE_CURRENT_SOURCE_DIR}/../MEDLoader + ${CMAKE_CURRENT_SOURCE_DIR}/../MEDLoader/Swig + ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL + ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/Bases + ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/Geometric2D + ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/ExprEval + ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/GaussPoints + ) + +SWIG_ADD_MODULE(MEDPartitioner python MEDPartitioner.i) +SWIG_LINK_LIBRARIES(MEDPartitioner ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} medpartitionercpp) + +IF(WIN32) + SET_TARGET_PROPERTIES(_MEDPartitioner PROPERTIES DEBUG_OUTPUT_NAME _MEDPartitioner_d) +ENDIF(WIN32) +INSTALL(TARGETS ${SWIG_MODULE_MEDPartitioner_REAL_NAME} DESTINATION ${SALOME_INSTALL_PYTHON}) + +SET(PYFILES_TO_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/MEDPartitioner.py) +INSTALL_AND_COMPILE_PYTHON_FILE("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_SCRIPT_PYTHON}) + +INSTALL(FILES MEDPartitioner.i MEDPartitionerCommon.i DESTINATION ${SALOME_INSTALL_HEADERS}) +INSTALL(FILES MEDPartitionerTest.py DESTINATION ${SALOME_INSTALL_SCRIPT_PYTHON}) + +SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env) +ADD_TEST(MEDPartitionerTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MEDPartitionerTest.py) +SET_TESTS_PROPERTIES(MEDPartitionerTest PROPERTIES ENVIRONMENT "${tests_env}") + +# Application tests + +SET(TEST_INSTALL_DIRECTORY ${SALOME_INSTALL_SCRIPT_SCRIPTS}/test/MEDCoupling/MEDPartitioner_Swig) +INSTALL(FILES MEDPartitionerTest.py DESTINATION ${TEST_INSTALL_DIRECTORY}) + +INSTALL(FILES CTestTestfileInstall.cmake + DESTINATION ${TEST_INSTALL_DIRECTORY} + RENAME CTestTestfile.cmake) + + diff --git a/src/MEDPartitioner_Swig/CTestTestfileInstall.cmake b/src/MEDPartitioner_Swig/CTestTestfileInstall.cmake new file mode 100644 index 000000000..2100e6bf0 --- /dev/null +++ b/src/MEDPartitioner_Swig/CTestTestfileInstall.cmake @@ -0,0 +1,21 @@ +# Copyright (C) 2015 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, or (at your option) any later version. +# +# 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 +# + +ADD_TEST(MEDPartitionerTest python MEDPartitionerTest.py) +SET_TESTS_PROPERTIES(MEDPartitionerTest PROPERTIES LABELS "${COMPONENT_NAME}") diff --git a/src/MEDPartitioner_Swig/MEDPartitioner.i b/src/MEDPartitioner_Swig/MEDPartitioner.i new file mode 100644 index 000000000..b264da08e --- /dev/null +++ b/src/MEDPartitioner_Swig/MEDPartitioner.i @@ -0,0 +1,140 @@ +// Copyright (C) 2007-2015 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, or (at your option) any later version. +// +// 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 "MEDPartitionerCommon.i" + + +%pythoncode %{ +def ParaMEDMEMDataArrayDoublenew(cls,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayDouble____new___(cls,args) +def ParaMEDMEMDataArrayDoubleIadd(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayDouble____iadd___(self, self, *args) +def ParaMEDMEMDataArrayDoubleIsub(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayDouble____isub___(self, self, *args) +def ParaMEDMEMDataArrayDoubleImul(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayDouble____imul___(self, self, *args) +def ParaMEDMEMDataArrayDoubleIdiv(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayDouble____idiv___(self, self, *args) +def ParaMEDMEMDataArrayDoubleIpow(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayDouble____ipow___(self, self, *args) +def ParaMEDMEMDataArrayIntnew(cls,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayInt____new___(cls,args) +def ParaMEDMEMDataArrayIntIadd(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayInt____iadd___(self, self, *args) +def ParaMEDMEMDataArrayIntIsub(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayInt____isub___(self, self, *args) +def ParaMEDMEMDataArrayIntImul(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayInt____imul___(self, self, *args) +def ParaMEDMEMDataArrayIntIdiv(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayInt____idiv___(self, self, *args) +def ParaMEDMEMDataArrayIntImod(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayInt____imod___(self, self, *args) +def ParaMEDMEMDataArrayIntIpow(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayInt____ipow___(self, self, *args) +def ParaMEDMEMDataArrayDoubleTupleIadd(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayDoubleTuple____iadd___(self, self, *args) +def ParaMEDMEMDataArrayDoubleTupleIsub(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayDoubleTuple____isub___(self, self, *args) +def ParaMEDMEMDataArrayDoubleTupleImul(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayDoubleTuple____imul___(self, self, *args) +def ParaMEDMEMDataArrayDoubleTupleIdiv(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayDoubleTuple____idiv___(self, self, *args) +def ParaMEDMEMDataArrayIntTupleIadd(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayIntTuple____iadd___(self, self, *args) +def ParaMEDMEMDataArrayIntTupleIsub(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayIntTuple____isub___(self, self, *args) +def ParaMEDMEMDataArrayIntTupleImul(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayIntTuple____imul___(self, self, *args) +def ParaMEDMEMDataArrayIntTupleIdiv(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayIntTuple____idiv___(self, self, *args) +def ParaMEDMEMDataArrayIntTupleImod(self,*args): + import _MEDPartitioner + return _MEDPartitioner.DataArrayIntTuple____imod___(self, self, *args) +%} + + +%pythoncode %{ +DataArrayDouble.__new__=classmethod(ParaMEDMEMDataArrayDoublenew) +DataArrayDouble.__iadd__=ParaMEDMEMDataArrayDoubleIadd +DataArrayDouble.__isub__=ParaMEDMEMDataArrayDoubleIsub +DataArrayDouble.__imul__=ParaMEDMEMDataArrayDoubleImul +DataArrayDouble.__idiv__=ParaMEDMEMDataArrayDoubleIdiv +DataArrayDouble.__ipow__=ParaMEDMEMDataArrayDoubleIpow + +DataArrayInt.__new__=classmethod(ParaMEDMEMDataArrayIntnew) +DataArrayInt.__iadd__=ParaMEDMEMDataArrayIntIadd +DataArrayInt.__isub__=ParaMEDMEMDataArrayIntIsub +DataArrayInt.__imul__=ParaMEDMEMDataArrayIntImul +DataArrayInt.__idiv__=ParaMEDMEMDataArrayIntIdiv +DataArrayInt.__imod__=ParaMEDMEMDataArrayIntImod +DataArrayInt.__ipow__=ParaMEDMEMDataArrayIntIpow + +DataArrayDoubleTuple.__iadd__=ParaMEDMEMDataArrayDoubleTupleIadd +DataArrayDoubleTuple.__isub__=ParaMEDMEMDataArrayDoubleTupleIsub +DataArrayDoubleTuple.__imul__=ParaMEDMEMDataArrayDoubleTupleImul +DataArrayDoubleTuple.__idiv__=ParaMEDMEMDataArrayDoubleTupleIdiv + +DataArrayIntTuple.__iadd__=ParaMEDMEMDataArrayIntTupleIadd +DataArrayIntTuple.__isub__=ParaMEDMEMDataArrayIntTupleIsub +DataArrayIntTuple.__imul__=ParaMEDMEMDataArrayIntTupleImul +DataArrayIntTuple.__idiv__=ParaMEDMEMDataArrayIntTupleIdiv +DataArrayIntTuple.__imod__=ParaMEDMEMDataArrayIntTupleImod + +del ParaMEDMEMDataArrayDoublenew +del ParaMEDMEMDataArrayDoubleIadd +del ParaMEDMEMDataArrayDoubleIsub +del ParaMEDMEMDataArrayDoubleImul +del ParaMEDMEMDataArrayDoubleIdiv +del ParaMEDMEMDataArrayIntnew +del ParaMEDMEMDataArrayIntIadd +del ParaMEDMEMDataArrayIntIsub +del ParaMEDMEMDataArrayIntImul +del ParaMEDMEMDataArrayIntIdiv +del ParaMEDMEMDataArrayIntImod +del ParaMEDMEMDataArrayDoubleTupleIadd +del ParaMEDMEMDataArrayDoubleTupleIsub +del ParaMEDMEMDataArrayDoubleTupleImul +del ParaMEDMEMDataArrayDoubleTupleIdiv +del ParaMEDMEMDataArrayIntTupleIadd +del ParaMEDMEMDataArrayIntTupleIsub +del ParaMEDMEMDataArrayIntTupleImul +del ParaMEDMEMDataArrayIntTupleIdiv +del ParaMEDMEMDataArrayIntTupleImod +%} diff --git a/src/MEDPartitioner_Swig/MEDPartitionerCommon.i b/src/MEDPartitioner_Swig/MEDPartitionerCommon.i new file mode 100644 index 000000000..c7e3753f0 --- /dev/null +++ b/src/MEDPartitioner_Swig/MEDPartitionerCommon.i @@ -0,0 +1,81 @@ +// Copyright (C) 2007-2015 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, or (at your option) any later version. +// +// 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 MEDPartitioner + +%include std_vector.i +%include std_string.i + +%{ +#include "MEDCouplingAutoRefCountObjectPtr.hxx" +#include "MEDCouplingMemArray.hxx" +#include "MEDCouplingDataArrayTypemaps.i" +#include "MEDCouplingSkyLineArray.hxx" + +#include "MEDFileData.hxx" + +#include "MEDPARTITIONER_MEDPartitioner.hxx" + +#include "MEDPARTITIONER_Graph.hxx" + +using namespace ParaMEDMEM; +using namespace INTERP_KERNEL; +using namespace MEDPARTITIONER; +%} + +%template(ivec) std::vector; +%template(dvec) std::vector; +%template(svec) std::vector; + +#ifdef WITH_NUMPY +%init %{ import_array(); %} +#endif + +%feature("autodoc", "1"); +%feature("docstring"); + +%nodefaultctor; + +%newobject MEDPARTITIONER::MEDPartitioner::New; + +%rename (InterpKernelException) INTERP_KERNEL::Exception; + +%include "MEDCouplingRefCountObject.i" +%include "MEDCouplingMemArray.i" + +class MEDPartitioner +{ +public: + static MEDPartitioner *New(const std::string& filename, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception); + static MEDPartitioner *New(const ParaMEDMEM::MEDFileData* filedata, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception); + void Write(const std::string& filename) throw(INTERP_KERNEL::Exception); + ParaMEDMEM::MEDFileData* getMEDFileData() throw(INTERP_KERNEL::Exception); + MEDPARTITIONER::Graph* Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, Graph::splitter_type split, int* edgeweight=0) throw(INTERP_KERNEL::Exception); + %extend + { + MEDPartitioner(const std::string& filename, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception) + { + return MEDPartitioner::New(filename,ndomains,library,creates_boundary_faces, create_joints, mesure_memory); + } + MEDPartitioner(const ParaMEDMEM::MEDFileData* fileData, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception) + { + return MEDPartitioner::New(fileData,ndomains,library,creates_boundary_faces, create_joints, mesure_memory); + } + } +}; \ No newline at end of file diff --git a/src/MEDPartitioner_Swig/MEDPartitionerTest.py b/src/MEDPartitioner_Swig/MEDPartitionerTest.py new file mode 100644 index 000000000..a50adb6c7 --- /dev/null +++ b/src/MEDPartitioner_Swig/MEDPartitionerTest.py @@ -0,0 +1,44 @@ +# Copyright (C) 2012-2015 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, or (at your option) any later version. +# +# 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 MEDPartitioner import * +from MEDLoader import * +import unittest + +class MEDPartitionerTest(unittest.TestCase): + +# @unittest.skipUnless("BOOST" in RenumberAvailableMethods +#(),"requires BOOST prerequisite !") + def test1(self): + from MEDCoupling import MEDCouplingCMesh + #ren=RenumberingFactory("BOOST") + arr=DataArrayDouble(100) ; arr.iota() + c=MEDCouplingCMesh() ; c.setCoords(arr,arr) + m=c.buildUnstructured() + d=MEDFileData.New("/dn20/salome/imn/SALOME7YA/MED_BUILD/src/MEDLoader/Swig/splitted_blade1.med") + #mfd1 = MEDFileData.New() + p=MEDPartitioner.New(d,2); + #p=MEDPartitioner.New("/dn20/salome/imn/SALOME7YA/MED_BUILD/src/MEDLoader/Swig/splitted_blade1.med"); + #part=MEDPartitioner.Graph(m.generateGraph()) + #part.partGraph(2) + #a=part.getGraph() + #n2o,o2n=ren.renumber(a,b) + pass + +unittest.main() -- 2.39.2