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