Salome HOME
Tentative d externalisation en medcoupling memoire
authorAnthony Geay <anthony.geay@edf.fr>
Mon, 26 Apr 2021 19:53:20 +0000 (21:53 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Mon, 26 Apr 2021 19:53:20 +0000 (21:53 +0200)
src/DriverMED/DriverMED_Family.cxx
src/DriverMED/DriverMED_Family.h
src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx
src/DriverMED/DriverMED_W_SMESHDS_Mesh.h
src/MEDWrapper/MEDCoupling_Wrapper.hxx [new file with mode: 0644]
src/MEDWrapper/MED_Wrapper.hxx

index 2acd6a826050c797a5c0d11c4fe97272b7423bbd..f5b00968a0d58c314b0d8302c44722b74798b91e 100644 (file)
@@ -26,7 +26,6 @@
 //  Module : SMESH
 //
 #include "DriverMED_Family.h"
-#include "MED_Factory.hxx"
 
 #include <sstream>      
 
@@ -366,67 +365,6 @@ DriverMED_Family
   return aFamilies;
 }
 
-//=============================================================================
-/*!
- *  Create TFamilyInfo for this family
- */
-//=============================================================================
-MED::PFamilyInfo
-DriverMED_Family::GetFamilyInfo(const MED::PWrapper& theWrapper, 
-                                const MED::PMeshInfo& theMeshInfo) const
-{
-  ostringstream aStr;
-  aStr << "FAM_" << myId;
-  set<string>::const_iterator aGrIter = myGroupNames.begin();
-  for(; aGrIter != myGroupNames.end(); aGrIter++){
-    aStr << "_" << *aGrIter;
-  }
-  string aValue = aStr.str();
-  // PAL19785,0019867 - med forbids whitespace to be the last char in the name
-  int maxSize = MED::GetNOMLength();
-  int lastCharPos = min( maxSize, (int) aValue.size() ) - 1;
-  while ( isspace( aValue[ lastCharPos ] ))
-    aValue.resize( lastCharPos-- );
-
-  MED::PFamilyInfo anInfo;
-  if(myId == 0 || myGroupAttributVal == 0){
-    anInfo = theWrapper->CrFamilyInfo(theMeshInfo,
-                                      aValue,
-                                      myId,
-                                      myGroupNames);
-  }else{
-    MED::TStringVector anAttrDescs (1, "");  // 1 attribute with empty description,
-    MED::TIntVector anAttrIds (1, myId);        // Id=0,
-    MED::TIntVector anAttrVals (1, myGroupAttributVal);
-    anInfo = theWrapper->CrFamilyInfo(theMeshInfo,
-                                      aValue,
-                                      myId,
-                                      myGroupNames,
-                                      anAttrDescs,
-                                      anAttrIds,
-                                      anAttrVals);
-  }
-
-//  cout << endl;
-//  cout << "Groups: ";
-//  set<string>::iterator aGrIter = myGroupNames.begin();
-//  for (; aGrIter != myGroupNames.end(); aGrIter++)
-//  {
-//    cout << " " << *aGrIter;
-//  }
-//  cout << endl;
-//
-//  cout << "Elements: ";
-//  set<const SMDS_MeshElement *>::iterator anIter = myElements.begin();
-//  for (; anIter != myElements.end(); anIter++)
-//  {
-//    cout << " " << (*anIter)->GetID();
-//  }
-//  cout << endl;
-
-  return anInfo;
-}
-
 //=============================================================================
 /*!
  *  Initialize the tool by SMESHDS_GroupBase
index d102b87a9ffa791080f1876de566e1f7e87e2512..bdbf843013546ae7804e20ca10646eff994ebafc 100644 (file)
@@ -91,9 +91,10 @@ class MESHDRIVERMED_EXPORT DriverMED_Family
                 const bool doAllInGroups);
 
   //! Create TFamilyInfo for this family
+  template<class LowLevelWriter>
   MED::PFamilyInfo 
-  GetFamilyInfo (const MED::PWrapper& theWrapper, 
-                 const MED::PMeshInfo& theMeshInfo) const;
+  GetFamilyInfo(const LowLevelWriter& theWrapper, 
+                const MED::PMeshInfo& theMeshInfo) const;
 
   //! Returns elements of this family
   const ElementsSet& GetElements () const;
@@ -154,4 +155,70 @@ class MESHDRIVERMED_EXPORT DriverMED_Family
   ElemTypeSet         myTypes; // Issue 0020576
 };
 
+#include "MED_Factory.hxx"
+
+#include <set>
+#include <string>
+//=============================================================================
+/*!
+ *  Create TFamilyInfo for this family
+ */
+//=============================================================================
+template<class LowLevelWriter>
+MED::PFamilyInfo
+DriverMED_Family::GetFamilyInfo(const LowLevelWriter& theWrapper, 
+                                const MED::PMeshInfo& theMeshInfo) const
+{
+  std::ostringstream aStr;
+  aStr << "FAM_" << myId;
+  std::set<std::string>::const_iterator aGrIter = myGroupNames.begin();
+  for(; aGrIter != myGroupNames.end(); aGrIter++){
+    aStr << "_" << *aGrIter;
+  }
+  std::string aValue = aStr.str();
+  // PAL19785,0019867 - med forbids whitespace to be the last char in the name
+  int maxSize = MED::GetNOMLength();
+  int lastCharPos = std::min( maxSize, (int) aValue.size() ) - 1;
+  while ( isspace( aValue[ lastCharPos ] ))
+    aValue.resize( lastCharPos-- );
+
+  MED::PFamilyInfo anInfo;
+  if(myId == 0 || myGroupAttributVal == 0){
+    anInfo = theWrapper->CrFamilyInfo(theMeshInfo,
+                                      aValue,
+                                      myId,
+                                      myGroupNames);
+  }else{
+    MED::TStringVector anAttrDescs (1, "");  // 1 attribute with empty description,
+    MED::TIntVector anAttrIds (1, myId);        // Id=0,
+    MED::TIntVector anAttrVals (1, myGroupAttributVal);
+    anInfo = theWrapper->CrFamilyInfo(theMeshInfo,
+                                      aValue,
+                                      myId,
+                                      myGroupNames,
+                                      anAttrDescs,
+                                      anAttrIds,
+                                      anAttrVals);
+  }
+
+//  cout << endl;
+//  cout << "Groups: ";
+//  set<string>::iterator aGrIter = myGroupNames.begin();
+//  for (; aGrIter != myGroupNames.end(); aGrIter++)
+//  {
+//    cout << " " << *aGrIter;
+//  }
+//  cout << endl;
+//
+//  cout << "Elements: ";
+//  set<const SMDS_MeshElement *>::iterator anIter = myElements.begin();
+//  for (; anIter != myElements.end(); anIter++)
+//  {
+//    cout << " " << (*anIter)->GetID();
+//  }
+//  cout << endl;
+
+  return anInfo;
+}
+
 #endif
index e7739b177ba433cff0ea87e4048a89c372dc8748..d09ce5713b43ab571fc0347b83e24fa2eef90d90 100644 (file)
@@ -30,6 +30,7 @@
 #include "DriverMED_Family.h"
 #include "MED_Factory.hxx"
 #include "MED_Utilities.hxx"
+#include "MEDCoupling_Wrapper.hxx"
 #include "SMDS_IteratorOnIterators.hxx"
 #include "SMDS_MeshNode.hxx"
 #include "SMDS_SetIterator.hxx"
@@ -343,13 +344,26 @@ namespace
   }
 }
 
+Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
+{
+  MED::PWrapper myMed = CrWrapperW(myFile, myVersion);
+  return this->PerformInternal<MED::PWrapper>(myMed);
+}
+
+Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::PerformMedcoupling()
+{
+  MED::MCPWrapper myMed(new MED::MCTWrapper);
+  return this->PerformInternal<MED::MCPWrapper>(myMed);
+}
+
 //================================================================================
 /*!
  * \brief Write my mesh
  */
 //================================================================================
 
-Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
+template<class LowLevelWriter>
+Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::PerformInternal(LowLevelWriter myMed)
 {
   Status aResult = DRS_OK;
   try {
@@ -471,7 +485,6 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
       }
     }
 
-    MED::PWrapper myMed = CrWrapperW(myFile, myVersion);
     PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
     //MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
     myMed->SetMeshInfo(aMeshInfo);
@@ -532,7 +545,7 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
     list<DriverMED_FamilyPtr>::iterator aFamsIter;
     for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
     {
-      PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
+      PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo<LowLevelWriter>(myMed,aMeshInfo);
       myMed->SetFamilyInfo(aFamilyInfo);
     }
 
index 96196aa752ef36e3e9a38877120d1f92eee9a523..986a70c575bdacb725b80dfbbf894e49241096ca 100644 (file)
@@ -76,6 +76,11 @@ class MESHDRIVERMED_EXPORT DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh
    */
   virtual Status Perform();
 
+  Status PerformMedcoupling();
+
+  template<class LowLevelWriter>
+  Driver_Mesh::Status PerformInternal(LowLevelWriter myMed);
+
  private:
 
   std::list<SMESHDS_GroupBase*> myGroups;
diff --git a/src/MEDWrapper/MEDCoupling_Wrapper.hxx b/src/MEDWrapper/MEDCoupling_Wrapper.hxx
new file mode 100644 (file)
index 0000000..a7ef775
--- /dev/null
@@ -0,0 +1,168 @@
+// Copyright (C) 2021  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#pragma once
+
+#include "MED_Wrapper.hxx"
+
+#include "med.h"
+
+#include <memory>
+
+namespace MED
+{
+  class MEDWRAPPER_EXPORT MCTWrapper
+  {
+    public:
+      //! Create a MEDWrapper MED Mesh representation
+    PMeshInfo
+    CrMeshInfo(TInt theDim = 0,
+               TInt theSpaceDim = 0,
+               const std::string& theValue = "",
+               EMaillage theType = eNON_STRUCTURE,
+               const std::string& theDesc = "");
+    //! Write the MEDWrapper MED Mesh representation into the MED file
+    void
+    SetMeshInfo(const TMeshInfo& theInfo,
+                TErr* theErr = NULL);
+    //! Write a MEDWrapper MED Family representation into the MED file
+    void
+    SetFamilyInfo(const TFamilyInfo& theInfo,
+                  TErr* theErr = NULL);
+    //! Create a MEDWrapper MED Nodes representation
+    PNodeInfo
+    CrNodeInfo(const PMeshInfo& theMeshInfo,
+               TInt theNbElem,
+               EModeSwitch theMode = eFULL_INTERLACE,
+               ERepere theSystem = eCART,
+               EBooleen theIsElemNum = eVRAI,
+               EBooleen theIsElemNames = eFAUX);
+    //! Write the MEDWrapper MED Nodes representation into the MED file
+    void
+    SetNodeInfo(const TNodeInfo& theInfo,
+                TErr* theErr = NULL);
+                
+    //! Read a MEDWrapper MED Family representation by its numbers
+    void
+    GetFamilyInfo(TInt theFamId,
+                  TFamilyInfo& theInfo,
+                  TErr* theErr = NULL);
+                  
+    //! Create a MEDWrapper MED Family representation
+    PFamilyInfo
+    CrFamilyInfo(const PMeshInfo& theMeshInfo,
+                 const std::string& theValue,
+                 TInt theId,
+                 const TStringSet& theGroupNames,
+                 const TStringVector& theAttrDescs = TStringVector(),
+                 const TIntVector& theAttrIds = TIntVector(),
+                 const TIntVector& theAttrVals = TIntVector());
+    
+    //! Create a MEDWrapper MED Polygones representation
+    virtual
+    PPolygoneInfo
+    CrPolygoneInfo(const PMeshInfo& theMeshInfo,
+                   EEntiteMaillage theEntity,
+                   EGeometrieElement theGeom,
+                   TInt theNbElem,
+                   TInt theConnSize,
+                   EConnectivite theConnMode = eNOD,
+                   EBooleen theIsElemNum = eVRAI,
+                   EBooleen theIsElemNames = eVRAI);
+    
+    //! Create a MEDWrapper MED Polygones representation
+    virtual
+    PPolygoneInfo
+    CrPolygoneInfo(const PMeshInfo& theMeshInfo,
+                   EEntiteMaillage theEntity,
+                   EGeometrieElement theGeom,
+                   const TIntVector& theIndexes,
+                   const TIntVector& theConnectivities,
+                   EConnectivite theConnMode = eNOD,
+                   const TIntVector& theFamilyNums = TIntVector(),
+                   const TIntVector& theElemNums = TIntVector(),
+                   const TStringVector& theElemNames = TStringVector());
+                   
+                   
+    //! Write a MEDWrapper MED Polygones representation into the MED file
+    virtual
+    void
+    SetPolygoneInfo(const TPolygoneInfo& theInfo,
+                    TErr* theErr = NULL);
+    
+
+        //! Create a MEDWrapper MED Polyedres representation
+    virtual
+    PPolyedreInfo
+    CrPolyedreInfo(const PMeshInfo& theMeshInfo,
+                   EEntiteMaillage theEntity,
+                   EGeometrieElement theGeom,
+                   TInt theNbElem,
+                   TInt theNbFaces,
+                   TInt theConnSize,
+                   EConnectivite theConnMode = eNOD,
+                   EBooleen theIsElemNum = eVRAI,
+                   EBooleen theIsElemNames = eVRAI);
+                   
+                   
+    //! Write a MEDWrapper MED Polyedres representation into the MED file
+    virtual
+    void
+    SetPolyedreInfo(const TPolyedreInfo& theInfo,
+                    TErr* theErr = NULL);
+                    
+                    
+    //! Create a MEDWrapper MED Balls representation
+    /*! This feature is supported since version 3.0 */
+    virtual
+    PBallInfo
+    CrBallInfo(const PMeshInfo& theMeshInfo,
+               TInt theNbBalls,
+               EBooleen theIsElemNum = eVRAI);
+
+    //! Write a MEDWrapper representation of MED_BALL into the MED file
+    /*! This feature is supported since version 3.0 */
+    virtual
+    void
+    SetBallInfo(const TBallInfo& theInfo,
+                TErr* theErr = NULL);
+
+    
+    //! Create a MEDWrapper MED Cells representation
+    virtual
+    PCellInfo
+    CrCellInfo(const PMeshInfo& theMeshInfo,
+               EEntiteMaillage theEntity,
+               EGeometrieElement theGeom,
+               TInt theNbElem,
+               EConnectivite theConnMode = eNOD,
+               EBooleen theIsElemNum = eVRAI,
+               EBooleen theIsElemNames = eFAUX,
+               EModeSwitch theMode = eFULL_INTERLACE);
+
+    //! Write the MEDWrapper MED Cells representation into the MED file
+    virtual
+    void
+    SetCellInfo(const TCellInfo& theInfo,
+                TErr* theErr = NULL);
+    
+  };
+
+  using MCPWrapper = std::shared_ptr<MCTWrapper>;
+}
index bc73c9dd997921069e5101b42606248faf6e806c..7b28dcbd6d4c38076411b29e4581232824625b6c 100644 (file)
@@ -33,7 +33,7 @@ namespace MED
 {
   //----------------------------------------------------------------------------
   class TFile;
-  typedef boost::shared_ptr<TFile> PFile;
+  typedef std::shared_ptr<TFile> PFile;
 
   typedef enum {eLECTURE, eLECTURE_ECRITURE, eLECTURE_AJOUT, eCREATION} EModeAcces;
 
@@ -963,23 +963,23 @@ namespace MED
   //----------------------------------------------------------------------------
   //! Specialization of SharedPtr for TWrapper
   template<>
-  class MEDWRAPPER_EXPORT SharedPtr<TWrapper>: public boost::shared_ptr<TWrapper>
+  class MEDWRAPPER_EXPORT SharedPtr<TWrapper>: public std::shared_ptr<TWrapper>
   {
   public:
     SharedPtr() {}
 
     SharedPtr(TWrapper* p):
-      boost::shared_ptr<TWrapper>(p)
+      std::shared_ptr<TWrapper>(p)
     {}
 
     template<class Y>
     explicit SharedPtr(Y* p):
-      boost::shared_ptr<TWrapper>(p)
+      std::shared_ptr<TWrapper>(p)
     {}
 
     template<class Y>
     SharedPtr(const SharedPtr<Y>& r):
-      boost::shared_ptr<TWrapper>(boost::dynamic_pointer_cast<TWrapper,Y>(r))
+      std::shared_ptr<TWrapper>(boost::dynamic_pointer_cast<TWrapper,Y>(r))
     {}
 
     template<class Y>
@@ -1021,7 +1021,7 @@ namespace MED
     TWrapper*
     get() const // never throws
     {
-      return boost::shared_ptr<TWrapper>::get();
+      return std::shared_ptr<TWrapper>::get();
     }
   };
 }