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
Line 
1#ifndef __XIOS_CField__
2#define __XIOS_CField__
3
4/// XIOS headers ///
5#include "xios_spl.hpp"
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"
12#include "calendar_util.hpp"
13#include "array_new.hpp"
14#include "attribute_array.hpp"
15#include "declare_ref_func.hpp"
16#include "transformation_enum.hpp"
17#include "variable.hpp"
18#include "context_client.hpp"
19#include "pass_through_filter.hpp"
20#include "temporal_filter.hpp"
21
22
23
24namespace xios {
25
26   /// ////////////////////// Déclarations ////////////////////// ///
27
28   class CFieldGroup;
29   class CFieldAttributes;
30   class CField;
31
32   class CFile;
33   class CCouplerIn ;
34   class CCouplerOut ;
35   class CGrid;
36   class CContext;
37   class CGenericFilter;
38
39   class CGarbageCollector;
40   class COutputPin;
41   class CSourceFilter;
42   class CStoreFilter;
43   class CFileWriterFilter;
44   class CFileServerWriterFilter;
45
46   ///--------------------------------------------------------------
47
48   // Declare/Define CFieldAttribute
49   BEGIN_DECLARE_ATTRIBUTE_MAP(CField)
50#  include "field_attribute.conf"
51   END_DECLARE_ATTRIBUTE_MAP(CField)
52
53   class CContextClient ;
54
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
67         enum EReadField
68         {
69           RF_NODATA, RF_EOF, RF_DATA
70         };
71         
72      public:
73
74         typedef CFieldAttributes RelAttributes;
75         typedef CFieldGroup      RelGroup;
76
77         enum EEventId
78         {
79           EVENT_ID_UPDATE_DATA, EVENT_ID_READ_DATA, EVENT_ID_READ_DATA_READY,
80           EVENT_ID_ADD_VARIABLE, EVENT_ID_ADD_VARIABLE_GROUP, EVENT_ID_GRID_COMPLETED
81         };
82
83         /// Constructeurs ///
84         CField(void);
85         explicit CField(const StdString& id);
86         CField(const CField& field);       // Not implemented yet.
87         CField(const CField* const field); // Not implemented yet.
88
89         /// Accesseurs ///
90
91         CGrid* getRelGrid(void) const;
92         CFile* getRelFile(void) const;
93
94         func::CFunctor::ETimeType getOperationTimeType() const;
95
96      public:
97         int getNStep(void) const;
98
99         template <int N> void getData(CArray<double, N>& _data) const;
100
101         std::shared_ptr<COutputPin> getInstantDataFilter();
102
103         /// Mutateur ///
104         void setRelFile(CFile* _file);
105         void incrementNStep(void);
106         void resetNStep(int nstep = 0);
107         void resetNStepMax();
108
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);
112
113       public:
114          void makeGridAliasForCoupling(void) ;
115       public:
116         bool isActive(bool atCurrentTimestep = false) const;
117         bool hasOutputFile;
118
119         bool wasWritten() const;
120         void setWritten();
121
122         bool getUseCompressedOutput() const;
123         void setUseCompressedOutput();
124
125         /// Traitements ///
126         void solveGridReference(void);
127         void solveServerOperation(void);
128         void solveCheckMaskIndex(bool doSendingIndex);
129         void solveAllReferenceEnabledField(bool doSending2Server);
130         void solveOnlyReferenceEnabledField(void);
131         void generateNewTransformationGridDest();
132         void updateRef(CGrid* grid);
133         void buildGridTransformationGraph();
134         void solveGridDomainAxisRef(bool checkAtt);
135         void solveTransformedGrid();
136         void solveGenerateGrid();
137         void solveGridDomainAxisBaseRef();
138
139         void solveAllEnabledFieldsAndTransform();
140         void checkGridOfEnabledFields();
141         void sendGridOfEnabledFields();
142         void sendGridComponentOfEnabledFields();
143
144         void sendFieldToFileServer(void) ;
145         void sendCloseDefinition(void) ;
146     
147      public:
148         void sendFieldToCouplerOut(void) ;
149      private:
150         bool sendFieldToCouplerOut_done_=false;
151      public:
152
153         void sendFieldToInputFileServer(void) ;
154
155         /// Vérifications ///
156         void checkTimeAttributes(CDuration* freqOp=NULL);
157
158         void buildFilterGraph(CGarbageCollector& gc, bool enableOutput);
159
160         bool buildWorkflowGraph(CGarbageCollector& gc) ;
161         bool buildWorkflowGraphDone_ = false ;
162
163         size_t getGlobalWrittenSize(void) ;
164         
165         
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);
170
171//         virtual void fromBinary(StdIStream& is);
172
173         /// Destructeur ///
174         virtual ~CField(void);
175
176         /// Accesseurs statiques ///
177         static StdString GetName(void);
178         static StdString GetDefName(void);
179
180         static ENodeType GetType(void);
181
182        template <int N> void setData(const CArray<double, N>& _data);
183        static bool dispatchEvent(CEventServer& event);
184        void sendAllAttributesToServer(CContextClient* client) ; 
185        void sendUpdateData(const CArray<double,1>& data);
186        void sendUpdateData(Time timestamp, const CArray<double,1>& data, CContextClient* client);
187        static void recvUpdateData(CEventServer& event);
188        void recvUpdateData(std::map<int,CBufferIn*>& rankBuffers);
189        void recvUpdateDataFromClient(std::map<int,CBufferIn*>& rankBuffers);
190        void recvUpdateDataFromCoupler(std::map<int,CBufferIn*>& rankBuffers);
191       
192        void writeField(void);
193        bool sendReadDataRequest(const CDate& tsDataRequested, CContextClient* client);
194        bool sendReadDataRequestIfNeeded(void);
195        static void recvReadDataRequest(CEventServer& event);
196        void recvReadDataRequest(CContextServer* server);
197        EReadField readField(void);
198        static void recvReadDataReady(CEventServer& event);
199        void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers);
200        void recvDataFromCoupler(vector<int> ranks, vector<CBufferIn*> buffers) ;
201        void checkForLateDataFromServer(void);
202        void checkForLateDataFromCoupler(void) ;
203
204        void checkIfMustAutoTrigger(void); // ym obsolete
205        void autoTriggerIfNeeded(void); //ym obsolete
206        void triggerLateField(void) ;
207
208        void outputField(CArray<double,3>& fieldOut);
209        void outputField(CArray<double,2>& fieldOut);
210        void outputField(CArray<double,1>& fieldOut);
211        void inputField(CArray<double,3>& fieldOut);
212        void inputField(CArray<double,2>& fieldOut);
213        void inputField(CArray<double,1>& fieldOut);
214        void outputCompressedField(CArray<double, 1>& fieldOut);
215        void scaleFactorAddOffset(double scaleFactor, double addOffset);
216        void invertScaleFactorAddOffset(double scaleFactor, double addOffset);
217        void parse(xml::CXMLNode& node);
218
219        void setVirtualVariableGroup(CVariableGroup* newVVariableGroup);
220        CVariableGroup* getVirtualVariableGroup(void) const;
221        vector<CVariable*> getAllVariables(void) const;
222        virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0);
223
224        CVariable* addVariable(const string& id = "");
225        CVariableGroup* addVariableGroup(const string& id = "");       
226        void sendAddVariable(const string& id, CContextClient* client);
227        void sendAddVariableGroup(const string& id, CContextClient* client);
228        static void recvAddVariable(CEventServer& event);
229        void recvAddVariable(CBufferIn& buffer);
230        static void recvAddVariableGroup(CEventServer& event);
231        void recvAddVariableGroup(CBufferIn& buffer);       
232        void sendAddAllVariables(CContextClient* client);
233        void writeUpdateData(const CArray<double,1>& data);
234
235        const std::vector<StdString>& getRefDomainAxisIds();
236
237        const string& getExpression(void);
238        bool hasExpression(void) const;
239
240        bool hasGridMask(void) const;
241        CGrid* getGrid(void) { return grid_; } 
242
243        void connectToFileServer(CGarbageCollector& gc) ;
244        void connectToCouplerOut(CGarbageCollector& gc) ;
245        void connectToCouplerIn(CGarbageCollector& gc) ;
246        void connectToModelInput(CGarbageCollector& gc) ;
247        void connectToFileWriter(CGarbageCollector& gc) ;
248        void connectToClientInput(CGarbageCollector& gc) ;
249        void connectToServerInput(CGarbageCollector& gc) ;
250        void connectToModelOutput(CGarbageCollector& gc);
251
252        void computeGridIndexToFileServer(void) ;
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) ;
260      private:
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:
275        std::vector<CGrid*> getGridPath(void) ;
276
277      public:
278         /// Propriétés privées ///
279         CVariableGroup* vVariableGroup;
280
281         CGrid*  grid_=nullptr;
282//         CFile*  file;
283         
284         CFile* fileIn_ = nullptr ; //<! pointer to input related file
285         bool hasFileIn(void) const { return fileIn_==nullptr ? false : true ;} 
286         CFile* getFileIn(void) {return fileIn_;}
287         void setFileIn(CFile* fileIn) { fileIn_ = fileIn ;}
288         void unsetFileIn(void) { fileIn_ = nullptr ;}
289
290         CFile* fileOut_ = nullptr ; //<! pointer to output related file
291         bool hasFileOut(void) const { return fileOut_==nullptr ? false : true ;} 
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
297         bool hasCouplerIn(void) const { return couplerIn_==nullptr ? false : true ;}
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
303         bool hasCouplerOut(void) const { return couplerOut_==nullptr ? false : true ;}
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
318         CDuration freq_operation_srv, freq_write_srv;
319
320         bool written; //<! Was the field written at least once
321         int nstep, nstepMax;
322         bool isEOF;
323         CDate lastlast_Write_srv, last_Write_srv, last_operation_srv;
324         CDate lastDataRequestedFromServer, lastDataReceivedFromServer, dateEOF;
325         bool wasDataRequestedFromServer, wasDataAlreadyReceivedFromServer;
326         bool mustAutoTrigger;
327
328         map<int,std::shared_ptr<func::CFunctor> > foperation_srv;
329
330         // map<int, CArray<double,1> > data_srv;
331         CArray<double,1> recvDataSrv;
332         
333         std::shared_ptr<func::CFunctor> recvFoperationSrv;
334         string content;
335
336         std::vector<StdString> domAxisScalarIds_;
337         bool useCompressedOutput;
338
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
343
344         DECLARE_REF_FUNC(Field,field)
345       
346      private:
347         CContextClient* client;
348      public:
349         void setContextClient(CContextClient* newContextClient);
350         CContextClient* getContextClient(void) {return client;}
351
352      private:
353
354         bool areAllReferenceSolved;
355         bool isReferenceSolved;
356         bool isReferenceSolvedAndTransformed;
357         bool isGridChecked;
358         bool nstepMaxRead;
359
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
369      private:
370     
371         //! The type of operation attached to the field
372         func::CFunctor::ETimeType operationTimeType;
373
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         
380         //! The output pin of the filter providing the instant data for the field
381         std::shared_ptr<COutputPin> instantDataFilter;
382         
383         //! The output pin of the filters providing the result of the field's temporal operation
384         std::map<CDuration, std::shared_ptr<COutputPin>, DurationFakeLessComparator> temporalDataFilters;
385         
386         //! The output pin of the filter providing the instant data for self references
387         std::shared_ptr<COutputPin> selfReferenceFilter; // probably redondant with inputFilter
388
389         //! The source filter for data provided by the client
390         std::shared_ptr<CSourceFilter> clientSourceFilter;
391         
392         //! The source filter for data provided by the server
393         std::shared_ptr<CSourceFilter> serverSourceFilter;
394         
395         //! The terminal filter which stores the instant data
396         std::shared_ptr<CStoreFilter> storeFilter;
397       
398         //! The terminal filter which writes the data to file
399         std::shared_ptr<CFileWriterFilter> fileWriterFilter;
400       
401         //! The terminal filter which writes data to file
402         std::shared_ptr<CFileServerWriterFilter> fileServerWriterFilter;
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   ///-----------------------------------------------------------------
416} // namespace xios
417
418
419#endif // __XIOS_CField__
Note: See TracBrowser for help on using the repository browser.