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

Last change on this file since 1940 was 1935, checked in by ymipsl, 4 years ago

XIOS coupling.
Reorganize filters, update of the day.

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.8 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:
[952]107         int getNStep(void) const;
[266]108
[593]109         template <int N> void getData(CArray<double, N>& _data) const;
[219]110
[1542]111         std::shared_ptr<COutputPin> getInstantDataFilter();
[219]112
113         /// Mutateur ///
[347]114         void setRelFile(CFile* _file);
[266]115         void incrementNStep(void);
[952]116         void resetNStep(int nstep = 0);
[599]117         void resetNStepMax();
[219]118
[1330]119         std::map<int, StdSize> getGridAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
120         // Grid data buffer size for each connection of contextclient
121         std::map<int, StdSize> getGridDataBufferSize(CContextClient* client, bool bufferForWriting = false);
[509]122
[707]123       public:
[1875]124          void makeGridAliasForCoupling(void) ;
125       public:
[1158]126         bool isActive(bool atCurrentTimestep = false) const;
[651]127         bool hasOutputFile;
[219]128
[707]129         bool wasWritten() const;
130         void setWritten();
131
[676]132         bool getUseCompressedOutput() const;
133         void setUseCompressedOutput();
134
[219]135         /// Traitements ///
136         void solveGridReference(void);
[645]137         void solveServerOperation(void);
[509]138         void solveCheckMaskIndex(bool doSendingIndex);
[823]139         void solveAllReferenceEnabledField(bool doSending2Server);
[1784]140         void solveOnlyReferenceEnabledField(void);
[823]141         void generateNewTransformationGridDest();
142         void updateRef(CGrid* grid);
143         void buildGridTransformationGraph();
[509]144         void solveGridDomainAxisRef(bool checkAtt);
[619]145         void solveTransformedGrid();
[687]146         void solveGenerateGrid();
[775]147         void solveGridDomainAxisBaseRef();
[219]148
[1129]149         void solveAllEnabledFieldsAndTransform();
[1024]150         void checkGridOfEnabledFields();
151         void sendGridOfEnabledFields();
[1278]152         void sendGridComponentOfEnabledFields();
[1024]153
[1870]154         void sendFieldToFileServer(void) ;
[1875]155         void sendCloseDefinition(void) ;
156     
157      public:
158         void sendFieldToCouplerOut(void) ;
159      private:
160         bool sendFieldToCouplerOut_done_=false;
161      public:
162
[1872]163         void sendFieldToInputFileServer(void) ;
[1870]164
[1278]165         /// Vérifications ///
[1405]166         void checkTimeAttributes(CDuration* freqOp=NULL);
[1278]167
[640]168         void buildFilterGraph(CGarbageCollector& gc, bool enableOutput);
[1869]169
170         bool buildWorkflowGraph(CGarbageCollector& gc) ;
171         bool buildWorkflowGraphDone_ = false ;
172
[1215]173         size_t getGlobalWrittenSize(void) ;
174         
175         
[1542]176         std::shared_ptr<COutputPin> getFieldReference(CGarbageCollector& gc);
177         std::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc);
178         std::shared_ptr<COutputPin> getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
179         std::shared_ptr<COutputPin> getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
[640]180
[651]181//         virtual void fromBinary(StdIStream& is);
[219]182
183         /// Destructeur ///
184         virtual ~CField(void);
185
186         /// Accesseurs statiques ///
187         static StdString GetName(void);
188         static StdString GetDefName(void);
[509]189
[219]190         static ENodeType GetType(void);
[509]191
[651]192        template <int N> void setData(const CArray<double, N>& _data);
193        static bool dispatchEvent(CEventServer& event);
[1524]194        void sendAllAttributesToServer(CContextClient* client) ; 
[1875]195        void sendUpdateData(Time timestamp, const CArray<double,1>& data, CContextClient* client);
[1883]196        void sendUpdateDataServerToClient(bool isEOF, const CArray<double,1>& data, CContextClient* client) ;
197
[651]198        static void recvUpdateData(CEventServer& event);
[1930]199        void receiveUpdateData(CEventServer& event); 
[1875]200       
[1930]201        void recvUpdateData(std::map<int,CBufferIn*>& rankBuffers); // old interface to be removed
202        void recvUpdateDataFromClient(std::map<int,CBufferIn*>& rankBuffers); // old interface to be removed
203        void recvUpdateDataFromCoupler(std::map<int,CBufferIn*>& rankBuffers); // old interface to be removed
204       
[1882]205        void writeField(const CArray<double,1>& data);
[1934]206        bool sendReadDataRequest(const CDate& tsDataRequested);
[598]207        bool sendReadDataRequestIfNeeded(void);
208        static void recvReadDataRequest(CEventServer& event);
[1930]209        void recvReadDataRequest(void);
[1882]210        EReadField readField(CArray<double,1>& data);
[598]211        static void recvReadDataReady(CEventServer& event);
[1930]212        void receiveReadDataReady(CEventServer& event);
213        void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers); // old interface to remove
214        void recvDataFromCoupler(vector<int> ranks, vector<CBufferIn*> buffers) ; // old interface to remove
[1318]215        void checkForLateDataFromServer(void);
[1875]216        void checkForLateDataFromCoupler(void) ;
217
218        void checkIfMustAutoTrigger(void); // ym obsolete
219        void autoTriggerIfNeeded(void); //ym obsolete
220        void triggerLateField(void) ;
221
[1882]222//        void outputField(CArray<double,3>& fieldOut);
223//        void outputField(CArray<double,2>& fieldOut);
224        void outputField(const CArray<double,1>& dataIn, CArray<double,1>& dataOut);
225
226//        void inputField(CArray<double,3>& fieldOut);
227//        void inputField(CArray<double,2>& fieldOut);
228        void inputField(const CArray<double,1>& dataIn, CArray<double,1>& dataOut);
229        void outputCompressedField(const CArray<double,1>& dataIn, CArray<double, 1>& dataOut);
230        void scaleFactorAddOffset(CArray<double,1>& data, double scaleFactor, double addOffset);
231        void invertScaleFactorAddOffset(CArray<double,1>& data, double scaleFactor, double addOffset);
[651]232        void parse(xml::CXMLNode& node);
[509]233
[472]234        void setVirtualVariableGroup(CVariableGroup* newVVariableGroup);
235        CVariableGroup* getVirtualVariableGroup(void) const;
236        vector<CVariable*> getAllVariables(void) const;
[651]237        virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0);
[509]238
[651]239        CVariable* addVariable(const string& id = "");
[1144]240        CVariableGroup* addVariableGroup(const string& id = "");       
[1021]241        void sendAddVariable(const string& id, CContextClient* client);
[1144]242        void sendAddVariableGroup(const string& id, CContextClient* client);
[651]243        static void recvAddVariable(CEventServer& event);
244        void recvAddVariable(CBufferIn& buffer);
245        static void recvAddVariableGroup(CEventServer& event);
[1144]246        void recvAddVariableGroup(CBufferIn& buffer);       
[1021]247        void sendAddAllVariables(CContextClient* client);
[1024]248        void writeUpdateData(const CArray<double,1>& data);
[509]249
[887]250        const std::vector<StdString>& getRefDomainAxisIds();
[619]251
[1021]252        const string& getExpression(void);
253        bool hasExpression(void) const;
254
[1637]255        bool hasGridMask(void) const;
[1869]256        CGrid* getGrid(void) { return grid_; } 
[1637]257
[1869]258        void connectToFileServer(CGarbageCollector& gc) ;
[1875]259        void connectToCouplerOut(CGarbageCollector& gc) ;
260        void connectToCouplerIn(CGarbageCollector& gc) ;
[1870]261        void connectToModelInput(CGarbageCollector& gc) ;
[1871]262        void connectToFileWriter(CGarbageCollector& gc) ;
263        void connectToClientInput(CGarbageCollector& gc) ;
264        void connectToServerInput(CGarbageCollector& gc) ;
265        void connectToModelOutput(CGarbageCollector& gc);
[1883]266        void connectToFileReader(CGarbageCollector& gc) ;
267        void connectToServerToClient(CGarbageCollector& gc) ;
[1871]268
[1869]269        void computeGridIndexToFileServer(void) ;
[1870]270
271        void setContextClientDataBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
272                                        map<CContextClient*,map<int,size_t>>& maxEventSize, 
273                                        bool bufferForWriting) ;
274        void setContextClientAttributesBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
275                                                 map<CContextClient*,map<int,size_t>>& maxEventSize, 
276                                                 bool bufferForWriting) ;
[1869]277      private:
[1875]278          bool isGridCompleted_ = true ;
279      public:
280          bool isGridCompleted() { return isGridCompleted_ ;} 
281          void setGridCompleted(void) { isGridCompleted_= true; }
282          void unsetGridCompleted(void) { isGridCompleted_ = false ;}
283     
284      public:     
285          void sendGridCompleted(void) ;
286      private:   
287          static void recvGridCompleted(CEventServer& event);
288          void recvGridCompleted(CBufferIn& buffer);
289
290
291      private:
[1869]292        std::vector<CGrid*> getGridPath(void) ;
293
[707]294      public:
[219]295         /// Propriétés privées ///
[651]296         CVariableGroup* vVariableGroup;
[509]297
[1869]298         CGrid*  grid_=nullptr;
[1872]299//         CFile*  file;
[1869]300         
301         CFile* fileIn_ = nullptr ; //<! pointer to input related file
[1872]302         bool hasFileIn(void) const { return fileIn_==nullptr ? false : true ;} 
[1869]303         CFile* getFileIn(void) {return fileIn_;}
304         void setFileIn(CFile* fileIn) { fileIn_ = fileIn ;}
305         void unsetFileIn(void) { fileIn_ = nullptr ;}
[219]306
[1869]307         CFile* fileOut_ = nullptr ; //<! pointer to output related file
[1872]308         bool hasFileOut(void) const { return fileOut_==nullptr ? false : true ;} 
[1869]309         CFile* getFileOut(void) {return fileOut_;}
310         void setFileOut(CFile* fileOut) { fileOut_ = fileOut ;}
311         void unsetFileOut(void) { fileOut_ = nullptr ;}
312
313         CCouplerIn* couplerIn_ = nullptr ; //<!pointer to input related coupler
[1872]314         bool hasCouplerIn(void) const { return couplerIn_==nullptr ? false : true ;}
[1869]315         CCouplerIn* getCouplerIn(void) {return couplerIn_;}
316         void setCouplerIn(CCouplerIn* couplerIn) { couplerIn_ = couplerIn ;}
317         void unsetCouplerIn(void) { couplerIn_ = nullptr ;}
318
319         CCouplerOut* couplerOut_ = nullptr ; //<!pointer to output related coupler
[1872]320         bool hasCouplerOut(void) const { return couplerOut_==nullptr ? false : true ;}
[1869]321         CCouplerOut* getCouplerOut(void) {return couplerOut_;}
322         void setCouplerOut(CCouplerOut* couplerOut) { couplerOut_ = couplerOut ;}
323         void unsetCouplerOut(void) { couplerOut_ = nullptr ;}
324
325         bool modelIn_ = false ; //<! field can be received from model == true
326         bool getModelIn(void) { return modelIn_ ;}
327         void setModelIn(void) { modelIn_ = true ;}
328         void unsetModelIn(void) { modelIn_ = false ;}
329         
330         bool modelOut_ = false ; //<! field can be retrieve to model == true
331         bool getModelOut(void) { return modelOut_ ;}
332         void setModelOut(void) { modelOut_ = true ;}
333         void unsetModelOut(void) { modelOut_ = false ;}
334
[343]335         CDuration freq_operation_srv, freq_write_srv;
[219]336
[707]337         bool written; //<! Was the field written at least once
[952]338         int nstep, nstepMax;
[599]339         bool isEOF;
[651]340         CDate lastlast_Write_srv, last_Write_srv, last_operation_srv;
[1318]341         CDate lastDataRequestedFromServer, lastDataReceivedFromServer, dateEOF;
342         bool wasDataRequestedFromServer, wasDataAlreadyReceivedFromServer;
[1358]343         bool mustAutoTrigger;
[509]344
[1542]345         map<int,std::shared_ptr<func::CFunctor> > foperation_srv;
[509]346
[1144]347         // map<int, CArray<double,1> > data_srv;
[1882]348//         CArray<double,1> recvDataSrv; // not usefull anymore
[1024]349         
[1542]350         std::shared_ptr<func::CFunctor> recvFoperationSrv;
[651]351         string content;
[509]352
[887]353         std::vector<StdString> domAxisScalarIds_;
[676]354         bool useCompressedOutput;
[645]355
[1021]356         // Two variables to identify the time_counter meta data written in file, which has no time_counter
357         bool hasTimeInstant;
358         bool hasTimeCentered;
359
[1129]360
[540]361         DECLARE_REF_FUNC(Field,field)
[1869]362       
[640]363      private:
[1294]364         CContextClient* client;
[1875]365      public:
366         void setContextClient(CContextClient* newContextClient);
367         CContextClient* getContextClient(void) {return client;}
[1294]368
[1875]369      private:
370
[1129]371         bool areAllReferenceSolved;
372         bool isReferenceSolved;
373         bool isReferenceSolvedAndTransformed;
[1417]374         bool isGridChecked;
[1232]375         bool nstepMaxRead;
[1129]376
[1869]377       private: 
378         //! define if the field is part of the active workflow. It will be tagged to true when CField::buildWorkflowGraph is successfull
379         bool workflowEnabled_ = false ;
380       public: 
381         /*! workflowEnabled_ public accessor
382          * \return Value of workflowEnabled_ */
383         bool getWorkflowEnabled(void) { return  workflowEnabled_; }
384 
385
[1129]386      private:
[1869]387     
[645]388         //! The type of operation attached to the field
389         func::CFunctor::ETimeType operationTimeType;
390
[1869]391         //! The output pin of the input filter of the field
392         std::shared_ptr<CPassThroughFilter> inputFilter;
393
394         //! The self temporal data filter
395         std::shared_ptr<CTemporalFilter> selfTemporalDataFilter ;
396         
[640]397         //! The output pin of the filter providing the instant data for the field
[1542]398         std::shared_ptr<COutputPin> instantDataFilter;
[1869]399         
[643]400         //! The output pin of the filters providing the result of the field's temporal operation
[1542]401         std::map<CDuration, std::shared_ptr<COutputPin>, DurationFakeLessComparator> temporalDataFilters;
[1869]402         
[737]403         //! The output pin of the filter providing the instant data for self references
[1869]404         std::shared_ptr<COutputPin> selfReferenceFilter; // probably redondant with inputFilter
405
[640]406         //! The source filter for data provided by the client
[1935]407//         std::shared_ptr<CSourceFilter> clientSourceFilter; // obsolete to remove
[1930]408 
409         //! The source filter for data provided by the model to enter the client workflow
410         std::shared_ptr<CModelToClientSourceFilter> modelToClientSourceFilter_;
411
412         //! The source filter for data provided by the model to enter the client workflow
413         std::shared_ptr<CClientToModelStoreFilter> clientToModelStoreFilter_;
414
415         //! The source filter for data provided by the client that send data to server workflow
416         std::shared_ptr<CServerFromClientSourceFilter> serverFromClientSourceFilter_;
417
418         //! The source filter for data provided by an other to enter the current client workflow (coupling mode)
419         std::shared_ptr<CClientFromClientSourceFilter> clientFromClientSourceFilter_;
420
421         //! The source filter for data provided by server to enter the current client workflow (reading mode)
422         std::shared_ptr<CClientFromServerSourceFilter> clientFromServerSourceFilter_;
[1869]423         
[1930]424         //! The source filter for data read from file on server side
425         std::shared_ptr<CFileReaderSourceFilter> fileReaderSourceFilter_;
426
[640]427         //! The source filter for data provided by the server
[1935]428//         std::shared_ptr<CSourceFilter> serverSourceFilter; // obsolete to remove
[1869]429       
[1935]430         //! The terminal filter which send data to server for writing
431         std::shared_ptr<CClientToServerStoreFilter> clientToServerStoreFilter_;
[1869]432       
[1024]433         //! The terminal filter which writes data to file
[1935]434         std::shared_ptr<CFileWriterStoreFilter> fileWriterStoreFilter_;
[1883]435
[1930]436         //! The terminal filter which send data from server to client
[1934]437         std::shared_ptr<CServerToClientStoreFilter> serverToClientStoreFilter_;
[1883]438
439
[219]440   }; // class CField
441
442   ///--------------------------------------------------------------
443
444   // Declare/Define CFieldGroup and CFieldDefinition
445   DECLARE_GROUP(CField);
446
447   ///-----------------------------------------------------------------
448
449   template <>
450      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void);
451
452   ///-----------------------------------------------------------------
[335]453} // namespace xios
[219]454
455
[591]456#endif // __XIOS_CField__
Note: See TracBrowser for help on using the repository browser.