X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingMesh.cxx;h=fd1ef11719f26fb0c25bfc67c86e680895ef3001;hb=90b7c9c73054965b8085ab0ecd2646a3d59f475a;hp=48489218fdd5c05d9cb0d1e76937341278b72d7b;hpb=48e298dbf14059e3392eb522cfdb634bfefeaf1b;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingMesh.cxx b/src/MEDCoupling/MEDCouplingMesh.cxx old mode 100644 new mode 100755 index 48489218f..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,19 +31,19 @@ #include #include -using namespace ParaMEDMEM; +using namespace MEDCoupling; MEDCouplingMesh::MEDCouplingMesh():_time(0.),_iteration(-1),_order(-1) { } -MEDCouplingMesh::MEDCouplingMesh(const MEDCouplingMesh& other):_name(other._name),_description(other._description), +MEDCouplingMesh::MEDCouplingMesh(const MEDCouplingMesh& other):RefCountObject(other),_name(other._name),_description(other._description), _time(other._time),_iteration(other._iteration), _order(other._order),_time_unit(other._time_unit) { } -std::size_t MEDCouplingMesh::getHeapMemorySize() const +std::size_t MEDCouplingMesh::getHeapMemorySizeWithoutChildren() const { return _name.capacity()+_description.capacity()+_time_unit.capacity(); } @@ -56,7 +56,7 @@ bool MEDCouplingMesh::isStructured() const return getType()==CARTESIAN; } -bool MEDCouplingMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception) +bool MEDCouplingMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const { if(!other) throw INTERP_KERNEL::Exception("MEDCouplingMesh::isEqualIfNotWhy : other instance is NULL !"); @@ -106,32 +106,47 @@ bool MEDCouplingMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, * \param [in] prec - precision value used to compare node coordinates. * \return bool - \c true if the two meshes are equal, \c false else. */ -bool MEDCouplingMesh::isEqual(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception) +bool MEDCouplingMesh::isEqual(const MEDCouplingMesh *other, double prec) const { std::string tmp; return isEqualIfNotWhy(other,prec,tmp); } /*! - * This method checks geo equivalence between two meshes : 'this' and 'other'. - * If no exception is throw 'this' and 'other' are geometrically equivalent regarding 'levOfCheck' level. - * This method is typically used to change the mesh of a field "safely" depending the 'levOfCheck' level considered. - * So in case of success cell \c other[i] is equal to cell \c this[cellCor[i]]. If \a cellCor is null it means that for all i cell \c other[i] is equal to cell \c this[i]. + * This method checks geo equivalence between two meshes : \a this and \a other. + * If no exception is thrown \a this and \a other are geometrically equivalent regarding \a levOfCheck level. + * This method is typically used to change the mesh of a field "safely" depending the \a levOfCheck level considered. * - * @param levOfCheck input that specifies the level of check specified. The possible values are listed below. - * @param prec input that specifies precision for double float data used for comparison in meshes. - * @param cellCor output array not always informed (depending 'levOfCheck' param) that gives the corresponding array for cells from 'other' to 'this'. - * @param nodeCor output array not always informed (depending 'levOfCheck' param) that gives the corresponding array for nodes from 'other' to 'this'. + * In case of success cell \c other[i] is equal to the cell \c this[cellCor[i]]. + * In case of success node \c other->getCoords()[i] is equal to the node \c this->getCoords()[nodeCor[i]]. + * + * If \a cellCor is null (or Py_None) it means that for all #i cell in \a other is equal to cell # i in \a this. + * + * If \a nodeCor is null (or Py_None) it means that for all #i node in \a other is equal to node # i in \a this. + * + * So null (or Py_None) returned in \a cellCor and/or \a nodeCor means identity array. This is for optimization reason to avoid to build useless arrays + * for some \a levOfCheck (for example 0). + * + * **Warning a not null output does not mean that it is not identity !** + * + * \param [in] other - the mesh to be compared with \a this. + * \param [in] levOfCheck - input that specifies the level of check specified. The possible values are listed below. + * \param [in] prec - input that specifies precision for double float data used for comparison in meshes. + * \param [out] cellCor - output array not always informed (depending \a levOfCheck param) that gives the corresponding array for cells from \a other to \a this. + * \param [out] nodeCor - output array not always informed (depending \a levOfCheck param) that gives the corresponding array for nodes from \a other to \a this. * * Possible values for levOfCheck : - * - 0 for strict equality. This is the strongest level. 'cellCor' and 'nodeCor' params are never informed. - * - 10,11,12 for less strict equality. Two meshes are compared geometrically. In case of success 'cellCor' and 'nodeCor' are informed. Warning ! These equivalences are CPU/Mem costly. The 3 values correspond respectively to policy used for cell comparison (see MEDCouplingUMesh::zipConnectivityTraducer to have more details) - * - 20,21,22, for less strict equality. Two meshes are compared geometrically. The difference with the previous version is that nodes(coordinates) are expected to be the same between this and other. In case of success 'cellCor' is informed. Warning ! These equivalences are CPU/Mem costly. The 3 values correspond respectively to policy used for cell comparison (see MEDCouplingUMesh::zipConnectivityTraducer to have more details) + * - 0 for strict equality. This is the strongest level. \a cellCor and \a nodeCor params are never informed. + * - 10,11,12 (10+x) for less strict equality. Two meshes are compared geometrically. In case of success \a cellCor and \a nodeCor are informed. Warning ! These equivalences are CPU/Mem costly. The 3 values correspond respectively to policy used for cell comparison (see MEDCouplingUMesh::zipConnectivityTraducer to have more details) + * - 20,21,22 (20+x), for less strict equality. Two meshes are compared geometrically. The difference with the previous version is that nodes(coordinates) are expected to be the same between this and other. In case of success \a cellCor is informed. Warning ! These equivalences are CPU/Mem costly. The 3 values correspond respectively to policy used for cell comparison (see MEDCouplingUMesh::zipConnectivityTraducer to have more details) * - 1 for fast 'equality'. This is a lazy level. Just number of cells and number of nodes are considered here and 3 cells (begin,middle,end) * - 2 for deep 'equality' as 0 option except that no control is done on all strings in mesh. + * + * So the most strict level of check is 0 (equality). The least strict is 12. If the level of check 12 throws, the 2 meshes \a this and \a other are not similar enough + * 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; @@ -180,37 +195,39 @@ 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; } /*! - * This method checks fastly that 'this' and 'other' are equal. All common checks are done here. + * This method checks fastly that \a this and \a other are equal. All common checks are done here. */ -void MEDCouplingMesh::checkFastEquivalWith(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception) +void MEDCouplingMesh::checkFastEquivalWith(const MEDCouplingMesh *other, double prec) const { + if(!other) + throw INTERP_KERNEL::Exception("MEDCouplingMesh::checkFastEquivalWith : input mesh is null !"); if(getMeshDimension()!=other->getMeshDimension()) throw INTERP_KERNEL::Exception("checkFastEquivalWith : Mesh dimensions are not equal !"); if(getSpaceDimension()!=other->getSpaceDimension()) @@ -220,10 +237,12 @@ void MEDCouplingMesh::checkFastEquivalWith(const MEDCouplingMesh *other, double } /*! - * This method is very poor and looks only if 'this' and '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 { + if(!other) + throw INTERP_KERNEL::Exception("MEDCouplingMesh::areCompatibleForMerge : input mesh is null !"); if(getMeshDimension()!=other->getMeshDimension()) return false; if(getSpaceDimension()!=other->getSpaceDimension()) @@ -233,13 +252,26 @@ bool MEDCouplingMesh::areCompatibleForMerge(const MEDCouplingMesh *other) const /*! * This method is equivalent to MEDCouplingMesh::buildPart method except that here the cell ids are specified using slice \a beginCellIds \a endCellIds and \a stepCellIds. + * \b WARNING , there is a big difference compared to MEDCouplingMesh::buildPart method. + * If the input range is equal all cells in \a this, \a this is returned ! + * + * \return a new ref to be managed by the caller. Warning this ref can be equal to \a this if input slice is exactly equal to the whole cells in the same order. * * \sa MEDCouplingMesh::buildPart */ -MEDCouplingMesh *MEDCouplingMesh::buildPartRange(int beginCellIds, int endCellIds, int stepCellIds) const throw(INTERP_KERNEL::Exception) +MEDCouplingMesh *MEDCouplingMesh::buildPartRange(mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds) const { - MEDCouplingAutoRefCountObjectPtr cellIds=DataArrayInt::Range(beginCellIds,endCellIds,stepCellIds); - return buildPart(cellIds->begin(),cellIds->end()); + if(beginCellIds==0 && endCellIds==getNumberOfCells() && stepCellIds==1) + { + MEDCouplingMesh *ret(const_cast(this)); + ret->incrRef(); + return ret; + } + else + { + MCAuto cellIds=DataArrayIdType::Range(beginCellIds,endCellIds,stepCellIds); + return buildPart(cellIds->begin(),cellIds->end()); + } } /*! @@ -247,14 +279,14 @@ 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 throw(INTERP_KERNEL::Exception) +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); } /*! - * This method builds a field lying on 'this' with 'nbOfComp' components. + * This method builds a field lying on \a this with 'nbOfComp' components. * 'func' is a pointer that points to a function that takes 2 arrays in parameter and returns a boolean. * The first array is a in-param of size this->getSpaceDimension and the second an out param of size 'nbOfComp'. * The return field will have type specified by 't'. 't' is also used to determine where values of field will be @@ -263,14 +295,15 @@ MEDCouplingMesh *MEDCouplingMesh::buildPartRangeAndReduceNodes(int beginCellIds, * The 'func' is a callback that takes as first parameter an input array of size 'this->getSpaceDimension()', * the second parameter is a pointer on a valid zone of size at least equal to 'nbOfComp' values. And too finish * the returned value is a boolean that is equal to False in case of invalid evaluation (log(0) for example...) - * @param t type of field returned and specifies where the evaluation of func will be done. - * @param nbOfComp number of components of returned field. - * @param func pointer to a function that should return false if the evaluation failed. (division by 0. for example) - * @return field with counter = 1. + * + * \param t type of field returned and specifies where the evaluation of func will be done. + * \param nbOfComp number of components of returned field. + * \param func pointer to a function that should return false if the evaluation failed. (division by 0. for example) + * \return field with counter = 1. */ 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(); @@ -281,8 +314,10 @@ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbO * This method copyies all tiny strings from other (name and components name). * @throw if other and this have not same mesh type. */ -void MEDCouplingMesh::copyTinyStringsFrom(const MEDCouplingMesh *other) throw(INTERP_KERNEL::Exception) +void MEDCouplingMesh::copyTinyStringsFrom(const MEDCouplingMesh *other) { + if(!other) + throw INTERP_KERNEL::Exception("MEDCouplingMesh::copyTinyStringsFrom : input mesh is null !"); _name=other->_name; _description=other->_description; _time_unit=other->_time_unit; @@ -290,14 +325,14 @@ void MEDCouplingMesh::copyTinyStringsFrom(const MEDCouplingMesh *other) throw(IN /*! * This method copies all attributes that are \b NOT arrays in this. - * All tiny attributes not usefully for state of 'this' are ignored. + * All tiny attributes not usefully for state of \a this are ignored. */ -void MEDCouplingMesh::copyTinyInfoFrom(const MEDCouplingMesh *other) throw(INTERP_KERNEL::Exception) +void MEDCouplingMesh::copyTinyInfoFrom(const MEDCouplingMesh *other) { - copyTinyStringsFrom(other); _time=other->_time; _iteration=other->_iteration; _order=other->_order; + copyTinyStringsFrom(other); } /*! @@ -305,7 +340,7 @@ void MEDCouplingMesh::copyTinyInfoFrom(const MEDCouplingMesh *other) throw(INTER * 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 @@ -336,12 +371,14 @@ void MEDCouplingMesh::copyTinyInfoFrom(const MEDCouplingMesh *other) throw(INTER * \throw If the nodal connectivity of cells is not defined. * \throw If computing \a func fails. * + * \if ENABLE_EXAMPLES * \ref cpp_mcmesh_fillFromAnalytic "Here is a C++ example".
* \ref py_mcmesh_fillFromAnalytic "Here is a Python example". + * \endif */ -MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbOfComp, const char *func) const +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(); @@ -352,9 +389,9 @@ 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 char *func) const "fillFromAnalytic()" + * \ref MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbOfComp, const std::string& func) const "fillFromAnalytic()" * by the way how variable * names, used in the function, are associated with components of coordinates of field * location points; here, a variable name corresponding to a component is retrieved from @@ -386,14 +423,16 @@ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbO * \throw If the nodal connectivity of cells is not defined. * \throw If computing \a func fails. * + * \if ENABLE_EXAMPLES * \ref cpp_mcmesh_fillFromAnalytic2 "Here is a C++ example".
* \ref py_mcmesh_fillFromAnalytic2 "Here is a Python example". + * \endif */ -MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic2(TypeOfField t, int nbOfComp, const char *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(); } @@ -402,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 @@ -437,14 +476,16 @@ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic2(TypeOfField t, int nb * \throw If the nodal connectivity of cells is not defined. * \throw If computing \a func fails. * + * \if ENABLE_EXAMPLES * \ref cpp_mcmesh_fillFromAnalytic3 "Here is a C++ example".
* \ref py_mcmesh_fillFromAnalytic3 "Here is a Python example". + * \endif */ -MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic3(TypeOfField t, int nbOfComp, const std::vector& varsOrder, const char *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(); } @@ -462,7 +503,7 @@ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic3(TypeOfField t, int nb * is no more needed. * \throw If the meshes are of different mesh type. */ -MEDCouplingMesh *MEDCouplingMesh::MergeMeshes(const MEDCouplingMesh *mesh1, const MEDCouplingMesh *mesh2) throw(INTERP_KERNEL::Exception) +MEDCouplingMesh *MEDCouplingMesh::MergeMeshes(const MEDCouplingMesh *mesh1, const MEDCouplingMesh *mesh2) { if(!mesh1) throw INTERP_KERNEL::Exception("MEDCouplingMesh::MergeMeshes : first parameter is an empty mesh !"); @@ -489,9 +530,9 @@ MEDCouplingMesh *MEDCouplingMesh::MergeMeshes(const MEDCouplingMesh *mesh1, cons * \throw If \a meshes[ *i* ]->getMeshDimension() < 0. * \throw If the \a meshes are of different dimension (getMeshDimension()). */ -MEDCouplingMesh *MEDCouplingMesh::MergeMeshes(std::vector& meshes) throw(INTERP_KERNEL::Exception) +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". - */ -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 @@ -561,8 +631,8 @@ void MEDCouplingMesh::getCellsContainingPoint(const double *pos, double eps, std * this->getSpaceDimension() * \a nbOfPoints * \param [in] nbOfPoints - number of points to locate within \a this mesh. * \param [in] eps - radius of balls (i.e. the precision). - * \param [in,out] elts - vector returning ids of found cells. - * \param [in,out] eltsIndex - an array, of length \a nbOfPoints + 1, + * \param [out] elts - vector returning ids of found cells. + * \param [out] eltsIndex - an array, of length \a nbOfPoints + 1, * dividing cell ids in \a elts into groups each referring to one * point. Its every element (except the last one) is an index pointing to the * first id of a group of cells. For example cells in contact with the *i*-th @@ -572,45 +642,108 @@ void MEDCouplingMesh::getCellsContainingPoint(const double *pos, double eps, std * Number of cells in contact with the *i*-th point is * \a eltsIndex[ *i*+1 ] - \a eltsIndex[ *i* ]. * + * \if ENABLE_EXAMPLES * \ref cpp_mcumesh_getCellsContainingPoints "Here is a C++ example".
* \ref py_mcumesh_getCellsContainingPoints "Here is a Python example". + * \endif */ -void MEDCouplingMesh::getCellsContainingPoints(const double *pos, int nbOfPoints, double eps, std::vector& elts, std::vector& eltsIndex) const -{ - eltsIndex.resize(nbOfPoints+1); - eltsIndex[0]=0; - elts.clear(); - int spaceDim=getSpaceDimension(); - const double *work=pos; - for(int i=0;i& elts, MCAuto& eltsIndex) const +{ + 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(mcIdType i=0;i=0) - { - elts.push_back(ret); - eltsIndex[i+1]=eltsIndex[i]+1; - } - else - eltsIndex[i+1]=eltsIndex[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 char *fileName) const throw(INTERP_KERNEL::Exception) +std::string MEDCouplingMesh::writeVTK(const std::string& fileName, bool isBinary) const { + std::string ret(getVTKFileNameOf(fileName)); + // std::string cda,pda; - writeVTKAdvanced(fileName,cda,pda); + MCAuto byteArr; + if(isBinary) + { byteArr=DataArrayByte::New(); byteArr->alloc(0,1); } + 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 char *fileName, const std::string& cda, const std::string& pda) const throw(INTERP_KERNEL::Exception) +/// @cond INTERNAL +void MEDCouplingMesh::writeVTKAdvanced(const std::string& fileName, const std::string& cda, const std::string& pda, DataArrayByte *byteData) const { - std::ofstream ofs(fileName); - ofs << "\n"; - writeVTKLL(ofs,cda,pda); - ofs << "\n"; - ofs.close(); + std::ofstream ofs(fileName.c_str()); + ofs << "\n"; + writeVTKLL(ofs,cda,pda,byteData); + if(byteData) + { + ofs << "\n_1234"; + ofs << std::flush; ofs.close(); + std::ofstream ofs2(fileName.c_str(),std::ios_base::binary | std::ios_base::app); + ofs2.write(byteData->begin(),byteData->getNbOfElems()); ofs2 << std::flush; ofs2.close(); + std::ofstream ofs3(fileName.c_str(),std::ios_base::app); ofs3 << "\n\n\n"; ofs3.close(); + } + else + { + ofs << "\n"; + 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