From b96d5cf71c1fd2ab772cec0d5e800a824b488a92 Mon Sep 17 00:00:00 2001 From: ageay Date: Wed, 7 Aug 2013 15:29:52 +0000 Subject: [PATCH] Corba exchange of MEDCoupling1GTMesh --- src/MEDCoupling/MEDCoupling1GTUMesh.cxx | 199 ++++++++++++++++++ src/MEDCoupling/MEDCoupling1GTUMesh.hxx | 12 ++ src/MEDCoupling/MEDCouplingMemArray.cxx | 2 +- .../MEDCouplingMeshFieldFactoryComponent.cxx | 4 +- .../MEDCouplingCorbaSwigTest.py | 4 +- 5 files changed, 216 insertions(+), 5 deletions(-) diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx index 02d38fd91..c882ea914 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx @@ -1368,6 +1368,94 @@ bool MEDCoupling1SGTUMesh::isEmptyMesh(const std::vector& tinyInfo) const throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::isEmptyMesh : not implemented yet !"); } +void MEDCoupling1SGTUMesh::getTinySerializationInformation(std::vector& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const +{ + int it,order; + double time=getTime(it,order); + tinyInfo.clear(); tinyInfoD.clear(); littleStrings.clear(); + // + littleStrings.push_back(getName()); + littleStrings.push_back(getDescription()); + littleStrings.push_back(getTimeUnit()); + // + std::vector littleStrings2,littleStrings3; + if((const DataArrayDouble *)_coords) + _coords->getTinySerializationStrInformation(littleStrings2); + if((const DataArrayInt *)_conn) + _conn->getTinySerializationStrInformation(littleStrings3); + int sz0((int)littleStrings2.size()),sz1((int)littleStrings3.size()); + littleStrings.insert(littleStrings.end(),littleStrings2.begin(),littleStrings2.end()); + littleStrings.insert(littleStrings.end(),littleStrings3.begin(),littleStrings3.end()); + // + tinyInfo.push_back(getCellModelEnum()); + tinyInfo.push_back(it); + tinyInfo.push_back(order); + std::vector tinyInfo2,tinyInfo3; + if((const DataArrayDouble *)_coords) + _coords->getTinySerializationIntInformation(tinyInfo2); + if((const DataArrayInt *)_conn) + _conn->getTinySerializationIntInformation(tinyInfo3); + int sz2((int)tinyInfo2.size()),sz3((int)tinyInfo3.size()); + tinyInfo.push_back(sz0); tinyInfo.push_back(sz1); tinyInfo.push_back(sz2); tinyInfo.push_back(sz3); + tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end()); + tinyInfo.insert(tinyInfo.end(),tinyInfo3.begin(),tinyInfo3.end()); + // + tinyInfoD.push_back(time); +} + +void MEDCoupling1SGTUMesh::resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const +{ + std::vector tinyInfo2(tinyInfo.begin()+7,tinyInfo.begin()+7+tinyInfo[5]); + std::vector tinyInfo1(tinyInfo.begin()+7+tinyInfo[5],tinyInfo.begin()+7+tinyInfo[5]+tinyInfo[6]); + a1->resizeForUnserialization(tinyInfo1); + a2->resizeForUnserialization(tinyInfo2); +} + +void MEDCoupling1SGTUMesh::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const +{ + int sz(0); + if((const DataArrayInt *)_conn) + if(_conn->isAllocated()) + sz=_conn->getNbOfElems(); + a1=DataArrayInt::New(); + a1->alloc(sz,1); + if(sz!=0 && (const DataArrayInt *)_conn) + std::copy(_conn->begin(),_conn->end(),a1->getPointer()); + sz=0; + if((const DataArrayDouble *)_coords) + if(_coords->isAllocated()) + sz=_coords->getNbOfElems(); + a2=DataArrayDouble::New(); + a2->alloc(sz,1); + if(sz!=0 && (const DataArrayDouble *)_coords) + std::copy(_coords->begin(),_coords->end(),a2->getPointer()); +} + +void MEDCoupling1SGTUMesh::unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, + const std::vector& littleStrings) +{ + INTERP_KERNEL::NormalizedCellType gt((INTERP_KERNEL::NormalizedCellType)tinyInfo[0]); + _cm=&INTERP_KERNEL::CellModel::GetCellModel(gt); + setName(littleStrings[0].c_str()); + setDescription(littleStrings[1].c_str()); + setTimeUnit(littleStrings[2].c_str()); + setTime(tinyInfoD[0],tinyInfo[1],tinyInfo[2]); + int sz0(tinyInfo[3]),sz1(tinyInfo[4]),sz2(tinyInfo[5]),sz3(tinyInfo[6]); + // + _coords=DataArrayDouble::New(); + std::vector tinyInfo2(tinyInfo.begin()+7,tinyInfo.begin()+7+sz2); + _coords->resizeForUnserialization(tinyInfo2); + std::copy(a2->begin(),a2->end(),_coords->getPointer()); + _conn=DataArrayInt::New(); + std::vector tinyInfo3(tinyInfo.begin()+7+sz2,tinyInfo.begin()+7+sz2+sz3); + _conn->resizeForUnserialization(tinyInfo3); + std::copy(a1->begin(),a1->end(),_conn->getPointer()); + std::vector littleStrings2(littleStrings.begin()+3,littleStrings.begin()+3+sz0); + _coords->finishUnserialization(tinyInfo2,littleStrings2); + std::vector littleStrings3(littleStrings.begin()+3+sz0,littleStrings.begin()+3+sz0+sz1); + _conn->finishUnserialization(tinyInfo3,littleStrings3); +} + /*! * Checks if \a this and \a other meshes are geometrically equivalent with high * probability, else an exception is thrown. The meshes are considered equivalent if @@ -2500,6 +2588,117 @@ bool MEDCoupling1DGTUMesh::isEmptyMesh(const std::vector& tinyInfo) const throw INTERP_KERNEL::Exception("MEDCoupling1DGTUMesh::isEmptyMesh : not implemented yet !"); } +void MEDCoupling1DGTUMesh::getTinySerializationInformation(std::vector& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const +{ + int it,order; + double time=getTime(it,order); + tinyInfo.clear(); tinyInfoD.clear(); littleStrings.clear(); + // + littleStrings.push_back(getName()); + littleStrings.push_back(getDescription()); + littleStrings.push_back(getTimeUnit()); + // + std::vector littleStrings2,littleStrings3,littleStrings4; + if((const DataArrayDouble *)_coords) + _coords->getTinySerializationStrInformation(littleStrings2); + if((const DataArrayInt *)_conn) + _conn->getTinySerializationStrInformation(littleStrings3); + if((const DataArrayInt *)_conn_indx) + _conn_indx->getTinySerializationStrInformation(littleStrings4); + int sz0((int)littleStrings2.size()),sz1((int)littleStrings3.size()),sz2((int)littleStrings4.size()); + littleStrings.insert(littleStrings.end(),littleStrings2.begin(),littleStrings2.end()); + littleStrings.insert(littleStrings.end(),littleStrings3.begin(),littleStrings3.end()); + littleStrings.insert(littleStrings.end(),littleStrings4.begin(),littleStrings4.end()); + // + tinyInfo.push_back(getCellModelEnum()); + tinyInfo.push_back(it); + tinyInfo.push_back(order); + std::vector tinyInfo2,tinyInfo3,tinyInfo4; + if((const DataArrayDouble *)_coords) + _coords->getTinySerializationIntInformation(tinyInfo2); + if((const DataArrayInt *)_conn) + _conn->getTinySerializationIntInformation(tinyInfo3); + if((const DataArrayInt *)_conn_indx) + _conn_indx->getTinySerializationIntInformation(tinyInfo4); + int sz3((int)tinyInfo2.size()),sz4((int)tinyInfo3.size()),sz5((int)tinyInfo4.size()); + tinyInfo.push_back(sz0); tinyInfo.push_back(sz1); tinyInfo.push_back(sz2); tinyInfo.push_back(sz3); tinyInfo.push_back(sz4); tinyInfo.push_back(sz5); + tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end()); + tinyInfo.insert(tinyInfo.end(),tinyInfo3.begin(),tinyInfo3.end()); + tinyInfo.insert(tinyInfo.end(),tinyInfo4.begin(),tinyInfo4.end()); + // + tinyInfoD.push_back(time); +} + +void MEDCoupling1DGTUMesh::resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const +{ + std::vector tinyInfo2(tinyInfo.begin()+9,tinyInfo.begin()+9+tinyInfo[6]); + std::vector tinyInfo1(tinyInfo.begin()+9+tinyInfo[6],tinyInfo.begin()+9+tinyInfo[6]+tinyInfo[7]); + std::vector tinyInfo12(tinyInfo.begin()+9+tinyInfo[6]+tinyInfo[7],tinyInfo.begin()+9+tinyInfo[6]+tinyInfo[7]+tinyInfo[8]); + MEDCouplingAutoRefCountObjectPtr p1(DataArrayInt::New()); p1->resizeForUnserialization(tinyInfo1); + MEDCouplingAutoRefCountObjectPtr p2(DataArrayInt::New()); p2->resizeForUnserialization(tinyInfo12); + std::vector v(2); v[0]=p1; v[1]=p2; + p2=DataArrayInt::Aggregate(v); + a2->resizeForUnserialization(tinyInfo2); + a1->alloc(p2->getNbOfElems(),1); +} + +void MEDCoupling1DGTUMesh::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const +{ + int sz(0); + if((const DataArrayInt *)_conn) + if(_conn->isAllocated()) + sz=_conn->getNbOfElems(); + if((const DataArrayInt *)_conn_indx) + if(_conn_indx->isAllocated()) + sz+=_conn_indx->getNbOfElems(); + a1=DataArrayInt::New(); + a1->alloc(sz,1); + int *work(a1->getPointer()); + if(sz!=0 && (const DataArrayInt *)_conn) + work=std::copy(_conn->begin(),_conn->end(),a1->getPointer()); + if(sz!=0 && (const DataArrayInt *)_conn_indx) + std::copy(_conn_indx->begin(),_conn_indx->end(),work); + sz=0; + if((const DataArrayDouble *)_coords) + if(_coords->isAllocated()) + sz=_coords->getNbOfElems(); + a2=DataArrayDouble::New(); + a2->alloc(sz,1); + if(sz!=0 && (const DataArrayDouble *)_coords) + std::copy(_coords->begin(),_coords->end(),a2->getPointer()); +} + +void MEDCoupling1DGTUMesh::unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, + const std::vector& littleStrings) +{ + INTERP_KERNEL::NormalizedCellType gt((INTERP_KERNEL::NormalizedCellType)tinyInfo[0]); + _cm=&INTERP_KERNEL::CellModel::GetCellModel(gt); + setName(littleStrings[0].c_str()); + setDescription(littleStrings[1].c_str()); + setTimeUnit(littleStrings[2].c_str()); + setTime(tinyInfoD[0],tinyInfo[1],tinyInfo[2]); + int sz0(tinyInfo[3]),sz1(tinyInfo[4]),sz2(tinyInfo[5]),sz3(tinyInfo[6]),sz4(tinyInfo[7]),sz5(tinyInfo[8]); + // + _coords=DataArrayDouble::New(); + std::vector tinyInfo2(tinyInfo.begin()+9,tinyInfo.begin()+9+sz3); + _coords->resizeForUnserialization(tinyInfo2); + std::copy(a2->begin(),a2->end(),_coords->getPointer()); + _conn=DataArrayInt::New(); + std::vector tinyInfo3(tinyInfo.begin()+9+sz3,tinyInfo.begin()+9+sz3+sz4); + _conn->resizeForUnserialization(tinyInfo3); + std::copy(a1->begin(),a1->begin()+_conn->getNbOfElems(),_conn->getPointer()); + _conn_indx=DataArrayInt::New(); + std::vector tinyInfo4(tinyInfo.begin()+9+sz3+sz4,tinyInfo.begin()+9+sz3+sz4+sz5); + _conn_indx->resizeForUnserialization(tinyInfo4); + std::copy(a1->begin()+_conn->getNbOfElems(),a1->end(),_conn_indx->getPointer()); + std::vector littleStrings2(littleStrings.begin()+3,littleStrings.begin()+3+sz0); + _coords->finishUnserialization(tinyInfo2,littleStrings2); + std::vector littleStrings3(littleStrings.begin()+3+sz0,littleStrings.begin()+3+sz0+sz1); + _conn->finishUnserialization(tinyInfo3,littleStrings3); + std::vector littleStrings4(littleStrings.begin()+3+sz0+sz1,littleStrings.begin()+3+sz0+sz1+sz2); + _conn_indx->finishUnserialization(tinyInfo4,littleStrings4); +} + /*! * Finds nodes not used in any cell and returns an array giving a new id to every node * by excluding the unused nodes, for which the array holds -1. The result array is diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx index 8a8cb16d4..4725da20f 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx @@ -142,6 +142,12 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT static MEDCoupling1SGTUMesh *Merge1SGTUMeshesOnSameCoords(std::vector& a) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT MEDCoupling1SGTUMesh *buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT MEDCoupling1GTUMesh *computeDualMesh() const throw(INTERP_KERNEL::Exception); + public://serialization + MEDCOUPLING_EXPORT void getTinySerializationInformation(std::vector& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const; + MEDCOUPLING_EXPORT void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const; + MEDCOUPLING_EXPORT void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const; + MEDCOUPLING_EXPORT void unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, + const std::vector& littleStrings); private: MEDCoupling1SGTUMesh(const char *name, const INTERP_KERNEL::CellModel& cm); MEDCoupling1SGTUMesh(const MEDCoupling1SGTUMesh& other, bool recDeepCpy); @@ -223,6 +229,12 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT static DataArrayInt *AggregateNodalConnAndShiftNodeIds(const std::vector& nodalConns, const std::vector& offsetInNodeIdsPerElt) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static std::vector BuildAPolygonFromParts(const std::vector< std::vector >& parts) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT MEDCoupling1DGTUMesh *buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception); + public://serialization + MEDCOUPLING_EXPORT void getTinySerializationInformation(std::vector& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const; + MEDCOUPLING_EXPORT void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const; + MEDCOUPLING_EXPORT void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const; + MEDCOUPLING_EXPORT void unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, + const std::vector& littleStrings); private: MEDCoupling1DGTUMesh(const char *name, const INTERP_KERNEL::CellModel& cm); MEDCoupling1DGTUMesh(const MEDCoupling1DGTUMesh& other, bool recDeepCpy); diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index adc2f0b1c..43c1d4866 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -10797,7 +10797,7 @@ void DataArrayInt::finishUnserialization(const std::vector& tinyInfoI, cons setName(tinyInfoS[0].c_str()); if(isAllocated()) { - int nbOfCompo=getNumberOfComponents(); + int nbOfCompo=tinyInfoI[1]; for(int i=0;isetTime(2.3,4,5); + targetMesh->setTime(2.3,44,-55); targetMesh->setTimeUnit("us"); targetMesh->setDescription("My Description of 1SGTU"); ParaMEDMEM::DataArrayDouble *a1=ParaMEDMEM::DataArrayDouble::New(); a1->alloc(10,3); a1->setInfoOnComponent(0,"X1 [m]"); a1->setInfoOnComponent(1,"YY2 [km]"); a1->setInfoOnComponent(2,"ZZZ3 [km]"); @@ -262,7 +262,7 @@ namespace SALOME_TEST ParaMEDMEM::MEDCoupling1DGTUMesh *MEDCouplingCorbaServBasicsTest::build1DGTUMesh() { ParaMEDMEM::MEDCoupling1DGTUMesh *targetMesh=ParaMEDMEM::MEDCoupling1DGTUMesh::New("Mesh1DGT",INTERP_KERNEL::NORM_POLYGON); - targetMesh->setTime(2.3,4,5); + targetMesh->setTime(2.3,55,-66); targetMesh->setTimeUnit("us"); targetMesh->setDescription("My Description of 1DGTU"); ParaMEDMEM::DataArrayDouble *a1=ParaMEDMEM::DataArrayDouble::New(); a1->alloc(10,3); a1->setInfoOnComponent(0,"X1 [m]"); a1->setInfoOnComponent(1,"YY2 [km]"); a1->setInfoOnComponent(2,"ZZZ3 [km]"); diff --git a/src/MEDCouplingCorba_Swig/MEDCouplingCorbaSwigTest.py b/src/MEDCouplingCorba_Swig/MEDCouplingCorbaSwigTest.py index d42e5f46c..a8dd95ab5 100644 --- a/src/MEDCouplingCorba_Swig/MEDCouplingCorbaSwigTest.py +++ b/src/MEDCouplingCorba_Swig/MEDCouplingCorbaSwigTest.py @@ -192,7 +192,7 @@ class MEDCouplingCorbaServBasicsTest: def build1SGTUMesh(self): targetMesh=MEDCoupling1SGTUMesh("Mesh1SGT",NORM_QUAD4) - targetMesh.setTime(2.3,4,5) + targetMesh.setTime(2.3,44,-55) targetMesh.setTimeUnit("us") targetMesh.setDescription("My Description of 1SGTU"); a1=DataArrayDouble([1.,1.,0.,2.,1.,0.,3.,1.,0.,1.,0.,0.,2.,0.,0.,0.,0.,0.,0.,1.,0.,3.,0.,0.,4.,0.,0.,4.,1.,0.],10,3) @@ -207,7 +207,7 @@ class MEDCouplingCorbaServBasicsTest: def build1DGTUMesh(self): targetMesh=MEDCoupling1DGTUMesh("Mesh1DGT",NORM_POLYGON); - targetMesh.setTime(2.3,4,5) + targetMesh.setTime(2.3,55,-66) targetMesh.setTimeUnit("us") targetMesh.setDescription("My Description of 1DGTU"); a1=DataArrayDouble([1.,1.,0.,2.,1.,0.,3.,1.,0.,1.,0.,0.,2.,0.,0.,0.,0.,0.,0.,1.,0.,3.,0.,0.,4.,0.,0.,4.,1.,0.],10,3) -- 2.39.2