source: XIOS3/branches/xios-3.0-beta/src/node/scalar.hpp @ 2423

Last change on this file since 2423 was 2397, checked in by ymipsl, 22 months ago
  • Optimize remote connector computation in case of read (reverse way).
  • don't compute anymore clientFromServerConnector (and all intermediate computation) for non reading case.

YM

File size: 9.9 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    private: 
146          /** Clients that have to send a scalar. There can be multiple clients in case of secondary server, otherwise only one client. */
147      std::list<CContextClient*> clients;
148      std::set<CContextClient*> clientsSet;
149    public:
150      void setContextClient(CContextClient* contextClient) ;
151       
152    private:
153      std::set<StdString> relFiles;
154
155    private:
156      /** define if the scalar is completed or not ie all attributes have been received before in case
157           of grid reading from file or coupling */ 
158      bool isCompleted_=true ; 
159    public:     
160      /*!
161        \brief Check if a scalar is completed
162        Before make any scalar processing, we must be sure that all scalar informations have
163        been sent, for exemple when reading a grid in a file or when grid elements are sent by an
164        other context (coupling). So all direct reference of the scalar (scalar_ref) must be also completed
165        \return true if scalar and scalar reference are completed
166      */
167      bool isCompleted(void)
168      {
169        if (hasDirectScalarReference()) if (!getDirectScalarReference()->isCompleted()) return false;
170        else return isCompleted_ ;
171
172        MISSING_RETURN( "bool CAxis::isCompleted() " );
173        return true;
174      }
175      void setCompleted(void) { isCompleted_=true ; }
176      void unsetCompleted(void) { isCompleted_=false ; }
177
178
179
180    //////////////////////////////////////////////////////////////////////////////////////
181    //  this part is related to distribution, element definition, views and connectors  //
182    //////////////////////////////////////////////////////////////////////////////////////
183    private:
184      shared_ptr<CLocalElement> localElement_ = nullptr ;
185      void initializeLocalElement(void) ;
186       
187    public: 
188      shared_ptr<CLocalElement> getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; }
189      shared_ptr<CLocalView> getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;}
190       
191    private: 
192      void addFullView(void) ;
193      void addWorkflowView(void) ;
194      void addModelView(void) ;
195       
196    private:
197      shared_ptr<CLocalConnector> modelToWorkflowConnector_ ;
198      void computeModelToWorkflowConnector(void)  ;
199    public:
200      shared_ptr<CLocalConnector> getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;}
201
202    public:
203      void computeRemoteElement(CContextClient* client, EDistributionType) ;
204      void distributeToServer(CContextClient* client, bool inOut, std::map<int, CArray<size_t,1>>& globalIndexOut, std::map<int, CArray<size_t,1>>& globalIndexIn,
205                              shared_ptr<CScattererConnector> &scattererConnector, const string& scalarId="") ;
206
207      static void recvScalarDistribution(CEventServer& event) ;
208      void receivedScalarDistribution(CEventServer& event, int phasis) ;
209      void setServerMask(CArray<bool,1>& serverMask, CContextClient* client) ;
210      void sendDistributedAttributes(CContextClient* client, shared_ptr<CScattererConnector> scattererConnector, const string& scalarId) ;
211      static void recvDistributedAttributes(CEventServer& event) ;
212      void recvDistributedAttributes(CEventServer& event, const string& type) ;
213
214    private:
215      map<CContextClient*, shared_ptr<CDistributedElement>> remoteElement_ ;
216    public: 
217      shared_ptr<CDistributedElement> getRemoteElement(CContextClient* client) {return remoteElement_[client] ;}
218    private:
219      map<CContextClient*, shared_ptr<CScattererConnector>> clientToServerConnector_ ;
220    public: 
221      shared_ptr<CScattererConnector> getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;}
222
223    private:
224      shared_ptr<CGathererConnector>  gathererConnector_ ;
225    public:
226      shared_ptr<CGathererConnector> getGathererConnector(void) { return gathererConnector_ ;}
227    private:
228      shared_ptr<CGathererConnector> serverFromClientConnector_ ;
229      shared_ptr<CDistributedElement> elementFrom_ ;
230    public:
231      shared_ptr<CGathererConnector> getServerFromClientConnector(void) { return serverFromClientConnector_ ;}
232
233    private:
234     shared_ptr<CScattererConnector>  serverToClientConnector_ = nullptr ;
235     shared_ptr<CDistributedElement> elementTo_ ;
236    public: 
237      shared_ptr<CScattererConnector> getServerToClientConnector(void) { return serverToClientConnector_ ;} 
238
239    private:
240      map<CContextClient*,shared_ptr<CGathererConnector>>  clientFromServerConnector_  ;
241    public: 
242      shared_ptr<CGathererConnector> getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;} 
243
244    private:
245      DECLARE_REF_FUNC(Scalar,scalar)
246
247  }; // class CVar
248  ///--------------------------------------------------------------
249
250  // Declare/Define CScalarGroup and CScalarDefinition
251  DECLARE_GROUP(CScalar);
252} // namespace xios
253
254#endif // __XIOS_CScalar__
Note: See TracBrowser for help on using the repository browser.