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

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

New functionnality : domain, axis and scalar can now be retrieve with new syntax id :
ex. for domain :

id="domainId" : old syntax, working as before
id="fieldId::domainId" : get the domain related to "domainId" associated to the field "fieldId", work if only 1 domain related to domainId is associated to the field.
id="fieldId::domainId[n]" : get the nth domain related to "domainId" associated to the field "fieldId"
id="fieldId::" : get the domain associated the the field "fieldId, work if grid associated to th field is composed with exactly 1 domain (and possibly other components axis or scalars)
id="fieldId::[n] : get the nth domain composing the grid associated to the field

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