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

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

Solve issues for grid mask on server side.

YM

File size: 8.7 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           friend class CScalarGroup;
44
45            /// typedef ///
46            typedef CObjectTemplate<CScalar>   SuperClass;
47            typedef CScalarAttributes SuperClassAttribute;
48
49         public:
50           enum EEventId
51           {
52             EVENT_ID_SCALAR_DISTRIBUTION,
53             EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE,
54           } ;
55           static bool dispatchEvent(CEventServer& event);     
56           
57
58         public :
59
60            typedef CScalarAttributes RelAttributes;
61            typedef CScalarGroup      RelGroup;
62            typedef CTransformation<CScalar>::TransformationMapTypes TransMapTypes;
63
64            /// Constructeurs ///
65            CScalar(void);
66            explicit CScalar(const StdString & id);
67            CScalar(const CScalar & var);       // Not implemented yet.
68            CScalar(const CScalar * const var); // Not implemented yet.
69
70            /// Destructeur ///
71            virtual ~CScalar(void);
72
73         public :
74            /// Accesseurs statiques ///
75            static StdString GetName(void);
76            static StdString GetDefName(void);
77            static ENodeType GetType(void);
78
79         public:
80            static CScalar* createScalar();
81
82         public:
83            void checkAttributes(void);
84            bool checkAttributes_done_ = false ;
85           
86            void addRelFile(const StdString& filename);
87            bool IsWritten(const StdString& filename) const;
88            void checkAttributesOnClient();
89            virtual void parse(xml::CXMLNode & node);
90       
91         public:
92            void sendScalarToFileServer(CContextClient* client) ;
93         private:
94            std::set<CContextClient*> sendScalarToFileServer_done_ ;
95
96         public:
97            void sendScalarToCouplerOut(CContextClient* client, const string& fieldId, int posInGrid) ;
98         private:
99            std::set<CContextClient*> sendScalarToCouplerOut_done_ ;
100         
101         public:
102            void makeAliasForCoupling(const string& fieldId, int posInGrid) ;
103
104         public:
105           bool hasTransformation();
106           void solveInheritanceTransformation();
107           TransMapTypes getAllTransformations();
108           void duplicateTransformation(CScalar*);
109           CTransformation<CScalar>* addTransformation(ETranformationType transType, const StdString& id="");
110           bool isEqual(CScalar* scalar);
111        private: 
112          /** Clients that have to send a scalar. There can be multiple clients in case of secondary server, otherwise only one client. */
113         std::list<CContextClient*> clients;
114         std::set<CContextClient*> clientsSet;
115        public:
116          void setContextClient(CContextClient* contextClient) ;
117       
118         private:
119           std::set<StdString> relFiles;
120           TransMapTypes transformationMap_;
121
122            void setTransformations(const TransMapTypes&);
123
124       private:
125           static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m);
126           static std::map<StdString, ETranformationType> transformationMapList_;
127           static bool dummyTransformationMapList_;
128
129           /** define if the scalar is completed or not ie all attributes have been received before in case
130               of grid reading from file or coupling */ 
131      private:
132         /** define if the scalar is completed or not ie all attributes have been received before in case
133             of grid reading from file or coupling */ 
134         bool isCompleted_=true ; 
135      public:     
136         /*!
137           \brief Check if a scalar is completed
138           Before make any scalar processing, we must be sure that all scalar informations have
139           been sent, for exemple when reading a grid in a file or when grid elements are sent by an
140           other context (coupling). So all direct reference of the scalar (scalar_ref) must be also completed
141           \return true if scalar and scalar reference are completed
142          */
143         bool isCompleted(void)
144         {
145           if (hasDirectScalarReference()) if (!getDirectScalarReference()->isCompleted()) return false;
146           else return isCompleted_ ;
147         }
148         void setCompleted(void) { isCompleted_=true ; }
149         void unsetCompleted(void) { isCompleted_=false ; }
150
151
152
153       //////////////////////////////////////////////////////////////////////////////////////
154       //  this part is related to distribution, element definition, views and connectors  //
155       //////////////////////////////////////////////////////////////////////////////////////
156       private:
157         CLocalElement* localElement_ = nullptr ;
158         void initializeLocalElement(void) ;
159       
160       public: 
161         CLocalElement* getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; }
162         CLocalView* getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;}
163       
164       private: 
165         void addFullView(void) ;
166         void addWorkflowView(void) ;
167         void addModelView(void) ;
168       
169       private:
170         CLocalConnector* modelToWorkflowConnector_ ;
171         void computeModelToWorkflowConnector(void)  ;
172       public:
173         CLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;}
174
175       public:
176         void computeRemoteElement(CContextClient* client, EDistributionType) ;
177         void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex, const string& scalarId="") ;
178         static void recvScalarDistribution(CEventServer& event) ;
179         void receivedScalarDistribution(CEventServer& event, int phasis) ;
180         void setServerMask(CArray<bool,1>& serverMask, CContextClient* client) ;
181         void sendDistributedAttributes(CContextClient* client, CScattererConnector& scattererConnector, const string& scalarId) ;
182         static void recvDistributedAttributes(CEventServer& event) ;
183         void recvDistributedAttributes(CEventServer& event, const string& type) ;
184
185       private:
186         map<CContextClient*, CDistributedElement*> remoteElement_ ;
187       public: 
188         CDistributedElement* getRemoteElement(CContextClient* client) {return remoteElement_[client] ;}
189       private:
190         map<CContextClient*, CScattererConnector*> clientToServerConnector_ ;
191       public: 
192         CScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;}
193
194       private:
195         CGathererConnector*  gathererConnector_ ;
196       public:
197         CGathererConnector* getGathererConnector(void) { return gathererConnector_ ;}
198       private:
199         CGathererConnector* serverFromClientConnector_ ;
200         CDistributedElement* elementFrom_ ;
201       public:
202        CGathererConnector* getServerFromClientConnector(void) { return serverFromClientConnector_ ;}
203
204       private:
205         CScattererConnector*  serverToClientConnector_ = nullptr ;
206       public: 
207         CScattererConnector* getServerToClientConnector(void) { return serverToClientConnector_ ;} 
208
209       private:
210          map<CContextClient*,CGathererConnector*>  clientFromServerConnector_  ;
211       public: 
212         CGathererConnector* getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;} 
213
214      private:
215            DECLARE_REF_FUNC(Scalar,scalar)
216
217      }; // class CVar
218      ///--------------------------------------------------------------
219
220      // Declare/Define CScalarGroup and CScalarDefinition
221      DECLARE_GROUP(CScalar);
222} // namespace xios
223
224#endif // __XIOS_CScalar__
Note: See TracBrowser for help on using the repository browser.