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

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

Adapt transformation algorithm to new infrastructure (on going...)

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