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

Last change on this file since 2311 was 2311, checked in by ymipsl, 2 years ago

Add possibility to refer to a grid using the field which is attached to, using notation : "fieldId::"

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.0 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 
42   ///--------------------------------------------------------------
43
44   // Declare/Define CGridAttribute
45   BEGIN_DECLARE_ATTRIBUTE_MAP(CGrid)
46#  include "grid_attribute.conf"
47   END_DECLARE_ATTRIBUTE_MAP(CGrid)
48
49   ///--------------------------------------------------------------
50
51   class CGrid
52      : public CObjectTemplate<CGrid>
53      , public CGridAttributes
54   {
55         /// typedef ///
56         typedef CObjectTemplate<CGrid>   SuperClass;
57         typedef CGridAttributes SuperClassAttribute;
58
59      private:
60       
61        // define a structure to store elements (CDomain, CAxis, CScalar) using a void* and a type to cast the pointer
62         enum EElementType { TYPE_SCALAR, TYPE_AXIS, TYPE_DOMAIN } ;
63         struct SElement {void* ptr ; EElementType type ; CScalar* scalar ;  CAxis* axis ; CDomain* domain ; } ;
64         vector<SElement> elements_ ;
65         bool elementsComputed_ = false ; 
66         /** retrieve the vector of elements as a structure containing a void* and the type of pointer */
67         vector<SElement>& getElements(void) { if (!elementsComputed_) computeElements() ; return elements_ ; } 
68         void computeElements(void) ;
69         /** List order of axis and domain in a grid, if there is a domain, it will take value 2, axis 1, scalar 0 */
70         std::vector<int> order_;
71
72      public:
73
74         typedef CGridAttributes RelAttributes;
75         typedef CGridGroup      RelGroup;
76
77         enum EEventId
78         {
79           EVENT_ID_ADD_DOMAIN, EVENT_ID_ADD_AXIS, EVENT_ID_ADD_SCALAR,
80           EVENT_ID_SEND_MASK,
81
82         };
83
84         /// Constructeurs ///
85         CGrid(void);
86         explicit CGrid(const StdString& id);
87         CGrid(const CGrid& grid);       // Not implemented yet.
88         CGrid(const CGrid* const grid); // Not implemented yet.
89
90         /// Traitements ///
91//         void solveReference(void);
92
93         void checkEligibilityForCompressedOutput();
94         
95
96
97         void checkMaskIndex(bool doCalculateIndex);
98
99 //        virtual void toBinary  (StdOStream& os) const;
100//         virtual void fromBinary(StdIStream& is);
101
102         void addRelFileCompressed(const StdString& filename);
103
104         /// Tests ///
105         bool isCompressible(void) const;
106         bool isWrittenCompressed(const StdString& filename) const;
107
108      public:
109
110         /// Accesseurs ///
111         StdSize getDimension(void);
112
113         StdSize  getDataSize(void) ;
114
115         /**
116          * Get the local data grid size, ie the size of the compressed grid (inside the workflow)
117          * \return The size od the compressed grid
118          */
119         StdSize  getLocalDataSize(void) ;
120
121 
122         virtual void parse(xml::CXMLNode& node);
123
124         /// Destructeur ///
125         virtual ~CGrid(void);
126
127      public:
128
129         /// Accesseurs statiques ///
130         static StdString GetName(void);
131         static StdString GetDefName(void);
132
133         static ENodeType GetType(void);
134
135         /// Instanciateurs Statiques ///
136         static CGrid* createGrid(CDomain* domain);
137         static CGrid* createGrid(CDomain* domain, CAxis* axis);
138         static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
139                                  const CArray<int,1>& axisDomainOrder = CArray<int,1>());
140         static CGrid* createGrid(StdString id, const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
141                                  const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder = CArray<int,1>());
142         static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
143                                  const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder);
144         static CGrid* get(const string& id, bool noError=false) ; //<! return grid pointer using id
145         static bool has(const string& id) ; //<! return if grid exist using id
146         static StdString generateId(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
147                                     const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder = CArray<int,1>());
148         static StdString generateId(const CGrid* gridSrc, const CGrid* gridDest);
149         static CGrid* cloneGrid(const StdString& idNewGrid, CGrid* gridSrc);
150
151         CDomain* getAssociatedDomain(const string& domainId, bool noError=false) ;
152         CAxis*   getAssociatedAxis(const string& axisId, bool noError=false) ;
153         CScalar* getAssociatedScalar(const string& scalarId, bool noError=false) ;
154      public:           
155         void solveDomainAxisRef(bool areAttributesChecked);
156         void checkElementsAttributes(void) ;
157
158         void solveDomainRef(bool checkAtt);
159         void solveAxisRef(bool checkAtt);
160         void solveScalarRef(bool checkAtt);
161         void solveElementsRefInheritance(bool apply = true);
162         bool activateFieldWorkflow(CGarbageCollector& gc) ;
163        // void solveTransformations();
164         void solveDomainAxisBaseRef();
165
166         CDomain* addDomain(const std::string& id=StdString());
167         CAxis* addAxis(const std::string& id=StdString());
168         CScalar* addScalar(const std::string& id=StdString());
169
170      public:
171         void sendGridToFileServer(CContextClient* client) ;
172      private:
173         std::set<CContextClient*> sendGridToFileServer_done_ ;
174     
175      public:
176         void sendGridToCouplerOut(CContextClient* client, const string& fieldId) ;
177      private:
178         std::set<CContextClient*> sendGridToCouplerOut_done_ ;
179
180      public:
181         void makeAliasForCoupling(const string& fieldId) ;
182         string getCouplingAlias(const string& fieldId) ;
183
184      public:
185         void sendAddDomain(const std::string& id,CContextClient* contextClient);
186         void sendAddAxis(const std::string& id,CContextClient* contextClient);
187         void sendAddScalar(const std::string& id,CContextClient* contextClient);
188       
189         static void recvAddDomain(CEventServer& event);
190         void recvAddDomain(CBufferIn& buffer);
191         static void recvAddAxis(CEventServer& event);
192         void recvAddAxis(CBufferIn& buffer);
193         static void recvAddScalar(CEventServer& event);
194         void recvAddScalar(CBufferIn& buffer);
195
196         static bool dispatchEvent(CEventServer& event);
197       
198       public:
199         void setContextClient(CContextClient* contextClient);
200
201         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
202         std::map<int, StdSize> getDataBufferSize(CContextClient* client, const std::string& id = "", bool bufferForWriting = false);
203         std::vector<StdString> getDomainList();
204         std::vector<StdString> getAxisList();
205         std::vector<StdString> getScalarList();
206         std::vector<CDomain*> getDomains();
207         std::vector<CAxis*> getAxis();
208         std::vector<CScalar*> getScalars();
209         CDomain* getDomain(int domainIndex);
210         CAxis* getAxis(int axisIndex);
211         CScalar* getScalar(int scalarIndex);
212         std::vector<int> getAxisOrder();
213         std::vector<int> getGlobalDimension();
214         bool isScalarGrid() const;         
215
216         bool doGridHaveDataToWrite();
217         bool doGridHaveDataDistributed(CContextClient* client = 0);
218
219         ///////////////////////////////////////////
220         ////////    TRANSFORMATIONS           /////
221         ///////////////////////////////////////////
222      public:
223         pair<shared_ptr<CFilter>, shared_ptr<CFilter> > buildTransformationGraph(CGarbageCollector& gc, bool isSource, CGrid* gridSrc, double detectMissingValues,
224                                                                                  double defaultValue, CGrid*& newGrid, bool graphEnabled=false, CField* field=0) ;
225      private:
226        shared_ptr<CGridAlgorithm> gridAlgorithm_ = nullptr ;
227      public:
228        void setGridAlgorithm(shared_ptr<CGridAlgorithm> gridAlgorithm) {gridAlgorithm_ = gridAlgorithm;}
229        shared_ptr<CGridAlgorithm> getGridAlgorithm(void) { return gridAlgorithm_ ;}
230       
231        ///////////////////////////////////////////
232      public:
233
234        size_t getGlobalWrittenSize(void) ;
235         
236         bool isCompleted(void) ;
237         void setCompleted(void) ;
238         void unsetCompleted(void) ;
239
240
241         bool hasMask(void) const;
242        /** get mask pointer stored in mask_1d, or mask_2d, or..., or mask_7d */
243         CArray<bool,1> mask_ ;
244         CArray<bool,1>& getMask(void) ;
245
246      private:
247        /** Client-like distribution calculated based on the knowledge of the entire grid */
248       CDistributionClient* clientDistribution_;
249     public: 
250       void computeClientDistribution(void) ;
251     private:
252       bool computeClientDistribution_done_ = false ;
253     public:
254       CDistributionClient* getClientDistribution(void); 
255
256     private:   
257        void setVirtualDomainGroup(CDomainGroup* newVDomainGroup);
258        void setVirtualAxisGroup(CAxisGroup* newVAxisGroup);
259        void setVirtualScalarGroup(CScalarGroup* newVScalarGroup);
260
261        void setDomainList(const std::vector<CDomain*> domains = std::vector<CDomain*>());
262        void setAxisList(const std::vector<CAxis*> axis = std::vector<CAxis*>());
263        void setScalarList(const std::vector<CScalar*> scalars = std::vector<CScalar*>());
264
265        CDomainGroup* getVirtualDomainGroup() const;
266        CAxisGroup* getVirtualAxisGroup() const;
267        CScalarGroup* getVirtualScalarGroup() const;
268
269        int computeGridGlobalDimension(std::vector<int>& globalDim,
270                                       const std::vector<CDomain*> domains,
271                                       const std::vector<CAxis*> axis,
272                                       const std::vector<CScalar*> scalars,
273                                       const CArray<int,1>& axisDomainOrder);
274        int getDistributedDimension();
275      public:
276
277        bool isDataDistributed(void) ; 
278      private:
279
280/** Clients that have to send a grid. There can be multiple clients in case of secondary server, otherwise only one client. */
281        std::list<CContextClient*> clients;
282        std::set<CContextClient*> clientsSet;
283
284      private:
285        bool isChecked;
286        bool isDomainAxisChecked;
287        bool isIndexSent;
288
289        CDomainGroup* vDomainGroup_;
290        CAxisGroup* vAxisGroup_;
291        CScalarGroup* vScalarGroup_;
292        std::vector<std::string> axisList_, domList_, scalarList_;
293        bool isAxisListSet, isDomListSet, isScalarListSet;
294
295/** Map storing local ranks of connected receivers. Key = size of receiver's intracomm.
296  * It is calculated in computeConnectedClients(). */
297        std::map<int, std::vector<int> > connectedServerRank_;
298
299/** Map storing the size of data to be send. Key = size of receiver's intracomm
300  * It is calculated in computeConnectedClients(). */
301        std::map<int, std::map<int,size_t> > connectedDataSize_;
302
303/** Ranks of connected receivers in case of reading. It is calculated in recvIndex(). */
304        std::vector<int> connectedServerRankRead_;
305
306/** Size of data to be send in case of reading. It is calculated in recvIndex(). */
307        std::map<int,size_t> connectedDataSizeRead_;
308     
309         //! True if and only if the data defined on the grid can be outputted in a compressed way
310        bool isCompressible_;
311        std::set<std::string> relFilesCompressed;
312
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        bool hasDomainAxisBaseRef_;       
320        std::map<CGrid*, std::pair<bool,StdString> > gridSrc_;
321
322     //////////////////////////////////////////////////////////////////////////////////////
323     //  this part is related to distribution, element definition, views and connectors  //
324     //////////////////////////////////////////////////////////////////////////////////////
325      public:
326       CGrid* duplicateSentGrid(void) ;
327      private:
328       static void recvMask(CEventServer& event) ;
329       void receiveMask(CEventServer& event) ;
330
331      private: 
332       shared_ptr<CGridLocalElements> gridLocalElements_= nullptr ;
333        void computeGridLocalElements(void) ;
334      public:
335        shared_ptr<CGridLocalElements> getGridLocalElements(void) { if (gridLocalElements_==nullptr) computeGridLocalElements() ; return gridLocalElements_ ;}
336
337      private:
338        shared_ptr<CGridLocalConnector> modelToWorkflowConnector_ = nullptr ;
339      public:
340        void computeModelToWorkflowConnector(void) ;
341        shared_ptr<CGridLocalConnector> getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_;}
342
343      private:
344        shared_ptr<CGridLocalConnector> workflowToModelConnector_ = nullptr;
345      public:
346        void computeWorkflowToModelConnector(void) ;
347        shared_ptr<CGridLocalConnector> getWorkflowToModelConnector(void) { if (workflowToModelConnector_==nullptr) computeWorkflowToModelConnector() ; return workflowToModelConnector_;}
348
349      public: //?
350        void distributeGridToServer(CContextClient* client, const string& fieldId="");
351     
352           
353      private:
354        shared_ptr<CGridLocalConnector> workflowToFullConnector_ = nullptr;
355      public:
356        void computeWorkflowToFullConnector(void) ;
357        shared_ptr<CGridLocalConnector> getWorkflowToFullConnector(void) { if (workflowToFullConnector_==nullptr) computeWorkflowToFullConnector() ; return workflowToFullConnector_;}
358
359      private:
360        shared_ptr<CGridLocalConnector> fullToWorkflowConnector_ = nullptr;
361      public:
362        void computeFullToWorkflowConnector(void) ;
363        shared_ptr<CGridLocalConnector> getFullToWorkflowConnector(void) { if (fullToWorkflowConnector_==nullptr) computeFullToWorkflowConnector() ; return fullToWorkflowConnector_;}
364
365   
366
367      private:
368         shared_ptr<CGridGathererConnector> clientFromClientConnector_ = nullptr ;
369      public:
370         shared_ptr<CGridGathererConnector> getClientFromClientConnector(void) { if (clientFromClientConnector_==nullptr) computeClientFromClientConnector() ; return clientFromClientConnector_;}
371         void computeClientFromClientConnector(void) ;
372
373      private:
374         map<CContextClient*, shared_ptr<CGridScattererConnector>> clientToClientConnector_ ;
375      public:
376         shared_ptr<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*,shared_ptr<CGridGathererConnector>> clientFromServerConnector_  ;
381      public:
382         shared_ptr<CGridGathererConnector> getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client];}
383         void computeClientFromServerConnector(void) ;
384
385      private:
386         shared_ptr<CGridScattererConnector> serverToClientConnector_=nullptr ;
387      public:
388         shared_ptr<CGridScattererConnector> getServerToClientConnector(void) { if (serverToClientConnector_==nullptr) computeServerToClientConnector() ; return serverToClientConnector_;}
389         void computeServerToClientConnector(void) ;
390      private:
391         map<CContextClient*, shared_ptr<CGridScattererConnector>> clientToServerConnector_ ;
392      public:
393         shared_ptr<CGridScattererConnector> getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;} // make some test to see if connector exits for the given client
394         
395      private:
396         shared_ptr<CGridGathererConnector> serverFromClientConnector_ = nullptr ;
397      public:
398         shared_ptr<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.