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

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

XIOS coupling branch
Some updates.

First coupling test is beginning to work...

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.6 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"
[219]21
[300]22
[1869]23
[335]24namespace xios {
[509]25
[219]26   /// ////////////////////// Déclarations ////////////////////// ///
27
28   class CFieldGroup;
29   class CFieldAttributes;
30   class CField;
31
32   class CFile;
[1869]33   class CCouplerIn ;
34   class CCouplerOut ;
[219]35   class CGrid;
[640]36   class CContext;
[619]37   class CGenericFilter;
38
[640]39   class CGarbageCollector;
40   class COutputPin;
41   class CSourceFilter;
42   class CStoreFilter;
43   class CFileWriterFilter;
[1024]44   class CFileServerWriterFilter;
[640]45
[219]46   ///--------------------------------------------------------------
47
48   // Declare/Define CFieldAttribute
49   BEGIN_DECLARE_ATTRIBUTE_MAP(CField)
50#  include "field_attribute.conf"
51   END_DECLARE_ATTRIBUTE_MAP(CField)
52
[1853]53   class CContextClient ;
[1869]54
[219]55   ///--------------------------------------------------------------
56   class CField
57      : public CObjectTemplate<CField>
58      , public CFieldAttributes
59   {
60         /// friend ///
61         friend class CFile;
62
63         /// typedef ///
64         typedef CObjectTemplate<CField>   SuperClass;
65         typedef CFieldAttributes SuperClassAttribute;
66
[1232]67         enum EReadField
68         {
69           RF_NODATA, RF_EOF, RF_DATA
70         };
71         
[707]72      public:
[219]73
74         typedef CFieldAttributes RelAttributes;
75         typedef CFieldGroup      RelGroup;
76
[300]77         enum EEventId
78         {
[598]79           EVENT_ID_UPDATE_DATA, EVENT_ID_READ_DATA, EVENT_ID_READ_DATA_READY,
[1875]80           EVENT_ID_ADD_VARIABLE, EVENT_ID_ADD_VARIABLE_GROUP, EVENT_ID_GRID_COMPLETED
[651]81         };
[509]82
[219]83         /// Constructeurs ///
84         CField(void);
[651]85         explicit CField(const StdString& id);
86         CField(const CField& field);       // Not implemented yet.
87         CField(const CField* const field); // Not implemented yet.
[219]88
89         /// Accesseurs ///
90
[651]91         CGrid* getRelGrid(void) const;
92         CFile* getRelFile(void) const;
[219]93
[645]94         func::CFunctor::ETimeType getOperationTimeType() const;
95
[707]96      public:
[952]97         int getNStep(void) const;
[266]98
[593]99         template <int N> void getData(CArray<double, N>& _data) const;
[219]100
[1542]101         std::shared_ptr<COutputPin> getInstantDataFilter();
[219]102
103         /// Mutateur ///
[347]104         void setRelFile(CFile* _file);
[266]105         void incrementNStep(void);
[952]106         void resetNStep(int nstep = 0);
[599]107         void resetNStepMax();
[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 solveAllReferenceEnabledField(bool doSending2Server);
[1784]130         void solveOnlyReferenceEnabledField(void);
[823]131         void generateNewTransformationGridDest();
132         void updateRef(CGrid* grid);
133         void buildGridTransformationGraph();
[509]134         void solveGridDomainAxisRef(bool checkAtt);
[619]135         void solveTransformedGrid();
[687]136         void solveGenerateGrid();
[775]137         void solveGridDomainAxisBaseRef();
[219]138
[1129]139         void solveAllEnabledFieldsAndTransform();
[1024]140         void checkGridOfEnabledFields();
141         void sendGridOfEnabledFields();
[1278]142         void sendGridComponentOfEnabledFields();
[1024]143
[1870]144         void sendFieldToFileServer(void) ;
[1875]145         void sendCloseDefinition(void) ;
146     
147      public:
148         void sendFieldToCouplerOut(void) ;
149      private:
150         bool sendFieldToCouplerOut_done_=false;
151      public:
152
[1872]153         void sendFieldToInputFileServer(void) ;
[1870]154
[1278]155         /// Vérifications ///
[1405]156         void checkTimeAttributes(CDuration* freqOp=NULL);
[1278]157
[640]158         void buildFilterGraph(CGarbageCollector& gc, bool enableOutput);
[1869]159
160         bool buildWorkflowGraph(CGarbageCollector& gc) ;
161         bool buildWorkflowGraphDone_ = false ;
162
[1215]163         size_t getGlobalWrittenSize(void) ;
164         
165         
[1542]166         std::shared_ptr<COutputPin> getFieldReference(CGarbageCollector& gc);
167         std::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc);
168         std::shared_ptr<COutputPin> getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
169         std::shared_ptr<COutputPin> getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
[640]170
[651]171//         virtual void fromBinary(StdIStream& is);
[219]172
173         /// Destructeur ///
174         virtual ~CField(void);
175
176         /// Accesseurs statiques ///
177         static StdString GetName(void);
178         static StdString GetDefName(void);
[509]179
[219]180         static ENodeType GetType(void);
[509]181
[651]182        template <int N> void setData(const CArray<double, N>& _data);
183        static bool dispatchEvent(CEventServer& event);
[1524]184        void sendAllAttributesToServer(CContextClient* client) ; 
[638]185        void sendUpdateData(const CArray<double,1>& data);
[1875]186        void sendUpdateData(Time timestamp, const CArray<double,1>& data, CContextClient* client);
[651]187        static void recvUpdateData(CEventServer& event);
[1024]188        void recvUpdateData(std::map<int,CBufferIn*>& rankBuffers);
[1875]189        void recvUpdateDataFromClient(std::map<int,CBufferIn*>& rankBuffers);
190        void recvUpdateDataFromCoupler(std::map<int,CBufferIn*>& rankBuffers);
191       
[651]192        void writeField(void);
[1853]193        bool sendReadDataRequest(const CDate& tsDataRequested, CContextClient* client);
[598]194        bool sendReadDataRequestIfNeeded(void);
195        static void recvReadDataRequest(CEventServer& event);
[1853]196        void recvReadDataRequest(CContextServer* server);
[1232]197        EReadField readField(void);
[598]198        static void recvReadDataReady(CEventServer& event);
199        void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers);
[1875]200        void recvDataFromCoupler(vector<int> ranks, vector<CBufferIn*> buffers) ;
[1318]201        void checkForLateDataFromServer(void);
[1875]202        void checkForLateDataFromCoupler(void) ;
203
204        void checkIfMustAutoTrigger(void); // ym obsolete
205        void autoTriggerIfNeeded(void); //ym obsolete
206        void triggerLateField(void) ;
207
[1158]208        void outputField(CArray<double,3>& fieldOut);
209        void outputField(CArray<double,2>& fieldOut);
[651]210        void outputField(CArray<double,1>& fieldOut);
[1158]211        void inputField(CArray<double,3>& fieldOut);
212        void inputField(CArray<double,2>& fieldOut);
[599]213        void inputField(CArray<double,1>& fieldOut);
[676]214        void outputCompressedField(CArray<double, 1>& fieldOut);
[651]215        void scaleFactorAddOffset(double scaleFactor, double addOffset);
[599]216        void invertScaleFactorAddOffset(double scaleFactor, double addOffset);
[651]217        void parse(xml::CXMLNode& node);
[509]218
[472]219        void setVirtualVariableGroup(CVariableGroup* newVVariableGroup);
220        CVariableGroup* getVirtualVariableGroup(void) const;
221        vector<CVariable*> getAllVariables(void) const;
[651]222        virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0);
[509]223
[651]224        CVariable* addVariable(const string& id = "");
[1144]225        CVariableGroup* addVariableGroup(const string& id = "");       
[1021]226        void sendAddVariable(const string& id, CContextClient* client);
[1144]227        void sendAddVariableGroup(const string& id, CContextClient* client);
[651]228        static void recvAddVariable(CEventServer& event);
229        void recvAddVariable(CBufferIn& buffer);
230        static void recvAddVariableGroup(CEventServer& event);
[1144]231        void recvAddVariableGroup(CBufferIn& buffer);       
[1021]232        void sendAddAllVariables(CContextClient* client);
[1024]233        void writeUpdateData(const CArray<double,1>& data);
[509]234
[887]235        const std::vector<StdString>& getRefDomainAxisIds();
[619]236
[1021]237        const string& getExpression(void);
238        bool hasExpression(void) const;
239
[1637]240        bool hasGridMask(void) const;
[1869]241        CGrid* getGrid(void) { return grid_; } 
[1637]242
[1869]243        void connectToFileServer(CGarbageCollector& gc) ;
[1875]244        void connectToCouplerOut(CGarbageCollector& gc) ;
245        void connectToCouplerIn(CGarbageCollector& gc) ;
[1870]246        void connectToModelInput(CGarbageCollector& gc) ;
[1871]247        void connectToFileWriter(CGarbageCollector& gc) ;
248        void connectToClientInput(CGarbageCollector& gc) ;
249        void connectToServerInput(CGarbageCollector& gc) ;
250        void connectToModelOutput(CGarbageCollector& gc);
251
[1869]252        void computeGridIndexToFileServer(void) ;
[1870]253
254        void setContextClientDataBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
255                                        map<CContextClient*,map<int,size_t>>& maxEventSize, 
256                                        bool bufferForWriting) ;
257        void setContextClientAttributesBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
258                                                 map<CContextClient*,map<int,size_t>>& maxEventSize, 
259                                                 bool bufferForWriting) ;
[1869]260      private:
[1875]261          bool isGridCompleted_ = true ;
262      public:
263          bool isGridCompleted() { return isGridCompleted_ ;} 
264          void setGridCompleted(void) { isGridCompleted_= true; }
265          void unsetGridCompleted(void) { isGridCompleted_ = false ;}
266     
267      public:     
268          void sendGridCompleted(void) ;
269      private:   
270          static void recvGridCompleted(CEventServer& event);
271          void recvGridCompleted(CBufferIn& buffer);
272
273
274      private:
[1869]275        std::vector<CGrid*> getGridPath(void) ;
276
[707]277      public:
[219]278         /// Propriétés privées ///
[651]279         CVariableGroup* vVariableGroup;
[509]280
[1869]281         CGrid*  grid_=nullptr;
[1872]282//         CFile*  file;
[1869]283         
284         CFile* fileIn_ = nullptr ; //<! pointer to input related file
[1872]285         bool hasFileIn(void) const { return fileIn_==nullptr ? false : true ;} 
[1869]286         CFile* getFileIn(void) {return fileIn_;}
287         void setFileIn(CFile* fileIn) { fileIn_ = fileIn ;}
288         void unsetFileIn(void) { fileIn_ = nullptr ;}
[219]289
[1869]290         CFile* fileOut_ = nullptr ; //<! pointer to output related file
[1872]291         bool hasFileOut(void) const { return fileOut_==nullptr ? false : true ;} 
[1869]292         CFile* getFileOut(void) {return fileOut_;}
293         void setFileOut(CFile* fileOut) { fileOut_ = fileOut ;}
294         void unsetFileOut(void) { fileOut_ = nullptr ;}
295
296         CCouplerIn* couplerIn_ = nullptr ; //<!pointer to input related coupler
[1872]297         bool hasCouplerIn(void) const { return couplerIn_==nullptr ? false : true ;}
[1869]298         CCouplerIn* getCouplerIn(void) {return couplerIn_;}
299         void setCouplerIn(CCouplerIn* couplerIn) { couplerIn_ = couplerIn ;}
300         void unsetCouplerIn(void) { couplerIn_ = nullptr ;}
301
302         CCouplerOut* couplerOut_ = nullptr ; //<!pointer to output related coupler
[1872]303         bool hasCouplerOut(void) const { return couplerOut_==nullptr ? false : true ;}
[1869]304         CCouplerOut* getCouplerOut(void) {return couplerOut_;}
305         void setCouplerOut(CCouplerOut* couplerOut) { couplerOut_ = couplerOut ;}
306         void unsetCouplerOut(void) { couplerOut_ = nullptr ;}
307
308         bool modelIn_ = false ; //<! field can be received from model == true
309         bool getModelIn(void) { return modelIn_ ;}
310         void setModelIn(void) { modelIn_ = true ;}
311         void unsetModelIn(void) { modelIn_ = false ;}
312         
313         bool modelOut_ = false ; //<! field can be retrieve to model == true
314         bool getModelOut(void) { return modelOut_ ;}
315         void setModelOut(void) { modelOut_ = true ;}
316         void unsetModelOut(void) { modelOut_ = false ;}
317
[343]318         CDuration freq_operation_srv, freq_write_srv;
[219]319
[707]320         bool written; //<! Was the field written at least once
[952]321         int nstep, nstepMax;
[599]322         bool isEOF;
[651]323         CDate lastlast_Write_srv, last_Write_srv, last_operation_srv;
[1318]324         CDate lastDataRequestedFromServer, lastDataReceivedFromServer, dateEOF;
325         bool wasDataRequestedFromServer, wasDataAlreadyReceivedFromServer;
[1358]326         bool mustAutoTrigger;
[509]327
[1542]328         map<int,std::shared_ptr<func::CFunctor> > foperation_srv;
[509]329
[1144]330         // map<int, CArray<double,1> > data_srv;
[1024]331         CArray<double,1> recvDataSrv;
332         
[1542]333         std::shared_ptr<func::CFunctor> recvFoperationSrv;
[651]334         string content;
[509]335
[887]336         std::vector<StdString> domAxisScalarIds_;
[676]337         bool useCompressedOutput;
[645]338
[1021]339         // Two variables to identify the time_counter meta data written in file, which has no time_counter
340         bool hasTimeInstant;
341         bool hasTimeCentered;
342
[1129]343
[540]344         DECLARE_REF_FUNC(Field,field)
[1869]345       
[640]346      private:
[1294]347         CContextClient* client;
[1875]348      public:
349         void setContextClient(CContextClient* newContextClient);
350         CContextClient* getContextClient(void) {return client;}
[1294]351
[1875]352      private:
353
[1129]354         bool areAllReferenceSolved;
355         bool isReferenceSolved;
356         bool isReferenceSolvedAndTransformed;
[1417]357         bool isGridChecked;
[1232]358         bool nstepMaxRead;
[1129]359
[1869]360       private: 
361         //! define if the field is part of the active workflow. It will be tagged to true when CField::buildWorkflowGraph is successfull
362         bool workflowEnabled_ = false ;
363       public: 
364         /*! workflowEnabled_ public accessor
365          * \return Value of workflowEnabled_ */
366         bool getWorkflowEnabled(void) { return  workflowEnabled_; }
367 
368
[1129]369      private:
[1869]370     
[645]371         //! The type of operation attached to the field
372         func::CFunctor::ETimeType operationTimeType;
373
[1869]374         //! The output pin of the input filter of the field
375         std::shared_ptr<CPassThroughFilter> inputFilter;
376
377         //! The self temporal data filter
378         std::shared_ptr<CTemporalFilter> selfTemporalDataFilter ;
379         
[640]380         //! The output pin of the filter providing the instant data for the field
[1542]381         std::shared_ptr<COutputPin> instantDataFilter;
[1869]382         
[643]383         //! The output pin of the filters providing the result of the field's temporal operation
[1542]384         std::map<CDuration, std::shared_ptr<COutputPin>, DurationFakeLessComparator> temporalDataFilters;
[1869]385         
[737]386         //! The output pin of the filter providing the instant data for self references
[1869]387         std::shared_ptr<COutputPin> selfReferenceFilter; // probably redondant with inputFilter
388
[640]389         //! The source filter for data provided by the client
[1542]390         std::shared_ptr<CSourceFilter> clientSourceFilter;
[1869]391         
[640]392         //! The source filter for data provided by the server
[1542]393         std::shared_ptr<CSourceFilter> serverSourceFilter;
[1869]394         
[640]395         //! The terminal filter which stores the instant data
[1542]396         std::shared_ptr<CStoreFilter> storeFilter;
[1869]397       
[1158]398         //! The terminal filter which writes the data to file
[1542]399         std::shared_ptr<CFileWriterFilter> fileWriterFilter;
[1869]400       
[1024]401         //! The terminal filter which writes data to file
[1542]402         std::shared_ptr<CFileServerWriterFilter> fileServerWriterFilter;
[219]403   }; // class CField
404
405   ///--------------------------------------------------------------
406
407   // Declare/Define CFieldGroup and CFieldDefinition
408   DECLARE_GROUP(CField);
409
410   ///-----------------------------------------------------------------
411
412   template <>
413      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void);
414
415   ///-----------------------------------------------------------------
[335]416} // namespace xios
[219]417
418
[591]419#endif // __XIOS_CField__
Note: See TracBrowser for help on using the repository browser.