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

Last change on this file since 2204 was 2203, checked in by ymipsl, 3 years ago

New functionnality : domain, axis and scalar can now be retrieve with new syntax id :
ex. for domain :

id="domainId" : old syntax, working as before
id="fieldId::domainId" : get the domain related to "domainId" associated to the field "fieldId", work if only 1 domain related to domainId is associated to the field.
id="fieldId::domainId[n]" : get the nth domain related to "domainId" associated to the field "fieldId"
id="fieldId::" : get the domain associated the the field "fieldId, work if grid associated to th field is composed with exactly 1 domain (and possibly other components axis or scalars)
id="fieldId::[n] : get the nth domain composing the grid associated to the field

YM

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