00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __MEDFILEMESHLL_HXX__
00021 #define __MEDFILEMESHLL_HXX__
00022
00023 #include "MEDFileBasis.hxx"
00024 #include "MEDFileMeshElt.hxx"
00025
00026 #include "MEDCouplingUMesh.hxx"
00027 #include "MEDCouplingCMesh.hxx"
00028 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
00029
00030 extern "C"
00031 {
00032 #include "med.h"
00033 }
00034
00035 #include <map>
00036
00037 namespace ParaMEDMEM
00038 {
00039 class MEDFileMeshL2 : public RefCountObject
00040 {
00041 public:
00042 MEDFileMeshL2();
00043 const char *getName() const { return _name.getReprForWrite(); }
00044 const char *getDescription() const { return _description.getReprForWrite(); }
00045 const char *getTimeUnit() const { return _dt_unit.getReprForWrite(); }
00046 int getIteration() const { return _iteration; }
00047 int getOrder() const { return _order; }
00048 double getTime() { return _time; }
00049 std::vector<std::string> getAxisInfoOnMesh(med_idt fid, int mId, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim) throw(INTERP_KERNEL::Exception);
00050 static int GetMeshIdFromName(med_idt fid, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1) throw(INTERP_KERNEL::Exception);
00051 static double CheckMeshTimeStep(med_idt fid, const char *mname, int nstep, int dt, int it) throw(INTERP_KERNEL::Exception);
00052 static void ReadFamiliesAndGrps(med_idt fid, const char *mname, std::map<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps);
00053 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);
00054 protected:
00055 MEDFileString _name;
00056 MEDFileString _description;
00057 MEDFileString _dt_unit;
00058 int _iteration;
00059 int _order;
00060 double _time;
00061 };
00062
00063 class MEDFileUMeshL2 : public MEDFileMeshL2
00064 {
00065 public:
00066 MEDFileUMeshL2();
00067 void loadAll(med_idt fid, int mId, const char *mName, int dt, int it);
00068 void loadConnectivity(med_idt fid, int mdim, const char *mName, int dt, int it);
00069 void loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
00070 int getNumberOfLevels() const { return _per_type_mesh.size(); }
00071 bool emptyLev(int levId) const { return _per_type_mesh[levId].empty(); }
00072 const std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& getLev(int levId) const { return _per_type_mesh[levId]; }
00073 bool isFamDefinedOnLev(int levId) const;
00074 bool isNumDefinedOnLev(int levId) const;
00075 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> getCoords() const { return _coords; }
00076 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsFamily() const { return _fam_coords; }
00077 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsNum() const { return _num_coords; }
00078 static void WriteCoords(med_idt fid, const char *mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords);
00079 private:
00080 void sortTypes();
00081 private:
00082 std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > > _per_type_mesh;
00083 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
00084 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_coords;
00085 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
00086 };
00087
00088 class MEDFileCMeshL2 : public MEDFileMeshL2
00089 {
00090 public:
00091 MEDFileCMeshL2();
00092 void loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
00093 MEDCouplingCMesh *getMesh() { return _cmesh; }
00094 private:
00095 static med_data_type GetDataTypeCorrespondingToSpaceId(int id) throw(INTERP_KERNEL::Exception);
00096 private:
00097 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> _cmesh;
00098 };
00099
00100 class MEDFileMesh;
00101 class MEDFileUMeshSplitL1;
00102
00103 class MEDFileUMeshPermCompute
00104 {
00105 public:
00106 MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st);
00107 operator MEDCouplingUMesh *() const;
00108 void operator=(MEDCouplingUMesh *m);
00109 void updateTime() const;
00110 private:
00111 const MEDFileUMeshSplitL1 *_st;
00112 mutable unsigned int _mpt_time;
00113 mutable unsigned int _num_time;
00114 mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
00115 };
00116
00117 class MEDFileUMeshSplitL1 : public RefCountObject
00118 {
00119 friend class MEDFileUMeshPermCompute;
00120 public:
00121 MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id);
00122 MEDFileUMeshSplitL1(MEDCouplingUMesh *m);
00123 MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld);
00124 bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const;
00125 void clearNonDiscrAttributes() const;
00126 void synchronizeTinyInfo(const MEDFileMesh& master) const;
00127 void assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception);
00128 bool empty() const;
00129 bool presenceOfOneFams(const std::vector<int>& ids) const;
00130 int getMeshDimension() const;
00131 int getSize() const throw(INTERP_KERNEL::Exception);
00132 MEDCouplingUMesh *getFamilyPart(const std::vector<int>& ids, bool renum) const;
00133 DataArrayInt *getFamilyPartArr(const std::vector<int>& ids, bool renum) const;
00134 MEDCouplingUMesh *getWholeMesh(bool renum) const;
00135 const DataArrayInt *getFamilyField() const;
00136 const DataArrayInt *getNumberField() const;
00137 const DataArrayInt *getRevNumberField() const;
00138 void eraseFamilyField();
00139 void setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
00140 std::map<std::string, std::vector<std::string> >& groups) throw(INTERP_KERNEL::Exception);
00141 void write(med_idt fid, const char *mName, int mdim) const;
00142
00143 void setFamilyArr(DataArrayInt *famArr);
00144 void setRenumArr(DataArrayInt *renumArr);
00145
00146 static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp);
00147 static std::vector<int> GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
00148 static void TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
00149 std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
00150 static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da);
00151 static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds);
00152 private:
00153 MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
00154 DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const;
00155 void computeRevNum() const;
00156 private:
00157 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m_by_types;
00158 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
00159 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
00160 mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num;
00161 MEDFileUMeshPermCompute _m;
00162 };
00163 }
00164
00165 #endif