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

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

Some update on XIOS_COUPLING branch...

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: 11.5 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         bool checkIfCompleted(void) ;
115         void setCompleted(void) ;
116         void setUncompleted(void) ;
117
118      public:
119         /// Mutateur ///
120         void addRelFile(const StdString & filename);
121         void addRelFileCompressed(const StdString& filename);           
122         
123         void computeWrittenIndex();
124         void computeWrittenCompressedIndex(MPI_Comm);
125
126         void AllgatherRectilinearLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
127                                         CArray<double,1>& lon_g, CArray<double,1>& lat_g);
128
129         void fillInRectilinearBoundLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
130                                           CArray<double,2>& boundsLon, CArray<double,2>& boundsLat);
131         
132         void fillInLonLat();
133         bool distributionAttributesHaveValue() const;
134
135         size_t getGlobalWrittenSize() ;
136         /// Destructeur ///
137         virtual ~CDomain(void);
138
139         /// Accesseurs statiques ///
140         static StdString GetName(void);
141         static StdString GetDefName(void);
142
143         static ENodeType GetType(void);       
144
145      public:
146         CArray<double, 1> lonvalue, latvalue;
147         CArray<double, 2> bounds_lonvalue, bounds_latvalue;
148         CArray<double, 1> areavalue;
149
150         CArray<int,1> localIndexToWriteOnServer;
151
152         CArray<bool, 1> domainMask; // mask_1d, mask_2d -> domainMask
153         CArray<bool, 1> localMask; // domainMask + indexing
154         bool isCurvilinear ;
155         bool hasBounds ;
156         bool hasArea;
157         bool hasLonLat;
158         bool hasPole ;
159         bool hasLatInReadFile_ ; // specify if latitude is defined on read file, so it can be read later when grid distribution will be defined
160         bool hasBoundsLatInReadFile_ ; // specify if latitude boundarues are defined on read file, so it can be read later when grid distribution will be defined
161         bool hasLonInReadFile_ ; // specify if longitude is defined on read file, so it can be read later when grid distribution will be defined
162         bool hasBoundsLonInReadFile_ ; // specify if longitude boundaries are defined on read file, so it can be read later when grid distribution will be defined
163
164         void computeLocalMask(void) ;
165     
166         void computeConnectedClients(CContextClient* client); 
167         private: std::set<CContextClient*> computeConnectedClients_done_; public:
168         /** The number of server of a context client. Avoid to re-compute indice computed in a previous computeConnectedClient */
169         private: std::set<int> listNbServer_ ; public:
170         
171      private:
172         void checkDomain(void);
173         void checkLocalIDomain(void);
174         void checkLocalJDomain(void);
175
176         void checkMask(void);
177         void checkDomainData(void);
178         void checkCompression(void);
179
180         void checkBounds(void);
181         void checkArea(void);
182         void checkLonLat();
183
184         void setTransformations(const TransMapTypes&);         
185         void computeNGlobDomain();
186         
187       public:
188         void sendDomainToFileServer(CContextClient* client) ;
189       private:
190         std::set<CContextClient*> sendDomainToFileServer_done_ ;
191       private:
192         
193         void sendAttributes(); // ym obsolete -> to be removed
194         void sendIndex(CContextClient* client);
195         void sendDistributionAttributes(CContextClient* client);
196         void sendArea(CContextClient* client);
197         void sendLonLat(CContextClient* client);         
198         void sendDataIndex(CContextClient* client);
199         void convertLonLatValue();
200         void fillInRectilinearLonLat();
201         void fillInCurvilinearLonLat();
202         void fillInUnstructuredLonLat();
203         
204         static void recvDistributionAttributes(CEventServer& event);
205         static void recvIndex(CEventServer& event);
206         static void recvLon(CEventServer& event);
207         static void recvLat(CEventServer& event);
208         static void recvArea(CEventServer& event);
209         static void recvDataIndex(CEventServer& event);
210         void recvDistributionAttributes(CBufferIn& buffer);                 
211         void recvIndex(std::map<int, CBufferIn*>& rankBuffers);         
212         void recvLon(std::map<int, CBufferIn*>& rankBuffers);
213         void recvLat(std::map<int, CBufferIn*>& rankBuffers);
214         void recvArea(std::map<int, CBufferIn*>& rankBuffers);         
215         void recvDataIndex(std::map<int, CBufferIn*>& rankBuffers);
216
217         void completeLonLatClient(void); 
218         
219         
220       private:         
221
222/** Clients that have to send a domain. There can be multiple clients in case of secondary server, otherwise only one client. */
223         std::list<CContextClient*> clients;
224         std::set<CContextClient*> clientsSet;
225
226         bool isChecked, computedWrittenIndex_;
227         std::set<StdString> relFiles, relFilesCompressed;
228         bool isClientChecked; // Verify whether all attributes of domain on the client side are good
229         bool isClientAfterTransformationChecked;
230         
231         /** define if the domain is completed or not ie all attributes have been received before in case
232             of grid reading from file or coupling */ 
233         bool isCompleted_=true ; 
234
235/** 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)
236    indGlobs_[rank] -> array of global index received from the client of rank "rank"
237    indGlobs[rank](ind) -> global indices of the "ind" element sent.
238    Defined only on server side
239*/
240         std::map<int, CArray<int,1> > indGlob_;
241
242/** only on client sided : defined the number of clients which participate to a message sent to a server for longitude, lat, area, etc. attributes
243    nbSender[nbServers] --> first map is related to the server distribution (ie associated with the contextClient)
244    nbSenders[nbServers][server_rank]-> return the number of participants of a message sent to the server of rank "server_rank"
245*/
246         std::map<int, map<int,int> > nbSenders; 
247
248/** only on client side : Global index of each client sent to server: map<serverSize, map<serverRank, indexes>>
249    indSrv_[nbServers] -->  first map is related to the server distribution (ie associated with the contextClient)
250    indSrv_[nbServers][server_rank] -> array of global index sent to the server of rank "server_rank"
251    indSrv_[nbServers][server_rank](ind) --> global index on server of the local element "ind" sent (for lon, lat, mask, etc...)
252*/
253         std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_;
254         
255 /** make the mapping between the global index (the key) and the local index
256     globalLocalIndexMap_[global_index] --> get the local index
257 */       
258         std::unordered_map<size_t,size_t> globalLocalIndexMap_;
259
260
261/** only on server side : get the rank of each clients which participate to a received message
262*   recvClientRanks_[num_receiver] : client rank of the receiver "num_receiver"
263*/
264         std::vector<int> recvClientRanks_;
265
266         std::map<int,int> numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_;
267         std::map<int, CArray<int, 1> > compressedIndexToWriteOnServer;     
268         std::map<int, std::vector<int> > connectedServerRank_;
269
270         //! True if and only if the data defined on the domain can be outputted in a compressed way
271         bool isCompressible_;
272         bool isRedistributed_;
273         TransMapTypes transformationMap_;         
274         bool isUnstructed_;
275
276       
277       private:
278         static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m);
279         static std::map<StdString, ETranformationType> transformationMapList_;
280         static bool _dummyTransformationMapList;
281
282         DECLARE_REF_FUNC(Domain,domain)
283
284   }; // class CDomain
285
286   ///--------------------------------------------------------------
287
288   // Declare/Define CDomainGroup and CDomainDefinition
289   DECLARE_GROUP(CDomain);
290
291   ///--------------------------------------------------------------
292
293} // namespace xios
294
295#endif //__XIOS_CDomain__
Note: See TracBrowser for help on using the repository browser.