X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingMesh.cxx;h=fd1ef11719f26fb0c25bfc67c86e680895ef3001;hb=90b7c9c73054965b8085ab0ecd2646a3d59f475a;hp=eddba8553a95843675550fc17109d12d1b6605ec;hpb=79c404a024c4b00550400f158f89fcc64859e71d;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingMesh.cxx b/src/MEDCoupling/MEDCouplingMesh.cxx old mode 100644 new mode 100755 index eddba8553..fd1ef1171 --- a/src/MEDCoupling/MEDCouplingMesh.cxx +++ b/src/MEDCoupling/MEDCouplingMesh.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D +// Copyright (C) 2007-2020 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. +// 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 @@ -20,10 +20,10 @@ #include "MEDCouplingMesh.hxx" #include "MEDCouplingUMesh.hxx" -#include "MEDCouplingMemArray.hxx" +#include "MEDCouplingMemArray.txx" #include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingFieldDiscretization.hxx" -#include "MEDCouplingAutoRefCountObjectPtr.hxx" +#include "MCAuto.hxx" #include #include @@ -31,7 +31,7 @@ #include #include -using namespace ParaMEDMEM; +using namespace MEDCoupling; MEDCouplingMesh::MEDCouplingMesh():_time(0.),_iteration(-1),_order(-1) { @@ -146,7 +146,7 @@ bool MEDCouplingMesh::isEqual(const MEDCouplingMesh *other, double prec) const * to be compared. An interpolation using MEDCouplingRemapper class should be then used. */ void MEDCouplingMesh::checkGeoEquivalWith(const MEDCouplingMesh *other, int levOfCheck, double prec, - DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception) + DataArrayIdType *&cellCor, DataArrayIdType *&nodeCor) const { cellCor=0; nodeCor=0; @@ -195,28 +195,28 @@ void MEDCouplingMesh::checkGeoEquivalWith(const MEDCouplingMesh *other, int levO * \param [in] partBg - the array of node ids. * \param [in] partEnd - end of \a partBg, i.e. a pointer to a (last+1)-th element * of \a partBg. - * \return DataArrayInt * - a new instance of DataArrayInt holding ids of found + * \return DataArrayIdType * - a new instance of DataArrayIdType holding ids of found * cells. The caller is to delete this array using decrRef() as it is no * more needed. */ -DataArrayInt *MEDCouplingMesh::getCellIdsFullyIncludedInNodeIds(const int *partBg, const int *partEnd) const +DataArrayIdType *MEDCouplingMesh::getCellIdsFullyIncludedInNodeIds(const mcIdType *partBg, const mcIdType *partEnd) const { - std::vector crest; - std::set p(partBg,partEnd); - int nbOfCells=getNumberOfCells(); - for(int i=0;i crest; + std::set p(partBg,partEnd); + mcIdType nbOfCells=getNumberOfCells(); + for(mcIdType i=0;i conn; + std::vector conn; getNodeIdsOfCell(i,conn); bool cont=true; - for(std::vector::const_iterator iter=conn.begin();iter!=conn.end() && cont;iter++) + for(std::vector::const_iterator iter=conn.begin();iter!=conn.end() && cont;iter++) if(p.find(*iter)==p.end()) cont=false; if(cont) crest.push_back(i); } - DataArrayInt *ret=DataArrayInt::New(); - ret->alloc((int)crest.size(),1); + DataArrayIdType *ret=DataArrayIdType::New(); + ret->alloc(crest.size(),1); std::copy(crest.begin(),crest.end(),ret->getPointer()); return ret; } @@ -237,7 +237,7 @@ void MEDCouplingMesh::checkFastEquivalWith(const MEDCouplingMesh *other, double } /*! - * This method is very poor and looks only if \a this and \a other are candidate for merge of fields lying repectively on them. + * This method is very poor and looks only if \a this and \a other are candidate for merge of fields lying respectively on them. */ bool MEDCouplingMesh::areCompatibleForMerge(const MEDCouplingMesh *other) const { @@ -259,7 +259,7 @@ bool MEDCouplingMesh::areCompatibleForMerge(const MEDCouplingMesh *other) const * * \sa MEDCouplingMesh::buildPart */ -MEDCouplingMesh *MEDCouplingMesh::buildPartRange(int beginCellIds, int endCellIds, int stepCellIds) const +MEDCouplingMesh *MEDCouplingMesh::buildPartRange(mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds) const { if(beginCellIds==0 && endCellIds==getNumberOfCells() && stepCellIds==1) { @@ -269,7 +269,7 @@ MEDCouplingMesh *MEDCouplingMesh::buildPartRange(int beginCellIds, int endCellId } else { - MEDCouplingAutoRefCountObjectPtr cellIds=DataArrayInt::Range(beginCellIds,endCellIds,stepCellIds); + MCAuto cellIds=DataArrayIdType::Range(beginCellIds,endCellIds,stepCellIds); return buildPart(cellIds->begin(),cellIds->end()); } } @@ -279,9 +279,9 @@ MEDCouplingMesh *MEDCouplingMesh::buildPartRange(int beginCellIds, int endCellId * * \sa MEDCouplingMesh::buildPartAndReduceNodes */ -MEDCouplingMesh *MEDCouplingMesh::buildPartRangeAndReduceNodes(int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt*& arr) const +MEDCouplingMesh *MEDCouplingMesh::buildPartRangeAndReduceNodes(mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds, mcIdType& beginOut, mcIdType& endOut, mcIdType& stepOut, DataArrayIdType*& arr) const { - MEDCouplingAutoRefCountObjectPtr cellIds=DataArrayInt::Range(beginCellIds,endCellIds,stepCellIds); + MCAuto cellIds=DataArrayIdType::Range(beginCellIds,endCellIds,stepCellIds); return buildPartAndReduceNodes(cellIds->begin(),cellIds->end(),arr); } @@ -303,7 +303,7 @@ MEDCouplingMesh *MEDCouplingMesh::buildPartRangeAndReduceNodes(int beginCellIds, */ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbOfComp, FunctionToEvaluate func) const { - MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingFieldDouble::New(t,ONE_TIME); + MCAuto ret=MEDCouplingFieldDouble::New(t,ONE_TIME); ret->setMesh(this); ret->fillFromAnalytic(nbOfComp,func); ret->synchronizeTimeWithSupport(); @@ -329,10 +329,10 @@ void MEDCouplingMesh::copyTinyStringsFrom(const MEDCouplingMesh *other) */ void MEDCouplingMesh::copyTinyInfoFrom(const MEDCouplingMesh *other) { - copyTinyStringsFrom(other); _time=other->_time; _iteration=other->_iteration; _order=other->_order; + copyTinyStringsFrom(other); } /*! @@ -340,7 +340,7 @@ void MEDCouplingMesh::copyTinyInfoFrom(const MEDCouplingMesh *other) * Creates a new MEDCouplingFieldDouble of a given type, one time, with given number of * components, lying on \a this mesh, with contents got by applying a specified * function to coordinates of field location points (defined by the given field type). - * For example, if \a t == ParaMEDMEM::ON_CELLS, the function is applied to cell + * For example, if \a t == MEDCoupling::ON_CELLS, the function is applied to cell * barycenters.
* For more info on supported expressions that can be used in the function, see \ref * MEDCouplingArrayApplyFuncExpr. The function can include arbitrary named variables @@ -378,7 +378,7 @@ void MEDCouplingMesh::copyTinyInfoFrom(const MEDCouplingMesh *other) */ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbOfComp, const std::string& func) const { - MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingFieldDouble::New(t,ONE_TIME); + MCAuto ret=MEDCouplingFieldDouble::New(t,ONE_TIME); ret->setMesh(this); ret->fillFromAnalytic(nbOfComp,func); ret->synchronizeTimeWithSupport(); @@ -389,7 +389,7 @@ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbO * Creates a new MEDCouplingFieldDouble of a given type, one time, with given number of * components, lying on \a this mesh, with contents got by applying a specified * function to coordinates of field location points (defined by the given field type). - * For example, if \a t == ParaMEDMEM::ON_CELLS, the function is applied to cell + * For example, if \a t == MEDCoupling::ON_CELLS, the function is applied to cell * barycenters. This method differs from * \ref MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbOfComp, const std::string& func) const "fillFromAnalytic()" * by the way how variable @@ -428,11 +428,11 @@ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbO * \ref py_mcmesh_fillFromAnalytic2 "Here is a Python example". * \endif */ -MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic2(TypeOfField t, int nbOfComp, const std::string& func) const +MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalyticCompo(TypeOfField t, int nbOfComp, const std::string& func) const { - MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingFieldDouble::New(t,ONE_TIME); + MCAuto ret=MEDCouplingFieldDouble::New(t,ONE_TIME); ret->setMesh(this); - ret->fillFromAnalytic2(nbOfComp,func); + ret->fillFromAnalyticCompo(nbOfComp,func); ret->synchronizeTimeWithSupport(); return ret.retn(); } @@ -441,7 +441,7 @@ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic2(TypeOfField t, int nb * Creates a new MEDCouplingFieldDouble of a given type, one time, with given number of * components, lying on \a this mesh, with contents got by applying a specified * function to coordinates of field location points (defined by the given field type). - * For example, if \a t == ParaMEDMEM::ON_CELLS, the function is applied to cell + * For example, if \a t == MEDCoupling::ON_CELLS, the function is applied to cell * barycenters. This method differs from \ref \ref mcmesh_fillFromAnalytic * "fillFromAnalytic()" by the way how variable * names, used in the function, are associated with components of coordinates of field @@ -481,11 +481,11 @@ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic2(TypeOfField t, int nb * \ref py_mcmesh_fillFromAnalytic3 "Here is a Python example". * \endif */ -MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic3(TypeOfField t, int nbOfComp, const std::vector& varsOrder, const std::string& func) const +MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalyticNamedCompo(TypeOfField t, int nbOfComp, const std::vector& varsOrder, const std::string& func) const { - MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingFieldDouble::New(t,ONE_TIME); + MCAuto ret=MEDCouplingFieldDouble::New(t,ONE_TIME); ret->setMesh(this); - ret->fillFromAnalytic3(nbOfComp,varsOrder,func); + ret->fillFromAnalyticNamedCompo(nbOfComp,varsOrder,func); ret->synchronizeTimeWithSupport(); return ret.retn(); } @@ -532,7 +532,7 @@ MEDCouplingMesh *MEDCouplingMesh::MergeMeshes(const MEDCouplingMesh *mesh1, cons */ MEDCouplingMesh *MEDCouplingMesh::MergeMeshes(std::vector& meshes) { - std::vector< MEDCouplingAutoRefCountObjectPtr > ms1(meshes.size()); + std::vector< MCAuto > ms1(meshes.size()); std::vector< const MEDCouplingUMesh * > ms2(meshes.size()); for(std::size_t i=0;i - * \ref py_mcumesh_getCellsContainingPoint "Here is a Python example". - * \endif - */ -void MEDCouplingMesh::getCellsContainingPoint(const double *pos, double eps, std::vector& elts) const -{ - int ret=getCellContainingPoint(pos,eps); - elts.push_back(ret); -} - /*! * Finds cells in contact with several balls (i.e. points with precision). * This method is an extension of getCellContainingPoint() and @@ -668,39 +647,73 @@ void MEDCouplingMesh::getCellsContainingPoint(const double *pos, double eps, std * \ref py_mcumesh_getCellsContainingPoints "Here is a Python example". * \endif */ -void MEDCouplingMesh::getCellsContainingPoints(const double *pos, int nbOfPoints, double eps, MEDCouplingAutoRefCountObjectPtr& elts, MEDCouplingAutoRefCountObjectPtr& eltsIndex) const +void MEDCouplingMesh::getCellsContainingPoints(const double *pos, mcIdType nbOfPoints, double eps, MCAuto& elts, MCAuto& eltsIndex) const { - eltsIndex=DataArrayInt::New(); elts=DataArrayInt::New(); eltsIndex->alloc(nbOfPoints+1,1); eltsIndex->setIJ(0,0,0); elts->alloc(0,1); - int *eltsIndexPtr(eltsIndex->getPointer()); + eltsIndex=DataArrayIdType::New(); elts=DataArrayIdType::New(); eltsIndex->alloc(nbOfPoints+1,1); eltsIndex->setIJ(0,0,0); elts->alloc(0,1); + mcIdType *eltsIndexPtr(eltsIndex->getPointer()); int spaceDim(getSpaceDimension()); const double *work(pos); - for(int i=0;i=0) - { - elts->pushBackSilent(ret); - eltsIndexPtr[i+1]=eltsIndexPtr[i]+1; - } - else - eltsIndexPtr[i+1]=eltsIndexPtr[i]; + std::vector ret; + getCellsContainingPoint(work,eps,ret); + elts->insertAtTheEnd(ret.begin(),ret.end()); + eltsIndexPtr[i+1]=elts->getNumberOfTuples(); } } +/*! + * Behaves like MEDCouplingMesh::getCellsContainingPoints for cells in \a this that are linear. + * For quadratic cells in \a this, this method behaves by just considering linear part of cells. + * This method is here only for backward compatibility (interpolation GaussPoints to GaussPoints). + * + * \sa MEDCouplingMesh::getCellsContainingPoints, MEDCouplingRemapper::prepareNotInterpKernelOnlyGaussGauss + */ +void MEDCouplingMesh::getCellsContainingPointsLinearPartOnlyOnNonDynType(const double *pos, mcIdType nbOfPoints, double eps, MCAuto& elts, MCAuto& eltsIndex) const +{ + this->getCellsContainingPoints(pos,nbOfPoints,eps,elts,eltsIndex); +} + /*! * 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; + MCAuto 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; } +/// @cond INTERNAL void MEDCouplingMesh::writeVTKAdvanced(const std::string& fileName, const std::string& cda, const std::string& pda, DataArrayByte *byteData) const { std::ofstream ofs(fileName.c_str()); @@ -720,3 +733,17 @@ 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); +} +/// @endcond