1 // Copyright (C) 2010-2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay
21 #ifndef __MEDFILEFIELDREPRESENTATIONTREE_HXX__
22 #define __MEDFILEFIELDREPRESENTATIONTREE_HXX__
24 #include "MEDFileMesh.hxx"
25 #include "MEDFileField.hxx"
26 #include "MEDLoaderForPV.h"
33 class vtkQuadratureSchemeDefinition;
34 class vtkMutableDirectedGraph;
35 class vtkUnstructuredGrid;
36 class vtkRectilinearGrid;
37 class vtkStructuredGrid;
38 class vtkVariantArray;
45 class ExportedTinyInfo;
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;
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;
57 //! size of _loc_names is equal to _elgas.
58 mutable std::vector< std::vector<std::string> > _loc_names;
59 //! size of _elgas is equal to _loc_names. All instances in _elgas are \b not null.
60 mutable std::vector<vtkIdTypeArray *> _elgas;
61 //! same size than _loc_names and _elgas.
62 mutable std::vector< std::vector< std::pair< vtkQuadratureSchemeDefinition *, unsigned char > > > _defs;
65 class MEDLOADERFORPV_EXPORT MEDFileFieldRepresentationLeavesArrays : public MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeFieldMultiTS>
68 MEDFileFieldRepresentationLeavesArrays();
69 MEDFileFieldRepresentationLeavesArrays(const MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeFieldMultiTS>& arr);
70 MEDFileFieldRepresentationLeavesArrays& operator=(const MEDFileFieldRepresentationLeavesArrays& other);
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;
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[];
91 mutable bool _activated;
93 mutable std::string _ze_name;
94 mutable std::string _ze_full_name;
98 class MEDLOADERFORPV_EXPORT MEDFileFieldRepresentationLeaves
101 MEDFileFieldRepresentationLeaves();
102 MEDFileFieldRepresentationLeaves(const std::vector< MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeFieldMultiTS> >& arr,
103 const MEDCoupling::MCAuto<MEDCoupling::MEDFileFastCellSupportComparator>& fsp);
104 ~MEDFileFieldRepresentationLeaves();
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;
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;
129 std::vector<MEDFileFieldRepresentationLeavesArrays> _arrays;
130 MEDCoupling::MCAuto<MEDCoupling::MEDFileFastCellSupportComparator> _fsp;
131 mutable vtkDataSet *_cached_ds;
134 class MEDLOADERFORPV_EXPORT MEDFileFieldRepresentationTree
137 MEDFileFieldRepresentationTree();
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;
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;
158 void loadMainStructureOfFile(const char *fileName, bool isMEDOrSauv, int iPart, int nbOfParts);
159 void loadInMemory(MEDCoupling::MEDFileFields *fields, MEDCoupling::MEDFileMeshes *meshes);
160 void removeEmptyLeaves();
162 static bool IsFieldMeshRegardingInfo(const std::vector<std::string>& compInfos);
163 static std::string PostProcessFieldName(const std::string& fullFieldName);
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[];
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);
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;
182 class MEDLOADERFORPV_EXPORT TimeKeeper
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);
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;
201 mutable std::vector<double> _postprocessed_time;
202 std::vector< std::pair<bool,std::string> > _activated_ts;