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