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

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