1 // Copyright (C) 2007-2013 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 "MEDCouplingCurveLinearMesh.hxx"
30 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
38 class MEDFileMeshL2 : public RefCountObject
42 std::size_t getHeapMemorySize() const { return 0; }
43 const char *getName() const { return _name.getReprForWrite(); }
44 const char *getDescription() const { return _description.getReprForWrite(); }
45 const char *getTimeUnit() const { return _dt_unit.getReprForWrite(); }
46 int getIteration() const { return _iteration; }
47 int getOrder() const { return _order; }
48 double getTime() { return _time; }
49 std::vector<std::string> getAxisInfoOnMesh(med_idt fid, int mId, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim) throw(INTERP_KERNEL::Exception);
50 static int GetMeshIdFromName(med_idt fid, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1) throw(INTERP_KERNEL::Exception);
51 static double CheckMeshTimeStep(med_idt fid, const char *mname, int nstep, int dt, int it) throw(INTERP_KERNEL::Exception);
52 static void ReadFamiliesAndGrps(med_idt fid, const char *mname, std::map<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps);
53 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);
56 MEDFileString _description;
57 MEDFileString _dt_unit;
63 class MEDFileUMeshL2 : public MEDFileMeshL2
67 void loadAll(med_idt fid, int mId, const char *mName, int dt, int it);
68 void loadConnectivity(med_idt fid, int mdim, const char *mName, int dt, int it);
69 void loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
70 int getNumberOfLevels() const { return _per_type_mesh.size(); }
71 bool emptyLev(int levId) const { return _per_type_mesh[levId].empty(); }
72 const std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& getLev(int levId) const { return _per_type_mesh[levId]; }
73 bool isFamDefinedOnLev(int levId) const;
74 bool isNumDefinedOnLev(int levId) const;
75 bool isNamesDefinedOnLev(int levId) const;
76 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> getCoords() const { return _coords; }
77 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsFamily() const { return _fam_coords; }
78 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsNum() const { return _num_coords; }
79 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> getCoordsName() const { return _name_coords; }
80 static void WriteCoords(med_idt fid, const char *mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords, const DataArrayAsciiChar *nameCoords);
84 std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > > _per_type_mesh;
85 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
86 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_coords;
87 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
88 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _name_coords;
91 class MEDFileStrMeshL2 : public MEDFileMeshL2
95 class MEDFileCMeshL2 : public MEDFileStrMeshL2
99 void loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
100 MEDCouplingCMesh *getMesh() { return _cmesh; }
102 static med_data_type GetDataTypeCorrespondingToSpaceId(int id) throw(INTERP_KERNEL::Exception);
104 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> _cmesh;
107 class MEDFileCLMeshL2 : public MEDFileStrMeshL2
111 void loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
112 MEDCouplingCurveLinearMesh *getMesh() { return _clmesh; }
114 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> _clmesh;
118 class MEDFileUMeshSplitL1;
120 class MEDFileUMeshPermCompute
123 MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st);
124 operator MEDCouplingUMesh *() const;
125 void operator=(MEDCouplingUMesh *m);
126 void updateTime() const;
128 const MEDFileUMeshSplitL1 *_st;
129 mutable unsigned int _mpt_time;
130 mutable unsigned int _num_time;
131 mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
134 class MEDFileUMeshSplitL1 : public RefCountObject
136 friend class MEDFileUMeshPermCompute;
138 MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other);
139 MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id);
140 MEDFileUMeshSplitL1(MEDCouplingUMesh *m);
141 MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld);
142 std::size_t getHeapMemorySize() const;
143 MEDFileUMeshSplitL1 *deepCpy() const;
144 bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const;
145 void clearNonDiscrAttributes() const;
146 void synchronizeTinyInfo(const MEDFileMesh& master) const;
147 void assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception);
149 bool presenceOfOneFams(const std::vector<int>& ids) const;
150 int getMeshDimension() const;
151 void simpleRepr(std::ostream& oss) const;
152 int getSize() const throw(INTERP_KERNEL::Exception);
153 MEDCouplingUMesh *getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const;
154 DataArrayInt *getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const;
155 MEDCouplingUMesh *getWholeMesh(bool renum) const;
156 DataArrayInt *getOrCreateAndGetFamilyField() throw(INTERP_KERNEL::Exception);
157 const DataArrayInt *getFamilyField() const;
158 const DataArrayInt *getNumberField() const;
159 const DataArrayAsciiChar *getNameField() const;
160 const DataArrayInt *getRevNumberField() const;
161 void eraseFamilyField();
162 void setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
163 std::map<std::string, std::vector<std::string> >& groups) throw(INTERP_KERNEL::Exception);
164 void write(med_idt fid, const char *mName, int mdim) const;
166 void setFamilyArr(DataArrayInt *famArr);
167 void setRenumArr(DataArrayInt *renumArr);
168 void setNameArr(DataArrayAsciiChar *nameArr);
169 void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception);
171 void renumberNodesInConn(const int *newNodeNumbersO2N) throw(INTERP_KERNEL::Exception);
173 static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp);
174 static std::vector<int> GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
175 static void TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
176 std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
177 static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da);
178 static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds);
180 MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
181 DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const;
182 void computeRevNum() const;
184 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m_by_types;
185 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
186 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
187 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _names;
188 mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num;
189 MEDFileUMeshPermCompute _m;