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;
49 vtkIdTypeArray *findOrCreate(const MEDCoupling::MEDFileFieldGlobsReal *globs, const std::vector<std::string>& locsReallyUsed, vtkDoubleArray *vtkd, vtkDataSet *ds, bool& isNew) const;
50 void appendELGAIfAny(vtkDataSet *ds) const;
53 vtkIdTypeArray *isExisting(const std::vector<std::string>& locsReallyUsed, vtkDoubleArray *vtkd) const;
54 vtkIdTypeArray *createNew(const MEDCoupling::MEDFileFieldGlobsReal *globs, const std::vector<std::string>& locsReallyUsed, vtkDoubleArray *vtkd, vtkDataSet *ds) const;
56 //! size of _loc_names is equal to _elgas.
57 mutable std::vector< std::vector<std::string> > _loc_names;
58 //! size of _elgas is equal to _loc_names. All instances in _elgas are \b not null.
59 mutable std::vector<vtkIdTypeArray *> _elgas;
60 //! same size than _loc_names and _elgas.
61 mutable std::vector< std::vector< std::pair< vtkQuadratureSchemeDefinition *, unsigned char > > > _defs;
64 class MEDLOADERFORPV_EXPORT MEDFileFieldRepresentationLeavesArrays : public MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeFieldMultiTS>
67 MEDFileFieldRepresentationLeavesArrays();
68 MEDFileFieldRepresentationLeavesArrays(const MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeFieldMultiTS>& arr);
69 MEDFileFieldRepresentationLeavesArrays& operator=(const MEDFileFieldRepresentationLeavesArrays& other);
71 void setId(int& id) const;
72 void feedSIL(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
73 void computeFullNameInLeaves(const std::string& tsName, const std::string& meshName, const std::string& comSupStr) const;
74 bool getStatus() const;
75 bool setStatus(bool status) const;
76 std::string getZeName() const;
77 const char *getZeNameC() const;
78 void appendFields(const MEDTimeReq *tr, const MEDCoupling::MEDFileFieldGlobsReal *globs, const MEDCoupling::MEDMeshMultiLev *mml, const MEDCoupling::MEDFileMeshStruct *mst, vtkDataSet *ds) const;
79 void appendELGAIfAny(vtkDataSet *ds) const;
81 static const char ZE_SEP[];
82 static const char TS_STR[];
83 static const char COM_SUP_STR[];
84 static const char FAMILY_ID_CELL_NAME[];
85 static const char NUM_ID_CELL_NAME[];
86 static const char FAMILY_ID_NODE_NAME[];
87 static const char NUM_ID_NODE_NAME[];
88 static const char GLOBAL_NODE_ID_NAME[];
90 mutable bool _activated;
92 mutable std::string _ze_name;
93 mutable std::string _ze_full_name;
97 class MEDLOADERFORPV_EXPORT MEDFileFieldRepresentationLeaves
100 MEDFileFieldRepresentationLeaves();
101 MEDFileFieldRepresentationLeaves(const std::vector< MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeFieldMultiTS> >& arr,
102 const MEDCoupling::MCAuto<MEDCoupling::MEDFileFastCellSupportComparator>& fsp);
103 ~MEDFileFieldRepresentationLeaves();
105 void setId(int& id) const;
106 std::string getMeshName() const;
107 int getNumberOfArrays() const;
108 int getNumberOfTS() const;
109 void feedSIL(const MEDCoupling::MEDFileMeshes *ms, const std::string& meshName, vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
110 void computeFullNameInLeaves(const std::string& tsName, const std::string& meshName, const std::string& comSupStr) const;
111 bool containId(int id) const;
112 bool containZeName(const char *name, int& id) const;
113 void dumpState(std::map<std::string,bool>& status) const;
114 bool isActivated() const;
115 void printMySelf(std::ostream& os) const;
116 void activateAllArrays() const;
117 const MEDFileFieldRepresentationLeavesArrays& getLeafArr(int id) const;
118 std::vector<double> getTimeSteps(const TimeKeeper& tk) const;
119 std::vector< std::pair<int,int> > getTimeStepsInCoarseMEDFileFormat(std::vector<double>& ts) const;
120 std::string getHumanReadableOverviewOfTS() const;
121 vtkDataSet *buildVTKInstanceNoTimeInterpolation(const MEDTimeReq *tr, const MEDCoupling::MEDFileFieldGlobsReal *globs, const MEDCoupling::MEDFileMeshes *meshes) const;
123 vtkUnstructuredGrid *buildVTKInstanceNoTimeInterpolationUnstructured(MEDCoupling::MEDUMeshMultiLev *mm) const;
124 vtkRectilinearGrid *buildVTKInstanceNoTimeInterpolationCartesian(MEDCoupling::MEDCMeshMultiLev *mm) const;
125 vtkStructuredGrid *buildVTKInstanceNoTimeInterpolationCurveLinear(MEDCoupling::MEDCurveLinearMeshMultiLev *mm) const;
126 void appendFields(const MEDTimeReq *tr, const MEDCoupling::MEDFileFieldGlobsReal *globs, const MEDCoupling::MEDMeshMultiLev *mml, const MEDCoupling::MEDFileMeshes *meshes, vtkDataSet *ds) const;
128 std::vector<MEDFileFieldRepresentationLeavesArrays> _arrays;
129 MEDCoupling::MCAuto<MEDCoupling::MEDFileFastCellSupportComparator> _fsp;
130 mutable vtkDataSet *_cached_ds;
133 class MEDLOADERFORPV_EXPORT MEDFileFieldRepresentationTree
136 MEDFileFieldRepresentationTree();
137 int getNumberOfLeavesArrays() const;
138 void assignIds() const;
139 void activateTheFirst() const;
140 void computeFullNameInLeaves() const;
141 void feedSIL(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
142 std::string getActiveMeshName() const;
143 std::string feedSILForFamsAndGrps(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
144 std::string getNameOf(int id) const;
145 const char *getNameOfC(int id) const;
146 bool getStatusOf(int id) const;
147 int getIdHavingZeName(const char *name) const;
148 bool changeStatusOfAndUpdateToHaveCoherentVTKDataSet(int id, bool status) const;
149 int getMaxNumberOfTimeSteps() const;
151 std::string getDftMeshName() const;
152 std::vector<double> getTimeSteps(int& lev0, const TimeKeeper& tk) const;
153 vtkDataSet *buildVTKInstance(bool isStdOrMode, double timeReq, std::string& meshName, const TimeKeeper& tk) const;
154 void printMySelf(std::ostream& os) const;
155 std::map<std::string,bool> dumpState() const;
157 void loadMainStructureOfFile(const char *fileName, bool isMEDOrSauv, int iPart, int nbOfParts);
158 void removeEmptyLeaves();
160 static bool IsFieldMeshRegardingInfo(const std::vector<std::string>& compInfos);
161 static std::string PostProcessFieldName(const std::string& fullFieldName);
163 static const char ROOT_OF_GRPS_IN_TREE[];
164 static const char ROOT_OF_FAM_IDS_IN_TREE[];
165 static const char COMPO_STR_TO_LOCATE_MESH_DA[];
167 const MEDFileFieldRepresentationLeavesArrays& getLeafArr(int id) const;
168 const MEDFileFieldRepresentationLeaves& getTheSingleActivated(int& lev0, int& lev1, int& lev2) const;
169 static MEDCoupling::MEDFileFields *BuildFieldFromMeshes(const MEDCoupling::MEDFileMeshes *ms);
170 static void AppendFieldFromMeshes(const MEDCoupling::MEDFileMeshes *ms, MEDCoupling::MEDFileFields *ret);
171 static std::string BuildAUniqueArrayNameForMesh(const std::string& meshName, const MEDCoupling::MEDFileFields *ret);
172 static std::vector<std::string> SplitFieldNameIntoParts(const std::string& fullFieldName, char sep);
174 // 1st : timesteps, 2nd : meshName, 3rd : common support
175 std::vector< std::vector< std::vector< MEDFileFieldRepresentationLeaves > > > _data_structure;
176 MEDCoupling::MCAuto<MEDCoupling::MEDFileMeshes> _ms;
177 MEDCoupling::MCAuto<MEDCoupling::MEDFileFields> _fields;
180 class MEDLOADERFORPV_EXPORT TimeKeeper
183 TimeKeeper(int policy);
184 int getPolicy() const { return _policy; }
185 void setPolicy(int policy) { _policy=policy; }
186 std::vector<double> getTimeStepsRegardingPolicy(const std::vector< std::pair<int,int> >& tsPairs, const std::vector<double>& ts) const;
187 int getTimeStepIdFrom(double timeReq) const;
188 std::vector<double> getPostProcessedTime() const { return _postprocessed_time; }
189 void printSelf(std::ostream& oss) const;
190 std::vector<bool> getTheVectOfBool() const;
191 std::vector< std::pair<bool,std::string> >& getTimesFlagArray() { return _activated_ts; }
192 void setMaxNumberOfTimeSteps(int maxNumberOfTS);
194 std::vector<double> getTimeStepsRegardingPolicy0(const std::vector< std::pair<int,int> >& tsPairs, const std::vector<double>& ts) const;
195 std::vector<double> getTimeStepsRegardingPolicy1(const std::vector< std::pair<int,int> >& tsPairs, const std::vector<double>& ts) const;
196 std::vector<double> processedUsingPairOfIds(const std::vector< std::pair<int,int> >& tsPairs) const;
199 mutable std::vector<double> _postprocessed_time;
200 std::vector< std::pair<bool,std::string> > _activated_ts;