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