Back to index

salome-med  6.5.0
MEDFileMeshLL.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 #include "med.h"
00031 
00032 #include <map>
00033 
00034 namespace ParaMEDMEM
00035 {
00036   class MEDFileMeshL2 : public RefCountObject
00037   {
00038   public:
00039     MEDFileMeshL2();
00040     const char *getName() const { return _name.getReprForWrite(); }
00041     const char *getDescription() const { return _description.getReprForWrite(); }
00042     const char *getTimeUnit() const { return _dt_unit.getReprForWrite(); }
00043     int getIteration() const { return _iteration; }
00044     int getOrder() const { return _order; }
00045     double getTime() { return _time; }
00046     std::vector<std::string> getAxisInfoOnMesh(med_idt fid, int mId, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim) throw(INTERP_KERNEL::Exception);
00047     static int GetMeshIdFromName(med_idt fid, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1) throw(INTERP_KERNEL::Exception);
00048     static double CheckMeshTimeStep(med_idt fid, const char *mname, int nstep, int dt, int it) throw(INTERP_KERNEL::Exception);
00049     static void ReadFamiliesAndGrps(med_idt fid, const char *mname, std::map<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps);
00050     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);
00051   protected:
00052     MEDFileString _name;
00053     MEDFileString _description;
00054     MEDFileString _dt_unit;
00055     int _iteration;
00056     int _order;
00057     double _time;
00058   };
00059 
00060   class MEDFileUMeshL2 : public MEDFileMeshL2
00061   {
00062   public:
00063     MEDFileUMeshL2();
00064     void loadAll(med_idt fid, int mId, const char *mName, int dt, int it);
00065     void loadConnectivity(med_idt fid, int mdim, const char *mName, int dt, int it);
00066     void loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
00067     int getNumberOfLevels() const { return _per_type_mesh.size(); }
00068     bool emptyLev(int levId) const { return _per_type_mesh[levId].empty(); }
00069     const std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& getLev(int levId) const { return _per_type_mesh[levId]; }
00070     bool isFamDefinedOnLev(int levId) const;
00071     bool isNumDefinedOnLev(int levId) const;
00072     MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> getCoords() const { return _coords; }
00073     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsFamily() const { return _fam_coords; }
00074     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsNum() const { return _num_coords; }
00075     static void WriteCoords(med_idt fid, const char *mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords);
00076   private:
00077     void sortTypes();
00078   private:
00079     std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > > _per_type_mesh;
00080     MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
00081     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_coords;
00082     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
00083   };
00084 
00085   class MEDFileCMeshL2 : public MEDFileMeshL2
00086   {
00087   public:
00088     MEDFileCMeshL2();
00089     void loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
00090     MEDCouplingCMesh *getMesh() { return _cmesh; }
00091   private:
00092     static med_data_type GetDataTypeCorrespondingToSpaceId(int id) throw(INTERP_KERNEL::Exception);
00093   private:
00094     MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> _cmesh;
00095   };
00096 
00097   class MEDFileMesh;
00098   class MEDFileUMeshSplitL1;
00099 
00100   class MEDFileUMeshPermCompute
00101   {
00102   public:
00103     MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st);
00104     operator MEDCouplingUMesh *() const;
00105     void operator=(MEDCouplingUMesh *m);
00106     void updateTime() const;
00107   private:
00108     const MEDFileUMeshSplitL1 *_st;
00109     mutable unsigned int _mpt_time;
00110     mutable unsigned int _num_time;
00111     mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m;
00112   };
00113 
00114   class MEDFileUMeshSplitL1 : public RefCountObject
00115   {
00116     friend class MEDFileUMeshPermCompute;
00117   public:
00118     MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id);
00119     MEDFileUMeshSplitL1(MEDCouplingUMesh *m);
00120     MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld);
00121     bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const;
00122     void clearNonDiscrAttributes() const;
00123     void synchronizeTinyInfo(const MEDFileMesh& master) const;
00124     void assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception);
00125     bool empty() const;
00126     bool presenceOfOneFams(const std::vector<int>& ids) const;
00127     int getMeshDimension() const;
00128     void simpleRepr(std::ostream& oss) const;
00129     int getSize() const throw(INTERP_KERNEL::Exception);
00130     MEDCouplingUMesh *getFamilyPart(const std::vector<int>& ids, bool renum) const;
00131     DataArrayInt *getFamilyPartArr(const std::vector<int>& ids, bool renum) const;
00132     MEDCouplingUMesh *getWholeMesh(bool renum) const;
00133     const DataArrayInt *getFamilyField() const;
00134     const DataArrayInt *getNumberField() const;
00135     const DataArrayInt *getRevNumberField() const;
00136     void eraseFamilyField();
00137     void setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
00138                               std::map<std::string, std::vector<std::string> >& groups) throw(INTERP_KERNEL::Exception);
00139     void write(med_idt fid, const char *mName, int mdim) const;
00140     //
00141     void setFamilyArr(DataArrayInt *famArr);
00142     void setRenumArr(DataArrayInt *renumArr);
00143     void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception);
00144     //
00145     static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp);
00146     static std::vector<int> GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
00147     static void TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
00148                                     std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
00149     static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da);
00150     static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds);
00151   private:
00152     MEDCouplingUMesh *renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const;
00153     DataArrayInt *renumIfNeededArr(const DataArrayInt *da) const;
00154     void computeRevNum() const;
00155   private:
00156     MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> _m_by_types;
00157     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
00158     MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
00159     mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num;
00160     MEDFileUMeshPermCompute _m;
00161   };
00162 }
00163 
00164 #endif