Salome HOME
Revert "Synchronize adm files"
[modules/med.git] / src / MEDLoader / MEDFileMeshLL.hxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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<const BigMemoryObject *> getDirectChildrenWithNull() 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 std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim);
55     static int GetMeshIdFromName(med_idt fid, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1);
56     static double CheckMeshTimeStep(med_idt fid, const std::string& mname, int nstep, int dt, int it);
57     static void ReadFamiliesAndGrps(med_idt fid, const std::string& 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 std::string& 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 std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs);
74     void loadConnectivity(med_idt fid, int mdim, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs);
75     void loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it);
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 std::string& 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 std::string& mName, int dt, int it);
106     MEDCouplingCMesh *getMesh() { return _cmesh; }
107   private:
108     static med_data_type GetDataTypeCorrespondingToSpaceId(int id);
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 std::string& mName, int dt, int it);
118     MEDCouplingCurveLinearMesh *getMesh() { return _clmesh; }
119   private:
120     MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> _clmesh;
121   };
122
123   class MEDFileMesh;
124   class MEDFileUMeshSplitL1;
125
126   class MEDFileUMeshPermCompute : public BigMemoryObject
127   {
128   public:
129     MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st);
130     operator MEDCouplingUMesh *() const;
131     void operator=(MEDCouplingUMesh *m);
132     void updateTime() const;
133     std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
134     std::size_t getHeapMemorySizeWithoutChildren() const;
135   private:
136     const MEDFileUMeshSplitL1 *_st;
137     mutable std::size_t _mpt_time;
138     mutable std::size_t _num_time;
139     mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
140   };
141
142   class MEDFileUMeshAggregateCompute : public BigMemoryObject
143   {
144   public:
145     MEDFileUMeshAggregateCompute();
146     void setName(const std::string& name);
147     void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts);
148     void assignUMesh(MEDCouplingUMesh *m);
149     MEDCouplingUMesh *getUmesh() const;
150     std::vector<MEDCoupling1GTUMesh *> getParts() const;
151     std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes() const;
152     std::vector<MEDCoupling1GTUMesh *> getPartsWithoutComputation() const;
153     MEDCoupling1GTUMesh *getPartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const;
154     void getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, int& start, int& stop) const;
155     std::size_t getTimeOfThis() const;
156     std::size_t getHeapMemorySizeWithoutChildren() const;
157     std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
158     MEDFileUMeshAggregateCompute deepCpy(DataArrayDouble *coords) const;
159     bool isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const;
160     void clearNonDiscrAttributes() const;
161     void synchronizeTinyInfo(const MEDFileMesh& master) const;
162     bool empty() const;
163     int getMeshDimension() const;
164     std::vector<int> getDistributionOfTypes() const;
165     int getSize() const;
166     void setCoords(DataArrayDouble *coords);
167     void forceComputationOfPartsFromUMesh() const;
168   private:
169     std::size_t getTimeOfParts() const;
170     std::size_t getTimeOfUMesh() const;
171   private:
172     mutable std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> > _m_parts;
173     mutable std::size_t _mp_time;
174     mutable std::size_t _m_time;
175     mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
176   };
177
178   class MEDFileUMeshSplitL1 : public RefCountObject
179   {
180     friend class MEDFileUMeshPermCompute;
181   public:
182     MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other);
183     MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::string& mName, int id);
184     MEDFileUMeshSplitL1(MEDCoupling1GTUMesh *m);
185     MEDFileUMeshSplitL1(MEDCouplingUMesh *m);
186     MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld);
187     void setName(const std::string& name);
188     std::size_t getHeapMemorySizeWithoutChildren() const;
189     std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
190     MEDFileUMeshSplitL1 *deepCpy(DataArrayDouble *coords) const;
191     void setCoords(DataArrayDouble *coords);
192     bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const;
193     void clearNonDiscrAttributes() const;
194     void synchronizeTinyInfo(const MEDFileMesh& master) const;
195     void assignMesh(MEDCouplingUMesh *m, bool newOrOld);
196     void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts);
197     void forceComputationOfParts() const;
198     bool empty() const;
199     bool presenceOfOneFams(const std::vector<int>& ids) const;
200     int getMeshDimension() const;
201     void simpleRepr(std::ostream& oss) const;
202     int getSize() const;
203     MEDCouplingUMesh *getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const;
204     DataArrayInt *getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const;
205     MEDCouplingUMesh *getWholeMesh(bool renum) const;
206     std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes() const;
207     std::vector<MEDCoupling1GTUMesh *> getDirectUndergroundSingleGeoTypeMeshes() const { return _m_by_types.getPartsWithoutComputation(); }
208     MEDCoupling1GTUMesh *getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const { return _m_by_types.getPartWithoutComputation(gt); }
209     DataArrayInt *extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const;
210     DataArrayInt *extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const;
211     std::vector<int> getDistributionOfTypes() const { return _m_by_types.getDistributionOfTypes(); }
212     DataArrayInt *getOrCreateAndGetFamilyField();
213     const DataArrayInt *getFamilyField() const;
214     const DataArrayInt *getNumberField() const;
215     const DataArrayAsciiChar *getNameField() const;
216     const DataArrayInt *getRevNumberField() const;
217     void eraseFamilyField();
218     void setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
219                               std::map<std::string, std::vector<std::string> >& groups);
220     void write(med_idt fid, const std::string& mName, int mdim) const;
221     //
222     void setFamilyArr(DataArrayInt *famArr);
223     void setRenumArr(DataArrayInt *renumArr);
224     void setNameArr(DataArrayAsciiChar *nameArr);
225     void changeFamilyIdArr(int oldId, int newId);
226     //
227     void renumberNodesInConn(const int *newNodeNumbersO2N);
228     //
229     static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp);
230     static std::vector<int> GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
231     static void TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
232                                     std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
233     static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da);
234     static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds);
235   private:
236     void assignCommonPart();
237     MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
238     DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const;
239     void computeRevNum() const;
240   private:
241     MEDFileUMeshAggregateCompute _m_by_types;
242     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
243     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
244     MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _names;
245     mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num;
246     MEDFileUMeshPermCompute _m;
247   };
248 }
249
250 #endif