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

Last change on this file since 2203 was 2203, checked in by ymipsl, 3 years ago

New functionnality : domain, axis and scalar can now be retrieve with new syntax id :
ex. for domain :

id="domainId" : old syntax, working as before
id="fieldId::domainId" : get the domain related to "domainId" associated to the field "fieldId", work if only 1 domain related to domainId is associated to the field.
id="fieldId::domainId[n]" : get the nth domain related to "domainId" associated to the field "fieldId"
id="fieldId::" : get the domain associated the the field "fieldId, work if grid associated to th field is composed with exactly 1 domain (and possibly other components axis or scalars)
id="fieldId::[n] : get the nth domain composing the grid associated to the field

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