1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #ifndef __MEDFILEMESHLL_HXX__
22 #define __MEDFILEMESHLL_HXX__
24 #include "MEDFileBasis.hxx"
25 #include "MEDFileMeshElt.hxx"
27 #include "MEDCouplingUMesh.hxx"
28 #include "MEDCouplingCMesh.hxx"
29 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
37 class MEDFileMeshL2 : public RefCountObject
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);
54 MEDFileString _description;
55 MEDFileString _dt_unit;
61 class MEDFileUMeshL2 : public MEDFileMeshL2
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);
80 std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > > _per_type_mesh;
81 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
82 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_coords;
83 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
86 class MEDFileCMeshL2 : public MEDFileMeshL2
90 void loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
91 MEDCouplingCMesh *getMesh() { return _cmesh; }
93 static med_data_type GetDataTypeCorrespondingToSpaceId(int id) throw(INTERP_KERNEL::Exception);
95 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> _cmesh;
99 class MEDFileUMeshSplitL1;
101 class MEDFileUMeshPermCompute
104 MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st);
105 operator MEDCouplingUMesh *() const;
106 void operator=(MEDCouplingUMesh *m);
107 void updateTime() const;
109 const MEDFileUMeshSplitL1 *_st;
110 mutable unsigned int _mpt_time;
111 mutable unsigned int _num_time;
112 mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
115 class MEDFileUMeshSplitL1 : public RefCountObject
117 friend class MEDFileUMeshPermCompute;
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);
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;
142 void setFamilyArr(DataArrayInt *famArr);
143 void setRenumArr(DataArrayInt *renumArr);
144 void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception);
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);
153 MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
154 DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const;
155 void computeRevNum() const;
157 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m_by_types;
158 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
159 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
160 mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num;
161 MEDFileUMeshPermCompute _m;