[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" |
---|
| 20 | |
---|
[335] | 21 | namespace xios { |
---|
[509] | 22 | |
---|
[219] | 23 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
| 24 | |
---|
| 25 | class CDomainGroup; |
---|
| 26 | class CDomainAttributes; |
---|
| 27 | class CDomain; |
---|
[878] | 28 | class CFile; |
---|
[219] | 29 | |
---|
| 30 | ///-------------------------------------------------------------- |
---|
| 31 | |
---|
| 32 | // Declare/Define CDomainAttribute |
---|
| 33 | BEGIN_DECLARE_ATTRIBUTE_MAP(CDomain) |
---|
| 34 | # include "domain_attribute.conf" |
---|
[775] | 35 | # include "domain_attribute_private.conf" |
---|
[219] | 36 | END_DECLARE_ATTRIBUTE_MAP(CDomain) |
---|
| 37 | |
---|
| 38 | ///-------------------------------------------------------------- |
---|
| 39 | |
---|
| 40 | class CDomain |
---|
| 41 | : public CObjectTemplate<CDomain> |
---|
| 42 | , public CDomainAttributes |
---|
| 43 | { |
---|
[1158] | 44 | /// typedef /// |
---|
| 45 | typedef CObjectTemplate<CDomain> SuperClass; |
---|
| 46 | typedef CDomainAttributes SuperClassAttribute; |
---|
| 47 | public: |
---|
[300] | 48 | enum EEventId |
---|
| 49 | { |
---|
[1025] | 50 | EVENT_ID_INDEX, EVENT_ID_LON, EVENT_ID_LAT, |
---|
[1637] | 51 | EVENT_ID_AREA, |
---|
[1236] | 52 | EVENT_ID_DATA_INDEX, EVENT_ID_SERVER_ATTRIBUT |
---|
[300] | 53 | } ; |
---|
[509] | 54 | |
---|
[676] | 55 | public: |
---|
[219] | 56 | |
---|
| 57 | typedef CDomainAttributes RelAttributes; |
---|
| 58 | typedef CDomainGroup RelGroup; |
---|
[631] | 59 | typedef CTransformation<CDomain>::TransformationMapTypes TransMapTypes; |
---|
[219] | 60 | |
---|
| 61 | /// Constructeurs /// |
---|
| 62 | CDomain(void); |
---|
| 63 | explicit CDomain(const StdString & id); |
---|
| 64 | CDomain(const CDomain & domain); // Not implemented yet. |
---|
| 65 | CDomain(const CDomain * const domain); // Not implemented yet. |
---|
| 66 | |
---|
[622] | 67 | static CDomain* createDomain(); |
---|
[878] | 68 | |
---|
| 69 | CMesh* mesh; |
---|
[924] | 70 | void assignMesh(const StdString, const int); |
---|
[878] | 71 | |
---|
[631] | 72 | virtual void parse(xml::CXMLNode & node); |
---|
| 73 | |
---|
[1345] | 74 | void setContextClient(CContextClient* contextClient); |
---|
| 75 | |
---|
[219] | 76 | /// Vérifications /// |
---|
| 77 | void checkAttributes(void); |
---|
[1869] | 78 | bool checkAttributes_done_ = false ; |
---|
| 79 | |
---|
[509] | 80 | void checkAttributesOnClient(); |
---|
[657] | 81 | void checkAttributesOnClientAfterTransformation(); |
---|
[676] | 82 | void checkEligibilityForCompressedOutput(void); |
---|
| 83 | |
---|
[509] | 84 | void sendCheckedAttributes(); |
---|
| 85 | |
---|
[631] | 86 | bool hasTransformation(); |
---|
| 87 | void solveInheritanceTransformation(); |
---|
| 88 | TransMapTypes getAllTransformations(); |
---|
[687] | 89 | void redistribute(int nbLocalDomain); |
---|
[823] | 90 | void duplicateTransformation(CDomain*); |
---|
[836] | 91 | CTransformation<CDomain>* addTransformation(ETranformationType transType, const StdString& id=""); |
---|
[631] | 92 | |
---|
[1158] | 93 | public: |
---|
| 94 | const std::set<StdString> & getRelFiles(void) const; |
---|
[219] | 95 | bool IsWritten(const StdString & filename) const; |
---|
[676] | 96 | bool isWrittenCompressed(const StdString& filename) const; |
---|
[1144] | 97 | |
---|
[1639] | 98 | int getNumberWrittenIndexes(MPI_Comm writtenCom); |
---|
| 99 | int getTotalNumberWrittenIndexes(MPI_Comm writtenCom); |
---|
| 100 | int getOffsetWrittenIndexes(MPI_Comm writtenCom); |
---|
| 101 | CArray<int,1>& getCompressedIndexToWriteOnServer(MPI_Comm writtenCom); |
---|
[676] | 102 | |
---|
[1330] | 103 | std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false); |
---|
[731] | 104 | |
---|
[219] | 105 | bool isEmpty(void) const; |
---|
[594] | 106 | bool isDistributed(void) const; |
---|
[1025] | 107 | bool isCompressible(void) const; |
---|
| 108 | |
---|
[1158] | 109 | std::vector<int> getNbGlob(); |
---|
| 110 | bool isEqual(CDomain* domain); |
---|
[1236] | 111 | |
---|
| 112 | static bool dispatchEvent(CEventServer& event); |
---|
[1875] | 113 | |
---|
| 114 | private: |
---|
| 115 | /** define if the domain is completed or not ie all attributes have been received before in case |
---|
| 116 | of grid reading from file or coupling */ |
---|
| 117 | bool isCompleted_=true ; |
---|
| 118 | public: |
---|
| 119 | /*! |
---|
| 120 | \brief Check if a domain is completed |
---|
| 121 | Before make any domain processing, we must be sure that all domain informations have |
---|
| 122 | been sent, for exemple when reading a grid in a file or when grid elements are sent by an |
---|
| 123 | other context (coupling). So all direct reference of the domain (domain_ref) must be also completed |
---|
| 124 | \return true if domain and domain reference are completed |
---|
| 125 | */ |
---|
| 126 | bool isCompleted(void) |
---|
| 127 | { |
---|
| 128 | if (hasDirectDomainReference()) if (!getDirectDomainReference()->isCompleted()) return false; |
---|
| 129 | else return isCompleted_ ; |
---|
| 130 | } |
---|
| 131 | void setCompleted(void) { isCompleted_=true ; } |
---|
| 132 | void unsetCompleted(void) { isCompleted_=false ; } |
---|
[1236] | 133 | |
---|
[676] | 134 | public: |
---|
[219] | 135 | /// Mutateur /// |
---|
| 136 | void addRelFile(const StdString & filename); |
---|
[1236] | 137 | void addRelFileCompressed(const StdString& filename); |
---|
| 138 | |
---|
[1129] | 139 | void computeWrittenIndex(); |
---|
[1639] | 140 | void computeWrittenCompressedIndex(MPI_Comm); |
---|
[821] | 141 | |
---|
| 142 | void AllgatherRectilinearLonLat(CArray<double,1>& lon, CArray<double,1>& lat, |
---|
[809] | 143 | CArray<double,1>& lon_g, CArray<double,1>& lat_g); |
---|
[821] | 144 | |
---|
| 145 | void fillInRectilinearBoundLonLat(CArray<double,1>& lon, CArray<double,1>& lat, |
---|
[809] | 146 | CArray<double,2>& boundsLon, CArray<double,2>& boundsLat); |
---|
[1158] | 147 | |
---|
| 148 | void fillInLonLat(); |
---|
| 149 | bool distributionAttributesHaveValue() const; |
---|
[611] | 150 | |
---|
[1215] | 151 | size_t getGlobalWrittenSize() ; |
---|
[219] | 152 | /// Destructeur /// |
---|
| 153 | virtual ~CDomain(void); |
---|
| 154 | |
---|
| 155 | /// Accesseurs statiques /// |
---|
| 156 | static StdString GetName(void); |
---|
| 157 | static StdString GetDefName(void); |
---|
[509] | 158 | |
---|
[1236] | 159 | static ENodeType GetType(void); |
---|
| 160 | |
---|
| 161 | public: |
---|
| 162 | CArray<double, 1> lonvalue, latvalue; |
---|
| 163 | CArray<double, 2> bounds_lonvalue, bounds_latvalue; |
---|
| 164 | CArray<double, 1> areavalue; |
---|
| 165 | |
---|
[1637] | 166 | CArray<int,1> localIndexToWriteOnServer; |
---|
[1236] | 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 | void computeConnectedClients(CContextClient* client); |
---|
| 183 | private: std::set<CContextClient*> computeConnectedClients_done_; public: |
---|
| 184 | /** The number of server of a context client. Avoid to re-compute indice computed in a previous computeConnectedClient */ |
---|
| 185 | private: std::set<int> listNbServer_ ; public: |
---|
| 186 | |
---|
[631] | 187 | private: |
---|
[667] | 188 | void checkDomain(void); |
---|
| 189 | void checkLocalIDomain(void); |
---|
| 190 | void checkLocalJDomain(void); |
---|
| 191 | |
---|
| 192 | void checkMask(void); |
---|
| 193 | void checkDomainData(void); |
---|
| 194 | void checkCompression(void); |
---|
| 195 | |
---|
| 196 | void checkBounds(void); |
---|
| 197 | void checkArea(void); |
---|
| 198 | void checkLonLat(); |
---|
| 199 | |
---|
[1025] | 200 | void setTransformations(const TransMapTypes&); |
---|
[1158] | 201 | void computeNGlobDomain(); |
---|
[1870] | 202 | |
---|
| 203 | public: |
---|
| 204 | void sendDomainToFileServer(CContextClient* client) ; |
---|
| 205 | private: |
---|
| 206 | std::set<CContextClient*> sendDomainToFileServer_done_ ; |
---|
| 207 | private: |
---|
[1875] | 208 | public: |
---|
| 209 | void sendDomainToCouplerOut(CContextClient* client, const string& fieldId, int posInGrid) ; |
---|
| 210 | private: |
---|
| 211 | std::set<CContextClient*> sendDomainToCouplerOut_done_ ; |
---|
| 212 | |
---|
| 213 | public: |
---|
| 214 | void makeAliasForCoupling(const string& fieldId, int posInGrid) ; |
---|
| 215 | |
---|
| 216 | private: |
---|
| 217 | |
---|
[1870] | 218 | void sendAttributes(); // ym obsolete -> to be removed |
---|
[1875] | 219 | void sendIndex(CContextClient* client, const string& domainId=""); |
---|
| 220 | void sendDistributionAttributes(CContextClient* client, const string& domainId=""); |
---|
| 221 | void sendArea(CContextClient* client, const string& domainId=""); |
---|
| 222 | void sendLonLat(CContextClient* client, const string& domainId=""); |
---|
| 223 | void sendDataIndex(CContextClient* client, const string& domainId=""); |
---|
[1129] | 224 | void convertLonLatValue(); |
---|
[1158] | 225 | void fillInRectilinearLonLat(); |
---|
| 226 | void fillInCurvilinearLonLat(); |
---|
| 227 | void fillInUnstructuredLonLat(); |
---|
[1236] | 228 | |
---|
| 229 | static void recvDistributionAttributes(CEventServer& event); |
---|
| 230 | static void recvIndex(CEventServer& event); |
---|
| 231 | static void recvLon(CEventServer& event); |
---|
| 232 | static void recvLat(CEventServer& event); |
---|
| 233 | static void recvArea(CEventServer& event); |
---|
| 234 | static void recvDataIndex(CEventServer& event); |
---|
| 235 | void recvDistributionAttributes(CBufferIn& buffer); |
---|
| 236 | void recvIndex(std::map<int, CBufferIn*>& rankBuffers); |
---|
| 237 | void recvLon(std::map<int, CBufferIn*>& rankBuffers); |
---|
| 238 | void recvLat(std::map<int, CBufferIn*>& rankBuffers); |
---|
| 239 | void recvArea(std::map<int, CBufferIn*>& rankBuffers); |
---|
| 240 | void recvDataIndex(std::map<int, CBufferIn*>& rankBuffers); |
---|
| 241 | |
---|
| 242 | void completeLonLatClient(void); |
---|
[1869] | 243 | |
---|
| 244 | |
---|
[1025] | 245 | private: |
---|
[1345] | 246 | |
---|
| 247 | /** Clients that have to send a domain. There can be multiple clients in case of secondary server, otherwise only one client. */ |
---|
[1353] | 248 | std::list<CContextClient*> clients; |
---|
| 249 | std::set<CContextClient*> clientsSet; |
---|
[1345] | 250 | |
---|
[1129] | 251 | bool isChecked, computedWrittenIndex_; |
---|
[676] | 252 | std::set<StdString> relFiles, relFilesCompressed; |
---|
[551] | 253 | bool isClientChecked; // Verify whether all attributes of domain on the client side are good |
---|
[657] | 254 | bool isClientAfterTransformationChecked; |
---|
[1847] | 255 | |
---|
| 256 | /** 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) |
---|
| 257 | indGlobs_[rank] -> array of global index received from the client of rank "rank" |
---|
| 258 | indGlobs[rank](ind) -> global indices of the "ind" element sent. |
---|
| 259 | Defined only on server side |
---|
| 260 | */ |
---|
[1236] | 261 | std::map<int, CArray<int,1> > indGlob_; |
---|
[1025] | 262 | |
---|
[1847] | 263 | /** only on client sided : defined the number of clients which participate to a message sent to a server for longitude, lat, area, etc. attributes |
---|
| 264 | nbSender[nbServers] --> first map is related to the server distribution (ie associated with the contextClient) |
---|
| 265 | nbSenders[nbServers][server_rank]-> return the number of participants of a message sent to the server of rank "server_rank" |
---|
| 266 | */ |
---|
| 267 | std::map<int, map<int,int> > nbSenders; |
---|
| 268 | |
---|
| 269 | /** only on client side : Global index of each client sent to server: map<serverSize, map<serverRank, indexes>> |
---|
| 270 | indSrv_[nbServers] --> first map is related to the server distribution (ie associated with the contextClient) |
---|
| 271 | indSrv_[nbServers][server_rank] -> array of global index sent to the server of rank "server_rank" |
---|
| 272 | indSrv_[nbServers][server_rank](ind) --> global index on server of the local element "ind" sent (for lon, lat, mask, etc...) |
---|
| 273 | */ |
---|
[1542] | 274 | std::map<int, std::unordered_map<int, vector<size_t> > > indSrv_; |
---|
[1847] | 275 | |
---|
| 276 | /** make the mapping between the global index (the key) and the local index |
---|
| 277 | globalLocalIndexMap_[global_index] --> get the local index |
---|
| 278 | */ |
---|
| 279 | std::unordered_map<size_t,size_t> globalLocalIndexMap_; |
---|
| 280 | |
---|
| 281 | |
---|
| 282 | /** only on server side : get the rank of each clients which participate to a received message |
---|
| 283 | * recvClientRanks_[num_receiver] : client rank of the receiver "num_receiver" |
---|
| 284 | */ |
---|
[1236] | 285 | std::vector<int> recvClientRanks_; |
---|
[1847] | 286 | |
---|
[1249] | 287 | std::map<int,int> numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_; |
---|
| 288 | std::map<int, CArray<int, 1> > compressedIndexToWriteOnServer; |
---|
[1337] | 289 | std::map<int, std::vector<int> > connectedServerRank_; |
---|
[1236] | 290 | |
---|
[676] | 291 | //! True if and only if the data defined on the domain can be outputted in a compressed way |
---|
| 292 | bool isCompressible_; |
---|
[715] | 293 | bool isRedistributed_; |
---|
[1025] | 294 | TransMapTypes transformationMap_; |
---|
[657] | 295 | bool isUnstructed_; |
---|
[1847] | 296 | |
---|
[953] | 297 | |
---|
[836] | 298 | private: |
---|
| 299 | static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m); |
---|
| 300 | static std::map<StdString, ETranformationType> transformationMapList_; |
---|
| 301 | static bool _dummyTransformationMapList; |
---|
| 302 | |
---|
[540] | 303 | DECLARE_REF_FUNC(Domain,domain) |
---|
| 304 | |
---|
[219] | 305 | }; // class CDomain |
---|
| 306 | |
---|
| 307 | ///-------------------------------------------------------------- |
---|
| 308 | |
---|
| 309 | // Declare/Define CDomainGroup and CDomainDefinition |
---|
| 310 | DECLARE_GROUP(CDomain); |
---|
| 311 | |
---|
| 312 | ///-------------------------------------------------------------- |
---|
| 313 | |
---|
[335] | 314 | } // namespace xios |
---|
[219] | 315 | |
---|
[878] | 316 | #endif //__XIOS_CDomain__ |
---|