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

Last change on this file since 1158 was 1158, checked in by oabramkina, 3 years ago

Two server levels: merging with trunk r1137.
There are bugs.

  • Property svn:executable set to *
File size: 4.6 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)
27{
28  std::vector<CAxis*> axisListDestP = gridDst->getAxis();
29  std::vector<CDomain*> domainListSrcP = gridSrc->getDomains();
30
31  CExtractDomainToAxis* extractDomain = dynamic_cast<CExtractDomainToAxis*> (transformation);
32  int axisDstIndex = elementPositionInGridDst2AxisPosition[elementPositionInGrid];
33  int domainSrcIndex = elementPositionInGridSrc2DomainPosition[elementPositionInGrid];
34
35  return (new CAxisAlgorithmExtractDomain(axisListDestP[axisDstIndex], domainListSrcP[domainSrcIndex], extractDomain));
36}
37
38//bool CAxisAlgorithmExtractDomain::_dummyRegistered = CAxisAlgorithmExtractDomain::registerTrans();
39bool CAxisAlgorithmExtractDomain::registerTrans()
40{
41  CGridTransformationFactory<CAxis>::registerTransformation(TRANS_EXTRACT_DOMAIN_TO_AXIS, create);
42}
43
44
45CAxisAlgorithmExtractDomain::CAxisAlgorithmExtractDomain(CAxis* axisDestination, CDomain* domainSource, CExtractDomainToAxis* algo)
46 : CAxisAlgorithmTransformation(axisDestination, domainSource), pos_(-1), reduction_(0)
47{
48  algo->checkValid(axisDestination, domainSource);
49  StdString op = "extract";
50
51  switch (algo->direction)
52  {
53    case CExtractDomainToAxis::direction_attr::jDir:
54      dir_ = jDir;
55      break;
56    case CExtractDomainToAxis::direction_attr::iDir:
57      dir_ = iDir;
58      break;
59    default:
60      break;
61  }
62
63  pos_ = algo->position;
64  reduction_ = CReductionAlgorithm::createOperation(CReductionAlgorithm::ReductionOperations[op]);
65}
66
67void CAxisAlgorithmExtractDomain::apply(const std::vector<std::pair<int,double> >& localIndex,
68                                        const double* dataInput,
69                                        CArray<double,1>& dataOut,
70                                        std::vector<bool>& flagInitial,                     
71                                        bool ignoreMissingValue)
72{
73  reduction_->apply(localIndex, dataInput, dataOut, flagInitial, ignoreMissingValue);
74}
75
76CAxisAlgorithmExtractDomain::~CAxisAlgorithmExtractDomain()
77{
78  if (0 != reduction_) delete reduction_;
79}
80
81void CAxisAlgorithmExtractDomain::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
82{
83  this->transformationMapping_.resize(1);
84  this->transformationWeight_.resize(1);
85
86  TransformationIndexMap& transMap = this->transformationMapping_[0];
87  TransformationWeightMap& transWeight = this->transformationWeight_[0];
88
89  CArray<int,1>& axisDstIndex = axisDest_->index;
90  int ni_glo = domainSrc_->ni_glo, nj_glo = domainSrc_->nj_glo;
91  if (jDir == dir_)
92  {
93    int nbAxisIdx = axisDstIndex.numElements();
94    for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis)
95    {
96      int globalAxisIdx = axisDstIndex(idxAxis);
97      transMap[globalAxisIdx].resize(1);
98      transWeight[globalAxisIdx].resize(1);
99      transMap[globalAxisIdx][0] = globalAxisIdx * ni_glo + pos_;
100      transWeight[globalAxisIdx][0] = 1.0;
101
102    }
103  }
104  else if (iDir == dir_)
105  {
106    int nbAxisIdx = axisDstIndex.numElements();
107    for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis)
108    {
109      int globalAxisIdx = axisDstIndex(idxAxis);
110      transMap[globalAxisIdx].resize(1);
111      transWeight[globalAxisIdx].resize(1);
112      transMap[globalAxisIdx][0] = globalAxisIdx + ni_glo * pos_;
113      transWeight[globalAxisIdx][0] = 1.0;
114    }
115  }
116  else
117  {}
118}
119
120}
Note: See TracBrowser for help on using the repository browser.