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