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

Last change on this file since 2304 was 2304, checked in by ymipsl, 2 years ago

Fix problem in remote connector for read variable : supress redondance optimisation on remote connector in read case.
YM

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