Salome HOME
MERGE stage 1: keep doc/dev and src/MEDCalc/doc
[tools/medcoupling.git] / src / ParaMEDMEM / DisjointDEC.cxx
index f3f9bf666ee75f34963bd4132f52f28b3a6eb2ed..57e67fd2c93721871b57a49232740f8d0e8c55f6 100644 (file)
 #include <cmath>
 #include <iostream>
 
-/*! \defgroup dec DEC
- *
- * \section decintroduction Introduction
- *
- * Interface class for creation of a link between two 
- * processor groups for exhanging mesh or field data.
- * The \c DEC is defined by attaching a field on the receiving or on the 
- * sending side. 
- * On top of attaching a \c ParaMEDMEM::FIELD, it is possible to
- * attach a ICoCo::Field. This class is an abstract class that enables 
- * coupling of codes that respect the ICoCo interface \ref icoco. It has two implementations:
- * one for codes that express their fields as \ref medoupling fields (ICoCo::MEDField).
- * 
- * \section dec_options DEC Options
- * Options supported by \c DEC objects are
- *
- * <TABLE BORDER=1 >
- * <TR><TD>Option</TD><TD>Description</TD><TD>Default value</TD></TR>
- * <TR><TD>ForcedRenormalization</TD><TD>After receiving data, the target field is renormalized so that L2-norms of the source and target fields match.</TD><TD> false </TD></TR>
- *</TABLE>
-
-
- The following code excerpt shows how to set options for an object that inherits from \c DEC :
-
- \code
- InterpKernelDEC dec(source_group,target_group);
- dec.setOptions("ForcedRenormalization",true);
- dec.attachLocalField(field);
- dec.synchronize();
- if (source_group.containsMyRank())
- dec.sendData();
- else
- dec.recvData();
- \endcode
-*/
 
 namespace ParaMEDMEM
 {
 
-
-  /*! \addtogroup dec
-    @{ 
+  /*!
+   * \anchor DisjointDEC-det
+   * \class DisjointDEC
+   *
+   * Interface class for creation of a link between two
+   * processor groups for exhanging mesh or field data.
+   * The \c DEC is defined by attaching a field on the receiving or on the
+   * sending side.
+   * On top of attaching a \c ParaMEDMEM::ParaFIELD, it is possible to
+   * attach a ICoCo::Field. This class is an abstract class that enables
+   * coupling of codes that respect the ICoCo interface \ref icoco. It has two implementations:
+   * one for codes that express their fields as \ref fields "MEDCoupling fields" (ICoCo::MEDField).
+   *
+   * \section dec_options DEC Options
+   * Options supported by \c DEC objects are
+   *
+   * <TABLE BORDER=1 >
+   * <TR><TD>Option</TD><TD>Description</TD><TD>Default value</TD></TR>
+   * <TR><TD>ForcedRenormalization</TD><TD>After receiving data, the target field is renormalized so that L2-norms of the source and target fields match.</TD><TD> false </TD></TR>
+   *</TABLE>
+
+
+   The following code excerpt shows how to set options for an object that inherits from \c DEC :
+
+   \code
+   InterpKernelDEC dec(source_group,target_group);
+   dec.setOptions("ForcedRenormalization",true);
+   dec.attachLocalField(field);
+   dec.synchronize();
+   if (source_group.containsMyRank())
+     dec.sendData();
+   else
+     dec.recvData();
+   \endcode
   */
-  DisjointDEC::DisjointDEC(ProcessorGroup& source_group, ProcessorGroup& target_group):_local_field(0), 
-                                                                                       _source_group(&source_group),
-                                                                                       _target_group(&target_group),
-                                                                                       _owns_field(false),
-                                                                                       _owns_groups(false)
+
+
+  DisjointDEC::DisjointDEC(ProcessorGroup& source_group, ProcessorGroup& target_group):
+      _local_field(0),
+      _source_group(&source_group),
+      _target_group(&target_group),
+      _comm_interface(0),
+      _owns_field(false),
+      _owns_groups(false),
+      _union_comm(MPI_COMM_NULL)
   {
     _union_group = source_group.fuse(target_group);  
   }
   
-  DisjointDEC::DisjointDEC(const DisjointDEC& s):DEC(s),_local_field(0),_union_group(0),_source_group(0),_target_group(0),_owns_field(false),_owns_groups(false)
+  DisjointDEC::DisjointDEC(const DisjointDEC& s):
+      DEC(s),
+      _local_field(0),
+      _union_group(0),
+      _source_group(0),
+      _target_group(0),
+      _comm_interface(0),
+      _owns_field(false),
+      _owns_groups(false),
+      _union_comm(MPI_COMM_NULL)
   {
     copyInstance(s);
   }
@@ -113,9 +123,14 @@ namespace ParaMEDMEM
       _union_group = _source_group->fuse(*_target_group);
   }
 
-  DisjointDEC::DisjointDEC(const std::set<int>& source_ids, const std::set<int>& target_ids, const MPI_Comm& world_comm):_local_field(0), 
-                                                                                                                         _owns_field(false),
-                                                                                                                         _owns_groups(true)
+  DisjointDEC::DisjointDEC(const std::set<int>& source_ids,
+                           const std::set<int>& target_ids,
+                           const MPI_Comm& world_comm):
+     _local_field(0),
+     _owns_field(false),
+     _owns_groups(true),
+     _comm_interface(0),
+     _union_comm(MPI_COMM_NULL)
   {
     ParaMEDMEM::CommInterface comm;
     // Create the list of procs including source and target
@@ -131,15 +146,15 @@ namespace ParaMEDMEM
     MPI_Group union_group,world_group;
     comm.commGroup(world_comm,&world_group);
     comm.groupIncl(world_group,union_ids.size(),union_ranks_world,&union_group);
-    MPI_Comm union_comm;
-    comm.commCreate(world_comm,union_group,&union_comm);
+    comm.commCreate(world_comm,union_group,&_union_comm);
     delete[] union_ranks_world;
-
-    if (union_comm==MPI_COMM_NULL)
+    if (_union_comm==MPI_COMM_NULL)
       { // This process is not in union
         _source_group=0;
         _target_group=0;
         _union_group=0;
+        comm.groupFree(&union_group);
+        comm.groupFree(&world_group);
         return;
       }
 
@@ -164,10 +179,11 @@ namespace ParaMEDMEM
     delete [] target_ranks_union;
 
     // Create the MPIProcessorGroups
-    _source_group = new MPIProcessorGroup(comm,source_ids_union,union_comm);
-    _target_group = new MPIProcessorGroup(comm,target_ids_union,union_comm);
+    _source_group = new MPIProcessorGroup(comm,source_ids_union,_union_comm);
+    _target_group = new MPIProcessorGroup(comm,target_ids_union,_union_comm);
     _union_group = _source_group->fuse(*_target_group);
-
+    comm.groupFree(&union_group);
+    comm.groupFree(&world_group);
   }
 
   DisjointDEC::~DisjointDEC()
@@ -193,6 +209,8 @@ namespace ParaMEDMEM
     _target_group=0;
     delete _union_group;
     _union_group=0;
+    if (_union_comm != MPI_COMM_NULL)
+      _comm_interface->commFree(&_union_comm);
   }
 
   void DisjointDEC::setNature(NatureOfField nature)
@@ -305,7 +323,6 @@ namespace ParaMEDMEM
           }
       }
   }
-  /*! @} */
 
   bool DisjointDEC::isInSourceSide() const
   {