source: XIOS/dev/dev_olga/src/transformation/axis_algorithm_extract_domain.cpp @ 1620

Last change on this file since 1620 was 1612, checked in by oabramkina, 2 years ago

Dev: adding exception handling.

To activate it, compilation flag -DXIOS_EXCEPTION should be added.

  • Property svn:executable set to *
File size: 4.7 KB
Line 
1/*!
2   \file axis_algorithm_reduce_domain.cpp
3   \author Ha NGUYEN
4   \since 23 June 2016
5   \date 23 June 2016
6
7   \brief Algorithm for extract a domain to an axis
8 */
9#include "axis_algorithm_extract_domain.hpp"
10#include "extract_domain_to_axis.hpp"
11#include "axis.hpp"
12#include "domain.hpp"
13#include "grid.hpp"
14#include "grid_transformation_factory_impl.hpp"
15#include "reduction.hpp"
16
17namespace xios {
18CGenericAlgorithmTransformation* CAxisAlgorithmExtractDomain::create(CGrid* gridDst, CGrid* gridSrc,
19                                                                     CTransformation<CAxis>* transformation,
20                                                                     int elementPositionInGrid,
21                                                                     std::map<int, int>& elementPositionInGridSrc2ScalarPosition,
22                                                                     std::map<int, int>& elementPositionInGridSrc2AxisPosition,
23                                                                     std::map<int, int>& elementPositionInGridSrc2DomainPosition,
24                                                                     std::map<int, int>& elementPositionInGridDst2ScalarPosition,
25                                                                     std::map<int, int>& elementPositionInGridDst2AxisPosition,
26                                                                     std::map<int, int>& elementPositionInGridDst2DomainPosition)
27TRY
28{
29  std::vector<CAxis*> axisListDestP = gridDst->getAxis();
30  std::vector<CDomain*> domainListSrcP = gridSrc->getDomains();
31
32  CExtractDomainToAxis* extractDomain = dynamic_cast<CExtractDomainToAxis*> (transformation);
33  int axisDstIndex = elementPositionInGridDst2AxisPosition[elementPositionInGrid];
34  int domainSrcIndex = elementPositionInGridSrc2DomainPosition[elementPositionInGrid];
35
36  return (new CAxisAlgorithmExtractDomain(axisListDestP[axisDstIndex], domainListSrcP[domainSrcIndex], extractDomain));
37}
38CATCH
39
40//bool CAxisAlgorithmExtractDomain::_dummyRegistered = CAxisAlgorithmExtractDomain::registerTrans();
41bool CAxisAlgorithmExtractDomain::registerTrans()
42TRY
43{
44  CGridTransformationFactory<CAxis>::registerTransformation(TRANS_EXTRACT_DOMAIN_TO_AXIS, create);
45}
46CATCH
47
48
49CAxisAlgorithmExtractDomain::CAxisAlgorithmExtractDomain(CAxis* axisDestination, CDomain* domainSource, CExtractDomainToAxis* algo)
50 : CAxisAlgorithmTransformation(axisDestination, domainSource), pos_(-1), reduction_(0)
51TRY
52{
53  algo->checkValid(axisDestination, domainSource);
54  StdString op = "extract";
55
56  switch (algo->direction)
57  {
58    case CExtractDomainToAxis::direction_attr::jDir:
59      dir_ = jDir;
60      break;
61    case CExtractDomainToAxis::direction_attr::iDir:
62      dir_ = iDir;
63      break;
64    default:
65      break;
66  }
67
68  pos_ = algo->position;
69  reduction_ = CReductionAlgorithm::createOperation(CReductionAlgorithm::ReductionOperations[op]);
70}
71CATCH
72
73void CAxisAlgorithmExtractDomain::apply(const std::vector<std::pair<int,double> >& localIndex,
74                                        const double* dataInput,
75                                        CArray<double,1>& dataOut,
76                                        std::vector<bool>& flagInitial,                     
77                                        bool ignoreMissingValue, bool firstPass)
78TRY
79{
80  reduction_->apply(localIndex, dataInput, dataOut, flagInitial, ignoreMissingValue, firstPass);
81}
82CATCH
83
84CAxisAlgorithmExtractDomain::~CAxisAlgorithmExtractDomain()
85TRY
86{
87  if (0 != reduction_) delete reduction_;
88}
89CATCH
90
91void CAxisAlgorithmExtractDomain::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
92TRY
93{
94  this->transformationMapping_.resize(1);
95  this->transformationWeight_.resize(1);
96
97  TransformationIndexMap& transMap = this->transformationMapping_[0];
98  TransformationWeightMap& transWeight = this->transformationWeight_[0];
99
100  CArray<int,1>& axisDstIndex = axisDest_->index;
101  int ni_glo = domainSrc_->ni_glo, nj_glo = domainSrc_->nj_glo;
102  if (jDir == dir_)
103  {
104    int nbAxisIdx = axisDstIndex.numElements();
105    for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis)
106    {
107      int globalAxisIdx = axisDstIndex(idxAxis);
108      transMap[globalAxisIdx].resize(1);
109      transWeight[globalAxisIdx].resize(1);
110      transMap[globalAxisIdx][0] = globalAxisIdx * ni_glo + pos_;
111      transWeight[globalAxisIdx][0] = 1.0;
112
113    }
114  }
115  else if (iDir == dir_)
116  {
117    int nbAxisIdx = axisDstIndex.numElements();
118    for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis)
119    {
120      int globalAxisIdx = axisDstIndex(idxAxis);
121      transMap[globalAxisIdx].resize(1);
122      transWeight[globalAxisIdx].resize(1);
123      transMap[globalAxisIdx][0] = globalAxisIdx + ni_glo * pos_;
124      transWeight[globalAxisIdx][0] = 1.0;
125    }
126  }
127  else
128  {}
129}
130CATCH
131}
Note: See TracBrowser for help on using the repository browser.