source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/grid.hpp @ 2002

Last change on this file since 2002 was 2002, checked in by ymipsl, 3 years ago

Some cleaning of old transformation dead code

YM

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
  • Property svn:executable set to *
File size: 16.4 KB
Line 
1#ifndef __XIOS_CGrid__
2#define __XIOS_CGrid__
3
4/// XIOS headers ///
5#include "xios_spl.hpp"
6#include "group_factory.hpp"
7
8#include "declare_group.hpp"
9#include "domain.hpp"
10#include "axis.hpp"
11#include "scalar.hpp"
12#include "array_new.hpp"
13#include "attribute_array.hpp"
14#include "distribution_server.hpp"
15#include "client_server_mapping.hpp"
16#include "utils.hpp"
17#include "transformation_enum.hpp"
18#include "grid_local_connector.hpp"
19#include "grid_elements.hpp"
20#include "grid_scatterer_connector.hpp"
21#include "grid_gatherer_connector.hpp"
22#include "transformation_path.hpp"
23#include "filter.hpp"
24#include "grid_algorithm.hpp"
25
26
27namespace xios {
28
29   /// ////////////////////// Declarations ////////////////////// ///
30
31   class CGridGroup;
32   class CGridAttributes;
33   class CDomainGroup;
34   class CAxisGroup;
35   class CScalarGroup;
36   class CGrid;
37   class CDistributionClient;
38   class CDistributionServer;
39   class CServerDistributionDescription;
40   class CClientServerMapping;
41   class CGridTransformation;
42
43   ///--------------------------------------------------------------
44
45   // Declare/Define CGridAttribute
46   BEGIN_DECLARE_ATTRIBUTE_MAP(CGrid)
47#  include "grid_attribute.conf"
48   END_DECLARE_ATTRIBUTE_MAP(CGrid)
49
50   ///--------------------------------------------------------------
51
52   class CGrid
53      : public CObjectTemplate<CGrid>
54      , public CGridAttributes
55   {
56         /// typedef ///
57         typedef CObjectTemplate<CGrid>   SuperClass;
58         typedef CGridAttributes SuperClassAttribute;
59
60      private:
61       
62        // define a structure to store elements (CDomain, CAxis, CScalar) using a void* and a type to cast the pointer
63         enum EElementType { TYPE_SCALAR, TYPE_AXIS, TYPE_DOMAIN } ;
64         struct SElement {void* ptr ; EElementType type ; CScalar* scalar ;  CAxis* axis ; CDomain* domain ; } ;
65         vector<SElement> elements_ ;
66         bool elementsComputed_ = false ; 
67         /** retrieve the vector of elements as a structure containing a void* and the type of pointer */
68         vector<SElement>& getElements(void) { if (!elementsComputed_) computeElements() ; return elements_ ; } 
69         void computeElements(void) ;
70         /** List order of axis and domain in a grid, if there is a domain, it will take value 2, axis 1, scalar 0 */
71         std::vector<int> order_;
72
73      public:
74
75         typedef CGridAttributes RelAttributes;
76         typedef CGridGroup      RelGroup;
77
78         enum EEventId
79         {
80           EVENT_ID_ADD_DOMAIN, EVENT_ID_ADD_AXIS, EVENT_ID_ADD_SCALAR,
81           EVENT_ID_SEND_MASK,
82
83         };
84
85         /// Constructeurs ///
86         CGrid(void);
87         explicit CGrid(const StdString& id);
88         CGrid(const CGrid& grid);       // Not implemented yet.
89         CGrid(const CGrid* const grid); // Not implemented yet.
90
91         /// Traitements ///
92//         void solveReference(void);
93
94         void checkEligibilityForCompressedOutput();
95         
96
97
98         void checkMaskIndex(bool doCalculateIndex);
99
100 //        virtual void toBinary  (StdOStream& os) const;
101//         virtual void fromBinary(StdIStream& is);
102
103         void addRelFileCompressed(const StdString& filename);
104
105         /// Tests ///
106         bool isCompressible(void) const;
107         bool isWrittenCompressed(const StdString& filename) const;
108
109      public:
110
111         /// Accesseurs ///
112         StdSize getDimension(void);
113
114         StdSize  getDataSize(void) ;
115
116         /**
117          * Get the local data grid size, ie the size of the compressed grid (inside the workflow)
118          * \return The size od the compressed grid
119          */
120         StdSize  getLocalDataSize(void) ;
121
122 
123         virtual void parse(xml::CXMLNode& node);
124
125         /// Destructeur ///
126         virtual ~CGrid(void);
127
128      public:
129
130         /// Accesseurs statiques ///
131         static StdString GetName(void);
132         static StdString GetDefName(void);
133
134         static ENodeType GetType(void);
135
136         /// Instanciateurs Statiques ///
137         static CGrid* createGrid(CDomain* domain);
138         static CGrid* createGrid(CDomain* domain, CAxis* axis);
139         static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
140                                  const CArray<int,1>& axisDomainOrder = CArray<int,1>());
141         static CGrid* createGrid(StdString id, const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
142                                  const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder = CArray<int,1>());
143         static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
144                                  const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder);
145         static StdString generateId(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
146                                     const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder = CArray<int,1>());
147         static StdString generateId(const CGrid* gridSrc, const CGrid* gridDest);
148         static CGrid* cloneGrid(const StdString& idNewGrid, CGrid* gridSrc);
149
150      public:           
151         void solveDomainAxisRef(bool areAttributesChecked);
152         void checkElementsAttributes(void) ;
153
154         void solveDomainRef(bool checkAtt);
155         void solveAxisRef(bool checkAtt);
156         void solveScalarRef(bool checkAtt);
157         void solveElementsRefInheritance(bool apply = true);
158        // void solveTransformations();
159         void solveDomainAxisBaseRef();
160
161         CDomain* addDomain(const std::string& id=StdString());
162         CAxis* addAxis(const std::string& id=StdString());
163         CScalar* addScalar(const std::string& id=StdString());
164
165      public:
166         void sendGridToFileServer(CContextClient* client) ;
167      private:
168         std::set<CContextClient*> sendGridToFileServer_done_ ;
169     
170      public:
171         void sendGridToCouplerOut(CContextClient* client, const string& fieldId) ;
172      private:
173         std::set<CContextClient*> sendGridToCouplerOut_done_ ;
174
175      public:
176         void makeAliasForCoupling(const string& fieldId) ;
177
178      public:
179         void sendAddDomain(const std::string& id,CContextClient* contextClient);
180         void sendAddAxis(const std::string& id,CContextClient* contextClient);
181         void sendAddScalar(const std::string& id,CContextClient* contextClient);
182       
183         static void recvAddDomain(CEventServer& event);
184         void recvAddDomain(CBufferIn& buffer);
185         static void recvAddAxis(CEventServer& event);
186         void recvAddAxis(CBufferIn& buffer);
187         static void recvAddScalar(CEventServer& event);
188         void recvAddScalar(CBufferIn& buffer);
189
190         static bool dispatchEvent(CEventServer& event);
191       
192       public:
193         void setContextClient(CContextClient* contextClient);
194
195         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
196         std::map<int, StdSize> getDataBufferSize(CContextClient* client, const std::string& id = "", bool bufferForWriting = false);
197         std::vector<StdString> getDomainList();
198         std::vector<StdString> getAxisList();
199         std::vector<StdString> getScalarList();
200         std::vector<CDomain*> getDomains();
201         std::vector<CAxis*> getAxis();
202         std::vector<CScalar*> getScalars();
203         CDomain* getDomain(int domainIndex);
204         CAxis* getAxis(int axisIndex);
205         CScalar* getScalar(int scalarIndex);
206         std::vector<int> getAxisOrder();
207         std::vector<int> getGlobalDimension();
208         bool isScalarGrid() const;         
209
210         bool doGridHaveDataToWrite();
211         bool doGridHaveDataDistributed(CContextClient* client = 0);
212
213         ///////////////////////////////////////////
214         ////////    TRANSFORMATIONS           /////
215         ///////////////////////////////////////////
216      public:
217         CGridTransformation* getTransformations();
218
219         std::vector<std::string> getAuxInputTransformGrid(void) ; 
220         void setTransformationAlgorithms();
221         pair<shared_ptr<CFilter>, shared_ptr<CFilter> > buildTransformationGraph(CGarbageCollector& gc, bool isSource, CGrid* gridSrc, double detectMissingValues,
222                                                                                  double defaultValue, CGrid*& newGrid) ;
223      private:
224        CGridAlgorithm* gridAlgorithm_ = nullptr ;
225      public:
226        void setGridAlgorithm(CGridAlgorithm* gridAlgorithm) {gridAlgorithm_ = gridAlgorithm;}
227        CGridAlgorithm* getGridAlgorithm(void) { return gridAlgorithm_ ;}
228      private:
229         bool isTransformed_;
230         CGridTransformation* transformations_;
231         bool hasTransform_;
232       
233        ///////////////////////////////////////////
234      public:
235
236        size_t getGlobalWrittenSize(void) ;
237         
238         bool isCompleted(void) ;
239         void setCompleted(void) ;
240         void unsetCompleted(void) ;
241
242
243         bool hasMask(void) const;
244        /** get mask pointer stored in mask_1d, or mask_2d, or..., or mask_7d */
245         CArray<bool,1> mask_ ;
246         CArray<bool,1>& getMask(void) ;
247
248      private:
249        /** Client-like distribution calculated based on the knowledge of the entire grid */
250       CDistributionClient* clientDistribution_;
251     public: 
252       void computeClientDistribution(void) ;
253     private:
254       bool computeClientDistribution_done_ = false ;
255     public:
256       CDistributionClient* getClientDistribution(void); 
257
258     private:   
259        void setVirtualDomainGroup(CDomainGroup* newVDomainGroup);
260        void setVirtualAxisGroup(CAxisGroup* newVAxisGroup);
261        void setVirtualScalarGroup(CScalarGroup* newVScalarGroup);
262
263        void setDomainList(const std::vector<CDomain*> domains = std::vector<CDomain*>());
264        void setAxisList(const std::vector<CAxis*> axis = std::vector<CAxis*>());
265        void setScalarList(const std::vector<CScalar*> scalars = std::vector<CScalar*>());
266
267        CDomainGroup* getVirtualDomainGroup() const;
268        CAxisGroup* getVirtualAxisGroup() const;
269        CScalarGroup* getVirtualScalarGroup() const;
270
271        int computeGridGlobalDimension(std::vector<int>& globalDim,
272                                       const std::vector<CDomain*> domains,
273                                       const std::vector<CAxis*> axis,
274                                       const std::vector<CScalar*> scalars,
275                                       const CArray<int,1>& axisDomainOrder);
276        int getDistributedDimension();
277      public:
278
279        bool isDataDistributed(void) ; 
280      private:
281
282/** Clients that have to send a grid. There can be multiple clients in case of secondary server, otherwise only one client. */
283        std::list<CContextClient*> clients;
284        std::set<CContextClient*> clientsSet;
285
286      private:
287        bool isChecked;
288        bool isDomainAxisChecked;
289        bool isIndexSent;
290
291        CDomainGroup* vDomainGroup_;
292        CAxisGroup* vAxisGroup_;
293        CScalarGroup* vScalarGroup_;
294        std::vector<std::string> axisList_, domList_, scalarList_;
295        bool isAxisListSet, isDomListSet, isScalarListSet;
296
297/** Map storing local ranks of connected receivers. Key = size of receiver's intracomm.
298  * It is calculated in computeConnectedClients(). */
299        std::map<int, std::vector<int> > connectedServerRank_;
300
301/** Map storing the size of data to be send. Key = size of receiver's intracomm
302  * It is calculated in computeConnectedClients(). */
303        std::map<int, std::map<int,size_t> > connectedDataSize_;
304
305/** Ranks of connected receivers in case of reading. It is calculated in recvIndex(). */
306        std::vector<int> connectedServerRankRead_;
307
308/** Size of data to be send in case of reading. It is calculated in recvIndex(). */
309        std::map<int,size_t> connectedDataSizeRead_;
310     
311         //! True if and only if the data defined on the grid can be outputted in a compressed way
312        bool isCompressible_;
313        std::set<std::string> relFilesCompressed;
314
315       
316        std::vector<int> axisPositionInGrid_;
317        void computeAxisPositionInGrid(void) ;
318        bool computeAxisPositionInGrid_done_ = false ;
319        std::vector<int>& getAxisPositionInGrid(void) { if (!computeAxisPositionInGrid_done_) computeAxisPositionInGrid() ; return axisPositionInGrid_ ;}
320
321        bool hasDomainAxisBaseRef_;       
322        std::map<CGrid*, std::pair<bool,StdString> > gridSrc_;
323
324     //////////////////////////////////////////////////////////////////////////////////////
325     //  this part is related to distribution, element definition, views and connectors  //
326     //////////////////////////////////////////////////////////////////////////////////////
327      public:
328       CGrid* duplicateSentGrid(void) ;
329      private:
330       static void recvMask(CEventServer& event) ;
331       void receiveMask(CEventServer& event) ;
332
333      private: 
334        CGridLocalElements* gridLocalElements_= nullptr ;
335        void computeGridLocalElements(void) ;
336      public:
337        CGridLocalElements* getGridLocalElements(void) { if (gridLocalElements_==nullptr) computeGridLocalElements() ; return gridLocalElements_ ;}
338
339      private:
340        CGridLocalConnector* modelToWorkflowConnector_ = nullptr ;
341      public:
342        void computeModelToWorkflowConnector(void) ;
343        CGridLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_;}
344
345      private:
346        CGridLocalConnector* workflowToModelConnector_ ;
347      public:
348        void computeWorkflowToModelConnector(void) ;
349        CGridLocalConnector* getWorkflowToModelConnector(void) { if (workflowToModelConnector_==nullptr) computeWorkflowToModelConnector() ; return workflowToModelConnector_;}
350
351      public: //?
352        void distributeGridToFileServer(CContextClient* client);
353     
354           
355      private:
356        CGridLocalConnector* workflowToFullConnector_ = nullptr;
357      public:
358        void computeWorkflowToFullConnector(void) ;
359        CGridLocalConnector* getWorkflowToFullConnector(void) { if (workflowToFullConnector_==nullptr) computeWorkflowToFullConnector() ; return workflowToFullConnector_;}
360
361      private:
362        CGridLocalConnector* fullToWorkflowConnector_ = nullptr;
363      public:
364        void computeFullToWorkflowConnector(void) ;
365        CGridLocalConnector* getFullToWorkflowConnector(void) { if (fullToWorkflowConnector_==nullptr) computeFullToWorkflowConnector() ; return fullToWorkflowConnector_;}
366
367   
368
369      private:
370         CGridGathererConnector* clientFromClientConnector_ = nullptr ;
371      public:
372         CGridGathererConnector* getClientFromClientConnector(void) { if (clientFromClientConnector_==nullptr) computeClientFromClientConnector() ; return clientFromClientConnector_;}
373         void computeClientFromClientConnector(void) ;
374
375      private:
376         map<CContextClient*, CGridScattererConnector*> clientToClientConnector_ ;
377      public:
378         CGridScattererConnector* getClientToClientConnector(CContextClient* client) { return clientToClientConnector_[client] ;} // make some test to see if connector exits for the given client
379 
380
381      private:
382         map<CContextClient*,CGridGathererConnector*> clientFromServerConnector_  ;
383      public:
384         CGridGathererConnector* getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client];}
385         void computeClientFromServerConnector(void) ;
386
387      private:
388         CGridScattererConnector* serverToClientConnector_=nullptr ;
389      public:
390         CGridScattererConnector* getServerToClientConnector(void) { if (serverToClientConnector_==nullptr) computeServerToClientConnector() ; return serverToClientConnector_;}
391         void computeServerToClientConnector(void) ;
392      private:
393         map<CContextClient*, CGridScattererConnector*> clientToServerConnector_ ;
394      public:
395         CGridScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;} // make some test to see if connector exits for the given client
396         
397      private:
398         CGridGathererConnector* serverFromClientConnector_ = nullptr ;
399      public:
400         CGridGathererConnector* getServerFromClientConnector(void) { if (serverFromClientConnector_==nullptr) computeServerFromClientConnector() ; return serverFromClientConnector_;}
401         void computeServerFromClientConnector(void) ;
402
403   }; // class CGrid
404
405   // Declare/Define CGridGroup and CGridDefinition
406   DECLARE_GROUP(CGrid);
407
408   ///--------------------------------------------------------------
409
410} // namespace xios
411
412#endif // __XIOS_CGrid__
Note: See TracBrowser for help on using the repository browser.