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

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

Some update on XIOS_COUPLING branch...

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: 14.4 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
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         void setContextClient(CContextClient* newContextClient);
114         CContextClient* getContextClient();
115
116       public:
117         bool isActive(bool atCurrentTimestep = false) const;
118         bool hasOutputFile;
119
120         bool wasWritten() const;
121         void setWritten();
122
123         bool getUseCompressedOutput() const;
124         void setUseCompressedOutput();
125
126         /// Traitements ///
127         void solveGridReference(void);
128         void solveServerOperation(void);
129         void solveCheckMaskIndex(bool doSendingIndex);
130         void solveAllReferenceEnabledField(bool doSending2Server);
131         void solveOnlyReferenceEnabledField(void);
132         void generateNewTransformationGridDest();
133         void updateRef(CGrid* grid);
134         void buildGridTransformationGraph();
135         void solveGridDomainAxisRef(bool checkAtt);
136         void solveTransformedGrid();
137         void solveGenerateGrid();
138         void solveGridDomainAxisBaseRef();
139
140         void solveAllEnabledFieldsAndTransform();
141         void checkGridOfEnabledFields();
142         void sendGridOfEnabledFields();
143         void sendGridComponentOfEnabledFields();
144
145         void sendFieldToFileServer(void) ;
146         void sendFieldToInputFileServer(void) ;
147
148         /// Vérifications ///
149         void checkTimeAttributes(CDuration* freqOp=NULL);
150
151         void buildFilterGraph(CGarbageCollector& gc, bool enableOutput);
152
153         bool buildWorkflowGraph(CGarbageCollector& gc) ;
154         bool buildWorkflowGraphDone_ = false ;
155
156         size_t getGlobalWrittenSize(void) ;
157         
158         
159         std::shared_ptr<COutputPin> getFieldReference(CGarbageCollector& gc);
160         std::shared_ptr<COutputPin> getSelfReference(CGarbageCollector& gc);
161         std::shared_ptr<COutputPin> getTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
162         std::shared_ptr<COutputPin> getSelfTemporalDataFilter(CGarbageCollector& gc, CDuration outFreq);
163
164//         virtual void fromBinary(StdIStream& is);
165
166         /// Destructeur ///
167         virtual ~CField(void);
168
169         /// Accesseurs statiques ///
170         static StdString GetName(void);
171         static StdString GetDefName(void);
172
173         static ENodeType GetType(void);
174
175        template <int N> void setData(const CArray<double, N>& _data);
176        static bool dispatchEvent(CEventServer& event);
177        void sendAllAttributesToServer(CContextClient* client) ; 
178        void sendUpdateData(const CArray<double,1>& data);
179        void sendUpdateData(const CArray<double,1>& data, CContextClient* client);
180        static void recvUpdateData(CEventServer& event);
181        void recvUpdateData(std::map<int,CBufferIn*>& rankBuffers);
182        void writeField(void);
183        bool sendReadDataRequest(const CDate& tsDataRequested, CContextClient* client);
184        bool sendReadDataRequestIfNeeded(void);
185        static void recvReadDataRequest(CEventServer& event);
186        void recvReadDataRequest(CContextServer* server);
187        EReadField readField(void);
188        static void recvReadDataReady(CEventServer& event);
189        void recvReadDataReady(vector<int> ranks, vector<CBufferIn*> buffers);
190        void checkForLateDataFromServer(void);
191        void checkIfMustAutoTrigger(void);
192        void autoTriggerIfNeeded(void);
193        void outputField(CArray<double,3>& fieldOut);
194        void outputField(CArray<double,2>& fieldOut);
195        void outputField(CArray<double,1>& fieldOut);
196        void inputField(CArray<double,3>& fieldOut);
197        void inputField(CArray<double,2>& fieldOut);
198        void inputField(CArray<double,1>& fieldOut);
199        void outputCompressedField(CArray<double, 1>& fieldOut);
200        void scaleFactorAddOffset(double scaleFactor, double addOffset);
201        void invertScaleFactorAddOffset(double scaleFactor, double addOffset);
202        void parse(xml::CXMLNode& node);
203
204        void setVirtualVariableGroup(CVariableGroup* newVVariableGroup);
205        CVariableGroup* getVirtualVariableGroup(void) const;
206        vector<CVariable*> getAllVariables(void) const;
207        virtual void solveDescInheritance(bool apply, const CAttributeMap* const parent = 0);
208
209        CVariable* addVariable(const string& id = "");
210        CVariableGroup* addVariableGroup(const string& id = "");       
211        void sendAddVariable(const string& id, CContextClient* client);
212        void sendAddVariableGroup(const string& id, CContextClient* client);
213        static void recvAddVariable(CEventServer& event);
214        void recvAddVariable(CBufferIn& buffer);
215        static void recvAddVariableGroup(CEventServer& event);
216        void recvAddVariableGroup(CBufferIn& buffer);       
217        void sendAddAllVariables(CContextClient* client);
218        void writeUpdateData(const CArray<double,1>& data);
219
220        const std::vector<StdString>& getRefDomainAxisIds();
221
222        const string& getExpression(void);
223        bool hasExpression(void) const;
224
225        bool hasGridMask(void) const;
226        CGrid* getGrid(void) { return grid_; } 
227
228        void connectToFileServer(CGarbageCollector& gc) ;
229        void connectToModelInput(CGarbageCollector& gc) ;
230        void connectToFileWriter(CGarbageCollector& gc) ;
231        void connectToClientInput(CGarbageCollector& gc) ;
232        void connectToServerInput(CGarbageCollector& gc) ;
233        void connectToModelOutput(CGarbageCollector& gc);
234
235        void computeGridIndexToFileServer(void) ;
236
237        void setContextClientDataBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
238                                        map<CContextClient*,map<int,size_t>>& maxEventSize, 
239                                        bool bufferForWriting) ;
240        void setContextClientAttributesBufferSize(map<CContextClient*,map<int,size_t>>& bufferSize, 
241                                                 map<CContextClient*,map<int,size_t>>& maxEventSize, 
242                                                 bool bufferForWriting) ;
243      private:
244        std::vector<CGrid*> getGridPath(void) ;
245
246      public:
247         /// Propriétés privées ///
248         CVariableGroup* vVariableGroup;
249
250         CGrid*  grid_=nullptr;
251//         CFile*  file;
252         
253         CFile* fileIn_ = nullptr ; //<! pointer to input related file
254         bool hasFileIn(void) const { return fileIn_==nullptr ? false : true ;} 
255         CFile* getFileIn(void) {return fileIn_;}
256         void setFileIn(CFile* fileIn) { fileIn_ = fileIn ;}
257         void unsetFileIn(void) { fileIn_ = nullptr ;}
258
259         CFile* fileOut_ = nullptr ; //<! pointer to output related file
260         bool hasFileOut(void) const { return fileOut_==nullptr ? false : true ;} 
261         CFile* getFileOut(void) {return fileOut_;}
262         void setFileOut(CFile* fileOut) { fileOut_ = fileOut ;}
263         void unsetFileOut(void) { fileOut_ = nullptr ;}
264
265         CCouplerIn* couplerIn_ = nullptr ; //<!pointer to input related coupler
266         bool hasCouplerIn(void) const { return couplerIn_==nullptr ? false : true ;}
267         CCouplerIn* getCouplerIn(void) {return couplerIn_;}
268         void setCouplerIn(CCouplerIn* couplerIn) { couplerIn_ = couplerIn ;}
269         void unsetCouplerIn(void) { couplerIn_ = nullptr ;}
270
271         CCouplerOut* couplerOut_ = nullptr ; //<!pointer to output related coupler
272         bool hasCouplerOut(void) const { return couplerOut_==nullptr ? false : true ;}
273         CCouplerOut* getCouplerOut(void) {return couplerOut_;}
274         void setCouplerOut(CCouplerOut* couplerOut) { couplerOut_ = couplerOut ;}
275         void unsetCouplerOut(void) { couplerOut_ = nullptr ;}
276
277         bool modelIn_ = false ; //<! field can be received from model == true
278         bool getModelIn(void) { return modelIn_ ;}
279         void setModelIn(void) { modelIn_ = true ;}
280         void unsetModelIn(void) { modelIn_ = false ;}
281         
282         bool modelOut_ = false ; //<! field can be retrieve to model == true
283         bool getModelOut(void) { return modelOut_ ;}
284         void setModelOut(void) { modelOut_ = true ;}
285         void unsetModelOut(void) { modelOut_ = false ;}
286
287         CDuration freq_operation_srv, freq_write_srv;
288
289         bool written; //<! Was the field written at least once
290         int nstep, nstepMax;
291         bool isEOF;
292         CDate lastlast_Write_srv, last_Write_srv, last_operation_srv;
293         CDate lastDataRequestedFromServer, lastDataReceivedFromServer, dateEOF;
294         bool wasDataRequestedFromServer, wasDataAlreadyReceivedFromServer;
295         bool mustAutoTrigger;
296
297         map<int,std::shared_ptr<func::CFunctor> > foperation_srv;
298
299         // map<int, CArray<double,1> > data_srv;
300         CArray<double,1> recvDataSrv;
301         
302         std::shared_ptr<func::CFunctor> recvFoperationSrv;
303         string content;
304
305         std::vector<StdString> domAxisScalarIds_;
306         bool useCompressedOutput;
307
308         // Two variables to identify the time_counter meta data written in file, which has no time_counter
309         bool hasTimeInstant;
310         bool hasTimeCentered;
311
312
313         DECLARE_REF_FUNC(Field,field)
314       
315      private:
316         CContextClient* client;
317
318         bool areAllReferenceSolved;
319         bool isReferenceSolved;
320         bool isReferenceSolvedAndTransformed;
321         bool isGridChecked;
322         bool nstepMaxRead;
323
324       private: 
325         //! define if the field is part of the active workflow. It will be tagged to true when CField::buildWorkflowGraph is successfull
326         bool workflowEnabled_ = false ;
327       public: 
328         /*! workflowEnabled_ public accessor
329          * \return Value of workflowEnabled_ */
330         bool getWorkflowEnabled(void) { return  workflowEnabled_; }
331 
332
333      private:
334     
335         //! The type of operation attached to the field
336         func::CFunctor::ETimeType operationTimeType;
337
338         //! The output pin of the input filter of the field
339         std::shared_ptr<CPassThroughFilter> inputFilter;
340
341         //! The self temporal data filter
342         std::shared_ptr<CTemporalFilter> selfTemporalDataFilter ;
343         
344         //! The output pin of the filter providing the instant data for the field
345         std::shared_ptr<COutputPin> instantDataFilter;
346         
347         //! The output pin of the filters providing the result of the field's temporal operation
348         std::map<CDuration, std::shared_ptr<COutputPin>, DurationFakeLessComparator> temporalDataFilters;
349         
350         //! The output pin of the filter providing the instant data for self references
351         std::shared_ptr<COutputPin> selfReferenceFilter; // probably redondant with inputFilter
352
353         //! The source filter for data provided by the client
354         std::shared_ptr<CSourceFilter> clientSourceFilter;
355         
356         //! The source filter for data provided by the server
357         std::shared_ptr<CSourceFilter> serverSourceFilter;
358         
359         //! The terminal filter which stores the instant data
360         std::shared_ptr<CStoreFilter> storeFilter;
361       
362         //! The terminal filter which writes the data to file
363         std::shared_ptr<CFileWriterFilter> fileWriterFilter;
364       
365         //! The terminal filter which writes data to file
366         std::shared_ptr<CFileServerWriterFilter> fileServerWriterFilter;
367   }; // class CField
368
369   ///--------------------------------------------------------------
370
371   // Declare/Define CFieldGroup and CFieldDefinition
372   DECLARE_GROUP(CField);
373
374   ///-----------------------------------------------------------------
375
376   template <>
377      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void);
378
379   ///-----------------------------------------------------------------
380} // namespace xios
381
382
383#endif // __XIOS_CField__
Note: See TracBrowser for help on using the repository browser.