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

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

fix missing workflow dependcy when using grid_ref with field Id.
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;
[2011]41 
[219]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
[1930]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
[676]72      public:
[219]73
74         typedef CGridAttributes RelAttributes;
75         typedef CGridGroup      RelGroup;
76
[300]77         enum EEventId
78         {
[1973]79           EVENT_ID_ADD_DOMAIN, EVENT_ID_ADD_AXIS, EVENT_ID_ADD_SCALAR,
[1943]80           EVENT_ID_SEND_MASK,
81
[650]82         };
[509]83
[219]84         /// Constructeurs ///
85         CGrid(void);
[650]86         explicit CGrid(const StdString& id);
87         CGrid(const CGrid& grid);       // Not implemented yet.
88         CGrid(const CGrid* const grid); // Not implemented yet.
[219]89
90         /// Traitements ///
[509]91//         void solveReference(void);
[219]92
[676]93         void checkEligibilityForCompressedOutput();
[1930]94         
[676]95
[509]96
97         void checkMaskIndex(bool doCalculateIndex);
98
[650]99 //        virtual void toBinary  (StdOStream& os) const;
100//         virtual void fromBinary(StdIStream& is);
[219]101
[676]102         void addRelFileCompressed(const StdString& filename);
103
[219]104         /// Tests ///
[676]105         bool isCompressible(void) const;
106         bool isWrittenCompressed(const StdString& filename) const;
[219]107
[676]108      public:
[219]109
110         /// Accesseurs ///
[1158]111         StdSize getDimension(void);
[509]112
[1869]113         StdSize  getDataSize(void) ;
[219]114
[1875]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
[1973]121 
[650]122         virtual void parse(xml::CXMLNode& node);
[540]123
[219]124         /// Destructeur ///
125         virtual ~CGrid(void);
126
[676]127      public:
[219]128
129         /// Accesseurs statiques ///
130         static StdString GetName(void);
131         static StdString GetDefName(void);
[509]132
[219]133         static ENodeType GetType(void);
134
135         /// Instanciateurs Statiques ///
[347]136         static CGrid* createGrid(CDomain* domain);
137         static CGrid* createGrid(CDomain* domain, CAxis* axis);
[745]138         static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
[887]139                                  const CArray<int,1>& axisDomainOrder = CArray<int,1>());
[745]140         static CGrid* createGrid(StdString id, const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
[887]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);
[2311]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
[2315]146         static CField* getFieldFromId(const string& id) ; //<! return field id if used in grid reference
[745]147         static StdString generateId(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
[887]148                                     const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder = CArray<int,1>());
[823]149         static StdString generateId(const CGrid* gridSrc, const CGrid* gridDest);
150         static CGrid* cloneGrid(const StdString& idNewGrid, CGrid* gridSrc);
[219]151
[2206]152         CDomain* getAssociatedDomain(const string& domainId, bool noError=false) ;
153         CAxis*   getAssociatedAxis(const string& axisId, bool noError=false) ;
154         CScalar* getAssociatedScalar(const string& scalarId, bool noError=false) ;
[1144]155      public:           
[1869]156         void solveDomainAxisRef(bool areAttributesChecked);
157         void checkElementsAttributes(void) ;
[219]158
[509]159         void solveDomainRef(bool checkAtt);
160         void solveAxisRef(bool checkAtt);
[887]161         void solveScalarRef(bool checkAtt);
[1869]162         void solveElementsRefInheritance(bool apply = true);
[2206]163         bool activateFieldWorkflow(CGarbageCollector& gc) ;
[1869]164        // void solveTransformations();
[775]165         void solveDomainAxisBaseRef();
[509]166
[835]167         CDomain* addDomain(const std::string& id=StdString());
168         CAxis* addAxis(const std::string& id=StdString());
[887]169         CScalar* addScalar(const std::string& id=StdString());
[1870]170
171      public:
172         void sendGridToFileServer(CContextClient* client) ;
173      private:
174         std::set<CContextClient*> sendGridToFileServer_done_ ;
[1875]175     
[1870]176      public:
[1875]177         void sendGridToCouplerOut(CContextClient* client, const string& fieldId) ;
178      private:
179         std::set<CContextClient*> sendGridToCouplerOut_done_ ;
180
181      public:
182         void makeAliasForCoupling(const string& fieldId) ;
[2022]183         string getCouplingAlias(const string& fieldId) ;
[1875]184
185      public:
[1784]186         void sendAddDomain(const std::string& id,CContextClient* contextClient);
187         void sendAddAxis(const std::string& id,CContextClient* contextClient);
188         void sendAddScalar(const std::string& id,CContextClient* contextClient);
[1974]189       
[650]190         static void recvAddDomain(CEventServer& event);
191         void recvAddDomain(CBufferIn& buffer);
192         static void recvAddAxis(CEventServer& event);
193         void recvAddAxis(CBufferIn& buffer);
[887]194         static void recvAddScalar(CEventServer& event);
195         void recvAddScalar(CBufferIn& buffer);
[540]196
[650]197         static bool dispatchEvent(CEventServer& event);
[1875]198       
199       public:
[1294]200         void setContextClient(CContextClient* contextClient);
201
[1330]202         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
203         std::map<int, StdSize> getDataBufferSize(CContextClient* client, const std::string& id = "", bool bufferForWriting = false);
[540]204         std::vector<StdString> getDomainList();
205         std::vector<StdString> getAxisList();
[887]206         std::vector<StdString> getScalarList();
[540]207         std::vector<CDomain*> getDomains();
208         std::vector<CAxis*> getAxis();
[887]209         std::vector<CScalar*> getScalars();
[943]210         CDomain* getDomain(int domainIndex);
211         CAxis* getAxis(int axisIndex);
212         CScalar* getScalar(int scalarIndex);
[551]213         std::vector<int> getAxisOrder();
[567]214         std::vector<int> getGlobalDimension();
[1236]215         bool isScalarGrid() const;         
[540]216
[567]217         bool doGridHaveDataToWrite();
[1235]218         bool doGridHaveDataDistributed(CContextClient* client = 0);
[567]219
[1984]220         ///////////////////////////////////////////
221         ////////    TRANSFORMATIONS           /////
222         ///////////////////////////////////////////
223      public:
[1988]224         pair<shared_ptr<CFilter>, shared_ptr<CFilter> > buildTransformationGraph(CGarbageCollector& gc, bool isSource, CGrid* gridSrc, double detectMissingValues,
[2144]225                                                                                  double defaultValue, CGrid*& newGrid, bool graphEnabled=false, CField* field=0) ;
[1984]226      private:
[2270]227        shared_ptr<CGridAlgorithm> gridAlgorithm_ = nullptr ;
[1999]228      public:
[2270]229        void setGridAlgorithm(shared_ptr<CGridAlgorithm> gridAlgorithm) {gridAlgorithm_ = gridAlgorithm;}
230        shared_ptr<CGridAlgorithm> getGridAlgorithm(void) { return gridAlgorithm_ ;}
[1984]231       
232        ///////////////////////////////////////////
233      public:
234
235        size_t getGlobalWrittenSize(void) ;
[1875]236         
237         bool isCompleted(void) ;
238         void setCompleted(void) ;
239         void unsetCompleted(void) ;
[509]240
[1869]241
[1637]242         bool hasMask(void) const;
[1918]243        /** get mask pointer stored in mask_1d, or mask_2d, or..., or mask_7d */
244         CArray<bool,1> mask_ ;
245         CArray<bool,1>& getMask(void) ;
[509]246
[1973]247      private:
[1870]248        /** Client-like distribution calculated based on the knowledge of the entire grid */
249       CDistributionClient* clientDistribution_;
250     public: 
[1869]251       void computeClientDistribution(void) ;
[1870]252     private:
[1869]253       bool computeClientDistribution_done_ = false ;
[1870]254     public:
255       CDistributionClient* getClientDistribution(void); 
[1869]256
[1871]257     private:   
[540]258        void setVirtualDomainGroup(CDomainGroup* newVDomainGroup);
259        void setVirtualAxisGroup(CAxisGroup* newVAxisGroup);
[887]260        void setVirtualScalarGroup(CScalarGroup* newVScalarGroup);
[567]261
[887]262        void setDomainList(const std::vector<CDomain*> domains = std::vector<CDomain*>());
[540]263        void setAxisList(const std::vector<CAxis*> axis = std::vector<CAxis*>());
[887]264        void setScalarList(const std::vector<CScalar*> scalars = std::vector<CScalar*>());
[540]265
[887]266        CDomainGroup* getVirtualDomainGroup() const;
[540]267        CAxisGroup* getVirtualAxisGroup() const;
[887]268        CScalarGroup* getVirtualScalarGroup() const;
[619]269
[1158]270        int computeGridGlobalDimension(std::vector<int>& globalDim,
271                                       const std::vector<CDomain*> domains,
272                                       const std::vector<CAxis*> axis,
273                                       const std::vector<CScalar*> scalars,
274                                       const CArray<int,1>& axisDomainOrder);
275        int getDistributedDimension();
[1794]276      public:
277
[1870]278        bool isDataDistributed(void) ; 
[540]279      private:
[1236]280
[1294]281/** Clients that have to send a grid. There can be multiple clients in case of secondary server, otherwise only one client. */
[1353]282        std::list<CContextClient*> clients;
283        std::set<CContextClient*> clientsSet;
[1294]284
[1870]285      private:
[1294]286        bool isChecked;
287        bool isDomainAxisChecked;
288        bool isIndexSent;
289
[540]290        CDomainGroup* vDomainGroup_;
291        CAxisGroup* vAxisGroup_;
[887]292        CScalarGroup* vScalarGroup_;
293        std::vector<std::string> axisList_, domList_, scalarList_;
294        bool isAxisListSet, isDomListSet, isScalarListSet;
[567]295
[1330]296/** Map storing local ranks of connected receivers. Key = size of receiver's intracomm.
297  * It is calculated in computeConnectedClients(). */
[1263]298        std::map<int, std::vector<int> > connectedServerRank_;
[1243]299
[1330]300/** Map storing the size of data to be send. Key = size of receiver's intracomm
301  * It is calculated in computeConnectedClients(). */
[1263]302        std::map<int, std::map<int,size_t> > connectedDataSize_;
[1243]303
[1330]304/** Ranks of connected receivers in case of reading. It is calculated in recvIndex(). */
305        std::vector<int> connectedServerRankRead_;
306
307/** Size of data to be send in case of reading. It is calculated in recvIndex(). */
308        std::map<int,size_t> connectedDataSizeRead_;
[1870]309     
[676]310         //! True if and only if the data defined on the grid can be outputted in a compressed way
311        bool isCompressible_;
312        std::set<std::string> relFilesCompressed;
[619]313
[1870]314       
[620]315        std::vector<int> axisPositionInGrid_;
[1870]316        void computeAxisPositionInGrid(void) ;
317        bool computeAxisPositionInGrid_done_ = false ;
318        std::vector<int>& getAxisPositionInGrid(void) { if (!computeAxisPositionInGrid_done_) computeAxisPositionInGrid() ; return axisPositionInGrid_ ;}
319
[1158]320        bool hasDomainAxisBaseRef_;       
[823]321        std::map<CGrid*, std::pair<bool,StdString> > gridSrc_;
[1243]322
[1930]323     //////////////////////////////////////////////////////////////////////////////////////
324     //  this part is related to distribution, element definition, views and connectors  //
325     //////////////////////////////////////////////////////////////////////////////////////
[1984]326      public:
327       CGrid* duplicateSentGrid(void) ;
[1943]328      private:
329       static void recvMask(CEventServer& event) ;
330       void receiveMask(CEventServer& event) ;
[1243]331
[1918]332      private: 
[2267]333       shared_ptr<CGridLocalElements> gridLocalElements_= nullptr ;
[1918]334        void computeGridLocalElements(void) ;
335      public:
[2267]336        shared_ptr<CGridLocalElements> getGridLocalElements(void) { if (gridLocalElements_==nullptr) computeGridLocalElements() ; return gridLocalElements_ ;}
[1918]337
338      private:
[2267]339        shared_ptr<CGridLocalConnector> modelToWorkflowConnector_ = nullptr ;
[1918]340      public:
341        void computeModelToWorkflowConnector(void) ;
[2267]342        shared_ptr<CGridLocalConnector> getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_;}
[1918]343
[1930]344      private:
[2267]345        shared_ptr<CGridLocalConnector> workflowToModelConnector_ = nullptr;
[1930]346      public:
347        void computeWorkflowToModelConnector(void) ;
[2267]348        shared_ptr<CGridLocalConnector> getWorkflowToModelConnector(void) { if (workflowToModelConnector_==nullptr) computeWorkflowToModelConnector() ; return workflowToModelConnector_;}
[1930]349
350      public: //?
[2022]351        void distributeGridToServer(CContextClient* client, const string& fieldId="");
[1930]352     
[1934]353           
[1930]354      private:
[2267]355        shared_ptr<CGridLocalConnector> workflowToFullConnector_ = nullptr;
[1930]356      public:
357        void computeWorkflowToFullConnector(void) ;
[2267]358        shared_ptr<CGridLocalConnector> getWorkflowToFullConnector(void) { if (workflowToFullConnector_==nullptr) computeWorkflowToFullConnector() ; return workflowToFullConnector_;}
[1930]359
360      private:
[2267]361        shared_ptr<CGridLocalConnector> fullToWorkflowConnector_ = nullptr;
[1930]362      public:
363        void computeFullToWorkflowConnector(void) ;
[2267]364        shared_ptr<CGridLocalConnector> getFullToWorkflowConnector(void) { if (fullToWorkflowConnector_==nullptr) computeFullToWorkflowConnector() ; return fullToWorkflowConnector_;}
[1930]365
[1934]366   
367
[1930]368      private:
[2267]369         shared_ptr<CGridGathererConnector> clientFromClientConnector_ = nullptr ;
[1930]370      public:
[2267]371         shared_ptr<CGridGathererConnector> getClientFromClientConnector(void) { if (clientFromClientConnector_==nullptr) computeClientFromClientConnector() ; return clientFromClientConnector_;}
[1930]372         void computeClientFromClientConnector(void) ;
373
374      private:
[2267]375         map<CContextClient*, shared_ptr<CGridScattererConnector>> clientToClientConnector_ ;
[1930]376      public:
[2267]377         shared_ptr<CGridScattererConnector> getClientToClientConnector(CContextClient* client) { return clientToClientConnector_[client] ;} // make some test to see if connector exits for the given client
[1930]378 
379
380      private:
[2267]381         map<CContextClient*,shared_ptr<CGridGathererConnector>> clientFromServerConnector_  ;
[1930]382      public:
[2267]383         shared_ptr<CGridGathererConnector> getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client];}
[1930]384         void computeClientFromServerConnector(void) ;
385
[1934]386      private:
[2267]387         shared_ptr<CGridScattererConnector> serverToClientConnector_=nullptr ;
[1934]388      public:
[2267]389         shared_ptr<CGridScattererConnector> getServerToClientConnector(void) { if (serverToClientConnector_==nullptr) computeServerToClientConnector() ; return serverToClientConnector_;}
[1934]390         void computeServerToClientConnector(void) ;
391      private:
[2267]392         map<CContextClient*, shared_ptr<CGridScattererConnector>> clientToServerConnector_ ;
[1934]393      public:
[2267]394         shared_ptr<CGridScattererConnector> getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;} // make some test to see if connector exits for the given client
[1934]395         
396      private:
[2267]397         shared_ptr<CGridGathererConnector> serverFromClientConnector_ = nullptr ;
[1934]398      public:
[2267]399         shared_ptr<CGridGathererConnector> getServerFromClientConnector(void) { if (serverFromClientConnector_==nullptr) computeServerFromClientConnector() ; return serverFromClientConnector_;}
[1934]400         void computeServerFromClientConnector(void) ;
401
[219]402   }; // class CGrid
403
404   // Declare/Define CGridGroup and CGridDefinition
405   DECLARE_GROUP(CGrid);
406
407   ///--------------------------------------------------------------
408
[335]409} // namespace xios
[219]410
[591]411#endif // __XIOS_CGrid__
Note: See TracBrowser for help on using the repository browser.