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

Last change on this file since 1975 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
RevLine 
[591]1#ifndef __XIOS_CGrid__
2#define __XIOS_CGrid__
[219]3
[591]4/// XIOS headers ///
5#include "xios_spl.hpp"
[219]6#include "group_factory.hpp"
7
8#include "declare_group.hpp"
9#include "domain.hpp"
10#include "axis.hpp"
[887]11#include "scalar.hpp"
[369]12#include "array_new.hpp"
13#include "attribute_array.hpp"
[552]14#include "distribution_server.hpp"
[553]15#include "client_server_mapping.hpp"
[567]16#include "utils.hpp"
[619]17#include "transformation_enum.hpp"
[1918]18#include "grid_local_connector.hpp"
19#include "grid_elements.hpp"
[1930]20#include "grid_scatterer_connector.hpp"
21#include "grid_gatherer_connector.hpp"
[219]22
[1930]23
[335]24namespace xios {
[509]25
[1564]26   /// ////////////////////// Declarations ////////////////////// ///
[219]27
28   class CGridGroup;
29   class CGridAttributes;
[540]30   class CDomainGroup;
31   class CAxisGroup;
[887]32   class CScalarGroup;
[219]33   class CGrid;
[551]34   class CDistributionClient;
[552]35   class CDistributionServer;
[553]36   class CServerDistributionDescription;
37   class CClientServerMapping;
[620]38   class CGridTransformation;
[219]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
[1930]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
[676]70      public:
[219]71
72         typedef CGridAttributes RelAttributes;
73         typedef CGridGroup      RelGroup;
74
[300]75         enum EEventId
76         {
[1973]77           EVENT_ID_ADD_DOMAIN, EVENT_ID_ADD_AXIS, EVENT_ID_ADD_SCALAR,
[1943]78           EVENT_ID_SEND_MASK,
79
[650]80         };
[509]81
[219]82         /// Constructeurs ///
83         CGrid(void);
[650]84         explicit CGrid(const StdString& id);
85         CGrid(const CGrid& grid);       // Not implemented yet.
86         CGrid(const CGrid* const grid); // Not implemented yet.
[219]87
88         /// Traitements ///
[509]89//         void solveReference(void);
[219]90
[676]91         void checkEligibilityForCompressedOutput();
[1930]92         
[676]93
[509]94
95         void checkMaskIndex(bool doCalculateIndex);
96
[650]97 //        virtual void toBinary  (StdOStream& os) const;
98//         virtual void fromBinary(StdIStream& is);
[219]99
[676]100         void addRelFileCompressed(const StdString& filename);
101
[219]102         /// Tests ///
[676]103         bool isCompressible(void) const;
104         bool isWrittenCompressed(const StdString& filename) const;
[219]105
[676]106      public:
[219]107
108         /// Accesseurs ///
[1158]109         StdSize getDimension(void);
[509]110
[1869]111         StdSize  getDataSize(void) ;
[219]112
[1875]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
[1973]119 
[650]120         virtual void parse(xml::CXMLNode& node);
[540]121
[219]122         /// Destructeur ///
123         virtual ~CGrid(void);
124
[676]125      public:
[219]126
127         /// Accesseurs statiques ///
128         static StdString GetName(void);
129         static StdString GetDefName(void);
[509]130
[219]131         static ENodeType GetType(void);
132
133         /// Instanciateurs Statiques ///
[347]134         static CGrid* createGrid(CDomain* domain);
135         static CGrid* createGrid(CDomain* domain, CAxis* axis);
[745]136         static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
[887]137                                  const CArray<int,1>& axisDomainOrder = CArray<int,1>());
[745]138         static CGrid* createGrid(StdString id, const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
[887]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);
[745]142         static StdString generateId(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
[887]143                                     const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder = CArray<int,1>());
[823]144         static StdString generateId(const CGrid* gridSrc, const CGrid* gridDest);
145         static CGrid* cloneGrid(const StdString& idNewGrid, CGrid* gridSrc);
[219]146
[1144]147      public:           
[219]148         void computeIndex(void);
[586]149         void computeIndexScalarGrid();
[1869]150         void solveDomainAxisRef(bool areAttributesChecked);
151         void checkElementsAttributes(void) ;
[219]152
[509]153         void solveDomainRef(bool checkAtt);
154         void solveAxisRef(bool checkAtt);
[887]155         void solveScalarRef(bool checkAtt);
[1869]156         void solveElementsRefInheritance(bool apply = true);
157        // void solveTransformations();
[775]158         void solveDomainAxisBaseRef();
[509]159
[835]160         CDomain* addDomain(const std::string& id=StdString());
161         CAxis* addAxis(const std::string& id=StdString());
[887]162         CScalar* addScalar(const std::string& id=StdString());
[1870]163
164      public:
165         void sendGridToFileServer(CContextClient* client) ;
166      private:
167         std::set<CContextClient*> sendGridToFileServer_done_ ;
[1875]168     
[1870]169      public:
[1875]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:
[1784]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);
[1974]181       
[650]182         static void recvAddDomain(CEventServer& event);
183         void recvAddDomain(CBufferIn& buffer);
184         static void recvAddAxis(CEventServer& event);
185         void recvAddAxis(CBufferIn& buffer);
[887]186         static void recvAddScalar(CEventServer& event);
187         void recvAddScalar(CBufferIn& buffer);
[540]188
[650]189         static bool dispatchEvent(CEventServer& event);
[1875]190       
191       public:
[1294]192         void setContextClient(CContextClient* contextClient);
193
[1330]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);
[540]196         std::vector<StdString> getDomainList();
197         std::vector<StdString> getAxisList();
[887]198         std::vector<StdString> getScalarList();
[540]199         std::vector<CDomain*> getDomains();
200         std::vector<CAxis*> getAxis();
[887]201         std::vector<CScalar*> getScalars();
[943]202         CDomain* getDomain(int domainIndex);
203         CAxis* getAxis(int axisIndex);
204         CScalar* getScalar(int scalarIndex);
[551]205         std::vector<int> getAxisOrder();
[567]206         std::vector<int> getGlobalDimension();
[1236]207         bool isScalarGrid() const;         
[540]208
[567]209         bool doGridHaveDataToWrite();
[1235]210         bool doGridHaveDataDistributed(CContextClient* client = 0);
[567]211
[620]212         CGridTransformation* getTransformations();
[567]213
[632]214         void transformGrid(CGrid* transformGridSrc);
[1869]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
[775]224         void completeGrid(CGrid* transformGridSrc = 0);
[619]225         bool isTransformed();
226         void setTransformed();
[890]227         bool isGenerated();
228         void setGenerated();
[823]229         void addTransGridSource(CGrid* gridSrc);
230         std::map<CGrid*, std::pair<bool,StdString> >& getTransGridSource();
[824]231         bool hasTransform();
[1215]232         size_t getGlobalWrittenSize(void) ;
[1875]233         
234         bool isCompleted(void) ;
235         void setCompleted(void) ;
236         void unsetCompleted(void) ;
[509]237
[1869]238
[1637]239         bool hasMask(void) const;
[1918]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) ;
[509]243
[1973]244      private:
[1870]245        /** Client-like distribution calculated based on the knowledge of the entire grid */
246       CDistributionClient* clientDistribution_;
247     public: 
[1869]248       void computeClientDistribution(void) ;
[1870]249     private:
[1869]250       bool computeClientDistribution_done_ = false ;
[1870]251     public:
252       CDistributionClient* getClientDistribution(void); 
[1869]253
[1871]254     private:   
[540]255        void setVirtualDomainGroup(CDomainGroup* newVDomainGroup);
256        void setVirtualAxisGroup(CAxisGroup* newVAxisGroup);
[887]257        void setVirtualScalarGroup(CScalarGroup* newVScalarGroup);
[567]258
[887]259        void setDomainList(const std::vector<CDomain*> domains = std::vector<CDomain*>());
[540]260        void setAxisList(const std::vector<CAxis*> axis = std::vector<CAxis*>());
[887]261        void setScalarList(const std::vector<CScalar*> scalars = std::vector<CScalar*>());
[540]262
[887]263        CDomainGroup* getVirtualDomainGroup() const;
[540]264        CAxisGroup* getVirtualAxisGroup() const;
[887]265        CScalarGroup* getVirtualScalarGroup() const;
[619]266
267        void setTransformationAlgorithms();
[1158]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();
[1794]274      public:
275
[1870]276        bool isDataDistributed(void) ; 
[540]277      private:
[1236]278
[1294]279/** Clients that have to send a grid. There can be multiple clients in case of secondary server, otherwise only one client. */
[1353]280        std::list<CContextClient*> clients;
281        std::set<CContextClient*> clientsSet;
[1294]282
[1870]283      private:
[1294]284        bool isChecked;
285        bool isDomainAxisChecked;
286        bool isIndexSent;
287
[540]288        CDomainGroup* vDomainGroup_;
289        CAxisGroup* vAxisGroup_;
[887]290        CScalarGroup* vScalarGroup_;
291        std::vector<std::string> axisList_, domList_, scalarList_;
292        bool isAxisListSet, isDomListSet, isScalarListSet;
[567]293
[1330]294/** Map storing local ranks of connected receivers. Key = size of receiver's intracomm.
295  * It is calculated in computeConnectedClients(). */
[1263]296        std::map<int, std::vector<int> > connectedServerRank_;
[1243]297
[1330]298/** Map storing the size of data to be send. Key = size of receiver's intracomm
299  * It is calculated in computeConnectedClients(). */
[1263]300        std::map<int, std::map<int,size_t> > connectedDataSize_;
[1243]301
[1330]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_;
[1870]307     
[676]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;
[619]311
[1129]312        bool isTransformed_, isGenerated_;
[1870]313       
[620]314        std::vector<int> axisPositionInGrid_;
[1870]315        void computeAxisPositionInGrid(void) ;
316        bool computeAxisPositionInGrid_done_ = false ;
317        std::vector<int>& getAxisPositionInGrid(void) { if (!computeAxisPositionInGrid_done_) computeAxisPositionInGrid() ; return axisPositionInGrid_ ;}
318
[620]319        CGridTransformation* transformations_;
[1158]320        bool hasDomainAxisBaseRef_;       
[823]321        std::map<CGrid*, std::pair<bool,StdString> > gridSrc_;
[824]322        bool hasTransform_;
[1243]323
[1930]324     //////////////////////////////////////////////////////////////////////////////////////
325     //  this part is related to distribution, element definition, views and connectors  //
326     //////////////////////////////////////////////////////////////////////////////////////
[1943]327      private:
328       static void recvMask(CEventServer& event) ;
329       void receiveMask(CEventServer& event) ;
[1243]330
[1918]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
[1930]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     
[1934]352           
[1930]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
[1934]365   
366
[1930]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:
[1934]380         map<CContextClient*,CGridGathererConnector*> clientFromServerConnector_  ;
[1930]381      public:
[1934]382         CGridGathererConnector* getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client];}
[1930]383         void computeClientFromServerConnector(void) ;
384
[1934]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
[219]401   }; // class CGrid
402
403   // Declare/Define CGridGroup and CGridDefinition
404   DECLARE_GROUP(CGrid);
405
406   ///--------------------------------------------------------------
407
[335]408} // namespace xios
[219]409
[591]410#endif // __XIOS_CGrid__
Note: See TracBrowser for help on using the repository browser.