source: XIOS/dev/dev_olga/src/transformation/axis_algorithm_duplicate_scalar.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:eol-style set to native
File size: 3.0 KB
Line 
1/*!
2   \file axis_algorithm_duplicate_scalar.cpp
3
4   \brief Algorithm to duplicate scalar into  axis
5 */
6#include "axis_algorithm_duplicate_scalar.hpp"
7#include "duplicate_scalar_to_axis.hpp"
8#include "axis.hpp"
9#include "scalar.hpp"
10#include "grid.hpp"
11#include "grid_transformation_factory_impl.hpp"
12
13namespace xios {
14CGenericAlgorithmTransformation* CAxisAlgorithmDuplicateScalar::create(CGrid* gridDst, CGrid* gridSrc,
15                                                                     CTransformation<CAxis>* transformation,
16                                                                     int elementPositionInGrid,
17                                                                     std::map<int, int>& elementPositionInGridSrc2ScalarPosition,
18                                                                     std::map<int, int>& elementPositionInGridSrc2AxisPosition,
19                                                                     std::map<int, int>& elementPositionInGridSrc2DomainPosition,
20                                                                     std::map<int, int>& elementPositionInGridDst2ScalarPosition,
21                                                                     std::map<int, int>& elementPositionInGridDst2AxisPosition,
22                                                                     std::map<int, int>& elementPositionInGridDst2DomainPosition)
23TRY
24{
25  std::vector<CAxis*> axisListDestP = gridDst->getAxis();
26  std::vector<CScalar*> scalarListSrcP = gridSrc->getScalars();
27
28  CDuplicateScalarToAxis* duplicateScalar = dynamic_cast<CDuplicateScalarToAxis*> (transformation);
29  int axisDstIndex = elementPositionInGridDst2AxisPosition[elementPositionInGrid];
30  int scalarSrcIndex = elementPositionInGridSrc2ScalarPosition[elementPositionInGrid];
31
32  return (new CAxisAlgorithmDuplicateScalar(axisListDestP[axisDstIndex], scalarListSrcP[scalarSrcIndex], duplicateScalar));
33}
34CATCH
35
36bool CAxisAlgorithmDuplicateScalar::registerTrans()
37TRY
38{
39  CGridTransformationFactory<CAxis>::registerTransformation(TRANS_DUPLICATE_SCALAR_TO_AXIS, create);
40}
41CATCH
42
43
44CAxisAlgorithmDuplicateScalar::CAxisAlgorithmDuplicateScalar(CAxis* axisDestination, CScalar* scalarSource, CDuplicateScalarToAxis* algo)
45 : CAxisAlgorithmTransformation(axisDestination, scalarSource)
46{
47
48}
49
50
51CAxisAlgorithmDuplicateScalar::~CAxisAlgorithmDuplicateScalar()
52{
53}
54
55void CAxisAlgorithmDuplicateScalar::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
56TRY
57{
58  this->transformationMapping_.resize(1);
59  this->transformationWeight_.resize(1);
60
61  TransformationIndexMap& transMap = this->transformationMapping_[0];
62  TransformationWeightMap& transWeight = this->transformationWeight_[0];
63
64  CArray<int,1>& axisDstIndex = axisDest_->index;
65
66  int nbAxisIdx = axisDstIndex.numElements();
67  for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis)
68  {
69    int globalAxisIdx = axisDstIndex(idxAxis);
70    transMap[globalAxisIdx].resize(1);
71    transWeight[globalAxisIdx].resize(1);
72    transMap[globalAxisIdx][0] = 0 ;
73    transWeight[globalAxisIdx][0] = 1.0 ;
74  }
75}
76CATCH
77}
Note: See TracBrowser for help on using the repository browser.