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

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

Big cleaning 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: 12.8 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#include "element.hpp"
21#include "local_connector.hpp"
22#include "scatterer_connector.hpp"
23#include "gatherer_connector.hpp"
24#include "distribution_type.hpp"
25
26
27namespace xios {
28
29   /// ////////////////////// Déclarations ////////////////////// ///
30
31   class CDomainGroup;
32   class CDomainAttributes;
33   class CDomain;
34   class CFile;
35
36   ///--------------------------------------------------------------
37
38   // Declare/Define CDomainAttribute
39   BEGIN_DECLARE_ATTRIBUTE_MAP(CDomain)
40#  include "domain_attribute.conf"
41#  include "domain_attribute_private.conf"
42   END_DECLARE_ATTRIBUTE_MAP(CDomain)
43
44   ///--------------------------------------------------------------
45
46   class CDomain
47      : public CObjectTemplate<CDomain>
48      , public CDomainAttributes
49   {
50     /// typedef ///
51     typedef CObjectTemplate<CDomain>   SuperClass;
52     typedef CDomainAttributes SuperClassAttribute;
53     public:
54         enum EEventId
55         {
56           EVENT_ID_DOMAIN_DISTRIBUTION, EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE
57         } ;
58
59      public:
60
61         typedef CDomainAttributes RelAttributes;
62         typedef CDomainGroup      RelGroup;
63         typedef CTransformation<CDomain>::TransformationMapTypes TransMapTypes;
64
65         /// Constructeurs ///
66         CDomain(void);
67         explicit CDomain(const StdString & id);
68         CDomain(const CDomain & domain);       // Not implemented yet.
69         CDomain(const CDomain * const domain); // Not implemented yet.
70
71         static CDomain* createDomain();
72         
73         CMesh* mesh;
74         void assignMesh(const StdString, const int);
75       
76         virtual void parse(xml::CXMLNode & node);
77
78         void setContextClient(CContextClient* contextClient);
79
80         /// Vérifications ///
81         void checkAttributes(void);
82         bool checkAttributes_done_ = false ;
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         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
97
98         bool isEmpty(void) const;
99         bool isDistributed(void) const;
100
101        public :
102         /*!
103            \brief return if the domain can be written or not in a compressed way.
104            ie if there are some masked or indexed point on the domain. Valid only on server side.
105            \return true if domain can be writtedn in a compressed way
106         */ 
107         bool isCompressible(void) { if (!isCompressibleComputed_) computeIsCompressible() ; return isCompressible_ ;} 
108        private :
109         bool isCompressible_ ; /** specify if the domain can be written in a compressed way */ 
110         bool isCompressibleComputed_=false ; /** Indicate if compressability has been computed*/
111         void computeIsCompressible() ;
112
113      public :
114         bool isEqual(CDomain* domain);
115
116         static bool dispatchEvent(CEventServer& event);
117     
118      private:
119         /** define if the domain is completed or not ie all attributes have been received before in case
120             of grid reading from file or coupling */ 
121         bool isCompleted_=true ; 
122      public:     
123        /*!
124           \brief Check if a domain is completed
125           Before make any domain processing, we must be sure that all domain informations have
126           been sent, for exemple when reading a grid in a file or when grid elements are sent by an
127           other context (coupling). So all direct reference of the domain (domain_ref) must be also completed
128           \return true if domain and domain reference are completed
129          */
130         bool isCompleted(void)
131         {
132           if (hasDirectDomainReference()) if (!getDirectDomainReference()->isCompleted()) return false;
133           else return isCompleted_ ;
134         }
135         void setCompleted(void) { isCompleted_=true ; }
136         void unsetCompleted(void) { isCompleted_=false ; }
137
138      public:
139         /// Mutateur ///
140         void addRelFile(const StdString & filename);
141         void addRelFileCompressed(const StdString& filename);           
142         
143         void AllgatherRectilinearLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
144                                         CArray<double,1>& lon_g, CArray<double,1>& lat_g);
145
146         void fillInRectilinearBoundLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
147                                           CArray<double,2>& boundsLon, CArray<double,2>& boundsLat);
148         
149         void fillInLonLat();
150         bool distributionAttributesHaveValue() const;
151
152         size_t getGlobalWrittenSize() ;
153         /// Destructeur ///
154         virtual ~CDomain(void);
155
156         /// Accesseurs statiques ///
157         static StdString GetName(void);
158         static StdString GetDefName(void);
159
160         static ENodeType GetType(void);       
161
162      public:
163         CArray<double, 1> lonvalue, latvalue;
164         CArray<double, 2> bounds_lonvalue, bounds_latvalue;
165         CArray<double, 1> areavalue;
166
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         /** The number of server of a context client. Avoid to re-compute indice computed in a previous computeConnectedClient */
183         private: std::set<int> listNbServer_ ;
184         
185      private:
186         void checkDomain(void);
187         void checkLocalIDomain(void);
188         void checkLocalJDomain(void);
189
190         void checkMask(void);
191         void checkDomainData(void);
192         void checkCompression(void);
193
194         void checkBounds(void);
195         void checkArea(void);
196         void checkLonLat();
197
198         void setTransformations(const TransMapTypes&);         
199         void computeNGlobDomain();
200         
201       public:
202         void sendDomainToFileServer(CContextClient* client) ;
203       private:
204         std::set<CContextClient*> sendDomainToFileServer_done_ ;
205       public:
206         void sendDomainToCouplerOut(CContextClient* client, const string& fieldId, int posInGrid) ;
207       private:
208         std::set<CContextClient*> sendDomainToCouplerOut_done_ ;
209     
210       public:
211        void makeAliasForCoupling(const string& fieldId, int posInGrid) ;
212
213       private:
214
215         void convertLonLatValue();
216         void fillInRectilinearLonLat();
217         void fillInCurvilinearLonLat();
218         void fillInUnstructuredLonLat();
219         void completeLonLatClient(void); 
220         
221         
222       private:         
223
224/** Clients that have to send a domain. There can be multiple clients in case of secondary server, otherwise only one client. */
225         std::list<CContextClient*> clients;
226         std::set<CContextClient*> clientsSet;
227
228         bool isChecked ;
229         std::set<StdString> relFiles, relFilesCompressed;
230
231/** only on client side : Global index of each client sent to server: map<serverSize, map<serverRank, indexes>>
232    indSrv_[nbServers] -->  first map is related to the server distribution (ie associated with the contextClient)
233    indSrv_[nbServers][server_rank] -> array of global index sent to the server of rank "server_rank"
234    indSrv_[nbServers][server_rank](ind) --> global index on server of the local element "ind" sent (for lon, lat, mask, etc...)
235*/
236         std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_;
237
238         std::map<int, std::vector<int> > connectedServerRank_;
239
240         bool isRedistributed_;
241         TransMapTypes transformationMap_;         
242         bool isUnstructed_;
243
244       
245       private:
246         static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m);
247         static std::map<StdString, ETranformationType> transformationMapList_;
248         static bool _dummyTransformationMapList;
249
250       //////////////////////////////////////////////////////////////////////////////////////
251       //  this part is related to distribution, element definition, views and connectors  //
252       //////////////////////////////////////////////////////////////////////////////////////
253       private:
254         CLocalElement* localElement_ = nullptr ;
255         void initializeLocalElement(void) ;
256       
257       public: 
258         CLocalElement* getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; }
259         CLocalView* getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;}
260       
261       private: 
262         void addFullView(void) ;
263         void addWorkflowView(void) ;
264         void addModelView(void) ;
265       
266       private:
267         CLocalConnector* modelToWorkflowConnector_ ;
268         void computeModelToWorkflowConnector(void)  ;
269       public:
270         CLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;}
271
272       public:
273         void computeRemoteElement(CContextClient* client, EDistributionType) ;
274         void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex, CScattererConnector* &scattererConnector,
275                                 const string& domainId="") ;
276
277         static void recvDomainDistribution(CEventServer& event) ;
278         void receivedDomainDistribution(CEventServer& event, int phasis) ;
279
280         void sendDistributedAttributes(CContextClient* client, CScattererConnector& scaterrerConnector, const string& domainId) ;
281         static void recvDistributedAttributes(CEventServer& event) ;
282         void recvDistributedAttributes(CEventServer& event, const string& type) ;
283         void setServerMask(CArray<bool,1>& serverMask, CContextClient* client) ;
284
285       private:
286         map<CContextClient*, CDistributedElement*> remoteElement_ ;
287       public: 
288         CDistributedElement* getRemoteElement(CContextClient* client) {return remoteElement_[client] ;}
289       private:
290         map<CContextClient*, CScattererConnector*> clientToServerConnector_ ;
291       public: 
292         CScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;}
293       
294       private:
295         CGathererConnector*  gathererConnector_ ;
296       public:
297         CGathererConnector* getGathererConnector(void) { return gathererConnector_ ;}
298        private:
299         CGathererConnector* serverFromClientConnector_ ;
300         CDistributedElement* elementFrom_ ;
301       public:
302         CGathererConnector* getServerFromClientConnector(void) { return serverFromClientConnector_ ;}
303
304       private:
305         CScattererConnector*  serverToClientConnector_ = nullptr ;
306       public: 
307         CScattererConnector* getServerToClientConnector(void) { return serverToClientConnector_ ;} 
308
309       private:
310         map<CContextClient*,CGathererConnector*>  clientFromServerConnector_  ;
311       public: 
312         CGathererConnector* getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;}       
313         
314
315         DECLARE_REF_FUNC(Domain,domain)
316
317   }; // class CDomain
318
319   ///--------------------------------------------------------------
320
321   // Declare/Define CDomainGroup and CDomainDefinition
322   DECLARE_GROUP(CDomain);
323
324   ///--------------------------------------------------------------
325
326} // namespace xios
327
328#endif //__XIOS_CDomain__
Note: See TracBrowser for help on using the repository browser.