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

Last change on this file since 1956 was 1956, checked in by ymipsl, 4 years ago

Xios coupling

  • fix problem when sending grid mask from client to server
  • remove methods about grid compression, which will be managed in other ways

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: 16.5 KB
RevLine 
[591]1#ifndef __XIOS_CDomain__
2#define __XIOS_CDomain__
[219]3
[591]4/// XIOS headers ///
5#include "xios_spl.hpp"
[219]6#include "group_factory.hpp"
7
8#include "declare_group.hpp"
[540]9#include "declare_ref_func.hpp"
[300]10#include "event_client.hpp"
11#include "event_server.hpp"
12#include "buffer_in.hpp"
[369]13#include "array_new.hpp"
14#include "attribute_array.hpp"
[449]15#include "attribute_enum.hpp"
[631]16#include "transformation.hpp"
17#include "transformation_enum.hpp"
[1025]18#include "server_distribution_description.hpp"
[878]19#include "mesh.hpp"
[1918]20#include "element.hpp"
21#include "local_connector.hpp"
[1930]22#include "scatterer_connector.hpp"
[1918]23#include "gatherer_connector.hpp"
[1930]24#include "distribution_type.hpp"
[878]25
[1930]26
[335]27namespace xios {
[509]28
[219]29   /// ////////////////////// Déclarations ////////////////////// ///
30
31   class CDomainGroup;
32   class CDomainAttributes;
33   class CDomain;
[878]34   class CFile;
[219]35
36   ///--------------------------------------------------------------
37
38   // Declare/Define CDomainAttribute
39   BEGIN_DECLARE_ATTRIBUTE_MAP(CDomain)
40#  include "domain_attribute.conf"
[775]41#  include "domain_attribute_private.conf"
[219]42   END_DECLARE_ATTRIBUTE_MAP(CDomain)
43
44   ///--------------------------------------------------------------
45
46   class CDomain
47      : public CObjectTemplate<CDomain>
48      , public CDomainAttributes
49   {
[1158]50     /// typedef ///
51     typedef CObjectTemplate<CDomain>   SuperClass;
52     typedef CDomainAttributes SuperClassAttribute;
53     public:
[300]54         enum EEventId
55         {
[1025]56           EVENT_ID_INDEX, EVENT_ID_LON, EVENT_ID_LAT, 
[1637]57           EVENT_ID_AREA,
[1918]58           EVENT_ID_DATA_INDEX, EVENT_ID_SERVER_ATTRIBUT,
[1930]59           EVENT_ID_DOMAIN_DISTRIBUTION, EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE
[300]60         } ;
[509]61
[676]62      public:
[219]63
64         typedef CDomainAttributes RelAttributes;
65         typedef CDomainGroup      RelGroup;
[631]66         typedef CTransformation<CDomain>::TransformationMapTypes TransMapTypes;
[219]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
[622]74         static CDomain* createDomain();
[878]75         
76         CMesh* mesh;
[924]77         void assignMesh(const StdString, const int);
[878]78       
[631]79         virtual void parse(xml::CXMLNode & node);
80
[1345]81         void setContextClient(CContextClient* contextClient);
82
[219]83         /// Vérifications ///
84         void checkAttributes(void);
[1869]85         bool checkAttributes_done_ = false ;
86
[509]87         void checkAttributesOnClient();
[657]88         void checkAttributesOnClientAfterTransformation();
[676]89
[509]90         void sendCheckedAttributes();
91
[631]92         bool hasTransformation();
93         void solveInheritanceTransformation();
94         TransMapTypes getAllTransformations();
[687]95         void redistribute(int nbLocalDomain);
[823]96         void duplicateTransformation(CDomain*);
[836]97         CTransformation<CDomain>* addTransformation(ETranformationType transType, const StdString& id="");
[631]98
[1158]99      public:
100         const std::set<StdString> & getRelFiles(void) const;
[219]101         bool IsWritten(const StdString & filename) const;
[676]102         bool isWrittenCompressed(const StdString& filename) const;
[1144]103         
[1639]104         int getNumberWrittenIndexes(MPI_Comm writtenCom);
105         int getTotalNumberWrittenIndexes(MPI_Comm writtenCom);
106         int getOffsetWrittenIndexes(MPI_Comm writtenCom);
107         CArray<int,1>& getCompressedIndexToWriteOnServer(MPI_Comm writtenCom);
[676]108
[1330]109         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
[731]110
[219]111         bool isEmpty(void) const;
[594]112         bool isDistributed(void) const;
[1956]113
114        public :
115         /*!
116            \brief return if the domain can be written or not in a compressed way.
117            ie if there are some masked or indexed point on the domain. Valid only on server side.
118            \return true if domain can be writtedn in a compressed way
119         */ 
120         bool isCompressible(void) { if (!isCompressibleComputed_) computeIsCompressible() ; return isCompressible_ ;} 
121        private :
122         bool isCompressible_ ; /** specify if the domain can be written in a compressed way */ 
123         bool isCompressibleComputed_=false ; /** Indicate if compressability has been computed*/
124         void computeIsCompressible() ;
125
126      public :
[1158]127         std::vector<int> getNbGlob();
128         bool isEqual(CDomain* domain);
[1236]129
130         static bool dispatchEvent(CEventServer& event);
[1875]131     
132      private:
133         /** define if the domain is completed or not ie all attributes have been received before in case
134             of grid reading from file or coupling */ 
135         bool isCompleted_=true ; 
136      public:     
137        /*!
138           \brief Check if a domain is completed
139           Before make any domain processing, we must be sure that all domain informations have
140           been sent, for exemple when reading a grid in a file or when grid elements are sent by an
141           other context (coupling). So all direct reference of the domain (domain_ref) must be also completed
142           \return true if domain and domain reference are completed
143          */
144         bool isCompleted(void)
145         {
146           if (hasDirectDomainReference()) if (!getDirectDomainReference()->isCompleted()) return false;
147           else return isCompleted_ ;
148         }
149         void setCompleted(void) { isCompleted_=true ; }
150         void unsetCompleted(void) { isCompleted_=false ; }
[1236]151
[676]152      public:
[219]153         /// Mutateur ///
154         void addRelFile(const StdString & filename);
[1236]155         void addRelFileCompressed(const StdString& filename);           
156         
[1129]157         void computeWrittenIndex();
[1639]158         void computeWrittenCompressedIndex(MPI_Comm);
[821]159
160         void AllgatherRectilinearLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
[809]161                                         CArray<double,1>& lon_g, CArray<double,1>& lat_g);
[821]162
163         void fillInRectilinearBoundLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
[809]164                                           CArray<double,2>& boundsLon, CArray<double,2>& boundsLat);
[1158]165         
166         void fillInLonLat();
167         bool distributionAttributesHaveValue() const;
[611]168
[1215]169         size_t getGlobalWrittenSize() ;
[219]170         /// Destructeur ///
171         virtual ~CDomain(void);
172
173         /// Accesseurs statiques ///
174         static StdString GetName(void);
175         static StdString GetDefName(void);
[509]176
[1236]177         static ENodeType GetType(void);       
178
179      public:
180         CArray<double, 1> lonvalue, latvalue;
181         CArray<double, 2> bounds_lonvalue, bounds_latvalue;
182         CArray<double, 1> areavalue;
183
[1637]184         CArray<int,1> localIndexToWriteOnServer;
[1236]185
[1311]186         CArray<bool, 1> domainMask; // mask_1d, mask_2d -> domainMask
187         CArray<bool, 1> localMask; // domainMask + indexing
[384]188         bool isCurvilinear ;
[449]189         bool hasBounds ;
[611]190         bool hasArea;
[665]191         bool hasLonLat;
[953]192         bool hasPole ;
[1578]193         bool hasLatInReadFile_ ; // specify if latitude is defined on read file, so it can be read later when grid distribution will be defined
194         bool hasBoundsLatInReadFile_ ; // specify if latitude boundarues are defined on read file, so it can be read later when grid distribution will be defined
195         bool hasLonInReadFile_ ; // specify if longitude is defined on read file, so it can be read later when grid distribution will be defined
196         bool hasBoundsLonInReadFile_ ; // specify if longitude boundaries are defined on read file, so it can be read later when grid distribution will be defined
[953]197
[1291]198         void computeLocalMask(void) ;
[1869]199     
200         void computeConnectedClients(CContextClient* client); 
201         private: std::set<CContextClient*> computeConnectedClients_done_; public:
202         /** The number of server of a context client. Avoid to re-compute indice computed in a previous computeConnectedClient */
203         private: std::set<int> listNbServer_ ; public:
204         
[631]205      private:
[667]206         void checkDomain(void);
207         void checkLocalIDomain(void);
208         void checkLocalJDomain(void);
209
210         void checkMask(void);
211         void checkDomainData(void);
212         void checkCompression(void);
213
214         void checkBounds(void);
215         void checkArea(void);
216         void checkLonLat();
217
[1025]218         void setTransformations(const TransMapTypes&);         
[1158]219         void computeNGlobDomain();
[1870]220         
221       public:
222         void sendDomainToFileServer(CContextClient* client) ;
223       private:
224         std::set<CContextClient*> sendDomainToFileServer_done_ ;
[1943]225       public:
[1875]226         void sendDomainToCouplerOut(CContextClient* client, const string& fieldId, int posInGrid) ;
227       private:
228         std::set<CContextClient*> sendDomainToCouplerOut_done_ ;
229     
230       public:
231        void makeAliasForCoupling(const string& fieldId, int posInGrid) ;
232
233       private:
234
[1918]235         void sendDomainDistribution(CContextClient* client, const string& domainId="") ; //for testing
[1870]236         void sendAttributes(); // ym obsolete -> to be removed
[1875]237         void sendIndex(CContextClient* client, const string& domainId="");
238         void sendDistributionAttributes(CContextClient* client, const string& domainId="");
239         void sendArea(CContextClient* client, const string& domainId="");
240         void sendLonLat(CContextClient* client, const string& domainId="");         
241         void sendDataIndex(CContextClient* client, const string& domainId="");
[1129]242         void convertLonLatValue();
[1158]243         void fillInRectilinearLonLat();
244         void fillInCurvilinearLonLat();
245         void fillInUnstructuredLonLat();
[1236]246         
247         static void recvDistributionAttributes(CEventServer& event);
248         static void recvIndex(CEventServer& event);
249         static void recvLon(CEventServer& event);
250         static void recvLat(CEventServer& event);
251         static void recvArea(CEventServer& event);
252         static void recvDataIndex(CEventServer& event);
253         void recvDistributionAttributes(CBufferIn& buffer);                 
254         void recvIndex(std::map<int, CBufferIn*>& rankBuffers);         
255         void recvLon(std::map<int, CBufferIn*>& rankBuffers);
256         void recvLat(std::map<int, CBufferIn*>& rankBuffers);
257         void recvArea(std::map<int, CBufferIn*>& rankBuffers);         
258         void recvDataIndex(std::map<int, CBufferIn*>& rankBuffers);
259
260         void completeLonLatClient(void); 
[1869]261         
262         
[1025]263       private:         
[1345]264
265/** Clients that have to send a domain. There can be multiple clients in case of secondary server, otherwise only one client. */
[1353]266         std::list<CContextClient*> clients;
267         std::set<CContextClient*> clientsSet;
[1345]268
[1129]269         bool isChecked, computedWrittenIndex_;
[676]270         std::set<StdString> relFiles, relFilesCompressed;
[551]271         bool isClientChecked; // Verify whether all attributes of domain on the client side are good
[657]272         bool isClientAfterTransformationChecked;
[1847]273
274/** global index of the domain on server side, sent by the clients. This is global index for lon, lat, mask elements (ie non masked elements)
275    indGlobs_[rank] -> array of global index received from the client of rank "rank"
276    indGlobs[rank](ind) -> global indices of the "ind" element sent.
277    Defined only on server side
278*/
[1236]279         std::map<int, CArray<int,1> > indGlob_;
[1025]280
[1847]281/** only on client sided : defined the number of clients which participate to a message sent to a server for longitude, lat, area, etc. attributes
282    nbSender[nbServers] --> first map is related to the server distribution (ie associated with the contextClient)
283    nbSenders[nbServers][server_rank]-> return the number of participants of a message sent to the server of rank "server_rank"
284*/
285         std::map<int, map<int,int> > nbSenders; 
286
287/** only on client side : Global index of each client sent to server: map<serverSize, map<serverRank, indexes>>
288    indSrv_[nbServers] -->  first map is related to the server distribution (ie associated with the contextClient)
289    indSrv_[nbServers][server_rank] -> array of global index sent to the server of rank "server_rank"
290    indSrv_[nbServers][server_rank](ind) --> global index on server of the local element "ind" sent (for lon, lat, mask, etc...)
291*/
[1542]292         std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_;
[1847]293         
294 /** make the mapping between the global index (the key) and the local index
295     globalLocalIndexMap_[global_index] --> get the local index
296 */       
297         std::unordered_map<size_t,size_t> globalLocalIndexMap_;
298
299
300/** only on server side : get the rank of each clients which participate to a received message
301*   recvClientRanks_[num_receiver] : client rank of the receiver "num_receiver"
302*/
[1236]303         std::vector<int> recvClientRanks_;
[1847]304
[1249]305         std::map<int,int> numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_;
306         std::map<int, CArray<int, 1> > compressedIndexToWriteOnServer;     
[1337]307         std::map<int, std::vector<int> > connectedServerRank_;
[1236]308
[715]309         bool isRedistributed_;
[1025]310         TransMapTypes transformationMap_;         
[657]311         bool isUnstructed_;
[1847]312
[953]313       
[836]314       private:
315         static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m);
316         static std::map<StdString, ETranformationType> transformationMapList_;
317         static bool _dummyTransformationMapList;
318
[1930]319       //////////////////////////////////////////////////////////////////////////////////////
320       //  this part is related to distribution, element definition, views and connectors  //
321       //////////////////////////////////////////////////////////////////////////////////////
[1918]322       private:
323         CLocalElement* localElement_ = nullptr ;
324         void initializeLocalElement(void) ;
325       
326       public: 
327         CLocalElement* getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; }
328         CLocalView* getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;}
329       
330       private: 
331         void addFullView(void) ;
332         void addWorkflowView(void) ;
333         void addModelView(void) ;
334       
335       private:
336         CLocalConnector* modelToWorkflowConnector_ ;
337         void computeModelToWorkflowConnector(void)  ;
[1930]338       public:
339         CLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;}
340
341       public:
342         void computeRemoteElement(CContextClient* client, EDistributionType) ;
[1956]343         void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex, CScattererConnector* &scattererConnector,
344                                 const string& domainId="") ;
[1930]345
346         static void recvDomainDistribution(CEventServer& event) ;
347         void receivedDomainDistribution(CEventServer& event, int phasis) ;
348
349         void sendDistributedAttributes(CContextClient* client, CScattererConnector& scaterrerConnector, const string& domainId) ;
350         static void recvDistributedAttributes(CEventServer& event) ;
351         void recvDistributedAttributes(CEventServer& event, const string& type) ;
[1943]352         void setServerMask(CArray<bool,1>& serverMask, CContextClient* client) ;
353
[1930]354       private:
355         map<CContextClient*, CDistributedElement*> remoteElement_ ;
356       public: 
357         CDistributedElement* getRemoteElement(CContextClient* client) {return remoteElement_[client] ;}
358       private:
359         map<CContextClient*, CScattererConnector*> clientToServerConnector_ ;
360       public: 
361         CScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;}
[1934]362       
[1930]363       private:
[1918]364         CGathererConnector*  gathererConnector_ ;
[1943]365       public:
366         CGathererConnector* getGathererConnector(void) { return gathererConnector_ ;}
367        private:
[1930]368         CGathererConnector* serverFromClientConnector_ ;
369         CDistributedElement* elementFrom_ ;
370       public:
[1934]371         CGathererConnector* getServerFromClientConnector(void) { return serverFromClientConnector_ ;}
[1918]372
[1934]373       private:
374         CScattererConnector*  serverToClientConnector_ = nullptr ;
375       public: 
376         CScattererConnector* getServerToClientConnector(void) { return serverToClientConnector_ ;} 
377
378       private:
379         map<CContextClient*,CGathererConnector*>  clientFromServerConnector_  ;
380       public: 
381         CGathererConnector* getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;}       
[1918]382         
[1930]383
[540]384         DECLARE_REF_FUNC(Domain,domain)
385
[219]386   }; // class CDomain
387
388   ///--------------------------------------------------------------
389
390   // Declare/Define CDomainGroup and CDomainDefinition
391   DECLARE_GROUP(CDomain);
392
393   ///--------------------------------------------------------------
394
[335]395} // namespace xios
[219]396
[878]397#endif //__XIOS_CDomain__
Note: See TracBrowser for help on using the repository browser.