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