From: geay Date: Thu, 19 Jun 2014 09:50:15 +0000 (+0200) Subject: More check in MEDCouplingRemapper to help aggressive users of transferField, transfer... X-Git-Tag: V7_5_0a1~37^2~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=12627ebf1c9b699cdb7a88703967b368765692c2;p=modules%2Fmed.git More check in MEDCouplingRemapper to help aggressive users of transferField, transfer, reverseTransfer and reverseTransferField with invalid input fields regarding the input on prepare. --- diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx index 07a9d3b57..d4bd0aadd 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx @@ -251,6 +251,11 @@ std::string MEDCoupling1GTUMesh::getVTKDataSetType() const return std::string("UnstructuredGrid"); } +std::string MEDCoupling1GTUMesh::getVTKFileExtension() const +{ + return std::string("vtu"); +} + std::size_t MEDCoupling1GTUMesh::getHeapMemorySizeWithoutChildren() const { return MEDCouplingPointSet::getHeapMemorySizeWithoutChildren(); diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx index 55c85d39a..674d9bcf4 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx @@ -49,6 +49,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *checkTypeConsistencyAndContig(const std::vector& code, const std::vector& idsPerType) const; MEDCOUPLING_EXPORT void writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const; MEDCOUPLING_EXPORT std::string getVTKDataSetType() const; + MEDCOUPLING_EXPORT std::string getVTKFileExtension() const; // MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; MEDCOUPLING_EXPORT int getNodalConnectivityLength() const; diff --git a/src/MEDCoupling/MEDCouplingCMesh.cxx b/src/MEDCoupling/MEDCouplingCMesh.cxx index 65ee343c1..20343e55c 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCMesh.cxx @@ -915,6 +915,11 @@ void MEDCouplingCMesh::reprQuickOverview(std::ostream& stream) const } } +std::string MEDCouplingCMesh::getVTKFileExtension() const +{ + return std::string("vtr"); +} + std::string MEDCouplingCMesh::getVTKDataSetType() const { return std::string("RectilinearGrid"); diff --git a/src/MEDCoupling/MEDCouplingCMesh.hxx b/src/MEDCoupling/MEDCouplingCMesh.hxx index e19f6a099..ed587c3b2 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.hxx +++ b/src/MEDCoupling/MEDCouplingCMesh.hxx @@ -81,6 +81,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, const std::vector& littleStrings); MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; + MEDCOUPLING_EXPORT std::string getVTKFileExtension() const; private: MEDCouplingCMesh(); MEDCouplingCMesh(const MEDCouplingCMesh& other, bool deepCpy); diff --git a/src/MEDCoupling/MEDCouplingCurveLinearMesh.cxx b/src/MEDCoupling/MEDCouplingCurveLinearMesh.cxx index a5158def8..f54754b37 100644 --- a/src/MEDCoupling/MEDCouplingCurveLinearMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCurveLinearMesh.cxx @@ -918,6 +918,11 @@ void MEDCouplingCurveLinearMesh::reprQuickOverview(std::ostream& stream) const coo->reprQuickOverviewData(stream,200); } +std::string MEDCouplingCurveLinearMesh::getVTKFileExtension() const +{ + return std::string("vts"); +} + std::string MEDCouplingCurveLinearMesh::getVTKDataSetType() const { return std::string("StructuredGrid"); diff --git a/src/MEDCoupling/MEDCouplingCurveLinearMesh.hxx b/src/MEDCoupling/MEDCouplingCurveLinearMesh.hxx index ba8a07c91..45f153bba 100644 --- a/src/MEDCoupling/MEDCouplingCurveLinearMesh.hxx +++ b/src/MEDCoupling/MEDCouplingCurveLinearMesh.hxx @@ -83,6 +83,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, const std::vector& littleStrings); MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; + MEDCOUPLING_EXPORT std::string getVTKFileExtension() const; private: void getMeasureFieldMeshDim1(bool isAbs, MEDCouplingFieldDouble *field) const; void getMeasureFieldMeshDim2(bool isAbs, MEDCouplingFieldDouble *field) const; diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx index d50304f6c..c5de4848c 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx @@ -953,6 +953,11 @@ void MEDCouplingExtrudedMesh::reprQuickOverview(std::ostream& stream) const stream << "MEDCouplingExtrudedMesh C++ instance at " << this << ". Name : \"" << getName() << "\"."; } +std::string MEDCouplingExtrudedMesh::getVTKFileExtension() const +{ + return _mesh2D->getVTKFileExtension(); +} + std::string MEDCouplingExtrudedMesh::getVTKDataSetType() const { return _mesh2D->getVTKDataSetType(); diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx index 76c04ff93..18e4df385 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.hxx @@ -105,6 +105,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, const std::vector& littleStrings); MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; + MEDCOUPLING_EXPORT std::string getVTKFileExtension() const; private: MEDCouplingExtrudedMesh(const MEDCouplingUMesh *mesh3D, const MEDCouplingUMesh *mesh2D, int cell2DId); MEDCouplingExtrudedMesh(const MEDCouplingExtrudedMesh& other, bool deepCopy); diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index cfa138f3a..903340bc4 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -451,10 +451,10 @@ std::string MEDCouplingFieldDouble::advancedRepr() const return ret.str(); } -void MEDCouplingFieldDouble::writeVTK(const std::string& fileName, bool isBinary) const +std::string MEDCouplingFieldDouble::writeVTK(const std::string& fileName, bool isBinary) const { std::vector fs(1,this); - MEDCouplingFieldDouble::WriteVTK(fileName,fs,isBinary); + return MEDCouplingFieldDouble::WriteVTK(fileName,fs,isBinary); } bool MEDCouplingFieldDouble::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const @@ -3242,10 +3242,10 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator^=(const MEDCoupli * \ref py_mcfielddouble_WriteVTK "Here is a Python example". * \endif */ -void MEDCouplingFieldDouble::WriteVTK(const std::string& fileName, const std::vector& fs, bool isBinary) +std::string MEDCouplingFieldDouble::WriteVTK(const std::string& fileName, const std::vector& fs, bool isBinary) { if(fs.empty()) - return; + return std::string(); std::size_t nfs=fs.size(); if(!fs[0]) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : 1st instance of field is NULL !"); @@ -3257,6 +3257,7 @@ void MEDCouplingFieldDouble::WriteVTK(const std::string& fileName, const std::ve throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : Fields are not lying on a same mesh ! Expected by VTK ! MEDCouplingFieldDouble::setMesh or MEDCouplingFieldDouble::changeUnderlyingMesh can help to that."); if(!m) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : Fields are lying on a same mesh but it is empty !"); + std::string ret(m->getVTKFileNameOf(fileName)); MEDCouplingAutoRefCountObjectPtr byteArr; if(isBinary) { byteArr=DataArrayByte::New(); byteArr->alloc(0,1); } @@ -3278,7 +3279,8 @@ void MEDCouplingFieldDouble::WriteVTK(const std::string& fileName, const std::ve else throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : only node and cell fields supported for the moment !"); } - m->writeVTKAdvanced(fileName,coss.str(),noss.str(),byteArr); + m->writeVTKAdvanced(ret,coss.str(),noss.str(),byteArr); + return ret; } void MEDCouplingFieldDouble::reprQuickOverview(std::ostream& stream) const diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index dec30c8bf..57e24b668 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -43,7 +43,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void copyAllTinyAttrFrom(const MEDCouplingFieldDouble *other); MEDCOUPLING_EXPORT std::string simpleRepr() const; MEDCOUPLING_EXPORT std::string advancedRepr() const; - MEDCOUPLING_EXPORT void writeVTK(const std::string& fileName, bool isBinary=true) const; + MEDCOUPLING_EXPORT std::string writeVTK(const std::string& fileName, bool isBinary=true) const; MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const; MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const; MEDCOUPLING_EXPORT bool areCompatibleForMerge(const MEDCouplingField *other) const; @@ -191,7 +191,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT MEDCouplingFieldDouble *operator^(const MEDCouplingFieldDouble& other) const; MEDCOUPLING_EXPORT const MEDCouplingFieldDouble &operator^=(const MEDCouplingFieldDouble& other); MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *PowFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); - MEDCOUPLING_EXPORT static void WriteVTK(const std::string& fileName, const std::vector& fs, bool isBinary=true); + MEDCOUPLING_EXPORT static std::string WriteVTK(const std::string& fileName, const std::vector& fs, bool isBinary=true); public: MEDCOUPLING_EXPORT const MEDCouplingTimeDiscretization *getTimeDiscretizationUnderGround() const { return _time_discr; } MEDCOUPLING_EXPORT MEDCouplingTimeDiscretization *getTimeDiscretizationUnderGround() { return _time_discr; } diff --git a/src/MEDCoupling/MEDCouplingIMesh.cxx b/src/MEDCoupling/MEDCouplingIMesh.cxx index 9a5f1c535..d01d4e95c 100644 --- a/src/MEDCoupling/MEDCouplingIMesh.cxx +++ b/src/MEDCoupling/MEDCouplingIMesh.cxx @@ -1334,6 +1334,11 @@ void MEDCouplingIMesh::reprQuickOverview(std::ostream& stream) const stream << stream1.str(); } +std::string MEDCouplingIMesh::getVTKFileExtension() const +{ + return std::string("vti"); +} + std::string MEDCouplingIMesh::getVTKDataSetType() const { return std::string("ImageData"); diff --git a/src/MEDCoupling/MEDCouplingIMesh.hxx b/src/MEDCoupling/MEDCouplingIMesh.hxx index dd0f314aa..d638f738f 100644 --- a/src/MEDCoupling/MEDCouplingIMesh.hxx +++ b/src/MEDCoupling/MEDCouplingIMesh.hxx @@ -99,6 +99,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, const std::vector& littleStrings); MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; + MEDCOUPLING_EXPORT std::string getVTKFileExtension() const; private: MEDCouplingIMesh(); MEDCouplingIMesh(const MEDCouplingIMesh& other, bool deepCpy); diff --git a/src/MEDCoupling/MEDCouplingMesh.cxx b/src/MEDCoupling/MEDCouplingMesh.cxx index 241e05120..5216e4307 100644 --- a/src/MEDCoupling/MEDCouplingMesh.cxx +++ b/src/MEDCoupling/MEDCouplingMesh.cxx @@ -689,16 +689,41 @@ void MEDCouplingMesh::getCellsContainingPoints(const double *pos, int nbOfPoints /*! * Writes \a this mesh into a VTK format file named as specified. - * \param [in] fileName - the name of the file to write in. + * \param [in] fileName - the name of the file to write in. If the extension is OK the fileName will be used directly. + * If extension is invalid or no extension the right extension will be appended. + * \return - the real fileName * \throw If \a fileName is not a writable file. + * \sa getVTKFileNameOf */ -void MEDCouplingMesh::writeVTK(const std::string& fileName, bool isBinary) const +std::string MEDCouplingMesh::writeVTK(const std::string& fileName, bool isBinary) const { + std::string ret(getVTKFileNameOf(fileName)); + // std::string cda,pda; MEDCouplingAutoRefCountObjectPtr byteArr; if(isBinary) { byteArr=DataArrayByte::New(); byteArr->alloc(0,1); } - writeVTKAdvanced(fileName,cda,pda,byteArr); + writeVTKAdvanced(ret,cda,pda,byteArr); + return ret; +} + +/*! + * This method takes in input a file name \a fileName and considering the VTK extension of \a this (depending on the type of \a this) + * returns a right file name. If the input \a fileName has a valid extension the returned string is equal to \a fileName. + * + * \sa getVTKFileExtension + */ +std::string MEDCouplingMesh::getVTKFileNameOf(const std::string& fileName) const +{ + std::string ret; + std::string part0,part1; + SplitExtension(fileName,part0,part1); + std::string ext("."); ext+=getVTKFileExtension(); + if(part1==ext) + ret=fileName; + else + ret=fileName+ext; + return ret; } void MEDCouplingMesh::writeVTKAdvanced(const std::string& fileName, const std::string& cda, const std::string& pda, DataArrayByte *byteData) const @@ -720,3 +745,16 @@ void MEDCouplingMesh::writeVTKAdvanced(const std::string& fileName, const std::s ofs.close(); } } + +void MEDCouplingMesh::SplitExtension(const std::string& fileName, std::string& baseName, std::string& extension) +{ + std::size_t pos(fileName.find_last_of('.')); + if(pos==std::string::npos) + { + baseName=fileName; + extension.clear(); + return ; + } + baseName=fileName.substr(0,pos); + extension=fileName.substr(pos); +} diff --git a/src/MEDCoupling/MEDCouplingMesh.hxx b/src/MEDCoupling/MEDCouplingMesh.hxx index 8eae2e543..899298861 100644 --- a/src/MEDCoupling/MEDCouplingMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMesh.hxx @@ -145,9 +145,12 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT virtual void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const = 0; MEDCOUPLING_EXPORT virtual void unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, const std::vector& littleStrings) = 0; - MEDCOUPLING_EXPORT void writeVTK(const std::string& fileName, bool isBinary=true) const; + MEDCOUPLING_EXPORT std::string writeVTK(const std::string& fileName, bool isBinary=true) const; + MEDCOUPLING_EXPORT std::string getVTKFileNameOf(const std::string& fileName) const; + MEDCOUPLING_EXPORT virtual std::string getVTKFileExtension() const = 0; /// @cond INTERNAL MEDCOUPLING_EXPORT void writeVTKAdvanced(const std::string& fileName, const std::string& cda, const std::string& pda, DataArrayByte *byteData) const; + MEDCOUPLING_EXPORT static void SplitExtension(const std::string& fileName, std::string& baseName, std::string& extension); /// @endcond MEDCOUPLING_EXPORT virtual void writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const = 0; MEDCOUPLING_EXPORT virtual void reprQuickOverview(std::ostream& stream) const = 0; diff --git a/src/MEDCoupling/MEDCouplingRemapper.cxx b/src/MEDCoupling/MEDCouplingRemapper.cxx index 33a0debff..aaffd1d14 100644 --- a/src/MEDCoupling/MEDCouplingRemapper.cxx +++ b/src/MEDCoupling/MEDCouplingRemapper.cxx @@ -134,6 +134,8 @@ int MEDCouplingRemapper::prepareNotInterpKernelOnly() */ void MEDCouplingRemapper::transfer(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField, double dftValue) { + if(!srcField || !targetField) + throw INTERP_KERNEL::Exception("MEDCouplingRemapper::transfer : input field must be both not NULL !"); transferUnderground(srcField,targetField,true,dftValue); } @@ -148,34 +150,46 @@ void MEDCouplingRemapper::transfer(const MEDCouplingFieldDouble *srcField, MEDCo */ void MEDCouplingRemapper::partialTransfer(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField) { + if(!srcField || !targetField) + throw INTERP_KERNEL::Exception("MEDCouplingRemapper::partialTransfer : input field must be both not NULL !"); transferUnderground(srcField,targetField,false,std::numeric_limits::max()); } void MEDCouplingRemapper::reverseTransfer(MEDCouplingFieldDouble *srcField, const MEDCouplingFieldDouble *targetField, double dftValue) { + if(!srcField || !targetField) + throw INTERP_KERNEL::Exception("MEDCouplingRemapper::reverseTransfer : input fields must be both not NULL !"); checkPrepare(); + targetField->checkCoherency(); if(_src_ft->getDiscretization()->getStringRepr()!=srcField->getDiscretization()->getStringRepr()) throw INTERP_KERNEL::Exception("Incoherency with prepare call for source field"); if(_target_ft->getDiscretization()->getStringRepr()!=targetField->getDiscretization()->getStringRepr()) throw INTERP_KERNEL::Exception("Incoherency with prepare call for target field"); if(srcField->getNature()!=targetField->getNature()) throw INTERP_KERNEL::Exception("Natures of fields mismatch !"); - DataArrayDouble *array=srcField->getArray(); + if(targetField->getNumberOfTuplesExpected()!=_target_ft->getNumberOfTuplesExpected()) + { + std::ostringstream oss; + oss << "MEDCouplingRemapper::reverseTransfer : in given source field the number of tuples required is " << _target_ft->getNumberOfTuplesExpected() << " (on prepare) and number of tuples in given target field is " << targetField->getNumberOfTuplesExpected(); + oss << " ! It appears that the target support is not the same between the prepare and the transfer !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + DataArrayDouble *array(srcField->getArray()); int trgNbOfCompo=targetField->getNumberOfComponents(); if(array) { - if(trgNbOfCompo!=srcField->getNumberOfComponents()) + srcField->checkCoherency(); + if(trgNbOfCompo!=srcField->getNumberOfTuplesExpected()) throw INTERP_KERNEL::Exception("Number of components mismatch !"); } else { - array=DataArrayDouble::New(); - array->alloc(srcField->getNumberOfTuples(),trgNbOfCompo); - srcField->setArray(array); - array->decrRef(); + MEDCouplingAutoRefCountObjectPtr tmp(DataArrayDouble::New()); + tmp->alloc(srcField->getNumberOfTuplesExpected(),trgNbOfCompo); + srcField->setArray(tmp); } computeDeno(srcField->getNature(),srcField,targetField); - double *resPointer=array->getPointer(); + double *resPointer(srcField->getArray()->getPointer()); const double *inputPointer=targetField->getArray()->getConstPointer(); computeReverseProduct(inputPointer,trgNbOfCompo,dftValue,resPointer); } @@ -183,6 +197,9 @@ void MEDCouplingRemapper::reverseTransfer(MEDCouplingFieldDouble *srcField, cons MEDCouplingFieldDouble *MEDCouplingRemapper::transferField(const MEDCouplingFieldDouble *srcField, double dftValue) { checkPrepare(); + if(!srcField) + throw INTERP_KERNEL::Exception("MEDCouplingRemapper::transferField : input srcField is NULL !"); + srcField->checkCoherency(); if(_src_ft->getDiscretization()->getStringRepr()!=srcField->getDiscretization()->getStringRepr()) throw INTERP_KERNEL::Exception("Incoherency with prepare call for source field"); MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(*_target_ft,srcField->getTimeDiscretization()); @@ -194,6 +211,9 @@ MEDCouplingFieldDouble *MEDCouplingRemapper::transferField(const MEDCouplingFiel MEDCouplingFieldDouble *MEDCouplingRemapper::reverseTransferField(const MEDCouplingFieldDouble *targetField, double dftValue) { + if(!targetField) + throw INTERP_KERNEL::Exception("MEDCouplingRemapper::transferField : input targetField is NULL !"); + targetField->checkCoherency(); checkPrepare(); if(_target_ft->getDiscretization()->getStringRepr()!=targetField->getDiscretization()->getStringRepr()) throw INTERP_KERNEL::Exception("Incoherency with prepare call for target field"); @@ -896,6 +916,9 @@ void MEDCouplingRemapper::releaseData(bool matrixSuppression) void MEDCouplingRemapper::transferUnderground(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField, bool isDftVal, double dftValue) { + if(!srcField || !targetField) + throw INTERP_KERNEL::Exception("MEDCouplingRemapper::transferUnderground : srcField or targetField is NULL !"); + srcField->checkCoherency(); checkPrepare(); if(_src_ft->getDiscretization()->getStringRepr()!=srcField->getDiscretization()->getStringRepr()) throw INTERP_KERNEL::Exception("Incoherency with prepare call for source field"); @@ -903,10 +926,18 @@ void MEDCouplingRemapper::transferUnderground(const MEDCouplingFieldDouble *srcF throw INTERP_KERNEL::Exception("Incoherency with prepare call for target field"); if(srcField->getNature()!=targetField->getNature()) throw INTERP_KERNEL::Exception("Natures of fields mismatch !"); - DataArrayDouble *array=targetField->getArray(); - int srcNbOfCompo=srcField->getNumberOfComponents(); + if(srcField->getNumberOfTuplesExpected()!=_src_ft->getNumberOfTuplesExpected()) + { + std::ostringstream oss; + oss << "MEDCouplingRemapper::transferUnderground : in given source field the number of tuples required is " << _src_ft->getNumberOfTuplesExpected() << " (on prepare) and number of tuples in given source field is " << srcField->getNumberOfTuplesExpected(); + oss << " ! It appears that the source support is not the same between the prepare and the transfer !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + DataArrayDouble *array(targetField->getArray()); + int srcNbOfCompo(srcField->getNumberOfComponents()); if(array) { + targetField->checkCoherency(); if(srcNbOfCompo!=targetField->getNumberOfComponents()) throw INTERP_KERNEL::Exception("Number of components mismatch !"); } @@ -914,14 +945,13 @@ void MEDCouplingRemapper::transferUnderground(const MEDCouplingFieldDouble *srcF { if(!isDftVal) throw INTERP_KERNEL::Exception("MEDCouplingRemapper::partialTransfer : This method requires that the array of target field exists ! Allocate it or call MEDCouplingRemapper::transfer instead !"); - array=DataArrayDouble::New(); - array->alloc(targetField->getNumberOfTuples(),srcNbOfCompo); - targetField->setArray(array); - array->decrRef(); + MEDCouplingAutoRefCountObjectPtr tmp(DataArrayDouble::New()); + tmp->alloc(targetField->getNumberOfTuples(),srcNbOfCompo); + targetField->setArray(tmp); } computeDeno(srcField->getNature(),srcField,targetField); - double *resPointer=array->getPointer(); - const double *inputPointer=srcField->getArray()->getConstPointer(); + double *resPointer(targetField->getArray()->getPointer()); + const double *inputPointer(srcField->getArray()->getConstPointer()); computeProduct(inputPointer,srcNbOfCompo,isDftVal,dftValue,resPointer); } diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 039031123..be6bac00e 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -8667,6 +8667,11 @@ std::string MEDCouplingUMesh::getVTKDataSetType() const return std::string("UnstructuredGrid"); } +std::string MEDCouplingUMesh::getVTKFileExtension() const +{ + return std::string("vtu"); +} + /*! * Partitions the first given 2D mesh using the second given 2D mesh as a tool, and * returns a result mesh constituted by polygons. diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index ca49d9c79..5c0bed365 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -90,6 +90,7 @@ namespace ParaMEDMEM 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); MEDCOUPLING_EXPORT std::string getVTKDataSetType() const; + MEDCOUPLING_EXPORT std::string getVTKFileExtension() const; MEDCOUPLING_EXPORT void writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const; MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; //tools diff --git a/src/MEDCoupling/Test/MEDCouplingRemapperTest.cxx b/src/MEDCoupling/Test/MEDCouplingRemapperTest.cxx index 1d8f304ae..f3b1ee390 100644 --- a/src/MEDCoupling/Test/MEDCouplingRemapperTest.cxx +++ b/src/MEDCoupling/Test/MEDCouplingRemapperTest.cxx @@ -126,7 +126,7 @@ void MEDCouplingRemapperTest::test2DInterpP0P0R_1() MEDCouplingFieldDouble *targetField=MEDCouplingFieldDouble::New(ON_CELLS); targetField->setNature(ConservativeVolumic); - targetField->setMesh(sourceMesh); + targetField->setMesh(targetMesh); DataArrayDouble *array=DataArrayDouble::New(); array->alloc(targetMesh->getNumberOfCells(),1); targetField->setArray(array); diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 1bf0b4efc..f980dc2c5 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -14936,6 +14936,21 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(mu.getNodalConnectivity().isEqual(DataArrayInt([1,0,3,4,2,1,4,5,4,3,6,7,5,4,7,8,7,6,9,10,8,7,10,11]))) pass + def testSwig1GetValuesAsTuple1(self): + d=DataArrayDouble() + self.assertEqual(d.getValues(),[]) + self.assertEqual(d.getValuesAsTuple(),[]) + d=DataArrayDouble(24) ; d.iota() ; d.rearrange(3) + self.assertEqual(d.getValues(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.]) + self.assertEqual(d.getValuesAsTuple(),[(0.,1.,2.0),(3.,4.,5.0),(6.,7.,8.0),(9.,10.,11.0),(12.,13.,14.0),(15.,16.,17.0),(18.,19.,20.0),(21.,22.,23.)]) + d=DataArrayInt() + self.assertEqual(d.getValues(),[]) + self.assertEqual(d.getValuesAsTuple(),[]) + d=DataArrayInt(24) ; d.iota() ; d.rearrange(3) + self.assertEqual(d.getValues(),[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]) + self.assertEqual(d.getValuesAsTuple(),[(0,1,2),(3,4,5),(6,7,8),(9,10,11),(12,13,14),(15,16,17),(18,19,20),(21,22,23)]) + pass + def testSwig2AMR1(self): self.assertEqual((1,3,12),MEDCouplingStructuredMesh.GetSplitVectFromStruct([3,4,5])) self.assertEqual((3,2),MEDCouplingStructuredMesh.GetDimensionsFromCompactFrmt([(1,4),(2,4)])) diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 189db27d9..d33cb806d 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -545,7 +545,9 @@ namespace ParaMEDMEM virtual INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const throw(INTERP_KERNEL::Exception); virtual std::string simpleRepr() const throw(INTERP_KERNEL::Exception); virtual std::string advancedRepr() const throw(INTERP_KERNEL::Exception); - void writeVTK(const std::string& fileName, bool isBinary=true) const throw(INTERP_KERNEL::Exception); + std::string writeVTK(const std::string& fileName, bool isBinary=true) const throw(INTERP_KERNEL::Exception); + virtual std::string getVTKFileExtension() const; + std::string getVTKFileNameOf(const std::string& fileName) const; // tools virtual MEDCouplingFieldDouble *getMeasureField(bool isAbs) const throw(INTERP_KERNEL::Exception); virtual MEDCouplingFieldDouble *getMeasureFieldOnNode(bool isAbs) const throw(INTERP_KERNEL::Exception); @@ -3519,7 +3521,7 @@ namespace ParaMEDMEM void copyAllTinyAttrFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception); std::string simpleRepr() const throw(INTERP_KERNEL::Exception); std::string advancedRepr() const throw(INTERP_KERNEL::Exception); - void writeVTK(const std::string& fileName, bool isBinary=true) const throw(INTERP_KERNEL::Exception); + std::string writeVTK(const std::string& fileName, bool isBinary=true) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *clone(bool recDeepCpy) const; MEDCouplingFieldDouble *cloneWithMesh(bool recDeepCpy) const; MEDCouplingFieldDouble *deepCpy() const; @@ -4590,11 +4592,11 @@ namespace ParaMEDMEM return MEDCouplingFieldDouble::MergeFields(tmp); } - static void WriteVTK(const char *fileName, PyObject *li, bool isBinary=true) throw(INTERP_KERNEL::Exception) + static std::string WriteVTK(const char *fileName, PyObject *li, bool isBinary=true) throw(INTERP_KERNEL::Exception) { std::vector tmp; convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,"MEDCouplingFieldDouble",tmp); - MEDCouplingFieldDouble::WriteVTK(fileName,tmp,isBinary); + return MEDCouplingFieldDouble::WriteVTK(fileName,tmp,isBinary); } } };