source: XIOS/trunk/src/node/grid.hpp @ 830

Last change on this file since 830 was 824, checked in by mhnguyen, 8 years ago

Correcting the behavior of field_ref

+) If a field refers to another one via field_ref and there is no transformation between
grid of this field and one of refered field, this field will inherit attributes from field_ref.

Test
+) On Curie
+) All tests pass

  • 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: 14.4 KB
RevLine 
[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"
[369]11#include "array_new.hpp"
12#include "attribute_array.hpp"
[552]13#include "distribution_server.hpp"
[553]14#include "client_server_mapping.hpp"
[567]15#include "utils.hpp"
[619]16#include "transformation_enum.hpp"
[219]17
[335]18namespace xios {
[509]19
[219]20   /// ////////////////////// Déclarations ////////////////////// ///
21
22   class CGridGroup;
23   class CGridAttributes;
[540]24   class CDomainGroup;
25   class CAxisGroup;
[219]26   class CGrid;
[551]27   class CDistributionClient;
[552]28   class CDistributionServer;
[553]29   class CServerDistributionDescription;
30   class CClientServerMapping;
[620]31   class CGridTransformation;
[219]32
33   ///--------------------------------------------------------------
34
35   // Declare/Define CGridAttribute
36   BEGIN_DECLARE_ATTRIBUTE_MAP(CGrid)
37#  include "grid_attribute.conf"
38   END_DECLARE_ATTRIBUTE_MAP(CGrid)
39
40   ///--------------------------------------------------------------
41
42   class CGrid
43      : public CObjectTemplate<CGrid>
44      , public CGridAttributes
45   {
46         /// typedef ///
47         typedef CObjectTemplate<CGrid>   SuperClass;
48         typedef CGridAttributes SuperClassAttribute;
49
[676]50      public:
[219]51
52         typedef CGridAttributes RelAttributes;
53         typedef CGridGroup      RelGroup;
54
[300]55         enum EEventId
56         {
[540]57           EVENT_ID_INDEX, EVENT_ID_ADD_DOMAIN, EVENT_ID_ADD_AXIS
[650]58         };
[509]59
[619]60         enum EElementType
61         {
62           GRID_ONLY_AXIS, GRID_ONLY_DOMAIN, GRID_AXIS_DOMAIN
63         };
64
[219]65         /// Constructeurs ///
66         CGrid(void);
[650]67         explicit CGrid(const StdString& id);
68         CGrid(const CGrid& grid);       // Not implemented yet.
69         CGrid(const CGrid* const grid); // Not implemented yet.
[219]70
71         /// Traitements ///
[509]72//         void solveReference(void);
[219]73
[676]74         void checkEligibilityForCompressedOutput();
75
[509]76         void solveDomainAxisRef(bool areAttributesChecked);
77
78         void checkMaskIndex(bool doCalculateIndex);
79
[650]80 //        virtual void toBinary  (StdOStream& os) const;
81//         virtual void fromBinary(StdIStream& is);
[219]82
[676]83         void addRelFileCompressed(const StdString& filename);
84
[219]85         /// Tests ///
[676]86         bool isCompressible(void) const;
87         bool isWrittenCompressed(const StdString& filename) const;
[219]88
[676]89      public:
[219]90
91         /// Accesseurs ///
92         StdSize getDimension(void) const;
[509]93
[286]94         StdSize  getDataSize(void) const;
[219]95
96         /// Entrées-sorties de champs ///
[369]97         template <int n>
[593]98         void inputField(const CArray<double,n>& field, CArray<double,1>& stored) const;
99         template <int n>
100         void outputField(const CArray<double,1>& stored, CArray<double,n>& field) const;
[509]101
[599]102         void outputField(int rank, const CArray<double,1>& stored, double* field);
103         void inputField(int rank, const double* const field, CArray<double,1>& stored);
[509]104
[676]105         void outputCompressedField(int rank, const CArray<double,1>& stored, double* field);
106
[650]107         virtual void parse(xml::CXMLNode& node);
[540]108
[219]109         /// Destructeur ///
110         virtual ~CGrid(void);
111
[676]112      public:
[219]113
114         /// Accesseurs statiques ///
115         static StdString GetName(void);
116         static StdString GetDefName(void);
[509]117
[219]118         static ENodeType GetType(void);
119
120         /// Instanciateurs Statiques ///
[347]121         static CGrid* createGrid(CDomain* domain);
122         static CGrid* createGrid(CDomain* domain, CAxis* axis);
[745]123         static CGrid* createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
124                                  const CArray<bool,1>& axisDomainOrder = CArray<bool,1>());
125         static CGrid* createGrid(StdString id, const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
126                                  const CArray<bool,1>& axisDomainOrder = CArray<bool,1>());
127         static StdString generateId(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
128                                     const CArray<bool,1>& axisDomainOrder = CArray<bool,1>());
[823]129         static StdString generateId(const CGrid* gridSrc, const CGrid* gridDest);
130         static CGrid* cloneGrid(const StdString& idNewGrid, CGrid* gridSrc);
[219]131
[676]132      public:
[219]133
134         /// Entrées-sorties de champs (interne) ///
[650]135         void storeField_arr(const double* const data, CArray<double,1>& stored) const;
136         void restoreField_arr(const CArray<double,1>& stored, double* const data) const;
[219]137
138         /// Traitements protégés ///
139         void computeIndexServer(void);
140         void computeIndex(void);
[586]141         void computeIndexScalarGrid();
[676]142         void computeCompressedIndex();
[219]143
[509]144         void solveDomainRef(bool checkAtt);
145         void solveAxisRef(bool checkAtt);
[540]146         void solveDomainAxisRefInheritance(bool apply = true);
[619]147         void solveTransformations();
[775]148         void solveDomainAxisBaseRef();
[509]149
[540]150         void sendAddDomain(const std::string& id="");
151         void sendAddAxis(const std::string& id="");
152         void sendAllDomains();
153         void sendAllAxis();
154
[650]155         static void recvAddDomain(CEventServer& event);
156         void recvAddDomain(CBufferIn& buffer);
157         static void recvAddAxis(CEventServer& event);
158         void recvAddAxis(CBufferIn& buffer);
[540]159
[650]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);
[586]164         void sendIndexScalarGrid();
[509]165
166         void computeDomConServer();
167         std::map<int, int> getDomConServerSide();
[731]168         std::map<int, StdSize> getAttributesBufferSize();
169         std::map<int, StdSize> getDataBufferSize(const std::string& id = "");
[540]170         std::vector<StdString> getDomainList();
171         std::vector<StdString> getAxisList();
172         std::vector<CDomain*> getDomains();
173         std::vector<CAxis*> getAxis();
[551]174         std::vector<int> getAxisOrder();
[567]175         std::vector<int> getGlobalDimension();
[600]176         bool isScalarGrid() const;
[620]177         std::vector<int> getAxisPositionInGrid() const;
[540]178
[567]179         bool doGridHaveDataToWrite();
180         bool doGridHaveDataDistributed();
181         size_t getWrittenDataSize() const;
[676]182         int getNumberWrittenIndexes() const;
183         int getTotalNumberWrittenIndexes() const;
184         int getOffsetWrittenIndexes() const;
[567]185
186         const CDistributionServer* getDistributionServer() const;
[620]187         const CDistributionClient* getDistributionClient() const;
188         CGridTransformation* getTransformations();
[567]189
[632]190         void transformGrid(CGrid* transformGridSrc);
[775]191         void completeGrid(CGrid* transformGridSrc = 0);
[687]192         void doAutoDistribution(CGrid* transformGridSrc);
[619]193         bool isTransformed();
194         void setTransformed();
[823]195         void addTransGridSource(CGrid* gridSrc);
196         std::map<CGrid*, std::pair<bool,StdString> >& getTransGridSource();
[824]197         bool hasTransform();
[619]198
[219]199      public:
200
201         /// Propriétés privées ///
202         bool isChecked;
[509]203         bool isDomainAxisChecked;
[551]204         bool isIndexSent;
[219]205
[650]206         CArray<int, 1> storeIndex_client;
[509]207
[650]208         map<int, CArray<int, 1> > storeIndex_toSrv;
209         map<int,int> nbSenders;
[509]210
[676]211         map<int, CArray<size_t, 1> > outIndexFromClient, compressedOutIndexFromClient;
[650]212         void checkMask(void);
[821]213         void createMask(void);
[623]214         void modifyMask(const CArray<int,1>& indexToModify);
[509]215
[742]216         void computeGridGlobalDimension(const std::vector<CDomain*>& domains,
217                                         const std::vector<CAxis*>& axis,
218                                         const CArray<bool,1>& axisDomainOrder);
219
[540]220      private:
[567]221       template<int N>
222       void checkGridMask(CArray<bool,N>& gridMask,
[664]223                          const std::vector<CArray<bool,1>* >& domainMasks,
[567]224                          const std::vector<CArray<bool,1>* >& axisMasks,
[821]225                          const CArray<bool,1>& axisDomainOrder,
226                          bool createMask = false);
[623]227        template<int N>
228        void modifyGridMask(CArray<bool,N>& gridMask, const CArray<int,1>& indexToModify);
229
[540]230        void setVirtualDomainGroup(CDomainGroup* newVDomainGroup);
231        void setVirtualDomainGroup();
232        void setVirtualAxisGroup(CAxisGroup* newVAxisGroup);
233        void setVirtualAxisGroup();
[567]234
[540]235        void setAxisList(const std::vector<CAxis*> axis = std::vector<CAxis*>());
236        void setDomainList(const std::vector<CDomain*> domains = std::vector<CDomain*>());
237
238        CDomain* addDomain(const std::string& id);
239        CAxis* addAxis(const std::string& id);
240
241        CAxisGroup* getVirtualAxisGroup() const;
242        CDomainGroup* getVirtualDomainGroup() const;
[619]243
[657]244        void checkAttributesAfterTransformation();
[619]245
[657]246
[619]247        void setTransformationAlgorithms();
248
[676]249
[823]250
[540]251      private:
252        CDomainGroup* vDomainGroup_;
253        CAxisGroup* vAxisGroup_;
254        std::vector<std::string> axisList_, domList_;
255        bool isAxisListSet, isDomListSet;
[567]256
[551]257        CDistributionClient* clientDistribution_;
[552]258        CDistributionServer* serverDistribution_;
[568]259        CClientServerMapping* clientServerMap_;
[567]260        size_t writtenDataSize_;
[676]261        int numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_;
[584]262        std::map<int,size_t> connectedDataSize_;
263        std::vector<int> connectedServerRank_;
[586]264        bool isDataDistributed_;
[657]265        int positionDimensionDistributed_;
[676]266         //! True if and only if the data defined on the grid can be outputted in a compressed way
267        bool isCompressible_;
268        std::set<std::string> relFilesCompressed;
[619]269
270        bool isTransformed_;
[620]271        std::vector<int> axisPositionInGrid_;
272        CGridTransformation* transformations_;
[775]273        bool hasDomainAxisBaseRef_;
[823]274        std::vector<int> globalDim_;
275        std::map<CGrid*, std::pair<bool,StdString> > gridSrc_;
[824]276        bool hasTransform_;
[219]277   }; // class CGrid
278
279   ///--------------------------------------------------------------
280
[369]281   template <int n>
[567]282   void CGrid::inputField(const CArray<double,n>& field, CArray<double,1>& stored) const
[219]283   {
[369]284      if (this->getDataSize() != field.numElements())
285         ERROR("void CGrid::inputField(const  CArray<double,n>& field, CArray<double,1>& stored) const",
[680]286                << "[ Awaiting data of size = " << this->getDataSize() << ", "
[421]287                << "Received data size = "      << field.numElements() << " ] "
[680]288                << "The data array does not have the right size!")
[650]289      this->storeField_arr(field.dataFirst(), stored);
[219]290   }
291
[593]292   template <int n>
293   void CGrid::outputField(const CArray<double,1>& stored, CArray<double,n>& field) const
294   {
295      if (this->getDataSize() != field.numElements())
296         ERROR("void CGrid::outputField(const CArray<double,1>& stored, CArray<double,n>& field) const",
297                << "[ Size of the data = " << this->getDataSize() << ", "
298                << "Output data size = "   << field.numElements() << " ] "
[680]299                << "The ouput array does not have the right size!")
[593]300      this->restoreField_arr(stored, field.dataFirst());
301   }
302
[567]303   template<int N>
304   void CGrid::checkGridMask(CArray<bool,N>& gridMask,
[664]305                             const std::vector<CArray<bool,1>* >& domainMasks,
[567]306                             const std::vector<CArray<bool,1>* >& axisMasks,
[821]307                             const CArray<bool,1>& axisDomainOrder,
308                             bool createMask)
[567]309   {
310     int idx = 0;
311     int numElement = axisDomainOrder.numElements();
[650]312     int dim = domainMasks.size() * 2 + axisMasks.size();
[664]313     std::vector<CDomain*> domainP = this->getDomains();
[567]314
315     std::vector<int> idxLoop(dim,0), indexMap(numElement), eachDimSize(dim);
316     std::vector<int> currentIndex(dim);
317     int idxDomain = 0, idxAxis = 0;
318    for (int i = 0; i < numElement; ++i)
319    {
320      indexMap[i] = idx;
321      if (true == axisDomainOrder(i)) {
[664]322          eachDimSize[indexMap[i]]   = domainP[idxDomain]->ni;
323          eachDimSize[indexMap[i]+1] = domainP[idxDomain]->nj;
[567]324          idx += 2; ++idxDomain;
325      }
326      else {
327        eachDimSize[indexMap[i]] = axisMasks[idxAxis]->numElements();
328        ++idx; ++idxAxis;
329      }
330    }
331
[821]332    if (!gridMask.isEmpty() && !createMask)
[567]333    {
334      for (int i = 0; i < dim; ++i)
335      {
336        if (gridMask.extent(i) != eachDimSize[i])
[680]337          ERROR("CGrid::checkMask(void)",
338                << "The mask has one dimension whose size is different from the one of the local grid." << std::endl
339                << "Local size of dimension " << i << " is " << eachDimSize[i] << "." << std::endl
340                << "Mask size for dimension " << i << " is " << gridMask.extent(i) << ".");
[567]341      }
342    }
343    else {
344        CArrayBoolTraits<CArray<bool,N> >::resizeArray(gridMask,eachDimSize);
345        gridMask = true;
346    }
347
348    int ssize = gridMask.numElements();
349    idx = 0;
350    while (idx < ssize)
351    {
352      for (int i = 0; i < dim-1; ++i)
353      {
354        if (idxLoop[i] == eachDimSize[i])
355        {
356          idxLoop[i] = 0;
357          ++idxLoop[i+1];
358        }
359      }
360
361      // Find out outer index
362      idxDomain = idxAxis = 0;
363      bool maskValue = true;
364      for (int i = 0; i < numElement; ++i)
365      {
366        if (axisDomainOrder(i))
367        {
[664]368          maskValue = maskValue && (*domainMasks[idxDomain])(idxLoop[indexMap[i]] + idxLoop[indexMap[i]+1] * eachDimSize[indexMap[i]]);
[567]369          ++idxDomain;
370        }
371        else
372        {
373          maskValue = maskValue && (*axisMasks[idxAxis])(idxLoop[indexMap[i]]);
374          ++idxAxis;
375        }
376      }
377
378      int maskIndex = idxLoop[0];
379      int mulDim = 1;
380      for (int k = 1; k < dim; ++k)
381      {
382        mulDim *= eachDimSize[k-1];
383        maskIndex += idxLoop[k]*mulDim;
384      }
[623]385      *(gridMask.dataFirst()+maskIndex) &= maskValue;
[567]386
387      ++idxLoop[0];
388      ++idx;
389    }
390
391   }
392
[623]393   /*!
394     Modify the current mask of grid, the local index to be modified will take value false
395     \param [in/out] gridMask current mask of grid
396     \param [in] indexToModify local index to modify
397   */
398   template<int N>
399   void CGrid::modifyGridMask(CArray<bool,N>& gridMask, const CArray<int,1>& indexToModify)
400   {
401     bool valueToModify = false;
402     int num = indexToModify.numElements();
403     for (int idx = 0; idx < num; ++idx)
404     {
405       *(gridMask.dataFirst()+indexToModify(idx)) = valueToModify;
406     }
407   }
[219]408   ///--------------------------------------------------------------
409
410   // Declare/Define CGridGroup and CGridDefinition
411   DECLARE_GROUP(CGrid);
412
413   ///--------------------------------------------------------------
414
[335]415} // namespace xios
[219]416
[591]417#endif // __XIOS_CGrid__
Note: See TracBrowser for help on using the repository browser.