source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/scalar.hpp @ 1930

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

Big update on on going work related to data distribution and transfer between clients and servers.
Revisite of the source and store filter using "connectors".

YM

File size: 7.3 KB
Line 
1#ifndef __XIOS_CScalar__
2#define __XIOS_CScalar__
3
4/// XIOS headers ///
5#include "xios_spl.hpp"
6#include "declare_group.hpp"
7#include "declare_ref_func.hpp"
8#include "group_template.hpp"
9#include "array_new.hpp"
10#include "attribute_enum.hpp"
11#include "attribute_enum_impl.hpp"
12#include "attribute_array.hpp"
13#include "transformation.hpp"
14#include "transformation_enum.hpp"
15
16#include "element.hpp"
17#include "local_connector.hpp"
18#include "scatterer_connector.hpp"
19#include "gatherer_connector.hpp"
20#include "distribution_type.hpp"
21
22
23namespace xios
24{
25      /// ////////////////////// Déclarations ////////////////////// ///
26
27      class CScalarGroup;
28      class CScalarAttributes;
29      class CScalar;
30      ///--------------------------------------------------------------
31
32      // Declare/Define CVarAttribute
33      BEGIN_DECLARE_ATTRIBUTE_MAP(CScalar)
34#include "scalar_attribute.conf"
35      END_DECLARE_ATTRIBUTE_MAP(CScalar)
36
37      ///--------------------------------------------------------------
38
39      class CScalar
40         : public CObjectTemplate<CScalar>
41         , public CScalarAttributes
42      {
43            /// typedef ///
44            typedef CObjectTemplate<CScalar>   SuperClass;
45            typedef CScalarAttributes SuperClassAttribute;
46
47            friend class CScalarGroup;
48
49         public :
50
51            typedef CScalarAttributes RelAttributes;
52            typedef CScalarGroup      RelGroup;
53            typedef CTransformation<CScalar>::TransformationMapTypes TransMapTypes;
54
55            /// Constructeurs ///
56            CScalar(void);
57            explicit CScalar(const StdString & id);
58            CScalar(const CScalar & var);       // Not implemented yet.
59            CScalar(const CScalar * const var); // Not implemented yet.
60
61            /// Destructeur ///
62            virtual ~CScalar(void);
63
64         public :
65            /// Accesseurs statiques ///
66            static StdString GetName(void);
67            static StdString GetDefName(void);
68            static ENodeType GetType(void);
69
70         public:
71            static CScalar* createScalar();
72
73         public:
74            void checkAttributes(void);
75            bool checkAttributes_done_ = false ;
76           
77            void addRelFile(const StdString& filename);
78            bool IsWritten(const StdString& filename) const;
79            void checkAttributesOnClient();
80            virtual void parse(xml::CXMLNode & node);
81       
82         public:
83            void sendScalarToFileServer(CContextClient* client) ;
84         private:
85            std::set<CContextClient*> sendScalarToFileServer_done_ ;
86
87         public:
88            void sendScalarToCouplerOut(CContextClient* client, const string& fieldId, int posInGrid) ;
89         private:
90            std::set<CContextClient*> sendScalarToCouplerOut_done_ ;
91         
92         public:
93            void makeAliasForCoupling(const string& fieldId, int posInGrid) ;
94
95         public:
96           bool hasTransformation();
97           void solveInheritanceTransformation();
98           TransMapTypes getAllTransformations();
99           void duplicateTransformation(CScalar*);
100           CTransformation<CScalar>* addTransformation(ETranformationType transType, const StdString& id="");
101           bool isEqual(CScalar* scalar);
102        private: 
103          /** Clients that have to send a scalar. There can be multiple clients in case of secondary server, otherwise only one client. */
104         std::list<CContextClient*> clients;
105         std::set<CContextClient*> clientsSet;
106        public:
107          void setContextClient(CContextClient* contextClient) ;
108       
109         private:
110           std::set<StdString> relFiles;
111           TransMapTypes transformationMap_;
112
113            void setTransformations(const TransMapTypes&);
114
115       private:
116           static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m);
117           static std::map<StdString, ETranformationType> transformationMapList_;
118           static bool dummyTransformationMapList_;
119
120           /** define if the scalar is completed or not ie all attributes have been received before in case
121               of grid reading from file or coupling */ 
122      private:
123         /** define if the scalar is completed or not ie all attributes have been received before in case
124             of grid reading from file or coupling */ 
125         bool isCompleted_=true ; 
126      public:     
127         /*!
128           \brief Check if a scalar is completed
129           Before make any scalar processing, we must be sure that all scalar informations have
130           been sent, for exemple when reading a grid in a file or when grid elements are sent by an
131           other context (coupling). So all direct reference of the scalar (scalar_ref) must be also completed
132           \return true if scalar and scalar reference are completed
133          */
134         bool isCompleted(void)
135         {
136           if (hasDirectScalarReference()) if (!getDirectScalarReference()->isCompleted()) return false;
137           else return isCompleted_ ;
138         }
139         void setCompleted(void) { isCompleted_=true ; }
140         void unsetCompleted(void) { isCompleted_=false ; }
141
142
143
144       //////////////////////////////////////////////////////////////////////////////////////
145       //  this part is related to distribution, element definition, views and connectors  //
146       //////////////////////////////////////////////////////////////////////////////////////
147       private:
148         CLocalElement* localElement_ = nullptr ;
149         void initializeLocalElement(void) ;
150       
151       public: 
152         CLocalElement* getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; }
153         CLocalView* getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;}
154       
155       private: 
156         void addFullView(void) ;
157         void addWorkflowView(void) ;
158         void addModelView(void) ;
159       
160       private:
161         CLocalConnector* modelToWorkflowConnector_ ;
162         void computeModelToWorkflowConnector(void)  ;
163       public:
164         CLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;}
165
166       public:
167         void computeRemoteElement(CContextClient* client, EDistributionType) ;
168         void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex) ;
169       private:
170         map<CContextClient*, CDistributedElement*> remoteElement_ ;
171       public: 
172         CDistributedElement* getRemoteElement(CContextClient* client) {return remoteElement_[client] ;}
173       private:
174         map<CContextClient*, CScattererConnector*> clientToServerConnector_ ;
175       public: 
176         CScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;}
177
178       private:
179         CGathererConnector*  gathererConnector_ ;
180         CGathererConnector* serverFromClientConnector_ ;
181       public:
182        CGathererConnector* getServerFromClientConnector(void) { return serverFromClientConnector_ ;}
183
184
185
186
187
188      private:
189            DECLARE_REF_FUNC(Scalar,scalar)
190
191      }; // class CVar
192      ///--------------------------------------------------------------
193
194      // Declare/Define CScalarGroup and CScalarDefinition
195      DECLARE_GROUP(CScalar);
196} // namespace xios
197
198#endif // __XIOS_CScalar__
Note: See TracBrowser for help on using the repository browser.