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

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

Tracking memory leak :
Tranformations and algorithms are now managed with shared_ptr.

YM

File size: 9.5 KB
RevLine 
[887]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"
[1436]12#include "attribute_array.hpp"
[887]13#include "transformation.hpp"
14#include "transformation_enum.hpp"
[1984]15#include "transformation_path.hpp"
[1930]16#include "element.hpp"
17#include "local_connector.hpp"
18#include "scatterer_connector.hpp"
19#include "gatherer_connector.hpp"
20#include "distribution_type.hpp"
[1984]21#include "generic_algorithm_transformation.hpp"
[1930]22
23
[887]24namespace xios
25{
[1984]26  /// ////////////////////// Déclarations ////////////////////// ///
[887]27
[1984]28  class CScalarGroup;
29  class CScalarAttributes;
30  class CScalar;
[2206]31  class CField;
[1984]32  ///--------------------------------------------------------------
[887]33
[1984]34  // Declare/Define CVarAttribute
35  BEGIN_DECLARE_ATTRIBUTE_MAP(CScalar)
[887]36#include "scalar_attribute.conf"
[1984]37  END_DECLARE_ATTRIBUTE_MAP(CScalar)
[887]38
[1984]39  ///--------------------------------------------------------------
[887]40
[1984]41  class CScalar: public CObjectTemplate<CScalar>
42               , public CScalarAttributes
43  {
44      friend class CScalarGroup;
[1940]45
[1984]46      /// typedef ///
47      typedef CObjectTemplate<CScalar>   SuperClass;
48      typedef CScalarAttributes SuperClassAttribute;
[887]49
[1984]50    public:
51      enum EEventId
52      {
53        EVENT_ID_SCALAR_DISTRIBUTION,
54        EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE,
55      } ;
56      static bool dispatchEvent(CEventServer& event);     
[1940]57           
[887]58
[1984]59    public :
[887]60
[1984]61      typedef CScalarAttributes RelAttributes;
62      typedef CScalarGroup      RelGroup;
[887]63
[1984]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.
[887]69
[1984]70      /// Destructeur ///
71      virtual ~CScalar(void);
[887]72
[1984]73    public :
74      /// Accesseurs statiques ///
75      static StdString GetName(void);
76      static StdString GetDefName(void);
77      static ENodeType GetType(void);
[887]78
[1984]79    public:
80      static CScalar* createScalar();
[2206]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) ;
[887]84
[1984]85    public:
86      void checkAttributes(void);
87      bool checkAttributes_done_ = false ;
[1869]88           
[1984]89      void addRelFile(const StdString& filename);
90      bool IsWritten(const StdString& filename) const;
91      virtual void parse(xml::CXMLNode & node);
[1875]92       
[1984]93    public:
94      void sendScalarToCouplerOut(CContextClient* client, const string& fieldId, int posInGrid) ;
95    private:
96      std::set<CContextClient*> sendScalarToCouplerOut_done_ ;
[1875]97         
[1984]98    public:
99      void makeAliasForCoupling(const string& fieldId, int posInGrid) ;
[2022]100      string getCouplingAlias(const string& fieldId, int posInGrid) ;
[1875]101
[1984]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 ;
[2206]123      public:
124        bool activateFieldWorkflow(CGarbageCollector& gc) ;
[1984]125      private:
[2206]126        bool activateFieldWorkflow_done_=false ;
127      private:
[2270]128        shared_ptr<CGenericAlgorithmTransformation> transformationAlgorithm_ = nullptr ;
[1984]129      public:
[2270]130        void setTransformationAlgorithm(shared_ptr<CGenericAlgorithmTransformation> transformationAlgorithm) { transformationAlgorithm_=transformationAlgorithm ;}
131        shared_ptr<CGenericAlgorithmTransformation> getTransformationAlgorithm(void) { return transformationAlgorithm_ ;}   
[1984]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: 
[1875]142          /** Clients that have to send a scalar. There can be multiple clients in case of secondary server, otherwise only one client. */
[1984]143      std::list<CContextClient*> clients;
144      std::set<CContextClient*> clientsSet;
145    public:
146      void setContextClient(CContextClient* contextClient) ;
[1875]147       
[1984]148    private:
149      std::set<StdString> relFiles;
[887]150
[1984]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 ; }
[888]170
171
172
[1984]173    //////////////////////////////////////////////////////////////////////////////////////
174    //  this part is related to distribution, element definition, views and connectors  //
175    //////////////////////////////////////////////////////////////////////////////////////
176    private:
[2267]177      shared_ptr<CLocalElement> localElement_ = nullptr ;
[1984]178      void initializeLocalElement(void) ;
[1930]179       
[1984]180    public: 
[2267]181      shared_ptr<CLocalElement> getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; }
182      shared_ptr<CLocalView> getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;}
[1930]183       
[1984]184    private: 
185      void addFullView(void) ;
186      void addWorkflowView(void) ;
187      void addModelView(void) ;
[1930]188       
[1984]189    private:
[2267]190      shared_ptr<CLocalConnector> modelToWorkflowConnector_ ;
[1984]191      void computeModelToWorkflowConnector(void)  ;
192    public:
[2267]193      shared_ptr<CLocalConnector> getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;}
[1930]194
[1984]195    public:
196      void computeRemoteElement(CContextClient* client, EDistributionType) ;
[2267]197      void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex, shared_ptr<CScattererConnector> &scattererConnector,
[1958]198                                 const string& scalarId="") ;
199
[1984]200      static void recvScalarDistribution(CEventServer& event) ;
201      void receivedScalarDistribution(CEventServer& event, int phasis) ;
202      void setServerMask(CArray<bool,1>& serverMask, CContextClient* client) ;
[2267]203      void sendDistributedAttributes(CContextClient* client, shared_ptr<CScattererConnector> scattererConnector, const string& scalarId) ;
[1984]204      static void recvDistributedAttributes(CEventServer& event) ;
205      void recvDistributedAttributes(CEventServer& event, const string& type) ;
[1940]206
[1984]207    private:
[2267]208      map<CContextClient*, shared_ptr<CDistributedElement>> remoteElement_ ;
[1984]209    public: 
[2267]210      shared_ptr<CDistributedElement> getRemoteElement(CContextClient* client) {return remoteElement_[client] ;}
[1984]211    private:
[2267]212      map<CContextClient*, shared_ptr<CScattererConnector>> clientToServerConnector_ ;
[1984]213    public: 
[2267]214      shared_ptr<CScattererConnector> getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;}
[1930]215
[1984]216    private:
[2267]217      shared_ptr<CGathererConnector>  gathererConnector_ ;
[1984]218    public:
[2267]219      shared_ptr<CGathererConnector> getGathererConnector(void) { return gathererConnector_ ;}
[1984]220    private:
[2267]221      shared_ptr<CGathererConnector> serverFromClientConnector_ ;
222      shared_ptr<CDistributedElement> elementFrom_ ;
[1984]223    public:
[2267]224      shared_ptr<CGathererConnector> getServerFromClientConnector(void) { return serverFromClientConnector_ ;}
[1930]225
[1984]226    private:
[2267]227     shared_ptr<CScattererConnector>  serverToClientConnector_ = nullptr ;
[1984]228    public: 
[2267]229      shared_ptr<CScattererConnector> getServerToClientConnector(void) { return serverToClientConnector_ ;} 
[1930]230
[1984]231    private:
[2267]232      map<CContextClient*,shared_ptr<CGathererConnector>>  clientFromServerConnector_  ;
[1984]233    public: 
[2267]234      shared_ptr<CGathererConnector> getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;} 
[1930]235
[1984]236    private:
237      DECLARE_REF_FUNC(Scalar,scalar)
[887]238
[1984]239  }; // class CVar
240  ///--------------------------------------------------------------
[887]241
[1984]242  // Declare/Define CScalarGroup and CScalarDefinition
243  DECLARE_GROUP(CScalar);
[887]244} // namespace xios
245
246#endif // __XIOS_CScalar__
Note: See TracBrowser for help on using the repository browser.