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

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

XIOS coupling branch
Some updates.

First coupling test is beginning to work...

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: 12.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 "server_distribution_description.hpp"
19#include "mesh.hpp"
20
21namespace xios {
22
23   /// ////////////////////// Déclarations ////////////////////// ///
24
25   class CDomainGroup;
26   class CDomainAttributes;
27   class CDomain;
28   class CFile;
29
30   ///--------------------------------------------------------------
31
32   // Declare/Define CDomainAttribute
33   BEGIN_DECLARE_ATTRIBUTE_MAP(CDomain)
34#  include "domain_attribute.conf"
35#  include "domain_attribute_private.conf"
36   END_DECLARE_ATTRIBUTE_MAP(CDomain)
37
38   ///--------------------------------------------------------------
39
40   class CDomain
41      : public CObjectTemplate<CDomain>
42      , public CDomainAttributes
43   {
44     /// typedef ///
45     typedef CObjectTemplate<CDomain>   SuperClass;
46     typedef CDomainAttributes SuperClassAttribute;
47     public:
48         enum EEventId
49         {
50           EVENT_ID_INDEX, EVENT_ID_LON, EVENT_ID_LAT, 
51           EVENT_ID_AREA,
52           EVENT_ID_DATA_INDEX, EVENT_ID_SERVER_ATTRIBUT
53         } ;
54
55      public:
56
57         typedef CDomainAttributes RelAttributes;
58         typedef CDomainGroup      RelGroup;
59         typedef CTransformation<CDomain>::TransformationMapTypes TransMapTypes;
60
61         /// Constructeurs ///
62         CDomain(void);
63         explicit CDomain(const StdString & id);
64         CDomain(const CDomain & domain);       // Not implemented yet.
65         CDomain(const CDomain * const domain); // Not implemented yet.
66
67         static CDomain* createDomain();
68         
69         CMesh* mesh;
70         void assignMesh(const StdString, const int);
71       
72         virtual void parse(xml::CXMLNode & node);
73
74         void setContextClient(CContextClient* contextClient);
75
76         /// Vérifications ///
77         void checkAttributes(void);
78         bool checkAttributes_done_ = false ;
79
80         void checkAttributesOnClient();
81         void checkAttributesOnClientAfterTransformation();
82         void checkEligibilityForCompressedOutput(void);
83
84         void sendCheckedAttributes();
85
86         bool hasTransformation();
87         void solveInheritanceTransformation();
88         TransMapTypes getAllTransformations();
89         void redistribute(int nbLocalDomain);
90         void duplicateTransformation(CDomain*);
91         CTransformation<CDomain>* addTransformation(ETranformationType transType, const StdString& id="");
92
93      public:
94         const std::set<StdString> & getRelFiles(void) const;
95         bool IsWritten(const StdString & filename) const;
96         bool isWrittenCompressed(const StdString& filename) const;
97         
98         int getNumberWrittenIndexes(MPI_Comm writtenCom);
99         int getTotalNumberWrittenIndexes(MPI_Comm writtenCom);
100         int getOffsetWrittenIndexes(MPI_Comm writtenCom);
101         CArray<int,1>& getCompressedIndexToWriteOnServer(MPI_Comm writtenCom);
102
103         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
104
105         bool isEmpty(void) const;
106         bool isDistributed(void) const;
107         bool isCompressible(void) const; 
108 
109         std::vector<int> getNbGlob();
110         bool isEqual(CDomain* domain);
111
112         static bool dispatchEvent(CEventServer& event);
113     
114      private:
115         /** define if the domain is completed or not ie all attributes have been received before in case
116             of grid reading from file or coupling */ 
117         bool isCompleted_=true ; 
118      public:     
119        /*!
120           \brief Check if a domain is completed
121           Before make any domain processing, we must be sure that all domain informations have
122           been sent, for exemple when reading a grid in a file or when grid elements are sent by an
123           other context (coupling). So all direct reference of the domain (domain_ref) must be also completed
124           \return true if domain and domain reference are completed
125          */
126         bool isCompleted(void)
127         {
128           if (hasDirectDomainReference()) if (!getDirectDomainReference()->isCompleted()) return false;
129           else return isCompleted_ ;
130         }
131         void setCompleted(void) { isCompleted_=true ; }
132         void unsetCompleted(void) { isCompleted_=false ; }
133
134      public:
135         /// Mutateur ///
136         void addRelFile(const StdString & filename);
137         void addRelFileCompressed(const StdString& filename);           
138         
139         void computeWrittenIndex();
140         void computeWrittenCompressedIndex(MPI_Comm);
141
142         void AllgatherRectilinearLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
143                                         CArray<double,1>& lon_g, CArray<double,1>& lat_g);
144
145         void fillInRectilinearBoundLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
146                                           CArray<double,2>& boundsLon, CArray<double,2>& boundsLat);
147         
148         void fillInLonLat();
149         bool distributionAttributesHaveValue() const;
150
151         size_t getGlobalWrittenSize() ;
152         /// Destructeur ///
153         virtual ~CDomain(void);
154
155         /// Accesseurs statiques ///
156         static StdString GetName(void);
157         static StdString GetDefName(void);
158
159         static ENodeType GetType(void);       
160
161      public:
162         CArray<double, 1> lonvalue, latvalue;
163         CArray<double, 2> bounds_lonvalue, bounds_latvalue;
164         CArray<double, 1> areavalue;
165
166         CArray<int,1> localIndexToWriteOnServer;
167
168         CArray<bool, 1> domainMask; // mask_1d, mask_2d -> domainMask
169         CArray<bool, 1> localMask; // domainMask + indexing
170         bool isCurvilinear ;
171         bool hasBounds ;
172         bool hasArea;
173         bool hasLonLat;
174         bool hasPole ;
175         bool hasLatInReadFile_ ; // specify if latitude is defined on read file, so it can be read later when grid distribution will be defined
176         bool hasBoundsLatInReadFile_ ; // specify if latitude boundarues are defined on read file, so it can be read later when grid distribution will be defined
177         bool hasLonInReadFile_ ; // specify if longitude is defined on read file, so it can be read later when grid distribution will be defined
178         bool hasBoundsLonInReadFile_ ; // specify if longitude boundaries are defined on read file, so it can be read later when grid distribution will be defined
179
180         void computeLocalMask(void) ;
181     
182         void computeConnectedClients(CContextClient* client); 
183         private: std::set<CContextClient*> computeConnectedClients_done_; public:
184         /** The number of server of a context client. Avoid to re-compute indice computed in a previous computeConnectedClient */
185         private: std::set<int> listNbServer_ ; public:
186         
187      private:
188         void checkDomain(void);
189         void checkLocalIDomain(void);
190         void checkLocalJDomain(void);
191
192         void checkMask(void);
193         void checkDomainData(void);
194         void checkCompression(void);
195
196         void checkBounds(void);
197         void checkArea(void);
198         void checkLonLat();
199
200         void setTransformations(const TransMapTypes&);         
201         void computeNGlobDomain();
202         
203       public:
204         void sendDomainToFileServer(CContextClient* client) ;
205       private:
206         std::set<CContextClient*> sendDomainToFileServer_done_ ;
207       private:
208         public:
209         void sendDomainToCouplerOut(CContextClient* client, const string& fieldId, int posInGrid) ;
210       private:
211         std::set<CContextClient*> sendDomainToCouplerOut_done_ ;
212     
213       public:
214        void makeAliasForCoupling(const string& fieldId, int posInGrid) ;
215
216       private:
217
218         void sendAttributes(); // ym obsolete -> to be removed
219         void sendIndex(CContextClient* client, const string& domainId="");
220         void sendDistributionAttributes(CContextClient* client, const string& domainId="");
221         void sendArea(CContextClient* client, const string& domainId="");
222         void sendLonLat(CContextClient* client, const string& domainId="");         
223         void sendDataIndex(CContextClient* client, const string& domainId="");
224         void convertLonLatValue();
225         void fillInRectilinearLonLat();
226         void fillInCurvilinearLonLat();
227         void fillInUnstructuredLonLat();
228         
229         static void recvDistributionAttributes(CEventServer& event);
230         static void recvIndex(CEventServer& event);
231         static void recvLon(CEventServer& event);
232         static void recvLat(CEventServer& event);
233         static void recvArea(CEventServer& event);
234         static void recvDataIndex(CEventServer& event);
235         void recvDistributionAttributes(CBufferIn& buffer);                 
236         void recvIndex(std::map<int, CBufferIn*>& rankBuffers);         
237         void recvLon(std::map<int, CBufferIn*>& rankBuffers);
238         void recvLat(std::map<int, CBufferIn*>& rankBuffers);
239         void recvArea(std::map<int, CBufferIn*>& rankBuffers);         
240         void recvDataIndex(std::map<int, CBufferIn*>& rankBuffers);
241
242         void completeLonLatClient(void); 
243         
244         
245       private:         
246
247/** Clients that have to send a domain. There can be multiple clients in case of secondary server, otherwise only one client. */
248         std::list<CContextClient*> clients;
249         std::set<CContextClient*> clientsSet;
250
251         bool isChecked, computedWrittenIndex_;
252         std::set<StdString> relFiles, relFilesCompressed;
253         bool isClientChecked; // Verify whether all attributes of domain on the client side are good
254         bool isClientAfterTransformationChecked;
255
256/** 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)
257    indGlobs_[rank] -> array of global index received from the client of rank "rank"
258    indGlobs[rank](ind) -> global indices of the "ind" element sent.
259    Defined only on server side
260*/
261         std::map<int, CArray<int,1> > indGlob_;
262
263/** only on client sided : defined the number of clients which participate to a message sent to a server for longitude, lat, area, etc. attributes
264    nbSender[nbServers] --> first map is related to the server distribution (ie associated with the contextClient)
265    nbSenders[nbServers][server_rank]-> return the number of participants of a message sent to the server of rank "server_rank"
266*/
267         std::map<int, map<int,int> > nbSenders; 
268
269/** only on client side : Global index of each client sent to server: map<serverSize, map<serverRank, indexes>>
270    indSrv_[nbServers] -->  first map is related to the server distribution (ie associated with the contextClient)
271    indSrv_[nbServers][server_rank] -> array of global index sent to the server of rank "server_rank"
272    indSrv_[nbServers][server_rank](ind) --> global index on server of the local element "ind" sent (for lon, lat, mask, etc...)
273*/
274         std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_;
275         
276 /** make the mapping between the global index (the key) and the local index
277     globalLocalIndexMap_[global_index] --> get the local index
278 */       
279         std::unordered_map<size_t,size_t> globalLocalIndexMap_;
280
281
282/** only on server side : get the rank of each clients which participate to a received message
283*   recvClientRanks_[num_receiver] : client rank of the receiver "num_receiver"
284*/
285         std::vector<int> recvClientRanks_;
286
287         std::map<int,int> numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_;
288         std::map<int, CArray<int, 1> > compressedIndexToWriteOnServer;     
289         std::map<int, std::vector<int> > connectedServerRank_;
290
291         //! True if and only if the data defined on the domain can be outputted in a compressed way
292         bool isCompressible_;
293         bool isRedistributed_;
294         TransMapTypes transformationMap_;         
295         bool isUnstructed_;
296
297       
298       private:
299         static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m);
300         static std::map<StdString, ETranformationType> transformationMapList_;
301         static bool _dummyTransformationMapList;
302
303         DECLARE_REF_FUNC(Domain,domain)
304
305   }; // class CDomain
306
307   ///--------------------------------------------------------------
308
309   // Declare/Define CDomainGroup and CDomainDefinition
310   DECLARE_GROUP(CDomain);
311
312   ///--------------------------------------------------------------
313
314} // namespace xios
315
316#endif //__XIOS_CDomain__
Note: See TracBrowser for help on using the repository browser.