Salome HOME
[bos #38048] [EDF] (2023-T3) PARAMEDMEM Ergonomy.
[tools/medcoupling.git] / src / ParaMEDMEM / InterpKernelDEC.cxx
index 16a26546ed929f8e6d2b271f321d7c23e7a430f4..f4494f489a64877a22e5e44bb242c497bf17d12b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2020  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
@@ -69,6 +69,43 @@ namespace MEDCoupling
   {
   }
 
+  /*!
+   * Creates an InterpKernelDEC from an string identifier for the source and target groups.
+   * The set of procs might not cover entirely MPI_COMM_WORLD
+   * (a sub-communicator holding the union of source and target procs is recreated internally).
+   */
+  InterpKernelDEC::InterpKernelDEC(ProcessorGroup& generic_group, const std::string& source_group, const std::string& target_group):
+    DisjointDEC(generic_group.getProcIDsByName(source_group),generic_group.getProcIDsByName(target_group)),
+    _interpolation_matrix(0)
+  {
+  }
+  
+  /*!
+   * Split the interaction group based on the predefined token string "<->"
+   *  The string at left of the token will be the source group and the string at right the target group
+   */
+  static std::pair<std::string,std::string> GetGroupsName( const std::string& interaction_group )
+  {
+    const std::string delimiter = "<->";
+    size_t delimiter_position = interaction_group.find(delimiter);
+    if ( delimiter_position == std::string::npos )
+      throw ( "No delimiter <-> found in the interaction group.");
+
+    std::string src = interaction_group.substr(0,delimiter_position);
+    std::string tgt = interaction_group.substr(delimiter_position+delimiter.size(),interaction_group.size());
+    return std::make_pair(src,tgt);
+  }
+
+  /*!
+   * Creates an InterpKernelDEC from an string defining an interaction. 
+   *  The source and target group are obtained by spliting the string based in the "<->" token.
+   *  The constructor accepting a ProcessorGroup and two strings is reused.
+   */
+  InterpKernelDEC::InterpKernelDEC(ProcessorGroup& generic_group, const std::string& interaction_group ):
+    InterpKernelDEC(generic_group,GetGroupsName(interaction_group).first,GetGroupsName(interaction_group).second)
+  {
+  }
+
   InterpKernelDEC::~InterpKernelDEC()
   {
     release();
@@ -165,6 +202,15 @@ namespace MEDCoupling
     _interpolation_matrix->prepare();
   }
 
+  /*!
+   * Set a default value for non fetched entities
+   */
+  void InterpKernelDEC::synchronizeWithDefaultValue(double val)
+  {
+    this->synchronize();
+    if(_interpolation_matrix )
+      _interpolation_matrix->setDefaultValue(val);
+  }
 
   /*!
     Receives the data whether the processor is on the working side or on the lazy side. It must match a \a sendData() call on the other side.
@@ -181,6 +227,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