[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 | |
---|
[219] | 21 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
| 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 | |
---|
[1144] | 93 | /// Entrées-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> |
---|
[1250] | 97 | void outputField(const CArray<double,1>& stored, CArray<double,n>& field) const; |
---|
| 98 | template <int n> |
---|
| 99 | void uncompressField(const CArray<double,n>& data, CArray<double,1>& outData) const; |
---|
[509] | 100 | |
---|
[650] | 101 | virtual void parse(xml::CXMLNode& node); |
---|
[540] | 102 | |
---|
[219] | 103 | /// Destructeur /// |
---|
| 104 | virtual ~CGrid(void); |
---|
| 105 | |
---|
[676] | 106 | public: |
---|
[219] | 107 | |
---|
| 108 | /// Accesseurs statiques /// |
---|
| 109 | static StdString GetName(void); |
---|
| 110 | static StdString GetDefName(void); |
---|
[509] | 111 | |
---|
[219] | 112 | static ENodeType GetType(void); |
---|
| 113 | |
---|
| 114 | /// Instanciateurs Statiques /// |
---|
[347] | 115 | static CGrid* createGrid(CDomain* domain); |
---|
| 116 | static CGrid* createGrid(CDomain* domain, CAxis* axis); |
---|
[745] | 117 | static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
[887] | 118 | const CArray<int,1>& axisDomainOrder = CArray<int,1>()); |
---|
[745] | 119 | static CGrid* createGrid(StdString id, const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
[887] | 120 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder = CArray<int,1>()); |
---|
| 121 | static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
| 122 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder); |
---|
[745] | 123 | static StdString generateId(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
[887] | 124 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder = CArray<int,1>()); |
---|
[823] | 125 | static StdString generateId(const CGrid* gridSrc, const CGrid* gridDest); |
---|
| 126 | static CGrid* cloneGrid(const StdString& idNewGrid, CGrid* gridSrc); |
---|
[219] | 127 | |
---|
[1144] | 128 | public: |
---|
[219] | 129 | void computeIndexServer(void); |
---|
| 130 | void computeIndex(void); |
---|
[586] | 131 | void computeIndexScalarGrid(); |
---|
[1129] | 132 | void computeWrittenIndex(); |
---|
[219] | 133 | |
---|
[509] | 134 | void solveDomainRef(bool checkAtt); |
---|
| 135 | void solveAxisRef(bool checkAtt); |
---|
[887] | 136 | void solveScalarRef(bool checkAtt); |
---|
[540] | 137 | void solveDomainAxisRefInheritance(bool apply = true); |
---|
[619] | 138 | void solveTransformations(); |
---|
[775] | 139 | void solveDomainAxisBaseRef(); |
---|
[509] | 140 | |
---|
[835] | 141 | CDomain* addDomain(const std::string& id=StdString()); |
---|
| 142 | CAxis* addAxis(const std::string& id=StdString()); |
---|
[887] | 143 | CScalar* addScalar(const std::string& id=StdString()); |
---|
[540] | 144 | void sendAddDomain(const std::string& id=""); |
---|
| 145 | void sendAddAxis(const std::string& id=""); |
---|
[887] | 146 | void sendAddScalar(const std::string& id=""); |
---|
[540] | 147 | void sendAllDomains(); |
---|
| 148 | void sendAllAxis(); |
---|
[887] | 149 | void sendAllScalars(); |
---|
[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(); |
---|
[1236] | 168 | std::map<int, StdSize> getAttributesBufferSize(CContextClient* client); |
---|
| 169 | std::map<int, StdSize> getDataBufferSize(CContextClient* client, const std::string& id = ""); |
---|
[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) ; |
---|
[1236] | 205 | |
---|
[219] | 206 | public: |
---|
[650] | 207 | CArray<int, 1> storeIndex_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 | |
---|
[650] | 247 | void checkMask(void); |
---|
[821] | 248 | void createMask(void); |
---|
[1129] | 249 | void modifyMask(const CArray<int,1>& indexToModify, bool valueToModify = false); |
---|
| 250 | void modifyMaskSize(const std::vector<int>& newDimensionSize, bool newValue = false); |
---|
[509] | 251 | |
---|
[742] | 252 | void computeGridGlobalDimension(const std::vector<CDomain*>& domains, |
---|
| 253 | const std::vector<CAxis*>& axis, |
---|
[887] | 254 | const std::vector<CScalar*>& scalars, |
---|
| 255 | const CArray<int,1>& axisDomainOrder); |
---|
[742] | 256 | |
---|
[540] | 257 | private: |
---|
[567] | 258 | template<int N> |
---|
| 259 | void checkGridMask(CArray<bool,N>& gridMask, |
---|
[664] | 260 | const std::vector<CArray<bool,1>* >& domainMasks, |
---|
[567] | 261 | const std::vector<CArray<bool,1>* >& axisMasks, |
---|
[887] | 262 | const CArray<int,1>& axisDomainOrder, |
---|
[821] | 263 | bool createMask = false); |
---|
[623] | 264 | template<int N> |
---|
[1129] | 265 | void modifyGridMask(CArray<bool,N>& gridMask, const CArray<int,1>& indexToModify, bool valueToModify); |
---|
[623] | 266 | |
---|
[1129] | 267 | template<int N> |
---|
| 268 | void modifyGridMaskSize(CArray<bool,N>& gridMask, const std::vector<int>& eachDimSize, bool newValue); |
---|
| 269 | |
---|
[1144] | 270 | void storeField_arr(const double* const data, CArray<double, 1>& stored) const; |
---|
| 271 | void restoreField_arr(const CArray<double, 1>& stored, double* const data) const; |
---|
[1250] | 272 | void uncompressField_arr(const double* const data, CArray<double, 1>& outData) const; |
---|
[1144] | 273 | |
---|
[540] | 274 | void setVirtualDomainGroup(CDomainGroup* newVDomainGroup); |
---|
| 275 | void setVirtualAxisGroup(CAxisGroup* newVAxisGroup); |
---|
[887] | 276 | void setVirtualScalarGroup(CScalarGroup* newVScalarGroup); |
---|
[567] | 277 | |
---|
[887] | 278 | void setDomainList(const std::vector<CDomain*> domains = std::vector<CDomain*>()); |
---|
[540] | 279 | void setAxisList(const std::vector<CAxis*> axis = std::vector<CAxis*>()); |
---|
[887] | 280 | void setScalarList(const std::vector<CScalar*> scalars = std::vector<CScalar*>()); |
---|
[540] | 281 | |
---|
[887] | 282 | CDomainGroup* getVirtualDomainGroup() const; |
---|
[540] | 283 | CAxisGroup* getVirtualAxisGroup() const; |
---|
[887] | 284 | CScalarGroup* getVirtualScalarGroup() const; |
---|
[619] | 285 | |
---|
[657] | 286 | void checkAttributesAfterTransformation(); |
---|
[619] | 287 | void setTransformationAlgorithms(); |
---|
[865] | 288 | void computeIndexByElement(const std::vector<boost::unordered_map<size_t,std::vector<int> > >& indexServerOnElement, |
---|
[1263] | 289 | const CContextClient* client, |
---|
[865] | 290 | CClientServerMapping::GlobalIndexMap& globalIndexOnServer); |
---|
[1158] | 291 | int computeGridGlobalDimension(std::vector<int>& globalDim, |
---|
| 292 | const std::vector<CDomain*> domains, |
---|
| 293 | const std::vector<CAxis*> axis, |
---|
| 294 | const std::vector<CScalar*> scalars, |
---|
| 295 | const CArray<int,1>& axisDomainOrder); |
---|
| 296 | int getDistributedDimension(); |
---|
[619] | 297 | |
---|
[1025] | 298 | void computeClientIndex(); |
---|
| 299 | void computeConnectedClients(); |
---|
[1202] | 300 | void computeClientIndexScalarGrid(); |
---|
| 301 | void computeConnectedClientsScalarGrid(); |
---|
[1025] | 302 | |
---|
[540] | 303 | private: |
---|
[1236] | 304 | |
---|
[1294] | 305 | /** Clients that have to send a grid. There can be multiple clients in case of secondary server, otherwise only one client. */ |
---|
| 306 | std::set<CContextClient*> clients; |
---|
| 307 | |
---|
| 308 | bool isChecked; |
---|
| 309 | bool isDomainAxisChecked; |
---|
| 310 | bool isIndexSent; |
---|
| 311 | |
---|
[540] | 312 | CDomainGroup* vDomainGroup_; |
---|
| 313 | CAxisGroup* vAxisGroup_; |
---|
[887] | 314 | CScalarGroup* vScalarGroup_; |
---|
| 315 | std::vector<std::string> axisList_, domList_, scalarList_; |
---|
| 316 | bool isAxisListSet, isDomListSet, isScalarListSet; |
---|
[567] | 317 | |
---|
[1294] | 318 | /** Client-like distribution calculated based on the knowledge of the entire grid */ |
---|
[551] | 319 | CDistributionClient* clientDistribution_; |
---|
[1243] | 320 | |
---|
[1294] | 321 | /** Server-like distribution calculated upon receiving indexes */ |
---|
[552] | 322 | CDistributionServer* serverDistribution_; |
---|
[1243] | 323 | |
---|
[568] | 324 | CClientServerMapping* clientServerMap_; |
---|
[567] | 325 | size_t writtenDataSize_; |
---|
[676] | 326 | int numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_; |
---|
[1243] | 327 | |
---|
[1263] | 328 | /** Map storing local ranks of connected receivers. Key = size of receiver's intracomm */ |
---|
| 329 | std::map<int, std::vector<int> > connectedServerRank_; |
---|
[1243] | 330 | |
---|
[1263] | 331 | /** Map storing the size of data to be send. Key = size of receiver's intracomm */ |
---|
| 332 | std::map<int, std::map<int,size_t> > connectedDataSize_; |
---|
[1243] | 333 | |
---|
[1165] | 334 | bool isDataDistributed_; |
---|
[676] | 335 | //! True if and only if the data defined on the grid can be outputted in a compressed way |
---|
| 336 | bool isCompressible_; |
---|
| 337 | std::set<std::string> relFilesCompressed; |
---|
[619] | 338 | |
---|
[1129] | 339 | bool isTransformed_, isGenerated_; |
---|
| 340 | bool computedWrittenIndex_; |
---|
[620] | 341 | std::vector<int> axisPositionInGrid_; |
---|
| 342 | CGridTransformation* transformations_; |
---|
[1158] | 343 | bool hasDomainAxisBaseRef_; |
---|
[823] | 344 | std::map<CGrid*, std::pair<bool,StdString> > gridSrc_; |
---|
[824] | 345 | bool hasTransform_; |
---|
[1243] | 346 | |
---|
[1263] | 347 | /** Map storing global indexes of server-like (band-wise) distribution for sending to receivers. |
---|
| 348 | * Key = size of receiver's intracomm. |
---|
| 349 | */ |
---|
| 350 | // std::map<CContextClient*, CClientServerMapping::GlobalIndexMap> globalIndexOnServer_; |
---|
| 351 | std::map<int, CClientServerMapping::GlobalIndexMap> globalIndexOnServer_; |
---|
[1243] | 352 | |
---|
[1263] | 353 | |
---|
[1243] | 354 | /** List order of axis and domain in a grid, if there is a domain, it will take value 1 (true), axis 0 (false) */ |
---|
[887] | 355 | std::vector<int> order_; |
---|
[1243] | 356 | |
---|
[219] | 357 | }; // class CGrid |
---|
| 358 | |
---|
| 359 | ///-------------------------------------------------------------- |
---|
| 360 | |
---|
[369] | 361 | template <int n> |
---|
[567] | 362 | void CGrid::inputField(const CArray<double,n>& field, CArray<double,1>& stored) const |
---|
[219] | 363 | { |
---|
[1294] | 364 | //#ifdef __XIOS_DEBUG |
---|
[369] | 365 | if (this->getDataSize() != field.numElements()) |
---|
| 366 | ERROR("void CGrid::inputField(const CArray<double,n>& field, CArray<double,1>& stored) const", |
---|
[680] | 367 | << "[ Awaiting data of size = " << this->getDataSize() << ", " |
---|
[421] | 368 | << "Received data size = " << field.numElements() << " ] " |
---|
[955] | 369 | << "The data array does not have the right size! " |
---|
| 370 | << "Grid = " << this->GetName()) |
---|
[1294] | 371 | //#endif |
---|
[650] | 372 | this->storeField_arr(field.dataFirst(), stored); |
---|
[219] | 373 | } |
---|
| 374 | |
---|
[593] | 375 | template <int n> |
---|
| 376 | void CGrid::outputField(const CArray<double,1>& stored, CArray<double,n>& field) const |
---|
| 377 | { |
---|
[1294] | 378 | //#ifdef __XIOS_DEBUG |
---|
[593] | 379 | if (this->getDataSize() != field.numElements()) |
---|
| 380 | ERROR("void CGrid::outputField(const CArray<double,1>& stored, CArray<double,n>& field) const", |
---|
| 381 | << "[ Size of the data = " << this->getDataSize() << ", " |
---|
| 382 | << "Output data size = " << field.numElements() << " ] " |
---|
[955] | 383 | << "The ouput array does not have the right size! " |
---|
| 384 | << "Grid = " << this->GetName()) |
---|
[1294] | 385 | //#endif |
---|
[593] | 386 | this->restoreField_arr(stored, field.dataFirst()); |
---|
| 387 | } |
---|
| 388 | |
---|
[1250] | 389 | /*! |
---|
| 390 | This function removes the effect of mask on received data on the server. |
---|
| 391 | 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 |
---|
| 392 | \data data received data with masking effect on the server |
---|
| 393 | \outData data without masking effect |
---|
| 394 | */ |
---|
| 395 | template <int N> |
---|
| 396 | void CGrid::uncompressField(const CArray<double,N>& data, CArray<double,1>& outData) const |
---|
| 397 | { |
---|
| 398 | uncompressField_arr(data.dataFirst(), outData); |
---|
| 399 | } |
---|
| 400 | |
---|
[567] | 401 | template<int N> |
---|
| 402 | void CGrid::checkGridMask(CArray<bool,N>& gridMask, |
---|
[664] | 403 | const std::vector<CArray<bool,1>* >& domainMasks, |
---|
[567] | 404 | const std::vector<CArray<bool,1>* >& axisMasks, |
---|
[887] | 405 | const CArray<int,1>& axisDomainOrder, |
---|
[821] | 406 | bool createMask) |
---|
[567] | 407 | { |
---|
| 408 | int idx = 0; |
---|
| 409 | int numElement = axisDomainOrder.numElements(); |
---|
[650] | 410 | int dim = domainMasks.size() * 2 + axisMasks.size(); |
---|
[664] | 411 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
[567] | 412 | |
---|
| 413 | std::vector<int> idxLoop(dim,0), indexMap(numElement), eachDimSize(dim); |
---|
| 414 | std::vector<int> currentIndex(dim); |
---|
| 415 | int idxDomain = 0, idxAxis = 0; |
---|
| 416 | for (int i = 0; i < numElement; ++i) |
---|
| 417 | { |
---|
| 418 | indexMap[i] = idx; |
---|
[887] | 419 | if (2 == axisDomainOrder(i)) { |
---|
[664] | 420 | eachDimSize[indexMap[i]] = domainP[idxDomain]->ni; |
---|
| 421 | eachDimSize[indexMap[i]+1] = domainP[idxDomain]->nj; |
---|
[567] | 422 | idx += 2; ++idxDomain; |
---|
| 423 | } |
---|
[887] | 424 | else if (1 == axisDomainOrder(i)) { |
---|
[567] | 425 | eachDimSize[indexMap[i]] = axisMasks[idxAxis]->numElements(); |
---|
| 426 | ++idx; ++idxAxis; |
---|
| 427 | } |
---|
[976] | 428 | else {}; |
---|
[567] | 429 | } |
---|
| 430 | |
---|
[821] | 431 | if (!gridMask.isEmpty() && !createMask) |
---|
[567] | 432 | { |
---|
| 433 | for (int i = 0; i < dim; ++i) |
---|
| 434 | { |
---|
| 435 | if (gridMask.extent(i) != eachDimSize[i]) |
---|
[680] | 436 | ERROR("CGrid::checkMask(void)", |
---|
| 437 | << "The mask has one dimension whose size is different from the one of the local grid." << std::endl |
---|
| 438 | << "Local size of dimension " << i << " is " << eachDimSize[i] << "." << std::endl |
---|
[955] | 439 | << "Mask size for dimension " << i << " is " << gridMask.extent(i) << "." << std::endl |
---|
| 440 | << "Grid = " << this->GetName()) |
---|
[567] | 441 | } |
---|
| 442 | } |
---|
| 443 | else { |
---|
| 444 | CArrayBoolTraits<CArray<bool,N> >::resizeArray(gridMask,eachDimSize); |
---|
| 445 | gridMask = true; |
---|
| 446 | } |
---|
| 447 | |
---|
| 448 | int ssize = gridMask.numElements(); |
---|
| 449 | idx = 0; |
---|
| 450 | while (idx < ssize) |
---|
| 451 | { |
---|
| 452 | for (int i = 0; i < dim-1; ++i) |
---|
| 453 | { |
---|
| 454 | if (idxLoop[i] == eachDimSize[i]) |
---|
| 455 | { |
---|
| 456 | idxLoop[i] = 0; |
---|
| 457 | ++idxLoop[i+1]; |
---|
| 458 | } |
---|
| 459 | } |
---|
| 460 | |
---|
| 461 | // Find out outer index |
---|
| 462 | idxDomain = idxAxis = 0; |
---|
| 463 | bool maskValue = true; |
---|
| 464 | for (int i = 0; i < numElement; ++i) |
---|
| 465 | { |
---|
[887] | 466 | if (2 == axisDomainOrder(i)) |
---|
[567] | 467 | { |
---|
[664] | 468 | maskValue = maskValue && (*domainMasks[idxDomain])(idxLoop[indexMap[i]] + idxLoop[indexMap[i]+1] * eachDimSize[indexMap[i]]); |
---|
[567] | 469 | ++idxDomain; |
---|
| 470 | } |
---|
[887] | 471 | else if (1 == axisDomainOrder(i)) |
---|
[567] | 472 | { |
---|
| 473 | maskValue = maskValue && (*axisMasks[idxAxis])(idxLoop[indexMap[i]]); |
---|
| 474 | ++idxAxis; |
---|
| 475 | } |
---|
| 476 | } |
---|
| 477 | |
---|
| 478 | int maskIndex = idxLoop[0]; |
---|
| 479 | int mulDim = 1; |
---|
| 480 | for (int k = 1; k < dim; ++k) |
---|
| 481 | { |
---|
| 482 | mulDim *= eachDimSize[k-1]; |
---|
| 483 | maskIndex += idxLoop[k]*mulDim; |
---|
| 484 | } |
---|
[623] | 485 | *(gridMask.dataFirst()+maskIndex) &= maskValue; |
---|
[567] | 486 | |
---|
| 487 | ++idxLoop[0]; |
---|
| 488 | ++idx; |
---|
| 489 | } |
---|
| 490 | |
---|
| 491 | } |
---|
| 492 | |
---|
[1129] | 493 | template<int N> |
---|
| 494 | void CGrid::modifyGridMaskSize(CArray<bool,N>& gridMask, |
---|
| 495 | const std::vector<int>& eachDimSize, |
---|
| 496 | bool newValue) |
---|
| 497 | { |
---|
| 498 | if (N != eachDimSize.size()) |
---|
| 499 | { |
---|
| 500 | // ERROR("CGrid::modifyGridMaskSize(CArray<bool,N>& gridMask, |
---|
| 501 | // const std::vector<int>& eachDimSize, |
---|
| 502 | // bool newValue)", |
---|
| 503 | // << "Dimension size of the mask is different from input dimension size." << std::endl |
---|
| 504 | // << "Mask dimension is " << N << "." << std::endl |
---|
| 505 | // << "Input dimension is " << eachDimSize.size() << "." << std::endl |
---|
| 506 | // << "Grid = " << this->GetName()) |
---|
| 507 | } |
---|
| 508 | CArrayBoolTraits<CArray<bool,N> >::resizeArray(gridMask,eachDimSize); |
---|
| 509 | gridMask = newValue; |
---|
| 510 | } |
---|
| 511 | |
---|
| 512 | |
---|
[623] | 513 | /*! |
---|
| 514 | Modify the current mask of grid, the local index to be modified will take value false |
---|
| 515 | \param [in/out] gridMask current mask of grid |
---|
| 516 | \param [in] indexToModify local index to modify |
---|
| 517 | */ |
---|
| 518 | template<int N> |
---|
[1129] | 519 | void CGrid::modifyGridMask(CArray<bool,N>& gridMask, const CArray<int,1>& indexToModify, bool valueToModify) |
---|
| 520 | { |
---|
[623] | 521 | int num = indexToModify.numElements(); |
---|
| 522 | for (int idx = 0; idx < num; ++idx) |
---|
| 523 | { |
---|
| 524 | *(gridMask.dataFirst()+indexToModify(idx)) = valueToModify; |
---|
| 525 | } |
---|
| 526 | } |
---|
[219] | 527 | ///-------------------------------------------------------------- |
---|
| 528 | |
---|
| 529 | // Declare/Define CGridGroup and CGridDefinition |
---|
| 530 | DECLARE_GROUP(CGrid); |
---|
| 531 | |
---|
| 532 | ///-------------------------------------------------------------- |
---|
| 533 | |
---|
[335] | 534 | } // namespace xios |
---|
[219] | 535 | |
---|
[591] | 536 | #endif // __XIOS_CGrid__ |
---|