source: XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution_client.hpp @ 1878

Last change on this file since 1878 was 1869, checked in by ymipsl, 4 years ago

Some update...

YM

File size: 6.4 KB
Line 
1/*!
2   \file distribution_client.hpp
3   \author Ha NGUYEN
4   \since 13 Jan 2015
5   \date 09 Mars 2015
6
7   \brief Index distribution on client side.
8 */
9#ifndef __XIOS_DISTRIBUTIONCLIENT_HPP__
10#define __XIOS_DISTRIBUTIONCLIENT_HPP__
11
12#include <distribution.hpp>
13#include "axis.hpp"
14#include "domain.hpp"
15#include "grid.hpp"
16
17namespace xios {
18
19class CGrid;
20class CDomain;
21class CAxis;
22class CScalar;
23
24/*!
25  \class CDistributionClient
26  This class bases on the knowledge of distribution on client side (decided by users)
27to calculate the global index of its local data.
28*/
29class CDistributionClient : public CDistribution
30{
31public:
32  typedef CDistribution::GlobalLocalMap GlobalLocalDataMap;
33
34  public:
35    /** Default constructor */
36    CDistributionClient(int rank, CGrid* grid);
37
38    void createGlobalIndexSendToServer();
39
40    /** Default destructor */
41    virtual ~CDistributionClient();
42
43    virtual const std::vector<int>& getLocalDataIndexOnClient();
44    GlobalLocalDataMap& getGlobalLocalDataSendToServer();
45    GlobalLocalDataMap& getGlobalDataIndexOnClient();
46    const std::vector<bool>& getLocalMaskIndexOnClient();
47    const std::vector<int>& getLocalMaskedDataIndexOnClient();
48
49    size_t getLocalDataSize(void) { if (!isComputed_) createGlobalIndexSendToServer(); return localDataSize_ ;}
50    std::vector<int> getNGlob() { return nGlob_; }
51    std::vector<int> getDataNIndex() { return dataNIndex_; }
52
53    bool isDataDistributed() { return isDataDistributed_; }
54
55    static int getDomainIndex(const int& dataIIndex, const int& dataJIndex,
56                                     const int& dataIBegin, const int& dataJBegin,
57                                     const int& dataDim, const int& ni, int& j);
58    static int getAxisIndex(const int& dataIndex, const int& dataBegin, const int& ni);
59
60    void partialClear(void) ;  //! clear heavy sized attibutes
61
62  protected:
63    void createGlobalIndex();
64    void readDistributionInfo(CGrid* grid);
65    void readDistributionInfo(const std::vector<CDomain*>& domList,
66                              const std::vector<CAxis*>& axisList,
67                              const std::vector<CScalar*>& scalarList,
68                              const CArray<int,1>& axisDomainOrder);
69  private:
70    //! Create local index of a domain
71    void createLocalDomainDataIndex();
72
73    //! Create local index of an axis
74    void createLocalAxisDataIndex();
75
76    //! Create local index of a scalar
77    void createLocalScalarDataIndex();
78
79    template<int N>
80    void readGridMaskInfo(const CArray<bool,N>& gridMask);
81
82  private:
83    //!< LocalData index on client
84    GlobalLocalDataMap globalLocalDataSendToServerMap_;
85    GlobalLocalDataMap globalDataIndex_;
86
87    /*! Array holding masked data indexes.
88     * It includes:
89     *  masking on data (data_i/j_index or data_ni/nj and data_ibegin)
90     *  masking on grid elements (domains, axes or scalars)
91     * It DOES NOT include grid mask.
92     * The array size defines the data size entering the workflow. It is used by source filter of client or server1.
93    */
94    std::vector<int> localDataIndex_;
95
96    /*! Array holding grid mask. If grid mask is not defined, its size is zero.
97     * It is used by source filter of client for replacing unmasked data by NaN.
98    */
99    std::vector<bool> localMaskIndex_;
100
101    std::vector<int> localMaskedDataIndex_;
102    //!< the size of local data of the grid
103    size_t localDataSize_ ;
104
105  private:
106    /*! Domains and axis are considered elements.
107     * A grid composed of 1 domain and 1 axis has 2 elements */
108    int numElement_;
109    CArray<int,1> axisDomainOrder_; //!< Order of axis and domain of a grid
110
111    std::vector<int> nLocal_; //!< Local size of each dimension (ni, nj, etc, ...)
112    std::vector<int> nGlob_; //!< Global size of each dimension (e.x: ni_glo, nj_glo, etc, ...)
113    std::vector<int> nBeginLocal_;//!< Begin index of each dimension (e.x: for domain, it's always 0, for axis, it's zoom_begin, ...)
114    std::vector<int> nBeginGlobal_; //!< Begin index of each dimension (e.x: ibegin, jbegin, ...)
115
116    // Data_n_index of domain or axis (For now, axis uses its size as data_n_index
117    std::vector<int> dataNIndex_; //!< Data_n_index in case of domain
118    std::vector<int> dataDims_; //!< Data_dim, domain can have data_dim == 1 or 2
119    std::vector<int> dataBegin_; //!< Data begin (data_ibegin, data_jbegin, etc)
120    std::vector<CArray<int,1> > dataIndex_; //!< Data index
121    std::vector<CArray<int,1> > infoIndex_; //!< i_index, j_index
122
123    std::vector<int> indexMap_; //!< Mapping element index to dimension index
124    std::vector<CArray<int,1> > elementLocalIndex_;  //!< Local index of each element
125    std::vector<CArray<size_t,1> > elementGlobalIndex_; //!< Global index of each element
126    std::vector<CArray<bool,1> > elementIndexData_; //!< // The correct index of a domain has true value, the ghost one has false value
127    std::vector<size_t> elementNLocal_;
128    std::vector<size_t> elementNGlobal_;
129
130    //!< (Only for grid with one axis or scalar)Flag to determine whether data is distributed or not
131    bool isDataDistributed_;
132    int axisNum_;
133    int domainNum_;
134    bool isComputed_;
135
136  private:
137    // Just suppose that grid mask has 3 dimension. Need change
138    CArray<bool,1> gridMask_; //!< Mask of grid
139
140  private:
141    CDistributionClient(const CDistributionClient& distClient); //! Not implement
142};
143
144/*!
145  A grid can have multiple dimension, so can its mask in the form of multi-dimension array.
146It's not a good idea to store all multi-dimension arrays corresponding to each mask.
147One of the ways is to convert this array into 1-dimension one and every process is taken place on it.
148  \param [in] multi-dimension array grid mask
149*/
150template<int N>
151void CDistributionClient::readGridMaskInfo(const CArray<bool,N>& gridMask)
152{
153  int dim = gridMask.dimensions();
154  std::vector<int> dimensionSizes(dim);
155  for (int i = 0; i < dim; ++i) dimensionSizes[i] = gridMask.extent(i);
156
157  std::vector<int> idxLoop(dim,0);
158  int ssize = gridMask.numElements(), idx = 0;
159  gridMask_.resize(ssize);
160  while (idx < ssize)
161  {
162    for (int i = 0; i < dim-1; ++i)
163    {
164      if (idxLoop[i] == dimensionSizes[i])
165      {
166        idxLoop[i] = 0;
167        ++idxLoop[i+1];
168      }
169    }
170
171    int maskIndex = idxLoop[0];
172    int mulDim = 1;
173    for (int k = 1; k < dim; ++k)
174    {
175      mulDim *= dimensionSizes[k-1];
176      maskIndex += idxLoop[k]*mulDim;
177    }
178    gridMask_(maskIndex) = *(gridMask.dataFirst()+maskIndex);
179
180    ++idxLoop[0];
181    ++idx;
182  }
183}
184
185} // namespace xios
186#endif // __XIOS_DISTRIBUTIONCLIENT_HPP__
Note: See TracBrowser for help on using the repository browser.