#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 "transformation_path.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" #include "generic_algorithm_transformation.hpp" namespace xios { /// ////////////////////// DĂ©clarations ////////////////////// /// class CDomainGroup; class CDomainAttributes; class CDomain; class CFile; class CField ; ///-------------------------------------------------------------- // 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_COLLECTIVE=100, EVENT_ID_DOMAIN_DISTRIBUTION, EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE, EVENT_ID_NO_COLLECTIVE=100, } ; public: typedef CDomainAttributes RelAttributes; typedef CDomainGroup RelGroup; /// Constructeurs /// CDomain(void); explicit CDomain(const StdString & id); CDomain(const CDomain & domain); // Not implemented yet. CDomain(const CDomain * const domain); // Not implemented yet. static void releaseStaticAllocation(void) ; // release static allocation on heap static CDomain* createDomain(); static CDomain* get(const string& id, bool noError=false) ; //::TransformationMapTypes TransMapTypes; private: static bool initializeTransformationMap(std::map& m); static std::map transformationMapList_; static bool dummyTransformationMapList_; TransMapTypes transformationMap_; public: CTransformation* addTransformation(ETranformationType transType, const StdString& id=""); CTransformation* addTransformation(ETranformationType transType, CTransformation* transformation) ; void setTransformations(const TransMapTypes&); void duplicateTransformation(CDomain*); TransMapTypes getAllTransformations(); bool hasTransformation(); void solveInheritanceTransformation_old(); // to remove later void solveInheritanceTransformation(); private: bool solveInheritanceTransformation_done_= false ; public: bool activateFieldWorkflow(CGarbageCollector& gc) ; private: bool activateFieldWorkflow_done_=false ; private: shared_ptr transformationAlgorithm_ = nullptr ; public: void setTransformationAlgorithm(shared_ptr transformationAlgorithm) { transformationAlgorithm_=transformationAlgorithm ;} shared_ptr getTransformationAlgorithm(void) { return transformationAlgorithm_ ;} private: CTransformationPaths transformationPaths_ ; public: CTransformationPaths getTransformationPaths(void) {return transformationPaths_;} void setTransformationPaths(const CTransformationPaths& transformationPaths) { transformationPaths_=transformationPaths ;} //////////////////////////// void redistribute(int nbLocalDomain); public: const std::set & getRelFiles(void) const; bool IsWritten(const StdString & filename) const; bool isWrittenCompressed(const StdString& filename) const; std::map getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false); bool isEmpty(void) const; bool isDistributed(void) const; public : /*! \brief return if the domain can be written or not in a compressed way. ie if there are some masked or indexed point on the domain. Valid only on server side. \return true if domain can be writtedn in a compressed way */ bool isCompressible(void) { if (!isCompressibleComputed_) computeIsCompressible() ; return isCompressible_ ;} private : bool isCompressible_ ; /** specify if the domain can be written in a compressed way */ bool isCompressibleComputed_=false ; /** Indicate if compressability has been computed*/ void computeIsCompressible() ; public : 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_ ; MISSING_RETURN( "bool CDomain::isCompleted() " ); return true; } void setCompleted(void) { isCompleted_=true ; } void unsetCompleted(void) { isCompleted_=false ; } public: /// Mutateur /// void addRelFile(const StdString & filename); void addRelFileCompressed(const StdString& filename); 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 domainMask; // mask_1d, mask_2d -> domainMask CArray localMask; // domainMask + indexing bool isCurvilinear ; bool hasBounds ; bool hasArea; bool hasLonLat; bool hasPole ; void computeLocalMask(void) ; /** The number of server of a context client. Avoid to re-compute indice computed in a previous computeConnectedClient */ private: std::set listNbServer_ ; 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(); public: void sendDomainToFileServer(CContextClient* client) ; private: std::set sendDomainToFileServer_done_ ; public: void sendDomainToCouplerOut(CContextClient* client, const string& fieldId, int posInGrid) ; private: std::set sendDomainToCouplerOut_done_ ; public: void makeAliasForCoupling(const string& fieldId, int posInGrid) ; string getCouplingAlias(const string& fieldId, int posInGrid) ; private: void convertLonLatValue(); void fillInRectilinearLonLat(); void fillInCurvilinearLonLat(); void fillInUnstructuredLonLat(); 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 ; std::set relFiles, relFilesCompressed; /** 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_; std::map > connectedServerRank_; bool isRedistributed_; bool isUnstructed_; ////////////////////////////////////////////////////////////////////////////////////// // this part is related to distribution, element definition, views and connectors // ////////////////////////////////////////////////////////////////////////////////////// private: shared_ptr localElement_ = nullptr ; void initializeLocalElement(void) ; public: shared_ptr getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; } shared_ptr getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;} private: void addFullView(void) ; void addWorkflowView(void) ; void addModelView(void) ; private: shared_ptr modelToWorkflowConnector_ ; void computeModelToWorkflowConnector(void) ; public: shared_ptr getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;} public: void computeRemoteElement(CContextClient* client, EDistributionType) ; void distributeToServer(CContextClient* client, std::map>& globalIndexOut, std::map>& globalIndexIn, shared_ptr &scattererConnector, const string& domainId="") ; static void recvDomainDistribution(CEventServer& event) ; void receivedDomainDistribution(CEventServer& event, int phasis) ; void sendDistributedAttributes(CContextClient* client, shared_ptr scaterrerConnector, const string& domainId) ; static void recvDistributedAttributes(CEventServer& event) ; void recvDistributedAttributes(CEventServer& event, const string& type) ; void setServerMask(CArray& serverMask, CContextClient* client) ; private: map> remoteElement_ ; public: shared_ptr getRemoteElement(CContextClient* client) {return remoteElement_[client] ;} private: map> clientToServerConnector_ ; public: shared_ptr getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;} private: shared_ptr gathererConnector_ ; public: shared_ptr getGathererConnector(void) { return gathererConnector_ ;} private: shared_ptr serverFromClientConnector_ ; shared_ptr elementFrom_ ; public: shared_ptr getServerFromClientConnector(void) { return serverFromClientConnector_ ;} private: shared_ptr serverToClientConnector_ = nullptr ; shared_ptr elementTo_ ; public: shared_ptr getServerToClientConnector(void) { return serverToClientConnector_ ;} private: map> clientFromServerConnector_ ; public: shared_ptr 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__