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

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