source: XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/axis_algorithm_transformation.cpp @ 1878

Last change on this file since 1878 was 1784, checked in by ymipsl, 4 years ago
  • Preparing coupling functionalities.
  • Make some cleaner things

YM

File size: 4.2 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)
22TRY
23{
24  axisDestGlobalSize_ = axisDestination->n_glo.getValue();
25  int niDest = axisDestination->n.getValue();
26  int ibeginDest = axisDestination->begin.getValue();
27
28  for (int idx = 0; idx < niDest; ++idx)
29    if ((axisDestination->mask)(idx)) axisDestGlobalIndex_.push_back(ibeginDest+idx);
30}
31CATCH
32
33CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CDomain* domainSource)
34 : CGenericAlgorithmTransformation(), axisDest_(axisDestination), axisSrc_(0), domainSrc_(domainSource),scalarSrc_(0)
35TRY
36{
37  axisDestGlobalSize_ = axisDestination->n_glo.getValue();
38  int niDest = axisDestination->n.getValue();
39  int ibeginDest = axisDestination->begin.getValue();
40
41  for (int idx = 0; idx < niDest; ++idx)
42    if ((axisDestination->mask)(idx)) axisDestGlobalIndex_.push_back(ibeginDest+idx);
43}
44CATCH
45
46CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CScalar* scalarSource)
47 : CGenericAlgorithmTransformation(), axisDest_(axisDestination), axisSrc_(0), domainSrc_(0), scalarSrc_(scalarSource)
48TRY
49{
50  axisDestGlobalSize_ = axisDestination->n_glo.getValue();
51  int niDest = axisDestination->n.getValue();
52  int ibeginDest = axisDestination->begin.getValue();
53
54  for (int idx = 0; idx < niDest; ++idx)
55    if ((axisDestination->mask)(idx)) axisDestGlobalIndex_.push_back(ibeginDest+idx);
56}
57CATCH
58
59CAxisAlgorithmTransformation::~CAxisAlgorithmTransformation()
60{
61}
62
63void CAxisAlgorithmTransformation::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
64{
65}
66
67/*!
68  Compute global index of axis on different processes
69  \param [in] globalAxisIndex global index of axis source
70  \param [out] globalAxisIndexOnProc processes which contain the corresponding global index of axis source
71*/
72void CAxisAlgorithmTransformation::computeExchangeGlobalIndex(const CArray<size_t,1>& globalAxisIndex,
73                                                              int elementType,
74                                                              CClientClientDHTInt::Index2VectorInfoTypeMap& globalAxisIndexOnProc)
75TRY
76{
77  CContext* context = CContext::getCurrent();
78  int clientRank = context->intraCommRank_;
79  int clientSize = context->intraCommSize_;
80
81  size_t globalIndex;
82  int nIndexSize = 0;
83  CArray<bool,1>* ptLocalMask ;
84  CArray<bool,1> scalarMask(1) ;
85  scalarMask=true ;
86 
87  if (2 == elementType) 
88  {
89    nIndexSize = domainSrc_->i_index.numElements();
90    ptLocalMask=&(domainSrc_->localMask) ;
91  }
92  else if (1 == elementType)
93  {
94     nIndexSize = axisSrc_->index.numElements();
95     ptLocalMask=&(axisSrc_->mask) ;
96  }
97  else
98  {
99     nIndexSize=1  ; //  scalar
100     ptLocalMask=&scalarMask ;
101  }
102  CArray<bool,1>& localMask=*ptLocalMask ;
103 
104  CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank;
105  globalIndex2ProcRank.rehash(std::ceil(nIndexSize/globalIndex2ProcRank.max_load_factor()));
106  for (int idx = 0; idx < nIndexSize; ++idx)
107  {
108    if (localMask(idx))
109    {
110      if (2 == elementType) // domain
111      {
112       globalIndex = domainSrc_->i_index(idx) + domainSrc_->j_index(idx) * domainSrc_->ni_glo;
113      }
114      else if (1 == elementType) // axis
115      {
116        globalIndex = axisSrc_->index(idx);
117      }
118      else // scalar
119      {
120        globalIndex = 0;
121      }
122     
123      globalIndex2ProcRank[globalIndex].resize(1);
124      globalIndex2ProcRank[globalIndex][0] = clientRank;
125    }
126  }
127
128  CClientClientDHTInt dhtIndexProcRank(globalIndex2ProcRank, context->intraComm_);
129  dhtIndexProcRank.computeIndexInfoMapping(globalAxisIndex);
130
131  globalAxisIndexOnProc = dhtIndexProcRank.getInfoIndexMap();
132}
133CATCH
134
135}
Note: See TracBrowser for help on using the repository browser.