Salome HOME
refactor!: remove adm_local/ directory
[tools/medcoupling.git] / src / ParaMEDMEM / OverlapMapping.cxx
index ad5de95c7e03c82996144e177707126d8e260b72..051ad304319e099be64f82953c17b18633d0ffd9 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2023  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -311,7 +311,7 @@ void OverlapMapping::serializeMatrixStep0ST(const mcIdType *nbOfElemsSrc, mcIdTy
   int myProcId=_group.myRank();
   for(std::size_t i=0;i<_matrixes_st.size();i++)
     {
-      if(_source_proc_id_st[i]==myProcId)// && _target_proc_id_st[i]!=myProcId
+      if(_source_proc_id_st[i]==myProcId && _matrixes_st[i].size())// && _target_proc_id_st[i]!=myProcId
         {
           count[_target_proc_id_st[i]]=(int)_matrixes_st[i].size()+1;
           szz+=_matrixes_st[i].size()+1;
@@ -323,7 +323,7 @@ void OverlapMapping::serializeMatrixStep0ST(const mcIdType *nbOfElemsSrc, mcIdTy
     offsets[i]=offsets[i-1]+count[i-1];
   for(std::size_t i=0;i<_matrixes_st.size();i++)
     {
-      if(_source_proc_id_st[i]==myProcId)
+      if(_source_proc_id_st[i]==myProcId && _matrixes_st[i].size())
         {
           mcIdType start=offsets[_target_proc_id_st[i]];
           mcIdType *work=bigArr+start;
@@ -374,7 +374,7 @@ mcIdType OverlapMapping::serializeMatrixStep1ST(const mcIdType *nbOfElemsSrc, co
   std::size_t fullLgth=0;
   for(std::size_t i=0;i<_matrixes_st.size();i++)
     {
-      if(_source_proc_id_st[i]==myProcId)
+      if(_source_proc_id_st[i]==myProcId && _matrixes_st[i].size())
         {
           const std::vector< SparseDoubleVec >& mat=_matrixes_st[i];
           mcIdType lgthToSend=0;
@@ -393,7 +393,7 @@ mcIdType OverlapMapping::serializeMatrixStep1ST(const mcIdType *nbOfElemsSrc, co
   fullLgth=0;
   for(std::size_t i=0;i<_matrixes_st.size();i++)
     {
-      if(_source_proc_id_st[i]==myProcId)
+      if(_source_proc_id_st[i]==myProcId && _matrixes_st[i].size())
         {
           const std::vector< SparseDoubleVec >& mat=_matrixes_st[i];
           for(std::vector< SparseDoubleVec >::const_iterator it1=mat.begin();it1!=mat.end();it1++)
@@ -544,7 +544,8 @@ void OverlapMapping::multiply(const MEDCouplingFieldDouble *fieldInput, MEDCoupl
                   throw INTERP_KERNEL::Exception("OverlapMapping::multiply(): internal error: SEND: unexpected end iterator in _sent_src_ids!");
                 vals=fieldInput->getArray()->selectByTupleId(*(*isItem11).second);
               }
-            nbsend[procID] = (int)vals->getNbOfElems();
+            nbsend[procID] = (int)vals->getNbOfElems();  // nb of elem = nb_tuples*nb_compo
+            // Flat version of values to send:
             valsToSend.insert(valsToSend.end(),vals->getConstPointer(),vals->getConstPointer()+nbsend[procID]);
           }
 
@@ -569,14 +570,14 @@ void OverlapMapping::multiply(const MEDCouplingFieldDouble *fieldInput, MEDCoupl
                 map <int,mcIdType>::const_iterator isItem11 = _nb_of_rcv_src_ids.find(procID);
                 if (isItem11 == _nb_of_rcv_src_ids.end())
                   throw INTERP_KERNEL::Exception("OverlapMapping::multiply(): internal error: RCV: unexpected end iterator in _nb_of_rcv_src_ids!");
-                nbrecv[procID] = (int)((*isItem11).second);
+                nbrecv[procID] = (int)((*isItem11).second * nbOfCompo);
               }
             else
               {
-                map<int, vector<mcIdType> >::const_iterator isItem11 = _src_ids_zip_recv.find(procID);
-                if (isItem11 == _src_ids_zip_recv.end())
+                map<int, vector<mcIdType> >::const_iterator isItem22 = _src_ids_zip_recv.find(procID);
+                if (isItem22 == _src_ids_zip_recv.end())
                   throw INTERP_KERNEL::Exception("OverlapMapping::multiply(): internal error: RCV: unexpected end iterator in _src_ids_zip_recv!");
-                nbrecv[procID] = (int)((*isItem11).second.size()*nbOfCompo);
+                nbrecv[procID] = (int)((*isItem22).second.size() * nbOfCompo);
               }
           }
     }
@@ -618,7 +619,9 @@ void OverlapMapping::multiply(const MEDCouplingFieldDouble *fieldInput, MEDCoupl
   INTERP_KERNEL::AutoPtr<double> tmp=new double[nbOfCompo];
 
   // By default field value set to default value - so mark which cells are hit
-  INTERP_KERNEL::AutoPtr<bool> hit_cells = new bool[fieldOutput->getNumberOfTuples()];
+  mcIdType ntup = fieldOutput->getNumberOfTuples();
+  INTERP_KERNEL::AutoPtr<bool> hit_cells = new bool[ntup];
+  std::fill((bool *)hit_cells, (bool *)hit_cells+ntup, false);
 
   for(vector<int>::const_iterator itProc=_the_matrix_st_source_proc_id.begin(); itProc != _the_matrix_st_source_proc_id.end();itProc++)
   // For each source processor corresponding to a locally held matrix:
@@ -652,7 +655,7 @@ void OverlapMapping::multiply(const MEDCouplingFieldDouble *fieldInput, MEDCoupl
                   transform(localSrcField+((*it3).first)*nbOfCompo,
                             localSrcField+((*it3).first+1)*nbOfCompo,
                             (double *)tmp,
-                            bind2nd(multiplies<double>(),ratio) );
+                            [=](double d) { return d*ratio; });
                   // Accumulate with current value:
                   transform((double *)tmp,(double *)tmp+nbOfCompo,targetPt,targetPt,plus<double>());
                   hit_cells[j] = true;
@@ -709,7 +712,7 @@ void OverlapMapping::multiply(const MEDCouplingFieldDouble *fieldInput, MEDCoupl
                   transform(bigArr+nbrecv2[srcProcID]+((*it4).second)*nbOfCompo,
                             bigArr+nbrecv2[srcProcID]+((*it4).second+1)*nbOfCompo,
                             (double *)tmp,
-                            bind2nd(multiplies<double>(),ratio) );
+                            [=](double d) { return d*ratio; } );
                   transform((double *)tmp,(double *)tmp+nbOfCompo,targetPt,targetPt,plus<double>());
                   hit_cells[tgrIds[j]] = true;
                 }
@@ -738,7 +741,7 @@ void OverlapMapping::multiply(const MEDCouplingFieldDouble *fieldInput, MEDCoupl
                   transform(bigArr+nbrecv2[srcProcID]+((*it3).first)*nbOfCompo,
                             bigArr+nbrecv2[srcProcID]+((*it3).first+1)*nbOfCompo,
                             (double *)tmp,
-                            bind2nd(multiplies<double>(),ratio));
+                            [=](double d) { return d*ratio; } );
                   // Accumulate with current value:
                   transform((double *)tmp,(double *)tmp+nbOfCompo,targetPt,targetPt,plus<double>());
                   hit_cells[j] = true;
@@ -749,7 +752,7 @@ void OverlapMapping::multiply(const MEDCouplingFieldDouble *fieldInput, MEDCoupl
 
   // Fill in default values for cells which haven't been hit:
   int i = 0;
-  for(bool * hit_cells_ptr=hit_cells; i< fieldOutput->getNumberOfTuples(); hit_cells_ptr++,i++)
+  for(bool * hit_cells_ptr=hit_cells; i< ntup; hit_cells_ptr++,i++)
     if (!(*hit_cells_ptr))
       {
         double * targetPt=fieldOutput->getArray()->getPointer();