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

Last change on this file since 1847 was 1847, checked in by ymipsl, 21 months ago

XIOS_COUPLING branch : more comments and cleaning

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: 10.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         void checkAttributesOnClient();
79         void checkAttributesOnClientAfterTransformation();
80         void checkEligibilityForCompressedOutput(void);
81
82         void sendCheckedAttributes();
83
84         bool hasTransformation();
85         void solveInheritanceTransformation();
86         TransMapTypes getAllTransformations();
87         void redistribute(int nbLocalDomain);
88         void duplicateTransformation(CDomain*);
89         CTransformation<CDomain>* addTransformation(ETranformationType transType, const StdString& id="");
90
91      public:
92         const std::set<StdString> & getRelFiles(void) const;
93         bool IsWritten(const StdString & filename) const;
94         bool isWrittenCompressed(const StdString& filename) const;
95         
96         int getNumberWrittenIndexes(MPI_Comm writtenCom);
97         int getTotalNumberWrittenIndexes(MPI_Comm writtenCom);
98         int getOffsetWrittenIndexes(MPI_Comm writtenCom);
99         CArray<int,1>& getCompressedIndexToWriteOnServer(MPI_Comm writtenCom);
100
101         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
102
103         bool isEmpty(void) const;
104         bool isDistributed(void) const;
105         bool isCompressible(void) const; 
106 
107         std::vector<int> getNbGlob();
108         bool isEqual(CDomain* domain);
109
110         static bool dispatchEvent(CEventServer& event);
111
112      public:
113         /// Mutateur ///
114         void addRelFile(const StdString & filename);
115         void addRelFileCompressed(const StdString& filename);           
116         
117         void computeWrittenIndex();
118         void computeWrittenCompressedIndex(MPI_Comm);
119
120         void AllgatherRectilinearLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
121                                         CArray<double,1>& lon_g, CArray<double,1>& lat_g);
122
123         void fillInRectilinearBoundLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
124                                           CArray<double,2>& boundsLon, CArray<double,2>& boundsLat);
125         
126         void fillInLonLat();
127         bool distributionAttributesHaveValue() const;
128
129         size_t getGlobalWrittenSize() ;
130         /// Destructeur ///
131         virtual ~CDomain(void);
132
133         /// Accesseurs statiques ///
134         static StdString GetName(void);
135         static StdString GetDefName(void);
136
137         static ENodeType GetType(void);       
138
139      public:
140         CArray<double, 1> lonvalue, latvalue;
141         CArray<double, 2> bounds_lonvalue, bounds_latvalue;
142         CArray<double, 1> areavalue;
143
144         CArray<int,1> localIndexToWriteOnServer;
145
146         CArray<bool, 1> domainMask; // mask_1d, mask_2d -> domainMask
147         CArray<bool, 1> localMask; // domainMask + indexing
148         bool isCurvilinear ;
149         bool hasBounds ;
150         bool hasArea;
151         bool hasLonLat;
152         bool hasPole ;
153         bool hasLatInReadFile_ ; // specify if latitude is defined on read file, so it can be read later when grid distribution will be defined
154         bool hasBoundsLatInReadFile_ ; // specify if latitude boundarues are defined on read file, so it can be read later when grid distribution will be defined
155         bool hasLonInReadFile_ ; // specify if longitude is defined on read file, so it can be read later when grid distribution will be defined
156         bool hasBoundsLonInReadFile_ ; // specify if longitude boundaries are defined on read file, so it can be read later when grid distribution will be defined
157
158         void computeLocalMask(void) ;
159      private:
160         void checkDomain(void);
161         void checkLocalIDomain(void);
162         void checkLocalJDomain(void);
163
164         void checkMask(void);
165         void checkDomainData(void);
166         void checkCompression(void);
167
168         void checkBounds(void);
169         void checkArea(void);
170         void checkLonLat();
171
172         void setTransformations(const TransMapTypes&);         
173         void computeNGlobDomain();
174         void sendAttributes();
175         void sendIndex();
176         void sendDistributionAttributes();
177         void sendArea();
178         void sendLonLat();         
179         void sendDataIndex();
180         void convertLonLatValue();
181         void fillInRectilinearLonLat();
182         void fillInCurvilinearLonLat();
183         void fillInUnstructuredLonLat();
184         
185         static void recvDistributionAttributes(CEventServer& event);
186         static void recvIndex(CEventServer& event);
187         static void recvLon(CEventServer& event);
188         static void recvLat(CEventServer& event);
189         static void recvArea(CEventServer& event);
190         static void recvDataIndex(CEventServer& event);
191         void recvDistributionAttributes(CBufferIn& buffer);                 
192         void recvIndex(std::map<int, CBufferIn*>& rankBuffers);         
193         void recvLon(std::map<int, CBufferIn*>& rankBuffers);
194         void recvLat(std::map<int, CBufferIn*>& rankBuffers);
195         void recvArea(std::map<int, CBufferIn*>& rankBuffers);         
196         void recvDataIndex(std::map<int, CBufferIn*>& rankBuffers);
197
198         void completeLonLatClient(void); 
199         void computeConnectedClients();   
200
201       private:         
202
203/** Clients that have to send a domain. There can be multiple clients in case of secondary server, otherwise only one client. */
204         std::list<CContextClient*> clients;
205         std::set<CContextClient*> clientsSet;
206
207         bool isChecked, computedWrittenIndex_;
208         std::set<StdString> relFiles, relFilesCompressed;
209         bool isClientChecked; // Verify whether all attributes of domain on the client side are good
210         bool isClientAfterTransformationChecked;
211
212/** 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)
213    indGlobs_[rank] -> array of global index received from the client of rank "rank"
214    indGlobs[rank](ind) -> global indices of the "ind" element sent.
215    Defined only on server side
216*/
217         std::map<int, CArray<int,1> > indGlob_;
218
219/** only on client sided : defined the number of clients which participate to a message sent to a server for longitude, lat, area, etc. attributes
220    nbSender[nbServers] --> first map is related to the server distribution (ie associated with the contextClient)
221    nbSenders[nbServers][server_rank]-> return the number of participants of a message sent to the server of rank "server_rank"
222*/
223         std::map<int, map<int,int> > nbSenders; 
224
225/** only on client side : Global index of each client sent to server: map<serverSize, map<serverRank, indexes>>
226    indSrv_[nbServers] -->  first map is related to the server distribution (ie associated with the contextClient)
227    indSrv_[nbServers][server_rank] -> array of global index sent to the server of rank "server_rank"
228    indSrv_[nbServers][server_rank](ind) --> global index on server of the local element "ind" sent (for lon, lat, mask, etc...)
229*/
230         std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_;
231         
232 /** make the mapping between the global index (the key) and the local index
233     globalLocalIndexMap_[global_index] --> get the local index
234 */       
235         std::unordered_map<size_t,size_t> globalLocalIndexMap_;
236
237
238/** only on server side : get the rank of each clients which participate to a received message
239*   recvClientRanks_[num_receiver] : client rank of the receiver "num_receiver"
240*/
241         std::vector<int> recvClientRanks_;
242
243         std::map<int,int> numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_;
244         std::map<int, CArray<int, 1> > compressedIndexToWriteOnServer;     
245         std::map<int, std::vector<int> > connectedServerRank_;
246
247         //! True if and only if the data defined on the domain can be outputted in a compressed way
248         bool isCompressible_;
249         bool isRedistributed_;
250         TransMapTypes transformationMap_;         
251         bool isUnstructed_;
252
253       
254       private:
255         static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m);
256         static std::map<StdString, ETranformationType> transformationMapList_;
257         static bool _dummyTransformationMapList;
258
259         DECLARE_REF_FUNC(Domain,domain)
260
261   }; // class CDomain
262
263   ///--------------------------------------------------------------
264
265   // Declare/Define CDomainGroup and CDomainDefinition
266   DECLARE_GROUP(CDomain);
267
268   ///--------------------------------------------------------------
269
270} // namespace xios
271
272#endif //__XIOS_CDomain__
Note: See TracBrowser for help on using the repository browser.