source: XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/axis_algorithm/axis_algorithm_reduce_axis.cpp @ 1999

Last change on this file since 1999 was 1999, checked in by ymipsl, 7 months ago

Adapt transformation algorithm to new infrastructure (on going...)

YM

  • Property svn:eol-style set to native
  • 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
55  switch (algo->operation)
56  {
57    case CReduceAxisToAxis::operation_attr::sum:
58      operator_ = EReduction::sum;
59      break;
60    case CReduceAxisToAxis::operation_attr::min:
61      operator_ = EReduction::min;
62      break;
63    case CReduceAxisToAxis::operation_attr::max:
64      operator_ = EReduction::max;
65      break;
66    case CReduceAxisToAxis::operation_attr::average:
67      operator_ = EReduction::average;
68      break;
69    default:
70        ERROR("CAxisAlgorithmReduceAxis::CAxisAlgorithmReduceAxis(CAxis* axisDestination, CAxis* axisSource, CReduceAxisToAxis* algo)",
71         << "Operation is wrongly defined. Supported operations: sum, min, max, average." << std::endl
72         << "Axis source " <<axisSource->getId() << std::endl
73         << "Axis destination " << axisDestination->getId());
74
75    TransformationIndexMap& transMap = this->transformationMapping_;
76    CArray<int,1>& axisDstIndex = axisDestination->index;
77    int nbAxisIdx = axisDstIndex.numElements();
78    for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis)
79    {
80      int globalAxisIdx = axisDstIndex(idxAxis);
81      transMap[globalAxisIdx].resize(1);
82      transMap[globalAxisIdx][0]=globalAxisIdx ;     
83    }
84
85  }
86 
87  axisDestination->checkAttributes() ;
88  this->computeAlgorithm(axisSource->getLocalView(CElementView::WORKFLOW), axisDestination->getLocalView(CElementView::WORKFLOW)) ;
89}
90CATCH
91
92
93CAxisAlgorithmReduceAxis::~CAxisAlgorithmReduceAxis()
94TRY
95{
96 
97}
98CATCH
99
100
101}
Note: See TracBrowser for help on using the repository browser.