Salome HOME
Modification of the getHeapMemorySize computation.
[tools/medcoupling.git] / src / MEDLoader / SauvWriter.hxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File      : SauvWriter.hxx
20 // Created   : Wed Aug 24 11:18:49 2011
21 // Author    : Edward AGAPOV (eap)
22
23 #ifndef __SAUVWRITER_HXX__
24 #define __SAUVWRITER_HXX__
25
26 #include "MEDLoaderDefines.hxx"
27 #include "MEDCouplingRefCountObject.hxx"
28 #include "NormalizedUnstructuredMesh.hxx"
29 #include "SauvUtilities.hxx"
30 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
31
32 #include <vector>
33 #include <string>
34 #include <map>
35
36 namespace ParaMEDMEM
37 {
38   class MEDFileData;
39   class MEDFileMesh;
40   class MEDFileFieldMultiTS;
41   class DataArrayInt;
42
43   /*!
44    * \brief Class to write a MEDFileData into a SAUVE format file
45    */
46   class MEDLOADER_EXPORT SauvWriter : public ParaMEDMEM::RefCountObject
47   {
48   public:
49     static SauvWriter * New();
50     void setMEDFileDS(const MEDFileData* medData, unsigned meshIndex = 0);
51     void write(const char* fileName);
52
53   private:
54     std::size_t getHeapMemorySizeWithoutChildren() const;
55     std::vector<RefCountObject *> getDirectChildren() const;
56     /*!
57      * \brief Class representing a GIBI sub-mesh (described in the pile 1 of the SAUVE file).
58      * It stands for a named med sub-mesh (family, etc) and contains either cell IDs or other sub-meshes. 
59      */
60     struct SubMesh
61     {
62       std::vector<int>      _cellIDsByType[ INTERP_KERNEL::NORM_MAXTYPE+1 ];
63       std::vector<SubMesh*> _subs;
64       std::string           _name;
65       int                   _id;
66       int                   _nbSauvObjects;
67       int                   _dimRelExt;
68       int nbTypes() const;
69       static int cellIDsByTypeSize() { return INTERP_KERNEL::NORM_MAXTYPE+1; }
70     };
71     SubMesh* addSubMesh(const std::string& name, int dimRelExt);
72
73     void fillSubMeshes(int& nbSauvObjects, std::map<std::string,int>& nameNbMap);
74     void fillFamilySubMeshes();
75     void fillGroupSubMeshes();
76     void fillProfileSubMeshes();
77     int evaluateNbProfileSubMeshes() const;
78     void makeCompNames(const std::string&                  fieldName,
79                        const std::vector<std::string>&     compInfo,
80                        std::map<std::string, std::string>& compMedToGibi );
81     void makeProfileIDs( SubMesh*                          sm,
82                          INTERP_KERNEL::NormalizedCellType type,
83                          const DataArrayInt*               profile );
84     void writeFileHead();
85     void writeSubMeshes();
86     void writeCompoundSubMesh(int iSub);
87     void writeNodes();
88     void writeLongNames();
89     void writeNodalFields(std::map<std::string,int>& fldNamePrefixMap);
90     void writeElemFields(std::map<std::string,int>& fldNamePrefixMap);
91     void writeFieldNames(const bool isNodal, std::map<std::string,int>& fldNamePrefixMap);
92     void writeElemTimeStamp(int iF, int iter, int order);
93     void writeLastRecord();
94     void writeNames( const std::map<std::string,int>& nameNbMap );
95
96   private:
97
98     MEDCouplingAutoRefCountObjectPtr< MEDFileMesh >                        _fileMesh;
99     std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTS > > _nodeFields;
100     std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldMultiTS > > _cellFields;
101
102     std::vector<SubMesh>                      _subs;
103     std::map< int, SubMesh* >                 _famIDs2Sub;
104     std::map< std::string, SubMesh* >         _profile2Sub;
105     enum
106       {
107         LN_MAIL=0, LN_CHAM, LN_COMP, LN_NB
108       };
109     std::vector<SauvUtilities::nameGIBItoMED> _longNames[ LN_NB ];
110
111     std::fstream*                             _sauvFile;
112   };
113 }
114
115 #endif