Salome HOME
Merge from V6_main (04/10/2012)
[modules/med.git] / src / MEDLoader / MEDFileMeshLL.hxx
1 // Copyright (C) 2007-2012  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 "MEDCouplingAutoRefCountObjectPtr.hxx"
30
31 #include "med.h"
32
33 #include <map>
34
35 namespace ParaMEDMEM
36 {
37   class MEDFileMeshL2 : public RefCountObject
38   {
39   public:
40     MEDFileMeshL2();
41     const char *getName() const { return _name.getReprForWrite(); }
42     const char *getDescription() const { return _description.getReprForWrite(); }
43     const char *getTimeUnit() const { return _dt_unit.getReprForWrite(); }
44     int getIteration() const { return _iteration; }
45     int getOrder() const { return _order; }
46     double getTime() { return _time; }
47     std::vector<std::string> getAxisInfoOnMesh(med_idt fid, int mId, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim) throw(INTERP_KERNEL::Exception);
48     static int GetMeshIdFromName(med_idt fid, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1) throw(INTERP_KERNEL::Exception);
49     static double CheckMeshTimeStep(med_idt fid, const char *mname, int nstep, int dt, int it) throw(INTERP_KERNEL::Exception);
50     static void ReadFamiliesAndGrps(med_idt fid, const char *mname, std::map<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps);
51     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);
52   protected:
53     MEDFileString _name;
54     MEDFileString _description;
55     MEDFileString _dt_unit;
56     int _iteration;
57     int _order;
58     double _time;
59   };
60
61   class MEDFileUMeshL2 : public MEDFileMeshL2
62   {
63   public:
64     MEDFileUMeshL2();
65     void loadAll(med_idt fid, int mId, const char *mName, int dt, int it);
66     void loadConnectivity(med_idt fid, int mdim, const char *mName, int dt, int it);
67     void loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
68     int getNumberOfLevels() const { return _per_type_mesh.size(); }
69     bool emptyLev(int levId) const { return _per_type_mesh[levId].empty(); }
70     const std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& getLev(int levId) const { return _per_type_mesh[levId]; }
71     bool isFamDefinedOnLev(int levId) const;
72     bool isNumDefinedOnLev(int levId) const;
73     MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> getCoords() const { return _coords; }
74     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsFamily() const { return _fam_coords; }
75     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsNum() const { return _num_coords; }
76     static void WriteCoords(med_idt fid, const char *mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords);
77   private:
78     void sortTypes();
79   private:
80     std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > > _per_type_mesh;
81     MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
82     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_coords;
83     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
84   };
85
86   class MEDFileCMeshL2 : public MEDFileMeshL2
87   {
88   public:
89     MEDFileCMeshL2();
90     void loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
91     MEDCouplingCMesh *getMesh() { return _cmesh; }
92   private:
93     static med_data_type GetDataTypeCorrespondingToSpaceId(int id) throw(INTERP_KERNEL::Exception);
94   private:
95     MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> _cmesh;
96   };
97
98   class MEDFileMesh;
99   class MEDFileUMeshSplitL1;
100
101   class MEDFileUMeshPermCompute
102   {
103   public:
104     MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st);
105     operator MEDCouplingUMesh *() const;
106     void operator=(MEDCouplingUMesh *m);
107     void updateTime() const;
108   private:
109     const MEDFileUMeshSplitL1 *_st;
110     mutable unsigned int _mpt_time;
111     mutable unsigned int _num_time;
112     mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
113   };
114
115   class MEDFileUMeshSplitL1 : public RefCountObject
116   {
117     friend class MEDFileUMeshPermCompute;
118   public:
119     MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id);
120     MEDFileUMeshSplitL1(MEDCouplingUMesh *m);
121     MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld);
122     bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const;
123     void clearNonDiscrAttributes() const;
124     void synchronizeTinyInfo(const MEDFileMesh& master) const;
125     void assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception);
126     bool empty() const;
127     bool presenceOfOneFams(const std::vector<int>& ids) const;
128     int getMeshDimension() const;
129     void simpleRepr(std::ostream& oss) const;
130     int getSize() const throw(INTERP_KERNEL::Exception);
131     MEDCouplingUMesh *getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const;
132     DataArrayInt *getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const;
133     MEDCouplingUMesh *getWholeMesh(bool renum) const;
134     const DataArrayInt *getFamilyField() const;
135     const DataArrayInt *getNumberField() const;
136     const DataArrayInt *getRevNumberField() const;
137     void eraseFamilyField();
138     void setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
139                               std::map<std::string, std::vector<std::string> >& groups) throw(INTERP_KERNEL::Exception);
140     void write(med_idt fid, const char *mName, int mdim) const;
141     //
142     void setFamilyArr(DataArrayInt *famArr);
143     void setRenumArr(DataArrayInt *renumArr);
144     void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception);
145     //
146     static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp);
147     static std::vector<int> GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
148     static void TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
149                                     std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
150     static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da);
151     static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds);
152   private:
153     MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
154     DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const;
155     void computeRevNum() const;
156   private:
157     MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m_by_types;
158     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
159     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
160     mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num;
161     MEDFileUMeshPermCompute _m;
162   };
163 }
164
165 #endif