Salome HOME
Copyright update 2022
[modules/paravis.git] / src / Plugins / MEDReader / plugin / MEDLoaderForPV / MEDFileFieldRepresentationTree.hxx
1 // Copyright (C) 2010-2022  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
20
21 #ifndef __MEDFILEFIELDREPRESENTATIONTREE_HXX__
22 #define __MEDFILEFIELDREPRESENTATIONTREE_HXX__
23
24 #include "MEDFileMesh.hxx"
25 #include "MEDFileField.hxx"
26 #include "MEDLoaderForPV.h"
27
28 #include "vtkType.h"
29
30 #include <vector>
31 #include <map>
32
33 class vtkQuadratureSchemeDefinition;
34 class vtkMutableDirectedGraph;
35 class vtkUnstructuredGrid;
36 class vtkRectilinearGrid;
37 class vtkStructuredGrid;
38 class vtkVariantArray;
39 class vtkIdTypeArray;
40 class vtkDoubleArray;
41 class vtkDataArray;
42 class vtkDataSet;
43
44 class TimeKeeper;
45 class MEDTimeReq;
46 class ExportedTinyInfo;
47
48 class ELGACmp
49 {
50 public:
51   template<class T>
52   vtkIdTypeArray *findOrCreate(const MEDCoupling::MEDFileFieldGlobsReal *globs, const std::vector<std::string>& locsReallyUsed, vtkDataArray *vtkd, vtkDataSet *ds, bool& isNew, ExportedTinyInfo *internalInfo) const;
53   void appendELGAIfAny(vtkDataSet *ds) const;
54   ~ELGACmp();
55 private:
56   vtkIdTypeArray *isExisting(const std::vector<std::string>& locsReallyUsed, vtkDataArray *vtkd) const;
57   template<class T>
58   vtkIdTypeArray *createNew(const MEDCoupling::MEDFileFieldGlobsReal *globs, const std::vector<std::string>& locsReallyUsed, vtkDataArray *vtkd, vtkDataSet *ds, ExportedTinyInfo *internalInfo) const;
59 private:
60   //! size of _loc_names is equal to _elgas.
61   mutable std::vector< std::vector<std::string> > _loc_names;
62   //! size of _elgas is equal to _loc_names. All instances in _elgas are \b not null.
63   mutable std::vector<vtkIdTypeArray *> _elgas;
64   //! same size than _loc_names and _elgas.
65   mutable std::vector< std::vector< std::pair< vtkQuadratureSchemeDefinition *, unsigned char > > > _defs;
66 };
67
68 class MEDLOADERFORPV_EXPORT MEDFileFieldRepresentationLeavesArrays : public MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeFieldMultiTS>
69 {
70 public:
71   MEDFileFieldRepresentationLeavesArrays();
72   MEDFileFieldRepresentationLeavesArrays(const MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeFieldMultiTS>& arr);
73   MEDFileFieldRepresentationLeavesArrays& operator=(const MEDFileFieldRepresentationLeavesArrays& other);
74   int getId() const;
75   void setId(int& id) const;
76   void feedSIL(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
77   void computeFullNameInLeaves(const std::string& tsName, const std::string& meshName, const std::string& comSupStr) const;
78   bool getStatus() const;
79   bool setStatus(bool status) const;
80   std::string getZeName() const;
81   const char *getZeNameC() const;
82   void appendFields(const MEDTimeReq *tr, const MEDCoupling::MEDFileFieldGlobsReal *globs, const MEDCoupling::MEDMeshMultiLev *mml, const MEDCoupling::MEDFileMeshStruct *mst, vtkDataSet *ds, ExportedTinyInfo *internalInfo) const;
83   void appendELGAIfAny(vtkDataSet *ds) const;
84 public:
85   static const char ZE_SEP[];
86   static const char TS_STR[];
87   static const char COM_SUP_STR[];
88   static const char FAMILY_ID_CELL_NAME[];
89   static const char NUM_ID_CELL_NAME[];
90   static const char FAMILY_ID_NODE_NAME[];
91   static const char NUM_ID_NODE_NAME[];
92   static const char GLOBAL_NODE_ID_NAME[];
93 private:
94   mutable bool _activated;
95   mutable int _id;
96   mutable std::string _ze_name;
97   mutable std::string _ze_full_name;
98   ELGACmp _elga_cmp;
99 };
100
101 class MEDLOADERFORPV_EXPORT MEDFileFieldRepresentationLeaves
102 {
103 public:
104   MEDFileFieldRepresentationLeaves();
105   MEDFileFieldRepresentationLeaves(const std::vector< MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeFieldMultiTS> >& arr,
106                                    const MEDCoupling::MCAuto<MEDCoupling::MEDFileFastCellSupportComparator>& fsp);
107   ~MEDFileFieldRepresentationLeaves();
108   bool empty() const;
109   void setId(int& id) const;
110   std::string getMeshName() const;
111   int getNumberOfArrays() const;
112   int getNumberOfTS() const;
113   void feedSIL(const MEDCoupling::MEDFileMeshes *ms, const std::string& meshName, vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
114   void computeFullNameInLeaves(const std::string& tsName, const std::string& meshName, const std::string& comSupStr) const;
115   bool containId(int id) const;
116   bool containZeName(const char *name, int& id) const;
117   void dumpState(std::map<std::string,bool>& status) const;
118   bool isActivated() const;
119   void printMySelf(std::ostream& os) const;
120   void activateAllArrays() const;
121   const MEDFileFieldRepresentationLeavesArrays& getLeafArr(int id) const;
122   std::vector<double> getTimeSteps(const TimeKeeper& tk) const;
123   std::vector< std::pair<int,int> > getTimeStepsInCoarseMEDFileFormat(std::vector<double>& ts) const;
124   std::string getHumanReadableOverviewOfTS() const;
125   vtkDataSet *buildVTKInstanceNoTimeInterpolation(const MEDTimeReq *tr, const MEDCoupling::MEDFileFieldGlobsReal *globs, const MEDCoupling::MEDFileMeshes *meshes, ExportedTinyInfo *internalInfo=0) const;
126 private:
127   vtkUnstructuredGrid *buildVTKInstanceNoTimeInterpolationUnstructured(MEDCoupling::MEDUMeshMultiLev *mm) const;
128   vtkRectilinearGrid *buildVTKInstanceNoTimeInterpolationCartesian(MEDCoupling::MEDCMeshMultiLev *mm) const;
129   vtkStructuredGrid *buildVTKInstanceNoTimeInterpolationCurveLinear(MEDCoupling::MEDCurveLinearMeshMultiLev *mm) const;
130   void appendFields(const MEDTimeReq *tr, const MEDCoupling::MEDFileFieldGlobsReal *globs, const MEDCoupling::MEDMeshMultiLev *mml, const MEDCoupling::MEDFileMeshes *meshes, vtkDataSet *ds, ExportedTinyInfo *internalInfo=0) const;
131 private:
132   std::vector<MEDFileFieldRepresentationLeavesArrays> _arrays;
133   MEDCoupling::MCAuto<MEDCoupling::MEDFileFastCellSupportComparator> _fsp;
134   mutable vtkDataSet *_cached_ds;
135 };
136
137 class MEDLOADERFORPV_EXPORT MEDFileFieldRepresentationTree
138 {
139 public:
140   MEDFileFieldRepresentationTree();
141   int getNumberOfLeavesArrays() const;
142   void assignIds() const;
143   void activateTheFirst() const;
144   void computeFullNameInLeaves() const;
145   void feedSIL(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
146   std::string getActiveMeshName() const;
147   std::string feedSILForFamsAndGrps(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
148   std::string getNameOf(int id) const;
149   const char *getNameOfC(int id) const;
150   bool getStatusOf(int id) const;
151   int getIdHavingZeName(const char *name) const;
152   bool changeStatusOfAndUpdateToHaveCoherentVTKDataSet(int id, bool status) const;
153   int getMaxNumberOfTimeSteps() const;
154   //
155   std::string getDftMeshName() const;
156   std::vector<double> getTimeSteps(int& lev0, const TimeKeeper& tk) const;
157   vtkDataSet *buildVTKInstance(bool isStdOrMode, double timeReq, std::string& meshName, const TimeKeeper& tk, ExportedTinyInfo *internalInfo=0) const;
158   void printMySelf(std::ostream& os) const;
159   std::map<std::string,bool> dumpState() const;
160   //non const methods
161   void loadMainStructureOfFile(const char *fileName, int iPart, int nbOfParts);
162   void loadInMemory(MEDCoupling::MEDFileFields *fields, MEDCoupling::MEDFileMeshes *meshes);
163   void removeEmptyLeaves();
164   // static methods
165   static bool IsFieldMeshRegardingInfo(const std::vector<std::string>& compInfos);
166   static std::string PostProcessFieldName(const std::string& fullFieldName);
167 public:
168   static const char ROOT_OF_GRPS_IN_TREE[];
169   static const char ROOT_OF_FAM_IDS_IN_TREE[];
170   static const char COMPO_STR_TO_LOCATE_MESH_DA[];
171 private:
172   const MEDFileFieldRepresentationLeavesArrays& getLeafArr(int id) const;
173   const MEDFileFieldRepresentationLeaves& getTheSingleActivated(int& lev0, int& lev1, int& lev2) const;
174   static MEDCoupling::MEDFileFields *BuildFieldFromMeshes(const MEDCoupling::MEDFileMeshes *ms);
175   static void AppendFieldFromMeshes(const MEDCoupling::MEDFileMeshes *ms, MEDCoupling::MEDFileFields *ret);
176   static std::string BuildAUniqueArrayNameForMesh(const std::string& meshName, const MEDCoupling::MEDFileFields *ret);
177   static std::vector<std::string> SplitFieldNameIntoParts(const std::string& fullFieldName, char sep);
178 private:
179   // 1st : timesteps, 2nd : meshName, 3rd : common support
180   std::vector< std::vector< std::vector< MEDFileFieldRepresentationLeaves > > > _data_structure;
181   MEDCoupling::MCAuto<MEDCoupling::MEDFileMeshes> _ms;
182   MEDCoupling::MCAuto<MEDCoupling::MEDFileFields> _fields;
183 };
184
185 class MEDLOADERFORPV_EXPORT TimeKeeper
186 {
187 public:
188   TimeKeeper(int policy);
189   int getPolicy() const { return _policy; }
190   void setPolicy(int policy) { _policy=policy; }
191   std::vector<double> getTimeStepsRegardingPolicy(const std::vector< std::pair<int,int> >& tsPairs, const std::vector<double>& ts) const;
192   int getTimeStepIdFrom(double timeReq) const;
193   std::vector<double> getPostProcessedTime() const { return _postprocessed_time; }
194   void printSelf(std::ostream& oss) const;
195   std::vector<bool> getTheVectOfBool() const;
196   std::vector< std::pair<bool,std::string> >& getTimesFlagArray() { return _activated_ts; }
197   void setMaxNumberOfTimeSteps(int maxNumberOfTS);
198 private:
199   std::vector<double> getTimeStepsRegardingPolicy0(const std::vector< std::pair<int,int> >& tsPairs, const std::vector<double>& ts) const;
200   std::vector<double> getTimeStepsRegardingPolicy1(const std::vector< std::pair<int,int> >& tsPairs, const std::vector<double>& ts) const;
201   std::vector<double> processedUsingPairOfIds(const std::vector< std::pair<int,int> >& tsPairs) const;
202 private:
203   int _policy;
204   mutable std::vector<double> _postprocessed_time;
205   std::vector< std::pair<bool,std::string> > _activated_ts;
206 };
207
208 #endif