]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
[EDF27375] : implementation of retrieveNonFetchedIds
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 16 Aug 2023 09:45:38 +0000 (11:45 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 16 Aug 2023 09:45:38 +0000 (11:45 +0200)
src/ParaMEDMEM/InterpKernelDEC.cxx
src/ParaMEDMEM/InterpKernelDEC.hxx
src/ParaMEDMEM/InterpolationMatrix.cxx
src/ParaMEDMEM/InterpolationMatrix.hxx
src/ParaMEDMEM/MxN_Mapping.cxx
src/ParaMEDMEM/MxN_Mapping.hxx
src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i
src/ParaMEDMEM_Swig/test_InterpKernelDEC.py

index 8ed6b13019ac0f5ec5cb462ab96c477b556b3a69..18cf01e7c7bab4cc71791b33edb24097a2b18dbf 100644 (file)
@@ -190,6 +190,29 @@ namespace MEDCoupling
       }
   }
 
+  MCAuto<DataArrayIdType> InterpKernelDEC::retrieveNonFetchedIds() const
+  {
+    if( _source_group->containsMyRank() )
+    {
+      return this->retrieveNonFetchedIdsSource();
+    }
+    if( _target_group->containsMyRank() )
+    {
+      return this->retrieveNonFetchedIdsTarget();
+    }
+    THROW_IK_EXCEPTION("Not detected side of rank !");
+  }
+
+  MCAuto<DataArrayIdType> InterpKernelDEC::retrieveNonFetchedIdsSource() const
+  {
+    return _interpolation_matrix->retrieveNonFetchedIdsSource();
+  }
+
+  MCAuto<DataArrayIdType> InterpKernelDEC::retrieveNonFetchedIdsTarget() const
+  {
+    mcIdType nbTuples = _local_field->getField()->getNumberOfTuplesExpected();
+    return _interpolation_matrix->retrieveNonFetchedIdsTarget(nbTuples);
+  }
 
   /*!
     Receives the data at time \a time in asynchronous mode. The value of the field
index 52891b8b90ab8c740dcdbf3b656fcca1dba15dd5..eaa87526efd6ad5022dcbac80ca587e729d09922 100644 (file)
@@ -136,12 +136,16 @@ namespace MEDCoupling
 
     void synchronize();
     void synchronizeWithDefaultValue(double val);
+    MCAuto<DataArrayIdType> retrieveNonFetchedIds() const;
     void recvData();
     void recvData(double time);
     void sendData();
     void sendData(double time , double deltatime);
     void prepareSourceDE() { }
     void prepareTargetDE() { }
+  private:
+    MCAuto<DataArrayIdType> retrieveNonFetchedIdsSource() const;
+    MCAuto<DataArrayIdType> retrieveNonFetchedIdsTarget() const;
   private:
     InterpolationMatrix* _interpolation_matrix;
   };
index 7bf59e2ec047cc4194de817ed2c98d3131a8ae98..daee514fc427865014831859bc22f580a7de1bf3 100644 (file)
@@ -849,7 +849,10 @@ namespace MEDCoupling
     _mapping.prepareSendRecv();
   }
 
-
+  MCAuto<DataArrayIdType> InterpolationMatrix::retrieveNonFetchedIdsTarget(mcIdType nbTuples) const
+  {
+    return _mapping.retrieveNonFetchedIdsTarget(nbTuples);
+  }
 
   /*!
      \brief performs t=Ws, where t is the target field, s is the source field
@@ -866,7 +869,6 @@ namespace MEDCoupling
   {
     mcIdType nbcomp = ToIdType(field.getArray()->getNumberOfComponents());
     vector<double> target_value(_col_offsets.size()* nbcomp,0.0);
-
     //computing the matrix multiply on source side
     if (_source_group.containsMyRank())
       {
@@ -899,6 +901,36 @@ namespace MEDCoupling
     //on source side : sending  T=VT^(-1).(W.S)
     //on target side :: receiving T and storing it in field
     _mapping.sendRecv(target_value.data(),field,this->_presence_dft_value,this->_dft_value);
+
+    if( _target_group.containsMyRank() )
+    {
+      if( this->_presence_dft_value )
+      {
+        const MCAuto<DataArrayIdType> nonFetchedEntities = _mapping.retrieveNonFetchedIdsTarget(field.getArray()->getNumberOfTuples());
+        double *fieldPtr( field.getArray()->getPointerSilent() );
+        for( const mcIdType *eltId = nonFetchedEntities->begin() ; eltId != nonFetchedEntities->end() ; ++eltId)
+          std::fill( fieldPtr + (*eltId)*nbcomp, fieldPtr + ((*eltId)+1)*nbcomp, this->_dft_value );
+      }
+    }
+  }
+
+  MCAuto<DataArrayIdType> InterpolationMatrix::retrieveNonFetchedIdsSource() const
+  {
+    MCAuto<DataArrayIdType> ret(DataArrayIdType::New()); ret->alloc(0,1);
+    if (_source_group.containsMyRank())
+      {
+        mcIdType nbrows = ToIdType( _coeffs.size() );
+        for (mcIdType irow = 0; irow < nbrows; irow++)
+          {
+            if( _row_offsets[irow+1] == _row_offsets[irow] )
+            {
+              ret->pushBackSilent( irow );
+            }
+          }
+      }
+    else
+      THROW_IK_EXCEPTION("InterpolationMatrix::retrieveNonFetchedIdsSource : not supposed to be called target side !");
+    return ret;
   }
   
 
index 7e4f7a98989d9a12ef6696a45caaf176685012ad..a25cbe7c9c4550da1c89cb73bd177b0cdadb7f70 100644 (file)
@@ -54,7 +54,9 @@ namespace MEDCoupling
                          const mcIdType* distant_elems, const std::string& srcMeth, const std::string& targetMeth);
     void finishContributionW(ElementLocator& elementLocator);
     void finishContributionL(ElementLocator& elementLocator);
+    MCAuto<DataArrayIdType> retrieveNonFetchedIdsTarget(mcIdType nbTuples) const;
     void multiply(MEDCouplingFieldDouble& field) const;
+    MCAuto<DataArrayIdType> retrieveNonFetchedIdsSource() const;
     void transposeMultiply(MEDCouplingFieldDouble& field)const;
     void prepare();
     mcIdType getNbRows() const { return ToIdType(_row_offsets.size()); }
index fca6395a9c70a50f8b553e534d4adb22ea5c8074..c0e92223463b8094ecec4623cbf0cc685aaba43e 100644 (file)
@@ -134,6 +134,23 @@ namespace MEDCoupling
     delete[] recvdispls;
   }
 
+  MCAuto<DataArrayIdType> MxN_Mapping::retrieveNonFetchedIdsTarget(mcIdType nbTuples) const
+  {
+    MCAuto<DataArrayIdType> ret(DataArrayIdType::New()); ret->alloc(0,1);
+    std::vector<bool> hitMachine(nbTuples,false);
+    for (int i=0; i< _recv_proc_offsets[_union_group->size()]; i++)
+      {
+        mcIdType recvId(_recv_ids[i]);
+        hitMachine[recvId] = true;
+      }
+    for( mcIdType ituple = 0 ; ituple <  nbTuples ; ++ituple )
+      {
+        if( ! hitMachine[ituple] )
+          ret->pushBackSilent( ituple );
+      }
+    return ret;
+  }
+
   /*! Exchanging field data between two groups of processes
    * 
    * \param field MEDCoupling field containing the values to be sent
@@ -209,15 +226,6 @@ namespace MEDCoupling
             recvptr++;
           }
       }
-    if( isDftValue )
-    {
-      double *fieldPtr( fieldArr->getPointerSilent() );
-      for( mcIdType ituple = 0 ; ituple <  nbTuples ; ++ituple )
-      {
-        if( ! hitMachine[ituple] )
-          std::fill( fieldPtr + ituple*nbcomp, fieldPtr + (ituple+1)*nbcomp, dftValue);
-      }
-    }
     if (sendbuf!=0 && getAllToAllMethod()== Native)
       delete[] sendbuf;
     if (recvbuf !=0)
index 2c958e709630bc692188f10db5b37d760828f21b..8b44b7d757da9ff8bd7c589eb8e7223857ee5f8b 100644 (file)
@@ -45,6 +45,7 @@ namespace MEDCoupling
     void addElementFromSource(int distant_proc, mcIdType distant_elem);
     void prepareSendRecv();
     void sendRecv(MEDCouplingFieldDouble& field);
+    MCAuto<DataArrayIdType> retrieveNonFetchedIdsTarget(mcIdType nbTuples) const;
     void sendRecv(double* sendfield, MEDCouplingFieldDouble& field, bool isDftValue, double dftValue) const ;
     void reverseSendRecv(double* recvfield, MEDCouplingFieldDouble& field) const ;
  
index 5c65a95f4584ac44b53f7f60b77ad8486e9f3a22..624ffadd86b51ac2cf07af69a8008c7b5337a650 100644 (file)
@@ -75,6 +75,7 @@ using namespace ICoCo;
 
 %newobject MEDCoupling::InterpKernelDEC::_NewWithPG_internal;
 %newobject MEDCoupling::InterpKernelDEC::_NewWithComm_internal;
+%newobject MEDCoupling::InterpKernelDEC::retrieveNonFetchedIds;
 %newobject MEDCoupling::OverlapDEC::_NewWithComm_internal;
 
 %feature("unref") ParaSkyLineArray "$this->decrRef();"
@@ -323,6 +324,12 @@ namespace MEDCoupling
         {
           return new InterpKernelDEC(src_ids,trg_ids, *(MPI_Comm*)another_comm); // I know, ugly cast ...
         }
+
+        DataArrayIdType *retrieveNonFetchedIds() const
+        {
+          MCAuto<DataArrayIdType> ret = self->retrieveNonFetchedIds();
+          return ret.retn();
+        }
       }
   };
 
index 7be4f19da7c3f74153b6b7e7f798af7ce2eed917..4b5b289d7f35c7d616c32a9be22b72c31b8c4be0 100755 (executable)
@@ -289,8 +289,10 @@ class ParaMEDMEM_IK_DEC_Tests(unittest.TestCase):
             dec.recvData()
             if rank == 0:
                 self.assertTrue(field.getArray().isEqual(DataArrayDouble([0.6,0.6,-2000]),1e-12))
+                self.assertTrue( dec.retrieveNonFetchedIds().isEqual(DataArrayInt([2])) )
             if rank == 1:
                 self.assertTrue(field.getArray().isEqual(DataArrayDouble([1.0,-2000]),1e-12))
+                self.assertTrue( dec.retrieveNonFetchedIds().isEqual(DataArrayInt([1])) )
         else:
             mesh = eval("Target_Proc_{}".format(rank))()
             nb_local=mesh.getNumberOfCells()
@@ -307,10 +309,12 @@ class ParaMEDMEM_IK_DEC_Tests(unittest.TestCase):
                 # IntensiveMaximum => [[(0,S0,1/2.5),(1,S0,1.5/2.5)]
                 # 
                 self.assertTrue(field.getArray().isEqual(DataArrayDouble([0.6]),1e-12))
+                self.assertTrue( dec.retrieveNonFetchedIds().isEqual(DataArrayInt([])) )
             if rank == 3:
                 # matrix S1 / T3 = [[],[(0,S1,1.0)],[(0,S1,2.0)],[]]
                 # IntensiveMaximum => [[],[(0,S1,1.0/1.0)],[(0,S1,2.0/2.0)],[]]
                 self.assertTrue(field.getArray().isEqual(DataArrayDouble([-1000.0, 1.0, 1.0, -1000.0]),1e-8))
+                self.assertTrue( dec.retrieveNonFetchedIds().isEqual(DataArrayInt([0,3])) )
             # target -> source
             dec.sendData()