[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> |
---|
[1637] | 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=""); |
---|
[1927] | 149 | void sendGrid(void) ; |
---|
[540] | 150 | |
---|
[650] | 151 | static void recvAddDomain(CEventServer& event); |
---|
| 152 | void recvAddDomain(CBufferIn& buffer); |
---|
| 153 | static void recvAddAxis(CEventServer& event); |
---|
| 154 | void recvAddAxis(CBufferIn& buffer); |
---|
[887] | 155 | static void recvAddScalar(CEventServer& event); |
---|
| 156 | void recvAddScalar(CBufferIn& buffer); |
---|
[540] | 157 | |
---|
[650] | 158 | static bool dispatchEvent(CEventServer& event); |
---|
| 159 | static void recvIndex(CEventServer& event); |
---|
| 160 | void recvIndex(vector<int> ranks, vector<CBufferIn*> buffers); |
---|
| 161 | void sendIndex(void); |
---|
[586] | 162 | void sendIndexScalarGrid(); |
---|
[509] | 163 | |
---|
[1294] | 164 | void setContextClient(CContextClient* contextClient); |
---|
| 165 | |
---|
[509] | 166 | void computeDomConServer(); |
---|
| 167 | std::map<int, int> getDomConServerSide(); |
---|
[1330] | 168 | std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false); |
---|
| 169 | std::map<int, StdSize> getDataBufferSize(CContextClient* client, const std::string& id = "", bool bufferForWriting = false); |
---|
[540] | 170 | std::vector<StdString> getDomainList(); |
---|
| 171 | std::vector<StdString> getAxisList(); |
---|
[887] | 172 | std::vector<StdString> getScalarList(); |
---|
[540] | 173 | std::vector<CDomain*> getDomains(); |
---|
| 174 | std::vector<CAxis*> getAxis(); |
---|
[887] | 175 | std::vector<CScalar*> getScalars(); |
---|
[943] | 176 | CDomain* getDomain(int domainIndex); |
---|
| 177 | CAxis* getAxis(int axisIndex); |
---|
| 178 | CScalar* getScalar(int scalarIndex); |
---|
[551] | 179 | std::vector<int> getAxisOrder(); |
---|
[567] | 180 | std::vector<int> getGlobalDimension(); |
---|
[1236] | 181 | bool isScalarGrid() const; |
---|
[540] | 182 | |
---|
[567] | 183 | bool doGridHaveDataToWrite(); |
---|
[1235] | 184 | bool doGridHaveDataDistributed(CContextClient* client = 0); |
---|
[567] | 185 | size_t getWrittenDataSize() const; |
---|
[676] | 186 | int getNumberWrittenIndexes() const; |
---|
| 187 | int getTotalNumberWrittenIndexes() const; |
---|
| 188 | int getOffsetWrittenIndexes() const; |
---|
[567] | 189 | |
---|
[834] | 190 | CDistributionServer* getDistributionServer(); |
---|
| 191 | CDistributionClient* getDistributionClient(); |
---|
[620] | 192 | CGridTransformation* getTransformations(); |
---|
[567] | 193 | |
---|
[632] | 194 | void transformGrid(CGrid* transformGridSrc); |
---|
[775] | 195 | void completeGrid(CGrid* transformGridSrc = 0); |
---|
[687] | 196 | void doAutoDistribution(CGrid* transformGridSrc); |
---|
[619] | 197 | bool isTransformed(); |
---|
| 198 | void setTransformed(); |
---|
[890] | 199 | bool isGenerated(); |
---|
| 200 | void setGenerated(); |
---|
[823] | 201 | void addTransGridSource(CGrid* gridSrc); |
---|
| 202 | std::map<CGrid*, std::pair<bool,StdString> >& getTransGridSource(); |
---|
[824] | 203 | bool hasTransform(); |
---|
[1215] | 204 | size_t getGlobalWrittenSize(void) ; |
---|
[219] | 205 | public: |
---|
[650] | 206 | CArray<int, 1> storeIndex_client; |
---|
[1637] | 207 | CArray<bool, 1> storeMask_client; |
---|
[509] | 208 | |
---|
[1263] | 209 | /** Map containing indexes that will be sent in sendIndex(). */ |
---|
[1243] | 210 | std::map<CContextClient*, map<int, CArray<int, 1> > > storeIndex_toSrv; |
---|
| 211 | |
---|
[1263] | 212 | /** Map storing the number of senders. Key = size of receiver's intracomm */ |
---|
| 213 | std::map<int, std::map<int,int> > nbSenders; |
---|
| 214 | |
---|
| 215 | std::map<CContextClient*, std::map<int,int> > nbReadSenders; |
---|
| 216 | |
---|
[1236] | 217 | map<int, CArray<int, 1> > storeIndex_fromSrv; // Support, for now, reading with level-1 server |
---|
[1243] | 218 | |
---|
[1294] | 219 | map<int, CArray<size_t, 1> > outIndexFromClient; // Deprecated |
---|
[1243] | 220 | |
---|
[1294] | 221 | map<int, CArray<size_t, 1> > compressedOutIndexFromClient; |
---|
[1129] | 222 | |
---|
[1294] | 223 | /** Map storing received indexes. Key = sender rank, value = index array. */ |
---|
| 224 | map<int, CArray<size_t, 1> > outGlobalIndexFromClient; |
---|
| 225 | |
---|
| 226 | // Manh Ha's comment: " A client receives global index from other clients (via recvIndex) |
---|
| 227 | // then does mapping these index into local index of STORE_CLIENTINDEX |
---|
| 228 | // In this way, store_clientIndex can be used as an input of a source filter |
---|
| 229 | // Maybe we need a flag to determine whether a client wants to write. TODO " |
---|
| 230 | |
---|
| 231 | /** Map storing received data. Key = sender rank, value = data array. |
---|
| 232 | * The map is created in CGrid::computeClientIndex and filled upon receiving data in CField::recvUpdateData() */ |
---|
[1129] | 233 | map<int, CArray<size_t, 1> > outLocalIndexStoreOnClient; |
---|
| 234 | |
---|
[1294] | 235 | /** Indexes calculated based on server-like distribution. |
---|
| 236 | * They are used for writing/reading data and only calculated for server level that does the writing/reading. |
---|
| 237 | * Along with localIndexToWriteOnClient, these indexes are used to correctly place incoming data. */ |
---|
[1243] | 238 | CArray<size_t,1> localIndexToWriteOnServer; |
---|
[1129] | 239 | |
---|
[1294] | 240 | /** Indexes calculated based on client-like distribution. |
---|
| 241 | * They are used for writing/reading data and only calculated for server level that does the writing/reading. |
---|
| 242 | * Along with localIndexToWriteOnServer, these indexes are used to correctly place incoming data. */ |
---|
[1243] | 243 | CArray<size_t,1> localIndexToWriteOnClient; |
---|
| 244 | |
---|
[1025] | 245 | CArray<size_t,1> indexFromClients; |
---|
[1294] | 246 | |
---|
[1637] | 247 | bool hasMask(void) const; |
---|
[650] | 248 | void checkMask(void); |
---|
[821] | 249 | void createMask(void); |
---|
[1129] | 250 | void modifyMask(const CArray<int,1>& indexToModify, bool valueToModify = false); |
---|
| 251 | void modifyMaskSize(const std::vector<int>& newDimensionSize, bool newValue = false); |
---|
[509] | 252 | |
---|
[742] | 253 | void computeGridGlobalDimension(const std::vector<CDomain*>& domains, |
---|
| 254 | const std::vector<CAxis*>& axis, |
---|
[887] | 255 | const std::vector<CScalar*>& scalars, |
---|
| 256 | const CArray<int,1>& axisDomainOrder); |
---|
[742] | 257 | |
---|
[540] | 258 | private: |
---|
[567] | 259 | template<int N> |
---|
| 260 | void checkGridMask(CArray<bool,N>& gridMask, |
---|
[664] | 261 | const std::vector<CArray<bool,1>* >& domainMasks, |
---|
[567] | 262 | const std::vector<CArray<bool,1>* >& axisMasks, |
---|
[887] | 263 | const CArray<int,1>& axisDomainOrder, |
---|
[821] | 264 | bool createMask = false); |
---|
[623] | 265 | template<int N> |
---|
[1129] | 266 | void modifyGridMask(CArray<bool,N>& gridMask, const CArray<int,1>& indexToModify, bool valueToModify); |
---|
[623] | 267 | |
---|
[1129] | 268 | template<int N> |
---|
| 269 | void modifyGridMaskSize(CArray<bool,N>& gridMask, const std::vector<int>& eachDimSize, bool newValue); |
---|
| 270 | |
---|
[1144] | 271 | void storeField_arr(const double* const data, CArray<double, 1>& stored) const; |
---|
| 272 | void restoreField_arr(const CArray<double, 1>& stored, double* const data) const; |
---|
[1250] | 273 | void uncompressField_arr(const double* const data, CArray<double, 1>& outData) const; |
---|
[1637] | 274 | void maskField_arr(const double* const data, CArray<double, 1>& stored) const; |
---|
[1144] | 275 | |
---|
[540] | 276 | void setVirtualDomainGroup(CDomainGroup* newVDomainGroup); |
---|
| 277 | void setVirtualAxisGroup(CAxisGroup* newVAxisGroup); |
---|
[887] | 278 | void setVirtualScalarGroup(CScalarGroup* newVScalarGroup); |
---|
[567] | 279 | |
---|
[887] | 280 | void setDomainList(const std::vector<CDomain*> domains = std::vector<CDomain*>()); |
---|
[540] | 281 | void setAxisList(const std::vector<CAxis*> axis = std::vector<CAxis*>()); |
---|
[887] | 282 | void setScalarList(const std::vector<CScalar*> scalars = std::vector<CScalar*>()); |
---|
[540] | 283 | |
---|
[887] | 284 | CDomainGroup* getVirtualDomainGroup() const; |
---|
[540] | 285 | CAxisGroup* getVirtualAxisGroup() const; |
---|
[887] | 286 | CScalarGroup* getVirtualScalarGroup() const; |
---|
[619] | 287 | |
---|
[657] | 288 | void checkAttributesAfterTransformation(); |
---|
[619] | 289 | void setTransformationAlgorithms(); |
---|
[1542] | 290 | void computeIndexByElement(const std::vector<std::unordered_map<size_t,std::vector<int> > >& indexServerOnElement, |
---|
[1263] | 291 | const CContextClient* client, |
---|
[865] | 292 | CClientServerMapping::GlobalIndexMap& globalIndexOnServer); |
---|
[1158] | 293 | int computeGridGlobalDimension(std::vector<int>& globalDim, |
---|
| 294 | const std::vector<CDomain*> domains, |
---|
| 295 | const std::vector<CAxis*> axis, |
---|
| 296 | const std::vector<CScalar*> scalars, |
---|
| 297 | const CArray<int,1>& axisDomainOrder); |
---|
| 298 | int getDistributedDimension(); |
---|
[619] | 299 | |
---|
[1025] | 300 | void computeClientIndex(); |
---|
| 301 | void computeConnectedClients(); |
---|
[1202] | 302 | void computeClientIndexScalarGrid(); |
---|
| 303 | void computeConnectedClientsScalarGrid(); |
---|
[1025] | 304 | |
---|
[540] | 305 | private: |
---|
[1236] | 306 | |
---|
[1294] | 307 | /** Clients that have to send a grid. There can be multiple clients in case of secondary server, otherwise only one client. */ |
---|
[1353] | 308 | std::list<CContextClient*> clients; |
---|
| 309 | std::set<CContextClient*> clientsSet; |
---|
[1294] | 310 | |
---|
| 311 | bool isChecked; |
---|
| 312 | bool isDomainAxisChecked; |
---|
| 313 | bool isIndexSent; |
---|
| 314 | |
---|
[540] | 315 | CDomainGroup* vDomainGroup_; |
---|
| 316 | CAxisGroup* vAxisGroup_; |
---|
[887] | 317 | CScalarGroup* vScalarGroup_; |
---|
| 318 | std::vector<std::string> axisList_, domList_, scalarList_; |
---|
| 319 | bool isAxisListSet, isDomListSet, isScalarListSet; |
---|
[567] | 320 | |
---|
[1294] | 321 | /** Client-like distribution calculated based on the knowledge of the entire grid */ |
---|
[551] | 322 | CDistributionClient* clientDistribution_; |
---|
[1243] | 323 | |
---|
[1294] | 324 | /** Server-like distribution calculated upon receiving indexes */ |
---|
[552] | 325 | CDistributionServer* serverDistribution_; |
---|
[1243] | 326 | |
---|
[568] | 327 | CClientServerMapping* clientServerMap_; |
---|
[567] | 328 | size_t writtenDataSize_; |
---|
[676] | 329 | int numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_; |
---|
[1243] | 330 | |
---|
[1330] | 331 | /** Map storing local ranks of connected receivers. Key = size of receiver's intracomm. |
---|
| 332 | * It is calculated in computeConnectedClients(). */ |
---|
[1263] | 333 | std::map<int, std::vector<int> > connectedServerRank_; |
---|
[1243] | 334 | |
---|
[1330] | 335 | /** Map storing the size of data to be send. Key = size of receiver's intracomm |
---|
| 336 | * It is calculated in computeConnectedClients(). */ |
---|
[1263] | 337 | std::map<int, std::map<int,size_t> > connectedDataSize_; |
---|
[1243] | 338 | |
---|
[1330] | 339 | /** Ranks of connected receivers in case of reading. It is calculated in recvIndex(). */ |
---|
| 340 | std::vector<int> connectedServerRankRead_; |
---|
| 341 | |
---|
| 342 | /** Size of data to be send in case of reading. It is calculated in recvIndex(). */ |
---|
| 343 | std::map<int,size_t> connectedDataSizeRead_; |
---|
| 344 | |
---|
[1165] | 345 | bool isDataDistributed_; |
---|
[676] | 346 | //! True if and only if the data defined on the grid can be outputted in a compressed way |
---|
| 347 | bool isCompressible_; |
---|
| 348 | std::set<std::string> relFilesCompressed; |
---|
[619] | 349 | |
---|
[1129] | 350 | bool isTransformed_, isGenerated_; |
---|
| 351 | bool computedWrittenIndex_; |
---|
[620] | 352 | std::vector<int> axisPositionInGrid_; |
---|
| 353 | CGridTransformation* transformations_; |
---|
[1158] | 354 | bool hasDomainAxisBaseRef_; |
---|
[823] | 355 | std::map<CGrid*, std::pair<bool,StdString> > gridSrc_; |
---|
[824] | 356 | bool hasTransform_; |
---|
[1243] | 357 | |
---|
[1263] | 358 | /** Map storing global indexes of server-like (band-wise) distribution for sending to receivers. |
---|
| 359 | * Key = size of receiver's intracomm. |
---|
| 360 | */ |
---|
| 361 | // std::map<CContextClient*, CClientServerMapping::GlobalIndexMap> globalIndexOnServer_; |
---|
| 362 | std::map<int, CClientServerMapping::GlobalIndexMap> globalIndexOnServer_; |
---|
[1243] | 363 | |
---|
[1263] | 364 | |
---|
[1243] | 365 | /** List order of axis and domain in a grid, if there is a domain, it will take value 1 (true), axis 0 (false) */ |
---|
[887] | 366 | std::vector<int> order_; |
---|
[1243] | 367 | |
---|
[219] | 368 | }; // class CGrid |
---|
| 369 | |
---|
| 370 | ///-------------------------------------------------------------- |
---|
| 371 | |
---|
[369] | 372 | template <int n> |
---|
[567] | 373 | void CGrid::inputField(const CArray<double,n>& field, CArray<double,1>& stored) const |
---|
[1622] | 374 | TRY |
---|
[219] | 375 | { |
---|
[1294] | 376 | //#ifdef __XIOS_DEBUG |
---|
[369] | 377 | if (this->getDataSize() != field.numElements()) |
---|
| 378 | ERROR("void CGrid::inputField(const CArray<double,n>& field, CArray<double,1>& stored) const", |
---|
[680] | 379 | << "[ Awaiting data of size = " << this->getDataSize() << ", " |
---|
[421] | 380 | << "Received data size = " << field.numElements() << " ] " |
---|
[955] | 381 | << "The data array does not have the right size! " |
---|
[1343] | 382 | << "Grid = " << this->getId()) |
---|
[1294] | 383 | //#endif |
---|
[650] | 384 | this->storeField_arr(field.dataFirst(), stored); |
---|
[219] | 385 | } |
---|
[1622] | 386 | CATCH |
---|
[219] | 387 | |
---|
[593] | 388 | template <int n> |
---|
[1637] | 389 | void CGrid::maskField(const CArray<double,n>& field, CArray<double,1>& stored) const |
---|
| 390 | { |
---|
| 391 | //#ifdef __XIOS_DEBUG |
---|
| 392 | if (this->getDataSize() != field.numElements()) |
---|
| 393 | ERROR("void CGrid::inputField(const CArray<double,n>& field, CArray<double,1>& stored) const", |
---|
| 394 | << "[ Awaiting data of size = " << this->getDataSize() << ", " |
---|
| 395 | << "Received data size = " << field.numElements() << " ] " |
---|
| 396 | << "The data array does not have the right size! " |
---|
| 397 | << "Grid = " << this->getId()) |
---|
| 398 | //#endif |
---|
| 399 | this->maskField_arr(field.dataFirst(), stored); |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | template <int n> |
---|
[593] | 403 | void CGrid::outputField(const CArray<double,1>& stored, CArray<double,n>& field) const |
---|
[1622] | 404 | TRY |
---|
[593] | 405 | { |
---|
[1294] | 406 | //#ifdef __XIOS_DEBUG |
---|
[593] | 407 | if (this->getDataSize() != field.numElements()) |
---|
| 408 | ERROR("void CGrid::outputField(const CArray<double,1>& stored, CArray<double,n>& field) const", |
---|
| 409 | << "[ Size of the data = " << this->getDataSize() << ", " |
---|
| 410 | << "Output data size = " << field.numElements() << " ] " |
---|
[955] | 411 | << "The ouput array does not have the right size! " |
---|
[1343] | 412 | << "Grid = " << this->getId()) |
---|
[1294] | 413 | //#endif |
---|
[593] | 414 | this->restoreField_arr(stored, field.dataFirst()); |
---|
| 415 | } |
---|
[1622] | 416 | CATCH |
---|
[593] | 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 |
---|
[1622] | 426 | TRY |
---|
[1250] | 427 | { |
---|
| 428 | uncompressField_arr(data.dataFirst(), outData); |
---|
| 429 | } |
---|
[1622] | 430 | CATCH |
---|
[1250] | 431 | |
---|
[567] | 432 | template<int N> |
---|
| 433 | void CGrid::checkGridMask(CArray<bool,N>& gridMask, |
---|
[664] | 434 | const std::vector<CArray<bool,1>* >& domainMasks, |
---|
[567] | 435 | const std::vector<CArray<bool,1>* >& axisMasks, |
---|
[887] | 436 | const CArray<int,1>& axisDomainOrder, |
---|
[821] | 437 | bool createMask) |
---|
[1622] | 438 | TRY |
---|
[567] | 439 | { |
---|
[1637] | 440 | int idx = 0; |
---|
| 441 | int numElement = axisDomainOrder.numElements(); |
---|
| 442 | int dim = domainMasks.size() * 2 + axisMasks.size(); |
---|
| 443 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
| 444 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
[567] | 445 | |
---|
[1637] | 446 | std::vector<int> idxLoop(dim,0), indexMap(numElement), eachDimSize(dim); |
---|
| 447 | std::vector<int> currentIndex(dim); |
---|
| 448 | int idxDomain = 0, idxAxis = 0; |
---|
| 449 | for (int i = 0; i < numElement; ++i) |
---|
| 450 | { |
---|
| 451 | indexMap[i] = idx; |
---|
| 452 | if (2 == axisDomainOrder(i)) { |
---|
| 453 | eachDimSize[indexMap[i]] = domainP[idxDomain]->ni; |
---|
| 454 | eachDimSize[indexMap[i]+1] = domainP[idxDomain]->nj; |
---|
| 455 | idx += 2; ++idxDomain; |
---|
| 456 | } |
---|
| 457 | else if (1 == axisDomainOrder(i)) { |
---|
| 458 | // eachDimSize[indexMap[i]] = axisMasks[idxAxis]->numElements(); |
---|
| 459 | eachDimSize[indexMap[i]] = axisP[idxAxis]->n; |
---|
| 460 | ++idx; ++idxAxis; |
---|
| 461 | } |
---|
| 462 | else {}; |
---|
| 463 | } |
---|
| 464 | |
---|
| 465 | if (!gridMask.isEmpty() && !createMask) |
---|
| 466 | { |
---|
| 467 | for (int i = 0; i < dim; ++i) |
---|
[567] | 468 | { |
---|
[1637] | 469 | if (gridMask.extent(i) != eachDimSize[i]) |
---|
| 470 | ERROR("CGrid::checkMask(void)", |
---|
| 471 | << "The mask has one dimension whose size is different from the one of the local grid." << std::endl |
---|
| 472 | << "Local size of dimension " << i << " is " << eachDimSize[i] << "." << std::endl |
---|
| 473 | << "Mask size for dimension " << i << " is " << gridMask.extent(i) << "." << std::endl |
---|
| 474 | << "Grid = " << this->getId()) |
---|
[567] | 475 | } |
---|
[1637] | 476 | } |
---|
| 477 | else { |
---|
| 478 | CArrayBoolTraits<CArray<bool,N> >::resizeArray(gridMask,eachDimSize); |
---|
| 479 | gridMask = true; |
---|
| 480 | } |
---|
[567] | 481 | |
---|
[1637] | 482 | int ssize = gridMask.numElements(); |
---|
| 483 | idx = 0; |
---|
| 484 | while (idx < ssize) |
---|
| 485 | { |
---|
| 486 | for (int i = 0; i < dim-1; ++i) |
---|
[567] | 487 | { |
---|
[1637] | 488 | if (idxLoop[i] == eachDimSize[i]) |
---|
[567] | 489 | { |
---|
[1637] | 490 | idxLoop[i] = 0; |
---|
| 491 | ++idxLoop[i+1]; |
---|
[567] | 492 | } |
---|
| 493 | } |
---|
| 494 | |
---|
[1637] | 495 | // Find out outer index |
---|
| 496 | idxDomain = idxAxis = 0; |
---|
| 497 | bool maskValue = true; |
---|
| 498 | for (int i = 0; i < numElement; ++i) |
---|
[567] | 499 | { |
---|
[1637] | 500 | if (2 == axisDomainOrder(i)) |
---|
[567] | 501 | { |
---|
[1637] | 502 | int idxTmp = idxLoop[indexMap[i]] + idxLoop[indexMap[i]+1] * eachDimSize[indexMap[i]]; |
---|
| 503 | if (idxTmp < (*domainMasks[idxDomain]).numElements()) |
---|
| 504 | maskValue = maskValue && (*domainMasks[idxDomain])(idxTmp); |
---|
| 505 | else |
---|
| 506 | maskValue = false; |
---|
| 507 | ++idxDomain; |
---|
[567] | 508 | } |
---|
[1637] | 509 | else if (1 == axisDomainOrder(i)) |
---|
[567] | 510 | { |
---|
[1637] | 511 | int idxTmp = idxLoop[indexMap[i]]; |
---|
| 512 | if (idxTmp < (*axisMasks[idxAxis]).numElements()) |
---|
| 513 | maskValue = maskValue && (*axisMasks[idxAxis])(idxTmp); |
---|
| 514 | else |
---|
| 515 | maskValue = false; |
---|
[1421] | 516 | |
---|
[1637] | 517 | ++idxAxis; |
---|
[567] | 518 | } |
---|
[1637] | 519 | } |
---|
[567] | 520 | |
---|
[1637] | 521 | int maskIndex = idxLoop[0]; |
---|
| 522 | int mulDim = 1; |
---|
| 523 | for (int k = 1; k < dim; ++k) |
---|
| 524 | { |
---|
| 525 | mulDim *= eachDimSize[k-1]; |
---|
| 526 | maskIndex += idxLoop[k]*mulDim; |
---|
| 527 | } |
---|
| 528 | *(gridMask.dataFirst()+maskIndex) &= maskValue; |
---|
[1564] | 529 | |
---|
[1637] | 530 | ++idxLoop[0]; |
---|
| 531 | ++idx; |
---|
| 532 | } |
---|
[567] | 533 | } |
---|
[1622] | 534 | CATCH_DUMP_ATTR |
---|
[567] | 535 | |
---|
[1129] | 536 | template<int N> |
---|
| 537 | void CGrid::modifyGridMaskSize(CArray<bool,N>& gridMask, |
---|
| 538 | const std::vector<int>& eachDimSize, |
---|
| 539 | bool newValue) |
---|
[1622] | 540 | TRY |
---|
[1129] | 541 | { |
---|
| 542 | if (N != eachDimSize.size()) |
---|
| 543 | { |
---|
| 544 | // ERROR("CGrid::modifyGridMaskSize(CArray<bool,N>& gridMask, |
---|
| 545 | // const std::vector<int>& eachDimSize, |
---|
| 546 | // bool newValue)", |
---|
| 547 | // << "Dimension size of the mask is different from input dimension size." << std::endl |
---|
| 548 | // << "Mask dimension is " << N << "." << std::endl |
---|
| 549 | // << "Input dimension is " << eachDimSize.size() << "." << std::endl |
---|
[1343] | 550 | // << "Grid = " << this->getId()) |
---|
[1129] | 551 | } |
---|
| 552 | CArrayBoolTraits<CArray<bool,N> >::resizeArray(gridMask,eachDimSize); |
---|
| 553 | gridMask = newValue; |
---|
| 554 | } |
---|
[1622] | 555 | CATCH_DUMP_ATTR |
---|
[1129] | 556 | |
---|
| 557 | |
---|
[623] | 558 | /*! |
---|
| 559 | Modify the current mask of grid, the local index to be modified will take value false |
---|
| 560 | \param [in/out] gridMask current mask of grid |
---|
| 561 | \param [in] indexToModify local index to modify |
---|
| 562 | */ |
---|
| 563 | template<int N> |
---|
[1129] | 564 | void CGrid::modifyGridMask(CArray<bool,N>& gridMask, const CArray<int,1>& indexToModify, bool valueToModify) |
---|
[1622] | 565 | TRY |
---|
[1129] | 566 | { |
---|
[623] | 567 | int num = indexToModify.numElements(); |
---|
| 568 | for (int idx = 0; idx < num; ++idx) |
---|
| 569 | { |
---|
| 570 | *(gridMask.dataFirst()+indexToModify(idx)) = valueToModify; |
---|
| 571 | } |
---|
| 572 | } |
---|
[1622] | 573 | CATCH_DUMP_ATTR |
---|
| 574 | |
---|
[219] | 575 | ///-------------------------------------------------------------- |
---|
| 576 | |
---|
[1397] | 577 | |
---|
| 578 | |
---|
[219] | 579 | // Declare/Define CGridGroup and CGridDefinition |
---|
| 580 | DECLARE_GROUP(CGrid); |
---|
| 581 | |
---|
| 582 | ///-------------------------------------------------------------- |
---|
| 583 | |
---|
[335] | 584 | } // namespace xios |
---|
[219] | 585 | |
---|
[591] | 586 | #endif // __XIOS_CGrid__ |
---|