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<DataArrayDouble> MEDCouplingMesh::computeMeshCenterOfMass() const
+{
+ MCAuto<DataArrayDouble> cellCenters( this->computeCellCenterOfMass() );
+ MCAuto<MEDCouplingFieldDouble> vol( this->getMeasureField(true) );
+ MCAuto<DataArrayDouble> volXCenter( DataArrayDouble::Multiply(cellCenters,vol->getArray()) );
+ MCAuto<DataArrayDouble> 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.
MEDCOUPLING_EXPORT virtual std::string simpleRepr() const = 0;
MEDCOUPLING_EXPORT virtual std::string advancedRepr() const = 0;
// tools
+ MEDCOUPLING_EXPORT virtual MCAuto<DataArrayDouble> computeMeshCenterOfMass() const;
MEDCOUPLING_EXPORT virtual const DataArrayDouble *getDirectAccessOfCoordsArrIfInStructure() const = 0;
MEDCOUPLING_EXPORT virtual std::vector<mcIdType> getDistributionOfTypes() const = 0;
MEDCOUPLING_EXPORT virtual DataArrayIdType *checkTypeConsistencyAndContig(const std::vector<mcIdType>& code, const std::vector<const DataArrayIdType *>& idsPerType) const = 0;
self.assertEqual(arr3.getInfoOnComponents(),comps)
self.assertTrue(arr3.isEqual(arr))
+ def testComputeMeshCenterOfMass0(self):
+ #2D
+ arr = DataArrayDouble(5) ; arr.iota()
+ m = MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildUnstructured()
+ self.assertTrue( m.computeMeshCenterOfMass().isEqual(DataArrayDouble([2,2],1,2),1e-12) )
+ #3D
+ m = MEDCouplingCMesh() ; m.setCoords(arr,arr,arr) ; m=m.buildUnstructured()
+ self.assertTrue( m.computeMeshCenterOfMass().isEqual(DataArrayDouble([2,2,2],1,3),1e-12) )
+
+
pass
if __name__ == '__main__':
%newobject MEDCoupling::MEDCouplingMesh::buildPartRange;
%newobject MEDCoupling::MEDCouplingMesh::giveCellsWithType;
%newobject MEDCoupling::MEDCouplingMesh::getCoordinatesAndOwner;
+%newobject MEDCoupling::MEDCouplingMesh::computeMeshCenterOfMass;
%newobject MEDCoupling::MEDCouplingMesh::computeCellCenterOfMass;
%newobject MEDCoupling::MEDCouplingMesh::computeIsoBarycenterOfNodesPerCell;
%newobject MEDCoupling::MEDCouplingMesh::buildOrthogonalField;
{
return self->simpleRepr();
}
+
+ DataArrayDouble *computeMeshCenterOfMass() const
+ {
+ MCAuto<DataArrayDouble> ret(self->computeMeshCenterOfMass());
+ return ret.retn();
+ }
PyObject *getTime()
{