X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingMesh.cxx;h=f7ab4ccddf7179655a9efeea75057f387ac820da;hb=9abc40a840f69fd7f07b356cd31876b64dc81e14;hp=fd1ef11719f26fb0c25bfc67c86e680895ef3001;hpb=e0c843a1fe827a90af91ada8d2033ffb3a7dd1d8;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingMesh.cxx b/src/MEDCoupling/MEDCouplingMesh.cxx index fd1ef1171..f7ab4ccdd 100755 --- a/src/MEDCoupling/MEDCouplingMesh.cxx +++ b/src/MEDCoupling/MEDCouplingMesh.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2020 CEA/DEN, EDF R&D +// Copyright (C) 2007-2022 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 @@ -674,6 +674,22 @@ void MEDCouplingMesh::getCellsContainingPointsLinearPartOnlyOnNonDynType(const d this->getCellsContainingPoints(pos,nbOfPoints,eps,elts,eltsIndex); } +/*! + * Method computing center of mass of whole mesh (\a this) + * \return DataArrayDouble * - a new instance of DataArrayDouble with one tuple of n components where n is space dimension + */ +MCAuto MEDCouplingMesh::computeMeshCenterOfMass() const +{ + MCAuto cellCenters( this->computeCellCenterOfMass() ); + MCAuto vol( this->getMeasureField(true) ); + MCAuto volXCenter( DataArrayDouble::Multiply(cellCenters,vol->getArray()) ); + MCAuto ret(DataArrayDouble::New()); ret->alloc(1, this->getSpaceDimension()); + volXCenter->accumulate( ret->getPointer() ); + double volOfMesh(vol->accumulate(0)); + ret->applyLin(1.0/volOfMesh,0.0); + return ret; +} + /*! * Writes \a this mesh into a VTK format file named as specified. * \param [in] fileName - the name of the file to write in. If the extension is OK the fileName will be used directly.