Salome HOME
Update copyrights
[tools/medcoupling.git] / src / MEDLoader / MEDFileField.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 __MEDFILEFIELD_HXX__
22 #define __MEDFILEFIELD_HXX__
23
24 #include "MEDLoaderDefines.hxx"
25
26 #include "MEDFileFieldInternal.hxx"
27 #include "MEDFileFieldGlobs.hxx"
28 #include "MEDFileField1TS.hxx"
29 #include "MEDFileFieldMultiTS.hxx"
30
31 #include "MEDFileFieldOverView.hxx"
32 #include "MEDFileUtilities.txx"
33 #include "MEDFileEntities.hxx"
34
35 #include "MCAuto.hxx"
36 #include "MEDLoaderTraits.hxx"
37 #include "MEDCouplingTraits.hxx"
38 #include "MEDCouplingRefCountObject.hxx"
39 #include "MEDCouplingFieldInt.hxx"
40 #include "MEDCouplingMemArray.hxx"
41 #include "MEDCouplingPartDefinition.hxx"
42
43 #include "NormalizedUnstructuredMesh.hxx"
44 #include "InterpKernelException.hxx"
45
46 #include <vector>
47 #include <string>
48 #include <list>
49 #include <set>
50
51 #include "med.h"
52
53 namespace MEDCoupling
54 {
55   class MEDFileFieldGlobs;
56   class MEDCouplingMesh;
57   class MEDCouplingFieldDouble;
58   class MEDFileMesh;
59   class MEDFileFieldVisitor;
60
61   class MEDFileMeshes;
62
63   class MEDFileFieldsIterator;
64   class MEDFileStructureElements;
65   
66   /*!
67    * Use class.
68    */
69   class MEDFileFields : public RefCountObject, public MEDFileFieldGlobsReal, public MEDFileWritableStandAlone
70   {
71   public:
72     MEDLOADER_EXPORT static MEDFileFields *New();
73     MEDLOADER_EXPORT static MEDFileFields *New(const std::string& fileName, bool loadAll=true);
74     MEDLOADER_EXPORT static MEDFileFields *New(med_idt fid, bool loadAll=true);
75     MEDLOADER_EXPORT static MEDFileFields *NewAdv(const std::string& fileName, bool loadAll, const MEDFileEntities *entities);
76     MEDLOADER_EXPORT static MEDFileFields *NewAdv(med_idt fid, bool loadAll, const MEDFileEntities *entities);
77     MEDLOADER_EXPORT static MEDFileFields *NewWithDynGT(const std::string& fileName, const MEDFileStructureElements *se, bool loadAll=true);
78     MEDLOADER_EXPORT static MEDFileFields *NewWithDynGT(med_idt fid, const MEDFileStructureElements *se, bool loadAll=true);
79     MEDLOADER_EXPORT static MEDFileFields *New(DataArrayByte *db) { return BuildFromMemoryChunk<MEDFileFields>(db); }
80     MEDLOADER_EXPORT static MEDFileFields *LoadPartOf(const std::string& fileName, bool loadAll=true, const MEDFileMeshes *ms=0);
81     MEDLOADER_EXPORT static MEDFileFields *LoadSpecificEntities(const std::string& fileName, const std::vector< std::pair<TypeOfField,INTERP_KERNEL::NormalizedCellType> >& entities, bool loadAll=true);
82     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
83     MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
84     MEDLOADER_EXPORT MEDFileFields *deepCopy() const;
85     MEDLOADER_EXPORT MEDFileFields *shallowCpy() const;
86     MEDLOADER_EXPORT void writeLL(med_idt fid) const;
87     MEDLOADER_EXPORT void loadArrays();
88     MEDLOADER_EXPORT void loadArraysIfNecessary();
89     MEDLOADER_EXPORT void unloadArrays();
90     MEDLOADER_EXPORT void unloadArraysWithoutDataLoss();
91     MEDLOADER_EXPORT int getNumberOfFields() const;
92     MEDLOADER_EXPORT std::vector< std::pair<int,int> > getCommonIterations(bool& areThereSomeForgottenTS) const;
93     MEDLOADER_EXPORT std::vector<std::string> getFieldsNames() const;
94     MEDLOADER_EXPORT std::vector<std::string> getMeshesNames() const;
95     MEDLOADER_EXPORT std::string simpleRepr() const;
96     MEDLOADER_EXPORT void simpleRepr(int bkOffset, std::ostream& oss) const;
97     //
98     MEDLOADER_EXPORT void resize(int newSize);
99     MEDLOADER_EXPORT void pushField(MEDFileAnyTypeFieldMultiTS *field);
100     MEDLOADER_EXPORT void pushFields(const std::vector<MEDFileAnyTypeFieldMultiTS *>& fields);
101     MEDLOADER_EXPORT void setFieldAtPos(int i, MEDFileAnyTypeFieldMultiTS *field);
102     MEDLOADER_EXPORT int getPosFromFieldName(const std::string& fieldName) const;
103     MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTS *getFieldAtPos(int i) const;
104     MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTS *getFieldWithName(const std::string& fieldName) const;
105     MEDLOADER_EXPORT MEDFileFields *buildSubPart(const int *startIds, const int *endIds) const;
106     MEDLOADER_EXPORT bool removeFieldsWithoutAnyTimeStep();
107     MEDLOADER_EXPORT MEDFileFields *partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const;
108     MEDLOADER_EXPORT MEDFileFields *partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const;
109     MEDLOADER_EXPORT MEDFileFields *partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair<int,int> >& timeSteps) const;
110     MEDLOADER_EXPORT bool presenceOfStructureElements() const;
111     MEDLOADER_EXPORT void killStructureElements();
112     MEDLOADER_EXPORT void keepOnlyStructureElements();
113     MEDLOADER_EXPORT void keepOnlyOnMeshSE(const std::string& meshName, const std::string& seName);
114     MEDLOADER_EXPORT void getMeshSENames(std::vector< std::pair<std::string,std::string> >& ps) const;
115     MEDLOADER_EXPORT void blowUpSE(MEDFileMeshes *ms, const MEDFileStructureElements *ses);
116     MEDLOADER_EXPORT MCAuto<MEDFileFields> partOfThisOnStructureElements() const;
117     MEDLOADER_EXPORT MCAuto<MEDFileFields> partOfThisLyingOnSpecifiedMeshSEName(const std::string& meshName, const std::string& seName) const;
118     MEDLOADER_EXPORT void aggregate(const MEDFileFields& other);
119     MEDLOADER_EXPORT MEDFileFieldsIterator *iterator();
120     MEDLOADER_EXPORT void destroyFieldAtPos(int i);
121     MEDLOADER_EXPORT void destroyFieldsAtPos(const int *startIds, const int *endIds);
122     MEDLOADER_EXPORT void destroyFieldsAtPos2(int bg, int end, int step);
123     MEDLOADER_EXPORT bool changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab);
124     MEDLOADER_EXPORT bool renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector<int>& oldCode, const std::vector<int>& newCode, const DataArrayInt *renumO2N);
125     MEDLOADER_EXPORT void accept(MEDFileFieldVisitor& visitor) const;
126     MEDLOADER_EXPORT MCAuto<MEDFileFields> linearToQuadratic(const MEDFileMeshes *oldLin, const MEDFileMeshes *newQuad) const;
127   public:
128     MEDLOADER_EXPORT MEDFileFields *extractPart(const std::map<int, MCAuto<DataArrayInt> >& extractDef, MEDFileMesh *mm) const;
129   public:
130     MEDLOADER_EXPORT std::vector<std::string> getPflsReallyUsed() const;
131     MEDLOADER_EXPORT std::vector<std::string> getLocsReallyUsed() const;
132     MEDLOADER_EXPORT std::vector<std::string> getPflsReallyUsedMulti() const;
133     MEDLOADER_EXPORT std::vector<std::string> getLocsReallyUsedMulti() const;
134     MEDLOADER_EXPORT void changePflsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif);
135     MEDLOADER_EXPORT void changeLocsRefsNamesGen(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif);
136   private:
137     ~MEDFileFields() { }
138     MEDFileFields();
139     MEDFileFields(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities);
140   private:
141     std::vector< MCAuto<MEDFileAnyTypeFieldMultiTSWithoutSDA> > _fields;
142   };
143
144   class MEDFileFieldsIterator
145   {
146   public:
147     MEDLOADER_EXPORT MEDFileFieldsIterator(MEDFileFields *fs);
148     MEDLOADER_EXPORT ~MEDFileFieldsIterator();
149     MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTS *nextt();
150   private:
151     MCAuto<MEDFileFields> _fs;
152     int _iter_id;
153     int _nb_iter;
154   };
155 }
156
157 #endif