00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __MEDFILEMESH_HXX__
00021 #define __MEDFILEMESH_HXX__
00022
00023 #include "MEDFileMeshLL.hxx"
00024 #include "MEDFileUtilities.hxx"
00025
00026 #include <map>
00027
00028 namespace ParaMEDMEM
00029 {
00030 class MEDFileMesh : public RefCountObject, public MEDFileWritable
00031 {
00032 public:
00033 static MEDFileMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception);
00034 static MEDFileMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception);
00035 virtual bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const;
00036 virtual void clearNonDiscrAttributes() const;
00037 void setName(const char *name) { _name=name; }
00038 const char *getName() const { return _name.c_str(); }
00039 void setUnivName(const char *name) { _univ_name=name; }
00040 const char *getUnivName() const { return _univ_name.c_str(); }
00041 void setDescription(const char *name) { _desc_name=name; }
00042 const char *getDescription() const { return _desc_name.c_str(); }
00043 void setOrder(int order) { _order=order; }
00044 int getOrder() const { return _order; }
00045 void setIteration(int it) { _iteration=it; }
00046 int getIteration() const { return _iteration; }
00047 void setTimeValue(double time) { _time=time; }
00048 void setTime(double time, int dt, int it) { _time=time; _iteration=dt; _order=it; }
00049 double getTime(int& dt, int& it) { dt=_iteration; it=_order; return _time; }
00050 double getTimeValue() const { return _time; }
00051 void setTimeUnit(const char *unit) { _dt_unit=unit; }
00052 const char *getTimeUnit() const { return _dt_unit.c_str(); }
00053 virtual void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) = 0;
00054 virtual int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0;
00055 virtual MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax, bool renum=false) const throw(INTERP_KERNEL::Exception) = 0;
00056
00057 bool areFamsEqual(const MEDFileMesh *other, std::string& what) const;
00058 bool areGrpsEqual(const MEDFileMesh *other, std::string& what) const;
00059 bool existsFamily(int famId) const;
00060 bool existsFamily(const char *familyName) const;
00061 void setFamilyId(const char *familyName, int id);
00062 void addFamily(const char *familyName, int id) throw(INTERP_KERNEL::Exception);
00063 void addGrpOnFamily(const char *grpName, const char *famName) throw(INTERP_KERNEL::Exception);
00064 void setFamilyInfo(const std::map<std::string,int>& info);
00065 void setGroupInfo(const std::map<std::string, std::vector<std::string> >&info);
00066 void copyFamGrpMapsFrom(const MEDFileMesh& other);
00067 const std::map<std::string,int>& getFamilyInfo() const { return _families; }
00068 const std::map<std::string, std::vector<std::string> >& getGroupInfo() const { return _groups; }
00069 std::vector<std::string> getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception);
00070 std::vector<std::string> getFamiliesOnGroups(const std::vector<std::string>& grps) const throw(INTERP_KERNEL::Exception);
00071 std::vector<int> getFamiliesIdsOnGroup(const char *name) const throw(INTERP_KERNEL::Exception);
00072 void setFamiliesOnGroup(const char *name, const std::vector<std::string>& fams) throw(INTERP_KERNEL::Exception);
00073 void setFamiliesIdsOnGroup(const char *name, const std::vector<int>& famIds) throw(INTERP_KERNEL::Exception);
00074 std::vector<std::string> getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception);
00075 void setGroupsOnFamily(const char *famName, const std::vector<std::string>& grps) throw(INTERP_KERNEL::Exception);
00076 std::vector<std::string> getGroupsNames() const;
00077 std::vector<std::string> getFamiliesNames() const;
00078 void removeGroup(const char *name) throw(INTERP_KERNEL::Exception);
00079 void removeFamily(const char *name) throw(INTERP_KERNEL::Exception);
00080 void changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception);
00081 void changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception);
00082 int getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception);
00083 int getMaxFamilyId() const throw(INTERP_KERNEL::Exception);
00084 std::vector<int> getFamiliesIds(const std::vector<std::string>& famNames) const throw(INTERP_KERNEL::Exception);
00085 std::string getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception);
00086 virtual int getMeshDimension() const throw(INTERP_KERNEL::Exception) = 0;
00087
00088 virtual void setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector<const DataArrayInt *>& grps, bool renum=false) throw(INTERP_KERNEL::Exception);
00089 virtual void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception) = 0;
00090 virtual void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception) = 0;
00091 virtual const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0;
00092 virtual const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0;
00093 virtual const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0;
00094 virtual DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception) = 0;
00095 virtual DataArrayInt *getGroupsArr(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
00096 virtual DataArrayInt *getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
00097 virtual DataArrayInt *getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
00098 virtual DataArrayInt *getNodeGroupArr(const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
00099 virtual DataArrayInt *getNodeGroupsArr(const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
00100 virtual DataArrayInt *getNodeFamilyArr(const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
00101 virtual DataArrayInt *getNodeFamiliesArr(const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
00102 protected:
00103 MEDFileMesh();
00104 void dealWithTinyInfo(const MEDCouplingMesh *m) throw(INTERP_KERNEL::Exception);
00105 virtual void synchronizeTinyInfoOnLeaves() const = 0;
00106 virtual void appendFamilyEntries(const std::set<int>& famIds, const std::vector< std::vector<int> >& fidsOfGrps, const std::vector<std::string>& grpNames);
00107 static void TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector<int> >& famIdsPerGrp);
00108 protected:
00109 int _order;
00110 int _iteration;
00111 double _time;
00112 std::string _dt_unit;
00113 std::string _name;
00114 std::string _univ_name;
00115 std::string _desc_name;
00116 protected:
00117 std::map<std::string, std::vector<std::string> > _groups;
00118 std::map<std::string,int> _families;
00119 public:
00120 static const char DFT_FAM_NAME[];
00121 };
00122
00123 class MEDFileUMesh : public MEDFileMesh
00124 {
00125 friend class MEDFileMesh;
00126 public:
00127 static MEDFileUMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception);
00128 static MEDFileUMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception);
00129 static MEDFileUMesh *New();
00130 bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const;
00131 void clearNonDiscrAttributes() const;
00132 ~MEDFileUMesh();
00133
00134 void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
00135 int getMeshDimension() const throw(INTERP_KERNEL::Exception);
00136 int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
00137 const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
00138 const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
00139 const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
00140 std::vector<int> getNonEmptyLevels() const;
00141 std::vector<int> getNonEmptyLevelsExt() const;
00142 std::vector<int> getGrpNonEmptyLevels(const char *grp) const throw(INTERP_KERNEL::Exception);
00143 std::vector<int> getGrpNonEmptyLevelsExt(const char *grp) const throw(INTERP_KERNEL::Exception);
00144 std::vector<int> getFamNonEmptyLevels(const char *fam) const throw(INTERP_KERNEL::Exception);
00145 std::vector<int> getFamNonEmptyLevelsExt(const char *fam) const throw(INTERP_KERNEL::Exception);
00146 std::vector<int> getGrpsNonEmptyLevels(const std::vector<std::string>& grps) const throw(INTERP_KERNEL::Exception);
00147 std::vector<int> getGrpsNonEmptyLevelsExt(const std::vector<std::string>& grps) const throw(INTERP_KERNEL::Exception);
00148 std::vector<int> getFamsNonEmptyLevels(const std::vector<std::string>& fams) const throw(INTERP_KERNEL::Exception);
00149 std::vector<int> getFamsNonEmptyLevelsExt(const std::vector<std::string>& fams) const throw(INTERP_KERNEL::Exception);
00150 DataArrayDouble *getCoords() const;
00151 MEDCouplingUMesh *getGroup(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
00152 MEDCouplingUMesh *getGroups(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
00153 MEDCouplingUMesh *getFamily(int meshDimRelToMaxExt, const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
00154 MEDCouplingUMesh *getFamilies(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
00155 DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
00156 MEDCouplingUMesh *getMeshAtLevel(int meshDimRelToMaxExt, bool renum=false) const throw(INTERP_KERNEL::Exception);
00157 MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax, bool renum=false) const throw(INTERP_KERNEL::Exception);
00158 MEDCouplingUMesh *getLevel0Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
00159 MEDCouplingUMesh *getLevelM1Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
00160 MEDCouplingUMesh *getLevelM2Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
00161 MEDCouplingUMesh *getLevelM3Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
00162
00163 void setFamilyNameAttachedOnId(int id, const std::string& newFamName) throw(INTERP_KERNEL::Exception);
00164 void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception);
00165 void eraseGroupsAtLevel(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception);
00166 void setFamilyField(DataArrayInt *arr, const std::vector< std::vector< int > > &userfids, const std::vector<std::string>& grpNames, bool renum=false) throw(INTERP_KERNEL::Exception);
00167 void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception);
00168 void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception);
00169 void addNodeGroup(const std::string& name, const std::vector<int>& ids) throw(INTERP_KERNEL::Exception);
00170 void removeMeshAtLevel(int meshDimRelToMax) throw(INTERP_KERNEL::Exception);
00171 void setMeshAtLevel(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld=false) throw(INTERP_KERNEL::Exception);
00172 void setMeshAtLevelGen(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception);
00173 void setGroupsFromScratch(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms) throw(INTERP_KERNEL::Exception);
00174 void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms, bool renum) throw(INTERP_KERNEL::Exception);
00175 void optimizeFamilies() throw(INTERP_KERNEL::Exception);
00176 private:
00177 MEDFileUMesh();
00178 MEDFileUMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
00179 void loadUMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
00180 const MEDFileUMeshSplitL1 *getMeshAtLevSafe(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
00181 MEDFileUMeshSplitL1 *getMeshAtLevSafe(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception);
00182 void checkMeshDimCoherency(int meshDim, int meshDimRelToMax) const throw(INTERP_KERNEL::Exception);
00183 DataArrayDouble *checkMultiMesh(const std::vector<const MEDCouplingUMesh *>& ms) const throw(INTERP_KERNEL::Exception);
00184 void computeRevNum() const;
00185 void synchronizeTinyInfoOnLeaves() const;
00186 private:
00187 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> > _ms;
00188 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
00189 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_coords;
00190 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
00191 mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num_coords;
00192 };
00193
00194 class MEDFileCMesh : public MEDFileMesh
00195 {
00196 friend class MEDFileMesh;
00197 public:
00198 static MEDFileCMesh *New();
00199 static MEDFileCMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception);
00200 static MEDFileCMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception);
00201 bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const;
00202 int getMeshDimension() const throw(INTERP_KERNEL::Exception);
00203 void clearNonDiscrAttributes() const;
00204 const MEDCouplingCMesh *getMesh() const;
00205 MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax, bool renum=false) const throw(INTERP_KERNEL::Exception);
00206 void setMesh(MEDCouplingCMesh *m) throw(INTERP_KERNEL::Exception);
00207 void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
00208 int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
00209 DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
00210 void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception);
00211 void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception);
00212 const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
00213 const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
00214 const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
00215 private:
00216 MEDFileCMesh();
00217 void synchronizeTinyInfoOnLeaves() const;
00218 MEDFileCMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
00219 void loadCMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
00220 private:
00221 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> _cmesh;
00222 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_nodes;
00223 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_nodes;
00224 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_cells;
00225 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_cells;
00226 mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num_nodes;
00227 mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num_cells;
00228 };
00229
00230 class MEDFileMeshMultiTS : public RefCountObject, public MEDFileWritable
00231 {
00232 public:
00233 static MEDFileMeshMultiTS *New();
00234 static MEDFileMeshMultiTS *New(const char *fileName) throw(INTERP_KERNEL::Exception);
00235 static MEDFileMeshMultiTS *New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception);
00236 const char *getName() const throw(INTERP_KERNEL::Exception);
00237 MEDFileMesh *getOneTimeStep() const throw(INTERP_KERNEL::Exception);
00238 void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
00239 void setOneTimeStep(MEDFileMesh *mesh1TimeStep) throw(INTERP_KERNEL::Exception);
00240 private:
00241 void loadFromFile(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception);
00242 MEDFileMeshMultiTS();
00243 MEDFileMeshMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception);
00244 MEDFileMeshMultiTS(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception);
00245 private:
00246 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> > _mesh_one_ts;
00247 };
00248
00249 class MEDFileMeshes : public RefCountObject, public MEDFileWritable
00250 {
00251 public:
00252 static MEDFileMeshes *New();
00253 static MEDFileMeshes *New(const char *fileName) throw(INTERP_KERNEL::Exception);
00254 void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
00255 int getNumberOfMeshes() const throw(INTERP_KERNEL::Exception);
00256 MEDFileMesh *getMeshAtPos(int i) const throw(INTERP_KERNEL::Exception);
00257
00258 void resize(int newSize) throw(INTERP_KERNEL::Exception);
00259 void pushMesh(MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception);
00260 void setMeshAtPos(int i, MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception);
00261 void destroyMeshAtPos(int i) throw(INTERP_KERNEL::Exception);
00262 private:
00263 void checkCoherency() const throw(INTERP_KERNEL::Exception);
00264 void loadFromFile(const char *fileName) throw(INTERP_KERNEL::Exception);
00265 MEDFileMeshes();
00266 MEDFileMeshes(const char *fileName) throw(INTERP_KERNEL::Exception);
00267 private:
00268 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> > _meshes;
00269 };
00270 }
00271
00272 #endif