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

Last change on this file since 668 was 668, checked in by mhnguyen, 6 years ago

Implementing some code factoring

+) Replace some slow searching function by faster ones

Test
+) On Curie
+) test_client and test_complete are correct

File size: 3.8 KB
Line 
1/*!
2   \file generic_algorithm_transformation.hpp
3   \author Ha NGUYEN
4   \since 14 May 2015
5   \date 29 June 2015
6
7   \brief Interface for all transformation algorithms.
8 */
9#include "generic_algorithm_transformation.hpp"
10
11namespace xios {
12
13CGenericAlgorithmTransformation::CGenericAlgorithmTransformation()
14 : transformationMapping_(), transformationWeight_()
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] globalIndexGridDestSendToServer global index 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 long 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 std::vector<size_t>& globalIndexGridDestSendToServer,
32                                                             std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexWeightFromDestToSource)
33{
34  std::map<int, std::vector<int> >::const_iterator itbTransMap = transformationMapping_.begin(),
35                                                   itTransMap = itbTransMap,
36                                                   iteTransMap = transformationMapping_.end();
37  std::map<int, std::vector<double> >::const_iterator itTransWeight = transformationWeight_.begin();
38  std::map<size_t, std::vector<std::pair<size_t,double> > >::iterator iteWeight, itWeight;
39  std::vector<int>::const_iterator itbVec, itVec, iteVec;
40  std::vector<std::vector<size_t> > globalIndexSrcGrid;
41  CArray<size_t,1> globalIndexDestGrid;
42  std::vector<size_t> vecGlobalIndexGridSendToServer(globalIndexGridDestSendToServer.begin(), globalIndexGridDestSendToServer.end());
43  std::sort(vecGlobalIndexGridSendToServer.begin(), vecGlobalIndexGridSendToServer.end());
44  for (itTransMap = itbTransMap; itTransMap != iteTransMap; ++itTransMap, ++itTransWeight)
45  {
46    this->computeGlobalGridIndexFromGlobalIndexElement(itTransMap->first,
47                                                   itTransMap->second,
48                                                   elementPositionInGrid,
49                                                   gridDestGlobalDim,
50                                                   gridSrcGlobalDim,
51                                                   vecGlobalIndexGridSendToServer,
52                                                   globalIndexDestGrid,
53                                                   globalIndexSrcGrid);
54    size_t globalIndexSize = globalIndexDestGrid.numElements();
55    const std::vector<double>& currentVecWeight = itTransWeight->second;
56    for (size_t idx = 0; idx < globalIndexSize; ++idx)
57    {
58      size_t globalIndex = globalIndexDestGrid(idx);
59      for (int i = 0; i < globalIndexSrcGrid[idx].size(); ++i)
60      {
61        globaIndexWeightFromDestToSource[globalIndex].push_back(make_pair(globalIndexSrcGrid[idx][i], currentVecWeight[i]));
62      }
63    }
64  }
65}
66
67}
Note: See TracBrowser for help on using the repository browser.