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