[591] | 1 | #ifndef __XIOS_CGrid__ |
---|
| 2 | #define __XIOS_CGrid__ |
---|
[219] | 3 | |
---|
[591] | 4 | /// XIOS headers /// |
---|
| 5 | #include "xios_spl.hpp" |
---|
[219] | 6 | #include "group_factory.hpp" |
---|
| 7 | |
---|
| 8 | #include "declare_group.hpp" |
---|
| 9 | #include "domain.hpp" |
---|
| 10 | #include "axis.hpp" |
---|
[887] | 11 | #include "scalar.hpp" |
---|
[369] | 12 | #include "array_new.hpp" |
---|
| 13 | #include "attribute_array.hpp" |
---|
[552] | 14 | #include "distribution_server.hpp" |
---|
[553] | 15 | #include "client_server_mapping.hpp" |
---|
[567] | 16 | #include "utils.hpp" |
---|
[619] | 17 | #include "transformation_enum.hpp" |
---|
[219] | 18 | |
---|
[335] | 19 | namespace xios { |
---|
[509] | 20 | |
---|
[1564] | 21 | /// ////////////////////// Declarations ////////////////////// /// |
---|
[219] | 22 | |
---|
| 23 | class CGridGroup; |
---|
| 24 | class CGridAttributes; |
---|
[540] | 25 | class CDomainGroup; |
---|
| 26 | class CAxisGroup; |
---|
[887] | 27 | class CScalarGroup; |
---|
[219] | 28 | class CGrid; |
---|
[551] | 29 | class CDistributionClient; |
---|
[552] | 30 | class CDistributionServer; |
---|
[553] | 31 | class CServerDistributionDescription; |
---|
| 32 | class CClientServerMapping; |
---|
[620] | 33 | class CGridTransformation; |
---|
[219] | 34 | |
---|
| 35 | ///-------------------------------------------------------------- |
---|
| 36 | |
---|
| 37 | // Declare/Define CGridAttribute |
---|
| 38 | BEGIN_DECLARE_ATTRIBUTE_MAP(CGrid) |
---|
| 39 | # include "grid_attribute.conf" |
---|
| 40 | END_DECLARE_ATTRIBUTE_MAP(CGrid) |
---|
| 41 | |
---|
| 42 | ///-------------------------------------------------------------- |
---|
| 43 | |
---|
| 44 | class CGrid |
---|
| 45 | : public CObjectTemplate<CGrid> |
---|
| 46 | , public CGridAttributes |
---|
| 47 | { |
---|
| 48 | /// typedef /// |
---|
| 49 | typedef CObjectTemplate<CGrid> SuperClass; |
---|
| 50 | typedef CGridAttributes SuperClassAttribute; |
---|
| 51 | |
---|
[676] | 52 | public: |
---|
[219] | 53 | |
---|
| 54 | typedef CGridAttributes RelAttributes; |
---|
| 55 | typedef CGridGroup RelGroup; |
---|
| 56 | |
---|
[300] | 57 | enum EEventId |
---|
| 58 | { |
---|
[887] | 59 | EVENT_ID_INDEX, EVENT_ID_ADD_DOMAIN, EVENT_ID_ADD_AXIS, EVENT_ID_ADD_SCALAR |
---|
[650] | 60 | }; |
---|
[509] | 61 | |
---|
[219] | 62 | /// Constructeurs /// |
---|
| 63 | CGrid(void); |
---|
[650] | 64 | explicit CGrid(const StdString& id); |
---|
| 65 | CGrid(const CGrid& grid); // Not implemented yet. |
---|
| 66 | CGrid(const CGrid* const grid); // Not implemented yet. |
---|
[219] | 67 | |
---|
| 68 | /// Traitements /// |
---|
[509] | 69 | // void solveReference(void); |
---|
[219] | 70 | |
---|
[676] | 71 | void checkEligibilityForCompressedOutput(); |
---|
| 72 | |
---|
[509] | 73 | void solveDomainAxisRef(bool areAttributesChecked); |
---|
| 74 | |
---|
| 75 | void checkMaskIndex(bool doCalculateIndex); |
---|
| 76 | |
---|
[650] | 77 | // virtual void toBinary (StdOStream& os) const; |
---|
| 78 | // virtual void fromBinary(StdIStream& is); |
---|
[219] | 79 | |
---|
[676] | 80 | void addRelFileCompressed(const StdString& filename); |
---|
| 81 | |
---|
[219] | 82 | /// Tests /// |
---|
[676] | 83 | bool isCompressible(void) const; |
---|
| 84 | bool isWrittenCompressed(const StdString& filename) const; |
---|
[219] | 85 | |
---|
[676] | 86 | public: |
---|
[219] | 87 | |
---|
| 88 | /// Accesseurs /// |
---|
[1158] | 89 | StdSize getDimension(void); |
---|
[509] | 90 | |
---|
[286] | 91 | StdSize getDataSize(void) const; |
---|
[219] | 92 | |
---|
[1564] | 93 | /// Entrees-sorties de champs |
---|
[369] | 94 | template <int n> |
---|
[593] | 95 | void inputField(const CArray<double,n>& field, CArray<double,1>& stored) const; |
---|
| 96 | template <int n> |
---|
[1568] | 97 | void maskField(const CArray<double,n>& field, CArray<double,1>& stored) const; |
---|
| 98 | template <int n> |
---|
[1250] | 99 | void outputField(const CArray<double,1>& stored, CArray<double,n>& field) const; |
---|
| 100 | template <int n> |
---|
| 101 | void uncompressField(const CArray<double,n>& data, CArray<double,1>& outData) const; |
---|
[509] | 102 | |
---|
[650] | 103 | virtual void parse(xml::CXMLNode& node); |
---|
[540] | 104 | |
---|
[219] | 105 | /// Destructeur /// |
---|
| 106 | virtual ~CGrid(void); |
---|
| 107 | |
---|
[676] | 108 | public: |
---|
[219] | 109 | |
---|
| 110 | /// Accesseurs statiques /// |
---|
| 111 | static StdString GetName(void); |
---|
| 112 | static StdString GetDefName(void); |
---|
[509] | 113 | |
---|
[219] | 114 | static ENodeType GetType(void); |
---|
| 115 | |
---|
| 116 | /// Instanciateurs Statiques /// |
---|
[347] | 117 | static CGrid* createGrid(CDomain* domain); |
---|
| 118 | static CGrid* createGrid(CDomain* domain, CAxis* axis); |
---|
[745] | 119 | static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
[887] | 120 | const CArray<int,1>& axisDomainOrder = CArray<int,1>()); |
---|
[745] | 121 | static CGrid* createGrid(StdString id, const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
[887] | 122 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder = CArray<int,1>()); |
---|
| 123 | static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
| 124 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder); |
---|
[745] | 125 | static StdString generateId(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
[887] | 126 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder = CArray<int,1>()); |
---|
[823] | 127 | static StdString generateId(const CGrid* gridSrc, const CGrid* gridDest); |
---|
| 128 | static CGrid* cloneGrid(const StdString& idNewGrid, CGrid* gridSrc); |
---|
[219] | 129 | |
---|
[1144] | 130 | public: |
---|
[219] | 131 | void computeIndexServer(void); |
---|
| 132 | void computeIndex(void); |
---|
[586] | 133 | void computeIndexScalarGrid(); |
---|
[1129] | 134 | void computeWrittenIndex(); |
---|
[219] | 135 | |
---|
[509] | 136 | void solveDomainRef(bool checkAtt); |
---|
| 137 | void solveAxisRef(bool checkAtt); |
---|
[887] | 138 | void solveScalarRef(bool checkAtt); |
---|
[540] | 139 | void solveDomainAxisRefInheritance(bool apply = true); |
---|
[619] | 140 | void solveTransformations(); |
---|
[775] | 141 | void solveDomainAxisBaseRef(); |
---|
[509] | 142 | |
---|
[835] | 143 | CDomain* addDomain(const std::string& id=StdString()); |
---|
| 144 | CAxis* addAxis(const std::string& id=StdString()); |
---|
[887] | 145 | CScalar* addScalar(const std::string& id=StdString()); |
---|
[540] | 146 | void sendAddDomain(const std::string& id=""); |
---|
| 147 | void sendAddAxis(const std::string& id=""); |
---|
[887] | 148 | void sendAddScalar(const std::string& id=""); |
---|
[540] | 149 | void sendAllDomains(); |
---|
| 150 | void sendAllAxis(); |
---|
[887] | 151 | void sendAllScalars(); |
---|
[540] | 152 | |
---|
[650] | 153 | static void recvAddDomain(CEventServer& event); |
---|
| 154 | void recvAddDomain(CBufferIn& buffer); |
---|
| 155 | static void recvAddAxis(CEventServer& event); |
---|
| 156 | void recvAddAxis(CBufferIn& buffer); |
---|
[887] | 157 | static void recvAddScalar(CEventServer& event); |
---|
| 158 | void recvAddScalar(CBufferIn& buffer); |
---|
[540] | 159 | |
---|
[650] | 160 | static bool dispatchEvent(CEventServer& event); |
---|
| 161 | static void recvIndex(CEventServer& event); |
---|
| 162 | void recvIndex(vector<int> ranks, vector<CBufferIn*> buffers); |
---|
| 163 | void sendIndex(void); |
---|
[586] | 164 | void sendIndexScalarGrid(); |
---|
[509] | 165 | |
---|
[1294] | 166 | void setContextClient(CContextClient* contextClient); |
---|
| 167 | |
---|
[509] | 168 | void computeDomConServer(); |
---|
| 169 | std::map<int, int> getDomConServerSide(); |
---|
[1330] | 170 | std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false); |
---|
| 171 | std::map<int, StdSize> getDataBufferSize(CContextClient* client, const std::string& id = "", bool bufferForWriting = false); |
---|
[540] | 172 | std::vector<StdString> getDomainList(); |
---|
| 173 | std::vector<StdString> getAxisList(); |
---|
[887] | 174 | std::vector<StdString> getScalarList(); |
---|
[540] | 175 | std::vector<CDomain*> getDomains(); |
---|
| 176 | std::vector<CAxis*> getAxis(); |
---|
[887] | 177 | std::vector<CScalar*> getScalars(); |
---|
[943] | 178 | CDomain* getDomain(int domainIndex); |
---|
| 179 | CAxis* getAxis(int axisIndex); |
---|
| 180 | CScalar* getScalar(int scalarIndex); |
---|
[551] | 181 | std::vector<int> getAxisOrder(); |
---|
[567] | 182 | std::vector<int> getGlobalDimension(); |
---|
[1236] | 183 | bool isScalarGrid() const; |
---|
[540] | 184 | |
---|
[567] | 185 | bool doGridHaveDataToWrite(); |
---|
[1235] | 186 | bool doGridHaveDataDistributed(CContextClient* client = 0); |
---|
[567] | 187 | size_t getWrittenDataSize() const; |
---|
[676] | 188 | int getNumberWrittenIndexes() const; |
---|
| 189 | int getTotalNumberWrittenIndexes() const; |
---|
| 190 | int getOffsetWrittenIndexes() const; |
---|
[567] | 191 | |
---|
[834] | 192 | CDistributionServer* getDistributionServer(); |
---|
| 193 | CDistributionClient* getDistributionClient(); |
---|
[620] | 194 | CGridTransformation* getTransformations(); |
---|
[567] | 195 | |
---|
[632] | 196 | void transformGrid(CGrid* transformGridSrc); |
---|
[775] | 197 | void completeGrid(CGrid* transformGridSrc = 0); |
---|
[687] | 198 | void doAutoDistribution(CGrid* transformGridSrc); |
---|
[619] | 199 | bool isTransformed(); |
---|
| 200 | void setTransformed(); |
---|
[890] | 201 | bool isGenerated(); |
---|
| 202 | void setGenerated(); |
---|
[823] | 203 | void addTransGridSource(CGrid* gridSrc); |
---|
| 204 | std::map<CGrid*, std::pair<bool,StdString> >& getTransGridSource(); |
---|
[824] | 205 | bool hasTransform(); |
---|
[1215] | 206 | size_t getGlobalWrittenSize(void) ; |
---|
[1397] | 207 | void getLocalMask(CArray<bool,1>& localMask) ; |
---|
| 208 | template<int N> |
---|
| 209 | void getLocalMask(const CArray<bool,N>& gridMask, CArray<bool,1>& localMask) ; |
---|
[219] | 210 | public: |
---|
[650] | 211 | CArray<int, 1> storeIndex_client; |
---|
[1568] | 212 | CArray<bool, 1> storeMask_client; |
---|
[509] | 213 | |
---|
[1263] | 214 | /** Map containing indexes that will be sent in sendIndex(). */ |
---|
[1243] | 215 | std::map<CContextClient*, map<int, CArray<int, 1> > > storeIndex_toSrv; |
---|
| 216 | |
---|
[1263] | 217 | /** Map storing the number of senders. Key = size of receiver's intracomm */ |
---|
| 218 | std::map<int, std::map<int,int> > nbSenders; |
---|
| 219 | |
---|
| 220 | std::map<CContextClient*, std::map<int,int> > nbReadSenders; |
---|
| 221 | |
---|
[1236] | 222 | map<int, CArray<int, 1> > storeIndex_fromSrv; // Support, for now, reading with level-1 server |
---|
[1243] | 223 | |
---|
[1294] | 224 | map<int, CArray<size_t, 1> > outIndexFromClient; // Deprecated |
---|
[1243] | 225 | |
---|
[1294] | 226 | map<int, CArray<size_t, 1> > compressedOutIndexFromClient; |
---|
[1129] | 227 | |
---|
[1294] | 228 | /** Map storing received indexes. Key = sender rank, value = index array. */ |
---|
| 229 | map<int, CArray<size_t, 1> > outGlobalIndexFromClient; |
---|
| 230 | |
---|
| 231 | // Manh Ha's comment: " A client receives global index from other clients (via recvIndex) |
---|
| 232 | // then does mapping these index into local index of STORE_CLIENTINDEX |
---|
| 233 | // In this way, store_clientIndex can be used as an input of a source filter |
---|
| 234 | // Maybe we need a flag to determine whether a client wants to write. TODO " |
---|
| 235 | |
---|
| 236 | /** Map storing received data. Key = sender rank, value = data array. |
---|
| 237 | * The map is created in CGrid::computeClientIndex and filled upon receiving data in CField::recvUpdateData() */ |
---|
[1129] | 238 | map<int, CArray<size_t, 1> > outLocalIndexStoreOnClient; |
---|
| 239 | |
---|
[1294] | 240 | /** Indexes calculated based on server-like distribution. |
---|
| 241 | * They are used for writing/reading data and only calculated for server level that does the writing/reading. |
---|
| 242 | * Along with localIndexToWriteOnClient, these indexes are used to correctly place incoming data. */ |
---|
[1243] | 243 | CArray<size_t,1> localIndexToWriteOnServer; |
---|
[1129] | 244 | |
---|
[1294] | 245 | /** Indexes calculated based on client-like distribution. |
---|
| 246 | * They are used for writing/reading data and only calculated for server level that does the writing/reading. |
---|
| 247 | * Along with localIndexToWriteOnServer, these indexes are used to correctly place incoming data. */ |
---|
[1243] | 248 | CArray<size_t,1> localIndexToWriteOnClient; |
---|
| 249 | |
---|
[1025] | 250 | CArray<size_t,1> indexFromClients; |
---|
[1294] | 251 | |
---|
[650] | 252 | void checkMask(void); |
---|
[821] | 253 | void createMask(void); |
---|
[1129] | 254 | void modifyMask(const CArray<int,1>& indexToModify, bool valueToModify = false); |
---|
| 255 | void modifyMaskSize(const std::vector<int>& newDimensionSize, bool newValue = false); |
---|
[509] | 256 | |
---|
[742] | 257 | void computeGridGlobalDimension(const std::vector<CDomain*>& domains, |
---|
| 258 | const std::vector<CAxis*>& axis, |
---|
[887] | 259 | const std::vector<CScalar*>& scalars, |
---|
| 260 | const CArray<int,1>& axisDomainOrder); |
---|
[742] | 261 | |
---|
[540] | 262 | private: |
---|
[567] | 263 | template<int N> |
---|
| 264 | void checkGridMask(CArray<bool,N>& gridMask, |
---|
[664] | 265 | const std::vector<CArray<bool,1>* >& domainMasks, |
---|
[567] | 266 | const std::vector<CArray<bool,1>* >& axisMasks, |
---|
[887] | 267 | const CArray<int,1>& axisDomainOrder, |
---|
[821] | 268 | bool createMask = false); |
---|
[623] | 269 | template<int N> |
---|
[1129] | 270 | void modifyGridMask(CArray<bool,N>& gridMask, const CArray<int,1>& indexToModify, bool valueToModify); |
---|
[623] | 271 | |
---|
[1129] | 272 | template<int N> |
---|
| 273 | void modifyGridMaskSize(CArray<bool,N>& gridMask, const std::vector<int>& eachDimSize, bool newValue); |
---|
| 274 | |
---|
[1144] | 275 | void storeField_arr(const double* const data, CArray<double, 1>& stored) const; |
---|
| 276 | void restoreField_arr(const CArray<double, 1>& stored, double* const data) const; |
---|
[1250] | 277 | void uncompressField_arr(const double* const data, CArray<double, 1>& outData) const; |
---|
[1568] | 278 | void maskField_arr(const double* const data, CArray<double, 1>& stored) const; |
---|
[1144] | 279 | |
---|
[540] | 280 | void setVirtualDomainGroup(CDomainGroup* newVDomainGroup); |
---|
| 281 | void setVirtualAxisGroup(CAxisGroup* newVAxisGroup); |
---|
[887] | 282 | void setVirtualScalarGroup(CScalarGroup* newVScalarGroup); |
---|
[567] | 283 | |
---|
[887] | 284 | void setDomainList(const std::vector<CDomain*> domains = std::vector<CDomain*>()); |
---|
[540] | 285 | void setAxisList(const std::vector<CAxis*> axis = std::vector<CAxis*>()); |
---|
[887] | 286 | void setScalarList(const std::vector<CScalar*> scalars = std::vector<CScalar*>()); |
---|
[540] | 287 | |
---|
[887] | 288 | CDomainGroup* getVirtualDomainGroup() const; |
---|
[540] | 289 | CAxisGroup* getVirtualAxisGroup() const; |
---|
[887] | 290 | CScalarGroup* getVirtualScalarGroup() const; |
---|
[619] | 291 | |
---|
[657] | 292 | void checkAttributesAfterTransformation(); |
---|
[619] | 293 | void setTransformationAlgorithms(); |
---|
[1542] | 294 | void computeIndexByElement(const std::vector<std::unordered_map<size_t,std::vector<int> > >& indexServerOnElement, |
---|
[1263] | 295 | const CContextClient* client, |
---|
[865] | 296 | CClientServerMapping::GlobalIndexMap& globalIndexOnServer); |
---|
[1158] | 297 | int computeGridGlobalDimension(std::vector<int>& globalDim, |
---|
| 298 | const std::vector<CDomain*> domains, |
---|
| 299 | const std::vector<CAxis*> axis, |
---|
| 300 | const std::vector<CScalar*> scalars, |
---|
| 301 | const CArray<int,1>& axisDomainOrder); |
---|
| 302 | int getDistributedDimension(); |
---|
[619] | 303 | |
---|
[1025] | 304 | void computeClientIndex(); |
---|
| 305 | void computeConnectedClients(); |
---|
[1202] | 306 | void computeClientIndexScalarGrid(); |
---|
| 307 | void computeConnectedClientsScalarGrid(); |
---|
[1025] | 308 | |
---|
[540] | 309 | private: |
---|
[1236] | 310 | |
---|
[1294] | 311 | /** Clients that have to send a grid. There can be multiple clients in case of secondary server, otherwise only one client. */ |
---|
[1353] | 312 | std::list<CContextClient*> clients; |
---|
| 313 | std::set<CContextClient*> clientsSet; |
---|
[1294] | 314 | |
---|
| 315 | bool isChecked; |
---|
| 316 | bool isDomainAxisChecked; |
---|
| 317 | bool isIndexSent; |
---|
| 318 | |
---|
[540] | 319 | CDomainGroup* vDomainGroup_; |
---|
| 320 | CAxisGroup* vAxisGroup_; |
---|
[887] | 321 | CScalarGroup* vScalarGroup_; |
---|
| 322 | std::vector<std::string> axisList_, domList_, scalarList_; |
---|
| 323 | bool isAxisListSet, isDomListSet, isScalarListSet; |
---|
[567] | 324 | |
---|
[1294] | 325 | /** Client-like distribution calculated based on the knowledge of the entire grid */ |
---|
[551] | 326 | CDistributionClient* clientDistribution_; |
---|
[1243] | 327 | |
---|
[1294] | 328 | /** Server-like distribution calculated upon receiving indexes */ |
---|
[552] | 329 | CDistributionServer* serverDistribution_; |
---|
[1243] | 330 | |
---|
[568] | 331 | CClientServerMapping* clientServerMap_; |
---|
[567] | 332 | size_t writtenDataSize_; |
---|
[676] | 333 | int numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_; |
---|
[1243] | 334 | |
---|
[1330] | 335 | /** Map storing local ranks of connected receivers. Key = size of receiver's intracomm. |
---|
| 336 | * It is calculated in computeConnectedClients(). */ |
---|
[1263] | 337 | std::map<int, std::vector<int> > connectedServerRank_; |
---|
[1243] | 338 | |
---|
[1330] | 339 | /** Map storing the size of data to be send. Key = size of receiver's intracomm |
---|
| 340 | * It is calculated in computeConnectedClients(). */ |
---|
[1263] | 341 | std::map<int, std::map<int,size_t> > connectedDataSize_; |
---|
[1243] | 342 | |
---|
[1330] | 343 | /** Ranks of connected receivers in case of reading. It is calculated in recvIndex(). */ |
---|
| 344 | std::vector<int> connectedServerRankRead_; |
---|
| 345 | |
---|
| 346 | /** Size of data to be send in case of reading. It is calculated in recvIndex(). */ |
---|
| 347 | std::map<int,size_t> connectedDataSizeRead_; |
---|
| 348 | |
---|
[1165] | 349 | bool isDataDistributed_; |
---|
[676] | 350 | //! True if and only if the data defined on the grid can be outputted in a compressed way |
---|
| 351 | bool isCompressible_; |
---|
| 352 | std::set<std::string> relFilesCompressed; |
---|
[619] | 353 | |
---|
[1129] | 354 | bool isTransformed_, isGenerated_; |
---|
| 355 | bool computedWrittenIndex_; |
---|
[620] | 356 | std::vector<int> axisPositionInGrid_; |
---|
| 357 | CGridTransformation* transformations_; |
---|
[1158] | 358 | bool hasDomainAxisBaseRef_; |
---|
[823] | 359 | std::map<CGrid*, std::pair<bool,StdString> > gridSrc_; |
---|
[824] | 360 | bool hasTransform_; |
---|
[1243] | 361 | |
---|
[1263] | 362 | /** Map storing global indexes of server-like (band-wise) distribution for sending to receivers. |
---|
| 363 | * Key = size of receiver's intracomm. |
---|
| 364 | */ |
---|
| 365 | // std::map<CContextClient*, CClientServerMapping::GlobalIndexMap> globalIndexOnServer_; |
---|
| 366 | std::map<int, CClientServerMapping::GlobalIndexMap> globalIndexOnServer_; |
---|
[1243] | 367 | |
---|
[1263] | 368 | |
---|
[1243] | 369 | /** List order of axis and domain in a grid, if there is a domain, it will take value 1 (true), axis 0 (false) */ |
---|
[887] | 370 | std::vector<int> order_; |
---|
[1243] | 371 | |
---|
[219] | 372 | }; // class CGrid |
---|
| 373 | |
---|
| 374 | ///-------------------------------------------------------------- |
---|
| 375 | |
---|
[369] | 376 | template <int n> |
---|
[567] | 377 | void CGrid::inputField(const CArray<double,n>& field, CArray<double,1>& stored) const |
---|
[219] | 378 | { |
---|
[1294] | 379 | //#ifdef __XIOS_DEBUG |
---|
[369] | 380 | if (this->getDataSize() != field.numElements()) |
---|
| 381 | ERROR("void CGrid::inputField(const CArray<double,n>& field, CArray<double,1>& stored) const", |
---|
[680] | 382 | << "[ Awaiting data of size = " << this->getDataSize() << ", " |
---|
[421] | 383 | << "Received data size = " << field.numElements() << " ] " |
---|
[955] | 384 | << "The data array does not have the right size! " |
---|
[1343] | 385 | << "Grid = " << this->getId()) |
---|
[1294] | 386 | //#endif |
---|
[650] | 387 | this->storeField_arr(field.dataFirst(), stored); |
---|
[219] | 388 | } |
---|
| 389 | |
---|
[593] | 390 | template <int n> |
---|
[1568] | 391 | void CGrid::maskField(const CArray<double,n>& field, CArray<double,1>& stored) const |
---|
| 392 | { |
---|
| 393 | //#ifdef __XIOS_DEBUG |
---|
| 394 | if (this->getDataSize() != field.numElements()) |
---|
| 395 | ERROR("void CGrid::inputField(const CArray<double,n>& field, CArray<double,1>& stored) const", |
---|
| 396 | << "[ Awaiting data of size = " << this->getDataSize() << ", " |
---|
| 397 | << "Received data size = " << field.numElements() << " ] " |
---|
| 398 | << "The data array does not have the right size! " |
---|
| 399 | << "Grid = " << this->getId()) |
---|
| 400 | //#endif |
---|
| 401 | this->maskField_arr(field.dataFirst(), stored); |
---|
| 402 | } |
---|
| 403 | |
---|
| 404 | template <int n> |
---|
[593] | 405 | void CGrid::outputField(const CArray<double,1>& stored, CArray<double,n>& field) const |
---|
| 406 | { |
---|
[1294] | 407 | //#ifdef __XIOS_DEBUG |
---|
[593] | 408 | if (this->getDataSize() != field.numElements()) |
---|
| 409 | ERROR("void CGrid::outputField(const CArray<double,1>& stored, CArray<double,n>& field) const", |
---|
| 410 | << "[ Size of the data = " << this->getDataSize() << ", " |
---|
| 411 | << "Output data size = " << field.numElements() << " ] " |
---|
[955] | 412 | << "The ouput array does not have the right size! " |
---|
[1343] | 413 | << "Grid = " << this->getId()) |
---|
[1294] | 414 | //#endif |
---|
[593] | 415 | this->restoreField_arr(stored, field.dataFirst()); |
---|
| 416 | } |
---|
| 417 | |
---|
[1250] | 418 | /*! |
---|
| 419 | This function removes the effect of mask on received data on the server. |
---|
| 420 | This function only serve for the checking purpose. TODO: Something must be done to seperate mask and data_index from each other in received data |
---|
| 421 | \data data received data with masking effect on the server |
---|
| 422 | \outData data without masking effect |
---|
| 423 | */ |
---|
| 424 | template <int N> |
---|
| 425 | void CGrid::uncompressField(const CArray<double,N>& data, CArray<double,1>& outData) const |
---|
| 426 | { |
---|
| 427 | uncompressField_arr(data.dataFirst(), outData); |
---|
| 428 | } |
---|
| 429 | |
---|
[567] | 430 | template<int N> |
---|
| 431 | void CGrid::checkGridMask(CArray<bool,N>& gridMask, |
---|
[664] | 432 | const std::vector<CArray<bool,1>* >& domainMasks, |
---|
[567] | 433 | const std::vector<CArray<bool,1>* >& axisMasks, |
---|
[887] | 434 | const CArray<int,1>& axisDomainOrder, |
---|
[821] | 435 | bool createMask) |
---|
[567] | 436 | { |
---|
[1568] | 437 | int idx = 0; |
---|
| 438 | int numElement = axisDomainOrder.numElements(); |
---|
| 439 | int dim = domainMasks.size() * 2 + axisMasks.size(); |
---|
| 440 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
| 441 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
[567] | 442 | |
---|
[1568] | 443 | std::vector<int> idxLoop(dim,0), indexMap(numElement), eachDimSize(dim); |
---|
| 444 | std::vector<int> currentIndex(dim); |
---|
| 445 | int idxDomain = 0, idxAxis = 0; |
---|
| 446 | for (int i = 0; i < numElement; ++i) |
---|
| 447 | { |
---|
| 448 | indexMap[i] = idx; |
---|
| 449 | if (2 == axisDomainOrder(i)) { |
---|
| 450 | eachDimSize[indexMap[i]] = domainP[idxDomain]->ni; |
---|
| 451 | eachDimSize[indexMap[i]+1] = domainP[idxDomain]->nj; |
---|
| 452 | idx += 2; ++idxDomain; |
---|
| 453 | } |
---|
| 454 | else if (1 == axisDomainOrder(i)) { |
---|
| 455 | // eachDimSize[indexMap[i]] = axisMasks[idxAxis]->numElements(); |
---|
| 456 | eachDimSize[indexMap[i]] = axisP[idxAxis]->n; |
---|
| 457 | ++idx; ++idxAxis; |
---|
| 458 | } |
---|
| 459 | else {}; |
---|
| 460 | } |
---|
| 461 | |
---|
| 462 | if (!gridMask.isEmpty() && !createMask) |
---|
| 463 | { |
---|
| 464 | for (int i = 0; i < dim; ++i) |
---|
[567] | 465 | { |
---|
[1568] | 466 | if (gridMask.extent(i) != eachDimSize[i]) |
---|
| 467 | ERROR("CGrid::checkMask(void)", |
---|
| 468 | << "The mask has one dimension whose size is different from the one of the local grid." << std::endl |
---|
| 469 | << "Local size of dimension " << i << " is " << eachDimSize[i] << "." << std::endl |
---|
| 470 | << "Mask size for dimension " << i << " is " << gridMask.extent(i) << "." << std::endl |
---|
| 471 | << "Grid = " << this->getId()) |
---|
[567] | 472 | } |
---|
[1568] | 473 | } |
---|
| 474 | else { |
---|
| 475 | CArrayBoolTraits<CArray<bool,N> >::resizeArray(gridMask,eachDimSize); |
---|
| 476 | gridMask = true; |
---|
| 477 | } |
---|
[567] | 478 | |
---|
[1568] | 479 | int ssize = gridMask.numElements(); |
---|
| 480 | idx = 0; |
---|
| 481 | while (idx < ssize) |
---|
| 482 | { |
---|
| 483 | for (int i = 0; i < dim-1; ++i) |
---|
[567] | 484 | { |
---|
[1568] | 485 | if (idxLoop[i] == eachDimSize[i]) |
---|
[567] | 486 | { |
---|
[1568] | 487 | idxLoop[i] = 0; |
---|
| 488 | ++idxLoop[i+1]; |
---|
[567] | 489 | } |
---|
| 490 | } |
---|
| 491 | |
---|
[1568] | 492 | // Find out outer index |
---|
| 493 | idxDomain = idxAxis = 0; |
---|
| 494 | bool maskValue = true; |
---|
| 495 | for (int i = 0; i < numElement; ++i) |
---|
[567] | 496 | { |
---|
[1568] | 497 | if (2 == axisDomainOrder(i)) |
---|
[567] | 498 | { |
---|
[1568] | 499 | int idxTmp = idxLoop[indexMap[i]] + idxLoop[indexMap[i]+1] * eachDimSize[indexMap[i]]; |
---|
| 500 | if (idxTmp < (*domainMasks[idxDomain]).numElements()) |
---|
| 501 | maskValue = maskValue && (*domainMasks[idxDomain])(idxTmp); |
---|
| 502 | else |
---|
| 503 | maskValue = false; |
---|
| 504 | ++idxDomain; |
---|
[567] | 505 | } |
---|
[1568] | 506 | else if (1 == axisDomainOrder(i)) |
---|
[567] | 507 | { |
---|
[1568] | 508 | int idxTmp = idxLoop[indexMap[i]]; |
---|
| 509 | if (idxTmp < (*axisMasks[idxAxis]).numElements()) |
---|
| 510 | maskValue = maskValue && (*axisMasks[idxAxis])(idxTmp); |
---|
| 511 | else |
---|
| 512 | maskValue = false; |
---|
[1421] | 513 | |
---|
[1568] | 514 | ++idxAxis; |
---|
[567] | 515 | } |
---|
[1568] | 516 | } |
---|
[567] | 517 | |
---|
[1568] | 518 | int maskIndex = idxLoop[0]; |
---|
| 519 | int mulDim = 1; |
---|
| 520 | for (int k = 1; k < dim; ++k) |
---|
| 521 | { |
---|
| 522 | mulDim *= eachDimSize[k-1]; |
---|
| 523 | maskIndex += idxLoop[k]*mulDim; |
---|
| 524 | } |
---|
| 525 | *(gridMask.dataFirst()+maskIndex) &= maskValue; |
---|
[1564] | 526 | |
---|
[1568] | 527 | ++idxLoop[0]; |
---|
| 528 | ++idx; |
---|
| 529 | } |
---|
[567] | 530 | } |
---|
| 531 | |
---|
[1129] | 532 | template<int N> |
---|
| 533 | void CGrid::modifyGridMaskSize(CArray<bool,N>& gridMask, |
---|
| 534 | const std::vector<int>& eachDimSize, |
---|
| 535 | bool newValue) |
---|
| 536 | { |
---|
| 537 | if (N != eachDimSize.size()) |
---|
| 538 | { |
---|
| 539 | // ERROR("CGrid::modifyGridMaskSize(CArray<bool,N>& gridMask, |
---|
| 540 | // const std::vector<int>& eachDimSize, |
---|
| 541 | // bool newValue)", |
---|
| 542 | // << "Dimension size of the mask is different from input dimension size." << std::endl |
---|
| 543 | // << "Mask dimension is " << N << "." << std::endl |
---|
| 544 | // << "Input dimension is " << eachDimSize.size() << "." << std::endl |
---|
[1343] | 545 | // << "Grid = " << this->getId()) |
---|
[1129] | 546 | } |
---|
| 547 | CArrayBoolTraits<CArray<bool,N> >::resizeArray(gridMask,eachDimSize); |
---|
| 548 | gridMask = newValue; |
---|
| 549 | } |
---|
| 550 | |
---|
| 551 | |
---|
[623] | 552 | /*! |
---|
| 553 | Modify the current mask of grid, the local index to be modified will take value false |
---|
| 554 | \param [in/out] gridMask current mask of grid |
---|
| 555 | \param [in] indexToModify local index to modify |
---|
| 556 | */ |
---|
| 557 | template<int N> |
---|
[1129] | 558 | void CGrid::modifyGridMask(CArray<bool,N>& gridMask, const CArray<int,1>& indexToModify, bool valueToModify) |
---|
| 559 | { |
---|
[623] | 560 | int num = indexToModify.numElements(); |
---|
| 561 | for (int idx = 0; idx < num; ++idx) |
---|
| 562 | { |
---|
| 563 | *(gridMask.dataFirst()+indexToModify(idx)) = valueToModify; |
---|
| 564 | } |
---|
| 565 | } |
---|
[219] | 566 | ///-------------------------------------------------------------- |
---|
| 567 | |
---|
[1397] | 568 | |
---|
| 569 | /*! |
---|
| 570 | A grid can have multiple dimension, so can its mask in the form of multi-dimension array. |
---|
| 571 | It's not a good idea to store all multi-dimension arrays corresponding to each mask. |
---|
| 572 | One of the ways is to convert this array into 1-dimension one and every process is taken place on it. |
---|
| 573 | \param [in] multi-dimension array grid mask |
---|
| 574 | */ |
---|
| 575 | template<int N> |
---|
| 576 | void CGrid::getLocalMask(const CArray<bool,N>& gridMask, CArray<bool,1>& localMask) |
---|
| 577 | { |
---|
[1401] | 578 | if (gridMask.isEmpty()) return ; |
---|
[1397] | 579 | int dim = gridMask.dimensions(); |
---|
| 580 | std::vector<int> dimensionSizes(dim); |
---|
| 581 | for (int i = 0; i < dim; ++i) dimensionSizes[i] = gridMask.extent(i); |
---|
| 582 | |
---|
| 583 | std::vector<int> idxLoop(dim,0); |
---|
| 584 | int ssize = gridMask.numElements(), idx = 0; |
---|
| 585 | localMask.resize(ssize); |
---|
| 586 | while (idx < ssize) |
---|
| 587 | { |
---|
| 588 | for (int i = 0; i < dim-1; ++i) |
---|
| 589 | { |
---|
| 590 | if (idxLoop[i] == dimensionSizes[i]) |
---|
| 591 | { |
---|
| 592 | idxLoop[i] = 0; |
---|
| 593 | ++idxLoop[i+1]; |
---|
| 594 | } |
---|
| 595 | } |
---|
| 596 | |
---|
| 597 | int maskIndex = idxLoop[0]; |
---|
| 598 | int mulDim = 1; |
---|
| 599 | for (int k = 1; k < dim; ++k) |
---|
| 600 | { |
---|
| 601 | mulDim *= dimensionSizes[k-1]; |
---|
| 602 | maskIndex += idxLoop[k]*mulDim; |
---|
| 603 | } |
---|
| 604 | localMask(maskIndex) = *(gridMask.dataFirst()+maskIndex); |
---|
| 605 | |
---|
| 606 | ++idxLoop[0]; |
---|
| 607 | ++idx; |
---|
| 608 | } |
---|
| 609 | } |
---|
| 610 | |
---|
[219] | 611 | // Declare/Define CGridGroup and CGridDefinition |
---|
| 612 | DECLARE_GROUP(CGrid); |
---|
| 613 | |
---|
| 614 | ///-------------------------------------------------------------- |
---|
| 615 | |
---|
[335] | 616 | } // namespace xios |
---|
[219] | 617 | |
---|
[591] | 618 | #endif // __XIOS_CGrid__ |
---|