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 *getUnivName() const { return _univ_name.getReprForWrite(); }
46 const char *getTimeUnit() const { return _dt_unit.getReprForWrite(); }
47 int getIteration() const { return _iteration; }
48 int getOrder() const { return _order; }
49 double getTime() { return _time; }
50 std::vector<std::string> getAxisInfoOnMesh(med_idt fid, int mId, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim) throw(INTERP_KERNEL::Exception);
51 static int GetMeshIdFromName(med_idt fid, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1) throw(INTERP_KERNEL::Exception);
52 static double CheckMeshTimeStep(med_idt fid, const char *mname, int nstep, int dt, int it) throw(INTERP_KERNEL::Exception);
53 static void ReadFamiliesAndGrps(med_idt fid, const char *mname, std::map<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps);
54 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);
57 MEDFileString _description;
58 MEDFileString _univ_name;
59 MEDFileString _dt_unit;
65 class MEDFileUMeshL2 : public MEDFileMeshL2
69 void loadAll(med_idt fid, int mId, const char *mName, int dt, int it);
70 void loadConnectivity(med_idt fid, int mdim, const char *mName, int dt, int it);
71 void loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
72 int getNumberOfLevels() const { return _per_type_mesh.size(); }
73 bool emptyLev(int levId) const { return _per_type_mesh[levId].empty(); }
74 const std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& getLev(int levId) const { return _per_type_mesh[levId]; }
75 bool isFamDefinedOnLev(int levId) const;
76 bool isNumDefinedOnLev(int levId) const;
77 bool isNamesDefinedOnLev(int levId) const;
78 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> getCoords() const { return _coords; }
79 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsFamily() const { return _fam_coords; }
80 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsNum() const { return _num_coords; }
81 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> getCoordsName() const { return _name_coords; }
82 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);
86 std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > > _per_type_mesh;
87 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
88 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_coords;
89 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
90 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _name_coords;
93 class MEDFileStrMeshL2 : public MEDFileMeshL2
97 class MEDFileCMeshL2 : public MEDFileStrMeshL2
101 void loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
102 MEDCouplingCMesh *getMesh() { return _cmesh; }
104 static med_data_type GetDataTypeCorrespondingToSpaceId(int id) throw(INTERP_KERNEL::Exception);
106 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> _cmesh;
109 class MEDFileCLMeshL2 : public MEDFileStrMeshL2
113 void loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
114 MEDCouplingCurveLinearMesh *getMesh() { return _clmesh; }
116 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> _clmesh;
120 class MEDFileUMeshSplitL1;
122 class MEDFileUMeshPermCompute
125 MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st);
126 operator MEDCouplingUMesh *() const;
127 void operator=(MEDCouplingUMesh *m);
128 void updateTime() const;
130 const MEDFileUMeshSplitL1 *_st;
131 mutable unsigned int _mpt_time;
132 mutable unsigned int _num_time;
133 mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
136 class MEDFileUMeshSplitL1 : public RefCountObject
138 friend class MEDFileUMeshPermCompute;
140 MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other);
141 MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id);
142 MEDFileUMeshSplitL1(MEDCouplingUMesh *m);
143 MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld);
144 std::size_t getHeapMemorySize() const;
145 MEDFileUMeshSplitL1 *deepCpy() const;
146 bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const;
147 void clearNonDiscrAttributes() const;
148 void synchronizeTinyInfo(const MEDFileMesh& master) const;
149 void assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception);
151 bool presenceOfOneFams(const std::vector<int>& ids) const;
152 int getMeshDimension() const;
153 void simpleRepr(std::ostream& oss) const;
154 int getSize() const throw(INTERP_KERNEL::Exception);
155 MEDCouplingUMesh *getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const;
156 DataArrayInt *getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const;
157 MEDCouplingUMesh *getWholeMesh(bool renum) const;
158 DataArrayInt *getOrCreateAndGetFamilyField() throw(INTERP_KERNEL::Exception);
159 const DataArrayInt *getFamilyField() const;
160 const DataArrayInt *getNumberField() const;
161 const DataArrayAsciiChar *getNameField() const;
162 const DataArrayInt *getRevNumberField() const;
163 void eraseFamilyField();
164 void setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
165 std::map<std::string, std::vector<std::string> >& groups) throw(INTERP_KERNEL::Exception);
166 void write(med_idt fid, const char *mName, int mdim) const;
168 void setFamilyArr(DataArrayInt *famArr);
169 void setRenumArr(DataArrayInt *renumArr);
170 void setNameArr(DataArrayAsciiChar *nameArr);
171 void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception);
173 void renumberNodesInConn(const int *newNodeNumbersO2N) throw(INTERP_KERNEL::Exception);
175 static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp);
176 static std::vector<int> GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
177 static void TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
178 std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
179 static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da);
180 static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds);
182 MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
183 DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const;
184 void computeRevNum() const;
186 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m_by_types;
187 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
188 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
189 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> _names;
190 mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num;
191 MEDFileUMeshPermCompute _m;