source: XIOS/dev/dev_trunk_graph/src/transformation/axis_algorithm/axis_algorithm_reduce_axis.cpp

Last change on this file was 2138, checked in by yushan, 5 months ago

temporal commit for merging graph into XIOS_coupling @2137

  • Property svn:executable set to *
File size: 3.8 KB
Line 
1/*!
2   \file axis_algorithm_reduce_axis.cpp
3   \author Ha NGUYEN
4   \since 23 June 2016
5   \date 23 June 2016
6
7   \brief Algorithm for reduce a axis to an axis
8 */
9#include "axis_algorithm_reduce_axis.hpp"
10#include "reduce_axis_to_axis.hpp"
11#include "axis.hpp"
12#include "grid.hpp"
13#include "grid_transformation_factory_impl.hpp"
14
15
16namespace xios {
17CGenericAlgorithmTransformation* CAxisAlgorithmReduceAxis::create(bool isSource, CGrid* gridDst, CGrid* gridSrc,
18                                                                   CTransformation<CAxis>* transformation,
19                                                                   int elementPositionInGrid,
20                                                                   std::map<int, int>& elementPositionInGridSrc2ScalarPosition,
21                                                                   std::map<int, int>& elementPositionInGridSrc2AxisPosition,
22                                                                   std::map<int, int>& elementPositionInGridSrc2DomainPosition,
23                                                                   std::map<int, int>& elementPositionInGridDst2ScalarPosition,
24                                                                   std::map<int, int>& elementPositionInGridDst2AxisPosition,
25                                                                   std::map<int, int>& elementPositionInGridDst2DomainPosition)
26TRY
27{
28  std::vector<CAxis*> axisListDestP = gridDst->getAxis();
29  std::vector<CAxis*> axisListSrcP  = gridSrc->getAxis();
30
31  CReduceAxisToAxis* reduceAxis = dynamic_cast<CReduceAxisToAxis*> (transformation);
32  int axisDstIndex   = elementPositionInGridDst2AxisPosition[elementPositionInGrid];
33  int axisSrcIndex = elementPositionInGridSrc2AxisPosition[elementPositionInGrid];
34
35  return (new CAxisAlgorithmReduceAxis(isSource, axisListDestP[axisDstIndex], axisListSrcP[axisSrcIndex], reduceAxis));
36}
37CATCH
38
39bool CAxisAlgorithmReduceAxis::dummyRegistered_ = CAxisAlgorithmReduceAxis::registerTrans();
40bool CAxisAlgorithmReduceAxis::registerTrans()
41TRY
42{
43  return CGridTransformationFactory<CAxis>::registerTransformation(TRANS_REDUCE_AXIS_TO_AXIS, create);
44}
45CATCH
46
47
48CAxisAlgorithmReduceAxis::CAxisAlgorithmReduceAxis(bool isSource, CAxis* axisDestination, CAxis* axisSource, CReduceAxisToAxis* algo)
49 : CAlgorithmTransformationReduce(isSource)
50TRY
51{
52  eliminateRedondantSrc_= false ;
53  algo->checkValid(axisDestination, axisSource);
54  axisDestination->checkAttributes() ;
55
56  switch (algo->operation)
57  {
58    case CReduceAxisToAxis::operation_attr::sum:
59      operator_ = EReduction::sum;
60      break;
61    case CReduceAxisToAxis::operation_attr::min:
62      operator_ = EReduction::min;
63      break;
64    case CReduceAxisToAxis::operation_attr::max:
65      operator_ = EReduction::max;
66      break;
67    case CReduceAxisToAxis::operation_attr::average:
68      operator_ = EReduction::average;
69      break;
70    default:
71        ERROR("CAxisAlgorithmReduceAxis::CAxisAlgorithmReduceAxis(CAxis* axisDestination, CAxis* axisSource, CReduceAxisToAxis* algo)",
72         << "Operation is wrongly defined. Supported operations: sum, min, max, average." << std::endl
73         << "Axis source " <<axisSource->getId() << std::endl
74         << "Axis destination " << axisDestination->getId());
75  }
76
77  TransformationIndexMap& transMap = this->transformationMapping_;
78  CArray<int,1>& axisDstIndex = axisDestination->index;
79  int nbAxisIdx = axisDstIndex.numElements();
80  for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis)
81  {
82    int globalAxisIdx = axisDstIndex(idxAxis);
83    transMap[globalAxisIdx].resize(1);
84    transMap[globalAxisIdx][0]=globalAxisIdx ;     
85  }
86
87 
88  axisDestination->checkAttributes() ;
89  this->computeAlgorithm(axisSource->getLocalView(CElementView::WORKFLOW), axisDestination->getLocalView(CElementView::WORKFLOW)) ;
90}
91CATCH
92
93
94CAxisAlgorithmReduceAxis::~CAxisAlgorithmReduceAxis()
95TRY
96{
97 
98}
99CATCH
100
101
102}
Note: See TracBrowser for help on using the repository browser.