source: XIOS/dev/XIOS_DEV_CMIP6/src/transformation/axis_algorithm_transformation.cpp @ 1275

Last change on this file since 1275 was 1275, checked in by ymipsl, 5 years ago

implement diurnal cycle transformation taken as a grid tranformation : scalar -> axis

YM

File size: 3.8 KB
Line 
1/*!
2   \file axis_algorithm_transformation.hpp
3   \author Ha NGUYEN
4   \since 14 May 2015
5   \date 29 June 2015
6
7   \brief Interface for all axis transformation algorithms.
8 */
9
10#include "axis_algorithm_transformation.hpp"
11#include "axis_algorithm_inverse.hpp"
12#include "axis_algorithm_zoom.hpp"
13#include "context.hpp"
14#include "context_client.hpp"
15#include "client_client_dht_template.hpp"
16#include "axis.hpp"
17
18namespace xios {
19
20CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CAxis* axisSource)
21 : CGenericAlgorithmTransformation(), axisDest_(axisDestination), axisSrc_(axisSource), domainSrc_(0),scalarSrc_(0)
22{
23  axisDestGlobalSize_ = axisDestination->n_glo.getValue();
24  int niDest = axisDestination->n.getValue();
25  int ibeginDest = axisDestination->begin.getValue();
26
27  for (int idx = 0; idx < niDest; ++idx)
28    if ((axisDestination->mask)(idx)) axisDestGlobalIndex_.push_back(ibeginDest+idx);
29}
30
31CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CDomain* domainSource)
32 : CGenericAlgorithmTransformation(), axisDest_(axisDestination), axisSrc_(0), domainSrc_(domainSource),scalarSrc_(0)
33{
34  axisDestGlobalSize_ = axisDestination->n_glo.getValue();
35  int niDest = axisDestination->n.getValue();
36  int ibeginDest = axisDestination->begin.getValue();
37
38  for (int idx = 0; idx < niDest; ++idx)
39    if ((axisDestination->mask)(idx)) axisDestGlobalIndex_.push_back(ibeginDest+idx);
40}
41
42CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CScalar* scalarSource)
43 : CGenericAlgorithmTransformation(), axisDest_(axisDestination), axisSrc_(0), domainSrc_(0), scalarSrc_(scalarSource)
44{
45  axisDestGlobalSize_ = axisDestination->n_glo.getValue();
46  int niDest = axisDestination->n.getValue();
47  int ibeginDest = axisDestination->begin.getValue();
48
49  for (int idx = 0; idx < niDest; ++idx)
50    if ((axisDestination->mask)(idx)) axisDestGlobalIndex_.push_back(ibeginDest+idx);
51}
52CAxisAlgorithmTransformation::~CAxisAlgorithmTransformation()
53{
54}
55
56void CAxisAlgorithmTransformation::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
57{
58}
59
60/*!
61  Compute global index of axis on different processes
62  \param [in] globalAxisIndex global index of axis source
63  \param [out] globalAxisIndexOnProc processes which contain the corresponding global index of axis source
64*/
65void CAxisAlgorithmTransformation::computeExchangeGlobalIndex(const CArray<size_t,1>& globalAxisIndex,
66                                                              int elementType,
67                                                              CClientClientDHTInt::Index2VectorInfoTypeMap& globalAxisIndexOnProc)
68{
69  CContext* context = CContext::getCurrent();
70  CContextClient* client=context->client;
71  int clientRank = client->clientRank;
72  int clientSize = client->clientSize;
73
74  size_t globalIndex;
75  int nIndexSize = 0;
76  if (2 == elementType) nIndexSize = domainSrc_->i_index.numElements();
77  else if (1 == elementType) nIndexSize = axisSrc_->index.numElements();
78  else nIndexSize=1  ; //  scalar
79 
80  CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank;
81  globalIndex2ProcRank.rehash(std::ceil(nIndexSize/globalIndex2ProcRank.max_load_factor()));
82  for (int idx = 0; idx < nIndexSize; ++idx)
83  {
84    if (2 == elementType) // domain
85    {
86      globalIndex = domainSrc_->i_index(idx) + domainSrc_->j_index(idx) * domainSrc_->ni_glo;
87    }
88    else if (1 == elementType) // axis
89    {
90      globalIndex = axisSrc_->index(idx);
91    }
92    else // scalar
93    {
94      globalIndex = 0;
95    }
96
97    globalIndex2ProcRank[globalIndex].resize(1);
98    globalIndex2ProcRank[globalIndex][0] = clientRank;
99  }
100
101  CClientClientDHTInt dhtIndexProcRank(globalIndex2ProcRank, client->intraComm);
102  dhtIndexProcRank.computeIndexInfoMapping(globalAxisIndex);
103
104  globalAxisIndexOnProc = dhtIndexProcRank.getInfoIndexMap();
105}
106
107}
Note: See TracBrowser for help on using the repository browser.