From 9bd2dd723e8d6b4b1ad2e471d625361561f5cc47 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Mon, 26 Apr 2021 21:53:20 +0200 Subject: [PATCH] Tentative d externalisation en medcoupling memoire --- src/DriverMED/DriverMED_Family.cxx | 62 -------- src/DriverMED/DriverMED_Family.h | 71 ++++++++- src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx | 19 ++- src/DriverMED/DriverMED_W_SMESHDS_Mesh.h | 5 + src/MEDWrapper/MEDCoupling_Wrapper.hxx | 168 +++++++++++++++++++++ src/MEDWrapper/MED_Wrapper.hxx | 12 +- 6 files changed, 264 insertions(+), 73 deletions(-) create mode 100644 src/MEDWrapper/MEDCoupling_Wrapper.hxx diff --git a/src/DriverMED/DriverMED_Family.cxx b/src/DriverMED/DriverMED_Family.cxx index 2acd6a826..f5b00968a 100644 --- a/src/DriverMED/DriverMED_Family.cxx +++ b/src/DriverMED/DriverMED_Family.cxx @@ -26,7 +26,6 @@ // Module : SMESH // #include "DriverMED_Family.h" -#include "MED_Factory.hxx" #include @@ -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::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::iterator aGrIter = myGroupNames.begin(); -// for (; aGrIter != myGroupNames.end(); aGrIter++) -// { -// cout << " " << *aGrIter; -// } -// cout << endl; -// -// cout << "Elements: "; -// set::iterator anIter = myElements.begin(); -// for (; anIter != myElements.end(); anIter++) -// { -// cout << " " << (*anIter)->GetID(); -// } -// cout << endl; - - return anInfo; -} - //============================================================================= /*! * Initialize the tool by SMESHDS_GroupBase diff --git a/src/DriverMED/DriverMED_Family.h b/src/DriverMED/DriverMED_Family.h index d102b87a9..bdbf84301 100644 --- a/src/DriverMED/DriverMED_Family.h +++ b/src/DriverMED/DriverMED_Family.h @@ -91,9 +91,10 @@ class MESHDRIVERMED_EXPORT DriverMED_Family const bool doAllInGroups); //! Create TFamilyInfo for this family + template 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 +#include +//============================================================================= +/*! + * Create TFamilyInfo for this family + */ +//============================================================================= +template +MED::PFamilyInfo +DriverMED_Family::GetFamilyInfo(const LowLevelWriter& theWrapper, + const MED::PMeshInfo& theMeshInfo) const +{ + std::ostringstream aStr; + aStr << "FAM_" << myId; + std::set::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::iterator aGrIter = myGroupNames.begin(); +// for (; aGrIter != myGroupNames.end(); aGrIter++) +// { +// cout << " " << *aGrIter; +// } +// cout << endl; +// +// cout << "Elements: "; +// set::iterator anIter = myElements.begin(); +// for (; anIter != myElements.end(); anIter++) +// { +// cout << " " << (*anIter)->GetID(); +// } +// cout << endl; + + return anInfo; +} + #endif diff --git a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx index e7739b177..d09ce5713 100644 --- a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx +++ b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx @@ -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(myMed); +} + +Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::PerformMedcoupling() +{ + MED::MCPWrapper myMed(new MED::MCTWrapper); + return this->PerformInternal(myMed); +} + //================================================================================ /*! * \brief Write my mesh */ //================================================================================ -Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() +template +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 : "<GetName()); myMed->SetMeshInfo(aMeshInfo); @@ -532,7 +545,7 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() list::iterator aFamsIter; for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++) { - PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo); + PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo); myMed->SetFamilyInfo(aFamilyInfo); } diff --git a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h index 96196aa75..986a70c57 100644 --- a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h +++ b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.h @@ -76,6 +76,11 @@ class MESHDRIVERMED_EXPORT DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh */ virtual Status Perform(); + Status PerformMedcoupling(); + + template + Driver_Mesh::Status PerformInternal(LowLevelWriter myMed); + private: std::list myGroups; diff --git a/src/MEDWrapper/MEDCoupling_Wrapper.hxx b/src/MEDWrapper/MEDCoupling_Wrapper.hxx new file mode 100644 index 000000000..a7ef7759d --- /dev/null +++ b/src/MEDWrapper/MEDCoupling_Wrapper.hxx @@ -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 + +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; +} diff --git a/src/MEDWrapper/MED_Wrapper.hxx b/src/MEDWrapper/MED_Wrapper.hxx index bc73c9dd9..7b28dcbd6 100644 --- a/src/MEDWrapper/MED_Wrapper.hxx +++ b/src/MEDWrapper/MED_Wrapper.hxx @@ -33,7 +33,7 @@ namespace MED { //---------------------------------------------------------------------------- class TFile; - typedef boost::shared_ptr PFile; + typedef std::shared_ptr 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: public boost::shared_ptr + class MEDWRAPPER_EXPORT SharedPtr: public std::shared_ptr { public: SharedPtr() {} SharedPtr(TWrapper* p): - boost::shared_ptr(p) + std::shared_ptr(p) {} template explicit SharedPtr(Y* p): - boost::shared_ptr(p) + std::shared_ptr(p) {} template SharedPtr(const SharedPtr& r): - boost::shared_ptr(boost::dynamic_pointer_cast(r)) + std::shared_ptr(boost::dynamic_pointer_cast(r)) {} template @@ -1021,7 +1021,7 @@ namespace MED TWrapper* get() const // never throws { - return boost::shared_ptr::get(); + return std::shared_ptr::get(); } }; } -- 2.39.2