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

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

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

YM

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 14.6 KB
Line 
1#ifndef __XIOS_CDomain__
2#define __XIOS_CDomain__
3
4/// XIOS headers ///
5#include "xios_spl.hpp"
6#include "group_factory.hpp"
7
8#include "declare_group.hpp"
9#include "declare_ref_func.hpp"
10#include "event_client.hpp"
11#include "event_server.hpp"
12#include "buffer_in.hpp"
13#include "array_new.hpp"
14#include "attribute_array.hpp"
15#include "attribute_enum.hpp"
16#include "transformation.hpp"
17#include "transformation_enum.hpp"
18#include "transformation_path.hpp"
19#include "server_distribution_description.hpp"
20#include "mesh.hpp"
21#include "element.hpp"
22#include "local_connector.hpp"
23#include "scatterer_connector.hpp"
24#include "gatherer_connector.hpp"
25#include "distribution_type.hpp"
26#include "generic_algorithm_transformation.hpp"
27
28
29namespace xios
30{
31
32   /// ////////////////////// Déclarations ////////////////////// ///
33
34   class CDomainGroup;
35   class CDomainAttributes;
36   class CDomain;
37   class CFile;
38   class CField ;
39
40   ///--------------------------------------------------------------
41
42   // Declare/Define CDomainAttribute
43   BEGIN_DECLARE_ATTRIBUTE_MAP(CDomain)
44#  include "domain_attribute.conf"
45#  include "domain_attribute_private.conf"
46   END_DECLARE_ATTRIBUTE_MAP(CDomain)
47
48   ///--------------------------------------------------------------
49
50   class CDomain
51      : public CObjectTemplate<CDomain>
52      , public CDomainAttributes
53   {
54     /// typedef ///
55     typedef CObjectTemplate<CDomain>   SuperClass;
56     typedef CDomainAttributes SuperClassAttribute;
57     public:
58         enum EEventId
59         {
60           EVENT_ID_DOMAIN_DISTRIBUTION, EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE
61         } ;
62
63      public:
64
65         typedef CDomainAttributes RelAttributes;
66         typedef CDomainGroup      RelGroup;
67         
68         /// Constructeurs ///
69         CDomain(void);
70         explicit CDomain(const StdString & id);
71         CDomain(const CDomain & domain);       // Not implemented yet.
72         CDomain(const CDomain * const domain); // Not implemented yet.
73       
74         static CDomain* createDomain();
75         static CDomain* get(const string& id, bool noError=false) ; //<! return domain pointer using id
76         static bool has(const string& id) ; //<! return domain pointer using id
77         static CField*  getFieldFromId(const string& id) ;
78
79         CMesh* mesh;
80         void assignMesh(const StdString, const int);
81       
82         virtual void parse(xml::CXMLNode & node);
83
84         void setContextClient(CContextClient* contextClient);
85
86         /// Vérifications ///
87         void checkAttributes(void);
88         bool checkAttributes_done_ = false ;
89
90         
91      //////////////////////////
92      ///// transformations ////
93      //////////////////////////
94      public:
95        typedef CTransformation<CDomain>::TransformationMapTypes TransMapTypes;
96      private:
97        static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m);
98        static std::map<StdString, ETranformationType> transformationMapList_;
99        static bool dummyTransformationMapList_;
100        TransMapTypes transformationMap_;         
101
102      public:
103        CTransformation<CDomain>* addTransformation(ETranformationType transType, const StdString& id="");
104        CTransformation<CDomain>* addTransformation(ETranformationType transType, CTransformation<CDomain>* transformation) ;
105        void setTransformations(const TransMapTypes&);         
106        void duplicateTransformation(CDomain*);
107        TransMapTypes getAllTransformations();
108        bool hasTransformation();
109        void solveInheritanceTransformation_old(); // to remove later
110        void solveInheritanceTransformation();
111      private:
112        bool solveInheritanceTransformation_done_= false ;
113      public:
114        bool activateFieldWorkflow(CGarbageCollector& gc) ;
115      private:
116        bool activateFieldWorkflow_done_=false ;
117
118      private:
119        shared_ptr<CGenericAlgorithmTransformation> transformationAlgorithm_ = nullptr ;
120      public:
121        void setTransformationAlgorithm(shared_ptr<CGenericAlgorithmTransformation> transformationAlgorithm) { transformationAlgorithm_=transformationAlgorithm ;}
122        shared_ptr<CGenericAlgorithmTransformation> getTransformationAlgorithm(void) { return transformationAlgorithm_ ;}   
123      private:
124        CTransformationPaths transformationPaths_ ;
125      public:
126        CTransformationPaths getTransformationPaths(void) {return transformationPaths_;} 
127        void setTransformationPaths(const CTransformationPaths& transformationPaths) { transformationPaths_=transformationPaths ;}
128
129      ////////////////////////////
130
131         void redistribute(int nbLocalDomain);
132
133      public:
134         const std::set<StdString> & getRelFiles(void) const;
135         bool IsWritten(const StdString & filename) const;
136         bool isWrittenCompressed(const StdString& filename) const;
137         
138         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
139
140         bool isEmpty(void) const;
141         bool isDistributed(void) const;
142
143        public :
144         /*!
145            \brief return if the domain can be written or not in a compressed way.
146            ie if there are some masked or indexed point on the domain. Valid only on server side.
147            \return true if domain can be writtedn in a compressed way
148         */ 
149         bool isCompressible(void) { if (!isCompressibleComputed_) computeIsCompressible() ; return isCompressible_ ;} 
150        private :
151         bool isCompressible_ ; /** specify if the domain can be written in a compressed way */ 
152         bool isCompressibleComputed_=false ; /** Indicate if compressability has been computed*/
153         void computeIsCompressible() ;
154
155      public :
156         bool isEqual(CDomain* domain);
157
158         static bool dispatchEvent(CEventServer& event);
159     
160      private:
161         /** define if the domain is completed or not ie all attributes have been received before in case
162             of grid reading from file or coupling */ 
163         bool isCompleted_=true ; 
164      public:     
165        /*!
166           \brief Check if a domain is completed
167           Before make any domain processing, we must be sure that all domain informations have
168           been sent, for exemple when reading a grid in a file or when grid elements are sent by an
169           other context (coupling). So all direct reference of the domain (domain_ref) must be also completed
170           \return true if domain and domain reference are completed
171          */
172         bool isCompleted(void)
173         {
174           if (hasDirectDomainReference()) if (!getDirectDomainReference()->isCompleted()) return false;
175           else return isCompleted_ ;
176         }
177         void setCompleted(void) { isCompleted_=true ; }
178         void unsetCompleted(void) { isCompleted_=false ; }
179
180      public:
181         /// Mutateur ///
182         void addRelFile(const StdString & filename);
183         void addRelFileCompressed(const StdString& filename);           
184         
185         void AllgatherRectilinearLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
186                                         CArray<double,1>& lon_g, CArray<double,1>& lat_g);
187
188         void fillInRectilinearBoundLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
189                                           CArray<double,2>& boundsLon, CArray<double,2>& boundsLat);
190         
191         void fillInLonLat();
192         bool distributionAttributesHaveValue() const;
193
194         size_t getGlobalWrittenSize() ;
195         /// Destructeur ///
196         virtual ~CDomain(void);
197
198         /// Accesseurs statiques ///
199         static StdString GetName(void);
200         static StdString GetDefName(void);
201
202         static ENodeType GetType(void);       
203
204      public:
205         CArray<double, 1> lonvalue, latvalue;
206         CArray<double, 2> bounds_lonvalue, bounds_latvalue;
207         CArray<double, 1> areavalue;
208
209
210         CArray<bool, 1> domainMask; // mask_1d, mask_2d -> domainMask
211         CArray<bool, 1> localMask; // domainMask + indexing
212         bool isCurvilinear ;
213         bool hasBounds ;
214         bool hasArea;
215         bool hasLonLat;
216         bool hasPole ;
217         bool hasLatInReadFile_ ; // specify if latitude is defined on read file, so it can be read later when grid distribution will be defined
218         bool hasBoundsLatInReadFile_ ; // specify if latitude boundarues are defined on read file, so it can be read later when grid distribution will be defined
219         bool hasLonInReadFile_ ; // specify if longitude is defined on read file, so it can be read later when grid distribution will be defined
220         bool hasBoundsLonInReadFile_ ; // specify if longitude boundaries are defined on read file, so it can be read later when grid distribution will be defined
221
222         void computeLocalMask(void) ;
223     
224         /** The number of server of a context client. Avoid to re-compute indice computed in a previous computeConnectedClient */
225         private: std::set<int> listNbServer_ ;
226         
227      private:
228         void checkDomain(void);
229         void checkLocalIDomain(void);
230         void checkLocalJDomain(void);
231
232         void checkMask(void);
233         void checkDomainData(void);
234         void checkCompression(void);
235
236         void checkBounds(void);
237         void checkArea(void);
238         void checkLonLat();
239         
240       public:
241         void sendDomainToFileServer(CContextClient* client) ;
242       private:
243         std::set<CContextClient*> sendDomainToFileServer_done_ ;
244       public:
245         void sendDomainToCouplerOut(CContextClient* client, const string& fieldId, int posInGrid) ;
246       private:
247         std::set<CContextClient*> sendDomainToCouplerOut_done_ ;
248     
249       public:
250        void makeAliasForCoupling(const string& fieldId, int posInGrid) ;
251        string getCouplingAlias(const string& fieldId, int posInGrid) ;
252       private:
253
254         void convertLonLatValue();
255         void fillInRectilinearLonLat();
256         void fillInCurvilinearLonLat();
257         void fillInUnstructuredLonLat();
258         void completeLonLatClient(void); 
259         
260         
261       private:         
262
263/** Clients that have to send a domain. There can be multiple clients in case of secondary server, otherwise only one client. */
264         std::list<CContextClient*> clients;
265         std::set<CContextClient*> clientsSet;
266
267         bool isChecked ;
268         std::set<StdString> relFiles, relFilesCompressed;
269
270/** only on client side : Global index of each client sent to server: map<serverSize, map<serverRank, indexes>>
271    indSrv_[nbServers] -->  first map is related to the server distribution (ie associated with the contextClient)
272    indSrv_[nbServers][server_rank] -> array of global index sent to the server of rank "server_rank"
273    indSrv_[nbServers][server_rank](ind) --> global index on server of the local element "ind" sent (for lon, lat, mask, etc...)
274*/
275         std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_;
276
277         std::map<int, std::vector<int> > connectedServerRank_;
278
279         bool isRedistributed_;
280         bool isUnstructed_;
281
282       
283       //////////////////////////////////////////////////////////////////////////////////////
284       //  this part is related to distribution, element definition, views and connectors  //
285       //////////////////////////////////////////////////////////////////////////////////////
286       private:
287         shared_ptr<CLocalElement> localElement_ = nullptr ;
288         void initializeLocalElement(void) ;
289       
290       public: 
291         shared_ptr<CLocalElement> getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; }
292         shared_ptr<CLocalView> getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;}
293       
294       private: 
295         void addFullView(void) ;
296         void addWorkflowView(void) ;
297         void addModelView(void) ;
298       
299       private:
300         shared_ptr<CLocalConnector> modelToWorkflowConnector_ ;
301         void computeModelToWorkflowConnector(void)  ;
302       public:
303         shared_ptr<CLocalConnector> getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;}
304
305       public:
306         void computeRemoteElement(CContextClient* client, EDistributionType) ;
307         void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex, shared_ptr<CScattererConnector> &scattererConnector,
308                                 const string& domainId="") ;
309
310         static void recvDomainDistribution(CEventServer& event) ;
311         void receivedDomainDistribution(CEventServer& event, int phasis) ;
312
313         void sendDistributedAttributes(CContextClient* client, shared_ptr<CScattererConnector> scaterrerConnector, const string& domainId) ;
314         static void recvDistributedAttributes(CEventServer& event) ;
315         void recvDistributedAttributes(CEventServer& event, const string& type) ;
316         void setServerMask(CArray<bool,1>& serverMask, CContextClient* client) ;
317
318       private:
319         map<CContextClient*, shared_ptr<CDistributedElement>> remoteElement_ ;
320       public: 
321         shared_ptr<CDistributedElement> getRemoteElement(CContextClient* client) {return remoteElement_[client] ;}
322       private:
323         map<CContextClient*, shared_ptr<CScattererConnector>> clientToServerConnector_ ;
324       public: 
325         shared_ptr<CScattererConnector> getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;}
326       
327       private:
328         shared_ptr<CGathererConnector>  gathererConnector_ ;
329       public:
330         shared_ptr<CGathererConnector> getGathererConnector(void) { return gathererConnector_ ;}
331        private:
332         shared_ptr<CGathererConnector> serverFromClientConnector_ ;
333         shared_ptr<CDistributedElement> elementFrom_ ;
334       public:
335         shared_ptr<CGathererConnector> getServerFromClientConnector(void) { return serverFromClientConnector_ ;}
336
337       private:
338         shared_ptr<CScattererConnector>  serverToClientConnector_ = nullptr ;
339       public: 
340         shared_ptr<CScattererConnector> getServerToClientConnector(void) { return serverToClientConnector_ ;} 
341
342       private:
343         map<CContextClient*,shared_ptr<CGathererConnector>>  clientFromServerConnector_  ;
344       public: 
345         shared_ptr<CGathererConnector> getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;}       
346         
347
348         DECLARE_REF_FUNC(Domain,domain)
349
350   }; // class CDomain
351
352   ///--------------------------------------------------------------
353
354   // Declare/Define CDomainGroup and CDomainDefinition
355   DECLARE_GROUP(CDomain);
356
357   ///--------------------------------------------------------------
358
359} // namespace xios
360
361#endif //__XIOS_CDomain__
Note: See TracBrowser for help on using the repository browser.