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 | |
---|
11 | namespace xios { |
---|
12 | |
---|
13 | CGenericAlgorithmTransformation::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 | */ |
---|
28 | void 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)].resize(srcGridSize); |
---|
86 | DestinationGlobalIndex& tmp = globaIndexWeightFromDestToSource[(it->first)]; |
---|
87 | tmp.resize(srcGridSize); |
---|
88 | for (int i = 0; i < srcGridSize; ++i) |
---|
89 | { |
---|
90 | tmp[i].first = it->second; |
---|
91 | tmp[i].second = make_pair(globalIndexSrcGrid[idx][i], currentVecWeight[i]); |
---|
92 | // globaIndexWeightFromDestToSource[(it->first)][i] = (make_pair(it->second, make_pair(globalIndexSrcGrid[idx][i], currentVecWeight[i]))); |
---|
93 | } |
---|
94 | } |
---|
95 | } |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | void CGenericAlgorithmTransformation::computeIndexSourceMapping(const std::vector<CArray<double,1>* >& dataAuxInputs) |
---|
100 | { |
---|
101 | computeIndexSourceMapping_(dataAuxInputs); |
---|
102 | } |
---|
103 | |
---|
104 | std::vector<StdString> CGenericAlgorithmTransformation::getIdAuxInputs() |
---|
105 | { |
---|
106 | return idAuxInputs_; |
---|
107 | } |
---|
108 | |
---|
109 | } |
---|