Salome HOME
updated copyright message
[tools/medcoupling.git] / src / ParaMEDMEM / ParaFIELD.cxx
index a3929955b2bdd258462eaad50619a91c5bc313a1..4472a46ee9e0eb5950f8e0893e2fb64dc74746d9 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2023  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 
 #include <numeric>
 
-namespace ParaMEDMEM
+namespace MEDCoupling
 {
   /*!
-    \defgroup parafield ParaFIELD
-    This class encapsulates parallel fields. It basically encapsulates
-    a MEDCouplingField with extra information related to parallel 
+    \anchor ParaFIELD-det
+    \class ParaFIELD
+
+    This class encapsulates parallel fields.
+
+    It gathers a \ref fields "MEDCouplingField" with some extra information related to the parallel
     topology.
-    It is most conveniently created by giving a pointer to a MEDCouplingField
-    object and a \c ProcessorGroup.
+
+    It is most conveniently created by giving a pointer to a MEDCouplingFieldDouble
+    object and a ProcessorGroup.
     By default, a ParaFIELD object will be constructed with all field components
-    located on the same processors. In some specific cases, it might be necessary to scatter components over several processors. In this case, the constructor
-    using a ComponentTopology is required.
+    located on the same processors. In some specific cases, it might be necessary to scatter components over
+    several processors. In this case, the constructor using a ComponentTopology is required.
 
-    @{ */
+    */
 
   /*!
 
-    \brief  Constructing a \c ParaFIELD from a \c ParaSUPPORT and a \c ComponentTopology.
+    \brief  Constructing a \c ParaFIELD from a \c ParaMESH and a \c ComponentTopology.
 
-    This constructor creates an empty field based on the ParaSUPPORT description 
+    This constructor creates an empty field based on the ParaMESH description
     and the partitioning of components described in \a component_topology.
     It takes ownership over the \c _field object that it creates.
 
@@ -103,12 +107,12 @@ namespace ParaMEDMEM
   /*! \brief Constructor creating the ParaFIELD
     from a given FIELD and a processor group. 
 
-    This constructor supposes that support underlying \a subdomain_field has no ParaSUPPORT 
+    This constructor supposes that support underlying \a subdomain_field has no ParaMESH
     attached and it therefore recreates one. It therefore takes ownership over _support. The component topology associated with the field is a basic one (all components on the same processor). 
   */
   ParaFIELD::ParaFIELD(MEDCouplingFieldDouble* subdomain_field, ParaMESH *sup, const ProcessorGroup& proc_group):
     _field(subdomain_field),
-    _component_topology(ComponentTopology(_field->getNumberOfComponents())),_topology(0),_own_support(false),
+    _component_topology(ComponentTopology((int)_field->getNumberOfComponents())),_topology(0),_own_support(false),
     _support(sup)
   {
     if(_field)
@@ -118,12 +122,28 @@ namespace ParaMEDMEM
   }
 
   ParaFIELD::~ParaFIELD()
+  {
+    release();
+  }
+
+  /** Destructor involves MPI operations: make sure this is accessible from a proper
+   * method for Python wrapping.
+   */
+  void ParaFIELD::release()
   {
     if(_field)
-      _field->decrRef();
+      {
+        _field->decrRef();
+        _field = nullptr;
+      }
+
     if(_own_support)
-      delete _support;
+      {
+        delete _support;
+        _support = nullptr;
+      }
     delete _topology;
+    _topology = nullptr;
   }
 
   void ParaFIELD::synchronizeTarget(ParaFIELD* source_field)
@@ -168,9 +188,9 @@ namespace ParaMEDMEM
    * This method returns, if it exists, an array with only one component and as many as tuples as _field has.
    * This array gives for every element on which this->_field lies, its global number, if this->_field is nodal.
    * For example if _field is a nodal field : returned array will be the nodal global numbers.
-   * The content of this method is used to inform Working side to accumulate data recieved by lazy side.
+   * The content of this method is used to inform Working side to accumulate data received by lazy side.
    */
-  DataArrayInt* ParaFIELD::returnCumulativeGlobalNumbering() const
+  DataArrayIdType* ParaFIELD::returnCumulativeGlobalNumbering() const
   {
     if(!_field)
       return 0;
@@ -186,7 +206,7 @@ namespace ParaMEDMEM
       }
   }
 
-  DataArrayInt* ParaFIELD::returnGlobalNumbering() const
+  DataArrayIdType* ParaFIELD::returnGlobalNumbering() const
   {
     if(!_field)
       return 0;