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
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      {
[2326]54        EVENT_ID_COLLECTIVE=100,
[1984]55        EVENT_ID_SCALAR_DISTRIBUTION,
56        EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE,
[2326]57        EVENT_ID_NO_COLLECTIVE=1000,
[1984]58      } ;
59      static bool dispatchEvent(CEventServer& event);     
[1940]60           
[887]61
[1984]62    public :
[887]63
[1984]64      typedef CScalarAttributes RelAttributes;
65      typedef CScalarGroup      RelGroup;
[887]66
[1984]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.
[2274]72      static void releaseStaticAllocation(void) ; // release static allocation on heap
73     
[1984]74      /// Destructeur ///
75      virtual ~CScalar(void);
[887]76
[1984]77    public :
78      /// Accesseurs statiques ///
79      static StdString GetName(void);
80      static StdString GetDefName(void);
81      static ENodeType GetType(void);
[887]82
[1984]83    public:
84      static CScalar* createScalar();
[2206]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) ;
[887]88
[1984]89    public:
90      void checkAttributes(void);
91      bool checkAttributes_done_ = false ;
[1869]92           
[1984]93      void addRelFile(const StdString& filename);
94      bool IsWritten(const StdString& filename) const;
95      virtual void parse(xml::CXMLNode & node);
[1875]96       
[1984]97    public:
98      void sendScalarToCouplerOut(CContextClient* client, const string& fieldId, int posInGrid) ;
99    private:
100      std::set<CContextClient*> sendScalarToCouplerOut_done_ ;
[1875]101         
[1984]102    public:
103      void makeAliasForCoupling(const string& fieldId, int posInGrid) ;
[2022]104      string getCouplingAlias(const string& fieldId, int posInGrid) ;
[1875]105
[1984]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 ;
[2206]127      public:
128        bool activateFieldWorkflow(CGarbageCollector& gc) ;
[1984]129      private:
[2206]130        bool activateFieldWorkflow_done_=false ;
131      private:
[2270]132        shared_ptr<CGenericAlgorithmTransformation> transformationAlgorithm_ = nullptr ;
[1984]133      public:
[2270]134        void setTransformationAlgorithm(shared_ptr<CGenericAlgorithmTransformation> transformationAlgorithm) { transformationAlgorithm_=transformationAlgorithm ;}
135        shared_ptr<CGenericAlgorithmTransformation> getTransformationAlgorithm(void) { return transformationAlgorithm_ ;}   
[1984]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);
[2507]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 ;
[1984]154    private: 
[1875]155          /** Clients that have to send a scalar. There can be multiple clients in case of secondary server, otherwise only one client. */
[1984]156      std::list<CContextClient*> clients;
157      std::set<CContextClient*> clientsSet;
158    public:
159      void setContextClient(CContextClient* contextClient) ;
[1875]160       
[1984]161    private:
162      std::set<StdString> relFiles;
[887]163
[1984]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_ ;
[2282]180
181        MISSING_RETURN( "bool CAxis::isCompleted() " );
182        return true;
[1984]183      }
184      void setCompleted(void) { isCompleted_=true ; }
185      void unsetCompleted(void) { isCompleted_=false ; }
[888]186
187
188
[1984]189    //////////////////////////////////////////////////////////////////////////////////////
190    //  this part is related to distribution, element definition, views and connectors  //
191    //////////////////////////////////////////////////////////////////////////////////////
192    private:
[2267]193      shared_ptr<CLocalElement> localElement_ = nullptr ;
[1984]194      void initializeLocalElement(void) ;
[1930]195       
[1984]196    public: 
[2267]197      shared_ptr<CLocalElement> getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; }
198      shared_ptr<CLocalView> getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;}
[1930]199       
[1984]200    private: 
201      void addFullView(void) ;
202      void addWorkflowView(void) ;
203      void addModelView(void) ;
[1930]204       
[1984]205    private:
[2267]206      shared_ptr<CLocalConnector> modelToWorkflowConnector_ ;
[1984]207      void computeModelToWorkflowConnector(void)  ;
208    public:
[2267]209      shared_ptr<CLocalConnector> getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;}
[1930]210
[1984]211    public:
212      void computeRemoteElement(CContextClient* client, EDistributionType) ;
[2397]213      void distributeToServer(CContextClient* client, bool inOut, std::map<int, CArray<size_t,1>>& globalIndexOut, std::map<int, CArray<size_t,1>>& globalIndexIn,
[2304]214                              shared_ptr<CScattererConnector> &scattererConnector, const string& scalarId="") ;
[1958]215
[1984]216      static void recvScalarDistribution(CEventServer& event) ;
217      void receivedScalarDistribution(CEventServer& event, int phasis) ;
218      void setServerMask(CArray<bool,1>& serverMask, CContextClient* client) ;
[2267]219      void sendDistributedAttributes(CContextClient* client, shared_ptr<CScattererConnector> scattererConnector, const string& scalarId) ;
[1984]220      static void recvDistributedAttributes(CEventServer& event) ;
221      void recvDistributedAttributes(CEventServer& event, const string& type) ;
[1940]222
[1984]223    private:
[2267]224      map<CContextClient*, shared_ptr<CDistributedElement>> remoteElement_ ;
[1984]225    public: 
[2267]226      shared_ptr<CDistributedElement> getRemoteElement(CContextClient* client) {return remoteElement_[client] ;}
[1984]227    private:
[2267]228      map<CContextClient*, shared_ptr<CScattererConnector>> clientToServerConnector_ ;
[1984]229    public: 
[2267]230      shared_ptr<CScattererConnector> getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;}
[1930]231
[1984]232    private:
[2267]233      shared_ptr<CGathererConnector>  gathererConnector_ ;
[1984]234    public:
[2267]235      shared_ptr<CGathererConnector> getGathererConnector(void) { return gathererConnector_ ;}
[1984]236    private:
[2267]237      shared_ptr<CGathererConnector> serverFromClientConnector_ ;
238      shared_ptr<CDistributedElement> elementFrom_ ;
[1984]239    public:
[2267]240      shared_ptr<CGathererConnector> getServerFromClientConnector(void) { return serverFromClientConnector_ ;}
[1930]241
[1984]242    private:
[2267]243     shared_ptr<CScattererConnector>  serverToClientConnector_ = nullptr ;
[2304]244     shared_ptr<CDistributedElement> elementTo_ ;
[1984]245    public: 
[2267]246      shared_ptr<CScattererConnector> getServerToClientConnector(void) { return serverToClientConnector_ ;} 
[1930]247
[1984]248    private:
[2267]249      map<CContextClient*,shared_ptr<CGathererConnector>>  clientFromServerConnector_  ;
[1984]250    public: 
[2267]251      shared_ptr<CGathererConnector> getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;} 
[1930]252
[1984]253    private:
254      DECLARE_REF_FUNC(Scalar,scalar)
[887]255
[1984]256  }; // class CVar
257  ///--------------------------------------------------------------
[887]258
[1984]259  // Declare/Define CScalarGroup and CScalarDefinition
260  DECLARE_GROUP(CScalar);
[887]261} // namespace xios
262
263#endif // __XIOS_CScalar__
Note: See TracBrowser for help on using the repository browser.