Salome HOME
Modification of the getHeapMemorySize computation.
[modules/med.git] / src / MEDLoader / MEDFileMeshLL.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 // Author : Anthony Geay (CEA/DEN)
20
21 #ifndef __MEDFILEMESHLL_HXX__
22 #define __MEDFILEMESHLL_HXX__
23
24 #include "MEDFileBasis.hxx"
25 #include "MEDFileMeshElt.hxx"
26
27 #include "MEDCouplingUMesh.hxx"
28 #include "MEDCouplingCMesh.hxx"
29 #include "MEDCoupling1GTUMesh.hxx"
30 #include "MEDCouplingCurveLinearMesh.hxx"
31 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
32
33 #include "med.h"
34
35 #include <map>
36
37 namespace ParaMEDMEM
38 {
39   class MEDFileMeshReadSelector;
40   
41   class MEDFileMeshL2 : public RefCountObject
42   {
43   public:
44     MEDFileMeshL2();
45     std::size_t getHeapMemorySizeWithoutChildren() const;
46     std::vector<RefCountObject *> getDirectChildren() const;
47     const char *getName() const { return _name.getReprForWrite(); }
48     const char *getDescription() const { return _description.getReprForWrite(); }
49     const char *getUnivName() const { return _univ_name.getReprForWrite(); }
50     const char *getTimeUnit() const { return _dt_unit.getReprForWrite(); }
51     int getIteration() const { return _iteration; }
52     int getOrder() const { return _order; }
53     double getTime() { return _time; }
54     std::vector<std::string> getAxisInfoOnMesh(med_idt fid, int mId, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim) throw(INTERP_KERNEL::Exception);
55     static int GetMeshIdFromName(med_idt fid, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1) throw(INTERP_KERNEL::Exception);
56     static double CheckMeshTimeStep(med_idt fid, const char *mname, int nstep, int dt, int it) throw(INTERP_KERNEL::Exception);
57     static void ReadFamiliesAndGrps(med_idt fid, const char *mname, std::map<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps, MEDFileMeshReadSelector *mrs);
58     static void WriteFamiliesAndGrps(med_idt fid, const char *mname, const std::map<std::string,int>& fams, const std::map<std::string, std::vector<std::string> >& grps, int tooLongStrPol);
59   protected:
60     MEDFileString _name;
61     MEDFileString _description;
62     MEDFileString _univ_name;
63     MEDFileString _dt_unit;
64     int _iteration;
65     int _order;
66     double _time;
67   };
68
69   class MEDFileUMeshL2 : public MEDFileMeshL2
70   {
71   public:
72     MEDFileUMeshL2();
73     void loadAll(med_idt fid, int mId, const char *mName, int dt, int it, MEDFileMeshReadSelector *mrs);
74     void loadConnectivity(med_idt fid, int mdim, const char *mName, int dt, int it, MEDFileMeshReadSelector *mrs);
75     void loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
76     int getNumberOfLevels() const { return _per_type_mesh.size(); }
77     bool emptyLev(int levId) const { return _per_type_mesh[levId].empty(); }
78     const std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& getLev(int levId) const { return _per_type_mesh[levId]; }
79     bool isFamDefinedOnLev(int levId) const;
80     bool isNumDefinedOnLev(int levId) const;
81     bool isNamesDefinedOnLev(int levId) const;
82     MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> getCoords() const { return _coords; }
83     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsFamily() const { return _fam_coords; }
84     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsNum() const { return _num_coords; }
85     MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> getCoordsName() const { return _name_coords; }
86     static void WriteCoords(med_idt fid, const char *mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords, const DataArrayAsciiChar *nameCoords);
87   private:
88     void sortTypes();
89   private:
90     std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > > _per_type_mesh;
91     MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
92     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_coords;
93     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
94     MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _name_coords;
95   };
96
97   class MEDFileStrMeshL2 : public MEDFileMeshL2
98   {
99   };
100
101   class MEDFileCMeshL2 : public MEDFileStrMeshL2
102   {
103   public:
104     MEDFileCMeshL2();
105     void loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
106     MEDCouplingCMesh *getMesh() { return _cmesh; }
107   private:
108     static med_data_type GetDataTypeCorrespondingToSpaceId(int id) throw(INTERP_KERNEL::Exception);
109   private:
110     MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> _cmesh;
111   };
112   
113   class MEDFileCLMeshL2 : public MEDFileStrMeshL2
114   {
115   public:
116     MEDFileCLMeshL2();
117     void loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
118     MEDCouplingCurveLinearMesh *getMesh() { return _clmesh; }
119   private:
120     MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> _clmesh;
121   };
122
123   class MEDFileMesh;
124   class MEDFileUMeshSplitL1;
125
126   class MEDFileUMeshPermCompute
127   {
128   public:
129     MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st);
130     operator MEDCouplingUMesh *() const;
131     void operator=(MEDCouplingUMesh *m);
132     void updateTime() const;
133   private:
134     const MEDFileUMeshSplitL1 *_st;
135     mutable std::size_t _mpt_time;
136     mutable std::size_t _num_time;
137     mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
138   };
139
140   class MEDFileUMeshAggregateCompute : public RefCountObject
141   {
142   public:
143     MEDFileUMeshAggregateCompute();
144     void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts);
145     void assignUMesh(MEDCouplingUMesh *m);
146     MEDCouplingUMesh *getUmesh() const;
147     std::vector<MEDCoupling1GTUMesh *> getParts() const;
148     std::vector<MEDCoupling1GTUMesh *> getPartsWithoutComputation() const throw(INTERP_KERNEL::Exception);
149     MEDCoupling1GTUMesh *getPartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const throw(INTERP_KERNEL::Exception);
150     std::size_t getTimeOfThis() const;
151     std::size_t getHeapMemorySizeWithoutChildren() const;
152     std::vector<RefCountObject *> getDirectChildren() const;
153     MEDFileUMeshAggregateCompute deepCpy(DataArrayDouble *coords) const;
154     bool isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const;
155     void clearNonDiscrAttributes() const;
156     void synchronizeTinyInfo(const MEDFileMesh& master) const;
157     bool empty() const;
158     int getMeshDimension() const;
159     std::vector<int> getDistributionOfTypes() const throw(INTERP_KERNEL::Exception);
160     int getSize() const throw(INTERP_KERNEL::Exception);
161     void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception);
162   private:
163     void forceComputationOfPartsFromUMesh() const;
164     std::size_t getTimeOfParts() const;
165     std::size_t getTimeOfUMesh() const;
166   private:
167     mutable std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> > _m_parts;
168     mutable std::size_t _mp_time;
169     mutable std::size_t _m_time;
170     mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
171   };
172   
173   class MEDFileUMeshSplitL1 : public RefCountObject
174   {
175     friend class MEDFileUMeshPermCompute;
176   public:
177     MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other);
178     MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id);
179     MEDFileUMeshSplitL1(MEDCouplingUMesh *m);
180     MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld);
181     std::size_t getHeapMemorySizeWithoutChildren() const;
182     std::vector<RefCountObject *> getDirectChildren() const;
183     MEDFileUMeshSplitL1 *deepCpy(DataArrayDouble *coords) const;
184     void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception);
185     bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const;
186     void clearNonDiscrAttributes() const;
187     void synchronizeTinyInfo(const MEDFileMesh& master) const;
188     void assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception);
189     bool empty() const;
190     bool presenceOfOneFams(const std::vector<int>& ids) const;
191     int getMeshDimension() const;
192     void simpleRepr(std::ostream& oss) const;
193     int getSize() const throw(INTERP_KERNEL::Exception);
194     MEDCouplingUMesh *getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const;
195     DataArrayInt *getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const;
196     MEDCouplingUMesh *getWholeMesh(bool renum) const;
197     std::vector<MEDCoupling1GTUMesh *> getDirectUndergroundSingleGeoTypeMeshes() const throw(INTERP_KERNEL::Exception) { return _m_by_types.getPartsWithoutComputation(); }
198     MEDCoupling1GTUMesh *getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const throw(INTERP_KERNEL::Exception) { return _m_by_types.getPartWithoutComputation(gt); }
199     std::vector<int> getDistributionOfTypes() const throw(INTERP_KERNEL::Exception) { return _m_by_types.getDistributionOfTypes(); }
200     DataArrayInt *getOrCreateAndGetFamilyField() throw(INTERP_KERNEL::Exception);
201     const DataArrayInt *getFamilyField() const;
202     const DataArrayInt *getNumberField() const;
203     const DataArrayAsciiChar *getNameField() const;
204     const DataArrayInt *getRevNumberField() const;
205     void eraseFamilyField();
206     void setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
207                               std::map<std::string, std::vector<std::string> >& groups) throw(INTERP_KERNEL::Exception);
208     void write(med_idt fid, const char *mName, int mdim) const;
209     //
210     void setFamilyArr(DataArrayInt *famArr);
211     void setRenumArr(DataArrayInt *renumArr);
212     void setNameArr(DataArrayAsciiChar *nameArr);
213     void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception);
214     //
215     void renumberNodesInConn(const int *newNodeNumbersO2N) throw(INTERP_KERNEL::Exception);
216     //
217     static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp);
218     static std::vector<int> GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
219     static void TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
220                                     std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
221     static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da);
222     static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds);
223   private:
224     MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
225     DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const;
226     void computeRevNum() const;
227   private:
228     MEDFileUMeshAggregateCompute _m_by_types;
229     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
230     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
231     MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _names;
232     mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num;
233     MEDFileUMeshPermCompute _m;
234   };
235 }
236
237 #endif