source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/domain.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

  • 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.7 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         static void releaseStaticAllocation(void) ; // release static allocation on heap
74
75         static CDomain* createDomain();
76         static CDomain* get(const string& id, bool noError=false) ; //<! return domain pointer using id
77         static bool has(const string& id) ; //<! return domain pointer using id
78         static CField*  getFieldFromId(const string& id) ;
79
80         CMesh* mesh;
81         void assignMesh(const StdString, const int);
82       
83         virtual void parse(xml::CXMLNode & node);
84
85         void setContextClient(CContextClient* contextClient);
86
87         /// Vérifications ///
88         void checkAttributes(void);
89         bool checkAttributes_done_ = false ;
90
91         
92      //////////////////////////
93      ///// transformations ////
94      //////////////////////////
95      public:
96        typedef CTransformation<CDomain>::TransformationMapTypes TransMapTypes;
97      private:
98        static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m);
99        static std::map<StdString, ETranformationType> transformationMapList_;
100        static bool dummyTransformationMapList_;
101        TransMapTypes transformationMap_;         
102
103      public:
104        CTransformation<CDomain>* addTransformation(ETranformationType transType, const StdString& id="");
105        CTransformation<CDomain>* addTransformation(ETranformationType transType, CTransformation<CDomain>* transformation) ;
106        void setTransformations(const TransMapTypes&);         
107        void duplicateTransformation(CDomain*);
108        TransMapTypes getAllTransformations();
109        bool hasTransformation();
110        void solveInheritanceTransformation_old(); // to remove later
111        void solveInheritanceTransformation();
112      private:
113        bool solveInheritanceTransformation_done_= false ;
114      public:
115        bool activateFieldWorkflow(CGarbageCollector& gc) ;
116      private:
117        bool activateFieldWorkflow_done_=false ;
118
119      private:
120        shared_ptr<CGenericAlgorithmTransformation> transformationAlgorithm_ = nullptr ;
121      public:
122        void setTransformationAlgorithm(shared_ptr<CGenericAlgorithmTransformation> transformationAlgorithm) { transformationAlgorithm_=transformationAlgorithm ;}
123        shared_ptr<CGenericAlgorithmTransformation> getTransformationAlgorithm(void) { return transformationAlgorithm_ ;}   
124      private:
125        CTransformationPaths transformationPaths_ ;
126      public:
127        CTransformationPaths getTransformationPaths(void) {return transformationPaths_;} 
128        void setTransformationPaths(const CTransformationPaths& transformationPaths) { transformationPaths_=transformationPaths ;}
129
130      ////////////////////////////
131
132         void redistribute(int nbLocalDomain);
133
134      public:
135         const std::set<StdString> & getRelFiles(void) const;
136         bool IsWritten(const StdString & filename) const;
137         bool isWrittenCompressed(const StdString& filename) const;
138         
139         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
140
141         bool isEmpty(void) const;
142         bool isDistributed(void) const;
143
144        public :
145         /*!
146            \brief return if the domain can be written or not in a compressed way.
147            ie if there are some masked or indexed point on the domain. Valid only on server side.
148            \return true if domain can be writtedn in a compressed way
149         */ 
150         bool isCompressible(void) { if (!isCompressibleComputed_) computeIsCompressible() ; return isCompressible_ ;} 
151        private :
152         bool isCompressible_ ; /** specify if the domain can be written in a compressed way */ 
153         bool isCompressibleComputed_=false ; /** Indicate if compressability has been computed*/
154         void computeIsCompressible() ;
155
156      public :
157         bool isEqual(CDomain* domain);
158
159         static bool dispatchEvent(CEventServer& event);
160     
161      private:
162         /** define if the domain is completed or not ie all attributes have been received before in case
163             of grid reading from file or coupling */ 
164         bool isCompleted_=true ; 
165      public:     
166        /*!
167           \brief Check if a domain is completed
168           Before make any domain processing, we must be sure that all domain informations have
169           been sent, for exemple when reading a grid in a file or when grid elements are sent by an
170           other context (coupling). So all direct reference of the domain (domain_ref) must be also completed
171           \return true if domain and domain reference are completed
172          */
173         bool isCompleted(void)
174         {
175           if (hasDirectDomainReference()) if (!getDirectDomainReference()->isCompleted()) return false;
176           else return isCompleted_ ;
177         }
178         void setCompleted(void) { isCompleted_=true ; }
179         void unsetCompleted(void) { isCompleted_=false ; }
180
181      public:
182         /// Mutateur ///
183         void addRelFile(const StdString & filename);
184         void addRelFileCompressed(const StdString& filename);           
185         
186         void AllgatherRectilinearLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
187                                         CArray<double,1>& lon_g, CArray<double,1>& lat_g);
188
189         void fillInRectilinearBoundLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
190                                           CArray<double,2>& boundsLon, CArray<double,2>& boundsLat);
191         
192         void fillInLonLat();
193         bool distributionAttributesHaveValue() const;
194
195         size_t getGlobalWrittenSize() ;
196         /// Destructeur ///
197         virtual ~CDomain(void);
198
199         /// Accesseurs statiques ///
200         static StdString GetName(void);
201         static StdString GetDefName(void);
202
203         static ENodeType GetType(void);       
204
205      public:
206         CArray<double, 1> lonvalue, latvalue;
207         CArray<double, 2> bounds_lonvalue, bounds_latvalue;
208         CArray<double, 1> areavalue;
209
210
211         CArray<bool, 1> domainMask; // mask_1d, mask_2d -> domainMask
212         CArray<bool, 1> localMask; // domainMask + indexing
213         bool isCurvilinear ;
214         bool hasBounds ;
215         bool hasArea;
216         bool hasLonLat;
217         bool hasPole ;
218         bool hasLatInReadFile_ ; // specify if latitude is defined on read file, so it can be read later when grid distribution will be defined
219         bool hasBoundsLatInReadFile_ ; // specify if latitude boundarues are defined on read file, so it can be read later when grid distribution will be defined
220         bool hasLonInReadFile_ ; // specify if longitude is defined on read file, so it can be read later when grid distribution will be defined
221         bool hasBoundsLonInReadFile_ ; // specify if longitude boundaries are defined on read file, so it can be read later when grid distribution will be defined
222
223         void computeLocalMask(void) ;
224     
225         /** The number of server of a context client. Avoid to re-compute indice computed in a previous computeConnectedClient */
226         private: std::set<int> listNbServer_ ;
227         
228      private:
229         void checkDomain(void);
230         void checkLocalIDomain(void);
231         void checkLocalJDomain(void);
232
233         void checkMask(void);
234         void checkDomainData(void);
235         void checkCompression(void);
236
237         void checkBounds(void);
238         void checkArea(void);
239         void checkLonLat();
240         
241       public:
242         void sendDomainToFileServer(CContextClient* client) ;
243       private:
244         std::set<CContextClient*> sendDomainToFileServer_done_ ;
245       public:
246         void sendDomainToCouplerOut(CContextClient* client, const string& fieldId, int posInGrid) ;
247       private:
248         std::set<CContextClient*> sendDomainToCouplerOut_done_ ;
249     
250       public:
251        void makeAliasForCoupling(const string& fieldId, int posInGrid) ;
252        string getCouplingAlias(const string& fieldId, int posInGrid) ;
253       private:
254
255         void convertLonLatValue();
256         void fillInRectilinearLonLat();
257         void fillInCurvilinearLonLat();
258         void fillInUnstructuredLonLat();
259         void completeLonLatClient(void); 
260         
261         
262       private:         
263
264/** Clients that have to send a domain. There can be multiple clients in case of secondary server, otherwise only one client. */
265         std::list<CContextClient*> clients;
266         std::set<CContextClient*> clientsSet;
267
268         bool isChecked ;
269         std::set<StdString> relFiles, relFilesCompressed;
270
271/** only on client side : Global index of each client sent to server: map<serverSize, map<serverRank, indexes>>
272    indSrv_[nbServers] -->  first map is related to the server distribution (ie associated with the contextClient)
273    indSrv_[nbServers][server_rank] -> array of global index sent to the server of rank "server_rank"
274    indSrv_[nbServers][server_rank](ind) --> global index on server of the local element "ind" sent (for lon, lat, mask, etc...)
275*/
276         std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_;
277
278         std::map<int, std::vector<int> > connectedServerRank_;
279
280         bool isRedistributed_;
281         bool isUnstructed_;
282
283       
284       //////////////////////////////////////////////////////////////////////////////////////
285       //  this part is related to distribution, element definition, views and connectors  //
286       //////////////////////////////////////////////////////////////////////////////////////
287       private:
288         shared_ptr<CLocalElement> localElement_ = nullptr ;
289         void initializeLocalElement(void) ;
290       
291       public: 
292         shared_ptr<CLocalElement> getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; }
293         shared_ptr<CLocalView> getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;}
294       
295       private: 
296         void addFullView(void) ;
297         void addWorkflowView(void) ;
298         void addModelView(void) ;
299       
300       private:
301         shared_ptr<CLocalConnector> modelToWorkflowConnector_ ;
302         void computeModelToWorkflowConnector(void)  ;
303       public:
304         shared_ptr<CLocalConnector> getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;}
305
306       public:
307         void computeRemoteElement(CContextClient* client, EDistributionType) ;
308         void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex, shared_ptr<CScattererConnector> &scattererConnector,
309                                 const string& domainId="") ;
310
311         static void recvDomainDistribution(CEventServer& event) ;
312         void receivedDomainDistribution(CEventServer& event, int phasis) ;
313
314         void sendDistributedAttributes(CContextClient* client, shared_ptr<CScattererConnector> scaterrerConnector, const string& domainId) ;
315         static void recvDistributedAttributes(CEventServer& event) ;
316         void recvDistributedAttributes(CEventServer& event, const string& type) ;
317         void setServerMask(CArray<bool,1>& serverMask, CContextClient* client) ;
318
319       private:
320         map<CContextClient*, shared_ptr<CDistributedElement>> remoteElement_ ;
321       public: 
322         shared_ptr<CDistributedElement> getRemoteElement(CContextClient* client) {return remoteElement_[client] ;}
323       private:
324         map<CContextClient*, shared_ptr<CScattererConnector>> clientToServerConnector_ ;
325       public: 
326         shared_ptr<CScattererConnector> getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;}
327       
328       private:
329         shared_ptr<CGathererConnector>  gathererConnector_ ;
330       public:
331         shared_ptr<CGathererConnector> getGathererConnector(void) { return gathererConnector_ ;}
332        private:
333         shared_ptr<CGathererConnector> serverFromClientConnector_ ;
334         shared_ptr<CDistributedElement> elementFrom_ ;
335       public:
336         shared_ptr<CGathererConnector> getServerFromClientConnector(void) { return serverFromClientConnector_ ;}
337
338       private:
339         shared_ptr<CScattererConnector>  serverToClientConnector_ = nullptr ;
340       public: 
341         shared_ptr<CScattererConnector> getServerToClientConnector(void) { return serverToClientConnector_ ;} 
342
343       private:
344         map<CContextClient*,shared_ptr<CGathererConnector>>  clientFromServerConnector_  ;
345       public: 
346         shared_ptr<CGathererConnector> getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;}       
347         
348
349         DECLARE_REF_FUNC(Domain,domain)
350
351   }; // class CDomain
352
353   ///--------------------------------------------------------------
354
355   // Declare/Define CDomainGroup and CDomainDefinition
356   DECLARE_GROUP(CDomain);
357
358   ///--------------------------------------------------------------
359
360} // namespace xios
361
362#endif //__XIOS_CDomain__
Note: See TracBrowser for help on using the repository browser.