Salome HOME
MED file mesh loading on demand.
[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 "MEDCouplingCurveLinearMesh.hxx"
30 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
31
32 #include "med.h"
33
34 #include <map>
35
36 namespace ParaMEDMEM
37 {
38   class MEDFileMeshReadSelector;
39   
40   class MEDFileMeshL2 : public RefCountObject
41   {
42   public:
43     MEDFileMeshL2();
44     std::size_t getHeapMemorySize() const { return 0; }
45     const char *getName() const { return _name.getReprForWrite(); }
46     const char *getDescription() const { return _description.getReprForWrite(); }
47     const char *getUnivName() const { return _univ_name.getReprForWrite(); }
48     const char *getTimeUnit() const { return _dt_unit.getReprForWrite(); }
49     int getIteration() const { return _iteration; }
50     int getOrder() const { return _order; }
51     double getTime() { return _time; }
52     std::vector<std::string> getAxisInfoOnMesh(med_idt fid, int mId, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim) throw(INTERP_KERNEL::Exception);
53     static int GetMeshIdFromName(med_idt fid, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1) throw(INTERP_KERNEL::Exception);
54     static double CheckMeshTimeStep(med_idt fid, const char *mname, int nstep, int dt, int it) throw(INTERP_KERNEL::Exception);
55     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);
56     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);
57   protected:
58     MEDFileString _name;
59     MEDFileString _description;
60     MEDFileString _univ_name;
61     MEDFileString _dt_unit;
62     int _iteration;
63     int _order;
64     double _time;
65   };
66
67   class MEDFileUMeshL2 : public MEDFileMeshL2
68   {
69   public:
70     MEDFileUMeshL2();
71     void loadAll(med_idt fid, int mId, const char *mName, int dt, int it, MEDFileMeshReadSelector *mrs);
72     void loadConnectivity(med_idt fid, int mdim, const char *mName, int dt, int it, MEDFileMeshReadSelector *mrs);
73     void loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
74     int getNumberOfLevels() const { return _per_type_mesh.size(); }
75     bool emptyLev(int levId) const { return _per_type_mesh[levId].empty(); }
76     const std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& getLev(int levId) const { return _per_type_mesh[levId]; }
77     bool isFamDefinedOnLev(int levId) const;
78     bool isNumDefinedOnLev(int levId) const;
79     bool isNamesDefinedOnLev(int levId) const;
80     MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> getCoords() const { return _coords; }
81     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsFamily() const { return _fam_coords; }
82     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsNum() const { return _num_coords; }
83     MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> getCoordsName() const { return _name_coords; }
84     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);
85   private:
86     void sortTypes();
87   private:
88     std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > > _per_type_mesh;
89     MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
90     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_coords;
91     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
92     MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _name_coords;
93   };
94
95   class MEDFileStrMeshL2 : public MEDFileMeshL2
96   {
97   };
98
99   class MEDFileCMeshL2 : public MEDFileStrMeshL2
100   {
101   public:
102     MEDFileCMeshL2();
103     void loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
104     MEDCouplingCMesh *getMesh() { return _cmesh; }
105   private:
106     static med_data_type GetDataTypeCorrespondingToSpaceId(int id) throw(INTERP_KERNEL::Exception);
107   private:
108     MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> _cmesh;
109   };
110   
111   class MEDFileCLMeshL2 : public MEDFileStrMeshL2
112   {
113   public:
114     MEDFileCLMeshL2();
115     void loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
116     MEDCouplingCurveLinearMesh *getMesh() { return _clmesh; }
117   private:
118     MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> _clmesh;
119   };
120
121   class MEDFileMesh;
122   class MEDFileUMeshSplitL1;
123
124   class MEDFileUMeshPermCompute
125   {
126   public:
127     MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st);
128     operator MEDCouplingUMesh *() const;
129     void operator=(MEDCouplingUMesh *m);
130     void updateTime() const;
131   private:
132     const MEDFileUMeshSplitL1 *_st;
133     mutable unsigned int _mpt_time;
134     mutable unsigned int _num_time;
135     mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
136   };
137
138   class MEDFileUMeshSplitL1 : public RefCountObject
139   {
140     friend class MEDFileUMeshPermCompute;
141   public:
142     MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other);
143     MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id);
144     MEDFileUMeshSplitL1(MEDCouplingUMesh *m);
145     MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld);
146     std::size_t getHeapMemorySize() const;
147     MEDFileUMeshSplitL1 *deepCpy() const;
148     bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const;
149     void clearNonDiscrAttributes() const;
150     void synchronizeTinyInfo(const MEDFileMesh& master) const;
151     void assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception);
152     bool empty() const;
153     bool presenceOfOneFams(const std::vector<int>& ids) const;
154     int getMeshDimension() const;
155     void simpleRepr(std::ostream& oss) const;
156     int getSize() const throw(INTERP_KERNEL::Exception);
157     MEDCouplingUMesh *getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const;
158     DataArrayInt *getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const;
159     MEDCouplingUMesh *getWholeMesh(bool renum) const;
160     DataArrayInt *getOrCreateAndGetFamilyField() throw(INTERP_KERNEL::Exception);
161     const DataArrayInt *getFamilyField() const;
162     const DataArrayInt *getNumberField() const;
163     const DataArrayAsciiChar *getNameField() const;
164     const DataArrayInt *getRevNumberField() const;
165     void eraseFamilyField();
166     void setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
167                               std::map<std::string, std::vector<std::string> >& groups) throw(INTERP_KERNEL::Exception);
168     void write(med_idt fid, const char *mName, int mdim) const;
169     //
170     void setFamilyArr(DataArrayInt *famArr);
171     void setRenumArr(DataArrayInt *renumArr);
172     void setNameArr(DataArrayAsciiChar *nameArr);
173     void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception);
174     //
175     void renumberNodesInConn(const int *newNodeNumbersO2N) throw(INTERP_KERNEL::Exception);
176     //
177     static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp);
178     static std::vector<int> GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
179     static void TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
180                                     std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
181     static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da);
182     static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds);
183   private:
184     MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
185     DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const;
186     void computeRevNum() const;
187   private:
188     MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m_by_types;
189     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
190     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
191     MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _names;
192     mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num;
193     MEDFileUMeshPermCompute _m;
194   };
195 }
196
197 #endif