From f67dc0817fad8a24d547e09fdab9c36e280cd378 Mon Sep 17 00:00:00 2001 From: vsr Date: Fri, 12 Apr 2013 14:19:18 +0000 Subject: [PATCH] Merge from V6_main 12/04/2013 --- doc/doxygen/fakesources/MEDCouplingMemArray.C | 5 + doc/doxygen/fakesources/MEDCouplingMesh.C | 178 + doc/doxygen/fakesources/MEDCouplingUMesh.C | 343 + doc/doxygen/medcoupling.dox | 4 +- doc/doxygen/medcouplingexamples.doxy | 620 +- src/INTERP_KERNEL/BBTreePts.txx | 13 +- src/MEDCoupling/MEDCouplingCMesh.cxx | 133 +- .../MEDCouplingCurveLinearMesh.cxx | 34 +- src/MEDCoupling/MEDCouplingExtrudedMesh.cxx | 2 +- src/MEDCoupling/MEDCouplingField.cxx | 70 +- src/MEDCoupling/MEDCouplingField.hxx | 2 + .../MEDCouplingFieldDiscretization.cxx | 436 +- .../MEDCouplingFieldDiscretization.hxx | 24 +- src/MEDCoupling/MEDCouplingFieldDouble.cxx | 464 +- src/MEDCoupling/MEDCouplingFieldDouble.hxx | 12 +- src/MEDCoupling/MEDCouplingFieldTemplate.cxx | 42 +- src/MEDCoupling/MEDCouplingFieldTemplate.hxx | 1 + .../MEDCouplingGaussLocalization.cxx | 32 + .../MEDCouplingGaussLocalization.hxx | 5 + src/MEDCoupling/MEDCouplingMemArray.cxx | 232 +- src/MEDCoupling/MEDCouplingMemArray.hxx | 15 +- src/MEDCoupling/MEDCouplingMemArrayChar.cxx | 148 +- src/MEDCoupling/MEDCouplingMesh.cxx | 265 +- src/MEDCoupling/MEDCouplingMesh.hxx | 2 + src/MEDCoupling/MEDCouplingNatureOfField.cxx | 29 +- src/MEDCoupling/MEDCouplingNatureOfField.hxx | 2 + src/MEDCoupling/MEDCouplingPointSet.cxx | 54 +- src/MEDCoupling/MEDCouplingPointSet.hxx | 2 + src/MEDCoupling/MEDCouplingStructuredMesh.cxx | 39 + .../MEDCouplingTimeDiscretization.cxx | 254 +- .../MEDCouplingTimeDiscretization.hxx | 12 + src/MEDCoupling/MEDCouplingUMesh.cxx | 1566 ++- src/MEDCoupling/MEDCouplingUMesh.hxx | 2 +- src/MEDCoupling/MEDCouplingUMeshDesc.cxx | 2 +- .../Test/MEDCouplingBasicsTest4.cxx | 20 +- .../Test/MEDCouplingExamplesTest.cxx | 1303 ++- src/MEDCoupling_Swig/CMakeLists.txt | 3 +- src/MEDCoupling_Swig/MEDCoupling.i | 3 + src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 657 +- src/MEDCoupling_Swig/MEDCouplingCommon.i | 8822 ++++------------- .../MEDCouplingDataForTest.py | 4 +- .../MEDCouplingExamplesTest.py | 979 +- src/MEDCoupling_Swig/MEDCouplingFinalize.i | 2 + src/MEDCoupling_Swig/MEDCouplingMemArray.i | 5561 +++++++++++ src/MEDCoupling_Swig/MEDCouplingRemapper.i | 3 + src/MEDCoupling_Swig/MEDCouplingTypemaps.i | 280 +- src/MEDCoupling_Swig/Makefile.am | 4 +- src/MEDLoader/MEDFileField.cxx | 4 + src/MEDLoader/MEDFileMesh.cxx | 5 +- src/MEDLoader/MEDLoader.cxx | 148 +- src/MEDLoader/MEDLoader.hxx | 2 +- src/MEDLoader/SauvMedConvertor.cxx | 15 +- src/MEDLoader/SauvWriter.cxx | 18 +- src/MEDLoader/Swig/MEDLoader.i | 3 + src/MEDLoader/Swig/MEDLoaderCommon.i | 4 +- src/MEDLoader/Swig/MEDLoaderTest3.py | 12 + src/MEDLoader/Test/SauvLoaderTest.cxx | 89 +- src/MEDLoader/Test/SauvLoaderTest.hxx | 2 + src/ParaMEDMEM_Swig/ParaMEDMEM.i | 3 + 59 files changed, 15242 insertions(+), 7748 deletions(-) create mode 100644 doc/doxygen/fakesources/MEDCouplingMesh.C create mode 100644 doc/doxygen/fakesources/MEDCouplingUMesh.C create mode 100644 src/MEDCoupling_Swig/MEDCouplingMemArray.i diff --git a/doc/doxygen/fakesources/MEDCouplingMemArray.C b/doc/doxygen/fakesources/MEDCouplingMemArray.C index 78eb90726..1756efd3a 100644 --- a/doc/doxygen/fakesources/MEDCouplingMemArray.C +++ b/doc/doxygen/fakesources/MEDCouplingMemArray.C @@ -17,6 +17,11 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// This file contains some code used only for +// * generation of documentation for inline methods of DataArray* classes +// * groupping methods into "Basic API", "Advanced" and "Others..." sections + + namespace ParaMEDMEM { /*! diff --git a/doc/doxygen/fakesources/MEDCouplingMesh.C b/doc/doxygen/fakesources/MEDCouplingMesh.C new file mode 100644 index 000000000..ac6f20661 --- /dev/null +++ b/doc/doxygen/fakesources/MEDCouplingMesh.C @@ -0,0 +1,178 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// This file contains some code used only for +// * generation of documentation for inline methods of DataArray* classes +// * groupping methods into "Basic API", "Advanced" and "Others..." sections + + +namespace ParaMEDMEM +{ + //================================================================================ + /*! + * Checks if \a this and another MEDCouplingMesh are equal without considering + * textual data like mesh name, names of spatial components etc. + * \param [in] other - an instance of MEDCouplingMesh to compare with \a this one. + * \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::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const {} + + /*! + * Checks if \a this and \a other meshes are geometrically equivalent, else an + * exception is thrown. The meshes are + * considered equivalent if (1) \a this mesh contains the same nodes as the \a other + * mesh (with a specified precision) and (2) \a this mesh contains the same cells as + * the \a other mesh (with use of a specified cell comparison technique). The mapping + * from \a other to \a this for nodes and cells is returned via out parameters. + * \param [in] other - the mesh to compare with. + * \param [in] cellCompPol - id [0-2] of cell comparison method. See meaning of + * each method in description of MEDCouplingUMesh::zipConnectivityTraducer(). + * \param [in] prec - the precision used to compare nodes of the two meshes. + * \param [out] cellCor - a cell permutation array in "Old to New" mode. The caller is + * to delete this array using decrRef() as it is no more needed. + * \param [out] nodeCor - a node permutation array in "Old to New" mode. The caller is + * to delete this array using decrRef() as it is no more needed. + * \throw If the two meshes do not match. + */ + void MEDCouplingMesh::checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec,DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception) {} + + /*! + * Checks if \a this and \a other meshes are geometrically equivalent, else an + * exception is thrown. The meshes are considered equivalent if (1) they share the same + * node coordinates array(s) and (2) they contain the same cells (with use of a specified + * cell comparison technique). The mapping from cells of the \a other to ones of \a this + * is returned via an out parameter. + * \param [in] other - the mesh to compare with. + * \param [in] cellCompPol - id [0-2] of cell comparison method. See the meaning of + * each method in description of MEDCouplingUMesh::zipConnectivityTraducer(). + * \param [in] prec - a not used parameter. + * \param [out] cellCor - the permutation array in "Old to New" mode. The caller is + * to delete this array using decrRef() as it is no more needed. + * \throw If the two meshes do not match. + */ + void MEDCouplingMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec,DataArrayInt *&cellCor) const throw(INTERP_KERNEL::Exception) {} +} + +namespace ParaMEDMEM +{ +//================================================================================ +/////////////////////// GROUPPING members of MEDCouplingMesh ///////////////////// +//================================================================================ +/*! \name Basic API */ +///@{ + MEDCouplingMesh::MergeMeshes(const MEDCouplingMesh *mesh1, const MEDCouplingMesh *mesh2); + MEDCouplingMesh::MergeMeshes(std::vector& meshes); + MEDCouplingMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec,DataArrayInt *&cellCor) const; + MEDCouplingMesh::checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec,DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const; + MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbOfComp, FunctionToEvaluate func) const; + MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbOfComp, const char *func) const; + MEDCouplingMesh::fillFromAnalytic2(TypeOfField t, int nbOfComp, const char *func) const; + MEDCouplingMesh::fillFromAnalytic3(TypeOfField t, int nbOfComp, const std::vector& varsOrder, const char *func) const; + MEDCouplingMesh::getCellsContainingPoint(const double *pos, double eps, std::vector& elts) const; + MEDCouplingMesh::getCellsContainingPoints(const double *pos, int nbOfPoints, double eps, std::vector& elts, std::vector& eltsIndex) const; + MEDCouplingMesh::isEqual(const MEDCouplingMesh *other, double prec) const; + MEDCouplingMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const = 0; + MEDCouplingMesh::writeVTK(const char *fileName) const; +///@} + +/*! \name Advanced API */ +///@{ + MEDCouplingMesh::getCellIdsFullyIncludedInNodeIds(const int *partBg, const int *partEnd) const; +///@} + +/*! \name Others... */ +///@{ + MEDCouplingMesh::GetDimensionOfGeometricType(INTERP_KERNEL::NormalizedCellType type); + MEDCouplingMesh::GetReprOfGeometricType(INTERP_KERNEL::NormalizedCellType type); + MEDCouplingMesh::MEDCouplingMesh(); + MEDCouplingMesh::~MEDCouplingMesh(); + MEDCouplingMesh::MEDCouplingMesh(const MEDCouplingMesh& other); + MEDCouplingMesh::advancedRepr() const = 0; + MEDCouplingMesh::areCompatibleForMerge(const MEDCouplingMesh *other) const; + MEDCouplingMesh::buildOrthogonalField() const = 0; + MEDCouplingMesh::buildPart(const int *start, const int *end) const = 0; + MEDCouplingMesh::buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const = 0; + MEDCouplingMesh::buildUnstructured() const; + MEDCouplingMesh::checkCoherency() const; + MEDCouplingMesh::checkCoherency1(double eps=1e-12) const; + MEDCouplingMesh::checkCoherency2(double eps=1e-12) const; + MEDCouplingMesh::checkFastEquivalWith(const MEDCouplingMesh *other, double prec) const; + MEDCouplingMesh::checkGeoEquivalWith(const MEDCouplingMesh *other, int levOfCheck, double prec,DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const; + MEDCouplingMesh::checkTypeConsistencyAndContig(const std::vector& code, const std::vector& idsPerType) const; + MEDCouplingMesh::computeIsoBarycenterOfNodesPerCell() const; + MEDCouplingMesh::computeNbOfNodesPerCell() const; + MEDCouplingMesh::copyTinyInfoFrom(const MEDCouplingMesh *other); + MEDCouplingMesh::copyTinyStringsFrom(const MEDCouplingMesh *other); + MEDCouplingMesh::deepCpy() const = 0; + MEDCouplingMesh::getAllGeoTypes() const = 0; + MEDCouplingMesh::getBarycenterAndOwner() const = 0; + MEDCouplingMesh::getBoundingBox(double *bbox) const = 0; + MEDCouplingMesh::getCellContainingPoint(const double *pos, double eps) const = 0; + MEDCouplingMesh::getCoordinatesAndOwner() const = 0; + MEDCouplingMesh::getCoordinatesOfNode(int nodeId, std::vector& coo) const; + MEDCouplingMesh::getDescription() const; + MEDCouplingMesh::getDistributionOfTypes() const; + MEDCouplingMesh::getHeapMemorySize() const; + MEDCouplingMesh::getMeasureField(bool isAbs) const = 0; + MEDCouplingMesh::getMeasureFieldOnNode(bool isAbs) const = 0; + MEDCouplingMesh::getMeshDimension() const = 0; + MEDCouplingMesh::getName() const; + MEDCouplingMesh::getNodeIdsOfCell(int cellId, std::vector& conn) const = 0; + MEDCouplingMesh::getNumberOfCells() const = 0; + MEDCouplingMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const = 0; + MEDCouplingMesh::getNumberOfNodes() const = 0; + MEDCouplingMesh::getSpaceDimension() const = 0; + MEDCouplingMesh::getTime(int& iteration, int& order) const; + MEDCouplingMesh::getTimeUnit() const; + MEDCouplingMesh::getTinySerializationInformation(std::vector& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const = 0; + MEDCouplingMesh::getType() const = 0; + MEDCouplingMesh::getTypeOfCell(int cellId) const = 0; + MEDCouplingMesh::getVTKDataSetType() const; + MEDCouplingMesh::giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const; + MEDCouplingMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const; + MEDCouplingMesh::isStructured() const; + MEDCouplingMesh::mergeMyselfWith(const MEDCouplingMesh *other) const = 0; + MEDCouplingMesh::renumberCells(const int *old2NewBg, bool check=true); + MEDCouplingMesh::reprQuickOverview(std::ostream& stream) const; + MEDCouplingMesh::resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const = 0; + MEDCouplingMesh::rotate(const double *center, const double *vector, double angle) = 0; + MEDCouplingMesh::scale(const double *point, double factor) = 0; + MEDCouplingMesh::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const = 0; + MEDCouplingMesh::setDescription(const char *descr); + MEDCouplingMesh::setName(const char *name); + MEDCouplingMesh::setTime(double val, int iteration, int order); + MEDCouplingMesh::setTimeUnit(const char *unit); + MEDCouplingMesh::simpleRepr() const = 0; + MEDCouplingMesh::simplexize(int policy); + MEDCouplingMesh::splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsInPflPerType, std::vector& idsPerType) const; + MEDCouplingMesh::translate(const double *vector) = 0; + MEDCouplingMesh::unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2,const std::vector& littleStrings) = 0; + MEDCouplingMesh::writeVTKAdvanced(const char *fileName, const std::string& cda, const std::string& pda) const; + MEDCouplingMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const; + MEDCouplingMesh::_description; + MEDCouplingMesh::_iteration; + MEDCouplingMesh::_name; + MEDCouplingMesh::_order; + MEDCouplingMesh::_time; + MEDCouplingMesh::_time_unit; +///@} +} diff --git a/doc/doxygen/fakesources/MEDCouplingUMesh.C b/doc/doxygen/fakesources/MEDCouplingUMesh.C new file mode 100644 index 000000000..84c23f181 --- /dev/null +++ b/doc/doxygen/fakesources/MEDCouplingUMesh.C @@ -0,0 +1,343 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// This file contains some code used only for +// * generation of documentation for inline methods of MEDCouplingUMesh class, +// * groupping methods into "Basic API", "Advanced" and "Others..." sections + +namespace ParaMEDMEM +{ + /*! + * Returns the nodal connectivity array. For more info on how data in stored in + * this array, see \ref MEDCouplingUMeshAdvBuild. + * \return const DataArrayInt * - a pointer to the nodal connectivity array + * referred by \a this mesh. + */ + const DataArrayInt * MEDCouplingUMesh::getNodalConnectivity() const {} + /*! + * Returns the nodal connectivity index array. For more info on how data in stored in + * this array, see \ref MEDCouplingUMeshAdvBuild. + * \return const DataArrayInt * - a pointer to the nodal connectivity index array + * referred by \a this mesh. + */ + const DataArrayInt * MEDCouplingUMesh::getNodalConnectivityIndex() const {} + /*! + * Returns the nodal connectivity array. For more info on how data in stored in + * this array, see \ref MEDCouplingUMeshAdvBuild. + * \return const DataArrayInt * - a pointer to the nodal connectivity array + * referred by \a this mesh. + */ + DataArrayInt * MEDCouplingUMesh::getNodalConnectivity() {} + /*! + * Returns the nodal connectivity index array. For more info on how data in stored in + * this array, see \ref MEDCouplingUMeshAdvBuild. + * \return const DataArrayInt * - a pointer to the nodal connectivity index array + * referred by \a this mesh. + */ + DataArrayInt * MEDCouplingUMesh::getNodalConnectivityIndex() {} +} + +namespace ParaMEDMEM +{ +//================================================================================ +/////////////////////// MEDCouplingUMesh GROUPPING /////////////////////////////// +//================================================================================ + +/*! \name Basic API */ +///@{ +MEDCouplingUMesh::FuseUMeshesOnSameCoords(const std::vector& meshes, int compType, std::vector& corr); +MEDCouplingUMesh::Intersect2DMeshes(const MEDCouplingUMesh *m1, const MEDCouplingUMesh *m2, double eps, DataArrayInt *&cellNb1, DataArrayInt *&cellNb2); +MEDCouplingUMesh::MergeNodesOnUMeshesSharingSameCoords(const std::vector& meshes, double eps); +MEDCouplingUMesh::MergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2); +MEDCouplingUMesh::MergeUMeshes(std::vector& a); +MEDCouplingUMesh::MergeUMeshesOnSameCoords(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2); +MEDCouplingUMesh::MergeUMeshesOnSameCoords(const std::vector& meshes); +MEDCouplingUMesh::PutUMeshesOnSameAggregatedCoords(const std::vector& meshes); +MEDCouplingUMesh::allocateCells(int nbOfCells); +MEDCouplingUMesh::are2DCellsNotCorrectlyOriented(const double *vec, bool polyOnly, std::vector& cells) const; +MEDCouplingUMesh::areCellsIncludedIn(const MEDCouplingUMesh *other, int compType, DataArrayInt *& arr) const; +MEDCouplingUMesh::arePolyhedronsNotCorrectlyOriented(std::vector& cells) const; +MEDCouplingUMesh::buildBoundaryMesh(bool keepCoords) const; +MEDCouplingUMesh::buildDescendingConnectivity(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const; +MEDCouplingUMesh::buildDescendingConnectivity2(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const; +MEDCouplingUMesh::buildDirectionVectorField() const; +MEDCouplingUMesh::buildFacePartOfMySelfNode(const int *begin, const int *end, bool fullyIn) const; +MEDCouplingUMesh::buildOrthogonalField() const; +MEDCouplingUMesh::buildPartOfMySelf(const int *begin, const int *end, bool keepCoords=true) const; +MEDCouplingUMesh::buildPartOfMySelfNode(const int *begin, const int *end, bool fullyIn) const; +MEDCouplingUMesh::buildPartOrthogonalField(const int *begin, const int *end) const; +MEDCouplingUMesh::buildSlice3D(const double *origin, const double *vec, double eps, DataArrayInt *&cellIds) const; +MEDCouplingUMesh::buildSlice3DSurf(const double *origin, const double *vec, double eps, DataArrayInt *&cellIds) const; +MEDCouplingUMesh::checkCoherency() const; +MEDCouplingUMesh::checkCoherency1(double eps=1e-12) const; +MEDCouplingUMesh::checkCoherency2(double eps=1e-12) const; +MEDCouplingUMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec,DataArrayInt *&cellCor) const; +MEDCouplingUMesh::checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec,DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const; +MEDCouplingUMesh::checkFastEquivalWith(const MEDCouplingMesh *other, double prec) const; +MEDCouplingUMesh::clone(bool recDeepCpy) const; +MEDCouplingUMesh::computeIsoBarycenterOfNodesPerCell() const; +MEDCouplingUMesh::convertAllToPoly(); +MEDCouplingUMesh::convertQuadraticCellsToLinear(); +MEDCouplingUMesh::convertToPolyTypes(const int *cellIdsToConvertBg, const int *cellIdsToConvertEnd); +MEDCouplingUMesh::deepCpy() const; +MEDCouplingUMesh::findAndCorrectBadOriented3DExtrudedCells(); +MEDCouplingUMesh::findBoundaryNodes() const; +MEDCouplingUMesh::finishInsertingCells(); +MEDCouplingUMesh::getAllGeoTypes() const; +MEDCouplingUMesh::getAspectRatioField() const; +MEDCouplingUMesh::getBarycenterAndOwner() const; +MEDCouplingUMesh::getCellContainingPoint(const double *pos, double eps) const; +MEDCouplingUMesh::getCellIdsCrossingPlane(const double *origin, const double *vec, double eps) const; +MEDCouplingUMesh::getCellIdsFullyIncludedInNodeIds(const int *partBg, const int *partEnd) const; +MEDCouplingUMesh::getCellIdsLyingOnNodes(const int *begin, const int *end, bool fullyIn) const; +MEDCouplingUMesh::getCellsContainingPoint(const double *pos, double eps, std::vector& elts) const; +MEDCouplingUMesh::getCellsContainingPoints(const double *pos, int nbOfPoints, double eps, std::vector& elts, std::vector& eltsIndex) const; +MEDCouplingUMesh::getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps); +MEDCouplingUMesh::getCellsInBoundingBox(const double *bbox, double eps) const; +MEDCouplingUMesh::getEdgeRatioField() const; +MEDCouplingUMesh::getMeasureField(bool isAbs) const; +MEDCouplingUMesh::getMeasureFieldOnNode(bool isAbs) const; +MEDCouplingUMesh::getMeshDimension() const; +MEDCouplingUMesh::getNodalConnectivity() const; +MEDCouplingUMesh::getNodalConnectivity(); +MEDCouplingUMesh::getNodalConnectivityIndex() const; +MEDCouplingUMesh::getNodalConnectivityIndex(); +MEDCouplingUMesh::getNodeIdsInUse(int& nbrOfNodesInUse) const; +MEDCouplingUMesh::getNodeIdsOfCell(int cellId, std::vector& conn) const; +MEDCouplingUMesh::getNumberOfCells() const; +MEDCouplingUMesh::getPartBarycenterAndOwner(const int *begin, const int *end) const; +MEDCouplingUMesh::getPartMeasureField(bool isAbs, const int *begin, const int *end) const; +MEDCouplingUMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const; +MEDCouplingUMesh::getSkewField() const; +MEDCouplingUMesh::getTypeOfCell(int cellId) const; +MEDCouplingUMesh::getTypesOfPart(const int *begin, const int *end) const; +MEDCouplingUMesh::getWarpField() const; +MEDCouplingUMesh::insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, const int *nodalConnOfCell); +MEDCouplingUMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const; +MEDCouplingUMesh::mergeNodes(double precision, bool& areNodesMerged, int& newNbOfNodes); +MEDCouplingUMesh::mergeNodes2(double precision, bool& areNodesMerged, int& newNbOfNodes); +MEDCouplingUMesh::orientCorrectly2DCells(const double *vec, bool polyOnly); +MEDCouplingUMesh::orientCorrectlyPolyhedrons(); +MEDCouplingUMesh::renumberNodes(const int *newNodeNumbers, int newNbOfNodes); +MEDCouplingUMesh::renumberNodes2(const int *newNodeNumbers, int newNbOfNodes); +MEDCouplingUMesh::renumberNodesInConn(const int *newNodeNumbersO2N); +MEDCouplingUMesh::reprQuickOverview(std::ostream& stream) const; +MEDCouplingUMesh::setConnectivity(DataArrayInt *conn, DataArrayInt *connIndex, bool isComputingTypes=true); +MEDCouplingUMesh::setMeshDimension(int meshDim); +MEDCouplingUMesh::sortCellsInMEDFileFrmt(); +MEDCouplingUMesh::tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon); +MEDCouplingUMesh::unPolyze(); +MEDCouplingUMesh::zipConnectivityTraducer(int compType, int startCellId=0); +MEDCouplingUMesh::zipCoordsTraducer(); + ///@} + + /*! \name Advanced API */ +///@{ +MEDCouplingUMesh::areOnlySimplexCells() const; +MEDCouplingUMesh::checkButterflyCells(std::vector& cells, double eps=1e-12) const; +MEDCouplingUMesh::computeTypes(); +MEDCouplingUMesh::convertDegeneratedCells(); +MEDCouplingUMesh::convertExtrudedPolyhedra(); +MEDCouplingUMesh::getMeshLength() const; +MEDCouplingUMesh::isFullyQuadratic() const; +MEDCouplingUMesh::isPresenceOfQuadratic() const; +MEDCouplingUMesh::simplexize(int policy); +MEDCouplingUMesh::tessellate2D(double eps); +MEDCouplingUMesh::tessellate2DCurve(double eps); + ///@ + +/*! \name Others... */ +///@{ +MEDCouplingUMesh::AggregateSortedByTypeMeshesOnSameCoords(const std::vector& ms,DataArrayInt *&szOfCellGrpOfSameType,DataArrayInt *&idInMsOfCellGrpOfSameType); +MEDCouplingUMesh::AppendExtrudedCell(const int *connBg, const int *connEnd, int nbOfNodesPerLev, bool isQuad, std::vector& ret); +MEDCouplingUMesh::AreCellsEqual(const int *conn, const int *connI, int cell1, int cell2, int compType); +MEDCouplingUMesh::AreCellsEqual0(const int *conn, const int *connI, int cell1, int cell2); +MEDCouplingUMesh::AreCellsEqual1(const int *conn, const int *connI, int cell1, int cell2); +MEDCouplingUMesh::AreCellsEqual2(const int *conn, const int *connI, int cell1, int cell2); +MEDCouplingUMesh::AreCellsEqual3(const int *conn, const int *connI, int cell1, int cell2); +MEDCouplingUMesh::AreCellsEqual7(const int *conn, const int *connI, int cell1, int cell2); +MEDCouplingUMesh::AreCellsEqualInPool(const std::vector& candidates, int compType, const int *conn, const int *connI, DataArrayInt *result) ; +MEDCouplingUMesh::AssemblyForSplitFrom3DCurve(const std::vector& cut3DCurve, std::vector& nodesOnPlane, const int *nodal3DSurf, const int *nodalIndx3DSurf,const int *nodal3DCurve, const int *nodalIndx3DCurve,const int *desc, const int *descIndx, std::vector< std::pair >& cut3DSurf); +MEDCouplingUMesh::Build0DMeshFromCoords(DataArrayDouble *da); +MEDCouplingUMesh::BuildConvexEnvelopOf2DCellJarvis(const double *coords, const int *nodalConnBg, const int *nodalConnEnd, DataArrayInt *nodalConnecOut); +MEDCouplingUMesh::BuildIntersectEdges(const MEDCouplingUMesh *m1, const MEDCouplingUMesh *m2, const std::vector& addCoo, const std::vector< std::vector >& subDiv, std::vector< std::vector >& intersectEdge); +MEDCouplingUMesh::BuildIntersecting2DCellsFromEdges(double eps, const MEDCouplingUMesh *m1, const int *desc1, const int *descIndx1, const std::vector >& intesctEdges1, const std::vector< std::vector >& colinear2,const MEDCouplingUMesh *m2, const int *desc2, const int *descIndx2, const std::vector >& intesctEdges2,const std::vector& addCoords,std::vector& addCoordsQuadratic, std::vector& cr, std::vector& crI, std::vector& cNb1, std::vector& cNb2); +MEDCouplingUMesh::ComputeNeighborsOfCellsAdv(const DataArrayInt *desc, const DataArrayInt *descI, const DataArrayInt *revDesc, const DataArrayInt *revDescI,DataArrayInt *&neighbors, DataArrayInt *&neighborsIdx); +MEDCouplingUMesh::ComputeRangesFromTypeDistribution(const std::vector& code); +MEDCouplingUMesh::ComputeSpreadZoneGradually(const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn); +MEDCouplingUMesh::ComputeSpreadZoneGraduallyFromSeed(const int *seedBg, const int *seedEnd, const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn, int nbOfDepthPeeling, int& nbOfDepthPeelingPerformed); +MEDCouplingUMesh::ComputeSpreadZoneGraduallyFromSeedAlg(std::vector& fetched, const int *seedBg, const int *seedEnd, const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn, int nbOfDepthPeeling, int& nbOfDepthPeelingPerformed); +MEDCouplingUMesh::ComputeVecAndPtOfFace(double eps, const double *coords, const int *begin, const int *end, double *v, double *p); +MEDCouplingUMesh::CorrectExtrudedCell(int *begin, int *end); +MEDCouplingUMesh::CorrectExtrudedStaticCell(int *begin, int *end); +MEDCouplingUMesh::ExtractFromIndexedArrays(const int *idsOfSelectBg, const int *idsOfSelectEnd, const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn,DataArrayInt* &arrOut, DataArrayInt* &arrIndexOut); +MEDCouplingUMesh::FillInCompact3DMode(int spaceDim, int nbOfNodesInCell, const int *conn, const double *coo, double *zipFrmt); +MEDCouplingUMesh::FindCommonCellsAlg(int compType, int startCellId, const DataArrayInt *nodal, const DataArrayInt *nodalI, const DataArrayInt *revNodal, const DataArrayInt *revNodalI,DataArrayInt *& commonCellsArr, DataArrayInt *& commonCellsIArr); +MEDCouplingUMesh::IntersectDescending2DMeshes(const MEDCouplingUMesh *m1, const MEDCouplingUMesh *m2, double eps,std::vector< std::vector >& intersectEdge1, std::vector< std::vector >& colinear2, std::vector< std::vector >& subDiv2,MEDCouplingUMesh *& m1Desc, DataArrayInt *&desc1, DataArrayInt *&descIndx1, DataArrayInt *&revDesc1, DataArrayInt *&revDescIndx1,MEDCouplingUMesh *& m2Desc, DataArrayInt *&desc2, DataArrayInt *&descIndx2, DataArrayInt *&revDesc2, DataArrayInt *&revDescIndx2,std::vector& addCoo); +MEDCouplingUMesh::Is3DExtrudedCellWellOriented(const int *begin, const int *end, const double *coords); +MEDCouplingUMesh::Is3DExtrudedStaticCellWellOriented(const int *begin, const int *end, const double *coords); +MEDCouplingUMesh::IsPolygonWellOriented(bool isQuadratic, const double *vec, const int *begin, const int *end, const double *coords); +MEDCouplingUMesh::IsPolyhedronWellOriented(const int *begin, const int *end, const double *coords); +MEDCouplingUMesh::IsPyra5WellOriented(const int *begin, const int *end, const double *coords); +MEDCouplingUMesh::IsTetra4WellOriented(const int *begin, const int *end, const double *coords); +MEDCouplingUMesh::MEDCouplingUMesh(); +MEDCouplingUMesh::MEDCouplingUMesh(const MEDCouplingUMesh& other, bool deepCopy); +MEDCouplingUMesh::MergeUMeshesLL(std::vector& a); +MEDCouplingUMesh::New(); +MEDCouplingUMesh::New(const char *meshName, int meshDim); +MEDCouplingUMesh::RemoveIdsFromIndexedArrays(const int *idsToRemoveBg, const int *idsToRemoveEnd, DataArrayInt *arr, DataArrayInt *arrIndx, int offsetForRemoval=0); +MEDCouplingUMesh::SetPartOfIndexedArrays(const int *idsOfSelectBg, const int *idsOfSelectEnd, const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn,const DataArrayInt *srcArr, const DataArrayInt *srcArrIndex,DataArrayInt* &arrOut, DataArrayInt* &arrIndexOut); +MEDCouplingUMesh::SetPartOfIndexedArrays2(int start, int end, int step, const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn,const DataArrayInt *srcArr, const DataArrayInt *srcArrIndex,DataArrayInt* &arrOut, DataArrayInt* &arrIndexOut); +MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx(const int *idsOfSelectBg, const int *idsOfSelectEnd, DataArrayInt *arrInOut, const DataArrayInt *arrIndxIn,const DataArrayInt *srcArr, const DataArrayInt *srcArrIndex); +MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx2(int start, int end, int step, DataArrayInt *arrInOut, const DataArrayInt *arrIndxIn,const DataArrayInt *srcArr, const DataArrayInt *srcArrIndex); +MEDCouplingUMesh::SimplifyPolyhedronCell(double eps, const DataArrayDouble *coords, const int *begin, const int *end, DataArrayInt *res); +MEDCouplingUMesh::TryToCorrectPolyhedronOrientation(int *begin, int *end, const double *coords); +MEDCouplingUMesh::advancedRepr() const; +MEDCouplingUMesh::areCellsFrom2MeshEqual(const MEDCouplingUMesh *other, int cellId, double prec) const; +MEDCouplingUMesh::areCellsIncludedIn2(const MEDCouplingUMesh *other, DataArrayInt *& arr) const; +MEDCouplingUMesh::assemblyForSplitFrom3DSurf(const std::vector< std::pair >& cut3DSurf,const int *desc, const int *descIndx, DataArrayInt *nodalRes, DataArrayInt *nodalResIndx, DataArrayInt *cellIds) const; +MEDCouplingUMesh::buildExtrudedMesh(const MEDCouplingUMesh *mesh1D, int policy); +MEDCouplingUMesh::buildExtrudedMeshFromThisLowLev(int nbOfNodesOf1Lev, bool isQuad) const; +MEDCouplingUMesh::buildPartOfMySelf2(int start, int end, int step, bool keepCoords=true) const; +MEDCouplingUMesh::buildPartOfMySelfKeepCoords(const int *begin, const int *end) const; +MEDCouplingUMesh::buildPartOfMySelfKeepCoords2(int start, int end, int step) const; +MEDCouplingUMesh::buildSetInstanceFromThis(int spaceDim) const; +MEDCouplingUMesh::buildSpreadZonesWithPoly() const; +MEDCouplingUMesh::buildUnionOf2DMesh() const; +MEDCouplingUMesh::buildUnionOf3DMesh() const; +MEDCouplingUMesh::buildUnstructured() const; +MEDCouplingUMesh::cellIterator(); +MEDCouplingUMesh::cellsByType(); +MEDCouplingUMesh::checkConnectivityFullyDefined() const; +MEDCouplingUMesh::checkConsecutiveCellTypes() const; +MEDCouplingUMesh::checkConsecutiveCellTypesAndOrder(const INTERP_KERNEL::NormalizedCellType *orderBg, const INTERP_KERNEL::NormalizedCellType *orderEnd) const; +MEDCouplingUMesh::checkConsecutiveCellTypesForMEDFileFrmt() const; +MEDCouplingUMesh::checkFullyDefined() const; +MEDCouplingUMesh::checkTypeConsistencyAndContig(const std::vector& code, const std::vector& idsPerType) const; +MEDCouplingUMesh::computeFetchedNodeIds() const; +MEDCouplingUMesh::computeNbOfNodesPerCell() const; +MEDCouplingUMesh::computeNeighborsOfCells(DataArrayInt *&neighbors, DataArrayInt *&neighborsIdx) const; +MEDCouplingUMesh::computeNodeIdsAlg(std::vector& nodeIdsInUse) const; +MEDCouplingUMesh::computeSkin() const; +MEDCouplingUMesh::convertCellArrayPerGeoType(const DataArrayInt *da) const; +MEDCouplingUMesh::convertLinearCellsToQuadratic(int conversionType=0); +MEDCouplingUMesh::convertLinearCellsToQuadratic1D0(DataArrayInt *&conn, DataArrayInt *&connI, DataArrayDouble *& coords, std::set& types) const; +MEDCouplingUMesh::convertLinearCellsToQuadratic2D0(DataArrayInt *&conn, DataArrayInt *&connI, DataArrayDouble *& coords, std::set& types) const; +MEDCouplingUMesh::convertLinearCellsToQuadratic2D1(DataArrayInt *&conn, DataArrayInt *&connI, DataArrayDouble *& coords, std::set& types) const; +MEDCouplingUMesh::convertLinearCellsToQuadratic2DAnd3D0(const MEDCouplingUMesh *m1D, const DataArrayInt *desc, const DataArrayInt *descI, DataArrayInt *&conn, DataArrayInt *&connI, DataArrayDouble *& coords, std::set& types) const; +MEDCouplingUMesh::convertLinearCellsToQuadratic3D0(DataArrayInt *&conn, DataArrayInt *&connI, DataArrayDouble *& coords, std::set& types) const; +MEDCouplingUMesh::convertLinearCellsToQuadratic3D1(DataArrayInt *&conn, DataArrayInt *&connI, DataArrayDouble *& coords, std::set& types) const; +MEDCouplingUMesh::convexEnvelop2D(); +MEDCouplingUMesh::cppRepr() const; +MEDCouplingUMesh::distanceToPoint(const double *ptBg, const double *ptEnd, int& cellId, int& nodeId) const; +MEDCouplingUMesh::distanceToPoint2DCurveAlg(const double *pt, const DataArrayInt *cellIds, double& ret0, int& cellId) const; +MEDCouplingUMesh::distanceToPoint3DSurfAlg(const double *pt, const DataArrayInt *cellIds, double& ret0, int& cellId) const; +MEDCouplingUMesh::duplicateNodes(const int *nodeIdsToDuplicateBg, const int *nodeIdsToDuplicateEnd); +MEDCouplingUMesh::duplicateNodesInConn(const int *nodeIdsToDuplicateBg, const int *nodeIdsToDuplicateEnd, int offset); +MEDCouplingUMesh::emulateMEDMEMBDC(const MEDCouplingUMesh *nM1LevMesh, DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *&revDesc, DataArrayInt *&revDescIndx, DataArrayInt *& nM1LevMeshIds, DataArrayInt *&meshnM1Old2New) const; +MEDCouplingUMesh::explode3DMeshTo1D(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const; +MEDCouplingUMesh::fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, DataArrayInt *&cellIdsKeptArr) const; +MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation(const MEDCouplingUMesh *mesh1D, bool isQuad) const; +MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation2D(const MEDCouplingUMesh *mesh1D, bool isQuad) const; +MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation3D(const MEDCouplingUMesh *mesh1D, bool isQuad) const; +MEDCouplingUMesh::fillExtCoordsUsingTranslation(const MEDCouplingUMesh *mesh1D, bool isQuad) const; +MEDCouplingUMesh::findAndCorrectBadOriented3DCells(); +MEDCouplingUMesh::findCellIdsLyingOn(const MEDCouplingUMesh& otherDimM1OnSameCoords, DataArrayInt *&cellIdsRk0, DataArrayInt *&cellIdsRk1) const; +MEDCouplingUMesh::findCellIdsOnBoundary() const; +MEDCouplingUMesh::findCommonCells(int compType, int startCellId, DataArrayInt *& commonCellsArr, DataArrayInt *& commonCellsIArr) const; +MEDCouplingUMesh::findNodesToDuplicate(const MEDCouplingUMesh& otherDimM1OnSameCoords, DataArrayInt *& nodeIdsToDuplicate,DataArrayInt *& cellIdsNeededToBeRenum, DataArrayInt *& cellIdsNotModified) const; +MEDCouplingUMesh::getAllTypes() const; +MEDCouplingUMesh::getBoundingBoxForBBTree(std::vector& bbox) const; +MEDCouplingUMesh::getDistributionOfTypes() const; +MEDCouplingUMesh::getFastAveragePlaneOfThis(double *vec, double *pos) const; +MEDCouplingUMesh::getHeapMemorySize() const; +MEDCouplingUMesh::getLevArrPerCellTypes(const INTERP_KERNEL::NormalizedCellType *orderBg, const INTERP_KERNEL::NormalizedCellType *orderEnd, DataArrayInt *&nbPerType) const; +MEDCouplingUMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const; +MEDCouplingUMesh::getNumberOfNodesInCell(int cellId) const; +MEDCouplingUMesh::getQuadraticStatus() const; +MEDCouplingUMesh::getRenumArrForConsecutiveCellTypesSpec(const INTERP_KERNEL::NormalizedCellType *orderBg, const INTERP_KERNEL::NormalizedCellType *orderEnd) const; +MEDCouplingUMesh::getTinySerializationInformation(std::vector& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const; +MEDCouplingUMesh::getType() const { return UNSTRUCTURED; } +MEDCouplingUMesh::getVTKDataSetType() const; +MEDCouplingUMesh::giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const; +MEDCouplingUMesh::isContiguous1D() const; +MEDCouplingUMesh::isEmptyMesh(const std::vector& tinyInfo) const; +MEDCouplingUMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const; +MEDCouplingUMesh::keepCellIdsByType(INTERP_KERNEL::NormalizedCellType type, const int *begin, const int *end) const; +MEDCouplingUMesh::keepSpecifiedCells(INTERP_KERNEL::NormalizedCellType type, const int *idsPerGeoTypeBg, const int *idsPerGeoTypeEnd) const; +MEDCouplingUMesh::mergeMyselfWith(const MEDCouplingMesh *other) const; +MEDCouplingUMesh::partitionBySpreadZone() const; +MEDCouplingUMesh::project1D(const double *pt, const double *v, double eps, double *res) const; +MEDCouplingUMesh::rearrange2ConsecutiveCellTypes(); +MEDCouplingUMesh::renumberCells(const int *old2NewBg, bool check=true); +MEDCouplingUMesh::reprConnectivityOfThis() const; +MEDCouplingUMesh::reprConnectivityOfThisLL(std::ostringstream& stream) const; +MEDCouplingUMesh::resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const; +MEDCouplingUMesh::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const; +MEDCouplingUMesh::setPartOfMySelf(const int *cellIdsBg, const int *cellIdsEnd, const MEDCouplingUMesh& otherOnSameCoordsThanThis); +MEDCouplingUMesh::setPartOfMySelf2(int start, int end, int step, const MEDCouplingUMesh& otherOnSameCoordsThanThis); +MEDCouplingUMesh::shiftNodeNumbersInConn(int delta); +MEDCouplingUMesh::simpleRepr() const; +MEDCouplingUMesh::simplexizePlanarFace5(); +MEDCouplingUMesh::simplexizePlanarFace6(); +MEDCouplingUMesh::simplexizePol0(); +MEDCouplingUMesh::simplexizePol1(); +MEDCouplingUMesh::simplifyPolyhedra(double eps); +MEDCouplingUMesh::split3DCurveWithPlane(const double *origin, const double *vec, double eps, std::vector& cut3DCurve); +MEDCouplingUMesh::splitByType() const; +MEDCouplingUMesh::splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsInPflPerType, std::vector& idsPerType) const; +MEDCouplingUMesh::subDivide2DMesh(const int *nodeSubdived, const int *nodeIndxSubdived, const int *desc, const int *descIndex); +MEDCouplingUMesh::unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, const std::vector& littleStrings); +MEDCouplingUMesh::updateTime() const; +MEDCouplingUMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const; +MEDCouplingUMesh::~MEDCouplingUMesh(); +template MEDCouplingUMesh * MEDCouplingUMesh::buildDescendingConnectivityGen(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx, DimM1DescNbrer nbrer) const; +template void MEDCouplingUMesh::getCellsContainingPointsAlg +(const double *coords, const double *pos, int nbOfPoints,double eps, std::vector& elts, + std::vector& eltsIndex) const; + +const INTERP_KERNEL::NormalizedCellType MEDCouplingUMesh::MEDMEM_ORDER[N_MEDMEM_ORDER]; +const int MEDCouplingUMesh::N_MEDMEM_ORDER=24; +double MEDCouplingUMesh::EPS_FOR_POLYH_ORIENTATION; +int MEDCouplingUMesh::_mesh_dim; +std::set MEDCouplingUMesh::_types; +DataArrayInt * MEDCouplingUMesh::_nodal_connec; +DataArrayInt * MEDCouplingUMesh::_nodal_connec_index; + ///@} +} + diff --git a/doc/doxygen/medcoupling.dox b/doc/doxygen/medcoupling.dox index ac059fbde..70b91bf49 100644 --- a/doc/doxygen/medcoupling.dox +++ b/doc/doxygen/medcoupling.dox @@ -41,7 +41,7 @@ For beginners in \ref medcoupling "MEDCoupling" world, it is advisable to read t \section MEDCouplingMeshes Common concept shared by all type of Meshes in MEDCoupling -A mesh has a the following properties : +A mesh has the following properties : - name - **a dimension (called mesh dimension) and only one** (it implies that \b all cells constituting @@ -744,7 +744,7 @@ You can notice that it is possible to mix cell types as long as the dimension of \subpage medcouplingpyexamplesUmeshStdBuild1 "Here is the Python implementation." -\section MEDCouplingUMeshNodalConnectivity How MEDCouplingUMesh stores its nodal connectivity. +\section MEDCouplingUMeshNodalConnectivity How MEDCouplingUMesh stores its nodal connectivity \ref ParaMEDMEM::MEDCouplingUMesh "MEDCouplingUMesh class" stores its nodal connectivity into 2 arrays. diff --git a/doc/doxygen/medcouplingexamples.doxy b/doc/doxygen/medcouplingexamples.doxy index a049bca48..dfaba4afb 100644 --- a/doc/doxygen/medcouplingexamples.doxy +++ b/doc/doxygen/medcouplingexamples.doxy @@ -2,13 +2,621 @@ \page medcouplingcppexamples MEDCoupling C++ examples -\anchor cpp_mcpointset_ + +\anchor cpp_mcmesh_

-\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_ -\snippet MEDCouplingExamplesTest.py PySnippet_MEDCouplingPointSet_ -\snippet MEDCouplingExamplesTest.py Snippet_MEDCouplingPointSet_ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_ +\snippet MEDCouplingExamplesTest.py PySnippet_MEDCouplingUMesh_ +\snippet MEDCouplingExamplesTest.py Snippet_MEDCouplingUMesh_ + + +\anchor cpp_mcmesh_fillFromAnalytic3 +

Creating a field using a formular

+ +First, we create a 2D Cartesian mesh constituted by 2 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingMesh_fillFromAnalytic3_1 +Now we use +\ref ParaMEDMEM::MEDCouplingMesh::fillFromAnalytic3 "fillFromAnalytic3()" +to get a \ref ParaMEDMEM::MEDCouplingFieldDouble "MEDCouplingFieldDouble" on cells filled +with values computed using a formular \b func. This formular is applied to coordinates of +each point (barycenter) for which the field value is computed. We want to get the +field on cells, with 3 components computed as follows. (In \b func, we refer to the +first component of a point using the variable "a", and to the second component, using +the variable "b"). +- Component #0 = the second coordinate of the point; hence "IVec * b" in \b func. +- Component #1 = the first coordinate of the point; hence "JVec * a". +- Component #2 = distance between the point and SC origin (0.,0.); hence +"KVec * sqrt( a*a + b*b )". + +In addition we want to add 10.0 to each component computed as described above, hence +"10" in \b func. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingMesh_fillFromAnalytic3_2 +Now we ascertain that the result field is as we expect. We check the second tuple of +the \b field. We get barycenter of the cell #1 and checks that values of the second +tuple are computed as we want. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingMesh_fillFromAnalytic3_3 + + + +\anchor cpp_mcmesh_fillFromAnalytic2 +

Creating a field using a formular

+ +First, we create a 2D Cartesian mesh constituted by 2 cells. +Note that we set names to coordinates arrays ("a" and "b" ) which will be used to refer to +corresponding coordinates within a function. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingMesh_fillFromAnalytic2_1 +Now we use +\ref ParaMEDMEM::MEDCouplingMesh::fillFromAnalytic2 "fillFromAnalytic2()" +to get a \ref ParaMEDMEM::MEDCouplingFieldDouble "MEDCouplingFieldDouble" on cells filled +with values computed using a formular \b func. This formular is applied to coordinates of +each point (barycenter) for which the field value is computed. We want to get the +field on cells, with 3 components computed as follows. (In \b func, we refer to the +first component of a point using the variable "a", and to the second component, using +the variable "b"). +- Component #0 = the second coordinate of the point; hence "IVec * b" in \b func. +- Component #1 = the first coordinate of the point; hence "JVec * a". +- Component #2 = distance between the point and SC origin (0.,0.); hence +"KVec * sqrt( a*a + b*b )". + +In addition we want to add 10.0 to each component computed as described above, hence +"10" in \b func. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingMesh_fillFromAnalytic2_2 +Now we ascertain that the result field is as we expect. We check the second tuple of +the \b field. We get barycenter of the cell #1 and checks that values of the second +tuple are computed as we want. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingMesh_fillFromAnalytic2_3 + + +\anchor cpp_mcmesh_fillFromAnalytic +

Creating a field using a formular

+ +First, we create a 2D Cartesian mesh constituted by 2 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingMesh_fillFromAnalytic_1 +Now we use +\ref ParaMEDMEM::MEDCouplingMesh::fillFromAnalytic "fillFromAnalytic()" +to get a \ref ParaMEDMEM::MEDCouplingFieldDouble "MEDCouplingFieldDouble" on cells filled +with values computed using a formular \b func. This formular is applied to coordinates of +each point (barycenter) for which the field value is computed. We want to get the +field on cells, with 3 components computed as follows. (In \b func, we refer to the +first component of a point using the variable "a", and to the second component, using +the variable "b"). +- Component #0 = the second coordinate of the point; hence "IVec * b" in \b func. +- Component #1 = the first coordinate of the point; hence "JVec * a". +- Component #2 = distance between the point and SC origin (0.,0.); hence +"KVec * sqrt( a*a + b*b )". + +In addition we want to add 10.0 to each component computed as described above, hence +"10" in \b func. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingMesh_fillFromAnalytic_2 +Now we ascertain that the result field is as we expect. We check the second tuple of +the \b field. We get barycenter of the cell #1 and checks that values of the second +tuple are computed as we want. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingMesh_fillFromAnalytic_3 + + +\anchor cpp_mccmesh_getCoordsAt +

Getting node coordinates

+ +We create an 1D Cartesian mesh and retrieves node coordinates using +\ref ParaMEDMEM::MEDCouplingCMesh::getCoordsAt "getCoordsAt()". +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingCMesh_getCoordsAt_1 + + + +\anchor cpp_mcumesh_areCellsIncludedIn +

Cells correspondence in two meshes

+ +First, we create a 2D \b mesh1 with 3 QUAD4 and 2 TRI3 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_1 +Then we create a \b mesh2 which includes cells #4, #2 and #0 of \b mesh1. The two meshes +share the same node coordinates array. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_2 +Now we ascertain that +- \ref ParaMEDMEM::MEDCouplingUMesh::areCellsIncludedIn "areCellsIncludedIn()" +detects that all cells of \b mesh2 are present in \b mesh1, +- the correspondence array \b corr2to1, which gives cell ids of \b mesh2 within +\b mesh1, is equal to the array \b cells2 which selected cells from \b mesh1 for creation +of \b mesh2. + +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_3 +Now we apply +\ref ParaMEDMEM::MEDCouplingUMesh::areCellsIncludedIn "areCellsIncludedIn()" +in a reverse direction and ascertain that it returns \c false. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_4 +The contents of the correspondence +array \b corr1to2 [2, 3, 1, 4, 0] means the following. +- The cell #0 of \b mesh1 is equal to the cell #2 (== \b corr1to2[ 0 ]) of \b mesh2. +- The cell #1 of \b mesh1 is missing from \b mesh2 (as \b corr1to2[ 1 ] >= \b mesh2->getNumberOfCells()). +- The cell #2 of \b mesh1 is equal to the cell #1 (== \b corr1to2[ 2 ]) of \b mesh2. +- The cell #3 of \b mesh1 is missing from \b mesh2 (as \b corr1to2[ 3 ] >= \b mesh2->getNumberOfCells()). +- The cell #4 of \b mesh1 is equal to the cell #0 (== \b corr1to2[ 4 ]) of \b mesh2. + + +\anchor cpp_mcumesh_checkDeepEquivalWith +

Deep comparison of meshes

+ +First, we create two 2D meshes with two triangles, so that +- their nodes are almost same but permuted, +- the first triangle is based exactly on the same nodes (taking the permutation into account), +- an order of nodes in the second triangle is changed. + +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_1 +Then we check that +- \ref ParaMEDMEM::MEDCouplingUMesh::checkDeepEquivalWith "checkDeepEquivalWith()" +considers the meshes equal (i.e. it does not throw any exception) if it is called with a cell +comparison policy \b cellCompPol == 1 +- mapping from \b mesh1 to \b mesh2 for both nodes and cells is as expected. + +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_2 +Next we ascertain that +\ref ParaMEDMEM::MEDCouplingUMesh::checkDeepEquivalOnSameNodesWith "checkDeepEquivalOnSameNodesWith()" +consider \b mesh1 and \b mesh2 different as they do not share the same nodal connectivity +array.
+After that we make the meshes share the node coordinates array and insert new +triangles based on the same nodes but in different order. This is to ascertain that +\ref ParaMEDMEM::MEDCouplingUMesh::checkDeepEquivalOnSameNodesWith "checkDeepEquivalOnSameNodesWith()" +called with the weakest cell comparison policy considers the meshes equal. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_3 + + + +\anchor cpp_mcumesh_getPartBarycenterAndOwner +

Getting barycenters of cells

+ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getPartMeasureField_1 +Now we use +\ref ParaMEDMEM::MEDCouplingUMesh::getPartBarycenterAndOwner "getPartBarycenterAndOwner()" to get +barycenters of all but the first cell. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getPartMeasureField_3 +The returned array contains 4 tuples per 2 components. + + +\anchor cpp_mcumesh_findAndCorrectBadOriented3DExtrudedCells +

Fixing orientation of "extruded" volumes

+ +First, we create a mesh with 2 incorrectly oriented "extruded" volumes. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_1 +Now we check that +\ref ParaMEDMEM::MEDCouplingUMesh::findAndCorrectBadOriented3DExtrudedCells "findAndCorrectBadOriented3DExtrudedCells()" +finds and fixes the reversed cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_2 + + +\anchor cpp_mcumesh_arePolyhedronsNotCorrectlyOriented +

Fixing orientation of polyhedra

+ +First, we create a mesh with 2 polyhedra, one of which is incorrectly oriented. We create +two "extruded" polyhedra and then convert them to correctly defined polyhedra. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_1 +Now we check that +\ref ParaMEDMEM::MEDCouplingUMesh::arePolyhedronsNotCorrectlyOriented "arePolyhedronsNotCorrectlyOriented()" +finds one reversed cell. After that we fix it using +\ref ParaMEDMEM::MEDCouplingUMesh::orientCorrectlyPolyhedrons "orientCorrectlyPolyhedrons()" and +re-check the orientation of polyhedra. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_2 + + +\anchor cpp_mcumesh_are2DCellsNotCorrectlyOriented +

Fixing orientation of faces

+ +First, we create a 2D mesh in 3D space with 3 QUAD4 and 2 TRI3 cells. Orientation of the cell #1 is +reversed comparing with others. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_1 +Now we check that +\ref ParaMEDMEM::MEDCouplingUMesh::are2DCellsNotCorrectlyOriented "are2DCellsNotCorrectlyOriented()" +finds one reversed face. After that we fix the incorrectly oriented cell using +\ref ParaMEDMEM::MEDCouplingUMesh::orientCorrectly2DCells "orientCorrectly2DCells()" and +re-check the orientation of cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_2 + + +\anchor cpp_mcumesh_getCellsContainingPoints +

Finding cells containing a point (multi-point case)

+ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_1 +Then we use +\ref ParaMEDMEM::MEDCouplingUMesh::getCellsContainingPoints "getCellsContainingPoints()" to +get cells in contact with tree points. Two of them are in contact with some cells and one is not. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_2 +The contents of the result arrays \b cells ([4, 0, 1]) and \b cellsIndex ([0, 0, 1, 3]) +mean the following. +- Point #0 is in contact with none (== \b cellsIndx[1] - \b cellsIndx[0]) cell. +- Point #1 is in contact with 1 (== \b cellsIndx[2] - \b cellsIndx[1]) cell whose id is #4 + (== \b cells[ \b cellsIndx[ 1 ]]). +- Point #2 is in contact with 2 (== \b cellsIndx[3] - \b cellsIndx[2]) cells whose ids are #0 + (== \b cells[ \b cellsIndx[ 2 ]]) and #1 (== \b cells[ \b cellsIndx[ 2 ] + 1 ]). + + +\anchor cpp_mcumesh_getCellsContainingPoint +

Finding cells containing a point

+ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_1 +Then we use +\ref ParaMEDMEM::MEDCouplingUMesh::getCellsContainingPoint "getCellsContainingPoint()" to +get cells in contact with a small ball (point with precision) located near the node #4 and +shifted from this node by its radius \b eps. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_2 +Since the node #4 is shared by all cells, size of the vector \b cellIds must be equal to +the number of cells in \b mesh. + +\anchor cpp_mcumesh_buildPartOrthogonalField +

Getting normals of cells

+ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. Orientation of the cell #1 is +reversed. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_1 +Now we use +\ref ParaMEDMEM::MEDCouplingUMesh::buildPartOrthogonalField "buildPartOrthogonalField()" to get +normal vectors to the cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_2 + + + +\anchor cpp_mcumesh_getPartMeasureField +

Getting volumes of cells

+ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. Orientation of the cell #1 is +reversed. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getPartMeasureField_1 +Now we use +\ref ParaMEDMEM::MEDCouplingUMesh::getPartMeasureField "getPartMeasureField()" to get +volumes of all but the first cell. If we call +\ref ParaMEDMEM::MEDCouplingUMesh::getPartMeasureField "getPartMeasureField()" with \b +isAbs == \c true, the area of the cell #1 is returned positive, else, negative that +reflects its inverse orientation. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getPartMeasureField_2 + + + +\anchor cpp_mcumesh_getCellsInBoundingBox +

Getting cells using the bounding box

+ +First, we create a 2D mesh with 1 TRI3 cell. Bounding box of this cell is [0.,0., 1.,1]. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_1 +Now we check how +\ref ParaMEDMEM::MEDCouplingUMesh::getCellsInBoundingBox "getCellsInBoundingBox()" +searches for cells using the bounding box. We use a bounding box touching the bounding box +of the sole cell at one point (1.,1.). +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_2 +If \ref ParaMEDMEM::MEDCouplingUMesh::getCellsInBoundingBox "getCellsInBoundingBox()" is +called with parameter \b eps == 0.0, the cell is not found because the two bounding boxes +(one of the cell and the one passed as parameter) do not overlap.
+If \ref ParaMEDMEM::MEDCouplingUMesh::getCellsInBoundingBox "getCellsInBoundingBox()" is +called with parameter \b eps == 0.1, the cell is found because \b eps is used to increase +the bounding box of the cell and thus the two bounding boxes intersect each other.
+ +\anchor cpp_mcumesh_renumberNodesInConn +

Renumbering nodes in the connectivity array

+ +First, we create a 2D mesh with 1 QUAD4 cell and with undefined coordinates of nodes. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_renumberNodesInConn_1 +Now we use +\ref ParaMEDMEM::MEDCouplingUMesh::renumberNodesInConn "renumberNodesInConn()" +to get the following nodal connectivity of a sole cell: 0,1,2,3. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_renumberNodesInConn_2 +\b old2newIds array defines how node ids are changed: +- new id of node #0 is -1, +- new id of node #1 is 3, +- new id of node #2 is 4, +- new id of node #3 is 1, +- new id of node #4 is 0. + +\anchor cpp_mcumesh_renumberNodes +

Renumbering nodes

+First, we create a 2D mesh with 4 nodes and no cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_renumberNodes_1 +Next, we use +\ref ParaMEDMEM::MEDCouplingUMesh::renumberNodes "renumberNodes()" +to permute nodes so that +- old node #0 becomes #2, +- old node #1 remains #1, +- old node #2 becomes #0, +- old node #3 is removed. + +Number of nodes becomes 3. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_renumberNodes_2 + +Next we compare behavior of +\ref ParaMEDMEM::MEDCouplingUMesh::renumberNodes "renumberNodes()" and that of +\ref ParaMEDMEM::MEDCouplingUMesh::renumberNodes2 "renumberNodes2()" which, in contrast to +\ref ParaMEDMEM::MEDCouplingUMesh::renumberNodes "renumberNodes()", +moves merged nodes to their barycenter.
+We set #2 as new id of old node #3 and expect that +\ref ParaMEDMEM::MEDCouplingUMesh::renumberNodes2 "renumberNodes2()" moves old nodes #0 +and #3 to their barycenter (-0.3,0.0) which becomes position of node #2.
+\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_renumberNodes_3 + + +\anchor cpp_mcumesh_findBoundaryNodes +

Getting boundary nodes

+ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_findBoundaryNodes_1 +Now we use +\ref ParaMEDMEM::MEDCouplingUMesh::findBoundaryNodes "findBoundaryNodes()" to get ids +of boundary nodes. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_findBoundaryNodes_2 +\ref ParaMEDMEM::MEDCouplingUMesh::findBoundaryNodes "findBoundaryNodes()" returns all +node ids except the node #4 which is in the middle of \b mesh. + + +\anchor cpp_mcumesh_buildBoundaryMesh +

Getting a bounding mesh

+ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_1 +Now we use +\ref ParaMEDMEM::MEDCouplingUMesh::buildBoundaryMesh "buildBoundaryMesh()" to get a mesh +of lower dimension bounding \b mesh. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_2 +Depending on the value of a parameter, +\ref ParaMEDMEM::MEDCouplingUMesh::buildBoundaryMesh "buildBoundaryMesh()" +creates the mesh sharing the node coordinates array with \b mesh or not. + + +\anchor cpp_mcumesh_buildFacePartOfMySelfNode +

Retrieving a lower dimension mesh based on given nodes

+ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_1 +In the following code we retrieve nodes of the cell #0 an then we call +\ref ParaMEDMEM::MEDCouplingUMesh::buildFacePartOfMySelfNode "buildFacePartOfMySelfNode()" +twice with these nodes and with varying last parameter \b allNodes as input. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_2 +
If the last parameter is \c true +\ref ParaMEDMEM::MEDCouplingUMesh::buildFacePartOfMySelfNode "buildFacePartOfMySelfNode()" looks +for segements whose all nodes are given to it, hence it finds segments bounding the cell #0 only. +
If the last parameter is \c false +\ref ParaMEDMEM::MEDCouplingUMesh::buildFacePartOfMySelfNode "buildFacePartOfMySelfNode()" looks +for any segment whose nodes are given to it, hence it adds more segments to \b mesh2. + + +\anchor cpp_mcumesh_buildPartOfMySelfNode +

Copying cells selected by nodes

+ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_1 +In the following code we retrieve nodes of the cell #0 an then we call +\ref ParaMEDMEM::MEDCouplingUMesh::buildPartOfMySelfNode "buildPartOfMySelfNode()" +twice with these nodes and with varying last parameter \b allNodes as input. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_2 +
If the last parameter is \c true +\ref ParaMEDMEM::MEDCouplingUMesh::buildPartOfMySelfNode "buildPartOfMySelfNode()" looks +for cells whose all nodes are given to it, hence it finds the cell #0 only. +
If the last parameter is \c false +\ref ParaMEDMEM::MEDCouplingUMesh::buildPartOfMySelfNode "buildPartOfMySelfNode()" looks +for any cell whose nodes are given to it, hence it finds all cells of \b mesh because all +cells share the node #4. + + +\anchor cpp_mcumesh_getCellIdsLyingOnNodes +

Getting cells by nodes

+ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_1 +In the following code we retrieve nodes of the cell #0 an then we call +\ref ParaMEDMEM::MEDCouplingUMesh::getCellIdsLyingOnNodes "getCellIdsLyingOnNodes()" +twice with these nodes and with varying last parameter \b allNodes as input. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_2 +
If the last parameter is \c true +\ref ParaMEDMEM::MEDCouplingUMesh::getCellIdsLyingOnNodes "getCellIdsLyingOnNodes()" looks +for cells whose all nodes are given to it, hence it finds the cell #0 only. +
If the last parameter is \c false +\ref ParaMEDMEM::MEDCouplingUMesh::getCellIdsLyingOnNodes "getCellIdsLyingOnNodes()" looks +for any cell whose nodes are given to it, hence it finds all cells of \b mesh because all +cells share the node #4. + + + +\anchor cpp_mcumesh_getCellIdsFullyIncludedInNodeIds +

Getting cells by nodes

+ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_1 +In the following code we retrieve nodes of two cells an then we use +\ref ParaMEDMEM::MEDCouplingUMesh::getCellIdsFullyIncludedInNodeIds +"getCellIdsFullyIncludedInNodeIds()" to find these cells by their nodes. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_2 + + +\anchor cpp_mcumesh_buildPartOfMySelf +

Getting a part of mesh

+ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_1 +Now we use +\ref ParaMEDMEM::MEDCouplingUMesh::buildPartOfMySelf "buildPartOfMySelf()" to get a mesh +containing only two cells of \b mesh. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_2 + + +\anchor cpp_mcumesh_mergeNodes +

Merging equal nodes

+ +First, we create a 2D mesh with 1 QUAD4 and 2 TRI3 cells. The cells are based on 6 nodes +of which 2 nodes fully coincide (#3 and #4) and 3 nodes are equal with precision 0.003. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_mergeNodes_1 +Now we merge node duplicates using +\ref ParaMEDMEM::MEDCouplingUMesh::mergeNodes "mergeNodes()" and check values it returns. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_mergeNodes_2 +Contents of \b arr shows ids of old nodes after the merging. The nodes considered equal +one to the other have the same id in \b arr. + +Next we compare behavior of +\ref ParaMEDMEM::MEDCouplingUMesh::mergeNodes "mergeNodes()" and that of +\ref ParaMEDMEM::MEDCouplingUMesh::mergeNodes2 "mergeNodes2()" which, in contrast to +\ref ParaMEDMEM::MEDCouplingUMesh::mergeNodes "mergeNodes()", +moves merged nodes to their barycenter.
We expect that +\ref ParaMEDMEM::MEDCouplingUMesh::mergeNodes2 "mergeNodes2()" moves old nodes #0, #2 +and #5 to their barycenter equal to position of node #2.
+First we check that +\ref ParaMEDMEM::MEDCouplingUMesh::mergeNodes "mergeNodes()" does not move nodes +coincident with the node #2 to the position of node #2, and then we check that +\ref ParaMEDMEM::MEDCouplingUMesh::mergeNodes "mergeNodes2()" does move. +(We check only the second (Y) component of node coordinates since the first component of +these nodes is exactly same.) +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_mergeNodes_3 + + + +\anchor cpp_mcumesh_zipConnectivityTraducer +

Removing cell duplicates

+ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells, so that +- the cell #2 has the same nodal connectivity as the cell #1 does, +- the cell #3 has the same nodal connectivity as the cell #0 does, +- the cell #4 is based on the same nodes as the cell #0 but nodes order is different. + +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_1 +Now we use +\ref ParaMEDMEM::MEDCouplingUMesh::zipConnectivityTraducer "zipConnectivityTraducer()" +to remove duplicate cells. Then we check that two cells, having exactly same nodal +connectivity with other cells, have been removed. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_2 +Contents of \b arr shows ids of cells after duplicates removal. If a value (cell id) +equals to its index in \b arr, this means that the cell is not a duplicate of any cell +with lower id. Else, the value gives a cell id to which this cell is equal.
+Thus, the cells #0 and #1 have no preceding equal cell since \b arr[i] == i.
+The cell #2 equals to the cell #1 (== \b arr[2] ).
+The cell #3 equals to the cell #0 (== \b arr[3] ).
+The cell #4 has no equal cell. This is because the cell comparison technique specified +when we called +\ref ParaMEDMEM::MEDCouplingUMesh::zipConnectivityTraducer "zipConnectivityTraducer()" +was 0 ("exact"), if we had used the technique 2 ("nodal"), \b arr[4] would be 0. + + + +\anchor cpp_mcumesh_zipCoordsTraducer +

Removing unused nodes

+ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_1 +Now we create \b mesh2 including all nodes but only two cells of \b mesh, and we use \ref +ParaMEDMEM::MEDCouplingUMesh::zipCoordsTraducer "zipCoordsTraducer()" to remove unused +nodes from \b mesh2. +\ref ParaMEDMEM::MEDCouplingUMesh::zipCoordsTraducer "zipCoordsTraducer()" returns an array +with -1 for unused nodes and new ids for used ones. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_2 + + + +\anchor cpp_mcumesh_getNodeIdsInUse +

Retrieving unused nodes

+ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_1 +Now we create \b mesh2 including all nodes but only two cells of \b mesh, and we use \ref +ParaMEDMEM::MEDCouplingUMesh::getNodeIdsInUse "getNodeIdsInUse()" to get nodes of \b mesh2 +used in its two cells. +\ref ParaMEDMEM::MEDCouplingUMesh::getNodeIdsInUse "getNodeIdsInUse()" returns an array +with -1 for unused nodes and new ids for used ones. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_2 +Now we use \b newNbOfNodes returned by +\ref ParaMEDMEM::MEDCouplingUMesh::getNodeIdsInUse "getNodeIdsInUse()" to convert \b arr +to "New to Old" mode. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_3 + + +\anchor cpp_mcumesh_convertToPolyTypes +

Conversion of cells to "poly" types

+ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_convertToPolyTypes_1 +Now we convert cells #1 and #3 to type POLYGON and check the result +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_convertToPolyTypes_2 + + +\anchor cpp_mcumesh_buildDescendingConnectivity2 +

Retrieving the descending connectivity with orientation

+ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_1 +Now we get and check the descending connectivity. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_2 +Here we get connectivity of the cell #2 (#3 in FORTRAN mode) of \b mesh2 to see how +mutual orientation of cells in \b mesh and \b mesh2 is defined. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_3 +The contents of the result arrays \b desc and \b descIndx mean the following. +- The cell #0 of \b mesh (QUAD4) is bound by 4 (== \b descIndx[1] - \b descIndx[0]) + segments (SEG2) of \b mesh2 whose ids in FORTRAN mode are + - #1 (== \b desc[ \b descIndx[ 0 ]]), + - #2 (== \b desc[ \b descIndx[ 0 ] + 1 ]), + - #3 (== \b desc[ \b descIndx[ 0 ] + 2 ]) and + - #4 (== \b desc[ \b descIndx[ 0 ] + 3 ]). +
Ids are positive since order of nodes in the corresponding cells of \b mesh and \b mesh2 + are same. For example nodes of SEG2 #3 are [4,1] and nodes of QUAD4 #0 are [0,3,\b 4,\b 1]. +- The cell #1 of \b mesh (TRI3) is bound by 3 (== \b descIndx[2] - \b descIndx[1]) segements of + \b mesh2 whose ids in FORTRAN mode are: + - #-3 (== \b desc[ \b descIndx[ 1 ]]), + - #5 (== \b desc[ \b descIndx[ 1 ] + 1 ]) and + - #6 (== \b desc[ \b descIndx[ 1 ] + 2 ]). +
The id -3 means that order of nodes in SEG2 #3 ([4,1]) is different from the order of + these nodes in TRI3 #1: [\b 1,\b 4,2]. +- etc. + +The contents of the result arrays \b revDesc and \b revDescIndx mean the following. +- The cell #0 of \b mesh2 (SEG2) bounds 1 (== \b revDescIndx[1] - \b revDescIndx[0]) cell of \b + mesh whose id is: + - # 0 (== \b revDesc[ \b revDescIndx[ 0 ]]). +- The cell #1 of \b mesh2 bounds 2 (== \b revDescIndx[2] - \b revDescIndx[1]) cells of \b + mesh whose ids are: + - # 0 (== \b revDesc[ \b revDescIndx[ 1 ]]) and + - # 1 (== \b revDesc[ \b revDescIndx[ 1 ] + 1 ]). +- etc. + + + +\anchor cpp_mcumesh_buildDescendingConnectivity +

Retrieving the descending connectivity

+ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_1 +Now we get and check the descending connectivity. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_2 +The contents of the result arrays \b desc and \b descIndx mean the following. +- The cell #0 of \b mesh (QUAD4) is bound by 4 (== \b descIndx[1] - \b descIndx[0]) + segments (SEG2) of \b mesh2 whose ids are + - #0 (== \b desc[ \b descIndx[ 0 ]]), + - #1 (== \b desc[ \b descIndx[ 0 ] + 1 ]), + - #2 (== \b desc[ \b descIndx[ 0 ] + 2 ]) and + - #3 (== \b desc[ \b descIndx[ 0 ] + 3 ]). +- The cell #1 of \b mesh (TRI3) is bound by 3 (== \b descIndx[2] - \b descIndx[1]) segements of + \b mesh2 whose ids are: + - #2 (== \b desc[ \b descIndx[ 1 ]]), + - #4 (== \b desc[ \b descIndx[ 1 ] + 1 ]) and + - #5 (== \b desc[ \b descIndx[ 1 ] + 2 ]). +- etc. + +The contents of the result arrays \b revDesc and \b revDescIndx mean the following. +- The cell #0 of \b mesh2 (SEG2) bounds 1 (== \b revDescIndx[1] - \b revDescIndx[0]) cell of \b + mesh whose id is: + - # 0 (== \b revDesc[ \b revDescIndx[ 0 ]]). +- The cell #1 of \b mesh2 bounds 2 (== \b revDescIndx[2] - \b revDescIndx[1]) cells of \b + mesh whose ids are: + - # 0 (== \b revDesc[ \b revDescIndx[ 1 ]]) and + - # 1 (== \b revDesc[ \b revDescIndx[ 1 ] + 1 ]). +- etc. + + +\anchor cpp_mcumesh_getReverseNodalConnectivity +

Getting the reverse nodal connectivity

+ +First, we create a 2D mesh with 3 QUAD4 and 2 TRI3 cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_1 +Now we get and check its reverse nodal connectivity. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_2 +The contents of the result arrays mean the following. +- Node #0 is shared by 1 (== \b revNodalIndx[1] - \b revNodalIndx[0]) cell whose id is #0 + (== \b revNodal[ \b revNodalIndx[ 0 ]]). +- Node #1 is shared by 2 (== \b revNodalIndx[2] - \b revNodalIndx[1]) cells whose ids are #0 + (== \b revNodal[ \b revNodalIndx[ 1 ]]) and #1 (== \b revNodal[ \b revNodalIndx[ 1 ] + 1 ]). +- etc. \anchor cpp_mcpointset_scale

Scaling the mesh

@@ -224,7 +832,7 @@ As result contents of the array \b da are as follows. Here we re-fill \b da with zeros and copy \b dv into a component of \b da. -Note that the last parameter \a strictCompoCompare should be \a False +Note that the last parameter \b strictCompoCompare should be \c False in this case, else \ref ParaMEDMEM::DataArrayDouble::setPartOfValues1() throws an exception because \b da has 2 components but only one target component is specified. @@ -497,7 +1105,7 @@ As result contents of the array \b da are as follows. Here we re-fill \b da with zeros and copy \b dv into a component of \b da. -Note that the last parameter \a strictCompoCompare should be \a False +Note that the last parameter \b strictCompoCompare should be \c False in this case, else \ref ParaMEDMEM::DataArrayInt::setPartOfValues1() throws an exception because \b da has 2 components but only one target component is specified. diff --git a/src/INTERP_KERNEL/BBTreePts.txx b/src/INTERP_KERNEL/BBTreePts.txx index e6eb029f1..17d0c7f32 100644 --- a/src/INTERP_KERNEL/BBTreePts.txx +++ b/src/INTERP_KERNEL/BBTreePts.txx @@ -174,10 +174,12 @@ public: } /*! returns in \a elems the list of elements potentially containing the point pointed to by \a xx - \param xx pointer to query point coords - \param elems list of elements (given in 0-indexing) intersecting the bounding box - \sa BBTreePts::getElementsAroundPoint2 - */ + * ** Infinite norm is used here not norm 2 ! *** + * + * \param xx pointer to query point coords + * \param elems list of elements (given in 0-indexing) intersecting the bounding box + * \sa BBTreePts::getElementsAroundPoint2 + */ void getElementsAroundPoint(const double* xx, std::vector& elems) const { // terminal node : return list of elements intersecting bb @@ -188,8 +190,7 @@ public: const double* const bb_ptr=_pts+_elems[i]*dim; bool intersects = true; for(int idim=0;idim_epsilon) - intersects=false; + intersects=intersects && (std::abs(bb_ptr[idim]-xx[idim])<=_epsilon); if(intersects) elems.push_back(_elems[i]); } diff --git a/src/MEDCoupling/MEDCouplingCMesh.cxx b/src/MEDCoupling/MEDCouplingCMesh.cxx index 2e6cab4e9..0895a17cf 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCMesh.cxx @@ -388,6 +388,17 @@ std::string MEDCouplingCMesh::advancedRepr() const return simpleRepr(); } +/*! + * Returns a DataArrayDouble holding positions of nodes along a given axis. + * For more info on Cartesian meshes, see \ref MEDCouplingCMeshPage. + * \param [in] i - an index of axis, a value from [0,1,2]. + * \return const DataArrayDouble * - a pointer to the data array of node coordinates + * referred by \a this mesh. + * \throw If \a i is not one of [0,1,2]. + * + * \ref cpp_mccmesh_getCoordsAt "Here is a C++ example".
+ * \ref py_mccmesh_getCoordsAt "Here is a Python example". + */ const DataArrayDouble *MEDCouplingCMesh::getCoordsAt(int i) const throw(INTERP_KERNEL::Exception) { switch(i) @@ -403,6 +414,17 @@ const DataArrayDouble *MEDCouplingCMesh::getCoordsAt(int i) const throw(INTERP_K } } +/*! + * Returns a DataArrayDouble holding positions of nodes along a given axis. + * For more info on Cartesian meshes, see \ref MEDCouplingCMeshPage. + * \param [in] i - an index of axis, a value from [0,1,2]. + * \return const DataArrayDouble * - a pointer to the data array of node coordinates + * referred by \a this mesh. + * \throw If \a i is not one of [0,1,2]. + * + * \ref cpp_mccmesh_getCoordsAt "Here is a C++ example".
+ * \ref py_mccmesh_getCoordsAt "Here is a Python example". + */ DataArrayDouble *MEDCouplingCMesh::getCoordsAt(int i) throw(INTERP_KERNEL::Exception) { switch(i) @@ -418,6 +440,18 @@ DataArrayDouble *MEDCouplingCMesh::getCoordsAt(int i) throw(INTERP_KERNEL::Excep } } +/*! + * Sets node coordinates along a given axis. For more info on Cartesian meshes, see + * \ref MEDCouplingCMeshPage. + * \param [in] i - an index of axis, a value in range [0,1,2]. + * \param [in] arr - DataArrayDouble holding positions of nodes along the i-th + * axis. It must be an array of one component. + * \throw If \a arr->getNumberOfComponents() != 1. + * \throw If \a i is not one of [0,1,2]. + * + * \ref medcouplingcppexamplesCmeshStdBuild1 "Here is a C++ example".
+ * \ref medcouplingpyexamplesCmeshStdBuild1 "Here is a Python example". + */ void MEDCouplingCMesh::setCoordsAt(int i, const DataArrayDouble *arr) throw(INTERP_KERNEL::Exception) { if(arr) @@ -436,6 +470,21 @@ void MEDCouplingCMesh::setCoordsAt(int i, const DataArrayDouble *arr) throw(INTE } } +/*! + * Sets node coordinates along some of the tree axes. This method updates all the + * three node coordinates arrays at once. For more info on Cartesian meshes, see + * \ref MEDCouplingCMeshPage. + * \param [in] coordsX - DataArrayDouble holding positions of nodes along the X + * axis. It must be an array of one component or \c NULL. + * \param [in] coordsY - DataArrayDouble holding positions of nodes along the Y + * axis. It must be an array of one component or \c NULL. + * \param [in] coordsZ - DataArrayDouble holding positions of nodes along the Z + * axis. It must be an array of one component or \c NULL. + * \throw If \a coords*->getNumberOfComponents() != 1. + * + * \ref medcouplingcppexamplesCmeshStdBuild1 "Here is a C++ example".
+ * \ref medcouplingpyexamplesCmeshStdBuild1 "Here is a Python example". + */ void MEDCouplingCMesh::setCoords(const DataArrayDouble *coordsX, const DataArrayDouble *coordsY, const DataArrayDouble *coordsZ) { if(coordsX) @@ -480,6 +529,17 @@ void MEDCouplingCMesh::getBoundingBox(double *bbox) const } } +/*! + * Returns a new MEDCouplingFieldDouble containing volumes of cells constituting \a this + * mesh.
+ * For 1D cells, the returned field contains lengths.
+ * For 2D cells, the returned field contains areas.
+ * For 3D cells, the returned field contains volumes. + * \param [in] isAbs - a not used parameter. + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble on cells + * and one time . The caller is to delete this field using decrRef() as it is no + * more needed. + */ MEDCouplingFieldDouble *MEDCouplingCMesh::getMeasureField(bool isAbs) const { std::string name="MeasureOfMesh_"; @@ -557,6 +617,12 @@ void MEDCouplingCMesh::rotate(const double *center, const double *vector, double throw INTERP_KERNEL::Exception("No rotation available on CMesh : Traduce it to StructuredMesh to apply it !"); } +/*! + * Translates all nodes of \a this mesh by a given vector. Actually, it adds each + * component of the \a vector to all node coordinates of a corresponding axis. + * \param [in] vector - the translation vector whose size must be not less than \a + * this->getSpaceDimension(). + */ void MEDCouplingCMesh::translate(const double *vector) { if(_x_array) @@ -570,6 +636,12 @@ void MEDCouplingCMesh::translate(const double *vector) _z_array->getPointer(),std::bind2nd(std::plus(),vector[2])); } +/*! + * Applies scaling transformation to all nodes of \a this mesh. + * \param [in] point - coordinates of a scaling center. This array is to be of + * size \a this->getSpaceDimension() at least. + * \param [in] factor - a scale factor. + */ void MEDCouplingCMesh::scale(const double *point, double factor) { for(int i=0;i<3;i++) @@ -594,6 +666,13 @@ MEDCouplingMesh *MEDCouplingCMesh::mergeMyselfWith(const MEDCouplingMesh *other) return 0; } +/*! + * Returns a new DataArrayDouble holding coordinates of all nodes of \a this mesh. + * \return DataArrayDouble * - a new instance of DataArrayDouble, of size \a + * this->getNumberOfNodes() tuples per \a this->getSpaceDimension() + * components. The caller is to delete this array using decrRef() as it is + * no more needed. + */ DataArrayDouble *MEDCouplingCMesh::getCoordinatesAndOwner() const { DataArrayDouble *ret=DataArrayDouble::New(); @@ -620,6 +699,14 @@ DataArrayDouble *MEDCouplingCMesh::getCoordinatesAndOwner() const return ret; } +/*! + * Returns a new DataArrayDouble holding barycenters of all cells. The barycenter is + * computed by averaging coordinates of cell nodes. + * \return DataArrayDouble * - a new instance of DataArrayDouble, of size \a + * this->getNumberOfCells() tuples per \a this->getSpaceDimension() + * components. The caller is to delete this array using decrRef() as it is + * no more needed. + */ DataArrayDouble *MEDCouplingCMesh::getBarycenterAndOwner() const { DataArrayDouble *ret=DataArrayDouble::New(); @@ -775,7 +862,51 @@ void MEDCouplingCMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData void MEDCouplingCMesh::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception) { - stream << "MEDCouplingCMesh C++ instance at " << this << "."; + stream << "MEDCouplingCMesh C++ instance at " << this << ". Name : \"" << getName() << "\"."; + const DataArrayDouble *thisArr[3]={_x_array,_y_array,_z_array}; + std::ostringstream stream2[3]; + bool isDef[3]; + int nbOfCells=1,nbOfNodes=1; + for(int i=0;i<3;i++) + { + isDef[i]=thisArr[i]!=0; + if(isDef[i]) + { + char tmp='X'+i; + stream2[i] << tmp << " positions array "; + if(!thisArr[i]->isAllocated()) + stream2[i] << "set but not allocated."; + else + { + int nbCompo=thisArr[i]->getNumberOfComponents(); + if(nbCompo==1) + { + int nbTuples=thisArr[i]->getNumberOfTuples(); + if(nbTuples<1) + { stream2[i] << "set and allocated - WARNING number of elements < 1 !"; nbOfCells=-1; nbOfNodes=-1; } + else + { + stream2[i] << "(length=" << nbTuples << ")" << ": "; + thisArr[i]->reprQuickOverviewData(stream2[i],200); + if(nbOfCells!=-1) + { nbOfNodes*=nbTuples; nbOfCells*=nbTuples-1; } + } + } + else + { stream2[i] << "set and allocated - WARNING number of components != 1 !"; nbOfCells=-1; nbOfNodes=-1; } + } + } + } + if(!isDef[0] && !isDef[1] && !isDef[2]) + { stream << " No arrays set !"; return; } + if(nbOfCells>=0) + { stream << std::endl << "Number of cells : " << nbOfCells << ". Number of nodes : " << nbOfNodes << "."; } + for(int i=0;i<3;i++) + { + if(isDef[i]) + stream << std::endl << stream2[i].str(); + } + } std::string MEDCouplingCMesh::getVTKDataSetType() const throw(INTERP_KERNEL::Exception) diff --git a/src/MEDCoupling/MEDCouplingCurveLinearMesh.cxx b/src/MEDCoupling/MEDCouplingCurveLinearMesh.cxx index a7b953acf..6e93efb12 100644 --- a/src/MEDCoupling/MEDCouplingCurveLinearMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCurveLinearMesh.cxx @@ -323,8 +323,17 @@ void MEDCouplingCurveLinearMesh::setCoords(const DataArrayDouble *coords) throw( void MEDCouplingCurveLinearMesh::setNodeGridStructure(const int *gridStructBg, const int *gridStructEnd) throw(INTERP_KERNEL::Exception) { - _structure.resize(0); - _structure.insert(_structure.end(),gridStructBg,gridStructEnd); + std::size_t sz=std::distance(gridStructBg,gridStructEnd); + if(sz>=1 && sz<=3) + { + _structure.resize(0); + _structure.insert(_structure.end(),gridStructBg,gridStructEnd); + } + else + { + std::ostringstream oss; oss << "MEDCouplingCurveLinearMesh::setNodeGridStructure : size of input nodal grid structure (" << sz << ") should be in 1, 2 or 3 !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } } std::vector MEDCouplingCurveLinearMesh::getNodeGridStructure() const throw(INTERP_KERNEL::Exception) @@ -880,7 +889,26 @@ void MEDCouplingCurveLinearMesh::writeVTKLL(std::ostream& ofs, const std::string void MEDCouplingCurveLinearMesh::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception) { - stream << "MEDCouplingCurveLinearMesh C++ instance at " << this << "."; + stream << "MEDCouplingCurveLinearMesh C++ instance at " << this << ". Name : \"" << getName() << "\"."; + stream << "Nodal structure : ["; + for(std::size_t i=0;i<_structure.size();i++) + { + char tmp='X'+i; + stream << " " << tmp << "=" << _structure[i]; + if(i!=_structure.size()-1) + stream << ", "; + } + stream << " ]."; + const DataArrayDouble *coo(_coords); + if(!coo) + { stream << std::endl << "No coordinates set !"; return ; } + if(!coo->isAllocated()) + { stream << std::endl << "Coordinates set but not allocated !"; return ; } + int nbOfCompo=coo->getNumberOfComponents(); + if(nbOfCompo!=(int)_structure.size()) + { stream << std::endl << "Coordinates set and allocated but mismatch number of components !"; return ; } + stream << std::endl << "Coordinates ( number of tuples = " << coo->getNumberOfTuples() << " ) : "; + coo->reprQuickOverviewData(stream,200); } std::string MEDCouplingCurveLinearMesh::getVTKDataSetType() const throw(INTERP_KERNEL::Exception) diff --git a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx index 42b654466..5677bbe7b 100644 --- a/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx +++ b/src/MEDCoupling/MEDCouplingExtrudedMesh.cxx @@ -921,7 +921,7 @@ void MEDCouplingExtrudedMesh::writeVTKLL(std::ostream& ofs, const std::string& c void MEDCouplingExtrudedMesh::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception) { - stream << "MEDCouplingExtrudedMesh C++ instance at " << this << "."; + stream << "MEDCouplingExtrudedMesh C++ instance at " << this << ". Name : \"" << getName() << "\"."; } std::string MEDCouplingExtrudedMesh::getVTKDataSetType() const throw(INTERP_KERNEL::Exception) diff --git a/src/MEDCoupling/MEDCouplingField.cxx b/src/MEDCoupling/MEDCouplingField.cxx index 8478acdf5..967caf414 100644 --- a/src/MEDCoupling/MEDCouplingField.cxx +++ b/src/MEDCoupling/MEDCouplingField.cxx @@ -77,6 +77,10 @@ bool MEDCouplingField::isEqual(const MEDCouplingField *other, double meshPrec, d bool MEDCouplingField::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const { + if(!other) + throw INTERP_KERNEL::Exception("MEDCouplingField::isEqualWithoutConsideringStr : input field is NULL !"); + if(!_type) + throw INTERP_KERNEL::Exception("MEDCouplingField::isEqualWithoutConsideringStr : spatial discretization of this is NULL !"); if(!_type->isEqualWithoutConsideringStr(other->_type,valsPrec)) return false; if(_nature!=other->_nature) @@ -97,6 +101,8 @@ bool MEDCouplingField::isEqualWithoutConsideringStr(const MEDCouplingField *othe */ bool MEDCouplingField::areCompatibleForMerge(const MEDCouplingField *other) const { + if(!other) + throw INTERP_KERNEL::Exception("MEDCouplingField::areCompatibleForMerge : input field is NULL !"); if(!_type->isEqual(other->_type,1.)) return false; if(_nature!=other->_nature) @@ -112,6 +118,8 @@ bool MEDCouplingField::areCompatibleForMerge(const MEDCouplingField *other) cons */ bool MEDCouplingField::areStrictlyCompatible(const MEDCouplingField *other) const { + if(!other) + throw INTERP_KERNEL::Exception("MEDCouplingField::areStrictlyCompatible : input field is NULL !"); if(!_type->isEqual(other->_type,1.e-12)) return false; if(_nature!=other->_nature) @@ -161,6 +169,7 @@ NatureOfField MEDCouplingField::getNature() const */ void MEDCouplingField::setNature(NatureOfField nat) throw(INTERP_KERNEL::Exception) { + MEDCouplingNatureOfField::GetRepr(nat);//generate a throw if nat not recognized _nature=nat; } @@ -174,6 +183,8 @@ DataArrayDouble *MEDCouplingField::getLocalizationOfDiscr() const throw(INTERP_K { if(!_mesh) throw INTERP_KERNEL::Exception("MEDCouplingField::getLocalizationOfDiscr : No mesh set !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("MEDCouplingField::getLocalizationOfDiscr : No spatial discretization set !"); return _type->getLocalizationOfDiscValues(_mesh); } @@ -183,8 +194,10 @@ DataArrayDouble *MEDCouplingField::getLocalizationOfDiscr() const throw(INTERP_K */ MEDCouplingFieldDouble *MEDCouplingField::buildMeasureField(bool isAbs) const throw(INTERP_KERNEL::Exception) { - if(_mesh==0) - throw INTERP_KERNEL::Exception("MEDCouplingField::getMeasureField : no mesh defined !!!"); + if(!_mesh) + throw INTERP_KERNEL::Exception("MEDCouplingField::buildMeasureField : no mesh defined !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("MEDCouplingField::buildMeasureField : No spatial discretization set !"); return _type->getMeasureField(_mesh,isAbs); } @@ -195,6 +208,7 @@ void MEDCouplingField::setMesh(const MEDCouplingMesh *mesh) if(_mesh) _mesh->decrRef(); _mesh=mesh; + declareAsNew(); if(_mesh) { _mesh->incrRef(); @@ -216,6 +230,8 @@ void MEDCouplingField::setGaussLocalizationOnType(INTERP_KERNEL::NormalizedCellT { if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling setGaussLocalizationOnType method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call setGaussLocalizationOnType method !"); _type->setGaussLocalizationOnType(_mesh,type,refCoo,gsCoo,wg); } @@ -234,6 +250,8 @@ void MEDCouplingField::setGaussLocalizationOnCells(const int *begin, const int * { if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling setGaussLocalizationOnCells method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call setGaussLocalizationOnCells method !"); _type->setGaussLocalizationOnCells(_mesh,begin,end,refCoo,gsCoo,wg); } @@ -244,6 +262,8 @@ void MEDCouplingField::clearGaussLocalizations() { if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling clearGaussLocalizations method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call clearGaussLocalizations method !"); _type->clearGaussLocalizations(); } @@ -257,6 +277,8 @@ MEDCouplingGaussLocalization& MEDCouplingField::getGaussLocalization(int locId) { if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalization method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalization method !"); return _type->getGaussLocalization(locId); } @@ -269,6 +291,8 @@ int MEDCouplingField::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedC { if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalizationIdOfOneType method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalizationIdOfOneType method !"); return _type->getGaussLocalizationIdOfOneType(type); } @@ -276,6 +300,8 @@ std::set MEDCouplingField::getGaussLocalizationIdsOfOneType(INTERP_KERNEL:: { if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalizationIdsOfOneType method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalizationIdsOfOneType method !"); return _type->getGaussLocalizationIdsOfOneType(type); } @@ -287,6 +313,8 @@ int MEDCouplingField::getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exce { if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling getNbOfGaussLocalization method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getNbOfGaussLocalization method !"); return _type->getNbOfGaussLocalization(); } @@ -299,6 +327,8 @@ int MEDCouplingField::getGaussLocalizationIdOfOneCell(int cellId) const throw(IN { if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalizationIdOfOneCell method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalizationIdOfOneCell method !"); return _type->getGaussLocalizationIdOfOneCell(cellId); } @@ -314,6 +344,8 @@ void MEDCouplingField::getCellIdsHavingGaussLocalization(int locId, std::vector< cellIds.clear(); if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalizationIdOfOneCell method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getCellIdsHavingGaussLocalization method !"); _type->getCellIdsHavingGaussLocalization(locId,cellIds); } @@ -327,6 +359,8 @@ const MEDCouplingGaussLocalization& MEDCouplingField::getGaussLocalization(int l { if(!_mesh) throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalization method !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getGaussLocalization method !"); return _type->getGaussLocalization(locId); } @@ -360,19 +394,42 @@ MEDCouplingField::MEDCouplingField(const MEDCouplingField& other, bool deepCopy) /*! * This method returns a submesh of 'mesh' instance constituting cell ids contained in array defined as an interval [start;end). - * @param di is an array returned that specifies entity ids (nodes, cells ids...) in mesh 'mesh' of entity in returned submesh. + * @param di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array. + * + * \sa MEDCouplingField::buildSubMeshDataRange */ MEDCouplingMesh *MEDCouplingField::buildSubMeshData(const int *start, const int *end, DataArrayInt *&di) const { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call buildSubMeshData method !"); return _type->buildSubMeshData(_mesh,start,end,di); } +/*! + * This method returns a submesh of 'mesh' instance constituting cell ids defined by a range given by the 3 following inputs \a begin, \a end and \a step. + * + * \param [out] beginOut Valid only if \a di is NULL + * \param [out] endOut Valid only if \a di is NULL + * \param [out] stepOut Valid only if \a di is NULL + * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable. + * + * \sa MEDCouplingField::buildSubMeshData + */ +MEDCouplingMesh *MEDCouplingField::buildSubMeshDataRange(int begin, int end, int step, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const +{ + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call buildSubMeshDataRange method !"); + return _type->buildSubMeshDataRange(_mesh,begin,end,step,beginOut,endOut,stepOut,di); +} + /*! * This method returns tuples ids implied by the mesh selection of the cell ids contained in array defined as an interval [start;end). * \return a newly allocated DataArrayInt instance containing tuples ids. */ DataArrayInt *MEDCouplingField::computeTupleIdsToSelectFromCellIds(const int *startCellIds, const int *endCellIds) const { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call computeTupleIdsToSelectFromCellIds method !"); return _type->computeTupleIdsToSelectFromCellIds(_mesh,startCellIds,endCellIds); } @@ -382,6 +439,8 @@ DataArrayInt *MEDCouplingField::computeTupleIdsToSelectFromCellIds(const int *st */ int MEDCouplingField::getNumberOfTuplesExpected() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getNumberOfTuplesExpected method !"); if(_mesh) return _type->getNumberOfTuples(_mesh); else @@ -390,9 +449,12 @@ int MEDCouplingField::getNumberOfTuplesExpected() const throw(INTERP_KERNEL::Exc void MEDCouplingField::setDiscretization(MEDCouplingFieldDiscretization *newDisc) { + bool needUpdate=(const MEDCouplingFieldDiscretization *)_type!=newDisc; _type=newDisc; if(newDisc) newDisc->incrRef(); + if(needUpdate) + declareAsNew(); } /*! @@ -401,6 +463,8 @@ void MEDCouplingField::setDiscretization(MEDCouplingFieldDiscretization *newDisc */ int MEDCouplingField::getNumberOfMeshPlacesExpected() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Spatial discretization not set ! Impossible to call getNumberOfMeshPlacesExpected method !"); if(_mesh) return _type->getNumberOfMeshPlaces(_mesh); else diff --git a/src/MEDCoupling/MEDCouplingField.hxx b/src/MEDCoupling/MEDCouplingField.hxx index c42421e8c..ed37178f7 100644 --- a/src/MEDCoupling/MEDCouplingField.hxx +++ b/src/MEDCoupling/MEDCouplingField.hxx @@ -63,6 +63,7 @@ namespace ParaMEDMEM DataArrayDouble *getLocalizationOfDiscr() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *buildMeasureField(bool isAbs) const throw(INTERP_KERNEL::Exception); MEDCouplingMesh *buildSubMeshData(const int *start, const int *end, DataArrayInt *&di) const; + MEDCouplingMesh *buildSubMeshDataRange(int begin, int end, int step, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const; DataArrayInt *computeTupleIdsToSelectFromCellIds(const int *startCellIds, const int *endCellIds) const; const MEDCouplingFieldDiscretization *getDiscretization() const { return _type; } MEDCouplingFieldDiscretization *getDiscretization() { return _type; } @@ -84,6 +85,7 @@ namespace ParaMEDMEM const MEDCouplingGaussLocalization& getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception); void updateTime() const; std::size_t getHeapMemorySize() const; + virtual void reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception) = 0; protected: MEDCouplingField(TypeOfField type); MEDCouplingField(const MEDCouplingField& other, bool deepCopy=true); diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx index 2b79696e8..1c99da1c2 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -164,6 +164,14 @@ MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::clonePart(const return clone(); } +/*! + * For all field discretization excepted GaussPts the slice( \a beginCellId, \a endCellIds, \a stepCellId ) has no impact on the cloned instance. + */ +MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::clonePartRange(int beginCellIds, int endCellIds, int stepCellIds) const +{ + return clone(); +} + /*! * Excepted for MEDCouplingFieldDiscretizationPerCell no underlying TimeLabel object : nothing to do in generally. */ @@ -256,6 +264,22 @@ void MEDCouplingFieldDiscretization::integral(const MEDCouplingMesh *mesh, const } } +/*! + * This method is strictly equivalent to MEDCouplingFieldDiscretization::buildSubMeshData except that it is optimized for input defined as a range of cell ids. + * + * \param [out] beginOut Valid only if \a di is NULL + * \param [out] endOut Valid only if \a di is NULL + * \param [out] stepOut Valid only if \a di is NULL + * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable. + * + * \sa MEDCouplingFieldDiscretization::buildSubMeshData + */ +MEDCouplingMesh *MEDCouplingFieldDiscretization::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const +{ + MEDCouplingAutoRefCountObjectPtr da=DataArrayInt::Range(beginCellIds,endCellIds,stepCellIds); + return buildSubMeshData(mesh,da->begin(),da->end(),di); +} + void MEDCouplingFieldDiscretization::getSerializationIntArray(DataArrayInt *& arr) const { arr=0; @@ -355,6 +379,8 @@ void MEDCouplingFieldDiscretization::getCellIdsHavingGaussLocalization(int locId void MEDCouplingFieldDiscretization::RenumberEntitiesFromO2NArr(double eps, const int *old2NewPtr, int newNbOfEntity, DataArrayDouble *arr, const char *msg) { + if(!arr) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::RenumberEntitiesFromO2NArr : input array is NULL !"); int oldNbOfElems=arr->getNumberOfTuples(); int nbOfComp=arr->getNumberOfComponents(); int newNbOfTuples=newNbOfEntity; @@ -434,6 +460,11 @@ const char *MEDCouplingFieldDiscretizationP0::getRepr() const bool MEDCouplingFieldDiscretizationP0::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const { + if(!other) + { + reason="other spatial discretization is NULL, and this spatial discretization (P0) is defined."; + return false; + } const MEDCouplingFieldDiscretizationP0 *otherC=dynamic_cast(other); bool ret=otherC!=0; if(!ret) @@ -443,16 +474,22 @@ bool MEDCouplingFieldDiscretizationP0::isEqualIfNotWhy(const MEDCouplingFieldDis int MEDCouplingFieldDiscretizationP0::getNumberOfTuples(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfTuples : NULL input mesh !"); return mesh->getNumberOfCells(); } int MEDCouplingFieldDiscretizationP0::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getNumberOfMeshPlaces : NULL input mesh !"); return mesh->getNumberOfCells(); } DataArrayInt *MEDCouplingFieldDiscretizationP0::getOffsetArr(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getOffsetArr : NULL input mesh !"); int nbOfTuples=mesh->getNumberOfCells(); DataArrayInt *ret=DataArrayInt::New(); ret->alloc(nbOfTuples+1,1); @@ -463,6 +500,8 @@ DataArrayInt *MEDCouplingFieldDiscretizationP0::getOffsetArr(const MEDCouplingMe void MEDCouplingFieldDiscretizationP0::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::renumberArraysForCell : NULL input mesh !"); const int *array=old2NewBg; if(check) array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells()); @@ -477,6 +516,8 @@ void MEDCouplingFieldDiscretizationP0::renumberArraysForCell(const MEDCouplingMe DataArrayDouble *MEDCouplingFieldDiscretizationP0::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getLocalizationOfDiscValues : NULL input mesh !"); return mesh->getBarycenterAndOwner(); } @@ -493,12 +534,19 @@ void MEDCouplingFieldDiscretizationP0::computeMeshRestrictionFromTupleIds(const trueTupleRestriction=tmp2.retn(); } +void MEDCouplingFieldDiscretizationP0::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception) +{ + stream << "P0 spatial discretization."; +} + void MEDCouplingFieldDiscretizationP0::checkCompatibilityWithNature(NatureOfField nat) const throw(INTERP_KERNEL::Exception) { } void MEDCouplingFieldDiscretizationP0::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::checkCoherencyBetween : NULL input mesh !"); if(mesh->getNumberOfCells()!=da->getNumberOfTuples()) { std::ostringstream message; @@ -517,6 +565,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationP0::getMeasureField(const void MEDCouplingFieldDiscretizationP0::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getValueOn : NULL input mesh !"); int id=mesh->getCellContainingPoint(loc,_precision); if(id==-1) throw INTERP_KERNEL::Exception("Specified point is detected outside of mesh : unable to apply P0::getValueOn !"); @@ -534,6 +584,8 @@ void MEDCouplingFieldDiscretizationP0::getValueOnPos(const DataArrayDouble *arr, DataArrayDouble *MEDCouplingFieldDiscretizationP0::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::getValueOnMulti : NULL input mesh !"); std::vector elts,eltsIndex; mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,elts,eltsIndex); int spaceDim=mesh->getSpaceDimension(); @@ -591,24 +643,51 @@ DataArrayInt *MEDCouplingFieldDiscretizationP0::computeTupleIdsToSelectFromCellI * This method returns a submesh of 'mesh' instance constituting cell ids contained in array defined as an interval [start;end). * @param di is an array returned that specifies entity ids (here cells ids) in mesh 'mesh' of entity in returned submesh. * Example : The first cell id of returned mesh has the (*di)[0] id in 'mesh' + * + * \sa MEDCouplingFieldDiscretizationP0::buildSubMeshDataRange */ MEDCouplingMesh *MEDCouplingFieldDiscretizationP0::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const { - MEDCouplingMesh *ret=mesh->buildPart(start,end); - di=DataArrayInt::New(); - di->alloc((int)std::distance(start,end),1); - int *pt=di->getPointer(); - std::copy(start,end,pt); - return ret; + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::buildSubMeshData : NULL input mesh !"); + MEDCouplingAutoRefCountObjectPtr ret=mesh->buildPart(start,end); + MEDCouplingAutoRefCountObjectPtr diSafe=DataArrayInt::New(); + diSafe->alloc((int)std::distance(start,end),1); + std::copy(start,end,diSafe->getPointer()); + di=diSafe.retn(); + return ret.retn(); +} + +/*! + * This method is strictly equivalent to MEDCouplingFieldDiscretizationP0::buildSubMeshData except that it is optimized for input defined as a range of cell ids. + * + * \param [out] beginOut Valid only if \a di is NULL + * \param [out] endOut Valid only if \a di is NULL + * \param [out] stepOut Valid only if \a di is NULL + * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable. + * + * \sa MEDCouplingFieldDiscretizationP0::buildSubMeshData + */ +MEDCouplingMesh *MEDCouplingFieldDiscretizationP0::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const +{ + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP0::buildSubMeshDataRange : NULL input mesh !"); + MEDCouplingAutoRefCountObjectPtr ret=mesh->buildPartRange(beginCellIds,endCellIds,stepCellIds); + di=0; beginOut=beginCellIds; endOut=endCellIds; stepOut=stepCellIds; + return ret.retn(); } int MEDCouplingFieldDiscretizationOnNodes::getNumberOfTuples(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getNumberOfTuples : NULL input mesh !"); return mesh->getNumberOfNodes(); } int MEDCouplingFieldDiscretizationOnNodes::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getNumberOfMeshPlaces : NULL input mesh !"); return mesh->getNumberOfNodes(); } @@ -622,6 +701,8 @@ void MEDCouplingFieldDiscretizationOnNodes::renumberArraysForCell(const MEDCoupl DataArrayInt *MEDCouplingFieldDiscretizationOnNodes::getOffsetArr(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getOffsetArr : NULL input mesh !"); int nbOfTuples=mesh->getNumberOfNodes(); DataArrayInt *ret=DataArrayInt::New(); ret->alloc(nbOfTuples+1,1); @@ -631,6 +712,8 @@ DataArrayInt *MEDCouplingFieldDiscretizationOnNodes::getOffsetArr(const MEDCoupl DataArrayDouble *MEDCouplingFieldDiscretizationOnNodes::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::getLocalizationOfDiscValues : NULL input mesh !"); return mesh->getCoordinatesAndOwner(); } @@ -651,6 +734,8 @@ void MEDCouplingFieldDiscretizationOnNodes::computeMeshRestrictionFromTupleIds(c void MEDCouplingFieldDiscretizationOnNodes::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::checkCoherencyBetween : NULL input mesh !"); if(mesh->getNumberOfNodes()!=da->getNumberOfTuples()) { std::ostringstream message; @@ -667,11 +752,39 @@ void MEDCouplingFieldDiscretizationOnNodes::checkCoherencyBetween(const MEDCoupl */ MEDCouplingMesh *MEDCouplingFieldDiscretizationOnNodes::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const { - MEDCouplingMesh *ret=mesh->buildPartAndReduceNodes(start,end,di); - DataArrayInt *di2=di->invertArrayO2N2N2O(ret->getNumberOfNodes()); - di->decrRef(); - di=di2; - return ret; + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationNodes::buildSubMeshData : NULL input mesh !"); + DataArrayInt *diTmp=0; + MEDCouplingAutoRefCountObjectPtr ret=mesh->buildPartAndReduceNodes(start,end,diTmp); + MEDCouplingAutoRefCountObjectPtr diTmpSafe(diTmp); + MEDCouplingAutoRefCountObjectPtr di2=diTmpSafe->invertArrayO2N2N2O(ret->getNumberOfNodes()); + di=di2.retn(); + return ret.retn(); +} + +/*! + * This method is strictly equivalent to MEDCouplingFieldDiscretizationNodes::buildSubMeshData except that it is optimized for input defined as a range of cell ids. + * + * \param [out] beginOut Valid only if \a di is NULL + * \param [out] endOut Valid only if \a di is NULL + * \param [out] stepOut Valid only if \a di is NULL + * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable. + * + * \sa MEDCouplingFieldDiscretizationNodes::buildSubMeshData + */ +MEDCouplingMesh *MEDCouplingFieldDiscretizationOnNodes::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const +{ + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationOnNodes::buildSubMeshDataRange : NULL input mesh !"); + DataArrayInt *diTmp=0; + MEDCouplingAutoRefCountObjectPtr ret=mesh->buildPartRangeAndReduceNodes(beginCellIds,endCellIds,stepCellIds,beginOut,endOut,stepOut,diTmp); + if(diTmp) + { + MEDCouplingAutoRefCountObjectPtr diTmpSafe(diTmp); + MEDCouplingAutoRefCountObjectPtr di2=diTmpSafe->invertArrayO2N2N2O(ret->getNumberOfNodes()); + di=di2.retn(); + } + return ret.retn(); } /*! @@ -685,7 +798,7 @@ MEDCouplingMesh *MEDCouplingFieldDiscretizationOnNodes::buildSubMeshData(const M DataArrayInt *MEDCouplingFieldDiscretizationOnNodes::computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const { if(!mesh) - throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::computeTupleIdsToSelectFromCellIds : null mesh !"); + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::computeTupleIdsToSelectFromCellIds : NULL input mesh !"); const MEDCouplingAutoRefCountObjectPtr umesh=mesh->buildUnstructured(); MEDCouplingAutoRefCountObjectPtr umesh2=static_cast(umesh->buildPartOfMySelf(startCellIds,endCellIds,true)); return umesh2->computeFetchedNodeIds(); @@ -746,6 +859,11 @@ const char *MEDCouplingFieldDiscretizationP1::getRepr() const bool MEDCouplingFieldDiscretizationP1::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const { + if(!other) + { + reason="other spatial discretization is NULL, and this spatial discretization (P1) is defined."; + return false; + } const MEDCouplingFieldDiscretizationP1 *otherC=dynamic_cast(other); bool ret=otherC!=0; if(!ret) @@ -768,6 +886,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDiscretizationP1::getMeasureField(const void MEDCouplingFieldDiscretizationP1::getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueOn : NULL input mesh !"); int id=mesh->getCellContainingPoint(loc,_precision); if(id==-1) throw INTERP_KERNEL::Exception("Specified point is detected outside of mesh : unable to apply P1::getValueOn !"); @@ -783,6 +903,8 @@ void MEDCouplingFieldDiscretizationP1::getValueOn(const DataArrayDouble *arr, co */ void MEDCouplingFieldDiscretizationP1::getValueInCell(const MEDCouplingMesh *mesh, int cellId, const DataArrayDouble *arr, const double *loc, double *res) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueInCell : NULL input mesh !"); std::vector conn; std::vector coo; mesh->getNodeIdsOfCell(cellId,conn); @@ -808,6 +930,8 @@ void MEDCouplingFieldDiscretizationP1::getValueInCell(const MEDCouplingMesh *mes DataArrayDouble *MEDCouplingFieldDiscretizationP1::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationP1::getValueOnMulti : NULL input mesh !"); std::vector elts,eltsIndex; mesh->getCellsContainingPoints(loc,nbOfPoints,_precision,elts,eltsIndex); int spaceDim=mesh->getSpaceDimension(); @@ -828,6 +952,11 @@ DataArrayDouble *MEDCouplingFieldDiscretizationP1::getValueOnMulti(const DataArr return ret.retn(); } +void MEDCouplingFieldDiscretizationP1::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception) +{ + stream << "P1 spatial discretization."; +} + MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell():_discr_per_cell(0) { } @@ -853,6 +982,15 @@ MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(con } } +MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other, int beginCellIds, int endCellIds, int stepCellIds):_discr_per_cell(0) +{ + DataArrayInt *arr=other._discr_per_cell; + if(arr) + { + _discr_per_cell=arr->selectByTupleId2(beginCellIds,endCellIds,stepCellIds); + } +} + void MEDCouplingFieldDiscretizationPerCell::updateTime() const { if(_discr_per_cell) @@ -871,6 +1009,8 @@ void MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(const MEDCoupl { if(!_discr_per_cell) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell has no discretization per cell !"); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween : NULL input mesh !"); int nbOfTuples=_discr_per_cell->getNumberOfTuples(); if(nbOfTuples!=mesh->getNumberOfCells()) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell has a discretization per cell but it's not matching the underlying mesh !"); @@ -878,10 +1018,15 @@ void MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(const MEDCoupl bool MEDCouplingFieldDiscretizationPerCell::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const { + if(!other) + { + reason="other spatial discretization is NULL, and this spatial discretization (PerCell) is defined."; + return false; + } const MEDCouplingFieldDiscretizationPerCell *otherC=dynamic_cast(other); if(!otherC) { - reason="Spatial discrtization of this is ON_GAUSS, which is not the case of other."; + reason="Spatial discretization of this is ON_GAUSS, which is not the case of other."; return false; } if(_discr_per_cell==0) @@ -925,12 +1070,14 @@ void MEDCouplingFieldDiscretizationPerCell::renumberCells(const int *old2NewBg, delete [] const_cast(array); } -void MEDCouplingFieldDiscretizationPerCell::buildDiscrPerCellIfNecessary(const MEDCouplingMesh *m) +void MEDCouplingFieldDiscretizationPerCell::buildDiscrPerCellIfNecessary(const MEDCouplingMesh *mesh) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationPerCell::buildDiscrPerCellIfNecessary : NULL input mesh !"); if(!_discr_per_cell) { _discr_per_cell=DataArrayInt::New(); - int nbTuples=m->getNumberOfCells(); + int nbTuples=mesh->getNumberOfCells(); _discr_per_cell->alloc(nbTuples,1); int *ptr=_discr_per_cell->getPointer(); std::fill(ptr,ptr+nbTuples,DFT_INVALID_LOCID_VALUE); @@ -968,6 +1115,19 @@ const DataArrayInt *MEDCouplingFieldDiscretizationPerCell::getArrayOfDiscIds() c return _discr_per_cell; } +void MEDCouplingFieldDiscretizationPerCell::setArrayOfDiscIds(const DataArrayInt *adids) throw(INTERP_KERNEL::Exception) +{ + if(adids!=_discr_per_cell) + { + if(_discr_per_cell) + _discr_per_cell->decrRef(); + _discr_per_cell=const_cast(adids); + if(_discr_per_cell) + _discr_per_cell->incrRef(); + declareAsNew(); + } +} + MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss() { } @@ -976,6 +1136,10 @@ MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const M { } +MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other, int beginCellIds, int endCellIds, int stepCellIds):MEDCouplingFieldDiscretizationPerCell(other,beginCellIds,endCellIds,stepCellIds),_loc(other._loc) +{ +} + TypeOfField MEDCouplingFieldDiscretizationGauss::getEnum() const { return TYPE; @@ -983,6 +1147,11 @@ TypeOfField MEDCouplingFieldDiscretizationGauss::getEnum() const bool MEDCouplingFieldDiscretizationGauss::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const { + if(!other) + { + reason="other spatial discretization is NULL, and this spatial discretization (Gauss) is defined."; + return false; + } const MEDCouplingFieldDiscretizationGauss *otherC=dynamic_cast(other); if(!otherC) { @@ -1038,6 +1207,11 @@ MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clonePart(c return new MEDCouplingFieldDiscretizationGauss(*this,startCellIds,endCellIds); } +MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clonePartRange(int beginCellIds, int endCellIds, int stepCellIds) const +{ + return new MEDCouplingFieldDiscretizationGauss(*this,beginCellIds,endCellIds,stepCellIds); +} + std::string MEDCouplingFieldDiscretizationGauss::getStringRepr() const { std::ostringstream oss; oss << REPR << "." << std::endl; @@ -1088,11 +1262,19 @@ int MEDCouplingFieldDiscretizationGauss::getNumberOfTuples(const MEDCouplingMesh int MEDCouplingFieldDiscretizationGauss::getNumberOfMeshPlaces(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getNumberOfMeshPlaces : NULL input mesh !"); return mesh->getNumberOfCells(); } +/*! + * This method is redevelopped for performance reasons, but it is equivalent to a call to MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField + * and a call to DataArrayDouble::computeOffsets2 on the returned array. + */ DataArrayInt *MEDCouplingFieldDiscretizationGauss::getOffsetArr(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getOffsetArr : NULL input mesh !"); int nbOfTuples=mesh->getNumberOfCells(); MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(nbOfTuples+1,1); @@ -1118,6 +1300,8 @@ DataArrayInt *MEDCouplingFieldDiscretizationGauss::getOffsetArr(const MEDCouplin void MEDCouplingFieldDiscretizationGauss::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::renumberArraysForCell : NULL input mesh !"); const int *array=old2NewBg; if(check) array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells()); @@ -1147,6 +1331,8 @@ void MEDCouplingFieldDiscretizationGauss::renumberArraysForCell(const MEDCouplin DataArrayDouble *MEDCouplingFieldDiscretizationGauss::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getLocalizationOfDiscValues : NULL input mesh !"); checkNoOrphanCells(); MEDCouplingAutoRefCountObjectPtr umesh=mesh->buildUnstructured();//in general do nothing int nbOfTuples=getNumberOfTuples(mesh); @@ -1276,6 +1462,8 @@ double MEDCouplingFieldDiscretizationGauss::getIJK(const MEDCouplingMesh *mesh, void MEDCouplingFieldDiscretizationGauss::checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::checkCoherencyBetween : NULL input mesh !"); MEDCouplingFieldDiscretizationPerCell::checkCoherencyBetween(mesh,da); for(std::vector::const_iterator iter=_loc.begin();iter!=_loc.end();iter++) (*iter).checkCoherency(); @@ -1375,8 +1563,58 @@ DataArrayDouble *MEDCouplingFieldDiscretizationGauss::getValueOnMulti(const Data MEDCouplingMesh *MEDCouplingFieldDiscretizationGauss::buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const { - di=computeTupleIdsToSelectFromCellIds(mesh,start,end); - return mesh->buildPart(start,end); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildSubMeshData : NULL input mesh !"); + MEDCouplingAutoRefCountObjectPtr diSafe=computeTupleIdsToSelectFromCellIds(mesh,start,end); + MEDCouplingAutoRefCountObjectPtr ret=mesh->buildPart(start,end); + di=diSafe.retn(); + return ret.retn(); +} + +/*! + * This method is strictly equivalent to MEDCouplingFieldDiscretizationGauss::buildSubMeshData except that it is optimized for input defined as a range of cell ids. + * + * \param [out] beginOut Valid only if \a di is NULL + * \param [out] endOut Valid only if \a di is NULL + * \param [out] stepOut Valid only if \a di is NULL + * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable. + * + * \sa MEDCouplingFieldDiscretizationGauss::buildSubMeshData + */ +MEDCouplingMesh *MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const +{ + if(stepCellIds!=1)//even for stepCellIds==-1 the output will not be a range + return MEDCouplingFieldDiscretization::buildSubMeshDataRange(mesh,beginCellIds,endCellIds,stepCellIds,beginOut,endOut,stepOut,di); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange : NULL input mesh !"); + if(!_discr_per_cell) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange : no discretization array set !"); + di=0; beginOut=0; endOut=0; stepOut=stepCellIds; + const char msg[]="MEDCouplingFieldDiscretizationGauss::buildSubMeshDataRange : cell #"; + int nbOfTuples=_discr_per_cell->getNumberOfTuples(); + const int *w=_discr_per_cell->begin(); + int nbMaxOfLocId=(int)_loc.size(); + for(int i=0;i=0 && *w=endCellIds) + break; + } + else + { std::ostringstream oss; oss << msg << i << " has invalid id (" << *w << ") ! Should be in [0," << nbMaxOfLocId << ") !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } + } + else + { std::ostringstream oss; oss << msg << i << " is detected as orphan !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } + } + MEDCouplingAutoRefCountObjectPtr ret=mesh->buildPartRange(beginCellIds,endCellIds,stepCellIds); + return ret.retn(); } /*! @@ -1390,20 +1628,10 @@ DataArrayInt *MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCe { if(!mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCellIds : null mesh !"); - if(!_discr_per_cell) - throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCellIds : null discretization ids !"); + MEDCouplingAutoRefCountObjectPtr nbOfNodesPerCell=buildNbOfGaussPointPerCellField();//check of _discr_per_cell not NULL pointer int nbOfCells=mesh->getNumberOfCells(); if(_discr_per_cell->getNumberOfTuples()!=nbOfCells) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCellIds : mismatch of nb of tuples of cell ids array and number of cells !"); - MEDCouplingAutoRefCountObjectPtr nbOfNodesPerCell=DataArrayInt::New(); nbOfNodesPerCell->alloc(nbOfCells,1); - int *retPtr=nbOfNodesPerCell->getPointer(); - const int *pt=_discr_per_cell->getConstPointer(); - int nbMaxOfLocId=(int)_loc.size(); - for(int i=0;i=0 && *ptcomputeOffsets2(); MEDCouplingAutoRefCountObjectPtr sel=DataArrayInt::New(); sel->useArray(startCellIds,false,CPP_DEALLOC,(int)std::distance(startCellIds,endCellIds),1); return sel->buildExplicitArrByRanges(nbOfNodesPerCell); @@ -1426,41 +1654,45 @@ void MEDCouplingFieldDiscretizationGauss::renumberValuesOnCellsR(const MEDCoupli throw INTERP_KERNEL::Exception("Number of cells has changed and becomes higher with some cells that have been split ! Unable to conserve the Gauss field !"); } -void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType(const MEDCouplingMesh *m, INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, +void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType(const MEDCouplingMesh *mesh, INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType : NULL input mesh !"); const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type); - if((int)cm.getDimension()!=m->getMeshDimension()) + if((int)cm.getDimension()!=mesh->getMeshDimension()) { - std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType : mismatch of dimensions ! MeshDim==" << m->getMeshDimension(); + std::ostringstream oss; oss << "MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnType : mismatch of dimensions ! MeshDim==" << mesh->getMeshDimension(); oss << " whereas Type '" << cm.getRepr() << "' has dimension " << cm.getDimension() << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - buildDiscrPerCellIfNecessary(m); + buildDiscrPerCellIfNecessary(mesh); int id=(int)_loc.size(); MEDCouplingGaussLocalization elt(type,refCoo,gsCoo,wg); _loc.push_back(elt); int *ptr=_discr_per_cell->getPointer(); - int nbCells=m->getNumberOfCells(); + int nbCells=mesh->getNumberOfCells(); for(int i=0;igetTypeOfCell(i)==type) + if(mesh->getTypeOfCell(i)==type) ptr[i]=id; zipGaussLocalizations(); } -void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells(const MEDCouplingMesh *m, const int *begin, const int *end, const std::vector& refCoo, +void MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells(const MEDCouplingMesh *mesh, const int *begin, const int *end, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) { - buildDiscrPerCellIfNecessary(m); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalizationOnCells : NULL input mesh !"); + buildDiscrPerCellIfNecessary(mesh); if(std::distance(begin,end)<1) throw INTERP_KERNEL::Exception("Size of [begin,end) must be equal or greater than 1 !"); - INTERP_KERNEL::NormalizedCellType type=m->getTypeOfCell(*begin); + INTERP_KERNEL::NormalizedCellType type=mesh->getTypeOfCell(*begin); MEDCouplingGaussLocalization elt(type,refCoo,gsCoo,wg); int id=(int)_loc.size(); int *ptr=_discr_per_cell->getPointer(); for(const int *w=begin+1;w!=end;w++) { - if(m->getTypeOfCell(*w)!=type) + if(mesh->getTypeOfCell(*w)!=type) { std::ostringstream oss; oss << "The cell with id " << *w << " has been detected to be incompatible in the [begin,end) array specified !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); @@ -1484,6 +1716,25 @@ void MEDCouplingFieldDiscretizationGauss::clearGaussLocalizations() throw(INTERP _loc.clear(); } +void MEDCouplingFieldDiscretizationGauss::setGaussLocalization(int locId, const MEDCouplingGaussLocalization& loc) throw(INTERP_KERNEL::Exception) +{ + if(locId<0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalization : localization id has to be >=0 !"); + int sz=(int)_loc.size(); + MEDCouplingGaussLocalization gLoc(INTERP_KERNEL::NORM_ERROR); + if(locId>=sz) + _loc.resize(locId+1,gLoc); + _loc[locId]=loc; +} + +void MEDCouplingFieldDiscretizationGauss::resizeLocalizationVector(int newSz) throw(INTERP_KERNEL::Exception) +{ + if(newSz<0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::resizeLocalizationVector : new size has to be >=0 !"); + MEDCouplingGaussLocalization gLoc(INTERP_KERNEL::NORM_ERROR); + _loc.resize(newSz,gLoc); +} + MEDCouplingGaussLocalization& MEDCouplingFieldDiscretizationGauss::getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception) { checkLocalizationId(locId); @@ -1499,7 +1750,7 @@ int MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneCell(int cel { if(!_discr_per_cell) throw INTERP_KERNEL::Exception("No Gauss localization still set !"); - int locId=_discr_per_cell->getConstPointer()[cellId]; + int locId=_discr_per_cell->begin()[cellId]; if(locId<0) throw INTERP_KERNEL::Exception("No Gauss localization set for the specified cell !"); return locId; @@ -1571,17 +1822,34 @@ DataArrayInt *MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellFie throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::buildNbOfGaussPointPerCellField : no discretization array set !"); int nbOfTuples=_discr_per_cell->getNumberOfTuples(); MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); - const int *w=_discr_per_cell->getConstPointer(); + const int *w=_discr_per_cell->begin(); ret->alloc(nbOfTuples,1); int *valsToFill=ret->getPointer(); + int nbMaxOfLocId=(int)_loc.size(); for(int i=0;i=0 && *wgetConstPointer(); + const int *start=_discr_per_cell->begin(); int nbOfTuples=_discr_per_cell->getNumberOfTuples(); INTERP_KERNEL::AutoPtr tmp=new int[_loc.size()]; std::fill((int *)tmp,(int *)tmp+_loc.size(),-2); @@ -1645,6 +1913,11 @@ const char *MEDCouplingFieldDiscretizationGaussNE::getRepr() const bool MEDCouplingFieldDiscretizationGaussNE::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const { + if(!other) + { + reason="other spatial discretization is NULL, and this spatial discretization (GaussNE) is defined."; + return false; + } const MEDCouplingFieldDiscretizationGaussNE *otherC=dynamic_cast(other); bool ret=otherC!=0; if(!ret) @@ -1654,6 +1927,8 @@ bool MEDCouplingFieldDiscretizationGaussNE::isEqualIfNotWhy(const MEDCouplingFie int MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuples(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getNumberOfTuples : NULL input mesh !"); int ret=0; int nbOfCells=mesh->getNumberOfCells(); for(int i=0;igetNumberOfCells(); } DataArrayInt *MEDCouplingFieldDiscretizationGaussNE::getOffsetArr(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getOffsetArr : NULL input mesh !"); int nbOfTuples=mesh->getNumberOfCells(); DataArrayInt *ret=DataArrayInt::New(); ret->alloc(nbOfTuples+1,1); @@ -1693,6 +1972,8 @@ DataArrayInt *MEDCouplingFieldDiscretizationGaussNE::getOffsetArr(const MEDCoupl void MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell(const MEDCouplingMesh *mesh, const std::vector& arrays, const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell : NULL input mesh !"); const int *array=old2NewBg; if(check) array=DataArrayInt::CheckAndPreparePermutation(old2NewBg,old2NewBg+mesh->getNumberOfCells()); @@ -1726,6 +2007,8 @@ void MEDCouplingFieldDiscretizationGaussNE::renumberArraysForCell(const MEDCoupl DataArrayDouble *MEDCouplingFieldDiscretizationGaussNE::getLocalizationOfDiscValues(const MEDCouplingMesh *mesh) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getLocalizationOfDiscValues : NULL input mesh !"); MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); MEDCouplingAutoRefCountObjectPtr umesh=mesh->buildUnstructured();//in general do nothing int nbOfTuples=getNumberOfTuples(umesh); @@ -1914,6 +2197,8 @@ void MEDCouplingFieldDiscretizationGaussNE::checkCompatibilityWithNature(NatureO double MEDCouplingFieldDiscretizationGaussNE::getIJK(const MEDCouplingMesh *mesh, const DataArrayDouble *da, int cellId, int nodeIdInCell, int compoId) const throw(INTERP_KERNEL::Exception) { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::getIJK : NULL input mesh !"); int offset=0; for(int i=0;ibuildPart(start,end); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData : NULL input mesh !"); + MEDCouplingAutoRefCountObjectPtr diSafe=computeTupleIdsToSelectFromCellIds(mesh,start,end); + MEDCouplingAutoRefCountObjectPtr ret=mesh->buildPart(start,end); + di=diSafe.retn(); + return ret.retn(); +} + +/*! + * This method is strictly equivalent to MEDCouplingFieldDiscretizationGauss::buildSubMeshData except that it is optimized for input defined as a range of cell ids. + * + * \param [out] beginOut Valid only if \a di is NULL + * \param [out] endOut Valid only if \a di is NULL + * \param [out] stepOut Valid only if \a di is NULL + * \param [out] di is an array returned that specifies entity ids (nodes, cells, Gauss points... ) in array if no output range is foundable. + * + * \sa MEDCouplingFieldDiscretizationGauss::buildSubMeshData + */ +MEDCouplingMesh *MEDCouplingFieldDiscretizationGaussNE::buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const +{ + if(stepCellIds!=1)//even for stepCellIds==-1 the output will not be a range + return MEDCouplingFieldDiscretization::buildSubMeshDataRange(mesh,beginCellIds,endCellIds,stepCellIds,beginOut,endOut,stepOut,di); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGaussNE::buildSubMeshDataRange : NULL input mesh !"); + int nbOfCells=mesh->getNumberOfCells(); + di=0; beginOut=0; endOut=0; stepOut=stepCellIds; + const char msg[]="MEDCouplingFieldDiscretizationGaussNE::buildSubMeshDataRange : cell #"; + for(int i=0;igetTypeOfCell(i); + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type); + if(cm.isDynamic()) + { std::ostringstream oss; oss << msg << i << " presence of dynamic cell (polygons and polyedrons) ! Not implemented !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } + int delta=cm.getNumberOfNodes(); + if(i=endCellIds) + break; + } + MEDCouplingAutoRefCountObjectPtr ret=mesh->buildPartRange(beginCellIds,endCellIds,stepCellIds); + return ret.retn(); } + /*! * This method returns a tuple ids selection from cell ids selection [start;end). * This method is called by MEDCouplingFieldDiscretizationGaussNE::buildSubMeshData to return parameter \b di. @@ -2024,6 +2350,11 @@ void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnCellsR(const MEDCoup throw INTERP_KERNEL::Exception("Not implemented yet !"); } +void MEDCouplingFieldDiscretizationGaussNE::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception) +{ + stream << "Gauss points on nodes per element spatial discretization."; +} + MEDCouplingFieldDiscretizationGaussNE::MEDCouplingFieldDiscretizationGaussNE(const MEDCouplingFieldDiscretizationGaussNE& other):MEDCouplingFieldDiscretization(other) { } @@ -2061,6 +2392,11 @@ void MEDCouplingFieldDiscretizationKriging::checkCompatibilityWithNature(NatureO bool MEDCouplingFieldDiscretizationKriging::isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const { + if(!other) + { + reason="other spatial discretization is NULL, and this spatial discretization (Kriginig) is defined."; + return false; + } const MEDCouplingFieldDiscretizationKriging *otherC=dynamic_cast(other); bool ret=otherC!=0; if(!ret) @@ -2083,6 +2419,8 @@ void MEDCouplingFieldDiscretizationKriging::getValueOn(const DataArrayDouble *ar DataArrayDouble *MEDCouplingFieldDiscretizationKriging::getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfTargetPoints) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::getValueOnMulti : NULL input mesh !"); MEDCouplingAutoRefCountObjectPtr coords=getLocalizationOfDiscValues(mesh); int nbOfPts=coords->getNumberOfTuples(); int dimension=coords->getNumberOfComponents(); @@ -2115,6 +2453,11 @@ DataArrayDouble *MEDCouplingFieldDiscretizationKriging::getValueOnMulti(const Da return ret.retn(); } +void MEDCouplingFieldDiscretizationKriging::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception) +{ + stream << "Kriging spatial discretization."; +} + /*! * This method computes coefficients to apply to each representing points of \a mesh, that is to say the nodes of \a mesh given a field array \a arr whose * number of tuples should be equal to the number of representing points in \a mesh. @@ -2127,6 +2470,8 @@ DataArrayDouble *MEDCouplingFieldDiscretizationKriging::getValueOnMulti(const Da */ DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeVectorOfCoefficients(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, int& isDrift) const { + if(!mesh) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationKriging::computeVectorOfCoefficients : NULL input mesh !"); MEDCouplingAutoRefCountObjectPtr coords=getLocalizationOfDiscValues(mesh); int nbOfPts=coords->getNumberOfTuples(); //int dimension=coords->getNumberOfComponents(); @@ -2217,4 +2562,3 @@ DataArrayDouble *MEDCouplingFieldDiscretizationKriging::performDrift(const DataA // return ret.retn(); } - diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx index 7ba3e9068..22e40cea7 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx @@ -55,6 +55,7 @@ namespace ParaMEDMEM virtual MEDCouplingFieldDiscretization *deepCpy() const; virtual MEDCouplingFieldDiscretization *clone() const = 0; virtual MEDCouplingFieldDiscretization *clonePart(const int *startCellIds, const int *endCellIds) const; + virtual MEDCouplingFieldDiscretization *clonePartRange(int beginCellIds, int endCellIds, int stepCellIds) const; virtual std::string getStringRepr() const = 0; virtual const char *getRepr() const = 0; virtual int getNumberOfTuples(const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception) = 0; @@ -78,6 +79,7 @@ namespace ParaMEDMEM virtual DataArrayDouble *getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const = 0; virtual DataArrayInt *computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const = 0; virtual MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const = 0; + virtual MEDCouplingMesh *buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const; virtual void renumberValuesOnNodes(double epsOnVals, const int *old2New, int newNbOfNodes, DataArrayDouble *arr) const = 0; virtual void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const = 0; virtual void renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const = 0; @@ -98,6 +100,7 @@ namespace ParaMEDMEM virtual std::set getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception); virtual void getCellIdsHavingGaussLocalization(int locId, std::vector& cellIds) const throw(INTERP_KERNEL::Exception); virtual const MEDCouplingGaussLocalization& getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception); + virtual void reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception) = 0; virtual ~MEDCouplingFieldDiscretization(); protected: MEDCouplingFieldDiscretization(); @@ -134,7 +137,9 @@ namespace ParaMEDMEM void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const; void renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const; MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const; + MEDCouplingMesh *buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const; DataArrayInt *computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const; + void reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception); public: static const char REPR[]; static const TypeOfField TYPE; @@ -153,6 +158,7 @@ namespace ParaMEDMEM DataArrayInt *&cellRestriction, DataArrayInt *&trueTupleRestriction) const throw(INTERP_KERNEL::Exception); void checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception); MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const; + MEDCouplingMesh *buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const; DataArrayInt *computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const; void renumberValuesOnNodes(double epsOnVals, const int *old2New, int newNbOfNodes, DataArrayDouble *arr) const; void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const; @@ -173,6 +179,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const; void getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const; DataArrayDouble *getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const; + void reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception); public: static const char REPR[]; static const TypeOfField TYPE; @@ -188,11 +195,13 @@ namespace ParaMEDMEM { public: const DataArrayInt *getArrayOfDiscIds() const; + void setArrayOfDiscIds(const DataArrayInt *adids) throw(INTERP_KERNEL::Exception); void checkNoOrphanCells() const throw(INTERP_KERNEL::Exception); std::vector splitIntoSingleGaussDicrPerCellType(std::vector< int >& locIds) const throw(INTERP_KERNEL::Exception); protected: MEDCouplingFieldDiscretizationPerCell(); MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other, const int *startCellIds, const int *endCellIds); + MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other, int beginCellIds, int endCellIds, int stepCellIds); ~MEDCouplingFieldDiscretizationPerCell(); void updateTime() const; std::size_t getHeapMemorySize() const; @@ -201,7 +210,7 @@ namespace ParaMEDMEM bool isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const; void renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception); protected: - void buildDiscrPerCellIfNecessary(const MEDCouplingMesh *m); + void buildDiscrPerCellIfNecessary(const MEDCouplingMesh *mesh); protected: DataArrayInt *_discr_per_cell; static const int DFT_INVALID_LOCID_VALUE; @@ -216,6 +225,7 @@ namespace ParaMEDMEM bool isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const; MEDCouplingFieldDiscretization *clone() const; MEDCouplingFieldDiscretization *clonePart(const int *startCellIds, const int *endCellIds) const; + MEDCouplingFieldDiscretization *clonePartRange(int beginCellIds, int endCellIds, int stepCellIds) const; std::string getStringRepr() const; const char *getRepr() const; std::size_t getHeapMemorySize() const; @@ -240,15 +250,18 @@ namespace ParaMEDMEM void getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const; DataArrayDouble *getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const; MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const; + MEDCouplingMesh *buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const; DataArrayInt *computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const; void renumberValuesOnNodes(double epsOnVals, const int *old2New, int newNbOfNodes, DataArrayDouble *arr) const; void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const; void renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const; - void setGaussLocalizationOnType(const MEDCouplingMesh *m, INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, + void setGaussLocalizationOnType(const MEDCouplingMesh *mesh, INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception); - void setGaussLocalizationOnCells(const MEDCouplingMesh *m, const int *begin, const int *end, const std::vector& refCoo, + void setGaussLocalizationOnCells(const MEDCouplingMesh *mesh, const int *begin, const int *end, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception); void clearGaussLocalizations() throw(INTERP_KERNEL::Exception); + void setGaussLocalization(int locId, const MEDCouplingGaussLocalization& loc) throw(INTERP_KERNEL::Exception); + void resizeLocalizationVector(int newSz) throw(INTERP_KERNEL::Exception); MEDCouplingGaussLocalization& getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception); int getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception); int getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception); @@ -257,8 +270,10 @@ namespace ParaMEDMEM void getCellIdsHavingGaussLocalization(int locId, std::vector& cellIds) const throw(INTERP_KERNEL::Exception); const MEDCouplingGaussLocalization& getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception); DataArrayInt *buildNbOfGaussPointPerCellField() const throw(INTERP_KERNEL::Exception); + void reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception); protected: MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other, const int *startCellIds=0, const int *endCellIds=0); + MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other, int beginCellIds, int endCellIds, int stepCellIds); void zipGaussLocalizations(); int getOffsetOfCell(int cellId) const throw(INTERP_KERNEL::Exception); void checkLocalizationId(int locId) const throw(INTERP_KERNEL::Exception); @@ -298,10 +313,12 @@ namespace ParaMEDMEM void getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const; DataArrayDouble *getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const; MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const; + MEDCouplingMesh *buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const; DataArrayInt *computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const; void renumberValuesOnNodes(double epsOnVals, const int *old2New, int newNbOfNodes, DataArrayDouble *arr) const; void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const; void renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const; + void reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception); static const double *GetWeightArrayFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType, std::size_t& lgth) throw(INTERP_KERNEL::Exception); static const double *GetRefCoordsFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType, std::size_t& lgth) throw(INTERP_KERNEL::Exception); protected: @@ -358,6 +375,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *getMeasureField(const MEDCouplingMesh *mesh, bool isAbs) const; void getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const; DataArrayDouble *getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const; + void reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception); public://specific part DataArrayDouble *computeVectorOfCoefficients(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, int& isDrift) const; protected: diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index 5c874cf55..2bf4c48b8 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -130,14 +130,13 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::clone(bool recDeepCpy) const */ MEDCouplingFieldDouble *MEDCouplingFieldDouble::cloneWithMesh(bool recDeepCpy) const { - MEDCouplingFieldDouble *ret=clone(recDeepCpy); + MEDCouplingAutoRefCountObjectPtr ret=clone(recDeepCpy); if(_mesh) { - MEDCouplingMesh *mCpy=_mesh->deepCpy(); + MEDCouplingAutoRefCountObjectPtr mCpy=_mesh->deepCpy(); ret->setMesh(mCpy); - mCpy->decrRef(); } - return ret; + return ret.retn(); } /*! @@ -169,11 +168,14 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::deepCpy() const MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCopy) const { MEDCouplingTimeDiscretization *tdo=_time_discr->buildNewTimeReprFromThis(td,deepCopy); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),tdo,_type->clone()); + MEDCouplingAutoRefCountObjectPtr disc; + if(_type) + disc=_type->clone(); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(getNature(),tdo,disc.retn()); ret->setMesh(getMesh()); ret->setName(getName()); ret->setDescription(getDescription()); - return ret; + return ret.retn(); } /*! @@ -213,17 +215,30 @@ std::string MEDCouplingFieldDouble::simpleRepr() const std::ostringstream ret; ret << "FieldDouble with name : \"" << getName() << "\"\n"; ret << "Description of field is : \"" << getDescription() << "\"\n"; - ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; - ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; - ret << "FieldDouble nature of field is : " << MEDCouplingNatureOfField::GetRepr(_nature) << "\n"; + if(_type) + { ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; } + else + { ret << "FieldDouble has no spatial discretization !\n"; } + if(_time_discr) + { ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; } + else + { ret << "FieldDouble has no time discretization !\n"; } + ret << "FieldDouble nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n"; if(getArray()) { - int nbOfCompo=getArray()->getNumberOfComponents(); - ret << "FieldDouble default array has " << nbOfCompo << " components and " << getArray()->getNumberOfTuples() << " tuples.\n"; - ret << "FieldDouble default array has following info on components : "; - for(int i=0;igetInfoOnComponent(i) << "\" "; - ret << "\n"; + if(getArray()->isAllocated()) + { + int nbOfCompo=getArray()->getNumberOfComponents(); + ret << "FieldDouble default array has " << nbOfCompo << " components and " << getArray()->getNumberOfTuples() << " tuples.\n"; + ret << "FieldDouble default array has following info on components : "; + for(int i=0;igetInfoOnComponent(i) << "\" "; + ret << "\n"; + } + else + { + ret << "Array set but not allocated !\n"; + } } if(_mesh) ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr(); @@ -237,8 +252,14 @@ std::string MEDCouplingFieldDouble::advancedRepr() const std::ostringstream ret; ret << "FieldDouble with name : \"" << getName() << "\"\n"; ret << "Description of field is : \"" << getDescription() << "\"\n"; - ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; - ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; + if(_type) + { ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; } + else + { ret << "FieldDouble has no space discretization set !\n"; } + if(_time_discr) + { ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; } + else + { ret << "FieldDouble has no time discretization set !\n"; } if(getArray()) ret << "FieldDouble default array has " << getArray()->getNumberOfComponents() << " components and " << getArray()->getNumberOfTuples() << " tuples.\n"; if(_mesh) @@ -399,7 +420,9 @@ void MEDCouplingFieldDouble::renumberCells(const int *old2NewBg, bool check) thr void MEDCouplingFieldDouble::renumberCellsWithoutMesh(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception) { if(!_mesh) - throw INTERP_KERNEL::Exception("Expecting a defined mesh to be able to operate a renumbering !"); + throw INTERP_KERNEL::Exception("Expecting a defined mesh to be able to operate a renumbering !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Expecting a spatial discretization to be able to operate a renumbering !"); // _type->renumberCells(old2NewBg,check); std::vector arrays; @@ -412,8 +435,10 @@ void MEDCouplingFieldDouble::renumberCellsWithoutMesh(const int *old2NewBg, bool /*! * This method performs a clone of mesh and a renumbering of underlying nodes of it. The number of nodes remains not compulsory the same as renumberCells method. * The values of field are impacted in consequence to have the same geometrical field. + * + * \sa MEDCouplingFieldDouble::renumberNodesWithoutMesh */ -void MEDCouplingFieldDouble::renumberNodes(const int *old2NewBg) throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDouble::renumberNodes(const int *old2NewBg, double eps) throw(INTERP_KERNEL::Exception) { const MEDCouplingPointSet *meshC=dynamic_cast(_mesh); if(!meshC) @@ -421,18 +446,22 @@ void MEDCouplingFieldDouble::renumberNodes(const int *old2NewBg) throw(INTERP_KE int nbOfNodes=meshC->getNumberOfNodes(); MEDCouplingAutoRefCountObjectPtr meshC2((MEDCouplingPointSet *)meshC->deepCpy()); int newNbOfNodes=*std::max_element(old2NewBg,old2NewBg+nbOfNodes)+1; - renumberNodesWithoutMesh(old2NewBg,newNbOfNodes); + renumberNodesWithoutMesh(old2NewBg,newNbOfNodes,eps); meshC2->renumberNodes(old2NewBg,newNbOfNodes); setMesh(meshC2); } /*! * \b WARNING : use this method with lot of care ! - * This method performs half job of MEDCouplingFieldDouble::renumberNodes. That is to say no permutation of cells is done on underlying mesh. - * That is to say, the field content is changed by this method. + * ** WARNING : in case of throw the content in array can be partially modified until the exception raises ** + * This method performs half job of MEDCouplingFieldDouble::renumberNodes. That is to say no permutation of nodes is done on underlying mesh. + * That is to say, the field content is changed by this method. As the API suggests, this method can performs the half job of nodes contraction. + * That's why an epsilon is given to specify a threshold of error in case of two nodes are merged but the difference of values on these nodes are higher than \a eps. */ void MEDCouplingFieldDouble::renumberNodesWithoutMesh(const int *old2NewBg, int newNbOfNodes, double eps) throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("Expecting a spatial discretization to be able to operate a renumbering !"); std::vector arrays; _time_discr->getArrays(arrays); for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) @@ -467,15 +496,15 @@ DataArrayInt *MEDCouplingFieldDouble::getIdsInRange(double vmin, double vmax) co * * If \a this is field on node lying on a mesh that have 10 cells and 11 nodes for example. If part contains following cellIds [3,7,6]. * \a this is currently contains 11 tuples. If the restriction of mesh to 3 cells leads to a mesh with 6 nodes, the returned field, - * will contain 6 tuples and this field will lie on this restricted mesh. + * will contain 6 tuples and this field will lie on this restricted mesh. + * + * \sa MEDCouplingFieldDouble::buildSubPartRange */ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const DataArrayInt *part) const throw(INTERP_KERNEL::Exception) { if(part==0) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : not empty array must be passed to this method !"); - const int *start=part->getConstPointer(); - const int *end=start+part->getNbOfElems(); - return buildSubPart(start,end); + return buildSubPart(part->begin(),part->end()); } /*! @@ -506,14 +535,16 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const DataArrayInt * \ref cpp_mcfielddouble_subpart1 "Here a C++ example." * * \ref py_mcfielddouble_subpart1 "Here a Python example." - * \sa ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart(const DataArrayInt *) const + * \sa ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart(const DataArrayInt *) const, MEDCouplingFieldDouble::buildSubPartRange */ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const int *partBg, const int *partEnd) const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : Expecting a not NULL spatial discretization !"); DataArrayInt *arrSelect; MEDCouplingAutoRefCountObjectPtr m=_type->buildSubMeshData(_mesh,partBg,partEnd,arrSelect); MEDCouplingAutoRefCountObjectPtr arrSelect2(arrSelect); - MEDCouplingFieldDouble *ret=clone(false);//quick shallow copy. + MEDCouplingAutoRefCountObjectPtr ret=clone(false);//quick shallow copy. const MEDCouplingFieldDiscretization *disc=getDiscretization(); if(disc) ret->setDiscretization(MEDCouplingAutoRefCountObjectPtr(disc->clonePart(partBg,partEnd))); @@ -521,6 +552,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const int *partBg, std::vector arrays; _time_discr->getArrays(arrays); std::vector arrs; + std::vector< MEDCouplingAutoRefCountObjectPtr > arrsSafe; const int *arrSelBg=arrSelect->begin(); const int *arrSelEnd=arrSelect->end(); for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) @@ -528,13 +560,53 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const int *partBg, DataArrayDouble *arr=0; if(*iter) arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd); - arrs.push_back(arr); + arrs.push_back(arr); arrsSafe.push_back(arr); } ret->_time_discr->setArrays(arrs,0); - for(std::vector::const_iterator iter=arrs.begin();iter!=arrs.end();iter++) - if(*iter) - (*iter)->decrRef(); - return ret; + return ret.retn(); +} + +/*! + * This method is equivalent to MEDCouplingFieldDouble::buildSubPart, the only difference is that the input range of cell ids is + * given using a range given \a begin, \a end and \a step to optimize the part computation. + * + * \sa MEDCouplingFieldDouble::buildSubPart + */ +MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPartRange(int begin, int end, int step) const throw(INTERP_KERNEL::Exception) +{ + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : Expecting a not NULL spatial discretization !"); + DataArrayInt *arrSelect; + int beginOut,endOut,stepOut; + MEDCouplingAutoRefCountObjectPtr m=_type->buildSubMeshDataRange(_mesh,begin,end,step,beginOut,endOut,stepOut,arrSelect); + MEDCouplingAutoRefCountObjectPtr arrSelect2(arrSelect); + MEDCouplingAutoRefCountObjectPtr ret=clone(false);//quick shallow copy. + const MEDCouplingFieldDiscretization *disc=getDiscretization(); + if(disc) + ret->setDiscretization(MEDCouplingAutoRefCountObjectPtr(disc->clonePartRange(begin,end,step))); + ret->setMesh(m); + std::vector arrays; + _time_discr->getArrays(arrays); + std::vector arrs; + std::vector< MEDCouplingAutoRefCountObjectPtr > arrsSafe; + for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) + { + DataArrayDouble *arr=0; + if(*iter) + { + if(arrSelect) + { + const int *arrSelBg=arrSelect->begin(); + const int *arrSelEnd=arrSelect->end(); + arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd); + } + else + arr=(*iter)->selectByTupleId2(beginOut,endOut,stepOut); + } + arrs.push_back(arr); arrsSafe.push_back(arr); + } + ret->_time_discr->setArrays(arrs,0); + return ret.retn(); } TypeOfTimeDiscretization MEDCouplingFieldDouble::getTimeDiscretization() const @@ -573,6 +645,8 @@ void MEDCouplingFieldDouble::checkCoherency() const throw(INTERP_KERNEL::Excepti { if(!_mesh) throw INTERP_KERNEL::Exception("Field invalid because no mesh specified !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::checkCoherency : no spatial discretization !"); _time_discr->checkCoherency(); _type->checkCoherencyBetween(_mesh,getArray()); } @@ -637,6 +711,7 @@ double MEDCouplingFieldDouble::getMaxValue2(DataArrayInt*& tupleIds) const throw double ret=-std::numeric_limits::max(); bool isExistingArr=false; tupleIds=0; + MEDCouplingAutoRefCountObjectPtr ret1; for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) { if(*iter) @@ -644,14 +719,14 @@ double MEDCouplingFieldDouble::getMaxValue2(DataArrayInt*& tupleIds) const throw isExistingArr=true; DataArrayInt *tmp; ret=std::max(ret,(*iter)->getMaxValue2(tmp)); - if(!tupleIds) - tupleIds=tmp; - else - tmp->decrRef(); + MEDCouplingAutoRefCountObjectPtr tmpSafe(tmp); + if(!((const DataArrayInt *)ret1)) + ret1=tmpSafe; } } if(!isExistingArr) throw INTERP_KERNEL::Exception("getMaxValue2 : No arrays defined !"); + tupleIds=ret1.retn(); return ret; } @@ -694,6 +769,7 @@ double MEDCouplingFieldDouble::getMinValue2(DataArrayInt*& tupleIds) const throw double ret=-std::numeric_limits::max(); bool isExistingArr=false; tupleIds=0; + MEDCouplingAutoRefCountObjectPtr ret1; for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) { if(*iter) @@ -701,14 +777,14 @@ double MEDCouplingFieldDouble::getMinValue2(DataArrayInt*& tupleIds) const throw isExistingArr=true; DataArrayInt *tmp; ret=std::max(ret,(*iter)->getMinValue2(tmp)); - if(!tupleIds) - tupleIds=tmp; - else - tmp->decrRef(); + MEDCouplingAutoRefCountObjectPtr tmpSafe(tmp); + if(!((const DataArrayInt *)ret1)) + ret1=tmpSafe; } } if(!isExistingArr) throw INTERP_KERNEL::Exception("getMinValue2 : No arrays defined !"); + tupleIds=ret1.retn(); return ret; } @@ -807,7 +883,9 @@ double MEDCouplingFieldDouble::getWeightedAverageValue(int compId, bool isWAbs) double MEDCouplingFieldDouble::normL1(int compId) const throw(INTERP_KERNEL::Exception) { if(!_mesh) - throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL1"); + throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL1 !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL1 !"); int nbComps=getArray()->getNumberOfComponents(); if(compId<0 || compId>=nbComps) { @@ -830,6 +908,8 @@ void MEDCouplingFieldDouble::normL1(double *res) const throw(INTERP_KERNEL::Exce { if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL1"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL1 !"); _type->normL1(_mesh,getArray(),res); } @@ -844,6 +924,8 @@ double MEDCouplingFieldDouble::normL2(int compId) const throw(INTERP_KERNEL::Exc { if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL2"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL2 !"); int nbComps=getArray()->getNumberOfComponents(); if(compId<0 || compId>=nbComps) { @@ -866,6 +948,8 @@ void MEDCouplingFieldDouble::normL2(double *res) const throw(INTERP_KERNEL::Exce { if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL2"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL2 !"); _type->normL2(_mesh,getArray(),res); } @@ -878,6 +962,8 @@ double MEDCouplingFieldDouble::integral(int compId, bool isWAbs) const throw(INT { if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform integral"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform integral !"); int nbComps=getArray()->getNumberOfComponents(); if(compId<0 || compId>=nbComps) { @@ -898,6 +984,8 @@ void MEDCouplingFieldDouble::integral(bool isWAbs, double *res) const throw(INTE { if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform integral2"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform integral2 !"); _type->integral(_mesh,getArray(),isWAbs,res); } @@ -911,6 +999,8 @@ void MEDCouplingFieldDouble::getValueOnPos(int i, int j, int k, double *res) con const DataArrayDouble *arr=_time_discr->getArray(); if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOnPos"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnPos !"); _type->getValueOnPos(arr,_mesh,i,j,k,res); } @@ -923,6 +1013,8 @@ void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double *res) con const DataArrayDouble *arr=_time_discr->getArray(); if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOn"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnPos !"); _type->getValueOn(arr,_mesh,spaceLoc,res); } @@ -934,6 +1026,8 @@ DataArrayDouble *MEDCouplingFieldDouble::getValueOnMulti(const double *spaceLoc, const DataArrayDouble *arr=_time_discr->getArray(); if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOnMulti"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnMulti !"); return _type->getValueOnMulti(arr,_mesh,spaceLoc,nbOfPoints); } @@ -947,6 +1041,8 @@ void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double time, dou std::vector< const DataArrayDouble *> arrs=_time_discr->getArraysForTime(time); if(!_mesh) throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOn"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOn !"); std::vector res2; for(std::vector< const DataArrayDouble *>::const_iterator iter=arrs.begin();iter!=arrs.end();iter++) { @@ -974,8 +1070,10 @@ MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator=(double value) throw(IN { if(!_mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::operator= : no mesh defined !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform operator = !"); int nbOfTuple=_type->getNumberOfTuples(_mesh); - _time_discr->setUniformValue(nbOfTuple,1,value); + _time_discr->setOrCreateUniformValueOnAllComponents(nbOfTuple,value); return *this; } @@ -989,6 +1087,8 @@ void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, FunctionToEvaluate f { if(!_mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic : no mesh defined !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic !"); MEDCouplingAutoRefCountObjectPtr loc=_type->getLocalizationOfDiscValues(_mesh); _time_discr->fillFromAnalytic(loc,nbOfComp,func); } @@ -1003,6 +1103,8 @@ void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const char *func) th { if(!_mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic : no mesh defined !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic !"); MEDCouplingAutoRefCountObjectPtr loc=_type->getLocalizationOfDiscValues(_mesh); _time_discr->fillFromAnalytic(loc,nbOfComp,func); } @@ -1017,6 +1119,8 @@ void MEDCouplingFieldDouble::fillFromAnalytic2(int nbOfComp, const char *func) t { if(!_mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic2 : no mesh defined !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic2 !"); MEDCouplingAutoRefCountObjectPtr loc=_type->getLocalizationOfDiscValues(_mesh); _time_discr->fillFromAnalytic2(loc,nbOfComp,func); } @@ -1031,6 +1135,8 @@ void MEDCouplingFieldDouble::fillFromAnalytic3(int nbOfComp, const std::vector loc=_type->getLocalizationOfDiscValues(_mesh); _time_discr->fillFromAnalytic3(loc,nbOfComp,varsOrder,func); } @@ -1052,6 +1158,8 @@ void MEDCouplingFieldDouble::applyFunc(int nbOfComp, double val) { if(!_mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::applyFunc : no mesh defined !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform applyFunc !"); int nbOfTuple=_type->getNumberOfTuples(_mesh); _time_discr->setUniformValue(nbOfTuple,nbOfComp,val); } @@ -1137,6 +1245,8 @@ int MEDCouplingFieldDouble::getNumberOfTuples() const throw(INTERP_KERNEL::Excep { if(!_mesh) throw INTERP_KERNEL::Exception("Impossible to retrieve number of tuples because no mesh specified !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getNumberOfTuples !"); return _type->getNumberOfTuples(_mesh); } @@ -1169,7 +1279,8 @@ std::size_t MEDCouplingFieldDouble::getHeapMemorySize() const void MEDCouplingFieldDouble::setNature(NatureOfField nat) throw(INTERP_KERNEL::Exception) { MEDCouplingField::setNature(nat); - _type->checkCompatibilityWithNature(nat); + if(_type) + _type->checkCompatibilityWithNature(nat); } /*! @@ -1189,6 +1300,8 @@ void MEDCouplingFieldDouble::synchronizeTimeWithMesh() throw(INTERP_KERNEL::Exce double MEDCouplingFieldDouble::getIJK(int cellId, int nodeIdInCell, int compoId) const { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getIJK !"); return _type->getIJK(_mesh,getArray(),cellId,nodeIdInCell,compoId); } @@ -1223,6 +1336,8 @@ void MEDCouplingFieldDouble::getTinySerializationStrInformation(std::vector& tinyInfo) const { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !"); tinyInfo.clear(); tinyInfo.push_back((int)_type->getEnum()); tinyInfo.push_back((int)_time_discr->getEnum()); @@ -1240,6 +1355,8 @@ void MEDCouplingFieldDouble::getTinySerializationIntInformation(std::vector */ void MEDCouplingFieldDouble::getTinySerializationDbleInformation(std::vector& tinyInfo) const { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !"); tinyInfo.clear(); _time_discr->getTinySerializationDbleInformation(tinyInfo); std::vector tinyInfo2; @@ -1257,6 +1374,8 @@ void MEDCouplingFieldDouble::getTinySerializationDbleInformation(std::vector& tinyInfoI, DataArrayInt *&dataInt, std::vector& arrays) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !"); dataInt=0; std::vector tinyInfoITmp(tinyInfoI); int sz=tinyInfoITmp.back(); @@ -1270,6 +1389,8 @@ void MEDCouplingFieldDouble::resizeForUnserialization(const std::vector& ti void MEDCouplingFieldDouble::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !"); std::vector tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end()); // std::vector tmp(tinyInfoD); @@ -1293,26 +1414,28 @@ void MEDCouplingFieldDouble::finishUnserialization(const std::vector& tinyI */ void MEDCouplingFieldDouble::serialize(DataArrayInt *&dataInt, std::vector& arrays) const { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform serialize !"); _time_discr->getArrays(arrays); _type->getSerializationIntArray(dataInt); } /*! - * This method tries to to change the mesh support of \a this following the parameter 'levOfCheck' and 'prec'. + * This method tries to to change the mesh support of \a this following the parameter 'levOfCheck' and 'precOnMesh'. * Semantic of 'levOfCheck' is explained in MEDCouplingMesh::checkGeoEquivalWith method. This method is used to perform the job. * If this->_mesh is not defined or other an exeption will be throw. */ -void MEDCouplingFieldDouble::changeUnderlyingMesh(const MEDCouplingMesh *other, int levOfCheck, double prec) throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDouble::changeUnderlyingMesh(const MEDCouplingMesh *other, int levOfCheck, double precOnMesh, double eps) throw(INTERP_KERNEL::Exception) { if(_mesh==0 || other==0) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::changeUnderlyingMesh : is expected to operate on not null meshes !"); DataArrayInt *cellCor=0,*nodeCor=0; - other->checkGeoEquivalWith(_mesh,levOfCheck,prec,cellCor,nodeCor); + other->checkGeoEquivalWith(_mesh,levOfCheck,precOnMesh,cellCor,nodeCor); MEDCouplingAutoRefCountObjectPtr cellCor2(cellCor),nodeCor2(nodeCor); if(cellCor) renumberCellsWithoutMesh(cellCor->getConstPointer(),false); if(nodeCor) - renumberNodesWithoutMesh(nodeCor->getConstPointer(),_mesh->getNumberOfNodes()); + renumberNodesWithoutMesh(nodeCor->getConstPointer(),nodeCor->getMaxValueInArray()+1,eps); setMesh(const_cast(other)); } @@ -1321,14 +1444,18 @@ void MEDCouplingFieldDouble::changeUnderlyingMesh(const MEDCouplingMesh *other, * No interpolation will be done here only an analyze of two underlying mesh will be done to see if the meshes are geometrically equivalent. If yes, the eventual renumbering will be done and operator-= applyed after. * This method requires that 'f' and \a this are coherent (check coherency) and that 'f' and \a this would be coherent for a merge. * Semantic of 'levOfCheck' is explained in MEDCouplingMesh::checkGeoEquivalWith method. + * \param [in] precOnMesh precision for the mesh comparison between \c this->getMesh() and \c f->getMesh() + * \param [in] eps the precision on values that can appear in case of */ -void MEDCouplingFieldDouble::substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double prec) throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDouble::substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double precOnMesh, double eps) throw(INTERP_KERNEL::Exception) { checkCoherency(); + if(!f) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::substractInPlaceDM : input field is NULL !"); f->checkCoherency(); if(!areCompatibleForMerge(f)) - throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::diffWith : Fields are not compatible ; unable to apply mergeFields on them !"); - changeUnderlyingMesh(f->getMesh(),levOfCheck,prec); + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::substractInPlaceDM : Fields are not compatible ; unable to apply mergeFields on them !"); + changeUnderlyingMesh(f->getMesh(),levOfCheck,precOnMesh,eps); operator-=(*f); } @@ -1342,6 +1469,8 @@ bool MEDCouplingFieldDouble::mergeNodes(double eps, double epsOnVals) throw(INTE const MEDCouplingPointSet *meshC=dynamic_cast(_mesh); if(!meshC) throw INTERP_KERNEL::Exception("Invalid support mesh to apply mergeNodes on it : must be a MEDCouplingPointSet one !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform mergeNodes !"); MEDCouplingAutoRefCountObjectPtr meshC2((MEDCouplingPointSet *)meshC->deepCpy()); bool ret; int ret2; @@ -1367,6 +1496,8 @@ bool MEDCouplingFieldDouble::mergeNodes2(double eps, double epsOnVals) throw(INT const MEDCouplingPointSet *meshC=dynamic_cast(_mesh); if(!meshC) throw INTERP_KERNEL::Exception("Invalid support mesh to apply mergeNodes on it : must be a MEDCouplingPointSet one !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform mergeNodes2 !"); MEDCouplingAutoRefCountObjectPtr meshC2((MEDCouplingPointSet *)meshC->deepCpy()); bool ret; int ret2; @@ -1392,6 +1523,8 @@ bool MEDCouplingFieldDouble::zipCoords(double epsOnVals) throw(INTERP_KERNEL::Ex const MEDCouplingPointSet *meshC=dynamic_cast(_mesh); if(!meshC) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::zipCoords : Invalid support mesh to apply zipCoords on it : must be a MEDCouplingPointSet one !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform zipCoords !"); MEDCouplingAutoRefCountObjectPtr meshC2((MEDCouplingPointSet *)meshC->deepCpy()); int oldNbOfNodes=meshC2->getNumberOfNodes(); MEDCouplingAutoRefCountObjectPtr arr=meshC2->zipCoordsTraducer(); @@ -1417,7 +1550,9 @@ bool MEDCouplingFieldDouble::zipConnectivity(int compType, double epsOnVals) thr { const MEDCouplingUMesh *meshC=dynamic_cast(_mesh); if(!meshC) - throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::zipCoords : Invalid support mesh to apply zipCoords on it : must be a MEDCouplingPointSet one !"); + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::zipConnectivity : Invalid support mesh to apply zipCoords on it : must be a MEDCouplingPointSet one !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform zipConnectivity !"); MEDCouplingAutoRefCountObjectPtr meshC2((MEDCouplingUMesh *)meshC->deepCpy()); int oldNbOfCells=meshC2->getNumberOfCells(); MEDCouplingAutoRefCountObjectPtr arr=meshC2->zipConnectivityTraducer(compType); @@ -1478,6 +1613,10 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::extractSlice3D(const double *ori */ bool MEDCouplingFieldDouble::simplexize(int policy) throw(INTERP_KERNEL::Exception) { + if(!_mesh) + throw INTERP_KERNEL::Exception("No underlying mesh on this field to perform simplexize !"); + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform simplexize !"); int oldNbOfCells=_mesh->getNumberOfCells(); MEDCouplingAutoRefCountObjectPtr meshC2(_mesh->deepCpy()); MEDCouplingAutoRefCountObjectPtr arr=meshC2->simplexize(policy); @@ -1495,94 +1634,112 @@ bool MEDCouplingFieldDouble::simplexize(int policy) throw(INTERP_KERNEL::Excepti MEDCouplingFieldDouble *MEDCouplingFieldDouble::doublyContractedProduct() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform doublyContractedProduct !"); MEDCouplingTimeDiscretization *td=_time_discr->doublyContractedProduct(); td->copyTinyAttrFrom(*_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); ret->setName("DoublyContractedProduct"); ret->setMesh(getMesh()); - return ret; + return ret.retn(); } MEDCouplingFieldDouble *MEDCouplingFieldDouble::determinant() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform determinant !"); MEDCouplingTimeDiscretization *td=_time_discr->determinant(); td->copyTinyAttrFrom(*_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); ret->setName("Determinant"); ret->setMesh(getMesh()); - return ret; + return ret.retn(); } MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenValues() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform eigenValues !"); MEDCouplingTimeDiscretization *td=_time_discr->eigenValues(); td->copyTinyAttrFrom(*_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); ret->setName("EigenValues"); ret->setMesh(getMesh()); - return ret; + return ret.retn(); } MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenVectors() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform eigenVectors !"); MEDCouplingTimeDiscretization *td=_time_discr->eigenVectors(); td->copyTinyAttrFrom(*_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); ret->setName("EigenVectors"); ret->setMesh(getMesh()); - return ret; + return ret.retn(); } MEDCouplingFieldDouble *MEDCouplingFieldDouble::inverse() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform inverse !"); MEDCouplingTimeDiscretization *td=_time_discr->inverse(); td->copyTinyAttrFrom(*_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); ret->setName("Inversion"); ret->setMesh(getMesh()); - return ret; + return ret.retn(); } MEDCouplingFieldDouble *MEDCouplingFieldDouble::trace() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform trace !"); MEDCouplingTimeDiscretization *td=_time_discr->trace(); td->copyTinyAttrFrom(*_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); ret->setName("Trace"); ret->setMesh(getMesh()); - return ret; + return ret.retn(); } MEDCouplingFieldDouble *MEDCouplingFieldDouble::deviator() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform deviator !"); MEDCouplingTimeDiscretization *td=_time_discr->deviator(); td->copyTinyAttrFrom(*_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); - ret->setName("Trace"); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + ret->setName("Deviator"); ret->setMesh(getMesh()); - return ret; + return ret.retn(); } MEDCouplingFieldDouble *MEDCouplingFieldDouble::magnitude() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform magnitude !"); MEDCouplingTimeDiscretization *td=_time_discr->magnitude(); td->copyTinyAttrFrom(*_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); ret->setName("Magnitude"); ret->setMesh(getMesh()); - return ret; + return ret.retn(); } MEDCouplingFieldDouble *MEDCouplingFieldDouble::maxPerTuple() const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform maxPerTuple !"); MEDCouplingTimeDiscretization *td=_time_discr->maxPerTuple(); td->copyTinyAttrFrom(*_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); std::ostringstream oss; oss << "Max_" << getName(); ret->setName(oss.str().c_str()); ret->setMesh(getMesh()); - return ret; + return ret.retn(); } void MEDCouplingFieldDouble::changeNbOfComponents(int newNbOfComp, double dftValue) throw(INTERP_KERNEL::Exception) @@ -1592,12 +1749,14 @@ void MEDCouplingFieldDouble::changeNbOfComponents(int newNbOfComp, double dftVal MEDCouplingFieldDouble *MEDCouplingFieldDouble::keepSelectedComponents(const std::vector& compoIds) const throw(INTERP_KERNEL::Exception) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform keepSelectedComponents !"); MEDCouplingTimeDiscretization *td=_time_discr->keepSelectedComponents(compoIds); td->copyTinyAttrFrom(*_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); ret->setName(getName()); ret->setMesh(getMesh()); - return ret; + return ret.retn(); } void MEDCouplingFieldDouble::setSelectedComponents(const MEDCouplingFieldDouble *f, const std::vector& compoIds) throw(INTERP_KERNEL::Exception) @@ -1616,15 +1775,20 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const MEDCouplingFie throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MergeFields on them !"); const MEDCouplingMesh *m1=f1->getMesh(); const MEDCouplingMesh *m2=f2->getMesh(); - MEDCouplingMesh *m=m1->mergeMyselfWith(m2); + if(!m1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no underlying mesh of f1 !"); + if(!f1->_time_discr) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no time discr of f1 !"); + if(!f1->_type) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no spatial discr of f1 !"); + MEDCouplingAutoRefCountObjectPtr m=m1->mergeMyselfWith(m2); MEDCouplingTimeDiscretization *td=f1->_time_discr->aggregate(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(m); - m->decrRef(); ret->setName(f1->getName()); ret->setDescription(f1->getDescription()); - return ret; + return ret.retn(); } /*! @@ -1642,6 +1806,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const std::vector tds(a.size()); std::vector::const_iterator it=a.begin(); const MEDCouplingFieldDouble *ref=(*it++); + if(!ref) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : presence of NULL instance in first place of input vector !"); for(;it!=a.end();it++) if(!ref->areCompatibleForMerge(*it)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MergeFields on them !"); @@ -1657,11 +1823,11 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const std::vectorsetName(ms2[0]->getName()); m->setDescription(ms2[0]->getDescription()); MEDCouplingTimeDiscretization *td=tds[0]->aggregate(tds); td->copyTinyAttrFrom(*(a[0]->_time_discr)); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(a[0]->getNature(),td,a[0]->_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(a[0]->getNature(),td,a[0]->_type->clone()); ret->setMesh(m); ret->setName(a[0]->getName()); ret->setDescription(a[0]->getDescription()); - return ret; + return ret.retn(); } MEDCouplingFieldDouble *MEDCouplingFieldDouble::MeldFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) @@ -1670,13 +1836,15 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MeldFields(const MEDCouplingFiel throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MeldFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->meld(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); - return ret; + return ret.retn(); } MEDCouplingFieldDouble *MEDCouplingFieldDouble::DotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { + if(!f1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::DotFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply DotFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->dot(f2->_time_discr); @@ -1688,46 +1856,65 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::DotFields(const MEDCouplingField MEDCouplingFieldDouble *MEDCouplingFieldDouble::CrossProductFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { + if(!f1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::CrossProductFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply CrossProductFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->crossProduct(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); - return ret; + return ret.retn(); } MEDCouplingFieldDouble *MEDCouplingFieldDouble::MaxFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { + if(!f1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MaxFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MaxFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->max(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); - return ret; + return ret.retn(); } MEDCouplingFieldDouble *MEDCouplingFieldDouble::MinFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { + if(!f1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MinFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MinFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->min(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); - return ret; + return ret.retn(); +} + +MEDCouplingFieldDouble *MEDCouplingFieldDouble::negate() const throw(INTERP_KERNEL::Exception) +{ + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform negate !"); + MEDCouplingTimeDiscretization *td=_time_discr->negate(); + td->copyTinyAttrFrom(*_time_discr); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + ret->setMesh(getMesh()); + return ret.retn(); } MEDCouplingFieldDouble *MEDCouplingFieldDouble::AddFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { + if(!f1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::AddFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply AddFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->add(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); - return ret; + return ret.retn(); } const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator+=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) @@ -1740,13 +1927,15 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator+=(const MEDCoupli MEDCouplingFieldDouble *MEDCouplingFieldDouble::SubstractFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { + if(!f1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::SubstractFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply SubstractFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->substract(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); - return ret; + return ret.retn(); } const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator-=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) @@ -1759,13 +1948,15 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator-=(const MEDCoupli MEDCouplingFieldDouble *MEDCouplingFieldDouble::MultiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { + if(!f1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MultiplyFields : input field is NULL !"); if(!f1->areCompatibleForMul(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MultiplyFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->multiply(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); - return ret; + return ret.retn(); } const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator*=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) @@ -1778,13 +1969,15 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator*=(const MEDCoupli MEDCouplingFieldDouble *MEDCouplingFieldDouble::DivideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { + if(!f1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::DivideFields : input field is NULL !"); if(!f1->areCompatibleForDiv(f2)) throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply DivideFields on them !"); MEDCouplingTimeDiscretization *td=f1->_time_discr->divide(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); ret->setMesh(f1->getMesh()); - return ret; + return ret.retn(); } const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator/=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) @@ -1795,6 +1988,42 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator/=(const MEDCoupli return *this; } +/*! + * Directly called by MEDCouplingFieldDouble::operator^. + * + * \sa MEDCouplingFieldDouble::operator^ + */ +MEDCouplingFieldDouble *MEDCouplingFieldDouble::PowFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) +{ + if(!f1) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::PowFields : input field is NULL !"); + if(!f1->areCompatibleForMul(f2)) + throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply PowFields on them !"); + MEDCouplingTimeDiscretization *td=f1->_time_discr->pow(f2->_time_discr); + td->copyTinyAttrFrom(*f1->_time_discr); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); + ret->setMesh(f1->getMesh()); + return ret.retn(); +} + +/*! + * Directly call MEDCouplingFieldDouble::PowFields static method. + * + * \sa MEDCouplingFieldDouble::PowFields + */ +MEDCouplingFieldDouble *MEDCouplingFieldDouble::operator^(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) +{ + return PowFields(this,&other); +} + +const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator^=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) +{ + if(!areCompatibleForDiv(&other)) + throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply /= on them !"); + _time_discr->powEqual(other._time_discr); + return *this; +} + /*! * This method writes the field series 'fs' in the VTK file 'fileName'. * If 'fs' is empty no file is written. If fields lies on more than one mesh an exception will be thrown and no file will be written too. @@ -1806,7 +2035,11 @@ void MEDCouplingFieldDouble::WriteVTK(const char *fileName, const std::vectorgetMesh(); + if(!m) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : 1st instance of field lies on NULL mesh !"); for(std::size_t i=1;igetMesh()!=m) 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."); @@ -1830,3 +2063,44 @@ void MEDCouplingFieldDouble::WriteVTK(const char *fileName, const std::vectorwriteVTKAdvanced(fileName,coss.str(),noss.str()); } + +void MEDCouplingFieldDouble::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception) +{ + stream << "MEDCouplingFieldDouble C++ instance at " << this << ". Name : \"" << _name << "\"." << std::endl; + const char *nat=0; + try + { + nat=MEDCouplingNatureOfField::GetRepr(_nature); + stream << "Nature of field : " << nat << ".\n"; + } + catch(INTERP_KERNEL::Exception& e) + { } + const MEDCouplingFieldDiscretization *fd(_type); + if(!fd) + stream << "No spatial discretization set !"; + else + fd->reprQuickOverview(stream); + stream << std::endl; + if(!_mesh) + stream << "\nNo mesh support defined !"; + else + { + std::ostringstream oss; + _mesh->reprQuickOverview(oss); + std::string tmp(oss.str()); + stream << "\nMesh info : " << tmp.substr(0,tmp.find('\n')); + } + if(_time_discr) + { + const DataArrayDouble *arr=_time_discr->getArray(); + if(arr) + { + stream << "\n\nArray info : "; + arr->reprQuickOverview(stream); + } + else + { + stream << "\n\nNo data array set !"; + } + } +} diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index 4da0aec21..6e3c3282f 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -53,11 +53,12 @@ namespace ParaMEDMEM bool areCompatibleForMeld(const MEDCouplingFieldDouble *other) const; void renumberCells(const int *old2NewBg, bool check=true) throw(INTERP_KERNEL::Exception); void renumberCellsWithoutMesh(const int *old2NewBg, bool check=true) throw(INTERP_KERNEL::Exception); - void renumberNodes(const int *old2NewBg) throw(INTERP_KERNEL::Exception); + void renumberNodes(const int *old2NewBg, double eps=1e-15) throw(INTERP_KERNEL::Exception); void renumberNodesWithoutMesh(const int *old2NewBg, int newNbOfNodes, double eps=1e-15) throw(INTERP_KERNEL::Exception); DataArrayInt *getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *buildSubPart(const DataArrayInt *part) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *buildSubPart(const int *partBg, const int *partEnd) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *buildSubPartRange(int begin, int end, int step) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *deepCpy() const; MEDCouplingFieldDouble *clone(bool recDeepCpy) const; MEDCouplingFieldDouble *cloneWithMesh(bool recDeepCpy) const; @@ -139,8 +140,8 @@ namespace ParaMEDMEM void finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS); void serialize(DataArrayInt *&dataInt, std::vector& arrays) const; // - void changeUnderlyingMesh(const MEDCouplingMesh *other, int levOfCheck, double prec) throw(INTERP_KERNEL::Exception); - void substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double prec) throw(INTERP_KERNEL::Exception); + void changeUnderlyingMesh(const MEDCouplingMesh *other, int levOfCheck, double precOnMesh, double eps=1e-15) throw(INTERP_KERNEL::Exception); + void substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double precOnMesh, double eps=1e-15) throw(INTERP_KERNEL::Exception); bool mergeNodes(double eps, double epsOnVals=1e-15) throw(INTERP_KERNEL::Exception); bool mergeNodes2(double eps, double epsOnVals=1e-15) throw(INTERP_KERNEL::Exception); bool zipCoords(double epsOnVals=1e-15) throw(INTERP_KERNEL::Exception); @@ -171,6 +172,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *max(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return MaxFields(this,&other); } static MEDCouplingFieldDouble *MinFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *min(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return MinFields(this,&other); } + MEDCouplingFieldDouble *negate() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *operator+(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return AddFields(this,&other); } const MEDCouplingFieldDouble &operator+=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); static MEDCouplingFieldDouble *AddFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); @@ -183,10 +185,14 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *operator/(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return DivideFields(this,&other); } const MEDCouplingFieldDouble &operator/=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); static MEDCouplingFieldDouble *DivideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *operator^(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); + const MEDCouplingFieldDouble &operator^=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); + static MEDCouplingFieldDouble *PowFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); static void WriteVTK(const char *fileName, const std::vector& fs) throw(INTERP_KERNEL::Exception); public: const MEDCouplingTimeDiscretization *getTimeDiscretizationUnderGround() const { return _time_discr; } MEDCouplingTimeDiscretization *getTimeDiscretizationUnderGround() { return _time_discr; } + void reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception); private: MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td); MEDCouplingFieldDouble(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td); diff --git a/src/MEDCoupling/MEDCouplingFieldTemplate.cxx b/src/MEDCoupling/MEDCouplingFieldTemplate.cxx index 41733cfd3..235146889 100644 --- a/src/MEDCoupling/MEDCouplingFieldTemplate.cxx +++ b/src/MEDCoupling/MEDCouplingFieldTemplate.cxx @@ -61,8 +61,11 @@ std::string MEDCouplingFieldTemplate::simpleRepr() const std::ostringstream ret; ret << "FieldTemplate with name : \"" << getName() << "\"\n"; ret << "Description of field is : \"" << getDescription() << "\"\n"; - ret << "FieldTemplate space discretization is : " << _type->getStringRepr() << "\n"; - ret << "FieldTemplate nature of field is : " << MEDCouplingNatureOfField::GetRepr(_nature) << "\n"; + if(_type) + { ret << "FieldTemplate space discretization is : " << _type->getStringRepr() << "\n"; } + else + { ret << "FieldTemplate has no spatial discretization !\n"; } + ret << "FieldTemplate nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n"; if(_mesh) ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr(); else @@ -77,6 +80,8 @@ std::string MEDCouplingFieldTemplate::advancedRepr() const void MEDCouplingFieldTemplate::getTinySerializationIntInformation(std::vector& tinyInfo) const { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !"); tinyInfo.clear(); tinyInfo.push_back((int)_type->getEnum()); tinyInfo.push_back((int)_nature); @@ -88,6 +93,8 @@ void MEDCouplingFieldTemplate::getTinySerializationIntInformation(std::vector& tinyInfo) const { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !"); tinyInfo.clear(); _type->getTinySerializationDbleInformation(tinyInfo); } @@ -101,6 +108,8 @@ void MEDCouplingFieldTemplate::getTinySerializationStrInformation(std::vector& tinyInfoI, DataArrayInt *&dataInt) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !"); dataInt=0; std::vector tinyInfoITmp(tinyInfoI.begin()+2,tinyInfoI.end()); _type->resizeForUnserialization(tinyInfoITmp,dataInt); @@ -108,6 +117,8 @@ void MEDCouplingFieldTemplate::resizeForUnserialization(const std::vector& void MEDCouplingFieldTemplate::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) { + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !"); _nature=(NatureOfField)tinyInfoI[1]; _type->finishUnserialization(tinyInfoD); _name=tinyInfoS[0]; @@ -119,3 +130,30 @@ void MEDCouplingFieldTemplate::serialize(DataArrayInt *&dataInt) const _type->getSerializationIntArray(dataInt); } +void MEDCouplingFieldTemplate::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception) +{ + stream << "MEDCouplingFieldTemplate C++ instance at " << this << ". Name : \"" << _name << "\"." << std::endl; + const char *nat=0; + try + { + nat=MEDCouplingNatureOfField::GetRepr(_nature); + stream << "Nature of field template : " << nat << ".\n"; + } + catch(INTERP_KERNEL::Exception& e) + { } + const MEDCouplingFieldDiscretization *fd(_type); + if(!fd) + stream << "No spatial discretization set !"; + else + fd->reprQuickOverview(stream); + stream << std::endl; + if(!_mesh) + stream << "\nNo mesh support defined !"; + else + { + std::ostringstream oss; + _mesh->reprQuickOverview(oss); + std::string tmp(oss.str()); + stream << "\nMesh info : " << tmp.substr(0,tmp.find('\n')); + } +} diff --git a/src/MEDCoupling/MEDCouplingFieldTemplate.hxx b/src/MEDCoupling/MEDCouplingFieldTemplate.hxx index b297287c2..3fb6cfa8a 100644 --- a/src/MEDCoupling/MEDCouplingFieldTemplate.hxx +++ b/src/MEDCoupling/MEDCouplingFieldTemplate.hxx @@ -43,6 +43,7 @@ namespace ParaMEDMEM void finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS); void serialize(DataArrayInt *&dataInt) const; // + void reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception); private: MEDCouplingFieldTemplate(const MEDCouplingFieldDouble& f) throw(INTERP_KERNEL::Exception); MEDCouplingFieldTemplate(TypeOfField type); diff --git a/src/MEDCoupling/MEDCouplingGaussLocalization.cxx b/src/MEDCoupling/MEDCouplingGaussLocalization.cxx index 085ea3c2f..5906ffc8b 100644 --- a/src/MEDCoupling/MEDCouplingGaussLocalization.cxx +++ b/src/MEDCoupling/MEDCouplingGaussLocalization.cxx @@ -42,6 +42,23 @@ catch(INTERP_KERNEL::Exception& e) throw e; } +ParaMEDMEM::MEDCouplingGaussLocalization::MEDCouplingGaussLocalization(INTERP_KERNEL::NormalizedCellType typ) throw(INTERP_KERNEL::Exception) +try:_type(typ) +{ + INTERP_KERNEL::CellModel::GetCellModel(_type); +} +catch(INTERP_KERNEL::Exception& e) + { + _type=INTERP_KERNEL::NORM_ERROR; + throw e; + } + +void ParaMEDMEM::MEDCouplingGaussLocalization::setType(INTERP_KERNEL::NormalizedCellType typ) throw(INTERP_KERNEL::Exception) +{ + INTERP_KERNEL::CellModel::GetCellModel(typ);//throws if not found. This is a check + _type=typ; +} + void ParaMEDMEM::MEDCouplingGaussLocalization::checkCoherency() const throw(INTERP_KERNEL::Exception) { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_type); @@ -203,6 +220,21 @@ void ParaMEDMEM::MEDCouplingGaussLocalization::setWeight(int gaussPtIdInCell, do _weight[gaussPtIdInCell]=newVal; } +void ParaMEDMEM::MEDCouplingGaussLocalization::setRefCoords(const std::vector& refCoo) throw(INTERP_KERNEL::Exception) +{ + _ref_coord=refCoo; +} + +void ParaMEDMEM::MEDCouplingGaussLocalization::setGaussCoords(const std::vector& gsCoo) throw(INTERP_KERNEL::Exception) +{ + _gauss_coord=gsCoo; +} + +void ParaMEDMEM::MEDCouplingGaussLocalization::setWeights(const std::vector& w) throw(INTERP_KERNEL::Exception) +{ + _weight=w; +} + /*! * The format of 'tinyData' parameter is the same than pushed in method ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationIntInfo. */ diff --git a/src/MEDCoupling/MEDCouplingGaussLocalization.hxx b/src/MEDCoupling/MEDCouplingGaussLocalization.hxx index cdfae2ba1..d8559ebd9 100644 --- a/src/MEDCoupling/MEDCouplingGaussLocalization.hxx +++ b/src/MEDCoupling/MEDCouplingGaussLocalization.hxx @@ -36,7 +36,9 @@ namespace ParaMEDMEM public: MEDCouplingGaussLocalization(INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& w) throw(INTERP_KERNEL::Exception); + MEDCouplingGaussLocalization(INTERP_KERNEL::NormalizedCellType typ) throw(INTERP_KERNEL::Exception); INTERP_KERNEL::NormalizedCellType getType() const { return _type; } + void setType(INTERP_KERNEL::NormalizedCellType typ) throw(INTERP_KERNEL::Exception); int getNumberOfGaussPt() const { return (int)_weight.size(); } int getDimension() const; int getNumberOfPtsInRefCell() const; @@ -57,6 +59,9 @@ namespace ParaMEDMEM void setRefCoord(int ptIdInCell, int comp, double newVal) throw(INTERP_KERNEL::Exception); void setGaussCoord(int gaussPtIdInCell, int comp, double newVal) throw(INTERP_KERNEL::Exception); void setWeight(int gaussPtIdInCell, double newVal) throw(INTERP_KERNEL::Exception); + void setRefCoords(const std::vector& refCoo) throw(INTERP_KERNEL::Exception); + void setGaussCoords(const std::vector& gsCoo) throw(INTERP_KERNEL::Exception); + void setWeights(const std::vector& w) throw(INTERP_KERNEL::Exception); // static MEDCouplingGaussLocalization BuildNewInstanceFromTinyInfo(int dim, const std::vector& tinyData); static bool AreAlmostEqual(const std::vector& v1, const std::vector& v2, double eps); diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 7e146a3bd..abfc07b23 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -39,7 +39,7 @@ template void DataArrayDouble::findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, DataArrayInt *c, DataArrayInt *cI) const { const double *coordsPtr=getConstPointer(); - BBTree myTree(bbox,0,0,nbNodes,prec/10); + BBTreePts myTree(bbox,0,0,nbNodes,prec); std::vector isDone(nbNodes); for(int i=0;i -void DataArrayDouble::FindTupleIdsNearTuplesAlg(const BBTree& myTree, const double *pos, int nbOfTuples, double eps, +void DataArrayDouble::FindTupleIdsNearTuplesAlg(const BBTreePts& myTree, const double *pos, int nbOfTuples, double eps, DataArrayInt *c, DataArrayInt *cI) { for(int i=0;i1) - { - oss2 << "("; - for(int j=0;j1) + { + oss2 << "("; + for(int j=0;j=0 && *wgetNumberOfTuples) !"); + throw INTERP_KERNEL::Exception("DataArrayDouble::selectByTupleIdSafe : some ids has been detected to be out of [0,this->getNumberOfTuples) !"); ret->copyStringInfoFrom(*this); return ret.retn(); } @@ -1445,7 +1453,6 @@ DataArrayDouble *DataArrayDouble::selectByTupleIdSafe(const int *new2OldBg, cons * \param [in] step - index increment to get index of the next tuple to copy. * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller * is to delete using decrRef() as it is no more needed. - * \throw If (\a end2 < \a bg) or (\a step <= 0). * \sa DataArrayDouble::substr. */ DataArrayDouble *DataArrayDouble::selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception) @@ -1453,7 +1460,7 @@ DataArrayDouble *DataArrayDouble::selectByTupleId2(int bg, int end2, int step) c checkAllocated(); MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); int nbComp=getNumberOfComponents(); - int newNbOfTuples=GetNumberOfItemGivenBES(bg,end2,step,"DataArrayDouble::selectByTupleId2 : "); + int newNbOfTuples=GetNumberOfItemGivenBESRelative(bg,end2,step,"DataArrayDouble::selectByTupleId2 : "); ret->alloc(newNbOfTuples,nbComp); double *pt=ret->getPointer(); const double *srcPt=getConstPointer()+bg*nbComp; @@ -1607,6 +1614,7 @@ DataArrayDouble *DataArrayDouble::changeNbOfComponents(int newNbOfComp, double d /*! * Changes the number of components within \a this array so that its raw data **does * not** change, instead splitting this data into tuples changes. + * \warning This method erases all (name and unit) component info set before! * \param [in] newNbOfComp - number of components for \a this array to have. * \throw If \a this is not allocated * \throw If getNbOfElems() % \a newNbOfCompo != 0. @@ -1634,9 +1642,9 @@ void DataArrayDouble::rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception * of tuples, and inversely its number of tuples to become equal to its number of * components. So that its raw data **does not** change, instead splitting this * data into tuples changes. - * \throw If \a this is not allocated. * \warning This method erases all (name and unit) component info set before! * \warning Do not confuse this method with fromNoInterlace() and toNoInterlace()! + * \throw If \a this is not allocated. * \sa rearrange() */ void DataArrayDouble::transpose() throw(INTERP_KERNEL::Exception) @@ -1731,10 +1739,10 @@ void DataArrayDouble::meldWith(const DataArrayDouble *other) throw(INTERP_KERNEL * * This method is typically used by MEDCouplingPointSet::findCommonNodes() and * MEDCouplingUMesh::mergeNodes(). - * \param [in] prec - minimal absolute distance between two tuples at which they are + * \param [in] prec - minimal absolute distance between two tuples (infinite norm) at which they are * considered not coincident. - * \param [in] limitTupleId - limit tuple id. Tuples with id strictly lower than \a - * limitTupleId are not considered. + * \param [in] limitTupleId - limit tuple id. If all tuples within a group of coincident + * tuples have id strictly lower than \a limitTupleId then they are not returned. * \param [out] comm - the array holding ids (== indices) of coincident tuples. * \a comm->getNumberOfComponents() == 1. * \a comm->getNumberOfTuples() == \a commIndex->back(). @@ -1761,19 +1769,17 @@ void DataArrayDouble::findCommonTuples(double prec, int limitTupleId, DataArrayI int nbOfTuples=getNumberOfTuples(); // - MEDCouplingAutoRefCountObjectPtr bbox=computeBBoxPerTuple(prec); - // MEDCouplingAutoRefCountObjectPtr c(DataArrayInt::New()),cI(DataArrayInt::New()); c->alloc(0,1); cI->pushBackSilent(0); switch(nbOfCompo) { case 3: - findCommonTuplesAlg<3>(bbox->getConstPointer(),nbOfTuples,limitTupleId,prec,c,cI); + findCommonTuplesAlg<3>(begin(),nbOfTuples,limitTupleId,prec,c,cI); break; case 2: - findCommonTuplesAlg<2>(bbox->getConstPointer(),nbOfTuples,limitTupleId,prec,c,cI); + findCommonTuplesAlg<2>(begin(),nbOfTuples,limitTupleId,prec,c,cI); break; case 1: - findCommonTuplesAlg<1>(bbox->getConstPointer(),nbOfTuples,limitTupleId,prec,c,cI); + findCommonTuplesAlg<1>(begin(),nbOfTuples,limitTupleId,prec,c,cI); break; default: throw INTERP_KERNEL::Exception("DataArrayDouble::findCommonTuples : nb of components managed are 1,2 and 3 ! not implemented for other number of components !"); @@ -1906,8 +1912,8 @@ DataArrayInt *DataArrayDouble::findClosestTupleId(const DataArrayDouble *other) * that coincident tuples are excluded. * \param [in] prec - minimal absolute distance between two tuples at which they are * considered not coincident. - * \param [in] limitTupleId - limit tuple id. Tuples with id strictly lower than \a - * limiTupleId are not considered and thus not excluded. + * \param [in] limitTupleId - limit tuple id. If all tuples within a group of coincident + * tuples have id strictly lower than \a limitTupleId then they are not excluded. * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller * is to delete using decrRef() as it is no more needed. * \throw If \a this is not allocated. @@ -2758,7 +2764,7 @@ DataArrayDouble *DataArrayDouble::computeBBoxPerTuple(double epsilon)const throw * Two tuples are considered equal if the euclidian distance between the two tuples is lower than \a eps. * * \param [in] other a DataArrayDouble having same number of components than \a this. - * \param [in] eps absolute precision representing euclidian distance between 2 tuples behind which 2 tuples are considered equal. + * \param [in] eps absolute precision representing distance (using infinite norm) between 2 tuples behind which 2 tuples are considered equal. * \param [out] c will contain the set of tuple ids in \a this that are equal to to the tuple ids in \a other contiguously. * \a cI allows to extract information in \a c. * \param [out] cI is an indirection array that allows to extract the data contained in \a c. @@ -2776,7 +2782,6 @@ void DataArrayDouble::computeTupleIdsNearTuples(const DataArrayDouble *other, do if(!other) throw INTERP_KERNEL::Exception("DataArrayDouble::computeTupleIdsNearTuples : input pointer other is null !"); checkAllocated(); - MEDCouplingAutoRefCountObjectPtr bbox=computeBBoxPerTuple(eps); other->checkAllocated(); int nbOfCompo=getNumberOfComponents(); int otherNbOfCompo=other->getNumberOfComponents(); @@ -2788,19 +2793,19 @@ void DataArrayDouble::computeTupleIdsNearTuples(const DataArrayDouble *other, do { case 3: { - BBTree<3,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10); + BBTreePts<3,int> myTree(begin(),0,0,getNumberOfTuples(),eps); FindTupleIdsNearTuplesAlg<3>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr); break; } case 2: { - BBTree<2,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10); + BBTreePts<2,int> myTree(begin(),0,0,getNumberOfTuples(),eps); FindTupleIdsNearTuplesAlg<2>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr); break; } case 1: { - BBTree<1,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10); + BBTreePts<1,int> myTree(begin(),0,0,getNumberOfTuples(),eps); FindTupleIdsNearTuplesAlg<1>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr); break; } @@ -3622,12 +3627,12 @@ void DataArrayDouble::applyLin(double a, double b) throw(INTERP_KERNEL::Exceptio /*! * Modify all elements of \a this array, so that * an element _x_ becomes \f$ numerator / x \f$. - * \param [in] numerator - the numerator used to modify array elements. - * \throw If \a this is not allocated. - * \throw If there is an element equal to 0.0 in \a this array. * \warning If an exception is thrown because of presence of 0.0 element in \a this * array, all elements processed before detection of the zero element remain * modified. + * \param [in] numerator - the numerator used to modify array elements. + * \throw If \a this is not allocated. + * \throw If there is an element equal to 0.0 in \a this array. */ void DataArrayDouble::applyInv(double numerator) throw(INTERP_KERNEL::Exception) { @@ -4028,13 +4033,12 @@ DataArrayDoubleIterator *DataArrayDouble::iterator() throw(INTERP_KERNEL::Except * array whose values are within a given range. Textual data is not copied. * \param [in] vmin - a lowest acceptable value. * \param [in] vmax - a greatest acceptable value. - * \return DataArrayDouble * - the new instance of DataArrayDouble. + * \return DataArrayInt * - the new instance of DataArrayInt. * The caller is to delete this result array using decrRef() as it is no more * needed. - * \throw If \a this->getNumberOfComponents() != 1 - * - * \ref cpp_mcdataarraydouble_getidsinrange "Here is a C++ example". + * \throw If \a this->getNumberOfComponents() != 1. * + * \ref cpp_mcdataarraydouble_getidsinrange "Here is a C++ example".
* \ref py_mcdataarraydouble_getidsinrange "Here is a Python example". */ DataArrayInt *DataArrayDouble::getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception) @@ -4817,6 +4821,7 @@ void DataArrayDouble::multiplyEqual(const DataArrayDouble *other) throw(INTERP_K * * Info on components is copied either from the first array (in the first case) or from * the array with maximal number of elements (getNbOfElems()). + * \warning No check of division by zero is performed! * \param [in] a1 - a numerator array. * \param [in] a2 - a denominator array. * \return DataArrayDouble * - the new instance of DataArrayDouble. @@ -4826,7 +4831,6 @@ void DataArrayDouble::multiplyEqual(const DataArrayDouble *other) throw(INTERP_K * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and * none of them has number of tuples or components equal to 1. - * \warning No check of division by zero is performed! */ DataArrayDouble *DataArrayDouble::Divide(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception) { @@ -4894,12 +4898,12 @@ DataArrayDouble *DataArrayDouble::Divide(const DataArrayDouble *a1, const DataAr * 3. The arrays have same number of components and \a other array has one tuple. Then * _a_ [ i, j ] /= _a2_ [ 0, j ]. * + * \warning No check of division by zero is performed! * \param [in] other - an array to divide \a this one by. * \throw If \a other is NULL. * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and * \a other has number of both tuples and components not equal to 1. - * \warning No check of division by zero is performed! */ void DataArrayDouble::divideEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception) { @@ -5590,35 +5594,7 @@ void DataArrayInt::reprQuickOverview(std::ostream& stream) const throw(INTERP_KE { int nbOfTuples=getNumberOfTuples(); stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl; - const int *data=begin(); - std::ostringstream oss2; oss2 << "["; - std::string oss2Str(oss2.str()); - bool isFinished=true; - for(int i=0;i1) - { - oss2 << "("; - for(int j=0;j1) + { + oss2 << "("; + for(int j=0;jgetNumberOfComponents() != 1. * \throw If \a arrEnd - arrBg < 2. * \throw If any value of \a this is not less than \a arrEnd[-1]. - * \warning The values contained in \a arrBg should be sorted ascendently. No - * check of this is be done. If not, the result is not warranted. - * */ void DataArrayInt::splitByValueRange(const int *arrBg, const int *arrEnd, DataArrayInt *& castArr, DataArrayInt *& rankInsideCast, DataArrayInt *& castsPresent) const throw(INTERP_KERNEL::Exception) @@ -6147,10 +6157,10 @@ void DataArrayInt::useExternalArrayWithRWAccess(const int *array, int nbOfTuple, * arranged in memory. If \a this array holds 2 components of 3 values: * \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$, then the result array holds these values arranged * as follows: \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$. + * \warning Do not confuse this method with transpose()! * \return DataArrayInt * - the new instance of DataArrayInt that the caller * is to delete using decrRef() as it is no more needed. * \throw If \a this is not allocated. - * \warning Do not confuse this method with transpose()! */ DataArrayInt *DataArrayInt::fromNoInterlace() const throw(INTERP_KERNEL::Exception) { @@ -6168,10 +6178,10 @@ DataArrayInt *DataArrayInt::fromNoInterlace() const throw(INTERP_KERNEL::Excepti * arranged in memory. If \a this array holds 2 components of 3 values: * \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$, then the result array holds these values arranged * as follows: \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$. + * \warning Do not confuse this method with transpose()! * \return DataArrayInt * - the new instance of DataArrayInt that the caller * is to delete using decrRef() as it is no more needed. * \throw If \a this is not allocated. - * \warning Do not confuse this method with transpose()! */ DataArrayInt *DataArrayInt::toNoInterlace() const throw(INTERP_KERNEL::Exception) { @@ -6402,7 +6412,6 @@ DataArrayInt *DataArrayInt::selectByTupleIdSafe(const int *new2OldBg, const int * \param [in] step - index increment to get index of the next tuple to copy. * \return DataArrayInt * - the new instance of DataArrayInt that the caller * is to delete using decrRef() as it is no more needed. - * \throw If (\a end2 < \a bg) or (\a step <= 0). * \sa DataArrayInt::substr. */ DataArrayInt *DataArrayInt::selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception) @@ -6410,7 +6419,7 @@ DataArrayInt *DataArrayInt::selectByTupleId2(int bg, int end2, int step) const t checkAllocated(); MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); int nbComp=getNumberOfComponents(); - int newNbOfTuples=GetNumberOfItemGivenBES(bg,end2,step,"DataArrayInt::selectByTupleId2 : "); + int newNbOfTuples=GetNumberOfItemGivenBESRelative(bg,end2,step,"DataArrayInt::selectByTupleId2 : "); ret->alloc(newNbOfTuples,nbComp); int *pt=ret->getPointer(); const int *srcPt=getConstPointer()+bg*nbComp; @@ -6803,6 +6812,7 @@ DataArrayInt *DataArrayInt::substr(int tupleIdBg, int tupleIdEnd) const throw(IN /*! * Changes the number of components within \a this array so that its raw data **does * not** change, instead splitting this data into tuples changes. + * \warning This method erases all (name and unit) component info set before! * \param [in] newNbOfComp - number of components for \a this array to have. * \throw If \a this is not allocated * \throw If getNbOfElems() % \a newNbOfCompo != 0. @@ -6830,9 +6840,9 @@ void DataArrayInt::rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception) * of tuples, and inversely its number of tuples to become equal to its number of * components. So that its raw data **does not** change, instead splitting this * data into tuples changes. - * \throw If \a this is not allocated. * \warning This method erases all (name and unit) component info set before! * \warning Do not confuse this method with fromNoInterlace() and toNoInterlace()! + * \throw If \a this is not allocated. * \sa rearrange() */ void DataArrayInt::transpose() throw(INTERP_KERNEL::Exception) @@ -8168,12 +8178,12 @@ DataArrayInt *DataArrayInt::negate() const throw(INTERP_KERNEL::Exception) /*! * Modify all elements of \a this array, so that * an element _x_ becomes \f$ numerator / x \f$. - * \param [in] numerator - the numerator used to modify array elements. - * \throw If \a this is not allocated. - * \throw If there is an element equal to 0 in \a this array. * \warning If an exception is thrown because of presence of 0 element in \a this * array, all elements processed before detection of the zero element remain * modified. + * \param [in] numerator - the numerator used to modify array elements. + * \throw If \a this is not allocated. + * \throw If there is an element equal to 0 in \a this array. */ void DataArrayInt::applyInv(int numerator) throw(INTERP_KERNEL::Exception) { @@ -8258,12 +8268,12 @@ DataArrayInt *DataArrayInt::getIdsInRange(int vmin, int vmax) const throw(INTERP /*! * Modify all elements of \a this array, so that * an element _x_ becomes val % x . - * \param [in] val - the divident used to modify array elements. - * \throw If \a this is not allocated. - * \throw If there is an element equal to or less than 0 in \a this array. * \warning If an exception is thrown because of presence of an element <= 0 in \a this * array, all elements processed before detection of the zero element remain * modified. + * \param [in] val - the divident used to modify array elements. + * \throw If \a this is not allocated. + * \throw If there is an element equal to or less than 0 in \a this array. */ void DataArrayInt::applyRModulus(int val) throw(INTERP_KERNEL::Exception) { @@ -9633,6 +9643,7 @@ void DataArrayInt::multiplyEqual(const DataArrayInt *other) throw(INTERP_KERNEL: * * Info on components is copied either from the first array (in the first case) or from * the array with maximal number of elements (getNbOfElems()). + * \warning No check of division by zero is performed! * \param [in] a1 - a numerator array. * \param [in] a2 - a denominator array. * \return DataArrayInt * - the new instance of DataArrayInt. @@ -9642,7 +9653,6 @@ void DataArrayInt::multiplyEqual(const DataArrayInt *other) throw(INTERP_KERNEL: * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and * none of them has number of tuples or components equal to 1. - * \warning No check of division by zero is performed! */ DataArrayInt *DataArrayInt::Divide(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception) { @@ -9710,12 +9720,12 @@ DataArrayInt *DataArrayInt::Divide(const DataArrayInt *a1, const DataArrayInt *a * 3. The arrays have same number of components and \a other array has one tuple. Then * _a_ [ i, j ] /= _a2_ [ 0, j ]. * + * \warning No check of division by zero is performed! * \param [in] other - an array to divide \a this one by. * \throw If \a other is NULL. * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and * \a other has number of both tuples and components not equal to 1. - * \warning No check of division by zero is performed! */ void DataArrayInt::divideEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception) { @@ -9776,6 +9786,7 @@ void DataArrayInt::divideEqual(const DataArrayInt *other) throw(INTERP_KERNEL::E * * Info on components is copied either from the first array (in the first case) or from * the array with maximal number of elements (getNbOfElems()). + * \warning No check of division by zero is performed! * \param [in] a1 - a dividend array. * \param [in] a2 - a divisor array. * \return DataArrayInt * - the new instance of DataArrayInt. @@ -9785,7 +9796,6 @@ void DataArrayInt::divideEqual(const DataArrayInt *other) throw(INTERP_KERNEL::E * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and * none of them has number of tuples or components equal to 1. - * \warning No check of division by zero is performed! */ DataArrayInt *DataArrayInt::Modulus(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception) { @@ -9853,12 +9863,12 @@ DataArrayInt *DataArrayInt::Modulus(const DataArrayInt *a1, const DataArrayInt * * 3. The arrays have same number of components and \a other array has one tuple. Then * _a_ [ i, j ] %= _a2_ [ 0, j ]. * + * \warning No check of division by zero is performed! * \param [in] other - a divisor array. * \throw If \a other is NULL. * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and * \a other has number of both tuples and components not equal to 1. - * \warning No check of division by zero is performed! */ void DataArrayInt::modulusEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception) { diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 077c9c75a..d6d44aeec 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -26,7 +26,6 @@ #include "MEDCouplingRefCountObject.hxx" #include "InterpKernelException.hxx" #include "BBTreePts.txx" -#include "BBTree.txx" #include #include @@ -139,8 +138,10 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT virtual void reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) = 0; MEDCOUPLING_EXPORT virtual void reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception) = 0; MEDCOUPLING_EXPORT virtual void reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception) = 0; + MEDCOUPLING_EXPORT virtual void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const throw(INTERP_KERNEL::Exception) = 0; protected: DataArray() { } + ~DataArray() { } protected: static void CheckValueInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception); static void CheckValueInRangeEx(int value, int start, int end, const char *msg) throw(INTERP_KERNEL::Exception); @@ -178,7 +179,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT double popBackSilent() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void pack() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::size_t getNbOfElemAllocated() const throw(INTERP_KERNEL::Exception) { return _mem.getNbOfElemAllocated(); } - MEDCOUPLING_EXPORT void alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void alloc(int nbOfTuple, int nbOfCompo=1) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void fillWithZero() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void fillWithValue(double val) throw(INTERP_KERNEL::Exception); @@ -197,6 +198,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isEqual(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception); @@ -330,7 +332,7 @@ namespace ParaMEDMEM template static void FindClosestTupleIdAlg(const BBTreePts& myTree, double dist, const double *pos, int nbOfTuples, const double *thisPt, int thisNbOfTuples, int *res); template - static void FindTupleIdsNearTuplesAlg(const BBTree& myTree, const double *pos, int nbOfTuples, double eps, + static void FindTupleIdsNearTuplesAlg(const BBTreePts& myTree, const double *pos, int nbOfTuples, double eps, DataArrayInt *c, DataArrayInt *cI); private: ~DataArrayDouble() { } @@ -394,7 +396,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT int popBackSilent() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void pack() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::size_t getNbOfElemAllocated() const throw(INTERP_KERNEL::Exception) { return _mem.getNbOfElemAllocated(); } - MEDCOUPLING_EXPORT void alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void alloc(int nbOfTuple, int nbOfCompo=1) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isEqual(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayInt& other, std::string& reason) const throw(INTERP_KERNEL::Exception); @@ -419,6 +421,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void transformWithIndArr(const int *indArrBg, const int *indArrEnd) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *transformWithIndArrR(const int *indArrBg, const int *indArrEnd) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void splitByValueRange(const int *arrBg, const int *arrEnd, @@ -610,7 +613,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT char popBackSilent() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void pack() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::size_t getNbOfElemAllocated() const throw(INTERP_KERNEL::Exception) { return _mem.getNbOfElemAllocated(); } - MEDCOUPLING_EXPORT void alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void alloc(int nbOfTuple, int nbOfCompo=1) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isEqual(const DataArrayChar& other) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT virtual bool isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const throw(INTERP_KERNEL::Exception); @@ -703,6 +706,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const throw(INTERP_KERNEL::Exception); private: ~DataArrayByte() { } @@ -759,6 +763,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const throw(INTERP_KERNEL::Exception); private: ~DataArrayAsciiChar() { } diff --git a/src/MEDCoupling/MEDCouplingMemArrayChar.cxx b/src/MEDCoupling/MEDCouplingMemArrayChar.cxx index 37c72e1b6..0906a91ad 100644 --- a/src/MEDCoupling/MEDCouplingMemArrayChar.cxx +++ b/src/MEDCoupling/MEDCouplingMemArrayChar.cxx @@ -580,7 +580,7 @@ DataArrayChar *DataArrayChar::selectByTupleId2(int bg, int end2, int step) const checkAllocated(); MEDCouplingAutoRefCountObjectPtr ret=buildEmptySpecializedDAChar(); int nbComp=getNumberOfComponents(); - int newNbOfTuples=GetNumberOfItemGivenBES(bg,end2,step,"DataArrayInt::selectByTupleId2 : "); + int newNbOfTuples=GetNumberOfItemGivenBESRelative(bg,end2,step,"DataArrayInt::selectByTupleId2 : "); ret->alloc(newNbOfTuples,nbComp); char *pt=ret->getPointer(); const char *srcPt=getConstPointer()+bg*nbComp; @@ -1898,35 +1898,7 @@ void DataArrayByte::reprQuickOverview(std::ostream& stream) const throw(INTERP_K { int nbOfTuples=getNumberOfTuples(); stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl; - const char *data=begin(); - std::ostringstream oss2; oss2 << "["; - std::string oss2Str(oss2.str()); - bool isFinished=true; - for(int i=0;i1) - { - oss2 << "("; - for(int j=0;j1) + { + oss2 << "("; + for(int j=0;j(&other); @@ -2223,43 +2230,7 @@ void DataArrayAsciiChar::reprQuickOverview(std::ostream& stream) const throw(INT { int nbOfTuples=getNumberOfTuples(); stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl; - const char *data=begin(); - std::ostringstream oss2; oss2 << "["; - std::string oss2Str(oss2.str()); - bool isFinished=true; - for(int i=0;i(&other); diff --git a/src/MEDCoupling/MEDCouplingMesh.cxx b/src/MEDCoupling/MEDCouplingMesh.cxx index d48d0a73e..1e1f6d278 100644 --- a/src/MEDCoupling/MEDCouplingMesh.cxx +++ b/src/MEDCoupling/MEDCouplingMesh.cxx @@ -100,6 +100,12 @@ bool MEDCouplingMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, return true; } +/*! + * Checks if \a this and another MEDCouplingMesh are fully equal. + * \param [in] other - an instance of MEDCouplingMesh to compare with \a this one. + * \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) { std::string tmp; @@ -170,9 +176,13 @@ void MEDCouplingMesh::checkGeoEquivalWith(const MEDCouplingMesh *other, int levO } /*! - * Given a nodeIds range ['partBg','partEnd'), this method returns the set of cell ids in ascendant order whose connectivity of - * these cells are fully included in the range. As a consequence the returned set of cell ids does \b not \b always fit the nodes in ['partBg','partEnd') - * This method returns the corresponding cells in a newly created array that the caller has the responsability. + * Finds cells whose all nodes are in a given array of node ids. + * \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 + * 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 { @@ -221,6 +231,28 @@ bool MEDCouplingMesh::areCompatibleForMerge(const MEDCouplingMesh *other) const return true; } +/*! + * 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. + * + * \sa MEDCouplingMesh::buildPart + */ +MEDCouplingMesh *MEDCouplingMesh::buildPartRange(int beginCellIds, int endCellIds, int stepCellIds) const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr cellIds=DataArrayInt::Range(beginCellIds,endCellIds,stepCellIds); + return buildPart(cellIds->begin(),cellIds->end()); +} + +/*! + * This method is equivalent to MEDCouplingMesh::buildPartAndReduceNodes method except that here the cell ids are specified using slice \a beginCellIds \a endCellIds and \a stepCellIds. + * + * \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) +{ + MEDCouplingAutoRefCountObjectPtr cellIds=DataArrayInt::Range(beginCellIds,endCellIds,stepCellIds); + return buildPartAndReduceNodes(cellIds->begin(),cellIds->end(),arr); +} + /*! * This method builds a field lying on 'this' with 'nbOfComp' components. * 'func' is a pointer that points to a function that takes 2 arrays in parameter and returns a boolean. @@ -269,32 +301,43 @@ void MEDCouplingMesh::copyTinyInfoFrom(const MEDCouplingMesh *other) throw(INTER } /*! - * This method builds a field lying on 'this' with 'nbOfComp' components. - * 'func' is a string that is the expression to evaluate. - * The return field will have type specified by 't'. 't' is also used to determine where values of field will be - * evaluate. - * This method is equivalent to those taking a C++ function pointer except that here the 'func' is informed by - * an interpretable input string. + * \anchor mcmesh_fillFromAnalytic + * 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 + * barycenters.
+ * For more info on supported expressions that can be used in the function, see \ref + * MEDCouplingArrayApplyFuncExpr. The function can include arbitrary named variables + * (e.g. "x","y" or "va44") to refer to components of point coordinates. Names of + * variables are sorted in \b alphabetical \b order to associate a variable name with a + * component. For example, in the expression "2*x+z", "x" stands for the component #0 + * and "z" stands for the component #1 (\b not #2)!
+ * In a general case, a value resulting from the function evaluation is assigned to all + * components of the field. But there is a possibility to have its own expression for + * each component within one function. For this purpose, there are predefined variable + * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to + * the component #0 etc). A factor of such a variable is added to the + * corresponding component only.
+ * For example, \a nbOfComp == 4, \a this->getSpaceDimension() == 3, coordinates of a + * point are (1.,3.,7.), then + * - "2*x + z" produces (5.,5.,5.,5.) + * - "2*x + 0*y + z" produces (9.,9.,9.,9.) + * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,4.) + * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,4.) * - * The dynamic interpretor uses \b alphabetical \b order to assign the component id to the var name. - * For example : - * - "2*x+z" func : x stands for component #0 and z stands for component #1 \b NOT #2 ! - * - * Some var names are reserved and have special meaning. IVec stands for (1,0,0,...). JVec stands for (0,1,0...). - * KVec stands for (0,0,1,...)... These keywords allows too differentate the evaluation of output components each other. - * - * If 'nbOfComp' equals to 4 for example and that 'this->getSpaceDimension()' equals to 3. - * - * For the input tuple T = (1.,3.,7.) : - * - '2*x+z' will return (5.,5.,5.,5.) - * - '2*x+0*y+z' will return (9.,9.,9.,9.) - * - '2*x*IVec+(x+z)*LVec' will return (2.,0.,0.,4.) - * - '2*x*IVec+(y+z)*KVec' will return (2.,0.,10.,0.) + * \param [in] t - the field type. It defines, apart from other things, points to + * coordinates of which the function is applied to get field values. + * \param [in] nbOfComp - the number of components in the result field. + * \param [in] func - a string defining the expression which is evaluated to get + * field values. + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The + * caller is to delete this field using decrRef() as it is no more needed. + * \throw If the nodal connectivity of cells is not defined. + * \throw If computing \a func fails. * - * @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 expression. - * @return field with counter = 1. + * \ref cpp_mcmesh_fillFromAnalytic "Here is a C++ example".
+ * \ref py_mcmesh_fillFromAnalytic "Here is a Python example". */ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbOfComp, const char *func) const { @@ -306,15 +349,44 @@ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic(TypeOfField t, int nbO } /*! - * This method builds a field lying on 'this' with 'nbOfComp' components. - * 'func' is a string that is the expression to evaluate. - * The return field will have type specified by 't'. 't' is also used to determine where values of field will be - * evaluate. This method is different than MEDCouplingMesh::fillFromAnalytic, because the info on components are used here to determine vars pos in 'func'. + * 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 + * barycenters. This method differs from \ref mcmesh_fillFromAnalytic "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 + * a corresponding node coordinates array (where it is set via + * DataArrayDouble::setInfoOnComponent()).
+ * For more info on supported expressions that can be used in the function, see \ref + * MEDCouplingArrayApplyFuncExpr.
+ * In a general case, a value resulting from the function evaluation is assigned to all + * components of a field value. But there is a possibility to have its own expression for + * each component within one function. For this purpose, there are predefined variable + * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to + * the component #0 etc). A factor of such a variable is added to the + * corresponding component only.
+ * For example, \a nbOfComp == 4, \a this->getSpaceDimension() == 3, names of + * spatial components are "x", "y" and "z", coordinates of a + * point are (1.,3.,7.), then + * - "2*x + z" produces (9.,9.,9.,9.) + * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,8.) + * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,8.) * - * @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 expression. - * @return field with counter = 1. + * \param [in] t - the field type. It defines, apart from other things, the points to + * coordinates of which the function is applied to get field values. + * \param [in] nbOfComp - the number of components in the result field. + * \param [in] func - a string defining the expression which is evaluated to get + * field values. + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The + * caller is to delete this field using decrRef() as it is no more needed. + * \throw If the node coordinates are not defined. + * \throw If the nodal connectivity of cells is not defined. + * \throw If computing \a func fails. + * + * \ref cpp_mcmesh_fillFromAnalytic2 "Here is a C++ example".
+ * \ref py_mcmesh_fillFromAnalytic2 "Here is a Python example". */ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic2(TypeOfField t, int nbOfComp, const char *func) const { @@ -326,15 +398,46 @@ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic2(TypeOfField t, int nb } /*! - * This method builds a field lying on 'this' with 'nbOfComp' components. - * 'func' is a string that is the expression to evaluate. - * The return field will have type specified by 't'. 't' is also used to determine where values of field will be - * evaluate. This method is different than MEDCouplingMesh::fillFromAnalytic, because 'varsOrder' specifies the pos to assign of vars in 'func'. + * 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 + * 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 + * location points; here, a component index of a variable is defined by a + * rank of the variable within the input array \a varsOrder.
+ * For more info on supported expressions that can be used in the function, see \ref + * MEDCouplingArrayApplyFuncExpr. + * In a general case, a value resulting from the function evaluation is assigned to all + * components of the field. But there is a possibility to have its own expression for + * each component within one function. For this purpose, there are predefined variable + * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to + * the component #0 etc). A factor of such a variable is added to the + * corresponding component only.
+ * For example, \a nbOfComp == 4, \a this->getSpaceDimension() == 3, names of + * spatial components are given in \a varsOrder: ["x", "y","z"], coordinates of a + * point are (1.,3.,7.), then + * - "2*x + z" produces (9.,9.,9.,9.) + * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,8.) + * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,8.) * - * @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 expression. - * @return field with counter = 1. + * \param [in] t - the field type. It defines, apart from other things, the points to + * coordinates of which the function is applied to get field values. + * \param [in] nbOfComp - the number of components in the result field. + * \param [in] varsOrder - the vector defining names of variables used to refer to + * components of coordinates of field location points. A variable named + * varsOrder[0] refers to the component #0 etc. + * \param [in] func - a string defining the expression which is evaluated to get + * field values. + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The + * caller is to delete this field using decrRef() as it is no more needed. + * \throw If the node coordinates are not defined. + * \throw If the nodal connectivity of cells is not defined. + * \throw If computing \a func fails. + * + * \ref cpp_mcmesh_fillFromAnalytic3 "Here is a C++ example".
+ * \ref py_mcmesh_fillFromAnalytic3 "Here is a Python example". */ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic3(TypeOfField t, int nbOfComp, const std::vector& varsOrder, const char *func) const { @@ -346,10 +449,17 @@ MEDCouplingFieldDouble *MEDCouplingMesh::fillFromAnalytic3(TypeOfField t, int nb } /*! - * retruns a newly created mesh with counter=1 - * that is the union of \b mesh1 and \b mesh2 if possible. The cells of \b mesh2 will appear after cells of \b mesh1. Idem for nodes. - * The only contraint is that \b mesh1 an \b mesh2 have the same mesh types. If it is not the case please use the other API of MEDCouplingMesh::MergeMeshes, - * with input vector of meshes. + * Creates a new MEDCouplingMesh by concatenating two given meshes, if possible. + * Cells and nodes of + * the first mesh precede cells and nodes of the second mesh within the result mesh. + * The meshes must be of the same mesh type, else, an exception is thrown. The method + * MergeMeshes(), accepting a vector of input meshes, has no such a limitation. + * \param [in] mesh1 - the first mesh. + * \param [in] mesh2 - the second mesh. + * \return MEDCouplingMesh * - the result mesh. It is a new instance of + * MEDCouplingMesh. The caller is to delete this mesh using decrRef() as it + * 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) { @@ -361,10 +471,22 @@ MEDCouplingMesh *MEDCouplingMesh::MergeMeshes(const MEDCouplingMesh *mesh1, cons } /*! - * retruns a newly created mesh with counter=1 - * that is the union of meshes if possible. The cells of \b meshes[1] will appear after cells of \b meshes[0]. Idem for nodes. - * This method performs a systematic conversion to unstructured meshes before performing aggregation contrary to the other ParaMEDMEM::MEDCouplingMesh::MergeMeshes with - * two parameters that work only on the same type of meshes. So here it is possible to mix different type of meshes. + * Creates a new MEDCouplingMesh by concatenating all given meshes, if possible. + * Cells and nodes of + * the *i*-th mesh precede cells and nodes of the (*i*+1)-th mesh within the result mesh. + * This method performs a systematic conversion to unstructured meshes before + * performing aggregation contrary to the other MergeMeshes() + * with two parameters that works only on the same type of meshes. So here it is possible + * to mix different type of meshes. + * \param [in] meshes - a vector of meshes to concatenate. + * \return MEDCouplingMesh * - the result mesh. It is a new instance of + * MEDCouplingUMesh. The caller is to delete this mesh using decrRef() as it + * is no more needed. + * \throw If \a meshes.size() == 0. + * \throw If \a size[ *i* ] == NULL. + * \throw If the coordinates is not set in none of the meshes. + * \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) { @@ -410,12 +532,48 @@ const char *MEDCouplingMesh::GetReprOfGeometricType(INTERP_KERNEL::NormalizedCel return cm.getRepr(); } +/*! + * Finds cells in contact with a ball (i.e. a point with precision). + * \warning This method is suitable if the caller intends to evaluate only one + * point, for more points getCellsContainingPoints() is recommended as it is + * faster. + * \param [in] pos - array of coordinates of the ball central point. + * \param [in] eps - ball radius. + * \param [in,out] elts - vector returning ids of the found cells. It is cleared + * before inserting ids. + * + * \ref cpp_mcumesh_getCellsContainingPoint "Here is a C++ example".
+ * \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 + * getCellsContainingPoint() for the case of multiple points. + * \param [in] pos - an array of coordinates of points in full interlace mode : + * X0,Y0,Z0,X1,Y1,Z1,... Size of the array must be \a + * 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, + * 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 + * point are described by following range of indices: + * [ \a eltsIndex[ *i* ], \a eltsIndex[ *i*+1 ] ) and the cell ids are + * \a elts[ \a eltsIndex[ *i* ]], \a elts[ \a eltsIndex[ *i* ] + 1 ], ... + * Number of cells in contact with the *i*-th point is + * \a eltsIndex[ *i*+1 ] - \a eltsIndex[ *i* ]. + * + * \ref cpp_mcumesh_getCellsContainingPoints "Here is a C++ example".
+ * \ref py_mcumesh_getCellsContainingPoints "Here is a Python example". + */ void MEDCouplingMesh::getCellsContainingPoints(const double *pos, int nbOfPoints, double eps, std::vector& elts, std::vector& eltsIndex) const { eltsIndex.resize(nbOfPoints+1); @@ -437,8 +595,9 @@ void MEDCouplingMesh::getCellsContainingPoints(const double *pos, int nbOfPoints } /*! - * This method writes a file in VTK format into file 'fileName'. - * An exception is thrown if the file is not writable. + * Writes \a this mesh into a VTK format file named as specified. + * \param [in] fileName - the name of the file to write in. + * \throw If \a fileName is not a writable file. */ void MEDCouplingMesh::writeVTK(const char *fileName) const throw(INTERP_KERNEL::Exception) { diff --git a/src/MEDCoupling/MEDCouplingMesh.hxx b/src/MEDCoupling/MEDCouplingMesh.hxx index 83210b6e9..ff714a769 100644 --- a/src/MEDCoupling/MEDCouplingMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMesh.hxx @@ -117,6 +117,8 @@ namespace ParaMEDMEM virtual MEDCouplingMesh *mergeMyselfWith(const MEDCouplingMesh *other) const = 0; virtual MEDCouplingMesh *buildPart(const int *start, const int *end) const = 0; virtual MEDCouplingMesh *buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const = 0; + virtual MEDCouplingMesh *buildPartRange(int beginCellIds, int endCellIds, int stepCellIds) const throw(INTERP_KERNEL::Exception); + virtual MEDCouplingMesh *buildPartRangeAndReduceNodes(int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt*& arr) const throw(INTERP_KERNEL::Exception); virtual MEDCouplingUMesh *buildUnstructured() const throw(INTERP_KERNEL::Exception) = 0; virtual DataArrayInt *simplexize(int policy) throw(INTERP_KERNEL::Exception) = 0; virtual bool areCompatibleForMerge(const MEDCouplingMesh *other) const; diff --git a/src/MEDCoupling/MEDCouplingNatureOfField.cxx b/src/MEDCoupling/MEDCouplingNatureOfField.cxx index bf8984875..3c44332fb 100644 --- a/src/MEDCoupling/MEDCouplingNatureOfField.cxx +++ b/src/MEDCoupling/MEDCouplingNatureOfField.cxx @@ -21,6 +21,7 @@ #include "MEDCouplingNatureOfField.hxx" #include +#include namespace ParaMEDMEM { @@ -37,9 +38,33 @@ namespace ParaMEDMEM { const int *pos=std::find(POS_OF_NATUREOFFIELD,POS_OF_NATUREOFFIELD+NB_OF_POSSIBILITIES,(int)nat); if(pos==POS_OF_NATUREOFFIELD+NB_OF_POSSIBILITIES) - throw INTERP_KERNEL::Exception("MEDCouplingNatureOfField::getRepr : Unrecognized nature of field !"); + { + std::ostringstream oss; oss << "MEDCouplingNatureOfField::getRepr : Unrecognized nature of field ! "; + oss << GetAllPossibilitiesStr() << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } std::size_t pos2=std::distance(POS_OF_NATUREOFFIELD,pos); return REPR_OF_NATUREOFFIELD[pos2]; } + + std::string MEDCouplingNatureOfField::GetReprNoThrow(NatureOfField nat) + { + const int *pos=std::find(POS_OF_NATUREOFFIELD,POS_OF_NATUREOFFIELD+NB_OF_POSSIBILITIES,(int)nat); + if(pos==POS_OF_NATUREOFFIELD+NB_OF_POSSIBILITIES) + return std::string("Unrecognized nature of field !"); + std::size_t pos2=std::distance(POS_OF_NATUREOFFIELD,pos); + return std::string(REPR_OF_NATUREOFFIELD[pos2]); + } + + std::string MEDCouplingNatureOfField::GetAllPossibilitiesStr() + { + std::ostringstream oss; oss << "Possibilities are : "; + for(int i=0;i& * permutation to remove duplicated nodes. * \param [in] precision - minimal absolute distance between two nodes at which they are * considered not coincident. - * \param [in] limitNodeId - limit node id. Nodes with id strictly lower than \a - * limitTupleId are \b not considered. Put -1 to this parameter to have - * all nodes treated. + * \param [in] limitNodeId - limit node id. If all nodes within a group of coincident + * nodes have id strictly lower than \a limitTupleId then they are not + * returned. Put -1 to this parameter to have all nodes returned. * \param [out] areNodesMerged - is set to \a true if any coincident nodes found. * \param [out] newNbOfNodes - returns number of unique nodes. * \return DataArrayInt * - the permutation array in "Old to New" mode. For more @@ -259,22 +259,22 @@ DataArrayInt *MEDCouplingPointSet::buildPermArrayForMergeNode(double precision, DataArrayInt *comm,*commI; findCommonNodes(precision,limitNodeId,comm,commI); int oldNbOfNodes=getNumberOfNodes(); - DataArrayInt *ret=buildNewNumberingFromCommonNodesFormat(comm,commI,newNbOfNodes); + MEDCouplingAutoRefCountObjectPtr ret=buildNewNumberingFromCommonNodesFormat(comm,commI,newNbOfNodes); areNodesMerged=(oldNbOfNodes!=newNbOfNodes); comm->decrRef(); commI->decrRef(); - return ret; + return ret.retn(); } /*! * Finds nodes coincident within \a prec tolerance. * Ids of coincident nodes are stored in output arrays. * A pair of arrays (\a comm, \a commIndex) is called "Surjective Format 2". - * \param [in] prec - minimal absolute distance between two nodes at which they are + * \param [in] prec - minimal absolute distance (using infinite norm) between two nodes at which they are * considered not coincident. - * \param [in] limitNodeId - limit node id. Nodes with id strictly lower than \a - * limitTupleId are \b not considered. Put -1 to this parameter to have - * all nodes treated. + * \param [in] limitNodeId - limit node id. If all nodes within a group of coincident + * nodes have id strictly lower than \a limitTupleId then they are not + * returned. Put -1 to this parameter to have all nodes treated. * \param [out] comm - the array holding ids of coincident nodes. * \a comm->getNumberOfComponents() == 1. * \a comm->getNumberOfTuples() == \a commIndex->back(). The caller @@ -303,7 +303,7 @@ void MEDCouplingPointSet::findCommonNodes(double prec, int limitNodeId, DataArra * \param [in] pos - pointer to coordinates of the point. This array is expected to * be of length \a this->getSpaceDimension() at least, else the * behavior is not warranted. - * \param [in] eps - the lowest distance between a point and a node at which the node is + * \param [in] eps - the lowest distance between a point and a node (using infinite norm) at which the node is * not returned by this method. * \return DataArrayInt * - a new instance of DataArrayInt holding ids of nodes * close to the point. The caller is to delete this @@ -328,7 +328,7 @@ DataArrayInt *MEDCouplingPointSet::getNodeIdsNearPoint(const double *pos, double * behavior is not warranted. * \param [in] nbOfPoints - number of points whose coordinates are given by \a pos * parameter. - * \param [in] eps - the lowest distance between a point and a node at which the node is + * \param [in] eps - the lowest distance between (using infinite norm) a point and a node at which the node is * not returned by this method. * \param [out] c - array returning ids of nodes located closer than \a eps to the * given points. The caller @@ -471,9 +471,9 @@ double MEDCouplingPointSet::getCaracteristicDimension() const * This method recenter coordinates of nodes in \b this in order to be centered at the origin to benefit about the advantages of the precision to be around the box * around origin of 'radius' 1. * + * \warning this method is non const and alterates coordinates in \b this without modifying. * \param [in] eps absolute epsilon. under that value of delta between max and min no scale is performed. * - * \warning this method is non const and alterates coordinates in \b this without modifying. */ void MEDCouplingPointSet::recenterForMaxPrecision(double eps) throw(INTERP_KERNEL::Exception) { @@ -1044,11 +1044,37 @@ MEDCouplingMesh *MEDCouplingPointSet::buildPart(const int *start, const int *end */ MEDCouplingMesh *MEDCouplingPointSet::buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const { - MEDCouplingPointSet *ret=buildPartOfMySelf(start,end,true); + MEDCouplingAutoRefCountObjectPtr ret=buildPartOfMySelf(start,end,true); arr=ret->zipCoordsTraducer(); - return ret; + return ret.retn(); } +/*! + * This method specialized the MEDCouplingMesh::buildPartRange + * + * \sa MEDCouplingUMesh::buildPartOfMySelf2 + */ +MEDCouplingMesh *MEDCouplingPointSet::buildPartRange(int beginCellIds, int endCellIds, int stepCellIds) const throw(INTERP_KERNEL::Exception) +{ + return buildPartOfMySelf2(beginCellIds,endCellIds,stepCellIds,true); +} + +/*! + * This method specialized the MEDCouplingMesh::buildPartRangeAndReduceNodes + * + * \param [out] beginOut valid only if \a arr not NULL ! + * \param [out] endOut valid only if \a arr not NULL ! + * \param [out] stepOut valid only if \a arr not NULL ! + * \param [out] arr correspondance old to new in node ids. + * + * \sa MEDCouplingUMesh::buildPartOfMySelf2 + */ +MEDCouplingMesh *MEDCouplingPointSet::buildPartRangeAndReduceNodes(int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt*& arr) const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret=buildPartOfMySelf2(beginCellIds,endCellIds,stepCellIds,true); + arr=ret->zipCoordsTraducer(); + return ret.retn(); +} /*! * 'This' is expected to be of spaceDim==2. Idem for 'center' and 'vect' diff --git a/src/MEDCoupling/MEDCouplingPointSet.hxx b/src/MEDCoupling/MEDCouplingPointSet.hxx index 908ef71e5..e0ef76118 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.hxx +++ b/src/MEDCoupling/MEDCouplingPointSet.hxx @@ -94,6 +94,8 @@ namespace ParaMEDMEM static void Rotate3DAlg(const double *center, const double *vect, double angle, int nbNodes, double *coords); MEDCouplingMesh *buildPart(const int *start, const int *end) const; MEDCouplingMesh *buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const; + MEDCouplingMesh *buildPartRange(int beginCellIds, int endCellIds, int stepCellIds) const throw(INTERP_KERNEL::Exception); + MEDCouplingMesh *buildPartRangeAndReduceNodes(int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt*& arr) const throw(INTERP_KERNEL::Exception); virtual MEDCouplingPointSet *buildPartOfMySelf(const int *start, const int *end, bool keepCoords=true) const = 0; virtual MEDCouplingPointSet *buildPartOfMySelf2(int start, int end, int step, bool keepCoords=true) const throw(INTERP_KERNEL::Exception) = 0; virtual MEDCouplingPointSet *buildPartOfMySelfNode(const int *start, const int *end, bool fullyIn) const = 0; diff --git a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx index ffd9c27c6..77f8ca03e 100644 --- a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx +++ b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx @@ -193,6 +193,12 @@ void MEDCouplingStructuredMesh::splitProfilePerType(const DataArrayInt *profile, idsPerType.push_back(profile->deepCpy()); } +/*! + * Creates a new unstructured mesh (MEDCouplingUMesh) from \a this structured one. + * \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. The caller is to + * delete this array using decrRef() as it is no more needed. + * \throw If \a this->getMeshDimension() is not among [1,2,3]. + */ MEDCouplingUMesh *MEDCouplingStructuredMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception) { int meshDim=getMeshDimension(); @@ -217,6 +223,16 @@ MEDCouplingUMesh *MEDCouplingStructuredMesh::buildUnstructured() const throw(INT return ret; } +/*! + * Creates a new MEDCouplingUMesh containing a part of cells of \a this mesh. + * The cells to include to the + * result mesh are specified by an array of cell ids. + * \param [in] start - an array of cell ids to include to the result mesh. + * \param [in] end - specifies the end of the array \a start, so that + * the last value of \a start is \a end[ -1 ]. + * \return MEDCouplingMesh * - a new instance of MEDCouplingUMesh. The caller is to + * delete this mesh using decrRef() as it is no more needed. + */ MEDCouplingMesh *MEDCouplingStructuredMesh::buildPart(const int *start, const int *end) const { MEDCouplingUMesh *um=buildUnstructured(); @@ -238,6 +254,14 @@ DataArrayInt *MEDCouplingStructuredMesh::simplexize(int policy) throw(INTERP_KER throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::simplexize : not available for Cartesian mesh !"); } +/*! + * Returns a new MEDCouplingFieldDouble holding normal vectors to cells of \a this + * 2D mesh. The computed vectors have 3 components and are normalized. + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble on + * cells and one time. The caller is to delete this field using decrRef() as + * it is no more needed. + * \throw If \a this->getMeshDimension() != 2. + */ MEDCouplingFieldDouble *MEDCouplingStructuredMesh::buildOrthogonalField() const { if(getMeshDimension()!=2) @@ -344,6 +368,14 @@ void MEDCouplingStructuredMesh::fill3DUnstructuredMesh(MEDCouplingUMesh *m) cons connI->decrRef(); } +/*! + * Returns a cell id by its (i,j,k) index. The cell is located between the i-th and + * ( i + 1 )-th nodes along X axis etc. + * \param [in] i - a index of node coordinates array along X axis. + * \param [in] j - a index of node coordinates array along Y axis. + * \param [in] k - a index of node coordinates array along Z axis. + * \return int - a cell id in \a this mesh. + */ int MEDCouplingStructuredMesh::getCellIdFromPos(int i, int j, int k) const { int tmp[3]={i,j,k}; @@ -354,6 +386,13 @@ int MEDCouplingStructuredMesh::getCellIdFromPos(int i, int j, int k) const return std::accumulate(tmp,tmp+meshDim,0); } +/*! + * Returns a node id by its (i,j,k) index. + * \param [in] i - a index of node coordinates array along X axis. + * \param [in] j - a index of node coordinates array along Y axis. + * \param [in] k - a index of node coordinates array along Z axis. + * \return int - a node id in \a this mesh. + */ int MEDCouplingStructuredMesh::getNodeIdFromPos(int i, int j, int k) const { int tmp[3]={i,j,k}; diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index 7836e91c4..b75dbd2ab 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -356,7 +356,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::doublyContractedPr std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jdoublyContractedProduct(); @@ -364,7 +364,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::doublyContractedPr arrays2[j]=0; } std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jsetArrays(arrays3,0); return ret; @@ -375,7 +375,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::determinant() cons std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jdeterminant(); @@ -383,7 +383,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::determinant() cons arrays2[j]=0; } std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); @@ -396,7 +396,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenValues() cons std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jeigenValues(); @@ -404,7 +404,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenValues() cons arrays2[j]=0; } std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); @@ -417,7 +417,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenVectors() con std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jeigenVectors(); @@ -425,7 +425,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::eigenVectors() con arrays2[j]=0; } std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); @@ -438,7 +438,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::inverse() const th std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jinverse(); @@ -446,7 +446,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::inverse() const th arrays2[j]=0; } std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); @@ -459,7 +459,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::trace() const thro std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jtrace(); @@ -467,7 +467,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::trace() const thro arrays2[j]=0; } std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); @@ -480,7 +480,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::deviator() const t std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jdeviator(); @@ -488,7 +488,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::deviator() const t arrays2[j]=0; } std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); @@ -501,7 +501,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::magnitude() const std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jmagnitude(); @@ -509,7 +509,28 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::magnitude() const arrays2[j]=0; } std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); + ret->setArrays(arrays3,0); + return ret; +} + +MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::negate() const throw(INTERP_KERNEL::Exception) +{ + std::vector arrays; + getArrays(arrays); + std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); + for(std::size_t j=0;jnegate(); + else + arrays2[j]=0; + } + std::vector arrays3(arrays.size()); + for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); @@ -522,7 +543,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::maxPerTuple() cons std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jmaxPerTuple(); @@ -530,7 +551,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::maxPerTuple() cons arrays2[j]=0; } std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); @@ -543,7 +564,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::keepSelectedCompon std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jkeepSelectedComponents(compoIds); @@ -551,7 +572,7 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::keepSelectedCompon arrays2[j]=0; } std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jsetTimeUnit(getTimeUnit()); @@ -566,7 +587,7 @@ void MEDCouplingTimeDiscretization::setSelectedComponents(const MEDCouplingTimeD other->getArrays(arrays2); if(arrays1.size()!=arrays2.size()) throw INTERP_KERNEL::Exception("TimeDiscretization::setSelectedComponents : number of arrays mismatch !"); - for(unsigned int i=0;isetSelectedComponents(arrays2[i],compoIds); @@ -580,7 +601,7 @@ void MEDCouplingTimeDiscretization::changeNbOfComponents(int newNbOfComp, double std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jchangeNbOfComponents(newNbOfComp,dftValue); @@ -588,7 +609,7 @@ void MEDCouplingTimeDiscretization::changeNbOfComponents(int newNbOfComp, double arrays2[j]=0; } std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;j arrays; getArrays(arrays); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jsortPerTuple(asc); @@ -609,33 +630,61 @@ void MEDCouplingTimeDiscretization::setUniformValue(int nbOfTuple, int nbOfCompo std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jincrRef(); - arrays[j]->fillWithValue(value); - arrays2[j]=arrays[j]; + arrays2[j]=arrays[j]->changeNbOfComponents(nbOfCompo,value); + arrays2[j]->fillWithValue(value); } else { - DataArrayDouble *tmp=DataArrayDouble::New(); - tmp->alloc(nbOfTuple,nbOfCompo); - tmp->fillWithValue(value); - arrays2[j]=tmp; + arrays2[j]=DataArrayDouble::New(); + arrays2[j]->alloc(nbOfTuple,nbOfCompo); + arrays2[j]->fillWithValue(value); } } std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;j arrays; + getArrays(arrays); + std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); + bool newArr=false; + for(std::size_t j=0;jincrRef(); + arrays2[j]->fillWithValue(value); + } + else + { + newArr=true; + arrays2[j]=DataArrayDouble::New(); + arrays2[j]->alloc(nbOfTuple,1); + arrays2[j]->fillWithValue(value); + } + } + if(newArr) + { + std::vector arrays3(arrays.size()); + for(std::size_t j=0;j arrays; getArrays(arrays); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;japplyLin(a,b,compoId); @@ -647,7 +696,7 @@ void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, FunctionToEvaluate f std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;japplyFunc(nbOfComp,func); @@ -655,7 +704,7 @@ void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, FunctionToEvaluate f arrays2[j]=0; } std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;j arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;japplyFunc(nbOfComp,func); @@ -673,7 +722,7 @@ void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, const char *func) arrays2[j]=0; } std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;j arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;japplyFunc2(nbOfComp,func); @@ -691,7 +740,7 @@ void MEDCouplingTimeDiscretization::applyFunc2(int nbOfComp, const char *func) arrays2[j]=0; } std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;j arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;japplyFunc3(nbOfComp,varsOrder,func); @@ -709,7 +758,7 @@ void MEDCouplingTimeDiscretization::applyFunc3(int nbOfComp, const std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;j arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;japplyFunc(func); @@ -727,7 +776,7 @@ void MEDCouplingTimeDiscretization::applyFunc(const char *func) arrays2[j]=0; } std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;j arrays; getArrays(arrays); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;japplyFuncFast32(func); @@ -747,7 +796,7 @@ void MEDCouplingTimeDiscretization::applyFuncFast64(const char *func) { std::vector arrays; getArrays(arrays); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;japplyFuncFast64(func); @@ -759,10 +808,10 @@ void MEDCouplingTimeDiscretization::fillFromAnalytic(const DataArrayDouble *loc, std::vector arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;japplyFunc(nbOfComp,func); std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;j arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;japplyFunc(nbOfComp,func); std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;j arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;japplyFunc2(nbOfComp,func); std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;j arrays; getArrays(arrays); std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;japplyFunc3(nbOfComp,varsOrder,func); std::vector arrays3(arrays.size()); - for(int j=0;j<(int)arrays.size();j++) + for(std::size_t j=0;jdivideEqual(other->getArray()); } +MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::pow(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("pow on mismatched time discretization !"); + MEDCouplingAutoRefCountObjectPtr arr=DataArrayDouble::Pow(getArray(),other->getArray()); + MEDCouplingNoTimeLabel *ret=new MEDCouplingNoTimeLabel; + ret->setArray(arr,0); + return ret; +} + +void MEDCouplingNoTimeLabel::powEqual(const MEDCouplingTimeDiscretization *other) +{ + const MEDCouplingNoTimeLabel *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("NoTimeLabel::powEqual on mismatched time discretization !"); + if(!getArray()) + throw INTERP_KERNEL::Exception("MEDCouplingNoTimeLabel::powEqual : Data Array is NULL !"); + getArray()->powEqual(other->getArray()); +} + MEDCouplingTimeDiscretization *MEDCouplingNoTimeLabel::performCpy(bool deepCpy) const { return new MEDCouplingNoTimeLabel(*this,deepCpy); @@ -1531,6 +1601,30 @@ void MEDCouplingWithTimeStep::divideEqual(const MEDCouplingTimeDiscretization *o getArray()->divideEqual(other->getArray()); } +MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::pow(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("WithTimeStep::pow on mismatched time discretization !"); + MEDCouplingAutoRefCountObjectPtr arr=DataArrayDouble::Pow(getArray(),other->getArray()); + MEDCouplingWithTimeStep *ret=new MEDCouplingWithTimeStep; + ret->setArray(arr,0); + int tmp1,tmp2; + double tmp3=getStartTime(tmp1,tmp2); + ret->setStartTime(tmp3,tmp1,tmp2); + return ret; +} + +void MEDCouplingWithTimeStep::powEqual(const MEDCouplingTimeDiscretization *other) +{ + const MEDCouplingWithTimeStep *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("WithTimeStep::powEqual on mismatched time discretization !"); + if(!getArray()) + throw INTERP_KERNEL::Exception("MEDCouplingWithTimeLabel::powEqual : Data Array is NULL !"); + getArray()->powEqual(other->getArray()); +} + MEDCouplingTimeDiscretization *MEDCouplingWithTimeStep::performCpy(bool deepCpy) const { return new MEDCouplingWithTimeStep(*this,deepCpy); @@ -2058,6 +2152,32 @@ void MEDCouplingConstOnTimeInterval::divideEqual(const MEDCouplingTimeDiscretiza getArray()->divideEqual(other->getArray()); } +MEDCouplingTimeDiscretization *MEDCouplingConstOnTimeInterval::pow(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("pow on mismatched time discretization !"); + MEDCouplingAutoRefCountObjectPtr arr=DataArrayDouble::Pow(getArray(),other->getArray()); + MEDCouplingConstOnTimeInterval *ret=new MEDCouplingConstOnTimeInterval; + ret->setArray(arr,0); + int tmp1,tmp2; + double tmp3=getStartTime(tmp1,tmp2); + ret->setStartTime(tmp3,tmp1,tmp2); + tmp3=getEndTime(tmp1,tmp2); + ret->setEndTime(tmp3,tmp1,tmp2); + return ret; +} + +void MEDCouplingConstOnTimeInterval::powEqual(const MEDCouplingTimeDiscretization *other) +{ + const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("ConstOnTimeInterval::powEqual on mismatched time discretization !"); + if(!getArray()) + throw INTERP_KERNEL::Exception("MEDCouplingConstOnTimeInterval::powEqual : Data Array is NULL !"); + getArray()->powEqual(other->getArray()); +} + MEDCouplingTwoTimeSteps::MEDCouplingTwoTimeSteps(const MEDCouplingTwoTimeSteps& other, bool deepCpy):MEDCouplingTimeDiscretization(other,deepCpy), _start_time(other._start_time),_end_time(other._end_time), _start_iteration(other._start_iteration),_end_iteration(other._end_iteration), @@ -2739,3 +2859,29 @@ void MEDCouplingLinearTime::divideEqual(const MEDCouplingTimeDiscretization *oth getArray()->divideEqual(other->getArray()); getEndArray()->divideEqual(other->getEndArray()); } + +MEDCouplingTimeDiscretization *MEDCouplingLinearTime::pow(const MEDCouplingTimeDiscretization *other) const +{ + const MEDCouplingLinearTime *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("LinearTime::pow on mismatched time discretization !"); + MEDCouplingAutoRefCountObjectPtr arr1=DataArrayDouble::Pow(getArray(),other->getArray()); + MEDCouplingAutoRefCountObjectPtr arr2=DataArrayDouble::Pow(getEndArray(),other->getEndArray()); + MEDCouplingLinearTime *ret=new MEDCouplingLinearTime; + ret->setArray(arr1,0); + ret->setEndArray(arr2,0); + return ret; +} + +void MEDCouplingLinearTime::powEqual(const MEDCouplingTimeDiscretization *other) +{ + const MEDCouplingLinearTime *otherC=dynamic_cast(other); + if(!otherC) + throw INTERP_KERNEL::Exception("LinearTime::addEqual on mismatched time discretization !"); + if(!getArray()) + throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::powEqual : Data Array is NULL !"); + if(!getEndArray()) + throw INTERP_KERNEL::Exception("MEDCouplingLinearTime::powEqual : Data Array (end) is NULL !"); + getArray()->powEqual(other->getArray()); + getEndArray()->powEqual(other->getEndArray()); +} diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx index d5a51be86..b252ef5e1 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx @@ -75,6 +75,8 @@ namespace ParaMEDMEM virtual void multiplyEqual(const MEDCouplingTimeDiscretization *other) = 0; virtual MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const = 0; virtual void divideEqual(const MEDCouplingTimeDiscretization *other) = 0; + virtual MEDCouplingTimeDiscretization *pow(const MEDCouplingTimeDiscretization *other) const = 0; + virtual void powEqual(const MEDCouplingTimeDiscretization *other) = 0; virtual void getTinySerializationIntInformation(std::vector& tinyInfo) const; virtual void getTinySerializationDbleInformation(std::vector& tinyInfo) const; virtual void getTinySerializationStrInformation(std::vector& tinyInfo) const; @@ -126,12 +128,14 @@ namespace ParaMEDMEM virtual MEDCouplingTimeDiscretization *trace() const throw(INTERP_KERNEL::Exception); virtual MEDCouplingTimeDiscretization *deviator() const throw(INTERP_KERNEL::Exception); virtual MEDCouplingTimeDiscretization *magnitude() const throw(INTERP_KERNEL::Exception); + virtual MEDCouplingTimeDiscretization *negate() const throw(INTERP_KERNEL::Exception); virtual MEDCouplingTimeDiscretization *maxPerTuple() const throw(INTERP_KERNEL::Exception); virtual MEDCouplingTimeDiscretization *keepSelectedComponents(const std::vector& compoIds) const throw(INTERP_KERNEL::Exception); virtual void setSelectedComponents(const MEDCouplingTimeDiscretization *other, const std::vector& compoIds) throw(INTERP_KERNEL::Exception); virtual void changeNbOfComponents(int newNbOfComp, double dftValue) throw(INTERP_KERNEL::Exception); virtual void sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception); virtual void setUniformValue(int nbOfTuple, int nbOfCompo, double value); + virtual void setOrCreateUniformValueOnAllComponents(int nbOfTuple, double value); virtual void applyLin(double a, double b, int compoId); virtual void applyFunc(int nbOfComp, FunctionToEvaluate func); virtual void applyFunc(int nbOfComp, const char *func); @@ -177,6 +181,8 @@ namespace ParaMEDMEM void multiplyEqual(const MEDCouplingTimeDiscretization *other); MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const; void divideEqual(const MEDCouplingTimeDiscretization *other); + MEDCouplingTimeDiscretization *pow(const MEDCouplingTimeDiscretization *other) const; + void powEqual(const MEDCouplingTimeDiscretization *other); bool isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const; bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; bool areCompatible(const MEDCouplingTimeDiscretization *other) const; @@ -238,6 +244,8 @@ namespace ParaMEDMEM void multiplyEqual(const MEDCouplingTimeDiscretization *other); MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const; void divideEqual(const MEDCouplingTimeDiscretization *other); + MEDCouplingTimeDiscretization *pow(const MEDCouplingTimeDiscretization *other) const; + void powEqual(const MEDCouplingTimeDiscretization *other); bool isEqualIfNotWhy(const MEDCouplingTimeDiscretization *other, double prec, std::string& reason) const; bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretization *other, double prec) const; bool areCompatible(const MEDCouplingTimeDiscretization *other) const; @@ -322,6 +330,8 @@ namespace ParaMEDMEM void multiplyEqual(const MEDCouplingTimeDiscretization *other); MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const; void divideEqual(const MEDCouplingTimeDiscretization *other); + MEDCouplingTimeDiscretization *pow(const MEDCouplingTimeDiscretization *other) const; + void powEqual(const MEDCouplingTimeDiscretization *other); void setStartTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception) { _start_time=time; _start_iteration=iteration; _start_order=order; } void setEndTime(double time, int iteration, int order) throw(INTERP_KERNEL::Exception) { _end_time=time; _end_iteration=iteration; _end_order=order; } double getStartTime(int& iteration, int& order) const throw(INTERP_KERNEL::Exception) { iteration=_start_iteration; order=_start_order; return _start_time; } @@ -434,6 +444,8 @@ namespace ParaMEDMEM void multiplyEqual(const MEDCouplingTimeDiscretization *other); MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const; void divideEqual(const MEDCouplingTimeDiscretization *other); + MEDCouplingTimeDiscretization *pow(const MEDCouplingTimeDiscretization *other) const; + void powEqual(const MEDCouplingTimeDiscretization *other); public: static const TypeOfTimeDiscretization DISCRETIZATION=LINEAR_TIME; static const char REPR[]; diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index caadbd866..d5425440e 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -64,11 +64,24 @@ MEDCouplingUMesh *MEDCouplingUMesh::New(const char *meshName, int meshDim) return ret; } +/*! + * Returns a new MEDCouplingMesh which is a full copy of \a this one. No data is shared + * between \a this and the new mesh. + * \return MEDCouplingMesh * - a new instance of MEDCouplingMesh. The caller is to + * delete this mesh using decrRef() as it is no more needed. + */ MEDCouplingMesh *MEDCouplingUMesh::deepCpy() const { return clone(true); } +/*! + * Returns a new MEDCouplingMesh which is a copy of \a this one. + * \param [in] recDeepCpy - if \a true, the copy is deep, else all data arrays of \a + * this mesh are shared by the new mesh. + * \return MEDCouplingMesh * - a new instance of MEDCouplingMesh. The caller is to + * delete this mesh using decrRef() as it is no more needed. + */ MEDCouplingUMesh *MEDCouplingUMesh::clone(bool recDeepCpy) const { return new MEDCouplingUMesh(*this,recDeepCpy); @@ -102,10 +115,17 @@ MEDCouplingUMesh::MEDCouplingUMesh():_mesh_dim(-2),_nodal_connec(0),_nodal_conne } /*! - * This method checks that this is correctly designed. For example le coordinates are set, nodal connectivity. - * When this method returns without throwing any exception, 'this' is expected to be writable, exchangeable and to be - * available for most of algorithm. When a mesh has been constructed from scratch it is a good habits to call this method to check - * that all is in order in 'this'. + * Checks if \a this mesh is well defined. If no exception is thrown by this method, + * then \a this mesh is most probably is writable, exchangeable and available for most + * of algorithms. When a mesh is constructed from scratch, it is a good habit to call + * this method to check that all is in order with \a this mesh. + * \throw If the mesh dimension is not set. + * \throw If the coordinates array is not set (if mesh dimension != -1 ). + * \throw If \a this mesh contains elements of dimension different from the mesh dimension. + * \throw If the connectivity data array has more than one component. + * \throw If the connectivity data array has a named component. + * \throw If the connectivity index data array has more than one component. + * \throw If the connectivity index data array has a named component. */ void MEDCouplingUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception) { @@ -139,9 +159,20 @@ void MEDCouplingUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception) } /*! - * This method performs deeper checking in 'this' than MEDCouplingUMesh::checkCoherency does. - * So this method is more time-consuming. This method checks that nodal connectivity points to valid node ids. - * No geometrical aspects are checked here. These aspects are done in MEDCouplingUMesh::checkCoherency2. + * Checks if \a this mesh is well defined. If no exception is thrown by this method, + * then \a this mesh is most probably is writable, exchangeable and available for all + * algorithms.
In addition to the checks performed by checkCoherency(), this + * method thoroughly checks the nodal connectivity. + * \param [in] eps - a not used parameter. + * \throw If the mesh dimension is not set. + * \throw If the coordinates array is not set (if mesh dimension != -1 ). + * \throw If \a this mesh contains elements of dimension different from the mesh dimension. + * \throw If the connectivity data array has more than one component. + * \throw If the connectivity data array has a named component. + * \throw If the connectivity index data array has more than one component. + * \throw If the connectivity index data array has a named component. + * \throw If number of nodes defining an element does not correspond to the type of element. + * \throw If the nodal connectivity includes an invalid node id. */ void MEDCouplingUMesh::checkCoherency1(double eps) const throw(INTERP_KERNEL::Exception) { @@ -199,11 +230,34 @@ void MEDCouplingUMesh::checkCoherency1(double eps) const throw(INTERP_KERNEL::Ex } } + +/*! + * Checks if \a this mesh is well defined. If no exception is thrown by this method, + * then \a this mesh is most probably is writable, exchangeable and available for all + * algorithms.
This method performs the same checks as checkCoherency1() does. + * \param [in] eps - a not used parameter. + * \throw If the mesh dimension is not set. + * \throw If the coordinates array is not set (if mesh dimension != -1 ). + * \throw If \a this mesh contains elements of dimension different from the mesh dimension. + * \throw If the connectivity data array has more than one component. + * \throw If the connectivity data array has a named component. + * \throw If the connectivity index data array has more than one component. + * \throw If the connectivity index data array has a named component. + * \throw If number of nodes defining an element does not correspond to the type of element. + * \throw If the nodal connectivity includes an invalid node id. + */ void MEDCouplingUMesh::checkCoherency2(double eps) const throw(INTERP_KERNEL::Exception) { checkCoherency1(eps); } +/*! + * Sets dimension of \a this mesh. The mesh dimension in general depends on types of + * elements contained in the mesh. For more info on the mesh dimension see + * \ref MEDCouplingUMeshPage. + * \param [in] meshDim - a new mesh dimension. + * \throw If \a meshDim is invalid. A valid range is -1 <= meshDim <= 3. + */ void MEDCouplingUMesh::setMeshDimension(int meshDim) { if(meshDim<-1 || meshDim>3) @@ -212,6 +266,13 @@ void MEDCouplingUMesh::setMeshDimension(int meshDim) declareAsNew(); } +/*! + * Allocates memory to store given number of cells. + * \param [in] nbOfCells - number of cell \a this mesh will contain. + * + * \ref medcouplingcppexamplesUmeshStdBuild1 "Here is a C++ example".
+ * \ref medcouplingpyexamplesUmeshStdBuild1 "Here is a Python example". + */ void MEDCouplingUMesh::allocateCells(int nbOfCells) { if(_nodal_connec_index) @@ -232,10 +293,14 @@ void MEDCouplingUMesh::allocateCells(int nbOfCells) } /*! - * Appends a cell in connectivity array. - * @param type type of cell to add. - * @param size number of nodes constituting this cell. - * @param nodalConnOfCell the connectivity of the cell to add. + * Appends a cell to the connectivity array. For deeper understanding what is + * happening see \ref MEDCouplingUMeshNodalConnectivity. + * \param [in] type - type of cell to add. + * \param [in] size - number of nodes constituting this cell. + * \param [in] nodalConnOfCell - the connectivity of the cell to add. + * + * \ref medcouplingcppexamplesUmeshStdBuild1 "Here is a C++ example".
+ * \ref medcouplingpyexamplesUmeshStdBuild1 "Here is a Python example". */ void MEDCouplingUMesh::insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, const int *nodalConnOfCell) throw(INTERP_KERNEL::Exception) { @@ -267,7 +332,11 @@ void MEDCouplingUMesh::insertNextCell(INTERP_KERNEL::NormalizedCellType type, in } /*! - * Method to be called to cloture the insertion of cells using this->insertNextCell. + * Compacts data arrays to release unused memory. This method is to be called after + * finishing cell insertion using \a this->insertNextCell(). + * + * \ref medcouplingcppexamplesUmeshStdBuild1 "Here is a C++ example".
+ * \ref medcouplingpyexamplesUmeshStdBuild1 "Here is a Python example". */ void MEDCouplingUMesh::finishInsertingCells() { @@ -300,6 +369,10 @@ MEDCouplingUMeshCellByTypeEntry *MEDCouplingUMesh::cellsByType() throw(INTERP_KE return new MEDCouplingUMeshCellByTypeEntry(this); } +/*! + * Returns a set of all cell types available in \a this mesh. + * \return std::set - the set of cell types. + */ std::set MEDCouplingUMesh::getAllGeoTypes() const { return _types; @@ -366,6 +439,14 @@ bool MEDCouplingUMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec return true; } +/*! + * \brief Checks if data arrays of this mesh (node coordinates, nodal + * connectivity of cells, etc) of two meshes are same. Textual data like name etc. are + * not considered. + * \param [in] other - the mesh to compare with. + * \param [in] prec - precision value used to compare node coordinates. + * \return bool - \a true if the two meshes are same. + */ bool MEDCouplingUMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const { const MEDCouplingUMesh *otherC=dynamic_cast(other); @@ -393,13 +474,24 @@ bool MEDCouplingUMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *other } /*! - * This method looks if 'this' and 'other' are geometrically equivalent that is to say if each cell in 'other' correspond to one cell and only one - * in 'this' is found regarding 'prec' parameter and 'cellCompPol' parameter. - * - * In case of success cellCor and nodeCor are informed both. - * @param cellCompPol values are described in MEDCouplingUMesh::zipConnectivityTraducer method. - * @param cellCor output array giving the correspondance of cells from 'other' to 'this'. - * @param nodeCor output array giving the correspondance of nodes from 'other' to 'this'. + * Checks if \a this and \a other meshes are geometrically equivalent, else an + * exception is thrown. The meshes are + * considered equivalent if (1) \a this mesh contains the same nodes as the \a other + * mesh (with a specified precision) and (2) \a this mesh contains the same cells as + * the \a other mesh (with use of a specified cell comparison technique). The mapping + * from \a other to \a this for nodes and cells is returned via out parameters. + * \param [in] other - the mesh to compare with. + * \param [in] cellCompPol - id [0-2] of cell comparison method. See meaning of + * each method in description of MEDCouplingUMesh::zipConnectivityTraducer(). + * \param [in] prec - the precision used to compare nodes of the two meshes. + * \param [out] cellCor - a cell permutation array in "Old to New" mode. The caller is + * to delete this array using decrRef() as it is no more needed. + * \param [out] nodeCor - a node permutation array in "Old to New" mode. The caller is + * to delete this array using decrRef() as it is no more needed. + * \throw If the two meshes do not match. + * + * \ref cpp_mcumesh_checkDeepEquivalWith "Here is a C++ example".
+ * \ref py_mcumesh_checkDeepEquivalWith "Here is a Python example". */ void MEDCouplingUMesh::checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec, DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception) @@ -438,14 +530,21 @@ void MEDCouplingUMesh::checkDeepEquivalWith(const MEDCouplingMesh *other, int ce } /*! - * This method looks if 'this' and 'other' are geometrically equivalent that is to say if each cell in 'other' correspond to one cell and only one - * in 'this' is found regarding 'prec' parameter and 'cellCompPol' parameter. The difference with MEDCouplingUMesh::checkDeepEquivalWith method is that - * coordinates of 'this' and 'other' are expected to be the same. If not an exception will be thrown. - * This method is close to MEDCouplingUMesh::areCellsIncludedIn except that this method throws exception ! - * - * In case of success cellCor are informed both. - * @param cellCompPol values are described in MEDCouplingUMesh::zipConnectivityTraducer method. - * @param cellCor output array giving the correspondance of cells from 'other' to 'this'. + * Checks if \a this and \a other meshes are geometrically equivalent, else an + * exception is thrown. The meshes are considered equivalent if (1) they share one + * node coordinates array and (2) they contain the same cells (with use of a specified + * cell comparison technique). The mapping from cells of the \a other to ones of \a this + * is returned via an out parameter. + * \param [in] other - the mesh to compare with. + * \param [in] cellCompPol - id [0-2] of cell comparison method. See the meaning of + * each method in description of MEDCouplingUMesh::zipConnectivityTraducer(). + * \param [in] prec - a not used parameter. + * \param [out] cellCor - the permutation array in "Old to New" mode. The caller is + * to delete this array using decrRef() as it is no more needed. + * \throw If the two meshes do not match. + * + * \ref cpp_mcumesh_checkDeepEquivalWith "Here is a C++ example".
+ * \ref py_mcumesh_checkDeepEquivalWith "Here is a Python example". */ void MEDCouplingUMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec, DataArrayInt *&cellCor) const throw(INTERP_KERNEL::Exception) @@ -474,7 +573,14 @@ void MEDCouplingUMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *ot } /*! - * This method checks fastly that 'this' and 'other' are equal. + * 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 + * (1) meshes contain the same number of nodes and the same number of elements of the + * same types (2) three cells of the two meshes are based on coincident nodes (with a + * specified precision). + * \param [in] other - the mesh to compare with. + * \param [in] prec - the precision used to compare nodes of the two meshes. + * \throw If the two meshes do not match. */ void MEDCouplingUMesh::checkFastEquivalWith(const MEDCouplingMesh *other, double prec) const throw(INTERP_KERNEL::Exception) { @@ -494,8 +600,25 @@ void MEDCouplingUMesh::checkFastEquivalWith(const MEDCouplingMesh *other, double } /*! - * \b WARNING this method do the assumption that connectivity lies on the coordinates set. - * For speed reasons no check of this will be done. + * Returns the reverse nodal connectivity. The reverse nodal connectivity enumerates + * cells each node belongs to. + * \warning For speed reasons, this method does not check if node ids in the nodal + * connectivity correspond to the size of node coordinates array. + * \param [in,out] revNodal - an array holding ids of cells sharing each node. + * \param [in,out] revNodalIndx - an array, of length \a this->getNumberOfNodes() + 1, + * dividing cell ids in \a revNodal into groups each referring to one + * node. Its every element (except the last one) is an index pointing to the + * first id of a group of cells. For example cells sharing the node #1 are + * described by following range of indices: + * [ \a revNodalIndx[1], \a revNodalIndx[2] ) and the cell ids are + * \a revNodal[ \a revNodalIndx[1] ], \a revNodal[ \a revNodalIndx[1] + 1], ... + * Number of cells sharing the *i*-th node is + * \a revNodalIndx[ *i*+1 ] - \a revNodalIndx[ *i* ]. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * + * \ref cpp_mcumesh_getReverseNodalConnectivity "Here is a C++ example".
+ * \ref py_mcumesh_getReverseNodalConnectivity "Here is a Python example". */ void MEDCouplingUMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const throw(INTERP_KERNEL::Exception) { @@ -589,23 +712,46 @@ private: /// @endcond /*! - * \b WARNING this method do the assumption that connectivity lies on the coordinates set. - * For speed reasons no check of this will be done. - * Given 'this' with spacedim equal to s and meshdim equal to p, this method returns a new allocated mesh - * lying on the same coordinates than 'this' and having a meshdim equal to p-1. - * The algorithm to compute this p-1 mesh is the following : - * For each cell in 'this' it splits into p-1 elements. - * If this p-1 element does not already exists it is appended to the returned mesh - * If this p-1 element already exists, it is not appended. - * This method returns or 4 arrays plus the returned mesh. - * 'desc' and 'descIndx' are the descending connectivity. These 2 arrays tell for each cell in 'this', to wich p-1 dimension cell in returned mesh it refers. - * For a cell with a cellid c in 'this' it is constituted of cells in [desc+descIndx[c],desc+descIndex[c+1]) - * - * Reversely 'revDesc' and 'revDescIndx' are the reverse descending connectivity. These 2 arrays tell for each cell in returned mesh, to wich cell in 'this' it refers. - * For a cell with a cellid d in returned p-1 mesh it is shared by the following cells in 'this' [revDesc+revDescIndx[d],revDesc+revDescIndx[d+1]) - * - * \warning This method returns a mesh whose geometric type order in are \b not sorted. - * In view of the MED file writing, a renumbering of cells in returned mesh (using MEDCouplingUMesh::sortCellsInMEDFileFrmt) should be necessary. + * Creates a new MEDCouplingUMesh containing cells, of dimension one less than \a + * this->getMeshDimension(), that bound cells of \a this mesh. In addition arrays + * describing correspondence between cells of \a this and the result meshes are + * returned. The arrays \a desc and \a descIndx describe the descending connectivity, + * i.e. enumerate cells of the result mesh bounding each cell of \a this mesh. The + * arrays \a revDesc and \a revDescIndx describe the reverse descending connectivity, + * i.e. enumerate cells of \a this mesh bounded by each cell of the result mesh. + * \warning For speed reasons, this method does not check if node ids in the nodal + * connectivity correspond to the size of node coordinates array. + * \warning Cells of the result mesh are \b not sorted by geometric type, hence, + * to write this mesh to the MED file, its cells must be sorted using + * sortCellsInMEDFileFrmt(). + * \param [in,out] desc - the array containing cell ids of the result mesh bounding + * each cell of \a this mesh. + * \param [in,out] descIndx - the array, of length \a this->getNumberOfCells() + 1, + * dividing cell ids in \a desc into groups each referring to one + * cell of \a this mesh. Its every element (except the last one) is an index + * pointing to the first id of a group of cells. For example cells of the + * result mesh bounding the cell #1 of \a this mesh are described by following + * range of indices: + * [ \a descIndx[1], \a descIndx[2] ) and the cell ids are + * \a desc[ \a descIndx[1] ], \a desc[ \a descIndx[1] + 1], ... + * Number of cells of the result mesh sharing the *i*-th cell of \a this mesh is + * \a descIndx[ *i*+1 ] - \a descIndx[ *i* ]. + * \param [in,out] revDesc - the array containing cell ids of \a this mesh bounded + * by each cell of the result mesh. + * \param [in,out] revDescIndx - the array, of length one more than number of cells + * in the result mesh, + * dividing cell ids in \a revDesc into groups each referring to one + * cell of the result mesh the same way as \a descIndx divides \a desc. + * \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. The caller is to + * delete this mesh using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is node defined. + * \throw If \a desc == NULL || \a descIndx == NULL || \a revDesc == NULL || \a + * revDescIndx == NULL. + * + * \ref cpp_mcumesh_buildDescendingConnectivity "Here is a C++ example".
+ * \ref py_mcumesh_buildDescendingConnectivity "Here is a Python example". + * \sa buildDescendingConnectivity2() */ MEDCouplingUMesh *MEDCouplingUMesh::buildDescendingConnectivity(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const throw(INTERP_KERNEL::Exception) { @@ -628,15 +774,53 @@ MEDCouplingUMesh *MEDCouplingUMesh::explode3DMeshTo1D(DataArrayInt *desc, DataAr } /*! - * WARNING this method do the assumption that connectivity lies on the coordinates set. - * For speed reasons no check of this will be done. - * This method differs from MEDCouplingUMesh::buildDescendingConnectivity method in that 'desc' is in different format. - * This method is more precise because it returns in descending connectivity giving the direction. If value is positive the n-1 dim element is taken in the same direction, - * if it is in the opposite direction it is retrieved negative. So the problem is for elemt #0 in C convention. That's why this method is the only one that retrieves - * an array in relative "FORTRAN" mode. - * - * \warning This method returns a mesh whose geometric type order in are \b not sorted. - * In view of the MED file writing, a renumbering of cells in returned mesh (using MEDCouplingUMesh::sortCellsInMEDFileFrmt) should be necessary. + * Creates a new MEDCouplingUMesh containing cells, of dimension one less than \a + * this->getMeshDimension(), that bound cells of \a this mesh. In + * addition arrays describing correspondence between cells of \a this and the result + * meshes are returned. The arrays \a desc and \a descIndx describe the descending + * connectivity, i.e. enumerate cells of the result mesh bounding each cell of \a this + * mesh. This method differs from buildDescendingConnectivity() in that apart + * from cell ids, \a desc returns mutual orientation of cells in \a this and the + * result meshes. So a positive id means that order of nodes in corresponding cells + * of two meshes is same, and a negative id means a reverse order of nodes. Since a + * cell with id #0 can't be negative, the array \a desc returns ids in FORTRAN mode, + * i.e. cell ids are one-based. + * Arrays \a revDesc and \a revDescIndx describe the reverse descending connectivity, + * i.e. enumerate cells of \a this mesh bounded by each cell of the result mesh. + * \warning For speed reasons, this method does not check if node ids in the nodal + * connectivity correspond to the size of node coordinates array. + * \warning Cells of the result mesh are \b not sorted by geometric type, hence, + * to write this mesh to the MED file, its cells must be sorted using + * sortCellsInMEDFileFrmt(). + * \param [in,out] desc - the array containing cell ids of the result mesh bounding + * each cell of \a this mesh. + * \param [in,out] descIndx - the array, of length \a this->getNumberOfCells() + 1, + * dividing cell ids in \a desc into groups each referring to one + * cell of \a this mesh. Its every element (except the last one) is an index + * pointing to the first id of a group of cells. For example cells of the + * result mesh bounding the cell #1 of \a this mesh are described by following + * range of indices: + * [ \a descIndx[1], \a descIndx[2] ) and the cell ids are + * \a desc[ \a descIndx[1] ], \a desc[ \a descIndx[1] + 1], ... + * Number of cells of the result mesh sharing the *i*-th cell of \a this mesh is + * \a descIndx[ *i*+1 ] - \a descIndx[ *i* ]. + * \param [in,out] revDesc - the array containing cell ids of \a this mesh bounded + * by each cell of the result mesh. + * \param [in,out] revDescIndx - the array, of length one more than number of cells + * in the result mesh, + * dividing cell ids in \a revDesc into groups each referring to one + * cell of the result mesh the same way as \a descIndx divides \a desc. + * \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. This result mesh + * shares the node coordinates array with \a this mesh. The caller is to + * delete this mesh using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is node defined. + * \throw If \a desc == NULL || \a descIndx == NULL || \a revDesc == NULL || \a + * revDescIndx == NULL. + * + * \ref cpp_mcumesh_buildDescendingConnectivity2 "Here is a C++ example".
+ * \ref py_mcumesh_buildDescendingConnectivity2 "Here is a Python example". + * \sa buildDescendingConnectivity() */ MEDCouplingUMesh *MEDCouplingUMesh::buildDescendingConnectivity2(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const throw(INTERP_KERNEL::Exception) { @@ -838,20 +1022,26 @@ struct MEDCouplingAccVisit /// @endcond - /*! - * This method convert cell with ids in ['cellIdsToConvertBg','cellIdsToConvertEnd') into 'this' into dynamic types without changing geometry. - * That is to say if 'this' is a 2D, mesh after the invocation of this method it will contain only polygons. - * If 'this' is a 3D mesh after the invocation of this method it will contain only polyhedra. - * If mesh dimension is not in [2,3] an exception is thrown. - * Of course pay attention that the resulting mesh is slower than previous one. - * If in ['cellIdsToConvertBg','cellIdsToConvertEnd') there is a cell id not in [0,'this->getNumberOfCells()') an exception will be thrown. - * In this case if meshDim==2 the mesh is still valid and only cells treated before throw will be converted into polygon. - * If mesh==3, after throw the mesh is \b unconsistent ! - * This method is above all designed to test more extensively algorithms able to deal with polygons/polyhedra. - * - * \warning This method modifies can modify significantly the geometric type order in \a this. - * In view of the MED file writing, a renumbering of cells in \a this (using MEDCouplingUMesh::sortCellsInMEDFileFrmt) should be necessary. + * Converts specified cells to either polygons (if \a this is a 2D mesh) or + * polyhedrons (if \a this is a 3D mesh). The cells to convert are specified by an + * array of cell ids. Pay attention that after conversion all algorithms work slower + * with \a this mesh than before conversion.
If an exception is thrown during the + * conversion due presence of invalid ids in the array of cells to convert, as a + * result \a this mesh contains some already converted elements. In this case the 2D + * mesh remains valid but 3D mesh becomes \b inconsistent! + * \warning This method can significantly modify the order of geometric types in \a this, + * hence, to write this mesh to the MED file, its cells must be sorted using + * sortCellsInMEDFileFrmt(). + * \param [in] cellIdsToConvertBg - the array holding ids of cells to convert. + * \param [in] cellIdsToConvertEnd - a pointer to the last-plus-one-th element of \a + * cellIdsToConvertBg. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is node defined. + * \throw If dimension of \a this mesh is not either 2 or 3. + * + * \ref cpp_mcumesh_convertToPolyTypes "Here is a C++ example".
+ * \ref py_mcumesh_convertToPolyTypes "Here is a Python example". */ void MEDCouplingUMesh::convertToPolyTypes(const int *cellIdsToConvertBg, const int *cellIdsToConvertEnd) { @@ -930,9 +1120,14 @@ void MEDCouplingUMesh::convertToPolyTypes(const int *cellIdsToConvertBg, const i } /*! - * This method converts all cells into poly type if possible. - * This method is purely for userfriendliness. - * As this method can be costly in Memory, no optimization is done to avoid construction of useless vector. + * Converts all cells to either polygons (if \a this is a 2D mesh) or + * polyhedrons (if \a this is a 3D mesh). + * \warning As this method is purely for user-friendliness and no optimization is + * done to avoid construction of a useless vector, this method can be costly + * in memory. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is node defined. + * \throw If dimension of \a this mesh is not either 2 or 3. */ void MEDCouplingUMesh::convertAllToPoly() { @@ -944,17 +1139,29 @@ void MEDCouplingUMesh::convertAllToPoly() } /*! - * This method expects that 'this' has a spacedim equal to 3 and a mesh dimension equal to 3 too, if not an exception will be thrown. - * This method work only on cells with type NORM_POLYHED, all other cells with different type, are remains unchanged. - * For such polyhedra, they are expected to have only 1 face (containing 2 faces in opposition), having 2*n number of nodes (n nodes on - * each 2 faces hidden in the single face of polyhedron). - * The first face is expected to be right oriented because all faces of this polyhedron will be deduced. - * When called 'this' is an invalid mesh on MED sense. This method will correct that for polyhedra. - * In case of presence of polyhedron that has not the extruded aspect (2 faces with the same number of nodes) an exception is thrown and 'this' - * remains unchanged. - * This method is useful only for users that wants to build extruded unstructured mesh. - * This method is a convenient one that avoids boring polyhedra setting during insertNextCell process. - * In case of success, 'this' has be corrected contains the same number of cells and is valid in MED sense. + * Fixes nodal connectivity of invalid cells of type NORM_POLYHED. This method + * expects that all NORM_POLYHED cells have connectivity similar to that of prismatic + * volumes like NORM_HEXA8, NORM_PENTA6 etc., i.e. the first half of nodes describes a + * base facet of the volume and the second half of nodes describes an opposite facet + * having the same number of nodes as the base one. This method converts such + * connectivity to a valid polyhedral format where connectivity of each facet is + * explicitly described and connectivity of facets are separated by -1. If \a this mesh + * contains a NORM_POLYHED cell with a valid connectivity, or an invalid connectivity is + * not as expected, an exception is thrown and the mesh remains unchanged. Care of + * a correct orientation of the first facet of a polyhedron, else orientation of a + * corrected cell is reverse.
+ * This method is useful to build an extruded unstructured mesh with polyhedrons as + * it releases the user from boring description of polyhedra connectivity in the valid + * format. + * \throw If \a this->getMeshDimension() != 3. + * \throw If \a this->getSpaceDimension() != 3. + * \throw If the nodal connectivity of cells is not defined. + * \throw If the coordinates array is not set. + * \throw If \a this mesh contains polyhedrons with the valid connectivity. + * \throw If \a this mesh contains polyhedrons with odd number of nodes. + * + * \ref cpp_mcumesh_arePolyhedronsNotCorrectlyOriented "Here is a C++ example".
+ * \ref py_mcumesh_arePolyhedronsNotCorrectlyOriented "Here is a Python example". */ void MEDCouplingUMesh::convertExtrudedPolyhedra() throw(INTERP_KERNEL::Exception) { @@ -1006,9 +1213,9 @@ void MEDCouplingUMesh::convertExtrudedPolyhedra() throw(INTERP_KERNEL::Exception newc[j]=c[ci[i]+1+n1+(n1-j)%n1]; newc[n1+5*j]=-1; newc[n1+5*j+1]=c[ci[i]+1+j]; - newc[n1+5*j+2]=c[ci[i]+1+(j+1)%n1]; + newc[n1+5*j+2]=c[ci[i]+1+j+n1]; newc[n1+5*j+3]=c[ci[i]+1+(j+1)%n1+n1]; - newc[n1+5*j+4]=c[ci[i]+1+j+n1]; + newc[n1+5*j+4]=c[ci[i]+1+(j+1)%n1]; } newc+=n1*6; } @@ -1019,15 +1226,18 @@ void MEDCouplingUMesh::convertExtrudedPolyhedra() throw(INTERP_KERNEL::Exception _nodal_connec->decrRef(); _nodal_connec=newC.retn(); } + /*! - * This method is the opposite of ParaMEDMEM::MEDCouplingUMesh::convertToPolyTypes method. - * The aim is to take all polygons or polyhedrons cell and to try to traduce them into classical cells. - * - * \return If true at least one cell has been unpolyzed. - \n If false has been returned the nodal connectivity of \a this has **not** been altered and \a this has remains unchanged. - * - * \warning This method modifies can modify significantly the geometric type order in \a this. - * In view of the MED file writing, a renumbering of cells in \a this (using MEDCouplingUMesh::sortCellsInMEDFileFrmt) should be necessary. + * Converts all polygons (if \a this is a 2D mesh) or polyhedrons (if \a this is a 3D + * mesh) to cells of classical types. This method is opposite to convertToPolyTypes(). + * \warning Cells of the result mesh are \b not sorted by geometric type, hence, + * to write this mesh to the MED file, its cells must be sorted using + * sortCellsInMEDFileFrmt(). + * \return \c true if at least one cell has been converted, \c false else. In the + * last case the nodal connectivity remains unchanged. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * \throw If \a this->getMeshDimension() < 0. */ bool MEDCouplingUMesh::unPolyze() { @@ -1197,15 +1407,21 @@ void MEDCouplingUMesh::computeNodeIdsAlg(std::vector& nodeIdsInUse) const } /*! - * Array returned is the correspondance in \b old \b to \b new format (that's why 'nbrOfNodesInUse' is returned too). - * The returned array is newly created and should be dealt by the caller. - * To retrieve the new to old format the user can use DataArrayInt::invertArrayO2N2N2O method. - * The size of returned array is the number of nodes of 'this'. - * -1 values in returned array means that the corresponding node never appear in any nodal connectivity of cells constituting 'this'. - * @param [out] nbrOfNodesInUse out parameter that specifies how many of nodes in 'this' is really used in nodal connectivity. - * @return a newly allocated DataArrayInt that tells for each nodeid in \b this if it is unused (-1) or used (the corresponding new id) - * \throw if a cell contains in its nodal connectivity a node id >= nb of nodes an exception will be thrown. - * \sa MEDCouplingUMesh::computeNodeIdsAlg + * 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 + * a mapping in "Old to New" mode. + * \param [out] nbrOfNodesInUse - number of node ids present in the nodal connectivity. + * \return DataArrayInt * - a new instance of DataArrayInt. Its length is \a + * this->getNumberOfNodes(). It holds for each node of \a this mesh either -1 + * if the node is unused or a new id else. The caller is to delete this + * array using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * \throw If the nodal connectivity includes an invalid id. + * + * \ref cpp_mcumesh_getNodeIdsInUse "Here is a C++ example".
+ * \ref py_mcumesh_getNodeIdsInUse "Here is a Python example". + * \sa computeNodeIdsAlg() */ DataArrayInt *MEDCouplingUMesh::getNodeIdsInUse(int& nbrOfNodesInUse) const throw(INTERP_KERNEL::Exception) { @@ -1263,10 +1479,18 @@ DataArrayInt *MEDCouplingUMesh::computeNbOfNodesPerCell() const throw(INTERP_KER } /*! - * Array returned is the correspondance in \b old \b to \b new format. The returned array is newly created and should be dealt by the caller. - * The maximum value stored in returned array is the number of nodes of 'this' minus 1 after call of this method. - * The size of returned array is the number of nodes of the old (previous to the call of this method) number of nodes. - * -1 values in returned array means that the corresponding old node is no more used. + * Removes unused nodes (the node coordinates array is shorten) and returns an array + * mapping between new and old node ids in "Old to New" mode. -1 values in the returned + * array mean that the corresponding old node is no more used. + * \return DataArrayInt * - a new instance of DataArrayInt of length \a + * this->getNumberOfNodes() before call of this method. The caller is to + * delete this array using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * \throw If the nodal connectivity includes an invalid id. + * + * \ref cpp_mcumesh_zipCoordsTraducer "Here is a C++ example".
+ * \ref py_mcumesh_zipCoordsTraducer "Here is a Python example". */ DataArrayInt *MEDCouplingUMesh::zipCoordsTraducer() throw(INTERP_KERNEL::Exception) { @@ -1602,20 +1826,33 @@ void MEDCouplingUMesh::FindCommonCellsAlg(int compType, int startCellId, const D } /*! - * This method could potentially modify \a this. This method merges cells if there are cells equal in \a this. The comparison is specified by \a compType. - * This method keeps the coordiantes of \a this. + * Removes duplicates of cells from \a this mesh and returns an array mapping between + * new and old cell ids in "Old to New" mode. Nothing is changed in \a this mesh if no + * equal cells found. + * \warning Cells of the result mesh are \b not sorted by geometric type, hence, + * to write this mesh to the MED file, its cells must be sorted using + * sortCellsInMEDFileFrmt(). + * \param [in] compType - specifies a cell comparison technique. Meaning of its + * valid values [0,1,2] is as follows. + * - 0 : "exact". Two cells are considered equal \c iff they have exactly same nodal + * connectivity and type. This is the strongest policy. + * - 1 : "permuted same orientation". Two cells are considered equal \c iff they + * are based on same nodes and have the same type and orientation. + * - 2 : "nodal". Two cells are considered equal \c iff they + * are based on same nodes and have the same type. This is the weakest + * policy, it can be used by users not sensitive to cell orientation. + * \param [in] startCellId - specifies the cell id at which search for equal cells + * starts. By default it is 0, which means that all cells in \a this will be + * scanned. + * \return DataArrayInt - a new instance of DataArrayInt, of length \a + * this->getNumberOfCells() before call of this method. The caller is to + * delete this array using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * \throw If the nodal connectivity includes an invalid id. * - * \param [in] compType input specifying the technique used to compare cells each other. - * - 0 : exactly. A cell is detected to be the same if and only if the connectivity is exactly the same without permutation and types same too. This is the strongest policy. - * - 1 : permutation same orientation. cell1 and cell2 are considered equal if the connectivity of cell2 can be deduced by those of cell1 by direct permutation (with exactly the same orientation) - * and their type equal. For 1D mesh the policy 1 is equivalent to 0. - * - 2 : nodal. cell1 and cell2 are equal if and only if cell1 and cell2 have same type and have the same nodes constituting connectivity. This is the laziest policy. This policy - * can be used for users not sensitive to orientation of cell - * \param [in] startCellId specifies the cellId starting from which the equality computation will be carried out. By default it is 0, which it means that all cells in \a this will be scanned - * \return the correspondance array old to new in a newly allocated array. - * - * \warning This method modifies can modify significantly the geometric type order in \a this. - * In view of the MED file writing, a renumbering of cells in \a this (using MEDCouplingUMesh::sortCellsInMEDFileFrmt) should be necessary. + * \ref cpp_mcumesh_zipConnectivityTraducer "Here is a C++ example".
+ * \ref py_mcumesh_zipConnectivityTraducer "Here is a Python example". */ DataArrayInt *MEDCouplingUMesh::zipConnectivityTraducer(int compType, int startCellId) throw(INTERP_KERNEL::Exception) { @@ -1632,15 +1869,26 @@ DataArrayInt *MEDCouplingUMesh::zipConnectivityTraducer(int compType, int startC } /*! - * This method makes the assumption that 'this' and 'other' share the same coords. If not an exception will be thrown ! - * This method tries to determine if 'other' is fully included in 'this'. To compute that, this method works with connectivity as MEDCouplingUMesh::zipConnectivityTraducer method does. - * This method is close to MEDCouplingUMesh::checkDeepEquivalOnSameNodesWith or MEDCouplingMesh::checkGeoEquivalWith with policy 20,21,or 22. - * The main difference is that this method is not expected to throw exception. - * This method has two outputs : + * Checks if \a this mesh includes all cells of an \a other mesh, and returns an array + * giving for each cell of the \a other an id of a cell in \a this mesh. A value larger + * than \a other->getNumberOfCells() in the returned array means that there is no + * corresponding cell in \a this mesh. + * It is expected that \a this and \a other meshes share the same node coordinates + * array, if it is not so an exception is thrown. + * \param [in] other - the mesh to compare with. + * \param [in] compType - specifies a cell comparison technique. For meaning of its + * valid values [0,1,2], see zipConnectivityTraducer(). + * \param [out] arr - a new instance of DataArrayInt returning correspondence + * between cells of the two meshes. It contains \a other->getNumberOfCells() + * values. The caller is to delete this array using + * decrRef() as it is no more needed. + * \return bool - \c true if all cells of \a other mesh are present in the \a this + * mesh. * - * @param compType is the comparison type. The possible values of this parameter are described in ParaMEDMEM::MEDCouplingUMesh::zipConnectivityTraducer method - * @param arr is an output parameter that returns a \b newly created instance. This array is of size 'other->getNumberOfCells()'. - * @return If 'other' is fully included in 'this 'true is returned. If not false is returned. + * \ref cpp_mcumesh_areCellsIncludedIn "Here is a C++ example".
+ * \ref py_mcumesh_areCellsIncludedIn "Here is a Python example". + * \sa checkDeepEquivalOnSameNodesWith() + * \sa checkGeoEquivalWith() */ bool MEDCouplingUMesh::areCellsIncludedIn(const MEDCouplingUMesh *other, int compType, DataArrayInt *& arr) const throw(INTERP_KERNEL::Exception) { @@ -1708,8 +1956,20 @@ bool MEDCouplingUMesh::areCellsIncludedIn2(const MEDCouplingUMesh *other, DataAr } /*! - * @param areNodesMerged if at least two nodes have been merged. - * @return old to new node correspondance. + * Merges nodes equal within \a precision and returns an array describing the + * permutation used to remove duplicate nodes. + * \param [in] precision - minimal absolute distance between two nodes at which they are + * considered not coincident. + * \param [out] areNodesMerged - is set to \c true if any coincident nodes removed. + * \param [out] newNbOfNodes - number of nodes remaining after the removal. + * \return DataArrayInt * - the permutation array in "Old to New" mode. For more + * info on "Old to New" mode see \ref MEDCouplingArrayRenumbering. The caller + * is to delete this array using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * + * \ref cpp_mcumesh_mergeNodes "Here is a C++ example".
+ * \ref py_mcumesh_mergeNodes "Here is a Python example". */ DataArrayInt *MEDCouplingUMesh::mergeNodes(double precision, bool& areNodesMerged, int& newNbOfNodes) { @@ -1719,8 +1979,23 @@ DataArrayInt *MEDCouplingUMesh::mergeNodes(double precision, bool& areNodesMerge return ret; } + /*! - * Idem ParaMEDMEM::MEDCouplingUMesh::mergeNodes method except that the merged nodes are meld into the barycenter of them. + * Merges nodes equal within \a precision and returns an array describing the + * permutation used to remove duplicate nodes. In contrast to mergeNodes(), location + * of merged nodes is changed to be at their barycenter. + * \param [in] precision - minimal absolute distance between two nodes at which they are + * considered not coincident. + * \param [out] areNodesMerged - is set to \c true if any coincident nodes removed. + * \param [out] newNbOfNodes - number of nodes remaining after the removal. + * \return DataArrayInt * - the permutation array in "Old to New" mode. For more + * info on "Old to New" mode see \ref MEDCouplingArrayRenumbering. The caller + * is to delete this array using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * + * \ref cpp_mcumesh_mergeNodes "Here is a C++ example".
+ * \ref py_mcumesh_mergeNodes "Here is a Python example". */ DataArrayInt *MEDCouplingUMesh::mergeNodes2(double precision, bool& areNodesMerged, int& newNbOfNodes) { @@ -1731,10 +2006,19 @@ DataArrayInt *MEDCouplingUMesh::mergeNodes2(double precision, bool& areNodesMerg } /*! - * This method tries to use 'other' coords and use it for 'this'. If no exception was thrown after the call of this method : - * this->_coords==other->_coords. If an exception is thrown 'this' remains unchanged. - * Contrary to MEDCouplingUMesh::tryToShareSameCoords method this method makes a deeper analyze of coordinates (and so more expensive) than simple equality. - * Two nodes one in 'this' and other in 'other' are considered equal if the distance between the two is lower than epsilon. + * Substitutes node coordinates array of \a this mesh with that of \a other mesh + * (i.e. \a this->_coords with \a other._coords) provided that coordinates of the two + * meshes match with a specified precision, else an exception is thrown and \a this + * remains unchanged. In case of success the nodal connectivity of \a this mesh + * is permuted according to new order of nodes. + * Contrary to tryToShareSameCoords() this method makes a deeper analysis of + * coordinates (and so more expensive) than simple equality. + * \param [in] other - the other mesh whose node coordinates array will be used by + * \a this mesh in case of their equality. + * \param [in] epsilon - the precision used to compare coordinates (using infinite norm). + * \throw If the coordinates array of \a this is not set. + * \throw If the coordinates array of \a other is not set. + * \throw If the coordinates of \a this and \a other do not match. */ void MEDCouplingUMesh::tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception) { @@ -1801,13 +2085,25 @@ MEDCouplingPointSet *MEDCouplingUMesh::buildPartOfMySelf2(int start, int end, in } /*! - * build a sub part of \b this. This sub part is defined by the cell ids contained in the array in [begin,end). - * @param begin begin of array containing the cell ids to keep. - * @param end end of array of cell ids to keep. \b WARNING end param is \b not included ! Idem STL standard definitions. - * @param keepCoords that specifies if you want or not to keep coords as this or zip it (see ParaMEDMEM::MEDCouplingUMesh::zipCoords). If true zipCoords is \b NOT called, if false, zipCoords is called. - * - * \warning This method modifies can generate an unstructured mesh whose cells are not sorted by geometric type order. - * In view of the MED file writing, a renumbering of cells of returned unstructured mesh (using MEDCouplingUMesh::sortCellsInMEDFileFrmt) should be necessary. + * Creates a new MEDCouplingUMesh containing specified cells of \a this mesh. + * The result mesh shares or not the node coordinates array with \a this mesh depending + * on \a keepCoords parameter. + * \warning Cells of the result mesh can be \b not sorted by geometric type, hence, + * to write this mesh to the MED file, its cells must be sorted using + * sortCellsInMEDFileFrmt(). + * \param [in] begin - an array of cell ids to include to the new mesh. + * \param [in] end - a pointer to last-plus-one-th element of \a begin. + * \param [in] keepCoords - if \c true, the result mesh shares the node coordinates + * array of \a this mesh, else "free" nodes are removed from the result mesh + * by calling zipCoords(). + * \return MEDCouplingPointSet * - a new instance of MEDCouplingUMesh. The caller is + * to delete this mesh using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * \throw If any cell id in the array \a begin is not valid. + * + * \ref cpp_mcumesh_buildPartOfMySelf "Here is a C++ example".
+ * \ref py_mcumesh_buildPartOfMySelf "Here is a Python example". */ MEDCouplingPointSet *MEDCouplingUMesh::buildPartOfMySelf(const int *begin, const int *end, bool keepCoords) const { @@ -1940,6 +2236,20 @@ void MEDCouplingUMesh::setPartOfMySelf2(int start, int end, int step, const MEDC } } +/*! + * Finds cells whose all nodes are in a given array of node ids. + * \param [in] partBg - the array of node ids. + * \param [in] partEnd - a pointer to a (last+1)-th element of \a partBg. + * \return DataArrayInt * - a new instance of DataArrayInt holding ids of found + * cells. The caller is to delete this array using decrRef() as it is no + * more needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * \throw If any cell id in \a partBg is not valid. + * + * \ref cpp_mcumesh_getCellIdsFullyIncludedInNodeIds "Here is a C++ example".
+ * \ref py_mcumesh_getCellIdsFullyIncludedInNodeIds "Here is a Python example". + */ DataArrayInt *MEDCouplingUMesh::getCellIdsFullyIncludedInNodeIds(const int *partBg, const int *partEnd) const { DataArrayInt *cellIdsKept=0; @@ -1989,7 +2299,21 @@ void MEDCouplingUMesh::fillCellIdsToKeepFromNodeIds(const int *begin, const int } /*! - * This method is very close too MEDCouplingUMesh::buildPartOfMySelfNode. The difference is that it returns directly ids. + * Finds cells whose all or some nodes are in a given array of node ids. + * \param [in] begin - the array of node ids. + * \param [in] end - a pointer to the (last+1)-th element of \a begin. + * \param [in] fullyIn - if \c true, then cells whose all nodes are in the + * array \a begin are returned only, else cells whose any node is in the + * array \a begin are returned. + * \return DataArrayInt * - a new instance of DataArrayInt holding ids of found + * cells. The caller is to delete this array using decrRef() as it is no more + * needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * \throw If any cell id in \a begin is not valid. + * + * \ref cpp_mcumesh_getCellIdsLyingOnNodes "Here is a C++ example".
+ * \ref py_mcumesh_getCellIdsLyingOnNodes "Here is a Python example". */ DataArrayInt *MEDCouplingUMesh::getCellIdsLyingOnNodes(const int *begin, const int *end, bool fullyIn) const { @@ -2000,10 +2324,25 @@ DataArrayInt *MEDCouplingUMesh::getCellIdsLyingOnNodes(const int *begin, const i } /*! - * Keeps from 'this' only cells which constituing point id are in the ids specified by ['begin','end'). - * The return newly allocated mesh will share the same coordinates as 'this'. - * Parameter 'fullyIn' specifies if a cell that has part of its nodes in ids array is kept or not. - * If 'fullyIn' is true only cells whose ids are \b fully contained in ['begin','end') tab will be kept. + Creates a new MEDCouplingUMesh containing some cells of \a this mesh. The cells to + copy are selected basing on specified node ids and the value of \a fullyIn + parameter. If \a fullyIn ==\c true, a cell is copied if its all nodes are in the + array \a begin of node ids. If \a fullyIn ==\c false, a cell is copied if any its + node is in the array of node ids. The created mesh shares the node coordinates array + with \a this mesh. + * \param [in] begin - the array of node ids. + * \param [in] end - a pointer to the (last+1)-th element of \a begin. + * \param [in] fullyIn - if \c true, then cells whose all nodes are in the + * array \a begin are copied, else cells whose any node is in the + * array \a begin are copied. + * \return MEDCouplingPointSet * - new instance of MEDCouplingUMesh. The caller is + * to delete this mesh using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * \throw If any node id in \a begin is not valid. + * + * \ref cpp_mcumesh_buildPartOfMySelfNode "Here is a C++ example".
+ * \ref py_mcumesh_buildPartOfMySelfNode "Here is a Python example". */ MEDCouplingPointSet *MEDCouplingUMesh::buildPartOfMySelfNode(const int *begin, const int *end, bool fullyIn) const { @@ -2014,10 +2353,26 @@ MEDCouplingPointSet *MEDCouplingUMesh::buildPartOfMySelfNode(const int *begin, c } /*! - * Contrary to MEDCouplingUMesh::buildPartOfMySelfNode method this method builds a mesh with a meshDimension equal to - * this->getMeshDimension()-1. The return newly allocated mesh will share the same coordinates as 'this'. - * Parameter 'fullyIn' specifies if a face that has part of its nodes in ids array is kept or not. - * If 'fullyIn' is true only faces whose ids are \b fully contained in ['begin','end') tab will be kept. + * Creates a new MEDCouplingUMesh containing cells, of dimension one less than \a + * this->getMeshDimension(), that bound some cells of \a this mesh. + * The cells of lower dimension to include to the result mesh are selected basing on + * specified node ids and the value of \a fullyIn parameter. If \a fullyIn ==\c true, a + * cell is copied if its all nodes are in the array \a begin of node ids. If \a fullyIn + * ==\c false, a cell is copied if any its node is in the array of node ids. The + * created mesh shares the node coordinates array with \a this mesh. + * \param [in] begin - the array of node ids. + * \param [in] end - a pointer to the (last+1)-th element of \a begin. + * \param [in] fullyIn - if \c true, then cells whose all nodes are in the + * array \a begin are added, else cells whose any node is in the + * array \a begin are added. + * \return MEDCouplingPointSet * - new instance of MEDCouplingUMesh. The caller is + * to delete this mesh using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * \throw If any node id in \a begin is not valid. + * + * \ref cpp_mcumesh_buildFacePartOfMySelfNode "Here is a C++ example".
+ * \ref py_mcumesh_buildFacePartOfMySelfNode "Here is a Python example". */ MEDCouplingPointSet *MEDCouplingUMesh::buildFacePartOfMySelfNode(const int *begin, const int *end, bool fullyIn) const { @@ -2029,10 +2384,18 @@ MEDCouplingPointSet *MEDCouplingUMesh::buildFacePartOfMySelfNode(const int *begi } /*! - * This method returns a mesh with meshDim=this->getMeshDimension()-1. - * This returned mesh contains cells that are linked with one and only one cell of this. - * @param keepCoords specifies if ParaMEDMEM::MEDCouplingUMesh::zipCoords is called on returned mesh before being returned. If true zipCoords is \b NOT called, if false, zipCoords is called. - * @return mesh with ref counter equal to 1. + * Creates a new MEDCouplingUMesh containing cells, of dimension one less than \a + * this->getMeshDimension(), which bound only one cell of \a this mesh. + * \param [in] keepCoords - if \c true, the result mesh shares the node coordinates + * array of \a this mesh, else "free" nodes are removed from the result mesh + * by calling zipCoords(). + * \return MEDCouplingPointSet * - a new instance of MEDCouplingUMesh. The caller is + * to delete this mesh using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * + * \ref cpp_mcumesh_buildBoundaryMesh "Here is a C++ example".
+ * \ref py_mcumesh_buildBoundaryMesh "Here is a Python example". */ MEDCouplingPointSet *MEDCouplingUMesh::buildBoundaryMesh(bool keepCoords) const { @@ -2176,8 +2539,15 @@ MEDCouplingUMesh *MEDCouplingUMesh::computeSkin() const throw(INTERP_KERNEL::Exc } /*! - * This methods returns set of nodes in a newly allocated array that the caller has to deal with. - * The returned nodes ids are those lying on the boundary of \b this. + * Finds nodes lying on the boundary of \a this mesh. + * \return DataArrayInt * - a new instance of DataArrayInt holding ids of found + * nodes. The caller is to delete this array using decrRef() as it is no + * more needed + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is node defined. + * + * \ref cpp_mcumesh_findBoundaryNodes "Here is a C++ example".
+ * \ref py_mcumesh_findBoundaryNodes "Here is a Python example". */ DataArrayInt *MEDCouplingUMesh::findBoundaryNodes() const { @@ -2191,14 +2561,20 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildUnstructured() const throw(INTERP_KERNE return const_cast(this); } -/* - * This method renumber 'this' using 'newNodeNumbers' array of size this->getNumberOfNodes. - * newNbOfNodes specifies the *std::max_element(newNodeNumbers,newNodeNumbers+this->getNumberOfNodes()) - * This value is asked because often known by the caller of this method. - * This method, contrary to MEDCouplingMesh::renumberCells does NOT conserve the number of nodes before and after. +/*! + * Permutes and possibly removes nodes as specified by \a newNodeNumbers array. + * If \a newNodeNumbers[ i ] < 0 then the i-th node is removed, + * else \a newNodeNumbers[ i ] is a new id of the i-th node. The nodal connectivity + * array is modified accordingly. + * \param [in] newNodeNumbers - a permutation array, of length \a + * this->getNumberOfNodes(), in "Old to New" mode. + * See \ref MEDCouplingArrayRenumbering for more info on renumbering modes. + * \param [in] newNbOfNodes - number of nodes remaining after renumbering. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. * - * @param newNodeNumbers array specifying the new numbering in old2New convention. - * @param newNbOfNodes the new number of nodes. + * \ref cpp_mcumesh_renumberNodes "Here is a C++ example".
+ * \ref py_mcumesh_renumberNodes "Here is a Python example". */ void MEDCouplingUMesh::renumberNodes(const int *newNodeNumbers, int newNbOfNodes) { @@ -2206,16 +2582,22 @@ void MEDCouplingUMesh::renumberNodes(const int *newNodeNumbers, int newNbOfNodes renumberNodesInConn(newNodeNumbers); } -/* - * This method renumber 'this' using 'newNodeNumbers' array of size this->getNumberOfNodes. - * newNbOfNodes specifies the *std::max_element(newNodeNumbers,newNodeNumbers+this->getNumberOfNodes()) - * This value is asked because often known by the caller of this method. - * This method, contrary to MEDCouplingMesh::renumberCells does NOT conserve the number of nodes before and after. - * The difference with ParaMEDMEM::MEDCouplingUMesh::renumberNodes method is in the fact that the barycenter of merged nodes is computed here. - * - * @param newNodeNumbers array specifying the new numbering. - * @param newNbOfNodes the new number of nodes. +/*! + * Permutes and possibly removes nodes as specified by \a newNodeNumbers array. + * If \a newNodeNumbers[ i ] < 0 then the i-th node is removed, + * else \a newNodeNumbers[ i ] is a new id of the i-th node. The nodal connectivity + * array is modified accordingly. In contrast to renumberNodes(), location + * of merged nodes (whose new ids coincide) is changed to be at their barycenter. + * \param [in] newNodeNumbers - a permutation array, of length \a + * this->getNumberOfNodes(), in "Old to New" mode. + * See \ref MEDCouplingArrayRenumbering for more info on renumbering modes. + * \param [in] newNbOfNodes - number of nodes remaining after renumbering, which is + * actually one more than the maximal id in \a newNodeNumbers. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. * + * \ref cpp_mcumesh_renumberNodes "Here is a C++ example".
+ * \ref py_mcumesh_renumberNodes "Here is a Python example". */ void MEDCouplingUMesh::renumberNodes2(const int *newNodeNumbers, int newNbOfNodes) { @@ -2302,10 +2684,17 @@ void MEDCouplingUMesh::duplicateNodes(const int *nodeIdsToDuplicateBg, const int } /*! - * This method renumbers nodes \b in \b connectivity \b only \b without \b any \b reference \b to \b coords. - * This method performs no check on the fact that new coordinate ids are valid. \b Use \b it \b with \b care ! - * This method is an generalization of \ref ParaMEDMEM::MEDCouplingUMesh::shiftNodeNumbersInConn "shiftNodeNumbersInConn method". - * @param [in] newNodeNumbers in old2New convention + * Changes ids of nodes within the nodal connectivity arrays according to a permutation + * array in "Old to New" mode. The node coordinates array is \b not changed by this method. + * This method is a generalization of shiftNodeNumbersInConn(). + * \warning This method performs no check of validity of new ids. **Use it with care !** + * \param [in] newNodeNumbersO2N - a permutation array, of length \a + * this->getNumberOfNodes(), in "Old to New" mode. + * See \ref MEDCouplingArrayRenumbering for more info on renumbering modes. + * \throw If the nodal connectivity of cells is not defined. + * + * \ref cpp_mcumesh_renumberNodesInConn "Here is a C++ example".
+ * \ref py_mcumesh_renumberNodesInConn "Here is a Python example". */ void MEDCouplingUMesh::renumberNodesInConn(const int *newNodeNumbersO2N) { @@ -2444,9 +2833,21 @@ void MEDCouplingUMesh::renumberCells(const int *old2NewBg, bool check) throw(INT } /*! - * Given a boundary box 'bbox' returns elements 'elems' contained in this 'bbox'. - * Warning 'elems' is incremented during the call so if elems is not empty before call returned elements will be - * added in 'elems' parameter. + * Finds cells whose bounding boxes intersect a given bounding box. + * \param [in] bbox - an array defining the bounding box via coordinates of its + * extremum points in "no interlace" mode, i.e. xMin, xMax, yMin, yMax, zMin, + * zMax (if in 3D). + * \param [in] eps - a factor used to increase size of the bounding box of cell + * before comparing it with \a bbox. This factor is multiplied by the maximal + * extent of the bounding box of cell to produce an addition to this bounding box. + * \return DataArrayInt * - a new instance of DataArrayInt holding ids for found + * cells. The caller is to delete this array using decrRef() as it is no more + * needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * + * \ref cpp_mcumesh_getCellsInBoundingBox "Here is a C++ example".
+ * \ref py_mcumesh_getCellsInBoundingBox "Here is a Python example". */ DataArrayInt *MEDCouplingUMesh::getCellsInBoundingBox(const double *bbox, double eps) const { @@ -2546,7 +2947,10 @@ DataArrayInt *MEDCouplingUMesh::getCellsInBoundingBox(const INTERP_KERNEL::Direc } /*! - * Returns the cell type of cell with id 'cellId'. + * Returns a type of a cell by its id. + * \param [in] cellId - the id of the cell of interest. + * \return INTERP_KERNEL::NormalizedCellType - enumeration item describing the cell type. + * \throw If \a cellId is invalid. Valid range is [0, \a this->getNumberOfCells() ). */ INTERP_KERNEL::NormalizedCellType MEDCouplingUMesh::getTypeOfCell(int cellId) const { @@ -2606,9 +3010,13 @@ int MEDCouplingUMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType } /*! - * Appends the nodal connectivity in 'conn' of cell with id 'cellId'. - * All elements added in conn can be used by MEDCouplingUMesh::getCoordinatesOfNode method. - * That is to say -1 separator is omitted in returned conn. + * Returns the nodal connectivity of a given cell. + * The separator of faces within polyhedron connectivity (-1) is not returned, thus + * all returned node ids can be used in getCoordinatesOfNode(). + * \param [in] cellId - an id of the cell of interest. + * \param [in,out] conn - a vector where the node ids are appended. It is not + * cleared before the appending. + * \throw If \a cellId is invalid. Valid range is [0, \a this->getNumberOfCells() ). */ void MEDCouplingUMesh::getNodeIdsOfCell(int cellId, std::vector& conn) const { @@ -2629,7 +3037,10 @@ std::string MEDCouplingUMesh::simpleRepr() const double tt=getTime(tmpp1,tmpp2); ret << "Time attached to the mesh [unit] : " << tt << " [" << getTimeUnit() << "]\n"; ret << "Iteration : " << tmpp1 << " Order : " << tmpp2 << "\n"; - ret << "Mesh dimension : " << _mesh_dim << "\nSpace dimension : "; + if(_mesh_dim>=-1) + { ret << "Mesh dimension : " << _mesh_dim << "\nSpace dimension : "; } + else + { ret << " Mesh dimension has not been set or is invalid !"; } if(_coords!=0) { const int spaceDim=getSpaceDimension(); @@ -2783,8 +3194,15 @@ int MEDCouplingUMesh::getNumberOfNodesInCell(int cellId) const } /*! - * This method is equivalent to MEDCouplingUMesh::getAllTypes excecpt that it returns only types of submesh which cell ids are in [begin,end). - * This method avoids to compute explicitely submesh to get its types. + * Returns types of cells of the specified part of \a this mesh. + * This method avoids computing sub-mesh explicitely to get its types. + * \param [in] begin - an array of cell ids of interest. + * \param [in] end - the end of \a begin, i.e. a pointer to its (last+1)-th element. + * \return std::set - a set of enumeration items + * describing the cell types. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * \sa getAllTypes() */ std::set MEDCouplingUMesh::getTypesOfPart(const int *begin, const int *end) const throw(INTERP_KERNEL::Exception) { @@ -2798,8 +3216,14 @@ std::set MEDCouplingUMesh::getTypesOfPart(con } /*! - * Method reserved for advanced users having prepared their connectivity before. - * Arrays 'conn' and 'connIndex' will be aggregated without any copy and their counter will be incremented. + * Defines the nodal connectivity using given connectivity arrays. Optionally updates + * a set of types of cells constituting \a this mesh. + * This method is for advanced users having prepared their connectivity before. For + * more info on using this method see \ref MEDCouplingUMeshAdvBuild. + * \param [in] conn - the nodal connectivity array. + * \param [in] connIndex - the nodal connectivity index array. + * \param [in] isComputingTypes - if \c true, the set of types constituting \a this + * mesh is updated. */ void MEDCouplingUMesh::setConnectivity(DataArrayInt *conn, DataArrayInt *connIndex, bool isComputingTypes) { @@ -2833,7 +3257,8 @@ MEDCouplingUMesh::~MEDCouplingUMesh() } /*! - * This method recomputes all cell types of 'this'. + * Recomputes a set of cell types of \a this mesh. For more info see + * \ref MEDCouplingUMeshNodalConnectivity. */ void MEDCouplingUMesh::computeTypes() { @@ -2867,6 +3292,11 @@ void MEDCouplingUMesh::checkConnectivityFullyDefined() const throw(INTERP_KERNEL throw INTERP_KERNEL::Exception("Reverse nodal connectivity computation requires full connectivity set in unstructured mesh."); } +/*! + * Returns a number of cells constituting \a this mesh. + * \return int - the number of cells in \a this mesh. + * \throw If the nodal connectivity of cells is not defined. + */ int MEDCouplingUMesh::getNumberOfCells() const { if(_nodal_connec_index) @@ -2878,6 +3308,12 @@ int MEDCouplingUMesh::getNumberOfCells() const throw INTERP_KERNEL::Exception("Unable to get number of cells because no connectivity specified !"); } +/*! + * Returns a dimension of \a this mesh, i.e. a dimension of cells constituting \a this + * mesh. For more info see \ref MEDCouplingMeshesPage. + * \return int - the dimension of \a this mesh. + * \throw If the mesh dimension is not defined using setMeshDimension(). + */ int MEDCouplingUMesh::getMeshDimension() const { if(_mesh_dim<-1) @@ -2886,7 +3322,10 @@ int MEDCouplingUMesh::getMeshDimension() const } /*! - * This method is for test reason. Normally the integer returned is not useable by user. + * Returns a length of the nodal connectivity array. + * This method is for test reason. Normally the integer returned is not useable by + * user. For more info see \ref MEDCouplingUMeshNodalConnectivity. + * \return int - the length of the nodal connectivity array. */ int MEDCouplingUMesh::getMeshLength() const { @@ -3060,13 +3499,16 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildPartOfMySelfKeepCoords(const int *begin } /*! - * brief returns the volumes of the cells underlying the field \a field - * - * For 2D geometries, the returned field contains the areas. - * For 3D geometries, the returned field contains the volumes. - * - * param field field on which cells the volumes are required - * return field containing the volumes, area or length depending the meshdimension. + * Returns a new MEDCouplingFieldDouble containing volumes of cells constituting \a this + * mesh.
+ * For 1D cells, the returned field contains lengths.
+ * For 2D cells, the returned field contains areas.
+ * For 3D cells, the returned field contains volumes. + * \param [in] isAbs - if \c true, the computed cell volume does not reflect cell + * orientation, i.e. the volume is always positive. + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble on cells + * and one time . The caller is to delete this field using decrRef() as it is no + * more needed. */ MEDCouplingFieldDouble *MEDCouplingUMesh::getMeasureField(bool isAbs) const { @@ -3106,8 +3548,22 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::getMeasureField(bool isAbs) const } /*! - * This method is equivalent to MEDCouplingUMesh::getMeasureField except that only part defined by [begin,end) is returned ! - * This method avoids to build explicitely part of this to perform the work. + * Returns a new DataArrayDouble containing volumes of specified cells of \a this + * mesh.
+ * For 1D cells, the returned array contains lengths.
+ * For 2D cells, the returned array contains areas.
+ * For 3D cells, the returned array contains volumes. + * This method avoids building explicitly a part of \a this mesh to perform the work. + * \param [in] isAbs - if \c true, the computed cell volume does not reflect cell + * orientation, i.e. the volume is always positive. + * \param [in] begin - an array of cell ids of interest. + * \param [in] end - the end of \a begin, i.e. a pointer to its (last+1)-th element. + * \return DataArrayDouble * - a new instance of DataArrayDouble. The caller is to + * delete this array using decrRef() as it is no more needed. + * + * \ref cpp_mcumesh_getPartMeasureField "Here is a C++ example".
+ * \ref py_mcumesh_getPartMeasureField "Here is a Python example". + * \sa getMeasureField() */ DataArrayDouble *MEDCouplingUMesh::getPartMeasureField(bool isAbs, const int *begin, const int *end) const { @@ -3143,8 +3599,19 @@ DataArrayDouble *MEDCouplingUMesh::getPartMeasureField(bool isAbs, const int *be } /*! - * This methods returns a field on nodes and no time. This method is useful to check "P1*" conservative interpolators. - * This field returns the getMeasureField of the dualMesh in P1 sens of 'this'. + * Returns a new MEDCouplingFieldDouble containing volumes of cells of a dual mesh of + * \a this one. The returned field contains the dual cell volume for each corresponding + * node in \a this mesh. In other words, the field returns the getMeasureField() of + * the dual mesh in P1 sens of \a this.
+ * For 1D cells, the returned field contains lengths.
+ * For 2D cells, the returned field contains areas.
+ * For 3D cells, the returned field contains volumes. + * This method is useful to check "P1*" conservative interpolators. + * \param [in] isAbs - if \c true, the computed cell volume does not reflect cell + * orientation, i.e. the volume is always positive. + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble on + * nodes and one time. The caller is to delete this array using decrRef() as + * it is no more needed. */ MEDCouplingFieldDouble *MEDCouplingUMesh::getMeasureFieldOnNode(bool isAbs) const { @@ -3173,8 +3640,21 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::getMeasureFieldOnNode(bool isAbs) cons } /*! - * This methods returns a vector field on cells that represents the orthogonal vector normalized of each 2D cell of this. - * This method is only callable on mesh with meshdim == 2 and spacedim==2 or 3. + * Returns a new MEDCouplingFieldDouble holding normal vectors to cells of \a this + * mesh. The returned normal vectors to each cell have a norm2 equal to 1. + * The computed vectors have this->getMeshDimension()+1 components + * and are normalized. + *
\a this can be either + * - a 2D mesh in 2D or 3D space or + * - an 1D mesh in 2D space. + * + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble on + * cells and one time. The caller is to delete this field using decrRef() as + * it is no more needed. + * \throw If the nodal connectivity of cells is not defined. + * \throw If the coordinates array is not set. + * \throw If the mesh dimension is not set. + * \throw If the mesh and space dimension is not as specified above. */ MEDCouplingFieldDouble *MEDCouplingUMesh::buildOrthogonalField() const { @@ -3231,8 +3711,27 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::buildOrthogonalField() const } /*! - * This method is equivalent to MEDCouplingUMesh::buildOrthogonalField except that only part defined by [begin,end) is returned ! - * This method avoids to build explicitely part of this to perform the work. + * Returns a new MEDCouplingFieldDouble holding normal vectors to specified cells of + * \a this mesh. The computed vectors have this->getMeshDimension()+1 components + * and are normalized. + *
\a this can be either + * - a 2D mesh in 2D or 3D space or + * - an 1D mesh in 2D space. + * + * This method avoids building explicitly a part of \a this mesh to perform the work. + * \param [in] begin - an array of cell ids of interest. + * \param [in] end - the end of \a begin, i.e. a pointer to its (last+1)-th element. + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble on + * cells and one time. The caller is to delete this field using decrRef() as + * it is no more needed. + * \throw If the nodal connectivity of cells is not defined. + * \throw If the coordinates array is not set. + * \throw If the mesh dimension is not set. + * \throw If the mesh and space dimension is not as specified above. + * \sa buildOrthogonalField() + * + * \ref cpp_mcumesh_buildPartOrthogonalField "Here is a C++ example".
+ * \ref py_mcumesh_buildPartOrthogonalField "Here is a Python example". */ MEDCouplingFieldDouble *MEDCouplingUMesh::buildPartOrthogonalField(const int *begin, const int *end) const { @@ -3287,8 +3786,16 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::buildPartOrthogonalField(const int *be } /*! - * This methods returns a vector newly created field on cells that represents the direction vector of each 1D cell of this. - * This method is only callable on mesh with meshdim == 1 containing only SEG2. + * Returns a new MEDCouplingFieldDouble holding a direction vector for each SEG2 in \a + * this 1D mesh. The computed vectors have this->getSpaceDimension() components + * and are \b not normalized. + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble on + * cells and one time. The caller is to delete this field using decrRef() as + * it is no more needed. + * \throw If the nodal connectivity of cells is not defined. + * \throw If the coordinates array is not set. + * \throw If \a this->getMeshDimension() != 1. + * \throw If \a this mesh includes cells of type other than SEG2. */ MEDCouplingFieldDouble *MEDCouplingUMesh::buildDirectionVectorField() const { @@ -3318,18 +3825,27 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::buildDirectionVectorField() const } /*! - * This method expects that 'this' is fully defined and has a spaceDim==3 and a meshDim==3. If it is not the case an exception will be thrown. - * This method returns 2 objects : - * - a newly created mesh instance containing the result of the slice lying on different coords than 'this' and with a meshdim == 2 - * - a newly created dataarray having number of tuples equal to the number of cells in returned mesh that tells for each 2D cell in returned - * mesh the 3D cell id is 'this' it comes from. - * This method works only for linear meshes (non quadratic). - * If plane crosses within 'eps' a face in 'this' shared by more than 1 cell, 2 output faces will be generated. The 2 faces having the same geometry than intersecting - * face. Only 'cellIds' parameter can distinguish the 2. - * @param origin is the origin of the plane. It should be an array of length 3. - * @param vec is the direction vector of the plane. It should be an array of length 3. Norm of 'vec' should be > 1e-6. - * @param eps is the precision. It is used by called method MEDCouplingUMesh::getCellIdsCrossingPlane for the first 3D cell selection (in absolute). 'eps' is - * also used to state if new points should be created or already existing points are reused. 'eps' is also used to tells if plane overlaps a face, edge or nodes (in absolute). + * Creates a 2D mesh by cutting \a this 3D mesh with a plane. In addition to the mesh, + * returns a new DataArrayInt, of length equal to the number of 2D cells in the result + * mesh, holding, for each cell in the result mesh, an id of a 3D cell it comes + * from. If a result face is shared by two 3D cells, then the face in included twice in + * the result mesh. + * \param [in] origin - 3 components of a point defining location of the plane. + * \param [in] vec - 3 components of a vector normal to the plane. Vector magnitude + * must be greater than 1e-6. + * \param [in] eps - half-thickness of the plane. + * \param [out] cellIds - a new instance of DataArrayInt holding ids of 3D cells + * producing correspondent 2D cells. The caller is to delete this array + * using decrRef() as it is no more needed. + * \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. This mesh does + * not share the node coordinates array with \a this mesh. The caller is to + * delete this mesh using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * \throw If \a this->getMeshDimension() != 3 or \a this->getSpaceDimension() != 3. + * \throw If magnitude of \a vec is less than 1e-6. + * \throw If the plane does not intersect any 3D cell of \a this mesh. + * \throw If \a this includes quadratic cells. */ MEDCouplingUMesh *MEDCouplingUMesh::buildSlice3D(const double *origin, const double *vec, double eps, DataArrayInt *&cellIds) const throw(INTERP_KERNEL::Exception) { @@ -3375,18 +3891,27 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildSlice3D(const double *origin, const dou } /*! - * This method expects that 'this' is fully defined and has a spaceDim==3 and a meshDim==2. If it is not the case an exception will be thrown. - * This method returns 2 objects : - * - a newly created mesh instance containing the result of the slice lying on different coords than 'this' and with a meshdim == 1 - * - a newly created dataarray having number of tuples equal to the number of cells in returned mesh that tells for each 2D cell in returned - * mesh the 3DSurf cell id is 'this' it comes from. - * This method works only for linear meshes (non quadratic). - * If plane crosses within 'eps' a face in 'this' shared by more than 1 cell, 2 output faces will be generated. The 2 faces having the same geometry than intersecting - * face. Only 'cellIds' parameter can distinguish the 2. - * @param origin is the origin of the plane. It should be an array of length 3. - * @param vec is the direction vector of the plane. It should be an array of length 3. Norm of 'vec' should be > 1e-6. - * @param eps is the precision. It is used by called method MEDCouplingUMesh::getCellIdsCrossingPlane for the first 3DSurf cell selection (in absolute). 'eps' is - * also used to state if new points should be created or already existing points are reused. 'eps' is also used to tells if plane overlaps a face, edge or nodes (in absolute). + * Creates an 1D mesh by cutting \a this 2D mesh in 3D space with a plane. In +addition to the mesh, returns a new DataArrayInt, of length equal to the number of 1D cells in the result mesh, holding, for each cell in the result mesh, an id of a 2D cell it comes +from. If a result segment is shared by two 2D cells, then the segment in included twice in +the result mesh. + * \param [in] origin - 3 components of a point defining location of the plane. + * \param [in] vec - 3 components of a vector normal to the plane. Vector magnitude + * must be greater than 1e-6. + * \param [in] eps - half-thickness of the plane. + * \param [out] cellIds - a new instance of DataArrayInt holding ids of faces + * producing correspondent segments. The caller is to delete this array + * using decrRef() as it is no more needed. + * \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. This is an 1D + * mesh in 3D space. This mesh does not share the node coordinates array with + * \a this mesh. The caller is to delete this mesh using decrRef() as it is + * no more needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * \throw If \a this->getMeshDimension() != 2 or \a this->getSpaceDimension() != 3. + * \throw If magnitude of \a vec is less than 1e-6. + * \throw If the plane does not intersect any 2D cell of \a this mesh. + * \throw If \a this includes quadratic cells. */ MEDCouplingUMesh *MEDCouplingUMesh::buildSlice3DSurf(const double *origin, const double *vec, double eps, DataArrayInt *&cellIds) const throw(INTERP_KERNEL::Exception) { @@ -3455,10 +3980,19 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildSlice3DSurf(const double *origin, const } /*! - * This method expects that 'this' is fully defined and has a spaceDim==3. If it is not the case an exception will be thrown. - * This method returns a newly created dataarray containing cellsids in 'this' that potentially crosses the plane specified by 'origin' and 'vec'. - * @param origin is the origin of the plane. It should be an array of length 3. - * @param vec is the direction vector of the plane. It should be an array of length 3. Norm of 'vec' should be > 1e-6. + * Finds cells whose bounding boxes intersect a given plane. + * \param [in] origin - 3 components of a point defining location of the plane. + * \param [in] vec - 3 components of a vector normal to the plane. Vector magnitude + * must be greater than 1e-6. + * \param [in] eps - half-thickness of the plane. + * \return DataArrayInt * - a new instance of DataArrayInt holding ids of the found + * cells. The caller is to delete this array using decrRef() as it is no more + * needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * \throw If \a this->getSpaceDimension() != 3. + * \throw If magnitude of \a vec is less than 1e-6. + * \sa buildSlice3D() */ DataArrayInt *MEDCouplingUMesh::getCellIdsCrossingPlane(const double *origin, const double *vec, double eps) const throw(INTERP_KERNEL::Exception) { @@ -3686,10 +4220,16 @@ void MEDCouplingUMesh::distanceToPoint2DCurveAlg(const double *pt, const DataArr } /*! - * Returns a cell if any that contains the point located on 'pos' with precison eps. - * If 'pos' is outside 'this' -1 is returned. If several cells contain this point the cell with the smallest id is returned. - * \b Warning this method is good if the caller intends to evaluate only one point. But if more than one point is requested on 'this' - * it is better to use MEDCouplingUMesh::getCellsContainingPoints method because in this case, the acceleration structure will be computed only once. + * Finds cells in contact with a ball (i.e. a point with precision). + * \warning This method is suitable if the caller intends to evaluate only one + * point, for more points getCellsContainingPoints() is recommended as it is + * faster. + * \param [in] pos - array of coordinates of the ball central point. + * \param [in] eps - ball radius. + * \return int - a smallest id of cells being in contact with the ball, -1 in case + * if there are no such cells. + * \throw If the coordinates array is not set. + * \throw If \a this->getMeshDimension() != \a this->getSpaceDimension(). */ int MEDCouplingUMesh::getCellContainingPoint(const double *pos, double eps) const { @@ -3701,9 +4241,19 @@ int MEDCouplingUMesh::getCellContainingPoint(const double *pos, double eps) cons } /*! - * Returns all cellIds in 'elts' of point 'pos' with eps accuracy. - * \b Warning this method is good if the caller intends to evaluate only one point. But if more than one point is requested on 'this' - * it is better to use MEDCouplingUMesh::getCellsContainingPoints method because in this case, the acceleration structure will be computed only once. + * Finds cells in contact with a ball (i.e. a point with precision). + * \warning This method is suitable if the caller intends to evaluate only one + * point, for more points getCellsContainingPoints() is recommended as it is + * faster. + * \param [in] pos - array of coordinates of the ball central point. + * \param [in] eps - ball radius. + * \param [in,out] elts - vector returning ids of the found cells. It is cleared + * before inserting ids. + * \throw If the coordinates array is not set. + * \throw If \a this->getMeshDimension() != \a this->getSpaceDimension(). + * + * \ref cpp_mcumesh_getCellsContainingPoint "Here is a C++ example".
+ * \ref py_mcumesh_getCellsContainingPoint "Here is a Python example". */ void MEDCouplingUMesh::getCellsContainingPoint(const double *pos, double eps, std::vector& elts) const { @@ -3872,15 +4422,30 @@ void MEDCouplingUMesh::getCellsContainingPointsAlg(const double *coords, const d } } } - /*! - * This method is an extension of MEDCouplingUMesh::getCellContainingPoint and MEDCouplingUMesh::getCellsContainingPoint. - * This method performs 'nbOfPoints' time the getCellsContainingPoint request. This method is recommended rather than the 2 others - * in case of multi points searching. - * This method returns 2 arrays 'elts' and 'eltsIndex'. 'eltsIndex' is of size 'nbOfPoints+1' and 'elts' is of size 'eltsIndex[nbOfPoints-1]'. - * For point j in [0,nbOfPoints), (eltsIndex[j+1]-eltsIndex[j]) cells contain this point. These cells are : [elts.begin()+eltsIndex[j],elts.begin():eltsIndex[j+1]). - * - * \param pos input parameter that points to an array of size 'getSpaceDim()*nbOfPoints' points stored in full interlace mode : X0,Y0,Z0,X1,Y1,Z1... + * Finds cells in contact with several balls (i.e. points with precision). + * This method is an extension of getCellContainingPoint() and + * getCellsContainingPoint() for the case of multiple points. + * \param [in] pos - an array of coordinates of points in full interlace mode : + * X0,Y0,Z0,X1,Y1,Z1,... Size of the array must be \a + * 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, + * 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 + * point are described by following range of indices: + * [ \a eltsIndex[ *i* ], \a eltsIndex[ *i*+1 ] ) and the cell ids are + * \a elts[ \a eltsIndex[ *i* ]], \a elts[ \a eltsIndex[ *i* ] + 1 ], ... + * Number of cells in contact with the *i*-th point is + * \a eltsIndex[ *i*+1 ] - \a eltsIndex[ *i* ]. + * \throw If the coordinates array is not set. + * \throw If \a this->getMeshDimension() != \a this->getSpaceDimension(). + * + * \ref cpp_mcumesh_getCellsContainingPoints "Here is a C++ example".
+ * \ref py_mcumesh_getCellsContainingPoints "Here is a Python example". */ void MEDCouplingUMesh::getCellsContainingPoints(const double *pos, int nbOfPoints, double eps, std::vector& elts, std::vector& eltsIndex) const @@ -3926,10 +4491,14 @@ void MEDCouplingUMesh::getCellsContainingPoints(const double *pos, int nbOfPoint } /*! - * This method is only available for a mesh with meshDim==2 and spaceDim==2||spaceDim==3. - * This method returns a vector 'cells' where all detected butterfly cells have been added to cells. - * A 2D cell is considered to be butterfly if it exists at least one pair of distinct edges of it that intersect each other - * anywhere excepted their extremities. An INTERP_KERNEL::NORM_NORI3 could \b not be butterfly. + * Finds butterfly cells in \a this mesh. A 2D cell is considered to be butterfly if at + * least two its edges intersect each other anywhere except their extremities. An + * INTERP_KERNEL::NORM_NORI3 cell can \b not be butterfly. + * \param [in,out] cells - a vector returning ids of the found cells. It is not + * cleared before filling in. + * \param [in] eps - precision. + * \throw If \a this->getMeshDimension() != 2. + * \throw If \a this->getSpaceDimension() != 2 && \a this->getSpaceDimension() != 3. */ void MEDCouplingUMesh::checkButterflyCells(std::vector& cells, double eps) const { @@ -4346,7 +4915,10 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildExtrudedMeshFromThisLowLev(int nbOfNode } /*! - * This method returns if 'this' is constituted by only quadratic cells. + * Checks if \a this mesh is constituted by only quadratic cells. + * \return bool - \c true if there are only quadratic cells in \a this mesh. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. */ bool MEDCouplingUMesh::isFullyQuadratic() const { @@ -4363,7 +4935,10 @@ bool MEDCouplingUMesh::isFullyQuadratic() const } /*! - * This method returns if there is at least one quadratic cell. + * Checks if \a this mesh includes any quadratic cell. + * \return bool - \c true if there is at least one quadratic cells in \a this mesh. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. */ bool MEDCouplingUMesh::isPresenceOfQuadratic() const { @@ -4380,8 +4955,10 @@ bool MEDCouplingUMesh::isPresenceOfQuadratic() const } /*! - * This method convert quadratic cells to linear cells if any was found. - * If no such cells exists 'this' remains unchanged. + * Converts all quadratic cells to linear ones. If there are no quadratic cells in \a + * this mesh, it remains unchanged. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. */ void MEDCouplingUMesh::convertQuadraticCellsToLinear() throw(INTERP_KERNEL::Exception) { @@ -4756,12 +5333,18 @@ DataArrayInt *MEDCouplingUMesh::convertLinearCellsToQuadratic3D1(DataArrayInt *& } /*! - * This method tessallates 'this' so that the number of cells remains the same. - * This method works only for meshes with spaceDim equal to 2 and meshDim equal to 2. - * If no cells are quadratic in 'this' (INTERP_KERNEL::NORM_QUAD8, INTERP_KERNEL::NORM_TRI6, INTERP_KERNEL::NORM_QPOLYG ) this method will remain unchanged. - * - * \b WARNING this method can lead to a uge amount of nodes if eps is very low. - * @param eps specifies the maximal angle (in radian) between 2 subedges of polylinized edge constituting the input polygon. + * Tessellates \a this 2D mesh by dividing not straight edges of quadratic faces, + * so that the number of cells remains the same. Quadratic faces are converted to + * polygons. This method works only for 2D meshes in + * 2D space. If no cells are quadratic (INTERP_KERNEL::NORM_QUAD8, + * INTERP_KERNEL::NORM_TRI6, INTERP_KERNEL::NORM_QPOLYG ), \a this mesh remains unchanged. + * \warning This method can lead to a huge amount of nodes if \a eps is very low. + * \param [in] eps - specifies the maximal angle (in radians) between 2 sub-edges of + * a polylinized edge constituting the input polygon. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * \throw If \a this->getMeshDimension() != 2. + * \throw If \a this->getSpaceDimension() != 2. */ void MEDCouplingUMesh::tessellate2D(double eps) throw(INTERP_KERNEL::Exception) { @@ -4783,12 +5366,14 @@ void MEDCouplingUMesh::tessellate2D(double eps) throw(INTERP_KERNEL::Exception) } /*! - * This method tessallates 'this' so that the number of cells remains the same. - * This method works only for meshes with spaceDim equal to 2 and meshDim equal to 1. - * If no cells are quadratic in 'this' (INTERP_KERNEL::NORM_QUAD8, INTERP_KERNEL::NORM_TRI6, INTERP_KERNEL::NORM_QPOLYG ) this method will remain unchanged. - * - * \b WARNING this method can lead to a uge amount of nodes if eps is very low. - * @param eps specifies the maximal angle (in radian) between 2 subedges of polylinized edge constituting the input polygon. + * Tessellates \a this 1D mesh in 2D space by dividing not straight quadratic edges. + * \warning This method can lead to a huge amount of nodes if \a eps is very low. + * \param [in] eps - specifies the maximal angle (in radian) between 2 sub-edges of + * a sub-divided edge. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * \throw If \a this->getMeshDimension() != 1. + * \throw If \a this->getSpaceDimension() != 2. */ void MEDCouplingUMesh::tessellate2DCurve(double eps) throw(INTERP_KERNEL::Exception) { @@ -4862,16 +5447,26 @@ void MEDCouplingUMesh::tessellate2DCurve(double eps) throw(INTERP_KERNEL::Except } /*! - * This methods modify this by converting each cells into simplex cell, that is too say triangle for meshdim==2 or tetra for meshdim==3. - * This cut into simplex is performed following the parameter \a policy. This method so typically increases the number of cells of \a this. - * This method \b keeps the number of nodes \b unchanged. That's why the splitting policy in 3D INTERP_KERNEL::GENERAL_24 and INTERP_KERNEL::GENERAL_48 are not available here. - * This method returns new2old newly allocated array that specifies a each cell of \a this after the call what was its id it comes. - * - * The semantic of \a policy parameter : - * - 1 only QUAD4. For QUAD4 the cut is done along 0-2 diagonal for QUAD4 - * - 2 only QUAD4. For QUAD4 the cut is done along 1-3 diagonal for QUAD4 - * - PLANAR_FACE_5 only HEXA8. All HEXA8 are split into 5 TETRA4 - * - PLANAR_FACE_6 only HEXA8. All HEXA8 are split into 6 TETRA4 + * Divides every cell of \a this mesh into simplices (triangles in 2D and tetrahedra in 3D). + * In addition, returns an array mapping new cells to old ones.
+ * This method typically increases the number of cells in \a this mesh + * but the number of nodes remains \b unchanged. + * That's why the 3D splitting policies + * INTERP_KERNEL::GENERAL_24 and INTERP_KERNEL::GENERAL_48 are not available here. + * \param [in] policy - specifies a pattern used for splitting. + * The semantic of \a policy is: + * - 0 - to split QUAD4 by cutting it along 0-2 diagonal (for 2D mesh only). + * - 1 - to split QUAD4 by cutting it along 1-3 diagonal (for 2D mesh only). + * - INTERP_KERNEL::PLANAR_FACE_5 - to split HEXA8 into 5 TETRA4 (for 3D mesh only). + * - INTERP_KERNEL::PLANAR_FACE_6 - to split HEXA8 into 6 TETRA4 (for 3D mesh only). + * \return DataArrayInt * - a new instance of DataArrayInt holding, for each new cell, + * an id of old cell producing it. The caller is to delete this array using + * decrRef() as it is no more needed. + * \throw If \a policy is 0 or 1 and \a this->getMeshDimension() != 2. + * \throw If \a policy is INTERP_KERNEL::PLANAR_FACE_5 or INTERP_KERNEL::PLANAR_FACE_6 + * and \a this->getMeshDimension() != 3. + * \throw If \a policy is not one of the four discussed above. + * \throw If the nodal connectivity of cells is not defined. */ DataArrayInt *MEDCouplingUMesh::simplexize(int policy) throw(INTERP_KERNEL::Exception) { @@ -4890,11 +5485,26 @@ DataArrayInt *MEDCouplingUMesh::simplexize(int policy) throw(INTERP_KERNEL::Exce } } +/*! + * Checks if \a this mesh is constituted by simplex cells only. Simplex cells are: + * - 1D: INTERP_KERNEL::NORM_SEG2 + * - 2D: INTERP_KERNEL::NORM_TRI3 + * - 3D: INTERP_KERNEL::NORM_TETRA4. + * + * This method is useful for users that need to use P1 field services as + * MEDCouplingFieldDouble::getValueOn(), MEDCouplingField::buildMeasureField() etc. + * All these methods need mesh support containing only simplex cells. + * \return bool - \c true if there are only simplex cells in \a this mesh. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * \throw If \a this->getMeshDimension() < 1. + */ bool MEDCouplingUMesh::areOnlySimplexCells() const throw(INTERP_KERNEL::Exception) { checkFullyDefined(); - if(getMeshDimension()<1) - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::areOnlySimplexCells : only available with meshes having a meshdim >= 1 !"); + int mdim=getMeshDimension(); + if(mdim<1 || mdim>3) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::areOnlySimplexCells : only available with meshes having a meshdim 1, 2 or 3 !"); int nbCells=getNumberOfCells(); const int *conn=_nodal_connec->getConstPointer(); const int *connI=_nodal_connec_index->getConstPointer(); @@ -5200,13 +5810,14 @@ void MEDCouplingUMesh::subDivide2DMesh(const int *nodeSubdived, const int *nodeI } /*! - * This method converts all degenerated cells to simpler cells. For example a NORM_QUAD4 cell consituted from 2 same node id in its - * nodal connectivity will be transform to a NORM_TRI3 cell. - * This method works \b only \b on \b linear cells. - * This method works on nodes ids, that is to say a call to ParaMEDMEM::MEDCouplingUMesh::mergeNodes - * method could be useful before calling this method in case of presence of several pair of nodes located on same position. - * This method throws an exception if 'this' is not fully defined (connectivity). - * This method throws an exception too if a "too" degenerated cell is detected. For example a NORM_TRI3 with 3 times the same node id. + * Converts degenerated 2D or 3D linear cells of \a this mesh into cells of simpler + * type. For example an INTERP_KERNEL::NORM_QUAD4 cell having only three unique nodes in + * its connectivity is transformed into an INTERP_KERNEL::NORM_TRI3 cell. This method + * does \b not perform geometrical checks and checks only nodal connectivity of cells, + * so it can be useful to call mergeNodes() before calling this method. + * \throw If \a this->getMeshDimension() <= 1. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. */ void MEDCouplingUMesh::convertDegeneratedCells() throw(INTERP_KERNEL::Exception) { @@ -5240,10 +5851,20 @@ void MEDCouplingUMesh::convertDegeneratedCells() throw(INTERP_KERNEL::Exception) } /*! - * This method checks that all or only polygons (depending 'polyOnly' parameter) 2D cells are correctly oriented relative to 'vec' vector. - * The 'vec' vector has to have a non nul norm. - * If not 'cells' parameter will be appended with cellIds of incorrect cells. - * @throw when 'this' is not a mesh with meshdim==2 and spacedim==3 + * Finds incorrectly oriented cells of this 2D mesh in 3D space. + * A cell is considered to be oriented correctly if an angle between its + * normal vector and a given vector is less than \c PI / \c 2. + * \param [in] vec - 3 components of the vector specifying the correct orientation of + * cells. + * \param [in] polyOnly - if \c true, only polygons are checked, else, all cells are + * checked. + * \param [in,out] cells - a vector returning ids of incorrectly oriented cells. It + * is not cleared before filling in. + * \throw If \a this->getMeshDimension() != 2. + * \throw If \a this->getSpaceDimension() != 3. + * + * \ref cpp_mcumesh_are2DCellsNotCorrectlyOriented "Here is a C++ example".
+ * \ref py_mcumesh_are2DCellsNotCorrectlyOriented "Here is a Python example". */ void MEDCouplingUMesh::are2DCellsNotCorrectlyOriented(const double *vec, bool polyOnly, std::vector& cells) const throw(INTERP_KERNEL::Exception) { @@ -5266,9 +5887,18 @@ void MEDCouplingUMesh::are2DCellsNotCorrectlyOriented(const double *vec, bool po } /*! - * This method orient correctly (if needed) all or only polygons (depending 'polyOnly' parameter) 2D cells are correctly oriented relative to 'vec' vector. - * The 'vec' vector has to have a non nul norm. - * @throw when 'this' is not a mesh with meshdim==2 and spacedim==3 + * Reverse connectivity of 2D cells whose orientation is not correct. A cell is + * considered to be oriented correctly if an angle between its normal vector and a + * given vector is less than \c PI / \c 2. + * \param [in] vec - 3 components of the vector specifying the correct orientation of + * cells. + * \param [in] polyOnly - if \c true, only polygons are checked, else, all cells are + * checked. + * \throw If \a this->getMeshDimension() != 2. + * \throw If \a this->getSpaceDimension() != 3. + * + * \ref cpp_mcumesh_are2DCellsNotCorrectlyOriented "Here is a C++ example".
+ * \ref py_mcumesh_are2DCellsNotCorrectlyOriented "Here is a Python example". */ void MEDCouplingUMesh::orientCorrectly2DCells(const double *vec, bool polyOnly) throw(INTERP_KERNEL::Exception) { @@ -5300,9 +5930,17 @@ void MEDCouplingUMesh::orientCorrectly2DCells(const double *vec, bool polyOnly) } /*! - * This method checks that all polyhedrons cells have correctly oriented faces. - * If not, 'cells' parameter will be appended with cellIds of incorrect cells. - * @throw when 'this' is not a mesh with meshdim==3 and spacedim==3 + * Finds incorrectly oriented polyhedral cells, i.e. polyhedrons having correctly + * oriented facets. The normal vector of the facet should point out of the cell. + * \param [in,out] cells - a vector returning ids of incorrectly oriented cells. It + * is not cleared before filling in. + * \throw If \a this->getMeshDimension() != 3. + * \throw If \a this->getSpaceDimension() != 3. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * + * \ref cpp_mcumesh_arePolyhedronsNotCorrectlyOriented "Here is a C++ example".
+ * \ref py_mcumesh_arePolyhedronsNotCorrectlyOriented "Here is a Python example". */ void MEDCouplingUMesh::arePolyhedronsNotCorrectlyOriented(std::vector& cells) const throw(INTERP_KERNEL::Exception) { @@ -5324,9 +5962,16 @@ void MEDCouplingUMesh::arePolyhedronsNotCorrectlyOriented(std::vector& cell } /*! - * This method tries to orient correctly polhedrons cells. - * - * \throw when 'this' is not a mesh with meshdim==3 and spacedim==3. An exception is also thrown when the attempt of reparation fails. + * Tries to fix connectivity of polyhedra, so that normal vector of all facets to point + * out of the cell. + * \throw If \a this->getMeshDimension() != 3. + * \throw If \a this->getSpaceDimension() != 3. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * \throw If the reparation fails. + * + * \ref cpp_mcumesh_arePolyhedronsNotCorrectlyOriented "Here is a C++ example".
+ * \ref py_mcumesh_arePolyhedronsNotCorrectlyOriented "Here is a Python example". * \sa MEDCouplingUMesh::findAndCorrectBadOriented3DCells */ void MEDCouplingUMesh::orientCorrectlyPolyhedrons() throw(INTERP_KERNEL::Exception) @@ -5358,12 +6003,20 @@ void MEDCouplingUMesh::orientCorrectlyPolyhedrons() throw(INTERP_KERNEL::Excepti } /*! - * This method is expected to be applied on a mesh with spaceDim==3 and meshDim==3. If not an exception will be thrown. - * This method analyzes only linear extruded 3D cells (NORM_HEXA8,NORM_PENTA6,NORM_HEXGP12...) - * If some extruded cells does not fulfill the MED norm for extruded cells (first face of 3D cell should be oriented to the exterior of the 3D cell). - * Some viewers are very careful of that (SMESH), but ParaVis ignore that. + * Finds and fixes incorrectly oriented linear extruded volumes (INTERP_KERNEL::NORM_HEXA8, + * INTERP_KERNEL::NORM_PENTA6, INTERP_KERNEL::NORM_HEXGP12 etc) to respect the MED convention + * according to which the first facet of the cell should be oriented to have the normal vector + * pointing out of cell. + * \return DataArrayInt * - a new instance of DataArrayInt holding ids of fixed + * cells. The caller is to delete this array using decrRef() as it is no more + * needed. + * \throw If \a this->getMeshDimension() != 3. + * \throw If \a this->getSpaceDimension() != 3. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. * - * \ret a newly allocated int array with one components containing cell ids renumbered to fit the convention of MED (MED file and MEDCoupling) + * \ref cpp_mcumesh_findAndCorrectBadOriented3DExtrudedCells "Here is a C++ example".
+ * \ref py_mcumesh_findAndCorrectBadOriented3DExtrudedCells "Here is a Python example". * \sa MEDCouplingUMesh::findAndCorrectBadOriented3DCells */ DataArrayInt *MEDCouplingUMesh::findAndCorrectBadOriented3DExtrudedCells() throw(INTERP_KERNEL::Exception) @@ -5482,10 +6135,27 @@ void MEDCouplingUMesh::getFastAveragePlaneOfThis(double *vec, double *pos) const } /*! - * The returned newly created field has to be managed by the caller. - * This method returns a field on cell with no time lying on 'this'. The meshdimension and spacedimension of this are expected to be both in [2,3]. If not an exception will be thrown. - * This method for the moment only deals with NORM_TRI3, NORM_QUAD4 and NORM_TETRA4 geometric types. - * If a cell has an another type an exception will be thrown. + * Creates a new MEDCouplingFieldDouble holding Edge Ratio values of all + * cells. Currently cells of the following types are treated: + * INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4 and INTERP_KERNEL::NORM_TETRA4. + * For a cell of other type an exception is thrown. + * Space dimension of a 2D mesh can be either 2 or 3. + * The Edge Ratio of a cell \f$t\f$ is: + * \f$\frac{|t|_\infty}{|t|_0}\f$, + * where \f$|t|_\infty\f$ and \f$|t|_0\f$ respectively denote the greatest and + * the smallest edge lengths of \f$t\f$. + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble on + * cells and one time, lying on \a this mesh. The caller is to delete this + * field using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * \throw If \a this mesh contains elements of dimension different from the mesh dimension. + * \throw If the connectivity data array has more than one component. + * \throw If the connectivity data array has a named component. + * \throw If the connectivity index data array has more than one component. + * \throw If the connectivity index data array has a named component. + * \throw If \a this->getMeshDimension() is neither 2 nor 3. + * \throw If \a this->getSpaceDimension() is neither 2 nor 3. + * \throw If \a this mesh includes cells of type different from the ones enumerated above. */ MEDCouplingFieldDouble *MEDCouplingUMesh::getEdgeRatioField() const throw(INTERP_KERNEL::Exception) { @@ -5541,10 +6211,23 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::getEdgeRatioField() const throw(INTERP } /*! - * The returned newly created field has to be managed by the caller. - * This method returns a field on cell with no time lying on 'this'. The meshdimension and spacedimension of this are expected to be both in [2,3]. If not an exception will be thrown. - * This method for the moment only deals with NORM_TRI3, NORM_QUAD4 and NORM_TETRA4 geometric types. - * If a cell has an another type an exception will be thrown. + * Creates a new MEDCouplingFieldDouble holding Aspect Ratio values of all + * cells. Currently cells of the following types are treated: + * INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4 and INTERP_KERNEL::NORM_TETRA4. + * For a cell of other type an exception is thrown. + * Space dimension of a 2D mesh can be either 2 or 3. + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble on + * cells and one time, lying on \a this mesh. The caller is to delete this + * field using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * \throw If \a this mesh contains elements of dimension different from the mesh dimension. + * \throw If the connectivity data array has more than one component. + * \throw If the connectivity data array has a named component. + * \throw If the connectivity index data array has more than one component. + * \throw If the connectivity index data array has a named component. + * \throw If \a this->getMeshDimension() is neither 2 nor 3. + * \throw If \a this->getSpaceDimension() is neither 2 nor 3. + * \throw If \a this mesh includes cells of type different from the ones enumerated above. */ MEDCouplingFieldDouble *MEDCouplingUMesh::getAspectRatioField() const throw(INTERP_KERNEL::Exception) { @@ -5600,10 +6283,22 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::getAspectRatioField() const throw(INTE } /*! - * The returned newly created field has to be managed by the caller. - * This method returns a field on cell with no time lying on 'this'. The meshdimension must be equal to 2 and the spacedimension must be equal to 3. If not an exception will be thrown. - * This method for the moment only deals with NORM_QUAD4 geometric type. - * If a cell has an another type an exception will be thrown. + * Creates a new MEDCouplingFieldDouble holding Warping factor values of all + * cells of \a this 2D mesh in 3D space. Currently cells of the following types are + * treated: INTERP_KERNEL::NORM_QUAD4. + * For a cell of other type an exception is thrown. + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble on + * cells and one time, lying on \a this mesh. The caller is to delete this + * field using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * \throw If \a this mesh contains elements of dimension different from the mesh dimension. + * \throw If the connectivity data array has more than one component. + * \throw If the connectivity data array has a named component. + * \throw If the connectivity index data array has more than one component. + * \throw If the connectivity index data array has a named component. + * \throw If \a this->getMeshDimension() != 2. + * \throw If \a this->getSpaceDimension() != 3. + * \throw If \a this mesh includes cells of type different from the ones enumerated above. */ MEDCouplingFieldDouble *MEDCouplingUMesh::getWarpField() const throw(INTERP_KERNEL::Exception) { @@ -5646,11 +6341,24 @@ MEDCouplingFieldDouble *MEDCouplingUMesh::getWarpField() const throw(INTERP_KERN return ret.retn(); } + /*! - * The returned newly created field has to be managed by the caller. - * This method returns a field on cell with no time lying on 'this'. The meshdimension must be equal to 2 and the spacedimension must be equal to 3. If not an exception will be thrown. - * This method for the moment only deals with NORM_QUAD4 geometric type. - * If a cell has an another type an exception will be thrown. + * Creates a new MEDCouplingFieldDouble holding Skew factor values of all + * cells of \a this 2D mesh in 3D space. Currently cells of the following types are + * treated: INTERP_KERNEL::NORM_QUAD4. + * For a cell of other type an exception is thrown. + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble on + * cells and one time, lying on \a this mesh. The caller is to delete this + * field using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * \throw If \a this mesh contains elements of dimension different from the mesh dimension. + * \throw If the connectivity data array has more than one component. + * \throw If the connectivity data array has a named component. + * \throw If the connectivity index data array has more than one component. + * \throw If the connectivity index data array has a named component. + * \throw If \a this->getMeshDimension() != 2. + * \throw If \a this->getSpaceDimension() != 3. + * \throw If \a this mesh includes cells of type different from the ones enumerated above. */ MEDCouplingFieldDouble *MEDCouplingUMesh::getSkewField() const throw(INTERP_KERNEL::Exception) { @@ -5989,10 +6697,12 @@ MEDCouplingUMesh *MEDCouplingUMesh::emulateMEDMEMBDC(const MEDCouplingUMesh *nM1 } /*! - * This method sorts cell in this so that cells are sorted by cell type specified by MEDMEM and so for MED file. - * It avoids to deal with renum in MEDLoader so it is useful for MED file R/W with multi types. - * This method returns a newly allocated array old2New. - * This method expects that connectivity of this is set. If not an exception will be thrown. Coordinates are not taken into account. + * Permutes the nodal connectivity arrays so that the cells are sorted by type, which is + * necessary for writing the mesh to MED file. Additionally returns a permutation array + * in "Old to New" mode. + * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete + * this array using decrRef() as it is no more needed. + * \throw If the nodal connectivity of cells is not defined. */ DataArrayInt *MEDCouplingUMesh::sortCellsInMEDFileFrmt() throw(INTERP_KERNEL::Exception) { @@ -6384,13 +7094,16 @@ MEDCouplingMesh *MEDCouplingUMesh::mergeMyselfWith(const MEDCouplingMesh *other) } /*! - * This method is ** very badly named ** : This method computes the center of inertia of each cells in \a this. - * So this method is not a right choice for degnerated meshes (not well oriented, cells with measure close to zero). - * - * \return a newly allocated DataArrayDouble instance that the caller has to deal with. The returned - * DataArrayDouble instance will have \c this->getNumberOfCells() tuples and \c this->getSpaceDimension() components. - * - * \sa MEDCouplingUMesh::computeIsoBarycenterOfNodesPerCell + * Returns a new DataArrayDouble holding barycenters of all cells. The barycenter is + * computed by averaging coordinates of cell nodes, so this method is not a right + * choice for degnerated meshes (not well oriented, cells with measure close to zero). + * \return DataArrayDouble * - a new instance of DataArrayDouble, of size \a + * this->getNumberOfCells() tuples per \a this->getSpaceDimension() + * components. The caller is to delete this array using decrRef() as it is + * no more needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * \sa MEDCouplingUMesh::computeIsoBarycenterOfNodesPerCell */ DataArrayDouble *MEDCouplingUMesh::getBarycenterAndOwner() const { @@ -6487,9 +7200,21 @@ DataArrayDouble *MEDCouplingUMesh::computeIsoBarycenterOfNodesPerCell() const th } /*! - * This method is similar to MEDCouplingUMesh::getBarycenterAndOwner except that it works on subPart of 'this' without - * building explicitely it. The input part is defined by an array [begin,end). All ids contained in this array should be less than this->getNumberOfCells(). - * No check of that will be done ! + * Returns a new DataArrayDouble holding barycenters of specified cells. The + * barycenter is computed by averaging coordinates of cell nodes. The cells to treat + * are specified via an array of cell ids. + * \warning Validity of the specified cell ids is not checked! + * Valid range is [ 0, \a this->getNumberOfCells() ). + * \param [in] begin - an array of cell ids of interest. + * \param [in] end - the end of \a begin, i.e. a pointer to its (last+1)-th element. + * \return DataArrayDouble * - a new instance of DataArrayDouble, of size ( \a + * end - \a begin ) tuples per \a this->getSpaceDimension() components. The + * caller is to delete this array using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * + * \ref cpp_mcumesh_getPartBarycenterAndOwner "Here is a C++ example".
+ * \ref py_mcumesh_getPartBarycenterAndOwner "Here is a Python example". */ DataArrayDouble *MEDCouplingUMesh::getPartBarycenterAndOwner(const int *begin, const int *end) const { @@ -6540,10 +7265,19 @@ MEDCouplingUMesh *MEDCouplingUMesh::Build0DMeshFromCoords(DataArrayDouble *da) t ret->setConnectivity(c,cI,true); return ret.retn(); } - /*! - * Returns a newly created mesh (with ref count ==1) that contains merge of 'mesh1' and 'other'. - * The coords of 'mesh2' are added at the end of coords of 'mesh1'. + * Creates a new MEDCouplingUMesh by concatenating two given meshes of the same dimension. + * Cells and nodes of + * the first mesh precede cells and nodes of the second mesh within the result mesh. + * \param [in] mesh1 - the first mesh. + * \param [in] mesh2 - the second mesh. + * \return MEDCouplingUMesh * - the result mesh. It is a new instance of + * MEDCouplingUMesh. The caller is to delete this mesh using decrRef() as it + * is no more needed. + * \throw If \a mesh1 == NULL or \a mesh2 == NULL. + * \throw If the coordinates array is not set in none of the meshes. + * \throw If \a mesh1->getMeshDimension() < 0 or \a mesh2->getMeshDimension() < 0. + * \throw If \a mesh1->getMeshDimension() != \a mesh2->getMeshDimension(). */ MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception) { @@ -6553,11 +7287,19 @@ MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshes(const MEDCouplingUMesh *mesh1, } /*! - * This method returns in case of success a mesh constitued from union of all meshes in 'a'. - * There should be \b no presence of null pointer into 'a'. If any an INTERP_KERNEL::Exception will be thrown. - * The returned mesh will contain aggregation of nodes in 'a' (in the same order) and aggregation of - * cells in meshes in 'a' (in the same order too). - */ + * Creates a new MEDCouplingUMesh by concatenating all given meshes of the same dimension. + * Cells and nodes of + * the *i*-th mesh precede cells and nodes of the (*i*+1)-th mesh within the result mesh. + * \param [in] a - a vector of meshes (MEDCouplingUMesh) to concatenate. + * \return MEDCouplingUMesh * - the result mesh. It is a new instance of + * MEDCouplingUMesh. The caller is to delete this mesh using decrRef() as it + * is no more needed. + * \throw If \a a.size() == 0. + * \throw If \a a[ *i* ] == NULL. + * \throw If the coordinates array is not set in none of the meshes. + * \throw If \a a[ *i* ]->getMeshDimension() < 0. + * \throw If the meshes in \a a are of different dimension (getMeshDimension()). +*/ MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshes(std::vector& a) throw(INTERP_KERNEL::Exception) { std::size_t sz=a.size(); @@ -6649,8 +7391,19 @@ MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshesLL(std::vectorgetMeshDimension() < 0 or \a mesh2->getMeshDimension() < 0. + * \throw If \a mesh1->getMeshDimension() != \a mesh2->getMeshDimension(). */ MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshesOnSameCoords(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception) { @@ -6660,8 +7413,19 @@ MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshesOnSameCoords(const MEDCouplingUM } /*! - * Idem MergeUMeshes except that 'meshes' are expected to lyie on the same coords and 'meshes' have the same meshdim. - * 'meshes' must be a non empty vector. + * Creates a new MEDCouplingUMesh by concatenating cells of all given meshes of same + * dimension and sharing the node coordinates array. + * All cells of the *i*-th mesh precede all cells of the + * (*i*+1)-th mesh within the result mesh. + * \param [in] a - a vector of meshes (MEDCouplingUMesh) to concatenate. + * \return MEDCouplingUMesh * - the result mesh. It is a new instance of + * MEDCouplingUMesh. The caller is to delete this mesh using decrRef() as it + * is no more needed. + * \throw If \a a.size() == 0. + * \throw If \a a[ *i* ] == NULL. + * \throw If the meshes do not share the node coordinates array. + * \throw If \a a[ *i* ]->getMeshDimension() < 0. + * \throw If the meshes in \a a are of different dimension (getMeshDimension()). */ MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshesOnSameCoords(const std::vector& meshes) { @@ -6716,16 +7480,28 @@ MEDCouplingUMesh *MEDCouplingUMesh::MergeUMeshesOnSameCoords(const std::vectorgetMeshDimension() < 0. + * \throw If the \a meshes are of different dimension (getMeshDimension()). + * \throw If the nodal connectivity of cells of any of \a meshes is not defined. + * \throw If the nodal connectivity any of \a meshes includes an invalid id. */ MEDCouplingUMesh *MEDCouplingUMesh::FuseUMeshesOnSameCoords(const std::vector& meshes, int compType, std::vector& corr) { @@ -6750,16 +7526,17 @@ MEDCouplingUMesh *MEDCouplingUMesh::FuseUMeshesOnSameCoords(const std::vector& meshes) throw(INTERP_KERNEL::Exception) { @@ -6804,18 +7581,16 @@ void MEDCouplingUMesh::PutUMeshesOnSameAggregatedCoords(const std::vector& meshes, double eps) throw(INTERP_KERNEL::Exception) { @@ -7442,7 +8217,7 @@ void MEDCouplingUMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData void MEDCouplingUMesh::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception) { - stream << "MEDCouplingUMesh C++ instance at " << this << "."; + stream << "MEDCouplingUMesh C++ instance at " << this << ". Name : \"" << getName() << "\"."; if(_mesh_dim==-2) { stream << " Not set !"; return ; } stream << " Mesh dimension : " << _mesh_dim << "."; @@ -7470,8 +8245,29 @@ std::string MEDCouplingUMesh::getVTKDataSetType() const throw(INTERP_KERNEL::Exc return std::string("UnstructuredGrid"); } -/// @cond INTERNAL - +/*! + * Partitions the first given 2D mesh using the second given 2D mesh as a tool, and + * returns a result mesh constituted by polygons. The meshes should be in 2D space. In + * addition, returns two arrays mapping cells of the result mesh to cells of the input + * meshes. + * \param [in] m1 - the first input mesh which is a partitioned object. + * \param [in] m2 - the second input mesh which is a partition tool. + * \param [in] eps - precision used to detect coincident mesh entities. + * \param [out] cellNb1 - a new instance of DataArrayInt holding for each result + * cell an id of the cell of \a m1 it comes from. The caller is to delete + * this array using decrRef() as it is no more needed. + * \param [out] cellNb2 - a new instance of DataArrayInt holding for each result + * cell an id of the cell of \a m2 it comes from. -1 value means that a + * result cell comes from a cell (or part of cell) of \a m1 not overlapped by + * any cell of \a m2. The caller is to delete this array using decrRef() as + * it is no more needed. + * \return MEDCouplingUMesh * - the result 2D mesh which is a new instance of + * MEDCouplingUMesh. The caller is to delete this mesh using decrRef() as it + * is no more needed. + * \throw If the coordinates array is not set in any of the meshes. + * \throw If the nodal connectivity of cells is not defined in any of the meshes. + * \throw If any of the meshes is not a 2D mesh in 2D space. + */ MEDCouplingUMesh *MEDCouplingUMesh::Intersect2DMeshes(const MEDCouplingUMesh *m1, const MEDCouplingUMesh *m2, double eps, DataArrayInt *&cellNb1, DataArrayInt *&cellNb2) throw(INTERP_KERNEL::Exception) { m1->checkFullyDefined(); @@ -7517,8 +8313,6 @@ MEDCouplingUMesh *MEDCouplingUMesh::Intersect2DMeshes(const MEDCouplingUMesh *m1 return ret.retn(); } -/// @endcond - void MEDCouplingUMesh::BuildIntersecting2DCellsFromEdges(double eps, const MEDCouplingUMesh *m1, const int *desc1, const int *descIndx1, const std::vector >& intesctEdges1, const std::vector< std::vector >& colinear2, const MEDCouplingUMesh *m2, const int *desc2, const int *descIndx2, const std::vector >& intesctEdges2, diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index 93f44214b..75f0db4c0 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -55,7 +55,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void checkCoherency1(double eps=1e-12) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkCoherency2(double eps=1e-12) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setMeshDimension(int meshDim); - MEDCOUPLING_EXPORT void allocateCells(int nbOfCells); + MEDCOUPLING_EXPORT void allocateCells(int nbOfCells=0); MEDCOUPLING_EXPORT void insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, const int *nodalConnOfCell) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void finishInsertingCells(); MEDCOUPLING_EXPORT MEDCouplingUMeshCellIterator *cellIterator(); diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx index 8cc1e5dbb..4c6ef588f 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx @@ -536,5 +536,5 @@ DataArrayDouble *MEDCouplingUMeshDesc::computeIsoBarycenterOfNodesPerCell() cons void MEDCouplingUMeshDesc::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception) { - stream << "MEDCouplingUMeshDesc C++ instance at " << this << "."; + stream << "MEDCouplingUMeshDesc C++ instance at " << this << ". Name : \"" << getName() << "\"."; } diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx index 3a0f222ed..cba01a300 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx @@ -1635,17 +1635,15 @@ void MEDCouplingBasicsTest4::testConvertExtrudedPolyhedra1() CPPUNIT_ASSERT_EQUAL((std::size_t)10,dai->getNbOfElems()); CPPUNIT_ASSERT_EQUAL((std::size_t)159,da->getNbOfElems()); // - const int expected1[159]={14, 1, 2, 3, 4, - 18, 5, 6, 7, 8, 9, 10, 11, 12, - 14, 13, 14, 15, 16, - 31, 17, 18, 19, -1, 20, 22, 21, -1, 17, 18, 21, 20, -1, 18, 19, 22, 21, -1, 19, 17, 20, - 22, - 16, 23, 24, 25, 26, 27, 28, - 31, 29, 30, 31, 32, 33, -1, 34, 38, 37, 36, 35, -1, 29, 30, 35, 34, -1, 30, 31, 36, 35, -1, 31, 32, 37, 36, -1, 32, 33, 38, 37, - -1, 33, 29, 34, 38, - 18, 39, 40, 41, 42, 43, 44, 45, 46, - 22, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, - 31, 59, 60, 61, 62, 63, 64, 65, -1, 66, 72, 71, 70, 69, 68, 67, -1, 59, 60, 67, 66, -1, 60, 61, 68, 67, -1, 61, 62, 69, 68, -1, 62, 63, 70, 69, -1, 63, 64, 71, 70, -1, 64, 65, 72, 71, -1, 65, 59, 66, 72}; + const int expected1[159]={14,1,2,3,4, + 18,5,6,7,8,9,10,11,12, + 14,13,14,15,16, + 31,17,18,19,-1,20,22,21,-1,17,20,21,18,-1,18,21,22,19,-1,19,22,20,17, + 16,23,24,25,26,27,28, + 31,29,30,31,32,33,-1,34,38,37,36,35,-1,29,34,35,30,-1,30,35,36,31,-1,31,36,37,32,-1,32,37,38,33,-1,33,38,34,29, + 18,39,40,41,42,43,44,45,46, + 22,47,48,49,50,51,52,53,54,55,56,57,58, + 31,59,60,61,62,63,64,65,-1,66,72,71,70,69,68,67,-1,59,66,67,60,-1,60,67,68,61,-1,61,68,69,62,-1,62,69,70,63,-1,63,70,71,64,-1,64,71,72,65,-1,65,72,66,59}; const int expected2[10]={0,5,14,19,42,49,86,95,108,159}; CPPUNIT_ASSERT(std::equal(expected1,expected1+159,da->getConstPointer())); CPPUNIT_ASSERT(std::equal(expected2,expected2+10,dai->getConstPointer())); diff --git a/src/MEDCoupling/Test/MEDCouplingExamplesTest.cxx b/src/MEDCoupling/Test/MEDCouplingExamplesTest.cxx index e1960adda..3a1ed18a7 100644 --- a/src/MEDCoupling/Test/MEDCouplingExamplesTest.cxx +++ b/src/MEDCoupling/Test/MEDCouplingExamplesTest.cxx @@ -27,14 +27,1087 @@ #include "MEDCouplingMultiFields.hxx" +void CppExample_MEDCouplingPointSet_fillFromAnalytic3() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_1] + const double coords[4] = {0.,2.,4.,6.}; // 6. is not used + MEDCouplingAutoRefCountObjectPtr x = DataArrayDouble::New(); + x->useExternalArrayWithRWAccess( coords, 3, 1 ); + MEDCouplingAutoRefCountObjectPtr y = DataArrayDouble::New(); + y->useExternalArrayWithRWAccess( coords, 2, 1 ); + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingCMesh::New(); + mesh->setCoords(x,y); + //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_1] + //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_2] + const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10"; + const char* varNames[2] = { "a", "b" }; // names used to refer to X and Y coord components + std::vector varNamesVec( varNames, varNames+2 ); + MEDCouplingAutoRefCountObjectPtr field = + mesh->fillFromAnalytic3( ParaMEDMEM::ON_CELLS, 3, varNamesVec, func ); + //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_2] + //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_3] + double vals1[3]; // values of the cell #1 + CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components in the field + field->getArray()->getTuple( 1, vals1 ); + // + MEDCouplingAutoRefCountObjectPtr bc = + mesh->getBarycenterAndOwner(); // func is applied to barycenters of cells + double bc1[2]; // coordinates of the second point + bc->getTuple( 1, bc1 ); + // + double dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ); // "sqrt( a*a + b*b )" + CPPUNIT_ASSERT_DOUBLES_EQUAL( vals1[0], 10 + bc1[1], 13 ); // "10 + IVec * b" + CPPUNIT_ASSERT_DOUBLES_EQUAL( vals1[1], 10 + bc1[0], 13 ); // "10 + JVec * a" + CPPUNIT_ASSERT_DOUBLES_EQUAL( vals1[2], 10 + dist , 13 ); // "10 + KVec * sqrt( a*a + b*b )" + //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic3_3] +} + +void CppExample_MEDCouplingPointSet_fillFromAnalytic2() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_1] + const double coords[4] = {0.,2.,4.,6.}; // 6. is not used + MEDCouplingAutoRefCountObjectPtr x = DataArrayDouble::New(); + x->useExternalArrayWithRWAccess( coords, 3, 1 ); + MEDCouplingAutoRefCountObjectPtr y = DataArrayDouble::New(); + y->useExternalArrayWithRWAccess( coords, 2, 1 ); + x->setInfoOnComponent(0,"a"); // name used to refer to X coordinate within a function + y->setInfoOnComponent(0,"b"); // name used to refer to Y coordinate within a function + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingCMesh::New(); + mesh->setCoords(x,y); + //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_1] + //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_2] + const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10"; + MEDCouplingAutoRefCountObjectPtr field = + mesh->fillFromAnalytic2( ParaMEDMEM::ON_CELLS, 3, func ); + //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_2] + //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_3] + double vals1[3]; // values of the cell #1 + CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components in the field + field->getArray()->getTuple( 1, vals1 ); + // + MEDCouplingAutoRefCountObjectPtr bc = + mesh->getBarycenterAndOwner(); // func is applied to barycenters of cells + double bc1[2]; // coordinates of the second point + bc->getTuple( 1, bc1 ); + // + double dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ); // "sqrt( a*a + b*b )" + CPPUNIT_ASSERT_DOUBLES_EQUAL( vals1[0], 10 + bc1[1], 13 ); // "10 + IVec * b" + CPPUNIT_ASSERT_DOUBLES_EQUAL( vals1[1], 10 + bc1[0], 13 ); // "10 + JVec * a" + CPPUNIT_ASSERT_DOUBLES_EQUAL( vals1[2], 10 + dist , 13 ); // "10 + KVec * sqrt( a*a + b*b )" + //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic2_3] +} + +void CppExample_MEDCouplingPointSet_fillFromAnalytic() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_1] + const double coords[4] = {0.,2.,4.,6.}; // 6. is not used + MEDCouplingAutoRefCountObjectPtr x = DataArrayDouble::New(); + x->useExternalArrayWithRWAccess( coords, 3, 1 ); + MEDCouplingAutoRefCountObjectPtr y = DataArrayDouble::New(); + y->useExternalArrayWithRWAccess( coords, 2, 1 ); + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingCMesh::New(); + mesh->setCoords(x,y); + //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_1] + //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_2] + const char func[] = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10"; + MEDCouplingAutoRefCountObjectPtr field = + mesh->fillFromAnalytic( ParaMEDMEM::ON_CELLS, 3, func ); + //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_2] + //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_3] + double vals1[3]; // values of the cell #1 + CPPUNIT_ASSERT( field->getNumberOfComponents() == 3 ); // 3 components in the field + field->getArray()->getTuple( 1, vals1 ); + // + MEDCouplingAutoRefCountObjectPtr bc = + mesh->getBarycenterAndOwner(); // func is applied to barycenters of cells + double bc1[2]; // coordinates of the second point + bc->getTuple( 1, bc1 ); + // + double dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ); // "sqrt( a*a + b*b )" + CPPUNIT_ASSERT_DOUBLES_EQUAL( vals1[0], 10 + bc1[1], 13 ); // "10 + IVec * b" + CPPUNIT_ASSERT_DOUBLES_EQUAL( vals1[1], 10 + bc1[0], 13 ); // "10 + JVec * a" + CPPUNIT_ASSERT_DOUBLES_EQUAL( vals1[2], 10 + dist , 13 ); // "10 + KVec * sqrt( a*a + b*b )" + //! [CppSnippet_MEDCouplingMesh_fillFromAnalytic_3] +} + +void CppExample_MEDCouplingPointSet_getCoordsAt() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingCMesh_getCoordsAt_1] + const double coords[3] = {1.,2.,4.}; + MEDCouplingAutoRefCountObjectPtr x = DataArrayDouble::New(); + x->useExternalArrayWithRWAccess( coords, 3, 1 ); + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingCMesh::New(); + mesh->setCoordsAt(0,x); + const DataArrayDouble* x2=mesh->getCoordsAt(0); + CPPUNIT_ASSERT( x2->isEqual( *x, 1e-13 )); + //! [CppSnippet_MEDCouplingCMesh_getCoordsAt_1] +} + +void CppExample_MEDCouplingUMesh_areCellsIncludedIn() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_1] + MEDCouplingAutoRefCountObjectPtr mesh1=MEDCouplingUMesh::New(); + mesh1->setMeshDimension(2); + mesh1->allocateCells(5); + const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4}; + mesh1->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // #0 + mesh1->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // #1 + mesh1->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // #2 + mesh1->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // #3 + mesh1->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // #4 + mesh1->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh1->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_1] + //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_2] + const int cells2[3] = { 4,2,0 }; // even cells selected + MEDCouplingAutoRefCountObjectPtr mesh2 = + (MEDCouplingUMesh*) mesh1->buildPartOfMySelf( cells2, cells2+3, true ); + //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_2] + //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_3] + int compType = 0; // the strongest policy + DataArrayInt *corr2to1, *corr1to2; + // a larger mesh1 includes a smaller mesh2 + CPPUNIT_ASSERT( mesh1->areCellsIncludedIn( mesh2, compType, corr2to1 )); + CPPUNIT_ASSERT( std::equal( cells2, cells2+3, corr2to1->getConstPointer() )); + //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_3] + //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_4] + // the smaller mesh2 does NOT include the larger mesh1 + CPPUNIT_ASSERT( ! mesh2->areCellsIncludedIn( mesh1, compType, corr1to2 )); + const int corr1to2Expected[5] = {2, 3, 1, 4, 0}; + CPPUNIT_ASSERT(std::equal( corr1to2Expected, corr1to2Expected+5, corr1to2->getConstPointer() )); + //! [CppSnippet_MEDCouplingUMesh_areCellsIncludedIn_4] + corr2to1->decrRef(); + corr1to2->decrRef(); +} + +void CppExample_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_1] + // 2D coordinates of 5 base nodes + const double coords[5*2]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2 }; + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->useExternalArrayWithRWAccess( coords, 5, 2 ); + // coordinates of 5 top nodes + MEDCouplingAutoRefCountObjectPtr coordsArr2 = coordsArr->deepCpy(); + // 3D coordinates of base + top nodes + coordsArr = coordsArr-> changeNbOfComponents( 3, 0 ); + coordsArr2 = coordsArr2->changeNbOfComponents( 3, 1 ); + coordsArr = DataArrayDouble::Aggregate( coordsArr, coordsArr2 ); + // mesh + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setCoords(coordsArr); + mesh->setMeshDimension(3); + mesh->allocateCells(2); + // connectivity of reversed HEXA8 and PENTA6 + const int conn[8+6]={0,1,4,3, 5,6,9,8, 1,2,4, 6,7,9}; + mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8, 8,conn+0); + mesh->insertNextCell(INTERP_KERNEL::NORM_PENTA6,6,conn+8); + mesh->finishInsertingCells(); + //! [CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_1] + //! [CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_2] + MEDCouplingAutoRefCountObjectPtr fixedCells = + mesh->findAndCorrectBadOriented3DExtrudedCells(); + CPPUNIT_ASSERT( fixedCells->getNumberOfTuples() == 2 ); // 2 cells fixed + fixedCells = mesh->findAndCorrectBadOriented3DExtrudedCells(); + CPPUNIT_ASSERT( fixedCells->getNumberOfTuples() == 0 ); // no bad cells + //! [CppSnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_2] +} + +void CppExample_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_1] + // 2D coordinates of 5 base nodes + const double coords[5*2]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2 }; + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->useExternalArrayWithRWAccess( coords, 5, 2 ); + // coordinates of 5 top nodes + MEDCouplingAutoRefCountObjectPtr coordsArr2 = coordsArr->deepCpy(); + // 3D coordinates of base + top nodes + coordsArr = coordsArr-> changeNbOfComponents( 3, 0 ); + coordsArr2 = coordsArr2->changeNbOfComponents( 3, 1 ); + coordsArr = DataArrayDouble::Aggregate( coordsArr, coordsArr2 ); + // mesh + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setCoords(coordsArr); + mesh->setMeshDimension(3); + mesh->allocateCells(2); + // connectivity of a HEXA8 + a reversed PENTA6 + const int conn[8+6]={0,3,4,1, 5,8,9,6, 1,2,4, 6,7,9}; + mesh->insertNextCell(INTERP_KERNEL::NORM_POLYHED,8,conn); // "extruded" polyhedron + mesh->insertNextCell(INTERP_KERNEL::NORM_POLYHED,6,conn+8); + mesh->finishInsertingCells(); + // fix connectivity of NORM_POLYHED's + mesh->convertExtrudedPolyhedra(); + //! [CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_1] + //! [CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_2] + std::vector badCellIds; + mesh->arePolyhedronsNotCorrectlyOriented( badCellIds ); + CPPUNIT_ASSERT( badCellIds.size() == 1 ); // one polyhedron is KO + // fix invalid rolyherdons + mesh->orientCorrectlyPolyhedrons(); + // re-check orientation + badCellIds.clear(); // as badCellIds is not cleared by arePolyhedronsNotCorrectlyOriented() + mesh->arePolyhedronsNotCorrectlyOriented( badCellIds ); + CPPUNIT_ASSERT( badCellIds.size() == 0 ); // connectivity is OK + //! [CppSnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_2] +} + +void CppExample_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[18]={0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4 + mesh->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + mesh->changeSpaceDimension(3); + //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_1] + //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_2] + const double vec[3] = {0.,0.,-1.}; + std::vector badCellIds; + mesh->are2DCellsNotCorrectlyOriented( vec, false, badCellIds ); + CPPUNIT_ASSERT( badCellIds.size() == 1 ); // one cell is reversed + // fix orientation + mesh->orientCorrectly2DCells( vec, false ); + // re-check orientation + badCellIds.clear(); // as badCellIds is not cleared by are2DCellsNotCorrectlyOriented() + mesh->are2DCellsNotCorrectlyOriented( vec, false, badCellIds ); + CPPUNIT_ASSERT( badCellIds.size() == 0 ); // the orientation is OK + //! [CppSnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_2] +} + +void CppExample_MEDCouplingUMesh_getCellsContainingPoints() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4 + mesh->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_1] + //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_2] + const double pos[3*2] = { 10., 10, // point out of the mesh + 0.3, 0.3, // point located somewhere inside the mesh + coords[2], coords[3]}; // point at the node #1 + const double eps = 1e-4; // ball radius + std::vector cells, cellsIndex; + mesh->getCellsContainingPoints( pos, 3, eps, cells, cellsIndex ); + const int cellsExpected[3]={4, 0, 1}; + const int cellsIndexExpected[4]={0, 0, 1, 3}; + CPPUNIT_ASSERT(std::equal( cellsExpected, cellsExpected+3, &cells[0])); + CPPUNIT_ASSERT(std::equal( cellsIndexExpected, cellsIndexExpected+4, &cellsIndex[0])); + //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoints_2] +} + +void CppExample_MEDCouplingUMesh_getCellsContainingPoint() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4 + mesh->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_1] + //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_2] + const double* coords4 = coords + 4*2; // coordinates of the node #4 + const double eps = 1e-4; // ball radius + const double pos[2] = { coords4[0] + eps, coords4[1] - eps }; // ball center + std::vector cellIds; + mesh->getCellsContainingPoint( pos, eps, cellIds ); + CPPUNIT_ASSERT ( (int)cellIds.size() == mesh->getNumberOfCells() ); + //! [CppSnippet_MEDCouplingUMesh_getCellsContainingPoint_2] +} + +void CppExample_MEDCouplingUMesh_buildPartOrthogonalField() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4 + mesh->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_1] + //! [CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_2] + const int part[4] = {1,2,3,4}; // cell #0 is omitted + MEDCouplingAutoRefCountObjectPtr vecField= + mesh->buildPartOrthogonalField( part, part+4 ); + CPPUNIT_ASSERT ( vecField->getArray()->getNumberOfTuples() == 4 ); + CPPUNIT_ASSERT ( vecField->getArray()->getNumberOfComponents() == 3 ); + //! [CppSnippet_MEDCouplingUMesh_buildPartOrthogonalField_2] +} + +void CppExample_MEDCouplingUMesh_getPartMeasureField() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[18]={0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4 + mesh->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_1] + //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_2] + const bool isAbs = true; + const int part[4] = {1,2,3,4}; // cell #0 is omitted + MEDCouplingAutoRefCountObjectPtr areaArr= + mesh->getPartMeasureField( isAbs, part, part+4 ); + CPPUNIT_ASSERT( areaArr->getIJ(0,0) > 0 ); // orientation ignored + areaArr=mesh->getPartMeasureField( !isAbs, part, part+4 ); + CPPUNIT_ASSERT( areaArr->getIJ(0,0) < 0 ); // orientation considered + CPPUNIT_ASSERT ( areaArr->getNumberOfTuples() == 4 ); + //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_2] + //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_3] + const int cellIds[4] = {1,2,3,4}; // cell #0 is omitted + MEDCouplingAutoRefCountObjectPtr baryCenters= + mesh->getPartBarycenterAndOwner( cellIds, cellIds+4 ); + CPPUNIT_ASSERT( baryCenters->getNumberOfTuples() == 4 ); + CPPUNIT_ASSERT( baryCenters->getNumberOfComponents() == mesh->getSpaceDimension() ); + //! [CppSnippet_MEDCouplingUMesh_getPartMeasureField_3] +} + +void CppExample_MEDCouplingUMesh_getCellsInBoundingBox() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(1); + const double coords[3*2]={0.,0., 0.,1., 1.,1}; + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->useExternalArrayWithRWAccess(coords, 3,2); + mesh->setCoords(coordsArr); + mesh->allocateCells(1); + const int conn[3]={0,1,2}; + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn); + mesh->finishInsertingCells(); + //! [CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_1] + //! [CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_2] + const double bbox[] = {1., 1., 1.001,1.001}; // xMin, xMax, yMin, yMax + MEDCouplingAutoRefCountObjectPtr cellIdsArr = + mesh->getCellsInBoundingBox( bbox, 0.0 ); + CPPUNIT_ASSERT( cellIdsArr->getNumberOfTuples() == 0 ); + cellIdsArr = mesh->getCellsInBoundingBox( bbox, 0.1 ); + CPPUNIT_ASSERT( cellIdsArr->getNumberOfTuples() == 1 ); + //! [CppSnippet_MEDCouplingUMesh_getCellsInBoundingBox_2] +} + +void CppExample_MEDCouplingUMesh_renumberNodesInConn() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_renumberNodesInConn_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(1); + const int conn[4]={4,3,2,1}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); + mesh->finishInsertingCells(); + //! [CppSnippet_MEDCouplingUMesh_renumberNodesInConn_1] + //! [CppSnippet_MEDCouplingUMesh_renumberNodesInConn_2] + const int old2newIds[] = {-1,3,2,1,0}; + mesh->renumberNodesInConn( old2newIds ); + const int nodes0Expected[] = {0,1,2,3}; + std::vector nodes0; + mesh->getNodeIdsOfCell( 0, nodes0 ); + CPPUNIT_ASSERT(std::equal( nodes0Expected, nodes0Expected+4, &nodes0[0] )); + //! [CppSnippet_MEDCouplingUMesh_renumberNodesInConn_2] +} + +void CppExample_MEDCouplingUMesh_renumberNodes() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_renumberNodes_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + const double coords[4*2]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.3}; + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->useExternalArrayWithRWAccess(coords, 4,2); + mesh->setCoords(coordsArr); + mesh->allocateCells(0); + mesh->finishInsertingCells(); + //! [CppSnippet_MEDCouplingUMesh_renumberNodes_1] + //! [CppSnippet_MEDCouplingUMesh_renumberNodes_2] + const int newIds[] = { 2,1,0,-1 }; + mesh->renumberNodes(newIds, 3); + coordsArr = mesh->getCoordinatesAndOwner(); // get a shorten array + const double coordsExpected[3*2]={0.7,-0.3, 0.2,-0.3, -0.3,-0.3}; + MEDCouplingAutoRefCountObjectPtr coordsExpectedArr=DataArrayDouble::New(); + coordsExpectedArr->useExternalArrayWithRWAccess(coordsExpected, 3,2); + CPPUNIT_ASSERT( coordsExpectedArr->isEqual( *coordsArr, 1e-13 )); + //! [CppSnippet_MEDCouplingUMesh_renumberNodes_2] + //! [CppSnippet_MEDCouplingUMesh_renumberNodes_3] + coordsArr->useExternalArrayWithRWAccess(coords, 4,2); // restore old nodes + const int newIds2[] = { 2,1,0,2 }; + mesh->renumberNodes2(newIds2, 3); + coordsArr = mesh->getCoordinatesAndOwner(); // get a shorten array + const double coordsExpected2[3*2]={0.7,-0.3, 0.2,-0.3, -0.3, 0.0}; + MEDCouplingAutoRefCountObjectPtr coordsExpectedArr2=DataArrayDouble::New(); + coordsExpectedArr2->useExternalArrayWithRWAccess(coordsExpected2, 3,2); + CPPUNIT_ASSERT( coordsExpectedArr2->isEqual( *coordsArr, 1e-13 )); + //! [CppSnippet_MEDCouplingUMesh_renumberNodes_3] +} + +void CppExample_MEDCouplingUMesh_findBoundaryNodes() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_findBoundaryNodes_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4 + mesh->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_findBoundaryNodes_1] + //! [CppSnippet_MEDCouplingUMesh_findBoundaryNodes_2] + MEDCouplingAutoRefCountObjectPtr nodeIdsArr=mesh->findBoundaryNodes(); + CPPUNIT_ASSERT( nodeIdsArr->getNumberOfTuples() == mesh->getNumberOfNodes() - 1 ); + //! [CppSnippet_MEDCouplingUMesh_findBoundaryNodes_2] +} + +void CppExample_MEDCouplingUMesh_buildBoundaryMesh() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4 + mesh->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_1] + //! [CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_2] + MEDCouplingAutoRefCountObjectPtr mesh1=mesh->buildBoundaryMesh(true); + MEDCouplingAutoRefCountObjectPtr mesh2=mesh->buildBoundaryMesh(false); + CPPUNIT_ASSERT( coordsArr->isEqual( *mesh1->getCoords(), 1e-13 )); // same nodes + CPPUNIT_ASSERT( !coordsArr->isEqual( *mesh2->getCoords(), 1e-13 )); // different nodes + //! [CppSnippet_MEDCouplingUMesh_buildBoundaryMesh_2] +} + +void CppExample_MEDCouplingUMesh_buildFacePartOfMySelfNode() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4 + mesh->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_1] + //! [CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_2] + std::vector nodes; + mesh->getNodeIdsOfCell( 0, nodes ); + const bool allNodes = true; + MEDCouplingAutoRefCountObjectPtr mesh1 = + (MEDCouplingUMesh*)mesh->buildFacePartOfMySelfNode( &nodes[0],&nodes[0]+nodes.size(),allNodes); + CPPUNIT_ASSERT( mesh1->getNumberOfCells() == 4 ); // 4 segments bounding QUAD4 #0 only + MEDCouplingAutoRefCountObjectPtr mesh2 = + (MEDCouplingUMesh*)mesh->buildFacePartOfMySelfNode( &nodes[0],&nodes[0]+nodes.size(),!allNodes); + CPPUNIT_ASSERT( mesh2->getNumberOfCells() == 9 ); // more segments added + //! [CppSnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_2] +} + +void CppExample_MEDCouplingUMesh_buildPartOfMySelfNode() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4 + mesh->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_1] + //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_2] + std::vector nodes; + mesh->getNodeIdsOfCell( 0, nodes ); + const bool allNodes = true; + MEDCouplingAutoRefCountObjectPtr mesh1 = + (MEDCouplingUMesh*)mesh->buildPartOfMySelfNode( &nodes[0], &nodes[0]+nodes.size(), allNodes); + MEDCouplingAutoRefCountObjectPtr mesh2 = + (MEDCouplingUMesh*)mesh->buildPartOfMySelfNode( &nodes[0], &nodes[0]+nodes.size(),!allNodes); + CPPUNIT_ASSERT_EQUAL( mesh1->getNumberOfCells(), 1 ); + CPPUNIT_ASSERT_EQUAL( mesh2->getNumberOfCells(), mesh->getNumberOfCells() ); + //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelfNode_2] +} + +void CppExample_MEDCouplingUMesh_getCellIdsLyingOnNodes() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4 + mesh->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_1] + //! [CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_2] + std::vector nodes; + mesh->getNodeIdsOfCell( 0, nodes ); + const bool allNodes = true; + DataArrayInt* cellIdsArr1 = mesh->getCellIdsLyingOnNodes( &nodes[0], &nodes[0]+nodes.size(), allNodes); + DataArrayInt* cellIdsArr2 = mesh->getCellIdsLyingOnNodes( &nodes[0], &nodes[0]+nodes.size(),!allNodes); + CPPUNIT_ASSERT_EQUAL( cellIdsArr1->getNumberOfTuples(), 1 ); + CPPUNIT_ASSERT_EQUAL( cellIdsArr2->getNumberOfTuples(), mesh->getNumberOfCells() ); + //! [CppSnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_2] + cellIdsArr1->decrRef(); + cellIdsArr2->decrRef(); +} + +void CppExample_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4 + mesh->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_1] + //! [CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_2] + const int cellIds[2]={1,2}; + std::vector nodes; + mesh->getNodeIdsOfCell( cellIds[0], nodes ); + mesh->getNodeIdsOfCell( cellIds[1], nodes ); + DataArrayInt* cellIdsArr = mesh->getCellIdsFullyIncludedInNodeIds( &nodes[0], &nodes[0]+nodes.size()); + CPPUNIT_ASSERT(std::equal( cellIds, cellIds+2, cellIdsArr->getPointer() )); + //! [CppSnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_2] + cellIdsArr->decrRef(); +} + +void CppExample_MEDCouplingUMesh_buildPartOfMySelf() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4 + mesh->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_1] + //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_2] + const int cellIds[2]={1,2}; + MEDCouplingUMesh* mesh2=(MEDCouplingUMesh*)mesh->buildPartOfMySelf(cellIds,cellIds+2,true); + MEDCouplingUMesh* mesh3=(MEDCouplingUMesh*)mesh->buildPartOfMySelf(cellIds,cellIds+2,false); + CPPUNIT_ASSERT( coordsArr->isEqual( *mesh2->getCoords(), 1e-13 )); // same nodes + CPPUNIT_ASSERT( !coordsArr->isEqual( *mesh3->getCoords(), 1e-13 )); // different nodes + for ( int i = 0; i < 2; ++i ) + { + std::vector nodes1, nodes2; + mesh ->getNodeIdsOfCell(cellIds[i], nodes1); + mesh2->getNodeIdsOfCell(i, nodes2); + CPPUNIT_ASSERT( nodes1 == nodes2 ); // cell #cellIds[i] was copied + } + //! [CppSnippet_MEDCouplingUMesh_buildPartOfMySelf_2] + mesh2->decrRef(); + mesh3->decrRef(); +} + +void CppExample_MEDCouplingUMesh_mergeNodes() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_mergeNodes_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[18]={0,3,4,1, 1,4,2, 4,5,2}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); + mesh->finishInsertingCells(); + const double coords[6*2]={0.3,-0.301, // #0 + 0.2,-0.3, // #1 + 0.3,-0.302, // #2 ~~ #0 + 1.1,0.0, // #3 + 1.1,0.0, // #4 == #3 + 0.3,-0.303}; // #5 ~~ #0 + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(6,2); + std::copy(coords,coords+6*2,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_mergeNodes_1] + //! [CppSnippet_MEDCouplingUMesh_mergeNodes_2] + bool areNodesMerged; int newNbOfNodes; + MEDCouplingAutoRefCountObjectPtr arr= + mesh->mergeNodes(0.004,areNodesMerged,newNbOfNodes); + const int idsExpected[6] = {0, 1, 0, 2, 2, 0}; + CPPUNIT_ASSERT(std::equal(idsExpected,idsExpected+6,arr->getPointer())); + CPPUNIT_ASSERT( areNodesMerged ); + CPPUNIT_ASSERT_EQUAL( 3, newNbOfNodes ); + //! [CppSnippet_MEDCouplingUMesh_mergeNodes_2] + //! [CppSnippet_MEDCouplingUMesh_mergeNodes_3] + const double* baryCoords2 = coords + 2*2; // initial coordinates of node #2 + coordsArr=mesh->getCoordinatesAndOwner(); // retrieve a new shorten coord array + CPPUNIT_ASSERT( fabs( baryCoords2[1] - coordsArr->getIJ(0,1)) > 1e-4 ); // Y of node #0 differs from that of baryCoords2 + // restore coordinates + coordsArr->alloc(6,2); + std::copy(coords,coords+6*2,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + // call mergeNodes2() + arr = mesh->mergeNodes2(0.004,areNodesMerged,newNbOfNodes); + coordsArr=mesh->getCoordinatesAndOwner(); // retrieve a new shorten coord array + CPPUNIT_ASSERT_DOUBLES_EQUAL( baryCoords2[1], coordsArr->getIJ(0,1), 13 ); // Y of node #0 equals to that of baryCoords2 + //! [CppSnippet_MEDCouplingUMesh_mergeNodes_3] +} + +void CppExample_MEDCouplingUMesh_zipConnectivityTraducer() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[11]={0,3,4,1, 1,4,2, 4,1,0,3}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+0); // 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 2 == 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+0); // 3 == 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+7); // 4 ~~ 0 + mesh->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_1] + //! [CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_2] + const int oldNbCells = mesh->getNumberOfCells(); + DataArrayInt *arr = mesh->zipConnectivityTraducer(0); + CPPUNIT_ASSERT_EQUAL( oldNbCells-2, mesh->getNumberOfCells() ); + const int idsExpected[5] = {0, 1, 1, 0, 2}; + CPPUNIT_ASSERT(std::equal(idsExpected,idsExpected+5,arr->getPointer())); + //! [CppSnippet_MEDCouplingUMesh_zipConnectivityTraducer_2] + arr->decrRef(); +} + +void CppExample_MEDCouplingUMesh_zipCoordsTraducer() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4 + mesh->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_1] + //! [CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_2] + const int cellIds[2]={1,2}; + MEDCouplingUMesh* mesh2=(MEDCouplingUMesh*)mesh->buildPartOfMySelf(cellIds,cellIds+2,true); + DataArrayInt *arr=mesh2->zipCoordsTraducer(); + CPPUNIT_ASSERT_EQUAL( 4, mesh2->getNumberOfNodes() ); // nb of nodes decreased + CPPUNIT_ASSERT_EQUAL( mesh->getNumberOfNodes(), arr->getNumberOfTuples() ); + const int idsExpected[9] = {-1,0,1,-1,2,3,-1,-1,-1}; // -1 for unused nodes + CPPUNIT_ASSERT(std::equal(idsExpected,idsExpected+9,arr->getPointer())); + //! [CppSnippet_MEDCouplingUMesh_zipCoordsTraducer_2] + mesh2->decrRef(); + arr->decrRef(); +} + +void CppExample_MEDCouplingUMesh_getNodeIdsInUse() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4 + mesh->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_1] + //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_2] + const int cellIds[2]={1,2}; + MEDCouplingUMesh* mesh2=(MEDCouplingUMesh*)mesh->buildPartOfMySelf(cellIds,cellIds+2,true); + int newNbOfNodes = 0; + DataArrayInt *arr=mesh2->getNodeIdsInUse( newNbOfNodes ); + const int idsExpected[9] = {-1,0,1,-1,2,3,-1,-1,-1}; + CPPUNIT_ASSERT(std::equal(idsExpected,idsExpected+9,arr->getPointer())); + //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_2] + //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_3] + DataArrayInt *arr2=arr->invertArrayO2N2N2O(newNbOfNodes); + const int idsExpected2[4] = {1,2,4,5}; + CPPUNIT_ASSERT(std::equal(idsExpected2,idsExpected2+4,arr2->getPointer())); + //! [CppSnippet_MEDCouplingUMesh_getNodeIdsInUse_3] + mesh2->decrRef(); + arr->decrRef(); + arr2->decrRef(); +} + +void CppExample_MEDCouplingUMesh_convertToPolyTypes() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_convertToPolyTypes_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4 + mesh->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_convertToPolyTypes_1] + //! [CppSnippet_MEDCouplingUMesh_convertToPolyTypes_2] + const int cells[2]={1,3}; + mesh->convertToPolyTypes(cells, cells+2); + CPPUNIT_ASSERT( mesh->getTypeOfCell(0) == INTERP_KERNEL::NORM_QUAD4 ); + CPPUNIT_ASSERT( mesh->getTypeOfCell(1) == INTERP_KERNEL::NORM_POLYGON ); + CPPUNIT_ASSERT( mesh->getTypeOfCell(2) == INTERP_KERNEL::NORM_TRI3 ); + CPPUNIT_ASSERT( mesh->getTypeOfCell(3) == INTERP_KERNEL::NORM_POLYGON ); + //! [CppSnippet_MEDCouplingUMesh_convertToPolyTypes_2] +} + +void CppExample_MEDCouplingUMesh_buildDescendingConnectivity2() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4 + mesh->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_1] + //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_2] + DataArrayInt *desc =DataArrayInt::New(); + DataArrayInt *descIndx =DataArrayInt::New(); + DataArrayInt *revDesc =DataArrayInt::New(); + DataArrayInt *revDescIndx=DataArrayInt::New(); + MEDCouplingUMesh * mesh2 = mesh->buildDescendingConnectivity2(desc,descIndx,revDesc,revDescIndx); + const int descExpected[] = {1,2,3,4,-3,5,6,7,8,-5,9,10,-2,11,12,13,-7,-10}; + const int descIndxExpected[] = {0,4,7,10,14,18}; + const int revDescExpected[] = {0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4}; + const int revDescIndxExpected[] = {0,1,3,5,6,8,9,11,12,13,15,16,17,18}; + CPPUNIT_ASSERT(std::equal(descExpected,descExpected+18,desc->getPointer())); + CPPUNIT_ASSERT(std::equal(descIndxExpected,descIndxExpected+6,descIndx->getPointer())); + CPPUNIT_ASSERT(std::equal(revDescExpected,revDescExpected+18,revDesc->getPointer())); + CPPUNIT_ASSERT(std::equal(revDescIndxExpected,revDescIndxExpected+14,revDescIndx->getPointer())); + //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_2] + //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_3] + const int cell2ConnExpect[] = {4,1}; + std::vector cell2Conn; + mesh2->getNodeIdsOfCell( 3-1, cell2Conn ); // cell #3 in FORTRAN mode + CPPUNIT_ASSERT(std::equal(cell2ConnExpect,cell2ConnExpect+2,&cell2Conn[0])); + //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity2_3] + desc->decrRef(); + descIndx->decrRef(); + revDesc->decrRef(); + revDescIndx->decrRef(); + mesh2->decrRef(); +} + +void CppExample_MEDCouplingUMesh_buildDescendingConnectivity() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4 + mesh->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_1] + //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_2] + DataArrayInt *desc =DataArrayInt::New(); + DataArrayInt *descIndx =DataArrayInt::New(); + DataArrayInt *revDesc =DataArrayInt::New(); + DataArrayInt *revDescIndx=DataArrayInt::New(); + MEDCouplingUMesh * mesh2 = mesh->buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx); + const int descExpected[] = {0,1,2,3, 2,4,5, 6,7,4, 8,9,1,10, 11,12,6,9}; + const int descIndxExpected[] = {0,4,7,10,14,18}; + const int revDescExpected[] = {0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4}; + const int revDescIndxExpected[] = {0,1,3,5,6,8,9,11,12,13,15,16,17,18}; + CPPUNIT_ASSERT(std::equal(descExpected,descExpected+18,desc->getPointer())); + CPPUNIT_ASSERT(std::equal(descIndxExpected,descIndxExpected+6,descIndx->getPointer())); + CPPUNIT_ASSERT(std::equal(revDescExpected,revDescExpected+18,revDesc->getPointer())); + CPPUNIT_ASSERT(std::equal(revDescIndxExpected,revDescIndxExpected+14,revDescIndx->getPointer())); + //! [CppSnippet_MEDCouplingUMesh_buildDescendingConnectivity_2] + desc->decrRef(); + descIndx->decrRef(); + revDesc->decrRef(); + revDescIndx->decrRef(); + mesh2->decrRef(); +} + +void CppExample_MEDCouplingUMesh_getReverseNodalConnectivity() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_1] + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); + mesh->setMeshDimension(2); + mesh->allocateCells(5); + const int conn[18]={0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4}; + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); // 0 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+4); // 1 + mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+7); // 2 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+10); // 3 + mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+14); // 4 + mesh->finishInsertingCells(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->alloc(9,2); + const double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 }; + std::copy(coords,coords+18,coordsArr->getPointer()); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_1] + //! [CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_2] + DataArrayInt *revNodal=DataArrayInt::New(); + DataArrayInt *revNodalIndx=DataArrayInt::New(); + mesh->getReverseNodalConnectivity(revNodal,revNodalIndx); + const int revNodalExpected[18]={0,0,1,1,2,0,3,0,1,2,3,4,2,4,3,3,4,4}; + const int revNodalIndexExpected[10]={0,1,3,5,7,12,14,15,17,18}; + CPPUNIT_ASSERT(std::equal(revNodalExpected,revNodalExpected+18,revNodal->getPointer())); + CPPUNIT_ASSERT(std::equal(revNodalIndexExpected,revNodalIndexExpected+10,revNodalIndx->getPointer())); + //! [CppSnippet_MEDCouplingUMesh_getReverseNodalConnectivity_2] + revNodal->decrRef(); + revNodalIndx->decrRef(); +} + +void CppExample_MEDCouplingUMesh_checkDeepEquivalWith() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_1] + // mesh 1 + MEDCouplingUMesh *mesh1=MEDCouplingUMesh::New(); + const double coords[4*2]={0.0,0.0, // #0 + 1.0,0.0, // #1 + 1.0,1.0, // #2 + 0.0,1.0}; // #3 + { + mesh1->setMeshDimension(2); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->useExternalArrayWithRWAccess( coords, 4, 2 ); + mesh1->setCoords(coordsArr); + mesh1->allocateCells(2); + const int conn[6]={0,1,2, 1,2,3}; + mesh1->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+0); // #0 + mesh1->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+3); // #1 + mesh1->finishInsertingCells(); + } + // mesh 2 + MEDCouplingUMesh *mesh2=MEDCouplingUMesh::New(); + const double coords2[4*2]={0.0,1.0, // #0 = #3 + 0.0,0.0, // #1 = #0 + 1.0,0.0, // #2 = #1 + 1.0,1.001}; // #3 ~ #2 + { + mesh2->setMeshDimension(2); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); + coordsArr->useExternalArrayWithRWAccess( coords2, 4, 2 ); + mesh2->setCoords(coordsArr); + mesh2->allocateCells(2); + const int conn[6]={2,3,0, 3,1,2}; + mesh2->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+0); // #0 = #1 + mesh2->insertNextCell(INTERP_KERNEL::NORM_TRI3,3, conn+3); // #1 ~ #0 + mesh2->finishInsertingCells(); + } + //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_1] + //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_2] + int cellCompPol = 1; // "permuted same orientation" - policy of medium severity + DataArrayInt *nOld2New, *cOld2New; + mesh1->checkDeepEquivalWith( mesh2, cellCompPol, 0.002, cOld2New, nOld2New ); + const int nOld2NewExpected[4] = { 3, 0, 1, 2 }; + const int cOld2NewExpected[2] = { 1, 0 }; + CPPUNIT_ASSERT(std::equal(nOld2NewExpected,nOld2NewExpected+4,nOld2New->getConstPointer())); + CPPUNIT_ASSERT(std::equal(cOld2NewExpected,cOld2NewExpected+2,cOld2New->getConstPointer())); + //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_2] + //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_3] + cOld2New->decrRef(); // else memory leaks + CPPUNIT_ASSERT_THROW ( mesh1->checkDeepEquivalOnSameNodesWith( mesh2, cellCompPol, 0.002, cOld2New ), INTERP_KERNEL::Exception ); + mesh2->setCoords( mesh1->getCoords() ); // make meshes share the same coordinates array + mesh2->allocateCells(2); + const int conn[6]={1,2,3, 1,0,2}; + mesh2->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn+0); // #0 = #1 + mesh2->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn+3); // #1 ~ #0 + mesh2->finishInsertingCells(); + cellCompPol = 2; // the weakest policy + mesh1->checkDeepEquivalOnSameNodesWith( mesh2, cellCompPol, 0, cOld2New ); + //! [CppSnippet_MEDCouplingUMesh_checkDeepEquivalWith_3] + nOld2New->decrRef(); + cOld2New->decrRef(); + mesh1->decrRef(); + mesh2->decrRef(); +} + void CppExample_MEDCouplingPointSet_scale() { using namespace ParaMEDMEM; //! [CppSnippet_MEDCouplingPointSet_scale_1] double coords[4*2]={0.0,0.0, 1.0,0.0, 1.0,1.0, 0.0,1.0}; // 2D coordinates of 4 nodes - DataArrayDouble *coordsArr=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); coordsArr->useExternalArrayWithRWAccess(coords, 4,2); - MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(); + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); mesh->setCoords(coordsArr); DataArrayDouble *initCoords = coordsArr->deepCpy(); //! [CppSnippet_MEDCouplingPointSet_scale_1] @@ -48,8 +1121,6 @@ void CppExample_MEDCouplingPointSet_scale() CPPUNIT_ASSERT( coordsArr2->isEqualWithoutConsideringStr( *initCoords, 1.0 )); CPPUNIT_ASSERT( !coordsArr2->isEqualWithoutConsideringStr( *initCoords, 0.9 )); // release data - mesh->decrRef(); - coordsArr->decrRef(); initCoords->decrRef(); //! [CppSnippet_MEDCouplingPointSet_scale_3] } @@ -59,9 +1130,9 @@ void CppExample_MEDCouplingPointSet_translate() using namespace ParaMEDMEM; //! [CppSnippet_MEDCouplingPointSet_translate_1] double coords[4*2]={0.0,0.0, 1.0,0.0, 1.0,1.0, 0.0,1.0}; // 2D coordinates of 4 nodes - DataArrayDouble *coordsArr=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); coordsArr->useExternalArrayWithRWAccess(coords, 4,2); - MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(); + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); mesh->setCoords(coordsArr); DataArrayDouble *initCoords = coordsArr->deepCpy(); //! [CppSnippet_MEDCouplingPointSet_translate_1] @@ -74,8 +1145,6 @@ void CppExample_MEDCouplingPointSet_translate() CPPUNIT_ASSERT( coordsArr2->isEqualWithoutConsideringStr( *initCoords, 1.0 )); CPPUNIT_ASSERT( !coordsArr2->isEqualWithoutConsideringStr( *initCoords, 0.9 )); // release data - mesh->decrRef(); - coordsArr->decrRef(); initCoords->decrRef(); //! [CppSnippet_MEDCouplingPointSet_translate_3] } @@ -85,15 +1154,17 @@ void CppExample_MEDCouplingPointSet_rotate() using namespace ParaMEDMEM; //! [CppSnippet_MEDCouplingPointSet_rotate_1] double coords[4*2]={0.0,0.0, 0.1,0.0, 0.1,0.1, 0.0,0.1}; // 2D coordinates of 4 nodes - DataArrayDouble *coordsArr=DataArrayDouble::New(); + double coordsOrig[4*2]; + std::copy(coords,coords+sizeof(coords)/sizeof(double),coordsOrig);//keep tracks of initial values + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); coordsArr->useExternalArrayWithRWAccess(coords, 4,2); - MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(); + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); mesh->setCoords(coordsArr); //! [CppSnippet_MEDCouplingPointSet_rotate_1] //! [CppSnippet_MEDCouplingPointSet_rotate_2] double center[3] = {0.,0.,0.}; // it suits for 2D as well double vector[3] = {0.,0.,1.}; // it is not used in 2D - mesh->rotate( center, vector, -M_PI/2); + mesh->rotate( center, vector, -M_PI/2); // warning here C++ 'coords' array (defined above) has been modified ! //! [CppSnippet_MEDCouplingPointSet_rotate_2] //! [CppSnippet_MEDCouplingPointSet_rotate_3] mesh->changeSpaceDimension(3); @@ -102,10 +1173,8 @@ void CppExample_MEDCouplingPointSet_rotate() //! [CppSnippet_MEDCouplingPointSet_rotate_4] mesh->changeSpaceDimension(2); const DataArrayDouble * coordsArr2 = mesh->getCoords(); + coordsArr->useExternalArrayWithRWAccess(coordsOrig, 4,2); CPPUNIT_ASSERT( coordsArr2->isEqualWithoutConsideringStr( *coordsArr, 1e-13 )); - // release data - mesh->decrRef(); - coordsArr->decrRef(); //! [CppSnippet_MEDCouplingPointSet_rotate_4] } @@ -115,16 +1184,14 @@ void CppExample_MEDCouplingPointSet_getBoundingBox() //! [CppSnippet_MEDCouplingPointSet_getBoundingBox_1] double cc[2*3]={0.0, 0.1, 0.2, // 3D coordinates of 2 nodes 2.0, 2.1, 2.2}; - DataArrayDouble *coordsArr=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); coordsArr->useExternalArrayWithRWAccess(cc, 2,3); - MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(); + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); mesh->setCoords(coordsArr); - coordsArr->decrRef(); //! [CppSnippet_MEDCouplingPointSet_getBoundingBox_1] //! [CppSnippet_MEDCouplingPointSet_getBoundingBox_2] double bbox[3][2]; mesh->getBoundingBox( (double*) bbox ); - mesh->decrRef(); // check the returned coordinates of extremum points of the bounding box for ( int i = 0; i < 2; ++i ) // point id @@ -138,20 +1205,19 @@ void CppExample_MEDCouplingPointSet_getNodeIdsNearPoint() using namespace ParaMEDMEM; //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_1] // 2D coordinates of 5 nodes - double coords[5*2]={0.3,-0.301, // #0 + double coords[5*2]={0.3,-0.30001, // #0 0.2,-0.3, // #1 - 0.3,-0.302, // #2 + 0.3,-0.30002, // #2 1.1,0.0, // #3 - 0.3,-0.303};// #4 - DataArrayDouble *coordsArr=DataArrayDouble::New(); + 0.3,-0.30003};// #4 + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); coordsArr->useExternalArrayWithRWAccess(coords, 5,2); - MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(); + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); mesh->setCoords(coordsArr); - coordsArr->decrRef(); //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_1] //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_2] double point [2]={0.3, -0.3}; // point close to nodes #0, #2 and #4 - DataArrayInt *ids = mesh->getNodeIdsNearPoint(point, 1e-13); + DataArrayInt *ids = mesh->getNodeIdsNearPoint(point, 1e-2); // check found ids const int expectedIDs[3] = {0,2,4}; @@ -159,7 +1225,6 @@ void CppExample_MEDCouplingPointSet_getNodeIdsNearPoint() CPPUNIT_ASSERT_EQUAL(3, okIDs->getNumberOfTuples()); // release data - mesh->decrRef(); ids->decrRef(); okIDs->decrRef(); //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_2] @@ -176,19 +1241,18 @@ void CppExample_MEDCouplingPointSet_getNodeIdsNearPoints() 1.1,0.0, // #4 1.1,0.002, // #5 0.3,-0.303};// #6 - DataArrayDouble *coordsArr=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); coordsArr->useExternalArrayWithRWAccess(coords, 7,2); - MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(); + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); mesh->setCoords(coordsArr); - coordsArr->decrRef(); //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_1] //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_2] const int nbOfPoints = 3; - double points [nbOfPoints*2]={0.2,-0.301, // ~ node #1 + double points [nbOfPoints*2]={0.2,-0.30001, // ~ node #1 0.0, 0.0, 1.1, 0.002}; // ~ nodes #3, #4 and #5 DataArrayInt *ids, *idsIndex; - mesh->getNodeIdsNearPoints(points, nbOfPoints, 1e-13,ids,idsIndex); + mesh->getNodeIdsNearPoints(points, nbOfPoints, 1e-1,ids,idsIndex); // check found ids (i.e. contents of 'ids' array) const int expectedIDs[4] = {1, 3, 4, 5}; @@ -196,7 +1260,6 @@ void CppExample_MEDCouplingPointSet_getNodeIdsNearPoints() CPPUNIT_ASSERT_EQUAL(4, okIDs->getNumberOfTuples()); // release data - mesh->decrRef(); ids->decrRef(); idsIndex->decrRef(); okIDs->decrRef(); @@ -213,22 +1276,20 @@ void CppExample_MEDCouplingPointSet_findCommonNodes() 1.1,0.0, // 3 1.1,0.0, // 4 0.3,-0.303};// 5 - DataArrayDouble *coordsArr=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); coordsArr->useExternalArrayWithRWAccess(coords, 6,2); - MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(); + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); mesh->setCoords(coordsArr); - coordsArr->decrRef(); //! [CppSnippet_MEDCouplingPointSet_findCommonNodes_1] //! [CppSnippet_MEDCouplingPointSet_findCommonNodes_2] DataArrayInt *com, *comI; mesh->findCommonNodes(1e-13,-1,com,comI); CPPUNIT_ASSERT_EQUAL(2, com->getNumberOfTuples()); + com->decrRef(); comI->decrRef(); mesh->findCommonNodes(0.004,-1,com,comI); CPPUNIT_ASSERT_EQUAL(5, com->getNumberOfTuples()); //! [CppSnippet_MEDCouplingPointSet_findCommonNodes_2] - mesh->decrRef(); - com->decrRef(); - comI->decrRef(); + com->decrRef(); comI->decrRef(); } void CppExample_MEDCouplingPointSet_getCoordinatesOfNode() @@ -236,19 +1297,17 @@ void CppExample_MEDCouplingPointSet_getCoordinatesOfNode() using namespace ParaMEDMEM; //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_1] double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3}; - DataArrayDouble *coordsArr=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr coordsArr=DataArrayDouble::New(); coordsArr->useExternalArrayWithRWAccess(coords, 3,2); - MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(); + MEDCouplingAutoRefCountObjectPtr mesh=MEDCouplingUMesh::New(); mesh->setCoords(coordsArr); - coordsArr->decrRef(); //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_1] //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_2] std::vector coords2; mesh->getCoordinatesOfNode(1,coords2); - CPPUNIT_ASSERT_DOUBLES_EQUAL(coords[0],coords2[0],1e-13); - CPPUNIT_ASSERT_DOUBLES_EQUAL(coords[1],coords2[1],1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(coords[2],coords2[0],1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(coords[3],coords2[1],1e-13); //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_2] - mesh->decrRef(); } void CppExample_DataArrayInt_buildPermutationArr() @@ -340,7 +1399,7 @@ void CppExample_DataArrayDouble_findCommonTuples() //! [CppSnippet_DataArrayDouble_findCommonTuples1] //! [CppSnippet_DataArrayDouble_findCommonTuples2] DataArrayInt *c=0,*cI=0; - da->findCommonTuples(1e-1,-1,c,cI); + da->findCommonTuples(1.01e-1,-1,c,cI); const int expected3[5]={0,3,4,1,2}; const int expected4[3]={0,3,5}; @@ -490,11 +1549,11 @@ void CppSnippetUMeshStdBuild1() mesh->finishInsertingCells(); //! [CppSnippetUMeshStdBuild1_3] //! [CppSnippetUMeshStdBuild1_4] - ParaMEDMEM::DataArrayDouble *myCoords=ParaMEDMEM::DataArrayDouble::New(); - myCoords->alloc(9,3);//here myCoords are declared to have 3 components, mesh will deduce that its spaceDim==3. - std::copy(coords,coords+27,myCoords->getPointer()); - mesh->setCoords(myCoords);//myCorrds contains 9 tuples, that is to say mesh contains 9 nodes. - myCoords->decrRef(); + ParaMEDMEM::DataArrayDouble *coordsArr=ParaMEDMEM::DataArrayDouble::New(); + coordsArr->alloc(9,3);//here coordsArr are declared to have 3 components, mesh will deduce that its spaceDim==3. + std::copy(coords,coords+27,coordsArr->getPointer()); + mesh->setCoords(coordsArr);//coordsArr contains 9 tuples, that is to say mesh contains 9 nodes. + coordsArr->decrRef(); //! [CppSnippetUMeshStdBuild1_4] mesh->checkCoherency(); //! [CppSnippetUMeshStdBuild1_5] @@ -570,11 +1629,11 @@ void CppSnippetUMeshAdvBuild1() nodalConnI->decrRef();// nodalConnI DataArrayInt instance is owned by mesh after call to setConnectivity method. No more need here -> decrRef() //! [CppSnippetUMeshAdvBuild1_3] //! [CppSnippetUMeshAdvBuild1_4] - ParaMEDMEM::DataArrayDouble *myCoords=ParaMEDMEM::DataArrayDouble::New(); - myCoords->alloc(9,3);//here myCoords are declared to have 3 components, mesh will deduce that its spaceDim==3. - std::copy(coords,coords+27,myCoords->getPointer()); - mesh->setCoords(myCoords);//myCorrds contains 9 tuples, that is to say mesh contains 9 nodes. - myCoords->decrRef(); + ParaMEDMEM::DataArrayDouble *coordsArr=ParaMEDMEM::DataArrayDouble::New(); + coordsArr->alloc(9,3);//here coordsArr are declared to have 3 components, mesh will deduce that its spaceDim==3. + std::copy(coords,coords+27,coordsArr->getPointer()); + mesh->setCoords(coordsArr);//coordsArr contains 9 tuples, that is to say mesh contains 9 nodes. + coordsArr->decrRef(); //! [CppSnippetUMeshAdvBuild1_4] mesh->checkCoherency(); //! [CppSnippetUMeshAdvBuild1_5] @@ -588,98 +1647,98 @@ void CppSnippetDataArrayBuild1() const int nbOfNodes=12; double coords[3*nbOfNodes]={2.,3.,4.,3.,4.,5.,4.,5.,6.,5.,6.,7.,6.,7.,8.,7.,8.,9.,8.,9.,10.,9.,10.,11.,10.,11.,12.,11.,12.,13.,12.,13.,14.,13.,14.,15.}; // - ParaMEDMEM::DataArrayDouble *myCoords=0; + ParaMEDMEM::DataArrayDouble *coordsArr=0; double *tmp=0; //! [CppSnippetDataArrayBuild1_0] // //! [CppSnippetDataArrayBuild1_1] - myCoords=ParaMEDMEM::DataArrayDouble::New(); - myCoords->useArray(coords,false,ParaMEDMEM::CPP_DEALLOC,nbOfNodes,3); - //now use myCoords as you need + coordsArr=ParaMEDMEM::DataArrayDouble::New(); + coordsArr->useArray(coords,false,ParaMEDMEM::CPP_DEALLOC,nbOfNodes,3); + //now use coordsArr as you need //... - //myCoords is no more useful here : release it - myCoords->decrRef(); + //coordsArr is no more useful here : release it + coordsArr->decrRef(); //! [CppSnippetDataArrayBuild1_1] //! [CppSnippetDataArrayBuild1_2] - myCoords=ParaMEDMEM::DataArrayDouble::New(); + coordsArr=ParaMEDMEM::DataArrayDouble::New(); tmp=new double[3*nbOfNodes]; std::copy(coords,coords+3*nbOfNodes,tmp); - myCoords->useArray(tmp,true,ParaMEDMEM::CPP_DEALLOC,nbOfNodes,3); - //now use myCoords as you need + coordsArr->useArray(tmp,true,ParaMEDMEM::CPP_DEALLOC,nbOfNodes,3); + //now use coordsArr as you need //... - //myCoords is no more useful, release it - myCoords->decrRef(); + //coordsArr is no more useful, release it + coordsArr->decrRef(); //! [CppSnippetDataArrayBuild1_2] //! [CppSnippetDataArrayBuild1_3] - myCoords=ParaMEDMEM::DataArrayDouble::New(); + coordsArr=ParaMEDMEM::DataArrayDouble::New(); tmp=(double *)malloc(3*nbOfNodes*sizeof(double)); std::copy(coords,coords+3*nbOfNodes,tmp); - myCoords->useArray(tmp,true,ParaMEDMEM::C_DEALLOC,nbOfNodes,3); - //now use myCoords as you need + coordsArr->useArray(tmp,true,ParaMEDMEM::C_DEALLOC,nbOfNodes,3); + //now use coordsArr as you need //... - //myCoords is no more useful here : release it - myCoords->decrRef(); + //coordsArr is no more useful here : release it + coordsArr->decrRef(); //! [CppSnippetDataArrayBuild1_3] //! [CppSnippetDataArrayBuild1_4] - myCoords=ParaMEDMEM::DataArrayDouble::New(); - myCoords->alloc(nbOfNodes,3); - tmp=myCoords->getPointer(); + coordsArr=ParaMEDMEM::DataArrayDouble::New(); + coordsArr->alloc(nbOfNodes,3); + tmp=coordsArr->getPointer(); std::copy(coords,coords+3*nbOfNodes,tmp); - myCoords->declareAsNew();//you have modified data pointed by internal pointer notify object - //now use myCoords as you need + coordsArr->declareAsNew();//you have modified data pointed by internal pointer notify object + //now use coordsArr as you need //... - //myCoords is no more useful here : release it - myCoords->decrRef(); + //coordsArr is no more useful here : release it + coordsArr->decrRef(); //! [CppSnippetDataArrayBuild1_4] - myCoords=ParaMEDMEM::DataArrayDouble::New(); - myCoords->alloc(nbOfNodes,3); - tmp=myCoords->getPointer(); + coordsArr=ParaMEDMEM::DataArrayDouble::New(); + coordsArr->alloc(nbOfNodes,3); + tmp=coordsArr->getPointer(); std::copy(coords,coords+3*nbOfNodes,tmp); - ParaMEDMEM::DataArrayDouble *myCoordsCpy=0; + ParaMEDMEM::DataArrayDouble *coordsArrCpy=0; //! [CppSnippetDataArrayBuild1_5] - myCoordsCpy=myCoords->deepCpy(); + coordsArrCpy=coordsArr->deepCpy(); //! [CppSnippetDataArrayBuild1_5] //! [CppSnippetDataArrayBuild1_6] - CPPUNIT_ASSERT(myCoordsCpy->isEqual(*myCoords,1e-12)); - myCoordsCpy->setIJ(0,0,1000.); - CPPUNIT_ASSERT(!myCoordsCpy->isEqual(*myCoords,1e-12));//myCoordsCpy only has been modified + CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12)); + coordsArrCpy->setIJ(0,0,1000.); + CPPUNIT_ASSERT(!coordsArrCpy->isEqual(*coordsArr,1e-12));//coordsArrCpy only has been modified //! [CppSnippetDataArrayBuild1_6] //! [CppSnippetDataArrayBuild1_7] - myCoordsCpy->decrRef(); + coordsArrCpy->decrRef(); //! [CppSnippetDataArrayBuild1_7] //! [CppSnippetDataArrayBuild1_5bis] - myCoordsCpy=myCoords->performCpy(true); + coordsArrCpy=coordsArr->performCpy(true); //! [CppSnippetDataArrayBuild1_5bis] - CPPUNIT_ASSERT(myCoordsCpy->isEqual(*myCoords,1e-12)); - myCoordsCpy->setIJ(0,0,1000.); - CPPUNIT_ASSERT(!myCoordsCpy->isEqual(*myCoords,1e-12));//myCoordsCpy only has been modified - myCoordsCpy->decrRef(); + CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12)); + coordsArrCpy->setIJ(0,0,1000.); + CPPUNIT_ASSERT(!coordsArrCpy->isEqual(*coordsArr,1e-12));//coordsArrCpy only has been modified + coordsArrCpy->decrRef(); //! [CppSnippetDataArrayBuild1_8] - myCoordsCpy=myCoords->performCpy(false); + coordsArrCpy=coordsArr->performCpy(false); //! [CppSnippetDataArrayBuild1_8] //! [CppSnippetDataArrayBuild1_9] - CPPUNIT_ASSERT(myCoordsCpy->isEqual(*myCoords,1e-12)); - myCoordsCpy->setIJ(0,0,1000.); - CPPUNIT_ASSERT(myCoordsCpy->isEqual(*myCoords,1e-12));//myCoords and myCoordsCpy have been modified simultaneously + CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12)); + coordsArrCpy->setIJ(0,0,1000.); + CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12));//coordsArr and coordsArrCpy have been modified simultaneously //! [CppSnippetDataArrayBuild1_9] //! [CppSnippetDataArrayBuild1_10] - myCoordsCpy->decrRef(); + coordsArrCpy->decrRef(); //! [CppSnippetDataArrayBuild1_10] //! [CppSnippetDataArrayBuild1_11] - myCoordsCpy=ParaMEDMEM::DataArrayDouble::New(); + coordsArrCpy=ParaMEDMEM::DataArrayDouble::New(); //! [CppSnippetDataArrayBuild1_11] //! [CppSnippetDataArrayBuild1_12] - myCoordsCpy->cpyFrom(*myCoords); + coordsArrCpy->cpyFrom(*coordsArr); //! [CppSnippetDataArrayBuild1_12] //! [CppSnippetDataArrayBuild1_13] - CPPUNIT_ASSERT(myCoordsCpy->isEqual(*myCoords,1e-12)); - myCoordsCpy->setIJ(0,0,2000.); - CPPUNIT_ASSERT(!myCoordsCpy->isEqual(*myCoords,1e-12));//myCoordsCpy only has been modified + CPPUNIT_ASSERT(coordsArrCpy->isEqual(*coordsArr,1e-12)); + coordsArrCpy->setIJ(0,0,2000.); + CPPUNIT_ASSERT(!coordsArrCpy->isEqual(*coordsArr,1e-12));//coordsArrCpy only has been modified //! [CppSnippetDataArrayBuild1_13] //! [CppSnippetDataArrayBuild1_14] - myCoordsCpy->decrRef(); + coordsArrCpy->decrRef(); //! [CppSnippetDataArrayBuild1_14] - myCoords->decrRef(); + coordsArr->decrRef(); //! [CppSnippetDataArrayBuild1_14] } @@ -817,6 +1876,42 @@ void CppSnippetFieldDoubleBuild4() int main(int argc, char *argv[]) { + CppExample_MEDCouplingPointSet_getCoordsAt(); + CppExample_MEDCouplingUMesh_areCellsIncludedIn(); + CppExample_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells(); + CppExample_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented(); + CppExample_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented(); + CppExample_MEDCouplingUMesh_getCellsContainingPoints(); + CppExample_MEDCouplingUMesh_getCellsContainingPoint(); + CppExample_MEDCouplingUMesh_buildPartOrthogonalField(); + CppExample_MEDCouplingUMesh_getPartMeasureField(); + CppExample_MEDCouplingUMesh_getCellsInBoundingBox(); + CppExample_MEDCouplingUMesh_renumberNodesInConn(); + CppExample_MEDCouplingUMesh_renumberNodes(); + CppExample_MEDCouplingUMesh_findBoundaryNodes(); + CppExample_MEDCouplingUMesh_buildBoundaryMesh(); + CppExample_MEDCouplingUMesh_buildFacePartOfMySelfNode(); + CppExample_MEDCouplingUMesh_buildPartOfMySelfNode(); + CppExample_MEDCouplingUMesh_getCellIdsLyingOnNodes(); + CppExample_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds(); + CppExample_MEDCouplingUMesh_buildPartOfMySelf(); + CppExample_MEDCouplingUMesh_mergeNodes(); + CppExample_MEDCouplingUMesh_zipConnectivityTraducer(); + CppExample_MEDCouplingUMesh_zipCoordsTraducer(); + CppExample_MEDCouplingUMesh_getNodeIdsInUse(); + CppExample_MEDCouplingUMesh_convertToPolyTypes(); + CppExample_MEDCouplingUMesh_buildDescendingConnectivity2(); + CppExample_MEDCouplingUMesh_buildDescendingConnectivity(); + CppExample_MEDCouplingUMesh_getReverseNodalConnectivity(); + CppExample_MEDCouplingUMesh_checkDeepEquivalWith(); + CppExample_MEDCouplingPointSet_scale(); + CppExample_MEDCouplingPointSet_translate(); + CppExample_MEDCouplingPointSet_rotate(); + CppExample_MEDCouplingPointSet_getBoundingBox(); + CppExample_MEDCouplingPointSet_getNodeIdsNearPoint(); + CppExample_MEDCouplingPointSet_getNodeIdsNearPoints(); + CppExample_MEDCouplingPointSet_findCommonNodes(); + CppExample_MEDCouplingPointSet_getCoordinatesOfNode(); CppExample_DataArrayInt_buildPermutationArr(); CppExample_DataArrayInt_invertArrayO2N2N2O(); CppExample_DataArrayInt_invertArrayN2O2O2N(); diff --git a/src/MEDCoupling_Swig/CMakeLists.txt b/src/MEDCoupling_Swig/CMakeLists.txt index f626e1b23..17e8f4310 100644 --- a/src/MEDCoupling_Swig/CMakeLists.txt +++ b/src/MEDCoupling_Swig/CMakeLists.txt @@ -27,6 +27,7 @@ SET_SOURCE_FILES_PROPERTIES(MEDCoupling.i PROPERTIES SWIG_DEFINITIONS "-shadow") SET (MEDCoupling_SWIG_DPYS_FILES MEDCouplingCommon.i + MEDCouplingMemArray.i MEDCouplingFinalize.i MEDCouplingTypemaps.i) @@ -74,7 +75,7 @@ INSTALL(TARGETS ${SWIG_MODULE_MEDCoupling_REAL_NAME} ${SWIG_MODULE_MEDCouplingRe SET(PYFILES_TO_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/MEDCoupling.py ${CMAKE_CURRENT_BINARY_DIR}/MEDCouplingRemapper.py ${CMAKE_CURRENT_SOURCE_DIR}/libMEDCoupling_Swig.py) INSTALL_AND_COMPILE_PYTHON_FILE("${PYFILES_TO_INSTALL}" ${MED_salomescript_PYTHON}) -INSTALL(FILES MEDCoupling.i MEDCouplingCommon.i MEDCouplingFinalize.i MEDCouplingRemapper.i MEDCouplingTypemaps.i DESTINATION ${MED_salomeinclude_HEADERS}) +INSTALL(FILES MEDCoupling.i MEDCouplingCommon.i MEDCouplingMemArray.i MEDCouplingFinalize.i MEDCouplingRemapper.i MEDCouplingTypemaps.i DESTINATION ${MED_salomeinclude_HEADERS}) INSTALL(FILES MEDCouplingBasicsTest.py MEDCouplingRemapperTest.py MEDCouplingDataForTest.py DESTINATION ${MED_salomescript_PYTHON}) ADD_TEST(MEDCouplingBasicsTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MEDCouplingBasicsTest.py) diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index 3c7aa96c5..9443f9b79 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -47,6 +47,9 @@ def ParaMEDMEMMEDCouplingFieldDoubleImul(self,*args): def ParaMEDMEMMEDCouplingFieldDoubleIdiv(self,*args): import _MEDCoupling return _MEDCoupling.MEDCouplingFieldDouble____idiv___(self, self, *args) +def ParaMEDMEMMEDCouplingFieldDoubleIpow(self,*args): + import _MEDCoupling + return _MEDCoupling.MEDCouplingFieldDouble____ipow___(self, self, *args) def ParaMEDMEMDataArrayIntIadd(self,*args): import _MEDCoupling return _MEDCoupling.DataArrayInt____iadd___(self, self, *args) diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 0b7838de8..0d44b4e6c 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -5081,7 +5081,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): c.changeSpaceDimension(2); # d=DataArrayDouble.New(); - d.alloc(5,1); + d.alloc(5); d.iota(); e=MEDCouplingCMesh.New(); e.setCoordsAt(0,d); @@ -7957,15 +7957,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual(10,dai.getNbOfElems()); self.assertEqual(159,da.getNbOfElems()); # - expected1=[14, 1, 2, 3, 4, - 18, 5, 6, 7, 8, 9, 10, 11, 12, - 14, 13, 14, 15, 16, - 31, 17, 18, 19, -1, 20, 22, 21, -1, 17, 18, 21, 20, -1, 18, 19, 22, 21, -1, 19, 17, 20, 22, - 16, 23, 24, 25, 26, 27, 28, - 31, 29, 30, 31, 32, 33, -1, 34, 38, 37, 36, 35, -1, 29, 30, 35, 34, -1, 30, 31, 36, 35, -1, 31, 32, 37, 36, -1, 32, 33, 38, 37, -1, 33, 29, 34, 38, - 18, 39, 40, 41, 42, 43, 44, 45, 46, - 22, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, - 31, 59, 60, 61, 62, 63, 64, 65, -1, 66, 72, 71, 70, 69, 68, 67, -1, 59, 60, 67, 66, -1, 60, 61, 68, 67, -1, 61, 62, 69, 68, -1, 62, 63, 70, 69, -1, 63, 64, 71, 70, -1, 64, 65, 72, 71, -1, 65, 59, 66, 72]; + expected1=[14,1,2,3,4,18,5,6,7,8,9,10,11,12,14,13,14,15,16,31,17,18,19,-1,20,22,21,-1,17,20,21,18,-1,18,21,22,19,-1,19,22,20,17,16,23,24,25,26,27,28,31,29,30,31,32,33,-1,34,38,37,36,35,-1,29,34,35,30,-1,30,35,36,31,-1,31,36,37,32,-1,32,37,38,33,-1,33,38,34,29,18,39,40,41,42,43,44,45,46,22,47,48,49,50,51,52,53,54,55,56,57,58,31,59,60,61,62,63,64,65,-1,66,72,71,70,69,68,67,-1,59,66,67,60,-1,60,67,68,61,-1,61,68,69,62,-1,62,69,70,63,-1,63,70,71,64,-1,64,71,72,65,-1,65,72,66,59]; expected2=[0,5,14,19,42,49,86,95,108,159] self.assertEqual(expected1,da.getValues()); self.assertEqual(expected2,dai.getValues()); @@ -11911,6 +11903,651 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0]))) self.assertTrue(e.isEqual(DataArrayInt([0,1,2,3,4,5,6]))) pass + + def testSwigAdvGauss(self): + f=MEDCouplingFieldTemplate(ON_GAUSS_PT) + f.setDiscretization(None) + f.__repr__() ; f.__str__() + # + f=MEDCouplingFieldTemplate(ON_GAUSS_PT) + d=f.getDiscretization() + i=DataArrayInt() ; i.alloc(10,1) ; i.iota(1) + d.setArrayOfDiscIds(i) + f.__repr__() ; f.__str__() + i2=d.getArrayOfDiscIds() + self.assertEqual(i.__repr__(),i2.__repr__()) + # + f=MEDCouplingFieldDouble(ON_GAUSS_PT) + f.setDiscretization(None) + f.__repr__() ; f.__str__() + # + f=MEDCouplingFieldDouble(ON_GAUSS_PT) + d=f.getDiscretization() + i=DataArrayInt() ; i.alloc(10,1) ; i.iota(1) + d.setArrayOfDiscIds(i) + f.__repr__() ; f.__str__() + # + gl=MEDCouplingGaussLocalization(NORM_SEG2,[0,1],[0.5],[1.]) + gl.setWeights([3.]) + gl.__repr__() ; gl.__str__() + gl=MEDCouplingGaussLocalization(NORM_ERROR) + gl.setWeights([3.]) + gl.__repr__() ; gl.__str__() + pass + + def testSwig2NonRegressionBugSubstractInPlaceDM(self): + m0=MEDCouplingCMesh() + arr=DataArrayDouble(5,1) ; arr.iota(0.) + m0.setCoords(arr,arr) + m0=m0.buildUnstructured() + m00=m0[::2] ; m00.simplexize(0) ; m01=m0[1::2] + m0=MEDCouplingUMesh.MergeUMeshes([m00,m01]) + m0.getCoords()[:]*=1/4. + m0.setName("mesh") + # + NodeField=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; NodeField.setTime(5.6,5,6) ; NodeField.setMesh(m0) + NodeField.setName("NodeField") + NodeField.fillFromAnalytic(1,"exp(-((x-1)*(x-1)+(y-1)*(y-1)))") ; NodeField.getArray().setInfoOnComponent(0,"powernode [W]") + proc0=m0.getCellsInBoundingBox([(0.,0.4),(0.,0.4)],1e-10) + proc1=proc0.buildComplement(m0.getNumberOfCells()) + # + NodeField0=NodeField[proc0] ; NodeField0.getMesh().setName(m0.getName()) + NodeField1=NodeField[proc1] ; NodeField1.getMesh().setName(m0.getName()) + # + NodeField_read=MEDCouplingFieldDouble.MergeFields([NodeField0,NodeField1]) + NodeField_read.mergeNodes(1e-10) + NodeFieldCpy=NodeField.deepCpy() + NodeFieldCpy.mergeNodes(1e-10) + NodeField.checkCoherency() + self.assertTrue(not NodeField.getArray().isUniform(0.,1e-12)) + NodeField.substractInPlaceDM(NodeField_read,10,1e-12) + self.assertTrue(NodeField.getArray().isUniform(0.,1e-12)) + pass + + def testSwigFieldOperationOpen1(self): + ## MEDCouplingFieldDouble.__add__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__add__,2) + self.assertRaises(InterpKernelException,f.__add__,range(5)) + self.assertRaises(InterpKernelException,f.__add__,arr) + self.assertRaises(InterpKernelException,f.__add__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__add__,2) + self.assertRaises(InterpKernelException,f.__add__,range(5)) + self.assertRaises(InterpKernelException,f.__add__,arr) + self.assertRaises(InterpKernelException,f.__add__,f2) + self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0)) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + ff=f+2 + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,9),(3,10),(4,11),(5,12),(6,13)]),1e-12)) + ff=f+arr + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(2,10),(4,13),(6,16),(8,19)]),1e-12)) + self.assertRaises(InterpKernelException,f.__add__,f2) + f2.setArray(arr) + ff=f+f2 + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(2,10),(4,13),(6,16),(8,19)]),1e-12)) + ff=f+[5,8] + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(5,15),(6,16),(7,17),(8,18),(9,19)]),1e-12)) + ### MEDCouplingFieldDouble.__sub__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__sub__,2) + self.assertRaises(InterpKernelException,f.__sub__,range(5)) + self.assertRaises(InterpKernelException,f.__sub__,arr) + self.assertRaises(InterpKernelException,f.__sub__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__sub__,2) + self.assertRaises(InterpKernelException,f.__sub__,range(5)) + self.assertRaises(InterpKernelException,f.__sub__,arr) + self.assertRaises(InterpKernelException,f.__sub__,f2) + self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0)) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + ff=f-2 + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(-2,5),(-1,6),(0,7),(1,8),(2,9)]),1e-12)) + ff=f-arr + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(0,6),(0,5),(0,4),(0,3)]),1e-12)) + self.assertRaises(InterpKernelException,f.__sub__,f2) + f2.setArray(arr) + ff=f-f2 + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(0,6),(0,5),(0,4),(0,3)]),1e-12)) + ff=f-[5,8] + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(-5,-1),(-4,0),(-3,1),(-2,2),(-1,3)]),1e-12)) + ### MEDCouplingFieldDouble.__mul__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__mul__,2) + self.assertRaises(InterpKernelException,f.__mul__,range(5)) + self.assertRaises(InterpKernelException,f.__mul__,arr) + self.assertRaises(InterpKernelException,f.__mul__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__mul__,2) + self.assertRaises(InterpKernelException,f.__mul__,range(5)) + self.assertRaises(InterpKernelException,f.__mul__,arr) + self.assertRaises(InterpKernelException,f.__mul__,f2) + self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0)) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + ff=f*2 + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,14),(2,16),(4,18),(6,20),(8,22)]),1e-12)) + ff=f*arr + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,0),(1,16),(4,36),(9,60),(16,88)]),1e-12)) + self.assertRaises(InterpKernelException,f.__mul__,f2) + f2.setArray(arr) + ff=f*f2 + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,0),(1,16),(4,36),(9,60),(16,88)]),1e-12)) + ff=f*[5,8] + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,56),(5,64),(10,72),(15,80),(20,88)]),1e-12)) + ### MEDCouplingFieldDouble.__div__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__div__,2) + self.assertRaises(InterpKernelException,f.__div__,range(5)) + self.assertRaises(InterpKernelException,f.__div__,arr) + self.assertRaises(InterpKernelException,f.__div__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__div__,2) + self.assertRaises(InterpKernelException,f.__div__,range(5)) + self.assertRaises(InterpKernelException,f.__div__,arr) + self.assertRaises(InterpKernelException,f.__div__,f2) + self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0)) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + self.assertRaises(InterpKernelException,f.__div__,0) + ff=f/2 + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,3.5),(0.5,4),(1,4.5),(1.5,5),(2,5.5)]),1e-12)) + ff=f/arr + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,3.5),(0.5,2),(0.6666666666666666,1.5),(0.75,1.25),(0.8,1.1)]),1e-12)) + self.assertRaises(InterpKernelException,f.__div__,f2) + f2.setArray(arr) + ff=f/f2 + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,3.5),(0.5,2),(0.6666666666666666,1.5),(0.75,1.25),(0.8,1.1)]),1e-12)) + ff=f/[5,8] + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,0.875),(0.2,1),(0.4,1.125),(0.6,1.25),(0.8,1.375)]),1e-12)) + ### MEDCouplingFieldDouble.__pow__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5) + arr[:]=[1,1,3,2,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__div__,2) + self.assertRaises(InterpKernelException,f.__div__,range(5)) + self.assertRaises(InterpKernelException,f.__div__,arr) + self.assertRaises(InterpKernelException,f.__div__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__div__,2) + self.assertRaises(InterpKernelException,f.__div__,range(5)) + self.assertRaises(InterpKernelException,f.__div__,arr) + self.assertRaises(InterpKernelException,f.__div__,f2) + self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0)) + f.getArray().alloc(5,1) + f.getArray()[:]=range(2,7) + ff=f**2 + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([4,9,16,25,36]),1e-12)) + ff=f**arr + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([2,3,64,25,1]),1e-12)) + f2.setArray(arr) + ff=f**f2 + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([2,3,64,25,1]),1e-12)) + ## MEDCouplingFieldDouble.__iadd__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__iadd__,2) + self.assertRaises(InterpKernelException,f.__iadd__,range(5)) + self.assertRaises(InterpKernelException,f.__iadd__,arr) + self.assertRaises(InterpKernelException,f.__iadd__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__iadd__,2) + self.assertRaises(InterpKernelException,f.__iadd__,range(5)) + self.assertRaises(InterpKernelException,f.__iadd__,arr) + self.assertRaises(InterpKernelException,f.__iadd__,f2) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + f.checkCoherency() + f+=2 + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(2,9),(3,10),(4,11),(5,12),(6,13)]),1e-12)) + f+=arr + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(2,9),(4,12),(6,15),(8,18),(10,21)]),1e-12)) + f2.setArray(arr) + f+=f2 + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(2,9),(5,14),(8,19),(11,24),(14,29)]),1e-12)) + f+=[0.1,0.2] + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(2.1,9.2),(5.1,14.2),(8.1,19.2),(11.1,24.2),(14.1,29.2)]),1e-12)) + ## MEDCouplingFieldDouble.__isub__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__isub__,2) + self.assertRaises(InterpKernelException,f.__isub__,range(5)) + self.assertRaises(InterpKernelException,f.__isub__,arr) + self.assertRaises(InterpKernelException,f.__isub__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__isub__,2) + self.assertRaises(InterpKernelException,f.__isub__,range(5)) + self.assertRaises(InterpKernelException,f.__isub__,arr) + self.assertRaises(InterpKernelException,f.__isub__,f2) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + f.checkCoherency() + f-=2 + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(-2,5),(-1,6),(0,7),(1,8),(2,9)]),1e-12)) + f-=arr + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(-2,5),(-2,4),(-2,3),(-2,2),(-2,1)]),1e-12)) + f2.setArray(arr) + f-=f2 + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(-2,5),(-3,2),(-4,-1),(-5,-4),(-6,-7)]),1e-12)) + f-=[0.1,0.2] + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(-2.1,4.8),(-3.1,1.8),(-4.1,-1.2),(-5.1,-4.2),(-6.1,-7.2)]),1e-12)) + ## MEDCouplingFieldDouble.__imul__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__imul__,2) + self.assertRaises(InterpKernelException,f.__imul__,range(5)) + self.assertRaises(InterpKernelException,f.__imul__,arr) + self.assertRaises(InterpKernelException,f.__imul__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__imul__,2) + self.assertRaises(InterpKernelException,f.__imul__,range(5)) + self.assertRaises(InterpKernelException,f.__imul__,arr) + self.assertRaises(InterpKernelException,f.__imul__,f2) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + f.checkCoherency() + f*=2 + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,14),(2,16),(4,18),(6,20),(8,22)]),1e-12)) + f*=arr + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,0),(2,32),(8,72),(18,120),(32,176)]),1e-12)) + f2.setArray(arr) + f*=f2 + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,0),(2,64),(16,288),(54,720),(128,1408)]),1e-12)) + f*=[0.1,0.2] + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,0),(0.2,12.8),(1.6,57.6),(5.4,144),(12.8,281.6)]),1e-12)) + ## MEDCouplingFieldDouble.__idiv__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__idiv__,2) + self.assertRaises(InterpKernelException,f.__idiv__,range(5)) + self.assertRaises(InterpKernelException,f.__idiv__,arr) + self.assertRaises(InterpKernelException,f.__idiv__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__idiv__,2) + self.assertRaises(InterpKernelException,f.__idiv__,range(5)) + self.assertRaises(InterpKernelException,f.__idiv__,arr) + self.assertRaises(InterpKernelException,f.__idiv__,f2) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + f.checkCoherency() + f/=2 + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,3.5),(0.5,4),(1,4.5),(1.5,5),(2,5.5)]),1e-12)) + f/=arr + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,1.75),(0.25,1),(0.3333333333333333,0.75),(0.375,0.625),(0.4,0.55)]),1e-12)) + f2.setArray(arr) + f/=f2 + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,0.875),(0.125,0.25),(0.1111111111111111,0.125),(0.09375,0.078125),(0.08,0.055)]),1e-12)) + f/=[0.1,0.2] + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,4.375),(1.25,1.25),(1.1111111111111111,0.625),(0.9375,0.390625),(0.8,0.275)]),1e-12)) + ## MEDCouplingFieldDouble.__ipow__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__ipow__,2) + self.assertRaises(InterpKernelException,f.__ipow__,range(5)) + self.assertRaises(InterpKernelException,f.__ipow__,arr) + self.assertRaises(InterpKernelException,f.__ipow__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__ipow__,2) + self.assertRaises(InterpKernelException,f.__ipow__,range(5)) + self.assertRaises(InterpKernelException,f.__ipow__,arr) + self.assertRaises(InterpKernelException,f.__ipow__,f2) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + f.checkCoherency() + f**=2 + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,49),(1,64),(4,81),(9,100),(16,121)]),1e-12)) + ## MEDCouplingFieldDouble.__radd__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__radd__,2) + self.assertRaises(InterpKernelException,f.__radd__,range(5)) + self.assertRaises(InterpKernelException,f.__radd__,arr) + self.assertRaises(InterpKernelException,f.__radd__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__radd__,2) + self.assertRaises(InterpKernelException,f.__radd__,range(5)) + self.assertRaises(InterpKernelException,f.__radd__,arr) + self.assertRaises(InterpKernelException,f.__radd__,f2) + self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0)) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + ff=2+f + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,9),(3,10),(4,11),(5,12),(6,13)]),1e-12)) + ff=arr+f + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(2,10),(4,13),(6,16),(8,19)]),1e-12)) + self.assertRaises(InterpKernelException,f.__radd__,f2) + ff=[5,8]+f + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(5,15),(6,16),(7,17),(8,18),(9,19)]),1e-12)) + ### MEDCouplingFieldDouble.__rsub__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__rsub__,2) + self.assertRaises(InterpKernelException,f.__rsub__,range(5)) + self.assertRaises(InterpKernelException,f.__rsub__,arr) + self.assertRaises(InterpKernelException,f.__rsub__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__rsub__,2) + self.assertRaises(InterpKernelException,f.__rsub__,range(5)) + self.assertRaises(InterpKernelException,f.__rsub__,arr) + self.assertRaises(InterpKernelException,f.__rsub__,f2) + self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0)) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + ff=2-f + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,-5),(1,-6),(0,-7),(-1,-8),(-2,-9)]),1e-12)) + ff=arr-f + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,-7),(0,-6),(0,-5),(0,-4),(0,-3)]),1e-12)) + self.assertRaises(InterpKernelException,f.__rsub__,f2) + ### MEDCouplingFieldDouble.__rmul__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__rmul__,2) + self.assertRaises(InterpKernelException,f.__rmul__,range(5)) + self.assertRaises(InterpKernelException,f.__rmul__,arr) + self.assertRaises(InterpKernelException,f.__rmul__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__rmul__,2) + self.assertRaises(InterpKernelException,f.__rmul__,range(5)) + self.assertRaises(InterpKernelException,f.__rmul__,arr) + self.assertRaises(InterpKernelException,f.__rmul__,f2) + self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0)) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + ff=2*f + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,14),(2,16),(4,18),(6,20),(8,22)]),1e-12)) + ff=arr*f + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,0),(1,16),(4,36),(9,60),(16,88)]),1e-12)) + self.assertRaises(InterpKernelException,f.__rmul__,f2) + ff=f*[5,8] + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,56),(5,64),(10,72),(15,80),(20,88)]),1e-12)) + ### MEDCouplingFieldDouble.__rdiv__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__rdiv__,2) + self.assertRaises(InterpKernelException,f.__rdiv__,range(5)) + self.assertRaises(InterpKernelException,f.__rdiv__,arr) + self.assertRaises(InterpKernelException,f.__rdiv__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__rdiv__,2) + self.assertRaises(InterpKernelException,f.__rdiv__,range(5)) + self.assertRaises(InterpKernelException,f.__rdiv__,arr) + self.assertRaises(InterpKernelException,f.__rdiv__,f2) + self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0)) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(1,6) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + ff=2/f + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,0.25),(1,0.22222222222222221),(0.66666666666666663,0.20000000000000001),(0.5,0.18181818181818182),(0.40000000000000002,0.16666666666666666)]),1e-12)) + ff=arr/f + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(1,0.25),(1,0.44444444444444442),(1,0.59999999999999998),(1,0.72727272727272729),(1,0.83333333333333337)]),1e-12)) + self.assertRaises(InterpKernelException,f.__rdiv__,f2) + pass + + def testSwig2FieldDoubleBuildSubPartRange1(self): + #ON_CELLS + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) ; arr[:,0]=range(7,12) ; arr[:,1]=100+arr[:,0] + f.setArray(arr) + f.checkCoherency() + ff=f[1:-1:2] + ff.checkCoherency() + self.assertTrue((m.buildPartOfMySelf([1,3],True)).isEqual(ff.getMesh(),1e-12)) + self.assertTrue(9,ff.getMesh().getNumberOfNodes()) + self.assertTrue(2,ff.getMesh().getNumberOfCells()) + self.assertTrue(ff.getArray().isEqual(arr[[1,3]],1e-12)) + # + a,b=f.buildSubMeshDataRange(2,5,1) + self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(a,1e-12)) + self.assertEqual(b,slice(2,5,1)) + ff=f[2:] + ff.checkCoherency() + self.assertTrue((m.buildPartOfMySelf([2,3,4],True)).isEqual(ff.getMesh(),1e-12)) + self.assertTrue(9,ff.getMesh().getNumberOfNodes()) + self.assertTrue(3,ff.getMesh().getNumberOfCells()) + self.assertTrue(ff.getArray().isEqual(arr[[2,3,4]],1e-12)) + # + ff=f[-2:0:-1] + ff.checkCoherency() + self.assertTrue((m.buildPartOfMySelf([3,2,1],True)).isEqual(ff.getMesh(),1e-12)) + self.assertTrue(9,ff.getMesh().getNumberOfNodes()) + self.assertTrue(3,ff.getMesh().getNumberOfCells()) + self.assertTrue(ff.getArray().isEqual(arr[[3,2,1]],1e-12)) + self.assertTrue(f[-2:0:-1,1].getArray().isEqual(arr[[3,2,1],1],1e-12)) + #ON_NODES + f=MEDCouplingFieldDouble(ON_NODES) + f.setMesh(m) + arr=DataArrayDouble(9,2) ; arr[:,0]=range(7,16) ; arr[:,1]=100+arr[:,0] + f.setArray(arr) + f.checkCoherency() + ff=f[1:-1:2] + ff.checkCoherency() + self.assertTrue((m.buildPartOfMySelf([1,3],False)).isEqual(ff.getMesh(),1e-12)) + self.assertTrue(6,ff.getMesh().getNumberOfNodes()) + self.assertTrue(2,ff.getMesh().getNumberOfCells()) + self.assertTrue(ff.getArray().isEqual(arr[[1,2,3,4,6,7]],1e-12)) + # + m2=m.buildPartRange(2,5,1) + self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(m2,1e-12)) + m2,b=m.buildPartRangeAndReduceNodes(2,5,1) + self.assertTrue(m.buildPartOfMySelf([2,3,4],False).isEqual(m2,1e-12)) + self.assertTrue(b.isEqual(DataArrayInt([-1,-1,0,1,2,3,4,5,6]))) + a,b=f.buildSubMeshDataRange(2,5,1) + self.assertTrue(m.buildPartOfMySelf([2,3,4],False).isEqual(a,1e-12)) + self.assertTrue(b.isEqual(DataArrayInt([2,3,4,5,6,7,8]))) + ff=f[2:] + ff.checkCoherency() + self.assertTrue((m.buildPartOfMySelf([2,3,4],False)).isEqual(ff.getMesh(),1e-12)) + self.assertTrue(7,ff.getMesh().getNumberOfNodes()) + self.assertTrue(3,ff.getMesh().getNumberOfCells()) + self.assertTrue(ff.getArray().isEqual(arr[[2,3,4,5,6,7,8]],1e-12)) + # + ff=f[-2:0:-1] + ff.checkCoherency() + self.assertTrue((m.buildPartOfMySelf([3,2,1],False)).isEqual(ff.getMesh(),1e-12)) + self.assertTrue(7,ff.getMesh().getNumberOfNodes()) + self.assertTrue(3,ff.getMesh().getNumberOfCells()) + self.assertTrue(ff.getArray().isEqual(arr[[1,2,3,4,5,6,7]],1e-12)) + self.assertTrue(f[-2:0:-1,1].getArray().isEqual(arr[[1,2,3,4,5,6,7],1],1e-12)) + #ON_GAUSS_NE + f=MEDCouplingFieldDouble(ON_GAUSS_NE) + f.setMesh(m) + arr=DataArrayDouble(18,2) ; arr[:,0]=range(7,25) ; arr[:,1]=100+arr[:,0] + f.setArray(arr) + f.checkCoherency() + ff=f[1:-1:2] + ff.checkCoherency() + self.assertTrue((m.buildPartOfMySelf([1,3],True)).isEqual(ff.getMesh(),1e-12)) + self.assertTrue(9,ff.getMesh().getNumberOfNodes()) + self.assertTrue(2,ff.getMesh().getNumberOfCells()) + self.assertTrue(ff.getArray().isEqual(arr[[4,5,6,10,11,12,13]],1e-12)) + # + a,b=f.buildSubMeshDataRange(2,5,1) + self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(a,1e-12)) + self.assertEqual(b,slice(7,18,1)) + ff=f[2:] + ff.checkCoherency() + self.assertTrue((m.buildPartOfMySelf([2,3,4],True)).isEqual(ff.getMesh(),1e-12)) + self.assertTrue(9,ff.getMesh().getNumberOfNodes()) + self.assertTrue(3,ff.getMesh().getNumberOfCells()) + self.assertTrue(ff.getArray().isEqual(arr[[7,8,9,10,11,12,13,14,15,16,17]],1e-12)) + # + ff=f[-2:0:-1] + ff.checkCoherency() + self.assertTrue((m.buildPartOfMySelf([3,2,1],True)).isEqual(ff.getMesh(),1e-12)) + self.assertTrue(9,ff.getMesh().getNumberOfNodes()) + self.assertTrue(3,ff.getMesh().getNumberOfCells()) + self.assertTrue(ff.getArray().isEqual(arr[[10,11,12,13,7,8,9,4,5,6]],1e-12)) + self.assertTrue(f[-2:0:-1,1].getArray().isEqual(arr[[10,11,12,13,7,8,9,4,5,6],1],1e-12)) + #ON_GAUSS_PT + f=MEDCouplingFieldDouble(ON_GAUSS_PT) + f.setMesh(m) + f.setGaussLocalizationOnCells([0,4],[0,0,1,0,1,1,1,0],[1.1,1.1,2.2,2.2],[0.2,0.8]); + f.setGaussLocalizationOnCells([3],[0,0,1,0,1,1,1,0],[1.1,1.1,2.2,2.2,3.,3.],[0.2,0.4,0.4]); + f.setGaussLocalizationOnCells([1],[0,0,1,0,1,0],[1.1,1.1,2.2,2.2,3.,3.,4.,4.],[0.1,0.1,0.4,0.4]); + f.setGaussLocalizationOnCells([2],[0,0,1,0,1,0],[1.1,1.1,2.2,2.2,3.,3.,4.,4.,5.,5.],[0.1,0.1,0.4,0.3,0.1]); + arr=DataArrayDouble(16,2) ; arr[:,0]=range(7,23) ; arr[:,1]=100+arr[:,0] + f.setArray(arr) + f.checkCoherency() + ff=f[1:-1:2] + ff.checkCoherency() + self.assertTrue((m.buildPartOfMySelf([1,3],True)).isEqual(ff.getMesh(),1e-12)) + self.assertTrue(9,ff.getMesh().getNumberOfNodes()) + self.assertTrue(2,ff.getMesh().getNumberOfCells()) + self.assertTrue(ff.getArray().isEqual(arr[[2,3,4,5,11,12,13]],1e-12)) + # + a,b=f.buildSubMeshDataRange(2,5,1) + self.assertTrue(m.buildPartOfMySelf([2,3,4],True).isEqual(a,1e-12)) + self.assertEqual(b,slice(6,16,1)) + ff=f[2:] + ff.checkCoherency() + self.assertTrue((m.buildPartOfMySelf([2,3,4],True)).isEqual(ff.getMesh(),1e-12)) + self.assertTrue(9,ff.getMesh().getNumberOfNodes()) + self.assertTrue(3,ff.getMesh().getNumberOfCells()) + self.assertTrue(ff.getArray().isEqual(arr[[6,7,8,9,10,11,12,13,14,15]],1e-12)) + # + ff=f[-2:0:-1] + ff.checkCoherency() + self.assertTrue((m.buildPartOfMySelf([3,2,1],True)).isEqual(ff.getMesh(),1e-12)) + self.assertTrue(9,ff.getMesh().getNumberOfNodes()) + self.assertTrue(3,ff.getMesh().getNumberOfCells()) + self.assertTrue(ff.getArray().isEqual(arr[[11,12,13,6,7,8,9,10,2,3,4,5]],1e-12)) + self.assertTrue(f[-2:0:-1,0].getArray().isEqual(arr[[11,12,13,6,7,8,9,10,2,3,4,5],0],1e-12)) + pass + + def testSwig2FieldDoubleApplyFuncBug1(self): + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(MEDCouplingDataForTest.build2DTargetMesh_1()) + f.applyFunc(3,700.) + f.checkCoherency() + self.assertEqual(3,f.getArray().getNumberOfComponents()) + f.getArray().rearrange(1) + self.assertTrue(f.getArray().isUniform(700.,1e-10)) + f.getArray().rearrange(3) + f.checkCoherency() + f.applyFunc(4,800.) + f.checkCoherency() + self.assertEqual(4,f.getArray().getNumberOfComponents()) + f.getArray().rearrange(1) + self.assertTrue(f.getArray().isUniform(800.,1e-10)) + f.getArray().rearrange(4) + f.checkCoherency() + pass + + def testSwig2ComputeTupleIdsNearTupleBug1(self): + coords=[1.1,0.0, 1.1,0.0 ]; + coordsArr=DataArrayDouble(coords,2,2); + mesh=MEDCouplingUMesh(); + mesh.setCoords(coordsArr); + points=[1.1, 0.002] + c,cI=mesh.getNodeIdsNearPoints(points,0.00185); + self.assertTrue(c.isEqual(DataArrayInt([]))) + self.assertTrue(cI.isEqual(DataArrayInt([0,0]))) + c,cI=mesh.getNodeIdsNearPoints(points,0.00200000000000001); + self.assertTrue(c.isEqual(DataArrayInt([0,1]))) + self.assertTrue(cI.isEqual(DataArrayInt([0,2]))) + pass def setUp(self): pass diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 767ceffce..ae3174186 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -45,6 +45,7 @@ using namespace ParaMEDMEM; using namespace INTERP_KERNEL; + %} %template(ivec) std::vector; @@ -92,6 +93,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingFieldDiscretization::deepCpy; %newobject ParaMEDMEM::MEDCouplingFieldDiscretization::clone; %newobject ParaMEDMEM::MEDCouplingFieldDiscretization::clonePart; +%newobject ParaMEDMEM::MEDCouplingFieldDiscretization::clonePartRange; %newobject ParaMEDMEM::MEDCouplingFieldDiscretization::getMeasureField; %newobject ParaMEDMEM::MEDCouplingFieldDiscretization::getOffsetArr; %newobject ParaMEDMEM::MEDCouplingFieldDiscretization::getLocalizationOfDiscValues; @@ -129,13 +131,21 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingFieldDouble::MultiplyFields; %newobject ParaMEDMEM::MEDCouplingFieldDouble::DivideFields; %newobject ParaMEDMEM::MEDCouplingFieldDouble::min; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::negate; %newobject ParaMEDMEM::MEDCouplingFieldDouble::getIdsInRange; %newobject ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::buildSubPartRange; %newobject ParaMEDMEM::MEDCouplingFieldDouble::__getitem__; -%newobject ParaMEDMEM::MEDCouplingFieldDouble::operator+; -%newobject ParaMEDMEM::MEDCouplingFieldDouble::operator-; -%newobject ParaMEDMEM::MEDCouplingFieldDouble::operator*; -%newobject ParaMEDMEM::MEDCouplingFieldDouble::operator/; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::__neg__; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::__add__; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::__sub__; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::__mul__; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::__div__; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::__pow__; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::__radd__; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::__rsub__; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::__rmul__; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::__rdiv__; %newobject ParaMEDMEM::MEDCouplingFieldDouble::clone; %newobject ParaMEDMEM::MEDCouplingFieldDouble::cloneWithMesh; %newobject ParaMEDMEM::MEDCouplingFieldDouble::deepCpy; @@ -281,13 +291,9 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayDouble::findClosestTupleId; %newobject ParaMEDMEM::DataArrayDouble::duplicateEachTupleNTimes; %newobject ParaMEDMEM::DataArrayDouble::__neg__; -%newobject ParaMEDMEM::DataArrayDouble::__add__; %newobject ParaMEDMEM::DataArrayDouble::__radd__; -%newobject ParaMEDMEM::DataArrayDouble::__sub__; %newobject ParaMEDMEM::DataArrayDouble::__rsub__; -%newobject ParaMEDMEM::DataArrayDouble::__mul__; %newobject ParaMEDMEM::DataArrayDouble::__rmul__; -%newobject ParaMEDMEM::DataArrayDouble::__div__; %newobject ParaMEDMEM::DataArrayDouble::__rdiv__; %newobject ParaMEDMEM::DataArrayDouble::__pow__; %newobject ParaMEDMEM::DataArrayDouble::__rpow__; @@ -296,6 +302,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingMesh::checkDeepEquivalOnSameNodesWith; %newobject ParaMEDMEM::MEDCouplingMesh::checkTypeConsistencyAndContig; %newobject ParaMEDMEM::MEDCouplingMesh::computeNbOfNodesPerCell; +%newobject ParaMEDMEM::MEDCouplingMesh::buildPartRange; %newobject ParaMEDMEM::MEDCouplingMesh::giveCellsWithType; %newobject ParaMEDMEM::MEDCouplingMesh::getCoordinatesAndOwner; %newobject ParaMEDMEM::MEDCouplingMesh::getBarycenterAndOwner; @@ -374,6 +381,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingMultiFields::deepCpy; %newobject ParaMEDMEM::MEDCouplingFieldOverTime::New; +%feature("unref") DataArray "$this->decrRef();" %feature("unref") DataArrayDouble "$this->decrRef();" %feature("unref") MEDCouplingPointSet "$this->decrRef();" %feature("unref") MEDCouplingMesh "$this->decrRef();" @@ -397,28 +405,10 @@ using namespace INTERP_KERNEL; %rename(assign) *::operator=; %ignore ParaMEDMEM::MEDCouplingVersionMajMinRel; %ignore ParaMEDMEM::RefCountObject::decrRef; -%ignore ParaMEDMEM::MemArray::operator=; -%ignore ParaMEDMEM::MemArray::operator[]; %ignore ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationIntInfo; %ignore ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationDblInfo; %ignore ParaMEDMEM::MEDCouplingGaussLocalization::fillWithValues; %ignore ParaMEDMEM::MEDCouplingGaussLocalization::buildNewInstanceFromTinyInfo; -%ignore ParaMEDMEM::DataArrayIntIterator::nextt; -%ignore ParaMEDMEM::DataArrayIntTuple::repr; -%ignore ParaMEDMEM::DataArrayIntTuple::intValue; -%ignore ParaMEDMEM::DataArrayByteIterator::nextt; -%ignore ParaMEDMEM::DataArrayByteTuple::repr; -%ignore ParaMEDMEM::DataArrayByteTuple::byteValue; -%ignore ParaMEDMEM::DataArrayAsciiCharIterator::nextt; -%ignore ParaMEDMEM::DataArrayAsciiCharTuple::repr; -%ignore ParaMEDMEM::DataArrayAsciiCharTuple::asciiCharValue; -%ignore ParaMEDMEM::DataArrayDoubleIterator::nextt; -%ignore ParaMEDMEM::DataArrayDoubleTuple::repr; -%ignore ParaMEDMEM::DataArrayDoubleTuple::doubleValue; -%ignore ParaMEDMEM::DataArrayDouble::writeVTK; -%ignore ParaMEDMEM::DataArrayInt::writeVTK; -%ignore ParaMEDMEM::DataArrayDouble::SetArrayIn; -%ignore ParaMEDMEM::DataArrayInt::SetArrayIn; %nodefaultctor; @@ -496,6 +486,8 @@ namespace ParaMEDMEM }; } +%include "MEDCouplingMemArray.i" + namespace ParaMEDMEM { typedef enum @@ -521,6 +513,21 @@ namespace ParaMEDMEM } } + %extend MEDCouplingGaussLocalization + { + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->getStringRepr(); + } + + std::string __repr__() const throw(INTERP_KERNEL::Exception) + { + std::ostringstream oss; oss << "MEDCouplingGaussLocalization C++ instance at " << self << "." << std::endl; + oss << self->getStringRepr(); + return oss.str(); + } + } + class MEDCouplingMesh : public RefCountObject, public TimeLabel { public: @@ -550,6 +557,7 @@ namespace ParaMEDMEM virtual DataArrayDouble *computeIsoBarycenterOfNodesPerCell() const throw(INTERP_KERNEL::Exception); virtual DataArrayInt *giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception); virtual DataArrayInt *computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception); + virtual MEDCouplingMesh *buildPartRange(int beginCellIds, int endCellIds, int stepCellIds) const throw(INTERP_KERNEL::Exception); virtual int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception); virtual INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const throw(INTERP_KERNEL::Exception); virtual std::string simpleRepr() const throw(INTERP_KERNEL::Exception); @@ -840,6 +848,23 @@ namespace ParaMEDMEM return res; } + PyObject *buildPartRangeAndReduceNodes(int beginCellIds, int endCellIds, int stepCellIds) const throw(INTERP_KERNEL::Exception) + { + int a,b,c; + DataArrayInt *arr=0; + MEDCouplingMesh *ret=self->buildPartRangeAndReduceNodes(beginCellIds,endCellIds,stepCellIds,a,b,c,arr); + PyObject *res = PyTuple_New(2); + PyObject *obj0=convertMesh(ret, SWIG_POINTER_OWN | 0 ); + PyObject *obj1=0; + if(arr) + obj1=SWIG_NewPointerObj(SWIG_as_voidptr(arr),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + else + obj1=PySlice_New(PyInt_FromLong(a),PyInt_FromLong(b),PyInt_FromLong(b)); + PyTuple_SetItem(res,0,obj0); + PyTuple_SetItem(res,1,obj1); + return res; + } + PyObject *getDistributionOfTypes() const throw(INTERP_KERNEL::Exception) { std::vector vals=self->getDistributionOfTypes(); @@ -944,2015 +969,1360 @@ namespace ParaMEDMEM }; } -%extend ParaMEDMEM::DataArray -{ - PyObject *getInfoOnComponents() const throw(INTERP_KERNEL::Exception) - { - const std::vector& comps=self->getInfoOnComponents(); - PyObject *ret=PyList_New((int)comps.size()); - for(int i=0;i<(int)comps.size();i++) - PyList_SetItem(ret,i,PyString_FromString(comps[i].c_str())); - return ret; - } - - void copyPartOfStringInfoFrom(const DataArray& other, PyObject *li) throw(INTERP_KERNEL::Exception) - { - std::vector tmp; - convertPyToNewIntArr3(li,tmp); - self->copyPartOfStringInfoFrom(other,tmp); - } - - void copyPartOfStringInfoFrom2(PyObject *li, const DataArray& other) throw(INTERP_KERNEL::Exception) - { - std::vector tmp; - convertPyToNewIntArr3(li,tmp); - self->copyPartOfStringInfoFrom2(tmp,other); - } -} - -%extend ParaMEDMEM::DataArrayInt -{ - - std::string __repr__() const throw(INTERP_KERNEL::Exception) - { - std::ostringstream oss; - self->reprQuickOverview(oss); - return oss.str(); - } - - void pushBackValsSilent(PyObject *li) throw(INTERP_KERNEL::Exception) - { - int szArr,sw,iTypppArr; - std::vector stdvecTyyppArr; - const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); - self->pushBackValsSilent(tmp,tmp+szArr); - } +%include "NormalizedUnstructuredMesh.hxx" +%include "MEDCouplingNatureOfField.hxx" +%include "MEDCouplingTimeDiscretization.hxx" +%include "MEDCouplingGaussLocalization.hxx" +%include "MEDCouplingFieldDiscretization.hxx" - PyObject *partitionByDifferentValues() const throw(INTERP_KERNEL::Exception) - { - std::vector ret1; - std::vector ret0=self->partitionByDifferentValues(ret1); - std::size_t sz=ret0.size(); - PyObject *pyRet=PyTuple_New(2); - PyObject *pyRet0=PyList_New((int)sz); - PyObject *pyRet1=PyList_New((int)sz); - for(std::size_t i=0;isearchRangesInListOfIds(listOfIds,ret0,ret1); - PyObject *pyRet=PyTuple_New(2); - PyTuple_SetItem(pyRet,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(pyRet,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return pyRet; - } -} +%ignore ParaMEDMEM::MEDCouplingFieldDiscretization::clonePart; +%ignore ParaMEDMEM::MEDCouplingFieldDiscretization::buildSubMeshDataRange; +%ignore ParaMEDMEM::MEDCouplingFieldDiscretizationPerCell::getArrayOfDiscIds; -%extend ParaMEDMEM::DataArrayChar +namespace ParaMEDMEM { - int __len__() const throw(INTERP_KERNEL::Exception) - { - if(self->isAllocated()) - { - return self->getNumberOfTuples(); - } - else - { - throw INTERP_KERNEL::Exception("DataArrayChar::__len__ : Instance is NOT allocated !"); - } - } - - PyObject *isEqualIfNotWhy(const DataArrayChar& other) const throw(INTERP_KERNEL::Exception) - { - std::string ret1; - bool ret0=self->isEqualIfNotWhy(other,ret1); - PyObject *ret=PyTuple_New(2); - PyObject *ret0Py=ret0?Py_True:Py_False; - Py_XINCREF(ret0Py); - PyTuple_SetItem(ret,0,ret0Py); - PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str())); - return ret; - } - - void renumberInPlace(PyObject *li) throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - self->renumberInPlace(tmp); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - int size=self->getNumberOfTuples(); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - self->renumberInPlace(da2->getConstPointer()); - } - } - - void renumberInPlaceR(PyObject *li) throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - self->renumberInPlaceR(tmp); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - int size=self->getNumberOfTuples(); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - self->renumberInPlaceR(da2->getConstPointer()); - } - } - - DataArrayChar *renumber(PyObject *li) throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - if(size!=self->getNumberOfTuples()) + class MEDCouplingPointSet : public ParaMEDMEM::MEDCouplingMesh + { + public: + void updateTime() const; + void setCoords(const DataArrayDouble *coords) throw(INTERP_KERNEL::Exception); + DataArrayDouble *getCoordinatesAndOwner() const throw(INTERP_KERNEL::Exception); + bool areCoordsEqual(const MEDCouplingPointSet& other, double prec) const throw(INTERP_KERNEL::Exception); + void zipCoords() throw(INTERP_KERNEL::Exception); + double getCaracteristicDimension() const throw(INTERP_KERNEL::Exception); + void recenterForMaxPrecision(double eps) throw(INTERP_KERNEL::Exception); + void changeSpaceDimension(int newSpaceDim, double dftVal=0.) throw(INTERP_KERNEL::Exception); + void tryToShareSameCoords(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception); + virtual MEDCouplingPointSet *buildPartOfMySelf2(int start, int end, int step) const throw(INTERP_KERNEL::Exception); + virtual void tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception); + static DataArrayDouble *MergeNodesArray(const MEDCouplingPointSet *m1, const MEDCouplingPointSet *m2) throw(INTERP_KERNEL::Exception); + static MEDCouplingPointSet *BuildInstanceFromMeshType(MEDCouplingMeshType type) throw(INTERP_KERNEL::Exception); + virtual MEDCouplingPointSet *buildBoundaryMesh(bool keepCoords) const throw(INTERP_KERNEL::Exception); + virtual bool isEmptyMesh(const std::vector& tinyInfo) const throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps) throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *zipCoordsTraducer() throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *findBoundaryNodes() const; + %extend + { + std::string __str__() const throw(INTERP_KERNEL::Exception) { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + return self->simpleRepr(); } - return self->renumber(tmp); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - int size=self->getNumberOfTuples(); - if(size!=self->getNumberOfTuples()) + + PyObject *buildNewNumberingFromCommonNodesFormat(const DataArrayInt *comm, const DataArrayInt *commIndex) const throw(INTERP_KERNEL::Exception) { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + int newNbOfNodes; + DataArrayInt *ret0=self->buildNewNumberingFromCommonNodesFormat(comm,commIndex,newNbOfNodes); + PyObject *res = PyList_New(2); + PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(res,1,SWIG_From_int(newNbOfNodes)); + return res; } - return self->renumber(da2->getConstPointer()); - } - } - - DataArrayChar *renumberR(PyObject *li) throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - if(size!=self->getNumberOfTuples()) + + PyObject *findCommonNodes(double prec, int limitTupleId=-1) const throw(INTERP_KERNEL::Exception) { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + DataArrayInt *comm, *commIndex; + self->findCommonNodes(prec,limitTupleId,comm,commIndex); + PyObject *res = PyList_New(2); + PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(comm),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(res,1,SWIG_NewPointerObj(SWIG_as_voidptr(commIndex),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return res; } - return self->renumberR(tmp); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - int size=self->getNumberOfTuples(); - if(size!=self->getNumberOfTuples()) + + PyObject *getCoords() throw(INTERP_KERNEL::Exception) { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + DataArrayDouble *ret1=self->getCoords(); + if (ret1) + ret1->incrRef(); + return SWIG_NewPointerObj((void*)ret1,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,SWIG_POINTER_OWN | 0); } - return self->renumberR(da2->getConstPointer()); - } - } - - DataArrayChar *renumberAndReduce(PyObject *li, int newNbOfTuple) throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - if(size!=self->getNumberOfTuples()) + + PyObject *buildPartOfMySelf(PyObject *li, bool keepCoords=true) const throw(INTERP_KERNEL::Exception) { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + int szArr,sw,iTypppArr; + std::vector stdvecTyyppArr; + const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); + MEDCouplingPointSet *ret=self->buildPartOfMySelf(tmp,tmp+szArr,keepCoords); + if(sw==3)//DataArrayInt + { + void *argp; SWIG_ConvertPtr(li,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0); + DataArrayInt *argpt=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp); + std::string name=argpt->getName(); + if(!name.empty()) + ret->setName(name.c_str()); + } + return convertMesh(ret, SWIG_POINTER_OWN | 0 ); } - return self->renumberAndReduce(tmp,newNbOfTuple); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - int size=self->getNumberOfTuples(); - if(size!=self->getNumberOfTuples()) + + PyObject *buildPartOfMySelfNode(PyObject *li, bool fullyIn) const throw(INTERP_KERNEL::Exception) { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + int szArr,sw,iTypppArr; + std::vector stdvecTyyppArr; + const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); + MEDCouplingPointSet *ret=self->buildPartOfMySelfNode(tmp,tmp+szArr,fullyIn); + if(sw==3)//DataArrayInt + { + void *argp; SWIG_ConvertPtr(li,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0); + DataArrayInt *argpt=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp); + std::string name=argpt->getName(); + if(!name.empty()) + ret->setName(name.c_str()); + } + return convertMesh(ret, SWIG_POINTER_OWN | 0 ); } - return self->renumberAndReduce(da2->getConstPointer(),newNbOfTuple); - } - } - - DataArrayChar *selectByTupleIdSafe(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - return self->selectByTupleIdSafe(tmp,tmp+size); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - return self->selectByTupleIdSafe(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); - } - } - - DataArrayChar *keepSelectedComponents(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - std::vector tmp; - convertPyToNewIntArr3(li,tmp); - return self->keepSelectedComponents(tmp); - } - - static DataArrayChar *Aggregate(PyObject *dachs) throw(INTERP_KERNEL::Exception) - { - std::vector tmp; - convertFromPyObjVectorOfObj(dachs,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,"DataArrayChar",tmp); - return DataArrayChar::Aggregate(tmp); - } - - static DataArrayChar *Meld(PyObject *dachs) throw(INTERP_KERNEL::Exception) - { - std::vector tmp; - convertFromPyObjVectorOfObj(dachs,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,"DataArrayChar",tmp); - return DataArrayChar::Meld(tmp); - } -} - -%extend ParaMEDMEM::DataArrayByteTuple -{ - std::string __str__() const - { - return self->repr(); - } - char __int__() const throw(INTERP_KERNEL::Exception) - { - return self->byteValue(); - } - - DataArrayByte *buildDAByte() - { - return self->buildDAByte(1,self->getNumberOfCompo()); - } -} - -%extend ParaMEDMEM::DataArrayByteIterator -{ - PyObject *next() - { - DataArrayByteTuple *ret=self->nextt(); - if(ret) - return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayByteTuple,SWIG_POINTER_OWN | 0); - else - { - PyErr_SetString(PyExc_StopIteration,"No more data."); - return 0; - } - } -} - -%extend ParaMEDMEM::DataArrayByte -{ - DataArrayByte() throw(INTERP_KERNEL::Exception) - { - return DataArrayByte::New(); - } - - static DataArrayByte *New(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) - { - const char *msg="ParaMEDMEM::DataArrayByte::New : Available API are : \n-DataArrayByte.New()\n--DataArrayByte.New([1,3,4])\n-DataArrayByte.New([1,3,4],3)\n-DataArrayByte.New([1,3,4,5],2,2)\n-DataArrayByte.New(5)\n-DataArrayByte.New(5,2) !"; - if(PyList_Check(elt0) || PyTuple_Check(elt0)) - { - if(nbOfTuples) + PyObject *buildFacePartOfMySelfNode(PyObject *li, bool fullyIn) const throw(INTERP_KERNEL::Exception) { - if(PyInt_Check(nbOfTuples)) - { - int nbOfTuples1=PyInt_AS_LONG(nbOfTuples); - if(nbOfTuples1<0) - throw INTERP_KERNEL::Exception("DataArrayByte::New : should be a positive set of allocated memory !"); - if(nbOfComp) - { - if(PyInt_Check(nbOfComp)) - {//DataArrayByte.New([1,3,4,5],2,2) - int nbOfCompo=PyInt_AS_LONG(nbOfComp); - if(nbOfCompo<0) - throw INTERP_KERNEL::Exception("DataArrayByte::New : should be a positive number of components !"); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayByte::New(); - std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,nbOfCompo); - ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - return ret.retn(); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - {//DataArrayByte.New([1,3,4],3) - MEDCouplingAutoRefCountObjectPtr ret=DataArrayByte::New(); - int tmpp1=-1; - std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,tmpp1); - ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - return ret.retn(); - } + int szArr,sw,iTypppArr; + std::vector stdvecTyyppArr; + const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); + MEDCouplingPointSet *ret=self->buildFacePartOfMySelfNode(tmp,tmp+szArr,fullyIn); + if(sw==3)//DataArrayInt + { + void *argp; SWIG_ConvertPtr(li,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0); + DataArrayInt *argpt=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp); + std::string name=argpt->getName(); + if(!name.empty()) + ret->setName(name.c_str()); } - else - throw INTERP_KERNEL::Exception(msg); - } - else - {// DataArrayByte.New([1,3,4]) - MEDCouplingAutoRefCountObjectPtr ret=DataArrayByte::New(); - int tmpp1=-1,tmpp2=-1; - std::vector tmp=fillArrayWithPyListInt2(elt0,tmpp1,tmpp2); - ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - return ret.retn(); + return convertMesh(ret, SWIG_POINTER_OWN | 0 ); } - } - else if(PyInt_Check(elt0)) - { - int nbOfTuples1=PyInt_AS_LONG(elt0); - if(nbOfTuples1<0) - throw INTERP_KERNEL::Exception("DataArrayByte::New : should be a positive set of allocated memory !"); - if(nbOfTuples) + + void renumberNodes(PyObject *li, int newNbOfNodes) throw(INTERP_KERNEL::Exception) { - if(!nbOfComp) - { - if(PyInt_Check(nbOfTuples)) - {//DataArrayByte.New(5,2) - int nbOfCompo=PyInt_AS_LONG(nbOfTuples); - if(nbOfCompo<0) - throw INTERP_KERNEL::Exception("DataArrayByte::New : should be a positive number of components !"); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayByte::New(); - ret->alloc(nbOfTuples1,nbOfCompo); - return ret.retn(); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - {//DataArrayByte.New(5) - MEDCouplingAutoRefCountObjectPtr ret=DataArrayByte::New(); - ret->alloc(nbOfTuples1,1); - return ret.retn(); + int szArr,sw,iTypppArr; + std::vector stdvecTyyppArr; + const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); + self->renumberNodes(tmp,newNbOfNodes); } - } - else - throw INTERP_KERNEL::Exception(msg); - } - - DataArrayByte(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) - { - return ParaMEDMEM_DataArrayByte_New__SWIG_1(elt0,nbOfTuples,nbOfComp); - } - - std::string __repr__() const throw(INTERP_KERNEL::Exception) - { - std::ostringstream oss; - self->reprQuickOverview(oss); - return oss.str(); - } - - int __int__() const throw(INTERP_KERNEL::Exception) - { - return (int) self->byteValue(); - } - - DataArrayByteIterator *__iter__() throw(INTERP_KERNEL::Exception) - { - return self->iterator(); - } - - int getIJ(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception) - { - return (int)self->getIJ(tupleId,compoId); - } - - int getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception) - { - return (int)self->getIJSafe(tupleId,compoId); - } - - std::string __str__() const throw(INTERP_KERNEL::Exception) - { - return self->repr(); - } - - PyObject *toStrList() const throw(INTERP_KERNEL::Exception) - { - const char *vals=self->getConstPointer(); - int nbOfComp=self->getNumberOfComponents(); - int nbOfTuples=self->getNumberOfTuples(); - return convertCharArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); - } - - bool presenceOfTuple(PyObject *tupl) const throw(INTERP_KERNEL::Exception) - { - int sz=-1,sw=-1; - int ival=-1; std::vector ivval; - const int *pt=convertObjToPossibleCpp1_Safe(tupl,sw,sz,ival,ivval); - std::vector vals(sz); - std::copy(pt,pt+sz,vals.begin()); - return self->presenceOfTuple(vals); - } - - bool presenceOfValue(PyObject *vals) const throw(INTERP_KERNEL::Exception) - { - int sz=-1,sw=-1; - int ival=-1; std::vector ivval; - const int *pt=convertObjToPossibleCpp1_Safe(vals,sw,sz,ival,ivval); - std::vector vals2(sz); - std::copy(pt,pt+sz,vals2.begin()); - return self->presenceOfValue(vals2); - } - - int locateValue(PyObject *vals) const throw(INTERP_KERNEL::Exception) - { - int sz=-1,sw=-1; - int ival=-1; std::vector ivval; - const int *pt=convertObjToPossibleCpp1_Safe(vals,sw,sz,ival,ivval); - std::vector vals2(sz); - std::copy(pt,pt+sz,vals2.begin()); - return self->locateValue(vals2); - } - - int locateTuple(PyObject *tupl) const throw(INTERP_KERNEL::Exception) - { - int sz=-1,sw=-1; - int ival=-1; std::vector ivval; - const int *pt=convertObjToPossibleCpp1_Safe(tupl,sw,sz,ival,ivval); - std::vector vals(sz); - std::copy(pt,pt+sz,vals.begin()); - return self->locateTuple(vals); - } - - int search(PyObject *strOrListOfInt) const throw(INTERP_KERNEL::Exception) - { - int sz=-1,sw=-1; - int ival=-1; std::vector ivval; - const int *pt=convertObjToPossibleCpp1_Safe(strOrListOfInt,sw,sz,ival,ivval); - std::vector vals(sz); - std::copy(pt,pt+sz,vals.begin()); - return self->search(vals); - } - - PyObject *getTuple(int tupleId) throw(INTERP_KERNEL::Exception) - { - int sz=self->getNumberOfComponents(); - INTERP_KERNEL::AutoPtr tmp=new char[sz]; - self->getTuple(tupleId,tmp); - PyObject *ret=PyTuple_New(sz); - for(int i=0;igetMaxValue(tmp); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,PyInt_FromLong(r1)); - PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); - return ret; - } - - PyObject *getMinValue() const throw(INTERP_KERNEL::Exception) - { - int tmp; - int r1=(int)self->getMinValue(tmp); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,PyInt_FromLong(r1)); - PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); - return ret; - } - - int index(PyObject *obj) const throw(INTERP_KERNEL::Exception) - { - int nbOfCompo=self->getNumberOfComponents(); - switch(nbOfCompo) - { - case 1: + + void renumberNodes2(PyObject *li, int newNbOfNodes) throw(INTERP_KERNEL::Exception) { - if(PyInt_Check(obj)) - { - int val=(int)PyInt_AS_LONG(obj); - return self->locateValue(val); - } - else - throw INTERP_KERNEL::Exception("DataArrayByte::index : 'this' contains one component and trying to find an element which is not an integer !"); + int szArr,sw,iTypppArr; + std::vector stdvecTyyppArr; + const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); + self->renumberNodes2(tmp,newNbOfNodes); } - default: - return ParaMEDMEM_DataArrayByte_locateTuple(self,obj); - } - } - bool __contains__(PyObject *obj) const throw(INTERP_KERNEL::Exception) - { - int nbOfCompo=self->getNumberOfComponents(); - switch(nbOfCompo) - { - case 0: - return false; - case 1: - { - if(PyInt_Check(obj)) + PyObject *findNodesOnLine(PyObject *pt, PyObject *vec, double eps) const throw(INTERP_KERNEL::Exception) { - int val=(int)PyInt_AS_LONG(obj); - return self->presenceOfValue(val); - } - else - throw INTERP_KERNEL::Exception("DataArrayByte::__contains__ : 'this' contains one component and trying to find an element which is not an integer !"); - } - default: - return ParaMEDMEM_DataArrayByte_presenceOfTuple(self,obj); - } - } -} + int spaceDim=self->getSpaceDimension(); + double val,val2; + DataArrayDouble *a,*a2; + DataArrayDoubleTuple *aa,*aa2; + std::vector bb,bb2; + int sw; + const char msg[]="Python wrap of MEDCouplingPointSet::findNodesOnLine : 1st paramater for point."; + const char msg2[]="Python wrap of MEDCouplingPointSet::findNodesOnLine : 2nd paramater for vector."; + const double *p=convertObjToPossibleCpp5_Safe(pt,sw,val,a,aa,bb,msg,1,spaceDim,true); + const double *v=convertObjToPossibleCpp5_Safe(vec,sw,val2,a2,aa2,bb2,msg2,1,spaceDim,true); + std::vector nodes; + self->findNodesOnLine(p,v,eps,nodes); + DataArrayInt *ret=DataArrayInt::New(); + ret->alloc((int)nodes.size(),1); + std::copy(nodes.begin(),nodes.end(),ret->getPointer()); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + PyObject *findNodesOnPlane(PyObject *pt, PyObject *vec, double eps) const throw(INTERP_KERNEL::Exception) + { + int spaceDim=self->getSpaceDimension(); + double val,val2; + DataArrayDouble *a,*a2; + DataArrayDoubleTuple *aa,*aa2; + std::vector bb,bb2; + int sw; + const char msg[]="Python wrap of MEDCouplingPointSet::findNodesOnPlane : 1st paramater for point."; + const char msg2[]="Python wrap of MEDCouplingPointSet::findNodesOnPlane : 2nd paramater for vector."; + const double *p=convertObjToPossibleCpp5_Safe(pt,sw,val,a,aa,bb,msg,1,spaceDim,true); + const double *v=convertObjToPossibleCpp5_Safe(vec,sw,val2,a2,aa2,bb2,msg2,1,spaceDim,true); + std::vector nodes; + self->findNodesOnPlane(p,v,eps,nodes); + DataArrayInt *ret=DataArrayInt::New(); + ret->alloc((int)nodes.size(),1); + std::copy(nodes.begin(),nodes.end(),ret->getPointer()); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + + PyObject *getNodeIdsNearPoint(PyObject *pt, double eps) const throw(INTERP_KERNEL::Exception) + { + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + int spaceDim=self->getSpaceDimension(); + const char msg[]="Python wrap of MEDCouplingPointSet::getNodeIdsNearPoint : "; + const double *pos=convertObjToPossibleCpp5_Safe(pt,sw,val,a,aa,bb,msg,1,spaceDim,true); + DataArrayInt *ret=self->getNodeIdsNearPoint(pos,eps); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } -%extend ParaMEDMEM::DataArrayAsciiCharTuple -{ - std::string __str__() const - { - return self->repr(); - } + PyObject *getNodeIdsNearPoints(PyObject *pt, int nbOfPoints, double eps) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *c=0,*cI=0; + // + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + int spaceDim=self->getSpaceDimension(); + const char msg[]="Python wrap of MEDCouplingPointSet::getNodeIdsNearPoints : "; + const double *pos=convertObjToPossibleCpp5_Safe(pt,sw,val,a,aa,bb,msg,nbOfPoints,spaceDim,true); + self->getNodeIdsNearPoints(pos,nbOfPoints,eps,c,cI); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(c),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cI),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } - DataArrayAsciiChar *buildDAAsciiChar() - { - return self->buildDAAsciiChar(1,self->getNumberOfCompo()); - } -} + PyObject *getNodeIdsNearPoints(PyObject *pt, double eps) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *c=0,*cI=0; + int spaceDim=self->getSpaceDimension(); + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + int nbOfTuples=-1; + const double *ptPtr=convertObjToPossibleCpp5_Safe2(pt,sw,val,a,aa,bb,"Python wrap of MEDCouplingUMesh::getNodeIdsNearPoints",spaceDim,true,nbOfTuples); + self->getNodeIdsNearPoints(ptPtr,nbOfTuples,eps,c,cI); + // + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(c),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cI),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } -%extend ParaMEDMEM::DataArrayAsciiCharIterator -{ - PyObject *next() - { - DataArrayAsciiCharTuple *ret=self->nextt(); - if(ret) - return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiCharTuple,SWIG_POINTER_OWN | 0); - else - { - PyErr_SetString(PyExc_StopIteration,"No more data."); - return 0; - } - } -} + PyObject *getCellsInBoundingBox(PyObject *bbox, double eps) const throw(INTERP_KERNEL::Exception) + { + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + int spaceDim=self->getSpaceDimension(); + const char msg[]="Python wrap of MEDCouplingPointSet::getCellsInBoundingBox : "; + const double *tmp=convertObjToPossibleCpp5_Safe(bbox,sw,val,a,aa,bb,msg,spaceDim,2,true); + // + DataArrayInt *elems=self->getCellsInBoundingBox(tmp,eps); + return SWIG_NewPointerObj(SWIG_as_voidptr(elems),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } -%extend ParaMEDMEM::DataArrayAsciiChar -{ - DataArrayAsciiChar() throw(INTERP_KERNEL::Exception) - { - return DataArrayAsciiChar::New(); - } - - static DataArrayAsciiChar *New(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) - { - const char *msg="ParaMEDMEM::DataArrayAsciiChar::New : Available API are : \n-DataArrayAsciiChar.New()\n-DataArrayAsciiChar.New([1,3,4])\n-DataArrayAsciiChar.New([\"abc\",\"de\",\"fghi\"])\n-DataArrayAsciiChar.New([\"abc\",\"de\",\"fghi\"],\"t\")\n-DataArrayAsciiChar.New([1,3,4],3)\n-DataArrayAsciiChar.New([1,3,4,5],2,2)\n-DataArrayAsciiChar.New(5)\n-DataArrayAsciiChar.New(5,2) !"; - if(PyList_Check(elt0) || PyTuple_Check(elt0)) - { - if(nbOfTuples) + void duplicateNodesInCoords(PyObject *li) throw(INTERP_KERNEL::Exception) { - if(PyInt_Check(nbOfTuples)) - { - int nbOfTuples1=PyInt_AS_LONG(nbOfTuples); - if(nbOfTuples1<0) - throw INTERP_KERNEL::Exception("DataArrayAsciiChar::New : should be a positive set of allocated memory !"); - if(nbOfComp) - { - if(PyInt_Check(nbOfComp)) - {//DataArrayAsciiChar.New([1,3,4,5],2,2) - int nbOfCompo=PyInt_AS_LONG(nbOfComp); - if(nbOfCompo<0) - throw INTERP_KERNEL::Exception("DataArrayAsciiChar::New : should be a positive number of components !"); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); - std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,nbOfCompo); - ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - return ret.retn(); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - {//DataArrayAsciiChar.New([1,3,4],3) - MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); - int tmpp1=-1; - std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,tmpp1); - ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - return ret.retn(); - } - } - else if(PyString_Check(nbOfTuples)) + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + convertObjToPossibleCpp2(li,self->getNumberOfNodes(),sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) { - if(PyString_Size(nbOfTuples)!=1) - throw INTERP_KERNEL::Exception(msg); - //DataArrayAsciiChar.New(["abc","de","fghi"],"t") - std::vector tmp; - if(fillStringVector(elt0,tmp)) - return DataArrayAsciiChar::New(tmp,PyString_AsString(nbOfTuples)[0]); - else - throw INTERP_KERNEL::Exception(msg); + case 1: + return self->duplicateNodesInCoords(&singleVal,&singleVal+1); + case 2: + return self->duplicateNodesInCoords(&multiVal[0],&multiVal[0]+multiVal.size()); + case 4: + return self->duplicateNodesInCoords(daIntTyypp->begin(),daIntTyypp->end()); + default: + throw INTERP_KERNEL::Exception("MEDCouplingPointSet::duplicateNodesInCoords : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); } - else - throw INTERP_KERNEL::Exception(msg); } - else + + static void Rotate2DAlg(PyObject *center, double angle, int nbNodes, PyObject *coords) throw(INTERP_KERNEL::Exception) { - std::vector tmmp; - if(fillStringVector(elt0,tmmp)) - //DataArrayAsciiChar.New(["abc","de","fghi"]) - return DataArrayAsciiChar::New(tmmp,' '); - else - { - // DataArrayAsciiChar.New([1,3,4]) - MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); - int tmpp1=-1,tmpp2=-1; - std::vector tmp=fillArrayWithPyListInt2(elt0,tmpp1,tmpp2); - ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - return ret.retn(); - } + int sz; + INTERP_KERNEL::AutoPtr c=convertPyToNewDblArr2(center,&sz); + INTERP_KERNEL::AutoPtr coo=convertPyToNewDblArr2(coords,&sz); + ParaMEDMEM::MEDCouplingPointSet::Rotate2DAlg(c,angle,nbNodes,coo); + for(int i=0;i ret=DataArrayAsciiChar::New(); - ret->alloc(nbOfTuples1,nbOfCompo); - return ret.retn(); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - throw INTERP_KERNEL::Exception(msg); + int sz; + INTERP_KERNEL::AutoPtr c=convertPyToNewDblArr2(center,&sz); + int sw,nbNodes=0; + double val0; ParaMEDMEM::DataArrayDouble *val1=0; ParaMEDMEM::DataArrayDoubleTuple *val2=0; + std::vector val3; + const double *coo=convertObjToPossibleCpp5_Safe2(coords,sw,val0,val1,val2,val3, + "Rotate2DAlg",2,true,nbNodes); + if(sw!=2 && sw!=3) + throw INTERP_KERNEL::Exception("Invalid call to MEDCouplingPointSet::Rotate2DAlg : try another overload method !"); + ParaMEDMEM::MEDCouplingPointSet::Rotate2DAlg(c,angle,nbNodes,const_cast(coo)); } - else - {//DataArrayAsciiChar.New(5) - MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); - ret->alloc(nbOfTuples1,1); - return ret.retn(); + + static void Rotate3DAlg(PyObject *center, PyObject *vect, double angle, int nbNodes, PyObject *coords) throw(INTERP_KERNEL::Exception) + { + int sz,sz2; + INTERP_KERNEL::AutoPtr c=convertPyToNewDblArr2(center,&sz); + INTERP_KERNEL::AutoPtr coo=convertPyToNewDblArr2(coords,&sz); + INTERP_KERNEL::AutoPtr v=convertPyToNewDblArr2(vect,&sz2); + ParaMEDMEM::MEDCouplingPointSet::Rotate3DAlg(c,v,angle,nbNodes,coo); + for(int i=0;ireprQuickOverview(oss); - return oss.str(); - } - - DataArrayAsciiCharIterator *__iter__() throw(INTERP_KERNEL::Exception) - { - return self->iterator(); - } - - std::string getIJ(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception) - { - char tmp[2]; tmp[1]='\0'; - tmp[0]=self->getIJ(tupleId,compoId); - return std::string(tmp); - } - - std::string getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception) - { - char tmp[2]; tmp[1]='\0'; - tmp[0]=self->getIJSafe(tupleId,compoId); - return std::string(tmp); - } - - std::string __str__() const throw(INTERP_KERNEL::Exception) - { - return self->repr(); - } - - PyObject *toStrList() const throw(INTERP_KERNEL::Exception) - { - const char *vals=self->getConstPointer(); - int nbOfComp=self->getNumberOfComponents(); - int nbOfTuples=self->getNumberOfTuples(); - return convertCharArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); - } - - bool presenceOfTuple(PyObject *tupl) const throw(INTERP_KERNEL::Exception) - { - if(PyString_Check(tupl)) - { - Py_ssize_t sz=PyString_Size(tupl); - std::vector vals(sz); - std::copy(PyString_AsString(tupl),PyString_AsString(tupl)+sz,vals.begin()); - return self->presenceOfTuple(vals); - } - else - throw INTERP_KERNEL::Exception("DataArrayAsciiChar::presenceOfTuple : only strings in input supported !"); - } - - bool presenceOfValue(PyObject *vals) const throw(INTERP_KERNEL::Exception) - { - if(PyString_Check(vals)) - { - Py_ssize_t sz=PyString_Size(vals); - std::vector vals2(sz); - std::copy(PyString_AsString(vals),PyString_AsString(vals)+sz,vals2.begin()); - return self->presenceOfValue(vals2); - } - else - throw INTERP_KERNEL::Exception("DataArrayAsciiChar::presenceOfValue : only strings in input supported !"); - } + + static void Rotate3DAlg(PyObject *center, PyObject *vect, double angle, PyObject *coords) throw(INTERP_KERNEL::Exception) + { + int sz,sz2; + INTERP_KERNEL::AutoPtr c=convertPyToNewDblArr2(center,&sz); + int sw,nbNodes=0; + double val0; ParaMEDMEM::DataArrayDouble *val1=0; ParaMEDMEM::DataArrayDoubleTuple *val2=0; + std::vector val3; + const double *coo=convertObjToPossibleCpp5_Safe2(coords,sw,val0,val1,val2,val3, + "Rotate3DAlg",3,true,nbNodes); + if(sw!=2 && sw!=3) + throw INTERP_KERNEL::Exception("Invalid call to MEDCouplingPointSet::Rotate3DAlg : try another overload method !"); + INTERP_KERNEL::AutoPtr v=convertPyToNewDblArr2(vect,&sz2); + ParaMEDMEM::MEDCouplingPointSet::Rotate3DAlg(c,v,angle,nbNodes,const_cast(coo)); + } + } + }; - int locateValue(PyObject *vals) const throw(INTERP_KERNEL::Exception) - { - if(PyString_Check(vals)) - { - Py_ssize_t sz=PyString_Size(vals); - std::vector vals2(sz); - std::copy(PyString_AsString(vals),PyString_AsString(vals)+sz,vals2.begin()); - return self->locateValue(vals2); - } - else - throw INTERP_KERNEL::Exception("DataArrayAsciiChar::locateValue : only strings in input supported !"); - } + class MEDCouplingUMeshCell + { + public: + INTERP_KERNEL::NormalizedCellType getType() const; + %extend + { + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->repr(); + } - int locateTuple(PyObject *tupl) const throw(INTERP_KERNEL::Exception) - { - if(PyString_Check(tupl)) - { - Py_ssize_t sz=PyString_Size(tupl); - std::vector vals(sz); - std::copy(PyString_AsString(tupl),PyString_AsString(tupl)+sz,vals.begin()); - return self->locateTuple(vals); - } - else - throw INTERP_KERNEL::Exception("DataArrayAsciiChar::locateTuple : only strings in input supported !"); - } + PyObject *getAllConn() const throw(INTERP_KERNEL::Exception) + { + int ret2; + const int *r=self->getAllConn(ret2); + PyObject *ret=PyTuple_New(ret2); + for(int i=0;i vals(sz); - std::copy(PyString_AsString(strOrListOfInt),PyString_AsString(strOrListOfInt)+sz,vals.begin()); - return self->search(vals); - } - else - throw INTERP_KERNEL::Exception("DataArrayAsciiChar::search : only strings in input supported !"); - } - - PyObject *getTuple(int tupleId) const throw(INTERP_KERNEL::Exception) - { - int sz=self->getNumberOfComponents(); - INTERP_KERNEL::AutoPtr tmp=new char[sz+1]; tmp[sz]='\0'; - self->getTuple(tupleId,tmp); - return PyString_FromString(tmp); - } - - PyObject *getMaxValue() const throw(INTERP_KERNEL::Exception) - { - int tmp; - char tmp2[2]; tmp2[1]='\0'; - tmp2[0]=self->getMaxValue(tmp); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,PyString_FromString(tmp2)); - PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); - return ret; - } - - PyObject *getMinValue() const throw(INTERP_KERNEL::Exception) - { - int tmp; - char tmp2[2]; tmp2[1]='\0'; - tmp2[0]=self->getMinValue(tmp); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,PyString_FromString(tmp2)); - PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); - return ret; - } - - int index(PyObject *obj) const throw(INTERP_KERNEL::Exception) - { - int nbOfCompo=self->getNumberOfComponents(); - switch(nbOfCompo) - { - case 1: - { - if(PyString_Check(obj)) - { - Py_ssize_t sz=PyString_Size(obj); - char *pt=PyString_AsString(obj); - if(sz==1) - return self->locateValue(pt[0]); - else - throw INTERP_KERNEL::Exception("DataArrayAsciiChar::index : 'this' contains one component and trying to find a string with size different from 1 !"); - } - else - throw INTERP_KERNEL::Exception("DataArrayAsciiChar::index : 'this' contains one component and trying to find an element which is not an integer !"); - } - default: - return ParaMEDMEM_DataArrayAsciiChar_locateTuple(self,obj); - } - } + class MEDCouplingUMeshCellIterator + { + public: + %extend + { + PyObject *next() + { + MEDCouplingUMeshCell *ret=self->nextt(); + if(ret) + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMeshCell,0|0); + else + { + PyErr_SetString(PyExc_StopIteration,"No more data."); + return 0; + } + } + } + }; - bool __contains__(PyObject *obj) const throw(INTERP_KERNEL::Exception) - { - int nbOfCompo=self->getNumberOfComponents(); - switch(nbOfCompo) - { - case 0: - return false; - case 1: - { - if(PyString_Check(obj)) - { - Py_ssize_t sz=PyString_Size(obj); - char *pt=PyString_AsString(obj); - if(sz==1) - return self->presenceOfValue(pt[0]); - else - throw INTERP_KERNEL::Exception("DataArrayAsciiChar::__contains__ : 'this' contains one component and trying to find a string with size different from 1 !"); - } - else - throw INTERP_KERNEL::Exception("DataArrayAsciiChar::__contains__ : 'this' contains one component and trying to find an element which is not an integer !"); - } - default: - return ParaMEDMEM_DataArrayAsciiChar_presenceOfTuple(self,obj); - } - } - - PyObject *__getitem__(PyObject *obj) const throw(INTERP_KERNEL::Exception) - { - int sw,iTypppArr; - std::vector stdvecTyyppArr; - std::pair > sTyyppArr; - ParaMEDMEM::DataArrayInt *daIntTyypp=0; - convertObjToPossibleCpp2(obj,self->getNumberOfTuples(),sw,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp); - switch(sw) - { - case 1: - return ParaMEDMEM_DataArrayAsciiChar_getTuple(self,iTypppArr); - case 2: - return convertDataArrayChar(self->selectByTupleIdSafe(&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size()), SWIG_POINTER_OWN | 0 ); - case 3: - return convertDataArrayChar(self->selectByTupleId2(sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second), SWIG_POINTER_OWN | 0 ); - case 4: - return convertDataArrayChar(self->selectByTupleIdSafe(daIntTyypp->begin(),daIntTyypp->end()), SWIG_POINTER_OWN | 0 ); - default: - throw INTERP_KERNEL::Exception("DataArrayAsciiChar::__getitem__ : supporting int, list of int, tuple of int, DataArrayInt and slice in input !"); - } - } - - DataArrayAsciiChar *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception) - { - static const char msg[]="DataArrayAsciiChar::__setitem__ : supporting int, list of int, tuple of int, DataArrayInt and slice in input, and 4 types accepted in value : string, list or tuple of strings having same size, not null DataArrayChar instance."; - int sw1,iTypppArr; - std::vector stdvecTyyppArr; - std::pair > sTyyppArr; - ParaMEDMEM::DataArrayInt *daIntTyypp=0; - int nbOfCompo=self->getNumberOfComponents(); - int nbOfTuples=self->getNumberOfTuples(); - convertObjToPossibleCpp2(obj,nbOfTuples,sw1,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp); - int sw2; - char vc; std::string sc; std::vector vsc; DataArrayChar *dacc=0; - convertObjToPossibleCpp6(value,sw2,vc,sc,vsc,dacc); - switch(sw1) - { - case 1: - {//obj int - switch(sw2) - {//value char - case 1: - { - self->setPartOfValuesSimple3(vc,&iTypppArr,&iTypppArr+1,0,nbOfCompo,1); - return self; - } - //value string - case 2: - { - MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(sc); - self->setPartOfValues3(tmp,&iTypppArr,&iTypppArr+1,0,nbOfCompo,1,false); - return self; - } - //value vector - case 3: - { - MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(vsc,' '); - self->setPartOfValues3(tmp,&iTypppArr,&iTypppArr+1,0,nbOfCompo,1,false); - return self; - } - //value DataArrayChar - case 4: - { - self->setPartOfValues3(dacc,&iTypppArr,&iTypppArr+1,0,nbOfCompo,1,false); - return self; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - case 2: - {//obj list-tuple[int] - switch(sw2) - { - {//value char - case 1: - { - self->setPartOfValuesSimple3(vc,&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size(),0,nbOfCompo,1); - return self; - } - //value string - case 2: - { - MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(sc); - self->setPartOfValues3(tmp,&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size(),0,nbOfCompo,1,false); - return self; - } - //value vector - case 3: - { - MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(vsc,' '); - self->setPartOfValues3(tmp,&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size(),0,nbOfCompo,1,false); - return self; - } - //value DataArrayChar - case 4: - { - self->setPartOfValues3(dacc,&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size(),0,nbOfCompo,1,false); - return self; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - } - case 3: - {//slice - switch(sw2) - { - {//value char - case 1: - { - self->setPartOfValuesSimple1(vc,sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second,0,nbOfCompo,1); - return self; - } - //value string - case 2: - { - MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(sc); - self->setPartOfValues1(tmp,sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second,0,nbOfCompo,1,false); - return self; - } - //value vector - case 3: - { - MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(vsc,' '); - self->setPartOfValues1(tmp,sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second,0,nbOfCompo,1,false); - return self; - } - //value DataArrayChar - case 4: - { - self->setPartOfValues1(dacc,sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second,0,nbOfCompo,1,false); - return self; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - } - case 4: - {//DataArrayInt - switch(sw2) - { - {//value char - case 1: - { - self->setPartOfValuesSimple3(vc,daIntTyypp->begin(),daIntTyypp->end(),0,nbOfCompo,1); - return self; - } - //value string - case 2: - { - MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(sc); - self->setPartOfValues3(tmp,daIntTyypp->begin(),daIntTyypp->end(),0,nbOfCompo,1,false); - return self; - } - //value vector - case 3: - { - MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(vsc,' '); - self->setPartOfValues3(tmp,daIntTyypp->begin(),daIntTyypp->end(),0,nbOfCompo,1,false); - return self; - } - //value DataArrayChar - case 4: - { - self->setPartOfValues3(dacc,daIntTyypp->begin(),daIntTyypp->end(),0,nbOfCompo,1,false); - return self; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } -} - -%ignore ParaMEDMEM::DataArray::getInfoOnComponents; -%ignore ParaMEDMEM::DataArrayInt::partitionByDifferentValues; -%ignore ParaMEDMEM::DataArrayChar::getIJ; -%ignore ParaMEDMEM::DataArrayChar::getIJSafe; -%ignore ParaMEDMEM::DataArrayChar::search; -%ignore ParaMEDMEM::DataArrayChar::locateValue; -%ignore ParaMEDMEM::DataArrayChar::presenceOfValue; + class MEDCouplingUMeshCellByTypeIterator + { + public: + ~MEDCouplingUMeshCellByTypeIterator(); + %extend + { + PyObject *next() + { + MEDCouplingUMeshCellEntry *ret=self->nextt(); + if(ret) + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMeshCellEntry,SWIG_POINTER_OWN | 0); + else + { + PyErr_SetString(PyExc_StopIteration,"No more data."); + return 0; + } + } + } + }; -%include "MEDCouplingMemArray.hxx" -%include "NormalizedUnstructuredMesh.hxx" -%include "MEDCouplingNatureOfField.hxx" -%include "MEDCouplingTimeDiscretization.hxx" -%include "MEDCouplingGaussLocalization.hxx" -%include "MEDCouplingFieldDiscretization.hxx" + class MEDCouplingUMeshCellByTypeEntry + { + public: + ~MEDCouplingUMeshCellByTypeEntry(); + %extend + { + MEDCouplingUMeshCellByTypeIterator *__iter__() + { + return self->iterator(); + } + } + }; -%ignore ParaMEDMEM::MEDCouplingFieldDiscretization::clonePart; -%ignore ParaMEDMEM::MEDCouplingFieldDiscretizationPerCell::getArrayOfDiscIds; + class MEDCouplingUMeshCellEntry + { + public: + INTERP_KERNEL::NormalizedCellType getType() const; + int getNumberOfElems() const; + %extend + { + MEDCouplingUMeshCellIterator *__iter__() + { + return self->iterator(); + } + } + }; + + class MEDCouplingUMesh : public ParaMEDMEM::MEDCouplingPointSet + { + public: + static MEDCouplingUMesh *New() throw(INTERP_KERNEL::Exception); + static MEDCouplingUMesh *New(const char *meshName, int meshDim) throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *clone(bool recDeepCpy) const; + void updateTime() const; + void checkCoherency() const throw(INTERP_KERNEL::Exception); + void setMeshDimension(int meshDim) throw(INTERP_KERNEL::Exception); + void allocateCells(int nbOfCells=0) throw(INTERP_KERNEL::Exception); + void finishInsertingCells() throw(INTERP_KERNEL::Exception); + MEDCouplingUMeshCellByTypeEntry *cellsByType() throw(INTERP_KERNEL::Exception); + void setConnectivity(DataArrayInt *conn, DataArrayInt *connIndex, bool isComputingTypes=true) throw(INTERP_KERNEL::Exception); + INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const throw(INTERP_KERNEL::Exception); + void setPartOfMySelf2(int start, int end, int step, const MEDCouplingUMesh& otherOnSameCoordsThanThis) throw(INTERP_KERNEL::Exception); + int getNumberOfNodesInCell(int cellId) const throw(INTERP_KERNEL::Exception); + int getMeshLength() const throw(INTERP_KERNEL::Exception); + void computeTypes() throw(INTERP_KERNEL::Exception); + std::string reprConnectivityOfThis() const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception); + //tools + void shiftNodeNumbersInConn(int delta) throw(INTERP_KERNEL::Exception); + std::vector getQuadraticStatus() const throw(INTERP_KERNEL::Exception); + DataArrayInt *findCellIdsOnBoundary() const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *computeSkin() const throw(INTERP_KERNEL::Exception); + bool checkConsecutiveCellTypes() const throw(INTERP_KERNEL::Exception); + bool checkConsecutiveCellTypesForMEDFileFrmt() const throw(INTERP_KERNEL::Exception); + DataArrayInt *rearrange2ConsecutiveCellTypes() throw(INTERP_KERNEL::Exception); + DataArrayInt *sortCellsInMEDFileFrmt() throw(INTERP_KERNEL::Exception); + DataArrayInt *convertCellArrayPerGeoType(const DataArrayInt *da) const throw(INTERP_KERNEL::Exception); + DataArrayInt *computeFetchedNodeIds() const throw(INTERP_KERNEL::Exception); + DataArrayInt *zipConnectivityTraducer(int compType, int startCellId=0) throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *buildDescendingConnectivity(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *buildDescendingConnectivity2(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *explode3DMeshTo1D(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const throw(INTERP_KERNEL::Exception); + void orientCorrectlyPolyhedrons() throw(INTERP_KERNEL::Exception); + bool isPresenceOfQuadratic() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *buildDirectionVectorField() const throw(INTERP_KERNEL::Exception); + bool isContiguous1D() const throw(INTERP_KERNEL::Exception); + void tessellate2D(double eps) throw(INTERP_KERNEL::Exception); + void tessellate2DCurve(double eps) throw(INTERP_KERNEL::Exception); + void convertQuadraticCellsToLinear() throw(INTERP_KERNEL::Exception); + DataArrayInt *convertLinearCellsToQuadratic(int conversionType=0) throw(INTERP_KERNEL::Exception); + void convertDegeneratedCells() throw(INTERP_KERNEL::Exception); + bool areOnlySimplexCells() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *getEdgeRatioField() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *getAspectRatioField() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *getWarpField() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *getSkewField() const throw(INTERP_KERNEL::Exception); + DataArrayInt *convexEnvelop2D() throw(INTERP_KERNEL::Exception); + std::string cppRepr() const throw(INTERP_KERNEL::Exception); + DataArrayInt *findAndCorrectBadOriented3DExtrudedCells() throw(INTERP_KERNEL::Exception); + DataArrayInt *findAndCorrectBadOriented3DCells() throw(INTERP_KERNEL::Exception); + static MEDCouplingUMesh *Build0DMeshFromCoords(DataArrayDouble *da) throw(INTERP_KERNEL::Exception); + static MEDCouplingUMesh *MergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception); + static MEDCouplingUMesh *MergeUMeshesOnSameCoords(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception); + static DataArrayInt *ComputeSpreadZoneGradually(const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn) throw(INTERP_KERNEL::Exception); + static DataArrayInt *ComputeRangesFromTypeDistribution(const std::vector& code) throw(INTERP_KERNEL::Exception); + %extend { + MEDCouplingUMesh() throw(INTERP_KERNEL::Exception) + { + return MEDCouplingUMesh::New(); + } + + MEDCouplingUMesh(const char *meshName, int meshDim) throw(INTERP_KERNEL::Exception) + { + return MEDCouplingUMesh::New(meshName,meshDim); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->simpleRepr(); + } + + std::string __repr__() const throw(INTERP_KERNEL::Exception) + { + std::ostringstream oss; + self->reprQuickOverview(oss); + return oss.str(); + } + + MEDCouplingUMeshCellIterator *__iter__() throw(INTERP_KERNEL::Exception) + { + return self->cellIterator(); + } -namespace ParaMEDMEM -{ - class MEDCouplingPointSet : public ParaMEDMEM::MEDCouplingMesh - { - public: - void updateTime() const; - void setCoords(const DataArrayDouble *coords) throw(INTERP_KERNEL::Exception); - DataArrayDouble *getCoordinatesAndOwner() const throw(INTERP_KERNEL::Exception); - bool areCoordsEqual(const MEDCouplingPointSet& other, double prec) const throw(INTERP_KERNEL::Exception); - void zipCoords() throw(INTERP_KERNEL::Exception); - double getCaracteristicDimension() const throw(INTERP_KERNEL::Exception); - void recenterForMaxPrecision(double eps) throw(INTERP_KERNEL::Exception); - void changeSpaceDimension(int newSpaceDim, double dftVal=0.) throw(INTERP_KERNEL::Exception); - void tryToShareSameCoords(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception); - virtual MEDCouplingPointSet *buildPartOfMySelf2(int start, int end, int step) const throw(INTERP_KERNEL::Exception); - virtual void tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception); - static DataArrayDouble *MergeNodesArray(const MEDCouplingPointSet *m1, const MEDCouplingPointSet *m2) throw(INTERP_KERNEL::Exception); - static MEDCouplingPointSet *BuildInstanceFromMeshType(MEDCouplingMeshType type) throw(INTERP_KERNEL::Exception); - virtual MEDCouplingPointSet *buildBoundaryMesh(bool keepCoords) const throw(INTERP_KERNEL::Exception); - virtual bool isEmptyMesh(const std::vector& tinyInfo) const throw(INTERP_KERNEL::Exception); - //! size of returned tinyInfo must be always the same. - void getTinySerializationInformation(std::vector& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const throw(INTERP_KERNEL::Exception); - void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const throw(INTERP_KERNEL::Exception); - void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const throw(INTERP_KERNEL::Exception); - void unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, - const std::vector& littleStrings) throw(INTERP_KERNEL::Exception); - virtual DataArrayInt *getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps) throw(INTERP_KERNEL::Exception); - virtual DataArrayInt *zipCoordsTraducer() throw(INTERP_KERNEL::Exception); - virtual DataArrayInt *findBoundaryNodes() const; - %extend - { - std::string __str__() const throw(INTERP_KERNEL::Exception) - { - return self->simpleRepr(); - } - - PyObject *buildNewNumberingFromCommonNodesFormat(const DataArrayInt *comm, const DataArrayInt *commIndex) const throw(INTERP_KERNEL::Exception) - { - int newNbOfNodes; - DataArrayInt *ret0=self->buildNewNumberingFromCommonNodesFormat(comm,commIndex,newNbOfNodes); - PyObject *res = PyList_New(2); - PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyList_SetItem(res,1,SWIG_From_int(newNbOfNodes)); - return res; - } - - PyObject *findCommonNodes(double prec, int limitTupleId=-1) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *comm, *commIndex; - self->findCommonNodes(prec,limitTupleId,comm,commIndex); - PyObject *res = PyList_New(2); - PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(comm),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyList_SetItem(res,1,SWIG_NewPointerObj(SWIG_as_voidptr(commIndex),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return res; - } - - PyObject *getCoords() throw(INTERP_KERNEL::Exception) - { - DataArrayDouble *ret1=self->getCoords(); - if (ret1) - ret1->incrRef(); - return SWIG_NewPointerObj((void*)ret1,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,SWIG_POINTER_OWN | 0); - } - - PyObject *buildPartOfMySelf(PyObject *li, bool keepCoords=true) const throw(INTERP_KERNEL::Exception) - { - int szArr,sw,iTypppArr; - std::vector stdvecTyyppArr; - const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); - MEDCouplingPointSet *ret=self->buildPartOfMySelf(tmp,tmp+szArr,keepCoords); - if(sw==3)//DataArrayInt - { - void *argp; SWIG_ConvertPtr(li,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0); - DataArrayInt *argpt=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp); - std::string name=argpt->getName(); - if(!name.empty()) - ret->setName(name.c_str()); - } - return convertMesh(ret, SWIG_POINTER_OWN | 0 ); - } - - PyObject *buildPartOfMySelfNode(PyObject *li, bool fullyIn) const throw(INTERP_KERNEL::Exception) - { - int szArr,sw,iTypppArr; - std::vector stdvecTyyppArr; - const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); - MEDCouplingPointSet *ret=self->buildPartOfMySelfNode(tmp,tmp+szArr,fullyIn); - if(sw==3)//DataArrayInt - { - void *argp; SWIG_ConvertPtr(li,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0); - DataArrayInt *argpt=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp); - std::string name=argpt->getName(); - if(!name.empty()) - ret->setName(name.c_str()); - } - return convertMesh(ret, SWIG_POINTER_OWN | 0 ); - } - - PyObject *buildFacePartOfMySelfNode(PyObject *li, bool fullyIn) const throw(INTERP_KERNEL::Exception) - { - int szArr,sw,iTypppArr; - std::vector stdvecTyyppArr; - const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); - MEDCouplingPointSet *ret=self->buildFacePartOfMySelfNode(tmp,tmp+szArr,fullyIn); - if(sw==3)//DataArrayInt - { - void *argp; SWIG_ConvertPtr(li,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0); - DataArrayInt *argpt=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp); - std::string name=argpt->getName(); - if(!name.empty()) - ret->setName(name.c_str()); - } - return convertMesh(ret, SWIG_POINTER_OWN | 0 ); - } + MEDCouplingPointSet *__getitem__(PyObject *listOrDataArrI) throw(INTERP_KERNEL::Exception) + { + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + int nbc=self->getNumberOfCells(); + convertObjToPossibleCpp2(listOrDataArrI,nbc,sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + { + if(singleVal>=nbc) + { + std::ostringstream oss; + oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(singleVal>=0) + return self->buildPartOfMySelf(&singleVal,&singleVal+1,true); + else + { + if(nbc+singleVal>0) + { + int tmp=nbc+singleVal; + return self->buildPartOfMySelf(&tmp,&tmp+1,true); + } + else + { + std::ostringstream oss; + oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + } + case 2: + { + return static_cast(self->buildPartOfMySelf(&multiVal[0],&multiVal[0]+multiVal.size(),true)); + } + case 3: + { + return self->buildPartOfMySelf2(slic.first,slic.second.first,slic.second.second,true); + } + case 4: + { + if(!daIntTyypp) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::__getitem__ : null instance has been given in input !"); + daIntTyypp->checkAllocated(); + return self->buildPartOfMySelf(daIntTyypp->begin(),daIntTyypp->end(),true); + } + default: + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::__getitem__ : unrecognized type in input ! Possibilities are : int, list or tuple of int DataArrayInt instance !"); + } + } + + void setPartOfMySelf(PyObject *li, const MEDCouplingUMesh& otherOnSameCoordsThanThis) throw(INTERP_KERNEL::Exception) + { + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + int nbc=self->getNumberOfCells(); + convertObjToPossibleCpp2(li,nbc,sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + { + if(singleVal>=nbc) + { + std::ostringstream oss; + oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(singleVal>=0) + { + self->setPartOfMySelf(&singleVal,&singleVal+1,otherOnSameCoordsThanThis); + break; + } + else + { + if(nbc+singleVal>0) + { + int tmp=nbc+singleVal; + self->setPartOfMySelf(&tmp,&tmp+1,otherOnSameCoordsThanThis); + break; + } + else + { + std::ostringstream oss; + oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + } + case 2: + { + self->setPartOfMySelf(&multiVal[0],&multiVal[0]+multiVal.size(),otherOnSameCoordsThanThis); + break; + } + case 4: + { + if(!daIntTyypp) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::setPartOfMySelf : null instance has been given in input !"); + daIntTyypp->checkAllocated(); + self->setPartOfMySelf(daIntTyypp->begin(),daIntTyypp->end(),otherOnSameCoordsThanThis); + break; + } + default: + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::setPartOfMySelf : unrecognized type in input ! Possibilities are : int, list or tuple of int DataArrayInt instance !"); + } + } - void renumberNodes(PyObject *li, int newNbOfNodes) throw(INTERP_KERNEL::Exception) - { - int szArr,sw,iTypppArr; - std::vector stdvecTyyppArr; - const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); - self->renumberNodes(tmp,newNbOfNodes); - } + void __setitem__(PyObject *li, const MEDCouplingUMesh& otherOnSameCoordsThanThis) throw(INTERP_KERNEL::Exception) + { + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + int nbc=self->getNumberOfCells(); + convertObjToPossibleCpp2(li,nbc,sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + { + if(singleVal>=nbc) + { + std::ostringstream oss; + oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(singleVal>=0) + { + self->setPartOfMySelf(&singleVal,&singleVal+1,otherOnSameCoordsThanThis); + break; + } + else + { + if(nbc+singleVal>0) + { + int tmp=nbc+singleVal; + self->setPartOfMySelf(&tmp,&tmp+1,otherOnSameCoordsThanThis); + break; + } + else + { + std::ostringstream oss; + oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + } + case 2: + { + self->setPartOfMySelf(&multiVal[0],&multiVal[0]+multiVal.size(),otherOnSameCoordsThanThis); + break; + } + case 3: + { + self->setPartOfMySelf2(slic.first,slic.second.first,slic.second.second,otherOnSameCoordsThanThis); + break; + } + case 4: + { + if(!daIntTyypp) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::__setitem__ : null instance has been given in input !"); + daIntTyypp->checkAllocated(); + self->setPartOfMySelf(daIntTyypp->begin(),daIntTyypp->end(),otherOnSameCoordsThanThis); + break; + } + default: + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::__setitem__ : unrecognized type in input ! Possibilities are : int, list or tuple of int, slice, DataArrayInt instance !"); + } + } - void renumberNodes2(PyObject *li, int newNbOfNodes) throw(INTERP_KERNEL::Exception) - { - int szArr,sw,iTypppArr; - std::vector stdvecTyyppArr; - const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); - self->renumberNodes2(tmp,newNbOfNodes); - } + void insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, PyObject *li) throw(INTERP_KERNEL::Exception) + { + int szArr,sw,iTypppArr; + std::vector stdvecTyyppArr; + const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); + if(size>szArr) + { + std::ostringstream oss; oss << "Wrap of MEDCouplingUMesh::insertNextCell : request of connectivity with length " << size << " whereas the length of input is " << szArr << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + self->insertNextCell(type,size,tmp); + } - PyObject *findNodesOnLine(PyObject *pt, PyObject *vec, double eps) const throw(INTERP_KERNEL::Exception) - { - int spaceDim=self->getSpaceDimension(); - double val,val2; - DataArrayDouble *a,*a2; - DataArrayDoubleTuple *aa,*aa2; - std::vector bb,bb2; - int sw; - const char msg[]="Python wrap of MEDCouplingPointSet::findNodesOnLine : 1st paramater for point."; - const char msg2[]="Python wrap of MEDCouplingPointSet::findNodesOnLine : 2nd paramater for vector."; - const double *p=convertObjToPossibleCpp5_Safe(pt,sw,val,a,aa,bb,msg,1,spaceDim,true); - const double *v=convertObjToPossibleCpp5_Safe(vec,sw,val2,a2,aa2,bb2,msg2,1,spaceDim,true); - std::vector nodes; - self->findNodesOnLine(p,v,eps,nodes); - DataArrayInt *ret=DataArrayInt::New(); - ret->alloc((int)nodes.size(),1); - std::copy(nodes.begin(),nodes.end(),ret->getPointer()); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - PyObject *findNodesOnPlane(PyObject *pt, PyObject *vec, double eps) const throw(INTERP_KERNEL::Exception) - { - int spaceDim=self->getSpaceDimension(); - double val,val2; - DataArrayDouble *a,*a2; - DataArrayDoubleTuple *aa,*aa2; - std::vector bb,bb2; - int sw; - const char msg[]="Python wrap of MEDCouplingPointSet::findNodesOnPlane : 1st paramater for point."; - const char msg2[]="Python wrap of MEDCouplingPointSet::findNodesOnPlane : 2nd paramater for vector."; - const double *p=convertObjToPossibleCpp5_Safe(pt,sw,val,a,aa,bb,msg,1,spaceDim,true); - const double *v=convertObjToPossibleCpp5_Safe(vec,sw,val2,a2,aa2,bb2,msg2,1,spaceDim,true); - std::vector nodes; - self->findNodesOnPlane(p,v,eps,nodes); - DataArrayInt *ret=DataArrayInt::New(); - ret->alloc((int)nodes.size(),1); - std::copy(nodes.begin(),nodes.end(),ret->getPointer()); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - - PyObject *getNodeIdsNearPoint(PyObject *pt, double eps) const throw(INTERP_KERNEL::Exception) - { - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - int spaceDim=self->getSpaceDimension(); - const char msg[]="Python wrap of MEDCouplingPointSet::getNodeIdsNearPoint : "; - const double *pos=convertObjToPossibleCpp5_Safe(pt,sw,val,a,aa,bb,msg,1,spaceDim,true); - DataArrayInt *ret=self->getNodeIdsNearPoint(pos,eps); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - - PyObject *getNodeIdsNearPoints(PyObject *pt, int nbOfPoints, double eps) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *c=0,*cI=0; - // - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - int spaceDim=self->getSpaceDimension(); - const char msg[]="Python wrap of MEDCouplingPointSet::getNodeIdsNearPoints : "; - const double *pos=convertObjToPossibleCpp5_Safe(pt,sw,val,a,aa,bb,msg,nbOfPoints,spaceDim,true); - self->getNodeIdsNearPoints(pos,nbOfPoints,eps,c,cI); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(c),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cI),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *getNodeIdsNearPoints(PyObject *pt, double eps) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *c=0,*cI=0; - int spaceDim=self->getSpaceDimension(); - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - int nbOfTuples=-1; - const double *ptPtr=convertObjToPossibleCpp5_Safe2(pt,sw,val,a,aa,bb,"Python wrap of MEDCouplingUMesh::getNodeIdsNearPoints",spaceDim,true,nbOfTuples); - self->getNodeIdsNearPoints(ptPtr,nbOfTuples,eps,c,cI); - // - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(c),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cI),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *getCellsInBoundingBox(PyObject *bbox, double eps) const throw(INTERP_KERNEL::Exception) - { - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - int spaceDim=self->getSpaceDimension(); - const char msg[]="Python wrap of MEDCouplingPointSet::getCellsInBoundingBox : "; - const double *tmp=convertObjToPossibleCpp5_Safe(bbox,sw,val,a,aa,bb,msg,spaceDim,2,true); - // - DataArrayInt *elems=self->getCellsInBoundingBox(tmp,eps); - return SWIG_NewPointerObj(SWIG_as_voidptr(elems),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - - void duplicateNodesInCoords(PyObject *li) throw(INTERP_KERNEL::Exception) - { - int sw; - int singleVal; - std::vector multiVal; - std::pair > slic; - ParaMEDMEM::DataArrayInt *daIntTyypp=0; - convertObjToPossibleCpp2(li,self->getNumberOfNodes(),sw,singleVal,multiVal,slic,daIntTyypp); - switch(sw) - { - case 1: - return self->duplicateNodesInCoords(&singleVal,&singleVal+1); - case 2: - return self->duplicateNodesInCoords(&multiVal[0],&multiVal[0]+multiVal.size()); - case 4: - return self->duplicateNodesInCoords(daIntTyypp->begin(),daIntTyypp->end()); - default: - throw INTERP_KERNEL::Exception("MEDCouplingPointSet::duplicateNodesInCoords : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); - } - } - - static void Rotate2DAlg(PyObject *center, double angle, int nbNodes, PyObject *coords) throw(INTERP_KERNEL::Exception) - { - int sz; - INTERP_KERNEL::AutoPtr c=convertPyToNewDblArr2(center,&sz); - INTERP_KERNEL::AutoPtr coo=convertPyToNewDblArr2(coords,&sz); - ParaMEDMEM::MEDCouplingPointSet::Rotate2DAlg(c,angle,nbNodes,coo); - for(int i=0;i c=convertPyToNewDblArr2(center,&sz); - int sw,nbNodes=0; - double val0; ParaMEDMEM::DataArrayDouble *val1=0; ParaMEDMEM::DataArrayDoubleTuple *val2=0; - std::vector val3; - const double *coo=convertObjToPossibleCpp5_Safe2(coords,sw,val0,val1,val2,val3, - "Rotate2DAlg",2,true,nbNodes); - if(sw!=2 && sw!=3) - throw INTERP_KERNEL::Exception("Invalid call to MEDCouplingPointSet::Rotate2DAlg : try another overload method !"); - ParaMEDMEM::MEDCouplingPointSet::Rotate2DAlg(c,angle,nbNodes,const_cast(coo)); - } - - static void Rotate3DAlg(PyObject *center, PyObject *vect, double angle, int nbNodes, PyObject *coords) throw(INTERP_KERNEL::Exception) - { - int sz,sz2; - INTERP_KERNEL::AutoPtr c=convertPyToNewDblArr2(center,&sz); - INTERP_KERNEL::AutoPtr coo=convertPyToNewDblArr2(coords,&sz); - INTERP_KERNEL::AutoPtr v=convertPyToNewDblArr2(vect,&sz2); - ParaMEDMEM::MEDCouplingPointSet::Rotate3DAlg(c,v,angle,nbNodes,coo); - for(int i=0;i c=convertPyToNewDblArr2(center,&sz); - int sw,nbNodes=0; - double val0; ParaMEDMEM::DataArrayDouble *val1=0; ParaMEDMEM::DataArrayDoubleTuple *val2=0; - std::vector val3; - const double *coo=convertObjToPossibleCpp5_Safe2(coords,sw,val0,val1,val2,val3, - "Rotate3DAlg",3,true,nbNodes); - if(sw!=2 && sw!=3) - throw INTERP_KERNEL::Exception("Invalid call to MEDCouplingPointSet::Rotate3DAlg : try another overload method !"); - INTERP_KERNEL::AutoPtr v=convertPyToNewDblArr2(vect,&sz2); - ParaMEDMEM::MEDCouplingPointSet::Rotate3DAlg(c,v,angle,nbNodes,const_cast(coo)); - } - } - }; - - class MEDCouplingUMeshCell - { - public: - INTERP_KERNEL::NormalizedCellType getType() const; - %extend + void insertNextCell(INTERP_KERNEL::NormalizedCellType type, PyObject *li) throw(INTERP_KERNEL::Exception) { - std::string __str__() const throw(INTERP_KERNEL::Exception) - { - return self->repr(); - } - - PyObject *getAllConn() const throw(INTERP_KERNEL::Exception) - { - int ret2; - const int *r=self->getAllConn(ret2); - PyObject *ret=PyTuple_New(ret2); - for(int i=0;i stdvecTyyppArr; + const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); + self->insertNextCell(type,szArr,tmp); } - }; - - class MEDCouplingUMeshCellIterator - { - public: - %extend + + DataArrayInt *getNodalConnectivity() throw(INTERP_KERNEL::Exception) { - PyObject *next() - { - MEDCouplingUMeshCell *ret=self->nextt(); - if(ret) - return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMeshCell,0|0); - else - { - PyErr_SetString(PyExc_StopIteration,"No more data."); - return 0; - } - } + DataArrayInt *ret=self->getNodalConnectivity(); + if(ret) + ret->incrRef(); + return ret; } - }; - - class MEDCouplingUMeshCellByTypeIterator - { - public: - ~MEDCouplingUMeshCellByTypeIterator(); - %extend + DataArrayInt *getNodalConnectivityIndex() throw(INTERP_KERNEL::Exception) { - PyObject *next() - { - MEDCouplingUMeshCellEntry *ret=self->nextt(); - if(ret) - return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMeshCellEntry,SWIG_POINTER_OWN | 0); - else - { - PyErr_SetString(PyExc_StopIteration,"No more data."); - return 0; - } - } + DataArrayInt *ret=self->getNodalConnectivityIndex(); + if(ret) + ret->incrRef(); + return ret; } - }; - - class MEDCouplingUMeshCellByTypeEntry - { - public: - ~MEDCouplingUMeshCellByTypeEntry(); - %extend + PyObject *getAllTypes() const throw(INTERP_KERNEL::Exception) { - MEDCouplingUMeshCellByTypeIterator *__iter__() - { - return self->iterator(); - } + std::set result=self->getAllTypes(); + std::set::const_iterator iL=result.begin(); + PyObject *res = PyList_New(result.size()); + for (int i=0;iL!=result.end(); i++, iL++) + PyList_SetItem(res,i,PyInt_FromLong(*iL)); + return res; + } + + static PyObject *ComputeSpreadZoneGraduallyFromSeed(PyObject *seed, const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn, int nbOfDepthPeeling=-1) throw(INTERP_KERNEL::Exception) + { + int szArr,sw,iTypppArr; + std::vector stdvecTyyppArr; + const int *seedPtr=convertObjToPossibleCpp1_Safe(seed,sw,szArr,iTypppArr,stdvecTyyppArr); + int nbOfDepthPeelingPerformed=0; + DataArrayInt *ret0=MEDCouplingUMesh::ComputeSpreadZoneGraduallyFromSeed(seedPtr,seedPtr+szArr,arrIn,arrIndxIn,nbOfDepthPeeling,nbOfDepthPeelingPerformed); + PyObject *res=PyTuple_New(2); + PyTuple_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(res,1,PyInt_FromLong(nbOfDepthPeelingPerformed)); + return res; } - }; - class MEDCouplingUMeshCellEntry - { - public: - INTERP_KERNEL::NormalizedCellType getType() const; - int getNumberOfElems() const; - %extend + PyObject *findCommonCells(int compType, int startCellId=0) const throw(INTERP_KERNEL::Exception) { - MEDCouplingUMeshCellIterator *__iter__() - { - return self->iterator(); - } + DataArrayInt *v0=0,*v1=0; + self->findCommonCells(compType,startCellId,v0,v1); + PyObject *res = PyList_New(2); + PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(v0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(res,1,SWIG_NewPointerObj(SWIG_as_voidptr(v1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return res; } - }; - - class MEDCouplingUMesh : public ParaMEDMEM::MEDCouplingPointSet - { - public: - static MEDCouplingUMesh *New() throw(INTERP_KERNEL::Exception); - static MEDCouplingUMesh *New(const char *meshName, int meshDim) throw(INTERP_KERNEL::Exception); - MEDCouplingUMesh *clone(bool recDeepCpy) const; - void updateTime() const; - void checkCoherency() const throw(INTERP_KERNEL::Exception); - void setMeshDimension(int meshDim) throw(INTERP_KERNEL::Exception); - void allocateCells(int nbOfCells) throw(INTERP_KERNEL::Exception); - void finishInsertingCells() throw(INTERP_KERNEL::Exception); - MEDCouplingUMeshCellByTypeEntry *cellsByType() throw(INTERP_KERNEL::Exception); - void setConnectivity(DataArrayInt *conn, DataArrayInt *connIndex, bool isComputingTypes=true) throw(INTERP_KERNEL::Exception); - INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const throw(INTERP_KERNEL::Exception); - void setPartOfMySelf2(int start, int end, int step, const MEDCouplingUMesh& otherOnSameCoordsThanThis) throw(INTERP_KERNEL::Exception); - int getNumberOfNodesInCell(int cellId) const throw(INTERP_KERNEL::Exception); - int getMeshLength() const throw(INTERP_KERNEL::Exception); - void computeTypes() throw(INTERP_KERNEL::Exception); - std::string reprConnectivityOfThis() const throw(INTERP_KERNEL::Exception); - MEDCouplingUMesh *buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception); - //tools - void shiftNodeNumbersInConn(int delta) throw(INTERP_KERNEL::Exception); - std::vector getQuadraticStatus() const throw(INTERP_KERNEL::Exception); - DataArrayInt *findCellIdsOnBoundary() const throw(INTERP_KERNEL::Exception); - MEDCouplingUMesh *computeSkin() const throw(INTERP_KERNEL::Exception); - bool checkConsecutiveCellTypes() const throw(INTERP_KERNEL::Exception); - bool checkConsecutiveCellTypesForMEDFileFrmt() const throw(INTERP_KERNEL::Exception); - DataArrayInt *rearrange2ConsecutiveCellTypes() throw(INTERP_KERNEL::Exception); - DataArrayInt *sortCellsInMEDFileFrmt() throw(INTERP_KERNEL::Exception); - DataArrayInt *convertCellArrayPerGeoType(const DataArrayInt *da) const throw(INTERP_KERNEL::Exception); - DataArrayInt *computeFetchedNodeIds() const throw(INTERP_KERNEL::Exception); - DataArrayInt *zipConnectivityTraducer(int compType, int startCellId=0) throw(INTERP_KERNEL::Exception); - MEDCouplingUMesh *buildDescendingConnectivity(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const throw(INTERP_KERNEL::Exception); - MEDCouplingUMesh *buildDescendingConnectivity2(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const throw(INTERP_KERNEL::Exception); - MEDCouplingUMesh *explode3DMeshTo1D(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const throw(INTERP_KERNEL::Exception); - void orientCorrectlyPolyhedrons() throw(INTERP_KERNEL::Exception); - bool isPresenceOfQuadratic() const throw(INTERP_KERNEL::Exception); - MEDCouplingFieldDouble *buildDirectionVectorField() const throw(INTERP_KERNEL::Exception); - bool isContiguous1D() const throw(INTERP_KERNEL::Exception); - void tessellate2D(double eps) throw(INTERP_KERNEL::Exception); - void tessellate2DCurve(double eps) throw(INTERP_KERNEL::Exception); - void convertQuadraticCellsToLinear() throw(INTERP_KERNEL::Exception); - DataArrayInt *convertLinearCellsToQuadratic(int conversionType=0) throw(INTERP_KERNEL::Exception); - void convertDegeneratedCells() throw(INTERP_KERNEL::Exception); - bool areOnlySimplexCells() const throw(INTERP_KERNEL::Exception); - MEDCouplingFieldDouble *getEdgeRatioField() const throw(INTERP_KERNEL::Exception); - MEDCouplingFieldDouble *getAspectRatioField() const throw(INTERP_KERNEL::Exception); - MEDCouplingFieldDouble *getWarpField() const throw(INTERP_KERNEL::Exception); - MEDCouplingFieldDouble *getSkewField() const throw(INTERP_KERNEL::Exception); - DataArrayInt *convexEnvelop2D() throw(INTERP_KERNEL::Exception); - std::string cppRepr() const throw(INTERP_KERNEL::Exception); - DataArrayInt *findAndCorrectBadOriented3DExtrudedCells() throw(INTERP_KERNEL::Exception); - DataArrayInt *findAndCorrectBadOriented3DCells() throw(INTERP_KERNEL::Exception); - static MEDCouplingUMesh *Build0DMeshFromCoords(DataArrayDouble *da) throw(INTERP_KERNEL::Exception); - static MEDCouplingUMesh *MergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception); - static MEDCouplingUMesh *MergeUMeshesOnSameCoords(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception); - static DataArrayInt *ComputeSpreadZoneGradually(const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn) throw(INTERP_KERNEL::Exception); - static DataArrayInt *ComputeRangesFromTypeDistribution(const std::vector& code) throw(INTERP_KERNEL::Exception); - %extend { - MEDCouplingUMesh() throw(INTERP_KERNEL::Exception) + + static PyObject *FindCommonCellsAlg(int compType, int startCellId, const DataArrayInt *nodal, const DataArrayInt *nodalI, const DataArrayInt *revNodal, const DataArrayInt *revNodalI) throw(INTERP_KERNEL::Exception) { - return MEDCouplingUMesh::New(); + DataArrayInt *v0=0,*v1=0; + MEDCouplingUMesh::FindCommonCellsAlg(compType,startCellId,nodal,nodalI,revNodal,revNodalI,v0,v1); + PyObject *res = PyList_New(2); + PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(v0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(res,1,SWIG_NewPointerObj(SWIG_as_voidptr(v1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return res; } - MEDCouplingUMesh(const char *meshName, int meshDim) throw(INTERP_KERNEL::Exception) + PyObject *distanceToPoint(PyObject *point) const throw(INTERP_KERNEL::Exception) { - return MEDCouplingUMesh::New(meshName,meshDim); + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + int nbOfCompo=self->getSpaceDimension(); + const double *pt=convertObjToPossibleCpp5_Safe(point,sw,val,a,aa,bb,"Python wrap of MEDCouplingUMesh::distanceToPoint",1,nbOfCompo,true); + // + int cellId=-1,nodeId=-1; + double ret0=self->distanceToPoint(pt,pt+nbOfCompo,cellId,nodeId); + PyObject *ret=PyTuple_New(3); + PyTuple_SetItem(ret,0,PyFloat_FromDouble(ret0)); + PyTuple_SetItem(ret,1,PyInt_FromLong(cellId)); + PyTuple_SetItem(ret,2,PyInt_FromLong(nodeId)); + return ret; } - - std::string __str__() const throw(INTERP_KERNEL::Exception) + + PyObject *mergeNodes(double precision) throw(INTERP_KERNEL::Exception) { - return self->simpleRepr(); + bool ret1; + int ret2; + DataArrayInt *ret0=self->mergeNodes(precision,ret1,ret2); + PyObject *res = PyList_New(3); + PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(res,1,SWIG_From_bool(ret1)); + PyList_SetItem(res,2,SWIG_From_int(ret2)); + return res; } - - std::string __repr__() const throw(INTERP_KERNEL::Exception) + PyObject *mergeNodes2(double precision) throw(INTERP_KERNEL::Exception) { - std::ostringstream oss; - self->reprQuickOverview(oss); - return oss.str(); + bool ret1; + int ret2; + DataArrayInt *ret0=self->mergeNodes2(precision,ret1,ret2); + PyObject *res = PyList_New(3); + PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(res,1,SWIG_From_bool(ret1)); + PyList_SetItem(res,2,SWIG_From_int(ret2)); + return res; } - - MEDCouplingUMeshCellIterator *__iter__() throw(INTERP_KERNEL::Exception) + PyObject *checkButterflyCells(double eps=1e-12) throw(INTERP_KERNEL::Exception) { - return self->cellIterator(); + std::vector cells; + self->checkButterflyCells(cells,eps); + DataArrayInt *ret=DataArrayInt::New(); + ret->alloc((int)cells.size(),1); + std::copy(cells.begin(),cells.end(),ret->getPointer()); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); } - MEDCouplingPointSet *__getitem__(PyObject *listOrDataArrI) throw(INTERP_KERNEL::Exception) + PyObject *splitByType() const throw(INTERP_KERNEL::Exception) + { + std::vector ms=self->splitByType(); + int sz=ms.size(); + PyObject *ret = PyList_New(sz); + for(int i=0;i retCpp=self->partitionBySpreadZone(); + int sz=retCpp.size(); + PyObject *ret=PyList_New(sz); + for(int i=0;i tmp=convertPyToNewIntArr2(ids,&size); + MEDCouplingUMesh *ret=self->keepSpecifiedCells(type,tmp,tmp+size); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 ); + } + + bool checkConsecutiveCellTypesAndOrder(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + int sz; + INTERP_KERNEL::AutoPtr order=(INTERP_KERNEL::NormalizedCellType *)convertPyToNewIntArr2(li,&sz); + bool ret=self->checkConsecutiveCellTypesAndOrder(order,order+sz); + return ret; + } + + DataArrayInt *getRenumArrForConsecutiveCellTypesSpec(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + int sz; + INTERP_KERNEL::AutoPtr order=(INTERP_KERNEL::NormalizedCellType *)convertPyToNewIntArr2(li,&sz); + DataArrayInt *ret=self->getRenumArrForConsecutiveCellTypesSpec(order,(INTERP_KERNEL::NormalizedCellType *)order+sz); + return ret; + } + + PyObject *findNodesToDuplicate(const MEDCouplingUMesh& otherDimM1OnSameCoords) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *tmp0=0,*tmp1=0,*tmp2=0; + self->findNodesToDuplicate(otherDimM1OnSameCoords,tmp0,tmp1,tmp2); + PyObject *ret=PyTuple_New(3); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(tmp0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(tmp1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(tmp2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + + PyObject *findCellIdsLyingOn(const MEDCouplingUMesh& otherDimM1OnSameCoords) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *tmp0=0,*tmp1=0; + self->findCellIdsLyingOn(otherDimM1OnSameCoords,tmp0,tmp1); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(tmp0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(tmp1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + + void duplicateNodes(PyObject *li) throw(INTERP_KERNEL::Exception) { int sw; int singleVal; std::vector multiVal; std::pair > slic; ParaMEDMEM::DataArrayInt *daIntTyypp=0; - int nbc=self->getNumberOfCells(); - convertObjToPossibleCpp2(listOrDataArrI,nbc,sw,singleVal,multiVal,slic,daIntTyypp); + convertObjToPossibleCpp2(li,self->getNumberOfNodes(),sw,singleVal,multiVal,slic,daIntTyypp); switch(sw) { case 1: - { - if(singleVal>=nbc) - { - std::ostringstream oss; - oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - if(singleVal>=0) - return self->buildPartOfMySelf(&singleVal,&singleVal+1,true); - else - { - if(nbc+singleVal>0) - { - int tmp=nbc+singleVal; - return self->buildPartOfMySelf(&tmp,&tmp+1,true); - } - else - { - std::ostringstream oss; - oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - } - } + return self->duplicateNodes(&singleVal,&singleVal+1); case 2: - { - return static_cast(self->buildPartOfMySelf(&multiVal[0],&multiVal[0]+multiVal.size(),true)); - } - case 3: - { - return self->buildPartOfMySelf2(slic.first,slic.second.first,slic.second.second,true); - } + return self->duplicateNodes(&multiVal[0],&multiVal[0]+multiVal.size()); case 4: - { - if(!daIntTyypp) - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::__getitem__ : null instance has been given in input !"); - daIntTyypp->checkAllocated(); - return self->buildPartOfMySelf(daIntTyypp->begin(),daIntTyypp->end(),true); - } + return self->duplicateNodes(daIntTyypp->begin(),daIntTyypp->end()); default: - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::__getitem__ : unrecognized type in input ! Possibilities are : int, list or tuple of int DataArrayInt instance !"); + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::duplicateNodes : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); + } + } + + void duplicateNodesInConn(PyObject *li, int offset) throw(INTERP_KERNEL::Exception) + { + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + convertObjToPossibleCpp2(li,self->getNumberOfNodes(),sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + return self->duplicateNodesInConn(&singleVal,&singleVal+1,offset); + case 2: + return self->duplicateNodesInConn(&multiVal[0],&multiVal[0]+multiVal.size(),offset); + case 4: + return self->duplicateNodesInConn(daIntTyypp->begin(),daIntTyypp->end(),offset); + default: + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::duplicateNodesInConn : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); + } + } + + void renumberNodesInConn(PyObject *li) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + self->renumberNodesInConn(tmp); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + self->renumberNodesInConn(da2->getConstPointer()); + } + } + + PyObject *getLevArrPerCellTypes(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + int sz; + INTERP_KERNEL::AutoPtr order=(INTERP_KERNEL::NormalizedCellType *)convertPyToNewIntArr2(li,&sz); + DataArrayInt *tmp0,*tmp1=0; + tmp0=self->getLevArrPerCellTypes(order,(INTERP_KERNEL::NormalizedCellType *)order+sz,tmp1); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(tmp0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(tmp1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + + static PyObject *AggregateSortedByTypeMeshesOnSameCoords(PyObject *ms) throw(INTERP_KERNEL::Exception) + { + std::vector meshes; + convertFromPyObjVectorOfObj(ms,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh",meshes); + DataArrayInt *ret1=0,*ret2=0; + MEDCouplingUMesh *ret0=MEDCouplingUMesh::AggregateSortedByTypeMeshesOnSameCoords(meshes,ret1,ret2); + PyObject *ret=PyTuple_New(3); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(ret2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + + static PyObject *MergeUMeshesOnSameCoords(PyObject *ms) throw(INTERP_KERNEL::Exception) + { + std::vector meshes; + convertFromPyObjVectorOfObj(ms,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh",meshes); + MEDCouplingUMesh *ret=MEDCouplingUMesh::MergeUMeshesOnSameCoords(meshes); + return convertMesh(ret, SWIG_POINTER_OWN | 0 ); + } + + static PyObject *FuseUMeshesOnSameCoords(PyObject *ms, int compType) throw(INTERP_KERNEL::Exception) + { + int sz; + std::vector meshes; + convertFromPyObjVectorOfObj(ms,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh",meshes); + std::vector corr; + MEDCouplingUMesh *um=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,compType,corr); + sz=corr.size(); + PyObject *ret1=PyList_New(sz); + for(int i=0;i meshes; + convertFromPyObjVectorOfObj(ms,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh",meshes); + MEDCouplingUMesh::PutUMeshesOnSameAggregatedCoords(meshes); + } + + static void MergeNodesOnUMeshesSharingSameCoords(PyObject *ms, double eps) throw(INTERP_KERNEL::Exception) + { + std::vector meshes; + convertFromPyObjVectorOfObj(ms,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh",meshes); + MEDCouplingUMesh::MergeNodesOnUMeshesSharingSameCoords(meshes,eps); + } + + static bool RemoveIdsFromIndexedArrays(PyObject *li, DataArrayInt *arr, DataArrayInt *arrIndx, int offsetForRemoval=0) throw(INTERP_KERNEL::Exception) + { + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + if(!arrIndx) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::RemoveIdsFromIndexedArrays : null pointer as arrIndex !"); + convertObjToPossibleCpp2(li,arrIndx->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + return MEDCouplingUMesh::RemoveIdsFromIndexedArrays(&singleVal,&singleVal+1,arr,arrIndx,offsetForRemoval); + case 2: + return MEDCouplingUMesh::RemoveIdsFromIndexedArrays(&multiVal[0],&multiVal[0]+multiVal.size(),arr,arrIndx,offsetForRemoval); + case 4: + return MEDCouplingUMesh::RemoveIdsFromIndexedArrays(daIntTyypp->begin(),daIntTyypp->end(),arr,arrIndx,offsetForRemoval); + default: + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::RemoveIdsFromIndexedArrays : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); } } - void setPartOfMySelf(PyObject *li, const MEDCouplingUMesh& otherOnSameCoordsThanThis) throw(INTERP_KERNEL::Exception) + static PyObject *ExtractFromIndexedArrays(PyObject *li, const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn) throw(INTERP_KERNEL::Exception) { + DataArrayInt *arrOut=0,*arrIndexOut=0; int sw; int singleVal; std::vector multiVal; std::pair > slic; ParaMEDMEM::DataArrayInt *daIntTyypp=0; - int nbc=self->getNumberOfCells(); - convertObjToPossibleCpp2(li,nbc,sw,singleVal,multiVal,slic,daIntTyypp); + if(!arrIndxIn) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::ExtractFromIndexedArrays : null pointer as arrIndxIn !"); + convertObjToPossibleCpp2(li,arrIndxIn->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp); switch(sw) { case 1: { - if(singleVal>=nbc) - { - std::ostringstream oss; - oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - if(singleVal>=0) - { - self->setPartOfMySelf(&singleVal,&singleVal+1,otherOnSameCoordsThanThis); - break; - } - else - { - if(nbc+singleVal>0) - { - int tmp=nbc+singleVal; - self->setPartOfMySelf(&tmp,&tmp+1,otherOnSameCoordsThanThis); - break; - } - else - { - std::ostringstream oss; - oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - } + MEDCouplingUMesh::ExtractFromIndexedArrays(&singleVal,&singleVal+1,arrIn,arrIndxIn,arrOut,arrIndexOut); + break; } case 2: { - self->setPartOfMySelf(&multiVal[0],&multiVal[0]+multiVal.size(),otherOnSameCoordsThanThis); + MEDCouplingUMesh::ExtractFromIndexedArrays(&multiVal[0],&multiVal[0]+multiVal.size(),arrIn,arrIndxIn,arrOut,arrIndexOut); break; } case 4: { - if(!daIntTyypp) - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::setPartOfMySelf : null instance has been given in input !"); - daIntTyypp->checkAllocated(); - self->setPartOfMySelf(daIntTyypp->begin(),daIntTyypp->end(),otherOnSameCoordsThanThis); + MEDCouplingUMesh::ExtractFromIndexedArrays(daIntTyypp->begin(),daIntTyypp->end(),arrIn,arrIndxIn,arrOut,arrIndexOut); break; } default: - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::setPartOfMySelf : unrecognized type in input ! Possibilities are : int, list or tuple of int DataArrayInt instance !"); + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::ExtractFromIndexedArrays : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); } + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(arrOut),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(arrIndexOut),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; } - void __setitem__(PyObject *li, const MEDCouplingUMesh& otherOnSameCoordsThanThis) throw(INTERP_KERNEL::Exception) + static PyObject *SetPartOfIndexedArrays(PyObject *li, + const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn, + const DataArrayInt *srcArr, const DataArrayInt *srcArrIndex) throw(INTERP_KERNEL::Exception) { + DataArrayInt *arrOut=0,*arrIndexOut=0; int sw; int singleVal; std::vector multiVal; std::pair > slic; ParaMEDMEM::DataArrayInt *daIntTyypp=0; - int nbc=self->getNumberOfCells(); - convertObjToPossibleCpp2(li,nbc,sw,singleVal,multiVal,slic,daIntTyypp); + if(!arrIndxIn) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::SetPartOfIndexedArrays : null pointer as arrIndex !"); + convertObjToPossibleCpp2(li,arrIndxIn->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp); switch(sw) { case 1: { - if(singleVal>=nbc) - { - std::ostringstream oss; - oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - if(singleVal>=0) - { - self->setPartOfMySelf(&singleVal,&singleVal+1,otherOnSameCoordsThanThis); - break; - } - else - { - if(nbc+singleVal>0) - { - int tmp=nbc+singleVal; - self->setPartOfMySelf(&tmp,&tmp+1,otherOnSameCoordsThanThis); - break; - } - else - { - std::ostringstream oss; - oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - } - } - case 2: - { - self->setPartOfMySelf(&multiVal[0],&multiVal[0]+multiVal.size(),otherOnSameCoordsThanThis); + MEDCouplingUMesh::SetPartOfIndexedArrays(&singleVal,&singleVal+1,arrIn,arrIndxIn,srcArr,srcArrIndex,arrOut,arrIndexOut); break; } - case 3: + case 2: { - self->setPartOfMySelf2(slic.first,slic.second.first,slic.second.second,otherOnSameCoordsThanThis); + MEDCouplingUMesh::SetPartOfIndexedArrays(&multiVal[0],&multiVal[0]+multiVal.size(),arrIn,arrIndxIn,srcArr,srcArrIndex,arrOut,arrIndexOut); break; } case 4: { - if(!daIntTyypp) - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::__setitem__ : null instance has been given in input !"); - daIntTyypp->checkAllocated(); - self->setPartOfMySelf(daIntTyypp->begin(),daIntTyypp->end(),otherOnSameCoordsThanThis); + MEDCouplingUMesh::SetPartOfIndexedArrays(daIntTyypp->begin(),daIntTyypp->end(),arrIn,arrIndxIn,srcArr,srcArrIndex,arrOut,arrIndexOut); break; } default: - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::__setitem__ : unrecognized type in input ! Possibilities are : int, list or tuple of int, slice, DataArrayInt instance !"); + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::SetPartOfIndexedArrays : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); } + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(arrOut),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(arrIndexOut),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; } - void insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, PyObject *li) throw(INTERP_KERNEL::Exception) + static void SetPartOfIndexedArraysSameIdx(PyObject *li, DataArrayInt *arrIn, const DataArrayInt *arrIndxIn, + const DataArrayInt *srcArr, const DataArrayInt *srcArrIndex) throw(INTERP_KERNEL::Exception) { - int szArr,sw,iTypppArr; - std::vector stdvecTyyppArr; - const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); - if(size>szArr) + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + if(!arrIndxIn) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx : null pointer as arrIndex !"); + convertObjToPossibleCpp2(li,arrIndxIn->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) { - std::ostringstream oss; oss << "Wrap of MEDCouplingUMesh::insertNextCell : request of connectivity with length " << size << " whereas the length of input is " << szArr << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + case 1: + { + MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx(&singleVal,&singleVal+1,arrIn,arrIndxIn,srcArr,srcArrIndex); + break; + } + case 2: + { + MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx(&multiVal[0],&multiVal[0]+multiVal.size(),arrIn,arrIndxIn,srcArr,srcArrIndex); + break; + } + case 4: + { + MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx(daIntTyypp->begin(),daIntTyypp->end(),arrIn,arrIndxIn,srcArr,srcArrIndex); + break; + } + default: + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); } - self->insertNextCell(type,size,tmp); - } - - void insertNextCell(INTERP_KERNEL::NormalizedCellType type, PyObject *li) throw(INTERP_KERNEL::Exception) - { - int szArr,sw,iTypppArr; - std::vector stdvecTyyppArr; - const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); - self->insertNextCell(type,szArr,tmp); - } - - DataArrayInt *getNodalConnectivity() throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret=self->getNodalConnectivity(); - if(ret) - ret->incrRef(); - return ret; - } - DataArrayInt *getNodalConnectivityIndex() throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret=self->getNodalConnectivityIndex(); - if(ret) - ret->incrRef(); - return ret; - } - PyObject *getAllTypes() const throw(INTERP_KERNEL::Exception) - { - std::set result=self->getAllTypes(); - std::set::const_iterator iL=result.begin(); - PyObject *res = PyList_New(result.size()); - for (int i=0;iL!=result.end(); i++, iL++) - PyList_SetItem(res,i,PyInt_FromLong(*iL)); - return res; - } - - static PyObject *ComputeSpreadZoneGraduallyFromSeed(PyObject *seed, const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn, int nbOfDepthPeeling=-1) throw(INTERP_KERNEL::Exception) - { - int szArr,sw,iTypppArr; - std::vector stdvecTyyppArr; - const int *seedPtr=convertObjToPossibleCpp1_Safe(seed,sw,szArr,iTypppArr,stdvecTyyppArr); - int nbOfDepthPeelingPerformed=0; - DataArrayInt *ret0=MEDCouplingUMesh::ComputeSpreadZoneGraduallyFromSeed(seedPtr,seedPtr+szArr,arrIn,arrIndxIn,nbOfDepthPeeling,nbOfDepthPeelingPerformed); - PyObject *res=PyTuple_New(2); - PyTuple_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(res,1,PyInt_FromLong(nbOfDepthPeelingPerformed)); - return res; - } - - PyObject *findCommonCells(int compType, int startCellId=0) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *v0=0,*v1=0; - self->findCommonCells(compType,startCellId,v0,v1); - PyObject *res = PyList_New(2); - PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(v0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyList_SetItem(res,1,SWIG_NewPointerObj(SWIG_as_voidptr(v1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return res; } - static PyObject *FindCommonCellsAlg(int compType, int startCellId, const DataArrayInt *nodal, const DataArrayInt *nodalI, const DataArrayInt *revNodal, const DataArrayInt *revNodalI) throw(INTERP_KERNEL::Exception) - { - DataArrayInt *v0=0,*v1=0; - MEDCouplingUMesh::FindCommonCellsAlg(compType,startCellId,nodal,nodalI,revNodal,revNodalI,v0,v1); - PyObject *res = PyList_New(2); - PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(v0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyList_SetItem(res,1,SWIG_NewPointerObj(SWIG_as_voidptr(v1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return res; - } - - PyObject *distanceToPoint(PyObject *point) const throw(INTERP_KERNEL::Exception) + PyObject *are2DCellsNotCorrectlyOriented(PyObject *vec, bool polyOnly) const throw(INTERP_KERNEL::Exception) { double val; DataArrayDouble *a; DataArrayDoubleTuple *aa; std::vector bb; int sw; - int nbOfCompo=self->getSpaceDimension(); - const double *pt=convertObjToPossibleCpp5_Safe(point,sw,val,a,aa,bb,"Python wrap of MEDCouplingUMesh::distanceToPoint",1,nbOfCompo,true); + int spaceDim=self->getSpaceDimension(); + const char msg[]="Python wrap of MEDCouplingUMesh::are2DCellsNotCorrectlyOriented : "; + const double *v=convertObjToPossibleCpp5_Safe(vec,sw,val,a,aa,bb,msg,1,spaceDim,true); // - int cellId=-1,nodeId=-1; - double ret0=self->distanceToPoint(pt,pt+nbOfCompo,cellId,nodeId); - PyObject *ret=PyTuple_New(3); - PyTuple_SetItem(ret,0,PyFloat_FromDouble(ret0)); - PyTuple_SetItem(ret,1,PyInt_FromLong(cellId)); - PyTuple_SetItem(ret,2,PyInt_FromLong(nodeId)); - return ret; + std::vector cells; + self->are2DCellsNotCorrectlyOriented(v,polyOnly,cells); + DataArrayInt *ret=DataArrayInt::New(); + ret->alloc((int)cells.size(),1); + std::copy(cells.begin(),cells.end(),ret->getPointer()); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); } - PyObject *mergeNodes(double precision) throw(INTERP_KERNEL::Exception) - { - bool ret1; - int ret2; - DataArrayInt *ret0=self->mergeNodes(precision,ret1,ret2); - PyObject *res = PyList_New(3); - PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyList_SetItem(res,1,SWIG_From_bool(ret1)); - PyList_SetItem(res,2,SWIG_From_int(ret2)); - return res; - } - PyObject *mergeNodes2(double precision) throw(INTERP_KERNEL::Exception) + void orientCorrectly2DCells(PyObject *vec, bool polyOnly) throw(INTERP_KERNEL::Exception) { - bool ret1; - int ret2; - DataArrayInt *ret0=self->mergeNodes2(precision,ret1,ret2); - PyObject *res = PyList_New(3); - PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyList_SetItem(res,1,SWIG_From_bool(ret1)); - PyList_SetItem(res,2,SWIG_From_int(ret2)); - return res; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + int spaceDim=self->getSpaceDimension(); + const char msg[]="Python wrap of MEDCouplingUMesh::orientCorrectly2DCells : "; + const double *v=convertObjToPossibleCpp5_Safe(vec,sw,val,a,aa,bb,msg,1,spaceDim,true); + self->orientCorrectly2DCells(v,polyOnly); } - PyObject *checkButterflyCells(double eps=1e-12) throw(INTERP_KERNEL::Exception) + + PyObject *arePolyhedronsNotCorrectlyOriented() const throw(INTERP_KERNEL::Exception) { std::vector cells; - self->checkButterflyCells(cells,eps); + self->arePolyhedronsNotCorrectlyOriented(cells); DataArrayInt *ret=DataArrayInt::New(); ret->alloc((int)cells.size(),1); std::copy(cells.begin(),cells.end(),ret->getPointer()); return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); } - PyObject *splitByType() const throw(INTERP_KERNEL::Exception) - { - std::vector ms=self->splitByType(); - int sz=ms.size(); - PyObject *ret = PyList_New(sz); - for(int i=0;i retCpp=self->partitionBySpreadZone(); - int sz=retCpp.size(); - PyObject *ret=PyList_New(sz); - for(int i=0;igetFastAveragePlaneOfThis(vec,pos); + double vals[6]; + std::copy(vec,vec+3,vals); + std::copy(pos,pos+3,vals+3); + return convertDblArrToPyListOfTuple(vals,3,2); } - - PyObject *keepSpecifiedCells(INTERP_KERNEL::NormalizedCellType type, PyObject *ids) const throw(INTERP_KERNEL::Exception) + + static MEDCouplingUMesh *MergeUMeshes(PyObject *li) throw(INTERP_KERNEL::Exception) { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(ids,&size); - MEDCouplingUMesh *ret=self->keepSpecifiedCells(type,tmp,tmp+size); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 ); + std::vector tmp; + convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh",tmp); + return MEDCouplingUMesh::MergeUMeshes(tmp); } - bool checkConsecutiveCellTypesAndOrder(PyObject *li) const throw(INTERP_KERNEL::Exception) + PyObject *areCellsIncludedIn(const MEDCouplingUMesh *other, int compType) const throw(INTERP_KERNEL::Exception) { - int sz; - INTERP_KERNEL::AutoPtr order=(INTERP_KERNEL::NormalizedCellType *)convertPyToNewIntArr2(li,&sz); - bool ret=self->checkConsecutiveCellTypesAndOrder(order,order+sz); + DataArrayInt *ret1; + bool ret0=self->areCellsIncludedIn(other,compType,ret1); + PyObject *ret=PyTuple_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyTuple_SetItem(ret,0,ret0Py); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } - DataArrayInt *getRenumArrForConsecutiveCellTypesSpec(PyObject *li) const throw(INTERP_KERNEL::Exception) + PyObject *areCellsIncludedIn2(const MEDCouplingUMesh *other) const throw(INTERP_KERNEL::Exception) { - int sz; - INTERP_KERNEL::AutoPtr order=(INTERP_KERNEL::NormalizedCellType *)convertPyToNewIntArr2(li,&sz); - DataArrayInt *ret=self->getRenumArrForConsecutiveCellTypesSpec(order,(INTERP_KERNEL::NormalizedCellType *)order+sz); + DataArrayInt *ret1; + bool ret0=self->areCellsIncludedIn2(other,ret1); + PyObject *ret=PyTuple_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyTuple_SetItem(ret,0,ret0Py); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } - PyObject *findNodesToDuplicate(const MEDCouplingUMesh& otherDimM1OnSameCoords) const throw(INTERP_KERNEL::Exception) + PyObject *explode3DMeshTo1D() const throw(INTERP_KERNEL::Exception) { - DataArrayInt *tmp0=0,*tmp1=0,*tmp2=0; - self->findNodesToDuplicate(otherDimM1OnSameCoords,tmp0,tmp1,tmp2); - PyObject *ret=PyTuple_New(3); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(tmp0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(tmp1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(tmp2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + MEDCouplingAutoRefCountObjectPtr d0=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr d2=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr d3=DataArrayInt::New(); + MEDCouplingUMesh *m=self->explode3DMeshTo1D(d0,d1,d2,d3); + PyObject *ret=PyTuple_New(5); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(m),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,3,SWIG_NewPointerObj(SWIG_as_voidptr(d2.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,4,SWIG_NewPointerObj(SWIG_as_voidptr(d3.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } - PyObject *findCellIdsLyingOn(const MEDCouplingUMesh& otherDimM1OnSameCoords) const throw(INTERP_KERNEL::Exception) + PyObject *buildDescendingConnectivity() const throw(INTERP_KERNEL::Exception) { - DataArrayInt *tmp0=0,*tmp1=0; - self->findCellIdsLyingOn(otherDimM1OnSameCoords,tmp0,tmp1); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(tmp0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(tmp1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + MEDCouplingAutoRefCountObjectPtr d0=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr d2=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr d3=DataArrayInt::New(); + MEDCouplingUMesh *m=self->buildDescendingConnectivity(d0,d1,d2,d3); + PyObject *ret=PyTuple_New(5); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(m),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,3,SWIG_NewPointerObj(SWIG_as_voidptr(d2.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,4,SWIG_NewPointerObj(SWIG_as_voidptr(d3.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } - void duplicateNodes(PyObject *li) throw(INTERP_KERNEL::Exception) + PyObject *buildDescendingConnectivity2() const throw(INTERP_KERNEL::Exception) { - int sw; - int singleVal; - std::vector multiVal; - std::pair > slic; - ParaMEDMEM::DataArrayInt *daIntTyypp=0; - convertObjToPossibleCpp2(li,self->getNumberOfNodes(),sw,singleVal,multiVal,slic,daIntTyypp); - switch(sw) - { - case 1: - return self->duplicateNodes(&singleVal,&singleVal+1); - case 2: - return self->duplicateNodes(&multiVal[0],&multiVal[0]+multiVal.size()); - case 4: - return self->duplicateNodes(daIntTyypp->begin(),daIntTyypp->end()); - default: - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::duplicateNodes : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); - } + MEDCouplingAutoRefCountObjectPtr d0=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr d2=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr d3=DataArrayInt::New(); + MEDCouplingUMesh *m=self->buildDescendingConnectivity2(d0,d1,d2,d3); + PyObject *ret=PyTuple_New(5); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(m),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,3,SWIG_NewPointerObj(SWIG_as_voidptr(d2.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,4,SWIG_NewPointerObj(SWIG_as_voidptr(d3.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + + PyObject *computeNeighborsOfCells() const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *neighbors=0,*neighborsIdx=0; + self->computeNeighborsOfCells(neighbors,neighborsIdx); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(neighbors),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(neighborsIdx),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; } - void duplicateNodesInConn(PyObject *li, int offset) throw(INTERP_KERNEL::Exception) + static PyObject *ComputeNeighborsOfCellsAdv(const DataArrayInt *desc, const DataArrayInt *descI, const DataArrayInt *revDesc, const DataArrayInt *revDescI) throw(INTERP_KERNEL::Exception) { - int sw; - int singleVal; - std::vector multiVal; - std::pair > slic; - ParaMEDMEM::DataArrayInt *daIntTyypp=0; - convertObjToPossibleCpp2(li,self->getNumberOfNodes(),sw,singleVal,multiVal,slic,daIntTyypp); - switch(sw) - { - case 1: - return self->duplicateNodesInConn(&singleVal,&singleVal+1,offset); - case 2: - return self->duplicateNodesInConn(&multiVal[0],&multiVal[0]+multiVal.size(),offset); - case 4: - return self->duplicateNodesInConn(daIntTyypp->begin(),daIntTyypp->end(),offset); - default: - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::duplicateNodesInConn : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); - } + DataArrayInt *neighbors=0,*neighborsIdx=0; + MEDCouplingUMesh::ComputeNeighborsOfCellsAdv(desc,descI,revDesc,revDescI,neighbors,neighborsIdx); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(neighbors),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(neighborsIdx),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; } - void renumberNodesInConn(PyObject *li) throw(INTERP_KERNEL::Exception) + PyObject *emulateMEDMEMBDC(const MEDCouplingUMesh *nM1LevMesh) + { + MEDCouplingAutoRefCountObjectPtr d0=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); + DataArrayInt *d2,*d3,*d4,*dd5; + MEDCouplingUMesh *mOut=self->emulateMEDMEMBDC(nM1LevMesh,d0,d1,d2,d3,d4,dd5); + PyObject *ret=PyTuple_New(7); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(mOut),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,3,SWIG_NewPointerObj(SWIG_as_voidptr(d2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,4,SWIG_NewPointerObj(SWIG_as_voidptr(d3),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,5,SWIG_NewPointerObj(SWIG_as_voidptr(d4),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,6,SWIG_NewPointerObj(SWIG_as_voidptr(dd5),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + + PyObject *getReverseNodalConnectivity() const throw(INTERP_KERNEL::Exception) + { + MEDCouplingAutoRefCountObjectPtr d0=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); + self->getReverseNodalConnectivity(d0,d1); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + + DataArrayDouble *getPartBarycenterAndOwner(DataArrayInt *da) const throw(INTERP_KERNEL::Exception) + { + if(!da) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da->checkAllocated(); + return self->getPartBarycenterAndOwner(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems()); + } + + DataArrayDouble *getPartMeasureField(bool isAbs, DataArrayInt *da) const throw(INTERP_KERNEL::Exception) + { + if(!da) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da->checkAllocated(); + return self->getPartMeasureField(isAbs,da->getConstPointer(),da->getConstPointer()+da->getNbOfElems()); + } + + MEDCouplingFieldDouble *buildPartOrthogonalField(DataArrayInt *da) const throw(INTERP_KERNEL::Exception) + { + if(!da) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da->checkAllocated(); + return self->buildPartOrthogonalField(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems()); + } + + PyObject *getTypesOfPart(DataArrayInt *da) const throw(INTERP_KERNEL::Exception) + { + if(!da) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da->checkAllocated(); + std::set result=self->getTypesOfPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems()); + std::set::const_iterator iL=result.begin(); + PyObject *res = PyList_New(result.size()); + for (int i=0;iL!=result.end(); i++, iL++) + PyList_SetItem(res,i,PyInt_FromLong(*iL)); + return res; + } + + DataArrayInt *keepCellIdsByType(INTERP_KERNEL::NormalizedCellType type, DataArrayInt *da) const throw(INTERP_KERNEL::Exception) + { + if(!da) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da->checkAllocated(); + DataArrayInt *ret=self->keepCellIdsByType(type,da->getConstPointer(),da->getConstPointer()+da->getNbOfElems()); + ret->setName(da->getName().c_str()); + return ret; + } + + DataArrayInt *getCellIdsLyingOnNodes(PyObject *li, bool fullyIn) const throw(INTERP_KERNEL::Exception) { void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); if (!SWIG_IsOK(res1)) { int size; INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - self->renumberNodesInConn(tmp); + return self->getCellIdsLyingOnNodes(tmp,((const int *)tmp)+size,fullyIn); } else { @@ -2960,4790 +2330,383 @@ namespace ParaMEDMEM if(!da2) throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); da2->checkAllocated(); - self->renumberNodesInConn(da2->getConstPointer()); + return self->getCellIdsLyingOnNodes(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems(),fullyIn); } } - PyObject *getLevArrPerCellTypes(PyObject *li) const throw(INTERP_KERNEL::Exception) + PyObject *getNodeIdsInUse() const throw(INTERP_KERNEL::Exception) { - int sz; - INTERP_KERNEL::AutoPtr order=(INTERP_KERNEL::NormalizedCellType *)convertPyToNewIntArr2(li,&sz); - DataArrayInt *tmp0,*tmp1=0; - tmp0=self->getLevArrPerCellTypes(order,(INTERP_KERNEL::NormalizedCellType *)order+sz,tmp1); + int ret1=-1; + DataArrayInt *ret0=self->getNodeIdsInUse(ret1); PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(tmp0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(tmp1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,PyInt_FromLong(ret1)); return ret; } - static PyObject *AggregateSortedByTypeMeshesOnSameCoords(PyObject *ms) throw(INTERP_KERNEL::Exception) + static PyObject *Intersect2DMeshes(const MEDCouplingUMesh *m1, const MEDCouplingUMesh *m2, double eps) throw(INTERP_KERNEL::Exception) { - std::vector meshes; - convertFromPyObjVectorOfObj(ms,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh",meshes); - DataArrayInt *ret1=0,*ret2=0; - MEDCouplingUMesh *ret0=MEDCouplingUMesh::AggregateSortedByTypeMeshesOnSameCoords(meshes,ret1,ret2); + DataArrayInt *cellNb1=0,*cellNb2=0; + MEDCouplingUMesh *mret=MEDCouplingUMesh::Intersect2DMeshes(m1,m2,eps,cellNb1,cellNb2); PyObject *ret=PyTuple_New(3); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(ret2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(mret),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cellNb1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(cellNb2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } - static PyObject *MergeUMeshesOnSameCoords(PyObject *ms) throw(INTERP_KERNEL::Exception) - { - std::vector meshes; - convertFromPyObjVectorOfObj(ms,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh",meshes); - MEDCouplingUMesh *ret=MEDCouplingUMesh::MergeUMeshesOnSameCoords(meshes); - return convertMesh(ret, SWIG_POINTER_OWN | 0 ); - } - - static PyObject *FuseUMeshesOnSameCoords(PyObject *ms, int compType) throw(INTERP_KERNEL::Exception) + PyObject *buildSlice3D(PyObject *origin, PyObject *vec, double eps) const throw(INTERP_KERNEL::Exception) { - int sz; - std::vector meshes; - convertFromPyObjVectorOfObj(ms,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh",meshes); - std::vector corr; - MEDCouplingUMesh *um=MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,compType,corr); - sz=corr.size(); - PyObject *ret1=PyList_New(sz); - for(int i=0;igetSpaceDimension(); + if(spaceDim!=3) + throw INTERP_KERNEL::Exception("Python wrap of MEDCouplingUMesh::buildSlice3D : works only for spaceDim 3 !"); + double val,val2; + DataArrayDouble *a,*a2; + DataArrayDoubleTuple *aa,*aa2; + std::vector bb,bb2; + int sw; + const char msg[]="Python wrap of MEDCouplingUMesh::buildSlice3D : 1st paramater for origin."; + const char msg2[]="Python wrap of MEDCouplingUMesh::buildSlice3D : 2nd paramater for vector."; + const double *orig=convertObjToPossibleCpp5_Safe(origin,sw,val,a,aa,bb,msg,1,spaceDim,true); + const double *vect=convertObjToPossibleCpp5_Safe(vec,sw,val2,a2,aa2,bb2,msg2,1,spaceDim,true); + // + DataArrayInt *cellIds=0; + MEDCouplingUMesh *ret0=self->buildSlice3D(orig,vect,eps,cellIds); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cellIds),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } - static void PutUMeshesOnSameAggregatedCoords(PyObject *ms) throw(INTERP_KERNEL::Exception) + PyObject *buildSlice3DSurf(PyObject *origin, PyObject *vec, double eps) const throw(INTERP_KERNEL::Exception) { - std::vector meshes; - convertFromPyObjVectorOfObj(ms,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh",meshes); - MEDCouplingUMesh::PutUMeshesOnSameAggregatedCoords(meshes); + int spaceDim=self->getSpaceDimension(); + if(spaceDim!=3) + throw INTERP_KERNEL::Exception("Python wrap of MEDCouplingUMesh::buildSlice3DSurf : works only for spaceDim 3 !"); + double val,val2; + DataArrayDouble *a,*a2; + DataArrayDoubleTuple *aa,*aa2; + std::vector bb,bb2; + int sw; + const char msg[]="Python wrap of MEDCouplingUMesh::buildSlice3DSurf : 1st paramater for origin."; + const char msg2[]="Python wrap of MEDCouplingUMesh::buildSlice3DSurf : 2nd paramater for vector."; + const double *orig=convertObjToPossibleCpp5_Safe(origin,sw,val,a,aa,bb,msg,1,spaceDim,true); + const double *vect=convertObjToPossibleCpp5_Safe(vec,sw,val2,a2,aa2,bb2,msg2,1,spaceDim,true); + // + DataArrayInt *cellIds=0; + MEDCouplingUMesh *ret0=self->buildSlice3DSurf(orig,vect,eps,cellIds); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cellIds),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; } - static void MergeNodesOnUMeshesSharingSameCoords(PyObject *ms, double eps) throw(INTERP_KERNEL::Exception) + DataArrayInt *getCellIdsCrossingPlane(PyObject *origin, PyObject *vec, double eps) const throw(INTERP_KERNEL::Exception) { - std::vector meshes; - convertFromPyObjVectorOfObj(ms,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh",meshes); - MEDCouplingUMesh::MergeNodesOnUMeshesSharingSameCoords(meshes,eps); + int spaceDim=self->getSpaceDimension(); + if(spaceDim!=3) + throw INTERP_KERNEL::Exception("Python wrap of MEDCouplingUMesh::getCellIdsCrossingPlane : works only for spaceDim 3 !"); + double val,val2; + DataArrayDouble *a,*a2; + DataArrayDoubleTuple *aa,*aa2; + std::vector bb,bb2; + int sw; + const char msg[]="Python wrap of MEDCouplingUMesh::getCellIdsCrossingPlane : 1st paramater for origin."; + const char msg2[]="Python wrap of MEDCouplingUMesh::getCellIdsCrossingPlane : 2nd paramater for vector."; + const double *orig=convertObjToPossibleCpp5_Safe(origin,sw,val,a,aa,bb,msg,1,spaceDim,true); + const double *vect=convertObjToPossibleCpp5_Safe(vec,sw,val2,a2,aa2,bb2,msg2,1,spaceDim,true); + return self->getCellIdsCrossingPlane(orig,vect,eps); } - static bool RemoveIdsFromIndexedArrays(PyObject *li, DataArrayInt *arr, DataArrayInt *arrIndx, int offsetForRemoval=0) throw(INTERP_KERNEL::Exception) + void convertToPolyTypes(PyObject *li) throw(INTERP_KERNEL::Exception) { int sw; - int singleVal; - std::vector multiVal; - std::pair > slic; - ParaMEDMEM::DataArrayInt *daIntTyypp=0; - if(!arrIndx) - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::RemoveIdsFromIndexedArrays : null pointer as arrIndex !"); - convertObjToPossibleCpp2(li,arrIndx->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp); - switch(sw) - { - case 1: - return MEDCouplingUMesh::RemoveIdsFromIndexedArrays(&singleVal,&singleVal+1,arr,arrIndx,offsetForRemoval); - case 2: - return MEDCouplingUMesh::RemoveIdsFromIndexedArrays(&multiVal[0],&multiVal[0]+multiVal.size(),arr,arrIndx,offsetForRemoval); - case 4: - return MEDCouplingUMesh::RemoveIdsFromIndexedArrays(daIntTyypp->begin(),daIntTyypp->end(),arr,arrIndx,offsetForRemoval); - default: - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::RemoveIdsFromIndexedArrays : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); - } - } - - static PyObject *ExtractFromIndexedArrays(PyObject *li, const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn) throw(INTERP_KERNEL::Exception) - { - DataArrayInt *arrOut=0,*arrIndexOut=0; - int sw; - int singleVal; - std::vector multiVal; - std::pair > slic; - ParaMEDMEM::DataArrayInt *daIntTyypp=0; - if(!arrIndxIn) - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::ExtractFromIndexedArrays : null pointer as arrIndxIn !"); - convertObjToPossibleCpp2(li,arrIndxIn->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp); - switch(sw) - { - case 1: - { - MEDCouplingUMesh::ExtractFromIndexedArrays(&singleVal,&singleVal+1,arrIn,arrIndxIn,arrOut,arrIndexOut); - break; - } - case 2: - { - MEDCouplingUMesh::ExtractFromIndexedArrays(&multiVal[0],&multiVal[0]+multiVal.size(),arrIn,arrIndxIn,arrOut,arrIndexOut); - break; - } - case 4: - { - MEDCouplingUMesh::ExtractFromIndexedArrays(daIntTyypp->begin(),daIntTyypp->end(),arrIn,arrIndxIn,arrOut,arrIndexOut); - break; - } - default: - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::ExtractFromIndexedArrays : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); - } - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(arrOut),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(arrIndexOut),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - static PyObject *SetPartOfIndexedArrays(PyObject *li, - const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn, - const DataArrayInt *srcArr, const DataArrayInt *srcArrIndex) throw(INTERP_KERNEL::Exception) - { - DataArrayInt *arrOut=0,*arrIndexOut=0; - int sw; - int singleVal; - std::vector multiVal; - std::pair > slic; - ParaMEDMEM::DataArrayInt *daIntTyypp=0; - if(!arrIndxIn) - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::SetPartOfIndexedArrays : null pointer as arrIndex !"); - convertObjToPossibleCpp2(li,arrIndxIn->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp); - switch(sw) - { - case 1: - { - MEDCouplingUMesh::SetPartOfIndexedArrays(&singleVal,&singleVal+1,arrIn,arrIndxIn,srcArr,srcArrIndex,arrOut,arrIndexOut); - break; - } - case 2: - { - MEDCouplingUMesh::SetPartOfIndexedArrays(&multiVal[0],&multiVal[0]+multiVal.size(),arrIn,arrIndxIn,srcArr,srcArrIndex,arrOut,arrIndexOut); - break; - } - case 4: - { - MEDCouplingUMesh::SetPartOfIndexedArrays(daIntTyypp->begin(),daIntTyypp->end(),arrIn,arrIndxIn,srcArr,srcArrIndex,arrOut,arrIndexOut); - break; - } - default: - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::SetPartOfIndexedArrays : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); - } - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(arrOut),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(arrIndexOut),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - static void SetPartOfIndexedArraysSameIdx(PyObject *li, DataArrayInt *arrIn, const DataArrayInt *arrIndxIn, - const DataArrayInt *srcArr, const DataArrayInt *srcArrIndex) throw(INTERP_KERNEL::Exception) - { - int sw; - int singleVal; - std::vector multiVal; - std::pair > slic; - ParaMEDMEM::DataArrayInt *daIntTyypp=0; - if(!arrIndxIn) - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx : null pointer as arrIndex !"); - convertObjToPossibleCpp2(li,arrIndxIn->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp); + int pos1; + std::vector pos2; + DataArrayInt *pos3=0; + DataArrayIntTuple *pos4=0; + convertObjToPossibleCpp1(li,sw,pos1,pos2,pos3,pos4); switch(sw) { case 1: { - MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx(&singleVal,&singleVal+1,arrIn,arrIndxIn,srcArr,srcArrIndex); - break; + self->convertToPolyTypes(&pos1,&pos1+1); + return; } case 2: { - MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx(&multiVal[0],&multiVal[0]+multiVal.size(),arrIn,arrIndxIn,srcArr,srcArrIndex); - break; + if(pos2.empty()) + return; + self->convertToPolyTypes(&pos2[0],&pos2[0]+pos2.size()); + return ; } - case 4: + case 3: { - MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx(daIntTyypp->begin(),daIntTyypp->end(),arrIn,arrIndxIn,srcArr,srcArrIndex); - break; + self->convertToPolyTypes(pos3->begin(),pos3->end()); + return ; } default: - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::convertToPolyTypes : unexpected input array type recognized !"); } } + } + void convertAllToPoly(); + void convertExtrudedPolyhedra() throw(INTERP_KERNEL::Exception); + bool unPolyze() throw(INTERP_KERNEL::Exception); + void simplifyPolyhedra(double eps) throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *buildSpreadZonesWithPoly() const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *buildExtrudedMesh(const MEDCouplingUMesh *mesh1D, int policy) throw(INTERP_KERNEL::Exception); + }; - PyObject *are2DCellsNotCorrectlyOriented(PyObject *vec, bool polyOnly) const throw(INTERP_KERNEL::Exception) - { - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - int spaceDim=self->getSpaceDimension(); - const char msg[]="Python wrap of MEDCouplingUMesh::are2DCellsNotCorrectlyOriented : "; - const double *v=convertObjToPossibleCpp5_Safe(vec,sw,val,a,aa,bb,msg,1,spaceDim,true); - // - std::vector cells; - self->are2DCellsNotCorrectlyOriented(v,polyOnly,cells); - DataArrayInt *ret=DataArrayInt::New(); - ret->alloc((int)cells.size(),1); - std::copy(cells.begin(),cells.end(),ret->getPointer()); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - - void orientCorrectly2DCells(PyObject *vec, bool polyOnly) throw(INTERP_KERNEL::Exception) - { - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - int spaceDim=self->getSpaceDimension(); - const char msg[]="Python wrap of MEDCouplingUMesh::orientCorrectly2DCells : "; - const double *v=convertObjToPossibleCpp5_Safe(vec,sw,val,a,aa,bb,msg,1,spaceDim,true); - self->orientCorrectly2DCells(v,polyOnly); - } - - PyObject *arePolyhedronsNotCorrectlyOriented() const throw(INTERP_KERNEL::Exception) - { - std::vector cells; - self->arePolyhedronsNotCorrectlyOriented(cells); - DataArrayInt *ret=DataArrayInt::New(); - ret->alloc((int)cells.size(),1); - std::copy(cells.begin(),cells.end(),ret->getPointer()); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - - PyObject *getFastAveragePlaneOfThis() const throw(INTERP_KERNEL::Exception) + class MEDCouplingExtrudedMesh : public ParaMEDMEM::MEDCouplingMesh + { + public: + static MEDCouplingExtrudedMesh *New(const MEDCouplingUMesh *mesh3D, const MEDCouplingUMesh *mesh2D, int cell2DId) throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *build3DUnstructuredMesh() const throw(INTERP_KERNEL::Exception); + void updateTime() const throw(INTERP_KERNEL::Exception); + %extend { + MEDCouplingExtrudedMesh(const MEDCouplingUMesh *mesh3D, const MEDCouplingUMesh *mesh2D, int cell2DId) throw(INTERP_KERNEL::Exception) { - double vec[3]; - double pos[3]; - self->getFastAveragePlaneOfThis(vec,pos); - double vals[6]; - std::copy(vec,vec+3,vals); - std::copy(pos,pos+3,vals+3); - return convertDblArrToPyListOfTuple(vals,3,2); + return MEDCouplingExtrudedMesh::New(mesh3D,mesh2D,cell2DId); } - static MEDCouplingUMesh *MergeUMeshes(PyObject *li) throw(INTERP_KERNEL::Exception) - { - std::vector tmp; - convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh",tmp); - return MEDCouplingUMesh::MergeUMeshes(tmp); - } - - PyObject *areCellsIncludedIn(const MEDCouplingUMesh *other, int compType) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret1; - bool ret0=self->areCellsIncludedIn(other,compType,ret1); - PyObject *ret=PyTuple_New(2); - PyObject *ret0Py=ret0?Py_True:Py_False; - Py_XINCREF(ret0Py); - PyTuple_SetItem(ret,0,ret0Py); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *areCellsIncludedIn2(const MEDCouplingUMesh *other) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret1; - bool ret0=self->areCellsIncludedIn2(other,ret1); - PyObject *ret=PyTuple_New(2); - PyObject *ret0Py=ret0?Py_True:Py_False; - Py_XINCREF(ret0Py); - PyTuple_SetItem(ret,0,ret0Py); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *explode3DMeshTo1D() const throw(INTERP_KERNEL::Exception) - { - MEDCouplingAutoRefCountObjectPtr d0=DataArrayInt::New(); - MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); - MEDCouplingAutoRefCountObjectPtr d2=DataArrayInt::New(); - MEDCouplingAutoRefCountObjectPtr d3=DataArrayInt::New(); - MEDCouplingUMesh *m=self->explode3DMeshTo1D(d0,d1,d2,d3); - PyObject *ret=PyTuple_New(5); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(m),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,3,SWIG_NewPointerObj(SWIG_as_voidptr(d2.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,4,SWIG_NewPointerObj(SWIG_as_voidptr(d3.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *buildDescendingConnectivity() const throw(INTERP_KERNEL::Exception) + std::string __str__() const throw(INTERP_KERNEL::Exception) { - MEDCouplingAutoRefCountObjectPtr d0=DataArrayInt::New(); - MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); - MEDCouplingAutoRefCountObjectPtr d2=DataArrayInt::New(); - MEDCouplingAutoRefCountObjectPtr d3=DataArrayInt::New(); - MEDCouplingUMesh *m=self->buildDescendingConnectivity(d0,d1,d2,d3); - PyObject *ret=PyTuple_New(5); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(m),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,3,SWIG_NewPointerObj(SWIG_as_voidptr(d2.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,4,SWIG_NewPointerObj(SWIG_as_voidptr(d3.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; + return self->simpleRepr(); } - PyObject *buildDescendingConnectivity2() const throw(INTERP_KERNEL::Exception) - { - MEDCouplingAutoRefCountObjectPtr d0=DataArrayInt::New(); - MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); - MEDCouplingAutoRefCountObjectPtr d2=DataArrayInt::New(); - MEDCouplingAutoRefCountObjectPtr d3=DataArrayInt::New(); - MEDCouplingUMesh *m=self->buildDescendingConnectivity2(d0,d1,d2,d3); - PyObject *ret=PyTuple_New(5); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(m),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,3,SWIG_NewPointerObj(SWIG_as_voidptr(d2.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,4,SWIG_NewPointerObj(SWIG_as_voidptr(d3.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *computeNeighborsOfCells() const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *neighbors=0,*neighborsIdx=0; - self->computeNeighborsOfCells(neighbors,neighborsIdx); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(neighbors),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(neighborsIdx),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - static PyObject *ComputeNeighborsOfCellsAdv(const DataArrayInt *desc, const DataArrayInt *descI, const DataArrayInt *revDesc, const DataArrayInt *revDescI) throw(INTERP_KERNEL::Exception) - { - DataArrayInt *neighbors=0,*neighborsIdx=0; - MEDCouplingUMesh::ComputeNeighborsOfCellsAdv(desc,descI,revDesc,revDescI,neighbors,neighborsIdx); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(neighbors),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(neighborsIdx),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *emulateMEDMEMBDC(const MEDCouplingUMesh *nM1LevMesh) - { - MEDCouplingAutoRefCountObjectPtr d0=DataArrayInt::New(); - MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); - DataArrayInt *d2,*d3,*d4,*dd5; - MEDCouplingUMesh *mOut=self->emulateMEDMEMBDC(nM1LevMesh,d0,d1,d2,d3,d4,dd5); - PyObject *ret=PyTuple_New(7); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(mOut),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,3,SWIG_NewPointerObj(SWIG_as_voidptr(d2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,4,SWIG_NewPointerObj(SWIG_as_voidptr(d3),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,5,SWIG_NewPointerObj(SWIG_as_voidptr(d4),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,6,SWIG_NewPointerObj(SWIG_as_voidptr(dd5),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *getReverseNodalConnectivity() const throw(INTERP_KERNEL::Exception) - { - MEDCouplingAutoRefCountObjectPtr d0=DataArrayInt::New(); - MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); - self->getReverseNodalConnectivity(d0,d1); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - DataArrayDouble *getPartBarycenterAndOwner(DataArrayInt *da) const throw(INTERP_KERNEL::Exception) - { - if(!da) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da->checkAllocated(); - return self->getPartBarycenterAndOwner(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems()); - } - - DataArrayDouble *getPartMeasureField(bool isAbs, DataArrayInt *da) const throw(INTERP_KERNEL::Exception) - { - if(!da) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da->checkAllocated(); - return self->getPartMeasureField(isAbs,da->getConstPointer(),da->getConstPointer()+da->getNbOfElems()); - } - - MEDCouplingFieldDouble *buildPartOrthogonalField(DataArrayInt *da) const throw(INTERP_KERNEL::Exception) - { - if(!da) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da->checkAllocated(); - return self->buildPartOrthogonalField(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems()); - } - - PyObject *getTypesOfPart(DataArrayInt *da) const throw(INTERP_KERNEL::Exception) - { - if(!da) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da->checkAllocated(); - std::set result=self->getTypesOfPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems()); - std::set::const_iterator iL=result.begin(); - PyObject *res = PyList_New(result.size()); - for (int i=0;iL!=result.end(); i++, iL++) - PyList_SetItem(res,i,PyInt_FromLong(*iL)); - return res; - } - - DataArrayInt *keepCellIdsByType(INTERP_KERNEL::NormalizedCellType type, DataArrayInt *da) const throw(INTERP_KERNEL::Exception) - { - if(!da) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da->checkAllocated(); - DataArrayInt *ret=self->keepCellIdsByType(type,da->getConstPointer(),da->getConstPointer()+da->getNbOfElems()); - ret->setName(da->getName().c_str()); - return ret; - } - - DataArrayInt *getCellIdsLyingOnNodes(PyObject *li, bool fullyIn) const throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - return self->getCellIdsLyingOnNodes(tmp,((const int *)tmp)+size,fullyIn); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - return self->getCellIdsLyingOnNodes(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems(),fullyIn); - } - } - - PyObject *getNodeIdsInUse() const throw(INTERP_KERNEL::Exception) - { - int ret1=-1; - DataArrayInt *ret0=self->getNodeIdsInUse(ret1); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,PyInt_FromLong(ret1)); - return ret; - } - - static PyObject *Intersect2DMeshes(const MEDCouplingUMesh *m1, const MEDCouplingUMesh *m2, double eps) throw(INTERP_KERNEL::Exception) - { - DataArrayInt *cellNb1=0,*cellNb2=0; - MEDCouplingUMesh *mret=MEDCouplingUMesh::Intersect2DMeshes(m1,m2,eps,cellNb1,cellNb2); - PyObject *ret=PyTuple_New(3); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(mret),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cellNb1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(cellNb2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *buildSlice3D(PyObject *origin, PyObject *vec, double eps) const throw(INTERP_KERNEL::Exception) - { - int spaceDim=self->getSpaceDimension(); - if(spaceDim!=3) - throw INTERP_KERNEL::Exception("Python wrap of MEDCouplingUMesh::buildSlice3D : works only for spaceDim 3 !"); - double val,val2; - DataArrayDouble *a,*a2; - DataArrayDoubleTuple *aa,*aa2; - std::vector bb,bb2; - int sw; - const char msg[]="Python wrap of MEDCouplingUMesh::buildSlice3D : 1st paramater for origin."; - const char msg2[]="Python wrap of MEDCouplingUMesh::buildSlice3D : 2nd paramater for vector."; - const double *orig=convertObjToPossibleCpp5_Safe(origin,sw,val,a,aa,bb,msg,1,spaceDim,true); - const double *vect=convertObjToPossibleCpp5_Safe(vec,sw,val2,a2,aa2,bb2,msg2,1,spaceDim,true); - // - DataArrayInt *cellIds=0; - MEDCouplingUMesh *ret0=self->buildSlice3D(orig,vect,eps,cellIds); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cellIds),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *buildSlice3DSurf(PyObject *origin, PyObject *vec, double eps) const throw(INTERP_KERNEL::Exception) - { - int spaceDim=self->getSpaceDimension(); - if(spaceDim!=3) - throw INTERP_KERNEL::Exception("Python wrap of MEDCouplingUMesh::buildSlice3DSurf : works only for spaceDim 3 !"); - double val,val2; - DataArrayDouble *a,*a2; - DataArrayDoubleTuple *aa,*aa2; - std::vector bb,bb2; - int sw; - const char msg[]="Python wrap of MEDCouplingUMesh::buildSlice3DSurf : 1st paramater for origin."; - const char msg2[]="Python wrap of MEDCouplingUMesh::buildSlice3DSurf : 2nd paramater for vector."; - const double *orig=convertObjToPossibleCpp5_Safe(origin,sw,val,a,aa,bb,msg,1,spaceDim,true); - const double *vect=convertObjToPossibleCpp5_Safe(vec,sw,val2,a2,aa2,bb2,msg2,1,spaceDim,true); - // - DataArrayInt *cellIds=0; - MEDCouplingUMesh *ret0=self->buildSlice3DSurf(orig,vect,eps,cellIds); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cellIds),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - DataArrayInt *getCellIdsCrossingPlane(PyObject *origin, PyObject *vec, double eps) const throw(INTERP_KERNEL::Exception) - { - int spaceDim=self->getSpaceDimension(); - if(spaceDim!=3) - throw INTERP_KERNEL::Exception("Python wrap of MEDCouplingUMesh::getCellIdsCrossingPlane : works only for spaceDim 3 !"); - double val,val2; - DataArrayDouble *a,*a2; - DataArrayDoubleTuple *aa,*aa2; - std::vector bb,bb2; - int sw; - const char msg[]="Python wrap of MEDCouplingUMesh::getCellIdsCrossingPlane : 1st paramater for origin."; - const char msg2[]="Python wrap of MEDCouplingUMesh::getCellIdsCrossingPlane : 2nd paramater for vector."; - const double *orig=convertObjToPossibleCpp5_Safe(origin,sw,val,a,aa,bb,msg,1,spaceDim,true); - const double *vect=convertObjToPossibleCpp5_Safe(vec,sw,val2,a2,aa2,bb2,msg2,1,spaceDim,true); - return self->getCellIdsCrossingPlane(orig,vect,eps); - } - - void convertToPolyTypes(PyObject *li) throw(INTERP_KERNEL::Exception) - { - int sw; - int pos1; - std::vector pos2; - DataArrayInt *pos3=0; - DataArrayIntTuple *pos4=0; - convertObjToPossibleCpp1(li,sw,pos1,pos2,pos3,pos4); - switch(sw) - { - case 1: - { - self->convertToPolyTypes(&pos1,&pos1+1); - return; - } - case 2: - { - if(pos2.empty()) - return; - self->convertToPolyTypes(&pos2[0],&pos2[0]+pos2.size()); - return ; - } - case 3: - { - self->convertToPolyTypes(pos3->begin(),pos3->end()); - return ; - } - default: - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::convertToPolyTypes : unexpected input array type recognized !"); - } - } - } - void convertAllToPoly(); - void convertExtrudedPolyhedra() throw(INTERP_KERNEL::Exception); - bool unPolyze() throw(INTERP_KERNEL::Exception); - void simplifyPolyhedra(double eps) throw(INTERP_KERNEL::Exception); - MEDCouplingUMesh *buildSpreadZonesWithPoly() const throw(INTERP_KERNEL::Exception); - MEDCouplingUMesh *buildExtrudedMesh(const MEDCouplingUMesh *mesh1D, int policy) throw(INTERP_KERNEL::Exception); - }; - - class MEDCouplingExtrudedMesh : public ParaMEDMEM::MEDCouplingMesh - { - public: - static MEDCouplingExtrudedMesh *New(const MEDCouplingUMesh *mesh3D, const MEDCouplingUMesh *mesh2D, int cell2DId) throw(INTERP_KERNEL::Exception); - MEDCouplingUMesh *build3DUnstructuredMesh() const throw(INTERP_KERNEL::Exception); - void updateTime() const throw(INTERP_KERNEL::Exception); - %extend { - MEDCouplingExtrudedMesh(const MEDCouplingUMesh *mesh3D, const MEDCouplingUMesh *mesh2D, int cell2DId) throw(INTERP_KERNEL::Exception) - { - return MEDCouplingExtrudedMesh::New(mesh3D,mesh2D,cell2DId); - } - - std::string __str__() const throw(INTERP_KERNEL::Exception) - { - return self->simpleRepr(); - } - - std::string __repr__() const throw(INTERP_KERNEL::Exception) - { - std::ostringstream oss; - self->reprQuickOverview(oss); - return oss.str(); - } - - PyObject *getMesh2D() const throw(INTERP_KERNEL::Exception) - { - MEDCouplingUMesh *ret=self->getMesh2D(); - if(ret) - ret->incrRef(); - return convertMesh(ret, SWIG_POINTER_OWN | 0 ); - } - PyObject *getMesh1D() const throw(INTERP_KERNEL::Exception) - { - MEDCouplingUMesh *ret=self->getMesh1D(); - if(ret) - ret->incrRef(); - return convertMesh(ret, SWIG_POINTER_OWN | 0 ); - } - PyObject *getMesh3DIds() const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret=self->getMesh3DIds(); - if(ret) - ret->incrRef(); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - } - }; - - class MEDCouplingStructuredMesh : public ParaMEDMEM::MEDCouplingMesh - { - public: - void updateTime() const throw(INTERP_KERNEL::Exception); - int getCellIdFromPos(int i, int j, int k) const throw(INTERP_KERNEL::Exception); - int getNodeIdFromPos(int i, int j, int k) const throw(INTERP_KERNEL::Exception); - }; - - class MEDCouplingCMesh : public ParaMEDMEM::MEDCouplingStructuredMesh - { - public: - static MEDCouplingCMesh *New(); - static MEDCouplingCMesh *New(const char *meshName); - MEDCouplingCMesh *clone(bool recDeepCpy) const; - void setCoords(const DataArrayDouble *coordsX, - const DataArrayDouble *coordsY=0, - const DataArrayDouble *coordsZ=0) throw(INTERP_KERNEL::Exception); - void setCoordsAt(int i, const DataArrayDouble *arr) throw(INTERP_KERNEL::Exception); - %extend { - MEDCouplingCMesh() - { - return MEDCouplingCMesh::New(); - } - MEDCouplingCMesh(const char *meshName) - { - return MEDCouplingCMesh::New(meshName); - } - std::string __str__() const throw(INTERP_KERNEL::Exception) - { - return self->simpleRepr(); - } - std::string __repr__() const throw(INTERP_KERNEL::Exception) - { - std::ostringstream oss; - self->reprQuickOverview(oss); - return oss.str(); - } - DataArrayDouble *getCoordsAt(int i) throw(INTERP_KERNEL::Exception) - { - DataArrayDouble *ret=self->getCoordsAt(i); - if(ret) - ret->incrRef(); - return ret; - } - } - }; - - class MEDCouplingCurveLinearMesh : public ParaMEDMEM::MEDCouplingStructuredMesh - { - public: - static MEDCouplingCurveLinearMesh *New(); - static MEDCouplingCurveLinearMesh *New(const char *meshName); - MEDCouplingCurveLinearMesh *clone(bool recDeepCpy) const; - void setCoords(const DataArrayDouble *coords) throw(INTERP_KERNEL::Exception); - std::vector getNodeGridStructure() const throw(INTERP_KERNEL::Exception); - %extend { - MEDCouplingCurveLinearMesh() - { - return MEDCouplingCurveLinearMesh::New(); - } - MEDCouplingCurveLinearMesh(const char *meshName) - { - return MEDCouplingCurveLinearMesh::New(meshName); - } - std::string __str__() const throw(INTERP_KERNEL::Exception) - { - return self->simpleRepr(); - } - std::string __repr__() const throw(INTERP_KERNEL::Exception) - { - std::ostringstream oss; - self->reprQuickOverview(oss); - return oss.str(); - } - DataArrayDouble *getCoords() throw(INTERP_KERNEL::Exception) - { - DataArrayDouble *ret=self->getCoords(); - if(ret) - ret->incrRef(); - return ret; - } - void setNodeGridStructure(PyObject *gridStruct) throw(INTERP_KERNEL::Exception) - { - int szArr,sw,iTypppArr; - std::vector stdvecTyyppArr; - const int *tmp=convertObjToPossibleCpp1_Safe(gridStruct,sw,szArr,iTypppArr,stdvecTyyppArr); - self->setNodeGridStructure(tmp,tmp+szArr); - } - } - }; - -} - -%extend ParaMEDMEM::MEDCouplingFieldDiscretization -{ - MEDCouplingFieldDiscretization *clonePart(PyObject *li) - { - int sz=0,sw=-1,val1=-1; - std::vector val2; - const int *inp=convertObjToPossibleCpp1_Safe(li,sw,sz,val1,val2); - return self->clonePart(inp,inp+sz); - } - - PyObject *computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, PyObject *tupleIds) const throw(INTERP_KERNEL::Exception) - { - std::vector vVal; int iVal=-1; - int sz=-1,sw=0; - const int *tupleIdsBg=convertObjToPossibleCpp1_Safe(tupleIds,sw,sz,iVal,vVal); - if(sw==0) - throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::computeMeshRestrictionFromTupleIds : none parameter in input !"); - DataArrayInt *ret0=0,*ret1=0; - self->computeMeshRestrictionFromTupleIds(mesh,tupleIdsBg,tupleIdsBg+sz,ret0,ret1); - PyObject *pyRet=PyTuple_New(2); - PyTuple_SetItem(pyRet,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(pyRet,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return pyRet; - } -} - -%extend ParaMEDMEM::MEDCouplingFieldDiscretizationP0 -{ - PyObject *computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, PyObject *tupleIds) const throw(INTERP_KERNEL::Exception) - { return ParaMEDMEM_MEDCouplingFieldDiscretization_computeMeshRestrictionFromTupleIds__SWIG_1(self,mesh,tupleIds); } -} - -%extend ParaMEDMEM::MEDCouplingFieldDiscretizationOnNodes -{ - PyObject *computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, PyObject *tupleIds) const throw(INTERP_KERNEL::Exception) - { return ParaMEDMEM_MEDCouplingFieldDiscretization_computeMeshRestrictionFromTupleIds__SWIG_1(self,mesh,tupleIds); } -} - -%extend ParaMEDMEM::MEDCouplingFieldDiscretizationGauss -{ - PyObject *computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, PyObject *tupleIds) const throw(INTERP_KERNEL::Exception) - { return ParaMEDMEM_MEDCouplingFieldDiscretization_computeMeshRestrictionFromTupleIds__SWIG_1(self,mesh,tupleIds); } -} - -%extend ParaMEDMEM::MEDCouplingFieldDiscretizationGaussNE -{ - PyObject *computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, PyObject *tupleIds) const throw(INTERP_KERNEL::Exception) - { return ParaMEDMEM_MEDCouplingFieldDiscretization_computeMeshRestrictionFromTupleIds__SWIG_1(self,mesh,tupleIds); } -} - -%extend ParaMEDMEM::MEDCouplingFieldDiscretizationPerCell -{ - PyObject *getArrayOfDiscIds() const - { - DataArrayInt *ret=const_cast(self->getArrayOfDiscIds()); - if(ret) - ret->incrRef(); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - - PyObject *splitIntoSingleGaussDicrPerCellType() const throw(INTERP_KERNEL::Exception) - { - std::vector ret1; - std::vector ret0=self->splitIntoSingleGaussDicrPerCellType(ret1); - std::size_t sz=ret0.size(); - PyObject *pyRet=PyTuple_New(2); - PyObject *pyRet0=PyList_New((int)sz); - PyObject *pyRet1=PyList_New((int)sz); - for(std::size_t i=0;icomputeVectorOfCoefficients(mesh,arr,ret1); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,PyInt_FromLong(ret1)); - return ret; - } -} - -%extend ParaMEDMEM::DataArrayDoubleIterator -{ - PyObject *next() - { - DataArrayDoubleTuple *ret=self->nextt(); - if(ret) - return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,SWIG_POINTER_OWN|0); - else - { - PyErr_SetString(PyExc_StopIteration,"No more data."); - return 0; - } - } -} - -%extend ParaMEDMEM::DataArrayDoubleTuple -{ - std::string __str__() const throw(INTERP_KERNEL::Exception) - { - return self->repr(); - } - - double __float__() const throw(INTERP_KERNEL::Exception) - { - return self->doubleValue(); - } - - DataArrayDouble *buildDADouble() - { - return self->buildDADouble(1,self->getNumberOfCompo()); - } - - PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - MEDCouplingAutoRefCountObjectPtr ret=self->buildDADouble(1,self->getNumberOfCompo()); - ParaMEDMEM_DataArrayDouble____iadd___(ret,0,obj); - Py_XINCREF(trueSelf); - return trueSelf; - } - - PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - MEDCouplingAutoRefCountObjectPtr ret=self->buildDADouble(1,self->getNumberOfCompo()); - ParaMEDMEM_DataArrayDouble____isub___(ret,0,obj); - Py_XINCREF(trueSelf); - return trueSelf; - } - - PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - MEDCouplingAutoRefCountObjectPtr ret=self->buildDADouble(1,self->getNumberOfCompo()); - ParaMEDMEM_DataArrayDouble____imul___(ret,0,obj); - Py_XINCREF(trueSelf); - return trueSelf; - } - - PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - MEDCouplingAutoRefCountObjectPtr ret=self->buildDADouble(1,self->getNumberOfCompo()); - ParaMEDMEM_DataArrayDouble____idiv___(ret,0,obj); - Py_XINCREF(trueSelf); - return trueSelf; - } - - PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - int sw; - int singleVal; - std::vector multiVal; - std::pair > slic; - ParaMEDMEM::DataArrayInt *daIntTyypp=0; - const double *pt=self->getConstPointer(); - int nbc=self->getNumberOfCompo(); - convertObjToPossibleCpp2(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp); - switch(sw) - { - case 1: - { - if(singleVal>=nbc) - { - std::ostringstream oss; - oss << "Requesting for id " << singleVal << " having only " << nbc << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - if(singleVal>=0) - return PyFloat_FromDouble(pt[singleVal]); - else - { - if(nbc+singleVal>0) - return PyFloat_FromDouble(pt[nbc+singleVal]); - else - { - std::ostringstream oss; - oss << "Requesting for id " << singleVal << " having only " << nbc << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - } - } - case 2: - { - PyObject *t=PyTuple_New(multiVal.size()); - for(int j=0;j<(int)multiVal.size();j++) - { - int cid=multiVal[j]; - if(cid>=nbc) - { - std::ostringstream oss; - oss << "Requesting for id #" << cid << " having only " << nbc << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - PyTuple_SetItem(t,j,PyFloat_FromDouble(pt[cid])); - } - return t; - } - case 3: - { - int sz=DataArray::GetNumberOfItemGivenBES(slic.first,slic.second.first,slic.second.second,""); - PyObject *t=PyTuple_New(sz); - for(int j=0;j multiValV; - ParaMEDMEM::DataArrayDoubleTuple *daIntTyyppV=0; - int nbc=self->getNumberOfCompo(); - convertObjToPossibleCpp44(value,sw1,singleValV,multiValV,daIntTyyppV); - int singleVal; - std::vector multiVal; - std::pair > slic; - ParaMEDMEM::DataArrayInt *daIntTyypp=0; - double *pt=self->getPointer(); - convertObjToPossibleCpp2(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp); - switch(sw2) - { - case 1: - { - if(singleVal>=nbc) - { - std::ostringstream oss; - oss << "Requesting for setting id # " << singleVal << " having only " << nbc << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - switch(sw1) - { - case 1: - { - pt[singleVal]=singleValV; - return self; - } - case 2: - { - if(multiValV.size()!=1) - { - std::ostringstream oss; - oss << "Requesting for setting id # " << singleVal << " with a list or tuple with size != 1 ! "; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - pt[singleVal]=multiValV[0]; - return self; - } - case 3: - { - pt[singleVal]=daIntTyyppV->getConstPointer()[0]; - return self; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - case 2: - { - switch(sw1) - { - case 1: - { - for(std::vector::const_iterator it=multiVal.begin();it!=multiVal.end();it++) - { - if(*it>=nbc) - { - std::ostringstream oss; - oss << "Requesting for setting id # " << *it << " having only " << nbc << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - pt[*it]=singleValV; - } - return self; - } - case 2: - { - if(multiVal.size()!=multiValV.size()) - { - std::ostringstream oss; - oss << "Mismatch length of during assignment : " << multiValV.size() << " != " << multiVal.size() << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - for(int i=0;i<(int)multiVal.size();i++) - { - int pos=multiVal[i]; - if(pos>=nbc) - { - std::ostringstream oss; - oss << "Requesting for setting id # " << pos << " having only " << nbc << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - pt[multiVal[i]]=multiValV[i]; - } - return self; - } - case 3: - { - const double *ptV=daIntTyyppV->getConstPointer(); - if(nbc>daIntTyyppV->getNumberOfCompo()) - { - std::ostringstream oss; - oss << "Mismatch length of during assignment : " << nbc << " != " << daIntTyyppV->getNumberOfCompo() << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - std::copy(ptV,ptV+nbc,pt); - return self; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - case 3: - { - int sz=DataArray::GetNumberOfItemGivenBES(slic.first,slic.second.first,slic.second.second,""); - switch(sw1) - { - case 1: - { - for(int j=0;jgetConstPointer(); - if(sz>daIntTyyppV->getNumberOfCompo()) - { - std::ostringstream oss; - oss << "Mismatch length of during assignment : " << nbc << " != " << daIntTyyppV->getNumberOfCompo() << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - for(int j=0;j ret=DataArrayDouble::New(); - std::vector tmp=fillArrayWithPyListDbl2(elt0,nbOfTuples1,nbOfCompo); - ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - return ret.retn(); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - {//DataArrayDouble.New([1.,3.,4.],3) - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); - int tmpp1=-1; - std::vector tmp=fillArrayWithPyListDbl2(elt0,nbOfTuples1,tmpp1); - ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - return ret.retn(); - } - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - {// DataArrayDouble.New([1.,3.,4.]) - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); - int tmpp1=-1,tmpp2=-1; - std::vector tmp=fillArrayWithPyListDbl2(elt0,tmpp1,tmpp2); - ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - return ret.retn(); - } - } - else if(PyInt_Check(elt0)) - { - int nbOfTuples1=PyInt_AS_LONG(elt0); - if(nbOfTuples1<0) - throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !"); - if(nbOfTuples) - { - if(!elt2) - { - if(PyInt_Check(nbOfTuples)) - {//DataArrayDouble.New(5,2) - int nbOfCompo=PyInt_AS_LONG(nbOfTuples); - if(nbOfCompo<0) - throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !"); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); - ret->alloc(nbOfTuples1,nbOfCompo); - return ret.retn(); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - {//DataArrayDouble.New(5) - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); - ret->alloc(nbOfTuples1,1); - return ret.retn(); - } - } - else - throw INTERP_KERNEL::Exception(msg); - } - - DataArrayDouble(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *elt2=0) throw(INTERP_KERNEL::Exception) - { - return ParaMEDMEM_DataArrayDouble_New__SWIG_1(elt0,nbOfTuples,elt2); - } - - void pushBackValsSilent(PyObject *li) throw(INTERP_KERNEL::Exception) - { - double val; - std::vector bb; - int sw,nbTuples=-1; - const char msg[]="Python wrap of DataArrayDouble::pushBackValsSilent : "; - const double *tmp=convertObjToPossibleCpp5_SingleCompo(li,sw,val,bb,msg,true,nbTuples); - self->pushBackValsSilent(tmp,tmp+nbTuples); - } - - std::string __repr__() const throw(INTERP_KERNEL::Exception) - { - std::ostringstream oss; - self->reprQuickOverview(oss); - return oss.str(); - } - - std::string __str__() const throw(INTERP_KERNEL::Exception) - { - return self->repr(); - } - - double __float__() const throw(INTERP_KERNEL::Exception) - { - return self->doubleValue(); - } - - int __len__() const throw(INTERP_KERNEL::Exception) - { - if(self->isAllocated()) - { - return self->getNumberOfTuples(); - } - else - { - throw INTERP_KERNEL::Exception("DataArrayDouble::__len__ : Instance is NOT allocated !"); - } - } - - DataArrayDoubleIterator *__iter__() - { - return self->iterator(); - } - - void setValues(PyObject *li, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) - { - const char *msg="ParaMEDMEM::DataArrayDouble::setValues : Available API are : \n-DataArrayDouble.setValues([1.,3.,4.])\n-DataArrayDouble.setValues([1.,3.,4.],3)\n-DataArrayDouble.setValues([1.,3.,4.,5.],2,2)\n-DataArrayDouble.setValues([(1.,1.7),(3.,3.7),(4.,4.7)])\n !"; - if(PyList_Check(li) || PyTuple_Check(li)) - { - if(nbOfTuples) - { - if(PyInt_Check(nbOfTuples)) - { - int nbOfTuples1=PyInt_AS_LONG(nbOfTuples); - if(nbOfTuples1<0) - throw INTERP_KERNEL::Exception("DataArrayDouble::setValues : should be a positive set of allocated memory !"); - if(nbOfComp) - { - if(PyInt_Check(nbOfComp)) - {//DataArrayDouble.setValues([1.,3.,4.,5.],2,2) - int nbOfCompo=PyInt_AS_LONG(nbOfComp); - if(nbOfCompo<0) - throw INTERP_KERNEL::Exception("DataArrayDouble::setValues : should be a positive number of components !"); - std::vector tmp=fillArrayWithPyListDbl2(li,nbOfTuples1,nbOfCompo); - self->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),self->getPointer()); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - {//DataArrayDouble.setValues([1.,3.,4.],3) - int tmpp1=-1; - std::vector tmp=fillArrayWithPyListDbl2(li,nbOfTuples1,tmpp1); - self->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),self->getPointer()); - } - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - {// DataArrayDouble.setValues([1.,3.,4.]) - int tmpp1=-1,tmpp2=-1; - std::vector tmp=fillArrayWithPyListDbl2(li,tmpp1,tmpp2); - self->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),self->getPointer()); - } - } - else - throw INTERP_KERNEL::Exception(msg); - } - - PyObject *getValues() const throw(INTERP_KERNEL::Exception) - { - const double *vals=self->getConstPointer(); - return convertDblArrToPyList(vals,self->getNbOfElems()); - } - - PyObject *isEqualIfNotWhy(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception) - { - std::string ret1; - bool ret0=self->isEqualIfNotWhy(other,prec,ret1); - PyObject *ret=PyTuple_New(2); - PyObject *ret0Py=ret0?Py_True:Py_False; - Py_XINCREF(ret0Py); - PyTuple_SetItem(ret,0,ret0Py); - PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str())); - return ret; - } - - PyObject *getValuesAsTuple() const throw(INTERP_KERNEL::Exception) - { - const double *vals=self->getConstPointer(); - int nbOfComp=self->getNumberOfComponents(); - int nbOfTuples=self->getNumberOfTuples(); - return convertDblArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); - } - - DataArrayDouble *renumber(PyObject *li) throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - return self->renumber(tmp); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - int size=self->getNumberOfTuples(); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - return self->renumber(da2->getConstPointer()); - } - } - - DataArrayDouble *renumberR(PyObject *li) throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - return self->renumberR(tmp); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - int size=self->getNumberOfTuples(); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - return self->renumberR(da2->getConstPointer()); - } - } - - DataArrayDouble *renumberAndReduce(PyObject *li, int newNbOfTuple) throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - return self->renumberAndReduce(tmp,newNbOfTuple); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - int size=self->getNumberOfTuples(); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - return self->renumberAndReduce(da2->getConstPointer(),newNbOfTuple); - } - } - - void renumberInPlace(PyObject *li) throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - self->renumberInPlace(tmp); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - int size=self->getNumberOfTuples(); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - self->renumberInPlace(da2->getConstPointer()); - } - } - - void renumberInPlaceR(PyObject *li) throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - self->renumberInPlaceR(tmp); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - int size=self->getNumberOfTuples(); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - self->renumberInPlaceR(da2->getConstPointer()); - } - } - - DataArrayDouble *selectByTupleId(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - return self->selectByTupleId(tmp,tmp+size); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - return self->selectByTupleId(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); - } - } - - DataArrayDouble *selectByTupleIdSafe(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - return self->selectByTupleIdSafe(tmp,tmp+size); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - return self->selectByTupleIdSafe(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); - } - } - - PyObject *minimalDistanceTo(const DataArrayDouble *other) const throw(INTERP_KERNEL::Exception) - { - int thisTupleId,otherTupleId; - double r0=self->minimalDistanceTo(other,thisTupleId,otherTupleId); - PyObject *ret=PyTuple_New(3); - PyTuple_SetItem(ret,0,PyFloat_FromDouble(r0)); - PyTuple_SetItem(ret,1,PyInt_FromLong(thisTupleId)); - PyTuple_SetItem(ret,2,PyInt_FromLong(otherTupleId)); - return ret; - } - - PyObject *getMaxValue() const throw(INTERP_KERNEL::Exception) - { - int tmp; - double r1=self->getMaxValue(tmp); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,PyFloat_FromDouble(r1)); - PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); - return ret; - } - - PyObject *getMaxValue2() const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *tmp; - double r1=self->getMaxValue2(tmp); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,PyFloat_FromDouble(r1)); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *getMinValue() const throw(INTERP_KERNEL::Exception) - { - int tmp; - double r1=self->getMinValue(tmp); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,PyFloat_FromDouble(r1)); - PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); - return ret; - } - - PyObject *getMinValue2() const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *tmp; - double r1=self->getMinValue2(tmp); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,PyFloat_FromDouble(r1)); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *getMinMaxPerComponent() const throw(INTERP_KERNEL::Exception) - { - int nbOfCompo=self->getNumberOfComponents(); - INTERP_KERNEL::AutoPtr tmp=new double[2*nbOfCompo]; - self->getMinMaxPerComponent(tmp); - PyObject *ret=convertDblArrToPyListOfTuple(tmp,2,nbOfCompo); - return ret; - } - - PyObject *accumulate() const throw(INTERP_KERNEL::Exception) - { - int sz=self->getNumberOfComponents(); - INTERP_KERNEL::AutoPtr tmp=new double[sz]; - self->accumulate(tmp); - return convertDblArrToPyList(tmp,sz); - } - - DataArrayDouble *keepSelectedComponents(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - std::vector tmp; - convertPyToNewIntArr3(li,tmp); - return self->keepSelectedComponents(tmp); - } - - PyObject *findCommonTuples(double prec, int limitNodeId=-1) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *comm, *commIndex; - self->findCommonTuples(prec,limitNodeId,comm,commIndex); - PyObject *res = PyList_New(2); - PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(comm),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyList_SetItem(res,1,SWIG_NewPointerObj(SWIG_as_voidptr(commIndex),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return res; - } - - PyObject *distanceToTuple(PyObject *tuple) const throw(INTERP_KERNEL::Exception) - { - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - int tupleId=-1,nbTuples=-1,nbOfCompo=self->getNumberOfComponents(); - const double *pt=convertObjToPossibleCpp5_Safe(tuple,sw,val,a,aa,bb,"Python wrap of DataArrayDouble::distanceToTuple",1,nbOfCompo,true); - // - int cellId=-1,nodeId=-1; - double ret0=self->distanceToTuple(pt,pt+nbOfCompo,tupleId); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,PyFloat_FromDouble(ret0)); - PyTuple_SetItem(ret,1,PyInt_FromLong(tupleId)); - return ret; - } - - void setSelectedComponents(const DataArrayDouble *a, PyObject *li) throw(INTERP_KERNEL::Exception) - { - std::vector tmp; - convertPyToNewIntArr3(li,tmp); - self->setSelectedComponents(a,tmp); - } - - PyObject *getTuple(int tupleId) throw(INTERP_KERNEL::Exception) - { - int sz=self->getNumberOfComponents(); - INTERP_KERNEL::AutoPtr tmp=new double[sz]; - self->getTuple(tupleId,tmp); - return convertDblArrToPyList(tmp,sz); - } - - static DataArrayDouble *Aggregate(PyObject *li) throw(INTERP_KERNEL::Exception) - { - std::vector tmp; - convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,"DataArrayDouble",tmp); - return DataArrayDouble::Aggregate(tmp); - } - - static DataArrayDouble *Meld(PyObject *li) throw(INTERP_KERNEL::Exception) - { - std::vector tmp; - convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,"DataArrayDouble",tmp); - return DataArrayDouble::Meld(tmp); - } - - DataArrayDouble *selectByTupleRanges(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - std::vector > ranges; - convertPyToVectorPairInt(li,ranges); - return self->selectByTupleRanges(ranges); - } - - PyObject *computeTupleIdsNearTuples(PyObject *pt, double eps) const throw(INTERP_KERNEL::Exception) - { - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - int nbComp=self->getNumberOfComponents(),nbTuples=-1; - const char msg[]="Python wrap of DataArrayDouble::computeTupleIdsNearTuples : "; - const double *pos=convertObjToPossibleCpp5_Safe2(pt,sw,val,a,aa,bb,msg,nbComp,true,nbTuples); - MEDCouplingAutoRefCountObjectPtr inpu=DataArrayDouble::New(); inpu->useArray(pos,false,CPP_DEALLOC,nbTuples,nbComp); - DataArrayInt *c=0,*cI=0; - self->computeTupleIdsNearTuples(inpu,eps,c,cI); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(c),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cI),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in DataArrayDouble::__getitem__ !"; - self->checkAllocated(); - int nbOfTuples=self->getNumberOfTuples(); - int nbOfComponents=self->getNumberOfComponents(); - int it1,ic1; - std::vector vt1,vc1; - std::pair > pt1,pc1; - DataArrayInt *dt1=0,*dc1=0; - int sw; - convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1); - MEDCouplingAutoRefCountObjectPtr ret; - switch(sw) - { - case 1: - if(nbOfComponents==1) - return PyFloat_FromDouble(self->getIJSafe(it1,0)); - return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - case 2: - return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - case 3: - return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - case 4: - return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - case 5: - return PyFloat_FromDouble(self->getIJSafe(it1,ic1)); - case 6: - { - ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size()); - std::vector v2(1,ic1); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 7: - { - ret=self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second); - std::vector v2(1,ic1); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 8: - { - ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems()); - std::vector v2(1,ic1); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 9: - { - ret=self->selectByTupleIdSafe(&it1,&it1+1); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 10: - { - ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size()); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 11: - { - ret=self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 12: - { - ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems()); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 13: - { - ret=self->selectByTupleIdSafe(&it1,&it1+1); - int nbOfComp=(pc1.second.first-1-pc1.first)/pc1.second.second+1; - std::vector v2(nbOfComp); - for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 14: - { - ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size()); - int nbOfComp=(pc1.second.first-1-pc1.first)/pc1.second.second+1; - std::vector v2(nbOfComp); - for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 15: - { - ret=self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second); - int nbOfComp=(pc1.second.first-1-pc1.first)/pc1.second.second+1; - std::vector v2(nbOfComp); - for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 16: - { - ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems()); - int nbOfComp=(pc1.second.first-1-pc1.first)/pc1.second.second+1; - std::vector v2(nbOfComp); - for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayDouble *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception) - { - self->checkAllocated(); - const char msg[]="Unexpected situation in DataArrayDouble::__setitem__ !"; - int nbOfTuples=self->getNumberOfTuples(); - int nbOfComponents=self->getNumberOfComponents(); - int sw1,sw2; - double i1; - std::vector v1; - DataArrayDouble *d1=0; - convertObjToPossibleCpp4(value,sw1,i1,v1,d1); - int it1,ic1; - std::vector vt1,vc1; - std::pair > pt1,pc1; - DataArrayInt *dt1=0,*dc1=0; - convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1); - MEDCouplingAutoRefCountObjectPtr tmp; - switch(sw2) - { - case 1: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false); - return self; - case 3: - self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 2: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false); - return self; - case 3: - self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 3: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false); - return self; - case 3: - self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 4: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false); - return self; - case 3: - self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 5: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false); - return self; - case 3: - self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 6: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false); - return self; - case 3: - self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 7: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false); - return self; - case 3: - self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 8: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false); - return self; - case 3: - self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 9: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size()); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false); - return self; - case 3: - self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size()); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 10: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size()); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false); - return self; - case 3: - self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size()); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 11: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size()); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false); - return self; - case 3: - self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size()); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 12: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size()); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false); - return self; - case 3: - self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size()); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 13: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false); - return self; - case 3: - self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 14: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false); - return self; - case 3: - self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 15: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false); - return self; - case 3: - self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 16: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false); - return self; - case 3: - self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - return self; - } - - DataArrayDouble *__neg__() const throw(INTERP_KERNEL::Exception) - { - return self->negate(); - } - - DataArrayDouble *__add__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __add__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyLin(1.,val); - return ret.retn(); - } - case 2: - { - return DataArrayDouble::Add(self,a); - } - case 3: - { - MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - return DataArrayDouble::Add(self,aaa); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - return DataArrayDouble::Add(self,aaa); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayDouble *__radd__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __radd__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyLin(1.,val); - return ret.retn(); - } - case 3: - { - MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - return DataArrayDouble::Add(self,aaa); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - return DataArrayDouble::Add(self,aaa); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __iadd__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - self->applyLin(1.,val); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 2: - { - self->addEqual(a); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 3: - { - MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - self->addEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - self->addEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayDouble *__sub__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __sub__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyLin(1.,-val); - return ret.retn(); - } - case 2: - { - return DataArrayDouble::Substract(self,a); - } - case 3: - { - MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - return DataArrayDouble::Substract(self,aaa); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - return DataArrayDouble::Substract(self,aaa); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayDouble *__rsub__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __rsub__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyLin(-1.,val); - return ret.retn(); - } - case 3: - { - MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - return DataArrayDouble::Substract(aaa,self); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - return DataArrayDouble::Substract(aaa,self); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __isub__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - self->applyLin(1,-val); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 2: - { - self->substractEqual(a); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 3: - { - MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - self->substractEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - self->substractEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayDouble *__mul__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __mul__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyLin(val,0.); - return ret.retn(); - } - case 2: - { - return DataArrayDouble::Multiply(self,a); - } - case 3: - { - MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - return DataArrayDouble::Multiply(self,aaa); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - return DataArrayDouble::Multiply(self,aaa); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayDouble *__rmul__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __rmul__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyLin(val,0.); - return ret.retn(); - } - case 3: - { - MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - return DataArrayDouble::Multiply(self,aaa); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - return DataArrayDouble::Multiply(self,aaa); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __imul__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - self->applyLin(val,0.); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 2: - { - self->multiplyEqual(a); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 3: - { - MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - self->multiplyEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - self->multiplyEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayDouble *__div__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __div__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - if(val==0.) - throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !"); - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyLin(1/val,0.); - return ret.retn(); - } - case 2: - { - return DataArrayDouble::Divide(self,a); - } - case 3: - { - MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - return DataArrayDouble::Divide(self,aaa); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - return DataArrayDouble::Divide(self,aaa); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayDouble *__rdiv__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __rdiv__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyInv(val); - return ret.retn(); - } - case 3: - { - MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - return DataArrayDouble::Divide(aaa,self); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - return DataArrayDouble::Divide(aaa,self); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __idiv__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - if(val==0.) - throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !"); - self->applyLin(1./val,0.); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 2: - { - self->divideEqual(a); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 3: - { - MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - self->divideEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - self->divideEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayDouble *__pow__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __pow__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyPow(val); - return ret.retn(); - } - case 2: - { - return DataArrayDouble::Pow(self,a); - } - case 3: - { - MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - return DataArrayDouble::Pow(self,aaa); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - return DataArrayDouble::Pow(self,aaa); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayDouble *__rpow__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __rpow__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyRPow(val); - return ret.retn(); - } - case 3: - { - MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - return DataArrayDouble::Pow(aaa,self); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - return DataArrayDouble::Pow(aaa,self); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - PyObject *___ipow___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __ipow__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - self->applyPow(val); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 2: - { - self->powEqual(a); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 3: - { - MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - self->powEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - self->powEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - PyObject *computeTupleIdsNearTuples(const DataArrayDouble *other, double eps) - { - DataArrayInt *c=0,*cI=0; - // - self->computeTupleIdsNearTuples(other,eps,c,cI); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(c),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cI),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - }; - -%extend ParaMEDMEM::DataArrayIntTuple -{ - std::string __str__() const throw(INTERP_KERNEL::Exception) - { - return self->repr(); - } - - int __int__() const throw(INTERP_KERNEL::Exception) - { - return self->intValue(); - } - - DataArrayInt *buildDAInt() throw(INTERP_KERNEL::Exception) - { - return self->buildDAInt(1,self->getNumberOfCompo()); - } - - PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - MEDCouplingAutoRefCountObjectPtr ret=self->buildDAInt(1,self->getNumberOfCompo()); - ParaMEDMEM_DataArrayInt____iadd___(ret,0,obj); - Py_XINCREF(trueSelf); - return trueSelf; - } - - PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - MEDCouplingAutoRefCountObjectPtr ret=self->buildDAInt(1,self->getNumberOfCompo()); - ParaMEDMEM_DataArrayInt____isub___(ret,0,obj); - Py_XINCREF(trueSelf); - return trueSelf; - } - - PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - MEDCouplingAutoRefCountObjectPtr ret=self->buildDAInt(1,self->getNumberOfCompo()); - ParaMEDMEM_DataArrayInt____imul___(ret,0,obj); - Py_XINCREF(trueSelf); - return trueSelf; - } - - PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - MEDCouplingAutoRefCountObjectPtr ret=self->buildDAInt(1,self->getNumberOfCompo()); - ParaMEDMEM_DataArrayInt____idiv___(ret,0,obj); - Py_XINCREF(trueSelf); - return trueSelf; - } - - PyObject *___imod___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - MEDCouplingAutoRefCountObjectPtr ret=self->buildDAInt(1,self->getNumberOfCompo()); - ParaMEDMEM_DataArrayInt____imod___(ret,0,obj); - Py_XINCREF(trueSelf); - return trueSelf; - } - - PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - int sw; - int singleVal; - std::vector multiVal; - std::pair > slic; - ParaMEDMEM::DataArrayInt *daIntTyypp=0; - const int *pt=self->getConstPointer(); - int nbc=self->getNumberOfCompo(); - convertObjToPossibleCpp2(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp); - switch(sw) - { - case 1: - { - if(singleVal>=nbc) - { - std::ostringstream oss; - oss << "Requesting for id " << singleVal << " having only " << nbc << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - if(singleVal>=0) - return PyInt_FromLong(pt[singleVal]); - else - { - if(nbc+singleVal>0) - return PyInt_FromLong(pt[nbc+singleVal]); - else - { - std::ostringstream oss; - oss << "Requesting for id " << singleVal << " having only " << nbc << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - } - } - case 2: - { - PyObject *t=PyTuple_New(multiVal.size()); - for(int j=0;j<(int)multiVal.size();j++) - { - int cid=multiVal[j]; - if(cid>=nbc) - { - std::ostringstream oss; - oss << "Requesting for id #" << cid << " having only " << nbc << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - PyTuple_SetItem(t,j,PyInt_FromLong(pt[cid])); - } - return t; - } - case 3: - { - int sz=DataArray::GetNumberOfItemGivenBES(slic.first,slic.second.first,slic.second.second,""); - PyObject *t=PyTuple_New(sz); - for(int j=0;j multiValV; - std::pair > slicV; - ParaMEDMEM::DataArrayIntTuple *daIntTyyppV=0; - int nbc=self->getNumberOfCompo(); - convertObjToPossibleCpp22(value,nbc,sw1,singleValV,multiValV,slicV,daIntTyyppV); - int singleVal; - std::vector multiVal; - std::pair > slic; - ParaMEDMEM::DataArrayInt *daIntTyypp=0; - int *pt=self->getPointer(); - convertObjToPossibleCpp2(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp); - switch(sw2) - { - case 1: - { - if(singleVal>=nbc) - { - std::ostringstream oss; - oss << "Requesting for setting id # " << singleVal << " having only " << nbc << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - switch(sw1) - { - case 1: - { - pt[singleVal]=singleValV; - return self; - } - case 2: - { - if(multiValV.size()!=1) - { - std::ostringstream oss; - oss << "Requesting for setting id # " << singleVal << " with a list or tuple with size != 1 ! "; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - pt[singleVal]=multiValV[0]; - return self; - } - case 4: - { - pt[singleVal]=daIntTyyppV->getConstPointer()[0]; - return self; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - case 2: - { - switch(sw1) - { - case 1: - { - for(std::vector::const_iterator it=multiVal.begin();it!=multiVal.end();it++) - { - if(*it>=nbc) - { - std::ostringstream oss; - oss << "Requesting for setting id # " << *it << " having only " << nbc << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - pt[*it]=singleValV; - } - return self; - } - case 2: - { - if(multiVal.size()!=multiValV.size()) - { - std::ostringstream oss; - oss << "Mismatch length of during assignment : " << multiValV.size() << " != " << multiVal.size() << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - for(int i=0;i<(int)multiVal.size();i++) - { - int pos=multiVal[i]; - if(pos>=nbc) - { - std::ostringstream oss; - oss << "Requesting for setting id # " << pos << " having only " << nbc << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - pt[multiVal[i]]=multiValV[i]; - } - return self; - } - case 4: - { - const int *ptV=daIntTyyppV->getConstPointer(); - if(nbc>daIntTyyppV->getNumberOfCompo()) - { - std::ostringstream oss; - oss << "Mismatch length of during assignment : " << nbc << " != " << daIntTyyppV->getNumberOfCompo() << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - std::copy(ptV,ptV+nbc,pt); - return self; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - case 3: - { - int sz=DataArray::GetNumberOfItemGivenBES(slic.first,slic.second.first,slic.second.second,""); - switch(sw1) - { - case 1: - { - for(int j=0;jgetConstPointer(); - if(sz>daIntTyyppV->getNumberOfCompo()) - { - std::ostringstream oss; - oss << "Mismatch length of during assignment : " << nbc << " != " << daIntTyyppV->getNumberOfCompo() << " !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - for(int j=0;jnextt(); - if(ret) - return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,SWIG_POINTER_OWN | 0); - else - { - PyErr_SetString(PyExc_StopIteration,"No more data."); - return 0; - } - } -} - -%extend ParaMEDMEM::DataArrayInt - { - DataArrayInt() throw(INTERP_KERNEL::Exception) - { - return DataArrayInt::New(); - } - - static DataArrayInt *New(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) - { - const char *msg="ParaMEDMEM::DataArrayInt::New : Available API are : \n-DataArrayInt.New()\n--DataArrayInt.New([1,3,4])\n-DataArrayInt.New([1,3,4],3)\n-DataArrayInt.New([1,3,4,5],2,2)\n-DataArrayInt.New(5)\n-DataArrayInt.New(5,2) !"; - if(PyList_Check(elt0) || PyTuple_Check(elt0)) - { - if(nbOfTuples) - { - if(PyInt_Check(nbOfTuples)) - { - int nbOfTuples1=PyInt_AS_LONG(nbOfTuples); - if(nbOfTuples1<0) - throw INTERP_KERNEL::Exception("DataArrayInt::New : should be a positive set of allocated memory !"); - if(nbOfComp) - { - if(PyInt_Check(nbOfComp)) - {//DataArrayInt.New([1,3,4,5],2,2) - int nbOfCompo=PyInt_AS_LONG(nbOfComp); - if(nbOfCompo<0) - throw INTERP_KERNEL::Exception("DataArrayInt::New : should be a positive number of components !"); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); - std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,nbOfCompo); - ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - return ret.retn(); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - {//DataArrayInt.New([1,3,4],3) - MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); - int tmpp1=-1; - std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,tmpp1); - ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - return ret.retn(); - } - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - {// DataArrayInt.New([1,3,4]) - MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); - int tmpp1=-1,tmpp2=-1; - std::vector tmp=fillArrayWithPyListInt2(elt0,tmpp1,tmpp2); - ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - return ret.retn(); - } - } - else if(PyInt_Check(elt0)) - { - int nbOfTuples1=PyInt_AS_LONG(elt0); - if(nbOfTuples1<0) - throw INTERP_KERNEL::Exception("DataArrayInt::New : should be a positive set of allocated memory !"); - if(nbOfTuples) - { - if(!nbOfComp) - { - if(PyInt_Check(nbOfTuples)) - {//DataArrayInt.New(5,2) - int nbOfCompo=PyInt_AS_LONG(nbOfTuples); - if(nbOfCompo<0) - throw INTERP_KERNEL::Exception("DataArrayInt::New : should be a positive number of components !"); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); - ret->alloc(nbOfTuples1,nbOfCompo); - return ret.retn(); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - {//DataArrayInt.New(5) - MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); - ret->alloc(nbOfTuples1,1); - return ret.retn(); - } - } - else - throw INTERP_KERNEL::Exception(msg); - } - - DataArrayInt(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) - { - return ParaMEDMEM_DataArrayInt_New__SWIG_1(elt0,nbOfTuples,nbOfComp); - } - - std::string __str__() const throw(INTERP_KERNEL::Exception) - { - return self->repr(); - } - - int __len__() const throw(INTERP_KERNEL::Exception) - { - if(self->isAllocated()) - { - return self->getNumberOfTuples(); - } - else - { - throw INTERP_KERNEL::Exception("DataArrayInt::__len__ : Instance is NOT allocated !"); - } - } - - int __int__() const throw(INTERP_KERNEL::Exception) - { - return self->intValue(); - } - - DataArrayIntIterator *__iter__() - { - return self->iterator(); - } - - PyObject *accumulate() const throw(INTERP_KERNEL::Exception) - { - int sz=self->getNumberOfComponents(); - INTERP_KERNEL::AutoPtr tmp=new int[sz]; - self->accumulate(tmp); - return convertIntArrToPyList(tmp,sz); - } - - static PyObject *BuildOld2NewArrayFromSurjectiveFormat2(int nbOfOldTuples, PyObject *arr, PyObject *arrI) throw(INTERP_KERNEL::Exception) - { - int newNbOfTuples=-1; - int szArr,szArrI,sw,iTypppArr,iTypppArrI; - std::vector stdvecTyyppArr,stdvecTyyppArrI; - const int *arrPtr=convertObjToPossibleCpp1_Safe(arr,sw,szArr,iTypppArr,stdvecTyyppArr); - const int *arrIPtr=convertObjToPossibleCpp1_Safe(arrI,sw,szArrI,iTypppArrI,stdvecTyyppArrI); - DataArrayInt *ret0=ParaMEDMEM::DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(nbOfOldTuples,arrPtr,arrIPtr,arrIPtr+szArrI,newNbOfTuples); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj((void*)ret0,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,SWIG_POINTER_OWN | 0)); - PyTuple_SetItem(ret,1,PyInt_FromLong(newNbOfTuples)); - return ret; - } - - void setValues(PyObject *li, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) - { - const char *msg="ParaMEDMEM::DataArrayInt::setValues : Available API are : \n-DataArrayInt.setValues([1,3,4])\n-DataArrayInt.setValues([1,3,4],3)\n-DataArrayInt.setValues([1,3,4,5],2,2)\n-DataArrayInt.New(5)\n !"; - if(PyList_Check(li) || PyTuple_Check(li)) - { - if(nbOfTuples) - { - if(PyInt_Check(nbOfTuples)) - { - int nbOfTuples1=PyInt_AS_LONG(nbOfTuples); - if(nbOfTuples<0) - throw INTERP_KERNEL::Exception("DataArrayInt::setValue : should be a positive set of allocated memory !"); - if(nbOfComp) - { - if(PyInt_Check(nbOfComp)) - {//DataArrayInt.setValues([1,3,4,5],2,2) - int nbOfCompo=PyInt_AS_LONG(nbOfComp); - if(nbOfCompo<0) - throw INTERP_KERNEL::Exception("DataArrayInt::setValue : should be a positive number of components !"); - std::vector tmp=fillArrayWithPyListInt2(li,nbOfTuples1,nbOfCompo); - self->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),self->getPointer()); - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - {//DataArrayInt.setValues([1,3,4],3) - int tmpp1=-1; - std::vector tmp=fillArrayWithPyListInt2(li,nbOfTuples1,tmpp1); - self->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),self->getPointer()); - } - } - else - throw INTERP_KERNEL::Exception(msg); - } - else - {// DataArrayInt.setValues([1,3,4]) - int tmpp1=-1,tmpp2=-1; - std::vector tmp=fillArrayWithPyListInt2(li,tmpp1,tmpp2); - self->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),self->getPointer()); - } - } - else - throw INTERP_KERNEL::Exception(msg); - } - - PyObject *getValues() const throw(INTERP_KERNEL::Exception) - { - const int *vals=self->getConstPointer(); - return convertIntArrToPyList(vals,self->getNbOfElems()); - } - - PyObject *isEqualIfNotWhy(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception) - { - std::string ret1; - bool ret0=self->isEqualIfNotWhy(other,ret1); - PyObject *ret=PyTuple_New(2); - PyObject *ret0Py=ret0?Py_True:Py_False; - Py_XINCREF(ret0Py); - PyTuple_SetItem(ret,0,ret0Py); - PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str())); - return ret; - } - - PyObject *getValuesAsTuple() const throw(INTERP_KERNEL::Exception) - { - const int *vals=self->getConstPointer(); - int nbOfComp=self->getNumberOfComponents(); - int nbOfTuples=self->getNumberOfTuples(); - return convertIntArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); - } - - static PyObject *MakePartition(PyObject *gps, int newNb) throw(INTERP_KERNEL::Exception) - { - std::vector groups; - std::vector< std::vector > fidsOfGroups; - convertFromPyObjVectorOfObj(gps,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,"DataArrayInt",groups); - ParaMEDMEM::DataArrayInt *ret0=ParaMEDMEM::DataArrayInt::MakePartition(groups,newNb,fidsOfGroups); - PyObject *ret = PyList_New(2); - PyList_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - int sz=fidsOfGroups.size(); - PyObject *ret1 = PyList_New(sz); - for(int i=0;i tmp=convertPyToNewIntArr2(li,&size); - self->transformWithIndArr(tmp,tmp+size); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - self->transformWithIndArr(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); - } - } - - DataArrayInt *getIdsEqualList(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - int sw; - int singleVal; - std::vector multiVal; - std::pair > slic; - ParaMEDMEM::DataArrayInt *daIntTyypp=0; - convertObjToPossibleCpp2(obj,self->getNumberOfTuples(),sw,singleVal,multiVal,slic,daIntTyypp); - switch(sw) - { - case 1: - return self->getIdsEqualList(&singleVal,&singleVal+1); - case 2: - return self->getIdsEqualList(&multiVal[0],&multiVal[0]+multiVal.size()); - case 4: - return self->getIdsEqualList(daIntTyypp->begin(),daIntTyypp->end()); - default: - throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqualList : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); - } - } - - DataArrayInt *getIdsNotEqualList(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - int sw; - int singleVal; - std::vector multiVal; - std::pair > slic; - ParaMEDMEM::DataArrayInt *daIntTyypp=0; - convertObjToPossibleCpp2(obj,self->getNumberOfTuples(),sw,singleVal,multiVal,slic,daIntTyypp); - switch(sw) - { - case 1: - return self->getIdsNotEqualList(&singleVal,&singleVal+1); - case 2: - return self->getIdsNotEqualList(&multiVal[0],&multiVal[0]+multiVal.size()); - case 4: - return self->getIdsNotEqualList(daIntTyypp->begin(),daIntTyypp->end()); - default: - throw INTERP_KERNEL::Exception("DataArrayInt::getIdsNotEqualList : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); - } - } - - PyObject *splitByValueRange(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *ret0=0,*ret1=0,*ret2=0; - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - self->splitByValueRange(tmp,(int *)tmp+size,ret0,ret1,ret2); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - int size=self->getNumberOfTuples(); - self->splitByValueRange(da2->getConstPointer(),da2->getConstPointer()+size,ret0,ret1,ret2); - } - PyObject *ret = PyList_New(3); - PyList_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyList_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyList_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(ret2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - return ret; - } - - DataArrayInt *transformWithIndArrR(PyObject *li) const - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - return self->transformWithIndArrR(tmp,tmp+size); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - return self->transformWithIndArrR(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); - } - } - - void renumberInPlace(PyObject *li) throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - self->renumberInPlace(tmp); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - int size=self->getNumberOfTuples(); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - self->renumberInPlace(da2->getConstPointer()); - } - } - - void renumberInPlaceR(PyObject *li) throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - self->renumberInPlaceR(tmp); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - int size=self->getNumberOfTuples(); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - self->renumberInPlaceR(da2->getConstPointer()); - } - } - - DataArrayInt *renumberAndReduce(PyObject *li, int newNbOfTuple) throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - return self->renumberAndReduce(tmp,newNbOfTuple); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - int size=self->getNumberOfTuples(); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - return self->renumberAndReduce(da2->getConstPointer(),newNbOfTuple); - } - } - - DataArrayInt *renumber(PyObject *li) throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - return self->renumber(tmp); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - int size=self->getNumberOfTuples(); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - return self->renumber(da2->getConstPointer()); - } - } - - DataArrayInt *renumberR(PyObject *li) throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - return self->renumberR(tmp); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - int size=self->getNumberOfTuples(); - if(size!=self->getNumberOfTuples()) - { - throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); - } - return self->renumberR(da2->getConstPointer()); - } - } - - DataArrayInt *selectByTupleId(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - return self->selectByTupleId(tmp,tmp+size); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - return self->selectByTupleId(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); - } - } - - DataArrayInt *selectByTupleIdSafe(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - return self->selectByTupleIdSafe(tmp,tmp+size); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - return self->selectByTupleIdSafe(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); - } - } - - DataArrayInt *keepSelectedComponents(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - std::vector tmp; - convertPyToNewIntArr3(li,tmp); - return self->keepSelectedComponents(tmp); - } - - void setSelectedComponents(const DataArrayInt *a, PyObject *li) throw(INTERP_KERNEL::Exception) - { - std::vector tmp; - convertPyToNewIntArr3(li,tmp); - self->setSelectedComponents(a,tmp); - } - - PyObject *getTuple(int tupleId) throw(INTERP_KERNEL::Exception) - { - int sz=self->getNumberOfComponents(); - INTERP_KERNEL::AutoPtr tmp=new int[sz]; - self->getTuple(tupleId,tmp); - return convertIntArrToPyList(tmp,sz); - } - - PyObject *changeSurjectiveFormat(int targetNb) const throw(INTERP_KERNEL::Exception) - { - DataArrayInt *arr=0; - DataArrayInt *arrI=0; - self->changeSurjectiveFormat(targetNb,arr,arrI); - PyObject *res = PyList_New(2); - PyList_SetItem(res,0,SWIG_NewPointerObj((void*)arr,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,SWIG_POINTER_OWN | 0)); - PyList_SetItem(res,1,SWIG_NewPointerObj((void*)arrI,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,SWIG_POINTER_OWN | 0)); - return res; - } - - DataArrayInt *selectByTupleRanges(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - std::vector > ranges; - convertPyToVectorPairInt(li,ranges); - return self->selectByTupleRanges(ranges); - } - - static DataArrayInt *Meld(PyObject *li) throw(INTERP_KERNEL::Exception) - { - std::vector tmp; - convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,"DataArrayInt",tmp); - return DataArrayInt::Meld(tmp); - } - - static DataArrayInt *Aggregate(PyObject *li) throw(INTERP_KERNEL::Exception) - { - std::vector tmp; - convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,"DataArrayInt",tmp); - return DataArrayInt::Aggregate(tmp); - } - - static DataArrayInt *BuildUnion(PyObject *li) throw(INTERP_KERNEL::Exception) - { - std::vector tmp; - convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,"DataArrayInt",tmp); - return DataArrayInt::BuildUnion(tmp); - } - - static DataArrayInt *BuildIntersection(PyObject *li) throw(INTERP_KERNEL::Exception) - { - std::vector tmp; - convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,"DataArrayInt",tmp); - return DataArrayInt::BuildIntersection(tmp); - } - - PyObject *getMaxValue() const throw(INTERP_KERNEL::Exception) - { - int tmp; - int r1=self->getMaxValue(tmp); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,PyInt_FromLong(r1)); - PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); - return ret; - } - - PyObject *getMinValue() const throw(INTERP_KERNEL::Exception) - { - int tmp; - int r1=self->getMinValue(tmp); - PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,PyInt_FromLong(r1)); - PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); - return ret; - } - - int index(PyObject *obj) const throw(INTERP_KERNEL::Exception) - { - int nbOfCompo=self->getNumberOfComponents(); - switch(nbOfCompo) - { - case 1: - { - if(PyInt_Check(obj)) - { - int val=(int)PyInt_AS_LONG(obj); - return self->locateValue(val); - } - else - throw INTERP_KERNEL::Exception("DataArrayInt::index : 'this' contains one component and trying to find an element which is not an integer !"); - } - default: - { - std::vector arr; - convertPyToNewIntArr3(obj,arr); - return self->locateTuple(arr); - } - } - } - - bool __contains__(PyObject *obj) const throw(INTERP_KERNEL::Exception) - { - int nbOfCompo=self->getNumberOfComponents(); - switch(nbOfCompo) - { - case 0: - return false; - case 1: - { - if(PyInt_Check(obj)) - { - int val=(int)PyInt_AS_LONG(obj); - return self->presenceOfValue(val); - } - else - throw INTERP_KERNEL::Exception("DataArrayInt::__contains__ : 'this' contains one component and trying to find an element which is not an integer !"); - } - default: - { - std::vector arr; - convertPyToNewIntArr3(obj,arr); - return self->presenceOfTuple(arr); - } - } - } - - PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in DataArrayInt::__getitem__ !"; - self->checkAllocated(); - int nbOfTuples=self->getNumberOfTuples(); - int nbOfComponents=self->getNumberOfComponents(); - int it1,ic1; - std::vector vt1,vc1; - std::pair > pt1,pc1; - DataArrayInt *dt1=0,*dc1=0; - int sw; - convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1); - MEDCouplingAutoRefCountObjectPtr ret; - switch(sw) - { - case 1: - { - if(nbOfComponents==1) - return PyInt_FromLong(self->getIJSafe(it1,0)); - return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - case 2: - return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - case 3: - return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - case 4: - return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - case 5: - return PyInt_FromLong(self->getIJSafe(it1,ic1)); - case 6: - { - ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size()); - std::vector v2(1,ic1); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - case 7: - { - ret=self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second); - std::vector v2(1,ic1); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - case 8: - { - ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems()); - std::vector v2(1,ic1); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - case 9: - { - ret=self->selectByTupleIdSafe(&it1,&it1+1); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - case 10: - { - ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size()); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - case 11: - { - ret=self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - case 12: - { - ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems()); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - case 13: - { - ret=self->selectByTupleIdSafe(&it1,&it1+1); - int nbOfComp=(pc1.second.first-1-pc1.first)/pc1.second.second+1; - std::vector v2(nbOfComp); - for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - case 14: - { - ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size()); - int nbOfComp=(pc1.second.first-1-pc1.first)/pc1.second.second+1; - std::vector v2(nbOfComp); - for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - case 15: - { - ret=self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second); - int nbOfComp=(pc1.second.first-1-pc1.first)/pc1.second.second+1; - std::vector v2(nbOfComp); - for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - case 16: - { - ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems()); - int nbOfComp=(pc1.second.first-1-pc1.first)/pc1.second.second+1; - std::vector v2(nbOfComp); - for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayInt *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception) - { - self->checkAllocated(); - const char msg[]="Unexpected situation in __setitem__ !"; - int nbOfTuples=self->getNumberOfTuples(); - int nbOfComponents=self->getNumberOfComponents(); - int sw1,sw2; - int i1; - std::vector v1; - DataArrayInt *d1=0; - DataArrayIntTuple *dd1=0; - convertObjToPossibleCpp1(value,sw1,i1,v1,d1,dd1); - int it1,ic1; - std::vector vt1,vc1; - std::pair > pt1,pc1; - DataArrayInt *dt1=0,*dc1=0; - convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1); - MEDCouplingAutoRefCountObjectPtr tmp; - switch(sw2) - { - case 1: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1); - return self; - case 2: - tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false); - return self; - case 3: - self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1); - return self; - case 4: - tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); - self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 2: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1); - return self; - case 2: - tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false); - return self; - case 3: - self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1); - return self; - case 4: - tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); - self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 3: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1); - return self; - case 2: - tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false); - return self; - case 3: - self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1); - return self; - case 4: - tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); - self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 4: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1); - return self; - case 2: - tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false); - return self; - case 3: - self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1); - return self; - case 4: - tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); - self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 5: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1); - return self; - case 2: - tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false); - return self; - case 3: - self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1); - return self; - case 4: - tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); - self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 6: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1); - return self; - case 2: - tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false); - return self; - case 3: - self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1); - return self; - case 4: - tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); - self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 7: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1); - return self; - case 2: - tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false); - return self; - case 3: - self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1); - return self; - case 4: - tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); - self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 8: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1); - return self; - case 2: - tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false); - return self; - case 3: - self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1); - return self; - case 4: - tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); - self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 9: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size()); - return self; - case 2: - tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false); - return self; - case 3: - self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size()); - return self; - case 4: - tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); - self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size()); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 10: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size()); - return self; - case 2: - tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false); - return self; - case 3: - self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size()); - return self; - case 4: - tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); - self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size()); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 11: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size()); - return self; - case 2: - tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false); - return self; - case 3: - self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size()); - return self; - case 4: - tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); - self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size()); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 12: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size()); - return self; - case 2: - tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false); - return self; - case 3: - self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size()); - return self; - case 4: - tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); - self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size()); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 13: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second); - return self; - case 2: - tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false); - return self; - case 3: - self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second); - return self; - case 4: - tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); - self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 14: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second); - return self; - case 2: - tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false); - return self; - case 3: - self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second); - return self; - case 4: - tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); - self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 15: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second); - return self; - case 2: - tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false); - return self; - case 3: - self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second); - return self; - case 4: - tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); - self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 16: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second); - return self; - case 2: - tmp=DataArrayInt::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false); - return self; - case 3: - self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second); - return self; - case 4: - tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); - self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - return self; - } - - DataArrayInt *__neg__() const throw(INTERP_KERNEL::Exception) - { - return self->negate(); - } - - DataArrayInt *__add__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __add__ !"; - int val; - DataArrayInt *a; - std::vector aa; - DataArrayIntTuple *aaa; - int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyLin(1,val); - return ret.retn(); - } - case 2: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Add(self,aaa); - } - case 3: - { - return DataArrayInt::Add(self,a); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); - return DataArrayInt::Add(self,aaaa); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayInt *__radd__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __radd__ !"; - int val; - DataArrayInt *a; - std::vector aa; - DataArrayIntTuple *aaa; - int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyLin(1,val); - return ret.retn(); - } - case 2: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Add(self,aaa); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); - return DataArrayInt::Add(self,aaaa); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __iadd__ !"; - int val; - DataArrayInt *a; - std::vector aa; - DataArrayIntTuple *aaa; - int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); - switch(sw) - { - case 1: - { - self->applyLin(1,val); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 2: - { - MEDCouplingAutoRefCountObjectPtr bb=DataArrayInt::New(); bb->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - self->addEqual(bb); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 3: - { - self->addEqual(a); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); - self->addEqual(aaaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayInt *__sub__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __sub__ !"; - int val; - DataArrayInt *a; - std::vector aa; - DataArrayIntTuple *aaa; - int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyLin(1,-val); - return ret.retn(); - } - case 2: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Substract(self,aaa); - } - case 3: - { - return DataArrayInt::Substract(self,a); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); - return DataArrayInt::Substract(self,aaaa); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayInt *__rsub__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __rsub__ !"; - int val; - DataArrayInt *a; - std::vector aa; - DataArrayIntTuple *aaa; - int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyLin(-1,val); - return ret.retn(); - } - case 2: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Substract(aaa,self); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); - return DataArrayInt::Substract(aaaa,self); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __isub__ !"; - int val; - DataArrayInt *a; - std::vector aa; - DataArrayIntTuple *aaa; - int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); - switch(sw) - { - case 1: - { - self->applyLin(1,-val); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 2: - { - MEDCouplingAutoRefCountObjectPtr bb=DataArrayInt::New(); bb->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - self->substractEqual(bb); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 3: - { - self->substractEqual(a); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); - self->substractEqual(aaaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayInt *__mul__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __mul__ !"; - int val; - DataArrayInt *a; - std::vector aa; - DataArrayIntTuple *aaa; - int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyLin(val,0); - return ret.retn(); - } - case 2: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Multiply(self,aaa); - } - case 3: - { - return DataArrayInt::Multiply(self,a); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); - return DataArrayInt::Multiply(self,aaaa); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayInt *__rmul__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __rmul__ !"; - int val; - DataArrayInt *a; - std::vector aa; - DataArrayIntTuple *aaa; - int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyLin(val,0); - return ret.retn(); - } - case 2: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Multiply(self,aaa); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); - return DataArrayInt::Multiply(self,aaaa); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __imul__ !"; - int val; - DataArrayInt *a; - std::vector aa; - DataArrayIntTuple *aaa; - int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); - switch(sw) - { - case 1: - { - self->applyLin(val,0); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 2: - { - MEDCouplingAutoRefCountObjectPtr bb=DataArrayInt::New(); bb->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - self->multiplyEqual(bb); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 3: - { - self->multiplyEqual(a); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); - self->multiplyEqual(aaaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayInt *__div__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __div__ !"; - int val; - DataArrayInt *a; - std::vector aa; - DataArrayIntTuple *aaa; - int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyDivideBy(val); - return ret.retn(); - } - case 2: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Divide(self,aaa); - } - case 3: - { - return DataArrayInt::Divide(self,a); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); - return DataArrayInt::Divide(self,aaaa); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayInt *__rdiv__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __rdiv__ !"; - int val; - DataArrayInt *a; - std::vector aa; - DataArrayIntTuple *aaa; - int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyInv(val); - return ret.retn(); - } - case 2: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Divide(aaa,self); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); - return DataArrayInt::Divide(aaaa,self); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __idiv__ !"; - int val; - DataArrayInt *a; - std::vector aa; - DataArrayIntTuple *aaa; - int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); - switch(sw) - { - case 1: - { - self->applyDivideBy(val); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 2: - { - MEDCouplingAutoRefCountObjectPtr bb=DataArrayInt::New(); bb->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - self->divideEqual(bb); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 3: - { - self->divideEqual(a); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); - self->divideEqual(aaaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayInt *__mod__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __mod__ !"; - int val; - DataArrayInt *a; - std::vector aa; - DataArrayIntTuple *aaa; - int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyModulus(val); - return ret.retn(); - } - case 2: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Modulus(self,aaa); - } - case 3: - { - return DataArrayInt::Modulus(self,a); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); - return DataArrayInt::Modulus(self,aaaa); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayInt *__rmod__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __rmod__ !"; - int val; - DataArrayInt *a; - std::vector aa; - DataArrayIntTuple *aaa; - int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyRModulus(val); - return ret.retn(); - } - case 2: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Modulus(aaa,self); - } - case 3: - { - return DataArrayInt::Modulus(a,self); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); - return DataArrayInt::Modulus(aaaa,self); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - PyObject *___imod___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __imod__ !"; - int val; - DataArrayInt *a; - std::vector aa; - DataArrayIntTuple *aaa; - int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); - switch(sw) - { - case 1: - { - self->applyModulus(val); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 3: - { - self->modulusEqual(a); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); - self->modulusEqual(aaaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayInt *__pow__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __pow__ !"; - int val; - DataArrayInt *a; - std::vector aa; - DataArrayIntTuple *aaa; - int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyPow(val); - return ret.retn(); - } - case 2: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Pow(self,aaa); - } - case 3: - { - return DataArrayInt::Pow(self,a); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); - return DataArrayInt::Pow(self,aaaa); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - DataArrayInt *__rpow__(PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __rpow__ !"; - int val; - DataArrayInt *a; - std::vector aa; - DataArrayIntTuple *aaa; - int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); - ret->applyRPow(val); - return ret.retn(); - } - case 2: - { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Pow(aaa,self); - } - case 3: - { - return DataArrayInt::Pow(a,self); - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); - return DataArrayInt::Pow(aaaa,self); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - PyObject *___ipow___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __ipow__ !"; - int val; - DataArrayInt *a; - std::vector aa; - DataArrayIntTuple *aaa; - int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); - switch(sw) - { - case 1: - { - self->applyPow(val); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 3: - { - self->powEqual(a); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 4: - { - MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); - self->powEqual(aaaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - }; + std::string __repr__() const throw(INTERP_KERNEL::Exception) + { + std::ostringstream oss; + self->reprQuickOverview(oss); + return oss.str(); + } + + PyObject *getMesh2D() const throw(INTERP_KERNEL::Exception) + { + MEDCouplingUMesh *ret=self->getMesh2D(); + if(ret) + ret->incrRef(); + return convertMesh(ret, SWIG_POINTER_OWN | 0 ); + } + PyObject *getMesh1D() const throw(INTERP_KERNEL::Exception) + { + MEDCouplingUMesh *ret=self->getMesh1D(); + if(ret) + ret->incrRef(); + return convertMesh(ret, SWIG_POINTER_OWN | 0 ); + } + PyObject *getMesh3DIds() const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *ret=self->getMesh3DIds(); + if(ret) + ret->incrRef(); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + } + }; + + class MEDCouplingStructuredMesh : public ParaMEDMEM::MEDCouplingMesh + { + public: + void updateTime() const throw(INTERP_KERNEL::Exception); + int getCellIdFromPos(int i, int j, int k) const throw(INTERP_KERNEL::Exception); + int getNodeIdFromPos(int i, int j, int k) const throw(INTERP_KERNEL::Exception); + }; + + class MEDCouplingCMesh : public ParaMEDMEM::MEDCouplingStructuredMesh + { + public: + static MEDCouplingCMesh *New(); + static MEDCouplingCMesh *New(const char *meshName); + MEDCouplingCMesh *clone(bool recDeepCpy) const; + void setCoords(const DataArrayDouble *coordsX, + const DataArrayDouble *coordsY=0, + const DataArrayDouble *coordsZ=0) throw(INTERP_KERNEL::Exception); + void setCoordsAt(int i, const DataArrayDouble *arr) throw(INTERP_KERNEL::Exception); + %extend { + MEDCouplingCMesh() + { + return MEDCouplingCMesh::New(); + } + MEDCouplingCMesh(const char *meshName) + { + return MEDCouplingCMesh::New(meshName); + } + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->simpleRepr(); + } + std::string __repr__() const throw(INTERP_KERNEL::Exception) + { + std::ostringstream oss; + self->reprQuickOverview(oss); + return oss.str(); + } + DataArrayDouble *getCoordsAt(int i) throw(INTERP_KERNEL::Exception) + { + DataArrayDouble *ret=self->getCoordsAt(i); + if(ret) + ret->incrRef(); + return ret; + } + } + }; + + class MEDCouplingCurveLinearMesh : public ParaMEDMEM::MEDCouplingStructuredMesh + { + public: + static MEDCouplingCurveLinearMesh *New(); + static MEDCouplingCurveLinearMesh *New(const char *meshName); + MEDCouplingCurveLinearMesh *clone(bool recDeepCpy) const; + void setCoords(const DataArrayDouble *coords) throw(INTERP_KERNEL::Exception); + std::vector getNodeGridStructure() const throw(INTERP_KERNEL::Exception); + %extend { + MEDCouplingCurveLinearMesh() + { + return MEDCouplingCurveLinearMesh::New(); + } + MEDCouplingCurveLinearMesh(const char *meshName) + { + return MEDCouplingCurveLinearMesh::New(meshName); + } + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->simpleRepr(); + } + std::string __repr__() const throw(INTERP_KERNEL::Exception) + { + std::ostringstream oss; + self->reprQuickOverview(oss); + return oss.str(); + } + DataArrayDouble *getCoords() throw(INTERP_KERNEL::Exception) + { + DataArrayDouble *ret=self->getCoords(); + if(ret) + ret->incrRef(); + return ret; + } + void setNodeGridStructure(PyObject *gridStruct) throw(INTERP_KERNEL::Exception) + { + int szArr,sw,iTypppArr; + std::vector stdvecTyyppArr; + const int *tmp=convertObjToPossibleCpp1_Safe(gridStruct,sw,szArr,iTypppArr,stdvecTyyppArr); + self->setNodeGridStructure(tmp,tmp+szArr); + } + } + }; + +} + +%extend ParaMEDMEM::MEDCouplingFieldDiscretization +{ + MEDCouplingFieldDiscretization *clonePart(PyObject *li) + { + int sz=0,sw=-1,val1=-1; + std::vector val2; + const int *inp=convertObjToPossibleCpp1_Safe(li,sw,sz,val1,val2); + return self->clonePart(inp,inp+sz); + } + + PyObject *buildSubMeshDataRange(const MEDCouplingMesh *mesh, int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt *&di) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *ret1=0; + int bb,ee,ss; + MEDCouplingMesh *ret0=self->buildSubMeshDataRange(mesh,begin,end,step,bb,ee,ss,ret1); + PyObject *res=PyTuple_New(2); + PyTuple_SetItem(res,0,convertMesh(ret0, SWIG_POINTER_OWN | 0 )); + if(ret1) + PyTuple_SetItem(res,1,SWIG_NewPointerObj((void*)ret1,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,SWIG_POINTER_OWN | 0)); + else + { + PyObject *res1=PySlice_New(PyInt_FromLong(bb),PyInt_FromLong(ee),PyInt_FromLong(ss)); + PyTuple_SetItem(res,1,res1); + } + return res; + } + + PyObject *computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, PyObject *tupleIds) const throw(INTERP_KERNEL::Exception) + { + std::vector vVal; int iVal=-1; + int sz=-1,sw=0; + const int *tupleIdsBg=convertObjToPossibleCpp1_Safe(tupleIds,sw,sz,iVal,vVal); + if(sw==0) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretization::computeMeshRestrictionFromTupleIds : none parameter in input !"); + DataArrayInt *ret0=0,*ret1=0; + self->computeMeshRestrictionFromTupleIds(mesh,tupleIdsBg,tupleIdsBg+sz,ret0,ret1); + PyObject *pyRet=PyTuple_New(2); + PyTuple_SetItem(pyRet,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(pyRet,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return pyRet; + } +} + +%extend ParaMEDMEM::MEDCouplingFieldDiscretizationP0 +{ + PyObject *computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, PyObject *tupleIds) const throw(INTERP_KERNEL::Exception) + { return ParaMEDMEM_MEDCouplingFieldDiscretization_computeMeshRestrictionFromTupleIds__SWIG_1(self,mesh,tupleIds); } +} + +%extend ParaMEDMEM::MEDCouplingFieldDiscretizationOnNodes +{ + PyObject *computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, PyObject *tupleIds) const throw(INTERP_KERNEL::Exception) + { return ParaMEDMEM_MEDCouplingFieldDiscretization_computeMeshRestrictionFromTupleIds__SWIG_1(self,mesh,tupleIds); } +} + +%extend ParaMEDMEM::MEDCouplingFieldDiscretizationGauss +{ + PyObject *computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, PyObject *tupleIds) const throw(INTERP_KERNEL::Exception) + { return ParaMEDMEM_MEDCouplingFieldDiscretization_computeMeshRestrictionFromTupleIds__SWIG_1(self,mesh,tupleIds); } +} + +%extend ParaMEDMEM::MEDCouplingFieldDiscretizationGaussNE +{ + PyObject *computeMeshRestrictionFromTupleIds(const MEDCouplingMesh *mesh, PyObject *tupleIds) const throw(INTERP_KERNEL::Exception) + { return ParaMEDMEM_MEDCouplingFieldDiscretization_computeMeshRestrictionFromTupleIds__SWIG_1(self,mesh,tupleIds); } +} + +%extend ParaMEDMEM::MEDCouplingFieldDiscretizationPerCell +{ + PyObject *getArrayOfDiscIds() const + { + DataArrayInt *ret=const_cast(self->getArrayOfDiscIds()); + if(ret) + ret->incrRef(); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + + PyObject *splitIntoSingleGaussDicrPerCellType() const throw(INTERP_KERNEL::Exception) + { + std::vector ret1; + std::vector ret0=self->splitIntoSingleGaussDicrPerCellType(ret1); + std::size_t sz=ret0.size(); + PyObject *pyRet=PyTuple_New(2); + PyObject *pyRet0=PyList_New((int)sz); + PyObject *pyRet1=PyList_New((int)sz); + for(std::size_t i=0;icomputeVectorOfCoefficients(mesh,arr,ret1); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,PyInt_FromLong(ret1)); + return ret; + } +} namespace ParaMEDMEM { @@ -7779,7 +2742,7 @@ namespace ParaMEDMEM %extend { PyObject *getMesh() const throw(INTERP_KERNEL::Exception) { - MEDCouplingMesh *ret1=(MEDCouplingMesh *)self->getMesh(); + MEDCouplingMesh *ret1=const_cast(self->getMesh()); if(ret1) ret1->incrRef(); return convertMesh(ret1,SWIG_POINTER_OWN | 0 ); @@ -7837,6 +2800,23 @@ namespace ParaMEDMEM return res; } + PyObject *buildSubMeshDataRange(int begin, int end, int step) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *ret1=0; + int bb,ee,ss; + MEDCouplingMesh *ret0=self->buildSubMeshDataRange(begin,end,step,bb,ee,ss,ret1); + PyObject *res=PyTuple_New(2); + PyTuple_SetItem(res,0,convertMesh(ret0, SWIG_POINTER_OWN | 0 )); + if(ret1) + PyTuple_SetItem(res,1,SWIG_NewPointerObj((void*)ret1,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,SWIG_POINTER_OWN | 0)); + else + { + PyObject *res1=PySlice_New(PyInt_FromLong(bb),PyInt_FromLong(ee),PyInt_FromLong(ss)); + PyTuple_SetItem(res,1,res1); + } + return res; + } + DataArrayInt *computeTupleIdsToSelectFromCellIds(PyObject *li) const { int sw; @@ -7918,9 +2898,16 @@ namespace ParaMEDMEM } std::string __str__() const throw(INTERP_KERNEL::Exception) - { - return self->simpleRepr(); - } + { + return self->simpleRepr(); + } + + std::string __repr__() const throw(INTERP_KERNEL::Exception) + { + std::ostringstream oss; + self->reprQuickOverview(oss); + return oss.str(); + } } }; @@ -7963,8 +2950,8 @@ namespace ParaMEDMEM void setTimeValue(double val) throw(INTERP_KERNEL::Exception); void setEndTimeValue(double val) throw(INTERP_KERNEL::Exception); void updateTime() const throw(INTERP_KERNEL::Exception); - void changeUnderlyingMesh(const MEDCouplingMesh *other, int levOfCheck, double prec) throw(INTERP_KERNEL::Exception); - void substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double prec) throw(INTERP_KERNEL::Exception); + void changeUnderlyingMesh(const MEDCouplingMesh *other, int levOfCheck, double precOnMesh, double eps=1e-15) throw(INTERP_KERNEL::Exception); + void substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double precOnMesh, double eps=1e-15) throw(INTERP_KERNEL::Exception); bool mergeNodes(double eps, double epsOnVals=1e-15) throw(INTERP_KERNEL::Exception); bool mergeNodes2(double eps, double epsOnVals=1e-15) throw(INTERP_KERNEL::Exception); bool zipCoords(double epsOnVals=1e-15) throw(INTERP_KERNEL::Exception); @@ -8004,6 +2991,7 @@ namespace ParaMEDMEM double normL1(int compId) const throw(INTERP_KERNEL::Exception); double normL2(int compId) const throw(INTERP_KERNEL::Exception); DataArrayInt *getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *buildSubPartRange(int begin, int end, int step) const throw(INTERP_KERNEL::Exception); static MEDCouplingFieldDouble *MergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); static MEDCouplingFieldDouble *MeldFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); static MEDCouplingFieldDouble *DotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); @@ -8018,10 +3006,7 @@ namespace ParaMEDMEM static MEDCouplingFieldDouble *MultiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); static MEDCouplingFieldDouble *DivideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *min(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); - MEDCouplingFieldDouble *operator+(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); - MEDCouplingFieldDouble *operator-(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); - MEDCouplingFieldDouble *operator*(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); - MEDCouplingFieldDouble *operator/(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *negate() const throw(INTERP_KERNEL::Exception); %extend { MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME) { @@ -8038,6 +3023,13 @@ namespace ParaMEDMEM return self->simpleRepr(); } + std::string __repr__() const throw(INTERP_KERNEL::Exception) + { + std::ostringstream oss; + self->reprQuickOverview(oss); + return oss.str(); + } + DataArrayDouble *getArray() throw(INTERP_KERNEL::Exception) { DataArrayDouble *ret=self->getArray(); @@ -8270,7 +3262,7 @@ namespace ParaMEDMEM self->renumberCells(da2->getConstPointer(),check); } } - void renumberNodes(PyObject *li) throw(INTERP_KERNEL::Exception) + void renumberNodes(PyObject *li, double eps=1e-15) throw(INTERP_KERNEL::Exception) { void *da=0; int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); @@ -8278,7 +3270,7 @@ namespace ParaMEDMEM { int size; INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - self->renumberNodes(tmp); + self->renumberNodes(tmp,eps); } else { @@ -8286,7 +3278,7 @@ namespace ParaMEDMEM if(!da2) throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); da2->checkAllocated(); - self->renumberNodes(da2->getConstPointer()); + self->renumberNodes(da2->getConstPointer(),eps); } } @@ -8335,8 +3327,7 @@ namespace ParaMEDMEM } case 3: { - MEDCouplingAutoRefCountObjectPtr rg=DataArrayInt::Range(slic.first,slic.second.first,slic.second.second); - return self->buildSubPart(rg->begin(),rg->end()); + return self->buildSubPartRange(slic.first,slic.second.first,slic.second.second); } case 4: { @@ -8352,7 +3343,60 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *__getitem__(PyObject *li) const throw(INTERP_KERNEL::Exception) { - return ParaMEDMEM_MEDCouplingFieldDouble_buildSubPart(self,li); + const char msg[]="MEDCouplingFieldDouble::__getitem__ : invalid call Available API are : \n-myField[dataArrayInt]\n-myField[slice]\n-myField[pythonListOfCellIds]\n-myField[integer]\n-myField[dataArrayInt,1]\n-myField[slice,1]\n-myField[pythonListOfCellIds,1]\n-myField[integer,1]\n"; + if(PyTuple_Check(li)) + { + Py_ssize_t sz=PyTuple_Size(li); + if(sz!=2) + throw INTERP_KERNEL::Exception(msg); + PyObject *elt0=PyTuple_GetItem(li,0),*elt1=PyTuple_GetItem(li,1); + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + if(!self->getArray()) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::__getitem__ : no array set on field to deduce number of components !"); + try + { convertObjToPossibleCpp2(elt1,self->getArray()->getNumberOfComponents(),sw,singleVal,multiVal,slic,daIntTyypp); } + catch(INTERP_KERNEL::Exception& e) + { std::ostringstream oss; oss << "MEDCouplingFieldDouble::__getitem__ : invalid type in 2nd parameter (compo) !" << e.what(); throw INTERP_KERNEL::Exception(oss.str().c_str()); } + MEDCouplingAutoRefCountObjectPtr ret0=ParaMEDMEM_MEDCouplingFieldDouble_buildSubPart(self,elt0); + DataArrayDouble *ret0Arr=ret0->getArray(); + if(!ret0Arr) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::__getitem__ : no array exists to apply restriction on component on it !"); + switch(sw) + { + case 1: + { + std::vector v2(1,singleVal); + MEDCouplingAutoRefCountObjectPtr aarr=ret0Arr->keepSelectedComponents(v2); + ret0->setArray(aarr); + return ret0.retn(); + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr aarr=ret0Arr->keepSelectedComponents(multiVal); + ret0->setArray(aarr); + return ret0.retn(); + } + case 3: + { + int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(slic.first,slic.second.first,slic.second.second,"MEDCouplingFieldDouble::__getitem__ : invalid range in 2nd parameter (components) !"); + std::vector v2(nbOfComp); + for(int i=0;i aarr=ret0Arr->keepSelectedComponents(v2); + ret0->setArray(aarr); + return ret0.retn(); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + + } + else + return ParaMEDMEM_MEDCouplingFieldDouble_buildSubPart(self,li); } PyObject *getMaxValue2() const throw(INTERP_KERNEL::Exception) @@ -8405,32 +3449,574 @@ namespace ParaMEDMEM return self->extractSlice3D(orig,vect,eps); } - PyObject *___iadd___(PyObject *trueSelf, const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) + MEDCouplingFieldDouble *__add__(PyObject *obj) throw(INTERP_KERNEL::Exception) { - *self+=other; - Py_XINCREF(trueSelf); - return trueSelf; + return ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(self,obj); } - - PyObject *___isub___(PyObject *trueSelf, const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) + + MEDCouplingFieldDouble *__radd__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + return ParaMEDMEM_MEDCouplingFieldDouble___radd__Impl(self,obj); + } + + MEDCouplingFieldDouble *__sub__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__sub__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__sub__ : self field has no Array of values set !"; + void *argp; + // + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + return (*self)-(*other); + else + throw INTERP_KERNEL::Exception(msg); + } + // + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); + ret->applyLin(1.,-val); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 2: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Substract(self->getArray(),a); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 3: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Substract(self->getArray(),aaa); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 4: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Substract(self->getArray(),aaa); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } + } + + MEDCouplingFieldDouble *__rsub__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + return ParaMEDMEM_MEDCouplingFieldDouble___rsub__Impl(self,obj); + } + + MEDCouplingFieldDouble *__mul__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + return ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(self,obj); + } + + MEDCouplingFieldDouble *__rmul__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + return ParaMEDMEM_MEDCouplingFieldDouble___rmul__Impl(self,obj); + } + + MEDCouplingFieldDouble *__div__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__div__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__div__ : self field has no Array of values set !"; + void *argp; + // + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + return (*self)/(*other); + else + throw INTERP_KERNEL::Exception(msg); + } + // + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + if(val==0.) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble.__div__ : trying to divide by zero !"); + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); + ret->applyLin(1./val,0); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 2: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Divide(self->getArray(),a); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 3: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Divide(self->getArray(),aaa); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 4: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Divide(self->getArray(),aaa); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } + } + + MEDCouplingFieldDouble *__rdiv__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + return ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Impl(self,obj); + } + + MEDCouplingFieldDouble *__pow__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__pow__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__pow__ : self field has no Array of values set !"; + void *argp; + // + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + return (*self)^(*other); + else + throw INTERP_KERNEL::Exception(msg); + } + // + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); + ret->applyPow(val); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 2: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Pow(self->getArray(),a); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 3: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Pow(self->getArray(),aaa); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 4: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Pow(self->getArray(),aaa); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } + } + + MEDCouplingFieldDouble *__neg__() const throw(INTERP_KERNEL::Exception) + { + return self->negate(); + } + + PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__iadd__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__iadd__ : self field has no Array of values set !"; + void *argp; + // + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + { + *self+=*other; + Py_XINCREF(trueSelf); + return trueSelf; + } + else + throw INTERP_KERNEL::Exception(msg); + } + // + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + self->getArray()->applyLin(1.,val); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(a); + *self+=*ret2; + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(aaa); + *self+=*ret2; + Py_XINCREF(trueSelf); + return trueSelf; + } + case 4: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + self->getArray()->addEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } + } + + PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__isub__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__isub__ : self field has no Array of values set !"; + void *argp; + // + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + { + *self-=*other; + Py_XINCREF(trueSelf); + return trueSelf; + } + else + throw INTERP_KERNEL::Exception(msg); + } + // + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + self->getArray()->applyLin(1.,-val); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(a); + *self-=*ret2; + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(aaa); + *self-=*ret2; + Py_XINCREF(trueSelf); + return trueSelf; + } + case 4: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + self->getArray()->substractEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } + } + + PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) { - *self-=other; - Py_XINCREF(trueSelf); - return trueSelf; + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__imul__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__imul__ : self field has no Array of values set !"; + void *argp; + // + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + { + *self*=*other; + Py_XINCREF(trueSelf); + return trueSelf; + } + else + throw INTERP_KERNEL::Exception(msg); + } + // + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + self->getArray()->applyLin(val,0); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(a); + *self*=*ret2; + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(aaa); + *self*=*ret2; + Py_XINCREF(trueSelf); + return trueSelf; + } + case 4: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + self->getArray()->multiplyEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } } - PyObject *___imul___(PyObject *trueSelf, const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) + PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) { - *self*=other; - Py_XINCREF(trueSelf); - return trueSelf; + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__idiv__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__idiv__ : self field has no Array of values set !"; + void *argp; + // + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + { + *self/=*other; + Py_XINCREF(trueSelf); + return trueSelf; + } + else + throw INTERP_KERNEL::Exception(msg); + } + // + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + if(val==0.) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble.__idiv__ : trying to divide by zero !"); + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + self->getArray()->applyLin(1./val,0); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(a); + *self/=*ret2; + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(aaa); + *self/=*ret2; + Py_XINCREF(trueSelf); + return trueSelf; + } + case 4: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + self->getArray()->divideEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } } - PyObject *___idiv___(PyObject *trueSelf, const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) + PyObject *___ipow___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) { - *self/=other; - Py_XINCREF(trueSelf); - return trueSelf; + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__ipow__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__ipow__ : self field has no Array of values set !"; + void *argp; + // + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + { + *self^=*other; + Py_XINCREF(trueSelf); + return trueSelf; + } + else + throw INTERP_KERNEL::Exception(msg); + } + // + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + self->getArray()->applyPow(val); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(a); + *self^=*ret2; + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(aaa); + *self^=*ret2; + Py_XINCREF(trueSelf); + return trueSelf; + } + case 4: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + self->getArray()->powEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } } static MEDCouplingFieldDouble *MergeFields(PyObject *li) throw(INTERP_KERNEL::Exception) diff --git a/src/MEDCoupling_Swig/MEDCouplingDataForTest.py b/src/MEDCoupling_Swig/MEDCouplingDataForTest.py index d81841bcd..c888a0d74 100644 --- a/src/MEDCoupling_Swig/MEDCouplingDataForTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingDataForTest.py @@ -180,7 +180,7 @@ class MEDCouplingDataForTest: mesh2D.insertNextCell(NORM_QUAD4,4,conn2[14:18]); mesh2D.insertNextCell(NORM_POLYGON,6,conn2[18:24]); mesh2D.insertNextCell(NORM_QUAD4,4,conn2[24:28]); - mesh2D.finishInsertingCells(); + mesh2D.finishInsertingCells(); mesh2D.setCoords(myCoords); return ret,mesh2D @@ -584,7 +584,7 @@ class MEDCouplingDataForTest: m=MEDCouplingUMesh("MA1",2) m.setDescription("CREE PAR CODE_ASTER") ; m.setTimeUnit("SANS UNITES") ; m.setTime(-1.,-1,-1) m.setCoords(coo) - m.allocateCells(0) + m.allocateCells() conn=[[11,8,13],[11,13,12],[8,9,13],[9,14,13],[9,10,15],[9,15,14],[12,13,19],[13,16,19],[13,14,17],[13,17,16],[14,15,17],[15,18,17],[0,1,4,3],[1,2,5,4],[2,6,7,5],[3,4,8,11],[4,5,9,8],[5,7,10,9],[20,22,21,28,41,51],[21,25,20,29,42,51],[22,23,21,30,43,41],[23,27,21,31,35,43],[23,38,24,32,44,52],[24,27,23,33,31,52],[25,21,50,29,45,53],[21,39,50,34,46,45],[21,27,26,35,47,54],[26,39,21,36,34,54],[27,24,26,33,48,47],[24,40,26,37,49,48],[50,39,56,55,46,62,58,71],[39,26,57,56,36,63,59,62],[26,40,61,57,49,64,60,63],[55,56,17,18,58,65,68,72],[56,57,16,17,59,66,69,65],[57,61,19,16,60,67,70,66]] for i in xrange(0,12): m.insertNextCell(NORM_TRI3,conn[i]) diff --git a/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py b/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py index 8757b18b0..3f79d2cbb 100644 --- a/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py @@ -20,15 +20,884 @@ from MEDCoupling import * import unittest -from math import pi +from math import pi, sqrt class MEDCouplingBasicsTest(unittest.TestCase): - def testExample_MEDCouplingPointSet_(self): - #! [PySnippet_MEDCouplingPointSet__1] - pass - # mesh.allocateCells(1); - # mesh.insertNextCell(NORM_QUAD4,4,range(4)); - # mesh.finishInsertingCells(); + def testExample_MEDCouplingUMesh_(self): + #! [PySnippet_MEDCouplingUMesh__1] + return + + def testExample_MEDCouplingMesh_fillFromAnalytic3(self): + #! [PySnippet_MEDCouplingMesh_fillFromAnalytic3_1] + coords = [0.,2.,4.,6.] # 6. is not used + x=DataArrayDouble.New(coords[:3],3,1) + y=DataArrayDouble.New(coords[:2],2,1) + mesh=MEDCouplingCMesh.New() + mesh.setCoords(x,y) + #! [PySnippet_MEDCouplingMesh_fillFromAnalytic3_1] + #! [PySnippet_MEDCouplingMesh_fillFromAnalytic3_2] + func = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10" + varNames=["a","b"] # names used to refer to X and Y coord components + field=mesh.fillFromAnalytic3(ON_CELLS,3,varNames,func) + #! [PySnippet_MEDCouplingMesh_fillFromAnalytic3_2] + #! [PySnippet_MEDCouplingMesh_fillFromAnalytic3_3] + vals1 = field.getArray().getTuple(1) # values of the cell #1 + assert len( vals1 ) == 3 # 3 components in the field + # + bc = mesh.getBarycenterAndOwner() # func is applied to barycenters of cells + bc1 = bc.getTuple(1) # coordinates of the second point + # + dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ) # "sqrt( a*a + b*b )" + self.assertAlmostEqual( vals1[0], 10 + bc1[1], 13 ) # "10 + IVec * b" + self.assertAlmostEqual( vals1[1], 10 + bc1[0], 13 ) # "10 + JVec * a" + self.assertAlmostEqual( vals1[2], 10 + dist , 13 ) # "10 + KVec * sqrt( a*a + b*b )" + #! [PySnippet_MEDCouplingMesh_fillFromAnalytic3_3] + return + + def testExample_MEDCouplingMesh_fillFromAnalytic2(self): + #! [PySnippet_MEDCouplingMesh_fillFromAnalytic2_1] + coords = [0.,2.,4.,6.] # 6. is not used + x=DataArrayDouble.New(coords[:3],3,1) + y=DataArrayDouble.New(coords[:2],2,1) + x.setInfoOnComponent(0,"a") # name used to refer to X coordinate within a function + y.setInfoOnComponent(0,"b") # name used to refer to Y coordinate within a function + mesh=MEDCouplingCMesh.New() + mesh.setCoords(x,y) + #! [PySnippet_MEDCouplingMesh_fillFromAnalytic2_1] + #! [PySnippet_MEDCouplingMesh_fillFromAnalytic2_2] + func = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10" + field=mesh.fillFromAnalytic2(ON_CELLS,3,func) + #! [PySnippet_MEDCouplingMesh_fillFromAnalytic2_2] + #! [PySnippet_MEDCouplingMesh_fillFromAnalytic2_3] + vals1 = field.getArray().getTuple(1) # values of the cell #1 + assert len( vals1 ) == 3 # 3 components in the field + # + bc = mesh.getBarycenterAndOwner() # func is applied to barycenters of cells + bc1 = bc.getTuple(1) # coordinates of the second point + # + dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ) # "sqrt( a*a + b*b )" + self.assertAlmostEqual( vals1[0], 10 + bc1[1], 13 ) # "10 + IVec * b" + self.assertAlmostEqual( vals1[1], 10 + bc1[0], 13 ) # "10 + JVec * a" + self.assertAlmostEqual( vals1[2], 10 + dist , 13 ) # "10 + KVec * sqrt( a*a + b*b )" + #! [PySnippet_MEDCouplingMesh_fillFromAnalytic2_3] + return + + def testExample_MEDCouplingMesh_fillFromAnalytic(self): + #! [PySnippet_MEDCouplingMesh_fillFromAnalytic_1] + coords = [0.,2.,4.,6.] # 6. is not used + x=DataArrayDouble.New(coords[:3],3,1) + y=DataArrayDouble.New(coords[:2],2,1) + mesh=MEDCouplingCMesh.New() + mesh.setCoords(x,y) + #! [PySnippet_MEDCouplingMesh_fillFromAnalytic_1] + #! [PySnippet_MEDCouplingMesh_fillFromAnalytic_2] + func = "IVec * b + JVec * a + KVec * sqrt( a*a + b*b ) + 10" + field=mesh.fillFromAnalytic(ON_CELLS,3,func) + #! [PySnippet_MEDCouplingMesh_fillFromAnalytic_2] + #! [PySnippet_MEDCouplingMesh_fillFromAnalytic_3] + vals1 = field.getArray().getTuple(1) # values of the cell #1 + assert len( vals1 ) == 3 # 3 components in the field + # + bc = mesh.getBarycenterAndOwner() # func is applied to barycenters of cells + bc1 = bc.getTuple(1) # coordinates of the second point + # + dist = sqrt( bc1[0]*bc1[0] + bc1[1]*bc1[1] ) # "sqrt( a*a + b*b )" + self.assertAlmostEqual( vals1[0], 10 + bc1[1], 13 ) # "10 + IVec * b" + self.assertAlmostEqual( vals1[1], 10 + bc1[0], 13 ) # "10 + JVec * a" + self.assertAlmostEqual( vals1[2], 10 + dist , 13 ) # "10 + KVec * sqrt( a*a + b*b )" + #! [PySnippet_MEDCouplingMesh_fillFromAnalytic_3] + return + + def testExample_MEDCouplingCMesh_getCoordsAt(self): + #! [PySnippet_MEDCouplingCMesh_getCoordsAt_1] + coords = [1.,2.,4.] + x=DataArrayDouble.New(coords,3,1) + mesh=MEDCouplingCMesh.New() + mesh.setCoordsAt(0,x) + x2=mesh.getCoordsAt(0) + assert coords == x2.getValues() + #! [PySnippet_MEDCouplingCMesh_getCoordsAt_1] + return + + def testExample_MEDCouplingUMesh_areCellsIncludedIn(self): + #! [PySnippet_MEDCouplingUMesh_areCellsIncludedIn_1] + mesh1=MEDCouplingUMesh.New(); + mesh1.setMeshDimension(2); + mesh1.allocateCells(5); + conn=[0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4]; + mesh1.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh1.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh1.insertNextCell(NORM_TRI3,3, conn[7:10]); # 2 + mesh1.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3 + mesh1.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4 + mesh1.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh1.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_areCellsIncludedIn_1] + #! [PySnippet_MEDCouplingUMesh_areCellsIncludedIn_2] + cells2 = [ 4,2,0 ] + mesh2 = mesh1.buildPartOfMySelf(cells2, True ) # even cells selected + #! [PySnippet_MEDCouplingUMesh_areCellsIncludedIn_2] + #! [PySnippet_MEDCouplingUMesh_areCellsIncludedIn_3] + compType = 0 # the strongest policy + isOk, corr2to1 = mesh1.areCellsIncludedIn( mesh2, compType ) + assert isOk # a larger mesh1 includes a smaller mesh2 + assert corr2to1.getValues() == cells2 + #! [PySnippet_MEDCouplingUMesh_areCellsIncludedIn_3] + #! [PySnippet_MEDCouplingUMesh_areCellsIncludedIn_4] + isOk, corr1to2 = mesh2.areCellsIncludedIn( mesh1, compType ) + assert not isOk # the smaller mesh2 does NOT include the larger mesh1 + assert corr1to2.getValues() == [2, 3, 1, 4, 0] + #! [PySnippet_MEDCouplingUMesh_areCellsIncludedIn_4] + + def testExample_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells(self): + #! [PySnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_1] + # 2D coordinates of 5 base nodes + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,5,2); + # coordinates of 5 top nodes + coordsArr2 = coordsArr.deepCpy() + # 3D coordinates of base + top nodes + coordsArr = coordsArr.changeNbOfComponents( 3, 0 ) + coordsArr2 = coordsArr2.changeNbOfComponents( 3, 1 ) + coordsArr = DataArrayDouble.Aggregate([coordsArr,coordsArr2]) + # mesh + mesh=MEDCouplingUMesh.New(); + mesh.setCoords(coordsArr); + mesh.setMeshDimension(3); + mesh.allocateCells(2); + # connectivity of reversed HEXA8 and PENTA6 + conn=[0,1,4,3, 5,6,9,8, 1,2,4, 6,7,9] + mesh.insertNextCell(NORM_HEXA8, 8,conn[0:0+8]) + mesh.insertNextCell(NORM_PENTA6,6,conn[8:8+6]) + mesh.finishInsertingCells(); + #! [PySnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_1] + #! [PySnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_2] + fixedCells = mesh.findAndCorrectBadOriented3DExtrudedCells() + assert len( fixedCells.getValues() ) == 2 # 2 cells fixed + fixedCells = mesh.findAndCorrectBadOriented3DExtrudedCells() + assert len( fixedCells.getValues() ) == 0 # no bad cells + #! [PySnippet_MEDCouplingUMesh_findAndCorrectBadOriented3DExtrudedCells_2] + return + + def testExample_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented(self): + #! [PySnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_1] + # 2D coordinates of 5 base nodes + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,5,2); + # coordinates of 5 top nodes + coordsArr2 = coordsArr.deepCpy() + # 3D coordinates of base + top nodes + coordsArr = coordsArr.changeNbOfComponents( 3, 0 ) + coordsArr2 = coordsArr2.changeNbOfComponents( 3, 1 ) + coordsArr = DataArrayDouble.Aggregate([coordsArr,coordsArr2]) + # mesh + mesh=MEDCouplingUMesh.New(); + mesh.setCoords(coordsArr); + mesh.setMeshDimension(3); + mesh.allocateCells(2); + # connectivity of a HEXA8 + a reversed PENTA6 + conn=[0,3,4,1, 5,8,9,6, 1,2,4, 6,7,9] + mesh.insertNextCell(NORM_POLYHED, 8,conn[0:0+8]) # "extruded" polyhedron + mesh.insertNextCell(NORM_POLYHED,6,conn[8:8+6]) + mesh.finishInsertingCells(); + # fix connectivity of NORM_POLYHED's + mesh.convertExtrudedPolyhedra() + #! [PySnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_1] + #! [PySnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_2] + badCells = mesh.arePolyhedronsNotCorrectlyOriented() + assert len( badCells.getValues() ) == 1 # one polyhedron is KO + # fix invalid rolyherdons + mesh.orientCorrectlyPolyhedrons() + # re-check the orientation + badCells = mesh.arePolyhedronsNotCorrectlyOriented() + assert len( badCells.getValues() ) == 0 # connectivity is OK + #! [PySnippet_MEDCouplingUMesh_arePolyhedronsNotCorrectlyOriented_2] + return + + def testExample_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented(self): + #! [PySnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); # 2 + mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3 + mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4 + mesh.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh.setCoords(coordsArr); + mesh.changeSpaceDimension(3) + #! [PySnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_1] + #! [PySnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_2] + vec = [0.,0.,-1.] + badCellIds=mesh.are2DCellsNotCorrectlyOriented( vec, False ) + assert len( badCellIds ) == 1 # one cell is reversed + # fix orientation + mesh.orientCorrectly2DCells( vec, False ) + # re-check orientation + badCellIds=mesh.are2DCellsNotCorrectlyOriented( vec, False ) + assert len( badCellIds ) == 0 # the orientation is OK + #! [PySnippet_MEDCouplingUMesh_are2DCellsNotCorrectlyOriented_2] + return + + def testExample_MEDCouplingUMesh_getCellsContainingPoints(self): + #! [PySnippet_MEDCouplingUMesh_getCellsContainingPoints_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); # 2 + mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3 + mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4 + mesh.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_getCellsContainingPoints_1] + #! [PySnippet_MEDCouplingUMesh_getCellsContainingPoints_2] + pos = [ 10., 10, # point out of the mesh + 0.3, 0.3, # point located somewhere inside the mesh + coords[2], coords[3]] # point at the node #1 + eps = 1e-4 # ball radius + cells,cellsIndex=mesh.getCellsContainingPoints( pos, 3, eps ) + assert cells.getValues() == [4, 0, 1] + assert cellsIndex.getValues() == [0, 0, 1, 3] + #! [PySnippet_MEDCouplingUMesh_getCellsContainingPoints_2] + return + + + def testExample_MEDCouplingUMesh_getCellsContainingPoint(self): + #! [PySnippet_MEDCouplingUMesh_getCellsContainingPoint_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); # 2 + mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3 + mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4 + mesh.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_getCellsContainingPoint_1] + #! [PySnippet_MEDCouplingUMesh_getCellsContainingPoint_2] + pos4 = coords[ 4*2 : ] # coordinates of the node #4 + eps = 1e-4 # ball radius + pos = [ pos4[0]+eps, pos4[1]-eps ] # ball center + cellIds=mesh.getCellsContainingPoint( pos, eps ) + assert len( cellIds ) == mesh.getNumberOfCells() + #! [PySnippet_MEDCouplingUMesh_getCellsContainingPoint_2] + return + + + def testExample_MEDCouplingUMesh_buildPartOrthogonalField(self): + #! [PySnippet_MEDCouplingUMesh_buildPartOrthogonalField_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); # 2 + mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3 + mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4 + mesh.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_buildPartOrthogonalField_1] + #! [PySnippet_MEDCouplingUMesh_buildPartOrthogonalField_2] + part = DataArrayInt([1,2,3,4],4,1) # cell #0 is omitted + vecField=mesh.buildPartOrthogonalField( part ) + vecArr = vecField.getArray() + assert len( vecArr ) == len( part ) + assert vecArr.getNumberOfComponents() == 3 + #! [PySnippet_MEDCouplingUMesh_buildPartOrthogonalField_2] + return + + def testExample_MEDCouplingUMesh_getPartMeasureField(self): + #! [PySnippet_MEDCouplingUMesh_getPartMeasureField_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,2,4, 4,5,2, 6,7,4,3, 7,8,5,4]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); # 2 + mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3 + mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4 + mesh.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_getPartMeasureField_1] + #! [PySnippet_MEDCouplingUMesh_getPartMeasureField_2] + isAbs = True + part = DataArrayInt([1,2,3,4],4,1) # cell #0 is omitted + areaArr=mesh.getPartMeasureField( isAbs, part ) + assert areaArr[0] > 0 # orientation ignored + areaArr=mesh.getPartMeasureField( not isAbs, part ) + assert areaArr[0] < 0 # orientation considered + assert len( areaArr ) == len( part ) + #! [PySnippet_MEDCouplingUMesh_getPartMeasureField_2] + #! [PySnippet_MEDCouplingUMesh_getPartMeasureField_3] + part = DataArrayInt([1,2,3,4],4,1) # cell #0 is omitted + baryCenters = mesh.getPartBarycenterAndOwner( part ) + assert len( baryCenters ) == len( part ) + assert baryCenters.getNumberOfComponents() == mesh.getSpaceDimension() + #! [PySnippet_MEDCouplingUMesh_getPartMeasureField_3] + return + + def testExample_MEDCouplingUMesh_getCellsInBoundingBox(self): + #! [PySnippet_MEDCouplingUMesh_getCellsInBoundingBox_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + coords=[0.,0., 0.,1., 1.,1]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,3,2); + mesh.setCoords(coordsArr); + mesh.allocateCells(1); + conn=[0,1,2]; + mesh.insertNextCell(NORM_TRI3,3,conn); + mesh.finishInsertingCells(); + #! [PySnippet_MEDCouplingUMesh_getCellsInBoundingBox_1] + #! [PySnippet_MEDCouplingUMesh_getCellsInBoundingBox_2] + bbox = [1., 1., 1.001,1.001] # xMin, xMax, yMin, yMax + cellsInBox = mesh.getCellsInBoundingBox( bbox, 0.0 ) + assert cellsInBox.getValues() == [] + cellsInBox = mesh.getCellsInBoundingBox( bbox, 0.1 ) + assert cellsInBox.getValues() == [0] + #! [PySnippet_MEDCouplingUMesh_getCellsInBoundingBox_2] + + + def testExample_MEDCouplingUMesh_renumberNodesInConn(self): + #! [PySnippet_MEDCouplingUMesh_renumberNodesInConn_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(1); + conn=[4,3,2,1]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); + mesh.finishInsertingCells(); + #! [PySnippet_MEDCouplingUMesh_renumberNodesInConn_1] + #! [PySnippet_MEDCouplingUMesh_renumberNodesInConn_2] + old2newIds = [-1,3,2,1,0] + mesh.renumberNodesInConn( old2newIds ) + nodes0 = mesh.getNodeIdsOfCell( 0 ) + assert nodes0 == [0,1,2,3] + #! [PySnippet_MEDCouplingUMesh_renumberNodesInConn_2] + return + + + def testExample_MEDCouplingUMesh_renumberNodes(self): + #! [PySnippet_MEDCouplingUMesh_renumberNodes_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.3]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,4,2); + mesh.setCoords(coordsArr); + mesh.allocateCells(0); + mesh.finishInsertingCells(); + #! [PySnippet_MEDCouplingUMesh_renumberNodes_1] + #! [PySnippet_MEDCouplingUMesh_renumberNodes_2] + mesh.renumberNodes([ 2,1,0,-1 ], 3); + coordsArr = mesh.getCoords() # get a shorten array + assert coordsArr.getValues() == [0.7,-0.3, 0.2,-0.3, -0.3,-0.3] + #! [PySnippet_MEDCouplingUMesh_renumberNodes_2] + #! [PySnippet_MEDCouplingUMesh_renumberNodes_3] + coordsArr.setValues(coords,4,2); # restore old nodes + mesh.renumberNodes2([ 2,1,0,2 ], 3); + coordsArr = mesh.getCoords() # get a shorten array + assert coordsArr.getValues() == [0.7,-0.3, 0.2,-0.3, -0.3,0.0] + #! [PySnippet_MEDCouplingUMesh_renumberNodes_3] + return + + def testExample_MEDCouplingUMesh_findBoundaryNodes(self): + #! [PySnippet_MEDCouplingUMesh_findBoundaryNodes_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); # 2 + mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3 + mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4 + mesh.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_findBoundaryNodes_1] + #! [PySnippet_MEDCouplingUMesh_findBoundaryNodes_2] + nodeIdsArr=mesh.findBoundaryNodes() + assert nodeIdsArr.getNumberOfTuples() == mesh.getNumberOfNodes() - 1 + #! [PySnippet_MEDCouplingUMesh_findBoundaryNodes_2] + return + + def testExample_MEDCouplingUMesh_buildBoundaryMesh(self): + #! [PySnippet_MEDCouplingUMesh_buildBoundaryMesh_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); # 2 + mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3 + mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4 + mesh.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_buildBoundaryMesh_1] + #! [PySnippet_MEDCouplingUMesh_buildBoundaryMesh_2] + mesh1=mesh.buildBoundaryMesh(True) + mesh2=mesh.buildBoundaryMesh(False) + assert coordsArr.isEqual( mesh1.getCoords(), 1e-13 ) # same nodes + assert not coordsArr.isEqual( mesh2.getCoords(), 1e-13 ) # different nodes + #! [PySnippet_MEDCouplingUMesh_buildBoundaryMesh_2] + return + + def testExample_MEDCouplingUMesh_buildFacePartOfMySelfNode(self): + #! [PySnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); # 2 + mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3 + mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4 + mesh.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_1] + #! [PySnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_2] + nodeIds = mesh.getNodeIdsOfCell( 0 ) + allNodes = True + mesh1 = mesh.buildFacePartOfMySelfNode( nodeIds, allNodes ) + assert mesh1.getNumberOfCells() == 4 # 4 segments bounding QUAD4 #0 only + mesh2 = mesh.buildFacePartOfMySelfNode( nodeIds, not allNodes ) + assert mesh2.getNumberOfCells() > 4 # more segments added + #! [PySnippet_MEDCouplingUMesh_buildFacePartOfMySelfNode_2] + return + + + def testExample_MEDCouplingUMesh_buildPartOfMySelfNode(self): + #! [PySnippet_MEDCouplingUMesh_buildPartOfMySelfNode_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); # 2 + mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3 + mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4 + mesh.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_buildPartOfMySelfNode_1] + #! [PySnippet_MEDCouplingUMesh_buildPartOfMySelfNode_2] + nodeIds = mesh.getNodeIdsOfCell( 0 ) + allNodes = True + mesh1 = mesh.buildPartOfMySelfNode( nodeIds, allNodes ) + mesh2 = mesh.buildPartOfMySelfNode( nodeIds, not allNodes ) + assert mesh1.getNumberOfCells() == 1 # cell #0 is found only + assert mesh2.getNumberOfCells() == mesh.getNumberOfCells() # all cells are found + #! [PySnippet_MEDCouplingUMesh_buildPartOfMySelfNode_2] + return + + + def testExample_MEDCouplingUMesh_getCellIdsLyingOnNodes(self): + #! [PySnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); # 2 + mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3 + mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4 + mesh.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_1] + #! [PySnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_2] + nodeIds = mesh.getNodeIdsOfCell( 0 ) + allNodes = True + cellIdsArr1 = mesh.getCellIdsLyingOnNodes( nodeIds, allNodes ) + cellIdsArr2 = mesh.getCellIdsLyingOnNodes( nodeIds, not allNodes ) + assert cellIdsArr1.getNumberOfTuples() == 1 # cell #0 is found only + assert cellIdsArr2.getNumberOfTuples() == mesh.getNumberOfCells() # all cells are found + #! [PySnippet_MEDCouplingUMesh_getCellIdsLyingOnNodes_2] + return + + + def testExample_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds(self): + #! [PySnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); # 2 + mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3 + mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4 + mesh.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_1] + #! [PySnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_2] + cellIds = [1,2] + nodeIds = mesh.getNodeIdsOfCell( cellIds[0] ) + nodeIds += mesh.getNodeIdsOfCell( cellIds[1] ) + cellIdsArr = mesh.getCellIdsFullyIncludedInNodeIds( nodeIds ) + assert cellIdsArr.getValues() == cellIds + #! [PySnippet_MEDCouplingUMesh_getCellIdsFullyIncludedInNodeIds_2] + return + + + def testExample_MEDCouplingUMesh_buildPartOfMySelf(self): + #! [PySnippet_MEDCouplingUMesh_buildPartOfMySelf_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); # 2 + mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3 + mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4 + mesh.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_buildPartOfMySelf_1] + #! [PySnippet_MEDCouplingUMesh_buildPartOfMySelf_2] + cellIds=[1,2] + mesh2=mesh.buildPartOfMySelf(cellIds, True) + mesh3=mesh.buildPartOfMySelf(cellIds, False) + coordsArr2 = mesh2.getCoords() + assert coordsArr.isEqual( coordsArr2, 1e-13 ) # same nodes + coordsArr3 = mesh3.getCoords() + assert not coordsArr.isEqual( coordsArr3, 1e-13 ) # different nodes + assert mesh2.getNodeIdsOfCell(0) == mesh.getNodeIdsOfCell( cellIds[0]) # cell #1 was copied + assert mesh2.getNodeIdsOfCell(1) == mesh.getNodeIdsOfCell( cellIds[1]) # cell #2 was copied + #! [PySnippet_MEDCouplingUMesh_buildPartOfMySelf_2] + return + + def testExample_MEDCouplingUMesh_mergeNodes(self): + #! [PySnippet_MEDCouplingUMesh_mergeNodes_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,4,2, 4,5,2]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); + mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); + mesh.finishInsertingCells(); + coords=[0.3,-0.301, # 0 + 0.2,-0.3, # 1 + 0.3,-0.302, # 2 ~~ 0 + 1.1,0.0, # 3 + 1.1,0.0, # 4 == 3 + 0.3,-0.303];# 5 ~~ 0 + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,6,2); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_mergeNodes_1] + #! [PySnippet_MEDCouplingUMesh_mergeNodes_2] + arr,areNodesMerged,newNbOfNodes=mesh.mergeNodes(0.004) + assert arr.getValues() == [0, 1, 0, 2, 2, 0] + assert areNodesMerged + assert newNbOfNodes == 3 + #! [PySnippet_MEDCouplingUMesh_mergeNodes_2] + #! [PySnippet_MEDCouplingUMesh_mergeNodes_3] + baryCoords2 = coords[2*2:] # initial coordinates of node #2 + coordsArr = mesh.getCoords() # retrieve a new shorten coord array + self.assertNotAlmostEqual( baryCoords2[1], coordsArr.getIJ(0,1), 13 ) # Y of node #0 differs from that of baryCoords2 + # restore coordinates + coordsArr = DataArrayDouble(coords,6,2); + mesh.setCoords(coordsArr); + # call mergeNodes2() + mesh.mergeNodes2(0.004) + coordsArr = mesh.getCoords() # retrieve a new shorten coord array + self.assertAlmostEqual( baryCoords2[1], coordsArr.getIJ(0,1), 13 ) # Y of node #0 equals to that of baryCoords2 + #! [PySnippet_MEDCouplingUMesh_mergeNodes_3] + return + + def testExample_MEDCouplingUMesh_zipConnectivityTraducer(self): + #! [PySnippet_MEDCouplingUMesh_zipConnectivityTraducer_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,4,2]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 2 == 1 + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 3 == 0 + mesh.insertNextCell(NORM_QUAD4,4,conn[2:4]+conn[0:2]); # 4 ~~ 0 + mesh.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_zipConnectivityTraducer_1] + #! [PySnippet_MEDCouplingUMesh_zipConnectivityTraducer_2] + oldNbCells = mesh.getNumberOfCells() + arr = mesh.zipConnectivityTraducer(0) + assert mesh.getNumberOfCells() == oldNbCells-2 + assert arr.getValues() == [0, 1, 1, 0, 2] + #! [PySnippet_MEDCouplingUMesh_zipConnectivityTraducer_2] + return + + def testExample_MEDCouplingUMesh_zipCoordsTraducer(self): + #! [PySnippet_MEDCouplingUMesh_zipCoordsTraducer_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); # 2 + mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3 + mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4 + mesh.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_zipCoordsTraducer_1] + #! [PySnippet_MEDCouplingUMesh_zipCoordsTraducer_2] + cellIds=[1,2] + mesh2=mesh.buildPartOfMySelf(cellIds,True); + arr=mesh2.zipCoordsTraducer(); + assert mesh2.getNumberOfNodes() == 4 # nb of nodes decreased + assert arr.getValues() == [-1,0,1,-1,2,3,-1,-1,-1] # -1 for unused nodes + #! [PySnippet_MEDCouplingUMesh_zipCoordsTraducer_2] + return + + def testExample_MEDCouplingUMesh_getNodeIdsInUse(self): + #! [PySnippet_MEDCouplingUMesh_getNodeIdsInUse_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); # 2 + mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3 + mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4 + mesh.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_getNodeIdsInUse_1] + #! [PySnippet_MEDCouplingUMesh_getNodeIdsInUse_2] + cellIds=[1,2] + mesh2=mesh.buildPartOfMySelf(cellIds,True); + arr,newNbOfNodes=mesh2.getNodeIdsInUse(); + assert arr.getValues() == [-1,0,1,-1,2,3,-1,-1,-1] + #! [PySnippet_MEDCouplingUMesh_getNodeIdsInUse_2] + #! [PySnippet_MEDCouplingUMesh_getNodeIdsInUse_3] + arr2=arr.invertArrayO2N2N2O(newNbOfNodes); + assert arr2.getValues() == [1,2,4,5] + #! [PySnippet_MEDCouplingUMesh_getNodeIdsInUse_3] + return + + def testExample_MEDCouplingUMesh_convertToPolyTypes(self): + #! [PySnippet_MEDCouplingUMesh_convertToPolyTypes_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); # 2 + mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3 + mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4 + mesh.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_convertToPolyTypes_1] + #! [PySnippet_MEDCouplingUMesh_convertToPolyTypes_2] + cells=[1,3]; + mesh.convertToPolyTypes(cells); + assert mesh.getTypeOfCell(0) == NORM_QUAD4 + assert mesh.getTypeOfCell(1) == NORM_POLYGON, mesh.getTypeOfCell(1) + assert mesh.getTypeOfCell(2) == NORM_TRI3 + assert mesh.getTypeOfCell(3) == NORM_POLYGON + #! [PySnippet_MEDCouplingUMesh_convertToPolyTypes_2] + return + + def testExample_MEDCouplingUMesh_buildDescendingConnectivity2(self): + #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity2_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); # 2 + mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3 + mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4 + mesh.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity2_1] + #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity2_2] + desc=DataArrayInt.New(); + descIndx=DataArrayInt.New(); + revDesc=DataArrayInt.New(); + revDescIndx=DataArrayInt.New(); + mesh2=mesh.buildDescendingConnectivity2(desc,descIndx,revDesc,revDescIndx); + assert desc.getValues() == [1,2,3,4,-3,5,6, 7,8,-5,9,10,-2,11, 12,13,-7,-10] + assert descIndx.getValues() == [0,4,7,10,14,18] + assert revDesc.getValues() == [0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4] + assert revDescIndx.getValues() == [0,1,3,5,6,8,9,11,12,13,15,16,17,18] + #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity2_2] + #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity2_3] + assert mesh2.getNodeIdsOfCell( 3-1 ) == [4, 1] # cell #3 in FORTRAN mode + #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity2_3] + return + + def testExample_MEDCouplingUMesh_buildDescendingConnectivity(self): + #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); # 2 + mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3 + mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4 + mesh.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity_1] + #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity_2] + desc=DataArrayInt.New(); + descIndx=DataArrayInt.New(); + revDesc=DataArrayInt.New(); + revDescIndx=DataArrayInt.New(); + mesh2=mesh.buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx); + assert desc.getValues() == [0,1,2,3, 2,4,5, 6,7,4, 8,9,1,10, 11,12,6,9] + assert descIndx.getValues() == [0,4,7,10,14,18] + assert revDesc.getValues() == [0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4] + assert revDescIndx.getValues() == [0,1,3,5,6,8,9,11,12,13,15,16,17,18] + #! [PySnippet_MEDCouplingUMesh_buildDescendingConnectivity_2] + return + + def testExample_MEDCouplingUMesh_getReverseNodalConnectivity(self): + #! [PySnippet_MEDCouplingUMesh_getReverseNodalConnectivity_1] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(2); + mesh.allocateCells(5); + conn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]; + mesh.insertNextCell(NORM_QUAD4,4,conn[0:4]); # 0 + mesh.insertNextCell(NORM_TRI3,3, conn[4:7]); # 1 + mesh.insertNextCell(NORM_TRI3,3, conn[7:10]); # 2 + mesh.insertNextCell(NORM_QUAD4,4,conn[10:14]); # 3 + mesh.insertNextCell(NORM_QUAD4,4,conn[14:18]); # 4 + mesh.finishInsertingCells(); + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,9,2); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingUMesh_getReverseNodalConnectivity_1] + #! [PySnippet_MEDCouplingUMesh_getReverseNodalConnectivity_2] + revNodal,revNodalIndx=mesh.getReverseNodalConnectivity(); + assert revNodal.getValues() == [0,0,1,1,2,0,3,0,1,2,3,4,2,4,3,3,4,4]; + assert revNodalIndx.getValues() == [0,1,3,5,7,12,14,15,17,18]; + #! [PySnippet_MEDCouplingUMesh_getReverseNodalConnectivity_2] + return + + def testExample_MEDCouplingUMesh_checkDeepEquivalWith(self): + #! [PySnippet_MEDCouplingUMesh_checkDeepEquivalWith_1] + # mesh 1 + mesh1=MEDCouplingUMesh.New(); + mesh1.setMeshDimension(2); + coords=[0.0,0.0, #0 + 1.0,0.0, #1 + 1.0,1.0, #2 + 0.0,1.0] #3 + coordsArr=DataArrayDouble.New(coords,4,2); + mesh1.setCoords(coordsArr); + mesh1.allocateCells(2); + mesh1.insertNextCell(NORM_TRI3,3,[0,1,2]); #0 + mesh1.insertNextCell(NORM_TRI3,3,[1,2,3]); #1 + mesh1.finishInsertingCells(); + # mesh 2 + mesh2=MEDCouplingUMesh.New(); + mesh2.setMeshDimension(2); + coords=[0.0,1.0, #0 = #3 + 0.0,0.0, #1 = #0 + 1.0,0.0, #2 = #1 + 1.0,1.001] #3 ~ #2 + coordsArr2=DataArrayDouble.New(coords,4,2) + mesh2.setCoords(coordsArr2); + mesh2.allocateCells(2); + mesh2.insertNextCell(NORM_TRI3,3,[2,3,0]); #0 = #1 + mesh2.insertNextCell(NORM_TRI3,3,[3,1,2]); #1 ~ #0 + mesh2.finishInsertingCells(); + #! [PySnippet_MEDCouplingUMesh_checkDeepEquivalWith_1] + #! [PySnippet_MEDCouplingUMesh_checkDeepEquivalWith_2] + cellCompPol = 1 # "permuted same orientation" - policy of medium severity + cOld2New, nOld2New = mesh1.checkDeepEquivalWith( mesh2, cellCompPol, 0.002 ) + assert nOld2New.getValues() == [3, 0, 1, 2] + assert cOld2New.getValues() == [1, 0] + #! [PySnippet_MEDCouplingUMesh_checkDeepEquivalWith_2] + #! [PySnippet_MEDCouplingUMesh_checkDeepEquivalWith_3] + self.assertRaises( InterpKernelException, mesh1.checkDeepEquivalOnSameNodesWith, mesh2, cellCompPol, 0.002) + mesh2.setCoords(coordsArr) # make meshes share the same coordinates array + mesh2.allocateCells(2); + mesh2.insertNextCell(NORM_TRI3,3,[1,2,3]); #0 = #1 + mesh2.insertNextCell(NORM_TRI3,3,[1,0,2]); #1 ~ #0 + mesh2.finishInsertingCells(); + cellCompPol = 2 # the weakest policy + mesh1.checkDeepEquivalOnSameNodesWith( mesh2, cellCompPol, 0 ) + #! [PySnippet_MEDCouplingUMesh_checkDeepEquivalWith_3] + return def testExample_MEDCouplingPointSet_scale(self): #! [PySnippet_MEDCouplingPointSet_scale_1] @@ -49,7 +918,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): assert coords2.isEqualWithoutConsideringStr( initCoords, 1.0 ) assert not coords2.isEqualWithoutConsideringStr( initCoords, 0.9 ) #! [PySnippet_MEDCouplingPointSet_scale_3] - pass + return def testExample_MEDCouplingPointSet_translate(self): #! [PySnippet_MEDCouplingPointSet_translate_1] @@ -69,7 +938,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): assert coords2.isEqualWithoutConsideringStr( initCoords, 1 ) assert not coords2.isEqualWithoutConsideringStr( initCoords, 0.9 ) #! [PySnippet_MEDCouplingPointSet_translate_3] - pass + return def testExample_MEDCouplingPointSet_rotate(self): #! [PySnippet_MEDCouplingPointSet_rotate_1] @@ -95,7 +964,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): for i,c in enumerate( coords ): self.assertAlmostEqual( c, coords2[i], 13 ) #! [PySnippet_MEDCouplingPointSet_rotate_4] - pass + return def testExample_MEDCouplingPointSet_getBoundingBox(self): #! [PySnippet_MEDCouplingPointSet_getBoundingBox_1] @@ -120,7 +989,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): 0.2,-0.3, # 1 0.3,-0.302, # 2 1.1,0.0, # 3 - 0.3,-0.303];# 4 + 0.3,-0.30299999999999];# 4 coordsArr=DataArrayDouble.New(); coordsArr.setValues(coords,5,2); mesh=MEDCouplingUMesh.New(); @@ -131,7 +1000,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): ids=mesh.getNodeIdsNearPoint(point,0.003); assert ids.getValues() == [0,2,4] #! [PySnippet_MEDCouplingPointSet_getNodeIdsNearPoint_2] - pass + return def testExample_MEDCouplingPointSet_getNodeIdsNearPoints(self): #! [PySnippet_MEDCouplingPointSet_getNodeIdsNearPoints_1] @@ -154,9 +1023,9 @@ class MEDCouplingBasicsTest(unittest.TestCase): 1.1, 0.002] # ~ nodes #3, #4 and #5 ids,idsIndex=mesh.getNodeIdsNearPoints(points,3,0.003); assert ids.getValues() == [1, 3, 4, 5] - print idsIndex.getValues() + assert idsIndex.getValues() == [0, 1, 1, 4] #! [PySnippet_MEDCouplingPointSet_getNodeIdsNearPoints_2] - pass + return def testExample_MEDCouplingPointSet_findCommonNodes(self): #! [PySnippet_MEDCouplingPointSet_findCommonNodes_1] @@ -177,7 +1046,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): comm,commI=mesh.findCommonNodes(0.004) assert comm.getValues() == [0,2,5,3,4] #! [PySnippet_MEDCouplingPointSet_findCommonNodes_2] - pass + return def testExample_MEDCouplingPointSet_getCoordinatesOfNode(self): #! [PySnippet_MEDCouplingPointSet_getCoordinatesOfNode_1] @@ -192,7 +1061,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertAlmostEqual(0.2, nodeCoords[0],13); self.assertAlmostEqual(-0.3,nodeCoords[1],13); #! [PySnippet_MEDCouplingPointSet_getCoordinatesOfNode_2] - pass + return def testExample_DataArrayInt_getTuple(self): #! [Snippet_DataArrayInt_getTuple_1] @@ -200,13 +1069,13 @@ class MEDCouplingBasicsTest(unittest.TestCase): dv.alloc( 6, 1 ) dv.iota(7) dv.rearrange( 2 ) - print dv.getTuple( 1 ) + assert dv.getTuple( 1 ) == [9,10] #! [Snippet_DataArrayInt_getTuple_1] #! [Snippet_DataArrayInt_getTuple_2] for tpl in dv: print tpl #! [Snippet_DataArrayInt_getTuple_2] - pass + return def testExample_DataArrayInt_buildPermutationArr(self): #! [PySnippet_DataArrayInt_buildPermutationArr_1] @@ -217,7 +1086,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): c=a.buildPermutationArr(b) #! [PySnippet_DataArrayInt_buildPermutationArr_1] self.assertEqual([1,0,4,2,3],c.getValues()) - pass + return def testExample_DataArrayInt_invertArrayO2N2N2O(self): #! [PySnippet_DataArrayInt_invertArrayO2N2N2O_1] @@ -230,7 +1099,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual(expected1[i],da2.getIJ(i,0)); pass #! [PySnippet_DataArrayInt_invertArrayO2N2N2O_1] - pass + return def testExample_DataArrayInt_invertArrayN2O2O2N(self): #! [PySnippet_DataArrayInt_invertArrayN2O2O2N_1] @@ -243,7 +1112,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual(expected1[i],da2.getIJ(i,0)); pass #! [PySnippet_DataArrayInt_invertArrayN2O2O2N_1] - pass + return def testExample_DataArrayDouble_getIdsInRange(self): @@ -253,7 +1122,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): da[ :, :] = range(10) da2 = da.getIdsInRange( 2.5, 6 ) #! [PySnippet_DataArrayDouble_getIdsInRange_1] - pass + return def testExample_DataArrayDouble_setPartOfValues2(self): #! [Snippet_DataArrayDouble_setPartOfValues2_1] @@ -274,7 +1143,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): dv.rearrange( 6 ) da[ [0,2,3], [0,2,3,4,5,6]] = dv #! [Snippet_DataArrayDouble_setPartOfValues2_3] - pass + return def testExample_DataArrayInt_setPartOfValues2(self): #! [Snippet_DataArrayInt_setPartOfValues2_1] @@ -295,7 +1164,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): dv.rearrange( 6 ) da[ [0,2,3], [0,2,3,4,5,6]] = dv #! [Snippet_DataArrayInt_setPartOfValues2_3] - pass + return def testExample_DataArrayDouble_setPartOfValues3(self): #! [Snippet_DataArrayDouble_setPartOfValues3_1] @@ -316,7 +1185,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): dv.rearrange( 6 ) da[ 0:4:2, [0,2,3,4,5,6]] = dv #! [Snippet_DataArrayDouble_setPartOfValues3_3] - pass + return def testExample_DataArrayInt_setPartOfValues3(self): #! [Snippet_DataArrayInt_setPartOfValues3_1] @@ -337,7 +1206,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): dv.rearrange( 6 ) da[ 0:4:2, [0,2,3,4,5,6]] = dv #! [Snippet_DataArrayInt_setPartOfValues3_3] - pass + return def testExample_DataArrayDouble_setPartOfValues1(self): #! [Snippet_DataArrayDouble_setPartOfValues1_1] @@ -373,7 +1242,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): da2[ 0:3:2, 1:4:2 ] = dv self.assertTrue( da.isEqual( da2, 1e-20 )) #! [Snippet_DataArrayDouble_setPartOfValues1_6] - pass + return def testExample_DataArrayInt_setPartOfValues1(self): #! [Snippet_DataArrayInt_setPartOfValues1_1] @@ -409,7 +1278,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): da2[ 0:3:2, 1:4:2 ] = dv self.assertTrue( da.isEqual( da2 )) #! [Snippet_DataArrayInt_setPartOfValues1_6] - pass + return def testExample_DataArrayDouble_setPartOfValuesSimple1(self): #! [Snippet_DataArrayDouble_setPartOfValuesSimple1_1] @@ -439,7 +1308,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): da2[ 0:3:2, 1:4:2 ] = dv self.assertTrue( da.isEqual( da2, 1e-20 )) #! [Snippet_DataArrayDouble_setPartOfValuesSimple1_6] - pass + return def testExample_DataArrayInt_setPartOfValuesSimple1(self): #! [Snippet_DataArrayInt_setPartOfValuesSimple1_1] @@ -469,7 +1338,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): da2[ 0:3:2, 1:4:2 ] = dv self.assertTrue( da.isEqual( da2 )) #! [Snippet_DataArrayInt_setPartOfValuesSimple1_6] - pass + return def testExample_DataArrayDouble_setPartOfValuesSimple2(self): #! [Snippet_DataArrayDouble_setPartOfValuesSimple2_1] @@ -493,7 +1362,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): da.fillWithZero() da[[0,2], [1,3]] = dv #! [Snippet_DataArrayDouble_setPartOfValuesSimple2_5] - pass + return def testExample_DataArrayInt_setPartOfValuesSimple2(self): #! [Snippet_DataArrayInt_setPartOfValuesSimple2_1] @@ -517,7 +1386,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): da.fillWithZero() da[[0,2], [1,3]] = dv #! [Snippet_DataArrayInt_setPartOfValuesSimple2_5] - pass + return def testExample_DataArrayDouble_setPartOfValuesSimple3(self): #! [Snippet_DataArrayDouble_setPartOfValuesSimple3_1] @@ -541,7 +1410,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): da.fillWithZero() da[[0,2], 1:4:2] = dv #! [Snippet_DataArrayDouble_setPartOfValuesSimple3_5] - pass + return def testExample_DataArrayInt_setPartOfValuesSimple3(self): #! [Snippet_DataArrayInt_setPartOfValuesSimple3_1] @@ -565,7 +1434,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): da.fillWithZero() da[[0,2], 1:4:2] = dv #! [Snippet_DataArrayInt_setPartOfValuesSimple3_5] - pass + return def testExample_DataArrayDouble_setSelectedComponents(self): #! [Snippet_DataArrayDouble_setSelectedComponents1] @@ -586,7 +1455,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): dv2[:3,[1,0]] = da self.assertTrue( dv.isEqualWithoutConsideringStr( dv2, 1e-20 )) #! [Snippet_DataArrayDouble_setSelectedComponents3] - pass + return def testExample_DataArrayInt_setSelectedComponents(self): #! [Snippet_DataArrayInt_setSelectedComponents1] @@ -607,7 +1476,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): dv2[:3,[1,0]] = da self.assertTrue( dv.isEqualWithoutConsideringStr( dv2 )) #! [Snippet_DataArrayInt_setSelectedComponents3] - pass + return def testExample_DataArrayDouble_getDifferentValues(self): #! [Snippet_DataArrayDouble_getDifferentValues1] @@ -622,7 +1491,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertAlmostEqual(expected2[i],dv.getIJ(i,0),14); pass #! [Snippet_DataArrayDouble_getDifferentValues1] - pass + return def testExample_DataArrayDouble_findCommonTuples1(self): #! [PySnippet_DataArrayDouble_findCommonTuples1] @@ -631,13 +1500,13 @@ class MEDCouplingBasicsTest(unittest.TestCase): da.setValues(array2,6,2) #! [PySnippet_DataArrayDouble_findCommonTuples1] #! [PySnippet_DataArrayDouble_findCommonTuples2] - c,cI=da.findCommonTuples(1e-1); + c,cI=da.findCommonTuples(1.01e-1); expected3=[0,3,4,1,2] expected4=[0,3,5] self.assertEqual(expected3,c.getValues()) self.assertEqual(expected4,cI.getValues()) #! [PySnippet_DataArrayDouble_findCommonTuples2] - pass + return def testExampleDataArrayDoubleMeldWith(self): #! [PySnippet_DataArrayDouble_Meld1_1] @@ -695,7 +1564,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): arr2V=[1,2,1,2,0,0] a2=a1.keepSelectedComponents(arr2V) #! [SnippeDataArrayDoubleKeepSelectedComponents1_2] - pass + return def testExampleDataArrayIntKeepSelectedComponents1(self): #! [SnippeDataArrayIntKeepSelectedComponents1_1] @@ -718,7 +1587,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): #! [SnippeDataArrayIntKeepSelectedComponents1_3] a3=a1[:,arr2V ] #! [SnippeDataArrayIntKeepSelectedComponents1_3] - pass + return def testExampleFieldDoubleBuildSubPart1(self): from MEDCouplingDataForTest import MEDCouplingDataForTest @@ -832,7 +1701,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[0:4]) self.assertEqual(expected3[8:13],list(m2C.getNodalConnectivity().getValues())[8:13]) self.assertEqual(expected4,list(m2C.getNodalConnectivityIndex().getValues())) - pass + return def testExampleUMeshStdBuild1(self): # ! [PySnippetUMeshStdBuild1_1] @@ -853,13 +1722,13 @@ class MEDCouplingBasicsTest(unittest.TestCase): mesh.finishInsertingCells() # ! [PySnippetUMeshStdBuild1_3] # ! [PySnippetUMeshStdBuild1_4] - myCoords=DataArrayDouble.New(coords,9,3)#here myCoords are declared to have 3 components, mesh will deduce that its spaceDim==3. - mesh.setCoords(myCoords)#myCorrds contains 9 tuples, that is to say mesh contains 9 nodes. + coordsArr=DataArrayDouble.New(coords,9,3)#here coordsArr are declared to have 3 components, mesh will deduce that its spaceDim==3. + mesh.setCoords(coordsArr)#coordsArr contains 9 tuples, that is to say mesh contains 9 nodes. # ! [PySnippetUMeshStdBuild1_4] # ! [PySnippetUMeshStdBuild1_5] # ! [PySnippetUMeshStdBuild1_5] mesh.checkCoherency() - pass + return def testExampleCMeshStdBuild1(self): # ! [PySnippetCMeshStdBuild1_1] @@ -889,7 +1758,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual(9*7,mesh.getNumberOfNodes()) self.assertEqual(2,mesh.getSpaceDimension()) self.assertEqual(2,mesh.getMeshDimension()) - pass + return def testExampleUMeshAdvBuild1(self): # ! [PySnippetUMeshAdvBuild1_1] @@ -907,13 +1776,13 @@ class MEDCouplingBasicsTest(unittest.TestCase): mesh.setConnectivity(nodalConn,nodalConnI,True) # ! [PySnippetUMeshAdvBuild1_3] # ! [PySnippetUMeshAdvBuild1_4] - myCoords=DataArrayDouble.New(coords,9,3)#here myCoords are declared to have 3 components, mesh will deduce that its spaceDim==3. - mesh.setCoords(myCoords)#myCorrds contains 9 tuples, that is to say mesh contains 9 nodes. + coordsArr=DataArrayDouble.New(coords,9,3)#here coordsArr are declared to have 3 components, mesh will deduce that its spaceDim==3. + mesh.setCoords(coordsArr)#coordsArr contains 9 tuples, that is to say mesh contains 9 nodes. # ! [PySnippetUMeshAdvBuild1_4] # ! [PySnippetUMeshAdvBuild1_5] # ! [PySnippetUMeshAdvBuild1_5] mesh.checkCoherency() - pass + return def testExampleDataArrayBuild1(self): # ! [PySnippetDataArrayBuild1_0] @@ -936,7 +1805,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): # ! [PySnippetDataArrayBuild1_3bis] arrayInt=DataArrayInt.New(dataInt,5,3) # ! [PySnippetDataArrayBuild1_3bis] - pass + return def testExampleFieldDoubleBuild1(self): XCoords=[-0.3,0.07,0.1,0.3,0.45,0.47,0.49,1.,1.22] ; arrX=DataArrayDouble.New(XCoords) @@ -968,7 +1837,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): # ! [PySnippetFieldDoubleBuild1_2] # ! [PySnippetFieldDoubleBuild1_3] # ! [PySnippetFieldDoubleBuild1_3] - pass + return def testExampleFieldDoubleBuild2(self): XCoords=[-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22] ; arrX=DataArrayDouble.New(XCoords) @@ -986,7 +1855,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): # fieldOnNodes is now usable # ... # ! [PySnippetFieldDoubleBuild2_1] - pass + return def testExampleFieldDoubleBuild3(self): XCoords=[-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22] ; arrX=DataArrayDouble.New(XCoords) @@ -1006,7 +1875,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): # fieldOnCells is now usable # ... # ! [PySnippetFieldDoubleBuild3_1] - pass + return def testExampleFieldDoubleBuild4(self): XCoords=[-0.3,0.,0.1,0.3,0.45,0.47,0.49,1.,1.22] ; arrX=DataArrayDouble.New(XCoords) @@ -1027,7 +1896,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): # fieldOnNodes is now usable # ... # ! [PySnippetFieldDoubleBuild4_1] - pass + return def testExampleDataArrayApplyFunc1(self): # ! [PySnippetDataArrayApplyFunc1_1] @@ -1066,7 +1935,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): ddd1=ddd.applyFunc3(1,["X","Y","Z"],"X+Z") self.assertTrue(ddd1.isEqual(DataArrayDouble([4.,24.,44.,64.],4,1),1e-12)) # ! [PySnippetDataArrayApplyFunc1_9] - pass + return pass diff --git a/src/MEDCoupling_Swig/MEDCouplingFinalize.i b/src/MEDCoupling_Swig/MEDCouplingFinalize.i index 4c2c9df4f..9a755af66 100644 --- a/src/MEDCoupling_Swig/MEDCouplingFinalize.i +++ b/src/MEDCoupling_Swig/MEDCouplingFinalize.i @@ -35,6 +35,7 @@ MEDCouplingFieldDouble.__iadd__=ParaMEDMEMMEDCouplingFieldDoubleIadd MEDCouplingFieldDouble.__isub__=ParaMEDMEMMEDCouplingFieldDoubleIsub MEDCouplingFieldDouble.__imul__=ParaMEDMEMMEDCouplingFieldDoubleImul MEDCouplingFieldDouble.__idiv__=ParaMEDMEMMEDCouplingFieldDoubleIdiv +MEDCouplingFieldDouble.__ipow__=ParaMEDMEMMEDCouplingFieldDoubleIpow DataArrayDoubleTuple.__iadd__=ParaMEDMEMDataArrayDoubleTupleIadd DataArrayDoubleTuple.__isub__=ParaMEDMEMDataArrayDoubleTupleIsub @@ -55,6 +56,7 @@ del ParaMEDMEMMEDCouplingFieldDoubleIadd del ParaMEDMEMMEDCouplingFieldDoubleIsub del ParaMEDMEMMEDCouplingFieldDoubleImul del ParaMEDMEMMEDCouplingFieldDoubleIdiv +del ParaMEDMEMMEDCouplingFieldDoubleIpow del ParaMEDMEMDataArrayIntIadd del ParaMEDMEMDataArrayIntIsub del ParaMEDMEMDataArrayIntImul diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i new file mode 100644 index 000000000..af37bec17 --- /dev/null +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -0,0 +1,5561 @@ +// Copyright (C) 2007-2013 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. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (CEA/DEN) + +namespace ParaMEDMEM +{ + class DataArray : public RefCountObject, public TimeLabel + { + public: + void setName(const char *name); + void copyStringInfoFrom(const DataArray& other) throw(INTERP_KERNEL::Exception); + void copyPartOfStringInfoFrom(const DataArray& other, const std::vector& compoIds) throw(INTERP_KERNEL::Exception); + void copyPartOfStringInfoFrom2(const std::vector& compoIds, const DataArray& other) throw(INTERP_KERNEL::Exception); + bool areInfoEqualsIfNotWhy(const DataArray& other, std::string& reason) const throw(INTERP_KERNEL::Exception); + bool areInfoEquals(const DataArray& other) const throw(INTERP_KERNEL::Exception); + std::string cppRepr(const char *varName) const throw(INTERP_KERNEL::Exception); + std::string getName() const; + void setInfoOnComponents(const std::vector& info) throw(INTERP_KERNEL::Exception); + std::vector getVarsOnComponent() const throw(INTERP_KERNEL::Exception); + std::vector getUnitsOnComponent() const throw(INTERP_KERNEL::Exception); + std::string getInfoOnComponent(int i) const throw(INTERP_KERNEL::Exception); + std::string getVarOnComponent(int i) const throw(INTERP_KERNEL::Exception); + std::string getUnitOnComponent(int i) const throw(INTERP_KERNEL::Exception); + void setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception); + int getNumberOfComponents() const; + virtual int getNumberOfTuples() const throw(INTERP_KERNEL::Exception); + virtual std::size_t getNbOfElems() const throw(INTERP_KERNEL::Exception); + virtual std::size_t getNbOfElemAllocated() const throw(INTERP_KERNEL::Exception); + void checkNbOfTuples(int nbOfTuples, const char *msg) const throw(INTERP_KERNEL::Exception); + void checkNbOfComps(int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception); + void checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const throw(INTERP_KERNEL::Exception); + void checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception); + void checkNbOfElems(std::size_t nbOfElems, const char *msg) const throw(INTERP_KERNEL::Exception); + static int GetNumberOfItemGivenBES(int begin, int end, int step, const char *msg) throw(INTERP_KERNEL::Exception); + static int GetNumberOfItemGivenBESRelative(int begin, int end, int step, const char *msg) throw(INTERP_KERNEL::Exception); + static int GetPosOfItemGivenBESRelativeNoThrow(int value, int begin, int end, int step) throw(INTERP_KERNEL::Exception); + static std::string GetVarNameFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception); + static std::string GetUnitFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception); + void updateTime() const; + %extend + { + PyObject *getInfoOnComponents() const throw(INTERP_KERNEL::Exception) + { + const std::vector& comps=self->getInfoOnComponents(); + PyObject *ret=PyList_New((int)comps.size()); + for(int i=0;i<(int)comps.size();i++) + PyList_SetItem(ret,i,PyString_FromString(comps[i].c_str())); + return ret; + } + + void copyPartOfStringInfoFrom(const DataArray& other, PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyToNewIntArr3(li,tmp); + self->copyPartOfStringInfoFrom(other,tmp); + } + + void copyPartOfStringInfoFrom2(PyObject *li, const DataArray& other) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyToNewIntArr3(li,tmp); + self->copyPartOfStringInfoFrom2(tmp,other); + } + } + }; + + class DataArrayInt; + class DataArrayDoubleIterator; + + class DataArrayDouble : public DataArray + { + public: + static DataArrayDouble *New(); + bool isAllocated() const throw(INTERP_KERNEL::Exception); + void checkAllocated() const throw(INTERP_KERNEL::Exception); + void setInfoAndChangeNbOfCompo(const std::vector& info) throw(INTERP_KERNEL::Exception); + double doubleValue() const throw(INTERP_KERNEL::Exception); + bool empty() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *deepCpy() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *performCpy(bool deepCpy) const throw(INTERP_KERNEL::Exception); + void cpyFrom(const DataArrayDouble& other) throw(INTERP_KERNEL::Exception); + void reserve(std::size_t nbOfElems) throw(INTERP_KERNEL::Exception); + void pushBackSilent(double val) throw(INTERP_KERNEL::Exception); + void pushBackValsSilent(const double *valsBg, const double *valsEnd) throw(INTERP_KERNEL::Exception); + double popBackSilent() throw(INTERP_KERNEL::Exception); + void pack() const throw(INTERP_KERNEL::Exception); + void alloc(int nbOfTuple, int nbOfCompo=1) throw(INTERP_KERNEL::Exception); + void allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); + void fillWithZero() throw(INTERP_KERNEL::Exception); + void fillWithValue(double val) throw(INTERP_KERNEL::Exception); + void iota(double init=0.) throw(INTERP_KERNEL::Exception); + bool isUniform(double val, double eps) const throw(INTERP_KERNEL::Exception); + void sort(bool asc=true) throw(INTERP_KERNEL::Exception); + void reverse() throw(INTERP_KERNEL::Exception); + void checkMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception); + bool isMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception); + std::string repr() const throw(INTERP_KERNEL::Exception); + std::string reprZip() const throw(INTERP_KERNEL::Exception); + bool isEqual(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception); + bool isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception); + void reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception); + DataArrayInt *convertToIntArr() const; + DataArrayDouble *fromNoInterlace() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *toNoInterlace() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception); + DataArrayDouble *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); + void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception); + void transpose() throw(INTERP_KERNEL::Exception); + DataArrayDouble *changeNbOfComponents(int newNbOfComp, double dftValue) const throw(INTERP_KERNEL::Exception); + void meldWith(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception); + DataArrayDouble *duplicateEachTupleNTimes(int nbTimes) const throw(INTERP_KERNEL::Exception); + DataArrayDouble *getDifferentValues(double prec, int limitTupleId=-1) const throw(INTERP_KERNEL::Exception); + DataArrayInt *findClosestTupleId(const DataArrayDouble *other) const throw(INTERP_KERNEL::Exception); + void setPartOfValues1(const DataArrayDouble *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true) throw(INTERP_KERNEL::Exception); + void setPartOfValuesSimple1(double a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception); + void setPartOfValuesAdv(const DataArrayDouble *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception); + void setContigPartOfSelectedValues(int tupleIdStart, const DataArrayDouble *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception); + void setContigPartOfSelectedValues2(int tupleIdStart, const DataArrayDouble *a, int bg, int end2, int step) throw(INTERP_KERNEL::Exception); + double getIJ(int tupleId, int compoId) const; + double back() const throw(INTERP_KERNEL::Exception); + double getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception); + void setIJ(int tupleId, int compoId, double newVal) throw(INTERP_KERNEL::Exception); + void setIJSilent(int tupleId, int compoId, double newVal) throw(INTERP_KERNEL::Exception); + double *getPointer() throw(INTERP_KERNEL::Exception); + void checkNoNullValues() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *computeBBoxPerTuple(double epsilon=0.0) const throw(INTERP_KERNEL::Exception); + void recenterForMaxPrecision(double eps) throw(INTERP_KERNEL::Exception); + double getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception); + double getMaxValueInArray() const throw(INTERP_KERNEL::Exception); + double getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception); + double getMinValueInArray() const throw(INTERP_KERNEL::Exception); + double getAverageValue() const throw(INTERP_KERNEL::Exception); + double norm2() const throw(INTERP_KERNEL::Exception); + double normMax() const throw(INTERP_KERNEL::Exception); + void accumulate(double *res) const throw(INTERP_KERNEL::Exception); + double accumulate(int compId) const throw(INTERP_KERNEL::Exception); + DataArrayDouble *fromPolarToCart() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *fromCylToCart() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *fromSpherToCart() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *doublyContractedProduct() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *determinant() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *eigenValues() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *eigenVectors() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *inverse() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *trace() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *deviator() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *magnitude() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *maxPerTuple() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *buildEuclidianDistanceDenseMatrix() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *buildEuclidianDistanceDenseMatrixWith(const DataArrayDouble *other) const throw(INTERP_KERNEL::Exception); + void sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception); + void abs() throw(INTERP_KERNEL::Exception); + void applyLin(double a, double b, int compoId) throw(INTERP_KERNEL::Exception); + void applyLin(double a, double b) throw(INTERP_KERNEL::Exception); + void applyInv(double numerator) throw(INTERP_KERNEL::Exception); + void applyPow(double val) throw(INTERP_KERNEL::Exception); + void applyRPow(double val) throw(INTERP_KERNEL::Exception); + DataArrayDouble *negate() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *applyFunc(int nbOfComp, FunctionToEvaluate func) const throw(INTERP_KERNEL::Exception); + DataArrayDouble *applyFunc(int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception); + DataArrayDouble *applyFunc(const char *func) const throw(INTERP_KERNEL::Exception); + DataArrayDouble *applyFunc2(int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception); + DataArrayDouble *applyFunc3(int nbOfComp, const std::vector& varsOrder, const char *func) const throw(INTERP_KERNEL::Exception); + void applyFuncFast32(const char *func) throw(INTERP_KERNEL::Exception); + void applyFuncFast64(const char *func) throw(INTERP_KERNEL::Exception); + DataArrayInt *getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception); + static DataArrayDouble *Aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + static DataArrayDouble *Aggregate(const std::vector& arr) throw(INTERP_KERNEL::Exception); + static DataArrayDouble *Meld(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + static DataArrayDouble *Meld(const std::vector& arr) throw(INTERP_KERNEL::Exception); + static DataArrayDouble *Dot(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + static DataArrayDouble *CrossProduct(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + static DataArrayDouble *Max(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + static DataArrayDouble *Min(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + static DataArrayDouble *Add(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + void addEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception); + static DataArrayDouble *Substract(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + void substractEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception); + static DataArrayDouble *Multiply(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + void multiplyEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception); + static DataArrayDouble *Divide(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + void divideEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception); + static DataArrayDouble *Pow(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); + void powEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception); + %extend + { + DataArrayDouble() throw(INTERP_KERNEL::Exception) + { + return DataArrayDouble::New(); + } + + static DataArrayDouble *New(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *elt2=0) throw(INTERP_KERNEL::Exception) + { + const char *msg="ParaMEDMEM::DataArrayDouble::New : Available API are : \n-DataArrayDouble.New()\n-DataArrayDouble.New([1.,3.,4.])\n-DataArrayDouble.New([1.,3.,4.],3)\n-DataArrayDouble.New([1.,3.,4.,5.],2,2)\n-DataArrayDouble.New([1.,3.,4.,5.,7,8.],3,2)\n-DataArrayDouble.New(5)\n-DataArrayDouble.New(5,2) !"; + if(PyList_Check(elt0) || PyTuple_Check(elt0)) + { + if(nbOfTuples) + { + if(PyInt_Check(nbOfTuples)) + { + int nbOfTuples1=PyInt_AS_LONG(nbOfTuples); + if(nbOfTuples1<0) + throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !"); + if(elt2) + { + if(PyInt_Check(elt2)) + {//DataArrayDouble.New([1.,3.,4.,5.],2,2) + int nbOfCompo=PyInt_AS_LONG(elt2); + if(nbOfCompo<0) + throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !"); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); + std::vector tmp=fillArrayWithPyListDbl2(elt0,nbOfTuples1,nbOfCompo); + ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + return ret.retn(); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {//DataArrayDouble.New([1.,3.,4.],3) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); + int tmpp1=-1; + std::vector tmp=fillArrayWithPyListDbl2(elt0,nbOfTuples1,tmpp1); + ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + return ret.retn(); + } + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {// DataArrayDouble.New([1.,3.,4.]) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); + int tmpp1=-1,tmpp2=-1; + std::vector tmp=fillArrayWithPyListDbl2(elt0,tmpp1,tmpp2); + ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + return ret.retn(); + } + } + else if(PyInt_Check(elt0)) + { + int nbOfTuples1=PyInt_AS_LONG(elt0); + if(nbOfTuples1<0) + throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !"); + if(nbOfTuples) + { + if(!elt2) + { + if(PyInt_Check(nbOfTuples)) + {//DataArrayDouble.New(5,2) + int nbOfCompo=PyInt_AS_LONG(nbOfTuples); + if(nbOfCompo<0) + throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !"); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); + ret->alloc(nbOfTuples1,nbOfCompo); + return ret.retn(); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {//DataArrayDouble.New(5) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); + ret->alloc(nbOfTuples1,1); + return ret.retn(); + } + } + else + throw INTERP_KERNEL::Exception(msg); + } + + DataArrayDouble(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *elt2=0) throw(INTERP_KERNEL::Exception) + { + return ParaMEDMEM_DataArrayDouble_New__SWIG_1(elt0,nbOfTuples,elt2); + } + + void pushBackValsSilent(PyObject *li) throw(INTERP_KERNEL::Exception) + { + double val; + std::vector bb; + int sw,nbTuples=-1; + const char msg[]="Python wrap of DataArrayDouble::pushBackValsSilent : "; + const double *tmp=convertObjToPossibleCpp5_SingleCompo(li,sw,val,bb,msg,true,nbTuples); + self->pushBackValsSilent(tmp,tmp+nbTuples); + } + + std::string __repr__() const throw(INTERP_KERNEL::Exception) + { + std::ostringstream oss; + self->reprQuickOverview(oss); + return oss.str(); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->repr(); + } + + double __float__() const throw(INTERP_KERNEL::Exception) + { + return self->doubleValue(); + } + + int __len__() const throw(INTERP_KERNEL::Exception) + { + if(self->isAllocated()) + { + return self->getNumberOfTuples(); + } + else + { + throw INTERP_KERNEL::Exception("DataArrayDouble::__len__ : Instance is NOT allocated !"); + } + } + + DataArrayDoubleIterator *__iter__() + { + return self->iterator(); + } + + void setValues(PyObject *li, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) + { + const char *msg="ParaMEDMEM::DataArrayDouble::setValues : Available API are : \n-DataArrayDouble.setValues([1.,3.,4.])\n-DataArrayDouble.setValues([1.,3.,4.],3)\n-DataArrayDouble.setValues([1.,3.,4.,5.],2,2)\n-DataArrayDouble.setValues([(1.,1.7),(3.,3.7),(4.,4.7)])\n !"; + if(PyList_Check(li) || PyTuple_Check(li)) + { + if(nbOfTuples) + { + if(PyInt_Check(nbOfTuples)) + { + int nbOfTuples1=PyInt_AS_LONG(nbOfTuples); + if(nbOfTuples1<0) + throw INTERP_KERNEL::Exception("DataArrayDouble::setValues : should be a positive set of allocated memory !"); + if(nbOfComp) + { + if(PyInt_Check(nbOfComp)) + {//DataArrayDouble.setValues([1.,3.,4.,5.],2,2) + int nbOfCompo=PyInt_AS_LONG(nbOfComp); + if(nbOfCompo<0) + throw INTERP_KERNEL::Exception("DataArrayDouble::setValues : should be a positive number of components !"); + std::vector tmp=fillArrayWithPyListDbl2(li,nbOfTuples1,nbOfCompo); + self->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),self->getPointer()); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {//DataArrayDouble.setValues([1.,3.,4.],3) + int tmpp1=-1; + std::vector tmp=fillArrayWithPyListDbl2(li,nbOfTuples1,tmpp1); + self->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),self->getPointer()); + } + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {// DataArrayDouble.setValues([1.,3.,4.]) + int tmpp1=-1,tmpp2=-1; + std::vector tmp=fillArrayWithPyListDbl2(li,tmpp1,tmpp2); + self->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),self->getPointer()); + } + } + else + throw INTERP_KERNEL::Exception(msg); + } + + PyObject *getValues() const throw(INTERP_KERNEL::Exception) + { + const double *vals=self->getConstPointer(); + return convertDblArrToPyList(vals,self->getNbOfElems()); + } + + PyObject *isEqualIfNotWhy(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception) + { + std::string ret1; + bool ret0=self->isEqualIfNotWhy(other,prec,ret1); + PyObject *ret=PyTuple_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyTuple_SetItem(ret,0,ret0Py); + PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str())); + return ret; + } + + PyObject *getValuesAsTuple() const throw(INTERP_KERNEL::Exception) + { + const double *vals=self->getConstPointer(); + int nbOfComp=self->getNumberOfComponents(); + int nbOfTuples=self->getNumberOfTuples(); + return convertDblArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); + } + + DataArrayDouble *renumber(PyObject *li) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumber(tmp); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumber(da2->getConstPointer()); + } + } + + DataArrayDouble *renumberR(PyObject *li) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumberR(tmp); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumberR(da2->getConstPointer()); + } + } + + DataArrayDouble *renumberAndReduce(PyObject *li, int newNbOfTuple) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumberAndReduce(tmp,newNbOfTuple); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumberAndReduce(da2->getConstPointer(),newNbOfTuple); + } + } + + void renumberInPlace(PyObject *li) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + self->renumberInPlace(tmp); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + self->renumberInPlace(da2->getConstPointer()); + } + } + + void renumberInPlaceR(PyObject *li) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + self->renumberInPlaceR(tmp); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + self->renumberInPlaceR(da2->getConstPointer()); + } + } + + DataArrayDouble *selectByTupleId(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + return self->selectByTupleId(tmp,tmp+size); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + return self->selectByTupleId(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); + } + } + + DataArrayDouble *selectByTupleIdSafe(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + return self->selectByTupleIdSafe(tmp,tmp+size); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + return self->selectByTupleIdSafe(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); + } + } + + PyObject *minimalDistanceTo(const DataArrayDouble *other) const throw(INTERP_KERNEL::Exception) + { + int thisTupleId,otherTupleId; + double r0=self->minimalDistanceTo(other,thisTupleId,otherTupleId); + PyObject *ret=PyTuple_New(3); + PyTuple_SetItem(ret,0,PyFloat_FromDouble(r0)); + PyTuple_SetItem(ret,1,PyInt_FromLong(thisTupleId)); + PyTuple_SetItem(ret,2,PyInt_FromLong(otherTupleId)); + return ret; + } + + PyObject *getMaxValue() const throw(INTERP_KERNEL::Exception) + { + int tmp; + double r1=self->getMaxValue(tmp); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyFloat_FromDouble(r1)); + PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); + return ret; + } + + PyObject *getMaxValue2() const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *tmp; + double r1=self->getMaxValue2(tmp); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyFloat_FromDouble(r1)); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + + PyObject *getMinValue() const throw(INTERP_KERNEL::Exception) + { + int tmp; + double r1=self->getMinValue(tmp); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyFloat_FromDouble(r1)); + PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); + return ret; + } + + PyObject *getMinValue2() const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *tmp; + double r1=self->getMinValue2(tmp); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyFloat_FromDouble(r1)); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + + PyObject *getMinMaxPerComponent() const throw(INTERP_KERNEL::Exception) + { + int nbOfCompo=self->getNumberOfComponents(); + INTERP_KERNEL::AutoPtr tmp=new double[2*nbOfCompo]; + self->getMinMaxPerComponent(tmp); + PyObject *ret=convertDblArrToPyListOfTuple(tmp,2,nbOfCompo); + return ret; + } + + PyObject *accumulate() const throw(INTERP_KERNEL::Exception) + { + int sz=self->getNumberOfComponents(); + INTERP_KERNEL::AutoPtr tmp=new double[sz]; + self->accumulate(tmp); + return convertDblArrToPyList(tmp,sz); + } + + DataArrayDouble *keepSelectedComponents(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyToNewIntArr3(li,tmp); + return self->keepSelectedComponents(tmp); + } + + PyObject *findCommonTuples(double prec, int limitNodeId=-1) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *comm, *commIndex; + self->findCommonTuples(prec,limitNodeId,comm,commIndex); + PyObject *res = PyList_New(2); + PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(comm),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(res,1,SWIG_NewPointerObj(SWIG_as_voidptr(commIndex),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return res; + } + + PyObject *distanceToTuple(PyObject *tuple) const throw(INTERP_KERNEL::Exception) + { + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + int tupleId=-1,nbOfCompo=self->getNumberOfComponents(); + const double *pt=convertObjToPossibleCpp5_Safe(tuple,sw,val,a,aa,bb,"Python wrap of DataArrayDouble::distanceToTuple",1,nbOfCompo,true); + // + double ret0=self->distanceToTuple(pt,pt+nbOfCompo,tupleId); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyFloat_FromDouble(ret0)); + PyTuple_SetItem(ret,1,PyInt_FromLong(tupleId)); + return ret; + } + + void setSelectedComponents(const DataArrayDouble *a, PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyToNewIntArr3(li,tmp); + self->setSelectedComponents(a,tmp); + } + + PyObject *getTuple(int tupleId) throw(INTERP_KERNEL::Exception) + { + int sz=self->getNumberOfComponents(); + INTERP_KERNEL::AutoPtr tmp=new double[sz]; + self->getTuple(tupleId,tmp); + return convertDblArrToPyList(tmp,sz); + } + + static DataArrayDouble *Aggregate(PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,"DataArrayDouble",tmp); + return DataArrayDouble::Aggregate(tmp); + } + + static DataArrayDouble *Meld(PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,"DataArrayDouble",tmp); + return DataArrayDouble::Meld(tmp); + } + + DataArrayDouble *selectByTupleRanges(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + std::vector > ranges; + convertPyToVectorPairInt(li,ranges); + return self->selectByTupleRanges(ranges); + } + + PyObject *computeTupleIdsNearTuples(PyObject *pt, double eps) const throw(INTERP_KERNEL::Exception) + { + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + int nbComp=self->getNumberOfComponents(),nbTuples=-1; + const char msg[]="Python wrap of DataArrayDouble::computeTupleIdsNearTuples : "; + const double *pos=convertObjToPossibleCpp5_Safe2(pt,sw,val,a,aa,bb,msg,nbComp,true,nbTuples); + MEDCouplingAutoRefCountObjectPtr inpu=DataArrayDouble::New(); inpu->useArray(pos,false,CPP_DEALLOC,nbTuples,nbComp); + DataArrayInt *c=0,*cI=0; + self->computeTupleIdsNearTuples(inpu,eps,c,cI); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(c),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cI),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + + PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in DataArrayDouble::__getitem__ !"; + const char msg2[]="DataArrayDouble::__getitem__ : Mismatch of slice values in 2nd parameter (components) !"; + self->checkAllocated(); + int nbOfTuples=self->getNumberOfTuples(); + int nbOfComponents=self->getNumberOfComponents(); + int it1,ic1; + std::vector vt1,vc1; + std::pair > pt1,pc1; + DataArrayInt *dt1=0,*dc1=0; + int sw; + convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1); + MEDCouplingAutoRefCountObjectPtr ret; + switch(sw) + { + case 1: + if(nbOfComponents==1) + return PyFloat_FromDouble(self->getIJSafe(it1,0)); + return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + case 2: + return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + case 3: + return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + case 4: + return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + case 5: + return PyFloat_FromDouble(self->getIJSafe(it1,ic1)); + case 6: + { + ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size()); + std::vector v2(1,ic1); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 7: + { + ret=self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second); + std::vector v2(1,ic1); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 8: + { + ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems()); + std::vector v2(1,ic1); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 9: + { + ret=self->selectByTupleIdSafe(&it1,&it1+1); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 10: + { + ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size()); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 11: + { + ret=self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 12: + { + ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems()); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 13: + { + ret=self->selectByTupleIdSafe(&it1,&it1+1); + int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2); + std::vector v2(nbOfComp); + for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 14: + { + ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size()); + int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2); + std::vector v2(nbOfComp); + for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 15: + { + ret=self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second); + int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2); + std::vector v2(nbOfComp); + for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 16: + { + ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems()); + int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2); + std::vector v2(nbOfComp); + for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayDouble *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception) + { + self->checkAllocated(); + const char msg[]="Unexpected situation in DataArrayDouble::__setitem__ !"; + int nbOfTuples=self->getNumberOfTuples(); + int nbOfComponents=self->getNumberOfComponents(); + int sw1,sw2; + double i1; + std::vector v1; + DataArrayDouble *d1=0; + convertObjToPossibleCpp4(value,sw1,i1,v1,d1); + int it1,ic1; + std::vector vt1,vc1; + std::pair > pt1,pc1; + DataArrayInt *dt1=0,*dc1=0; + convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1); + MEDCouplingAutoRefCountObjectPtr tmp; + switch(sw2) + { + case 1: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1); + return self; + case 2: + tmp=DataArrayDouble::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false); + return self; + case 3: + self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 2: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1); + return self; + case 2: + tmp=DataArrayDouble::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false); + return self; + case 3: + self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 3: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1); + return self; + case 2: + tmp=DataArrayDouble::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false); + return self; + case 3: + self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 4: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1); + return self; + case 2: + tmp=DataArrayDouble::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false); + return self; + case 3: + self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 5: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1); + return self; + case 2: + tmp=DataArrayDouble::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false); + return self; + case 3: + self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 6: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1); + return self; + case 2: + tmp=DataArrayDouble::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false); + return self; + case 3: + self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 7: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1); + return self; + case 2: + tmp=DataArrayDouble::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false); + return self; + case 3: + self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 8: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1); + return self; + case 2: + tmp=DataArrayDouble::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false); + return self; + case 3: + self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 9: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size()); + return self; + case 2: + tmp=DataArrayDouble::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false); + return self; + case 3: + self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size()); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 10: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size()); + return self; + case 2: + tmp=DataArrayDouble::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false); + return self; + case 3: + self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size()); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 11: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size()); + return self; + case 2: + tmp=DataArrayDouble::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false); + return self; + case 3: + self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size()); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 12: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size()); + return self; + case 2: + tmp=DataArrayDouble::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false); + return self; + case 3: + self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size()); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 13: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second); + return self; + case 2: + tmp=DataArrayDouble::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false); + return self; + case 3: + self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 14: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second); + return self; + case 2: + tmp=DataArrayDouble::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false); + return self; + case 3: + self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 15: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second); + return self; + case 2: + tmp=DataArrayDouble::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false); + return self; + case 3: + self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 16: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second); + return self; + case 2: + tmp=DataArrayDouble::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false); + return self; + case 3: + self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + return self; + } + + DataArrayDouble *__neg__() const throw(INTERP_KERNEL::Exception) + { + return self->negate(); + } + + PyObject *__add__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in DataArrayDouble.__add__ !"; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + // + void *argp; + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + { + PyObject *tmp=SWIG_NewPointerObj(SWIG_as_voidptr(self),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, 0 | 0 ); + MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM_MEDCouplingFieldDouble___radd__Impl(other,tmp); + Py_XDECREF(tmp); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret.retn()),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 ); + } + else + throw INTERP_KERNEL::Exception(msg); + } + // + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyLin(1.,val); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 2: + { + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Add(self,a)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Add(self,aaa)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Add(self,aaa)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayDouble *__radd__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __radd__ !"; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyLin(1.,val); + return ret.retn(); + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + return DataArrayDouble::Add(self,aaa); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + return DataArrayDouble::Add(self,aaa); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __iadd__ !"; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + self->applyLin(1.,val); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + self->addEqual(a); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + self->addEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + self->addEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + PyObject *__sub__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __sub__ !"; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + // + void *argp; + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + { + PyObject *tmp=SWIG_NewPointerObj(SWIG_as_voidptr(self),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, 0 | 0 ); + MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM_MEDCouplingFieldDouble___rsub__Impl(other,tmp); + Py_XDECREF(tmp); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret.retn()),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 ); + } + else + throw INTERP_KERNEL::Exception(msg); + } + // + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyLin(1.,-val); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 2: + { + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Substract(self,a)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Substract(self,aaa)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Substract(self,aaa)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayDouble *__rsub__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __rsub__ !"; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyLin(-1.,val); + return ret.retn(); + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + return DataArrayDouble::Substract(aaa,self); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + return DataArrayDouble::Substract(aaa,self); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __isub__ !"; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + self->applyLin(1,-val); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + self->substractEqual(a); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + self->substractEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + self->substractEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + PyObject *__mul__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __mul__ !"; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + // + void *argp; + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + { + PyObject *tmp=SWIG_NewPointerObj(SWIG_as_voidptr(self),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, 0 | 0 ); + MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM_MEDCouplingFieldDouble___rmul__Impl(other,tmp); + Py_XDECREF(tmp); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret.retn()),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 ); + } + else + throw INTERP_KERNEL::Exception(msg); + } + // + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyLin(val,0.); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 2: + { + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Multiply(self,a)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Multiply(self,aaa)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Multiply(self,aaa)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayDouble *__rmul__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __rmul__ !"; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyLin(val,0.); + return ret.retn(); + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + return DataArrayDouble::Multiply(self,aaa); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + return DataArrayDouble::Multiply(self,aaa); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __imul__ !"; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + self->applyLin(val,0.); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + self->multiplyEqual(a); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + self->multiplyEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + self->multiplyEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + PyObject *__div__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __div__ !"; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + // + void *argp; + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + { + PyObject *tmp=SWIG_NewPointerObj(SWIG_as_voidptr(self),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, 0 | 0 ); + MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Impl(other,tmp); + Py_XDECREF(tmp); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret.retn()),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 ); + } + else + throw INTERP_KERNEL::Exception(msg); + } + // + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + if(val==0.) + throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !"); + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyLin(1/val,0.); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 2: + { + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Divide(self,a)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Divide(self,aaa)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Divide(self,aaa)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayDouble *__rdiv__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __rdiv__ !"; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyInv(val); + return ret.retn(); + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + return DataArrayDouble::Divide(aaa,self); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + return DataArrayDouble::Divide(aaa,self); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __idiv__ !"; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + if(val==0.) + throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !"); + self->applyLin(1./val,0.); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + self->divideEqual(a); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + self->divideEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + self->divideEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayDouble *__pow__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __pow__ !"; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyPow(val); + return ret.retn(); + } + case 2: + { + return DataArrayDouble::Pow(self,a); + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + return DataArrayDouble::Pow(self,aaa); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + return DataArrayDouble::Pow(self,aaa); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayDouble *__rpow__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __rpow__ !"; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyRPow(val); + return ret.retn(); + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + return DataArrayDouble::Pow(aaa,self); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + return DataArrayDouble::Pow(aaa,self); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + PyObject *___ipow___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __ipow__ !"; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + self->applyPow(val); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + self->powEqual(a); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + self->powEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); + self->powEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + PyObject *computeTupleIdsNearTuples(const DataArrayDouble *other, double eps) + { + DataArrayInt *c=0,*cI=0; + // + self->computeTupleIdsNearTuples(other,eps,c,cI); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(c),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cI),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + } + }; + + class DataArrayDoubleTuple; + + class DataArrayDoubleIterator + { + public: + DataArrayDoubleIterator(DataArrayDouble *da); + ~DataArrayDoubleIterator(); + %extend + { + PyObject *next() + { + DataArrayDoubleTuple *ret=self->nextt(); + if(ret) + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,SWIG_POINTER_OWN|0); + else + { + PyErr_SetString(PyExc_StopIteration,"No more data."); + return 0; + } + } + } + }; + + class DataArrayDoubleTuple + { + public: + int getNumberOfCompo() const; + DataArrayDouble *buildDADouble(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception); + %extend + { + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->repr(); + } + + double __float__() const throw(INTERP_KERNEL::Exception) + { + return self->doubleValue(); + } + + DataArrayDouble *buildDADouble() + { + return self->buildDADouble(1,self->getNumberOfCompo()); + } + + PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + MEDCouplingAutoRefCountObjectPtr ret=self->buildDADouble(1,self->getNumberOfCompo()); + ParaMEDMEM_DataArrayDouble____iadd___(ret,0,obj); + Py_XINCREF(trueSelf); + return trueSelf; + } + + PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + MEDCouplingAutoRefCountObjectPtr ret=self->buildDADouble(1,self->getNumberOfCompo()); + ParaMEDMEM_DataArrayDouble____isub___(ret,0,obj); + Py_XINCREF(trueSelf); + return trueSelf; + } + + PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + MEDCouplingAutoRefCountObjectPtr ret=self->buildDADouble(1,self->getNumberOfCompo()); + ParaMEDMEM_DataArrayDouble____imul___(ret,0,obj); + Py_XINCREF(trueSelf); + return trueSelf; + } + + PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + MEDCouplingAutoRefCountObjectPtr ret=self->buildDADouble(1,self->getNumberOfCompo()); + ParaMEDMEM_DataArrayDouble____idiv___(ret,0,obj); + Py_XINCREF(trueSelf); + return trueSelf; + } + + PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg2[]="DataArrayDoubleTuple::__getitem__ : Mismatch of slice values in 2nd parameter (components) !"; + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + const double *pt=self->getConstPointer(); + int nbc=self->getNumberOfCompo(); + convertObjToPossibleCpp2(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + { + if(singleVal>=nbc) + { + std::ostringstream oss; + oss << "Requesting for id " << singleVal << " having only " << nbc << " components !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(singleVal>=0) + return PyFloat_FromDouble(pt[singleVal]); + else + { + if(nbc+singleVal>0) + return PyFloat_FromDouble(pt[nbc+singleVal]); + else + { + std::ostringstream oss; + oss << "Requesting for id " << singleVal << " having only " << nbc << " components !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + } + case 2: + { + PyObject *t=PyTuple_New(multiVal.size()); + for(int j=0;j<(int)multiVal.size();j++) + { + int cid=multiVal[j]; + if(cid>=nbc) + { + std::ostringstream oss; + oss << "Requesting for id #" << cid << " having only " << nbc << " components !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + PyTuple_SetItem(t,j,PyFloat_FromDouble(pt[cid])); + } + return t; + } + case 3: + { + int sz=DataArray::GetNumberOfItemGivenBES(slic.first,slic.second.first,slic.second.second,msg2); + PyObject *t=PyTuple_New(sz); + for(int j=0;j multiValV; + ParaMEDMEM::DataArrayDoubleTuple *daIntTyyppV=0; + int nbc=self->getNumberOfCompo(); + convertObjToPossibleCpp44(value,sw1,singleValV,multiValV,daIntTyyppV); + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + double *pt=self->getPointer(); + convertObjToPossibleCpp2(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp); + switch(sw2) + { + case 1: + { + if(singleVal>=nbc) + { + std::ostringstream oss; + oss << "Requesting for setting id # " << singleVal << " having only " << nbc << " components !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + switch(sw1) + { + case 1: + { + pt[singleVal]=singleValV; + return self; + } + case 2: + { + if(multiValV.size()!=1) + { + std::ostringstream oss; + oss << "Requesting for setting id # " << singleVal << " with a list or tuple with size != 1 ! "; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + pt[singleVal]=multiValV[0]; + return self; + } + case 3: + { + pt[singleVal]=daIntTyyppV->getConstPointer()[0]; + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + case 2: + { + switch(sw1) + { + case 1: + { + for(std::vector::const_iterator it=multiVal.begin();it!=multiVal.end();it++) + { + if(*it>=nbc) + { + std::ostringstream oss; + oss << "Requesting for setting id # " << *it << " having only " << nbc << " components !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + pt[*it]=singleValV; + } + return self; + } + case 2: + { + if(multiVal.size()!=multiValV.size()) + { + std::ostringstream oss; + oss << "Mismatch length of during assignment : " << multiValV.size() << " != " << multiVal.size() << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + for(int i=0;i<(int)multiVal.size();i++) + { + int pos=multiVal[i]; + if(pos>=nbc) + { + std::ostringstream oss; + oss << "Requesting for setting id # " << pos << " having only " << nbc << " components !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + pt[multiVal[i]]=multiValV[i]; + } + return self; + } + case 3: + { + const double *ptV=daIntTyyppV->getConstPointer(); + if(nbc>daIntTyyppV->getNumberOfCompo()) + { + std::ostringstream oss; + oss << "Mismatch length of during assignment : " << nbc << " != " << daIntTyyppV->getNumberOfCompo() << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + std::copy(ptV,ptV+nbc,pt); + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + case 3: + { + int sz=DataArray::GetNumberOfItemGivenBES(slic.first,slic.second.first,slic.second.second,msg2); + switch(sw1) + { + case 1: + { + for(int j=0;jgetConstPointer(); + if(sz>daIntTyyppV->getNumberOfCompo()) + { + std::ostringstream oss; + oss << "Mismatch length of during assignment : " << nbc << " != " << daIntTyyppV->getNumberOfCompo() << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + for(int j=0;j& info) throw(INTERP_KERNEL::Exception); + int intValue() const throw(INTERP_KERNEL::Exception); + int getHashCode() const throw(INTERP_KERNEL::Exception); + bool empty() const throw(INTERP_KERNEL::Exception); + DataArrayInt *deepCpy() const throw(INTERP_KERNEL::Exception); + DataArrayInt *performCpy(bool deepCpy) const throw(INTERP_KERNEL::Exception); + void cpyFrom(const DataArrayInt& other) throw(INTERP_KERNEL::Exception); + void reserve(std::size_t nbOfElems) throw(INTERP_KERNEL::Exception); + void pushBackSilent(int val) throw(INTERP_KERNEL::Exception); + int popBackSilent() throw(INTERP_KERNEL::Exception); + void pack() const throw(INTERP_KERNEL::Exception); + void alloc(int nbOfTuple, int nbOfCompo=1) throw(INTERP_KERNEL::Exception); + void allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); + bool isEqual(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception); + bool isEqualWithoutConsideringStr(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception); + bool isEqualWithoutConsideringStrAndOrder(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception); + DataArrayInt *buildPermutationArr(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception); + void sort(bool asc=true) throw(INTERP_KERNEL::Exception); + void reverse() throw(INTERP_KERNEL::Exception); + void checkMonotonic(bool increasing) const throw(INTERP_KERNEL::Exception); + bool isMonotonic(bool increasing) const throw(INTERP_KERNEL::Exception); + void checkStrictlyMonotonic(bool increasing) const throw(INTERP_KERNEL::Exception); + bool isStrictlyMonotonic(bool increasing) const throw(INTERP_KERNEL::Exception); + void fillWithZero() throw(INTERP_KERNEL::Exception); + void fillWithValue(int val) throw(INTERP_KERNEL::Exception); + void iota(int init=0) throw(INTERP_KERNEL::Exception); + std::string repr() const throw(INTERP_KERNEL::Exception); + std::string reprZip() const throw(INTERP_KERNEL::Exception); + DataArrayInt *invertArrayO2N2N2O(int newNbOfElem) const; + DataArrayInt *invertArrayN2O2O2N(int oldNbOfElem) const; + DataArrayInt *invertArrayO2N2N2OBis(int newNbOfElem) const throw(INTERP_KERNEL::Exception); + void reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception); + DataArrayDouble *convertToDblArr() const; + DataArrayInt *fromNoInterlace() const throw(INTERP_KERNEL::Exception); + DataArrayInt *toNoInterlace() const throw(INTERP_KERNEL::Exception); + DataArrayInt *selectByTupleId2(int bg, int end, int step) const throw(INTERP_KERNEL::Exception); + DataArrayInt *checkAndPreparePermutation() const throw(INTERP_KERNEL::Exception); + DataArrayInt *buildPermArrPerLevel() const throw(INTERP_KERNEL::Exception); + bool isIdentity() const throw(INTERP_KERNEL::Exception); + bool isUniform(int val) const throw(INTERP_KERNEL::Exception); + DataArrayInt *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); + void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception); + void transpose() throw(INTERP_KERNEL::Exception); + DataArrayInt *changeNbOfComponents(int newNbOfComp, int dftValue) const throw(INTERP_KERNEL::Exception); + void meldWith(const DataArrayInt *other) throw(INTERP_KERNEL::Exception); + void setPartOfValues1(const DataArrayInt *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true) throw(INTERP_KERNEL::Exception); + void setPartOfValuesSimple1(int a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception); + void setPartOfValuesAdv(const DataArrayInt *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception); + void setContigPartOfSelectedValues(int tupleIdStart, const DataArrayInt*a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception); + void setContigPartOfSelectedValues2(int tupleIdStart, const DataArrayInt *a, int bg, int end2, int step) throw(INTERP_KERNEL::Exception); + void getTuple(int tupleId, int *res) const throw(INTERP_KERNEL::Exception); + int getIJ(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception); + int getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception); + int back() const throw(INTERP_KERNEL::Exception); + void setIJ(int tupleId, int compoId, int newVal) throw(INTERP_KERNEL::Exception); + void setIJSilent(int tupleId, int compoId, int newVal) throw(INTERP_KERNEL::Exception); + int *getPointer() throw(INTERP_KERNEL::Exception); + const int *getConstPointer() const throw(INTERP_KERNEL::Exception); + DataArrayIntIterator *iterator() throw(INTERP_KERNEL::Exception); + const int *begin() const throw(INTERP_KERNEL::Exception); + const int *end() const throw(INTERP_KERNEL::Exception); + DataArrayInt *getIdsEqual(int val) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getIdsNotEqual(int val) const throw(INTERP_KERNEL::Exception); + int changeValue(int oldValue, int newValue) throw(INTERP_KERNEL::Exception); + int locateTuple(const std::vector& tupl) const throw(INTERP_KERNEL::Exception); + int locateValue(int value) const throw(INTERP_KERNEL::Exception); + int locateValue(const std::vector& vals) const throw(INTERP_KERNEL::Exception); + int search(const std::vector& vals) const throw(INTERP_KERNEL::Exception); + bool presenceOfTuple(const std::vector& tupl) const throw(INTERP_KERNEL::Exception); + bool presenceOfValue(int value) const throw(INTERP_KERNEL::Exception); + bool presenceOfValue(const std::vector& vals) const throw(INTERP_KERNEL::Exception); + void accumulate(int *res) const throw(INTERP_KERNEL::Exception); + int accumulate(int compId) const throw(INTERP_KERNEL::Exception); + int getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception); + int getMaxValueInArray() const throw(INTERP_KERNEL::Exception); + int getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception); + int getMinValueInArray() const throw(INTERP_KERNEL::Exception); + void abs() throw(INTERP_KERNEL::Exception); + void applyLin(int a, int b, int compoId) throw(INTERP_KERNEL::Exception); + void applyLin(int a, int b) throw(INTERP_KERNEL::Exception); + void applyInv(int numerator) throw(INTERP_KERNEL::Exception); + DataArrayInt *negate() const throw(INTERP_KERNEL::Exception); + void applyDivideBy(int val) throw(INTERP_KERNEL::Exception); + void applyModulus(int val) throw(INTERP_KERNEL::Exception); + void applyRModulus(int val) throw(INTERP_KERNEL::Exception); + void applyPow(int val) throw(INTERP_KERNEL::Exception); + void applyRPow(int val) throw(INTERP_KERNEL::Exception); + DataArrayInt *getIdsInRange(int vmin, int vmax) const throw(INTERP_KERNEL::Exception); + static DataArrayInt *Aggregate(const DataArrayInt *a1, const DataArrayInt *a2, int offsetA2); + static DataArrayInt *Aggregate(const std::vector& arr) throw(INTERP_KERNEL::Exception); + static DataArrayInt *Meld(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception); + static DataArrayInt *Meld(const std::vector& arr) throw(INTERP_KERNEL::Exception); + static DataArrayInt *MakePartition(const std::vector& groups, int newNb, std::vector< std::vector >& fidsOfGroups) throw(INTERP_KERNEL::Exception); + static DataArrayInt *BuildUnion(const std::vector& arr) throw(INTERP_KERNEL::Exception); + static DataArrayInt *BuildIntersection(const std::vector& arr) throw(INTERP_KERNEL::Exception); + DataArrayInt *buildComplement(int nbOfElement) const throw(INTERP_KERNEL::Exception); + DataArrayInt *buildSubstraction(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); + DataArrayInt *buildSubstractionOptimized(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); + DataArrayInt *buildUnion(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); + DataArrayInt *buildIntersection(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); + DataArrayInt *buildUnique() const throw(INTERP_KERNEL::Exception); + DataArrayInt *deltaShiftIndex() const throw(INTERP_KERNEL::Exception); + void computeOffsets() throw(INTERP_KERNEL::Exception); + void computeOffsets2() throw(INTERP_KERNEL::Exception); + DataArrayInt *buildExplicitArrByRanges(const DataArrayInt *offsets) const throw(INTERP_KERNEL::Exception); + DataArrayInt *findRangeIdForEachTuple(const DataArrayInt *ranges) const throw(INTERP_KERNEL::Exception); + DataArrayInt *findIdInRangeForEachTuple(const DataArrayInt *ranges) const throw(INTERP_KERNEL::Exception); + DataArrayInt *duplicateEachTupleNTimes(int nbTimes) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getDifferentValues() const throw(INTERP_KERNEL::Exception); + static DataArrayInt *Add(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception); + void addEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception); + static DataArrayInt *Substract(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception); + void substractEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception); + static DataArrayInt *Multiply(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception); + void multiplyEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception); + static DataArrayInt *Divide(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception); + void divideEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception); + static DataArrayInt *Modulus(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception); + void modulusEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception); + static DataArrayInt *Pow(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception); + void powEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception); + public: + static int *CheckAndPreparePermutation(const int *start, const int *end); + static DataArrayInt *Range(int begin, int end, int step) throw(INTERP_KERNEL::Exception); + %extend + { + DataArrayInt() throw(INTERP_KERNEL::Exception) + { + return DataArrayInt::New(); + } + + static DataArrayInt *New(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) + { + const char *msg="ParaMEDMEM::DataArrayInt::New : Available API are : \n-DataArrayInt.New()\n-DataArrayInt.New([1,3,4])\n-DataArrayInt.New([1,3,4],3)\n-DataArrayInt.New([1,3,4,5],2,2)\n-DataArrayInt.New([1,3,4,5,7,8],3,2)\n-DataArrayInt.New(5)\n-DataArrayInt.New(5,2) !"; + if(PyList_Check(elt0) || PyTuple_Check(elt0)) + { + if(nbOfTuples) + { + if(PyInt_Check(nbOfTuples)) + { + int nbOfTuples1=PyInt_AS_LONG(nbOfTuples); + if(nbOfTuples1<0) + throw INTERP_KERNEL::Exception("DataArrayInt::New : should be a positive set of allocated memory !"); + if(nbOfComp) + { + if(PyInt_Check(nbOfComp)) + {//DataArrayInt.New([1,3,4,5],2,2) + int nbOfCompo=PyInt_AS_LONG(nbOfComp); + if(nbOfCompo<0) + throw INTERP_KERNEL::Exception("DataArrayInt::New : should be a positive number of components !"); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); + std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,nbOfCompo); + ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + return ret.retn(); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {//DataArrayInt.New([1,3,4],3) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); + int tmpp1=-1; + std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,tmpp1); + ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + return ret.retn(); + } + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {// DataArrayInt.New([1,3,4]) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); + int tmpp1=-1,tmpp2=-1; + std::vector tmp=fillArrayWithPyListInt2(elt0,tmpp1,tmpp2); + ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + return ret.retn(); + } + } + else if(PyInt_Check(elt0)) + { + int nbOfTuples1=PyInt_AS_LONG(elt0); + if(nbOfTuples1<0) + throw INTERP_KERNEL::Exception("DataArrayInt::New : should be a positive set of allocated memory !"); + if(nbOfTuples) + { + if(!nbOfComp) + { + if(PyInt_Check(nbOfTuples)) + {//DataArrayInt.New(5,2) + int nbOfCompo=PyInt_AS_LONG(nbOfTuples); + if(nbOfCompo<0) + throw INTERP_KERNEL::Exception("DataArrayInt::New : should be a positive number of components !"); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); + ret->alloc(nbOfTuples1,nbOfCompo); + return ret.retn(); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {//DataArrayInt.New(5) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); + ret->alloc(nbOfTuples1,1); + return ret.retn(); + } + } + else + throw INTERP_KERNEL::Exception(msg); + } + + DataArrayInt(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) + { + return ParaMEDMEM_DataArrayInt_New__SWIG_1(elt0,nbOfTuples,nbOfComp); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->repr(); + } + + int __len__() const throw(INTERP_KERNEL::Exception) + { + if(self->isAllocated()) + { + return self->getNumberOfTuples(); + } + else + { + throw INTERP_KERNEL::Exception("DataArrayInt::__len__ : Instance is NOT allocated !"); + } + } + + int __int__() const throw(INTERP_KERNEL::Exception) + { + return self->intValue(); + } + + DataArrayIntIterator *__iter__() + { + return self->iterator(); + } + + PyObject *accumulate() const throw(INTERP_KERNEL::Exception) + { + int sz=self->getNumberOfComponents(); + INTERP_KERNEL::AutoPtr tmp=new int[sz]; + self->accumulate(tmp); + return convertIntArrToPyList(tmp,sz); + } + + static PyObject *BuildOld2NewArrayFromSurjectiveFormat2(int nbOfOldTuples, PyObject *arr, PyObject *arrI) throw(INTERP_KERNEL::Exception) + { + int newNbOfTuples=-1; + int szArr,szArrI,sw,iTypppArr,iTypppArrI; + std::vector stdvecTyyppArr,stdvecTyyppArrI; + const int *arrPtr=convertObjToPossibleCpp1_Safe(arr,sw,szArr,iTypppArr,stdvecTyyppArr); + const int *arrIPtr=convertObjToPossibleCpp1_Safe(arrI,sw,szArrI,iTypppArrI,stdvecTyyppArrI); + DataArrayInt *ret0=ParaMEDMEM::DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(nbOfOldTuples,arrPtr,arrIPtr,arrIPtr+szArrI,newNbOfTuples); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj((void*)ret0,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,SWIG_POINTER_OWN | 0)); + PyTuple_SetItem(ret,1,PyInt_FromLong(newNbOfTuples)); + return ret; + } + + void setValues(PyObject *li, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) + { + const char *msg="ParaMEDMEM::DataArrayInt::setValues : Available API are : \n-DataArrayInt.setValues([1,3,4])\n-DataArrayInt.setValues([1,3,4],3)\n-DataArrayInt.setValues([1,3,4,5],2,2)\n-DataArrayInt.New(5)\n !"; + if(PyList_Check(li) || PyTuple_Check(li)) + { + if(nbOfTuples) + { + if(PyInt_Check(nbOfTuples)) + { + int nbOfTuples1=PyInt_AS_LONG(nbOfTuples); + if(nbOfTuples<0) + throw INTERP_KERNEL::Exception("DataArrayInt::setValue : should be a positive set of allocated memory !"); + if(nbOfComp) + { + if(PyInt_Check(nbOfComp)) + {//DataArrayInt.setValues([1,3,4,5],2,2) + int nbOfCompo=PyInt_AS_LONG(nbOfComp); + if(nbOfCompo<0) + throw INTERP_KERNEL::Exception("DataArrayInt::setValue : should be a positive number of components !"); + std::vector tmp=fillArrayWithPyListInt2(li,nbOfTuples1,nbOfCompo); + self->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),self->getPointer()); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {//DataArrayInt.setValues([1,3,4],3) + int tmpp1=-1; + std::vector tmp=fillArrayWithPyListInt2(li,nbOfTuples1,tmpp1); + self->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),self->getPointer()); + } + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {// DataArrayInt.setValues([1,3,4]) + int tmpp1=-1,tmpp2=-1; + std::vector tmp=fillArrayWithPyListInt2(li,tmpp1,tmpp2); + self->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),self->getPointer()); + } + } + else + throw INTERP_KERNEL::Exception(msg); + } + + PyObject *getValues() const throw(INTERP_KERNEL::Exception) + { + const int *vals=self->getConstPointer(); + return convertIntArrToPyList(vals,self->getNbOfElems()); + } + + PyObject *isEqualIfNotWhy(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception) + { + std::string ret1; + bool ret0=self->isEqualIfNotWhy(other,ret1); + PyObject *ret=PyTuple_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyTuple_SetItem(ret,0,ret0Py); + PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str())); + return ret; + } + + PyObject *getValuesAsTuple() const throw(INTERP_KERNEL::Exception) + { + const int *vals=self->getConstPointer(); + int nbOfComp=self->getNumberOfComponents(); + int nbOfTuples=self->getNumberOfTuples(); + return convertIntArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); + } + + static PyObject *MakePartition(PyObject *gps, int newNb) throw(INTERP_KERNEL::Exception) + { + std::vector groups; + std::vector< std::vector > fidsOfGroups; + convertFromPyObjVectorOfObj(gps,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,"DataArrayInt",groups); + ParaMEDMEM::DataArrayInt *ret0=ParaMEDMEM::DataArrayInt::MakePartition(groups,newNb,fidsOfGroups); + PyObject *ret = PyList_New(2); + PyList_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + int sz=fidsOfGroups.size(); + PyObject *ret1 = PyList_New(sz); + for(int i=0;i tmp=convertPyToNewIntArr2(li,&size); + self->transformWithIndArr(tmp,tmp+size); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + self->transformWithIndArr(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); + } + } + + DataArrayInt *getIdsEqualList(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + convertObjToPossibleCpp2(obj,self->getNumberOfTuples(),sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + return self->getIdsEqualList(&singleVal,&singleVal+1); + case 2: + return self->getIdsEqualList(&multiVal[0],&multiVal[0]+multiVal.size()); + case 4: + return self->getIdsEqualList(daIntTyypp->begin(),daIntTyypp->end()); + default: + throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqualList : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); + } + } + + DataArrayInt *getIdsNotEqualList(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + convertObjToPossibleCpp2(obj,self->getNumberOfTuples(),sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + return self->getIdsNotEqualList(&singleVal,&singleVal+1); + case 2: + return self->getIdsNotEqualList(&multiVal[0],&multiVal[0]+multiVal.size()); + case 4: + return self->getIdsNotEqualList(daIntTyypp->begin(),daIntTyypp->end()); + default: + throw INTERP_KERNEL::Exception("DataArrayInt::getIdsNotEqualList : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); + } + } + + PyObject *splitByValueRange(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *ret0=0,*ret1=0,*ret2=0; + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + self->splitByValueRange(tmp,(int *)tmp+size,ret0,ret1,ret2); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + self->splitByValueRange(da2->getConstPointer(),da2->getConstPointer()+size,ret0,ret1,ret2); + } + PyObject *ret = PyList_New(3); + PyList_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(ret2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + + DataArrayInt *transformWithIndArrR(PyObject *li) const + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + return self->transformWithIndArrR(tmp,tmp+size); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + return self->transformWithIndArrR(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); + } + } + + void renumberInPlace(PyObject *li) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + self->renumberInPlace(tmp); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + self->renumberInPlace(da2->getConstPointer()); + } + } + + void renumberInPlaceR(PyObject *li) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + self->renumberInPlaceR(tmp); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + self->renumberInPlaceR(da2->getConstPointer()); + } + } + + DataArrayInt *renumberAndReduce(PyObject *li, int newNbOfTuple) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumberAndReduce(tmp,newNbOfTuple); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumberAndReduce(da2->getConstPointer(),newNbOfTuple); + } + } + + DataArrayInt *renumber(PyObject *li) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumber(tmp); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumber(da2->getConstPointer()); + } + } + + DataArrayInt *renumberR(PyObject *li) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumberR(tmp); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumberR(da2->getConstPointer()); + } + } + + DataArrayInt *selectByTupleId(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + return self->selectByTupleId(tmp,tmp+size); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + return self->selectByTupleId(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); + } + } + + DataArrayInt *selectByTupleIdSafe(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + return self->selectByTupleIdSafe(tmp,tmp+size); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + return self->selectByTupleIdSafe(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); + } + } + + DataArrayInt *keepSelectedComponents(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyToNewIntArr3(li,tmp); + return self->keepSelectedComponents(tmp); + } + + void setSelectedComponents(const DataArrayInt *a, PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyToNewIntArr3(li,tmp); + self->setSelectedComponents(a,tmp); + } + + PyObject *getTuple(int tupleId) throw(INTERP_KERNEL::Exception) + { + int sz=self->getNumberOfComponents(); + INTERP_KERNEL::AutoPtr tmp=new int[sz]; + self->getTuple(tupleId,tmp); + return convertIntArrToPyList(tmp,sz); + } + + PyObject *changeSurjectiveFormat(int targetNb) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *arr=0; + DataArrayInt *arrI=0; + self->changeSurjectiveFormat(targetNb,arr,arrI); + PyObject *res = PyList_New(2); + PyList_SetItem(res,0,SWIG_NewPointerObj((void*)arr,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,SWIG_POINTER_OWN | 0)); + PyList_SetItem(res,1,SWIG_NewPointerObj((void*)arrI,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,SWIG_POINTER_OWN | 0)); + return res; + } + + DataArrayInt *selectByTupleRanges(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + std::vector > ranges; + convertPyToVectorPairInt(li,ranges); + return self->selectByTupleRanges(ranges); + } + + static DataArrayInt *Meld(PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,"DataArrayInt",tmp); + return DataArrayInt::Meld(tmp); + } + + static DataArrayInt *Aggregate(PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,"DataArrayInt",tmp); + return DataArrayInt::Aggregate(tmp); + } + + static DataArrayInt *BuildUnion(PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,"DataArrayInt",tmp); + return DataArrayInt::BuildUnion(tmp); + } + + static DataArrayInt *BuildIntersection(PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,"DataArrayInt",tmp); + return DataArrayInt::BuildIntersection(tmp); + } + + PyObject *getMaxValue() const throw(INTERP_KERNEL::Exception) + { + int tmp; + int r1=self->getMaxValue(tmp); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyInt_FromLong(r1)); + PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); + return ret; + } + + PyObject *getMinValue() const throw(INTERP_KERNEL::Exception) + { + int tmp; + int r1=self->getMinValue(tmp); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyInt_FromLong(r1)); + PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); + return ret; + } + + int index(PyObject *obj) const throw(INTERP_KERNEL::Exception) + { + int nbOfCompo=self->getNumberOfComponents(); + switch(nbOfCompo) + { + case 1: + { + if(PyInt_Check(obj)) + { + int val=(int)PyInt_AS_LONG(obj); + return self->locateValue(val); + } + else + throw INTERP_KERNEL::Exception("DataArrayInt::index : 'this' contains one component and trying to find an element which is not an integer !"); + } + default: + { + std::vector arr; + convertPyToNewIntArr3(obj,arr); + return self->locateTuple(arr); + } + } + } + + bool __contains__(PyObject *obj) const throw(INTERP_KERNEL::Exception) + { + int nbOfCompo=self->getNumberOfComponents(); + switch(nbOfCompo) + { + case 0: + return false; + case 1: + { + if(PyInt_Check(obj)) + { + int val=(int)PyInt_AS_LONG(obj); + return self->presenceOfValue(val); + } + else + throw INTERP_KERNEL::Exception("DataArrayInt::__contains__ : 'this' contains one component and trying to find an element which is not an integer !"); + } + default: + { + std::vector arr; + convertPyToNewIntArr3(obj,arr); + return self->presenceOfTuple(arr); + } + } + } + + PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in DataArrayInt::__getitem__ !"; + const char msg2[]="DataArrayInt::__getitem__ : Mismatch of slice values in 2nd parameter (components) !"; + self->checkAllocated(); + int nbOfTuples=self->getNumberOfTuples(); + int nbOfComponents=self->getNumberOfComponents(); + int it1,ic1; + std::vector vt1,vc1; + std::pair > pt1,pc1; + DataArrayInt *dt1=0,*dc1=0; + int sw; + convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1); + MEDCouplingAutoRefCountObjectPtr ret; + switch(sw) + { + case 1: + { + if(nbOfComponents==1) + return PyInt_FromLong(self->getIJSafe(it1,0)); + return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + case 2: + return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + case 3: + return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + case 4: + return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + case 5: + return PyInt_FromLong(self->getIJSafe(it1,ic1)); + case 6: + { + ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size()); + std::vector v2(1,ic1); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + case 7: + { + ret=self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second); + std::vector v2(1,ic1); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + case 8: + { + ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems()); + std::vector v2(1,ic1); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + case 9: + { + ret=self->selectByTupleIdSafe(&it1,&it1+1); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + case 10: + { + ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size()); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + case 11: + { + ret=self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + case 12: + { + ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems()); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + case 13: + { + ret=self->selectByTupleIdSafe(&it1,&it1+1); + int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2); + std::vector v2(nbOfComp); + for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + case 14: + { + ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size()); + int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2); + std::vector v2(nbOfComp); + for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + case 15: + { + ret=self->selectByTupleId2(pt1.first,pt1.second.first,pt1.second.second); + int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2); + std::vector v2(nbOfComp); + for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + case 16: + { + ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems()); + int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2); + std::vector v2(nbOfComp); + for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception) + { + self->checkAllocated(); + const char msg[]="Unexpected situation in __setitem__ !"; + int nbOfTuples=self->getNumberOfTuples(); + int nbOfComponents=self->getNumberOfComponents(); + int sw1,sw2; + int i1; + std::vector v1; + DataArrayInt *d1=0; + DataArrayIntTuple *dd1=0; + convertObjToPossibleCpp1(value,sw1,i1,v1,d1,dd1); + int it1,ic1; + std::vector vt1,vc1; + std::pair > pt1,pc1; + DataArrayInt *dt1=0,*dc1=0; + convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1); + MEDCouplingAutoRefCountObjectPtr tmp; + switch(sw2) + { + case 1: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1); + return self; + case 2: + tmp=DataArrayInt::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false); + return self; + case 3: + self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1); + return self; + case 4: + tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); + self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 2: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1); + return self; + case 2: + tmp=DataArrayInt::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false); + return self; + case 3: + self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1); + return self; + case 4: + tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); + self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 3: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1); + return self; + case 2: + tmp=DataArrayInt::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false); + return self; + case 3: + self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1); + return self; + case 4: + tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); + self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 4: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1); + return self; + case 2: + tmp=DataArrayInt::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false); + return self; + case 3: + self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1); + return self; + case 4: + tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); + self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 5: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1); + return self; + case 2: + tmp=DataArrayInt::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false); + return self; + case 3: + self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1); + return self; + case 4: + tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); + self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 6: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1); + return self; + case 2: + tmp=DataArrayInt::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false); + return self; + case 3: + self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1); + return self; + case 4: + tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); + self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 7: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1); + return self; + case 2: + tmp=DataArrayInt::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false); + return self; + case 3: + self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1); + return self; + case 4: + tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); + self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 8: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1); + return self; + case 2: + tmp=DataArrayInt::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false); + return self; + case 3: + self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1); + return self; + case 4: + tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); + self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 9: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size()); + return self; + case 2: + tmp=DataArrayInt::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false); + return self; + case 3: + self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size()); + return self; + case 4: + tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); + self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size()); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 10: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size()); + return self; + case 2: + tmp=DataArrayInt::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false); + return self; + case 3: + self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size()); + return self; + case 4: + tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); + self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size()); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 11: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size()); + return self; + case 2: + tmp=DataArrayInt::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false); + return self; + case 3: + self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size()); + return self; + case 4: + tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); + self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size()); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 12: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size()); + return self; + case 2: + tmp=DataArrayInt::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false); + return self; + case 3: + self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size()); + return self; + case 4: + tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); + self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size()); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 13: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second); + return self; + case 2: + tmp=DataArrayInt::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false); + return self; + case 3: + self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second); + return self; + case 4: + tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); + self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 14: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second); + return self; + case 2: + tmp=DataArrayInt::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false); + return self; + case 3: + self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second); + return self; + case 4: + tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); + self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 15: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second); + return self; + case 2: + tmp=DataArrayInt::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false); + return self; + case 3: + self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second); + return self; + case 4: + tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); + self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + case 16: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second); + return self; + case 2: + tmp=DataArrayInt::New(); + tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); + self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false); + return self; + case 3: + self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second); + return self; + case 4: + tmp=dd1->buildDAInt(1,self->getNumberOfComponents()); + self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second); + return self; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + return self; + } + + DataArrayInt *__neg__() const throw(INTERP_KERNEL::Exception) + { + return self->negate(); + } + + DataArrayInt *__add__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __add__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyLin(1,val); + return ret.retn(); + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Add(self,aaaa); + } + case 3: + { + return DataArrayInt::Add(self,a); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + return DataArrayInt::Add(self,aaaa); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__radd__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __radd__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyLin(1,val); + return ret.retn(); + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Add(self,aaaa); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + return DataArrayInt::Add(self,aaaa); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __iadd__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + self->applyLin(1,val); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr bb=DataArrayInt::New(); bb->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + self->addEqual(bb); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + self->addEqual(a); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + self->addEqual(aaaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__sub__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __sub__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyLin(1,-val); + return ret.retn(); + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Substract(self,aaaa); + } + case 3: + { + return DataArrayInt::Substract(self,a); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + return DataArrayInt::Substract(self,aaaa); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__rsub__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __rsub__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyLin(-1,val); + return ret.retn(); + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Substract(aaaa,self); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + return DataArrayInt::Substract(aaaa,self); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __isub__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + self->applyLin(1,-val); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr bb=DataArrayInt::New(); bb->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + self->substractEqual(bb); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + self->substractEqual(a); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + self->substractEqual(aaaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__mul__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __mul__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyLin(val,0); + return ret.retn(); + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Multiply(self,aaaa); + } + case 3: + { + return DataArrayInt::Multiply(self,a); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + return DataArrayInt::Multiply(self,aaaa); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__rmul__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __rmul__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyLin(val,0); + return ret.retn(); + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Multiply(self,aaaa); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + return DataArrayInt::Multiply(self,aaaa); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __imul__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + self->applyLin(val,0); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr bb=DataArrayInt::New(); bb->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + self->multiplyEqual(bb); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + self->multiplyEqual(a); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + self->multiplyEqual(aaaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__div__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __div__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyDivideBy(val); + return ret.retn(); + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Divide(self,aaaa); + } + case 3: + { + return DataArrayInt::Divide(self,a); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + return DataArrayInt::Divide(self,aaaa); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__rdiv__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __rdiv__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyInv(val); + return ret.retn(); + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Divide(aaaa,self); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + return DataArrayInt::Divide(aaaa,self); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __idiv__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + self->applyDivideBy(val); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr bb=DataArrayInt::New(); bb->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + self->divideEqual(bb); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + self->divideEqual(a); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + self->divideEqual(aaaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__mod__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __mod__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyModulus(val); + return ret.retn(); + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Modulus(self,aaaa); + } + case 3: + { + return DataArrayInt::Modulus(self,a); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + return DataArrayInt::Modulus(self,aaaa); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__rmod__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __rmod__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyRModulus(val); + return ret.retn(); + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Modulus(aaaa,self); + } + case 3: + { + return DataArrayInt::Modulus(a,self); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + return DataArrayInt::Modulus(aaaa,self); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + PyObject *___imod___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __imod__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + self->applyModulus(val); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + self->modulusEqual(a); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + self->modulusEqual(aaaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__pow__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __pow__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyPow(val); + return ret.retn(); + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Pow(self,aaaa); + } + case 3: + { + return DataArrayInt::Pow(self,a); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + return DataArrayInt::Pow(self,aaaa); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__rpow__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __rpow__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyRPow(val); + return ret.retn(); + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Pow(aaaa,self); + } + case 3: + { + return DataArrayInt::Pow(a,self); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + return DataArrayInt::Pow(aaaa,self); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + PyObject *___ipow___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __ipow__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + self->applyPow(val); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + self->powEqual(a); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + self->powEqual(aaaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + std::string __repr__() const throw(INTERP_KERNEL::Exception) + { + std::ostringstream oss; + self->reprQuickOverview(oss); + return oss.str(); + } + + void pushBackValsSilent(PyObject *li) throw(INTERP_KERNEL::Exception) + { + int szArr,sw,iTypppArr; + std::vector stdvecTyyppArr; + const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); + self->pushBackValsSilent(tmp,tmp+szArr); + } + + PyObject *partitionByDifferentValues() const throw(INTERP_KERNEL::Exception) + { + std::vector ret1; + std::vector ret0=self->partitionByDifferentValues(ret1); + std::size_t sz=ret0.size(); + PyObject *pyRet=PyTuple_New(2); + PyObject *pyRet0=PyList_New((int)sz); + PyObject *pyRet1=PyList_New((int)sz); + for(std::size_t i=0;isearchRangesInListOfIds(listOfIds,ret0,ret1); + PyObject *pyRet=PyTuple_New(2); + PyTuple_SetItem(pyRet,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(pyRet,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return pyRet; + } + } + }; + + class DataArrayIntTuple; + + class DataArrayIntIterator + { + public: + DataArrayIntIterator(DataArrayInt *da); + ~DataArrayIntIterator(); + %extend + { + PyObject *next() + { + DataArrayIntTuple *ret=self->nextt(); + if(ret) + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,SWIG_POINTER_OWN | 0); + else + { + PyErr_SetString(PyExc_StopIteration,"No more data."); + return 0; + } + } + } + }; + + class DataArrayIntTuple + { + public: + int getNumberOfCompo() const; + DataArrayInt *buildDAInt(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception); + %extend + { + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->repr(); + } + + int __int__() const throw(INTERP_KERNEL::Exception) + { + return self->intValue(); + } + + DataArrayInt *buildDAInt() throw(INTERP_KERNEL::Exception) + { + return self->buildDAInt(1,self->getNumberOfCompo()); + } + + PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + MEDCouplingAutoRefCountObjectPtr ret=self->buildDAInt(1,self->getNumberOfCompo()); + ParaMEDMEM_DataArrayInt____iadd___(ret,0,obj); + Py_XINCREF(trueSelf); + return trueSelf; + } + + PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + MEDCouplingAutoRefCountObjectPtr ret=self->buildDAInt(1,self->getNumberOfCompo()); + ParaMEDMEM_DataArrayInt____isub___(ret,0,obj); + Py_XINCREF(trueSelf); + return trueSelf; + } + + PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + MEDCouplingAutoRefCountObjectPtr ret=self->buildDAInt(1,self->getNumberOfCompo()); + ParaMEDMEM_DataArrayInt____imul___(ret,0,obj); + Py_XINCREF(trueSelf); + return trueSelf; + } + + PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + MEDCouplingAutoRefCountObjectPtr ret=self->buildDAInt(1,self->getNumberOfCompo()); + ParaMEDMEM_DataArrayInt____idiv___(ret,0,obj); + Py_XINCREF(trueSelf); + return trueSelf; + } + + PyObject *___imod___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + MEDCouplingAutoRefCountObjectPtr ret=self->buildDAInt(1,self->getNumberOfCompo()); + ParaMEDMEM_DataArrayInt____imod___(ret,0,obj); + Py_XINCREF(trueSelf); + return trueSelf; + } + + PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg2[]="DataArrayIntTuple::__getitem__ : Mismatch of slice values in 2nd parameter (components) !"; + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + const int *pt=self->getConstPointer(); + int nbc=self->getNumberOfCompo(); + convertObjToPossibleCpp2(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + { + if(singleVal>=nbc) + { + std::ostringstream oss; + oss << "Requesting for id " << singleVal << " having only " << nbc << " components !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(singleVal>=0) + return PyInt_FromLong(pt[singleVal]); + else + { + if(nbc+singleVal>0) + return PyInt_FromLong(pt[nbc+singleVal]); + else + { + std::ostringstream oss; + oss << "Requesting for id " << singleVal << " having only " << nbc << " components !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + } + case 2: + { + PyObject *t=PyTuple_New(multiVal.size()); + for(int j=0;j<(int)multiVal.size();j++) + { + int cid=multiVal[j]; + if(cid>=nbc) + { + std::ostringstream oss; + oss << "Requesting for id #" << cid << " having only " << nbc << " components !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + PyTuple_SetItem(t,j,PyInt_FromLong(pt[cid])); + } + return t; + } + case 3: + { + int sz=DataArray::GetNumberOfItemGivenBES(slic.first,slic.second.first,slic.second.second,msg2); + PyObject *t=PyTuple_New(sz); + for(int j=0;j multiValV; + std::pair > slicV; + ParaMEDMEM::DataArrayIntTuple *daIntTyyppV=0; + int nbc=self->getNumberOfCompo(); + convertObjToPossibleCpp22(value,nbc,sw1,singleValV,multiValV,slicV,daIntTyyppV); + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + int *pt=self->getPointer(); + convertObjToPossibleCpp2(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp); + switch(sw2) + { + case 1: + { + if(singleVal>=nbc) + { + std::ostringstream oss; + oss << "Requesting for setting id # " << singleVal << " having only " << nbc << " components !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + switch(sw1) + { + case 1: + { + pt[singleVal]=singleValV; + return self; + } + case 2: + { + if(multiValV.size()!=1) + { + std::ostringstream oss; + oss << "Requesting for setting id # " << singleVal << " with a list or tuple with size != 1 ! "; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + pt[singleVal]=multiValV[0]; + return self; + } + case 4: + { + pt[singleVal]=daIntTyyppV->getConstPointer()[0]; + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + case 2: + { + switch(sw1) + { + case 1: + { + for(std::vector::const_iterator it=multiVal.begin();it!=multiVal.end();it++) + { + if(*it>=nbc) + { + std::ostringstream oss; + oss << "Requesting for setting id # " << *it << " having only " << nbc << " components !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + pt[*it]=singleValV; + } + return self; + } + case 2: + { + if(multiVal.size()!=multiValV.size()) + { + std::ostringstream oss; + oss << "Mismatch length of during assignment : " << multiValV.size() << " != " << multiVal.size() << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + for(int i=0;i<(int)multiVal.size();i++) + { + int pos=multiVal[i]; + if(pos>=nbc) + { + std::ostringstream oss; + oss << "Requesting for setting id # " << pos << " having only " << nbc << " components !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + pt[multiVal[i]]=multiValV[i]; + } + return self; + } + case 4: + { + const int *ptV=daIntTyyppV->getConstPointer(); + if(nbc>daIntTyyppV->getNumberOfCompo()) + { + std::ostringstream oss; + oss << "Mismatch length of during assignment : " << nbc << " != " << daIntTyyppV->getNumberOfCompo() << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + std::copy(ptV,ptV+nbc,pt); + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + case 3: + { + int sz=DataArray::GetNumberOfItemGivenBES(slic.first,slic.second.first,slic.second.second,msg2); + switch(sw1) + { + case 1: + { + for(int j=0;jgetConstPointer(); + if(sz>daIntTyyppV->getNumberOfCompo()) + { + std::ostringstream oss; + oss << "Mismatch length of during assignment : " << nbc << " != " << daIntTyyppV->getNumberOfCompo() << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + for(int j=0;j& info) throw(INTERP_KERNEL::Exception); + int getHashCode() const throw(INTERP_KERNEL::Exception); + bool empty() const throw(INTERP_KERNEL::Exception); + void cpyFrom(const DataArrayChar& other) throw(INTERP_KERNEL::Exception); + void reserve(std::size_t nbOfElems) throw(INTERP_KERNEL::Exception); + void pushBackSilent(char val) throw(INTERP_KERNEL::Exception); + void pushBackValsSilent(const char *valsBg, const char *valsEnd) throw(INTERP_KERNEL::Exception); + char popBackSilent() throw(INTERP_KERNEL::Exception); + void pack() const throw(INTERP_KERNEL::Exception); + void alloc(int nbOfTuple, int nbOfCompo=1) throw(INTERP_KERNEL::Exception); + void allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); + bool isEqual(const DataArrayChar& other) const throw(INTERP_KERNEL::Exception); + bool isEqualWithoutConsideringStr(const DataArrayChar& other) const throw(INTERP_KERNEL::Exception); + void reverse() throw(INTERP_KERNEL::Exception); + void fillWithZero() throw(INTERP_KERNEL::Exception); + void fillWithValue(char val) throw(INTERP_KERNEL::Exception); + std::string repr() const throw(INTERP_KERNEL::Exception); + std::string reprZip() const throw(INTERP_KERNEL::Exception); + void reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception); + DataArrayInt *convertToIntArr() const throw(INTERP_KERNEL::Exception); + void renumberInPlace(const int *old2New) throw(INTERP_KERNEL::Exception); + void renumberInPlaceR(const int *new2Old) throw(INTERP_KERNEL::Exception); + DataArrayChar *renumber(const int *old2New) const throw(INTERP_KERNEL::Exception); + DataArrayChar *renumberR(const int *new2Old) const throw(INTERP_KERNEL::Exception); + DataArrayChar *renumberAndReduce(const int *old2NewBg, int newNbOfTuple) const throw(INTERP_KERNEL::Exception); + DataArrayChar *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception); + DataArrayChar *selectByTupleId2(int bg, int end, int step) const throw(INTERP_KERNEL::Exception); + bool isUniform(char val) const throw(INTERP_KERNEL::Exception); + void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception); + DataArrayChar *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); + DataArrayChar *changeNbOfComponents(int newNbOfComp, char dftValue) const throw(INTERP_KERNEL::Exception); + void meldWith(const DataArrayChar *other) throw(INTERP_KERNEL::Exception); + void setPartOfValuesAdv(const DataArrayChar *a, const DataArrayChar *tuplesSelec) throw(INTERP_KERNEL::Exception); + char back() const throw(INTERP_KERNEL::Exception); + void setIJ(int tupleId, int compoId, char newVal); + void setIJSilent(int tupleId, int compoId, char newVal); + char *getPointer(); + DataArrayInt *getIdsEqual(char val) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getIdsNotEqual(char val) const throw(INTERP_KERNEL::Exception); + int locateTuple(const std::vector& tupl) const throw(INTERP_KERNEL::Exception); + bool presenceOfTuple(const std::vector& tupl) const throw(INTERP_KERNEL::Exception); + char getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception); + char getMaxValueInArray() const throw(INTERP_KERNEL::Exception); + char getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception); + char getMinValueInArray() const throw(INTERP_KERNEL::Exception); + DataArrayInt *getIdsInRange(char vmin, char vmax) const throw(INTERP_KERNEL::Exception); + static DataArrayChar *Aggregate(const DataArrayChar *a1, const DataArrayChar *a2); + static DataArrayChar *Aggregate(const std::vector& arr) throw(INTERP_KERNEL::Exception); + static DataArrayChar *Meld(const DataArrayChar *a1, const DataArrayChar *a2) throw(INTERP_KERNEL::Exception); + static DataArrayChar *Meld(const std::vector& arr) throw(INTERP_KERNEL::Exception); + %extend + { + int __len__() const throw(INTERP_KERNEL::Exception) + { + if(self->isAllocated()) + { + return self->getNumberOfTuples(); + } + else + { + throw INTERP_KERNEL::Exception("DataArrayChar::__len__ : Instance is NOT allocated !"); + } + } + + PyObject *isEqualIfNotWhy(const DataArrayChar& other) const throw(INTERP_KERNEL::Exception) + { + std::string ret1; + bool ret0=self->isEqualIfNotWhy(other,ret1); + PyObject *ret=PyTuple_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyTuple_SetItem(ret,0,ret0Py); + PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str())); + return ret; + } + + void renumberInPlace(PyObject *li) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + self->renumberInPlace(tmp); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + self->renumberInPlace(da2->getConstPointer()); + } + } + + void renumberInPlaceR(PyObject *li) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + self->renumberInPlaceR(tmp); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + self->renumberInPlaceR(da2->getConstPointer()); + } + } + + DataArrayChar *renumber(PyObject *li) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumber(tmp); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumber(da2->getConstPointer()); + } + } + + DataArrayChar *renumberR(PyObject *li) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumberR(tmp); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumberR(da2->getConstPointer()); + } + } + + DataArrayChar *renumberAndReduce(PyObject *li, int newNbOfTuple) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumberAndReduce(tmp,newNbOfTuple); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumberAndReduce(da2->getConstPointer(),newNbOfTuple); + } + } + + DataArrayChar *selectByTupleIdSafe(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + return self->selectByTupleIdSafe(tmp,tmp+size); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + return self->selectByTupleIdSafe(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); + } + } + + DataArrayChar *keepSelectedComponents(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyToNewIntArr3(li,tmp); + return self->keepSelectedComponents(tmp); + } + + static DataArrayChar *Aggregate(PyObject *dachs) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertFromPyObjVectorOfObj(dachs,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,"DataArrayChar",tmp); + return DataArrayChar::Aggregate(tmp); + } + + static DataArrayChar *Meld(PyObject *dachs) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertFromPyObjVectorOfObj(dachs,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,"DataArrayChar",tmp); + return DataArrayChar::Meld(tmp); + } + } + }; + + class DataArrayByteIterator; + + class DataArrayByte : public DataArrayChar + { + public: + static DataArrayByte *New(); + DataArrayChar *buildEmptySpecializedDAChar() const throw(INTERP_KERNEL::Exception); + DataArrayByteIterator *iterator(); + DataArrayByte *deepCpy() const; + DataArrayByte *performCpy(bool deepCpy) const; + char byteValue() const throw(INTERP_KERNEL::Exception); + %extend + { + DataArrayByte() throw(INTERP_KERNEL::Exception) + { + return DataArrayByte::New(); + } + + static DataArrayByte *New(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) + { + const char *msg="ParaMEDMEM::DataArrayByte::New : Available API are : \n-DataArrayByte.New()\n--DataArrayByte.New([1,3,4])\n-DataArrayByte.New([1,3,4],3)\n-DataArrayByte.New([1,3,4,5],2,2)\n-DataArrayByte.New(5)\n-DataArrayByte.New(5,2) !"; + if(PyList_Check(elt0) || PyTuple_Check(elt0)) + { + if(nbOfTuples) + { + if(PyInt_Check(nbOfTuples)) + { + int nbOfTuples1=PyInt_AS_LONG(nbOfTuples); + if(nbOfTuples1<0) + throw INTERP_KERNEL::Exception("DataArrayByte::New : should be a positive set of allocated memory !"); + if(nbOfComp) + { + if(PyInt_Check(nbOfComp)) + {//DataArrayByte.New([1,3,4,5],2,2) + int nbOfCompo=PyInt_AS_LONG(nbOfComp); + if(nbOfCompo<0) + throw INTERP_KERNEL::Exception("DataArrayByte::New : should be a positive number of components !"); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayByte::New(); + std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,nbOfCompo); + ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + return ret.retn(); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {//DataArrayByte.New([1,3,4],3) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayByte::New(); + int tmpp1=-1; + std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,tmpp1); + ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + return ret.retn(); + } + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {// DataArrayByte.New([1,3,4]) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayByte::New(); + int tmpp1=-1,tmpp2=-1; + std::vector tmp=fillArrayWithPyListInt2(elt0,tmpp1,tmpp2); + ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + return ret.retn(); + } + } + else if(PyInt_Check(elt0)) + { + int nbOfTuples1=PyInt_AS_LONG(elt0); + if(nbOfTuples1<0) + throw INTERP_KERNEL::Exception("DataArrayByte::New : should be a positive set of allocated memory !"); + if(nbOfTuples) + { + if(!nbOfComp) + { + if(PyInt_Check(nbOfTuples)) + {//DataArrayByte.New(5,2) + int nbOfCompo=PyInt_AS_LONG(nbOfTuples); + if(nbOfCompo<0) + throw INTERP_KERNEL::Exception("DataArrayByte::New : should be a positive number of components !"); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayByte::New(); + ret->alloc(nbOfTuples1,nbOfCompo); + return ret.retn(); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {//DataArrayByte.New(5) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayByte::New(); + ret->alloc(nbOfTuples1,1); + return ret.retn(); + } + } + else + throw INTERP_KERNEL::Exception(msg); + } + + DataArrayByte(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) + { + return ParaMEDMEM_DataArrayByte_New__SWIG_1(elt0,nbOfTuples,nbOfComp); + } + + std::string __repr__() const throw(INTERP_KERNEL::Exception) + { + std::ostringstream oss; + self->reprQuickOverview(oss); + return oss.str(); + } + + int __int__() const throw(INTERP_KERNEL::Exception) + { + return (int) self->byteValue(); + } + + DataArrayByteIterator *__iter__() throw(INTERP_KERNEL::Exception) + { + return self->iterator(); + } + + int getIJ(int tupleId, int compoId) const + { + return (int)self->getIJ(tupleId,compoId); + } + + int getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception) + { + return (int)self->getIJSafe(tupleId,compoId); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->repr(); + } + + PyObject *toStrList() const throw(INTERP_KERNEL::Exception) + { + const char *vals=self->getConstPointer(); + int nbOfComp=self->getNumberOfComponents(); + int nbOfTuples=self->getNumberOfTuples(); + return convertCharArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); + } + + bool presenceOfTuple(PyObject *tupl) const throw(INTERP_KERNEL::Exception) + { + int sz=-1,sw=-1; + int ival=-1; std::vector ivval; + const int *pt=convertObjToPossibleCpp1_Safe(tupl,sw,sz,ival,ivval); + std::vector vals(sz); + std::copy(pt,pt+sz,vals.begin()); + return self->presenceOfTuple(vals); + } + + bool presenceOfValue(PyObject *vals) const throw(INTERP_KERNEL::Exception) + { + int sz=-1,sw=-1; + int ival=-1; std::vector ivval; + const int *pt=convertObjToPossibleCpp1_Safe(vals,sw,sz,ival,ivval); + std::vector vals2(sz); + std::copy(pt,pt+sz,vals2.begin()); + return self->presenceOfValue(vals2); + } + + int locateValue(PyObject *vals) const throw(INTERP_KERNEL::Exception) + { + int sz=-1,sw=-1; + int ival=-1; std::vector ivval; + const int *pt=convertObjToPossibleCpp1_Safe(vals,sw,sz,ival,ivval); + std::vector vals2(sz); + std::copy(pt,pt+sz,vals2.begin()); + return self->locateValue(vals2); + } + + int locateTuple(PyObject *tupl) const throw(INTERP_KERNEL::Exception) + { + int sz=-1,sw=-1; + int ival=-1; std::vector ivval; + const int *pt=convertObjToPossibleCpp1_Safe(tupl,sw,sz,ival,ivval); + std::vector vals(sz); + std::copy(pt,pt+sz,vals.begin()); + return self->locateTuple(vals); + } + + int search(PyObject *strOrListOfInt) const throw(INTERP_KERNEL::Exception) + { + int sz=-1,sw=-1; + int ival=-1; std::vector ivval; + const int *pt=convertObjToPossibleCpp1_Safe(strOrListOfInt,sw,sz,ival,ivval); + std::vector vals(sz); + std::copy(pt,pt+sz,vals.begin()); + return self->search(vals); + } + + PyObject *getTuple(int tupleId) throw(INTERP_KERNEL::Exception) + { + int sz=self->getNumberOfComponents(); + INTERP_KERNEL::AutoPtr tmp=new char[sz]; + self->getTuple(tupleId,tmp); + PyObject *ret=PyTuple_New(sz); + for(int i=0;igetMaxValue(tmp); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyInt_FromLong(r1)); + PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); + return ret; + } + + PyObject *getMinValue() const throw(INTERP_KERNEL::Exception) + { + int tmp; + int r1=(int)self->getMinValue(tmp); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyInt_FromLong(r1)); + PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); + return ret; + } + + int index(PyObject *obj) const throw(INTERP_KERNEL::Exception) + { + int nbOfCompo=self->getNumberOfComponents(); + switch(nbOfCompo) + { + case 1: + { + if(PyInt_Check(obj)) + { + int val=(int)PyInt_AS_LONG(obj); + return self->locateValue(val); + } + else + throw INTERP_KERNEL::Exception("DataArrayByte::index : 'this' contains one component and trying to find an element which is not an integer !"); + } + default: + return ParaMEDMEM_DataArrayByte_locateTuple(self,obj); + } + } + + bool __contains__(PyObject *obj) const throw(INTERP_KERNEL::Exception) + { + int nbOfCompo=self->getNumberOfComponents(); + switch(nbOfCompo) + { + case 0: + return false; + case 1: + { + if(PyInt_Check(obj)) + { + int val=(int)PyInt_AS_LONG(obj); + return self->presenceOfValue(val); + } + else + throw INTERP_KERNEL::Exception("DataArrayByte::__contains__ : 'this' contains one component and trying to find an element which is not an integer !"); + } + default: + return ParaMEDMEM_DataArrayByte_presenceOfTuple(self,obj); + } + } + } + }; + + class DataArrayByteTuple; + + class DataArrayByteIterator + { + public: + DataArrayByteIterator(DataArrayByte *da); + ~DataArrayByteIterator(); + }; + + class DataArrayByteTuple + { + public: + std::string repr() const throw(INTERP_KERNEL::Exception); + DataArrayByte *buildDAByte(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception); + %extend + { + std::string __str__() const + { + return self->repr(); + } + + char __int__() const throw(INTERP_KERNEL::Exception) + { + return self->byteValue(); + } + + DataArrayByte *buildDAByte() + { + return self->buildDAByte(1,self->getNumberOfCompo()); + } + } + }; + + class DataArrayAsciiCharIterator; + + class DataArrayAsciiChar : public DataArrayChar + { + public: + static DataArrayAsciiChar *New(); + DataArrayChar *buildEmptySpecializedDAChar() const throw(INTERP_KERNEL::Exception); + DataArrayAsciiCharIterator *iterator(); + DataArrayAsciiChar *deepCpy() const; + DataArrayAsciiChar *performCpy(bool deepCpy) const; + char asciiCharValue() const throw(INTERP_KERNEL::Exception); + %extend + { + DataArrayAsciiChar() throw(INTERP_KERNEL::Exception) + { + return DataArrayAsciiChar::New(); + } + + static DataArrayAsciiChar *New(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) + { + const char *msg="ParaMEDMEM::DataArrayAsciiChar::New : Available API are : \n-DataArrayAsciiChar.New()\n-DataArrayAsciiChar.New([1,3,4])\n-DataArrayAsciiChar.New([\"abc\",\"de\",\"fghi\"])\n-DataArrayAsciiChar.New([\"abc\",\"de\",\"fghi\"],\"t\")\n-DataArrayAsciiChar.New([1,3,4],3)\n-DataArrayAsciiChar.New([1,3,4,5],2,2)\n-DataArrayAsciiChar.New(5)\n-DataArrayAsciiChar.New(5,2) !"; + if(PyList_Check(elt0) || PyTuple_Check(elt0)) + { + if(nbOfTuples) + { + if(PyInt_Check(nbOfTuples)) + { + int nbOfTuples1=PyInt_AS_LONG(nbOfTuples); + if(nbOfTuples1<0) + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::New : should be a positive set of allocated memory !"); + if(nbOfComp) + { + if(PyInt_Check(nbOfComp)) + {//DataArrayAsciiChar.New([1,3,4,5],2,2) + int nbOfCompo=PyInt_AS_LONG(nbOfComp); + if(nbOfCompo<0) + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::New : should be a positive number of components !"); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); + std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,nbOfCompo); + ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + return ret.retn(); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {//DataArrayAsciiChar.New([1,3,4],3) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); + int tmpp1=-1; + std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,tmpp1); + ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + return ret.retn(); + } + } + else if(PyString_Check(nbOfTuples)) + { + if(PyString_Size(nbOfTuples)!=1) + throw INTERP_KERNEL::Exception(msg); + //DataArrayAsciiChar.New(["abc","de","fghi"],"t") + std::vector tmp; + if(fillStringVector(elt0,tmp)) + return DataArrayAsciiChar::New(tmp,PyString_AsString(nbOfTuples)[0]); + else + throw INTERP_KERNEL::Exception(msg); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + { + std::vector tmmp; + if(fillStringVector(elt0,tmmp)) + //DataArrayAsciiChar.New(["abc","de","fghi"]) + return DataArrayAsciiChar::New(tmmp,' '); + else + { + // DataArrayAsciiChar.New([1,3,4]) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); + int tmpp1=-1,tmpp2=-1; + std::vector tmp=fillArrayWithPyListInt2(elt0,tmpp1,tmpp2); + ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + return ret.retn(); + } + } + } + else if(PyInt_Check(elt0)) + { + int nbOfTuples1=PyInt_AS_LONG(elt0); + if(nbOfTuples1<0) + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::New : should be a positive set of allocated memory !"); + if(nbOfTuples) + { + if(!nbOfComp) + { + if(PyInt_Check(nbOfTuples)) + {//DataArrayAsciiChar.New(5,2) + int nbOfCompo=PyInt_AS_LONG(nbOfTuples); + if(nbOfCompo<0) + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::New : should be a positive number of components !"); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); + ret->alloc(nbOfTuples1,nbOfCompo); + return ret.retn(); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {//DataArrayAsciiChar.New(5) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); + ret->alloc(nbOfTuples1,1); + return ret.retn(); + } + } + else + throw INTERP_KERNEL::Exception(msg); + } + + DataArrayAsciiChar(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) + { + return ParaMEDMEM_DataArrayAsciiChar_New__SWIG_1(elt0,nbOfTuples,nbOfComp); + } + + std::string __repr__() const throw(INTERP_KERNEL::Exception) + { + std::ostringstream oss; + self->reprQuickOverview(oss); + return oss.str(); + } + + DataArrayAsciiCharIterator *__iter__() throw(INTERP_KERNEL::Exception) + { + return self->iterator(); + } + + std::string getIJ(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception) + { + char tmp[2]; tmp[1]='\0'; + tmp[0]=self->getIJ(tupleId,compoId); + return std::string(tmp); + } + + std::string getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception) + { + char tmp[2]; tmp[1]='\0'; + tmp[0]=self->getIJSafe(tupleId,compoId); + return std::string(tmp); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->repr(); + } + + PyObject *toStrList() const throw(INTERP_KERNEL::Exception) + { + const char *vals=self->getConstPointer(); + int nbOfComp=self->getNumberOfComponents(); + int nbOfTuples=self->getNumberOfTuples(); + return convertCharArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); + } + + bool presenceOfTuple(PyObject *tupl) const throw(INTERP_KERNEL::Exception) + { + if(PyString_Check(tupl)) + { + Py_ssize_t sz=PyString_Size(tupl); + std::vector vals(sz); + std::copy(PyString_AsString(tupl),PyString_AsString(tupl)+sz,vals.begin()); + return self->presenceOfTuple(vals); + } + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::presenceOfTuple : only strings in input supported !"); + } + + bool presenceOfValue(PyObject *vals) const throw(INTERP_KERNEL::Exception) + { + if(PyString_Check(vals)) + { + Py_ssize_t sz=PyString_Size(vals); + std::vector vals2(sz); + std::copy(PyString_AsString(vals),PyString_AsString(vals)+sz,vals2.begin()); + return self->presenceOfValue(vals2); + } + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::presenceOfValue : only strings in input supported !"); + } + + int locateValue(PyObject *vals) const throw(INTERP_KERNEL::Exception) + { + if(PyString_Check(vals)) + { + Py_ssize_t sz=PyString_Size(vals); + std::vector vals2(sz); + std::copy(PyString_AsString(vals),PyString_AsString(vals)+sz,vals2.begin()); + return self->locateValue(vals2); + } + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::locateValue : only strings in input supported !"); + } + + int locateTuple(PyObject *tupl) const throw(INTERP_KERNEL::Exception) + { + if(PyString_Check(tupl)) + { + Py_ssize_t sz=PyString_Size(tupl); + std::vector vals(sz); + std::copy(PyString_AsString(tupl),PyString_AsString(tupl)+sz,vals.begin()); + return self->locateTuple(vals); + } + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::locateTuple : only strings in input supported !"); + } + + int search(PyObject *strOrListOfInt) const throw(INTERP_KERNEL::Exception) + { + if(PyString_Check(strOrListOfInt)) + { + Py_ssize_t sz=PyString_Size(strOrListOfInt); + std::vector vals(sz); + std::copy(PyString_AsString(strOrListOfInt),PyString_AsString(strOrListOfInt)+sz,vals.begin()); + return self->search(vals); + } + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::search : only strings in input supported !"); + } + + PyObject *getTuple(int tupleId) const throw(INTERP_KERNEL::Exception) + { + int sz=self->getNumberOfComponents(); + INTERP_KERNEL::AutoPtr tmp=new char[sz+1]; tmp[sz]='\0'; + self->getTuple(tupleId,tmp); + return PyString_FromString(tmp); + } + + PyObject *getMaxValue() const throw(INTERP_KERNEL::Exception) + { + int tmp; + char tmp2[2]; tmp2[1]='\0'; + tmp2[0]=self->getMaxValue(tmp); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyString_FromString(tmp2)); + PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); + return ret; + } + + PyObject *getMinValue() const throw(INTERP_KERNEL::Exception) + { + int tmp; + char tmp2[2]; tmp2[1]='\0'; + tmp2[0]=self->getMinValue(tmp); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyString_FromString(tmp2)); + PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); + return ret; + } + + int index(PyObject *obj) const throw(INTERP_KERNEL::Exception) + { + int nbOfCompo=self->getNumberOfComponents(); + switch(nbOfCompo) + { + case 1: + { + if(PyString_Check(obj)) + { + Py_ssize_t sz=PyString_Size(obj); + char *pt=PyString_AsString(obj); + if(sz==1) + return self->locateValue(pt[0]); + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::index : 'this' contains one component and trying to find a string with size different from 1 !"); + } + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::index : 'this' contains one component and trying to find an element which is not an integer !"); + } + default: + return ParaMEDMEM_DataArrayAsciiChar_locateTuple(self,obj); + } + } + + bool __contains__(PyObject *obj) const throw(INTERP_KERNEL::Exception) + { + int nbOfCompo=self->getNumberOfComponents(); + switch(nbOfCompo) + { + case 0: + return false; + case 1: + { + if(PyString_Check(obj)) + { + Py_ssize_t sz=PyString_Size(obj); + char *pt=PyString_AsString(obj); + if(sz==1) + return self->presenceOfValue(pt[0]); + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::__contains__ : 'this' contains one component and trying to find a string with size different from 1 !"); + } + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::__contains__ : 'this' contains one component and trying to find an element which is not an integer !"); + } + default: + return ParaMEDMEM_DataArrayAsciiChar_presenceOfTuple(self,obj); + } + } + + PyObject *__getitem__(PyObject *obj) const throw(INTERP_KERNEL::Exception) + { + int sw,iTypppArr; + std::vector stdvecTyyppArr; + std::pair > sTyyppArr; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + convertObjToPossibleCpp2(obj,self->getNumberOfTuples(),sw,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp); + switch(sw) + { + case 1: + return ParaMEDMEM_DataArrayAsciiChar_getTuple(self,iTypppArr); + case 2: + return convertDataArrayChar(self->selectByTupleIdSafe(&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size()), SWIG_POINTER_OWN | 0 ); + case 3: + return convertDataArrayChar(self->selectByTupleId2(sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second), SWIG_POINTER_OWN | 0 ); + case 4: + return convertDataArrayChar(self->selectByTupleIdSafe(daIntTyypp->begin(),daIntTyypp->end()), SWIG_POINTER_OWN | 0 ); + default: + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::__getitem__ : supporting int, list of int, tuple of int, DataArrayInt and slice in input !"); + } + } + + DataArrayAsciiChar *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception) + { + static const char msg[]="DataArrayAsciiChar::__setitem__ : supporting int, list of int, tuple of int, DataArrayInt and slice in input, and 4 types accepted in value : string, list or tuple of strings having same size, not null DataArrayChar instance."; + int sw1,iTypppArr; + std::vector stdvecTyyppArr; + std::pair > sTyyppArr; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + int nbOfCompo=self->getNumberOfComponents(); + int nbOfTuples=self->getNumberOfTuples(); + convertObjToPossibleCpp2(obj,nbOfTuples,sw1,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp); + int sw2; + char vc; std::string sc; std::vector vsc; DataArrayChar *dacc=0; + convertObjToPossibleCpp6(value,sw2,vc,sc,vsc,dacc); + switch(sw1) + { + case 1: + {//obj int + switch(sw2) + {//value char + case 1: + { + self->setPartOfValuesSimple3(vc,&iTypppArr,&iTypppArr+1,0,nbOfCompo,1); + return self; + } + //value string + case 2: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(sc); + self->setPartOfValues3(tmp,&iTypppArr,&iTypppArr+1,0,nbOfCompo,1,false); + return self; + } + //value vector + case 3: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(vsc,' '); + self->setPartOfValues3(tmp,&iTypppArr,&iTypppArr+1,0,nbOfCompo,1,false); + return self; + } + //value DataArrayChar + case 4: + { + self->setPartOfValues3(dacc,&iTypppArr,&iTypppArr+1,0,nbOfCompo,1,false); + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + case 2: + {//obj list-tuple[int] + switch(sw2) + { + {//value char + case 1: + { + self->setPartOfValuesSimple3(vc,&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size(),0,nbOfCompo,1); + return self; + } + //value string + case 2: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(sc); + self->setPartOfValues3(tmp,&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size(),0,nbOfCompo,1,false); + return self; + } + //value vector + case 3: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(vsc,' '); + self->setPartOfValues3(tmp,&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size(),0,nbOfCompo,1,false); + return self; + } + //value DataArrayChar + case 4: + { + self->setPartOfValues3(dacc,&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size(),0,nbOfCompo,1,false); + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + } + case 3: + {//slice + switch(sw2) + { + {//value char + case 1: + { + self->setPartOfValuesSimple1(vc,sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second,0,nbOfCompo,1); + return self; + } + //value string + case 2: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(sc); + self->setPartOfValues1(tmp,sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second,0,nbOfCompo,1,false); + return self; + } + //value vector + case 3: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(vsc,' '); + self->setPartOfValues1(tmp,sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second,0,nbOfCompo,1,false); + return self; + } + //value DataArrayChar + case 4: + { + self->setPartOfValues1(dacc,sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second,0,nbOfCompo,1,false); + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + } + case 4: + {//DataArrayInt + switch(sw2) + { + {//value char + case 1: + { + self->setPartOfValuesSimple3(vc,daIntTyypp->begin(),daIntTyypp->end(),0,nbOfCompo,1); + return self; + } + //value string + case 2: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(sc); + self->setPartOfValues3(tmp,daIntTyypp->begin(),daIntTyypp->end(),0,nbOfCompo,1,false); + return self; + } + //value vector + case 3: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(vsc,' '); + self->setPartOfValues3(tmp,daIntTyypp->begin(),daIntTyypp->end(),0,nbOfCompo,1,false); + return self; + } + //value DataArrayChar + case 4: + { + self->setPartOfValues3(dacc,daIntTyypp->begin(),daIntTyypp->end(),0,nbOfCompo,1,false); + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + } + }; + + class DataArrayAsciiCharTuple; + + class DataArrayAsciiCharIterator + { + public: + DataArrayAsciiCharIterator(DataArrayAsciiChar *da); + ~DataArrayAsciiCharIterator(); + %extend + { + PyObject *next() + { + DataArrayAsciiCharTuple *ret=self->nextt(); + if(ret) + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiCharTuple,SWIG_POINTER_OWN | 0); + else + { + PyErr_SetString(PyExc_StopIteration,"No more data."); + return 0; + } + } + } + }; + + class DataArrayAsciiCharTuple + { + public: + int getNumberOfCompo() const; + DataArrayAsciiChar *buildDAAsciiChar(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception); + %extend + { + std::string __str__() const + { + return self->repr(); + } + + DataArrayAsciiChar *buildDAAsciiChar() + { + return self->buildDAAsciiChar(1,self->getNumberOfCompo()); + } + } + }; +} diff --git a/src/MEDCoupling_Swig/MEDCouplingRemapper.i b/src/MEDCoupling_Swig/MEDCouplingRemapper.i index 77c762e85..cfb1129e1 100644 --- a/src/MEDCoupling_Swig/MEDCouplingRemapper.i +++ b/src/MEDCoupling_Swig/MEDCouplingRemapper.i @@ -122,6 +122,9 @@ def ParaMEDMEMMEDCouplingFieldDoubleImul(self,*args): def ParaMEDMEMMEDCouplingFieldDoubleIdiv(self,*args): import _MEDCouplingRemapper return _MEDCouplingRemapper.MEDCouplingFieldDouble____idiv___(self, self, *args) +def ParaMEDMEMMEDCouplingFieldDoubleIpow(self,*args): + import _MEDCouplingRemapper + return _MEDCouplingRemapper.MEDCouplingFieldDouble____ipow___(self, self, *args) def ParaMEDMEMDataArrayIntIadd(self,*args): import _MEDCouplingRemapper return _MEDCouplingRemapper.DataArrayInt____iadd___(self, self, *args) diff --git a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i index c13cffe2d..fbbf34ea6 100644 --- a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i @@ -1423,7 +1423,7 @@ static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, dou f=ret; return &f[0]; } - catch(INTERP_KERNEL::Exception& e) { throw e; } + catch(INTERP_KERNEL::Exception& exc) { throw exc; } } void *argp; int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0); @@ -1839,3 +1839,281 @@ static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& s } throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple"); } + +static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) +{ + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__add__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__add__ : self field has no Array of values set !"; + void *argp; + // + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + return (*self)+(*other); + else + throw INTERP_KERNEL::Exception(msg); + } + // + double val; + ParaMEDMEM::DataArrayDouble *a; + ParaMEDMEM::DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); + ret->applyLin(1.,val); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 2: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),a); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 3: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 4: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } +} + +static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___radd__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) +{ + return ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(self,obj); +} + +static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rsub__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) +{ + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__rsub__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__rsub__ : self field has no Array of values set !"; + void *argp; + // + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + return (*other)-(*self); + else + throw INTERP_KERNEL::Exception(msg); + } + // + double val; + ParaMEDMEM::DataArrayDouble *a; + ParaMEDMEM::DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); + ret->applyLin(-1.,val); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 2: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Substract(a,self->getArray()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 3: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 4: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } +} + +static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) +{ + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__mul__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__mul__ : self field has no Array of values set !"; + void *argp; + // + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + return (*self)*(*other); + else + throw INTERP_KERNEL::Exception(msg); + } + // + double val; + ParaMEDMEM::DataArrayDouble *a; + ParaMEDMEM::DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); + ret->applyLin(val,0.); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 2: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),a); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 3: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 4: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } +} + +ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rmul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) +{ + return ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(self,obj); +} + +ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) +{ + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__rdiv__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__div__ : self field has no Array of values set !"; + void *argp; + // + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + return (*other)/(*self); + else + throw INTERP_KERNEL::Exception(msg); + } + // + double val; + ParaMEDMEM::DataArrayDouble *a; + ParaMEDMEM::DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); + ret->applyInv(val); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 2: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Divide(a,self->getArray()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 3: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 4: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } +} diff --git a/src/MEDCoupling_Swig/Makefile.am b/src/MEDCoupling_Swig/Makefile.am index c8b0dfcce..52150f59e 100644 --- a/src/MEDCoupling_Swig/Makefile.am +++ b/src/MEDCoupling_Swig/Makefile.am @@ -24,13 +24,13 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am lib_LTLIBRARIES = _MEDCoupling.la _MEDCouplingRemapper.la salomeinclude_HEADERS = \ - MEDCoupling.i MEDCouplingRemapper.i MEDCouplingTypemaps.i MEDCouplingCommon.i MEDCouplingFinalize.i + MEDCoupling.i MEDCouplingRemapper.i MEDCouplingTypemaps.i MEDCouplingCommon.i MEDCouplingFinalize.i MEDCouplingMemArray.i BUILT_SOURCES = MEDCouplingWRAP.cxx MEDCouplingRemapperWRAP.cxx SWIG_FLAGS = @SWIG_FLAGS@ -I$(srcdir) -I$(srcdir)/../MEDCoupling -I$(srcdir)/../INTERP_KERNEL/Bases -I$(srcdir)/../INTERP_KERNEL -dist__MEDCoupling_la_SOURCES = MEDCoupling.i MEDCouplingTypemaps.i MEDCouplingCommon.i MEDCouplingFinalize.i +dist__MEDCoupling_la_SOURCES = MEDCoupling.i MEDCouplingTypemaps.i MEDCouplingCommon.i MEDCouplingFinalize.i MEDCouplingMemArray.i nodist__MEDCoupling_la_SOURCES = MEDCouplingWRAP.cxx MEDCoupling.py: MEDCouplingWRAP.cxx diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 91d0b6275..fce2b6b6c 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -1063,6 +1063,8 @@ std::vector MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const M if(!disc2) throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !"); const DataArrayInt *da=disc2->getArrayOfDiscIds(); + if(!da) + throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss (no profile) : no localization ids per cell array available ! The input Gauss node field is maybe invalid !"); MEDCouplingAutoRefCountObjectPtr da2=da->selectByTupleId2(offset,offset+nbOfCells,1); MEDCouplingAutoRefCountObjectPtr retTmp=da2->getDifferentValues(); if(retTmp->presenceOfValue(-1)) @@ -1133,6 +1135,8 @@ std::vector MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const M if(!disc2) throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !"); const DataArrayInt *da=disc2->getArrayOfDiscIds(); + if(!da) + throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : no localization ids per cell array available ! The input Gauss node field is maybe invalid !"); MEDCouplingAutoRefCountObjectPtr da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples()); MEDCouplingAutoRefCountObjectPtr retTmp=da2->getDifferentValues(); if(retTmp->presenceOfValue(-1)) diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 8626120f3..6c583f5c4 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -2073,7 +2073,10 @@ DataArrayInt *MEDFileUMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::ve } /*! - * Returns a pointer to mesh at the specified level. + * Returns a pointer to mesh at the specified level. ** WARNING **, if the input \a meshDimRelToMaxExt is set to one (nodes), + * The returned mesh ** will be not valid **. It is a feature, because MEDLoader do not creates cells that do not exist ! + * To build a valid MEDCouplingUMesh instance from the returned value when \a meshDimRelToMaxExt is equal to one, simply + * call MEDCouplingUMesh::Build0DMeshFromCoords. * * \return a pointer to unstructured mesh that need to be managed by the caller. * \warning the returned pointer has to be managed by the caller. diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index 0550b850c..5af7ca0c0 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -304,7 +304,7 @@ std::vector MEDLoaderNS::getMeshNamesFid(med_idt fid) void MEDLoaderNS::fillGaussDataOnField(const char *fileName, const std::list& data, MEDCouplingFieldDouble *f) { - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); char locName[MED_NAME_SIZE+1]; int nloc=MEDnLocalization(fid); med_geometry_type typeGeo; @@ -341,7 +341,6 @@ void MEDLoaderNS::fillGaussDataOnField(const char *fileName, const std::list MEDLoader::GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); std::vector ret=MEDLoaderNS::getMeshNamesFid(fid); - MEDfileClose(fid); return ret; } @@ -467,7 +465,7 @@ std::vector MEDLoader::GetMeshNamesOnField(const char *fileName, co CheckFileForRead(fileName); std::vector ret; // - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); med_int nbFields=MEDnField(fid); // med_field_type typcha; @@ -488,14 +486,13 @@ std::vector MEDLoader::GetMeshNamesOnField(const char *fileName, co if(curFieldName==fieldName) ret.push_back(meshName); } - MEDfileClose(fid); return ret; } std::vector MEDLoader::GetMeshFamiliesNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); med_int nfam=MEDnFamily(fid,meshName); std::vector ret(nfam); char nomfam[MED_NAME_SIZE+1]; @@ -512,7 +509,6 @@ std::vector MEDLoader::GetMeshFamiliesNames(const char *fileName, c std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam)); ret[i]=cur; } - MEDfileClose(fid); return ret; } @@ -520,7 +516,7 @@ std::vector MEDLoader::GetMeshFamiliesNames(const char *fileName, c std::vector MEDLoader::GetMeshFamiliesNamesOnGroup(const char *fileName, const char *meshName, const char *grpName) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); med_int nfam=MEDnFamily(fid,meshName); std::vector ret; char nomfam[MED_NAME_SIZE+1]; @@ -542,14 +538,13 @@ std::vector MEDLoader::GetMeshFamiliesNamesOnGroup(const char *file ret.push_back(cur); } } - MEDfileClose(fid); return ret; } std::vector MEDLoader::GetMeshGroupsNamesOnFamily(const char *fileName, const char *meshName, const char *famName) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); med_int nfam=MEDnFamily(fid,meshName); std::vector ret; char nomfam[MED_NAME_SIZE+1]; @@ -573,7 +568,6 @@ std::vector MEDLoader::GetMeshGroupsNamesOnFamily(const char *fileN ret.push_back(cur2); } } - MEDfileClose(fid); if(!found) { std::ostringstream oss; @@ -587,7 +581,7 @@ std::vector MEDLoader::GetMeshGroupsNamesOnFamily(const char *fileN std::vector MEDLoader::GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); med_int nfam=MEDnFamily(fid,meshName); std::vector ret; char nomfam[MED_NAME_SIZE+1]; @@ -608,14 +602,13 @@ std::vector MEDLoader::GetMeshGroupsNames(const char *fileName, con ret.push_back(cur); } } - MEDfileClose(fid); return ret; } std::vector MEDLoader::GetTypesOfField(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); std::vector ret; - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); med_int nbFields=MEDnField(fid); // med_field_type typcha; @@ -678,7 +671,6 @@ std::vector MEDLoader::GetTypesOfField(const char *file } delete [] maa_ass; delete [] nomcha; - MEDfileClose(fid); return ret; } @@ -686,7 +678,7 @@ std::vector MEDLoader::GetAllFieldNames(const char *fileName) throw { CheckFileForRead(fileName); std::vector ret; - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); med_int nbFields=MEDnField(fid); med_field_type typcha; for(int i=0;i MEDLoader::GetAllFieldNames(const char *fileName) throw MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt); ret.push_back(std::string(nomcha)); } - MEDfileClose(fid); return ret; } @@ -710,7 +701,7 @@ std::vector MEDLoader::GetAllFieldNamesOnMesh(const char *fileName, { CheckFileForRead(fileName); std::vector ret; - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); med_int nbFields=MEDnField(fid); // med_field_type typcha; @@ -734,7 +725,6 @@ std::vector MEDLoader::GetAllFieldNamesOnMesh(const char *fileName, } delete [] maa_ass; delete [] nomcha; - MEDfileClose(fid); return ret; } @@ -756,7 +746,7 @@ std::vector MEDLoader::GetCellFieldNamesOnMesh(const char *fileName { CheckFileForRead(fileName); std::vector ret; - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); med_int nbFields=MEDnField(fid); // med_field_type typcha; @@ -799,7 +789,6 @@ std::vector MEDLoader::GetCellFieldNamesOnMesh(const char *fileName } } } - MEDfileClose(fid); return ret; } @@ -807,7 +796,7 @@ std::vector MEDLoader::GetNodeFieldNamesOnMesh(const char *fileName { CheckFileForRead(fileName); std::vector ret; - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); med_int nbFields=MEDnField(fid); char pflname[MED_NAME_SIZE+1]=""; char locname[MED_NAME_SIZE+1]=""; @@ -841,16 +830,14 @@ std::vector MEDLoader::GetNodeFieldNamesOnMesh(const char *fileName } } } - MEDfileClose(fid); return ret; } -std::vector< std::pair< std::pair, double> > MEDLoader::GetAllFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception) +std::vector< std::pair< std::pair, double> > MEDLoader::GetAllFieldIterations(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); - std::string meshNameCpp(meshName); std::vector< std::pair< std::pair, double > > ret; - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); med_int nbFields=MEDnField(fid); // med_field_type typcha; @@ -861,6 +848,7 @@ std::vector< std::pair< std::pair, double> > MEDLoader::GetAllFieldIter INTERP_KERNEL::AutoPtr nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); med_bool localmesh; // + std::ostringstream oss; oss << "MEDLoader::GetAllFieldIterations : No field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : "; for(int i=0;i, double> > MEDLoader::GetAllFieldIter MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt); ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt)); } + return ret; + } + else + { + oss << "\"" << curFieldName << "\""; + if(i!=nbFields-1) oss << ", "; } } - MEDfileClose(fid); - return ret; + oss << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); } double MEDLoader::GetTimeAttachedOnFieldIteration(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception) { CheckFileForRead(fileName); - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); med_int nbFields=MEDnField(fid); // med_field_type typcha; @@ -921,7 +915,6 @@ double MEDLoader::GetTimeAttachedOnFieldIteration(const char *fileName, const ch } } } - MEDfileClose(fid); if(!found || !found2) { std::ostringstream oss; @@ -950,7 +943,7 @@ std::vector< std::pair > MEDLoader::GetCellFieldIterations(const char * CheckFileForRead(fileName); std::string meshNameCpp(meshName); std::vector< std::pair > ret; - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); med_int nbFields=MEDnField(fid); // med_field_type typcha; @@ -963,6 +956,8 @@ std::vector< std::pair > MEDLoader::GetCellFieldIterations(const char * INTERP_KERNEL::AutoPtr nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); med_bool localmesh; // + std::ostringstream oss; oss << "MEDLoader::GetCellFieldIterations : No cell Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : "; + std::set s2; for(int i=0;i > MEDLoader::GetCellFieldIterations(const char * med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE, pflname,&profilesize,locname,&nbi); std::string maa_ass_cpp(maa_ass); - if(meshNameCpp==maa_ass_cpp && nbOfVal>0) + if(nbOfVal>0) { - found=true; - ret.push_back(std::make_pair(numdt,numo)); + if(meshNameCpp==maa_ass_cpp) + { + found=true; + ret.push_back(std::make_pair(numdt,numo)); + } + else + s2.insert(maa_ass_cpp); } } } } + else + { + oss << "\"" << curFieldName << "\""; + if(i!=nbFields-1) oss << ", "; + } + } + if(ret.empty()) + { + if(!s2.empty()) + { + oss << ". Cell Field \"" << fieldName << "\" exists but lies on meshes with names : \""; + std::copy(s2.begin(),s2.end(),std::ostream_iterator(oss,"\", \"")); + } + oss << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); } - MEDfileClose(fid); return ret; } @@ -1001,7 +1015,7 @@ std::vector< std::pair > MEDLoader::GetNodeFieldIterations(const char * CheckFileForRead(fileName); std::string meshNameCpp(meshName); std::vector< std::pair > ret; - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); med_int nbFields=MEDnField(fid); // med_field_type typcha; @@ -1014,6 +1028,8 @@ std::vector< std::pair > MEDLoader::GetNodeFieldIterations(const char * INTERP_KERNEL::AutoPtr nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); med_bool localmesh; // + std::ostringstream oss; oss << "MEDLoader::GetNodeFieldIterations : No node Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : "; + std::set s2; for(int i=0;i > MEDLoader::GetNodeFieldIterations(const char * med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE, pflname,&profilesize,locname,&nbi); std::string maa_ass_cpp(maa_ass); - if(meshNameCpp==maa_ass_cpp && nbOfVal>0) + if(nbOfVal>0) { - ret.push_back(std::make_pair(numdt,numo)); + if(meshNameCpp==maa_ass_cpp) + { ret.push_back(std::make_pair(numdt,numo)); } + else + s2.insert(maa_ass_cpp); } } } + else + { + oss << "\"" << curFieldName << "\""; + if(i!=nbFields-1) oss << ", "; + } + } + if(ret.empty()) + { + if(!s2.empty()) + { + oss << ". Node Field \"" << fieldName << "\" exists but lies on meshes with names : \""; + std::copy(s2.begin(),s2.end(),std::ostream_iterator(oss,"\", \"")); + } + oss << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); } - MEDfileClose(fid); return ret; } @@ -1158,7 +1191,7 @@ void MEDLoaderNS::readFieldDoubleDataInMedFile(const char *fileName, const char std::vector MEDLoaderNS::getIdsFromFamilies(const char *fileName, const char *meshName, const std::vector& fams) { std::vector ret; - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); med_int nfam=MEDnFamily(fid,meshName); char nomfam[MED_NAME_SIZE+1]; med_int numfam; @@ -1175,14 +1208,13 @@ std::vector MEDLoaderNS::getIdsFromFamilies(const char *fileName, const cha if(std::find(fams.begin(),fams.end(),cur)!=fams.end()) ret.push_back(numfam); } - MEDfileClose(fid); return ret; } std::vector MEDLoaderNS::getIdsFromGroups(const char *fileName, const char *meshName, const std::vector& grps) { std::vector ret; - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); med_int nfam=MEDnFamily(fid,meshName); char nomfam[MED_NAME_SIZE+1]; med_int numfam; @@ -1206,7 +1238,6 @@ std::vector MEDLoaderNS::getIdsFromGroups(const char *fileName, const char } } } - MEDfileClose(fid); return ret; } @@ -1261,7 +1292,7 @@ void MEDLoaderNS::dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfEle int MEDLoaderNS::readUMeshDimFromFile(const char *fileName, const char *meshName, std::vector& possibilities) { possibilities.clear(); - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); int ret; std::set poss; char nommaa[MED_NAME_SIZE+1]; @@ -1303,7 +1334,6 @@ int MEDLoaderNS::readUMeshDimFromFile(const char *fileName, const char *meshName poss.insert(curDim); } } - MEDfileClose(fid); if(!poss.empty()) { ret=*poss.rbegin(); @@ -1850,7 +1880,7 @@ MEDCouplingUMesh *MEDLoaderNS::readUMeshFromFileLev1(const char *fileName, const if(meshDimRelToMax>0) throw INTERP_KERNEL::Exception("meshDimRelToMax must be <=0 !"); //Extraction data from MED file. - med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); std::string trueMeshName; med_int mid=getIdFromMeshName(fid,meshName,trueMeshName); DataArrayDouble *coords=0; @@ -1861,7 +1891,6 @@ MEDCouplingUMesh *MEDLoaderNS::readUMeshFromFileLev1(const char *fileName, const meshDimExtract=meshDimExtract+meshDimRelToMax; MEDLoaderNS::keepSpecifiedMeshDim(conn,meshDimExtract); MEDLoaderNS::keepTypes(conn,typesToKeep); - MEDfileClose(fid); //Put data in returned data structure. MEDCouplingUMesh *ret=MEDCouplingUMesh::New(); ret->setName(trueMeshName.c_str()); @@ -2221,13 +2250,10 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGaussNE(const char *file */ void MEDLoaderNS::writeUMeshesDirectly(const char *fileName, const std::vector& mesh, const std::vector& families, bool forceFromScratch, bool &isRenumbering) { - med_idt fid=MEDfileOpen(fileName,forceFromScratch?MED_ACC_CREAT:MED_ACC_RDWR); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,forceFromScratch?MED_ACC_CREAT:MED_ACC_RDWR); std::string meshName(mesh[0]->getName()); if(meshName=="") - { - MEDfileClose(fid); - throw INTERP_KERNEL::Exception("MEDCouplingMesh must have a not null name !"); - } + throw INTERP_KERNEL::Exception("MEDCouplingMesh must have a not null name !"); isRenumbering=false; bool isFamilies=true; std::vector conn; @@ -2300,7 +2326,6 @@ void MEDLoaderNS::writeUMeshesDirectly(const char *fileName, const std::vectorgetNumberOfNodes(),arr->getConstPointer()); - MEDfileClose(fid); } /*! @@ -2342,7 +2367,7 @@ void MEDLoaderNS::writeUMeshesPartitionDirectly(const char *fileName, const char gidsOfFamilies[fid].push_back(gid); } fid=0; - med_idt fid2=MEDfileOpen(fileName,MED_ACC_RDWR); + MEDFileUtilities::AutoFid fid2=MEDfileOpen(fileName,MED_ACC_RDWR); for(std::set::const_iterator it=familyIds.begin();it!=familyIds.end();it++,fid++) { int ngro=gidsOfFamilies[fid].size(); @@ -2354,7 +2379,6 @@ void MEDLoaderNS::writeUMeshesPartitionDirectly(const char *fileName, const char MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,famName,MEDLoader::_TOO_LONG_STR); MEDfamilyCr(fid2,maa,famName,*it,ngro,groName); } - MEDfileClose(fid2); } /*! @@ -2367,7 +2391,7 @@ void MEDLoaderNS::appendNodeProfileField(const char *fileName, const ParaMEDMEM: med_float dt; INTERP_KERNEL::AutoPtr nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR); - med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt); + MEDFileUtilities::AutoFid fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt); int nbOfNodes=f->getMesh()->getNumberOfNodes(); const double *pt=f->getArray()->getConstPointer(); INTERP_KERNEL::AutoPtr profile=new int[nbOfNodes]; @@ -2377,7 +2401,6 @@ void MEDLoaderNS::appendNodeProfileField(const char *fileName, const ParaMEDMEM: std::transform(thisMeshNodeIds,thisMeshNodeIds+nbOfNodes,(int *)profile,std::bind2nd(std::plus(),1)); MEDprofileWr(fid,profileName,nbOfNodes,profile); MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_NODE,MED_NONE,MED_COMPACT_PFLMODE,profileName,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfNodes,(const unsigned char*)pt); - MEDfileClose(fid); } /*! @@ -2389,7 +2412,7 @@ void MEDLoaderNS::appendCellProfileField(const char *fileName, const ParaMEDMEM: med_int numdt,numo; med_float dt; int nbComp=f->getNumberOfComponents(); - med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt); + MEDFileUtilities::AutoFid fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt); std::list split; prepareCellFieldDoubleForWriting(f,thisMeshCellIdsPerType,split); const double *pt=f->getArray()->getConstPointer(); @@ -2409,7 +2432,6 @@ void MEDLoaderNS::appendCellProfileField(const char *fileName, const ParaMEDMEM: MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,(*iter).getNbOfTuple(),(const unsigned char*)pt); pt+=(*iter).getNbOfTuple()*nbComp; } - MEDfileClose(fid); } void MEDLoaderNS::appendNodeElementProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshCellIdsPerType) @@ -2417,7 +2439,7 @@ void MEDLoaderNS::appendNodeElementProfileField(const char *fileName, const Para med_int numdt,numo; med_float dt; int nbComp=f->getNumberOfComponents(); - med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt); + MEDFileUtilities::AutoFid fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt); std::list split; prepareCellFieldDoubleForWriting(f,thisMeshCellIdsPerType,split); const double *pt=f->getArray()->getConstPointer(); @@ -2442,7 +2464,6 @@ void MEDLoaderNS::appendNodeElementProfileField(const char *fileName, const Para nbOfEntity,(const unsigned char*)pt); pt+=nbOfValues*nbComp; } - MEDfileClose(fid); } /*! @@ -2507,7 +2528,7 @@ void MEDLoaderNS::appendFieldDirectly(const char *fileName, const ParaMEDMEM::ME } //end renumbering int nbComp=f->getNumberOfComponents(); - med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt); + MEDFileUtilities::AutoFid fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt); const double *pt=f->getArray()->getConstPointer(); INTERP_KERNEL::AutoPtr nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR); @@ -2624,7 +2645,6 @@ void MEDLoaderNS::appendFieldDirectly(const char *fileName, const ParaMEDMEM::ME default: throw INTERP_KERNEL::Exception("Not managed this type of FIELD !"); } - MEDfileClose(fid); if(renum) f->decrRef(); } diff --git a/src/MEDLoader/MEDLoader.hxx b/src/MEDLoader/MEDLoader.hxx index c81434af3..dcd3c0e61 100644 --- a/src/MEDLoader/MEDLoader.hxx +++ b/src/MEDLoader/MEDLoader.hxx @@ -107,7 +107,7 @@ class MEDLOADER_EXPORT MEDLoader static std::vector< std::pair > GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception); static std::vector< std::pair > GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception); static std::vector< std::pair > GetNodeFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception); - static std::vector< std::pair< std::pair, double> > GetAllFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception); + static std::vector< std::pair< std::pair, double> > GetAllFieldIterations(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception); static double GetTimeAttachedOnFieldIteration(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& fams) throw(INTERP_KERNEL::Exception); static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector& grps) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/SauvMedConvertor.cxx b/src/MEDLoader/SauvMedConvertor.cxx index 1ce5d818c..f4af715ff 100644 --- a/src/MEDLoader/SauvMedConvertor.cxx +++ b/src/MEDLoader/SauvMedConvertor.cxx @@ -1577,9 +1577,16 @@ void IntermediateMED::orientFaces3D() if ( lfIt2 != linkFacesMap.end() ) { list & ff = lfIt2->second; - ff.erase( find( ff.begin(), ff.end(), badFace )); - if ( ff.empty() ) - linkFacesMap.erase( lfIt2 ); + list::iterator lfIt3 = find( ff.begin(), ff.end(), badFace ); + // check if badFace has been found, + // else we can't erase it + // case of degenerated face in edge + if (lfIt3 != ff.end()) + { + ff.erase( lfIt3 ); + if ( ff.empty() ) + linkFacesMap.erase( lfIt2 ); + } } } badFace->_reverse = true; // reverse @@ -2376,7 +2383,7 @@ int DoubleField::setValues( double * valPtr, const int iSub, const int elemShift THROW_IK_EXCEPTION("SauvMedConvertor.cxx: support size mismatches field size"); // compute nb values in previous subs int valsShift = 0; - for ( int iS = iSub-1, shift = elemShift; shift > 0; ) + for ( int iS = iSub-1, shift = elemShift; shift > 0; --iS) { int nbE = _sub[iS]._support->size(); shift -= nbE; diff --git a/src/MEDLoader/SauvWriter.cxx b/src/MEDLoader/SauvWriter.cxx index 5fb31d2b6..88d17854d 100644 --- a/src/MEDLoader/SauvWriter.cxx +++ b/src/MEDLoader/SauvWriter.cxx @@ -404,7 +404,7 @@ void SauvWriter::fillFamilySubMeshes() //================================================================================ /*! - * \brief fill sub-mehses of groups + * \brief fill sub-meshes of groups */ //================================================================================ @@ -418,22 +418,30 @@ void SauvWriter::fillGroupSubMeshes() const vector& famNames = g2ff->second; if ( famNames.empty() ) continue; std::vector famSubMeshes( famNames.size() ); + std::size_t k = 0; for ( size_t i = 0; i < famNames.size(); ++i ) { int famID = _fileMesh->getFamilyId( famNames[i].c_str() ); map< int, SubMesh* >::iterator i2f = _famIDs2Sub.find( famID ); - if ( i2f == _famIDs2Sub.end() ) - THROW_IK_EXCEPTION("SauvWriter::fillGroupSubMeshes(): unknown family ID: " << famID); - famSubMeshes[ i ] = i2f->second; + if ( i2f != _famIDs2Sub.end() ) + { + famSubMeshes[ k ] = i2f->second; + ++k; + } } + // if a family exists but has no element, no submesh has been found for this family + // => we have to resize famSubMeshes with the number of submeshes stored + if (k != famNames.size()) + famSubMeshes.resize(k); SubMesh* grpSubMesh = addSubMesh( groupName, famSubMeshes[0]->_dimRelExt ); grpSubMesh->_subs.swap( famSubMeshes ); } } + //================================================================================ /*! - * \brief fill sub-mehses of profiles + * \brief fill sub-meshes of profiles */ //================================================================================ diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index 47ebf737b..96e20f5aa 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -48,6 +48,9 @@ def ParaMEDMEMMEDCouplingFieldDoubleImul(self,*args): def ParaMEDMEMMEDCouplingFieldDoubleIdiv(self,*args): import _MEDLoader return _MEDLoader.MEDCouplingFieldDouble____idiv___(self, self, *args) +def ParaMEDMEMMEDCouplingFieldDoubleIpow(self,*args): + import _MEDLoader + return _MEDLoader.MEDCouplingFieldDouble____ipow___(self, self, *args) def ParaMEDMEMDataArrayIntIadd(self,*args): import _MEDLoader return _MEDLoader.DataArrayInt____iadd___(self, self, *args) diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 44e291381..311657240 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -199,9 +199,9 @@ public: return ret; } - static PyObject *GetAllFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception) + static PyObject *GetAllFieldIterations(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception) { - std::vector< std::pair< std::pair, double> > res=MEDLoader::GetAllFieldIterations(fileName,meshName,fieldName); + std::vector< std::pair< std::pair, double> > res=MEDLoader::GetAllFieldIterations(fileName,fieldName); PyObject *ret=PyList_New(res.size()); int rk=0; for(std::vector< std::pair< std::pair, double> >::const_iterator iter=res.begin();iter!=res.end();iter++,rk++) diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 891437501..1f7d5d68e 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -555,6 +555,10 @@ class MEDLoaderTest(unittest.TestCase): # fname="Pyfile28.med" f1=MEDLoaderDataForTest.buildVecFieldOnGauss_2_Simpler(); + f1InvalidCpy=f1.deepCpy() + f1InvalidCpy.setDiscretization(MEDCouplingFieldDiscretizationGauss()) + f1InvalidCpy2=f1.deepCpy() + f1InvalidCpy2.setDiscretization(MEDCouplingFieldDiscretizationGauss()) m1=f1.getMesh() mm1=MEDFileUMesh.New() mm1.setCoords(m1.getCoords()) @@ -562,6 +566,9 @@ class MEDLoaderTest(unittest.TestCase): mm1.setName(m1.getName()) mm1.write(fname,2) ff1=MEDFileField1TS.New() + self.assertRaises(InterpKernelException,ff1.setFieldNoProfileSBT,f1InvalidCpy) # fails because no Gauss localization per cell set !* + f1InvalidCpy2.getDiscretization().setArrayOfDiscIds(f1.getDiscretization().getArrayOfDiscIds()) # fails because no Gauss localization set whereas gauss locid per cell given ! + self.assertRaises(InterpKernelException,ff1.setFieldNoProfileSBT,f1InvalidCpy2) ff1.setFieldNoProfileSBT(f1) ff1.write(fname,0) ff2=MEDFileField1TS.New(fname,f1.getName(),f1.getTime()[1],f1.getTime()[2]) @@ -1483,10 +1490,13 @@ class MEDLoaderTest(unittest.TestCase): da=DataArrayDouble(34) ; da.iota(3.) f.setArray(da) f.setName("fieldCellOnPflWithoutPfl") + fInvalid=f.deepCpy() f.setGaussLocalizationOnCells([0,1,2,3,4,5,6,7,8],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2]) f.setGaussLocalizationOnCells([9,10],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7,0.8,0.8],[0.8,0.07,0.13]) f.setGaussLocalizationOnCells([11,12],[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.3,0.7,0.7,0.8,0.8,0.8,0.8,0.8,0.8],[0.8,0.07,0.1,0.01,0.02]) f.checkCoherency() + fInvalid2=fInvalid.deepCpy() + fInvalid2.getDiscretization().setArrayOfDiscIds(f.getDiscretization().getArrayOfDiscIds()) # mm=MEDFileUMesh() mm.setMeshAtLevel(0,m) @@ -1494,6 +1504,8 @@ class MEDLoaderTest(unittest.TestCase): # f1ts=MEDFileField1TS.New() pfl=DataArrayInt(range(13)) ; pfl.setName("pfl") + self.assertRaises(InterpKernelException,f1ts.setFieldProfile,fInvalid,mm,0,pfl) # fails because no Gauss localization per cell set ! + self.assertRaises(InterpKernelException,f1ts.setFieldProfile,fInvalid2,mm,0,pfl) # fails because no Gauss localization set whereas gauss locid per cell given ! f1ts.setFieldProfile(f,mm,0,pfl) f1ts.write(fname,0) # diff --git a/src/MEDLoader/Test/SauvLoaderTest.cxx b/src/MEDLoader/Test/SauvLoaderTest.cxx index f6656a85b..f1c8f8d0d 100644 --- a/src/MEDLoader/Test/SauvLoaderTest.cxx +++ b/src/MEDLoader/Test/SauvLoaderTest.cxx @@ -51,6 +51,91 @@ void SauvLoaderTest::testSauv2Med() CPPUNIT_ASSERT_EQUAL(17,int(m->getGroupsNames().size())); } +void SauvLoaderTest::testMed2SauvOnAMeshWithVoidFamily() +{ + // Create a mesh with 2 quads. + const int spaceDim = 2; + const int nbOfNodes = 6; + double coords[nbOfNodes*spaceDim] = {0,0, 1,0, 1,1, 0,1, 2,0, 2,1}; + int conn[8]={0,1,2,3, 1,4,5,2}; + MEDCouplingUMesh *mesh2d=MEDCouplingUMesh::New("Mesh",spaceDim); + mesh2d->allocateCells(2); + mesh2d->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn); + mesh2d->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+4); + mesh2d->finishInsertingCells(); + DataArrayDouble *myCoords=DataArrayDouble::New(); + myCoords->alloc(nbOfNodes,spaceDim); + std::copy(coords,coords+nbOfNodes*spaceDim,myCoords->getPointer()); + mesh2d->setCoords(myCoords); + myCoords->decrRef(); + + // create a MedFileUMesh + MEDFileUMesh* m= MEDFileUMesh::New(); + m->setMeshAtLevel(0,mesh2d); + + // Create families and groups + + DataArrayInt *fam = DataArrayInt::New(); + fam->alloc(2,1); + int elemsFams[2] = {-2,-3}; + std::copy(elemsFams,elemsFams+2,fam->getPointer()); + + m->setFamilyFieldArr(0,fam); + + std::map theFamilies; + theFamilies["FAM_-1"]=-1; + theFamilies["FAM_-2"]=-2; + theFamilies["FAM_-3"]=-3; + + std::map > theGroups; + theGroups["Group1"].push_back("FAM_-2"); + theGroups["Group2"].push_back("FAM_-3"); + theGroups["Grouptot"].push_back("FAM_-1"); + theGroups["Grouptot"].push_back("FAM_-2"); + theGroups["Grouptot"].push_back("FAM_-3"); + m->setFamilyInfo(theFamilies); + m->setGroupInfo(theGroups); + + // write to MED for visual check + //const char* medFile = "mesh_with_void_family.med"; + //m->write(medFile, 2); + + // write to SAUV + const char* sauvFile = "mesh_with_void_family.sauv"; + MEDFileData* medData = MEDFileData::New(); + MEDFileMeshes* medMeshes = MEDFileMeshes::New(); + SauvWriter* sw=SauvWriter::New(); + medMeshes->setMeshAtPos(0, m); + medData->setMeshes(medMeshes); + sw->setMEDFileDS(medData); + sw->write(sauvFile); + + // read SAUV and check groups + MEDCouplingAutoRefCountObjectPtr sr=SauvReader::New(sauvFile); + MEDCouplingAutoRefCountObjectPtr d2=sr->loadInMEDFileDS(); + MEDFileUMesh * m2 = static_cast( d2->getMeshes()->getMeshAtPos(0) ); + std::vector groups = m->getGroupsNames(); + std::cout << "Number of groups: " << groups.size() << std::endl; + CPPUNIT_ASSERT_EQUAL(3,(int)groups.size()); + MEDCouplingUMesh * grp1 = m2->getGroup(0, "Group1"); + CPPUNIT_ASSERT_EQUAL(1,(int)grp1->getNumberOfCells()); + MEDCouplingUMesh * grp2 = m2->getGroup(0, "Group2"); + CPPUNIT_ASSERT_EQUAL(1,(int)grp2->getNumberOfCells()); + MEDCouplingUMesh * grptot = m2->getGroup(0, "Grouptot"); + CPPUNIT_ASSERT_EQUAL(2,(int)grptot->getNumberOfCells()); + + // clean + mesh2d->decrRef(); + medData->decrRef(); + medMeshes->decrRef(); + fam->decrRef(); + m->decrRef(); + sw->decrRef(); + grp1->decrRef(); + grp2->decrRef(); + grptot->decrRef(); +} + void SauvLoaderTest::testMed2Sauv() { // read pointe.med @@ -201,8 +286,8 @@ void SauvLoaderTest::testMed2Sauv() void SauvLoaderTest::tearDown() { - const int nbFilesToRemove = 2; - const char* fileToRemove[nbFilesToRemove] = { "allPillesTest.med", "pointe.sauv" }; + const int nbFilesToRemove = 3; + const char* fileToRemove[nbFilesToRemove] = { "allPillesTest.med", "pointe.sauv", "mesh_with_void_family.sauv" }; for ( int i = 0; i < nbFilesToRemove; ++i ) { #ifdef WIN32 diff --git a/src/MEDLoader/Test/SauvLoaderTest.hxx b/src/MEDLoader/Test/SauvLoaderTest.hxx index 6fe5705ea..a43d1299c 100644 --- a/src/MEDLoader/Test/SauvLoaderTest.hxx +++ b/src/MEDLoader/Test/SauvLoaderTest.hxx @@ -31,10 +31,12 @@ namespace ParaMEDMEM CPPUNIT_TEST_SUITE(SauvLoaderTest); CPPUNIT_TEST( testSauv2Med ); CPPUNIT_TEST( testMed2Sauv ); + CPPUNIT_TEST( testMed2SauvOnAMeshWithVoidFamily ); CPPUNIT_TEST_SUITE_END(); public: void testSauv2Med(); void testMed2Sauv(); + void testMed2SauvOnAMeshWithVoidFamily(); public: void tearDown(); diff --git a/src/ParaMEDMEM_Swig/ParaMEDMEM.i b/src/ParaMEDMEM_Swig/ParaMEDMEM.i index 9eadcf2cf..7eebdf86d 100644 --- a/src/ParaMEDMEM_Swig/ParaMEDMEM.i +++ b/src/ParaMEDMEM_Swig/ParaMEDMEM.i @@ -298,6 +298,9 @@ def ParaMEDMEMMEDCouplingFieldDoubleImul(self,*args): def ParaMEDMEMMEDCouplingFieldDoubleIdiv(self,*args): import _ParaMEDMEM return _ParaMEDMEM.MEDCouplingFieldDouble____idiv___(self, self, *args) +def ParaMEDMEMMEDCouplingFieldDoubleIpow(self,*args): + import _ParaMEDMEM + return _ParaMEDMEM.MEDCouplingFieldDouble____ipow___(self, self, *args) def ParaMEDMEMDataArrayIntIadd(self,*args): import _ParaMEDMEM return _ParaMEDMEM.DataArrayInt____iadd___(self, self, *args) -- 2.39.2