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

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

Adapt transformation algorithm to new infrastructure (on going...)

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: 17.1 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 computeIndex(void);
152         void computeIndexScalarGrid();
153         void solveDomainAxisRef(bool areAttributesChecked);
154         void checkElementsAttributes(void) ;
155
156         void solveDomainRef(bool checkAtt);
157         void solveAxisRef(bool checkAtt);
158         void solveScalarRef(bool checkAtt);
159         void solveElementsRefInheritance(bool apply = true);
160        // void solveTransformations();
161         void solveDomainAxisBaseRef();
162
163         CDomain* addDomain(const std::string& id=StdString());
164         CAxis* addAxis(const std::string& id=StdString());
165         CScalar* addScalar(const std::string& id=StdString());
166
167      public:
168         void sendGridToFileServer(CContextClient* client) ;
169      private:
170         std::set<CContextClient*> sendGridToFileServer_done_ ;
171     
172      public:
173         void sendGridToCouplerOut(CContextClient* client, const string& fieldId) ;
174      private:
175         std::set<CContextClient*> sendGridToCouplerOut_done_ ;
176
177      public:
178         void makeAliasForCoupling(const string& fieldId) ;
179
180      public:
181         void sendAddDomain(const std::string& id,CContextClient* contextClient);
182         void sendAddAxis(const std::string& id,CContextClient* contextClient);
183         void sendAddScalar(const std::string& id,CContextClient* contextClient);
184       
185         static void recvAddDomain(CEventServer& event);
186         void recvAddDomain(CBufferIn& buffer);
187         static void recvAddAxis(CEventServer& event);
188         void recvAddAxis(CBufferIn& buffer);
189         static void recvAddScalar(CEventServer& event);
190         void recvAddScalar(CBufferIn& buffer);
191
192         static bool dispatchEvent(CEventServer& event);
193       
194       public:
195         void setContextClient(CContextClient* contextClient);
196
197         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
198         std::map<int, StdSize> getDataBufferSize(CContextClient* client, const std::string& id = "", bool bufferForWriting = false);
199         std::vector<StdString> getDomainList();
200         std::vector<StdString> getAxisList();
201         std::vector<StdString> getScalarList();
202         std::vector<CDomain*> getDomains();
203         std::vector<CAxis*> getAxis();
204         std::vector<CScalar*> getScalars();
205         CDomain* getDomain(int domainIndex);
206         CAxis* getAxis(int axisIndex);
207         CScalar* getScalar(int scalarIndex);
208         std::vector<int> getAxisOrder();
209         std::vector<int> getGlobalDimension();
210         bool isScalarGrid() const;         
211
212         bool doGridHaveDataToWrite();
213         bool doGridHaveDataDistributed(CContextClient* client = 0);
214
215         ///////////////////////////////////////////
216         ////////    TRANSFORMATIONS           /////
217         ///////////////////////////////////////////
218      public:
219         CGridTransformation* getTransformations();
220
221         void transformGrid(CGrid* transformGridSrc);
222         
223         void prepareTransformGrid(CGrid* transformGridSrc);
224         bool prepareTransformGrid_done_ = false ;
225
226         void makeTransformGrid(void); 
227         bool makeTransformGrid_done_ = false ;
228         
229         std::vector<std::string> getAuxInputTransformGrid(void) ; 
230         std::map<CGrid*, std::pair<bool,StdString> >& getTransGridSource();
231         bool hasTransform();
232         void addTransGridSource(CGrid* gridSrc);
233         void completeGrid(CGrid* transformGridSrc = 0);
234         bool isTransformed();
235         void setTransformed();
236         bool isGenerated();
237         void setGenerated();
238         void setTransformationAlgorithms();
239         pair<shared_ptr<CFilter>, shared_ptr<CFilter> > buildTransformationGraph(CGarbageCollector& gc, bool isSource, CGrid* gridSrc, double detectMissingValues,
240                                                                                  double defaultValue, CGrid*& newGrid) ;
241      private:
242        CGridAlgorithm* gridAlgorithm_ = nullptr ;
243      public:
244        void setGridAlgorithm(CGridAlgorithm* gridAlgorithm) {gridAlgorithm_ = gridAlgorithm;}
245        CGridAlgorithm* getGridAlgorithm(void) { return gridAlgorithm_ ;}
246      private:
247         bool isTransformed_, isGenerated_;
248         CGridTransformation* transformations_;
249         bool hasTransform_;
250       
251        ///////////////////////////////////////////
252      public:
253
254        size_t getGlobalWrittenSize(void) ;
255         
256         bool isCompleted(void) ;
257         void setCompleted(void) ;
258         void unsetCompleted(void) ;
259
260
261         bool hasMask(void) const;
262        /** get mask pointer stored in mask_1d, or mask_2d, or..., or mask_7d */
263         CArray<bool,1> mask_ ;
264         CArray<bool,1>& getMask(void) ;
265
266      private:
267        /** Client-like distribution calculated based on the knowledge of the entire grid */
268       CDistributionClient* clientDistribution_;
269     public: 
270       void computeClientDistribution(void) ;
271     private:
272       bool computeClientDistribution_done_ = false ;
273     public:
274       CDistributionClient* getClientDistribution(void); 
275
276     private:   
277        void setVirtualDomainGroup(CDomainGroup* newVDomainGroup);
278        void setVirtualAxisGroup(CAxisGroup* newVAxisGroup);
279        void setVirtualScalarGroup(CScalarGroup* newVScalarGroup);
280
281        void setDomainList(const std::vector<CDomain*> domains = std::vector<CDomain*>());
282        void setAxisList(const std::vector<CAxis*> axis = std::vector<CAxis*>());
283        void setScalarList(const std::vector<CScalar*> scalars = std::vector<CScalar*>());
284
285        CDomainGroup* getVirtualDomainGroup() const;
286        CAxisGroup* getVirtualAxisGroup() const;
287        CScalarGroup* getVirtualScalarGroup() const;
288
289        int computeGridGlobalDimension(std::vector<int>& globalDim,
290                                       const std::vector<CDomain*> domains,
291                                       const std::vector<CAxis*> axis,
292                                       const std::vector<CScalar*> scalars,
293                                       const CArray<int,1>& axisDomainOrder);
294        int getDistributedDimension();
295      public:
296
297        bool isDataDistributed(void) ; 
298      private:
299
300/** Clients that have to send a grid. There can be multiple clients in case of secondary server, otherwise only one client. */
301        std::list<CContextClient*> clients;
302        std::set<CContextClient*> clientsSet;
303
304      private:
305        bool isChecked;
306        bool isDomainAxisChecked;
307        bool isIndexSent;
308
309        CDomainGroup* vDomainGroup_;
310        CAxisGroup* vAxisGroup_;
311        CScalarGroup* vScalarGroup_;
312        std::vector<std::string> axisList_, domList_, scalarList_;
313        bool isAxisListSet, isDomListSet, isScalarListSet;
314
315/** Map storing local ranks of connected receivers. Key = size of receiver's intracomm.
316  * It is calculated in computeConnectedClients(). */
317        std::map<int, std::vector<int> > connectedServerRank_;
318
319/** Map storing the size of data to be send. Key = size of receiver's intracomm
320  * It is calculated in computeConnectedClients(). */
321        std::map<int, std::map<int,size_t> > connectedDataSize_;
322
323/** Ranks of connected receivers in case of reading. It is calculated in recvIndex(). */
324        std::vector<int> connectedServerRankRead_;
325
326/** Size of data to be send in case of reading. It is calculated in recvIndex(). */
327        std::map<int,size_t> connectedDataSizeRead_;
328     
329         //! True if and only if the data defined on the grid can be outputted in a compressed way
330        bool isCompressible_;
331        std::set<std::string> relFilesCompressed;
332
333       
334        std::vector<int> axisPositionInGrid_;
335        void computeAxisPositionInGrid(void) ;
336        bool computeAxisPositionInGrid_done_ = false ;
337        std::vector<int>& getAxisPositionInGrid(void) { if (!computeAxisPositionInGrid_done_) computeAxisPositionInGrid() ; return axisPositionInGrid_ ;}
338
339        bool hasDomainAxisBaseRef_;       
340        std::map<CGrid*, std::pair<bool,StdString> > gridSrc_;
341
342     //////////////////////////////////////////////////////////////////////////////////////
343     //  this part is related to distribution, element definition, views and connectors  //
344     //////////////////////////////////////////////////////////////////////////////////////
345      public:
346       CGrid* duplicateSentGrid(void) ;
347      private:
348       static void recvMask(CEventServer& event) ;
349       void receiveMask(CEventServer& event) ;
350
351      private: 
352        CGridLocalElements* gridLocalElements_= nullptr ;
353        void computeGridLocalElements(void) ;
354      public:
355        CGridLocalElements* getGridLocalElements(void) { if (gridLocalElements_==nullptr) computeGridLocalElements() ; return gridLocalElements_ ;}
356
357      private:
358        CGridLocalConnector* modelToWorkflowConnector_ = nullptr ;
359      public:
360        void computeModelToWorkflowConnector(void) ;
361        CGridLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_;}
362
363      private:
364        CGridLocalConnector* workflowToModelConnector_ ;
365      public:
366        void computeWorkflowToModelConnector(void) ;
367        CGridLocalConnector* getWorkflowToModelConnector(void) { if (workflowToModelConnector_==nullptr) computeWorkflowToModelConnector() ; return workflowToModelConnector_;}
368
369      public: //?
370        void distributeGridToFileServer(CContextClient* client);
371     
372           
373      private:
374        CGridLocalConnector* workflowToFullConnector_ = nullptr;
375      public:
376        void computeWorkflowToFullConnector(void) ;
377        CGridLocalConnector* getWorkflowToFullConnector(void) { if (workflowToFullConnector_==nullptr) computeWorkflowToFullConnector() ; return workflowToFullConnector_;}
378
379      private:
380        CGridLocalConnector* fullToWorkflowConnector_ = nullptr;
381      public:
382        void computeFullToWorkflowConnector(void) ;
383        CGridLocalConnector* getFullToWorkflowConnector(void) { if (fullToWorkflowConnector_==nullptr) computeFullToWorkflowConnector() ; return fullToWorkflowConnector_;}
384
385   
386
387      private:
388         CGridGathererConnector* clientFromClientConnector_ = nullptr ;
389      public:
390         CGridGathererConnector* getClientFromClientConnector(void) { if (clientFromClientConnector_==nullptr) computeClientFromClientConnector() ; return clientFromClientConnector_;}
391         void computeClientFromClientConnector(void) ;
392
393      private:
394         map<CContextClient*, CGridScattererConnector*> clientToClientConnector_ ;
395      public:
396         CGridScattererConnector* getClientToClientConnector(CContextClient* client) { return clientToClientConnector_[client] ;} // make some test to see if connector exits for the given client
397 
398
399      private:
400         map<CContextClient*,CGridGathererConnector*> clientFromServerConnector_  ;
401      public:
402         CGridGathererConnector* getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client];}
403         void computeClientFromServerConnector(void) ;
404
405      private:
406         CGridScattererConnector* serverToClientConnector_=nullptr ;
407      public:
408         CGridScattererConnector* getServerToClientConnector(void) { if (serverToClientConnector_==nullptr) computeServerToClientConnector() ; return serverToClientConnector_;}
409         void computeServerToClientConnector(void) ;
410      private:
411         map<CContextClient*, CGridScattererConnector*> clientToServerConnector_ ;
412      public:
413         CGridScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;} // make some test to see if connector exits for the given client
414         
415      private:
416         CGridGathererConnector* serverFromClientConnector_ = nullptr ;
417      public:
418         CGridGathererConnector* getServerFromClientConnector(void) { if (serverFromClientConnector_==nullptr) computeServerFromClientConnector() ; return serverFromClientConnector_;}
419         void computeServerFromClientConnector(void) ;
420
421   }; // class CGrid
422
423   // Declare/Define CGridGroup and CGridDefinition
424   DECLARE_GROUP(CGrid);
425
426   ///--------------------------------------------------------------
427
428} // namespace xios
429
430#endif // __XIOS_CGrid__
Note: See TracBrowser for help on using the repository browser.