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

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

Changing the way to create virtual grid during transformation.

+)Instead of establishing relation between source grid of current transformation and
the original source grid (source grid of the first transformation), each transformation
keeps its list of source grid and destination, which will be used in interpolation.
+) Clean some redundant codes

Test
+) All official tests pass
+) interpolation tests pass

File size: 5.4 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    TransformationIndexMap::const_iterator itbTransMap = transformationMapping_[idxTrans].begin(), itTransMap,
38                                                     iteTransMap = transformationMapping_[idxTrans].end();
39    TransformationWeightMap::const_iterator itTransWeight = transformationWeight_[idxTrans].begin();
40
41    // If transformation position exists
42    TransformationIndexMap::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        globaIndexWeightFromDestToSource[(it->first)].resize(srcGridSize);
87        for (int i = 0; i < srcGridSize; ++i)
88        {
89          globaIndexWeightFromDestToSource[(it->first)][i] = (make_pair(it->second, make_pair(globalIndexSrcGrid[idx][i], currentVecWeight[i])));
90        }
91      }
92    }
93  }
94}
95
96void CGenericAlgorithmTransformation::computeIndexSourceMapping(const std::vector<CArray<double,1>* >& dataAuxInputs)
97{
98  computeIndexSourceMapping_(dataAuxInputs);
99}
100
101std::vector<StdString> CGenericAlgorithmTransformation::getIdAuxInputs()
102{
103  return idAuxInputs_;
104}
105
106}
Note: See TracBrowser for help on using the repository browser.