source: XIOS/trunk/src/transformation/scalar_algorithm_transformation.cpp @ 1620

Last change on this file since 1620 was 1403, checked in by ymipsl, 6 years ago

Fix bug in transformation when using mask and overlapped grid element (axis or domain).

YM

File size: 4.5 KB
Line 
1/*!
2   \file scalar_algorithm_transformation.hpp
3   \author Ha NGUYEN
4   \since 23 June 2016
5   \date 23 Oct 2016
6
7   \brief Interface for all scalar transformation algorithms.
8 */
9
10#include "scalar_algorithm_transformation.hpp"
11#include "context.hpp"
12#include "context_client.hpp"
13#include "client_client_dht_template.hpp"
14#include "domain.hpp"
15#include "axis.hpp"
16#include "scalar.hpp"
17
18namespace xios {
19
20CScalarAlgorithmTransformation::CScalarAlgorithmTransformation(CScalar* scalarDestination, CScalar* scalarSource)
21 : CGenericAlgorithmTransformation(),
22   scalarDest_(scalarDestination),
23   scalarSrc_(scalarSource), axisSrc_(0), domainSrc_(0)
24{
25}
26
27CScalarAlgorithmTransformation::CScalarAlgorithmTransformation(CScalar* scalarDestination, CAxis* axisSource)
28 : CGenericAlgorithmTransformation(),
29   scalarDest_(scalarDestination),
30   scalarSrc_(0), axisSrc_(axisSource), domainSrc_(0)
31{
32}
33
34CScalarAlgorithmTransformation::CScalarAlgorithmTransformation(CScalar* scalarDestination, CDomain* domainSource)
35 : CGenericAlgorithmTransformation(),
36   scalarDest_(scalarDestination),
37   scalarSrc_(0), axisSrc_(0), domainSrc_(domainSource)
38{
39}
40
41CScalarAlgorithmTransformation::~CScalarAlgorithmTransformation()
42{
43}
44
45void CScalarAlgorithmTransformation::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
46{
47}
48
49/*!
50  Compute global index of element source on different processes on knowing the global index source of transformation
51
52  \param [in] globalIndexElementSource global index source of transformation (represented in the transformation mapping)
53  \param [in] elementSourceType type of element source
54  \param [out] globalIndexElementSourceOnProc processes which contain the corresponding global index of scalar source
55*/
56void CScalarAlgorithmTransformation::computeExchangeGlobalIndex(const CArray<size_t,1>& globalIndexElementSource,
57                                                                int elementSourceType,
58                                                                CClientClientDHTInt::Index2VectorInfoTypeMap& globalIndexElementSourceOnProc)
59{
60  CContext* context = CContext::getCurrent();
61  CContextClient* client=context->client;
62  int clientRank = client->clientRank;
63  int clientSize = client->clientSize;
64
65  if (2 == elementSourceType) // Source is a domain
66  {
67    size_t globalIndex;
68    int nIndexSize = domainSrc_->i_index.numElements();
69    CArray<int,1>& iIndex = domainSrc_->i_index;
70    CArray<int,1>& jIndex = domainSrc_->j_index;
71    int niGlo = domainSrc_->ni_glo;
72    CArray<bool,1>& localMask = domainSrc_ -> localMask ;
73    CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank;
74    globalIndex2ProcRank.rehash(std::ceil(nIndexSize/globalIndex2ProcRank.max_load_factor()));
75    for (int idx = 0; idx < nIndexSize; ++idx)
76    {
77      if (localMask(idx))
78      {
79        globalIndex = jIndex(idx) * niGlo + iIndex(idx);
80        globalIndex2ProcRank[globalIndex].resize(1);
81        globalIndex2ProcRank[globalIndex][0] = clientRank;
82      }
83    }
84
85    CClientClientDHTInt dhtIndexProcRank(globalIndex2ProcRank, client->intraComm);
86    dhtIndexProcRank.computeIndexInfoMapping(globalIndexElementSource);
87    globalIndexElementSourceOnProc = dhtIndexProcRank.getInfoIndexMap();
88  }
89  else if (1 == elementSourceType) // Source is an axis
90  {
91    size_t globalIndex;
92    int nIndexSize = axisSrc_->index.numElements();
93    CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank;
94    globalIndex2ProcRank.rehash(std::ceil(nIndexSize/globalIndex2ProcRank.max_load_factor()));
95    CArray<bool,1>& localMask = axisSrc_ -> mask ;
96   
97    for (int idx = 0; idx < nIndexSize; ++idx)
98    {
99      if (localMask(idx))
100      {
101        globalIndex = axisSrc_->index(idx);
102        globalIndex2ProcRank[globalIndex].resize(1);
103        globalIndex2ProcRank[globalIndex][0] = clientRank;
104      }
105    }
106
107    CClientClientDHTInt dhtIndexProcRank(globalIndex2ProcRank, client->intraComm);
108    dhtIndexProcRank.computeIndexInfoMapping(globalIndexElementSource);
109    globalIndexElementSourceOnProc = dhtIndexProcRank.getInfoIndexMap();
110  }
111  else // scalar
112  {
113    size_t globalIndex = 0;   
114    CClientClientDHTInt::Index2VectorInfoTypeMap globalIndex2ProcRank;
115    globalIndex2ProcRank[globalIndex].resize(1);
116    globalIndex2ProcRank[globalIndex][0] = clientRank;
117
118    CClientClientDHTInt dhtIndexProcRank(globalIndex2ProcRank, client->intraComm);
119    dhtIndexProcRank.computeIndexInfoMapping(globalIndexElementSource);
120    globalIndexElementSourceOnProc = dhtIndexProcRank.getInfoIndexMap();
121  }
122}
123
124}
Note: See TracBrowser for help on using the repository browser.