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

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

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