#ifndef __XIOS_CDomain__ #define __XIOS_CDomain__ /// XIOS headers /// #include "xios_spl.hpp" #include "group_factory.hpp" #include "declare_group.hpp" #include "declare_ref_func.hpp" #include "event_client.hpp" #include "event_server.hpp" #include "buffer_in.hpp" #include "array_new.hpp" #include "attribute_array.hpp" #include "attribute_enum.hpp" #include "transformation.hpp" #include "transformation_enum.hpp" #include "server_distribution_description.hpp" #include "mesh.hpp" #include "element.hpp" #include "local_connector.hpp" #include "scatterer_connector.hpp" #include "gatherer_connector.hpp" #include "distribution_type.hpp" namespace xios { /// ////////////////////// DĂ©clarations ////////////////////// /// class CDomainGroup; class CDomainAttributes; class CDomain; class CFile; ///-------------------------------------------------------------- // Declare/Define CDomainAttribute BEGIN_DECLARE_ATTRIBUTE_MAP(CDomain) # include "domain_attribute.conf" # include "domain_attribute_private.conf" END_DECLARE_ATTRIBUTE_MAP(CDomain) ///-------------------------------------------------------------- class CDomain : public CObjectTemplate , public CDomainAttributes { /// typedef /// typedef CObjectTemplate SuperClass; typedef CDomainAttributes SuperClassAttribute; public: enum EEventId { EVENT_ID_INDEX, EVENT_ID_LON, EVENT_ID_LAT, EVENT_ID_AREA, EVENT_ID_DATA_INDEX, EVENT_ID_SERVER_ATTRIBUT, EVENT_ID_DOMAIN_DISTRIBUTION, EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE } ; public: typedef CDomainAttributes RelAttributes; typedef CDomainGroup RelGroup; typedef CTransformation::TransformationMapTypes TransMapTypes; /// Constructeurs /// CDomain(void); explicit CDomain(const StdString & id); CDomain(const CDomain & domain); // Not implemented yet. CDomain(const CDomain * const domain); // Not implemented yet. static CDomain* createDomain(); CMesh* mesh; void assignMesh(const StdString, const int); virtual void parse(xml::CXMLNode & node); void setContextClient(CContextClient* contextClient); /// VĂ©rifications /// void checkAttributes(void); bool checkAttributes_done_ = false ; void checkAttributesOnClient(); void checkAttributesOnClientAfterTransformation(); void checkEligibilityForCompressedOutput(void); void sendCheckedAttributes(); bool hasTransformation(); void solveInheritanceTransformation(); TransMapTypes getAllTransformations(); void redistribute(int nbLocalDomain); void duplicateTransformation(CDomain*); CTransformation* addTransformation(ETranformationType transType, const StdString& id=""); public: const std::set & getRelFiles(void) const; bool IsWritten(const StdString & filename) const; bool isWrittenCompressed(const StdString& filename) const; int getNumberWrittenIndexes(MPI_Comm writtenCom); int getTotalNumberWrittenIndexes(MPI_Comm writtenCom); int getOffsetWrittenIndexes(MPI_Comm writtenCom); CArray& getCompressedIndexToWriteOnServer(MPI_Comm writtenCom); std::map getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false); bool isEmpty(void) const; bool isDistributed(void) const; bool isCompressible(void) const; std::vector getNbGlob(); bool isEqual(CDomain* domain); static bool dispatchEvent(CEventServer& event); private: /** define if the domain is completed or not ie all attributes have been received before in case of grid reading from file or coupling */ bool isCompleted_=true ; public: /*! \brief Check if a domain is completed Before make any domain processing, we must be sure that all domain informations have been sent, for exemple when reading a grid in a file or when grid elements are sent by an other context (coupling). So all direct reference of the domain (domain_ref) must be also completed \return true if domain and domain reference are completed */ bool isCompleted(void) { if (hasDirectDomainReference()) if (!getDirectDomainReference()->isCompleted()) return false; else return isCompleted_ ; } void setCompleted(void) { isCompleted_=true ; } void unsetCompleted(void) { isCompleted_=false ; } public: /// Mutateur /// void addRelFile(const StdString & filename); void addRelFileCompressed(const StdString& filename); void computeWrittenIndex(); void computeWrittenCompressedIndex(MPI_Comm); void AllgatherRectilinearLonLat(CArray& lon, CArray& lat, CArray& lon_g, CArray& lat_g); void fillInRectilinearBoundLonLat(CArray& lon, CArray& lat, CArray& boundsLon, CArray& boundsLat); void fillInLonLat(); bool distributionAttributesHaveValue() const; size_t getGlobalWrittenSize() ; /// Destructeur /// virtual ~CDomain(void); /// Accesseurs statiques /// static StdString GetName(void); static StdString GetDefName(void); static ENodeType GetType(void); public: CArray lonvalue, latvalue; CArray bounds_lonvalue, bounds_latvalue; CArray areavalue; CArray localIndexToWriteOnServer; CArray domainMask; // mask_1d, mask_2d -> domainMask CArray localMask; // domainMask + indexing bool isCurvilinear ; bool hasBounds ; bool hasArea; bool hasLonLat; bool hasPole ; bool hasLatInReadFile_ ; // specify if latitude is defined on read file, so it can be read later when grid distribution will be defined bool hasBoundsLatInReadFile_ ; // specify if latitude boundarues are defined on read file, so it can be read later when grid distribution will be defined bool hasLonInReadFile_ ; // specify if longitude is defined on read file, so it can be read later when grid distribution will be defined bool hasBoundsLonInReadFile_ ; // specify if longitude boundaries are defined on read file, so it can be read later when grid distribution will be defined void computeLocalMask(void) ; void computeConnectedClients(CContextClient* client); private: std::set computeConnectedClients_done_; public: /** The number of server of a context client. Avoid to re-compute indice computed in a previous computeConnectedClient */ private: std::set listNbServer_ ; public: private: void checkDomain(void); void checkLocalIDomain(void); void checkLocalJDomain(void); void checkMask(void); void checkDomainData(void); void checkCompression(void); void checkBounds(void); void checkArea(void); void checkLonLat(); void setTransformations(const TransMapTypes&); void computeNGlobDomain(); public: void sendDomainToFileServer(CContextClient* client) ; private: std::set sendDomainToFileServer_done_ ; private: public: void sendDomainToCouplerOut(CContextClient* client, const string& fieldId, int posInGrid) ; private: std::set sendDomainToCouplerOut_done_ ; public: void makeAliasForCoupling(const string& fieldId, int posInGrid) ; private: void sendDomainDistribution(CContextClient* client, const string& domainId="") ; //for testing void sendAttributes(); // ym obsolete -> to be removed void sendIndex(CContextClient* client, const string& domainId=""); void sendDistributionAttributes(CContextClient* client, const string& domainId=""); void sendArea(CContextClient* client, const string& domainId=""); void sendLonLat(CContextClient* client, const string& domainId=""); void sendDataIndex(CContextClient* client, const string& domainId=""); void convertLonLatValue(); void fillInRectilinearLonLat(); void fillInCurvilinearLonLat(); void fillInUnstructuredLonLat(); static void recvDistributionAttributes(CEventServer& event); static void recvIndex(CEventServer& event); static void recvLon(CEventServer& event); static void recvLat(CEventServer& event); static void recvArea(CEventServer& event); static void recvDataIndex(CEventServer& event); void recvDistributionAttributes(CBufferIn& buffer); void recvIndex(std::map& rankBuffers); void recvLon(std::map& rankBuffers); void recvLat(std::map& rankBuffers); void recvArea(std::map& rankBuffers); void recvDataIndex(std::map& rankBuffers); void completeLonLatClient(void); private: /** Clients that have to send a domain. There can be multiple clients in case of secondary server, otherwise only one client. */ std::list clients; std::set clientsSet; bool isChecked, computedWrittenIndex_; std::set relFiles, relFilesCompressed; bool isClientChecked; // Verify whether all attributes of domain on the client side are good bool isClientAfterTransformationChecked; /** 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) indGlobs_[rank] -> array of global index received from the client of rank "rank" indGlobs[rank](ind) -> global indices of the "ind" element sent. Defined only on server side */ std::map > indGlob_; /** only on client sided : defined the number of clients which participate to a message sent to a server for longitude, lat, area, etc. attributes nbSender[nbServers] --> first map is related to the server distribution (ie associated with the contextClient) nbSenders[nbServers][server_rank]-> return the number of participants of a message sent to the server of rank "server_rank" */ std::map > nbSenders; /** only on client side : Global index of each client sent to server: map> indSrv_[nbServers] --> first map is related to the server distribution (ie associated with the contextClient) indSrv_[nbServers][server_rank] -> array of global index sent to the server of rank "server_rank" indSrv_[nbServers][server_rank](ind) --> global index on server of the local element "ind" sent (for lon, lat, mask, etc...) */ std::map > > indSrv_; /** make the mapping between the global index (the key) and the local index globalLocalIndexMap_[global_index] --> get the local index */ std::unordered_map globalLocalIndexMap_; /** only on server side : get the rank of each clients which participate to a received message * recvClientRanks_[num_receiver] : client rank of the receiver "num_receiver" */ std::vector recvClientRanks_; std::map numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_; std::map > compressedIndexToWriteOnServer; std::map > connectedServerRank_; //! True if and only if the data defined on the domain can be outputted in a compressed way bool isCompressible_; bool isRedistributed_; TransMapTypes transformationMap_; bool isUnstructed_; private: static bool initializeTransformationMap(std::map& m); static std::map transformationMapList_; static bool _dummyTransformationMapList; ////////////////////////////////////////////////////////////////////////////////////// // this part is related to distribution, element definition, views and connectors // ////////////////////////////////////////////////////////////////////////////////////// private: CLocalElement* localElement_ = nullptr ; void initializeLocalElement(void) ; public: CLocalElement* getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; } CLocalView* getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;} private: void addFullView(void) ; void addWorkflowView(void) ; void addModelView(void) ; private: CLocalConnector* modelToWorkflowConnector_ ; void computeModelToWorkflowConnector(void) ; public: CLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;} public: void computeRemoteElement(CContextClient* client, EDistributionType) ; void distributeToServer(CContextClient* client, std::map>& globalIndex, const string& domainId="") ; static void recvDomainDistribution(CEventServer& event) ; void receivedDomainDistribution(CEventServer& event, int phasis) ; void sendDistributedAttributes(CContextClient* client, CScattererConnector& scaterrerConnector, const string& domainId) ; static void recvDistributedAttributes(CEventServer& event) ; void recvDistributedAttributes(CEventServer& event, const string& type) ; private: map remoteElement_ ; public: CDistributedElement* getRemoteElement(CContextClient* client) {return remoteElement_[client] ;} private: map clientToServerConnector_ ; public: CScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;} private: CGathererConnector* gathererConnector_ ; CGathererConnector* serverFromClientConnector_ ; CDistributedElement* elementFrom_ ; public: CGathererConnector* getServerFromClientConnector(void) { return serverFromClientConnector_ ;} private: CScattererConnector* serverToClientConnector_ = nullptr ; public: CScattererConnector* getServerToClientConnector(void) { return serverToClientConnector_ ;} private: map clientFromServerConnector_ ; public: CGathererConnector* getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;} DECLARE_REF_FUNC(Domain,domain) }; // class CDomain ///-------------------------------------------------------------- // Declare/Define CDomainGroup and CDomainDefinition DECLARE_GROUP(CDomain); ///-------------------------------------------------------------- } // namespace xios #endif //__XIOS_CDomain__