[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> |
---|
[1144] | 97 | void outputField(const CArray<double,1>& stored, CArray<double,n>& field) const; |
---|
[509] | 98 | |
---|
[650] | 99 | virtual void parse(xml::CXMLNode& node); |
---|
[540] | 100 | |
---|
[219] | 101 | /// Destructeur /// |
---|
| 102 | virtual ~CGrid(void); |
---|
| 103 | |
---|
[676] | 104 | public: |
---|
[219] | 105 | |
---|
| 106 | /// Accesseurs statiques /// |
---|
| 107 | static StdString GetName(void); |
---|
| 108 | static StdString GetDefName(void); |
---|
[509] | 109 | |
---|
[219] | 110 | static ENodeType GetType(void); |
---|
| 111 | |
---|
| 112 | /// Instanciateurs Statiques /// |
---|
[347] | 113 | static CGrid* createGrid(CDomain* domain); |
---|
| 114 | static CGrid* createGrid(CDomain* domain, CAxis* axis); |
---|
[745] | 115 | static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
[887] | 116 | const CArray<int,1>& axisDomainOrder = CArray<int,1>()); |
---|
[745] | 117 | static CGrid* createGrid(StdString id, const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
[887] | 118 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder = CArray<int,1>()); |
---|
| 119 | static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
| 120 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder); |
---|
[745] | 121 | static StdString generateId(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>()); |
---|
[823] | 123 | static StdString generateId(const CGrid* gridSrc, const CGrid* gridDest); |
---|
| 124 | static CGrid* cloneGrid(const StdString& idNewGrid, CGrid* gridSrc); |
---|
[219] | 125 | |
---|
[1144] | 126 | public: |
---|
[219] | 127 | void computeIndexServer(void); |
---|
| 128 | void computeIndex(void); |
---|
[586] | 129 | void computeIndexScalarGrid(); |
---|
[1129] | 130 | void computeWrittenIndex(); |
---|
[219] | 131 | |
---|
[509] | 132 | void solveDomainRef(bool checkAtt); |
---|
| 133 | void solveAxisRef(bool checkAtt); |
---|
[887] | 134 | void solveScalarRef(bool checkAtt); |
---|
[540] | 135 | void solveDomainAxisRefInheritance(bool apply = true); |
---|
[619] | 136 | void solveTransformations(); |
---|
[775] | 137 | void solveDomainAxisBaseRef(); |
---|
[509] | 138 | |
---|
[835] | 139 | CDomain* addDomain(const std::string& id=StdString()); |
---|
| 140 | CAxis* addAxis(const std::string& id=StdString()); |
---|
[887] | 141 | CScalar* addScalar(const std::string& id=StdString()); |
---|
[540] | 142 | void sendAddDomain(const std::string& id=""); |
---|
| 143 | void sendAddAxis(const std::string& id=""); |
---|
[887] | 144 | void sendAddScalar(const std::string& id=""); |
---|
[540] | 145 | void sendAllDomains(); |
---|
| 146 | void sendAllAxis(); |
---|
[887] | 147 | void sendAllScalars(); |
---|
[540] | 148 | |
---|
[650] | 149 | static void recvAddDomain(CEventServer& event); |
---|
| 150 | void recvAddDomain(CBufferIn& buffer); |
---|
| 151 | static void recvAddAxis(CEventServer& event); |
---|
| 152 | void recvAddAxis(CBufferIn& buffer); |
---|
[887] | 153 | static void recvAddScalar(CEventServer& event); |
---|
| 154 | void recvAddScalar(CBufferIn& buffer); |
---|
[540] | 155 | |
---|
[650] | 156 | static bool dispatchEvent(CEventServer& event); |
---|
| 157 | static void recvIndex(CEventServer& event); |
---|
| 158 | void recvIndex(vector<int> ranks, vector<CBufferIn*> buffers); |
---|
| 159 | void sendIndex(void); |
---|
[586] | 160 | void sendIndexScalarGrid(); |
---|
[509] | 161 | |
---|
| 162 | void computeDomConServer(); |
---|
| 163 | std::map<int, int> getDomConServerSide(); |
---|
[731] | 164 | std::map<int, StdSize> getAttributesBufferSize(); |
---|
[1099] | 165 | std::vector<std::map<int, StdSize> > getDataBufferSize(const std::string& id = ""); |
---|
[540] | 166 | std::vector<StdString> getDomainList(); |
---|
| 167 | std::vector<StdString> getAxisList(); |
---|
[887] | 168 | std::vector<StdString> getScalarList(); |
---|
[540] | 169 | std::vector<CDomain*> getDomains(); |
---|
| 170 | std::vector<CAxis*> getAxis(); |
---|
[887] | 171 | std::vector<CScalar*> getScalars(); |
---|
[943] | 172 | CDomain* getDomain(int domainIndex); |
---|
| 173 | CAxis* getAxis(int axisIndex); |
---|
| 174 | CScalar* getScalar(int scalarIndex); |
---|
[551] | 175 | std::vector<int> getAxisOrder(); |
---|
[567] | 176 | std::vector<int> getGlobalDimension(); |
---|
[600] | 177 | bool isScalarGrid() const; |
---|
[1158] | 178 | std::vector<int> getAxisPositionInGrid() const; |
---|
[540] | 179 | |
---|
[567] | 180 | bool doGridHaveDataToWrite(); |
---|
| 181 | bool doGridHaveDataDistributed(); |
---|
| 182 | size_t getWrittenDataSize() const; |
---|
[676] | 183 | int getNumberWrittenIndexes() const; |
---|
| 184 | int getTotalNumberWrittenIndexes() const; |
---|
| 185 | int getOffsetWrittenIndexes() const; |
---|
[567] | 186 | |
---|
[834] | 187 | CDistributionServer* getDistributionServer(); |
---|
| 188 | CDistributionClient* getDistributionClient(); |
---|
[620] | 189 | CGridTransformation* getTransformations(); |
---|
[567] | 190 | |
---|
[632] | 191 | void transformGrid(CGrid* transformGridSrc); |
---|
[775] | 192 | void completeGrid(CGrid* transformGridSrc = 0); |
---|
[687] | 193 | void doAutoDistribution(CGrid* transformGridSrc); |
---|
[619] | 194 | bool isTransformed(); |
---|
| 195 | void setTransformed(); |
---|
[890] | 196 | bool isGenerated(); |
---|
| 197 | void setGenerated(); |
---|
[823] | 198 | void addTransGridSource(CGrid* gridSrc); |
---|
| 199 | std::map<CGrid*, std::pair<bool,StdString> >& getTransGridSource(); |
---|
[824] | 200 | bool hasTransform(); |
---|
[619] | 201 | |
---|
[219] | 202 | public: |
---|
| 203 | |
---|
| 204 | /// Propriétés privées /// |
---|
| 205 | bool isChecked; |
---|
[509] | 206 | bool isDomainAxisChecked; |
---|
[551] | 207 | bool isIndexSent; |
---|
[219] | 208 | |
---|
[650] | 209 | CArray<int, 1> storeIndex_client; |
---|
[509] | 210 | |
---|
[650] | 211 | map<int, CArray<int, 1> > storeIndex_toSrv; |
---|
[1021] | 212 | map<int, CArray<int, 1> > storeIndex_fromSrv; |
---|
[1136] | 213 | std::vector<map<int,int> > nbSenders, nbReadSenders; |
---|
[509] | 214 | |
---|
[1129] | 215 | map<int, CArray<size_t, 1> > outIndexFromClient, compressedOutIndexFromClient, outGlobalIndexFromClient; |
---|
| 216 | |
---|
| 217 | // A client receives global index from other clients (via recvIndex) |
---|
| 218 | // then does mapping these index into local index of STORE_CLIENTINDEX |
---|
| 219 | // In this way, store_clientIndex can be used as an input of a source filter |
---|
| 220 | // Maybe we need a flag to determine whether a client wants to write. TODO |
---|
| 221 | map<int, CArray<size_t, 1> > outLocalIndexStoreOnClient; |
---|
| 222 | |
---|
| 223 | // If a client wants to write out data, it'll use this index. |
---|
| 224 | // A client receives global index of data from other clients (via recvIndex), |
---|
| 225 | // then does remapping these index into local index to WRITE into a file |
---|
| 226 | CArray<size_t,1> localIndexToWriteOnClient, localIndexToWriteOnServer; |
---|
| 227 | |
---|
[1025] | 228 | CArray<size_t,1> indexFromClients; |
---|
[650] | 229 | void checkMask(void); |
---|
[821] | 230 | void createMask(void); |
---|
[1129] | 231 | void modifyMask(const CArray<int,1>& indexToModify, bool valueToModify = false); |
---|
| 232 | void modifyMaskSize(const std::vector<int>& newDimensionSize, bool newValue = false); |
---|
[509] | 233 | |
---|
[742] | 234 | void computeGridGlobalDimension(const std::vector<CDomain*>& domains, |
---|
| 235 | const std::vector<CAxis*>& axis, |
---|
[887] | 236 | const std::vector<CScalar*>& scalars, |
---|
| 237 | const CArray<int,1>& axisDomainOrder); |
---|
[742] | 238 | |
---|
[540] | 239 | private: |
---|
[567] | 240 | template<int N> |
---|
| 241 | void checkGridMask(CArray<bool,N>& gridMask, |
---|
[664] | 242 | const std::vector<CArray<bool,1>* >& domainMasks, |
---|
[567] | 243 | const std::vector<CArray<bool,1>* >& axisMasks, |
---|
[887] | 244 | const CArray<int,1>& axisDomainOrder, |
---|
[821] | 245 | bool createMask = false); |
---|
[623] | 246 | template<int N> |
---|
[1129] | 247 | void modifyGridMask(CArray<bool,N>& gridMask, const CArray<int,1>& indexToModify, bool valueToModify); |
---|
[623] | 248 | |
---|
[1129] | 249 | template<int N> |
---|
| 250 | void modifyGridMaskSize(CArray<bool,N>& gridMask, const std::vector<int>& eachDimSize, bool newValue); |
---|
| 251 | |
---|
[1144] | 252 | void storeField_arr(const double* const data, CArray<double, 1>& stored) const; |
---|
| 253 | void restoreField_arr(const CArray<double, 1>& stored, double* const data) const; |
---|
| 254 | |
---|
[540] | 255 | void setVirtualDomainGroup(CDomainGroup* newVDomainGroup); |
---|
| 256 | void setVirtualAxisGroup(CAxisGroup* newVAxisGroup); |
---|
[887] | 257 | void setVirtualScalarGroup(CScalarGroup* newVScalarGroup); |
---|
[567] | 258 | |
---|
[887] | 259 | void setDomainList(const std::vector<CDomain*> domains = std::vector<CDomain*>()); |
---|
[540] | 260 | void setAxisList(const std::vector<CAxis*> axis = std::vector<CAxis*>()); |
---|
[887] | 261 | void setScalarList(const std::vector<CScalar*> scalars = std::vector<CScalar*>()); |
---|
[540] | 262 | |
---|
[887] | 263 | CDomainGroup* getVirtualDomainGroup() const; |
---|
[540] | 264 | CAxisGroup* getVirtualAxisGroup() const; |
---|
[887] | 265 | CScalarGroup* getVirtualScalarGroup() const; |
---|
[619] | 266 | |
---|
[657] | 267 | void checkAttributesAfterTransformation(); |
---|
[619] | 268 | void setTransformationAlgorithms(); |
---|
[865] | 269 | void computeIndexByElement(const std::vector<boost::unordered_map<size_t,std::vector<int> > >& indexServerOnElement, |
---|
| 270 | CClientServerMapping::GlobalIndexMap& globalIndexOnServer); |
---|
[1158] | 271 | int computeGridGlobalDimension(std::vector<int>& globalDim, |
---|
| 272 | const std::vector<CDomain*> domains, |
---|
| 273 | const std::vector<CAxis*> axis, |
---|
| 274 | const std::vector<CScalar*> scalars, |
---|
| 275 | const CArray<int,1>& axisDomainOrder); |
---|
| 276 | int getDistributedDimension(); |
---|
[619] | 277 | |
---|
[1025] | 278 | void computeClientIndex(); |
---|
| 279 | void computeConnectedClients(); |
---|
[1202] | 280 | void computeClientIndexScalarGrid(); |
---|
| 281 | void computeConnectedClientsScalarGrid(); |
---|
[1025] | 282 | |
---|
[540] | 283 | private: |
---|
| 284 | CDomainGroup* vDomainGroup_; |
---|
| 285 | CAxisGroup* vAxisGroup_; |
---|
[887] | 286 | CScalarGroup* vScalarGroup_; |
---|
| 287 | std::vector<std::string> axisList_, domList_, scalarList_; |
---|
| 288 | bool isAxisListSet, isDomListSet, isScalarListSet; |
---|
[567] | 289 | |
---|
[551] | 290 | CDistributionClient* clientDistribution_; |
---|
[552] | 291 | CDistributionServer* serverDistribution_; |
---|
[568] | 292 | CClientServerMapping* clientServerMap_; |
---|
[567] | 293 | size_t writtenDataSize_; |
---|
[676] | 294 | int numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_; |
---|
[1099] | 295 | std::vector<std::map<int,size_t> > connectedDataSize_; |
---|
| 296 | std::vector<std::vector<int> > connectedServerRank_; |
---|
[1165] | 297 | bool isDataDistributed_; |
---|
[676] | 298 | //! True if and only if the data defined on the grid can be outputted in a compressed way |
---|
| 299 | bool isCompressible_; |
---|
| 300 | std::set<std::string> relFilesCompressed; |
---|
[619] | 301 | |
---|
[1129] | 302 | bool isTransformed_, isGenerated_; |
---|
| 303 | bool computedWrittenIndex_; |
---|
[620] | 304 | std::vector<int> axisPositionInGrid_; |
---|
| 305 | CGridTransformation* transformations_; |
---|
[1158] | 306 | bool hasDomainAxisBaseRef_; |
---|
[823] | 307 | std::map<CGrid*, std::pair<bool,StdString> > gridSrc_; |
---|
[824] | 308 | bool hasTransform_; |
---|
[865] | 309 | CClientServerMapping::GlobalIndexMap globalIndexOnServer_; |
---|
[835] | 310 | // List order of axis and domain in a grid, if there is a domain, it will take value 1 (true), axis 0 (false) |
---|
[887] | 311 | std::vector<int> order_; |
---|
[219] | 312 | }; // class CGrid |
---|
| 313 | |
---|
| 314 | ///-------------------------------------------------------------- |
---|
| 315 | |
---|
[369] | 316 | template <int n> |
---|
[567] | 317 | void CGrid::inputField(const CArray<double,n>& field, CArray<double,1>& stored) const |
---|
[219] | 318 | { |
---|
[369] | 319 | if (this->getDataSize() != field.numElements()) |
---|
| 320 | ERROR("void CGrid::inputField(const CArray<double,n>& field, CArray<double,1>& stored) const", |
---|
[680] | 321 | << "[ Awaiting data of size = " << this->getDataSize() << ", " |
---|
[421] | 322 | << "Received data size = " << field.numElements() << " ] " |
---|
[955] | 323 | << "The data array does not have the right size! " |
---|
| 324 | << "Grid = " << this->GetName()) |
---|
[650] | 325 | this->storeField_arr(field.dataFirst(), stored); |
---|
[219] | 326 | } |
---|
| 327 | |
---|
[593] | 328 | template <int n> |
---|
| 329 | void CGrid::outputField(const CArray<double,1>& stored, CArray<double,n>& field) const |
---|
| 330 | { |
---|
| 331 | if (this->getDataSize() != field.numElements()) |
---|
| 332 | ERROR("void CGrid::outputField(const CArray<double,1>& stored, CArray<double,n>& field) const", |
---|
| 333 | << "[ Size of the data = " << this->getDataSize() << ", " |
---|
| 334 | << "Output data size = " << field.numElements() << " ] " |
---|
[955] | 335 | << "The ouput array does not have the right size! " |
---|
| 336 | << "Grid = " << this->GetName()) |
---|
[593] | 337 | this->restoreField_arr(stored, field.dataFirst()); |
---|
| 338 | } |
---|
| 339 | |
---|
[567] | 340 | template<int N> |
---|
| 341 | void CGrid::checkGridMask(CArray<bool,N>& gridMask, |
---|
[664] | 342 | const std::vector<CArray<bool,1>* >& domainMasks, |
---|
[567] | 343 | const std::vector<CArray<bool,1>* >& axisMasks, |
---|
[887] | 344 | const CArray<int,1>& axisDomainOrder, |
---|
[821] | 345 | bool createMask) |
---|
[567] | 346 | { |
---|
| 347 | int idx = 0; |
---|
| 348 | int numElement = axisDomainOrder.numElements(); |
---|
[650] | 349 | int dim = domainMasks.size() * 2 + axisMasks.size(); |
---|
[664] | 350 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
[567] | 351 | |
---|
| 352 | std::vector<int> idxLoop(dim,0), indexMap(numElement), eachDimSize(dim); |
---|
| 353 | std::vector<int> currentIndex(dim); |
---|
| 354 | int idxDomain = 0, idxAxis = 0; |
---|
| 355 | for (int i = 0; i < numElement; ++i) |
---|
| 356 | { |
---|
| 357 | indexMap[i] = idx; |
---|
[887] | 358 | if (2 == axisDomainOrder(i)) { |
---|
[664] | 359 | eachDimSize[indexMap[i]] = domainP[idxDomain]->ni; |
---|
| 360 | eachDimSize[indexMap[i]+1] = domainP[idxDomain]->nj; |
---|
[567] | 361 | idx += 2; ++idxDomain; |
---|
| 362 | } |
---|
[887] | 363 | else if (1 == axisDomainOrder(i)) { |
---|
[567] | 364 | eachDimSize[indexMap[i]] = axisMasks[idxAxis]->numElements(); |
---|
| 365 | ++idx; ++idxAxis; |
---|
| 366 | } |
---|
[976] | 367 | else {}; |
---|
[567] | 368 | } |
---|
| 369 | |
---|
[821] | 370 | if (!gridMask.isEmpty() && !createMask) |
---|
[567] | 371 | { |
---|
| 372 | for (int i = 0; i < dim; ++i) |
---|
| 373 | { |
---|
| 374 | if (gridMask.extent(i) != eachDimSize[i]) |
---|
[680] | 375 | ERROR("CGrid::checkMask(void)", |
---|
| 376 | << "The mask has one dimension whose size is different from the one of the local grid." << std::endl |
---|
| 377 | << "Local size of dimension " << i << " is " << eachDimSize[i] << "." << std::endl |
---|
[955] | 378 | << "Mask size for dimension " << i << " is " << gridMask.extent(i) << "." << std::endl |
---|
| 379 | << "Grid = " << this->GetName()) |
---|
[567] | 380 | } |
---|
| 381 | } |
---|
| 382 | else { |
---|
| 383 | CArrayBoolTraits<CArray<bool,N> >::resizeArray(gridMask,eachDimSize); |
---|
| 384 | gridMask = true; |
---|
| 385 | } |
---|
| 386 | |
---|
| 387 | int ssize = gridMask.numElements(); |
---|
| 388 | idx = 0; |
---|
| 389 | while (idx < ssize) |
---|
| 390 | { |
---|
| 391 | for (int i = 0; i < dim-1; ++i) |
---|
| 392 | { |
---|
| 393 | if (idxLoop[i] == eachDimSize[i]) |
---|
| 394 | { |
---|
| 395 | idxLoop[i] = 0; |
---|
| 396 | ++idxLoop[i+1]; |
---|
| 397 | } |
---|
| 398 | } |
---|
| 399 | |
---|
| 400 | // Find out outer index |
---|
| 401 | idxDomain = idxAxis = 0; |
---|
| 402 | bool maskValue = true; |
---|
| 403 | for (int i = 0; i < numElement; ++i) |
---|
| 404 | { |
---|
[887] | 405 | if (2 == axisDomainOrder(i)) |
---|
[567] | 406 | { |
---|
[664] | 407 | maskValue = maskValue && (*domainMasks[idxDomain])(idxLoop[indexMap[i]] + idxLoop[indexMap[i]+1] * eachDimSize[indexMap[i]]); |
---|
[567] | 408 | ++idxDomain; |
---|
| 409 | } |
---|
[887] | 410 | else if (1 == axisDomainOrder(i)) |
---|
[567] | 411 | { |
---|
| 412 | maskValue = maskValue && (*axisMasks[idxAxis])(idxLoop[indexMap[i]]); |
---|
| 413 | ++idxAxis; |
---|
| 414 | } |
---|
| 415 | } |
---|
| 416 | |
---|
| 417 | int maskIndex = idxLoop[0]; |
---|
| 418 | int mulDim = 1; |
---|
| 419 | for (int k = 1; k < dim; ++k) |
---|
| 420 | { |
---|
| 421 | mulDim *= eachDimSize[k-1]; |
---|
| 422 | maskIndex += idxLoop[k]*mulDim; |
---|
| 423 | } |
---|
[623] | 424 | *(gridMask.dataFirst()+maskIndex) &= maskValue; |
---|
[567] | 425 | |
---|
| 426 | ++idxLoop[0]; |
---|
| 427 | ++idx; |
---|
| 428 | } |
---|
| 429 | |
---|
| 430 | } |
---|
| 431 | |
---|
[1129] | 432 | template<int N> |
---|
| 433 | void CGrid::modifyGridMaskSize(CArray<bool,N>& gridMask, |
---|
| 434 | const std::vector<int>& eachDimSize, |
---|
| 435 | bool newValue) |
---|
| 436 | { |
---|
| 437 | if (N != eachDimSize.size()) |
---|
| 438 | { |
---|
| 439 | // ERROR("CGrid::modifyGridMaskSize(CArray<bool,N>& gridMask, |
---|
| 440 | // const std::vector<int>& eachDimSize, |
---|
| 441 | // bool newValue)", |
---|
| 442 | // << "Dimension size of the mask is different from input dimension size." << std::endl |
---|
| 443 | // << "Mask dimension is " << N << "." << std::endl |
---|
| 444 | // << "Input dimension is " << eachDimSize.size() << "." << std::endl |
---|
| 445 | // << "Grid = " << this->GetName()) |
---|
| 446 | } |
---|
| 447 | CArrayBoolTraits<CArray<bool,N> >::resizeArray(gridMask,eachDimSize); |
---|
| 448 | gridMask = newValue; |
---|
| 449 | } |
---|
| 450 | |
---|
| 451 | |
---|
[623] | 452 | /*! |
---|
| 453 | Modify the current mask of grid, the local index to be modified will take value false |
---|
| 454 | \param [in/out] gridMask current mask of grid |
---|
| 455 | \param [in] indexToModify local index to modify |
---|
| 456 | */ |
---|
| 457 | template<int N> |
---|
[1129] | 458 | void CGrid::modifyGridMask(CArray<bool,N>& gridMask, const CArray<int,1>& indexToModify, bool valueToModify) |
---|
| 459 | { |
---|
[623] | 460 | int num = indexToModify.numElements(); |
---|
| 461 | for (int idx = 0; idx < num; ++idx) |
---|
| 462 | { |
---|
| 463 | *(gridMask.dataFirst()+indexToModify(idx)) = valueToModify; |
---|
| 464 | } |
---|
| 465 | } |
---|
[219] | 466 | ///-------------------------------------------------------------- |
---|
| 467 | |
---|
| 468 | // Declare/Define CGridGroup and CGridDefinition |
---|
| 469 | DECLARE_GROUP(CGrid); |
---|
| 470 | |
---|
| 471 | ///-------------------------------------------------------------- |
---|
| 472 | |
---|
[335] | 473 | } // namespace xios |
---|
[219] | 474 | |
---|
[591] | 475 | #endif // __XIOS_CGrid__ |
---|