Salome HOME
API modification : input string have type :
[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<const BigMemoryObject *> 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 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
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 BigMemoryObject
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<INTERP_KERNEL::NormalizedCellType> getGeoTypes() const;
149     std::vector<MEDCoupling1GTUMesh *> getPartsWithoutComputation() const;
150     MEDCoupling1GTUMesh *getPartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const;
151     void getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, int& start, int& stop) const;
152     std::size_t getTimeOfThis() const;
153     std::size_t getHeapMemorySizeWithoutChildren() const;
154     std::vector<const BigMemoryObject *> getDirectChildren() const;
155     MEDFileUMeshAggregateCompute deepCpy(DataArrayDouble *coords) const;
156     bool isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const;
157     void clearNonDiscrAttributes() const;
158     void synchronizeTinyInfo(const MEDFileMesh& master) const;
159     bool empty() const;
160     int getMeshDimension() const;
161     std::vector<int> getDistributionOfTypes() const;
162     int getSize() const;
163     void setCoords(DataArrayDouble *coords);
164     void forceComputationOfPartsFromUMesh() const;
165   private:
166     std::size_t getTimeOfParts() const;
167     std::size_t getTimeOfUMesh() const;
168   private:
169     mutable std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> > _m_parts;
170     mutable std::size_t _mp_time;
171     mutable std::size_t _m_time;
172     mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
173   };
174   
175   class MEDFileUMeshSplitL1 : public RefCountObject
176   {
177     friend class MEDFileUMeshPermCompute;
178   public:
179     MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other);
180     MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::string& mName, int id);
181     MEDFileUMeshSplitL1(MEDCoupling1GTUMesh *m);
182     MEDFileUMeshSplitL1(MEDCouplingUMesh *m);
183     MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld);
184     std::size_t getHeapMemorySizeWithoutChildren() const;
185     std::vector<const BigMemoryObject *> getDirectChildren() const;
186     MEDFileUMeshSplitL1 *deepCpy(DataArrayDouble *coords) const;
187     void setCoords(DataArrayDouble *coords);
188     bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const;
189     void clearNonDiscrAttributes() const;
190     void synchronizeTinyInfo(const MEDFileMesh& master) const;
191     void assignMesh(MEDCouplingUMesh *m, bool newOrOld);
192     void assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts);
193     void forceComputationOfParts() const;
194     bool empty() const;
195     bool presenceOfOneFams(const std::vector<int>& ids) const;
196     int getMeshDimension() const;
197     void simpleRepr(std::ostream& oss) const;
198     int getSize() const;
199     MEDCouplingUMesh *getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const;
200     DataArrayInt *getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const;
201     MEDCouplingUMesh *getWholeMesh(bool renum) const;
202     std::vector<INTERP_KERNEL::NormalizedCellType> getGeoTypes() const;
203     std::vector<MEDCoupling1GTUMesh *> getDirectUndergroundSingleGeoTypeMeshes() const { return _m_by_types.getPartsWithoutComputation(); }
204     MEDCoupling1GTUMesh *getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const { return _m_by_types.getPartWithoutComputation(gt); }
205     DataArrayInt *extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const;
206     DataArrayInt *extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const;
207     std::vector<int> getDistributionOfTypes() const { return _m_by_types.getDistributionOfTypes(); }
208     DataArrayInt *getOrCreateAndGetFamilyField();
209     const DataArrayInt *getFamilyField() const;
210     const DataArrayInt *getNumberField() const;
211     const DataArrayAsciiChar *getNameField() const;
212     const DataArrayInt *getRevNumberField() const;
213     void eraseFamilyField();
214     void setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
215                               std::map<std::string, std::vector<std::string> >& groups) throw(INTERP_KERNEL::Exception);
216     void write(med_idt fid, const std::string& mName, int mdim) const;
217     //
218     void setFamilyArr(DataArrayInt *famArr);
219     void setRenumArr(DataArrayInt *renumArr);
220     void setNameArr(DataArrayAsciiChar *nameArr);
221     void changeFamilyIdArr(int oldId, int newId);
222     //
223     void renumberNodesInConn(const int *newNodeNumbersO2N);
224     //
225     static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp);
226     static std::vector<int> GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
227     static void TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
228                                     std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
229     static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da);
230     static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds);
231   private:
232     void assignCommonPart();
233     MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
234     DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const;
235     void computeRevNum() const;
236   private:
237     MEDFileUMeshAggregateCompute _m_by_types;
238     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
239     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
240     MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _names;
241     mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num;
242     MEDFileUMeshPermCompute _m;
243   };
244 }
245
246 #endif