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