From 727a21093f2d75af3be01c08dfc5236bdd638442 Mon Sep 17 00:00:00 2001 From: eap Date: Mon, 25 May 2015 20:10:13 +0300 Subject: [PATCH] 0022875: conversion ConnectZone -> MedFileJoints implemented --- src/MEDLoader/MEDFileMesh.cxx | 41 ++++- src/MEDLoader/MEDFileMesh.hxx | 8 +- .../MEDPARTITIONER_ConnectZone.cxx | 14 ++ .../MEDPARTITIONER_ConnectZone.hxx | 3 + .../MEDPARTITIONER_MeshCollectionDriver.cxx | 155 ++++++++++++------ .../MEDPARTITIONER_MeshCollectionDriver.hxx | 5 +- 6 files changed, 166 insertions(+), 60 deletions(-) diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index cecf69996..b3dc94e17 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -2310,16 +2310,19 @@ int MEDFileMesh::getNumberOfJoints() /*! * \brief Return joints with all adjacent mesh domains */ -MEDFileJoints * MEDFileMesh::getJoints() +MEDFileJoints * MEDFileMesh::getJoints() const { - return _joints; + return (MEDFileJoints*) & (*_joints); } void MEDFileMesh::setJoints( MEDFileJoints* joints ) { - _joints = joints; - if ( joints ) - joints->incrRef(); + if ( joints != _joints ) + { + _joints = joints; + if ( joints ) + joints->incrRef(); + } } /*! @@ -6051,13 +6054,41 @@ void MEDFileMeshMultiTS::setOneTimeStep(MEDFileMesh *mesh1TimeStep) _mesh_one_ts[0]=mesh1TimeStep; } +MEDFileJoints * MEDFileMeshMultiTS::getJoints() const +{ + if ( MEDFileMesh* m = getOneTimeStep() ) + return m->getJoints(); + return 0; +} + +/*! + * \brief Set Joints that are common to all time-stamps + */ +void MEDFileMeshMultiTS::setJoints( MEDFileJoints* joints ) +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++) + { + (*it)->setJoints( joints ); + } +} + void MEDFileMeshMultiTS::write(med_idt fid) const { + MEDFileJoints * joints = getJoints(); + bool jointsWritten = false; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++) { + if ( jointsWritten ) + const_cast(**it).setJoints( 0 ); + else + jointsWritten = true; + (*it)->copyOptionsFrom(*this); (*it)->write(fid); } + + ((MEDFileMeshMultiTS*)this)->setJoints( joints ); // restore joints } void MEDFileMeshMultiTS::write(const std::string& fileName, int mode) const diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index cc36815f1..59ffc9695 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -162,9 +162,9 @@ namespace ParaMEDMEM MEDLOADER_EXPORT virtual DataArrayInt *getNodeFamiliesArr(const std::vector& fams, bool renum=false) const; // tools MEDLOADER_EXPORT virtual bool unPolyze(std::vector& oldCode, std::vector& newCode, DataArrayInt *& o2nRenumCell) = 0; - MEDLOADER_EXPORT int getNumberOfJoints(); - MEDLOADER_EXPORT MEDFileJoints *getJoints(); - MEDLOADER_EXPORT void setJoints( MEDFileJoints* joints ); + MEDLOADER_EXPORT int getNumberOfJoints(); + MEDLOADER_EXPORT MEDFileJoints *getJoints() const; + MEDLOADER_EXPORT void setJoints( MEDFileJoints* joints ); protected: MEDFileMesh(); //! protected because no way in MED file API to specify this name @@ -468,6 +468,8 @@ namespace ParaMEDMEM MEDLOADER_EXPORT void write(med_idt fid) const; MEDLOADER_EXPORT void write(const std::string& fileName, int mode) const; MEDLOADER_EXPORT void setOneTimeStep(MEDFileMesh *mesh1TimeStep); + MEDLOADER_EXPORT MEDFileJoints *getJoints() const; + MEDLOADER_EXPORT void setJoints( MEDFileJoints* joints ); private: ~MEDFileMeshMultiTS() { } void loadFromFile(const std::string& fileName, const std::string& mName); diff --git a/src/MEDPartitioner/MEDPARTITIONER_ConnectZone.cxx b/src/MEDPartitioner/MEDPARTITIONER_ConnectZone.cxx index 3726e0a1e..78fd1a0f4 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_ConnectZone.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_ConnectZone.cxx @@ -200,6 +200,20 @@ MEDPARTITIONER::ConnectZone::getEntityCorresp(int localEntity, int distantEntity return 0; } +std::vector< std::pair< int,int > > MEDPARTITIONER::ConnectZone::getEntities() const +{ + std::vector< std::pair< int,int > > types; + + std::map, MEDCouplingSkyLineArray*>::const_iterator + iter = _entity_corresp.begin(); + for ( ; iter != _entity_corresp.end(); iter++) + { + types.push_back( iter->first ); + } + + return types; +} + void MEDPARTITIONER::ConnectZone::setName(const std::string& name) { _name=name; diff --git a/src/MEDPartitioner/MEDPARTITIONER_ConnectZone.hxx b/src/MEDPartitioner/MEDPARTITIONER_ConnectZone.hxx index d943e7df5..8c1626dfd 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_ConnectZone.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_ConnectZone.hxx @@ -25,6 +25,7 @@ #include "MEDCouplingSkyLineArray.hxx" #include +#include #include namespace MEDPARTITIONER @@ -62,6 +63,8 @@ namespace MEDPARTITIONER int distantEntity) const; const ParaMEDMEM::MEDCouplingSkyLineArray * getEntityCorresp(int localEntity, int distantEntity) const; + std::vector< std::pair< int,int > > getEntities() const; + void setName(const std::string& name) ; void setDescription(const std::string& description) ; void setDistantDomainNumber(int distantDomainNumber) ; diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx index e440100f2..b8f01a26c 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx @@ -17,17 +17,21 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#include "MEDPARTITIONER_ParallelTopology.hxx" #include "MEDPARTITIONER_MeshCollectionDriver.hxx" + +#include "MEDPARTITIONER_ConnectZone.hxx" #include "MEDPARTITIONER_MeshCollection.hxx" #include "MEDPARTITIONER_ParaDomainSelector.hxx" +#include "MEDPARTITIONER_ParallelTopology.hxx" #include "MEDPARTITIONER_Utils.hxx" -#include "MEDCouplingUMesh.hxx" #include "MEDCouplingFieldDouble.hxx" -#include "MEDLoader.hxx" -#include "MEDFileMesh.hxx" +#include "MEDCouplingRefCountObject.hxx" +#include "MEDCouplingUMesh.hxx" +#include "MEDFileField.hxx" #include "MEDFileJoint.hxx" +#include "MEDFileMesh.hxx" +#include "MEDLoader.hxx" #include #include @@ -185,9 +189,11 @@ void MeshCollectionDriver::readSubdomain(int idomain) if (localFields.size()>0) MyGlobals::_Field_Descriptions.push_back(SerializeFromVectorOfString(localFields)); } -std::vector MeshCollectionDriver::getMeshes(int idomain) const + +ParaMEDMEM::MEDFileMesh* MeshCollectionDriver::getMesh(int idomain) const { - std::vector meshes; + ParaMEDMEM::MEDFileUMesh* mfm = ParaMEDMEM::MEDFileUMesh::New(); + ParaMEDMEM::MEDCouplingUMesh* cellMesh=_collection->getMesh(idomain); ParaMEDMEM::MEDCouplingUMesh* faceMesh=_collection->getFaceMesh(idomain); std::string finalMeshName=ExtractFromDescription(MyGlobals::_General_Informations[0], "finalMeshName="); @@ -203,14 +209,15 @@ std::vector MeshCollectionDriver::getMeshes // if (faceMeshFilter!=0) // faceMeshFilter->decrRef(); cellMesh->setName(finalMeshName); - meshes.push_back(cellMesh); + mfm->setMeshAtLevel( 0, cellMesh ); faceMesh->checkCoherency(); if (faceMesh->getNumberOfCells()>0) { faceMesh->tryToShareSameCoordsPermute(*cellMesh, 1e-10); - meshes.push_back(faceMesh); + mfm->setMeshAtLevel( -1, cellMesh ); } + // ParaMEDMEM::MEDCouplingUMesh* boundaryMesh=0; // if (MyGlobals::_Creates_Boundary_Faces>0) // { @@ -224,15 +231,11 @@ std::vector MeshCollectionDriver::getMeshes // MEDLoader::WriteUMesh(distfilename, boundaryMesh, false); // boundaryMesh->decrRef(); // } - return meshes; -} -void MeshCollectionDriver::setFileUMesh(ParaMEDMEM::MEDFileUMesh* mfm,int size, int idomain) const -{ + mfm->setFamilyInfo(_collection->getFamilyInfo()); mfm->setGroupInfo(_collection->getGroupInfo()); std::string key=Cle1ToStr("faceFamily_toArray",idomain); - if ( size == 2 && - _collection->getMapDataArrayInt().find(key)!=_collection->getMapDataArrayInt().end()) + if ( _collection->getMapDataArrayInt().find(key)!=_collection->getMapDataArrayInt().end()) { ParaMEDMEM::DataArrayInt *fam=_collection->getMapDataArrayInt().find(key)->second; mfm->setFamilyFieldArr(-1,fam); @@ -240,8 +243,64 @@ void MeshCollectionDriver::setFileUMesh(ParaMEDMEM::MEDFileUMesh* mfm,int size, key=Cle1ToStr("cellFamily_toArray",idomain); if (_collection->getMapDataArrayInt().find(key)!=_collection->getMapDataArrayInt().end()) mfm->setFamilyFieldArr(0,_collection->getMapDataArrayInt().find(key)->second); + + // add joints + + using ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr; + using ParaMEDMEM::MEDCouplingSkyLineArray; + using ParaMEDMEM::MEDFileJoint; + using ParaMEDMEM::MEDFileJointCorrespondence; + using ParaMEDMEM::MEDFileJointOneStep; + using ParaMEDMEM::MEDFileJoints; + using ParaMEDMEM::MEDFileJoints; + + if ( _collection->getCZ().size() > 0 ) + { + MEDCouplingAutoRefCountObjectPtr< MEDFileJoints > joints = MEDFileJoints::New(); + + for ( size_t i = 0; i < _collection->getCZ().size(); ++i ) + { + ConnectZone* cz = _collection->getCZ()[i]; + if ( !cz ) continue; + + MEDCouplingAutoRefCountObjectPtr< MEDFileJoint> + joint = MEDFileJoint::New( cz->getName(), finalMeshName, + finalMeshName, cz->getDistantDomainNumber() ); + joint->setDescription( cz->getDescription() ); + joints->pushJoint( joint ); + + MEDCouplingAutoRefCountObjectPtr< MEDFileJointOneStep> j1st = MEDFileJointOneStep::New(); + joint->pushStep( j1st ); + + const MEDCouplingSkyLineArray * nodeCorr = cz->getNodeCorresp(); + if ( nodeCorr ) + { + MEDCouplingAutoRefCountObjectPtr< MEDFileJointCorrespondence > + corr = MEDFileJointCorrespondence::New( nodeCorr->getValueArray() ); + j1st->pushCorrespondence( corr ); + } + + std::vector< std::pair< int,int > > types = cz->getEntities(); + INTERP_KERNEL::NormalizedCellType t1, t2; + for ( size_t it = 0; it < types.size(); ++it ) + { + const MEDCouplingSkyLineArray * cellCorr = + cz->getEntityCorresp( types[it].first, types[it].second ); + if ( cellCorr ) + { + t1 = INTERP_KERNEL::NormalizedCellType( types[it].first ); + t2 = INTERP_KERNEL::NormalizedCellType( types[it].second ); + MEDCouplingAutoRefCountObjectPtr< MEDFileJointCorrespondence> + corr = MEDFileJointCorrespondence::New( cellCorr->getValueArray(), t1, t2 ); + j1st->pushCorrespondence( corr ); + } + } + } + mfm->setJoints( joints ); + } } -ParaMEDMEM::MEDCouplingFieldDouble* MeshCollectionDriver::getField(std::string key, std::string description, ParaMEDMEM::DataArrayDouble* data, ParaMEDMEM::MEDFileUMesh* mfm, int idomain) const + +ParaMEDMEM::MEDCouplingFieldDouble* MeshCollectionDriver::getField(std::string key, std::string description, ParaMEDMEM::DataArrayDouble* data, ParaMEDMEM::MEDFileMesh* mfm, int idomain) const { std::string desc=description; if (MyGlobals::_Verbose>20) @@ -274,7 +333,7 @@ ParaMEDMEM::MEDCouplingFieldDouble* MeshCollectionDriver::getField(std::string k if (field && typeData==6) { field->setName(fieldName); - field->setMesh(mfm->getLevel0Mesh(false)); + field->setMesh(mfm->getGenMeshAtLevel(0)); ParaMEDMEM::DataArrayDouble *da=data; //get information for components etc.. std::vector r1; @@ -299,16 +358,12 @@ ParaMEDMEM::MEDCouplingFieldDouble* MeshCollectionDriver::getField(std::string k } return field; } + void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfilename) const { - std::vector meshes; - meshes=getMeshes(idomain); - MEDLoader::WriteUMeshes(distfilename, meshes, true); - - ParaMEDMEM::MEDFileUMesh* mfm=ParaMEDMEM::MEDFileUMesh::New(distfilename, _collection->getMesh(idomain)->getName()); - setFileUMesh(mfm,meshes.size(),idomain); - + ParaMEDMEM::MEDFileMesh* mfm = getMesh( idomain ); mfm->write(distfilename,0); + std::string key="/inewFieldDouble="+IntToStr(idomain)+"/"; std::map::iterator it; int nbfFieldFound=0; @@ -317,9 +372,9 @@ void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfile size_t found=(*it).first.find(key); if (found==std::string::npos) continue; - ParaMEDMEM::MEDCouplingFieldDouble* field=0; - field=getField(key, (*it).first, (*it).second, mfm, idomain); - nbfFieldFound++; + ParaMEDMEM::MEDCouplingFieldDouble* field=0; + field = getField(key, (*it).first, (*it).second, mfm, idomain); + nbfFieldFound++; try { MEDLoader::WriteField(distfilename,field,false); @@ -341,34 +396,36 @@ void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfile ParaMEDMEM::MEDFileData* MeshCollectionDriver::getMEDFileData() { - ParaMEDMEM::MEDFileData* newdata=ParaMEDMEM::MEDFileData::New(); - ParaMEDMEM::MEDFileMeshes* meshes(ParaMEDMEM::MEDFileMeshes::New()); - ParaMEDMEM::MEDFileFields* fields(ParaMEDMEM::MEDFileFields::New()); + ParaMEDMEM::MEDFileData* newdata = ParaMEDMEM::MEDFileData::New(); + ParaMEDMEM::MEDFileMeshes* meshes = ParaMEDMEM::MEDFileMeshes::New(); + ParaMEDMEM::MEDFileFields* fields = ParaMEDMEM::MEDFileFields::New(); for (int i=0; i<(_collection->getMesh()).size(); i++) - { - ParaMEDMEM::MEDFileUMesh* m(ParaMEDMEM::MEDFileUMesh::New()); - m->setMeshes(getMeshes(i),true); - meshes->pushMesh(m); - ParaMEDMEM::MEDFileUMesh *mfm = ParaMEDMEM::MEDFileUMesh::New(); - setFileUMesh(mfm,(_collection->getMesh()).size(),i); - meshes->pushMesh(mfm); - std::string key="/inewFieldDouble="+IntToStr(i)+"/"; - std::map::iterator it; - ParaMEDMEM::MEDFileAnyTypeFieldMultiTS* fieldsMTS; - for (it=_collection->getMapDataArrayDouble().begin() ; it!=_collection->getMapDataArrayDouble().end(); it++) { - size_t found=(*it).first.find(key); - if (found==std::string::npos) - continue; + ParaMEDMEM::MEDFileMesh* mfm = getMesh( i ); + meshes->pushMesh(mfm); + + std::string key="/inewFieldDouble="+IntToStr(i)+"/"; + std::map::iterator it; + ParaMEDMEM::MEDFileFieldMultiTS* fieldsMTS = ParaMEDMEM::MEDFileFieldMultiTS::New(); + for (it=_collection->getMapDataArrayDouble().begin() ; it!=_collection->getMapDataArrayDouble().end(); it++) + { + size_t found=(*it).first.find(key); + if (found==std::string::npos) + continue; ParaMEDMEM::MEDCouplingFieldDouble* field=0; field=getField(key, (*it).first, (*it).second, mfm, i); - ParaMEDMEM::MEDFileField1TS* f1ts(ParaMEDMEM::MEDFileField1TS::New()); - f1ts->setFieldNoProfileSBT(field); - fieldsMTS->pushBackTimeStep(f1ts); + ParaMEDMEM::MEDFileField1TS* f1ts = ParaMEDMEM::MEDFileField1TS::New(); + f1ts->setFieldNoProfileSBT(field); + fieldsMTS->pushBackTimeStep(f1ts); + + field->decrRef(); + f1ts->decrRef(); + } + fields->pushField(fieldsMTS); + + fieldsMTS->decrRef(); + mfm->decrRef(); } - fields->pushField(fieldsMTS); - mfm->decrRef(); - } newdata->setMeshes(meshes); newdata->setFields(fields); return newdata; diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.hxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.hxx index 701e6946c..d179d17ac 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.hxx @@ -49,9 +49,8 @@ namespace MEDPARTITIONER void readSubdomain(int idomain); void readData(ParaMEDMEM::MEDFileUMesh* mfm, int idomain) const; void readFileData(std::string file,std::string meshname,int idomain) const; - std::vector getMeshes(int idomain) const; - ParaMEDMEM::MEDCouplingFieldDouble* getField(std::string key, std::string description, ParaMEDMEM::DataArrayDouble* data, ParaMEDMEM::MEDFileUMesh* mfm, int idomain) const; - void setFileUMesh(ParaMEDMEM::MEDFileUMesh* mfm,int size, int idomain) const; + ParaMEDMEM::MEDFileMesh* getMesh(int idomain) const; + ParaMEDMEM::MEDCouplingFieldDouble* getField(std::string key, std::string description, ParaMEDMEM::DataArrayDouble* data, ParaMEDMEM::MEDFileMesh* mfm, int idomain) const; void writeMedFile(int idomain, const std::string& distfilename) const; protected: MeshCollection* _collection; -- 2.39.2