source: XIOS3/trunk/src/node/scalar.hpp @ 2507

Last change on this file since 2507 was 2507, checked in by ymipsl, 13 months ago

Merging XIOS3_ATTACHED branch into XIOS3 trunk.

YM

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