source: XIOS3/trunk/src/node/domain.hpp

Last change on this file was 2632, checked in by ymipsl, 5 weeks ago
  • Recheck grid/domain/axis/scalar after reading grid from file, otherwise some attributes are not taking into account.

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