source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field.hpp @ 2022

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

Reimplement coupling in the new infrastructure.
Tested for 2-way coupling toy model.

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: 15.2 KB
RevLine 
[591]1#ifndef __XIOS_CField__
2#define __XIOS_CField__
[219]3
[591]4/// XIOS headers ///
5#include "xios_spl.hpp"
[219]6#include "group_factory.hpp"
7#include "functor.hpp"
8#include "functor_type.hpp"
9#include "duration.hpp"
10#include "date.hpp"
11#include "declare_group.hpp"
[231]12#include "calendar_util.hpp"
[369]13#include "array_new.hpp"
14#include "attribute_array.hpp"
[540]15#include "declare_ref_func.hpp"
[619]16#include "transformation_enum.hpp"
[646]17#include "variable.hpp"
[1021]18#include "context_client.hpp"
[1869]19#include "pass_through_filter.hpp"
20#include "temporal_filter.hpp"
[1930]21#include "model_to_client_source_filter.hpp"
22#include "client_from_client_source_filter.hpp"
23#include "client_from_server_source_filter.hpp"
24#include "client_to_model_store_filter.hpp"
[1934]25#include "server_to_client_store_filter.hpp"
[1935]26#include "server_from_client_source_filter.hpp"
27#include "file_writer_store_filter.hpp"
28#include "client_to_server_store_filter.hpp"
29#include "file_reader_source_filter.hpp"
[219]30
[300]31
[1869]32
[509]33
[1935]34
[1930]35namespace xios
36{
37
[219]38   /// ////////////////////// Déclarations ////////////////////// ///
39
40   class CFieldGroup;
41   class CFieldAttributes;
42   class CField;
43
44   class CFile;
[1869]45   class CCouplerIn ;
46   class CCouplerOut ;
[219]47   class CGrid;
[640]48   class CContext;
[619]49   class CGenericFilter;
50
[640]51   class CGarbageCollector;
52   class COutputPin;
53   class CSourceFilter;
[1883]54   class CServerToClientFilter;
[219]55   ///--------------------------------------------------------------
56
57   // Declare/Define CFieldAttribute
58   BEGIN_DECLARE_ATTRIBUTE_MAP(CField)
59#  include "field_attribute.conf"
60   END_DECLARE_ATTRIBUTE_MAP(CField)
61
[1853]62   class CContextClient ;
[1869]63
[219]64   ///--------------------------------------------------------------
65   class CField
66      : public CObjectTemplate<CField>
67      , public CFieldAttributes
68   {
69         /// friend ///
70         friend class CFile;
71
72         /// typedef ///
73         typedef CObjectTemplate<CField>   SuperClass;
74         typedef CFieldAttributes SuperClassAttribute;
75
[1930]76      public :   
[1232]77         enum EReadField
78         {
79           RF_NODATA, RF_EOF, RF_DATA
80         };
81         
[707]82      public:
[219]83
84         typedef CFieldAttributes RelAttributes;
85         typedef CFieldGroup      RelGroup;
86
[300]87         enum EEventId
88         {
[598]89           EVENT_ID_UPDATE_DATA, EVENT_ID_READ_DATA, EVENT_ID_READ_DATA_READY,
[1875]90           EVENT_ID_ADD_VARIABLE, EVENT_ID_ADD_VARIABLE_GROUP, EVENT_ID_GRID_COMPLETED
[651]91         };
[509]92
[219]93         /// Constructeurs ///
94         CField(void);
[651]95         explicit CField(const StdString& id);
96         CField(const CField& field);       // Not implemented yet.
97         CField(const CField* const field); // Not implemented yet.
[219]98
99         /// Accesseurs ///
100
[651]101         CGrid* getRelGrid(void) const;
102         CFile* getRelFile(void) const;
[219]103
[645]104         func::CFunctor::ETimeType getOperationTimeType() const;
105
[707]106      public:
[593]107         template <int N> void getData(CArray<double, N>& _data) const;
[219]108
[1330]109         std::map<int, StdSize> getGridAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
110         // Grid data buffer size for each connection of contextclient
111         std::map<int, StdSize> getGridDataBufferSize(CContextClient* client, bool bufferForWriting = false);
[509]112
[707]113       public:
[1875]114          void makeGridAliasForCoupling(void) ;
115       public:
[1158]116         bool isActive(bool atCurrentTimestep = false) const;
[651]117         bool hasOutputFile;
[219]118
[707]119         bool wasWritten() const;
120         void setWritten();
121
[676]122         bool getUseCompressedOutput() const;
123         void setUseCompressedOutput();
124
[219]125         /// Traitements ///
126         void solveGridReference(void);
[645]127         void solveServerOperation(void);
[509]128         void solveCheckMaskIndex(bool doSendingIndex);
[823]129         void updateRef(CGrid* grid);
[509]130         void solveGridDomainAxisRef(bool checkAtt);
[775]131         void solveGridDomainAxisBaseRef();
[219]132
[1024]133         void checkGridOfEnabledFields();
134         void sendGridOfEnabledFields();
[1278]135         void sendGridComponentOfEnabledFields();
[1024]136
[1870]137         void sendFieldToFileServer(void) ;
[1875]138         void sendCloseDefinition(void) ;
139     
140      public:
141         void sendFieldToCouplerOut(void) ;
142      private:
143         bool sendFieldToCouplerOut_done_=false;
144      public:
145
[1872]146         void sendFieldToInputFileServer(void) ;
[1870]147
[1278]148         /// Vérifications ///
[1405]149         void checkTimeAttributes(CDuration* freqOp=NULL);
[1278]150
[1869]151         bool buildWorkflowGraph(CGarbageCollector& gc) ;
152         bool buildWorkflowGraphDone_ = false ;
153
[1215]154         size_t getGlobalWrittenSize(void) ;
155         
156         
[1542]157         std::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc);
158         std::shared_ptr<COutputPin> getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
159         std::shared_ptr<COutputPin> getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
[640]160
[651]161//         virtual void fromBinary(StdIStream& is);
[219]162
163         /// Destructeur ///
164         virtual ~CField(void);
165
166         /// Accesseurs statiques ///
167         static StdString GetName(void);
168         static StdString GetDefName(void);
[509]169
[219]170         static ENodeType GetType(void);
[509]171
[651]172        template <int N> void setData(const CArray<double, N>& _data);
173        static bool dispatchEvent(CEventServer& event);
[1524]174        void sendAllAttributesToServer(CContextClient* client) ; 
[1962]175       
[651]176        static void recvUpdateData(CEventServer& event);
[1930]177        void receiveUpdateData(CEventServer& event); 
[1962]178
[1934]179        bool sendReadDataRequest(const CDate& tsDataRequested);
[598]180        bool sendReadDataRequestIfNeeded(void);
181        static void recvReadDataRequest(CEventServer& event);
[1930]182        void recvReadDataRequest(void);
[598]183        static void recvReadDataReady(CEventServer& event);
[1930]184        void receiveReadDataReady(CEventServer& event);
185        void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers); // old interface to remove
186        void recvDataFromCoupler(vector<int> ranks, vector<CBufferIn*> buffers) ; // old interface to remove
[1318]187        void checkForLateDataFromServer(void);
[1875]188        void checkForLateDataFromCoupler(void) ;
189
190        void checkIfMustAutoTrigger(void); // ym obsolete
191        void autoTriggerIfNeeded(void); //ym obsolete
192        void triggerLateField(void) ;
193
[651]194        void parse(xml::CXMLNode& node);
[509]195
[472]196        void setVirtualVariableGroup(CVariableGroup* newVVariableGroup);
197        CVariableGroup* getVirtualVariableGroup(void) const;
198        vector<CVariable*> getAllVariables(void) const;
[651]199        virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0);
[509]200
[651]201        CVariable* addVariable(const string& id = "");
[1144]202        CVariableGroup* addVariableGroup(const string& id = "");       
[1021]203        void sendAddVariable(const string& id, CContextClient* client);
[1144]204        void sendAddVariableGroup(const string& id, CContextClient* client);
[651]205        static void recvAddVariable(CEventServer& event);
206        void recvAddVariable(CBufferIn& buffer);
207        static void recvAddVariableGroup(CEventServer& event);
[1144]208        void recvAddVariableGroup(CBufferIn& buffer);       
[1021]209        void sendAddAllVariables(CContextClient* client);
[509]210
[887]211        const std::vector<StdString>& getRefDomainAxisIds();
[619]212
[1021]213        const string& getExpression(void);
214        bool hasExpression(void) const;
215
[1637]216        bool hasGridMask(void) const;
[1984]217       
[1869]218        void connectToFileServer(CGarbageCollector& gc) ;
[1875]219        void connectToCouplerOut(CGarbageCollector& gc) ;
220        void connectToCouplerIn(CGarbageCollector& gc) ;
[1870]221        void connectToModelInput(CGarbageCollector& gc) ;
[1871]222        void connectToFileWriter(CGarbageCollector& gc) ;
223        void connectToClientInput(CGarbageCollector& gc) ;
224        void connectToServerInput(CGarbageCollector& gc) ;
225        void connectToModelOutput(CGarbageCollector& gc);
[1883]226        void connectToFileReader(CGarbageCollector& gc) ;
227        void connectToServerToClient(CGarbageCollector& gc) ;
[1871]228
[1870]229        void setContextClientDataBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
230                                        map<CContextClient*,map<int,size_t>>& maxEventSize, 
231                                        bool bufferForWriting) ;
232        void setContextClientAttributesBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
233                                                 map<CContextClient*,map<int,size_t>>& maxEventSize, 
234                                                 bool bufferForWriting) ;
[1869]235      private:
[1875]236          bool isGridCompleted_ = true ;
237      public:
[2022]238          bool isGridCompleted()  ; 
[1875]239          void setGridCompleted(void) { isGridCompleted_= true; }
240          void unsetGridCompleted(void) { isGridCompleted_ = false ;}
241     
242      public:     
243          void sendGridCompleted(void) ;
244      private:   
245          static void recvGridCompleted(CEventServer& event);
246          void recvGridCompleted(CBufferIn& buffer);
247
248
249      private:
[1869]250        std::vector<CGrid*> getGridPath(void) ;
251
[707]252      public:
[219]253         /// Propriétés privées ///
[651]254         CVariableGroup* vVariableGroup;
[509]255
[1869]256         CGrid*  grid_=nullptr;
[1984]257         CGrid* getGrid(void) { return grid_; } 
258     
259      private:
260         CGrid* sentGrid_=nullptr ;
261      public:
262         CGrid* getSentGrid(void) { return sentGrid_; }   
263
264      public:
[1872]265//         CFile*  file;
[1869]266         
267         CFile* fileIn_ = nullptr ; //<! pointer to input related file
[1872]268         bool hasFileIn(void) const { return fileIn_==nullptr ? false : true ;} 
[1869]269         CFile* getFileIn(void) {return fileIn_;}
270         void setFileIn(CFile* fileIn) { fileIn_ = fileIn ;}
271         void unsetFileIn(void) { fileIn_ = nullptr ;}
[219]272
[1869]273         CFile* fileOut_ = nullptr ; //<! pointer to output related file
[1872]274         bool hasFileOut(void) const { return fileOut_==nullptr ? false : true ;} 
[1869]275         CFile* getFileOut(void) {return fileOut_;}
276         void setFileOut(CFile* fileOut) { fileOut_ = fileOut ;}
277         void unsetFileOut(void) { fileOut_ = nullptr ;}
278
279         CCouplerIn* couplerIn_ = nullptr ; //<!pointer to input related coupler
[1872]280         bool hasCouplerIn(void) const { return couplerIn_==nullptr ? false : true ;}
[1869]281         CCouplerIn* getCouplerIn(void) {return couplerIn_;}
282         void setCouplerIn(CCouplerIn* couplerIn) { couplerIn_ = couplerIn ;}
283         void unsetCouplerIn(void) { couplerIn_ = nullptr ;}
284
285         CCouplerOut* couplerOut_ = nullptr ; //<!pointer to output related coupler
[1872]286         bool hasCouplerOut(void) const { return couplerOut_==nullptr ? false : true ;}
[1869]287         CCouplerOut* getCouplerOut(void) {return couplerOut_;}
288         void setCouplerOut(CCouplerOut* couplerOut) { couplerOut_ = couplerOut ;}
289         void unsetCouplerOut(void) { couplerOut_ = nullptr ;}
290
291         bool modelIn_ = false ; //<! field can be received from model == true
292         bool getModelIn(void) { return modelIn_ ;}
293         void setModelIn(void) { modelIn_ = true ;}
294         void unsetModelIn(void) { modelIn_ = false ;}
295         
296         bool modelOut_ = false ; //<! field can be retrieve to model == true
297         bool getModelOut(void) { return modelOut_ ;}
298         void setModelOut(void) { modelOut_ = true ;}
299         void unsetModelOut(void) { modelOut_ = false ;}
300
[1962]301         
[707]302         bool written; //<! Was the field written at least once
[1358]303         bool mustAutoTrigger;
[509]304
[651]305         string content;
[509]306
[887]307         std::vector<StdString> domAxisScalarIds_;
[676]308         bool useCompressedOutput;
[645]309
[1021]310         // Two variables to identify the time_counter meta data written in file, which has no time_counter
311         bool hasTimeInstant;
312         bool hasTimeCentered;
313
[1129]314
[540]315         DECLARE_REF_FUNC(Field,field)
[1869]316       
[640]317      private:
[1294]318         CContextClient* client;
[1875]319      public:
320         void setContextClient(CContextClient* newContextClient);
321         CContextClient* getContextClient(void) {return client;}
[1294]322
[1875]323      private:
324
[1129]325         bool areAllReferenceSolved;
326         bool isReferenceSolved;
327         bool isReferenceSolvedAndTransformed;
[1417]328         bool isGridChecked;
[1129]329
[1869]330       private: 
331         //! define if the field is part of the active workflow. It will be tagged to true when CField::buildWorkflowGraph is successfull
332         bool workflowEnabled_ = false ;
333       public: 
334         /*! workflowEnabled_ public accessor
335          * \return Value of workflowEnabled_ */
336         bool getWorkflowEnabled(void) { return  workflowEnabled_; }
337 
338
[1129]339      private:
[1869]340     
[645]341         //! The type of operation attached to the field
342         func::CFunctor::ETimeType operationTimeType;
343
[1869]344         //! The output pin of the input filter of the field
345         std::shared_ptr<CPassThroughFilter> inputFilter;
346
347         //! The self temporal data filter
348         std::shared_ptr<CTemporalFilter> selfTemporalDataFilter ;
349         
[640]350         //! The output pin of the filter providing the instant data for the field
[1542]351         std::shared_ptr<COutputPin> instantDataFilter;
[2011]352      public:
353          std::shared_ptr<COutputPin> getInstantDataFilter(void) { return instantDataFilter;}
354
355      private:
356
[643]357         //! The output pin of the filters providing the result of the field's temporal operation
[1542]358         std::map<CDuration, std::shared_ptr<COutputPin>, DurationFakeLessComparator> temporalDataFilters;
[1869]359         
[737]360         //! The output pin of the filter providing the instant data for self references
[1869]361         std::shared_ptr<COutputPin> selfReferenceFilter; // probably redondant with inputFilter
362
[640]363         //! The source filter for data provided by the client
[1935]364//         std::shared_ptr<CSourceFilter> clientSourceFilter; // obsolete to remove
[1930]365 
366         //! The source filter for data provided by the model to enter the client workflow
367         std::shared_ptr<CModelToClientSourceFilter> modelToClientSourceFilter_;
368
369         //! The source filter for data provided by the model to enter the client workflow
370         std::shared_ptr<CClientToModelStoreFilter> clientToModelStoreFilter_;
371
372         //! The source filter for data provided by the client that send data to server workflow
373         std::shared_ptr<CServerFromClientSourceFilter> serverFromClientSourceFilter_;
374
375         //! The source filter for data provided by an other to enter the current client workflow (coupling mode)
376         std::shared_ptr<CClientFromClientSourceFilter> clientFromClientSourceFilter_;
377
378         //! The source filter for data provided by server to enter the current client workflow (reading mode)
379         std::shared_ptr<CClientFromServerSourceFilter> clientFromServerSourceFilter_;
[1869]380         
[1930]381         //! The source filter for data read from file on server side
382         std::shared_ptr<CFileReaderSourceFilter> fileReaderSourceFilter_;
383
[640]384         //! The source filter for data provided by the server
[1935]385//         std::shared_ptr<CSourceFilter> serverSourceFilter; // obsolete to remove
[1869]386       
[1935]387         //! The terminal filter which send data to server for writing
388         std::shared_ptr<CClientToServerStoreFilter> clientToServerStoreFilter_;
[1869]389       
[1024]390         //! The terminal filter which writes data to file
[1935]391         std::shared_ptr<CFileWriterStoreFilter> fileWriterStoreFilter_;
[1883]392
[1930]393         //! The terminal filter which send data from server to client
[1934]394         std::shared_ptr<CServerToClientStoreFilter> serverToClientStoreFilter_;
[1883]395
396
[219]397   }; // class CField
398
399   ///--------------------------------------------------------------
400
401   // Declare/Define CFieldGroup and CFieldDefinition
402   DECLARE_GROUP(CField);
403
404   ///-----------------------------------------------------------------
405
406   template <>
407      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void);
408
409   ///-----------------------------------------------------------------
[335]410} // namespace xios
[219]411
412
[591]413#endif // __XIOS_CField__
Note: See TracBrowser for help on using the repository browser.