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

Last change on this file since 1612 was 1612, checked in by oabramkina, 5 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
RevLine 
[895]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"
[933]13#include "grid.hpp"
14#include "grid_transformation_factory_impl.hpp"
[977]15#include "reduction.hpp"
[895]16
17namespace xios {
[933]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)
[1612]27TRY
[933]28{
29  std::vector<CAxis*> axisListDestP = gridDst->getAxis();
30  std::vector<CDomain*> domainListSrcP = gridSrc->getDomains();
[895]31
[933]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}
[1612]38CATCH
[933]39
40//bool CAxisAlgorithmExtractDomain::_dummyRegistered = CAxisAlgorithmExtractDomain::registerTrans();
41bool CAxisAlgorithmExtractDomain::registerTrans()
[1612]42TRY
[933]43{
44  CGridTransformationFactory<CAxis>::registerTransformation(TRANS_EXTRACT_DOMAIN_TO_AXIS, create);
45}
[1612]46CATCH
[933]47
48
[895]49CAxisAlgorithmExtractDomain::CAxisAlgorithmExtractDomain(CAxis* axisDestination, CDomain* domainSource, CExtractDomainToAxis* algo)
50 : CAxisAlgorithmTransformation(axisDestination, domainSource), pos_(-1), reduction_(0)
[1612]51TRY
[895]52{
53  algo->checkValid(axisDestination, domainSource);
54  StdString op = "extract";
[980]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
[895]68  pos_ = algo->position;
69  reduction_ = CReductionAlgorithm::createOperation(CReductionAlgorithm::ReductionOperations[op]);
70}
[1612]71CATCH
[895]72
73void CAxisAlgorithmExtractDomain::apply(const std::vector<std::pair<int,double> >& localIndex,
74                                        const double* dataInput,
75                                        CArray<double,1>& dataOut,
[1158]76                                        std::vector<bool>& flagInitial,                     
[1260]77                                        bool ignoreMissingValue, bool firstPass)
[1612]78TRY
[895]79{
[1260]80  reduction_->apply(localIndex, dataInput, dataOut, flagInitial, ignoreMissingValue, firstPass);
[895]81}
[1612]82CATCH
[895]83
84CAxisAlgorithmExtractDomain::~CAxisAlgorithmExtractDomain()
[1612]85TRY
[895]86{
87  if (0 != reduction_) delete reduction_;
88}
[1612]89CATCH
[895]90
91void CAxisAlgorithmExtractDomain::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
[1612]92TRY
[895]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}
[1612]130CATCH
[895]131}
Note: See TracBrowser for help on using the repository browser.