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

Last change on this file since 1973 was 1973, checked in by ymipsl, 4 years ago

Big cleaning on XIOS coupling branch
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
23
24namespace xios {
25
26   /// ////////////////////// Declarations ////////////////////// ///
27
28   class CGridGroup;
29   class CGridAttributes;
30   class CDomainGroup;
31   class CAxisGroup;
32   class CScalarGroup;
33   class CGrid;
34   class CDistributionClient;
35   class CDistributionServer;
36   class CServerDistributionDescription;
37   class CClientServerMapping;
38   class CGridTransformation;
39
40   ///--------------------------------------------------------------
41
42   // Declare/Define CGridAttribute
43   BEGIN_DECLARE_ATTRIBUTE_MAP(CGrid)
44#  include "grid_attribute.conf"
45   END_DECLARE_ATTRIBUTE_MAP(CGrid)
46
47   ///--------------------------------------------------------------
48
49   class CGrid
50      : public CObjectTemplate<CGrid>
51      , public CGridAttributes
52   {
53         /// typedef ///
54         typedef CObjectTemplate<CGrid>   SuperClass;
55         typedef CGridAttributes SuperClassAttribute;
56
57      private:
58       
59        // define a structure to store elements (CDomain, CAxis, CScalar) using a void* and a type to cast the pointer
60         enum EElementType { TYPE_SCALAR, TYPE_AXIS, TYPE_DOMAIN } ;
61         struct SElement {void* ptr ; EElementType type ; CScalar* scalar ;  CAxis* axis ; CDomain* domain ; } ;
62         vector<SElement> elements_ ;
63         bool elementsComputed_ = false ; 
64         /** retrieve the vector of elements as a structure containing a void* and the type of pointer */
65         vector<SElement>& getElements(void) { if (!elementsComputed_) computeElements() ; return elements_ ; } 
66         void computeElements(void) ;
67         /** List order of axis and domain in a grid, if there is a domain, it will take value 2, axis 1, scalar 0 */
68         std::vector<int> order_;
69
70      public:
71
72         typedef CGridAttributes RelAttributes;
73         typedef CGridGroup      RelGroup;
74
75         enum EEventId
76         {
77           EVENT_ID_ADD_DOMAIN, EVENT_ID_ADD_AXIS, EVENT_ID_ADD_SCALAR,
78           EVENT_ID_SEND_MASK,
79
80         };
81
82         /// Constructeurs ///
83         CGrid(void);
84         explicit CGrid(const StdString& id);
85         CGrid(const CGrid& grid);       // Not implemented yet.
86         CGrid(const CGrid* const grid); // Not implemented yet.
87
88         /// Traitements ///
89//         void solveReference(void);
90
91         void checkEligibilityForCompressedOutput();
92         
93
94
95         void checkMaskIndex(bool doCalculateIndex);
96
97 //        virtual void toBinary  (StdOStream& os) const;
98//         virtual void fromBinary(StdIStream& is);
99
100         void addRelFileCompressed(const StdString& filename);
101
102         /// Tests ///
103         bool isCompressible(void) const;
104         bool isWrittenCompressed(const StdString& filename) const;
105
106      public:
107
108         /// Accesseurs ///
109         StdSize getDimension(void);
110
111         StdSize  getDataSize(void) ;
112
113         /**
114          * Get the local data grid size, ie the size of the compressed grid (inside the workflow)
115          * \return The size od the compressed grid
116          */
117         StdSize  getLocalDataSize(void) ;
118
119 
120         virtual void parse(xml::CXMLNode& node);
121
122         /// Destructeur ///
123         virtual ~CGrid(void);
124
125      public:
126
127         /// Accesseurs statiques ///
128         static StdString GetName(void);
129         static StdString GetDefName(void);
130
131         static ENodeType GetType(void);
132
133         /// Instanciateurs Statiques ///
134         static CGrid* createGrid(CDomain* domain);
135         static CGrid* createGrid(CDomain* domain, CAxis* axis);
136         static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
137                                  const CArray<int,1>& axisDomainOrder = CArray<int,1>());
138         static CGrid* createGrid(StdString id, const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
139                                  const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder = CArray<int,1>());
140         static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
141                                  const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder);
142         static StdString generateId(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
143                                     const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder = CArray<int,1>());
144         static StdString generateId(const CGrid* gridSrc, const CGrid* gridDest);
145         static CGrid* cloneGrid(const StdString& idNewGrid, CGrid* gridSrc);
146
147      public:           
148         void computeIndex(void);
149         void computeIndexScalarGrid();
150         void solveDomainAxisRef(bool areAttributesChecked);
151         void checkElementsAttributes(void) ;
152
153         void solveDomainRef(bool checkAtt);
154         void solveAxisRef(bool checkAtt);
155         void solveScalarRef(bool checkAtt);
156         void solveElementsRefInheritance(bool apply = true);
157        // void solveTransformations();
158         void solveDomainAxisBaseRef();
159
160         CDomain* addDomain(const std::string& id=StdString());
161         CAxis* addAxis(const std::string& id=StdString());
162         CScalar* addScalar(const std::string& id=StdString());
163
164      public:
165         void sendGridToFileServer(CContextClient* client) ;
166      private:
167         std::set<CContextClient*> sendGridToFileServer_done_ ;
168     
169      public:
170         void sendGridToCouplerOut(CContextClient* client, const string& fieldId) ;
171      private:
172         std::set<CContextClient*> sendGridToCouplerOut_done_ ;
173
174      public:
175         void makeAliasForCoupling(const string& fieldId) ;
176
177      public:
178         void sendAddDomain(const std::string& id,CContextClient* contextClient);
179         void sendAddAxis(const std::string& id,CContextClient* contextClient);
180         void sendAddScalar(const std::string& id,CContextClient* contextClient);
181         void sendAllDomains(CContextClient* contextClient);
182         void sendAllAxis(CContextClient* contextClient);
183         void sendAllScalars(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         CGridTransformation* getTransformations();
216
217         void transformGrid(CGrid* transformGridSrc);
218         
219         void prepareTransformGrid(CGrid* transformGridSrc);
220         bool prepareTransformGrid_done_ = false ;
221
222         void makeTransformGrid(void); 
223         bool makeTransformGrid_done_ = false ;
224         
225         std::vector<std::string> getAuxInputTransformGrid(void) ; 
226
227         void completeGrid(CGrid* transformGridSrc = 0);
228         bool isTransformed();
229         void setTransformed();
230         bool isGenerated();
231         void setGenerated();
232         void addTransGridSource(CGrid* gridSrc);
233         std::map<CGrid*, std::pair<bool,StdString> >& getTransGridSource();
234         bool hasTransform();
235         size_t getGlobalWrittenSize(void) ;
236         
237         bool isCompleted(void) ;
238         void setCompleted(void) ;
239         void unsetCompleted(void) ;
240
241
242         bool hasMask(void) const;
243        /** get mask pointer stored in mask_1d, or mask_2d, or..., or mask_7d */
244         CArray<bool,1> mask_ ;
245         CArray<bool,1>& getMask(void) ;
246
247      private:
248        /** Client-like distribution calculated based on the knowledge of the entire grid */
249       CDistributionClient* clientDistribution_;
250     public: 
251       void computeClientDistribution(void) ;
252     private:
253       bool computeClientDistribution_done_ = false ;
254     public:
255       CDistributionClient* getClientDistribution(void); 
256
257     private:   
258        void setVirtualDomainGroup(CDomainGroup* newVDomainGroup);
259        void setVirtualAxisGroup(CAxisGroup* newVAxisGroup);
260        void setVirtualScalarGroup(CScalarGroup* newVScalarGroup);
261
262        void setDomainList(const std::vector<CDomain*> domains = std::vector<CDomain*>());
263        void setAxisList(const std::vector<CAxis*> axis = std::vector<CAxis*>());
264        void setScalarList(const std::vector<CScalar*> scalars = std::vector<CScalar*>());
265
266        CDomainGroup* getVirtualDomainGroup() const;
267        CAxisGroup* getVirtualAxisGroup() const;
268        CScalarGroup* getVirtualScalarGroup() const;
269
270        void checkAttributesAfterTransformation();
271        void setTransformationAlgorithms();
272        int computeGridGlobalDimension(std::vector<int>& globalDim,
273                                       const std::vector<CDomain*> domains,
274                                       const std::vector<CAxis*> axis,
275                                       const std::vector<CScalar*> scalars,
276                                       const CArray<int,1>& axisDomainOrder);
277        int getDistributedDimension();
278      public:
279
280        bool isDataDistributed(void) ; 
281      private:
282
283/** Clients that have to send a grid. There can be multiple clients in case of secondary server, otherwise only one client. */
284        std::list<CContextClient*> clients;
285        std::set<CContextClient*> clientsSet;
286
287      private:
288        bool isChecked;
289        bool isDomainAxisChecked;
290        bool isIndexSent;
291
292        CDomainGroup* vDomainGroup_;
293        CAxisGroup* vAxisGroup_;
294        CScalarGroup* vScalarGroup_;
295        std::vector<std::string> axisList_, domList_, scalarList_;
296        bool isAxisListSet, isDomListSet, isScalarListSet;
297
298/** Map storing local ranks of connected receivers. Key = size of receiver's intracomm.
299  * It is calculated in computeConnectedClients(). */
300        std::map<int, std::vector<int> > connectedServerRank_;
301
302/** Map storing the size of data to be send. Key = size of receiver's intracomm
303  * It is calculated in computeConnectedClients(). */
304        std::map<int, std::map<int,size_t> > connectedDataSize_;
305
306/** Ranks of connected receivers in case of reading. It is calculated in recvIndex(). */
307        std::vector<int> connectedServerRankRead_;
308
309/** Size of data to be send in case of reading. It is calculated in recvIndex(). */
310        std::map<int,size_t> connectedDataSizeRead_;
311     
312         //! True if and only if the data defined on the grid can be outputted in a compressed way
313        bool isCompressible_;
314        std::set<std::string> relFilesCompressed;
315
316        bool isTransformed_, isGenerated_;
317       
318        std::vector<int> axisPositionInGrid_;
319        void computeAxisPositionInGrid(void) ;
320        bool computeAxisPositionInGrid_done_ = false ;
321        std::vector<int>& getAxisPositionInGrid(void) { if (!computeAxisPositionInGrid_done_) computeAxisPositionInGrid() ; return axisPositionInGrid_ ;}
322
323        CGridTransformation* transformations_;
324        bool hasDomainAxisBaseRef_;       
325        std::map<CGrid*, std::pair<bool,StdString> > gridSrc_;
326        bool hasTransform_;
327
328     //////////////////////////////////////////////////////////////////////////////////////
329     //  this part is related to distribution, element definition, views and connectors  //
330     //////////////////////////////////////////////////////////////////////////////////////
331      private:
332       static void recvMask(CEventServer& event) ;
333       void receiveMask(CEventServer& event) ;
334
335      private: 
336        CGridLocalElements* gridLocalElements_= nullptr ;
337        void computeGridLocalElements(void) ;
338      public:
339        CGridLocalElements* getGridLocalElements(void) { if (gridLocalElements_==nullptr) computeGridLocalElements() ; return gridLocalElements_ ;}
340
341      private:
342        CGridLocalConnector* modelToWorkflowConnector_ ;
343      public:
344        void computeModelToWorkflowConnector(void) ;
345        CGridLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_;}
346
347      private:
348        CGridLocalConnector* workflowToModelConnector_ ;
349      public:
350        void computeWorkflowToModelConnector(void) ;
351        CGridLocalConnector* getWorkflowToModelConnector(void) { if (workflowToModelConnector_==nullptr) computeWorkflowToModelConnector() ; return workflowToModelConnector_;}
352
353      public: //?
354        void distributeGridToFileServer(CContextClient* client);
355     
356           
357      private:
358        CGridLocalConnector* workflowToFullConnector_ = nullptr;
359      public:
360        void computeWorkflowToFullConnector(void) ;
361        CGridLocalConnector* getWorkflowToFullConnector(void) { if (workflowToFullConnector_==nullptr) computeWorkflowToFullConnector() ; return workflowToFullConnector_;}
362
363      private:
364        CGridLocalConnector* fullToWorkflowConnector_ = nullptr;
365      public:
366        void computeFullToWorkflowConnector(void) ;
367        CGridLocalConnector* getFullToWorkflowConnector(void) { if (fullToWorkflowConnector_==nullptr) computeFullToWorkflowConnector() ; return fullToWorkflowConnector_;}
368
369   
370
371      private:
372         CGridGathererConnector* clientFromClientConnector_ = nullptr ;
373      public:
374         CGridGathererConnector* getClientFromClientConnector(void) { if (clientFromClientConnector_==nullptr) computeClientFromClientConnector() ; return clientFromClientConnector_;}
375         void computeClientFromClientConnector(void) ;
376
377      private:
378         map<CContextClient*, CGridScattererConnector*> clientToClientConnector_ ;
379      public:
380         CGridScattererConnector* getClientToClientConnector(CContextClient* client) { return clientToClientConnector_[client] ;} // make some test to see if connector exits for the given client
381 
382
383      private:
384         map<CContextClient*,CGridGathererConnector*> clientFromServerConnector_  ;
385      public:
386         CGridGathererConnector* getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client];}
387         void computeClientFromServerConnector(void) ;
388
389      private:
390         CGridScattererConnector* serverToClientConnector_=nullptr ;
391      public:
392         CGridScattererConnector* getServerToClientConnector(void) { if (serverToClientConnector_==nullptr) computeServerToClientConnector() ; return serverToClientConnector_;}
393         void computeServerToClientConnector(void) ;
394      private:
395         map<CContextClient*, CGridScattererConnector*> clientToServerConnector_ ;
396      public:
397         CGridScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;} // make some test to see if connector exits for the given client
398         
399      private:
400         CGridGathererConnector* serverFromClientConnector_ = nullptr ;
401      public:
402         CGridGathererConnector* getServerFromClientConnector(void) { if (serverFromClientConnector_==nullptr) computeServerFromClientConnector() ; return serverFromClientConnector_;}
403         void computeServerFromClientConnector(void) ;
404
405   }; // class CGrid
406
407   // Declare/Define CGridGroup and CGridDefinition
408   DECLARE_GROUP(CGrid);
409
410   ///--------------------------------------------------------------
411
412} // namespace xios
413
414#endif // __XIOS_CGrid__
Note: See TracBrowser for help on using the repository browser.