source: XIOS/dev/dev_olga/src/node/grid.hpp @ 1594

Last change on this file since 1594 was 1594, checked in by oabramkina, 5 years ago

Bugfix on dev: NaNs? were not necessarily replaced upon writing by default_value in case of grid mask.

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
  • Property svn:executable set to *
File size: 24.1 KB
Line 
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
19namespace 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         /// Entrees-sorties de champs
94         template <int n>
95         void inputField(const CArray<double,n>& field, CArray<double,1>& stored) const;
96         template <int n>
97         void maskField(const CArray<double,n>& field, CArray<double,1>& stored) const;
98         template <int n>
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; 
102
103         virtual void parse(xml::CXMLNode& node);
104
105         /// Destructeur ///
106         virtual ~CGrid(void);
107
108      public:
109
110         /// Accesseurs statiques ///
111         static StdString GetName(void);
112         static StdString GetDefName(void);
113
114         static ENodeType GetType(void);
115
116         /// Instanciateurs Statiques ///
117         static CGrid* createGrid(CDomain* domain);
118         static CGrid* createGrid(CDomain* domain, CAxis* axis);
119         static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
120                                  const CArray<int,1>& axisDomainOrder = CArray<int,1>());
121         static CGrid* createGrid(StdString id, const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
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);
125         static StdString generateId(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
126                                     const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder = CArray<int,1>());
127         static StdString generateId(const CGrid* gridSrc, const CGrid* gridDest);
128         static CGrid* cloneGrid(const StdString& idNewGrid, CGrid* gridSrc);
129
130      public:           
131         void computeIndexServer(void);
132         void computeIndex(void);
133         void computeIndexScalarGrid();
134         void computeWrittenIndex();
135
136         void solveDomainRef(bool checkAtt);
137         void solveAxisRef(bool checkAtt);
138         void solveScalarRef(bool checkAtt);
139         void solveDomainAxisRefInheritance(bool apply = true);
140         void solveTransformations();
141         void solveDomainAxisBaseRef();
142
143         CDomain* addDomain(const std::string& id=StdString());
144         CAxis* addAxis(const std::string& id=StdString());
145         CScalar* addScalar(const std::string& id=StdString());
146         void sendAddDomain(const std::string& id="");
147         void sendAddAxis(const std::string& id="");
148         void sendAddScalar(const std::string& id="");
149         void sendAllDomains();
150         void sendAllAxis();
151         void sendAllScalars();
152
153         static void recvAddDomain(CEventServer& event);
154         void recvAddDomain(CBufferIn& buffer);
155         static void recvAddAxis(CEventServer& event);
156         void recvAddAxis(CBufferIn& buffer);
157         static void recvAddScalar(CEventServer& event);
158         void recvAddScalar(CBufferIn& buffer);
159
160         static bool dispatchEvent(CEventServer& event);
161         static void recvIndex(CEventServer& event);
162         void recvIndex(vector<int> ranks, vector<CBufferIn*> buffers);
163         void sendIndex(void);
164         void sendIndexScalarGrid();
165
166         void setContextClient(CContextClient* contextClient);
167
168         void computeDomConServer();
169         std::map<int, int> getDomConServerSide();
170         std::map<int, StdSize> getAttributesBufferSize(CContextClient* client, bool bufferForWriting = false);
171         std::map<int, StdSize> getDataBufferSize(CContextClient* client, const std::string& id = "", bool bufferForWriting = false);
172         std::vector<StdString> getDomainList();
173         std::vector<StdString> getAxisList();
174         std::vector<StdString> getScalarList();
175         std::vector<CDomain*> getDomains();
176         std::vector<CAxis*> getAxis();
177         std::vector<CScalar*> getScalars();
178         CDomain* getDomain(int domainIndex);
179         CAxis* getAxis(int axisIndex);
180         CScalar* getScalar(int scalarIndex);
181         std::vector<int> getAxisOrder();
182         std::vector<int> getGlobalDimension();
183         bool isScalarGrid() const;         
184
185         bool doGridHaveDataToWrite();
186         bool doGridHaveDataDistributed(CContextClient* client = 0);
187         size_t getWrittenDataSize() const;
188         int getNumberWrittenIndexes() const;
189         int getTotalNumberWrittenIndexes() const;
190         int getOffsetWrittenIndexes() const;
191
192         CDistributionServer* getDistributionServer();
193         CDistributionClient* getDistributionClient();
194         CGridTransformation* getTransformations();
195
196         void transformGrid(CGrid* transformGridSrc);
197         void completeGrid(CGrid* transformGridSrc = 0);
198         void doAutoDistribution(CGrid* transformGridSrc);
199         bool isTransformed();
200         void setTransformed();
201         bool isGenerated();
202         void setGenerated();
203         void addTransGridSource(CGrid* gridSrc);
204         std::map<CGrid*, std::pair<bool,StdString> >& getTransGridSource();
205         bool hasTransform();
206         size_t getGlobalWrittenSize(void) ;
207//         void getLocalMask(CArray<bool,1>& localMask) ;
208//         template<int N>
209//         void getLocalMask(const CArray<bool,N>& gridMask, CArray<bool,1>& localMask) ;
210      public:
211         CArray<int, 1> storeIndex_client;
212         CArray<bool, 1> storeMask_client;
213
214/** Map containing indexes that will be sent in sendIndex(). */
215         std::map<CContextClient*, map<int, CArray<int, 1> > > storeIndex_toSrv;
216
217/** Map storing the number of senders. Key = size of receiver's intracomm */
218         std::map<int, std::map<int,int> > nbSenders;
219
220         std::map<CContextClient*, std::map<int,int> > nbReadSenders;
221
222         map<int, CArray<int, 1> > storeIndex_fromSrv; // Support, for now, reading with level-1 server
223
224         map<int, CArray<size_t, 1> > outIndexFromClient;  // Deprecated
225
226         map<int, CArray<size_t, 1> > compressedOutIndexFromClient;
227
228/** Map storing received indexes. Key = sender rank, value = index array. */
229         map<int, CArray<size_t, 1> > outGlobalIndexFromClient;
230
231// Manh Ha's comment: " A client receives global index from other clients (via recvIndex)
232// then does mapping these index into local index of STORE_CLIENTINDEX
233// In this way, store_clientIndex can be used as an input of a source filter
234// Maybe we need a flag to determine whether a client wants to write. TODO "
235
236/** Map storing received data. Key = sender rank, value = data array.
237 *  The map is created in CGrid::computeClientIndex and filled upon receiving data in CField::recvUpdateData() */
238         map<int, CArray<size_t, 1> > outLocalIndexStoreOnClient; 
239
240/** Indexes calculated based on server-like distribution.
241 *  They are used for writing/reading data and only calculated for server level that does the writing/reading.
242 *  Along with localIndexToWriteOnClient, these indexes are used to correctly place incoming data. */
243         CArray<size_t,1> localIndexToWriteOnServer;
244
245/** Indexes calculated based on client-like distribution.
246 *  They are used for writing/reading data and only calculated for server level that does the writing/reading.
247 *  Along with localIndexToWriteOnServer, these indexes are used to correctly place incoming data. */
248         CArray<size_t,1> localIndexToWriteOnClient;
249
250         CArray<size_t,1> indexFromClients;
251
252         bool hasMask(void) const;
253         void checkMask(void);
254         void createMask(void);
255         void modifyMask(const CArray<int,1>& indexToModify, bool valueToModify = false);
256         void modifyMaskSize(const std::vector<int>& newDimensionSize, bool newValue = false);
257
258         void computeGridGlobalDimension(const std::vector<CDomain*>& domains,
259                                         const std::vector<CAxis*>& axis,
260                                         const std::vector<CScalar*>& scalars,
261                                         const CArray<int,1>& axisDomainOrder);
262
263      private:
264       template<int N>
265       void checkGridMask(CArray<bool,N>& gridMask,
266                          const std::vector<CArray<bool,1>* >& domainMasks,
267                          const std::vector<CArray<bool,1>* >& axisMasks,
268                          const CArray<int,1>& axisDomainOrder,
269                          bool createMask = false);
270        template<int N>
271        void modifyGridMask(CArray<bool,N>& gridMask, const CArray<int,1>& indexToModify, bool valueToModify);
272
273        template<int N>
274        void modifyGridMaskSize(CArray<bool,N>& gridMask, const std::vector<int>& eachDimSize, bool newValue);
275
276        void storeField_arr(const double* const data, CArray<double, 1>& stored) const;
277        void restoreField_arr(const CArray<double, 1>& stored, double* const data) const;
278        void uncompressField_arr(const double* const data, CArray<double, 1>& outData) const;
279        void maskField_arr(const double* const data, CArray<double, 1>& stored) const;
280
281        void setVirtualDomainGroup(CDomainGroup* newVDomainGroup);
282        void setVirtualAxisGroup(CAxisGroup* newVAxisGroup);
283        void setVirtualScalarGroup(CScalarGroup* newVScalarGroup);
284
285        void setDomainList(const std::vector<CDomain*> domains = std::vector<CDomain*>());
286        void setAxisList(const std::vector<CAxis*> axis = std::vector<CAxis*>());
287        void setScalarList(const std::vector<CScalar*> scalars = std::vector<CScalar*>());
288
289        CDomainGroup* getVirtualDomainGroup() const;
290        CAxisGroup* getVirtualAxisGroup() const;
291        CScalarGroup* getVirtualScalarGroup() const;
292
293        void checkAttributesAfterTransformation();
294        void setTransformationAlgorithms();
295        void computeIndexByElement(const std::vector<std::unordered_map<size_t,std::vector<int> > >& indexServerOnElement,
296                                   const CContextClient* client,
297                                   CClientServerMapping::GlobalIndexMap& globalIndexOnServer);
298        int computeGridGlobalDimension(std::vector<int>& globalDim,
299                                       const std::vector<CDomain*> domains,
300                                       const std::vector<CAxis*> axis,
301                                       const std::vector<CScalar*> scalars,
302                                       const CArray<int,1>& axisDomainOrder);
303        int getDistributedDimension();
304
305        void computeClientIndex();
306        void computeConnectedClients();
307        void computeClientIndexScalarGrid(); 
308        void computeConnectedClientsScalarGrid(); 
309
310      private:
311
312/** Clients that have to send a grid. There can be multiple clients in case of secondary server, otherwise only one client. */
313        std::list<CContextClient*> clients;
314        std::set<CContextClient*> clientsSet;
315
316        bool isChecked;
317        bool isDomainAxisChecked;
318        bool isIndexSent;
319
320        CDomainGroup* vDomainGroup_;
321        CAxisGroup* vAxisGroup_;
322        CScalarGroup* vScalarGroup_;
323        std::vector<std::string> axisList_, domList_, scalarList_;
324        bool isAxisListSet, isDomListSet, isScalarListSet;
325
326/** Client-like distribution calculated based on the knowledge of the entire grid */
327        CDistributionClient* clientDistribution_;
328
329/** Server-like distribution calculated upon receiving indexes */
330        CDistributionServer* serverDistribution_;
331
332        CClientServerMapping* clientServerMap_;
333        size_t writtenDataSize_;
334        int numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_;
335
336/** Map storing local ranks of connected receivers. Key = size of receiver's intracomm.
337  * It is calculated in computeConnectedClients(). */
338        std::map<int, std::vector<int> > connectedServerRank_;
339
340/** Map storing the size of data to be send. Key = size of receiver's intracomm
341  * It is calculated in computeConnectedClients(). */
342        std::map<int, std::map<int,size_t> > connectedDataSize_;
343
344/** Ranks of connected receivers in case of reading. It is calculated in recvIndex(). */
345        std::vector<int> connectedServerRankRead_;
346
347/** Size of data to be send in case of reading. It is calculated in recvIndex(). */
348        std::map<int,size_t> connectedDataSizeRead_;
349
350        bool isDataDistributed_;       
351         //! True if and only if the data defined on the grid can be outputted in a compressed way
352        bool isCompressible_;
353        std::set<std::string> relFilesCompressed;
354
355        bool isTransformed_, isGenerated_;
356        bool computedWrittenIndex_;
357        std::vector<int> axisPositionInGrid_;
358        CGridTransformation* transformations_;
359        bool hasDomainAxisBaseRef_;       
360        std::map<CGrid*, std::pair<bool,StdString> > gridSrc_;
361        bool hasTransform_;
362
363/** Map storing global indexes of server-like (band-wise) distribution for sending to receivers.
364  * Key = size of receiver's intracomm.
365  */
366//        std::map<CContextClient*, CClientServerMapping::GlobalIndexMap> globalIndexOnServer_;
367        std::map<int, CClientServerMapping::GlobalIndexMap> globalIndexOnServer_;
368
369
370/** List order of axis and domain in a grid, if there is a domain, it will take value 1 (true), axis 0 (false) */
371        std::vector<int> order_;
372
373   }; // class CGrid
374
375   ///--------------------------------------------------------------
376
377   template <int n>
378   void CGrid::inputField(const CArray<double,n>& field, CArray<double,1>& stored) const
379   {
380//#ifdef __XIOS_DEBUG
381      if (this->getDataSize() != field.numElements())
382         ERROR("void CGrid::inputField(const  CArray<double,n>& field, CArray<double,1>& stored) const",
383                << "[ Awaiting data of size = " << this->getDataSize() << ", "
384                << "Received data size = "      << field.numElements() << " ] "
385                << "The data array does not have the right size! "
386                << "Grid = " << this->getId())
387//#endif
388      this->storeField_arr(field.dataFirst(), stored);
389   }
390
391   template <int n>
392   void CGrid::maskField(const CArray<double,n>& field, CArray<double,1>& stored) const
393   {
394//#ifdef __XIOS_DEBUG
395      if (this->getDataSize() != field.numElements())
396         ERROR("void CGrid::inputField(const  CArray<double,n>& field, CArray<double,1>& stored) const",
397                << "[ Awaiting data of size = " << this->getDataSize() << ", "
398                << "Received data size = "      << field.numElements() << " ] "
399                << "The data array does not have the right size! "
400                << "Grid = " << this->getId())
401//#endif
402      this->maskField_arr(field.dataFirst(), stored);
403   }
404
405   template <int n>
406   void CGrid::outputField(const CArray<double,1>& stored, CArray<double,n>& field) const
407   {
408//#ifdef __XIOS_DEBUG
409      if (this->getDataSize() != field.numElements())
410         ERROR("void CGrid::outputField(const CArray<double,1>& stored, CArray<double,n>& field) const",
411                << "[ Size of the data = " << this->getDataSize() << ", "
412                << "Output data size = "   << field.numElements() << " ] "
413                << "The ouput array does not have the right size! "
414                << "Grid = " << this->getId())
415//#endif
416      this->restoreField_arr(stored, field.dataFirst());
417   }
418
419   /*!
420     This function removes the effect of mask on received data on the server.
421     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
422     \data data received data with masking effect on the server
423     \outData data without masking effect
424   */
425   template <int N>
426   void CGrid::uncompressField(const CArray<double,N>& data, CArray<double,1>& outData) const
427   {     
428     uncompressField_arr(data.dataFirst(), outData);
429   }
430
431   template<int N>
432   void CGrid::checkGridMask(CArray<bool,N>& gridMask,
433                             const std::vector<CArray<bool,1>* >& domainMasks,
434                             const std::vector<CArray<bool,1>* >& axisMasks,
435                             const CArray<int,1>& axisDomainOrder,
436                             bool createMask)
437   {
438     int idx = 0;
439     int numElement = axisDomainOrder.numElements();
440     int dim = domainMasks.size() * 2 + axisMasks.size();
441     std::vector<CDomain*> domainP = this->getDomains();
442     std::vector<CAxis*> axisP = this->getAxis();
443
444     std::vector<int> idxLoop(dim,0), indexMap(numElement), eachDimSize(dim);
445     std::vector<int> currentIndex(dim);
446     int idxDomain = 0, idxAxis = 0;
447    for (int i = 0; i < numElement; ++i)
448    {
449      indexMap[i] = idx;
450      if (2 == axisDomainOrder(i)) {
451          eachDimSize[indexMap[i]]   = domainP[idxDomain]->ni;
452          eachDimSize[indexMap[i]+1] = domainP[idxDomain]->nj;
453          idx += 2; ++idxDomain;
454      }
455      else if (1 == axisDomainOrder(i)) {
456//        eachDimSize[indexMap[i]] = axisMasks[idxAxis]->numElements();
457        eachDimSize[indexMap[i]] = axisP[idxAxis]->n;
458        ++idx; ++idxAxis;
459      }
460      else {};
461    }
462
463    if (!gridMask.isEmpty() && !createMask)
464    {
465      for (int i = 0; i < dim; ++i)
466      {
467        if (gridMask.extent(i) != eachDimSize[i])
468          ERROR("CGrid::checkMask(void)",
469                << "The mask has one dimension whose size is different from the one of the local grid." << std::endl
470                << "Local size of dimension " << i << " is " << eachDimSize[i] << "." << std::endl
471                << "Mask size for dimension " << i << " is " << gridMask.extent(i) << "." << std::endl
472                << "Grid = " << this->getId())
473      }
474    }
475    else {
476        CArrayBoolTraits<CArray<bool,N> >::resizeArray(gridMask,eachDimSize);
477        gridMask = true;
478    }
479
480    int ssize = gridMask.numElements();
481    idx = 0;
482    while (idx < ssize)
483    {
484      for (int i = 0; i < dim-1; ++i)
485      {
486        if (idxLoop[i] == eachDimSize[i])
487        {
488          idxLoop[i] = 0;
489          ++idxLoop[i+1];
490        }
491      }
492
493      // Find out outer index
494      idxDomain = idxAxis = 0;
495      bool maskValue = true;
496      for (int i = 0; i < numElement; ++i)
497      {
498        if (2 == axisDomainOrder(i))
499        {
500          int idxTmp = idxLoop[indexMap[i]] + idxLoop[indexMap[i]+1] * eachDimSize[indexMap[i]];
501          if (idxTmp < (*domainMasks[idxDomain]).numElements())
502            maskValue = maskValue && (*domainMasks[idxDomain])(idxTmp);
503          else
504            maskValue = false;
505          ++idxDomain;
506        }
507        else if (1 == axisDomainOrder(i))
508        {
509          int idxTmp = idxLoop[indexMap[i]];
510          if (idxTmp < (*axisMasks[idxAxis]).numElements())
511            maskValue = maskValue && (*axisMasks[idxAxis])(idxTmp);
512          else
513            maskValue = false;
514
515          ++idxAxis;
516        }
517      }
518
519      int maskIndex = idxLoop[0];
520      int mulDim = 1;
521      for (int k = 1; k < dim; ++k)
522      {
523        mulDim *= eachDimSize[k-1];
524        maskIndex += idxLoop[k]*mulDim;
525      }
526      *(gridMask.dataFirst()+maskIndex) &= maskValue;
527
528      ++idxLoop[0];
529      ++idx;
530    }
531   }
532
533   template<int N>
534   void CGrid::modifyGridMaskSize(CArray<bool,N>& gridMask,
535                                  const std::vector<int>& eachDimSize,
536                                  bool newValue)
537   {
538      if (N != eachDimSize.size())
539      {
540        // ERROR("CGrid::modifyGridMaskSize(CArray<bool,N>& gridMask,
541        //                                  const std::vector<int>& eachDimSize,
542        //                                  bool newValue)",
543        //       << "Dimension size of the mask is different from input dimension size." << std::endl
544        //       << "Mask dimension is " << N << "." << std::endl
545        //       << "Input dimension is " << eachDimSize.size() << "." << std::endl
546        //       << "Grid = " << this->getId())
547      }
548      CArrayBoolTraits<CArray<bool,N> >::resizeArray(gridMask,eachDimSize);
549      gridMask = newValue;
550   }
551                                 
552
553   /*!
554     Modify the current mask of grid, the local index to be modified will take value false
555     \param [in/out] gridMask current mask of grid
556     \param [in] indexToModify local index to modify
557   */
558   template<int N>
559   void CGrid::modifyGridMask(CArray<bool,N>& gridMask, const CArray<int,1>& indexToModify, bool valueToModify)
560   {     
561     int num = indexToModify.numElements();
562     for (int idx = 0; idx < num; ++idx)
563     {
564       *(gridMask.dataFirst()+indexToModify(idx)) = valueToModify;
565     }
566   }
567   ///--------------------------------------------------------------
568
569
570/*!
571  A grid can have multiple dimension, so can its mask in the form of multi-dimension array.
572It's not a good idea to store all multi-dimension arrays corresponding to each mask.
573One of the ways is to convert this array into 1-dimension one and every process is taken place on it.
574  \param [in] multi-dimension array grid mask
575*/
576//template<int N>
577//void CGrid::getLocalMask(const CArray<bool,N>& gridMask, CArray<bool,1>& localMask)
578//{
579//  if (gridMask.isEmpty()) return ;
580//  int dim = gridMask.dimensions();
581//  std::vector<int> dimensionSizes(dim);
582//  for (int i = 0; i < dim; ++i) dimensionSizes[i] = gridMask.extent(i);
583//
584//  std::vector<int> idxLoop(dim,0);
585//  int ssize = gridMask.numElements(), idx = 0;
586//  localMask.resize(ssize);
587//  while (idx < ssize)
588//  {
589//    for (int i = 0; i < dim-1; ++i)
590//    {
591//      if (idxLoop[i] == dimensionSizes[i])
592//      {
593//        idxLoop[i] = 0;
594//        ++idxLoop[i+1];
595//      }
596//    }
597//
598//    int maskIndex = idxLoop[0];
599//    int mulDim = 1;
600//    for (int k = 1; k < dim; ++k)
601//    {
602//      mulDim *= dimensionSizes[k-1];
603//      maskIndex += idxLoop[k]*mulDim;
604//    }
605//    localMask(maskIndex) = *(gridMask.dataFirst()+maskIndex);
606//
607//    ++idxLoop[0];
608//    ++idx;
609//  }
610//}
611
612   // Declare/Define CGridGroup and CGridDefinition
613   DECLARE_GROUP(CGrid);
614
615   ///--------------------------------------------------------------
616
617} // namespace xios
618
619#endif // __XIOS_CGrid__
Note: See TracBrowser for help on using the repository browser.