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

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

Tracking memory leak : release memory statically alocated

YM

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