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

Last change on this file since 2206 was 2206, checked in by ymipsl, 5 months ago

New feature : when can now use the syntax :
fieldId:domainId[n], in domain reference inside the workflow (XML). Same for axis and scalar.

YM

File size: 9.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#include "transformation_path.hpp"
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#include "generic_algorithm_transformation.hpp"
22
23
24namespace xios
25{
26  /// ////////////////////// Déclarations ////////////////////// ///
27
28  class CScalarGroup;
29  class CScalarAttributes;
30  class CScalar;
31  class CField;
32  ///--------------------------------------------------------------
33
34  // Declare/Define CVarAttribute
35  BEGIN_DECLARE_ATTRIBUTE_MAP(CScalar)
36#include "scalar_attribute.conf"
37  END_DECLARE_ATTRIBUTE_MAP(CScalar)
38
39  ///--------------------------------------------------------------
40
41  class CScalar: public CObjectTemplate<CScalar>
42               , public CScalarAttributes
43  {
44      friend class CScalarGroup;
45
46      /// typedef ///
47      typedef CObjectTemplate<CScalar>   SuperClass;
48      typedef CScalarAttributes SuperClassAttribute;
49
50    public:
51      enum EEventId
52      {
53        EVENT_ID_SCALAR_DISTRIBUTION,
54        EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE,
55      } ;
56      static bool dispatchEvent(CEventServer& event);     
57           
58
59    public :
60
61      typedef CScalarAttributes RelAttributes;
62      typedef CScalarGroup      RelGroup;
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      static CScalar* get(const string& id, bool noError=false) ; //<! return scalar pointer using id
82      static bool     has(const string& id) ; //<! return domain pointer using id
83      static CField*  getFieldFromId(const string& id) ;
84
85    public:
86      void checkAttributes(void);
87      bool checkAttributes_done_ = false ;
88           
89      void addRelFile(const StdString& filename);
90      bool IsWritten(const StdString& filename) const;
91      virtual void parse(xml::CXMLNode & node);
92       
93    public:
94      void sendScalarToCouplerOut(CContextClient* client, const string& fieldId, int posInGrid) ;
95    private:
96      std::set<CContextClient*> sendScalarToCouplerOut_done_ ;
97         
98    public:
99      void makeAliasForCoupling(const string& fieldId, int posInGrid) ;
100      string getCouplingAlias(const string& fieldId, int posInGrid) ;
101
102      ////////////////////////////////
103      ////    TRANSFORMATIONS     ////
104      ////////////////////////////////
105    public:
106      typedef CTransformation<CScalar>::TransformationMapTypes TransMapTypes;
107    private:
108      static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m);
109      static std::map<StdString, ETranformationType> transformationMapList_;
110      static bool dummyTransformationMapList_;      TransMapTypes transformationMap_;
111      void setTransformations(const TransMapTypes&);
112
113    public:
114      bool hasTransformation();
115      TransMapTypes getAllTransformations();
116      void duplicateTransformation(CScalar*);
117      CTransformation<CScalar>* addTransformation(ETranformationType transType, const StdString& id="");
118   
119       void solveInheritanceTransformation_old();
120       void solveInheritanceTransformation();
121      private:
122        bool solveInheritanceTransformation_done_= false ;
123      public:
124        bool activateFieldWorkflow(CGarbageCollector& gc) ;
125      private:
126        bool activateFieldWorkflow_done_=false ;
127      private:
128        CGenericAlgorithmTransformation* transformationAlgorithm_ = nullptr ;
129      public:
130        void setTransformationAlgorithm(CGenericAlgorithmTransformation* transformationAlgorithm) { transformationAlgorithm_=transformationAlgorithm ;}
131        CGenericAlgorithmTransformation* getTransformationAlgorithm(void) { return transformationAlgorithm_ ;}   
132      private:
133        CTransformationPaths transformationPaths_ ;
134      public:
135        CTransformationPaths getTransformationPaths(void) {return transformationPaths_;} 
136        void setTransformationPaths(const CTransformationPaths& transformationPaths) { transformationPaths_=transformationPaths ;}
137      ////////////////////////////////
138      ////////////////////////////////
139
140      bool isEqual(CScalar* scalar);
141    private: 
142          /** Clients that have to send a scalar. There can be multiple clients in case of secondary server, otherwise only one client. */
143      std::list<CContextClient*> clients;
144      std::set<CContextClient*> clientsSet;
145    public:
146      void setContextClient(CContextClient* contextClient) ;
147       
148    private:
149      std::set<StdString> relFiles;
150
151    private:
152      /** define if the scalar is completed or not ie all attributes have been received before in case
153           of grid reading from file or coupling */ 
154      bool isCompleted_=true ; 
155    public:     
156      /*!
157        \brief Check if a scalar is completed
158        Before make any scalar processing, we must be sure that all scalar informations have
159        been sent, for exemple when reading a grid in a file or when grid elements are sent by an
160        other context (coupling). So all direct reference of the scalar (scalar_ref) must be also completed
161        \return true if scalar and scalar reference are completed
162      */
163      bool isCompleted(void)
164      {
165        if (hasDirectScalarReference()) if (!getDirectScalarReference()->isCompleted()) return false;
166        else return isCompleted_ ;
167      }
168      void setCompleted(void) { isCompleted_=true ; }
169      void unsetCompleted(void) { isCompleted_=false ; }
170
171
172
173    //////////////////////////////////////////////////////////////////////////////////////
174    //  this part is related to distribution, element definition, views and connectors  //
175    //////////////////////////////////////////////////////////////////////////////////////
176    private:
177      CLocalElement* localElement_ = nullptr ;
178      void initializeLocalElement(void) ;
179       
180    public: 
181      CLocalElement* getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; }
182      CLocalView* getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;}
183       
184    private: 
185      void addFullView(void) ;
186      void addWorkflowView(void) ;
187      void addModelView(void) ;
188       
189    private:
190      CLocalConnector* modelToWorkflowConnector_ ;
191      void computeModelToWorkflowConnector(void)  ;
192    public:
193      CLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;}
194
195    public:
196      void computeRemoteElement(CContextClient* client, EDistributionType) ;
197      void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex, CScattererConnector* &scattererConnector,
198                                 const string& scalarId="") ;
199
200      static void recvScalarDistribution(CEventServer& event) ;
201      void receivedScalarDistribution(CEventServer& event, int phasis) ;
202      void setServerMask(CArray<bool,1>& serverMask, CContextClient* client) ;
203      void sendDistributedAttributes(CContextClient* client, CScattererConnector& scattererConnector, const string& scalarId) ;
204      static void recvDistributedAttributes(CEventServer& event) ;
205      void recvDistributedAttributes(CEventServer& event, const string& type) ;
206
207    private:
208      map<CContextClient*, CDistributedElement*> remoteElement_ ;
209    public: 
210      CDistributedElement* getRemoteElement(CContextClient* client) {return remoteElement_[client] ;}
211    private:
212      map<CContextClient*, CScattererConnector*> clientToServerConnector_ ;
213    public: 
214      CScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;}
215
216    private:
217      CGathererConnector*  gathererConnector_ ;
218    public:
219      CGathererConnector* getGathererConnector(void) { return gathererConnector_ ;}
220    private:
221      CGathererConnector* serverFromClientConnector_ ;
222      CDistributedElement* elementFrom_ ;
223    public:
224      CGathererConnector* getServerFromClientConnector(void) { return serverFromClientConnector_ ;}
225
226    private:
227      CScattererConnector*  serverToClientConnector_ = nullptr ;
228    public: 
229      CScattererConnector* getServerToClientConnector(void) { return serverToClientConnector_ ;} 
230
231    private:
232      map<CContextClient*,CGathererConnector*>  clientFromServerConnector_  ;
233    public: 
234      CGathererConnector* getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;} 
235
236    private:
237      DECLARE_REF_FUNC(Scalar,scalar)
238
239  }; // class CVar
240  ///--------------------------------------------------------------
241
242  // Declare/Define CScalarGroup and CScalarDefinition
243  DECLARE_GROUP(CScalar);
244} // namespace xios
245
246#endif // __XIOS_CScalar__
Note: See TracBrowser for help on using the repository browser.