source: XIOS/trunk/src/transformation/generic_algorithm_transformation.cpp @ 831

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

Cleaning up some redundant coeds and making some improvements

+) Remove some XIOS Search to make code run faster
+) Remove some commented codes

Test
+) On Curie
+) All tests pass

File size: 5.3 KB
Line 
1/*!
2   \file generic_algorithm_transformation.hpp
3   \author Ha NGUYEN
4   \since 14 May 2015
5   \date 21 Mars 2016
6
7   \brief Interface for all transformation algorithms.
8 */
9#include "generic_algorithm_transformation.hpp"
10
11namespace xios {
12
13CGenericAlgorithmTransformation::CGenericAlgorithmTransformation()
14 : transformationMapping_(), transformationWeight_(), transformationPosition_(), idAuxInputs_()
15{
16}
17
18/*!
19  This function computes the global indexes of grid source, which the grid destination is in demand.
20  \param[in] elementPositionInGrid position of an element in a grid .E.g: if grid is composed of domain and axis (in order),
21                then position of axis in grid is 2 (since a domain is considered to contain 2 elements (axis)
22  \param[in] gridDestGlobalDim global size of each dimension of grid source (all dimension must have the same size except of the one on which transformation is performed)
23  \param[in] gridSrcGlobalDim dimension size of source grid (it should share the same size for all dimension, maybe except the domain on which transformation is performed)
24  \param[in] globalLocalIndexGridDestSendToServer global and local index mapping of grid destination on the current client to send to server
25  \param[in/out] globaIndexWeightFromDestToSource mapping between transformed global index of grid destination
26             and the weighted value as well as global index from grid index source
27*/
28void CGenericAlgorithmTransformation::computeGlobalSourceIndex(int elementPositionInGrid,
29                                                               const std::vector<int>& gridDestGlobalDim,
30                                                               const std::vector<int>& gridSrcGlobalDim,
31                                                               const GlobalLocalMap& globalLocalIndexGridDestSendToServer,
32                                                               DestinationIndexMap& globaIndexWeightFromDestToSource)
33{
34  bool isTransPosEmpty = transformationPosition_.empty();
35  for (size_t idxTrans = 0; idxTrans < transformationMapping_.size(); ++idxTrans)
36  {
37    std::map<int, std::vector<int> >::const_iterator itbTransMap = transformationMapping_[idxTrans].begin(), itTransMap,
38                                                     iteTransMap = transformationMapping_[idxTrans].end();
39    std::map<int, std::vector<double> >::const_iterator itTransWeight = transformationWeight_[idxTrans].begin();
40
41    // If transformation position exists
42    std::map<int, std::vector<int> >::const_iterator itTransPos, iteTransPos;
43    if (!isTransPosEmpty)
44    {
45      itTransPos  = transformationPosition_[idxTrans].begin(),
46      iteTransPos = transformationPosition_[idxTrans].end();
47    }
48    std::vector<int> emptyTransPos;
49
50    std::vector<std::vector<size_t> > globalIndexSrcGrid;
51    std::vector<std::pair<size_t,int> > globalLocalIndexDest;
52    for (itTransMap = itbTransMap; itTransMap != iteTransMap; ++itTransMap, ++itTransWeight)
53    {
54      if (!isTransPosEmpty)
55      {
56        this->computeGlobalGridIndexFromGlobalIndexElement(itTransMap->first,
57                                                           itTransMap->second,
58                                                           itTransPos->second,
59                                                           elementPositionInGrid,
60                                                           gridDestGlobalDim,
61                                                           gridSrcGlobalDim,
62                                                           globalLocalIndexGridDestSendToServer,
63                                                           globalLocalIndexDest,
64                                                           globalIndexSrcGrid);
65        ++itTransPos;
66      }
67      else
68      {
69        this->computeGlobalGridIndexFromGlobalIndexElement(itTransMap->first,
70                                                           itTransMap->second,
71                                                           emptyTransPos,
72                                                           elementPositionInGrid,
73                                                           gridDestGlobalDim,
74                                                           gridSrcGlobalDim,
75                                                           globalLocalIndexGridDestSendToServer,
76                                                           globalLocalIndexDest,
77                                                           globalIndexSrcGrid);
78      }
79      std::vector<std::pair<size_t,int> >::const_iterator it = globalLocalIndexDest.begin(), ite = globalLocalIndexDest.end();
80      const std::vector<double>& currentVecWeight = itTransWeight->second;
81
82      for (size_t idx = 0; it != ite; ++it, ++idx)
83      {
84        size_t srcGridSize = globalIndexSrcGrid[idx].size();
85        globaIndexWeightFromDestToSource[(it->first)].reserve(srcGridSize);
86        for (int i = 0; i < srcGridSize; ++i)
87        {
88          globaIndexWeightFromDestToSource[(it->first)].push_back(make_pair(it->second, make_pair(globalIndexSrcGrid[idx][i], currentVecWeight[i])));
89        }
90      }
91    }
92  }
93}
94
95void CGenericAlgorithmTransformation::computeIndexSourceMapping(const std::vector<CArray<double,1>* >& dataAuxInputs)
96{
97  computeIndexSourceMapping_(dataAuxInputs);
98}
99
100std::vector<StdString> CGenericAlgorithmTransformation::getIdAuxInputs()
101{
102  return idAuxInputs_;
103}
104
105}
Note: See TracBrowser for help on using the repository browser.