Salome HOME
Update copyrights
[tools/medcoupling.git] / src / MEDLoader / MEDFileFieldGlobs.hxx
1 // Copyright (C) 2007-2019  CEA/DEN, EDF R&D
2 //
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, or (at your option) any later version.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (EDF R&D)
20
21 #ifndef __MEDFILEFIELDGLOBS_HXX__
22 #define __MEDFILEFIELDGLOBS_HXX__
23
24 #include "MEDLoaderDefines.hxx"
25
26 #include "NormalizedGeometricTypes"
27 #include "MEDCouplingMemArray.hxx"
28 #include "MCAuto.hxx"
29
30 #include "med.h"
31
32 namespace MEDCoupling
33 {
34   class MEDFileFieldGlobsReal;
35   class MEDFileEntities;
36   class MEDFileWritable;
37   class MEDFileFieldLoc;
38   
39   class MEDFileFieldGlobs : public RefCountObject
40   {
41   public:
42     static MEDFileFieldGlobs *New(med_idt fid);
43     static MEDFileFieldGlobs *New();
44     std::size_t getHeapMemorySizeWithoutChildren() const;
45     std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
46     MEDFileFieldGlobs *deepCopy() const;
47     MEDFileFieldGlobs *shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const;
48     MEDFileFieldGlobs *deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const;
49     void simpleRepr(std::ostream& oss) const;
50     void appendGlobs(const MEDFileFieldGlobs& other, double eps);
51     void checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const;
52     void checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const;
53     void loadProfileInFile(med_idt fid, int id, const std::string& pflName);
54     void loadProfileInFile(med_idt fid, int id);
55     void loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real);
56     void loadAllGlobals(med_idt fid, const MEDFileEntities *entities);
57     void writeGlobals(med_idt fid, const MEDFileWritable& opt) const;
58     std::vector<std::string> getPfls() const;
59     std::vector<std::string> getLocs() const;
60     bool existsPfl(const std::string& pflName) const;
61     bool existsLoc(const std::string& locName) const;
62     std::string createNewNameOfPfl() const;
63     std::string createNewNameOfLoc() const;
64     std::vector< std::vector<int> > whichAreEqualProfiles() const;
65     std::vector< std::vector<int> > whichAreEqualLocs(double eps) const;
66     void setFileName(const std::string& fileName) { _file_name=fileName; }
67     void changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif);
68     void changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif);
69     int getNbOfGaussPtPerCell(int locId) const;
70     int getLocalizationId(const std::string& loc) const;
71     int getProfileId(const std::string& pfl) const;
72     std::string getFileName() const { return _file_name; }
73     const MEDFileFieldLoc& getLocalizationFromId(int locId) const;
74     const MEDFileFieldLoc& getLocalization(const std::string& locName) const;
75     const DataArrayInt *getProfileFromId(int pflId) const;
76     const DataArrayInt *getProfile(const std::string& pflName) const;
77     MEDFileFieldLoc& getLocalizationFromId(int locId);
78     MEDFileFieldLoc& getLocalization(const std::string& locName);
79     DataArrayInt *getProfile(const std::string& pflName);
80     DataArrayInt *getProfileFromId(int pflId);
81     void killProfileIds(const std::vector<int>& pflIds);
82     void killLocalizationIds(const std::vector<int>& locIds);
83     void killStructureElementsInGlobs();
84     //
85     void appendProfile(DataArrayInt *pfl);
86     void appendLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w);
87     //
88     static std::string CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid);
89   protected:
90     MEDFileFieldGlobs(med_idt fid);
91     MEDFileFieldGlobs();
92     ~MEDFileFieldGlobs();
93   protected:
94     std::vector< MCAuto<DataArrayInt> > _pfls;
95     std::vector< MCAuto<MEDFileFieldLoc> > _locs;
96     std::string _file_name;
97   };
98
99   /// @endcond INTERNAL
100
101   class MEDFileFieldGlobsReal
102   {
103   public:
104     MEDLOADER_EXPORT MEDFileFieldGlobsReal(med_idt fid);
105     MEDLOADER_EXPORT MEDFileFieldGlobsReal();
106     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
107     MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
108     MEDLOADER_EXPORT void simpleReprGlobs(std::ostream& oss) const;
109     MEDLOADER_EXPORT void resetContent();
110     MEDLOADER_EXPORT void killStructureElementsInGlobs();
111     MEDLOADER_EXPORT void shallowCpyGlobs(const MEDFileFieldGlobsReal& other);
112     MEDLOADER_EXPORT void deepCpyGlobs(const MEDFileFieldGlobsReal& other);
113     MEDLOADER_EXPORT void shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other);
114     MEDLOADER_EXPORT void deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other);
115     MEDLOADER_EXPORT void appendGlobs(const MEDFileFieldGlobsReal& other, double eps);
116     MEDLOADER_EXPORT void checkGlobsCoherency() const;
117     MEDLOADER_EXPORT void checkGlobsPflsPartCoherency() const;
118     MEDLOADER_EXPORT void checkGlobsLocsPartCoherency() const;
119     MEDLOADER_EXPORT virtual std::vector<std::string> getPflsReallyUsed() const = 0;
120     MEDLOADER_EXPORT virtual std::vector<std::string> getLocsReallyUsed() const = 0;
121     MEDLOADER_EXPORT virtual std::vector<std::string> getPflsReallyUsedMulti() const = 0;
122     MEDLOADER_EXPORT virtual std::vector<std::string> getLocsReallyUsedMulti() const = 0;
123     MEDLOADER_EXPORT virtual void changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) = 0;
124     MEDLOADER_EXPORT virtual void changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif) = 0;
125     MEDLOADER_EXPORT virtual ~MEDFileFieldGlobsReal();
126     //
127     MEDLOADER_EXPORT void loadProfileInFile(med_idt fid, int id, const std::string& pflName);
128     MEDLOADER_EXPORT void loadProfileInFile(med_idt fid, int id);
129     MEDLOADER_EXPORT void loadGlobals(med_idt fid);
130     MEDLOADER_EXPORT void loadAllGlobals(med_idt fid, const MEDFileEntities *entities=0);
131     MEDLOADER_EXPORT void writeGlobals(med_idt fid, const MEDFileWritable& opt) const;
132     MEDLOADER_EXPORT std::vector<std::string> getPfls() const;
133     MEDLOADER_EXPORT std::vector<std::string> getLocs() const;
134     MEDLOADER_EXPORT bool existsPfl(const std::string& pflName) const;
135     MEDLOADER_EXPORT bool existsLoc(const std::string& locName) const;
136     MEDLOADER_EXPORT std::string createNewNameOfPfl() const;
137     MEDLOADER_EXPORT std::string createNewNameOfLoc() const;
138     MEDLOADER_EXPORT std::vector< std::vector<int> > whichAreEqualProfiles() const;
139     MEDLOADER_EXPORT std::vector< std::vector<int> > whichAreEqualLocs(double eps) const;
140     MEDLOADER_EXPORT void setFileName(const std::string& fileName);
141     MEDLOADER_EXPORT void changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif);
142     MEDLOADER_EXPORT void changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif);
143     MEDLOADER_EXPORT void changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif);
144     MEDLOADER_EXPORT void changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif);
145     MEDLOADER_EXPORT void changePflName(const std::string& oldName, const std::string& newName);
146     MEDLOADER_EXPORT void changeLocName(const std::string& oldName, const std::string& newName);
147     MEDLOADER_EXPORT std::vector< std::pair<std::vector<std::string>, std::string > > zipPflsNames();
148     MEDLOADER_EXPORT std::vector< std::pair<std::vector<std::string>, std::string > > zipLocsNames(double eps);
149     MEDLOADER_EXPORT int getNbOfGaussPtPerCell(int locId) const;
150     MEDLOADER_EXPORT int getLocalizationId(const std::string& loc) const;
151     MEDLOADER_EXPORT int getProfileId(const std::string& pfl) const;
152     MEDLOADER_EXPORT std::string getFileName() const;
153     MEDLOADER_EXPORT const MEDFileFieldLoc& getLocalizationFromId(int locId) const;
154     MEDLOADER_EXPORT const MEDFileFieldLoc& getLocalization(const std::string& locName) const;
155     MEDLOADER_EXPORT MEDFileFieldLoc& getLocalizationFromId(int locId);
156     MEDLOADER_EXPORT MEDFileFieldLoc& getLocalization(const std::string& locName);
157     MEDLOADER_EXPORT const DataArrayInt *getProfile(const std::string& pflName) const;
158     MEDLOADER_EXPORT const DataArrayInt *getProfileFromId(int pflId) const;
159     MEDLOADER_EXPORT DataArrayInt *getProfile(const std::string& pflName);
160     MEDLOADER_EXPORT DataArrayInt *getProfileFromId(int pflId);
161     MEDLOADER_EXPORT void killProfileIds(const std::vector<int>& pflIds);
162     MEDLOADER_EXPORT void killLocalizationIds(const std::vector<int>& locIds);
163     //
164     MEDLOADER_EXPORT void appendProfile(DataArrayInt *pfl);
165     MEDLOADER_EXPORT void appendLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w);
166   protected:
167     MEDFileFieldGlobs *contentNotNull();
168     const MEDFileFieldGlobs *contentNotNull() const;
169   protected:
170     MCAuto< MEDFileFieldGlobs > _globals;
171   };
172
173   class MEDFileFieldNameScope
174   {
175   public:
176     MEDLOADER_EXPORT MEDFileFieldNameScope();
177     MEDLOADER_EXPORT MEDFileFieldNameScope(const std::string& fieldName, const std::string& meshName);
178     MEDLOADER_EXPORT std::string getName() const;
179     MEDLOADER_EXPORT void setName(const std::string& fieldName);
180     MEDLOADER_EXPORT std::string getDtUnit() const;
181     MEDLOADER_EXPORT void setDtUnit(const std::string& dtUnit);
182     MEDLOADER_EXPORT void copyNameScope(const MEDFileFieldNameScope& other);
183     MEDLOADER_EXPORT std::string getMeshName() const;
184     MEDLOADER_EXPORT void setMeshName(const std::string& meshName);
185   protected:
186     std::string _name;
187     std::string _dt_unit;
188     std::string _mesh_name;
189   };
190 }
191
192 #endif