source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/zoom_axis.cpp @ 2284

Last change on this file since 2284 was 2270, checked in by ymipsl, 3 years ago

Tracking memory leak :
Tranformations and algorithms are now managed with shared_ptr.

YM

File size: 4.1 KB
RevLine 
[621]1#include "zoom_axis.hpp"
[2011]2#include "axis_algorithm_zoom.hpp"
[621]3#include "type.hpp"
4
5namespace xios {
6
7  /// ////////////////////// Définitions ////////////////////// ///
8
9  CZoomAxis::CZoomAxis(void)
10    : CObjectTemplate<CZoomAxis>(), CZoomAxisAttributes(), CTransformation<CAxis>()
11  { /* Ne rien faire de plus */ }
12
13  CZoomAxis::CZoomAxis(const StdString & id)
14    : CObjectTemplate<CZoomAxis>(id), CZoomAxisAttributes(), CTransformation<CAxis>()
15  { /* Ne rien faire de plus */ }
16
17  CZoomAxis::~CZoomAxis(void)
18  {}
19
[836]20  CTransformation<CAxis>* CZoomAxis::create(const StdString& id, xml::CXMLNode* node)
21  {
22    CZoomAxis* zoomAxis = CZoomAxisGroup::get("zoom_axis_definition")->createChild(id);
23    if (node) zoomAxis->parse(*node);
24    return static_cast<CTransformation<CAxis>*>(zoomAxis);
25  }
26
27  bool CZoomAxis::registerTrans()
28  {
[1984]29    return registerTransformation(TRANS_ZOOM_AXIS, {create, getTransformation});
[836]30  }
31
32  bool CZoomAxis::_dummyRegistered = CZoomAxis::registerTrans();
33
[621]34  //----------------------------------------------------------------
35
36  StdString CZoomAxis::GetName(void)    { return StdString("zoom_axis"); }
37  StdString CZoomAxis::GetDefName(void) { return StdString("zoom_axis"); }
38  ENodeType CZoomAxis::GetType(void)    { return eZoomAxis; }
39
40  void CZoomAxis::checkValid(CAxis* axisDest)
41  {
[666]42    int axisIBegin, axisNi, axisGlobalSize;
[787]43    int begin, end, n;
[621]44
[666]45    axisIBegin = axisDest->begin.getValue();
46    axisNi     = axisDest->n.getValue();
47    axisGlobalSize   = axisDest->n_glo.getValue();
[621]48
[1201]49    bool zoomByIndex = !this->index.isEmpty() && (0 != this->index.numElements());
[621]50
[1201]51    if (zoomByIndex)
52    {
53      begin = min(this->index);
54      end   = max(this->index);
55      n     = end - begin + 1;
56    }
57    else
58    {
59      begin = (this->begin.isEmpty()) ?  0 : this->begin.getValue();
60      n     = (this->n.isEmpty()) ?  axisGlobalSize : this->n.getValue();
61      end   = begin+n-1;
62    }
63
[787]64    if (begin < 0 || begin > axisGlobalSize - 1 || end < 0 || end > axisGlobalSize - 1
65        || n < 1 || n > axisGlobalSize || begin > end)
[680]66      ERROR("CZoomAxis::checkValid(CAxis* axisDest)",
[787]67            << "One or more attributes among 'begin' (" << begin << "), 'end' (" << end << "), 'n' (" << n << ") "
[680]68            << "of axis transformation [ id = '" << axisDest->getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] are not well specified");
[1201]69   
70    if (zoomByIndex && (!this->begin.isEmpty() || !this->n.isEmpty()))
71      ERROR("CZoomAxis::checkValid(CAxis* axisDest)",
72            << "Only one type of zoom is accepted. Define zoom by index with global_zoom_index or define zoom with begin and n. "
73            << "Axis transformation [ id = '" << axisDest->getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] are not well specified");
[621]74
[787]75    this->begin.setValue(begin);
76    this->n.setValue(n);
[621]77
78  }
79
[2270]80  shared_ptr<CGenericAlgorithmTransformation> CZoomAxis::createAlgorithm(bool isSource,
[2011]81                                                        CGrid* gridDst, CGrid* gridSrc,
82                                                        int elementPositionInGrid,
83                                                        std::map<int, int>& elementPositionInGridSrc2ScalarPosition,
84                                                        std::map<int, int>& elementPositionInGridSrc2AxisPosition,
85                                                        std::map<int, int>& elementPositionInGridSrc2DomainPosition,
86                                                        std::map<int, int>& elementPositionInGridDst2ScalarPosition,
87                                                        std::map<int, int>& elementPositionInGridDst2AxisPosition,
88                                                        std::map<int, int>& elementPositionInGridDst2DomainPosition)
89  {
90    return CAxisAlgorithmZoom::create(isSource, gridDst,  gridSrc, this, elementPositionInGrid,
91                       elementPositionInGridSrc2ScalarPosition, elementPositionInGridSrc2AxisPosition, elementPositionInGridSrc2DomainPosition,
92                       elementPositionInGridDst2ScalarPosition, elementPositionInGridDst2AxisPosition, elementPositionInGridDst2DomainPosition);
93  }
[621]94}
Note: See TracBrowser for help on using the repository browser.