source: XIOS/trunk/src/node/extract_domain_to_axis.cpp @ 895

Last change on this file since 895 was 895, checked in by mhnguyen, 5 years ago

Adding a new transformation: Reduce a domain to an axis

Test
+) On Curie
+) Tests pass and are correct

File size: 4.9 KB
Line 
1#include "extract_domain_to_axis.hpp"
2#include "type.hpp"
3#include "axis.hpp"
4#include "domain.hpp"
5
6namespace xios {
7
8  /// ////////////////////// Définitions ////////////////////// ///
9
10  CExtractDomainToAxis::CExtractDomainToAxis(void)
11    : CObjectTemplate<CExtractDomainToAxis>(), CExtractDomainToAxisAttributes(), CTransformation<CAxis>()
12  { /* Ne rien faire de plus */ }
13
14  CExtractDomainToAxis::CExtractDomainToAxis(const StdString & id)
15    : CObjectTemplate<CExtractDomainToAxis>(id), CExtractDomainToAxisAttributes(), CTransformation<CAxis>()
16  { /* Ne rien faire de plus */ }
17
18  CExtractDomainToAxis::~CExtractDomainToAxis(void)
19  {}
20
21  CTransformation<CAxis>* CExtractDomainToAxis::create(const StdString& id, xml::CXMLNode* node)
22  {
23    CExtractDomainToAxis* extractDomain = CExtractDomainToAxisGroup::get("extract_domain_to_axis_definition")->createChild(id);
24    if (node) extractDomain->parse(*node);
25    return static_cast<CTransformation<CAxis>*>(extractDomain);
26  }
27
28  bool CExtractDomainToAxis::registerTrans()
29  {
30    return registerTransformation(TRANS_EXTRACT_DOMAIN_TO_AXIS, CExtractDomainToAxis::create);
31  }
32
33  bool CExtractDomainToAxis::_dummyRegistered = CExtractDomainToAxis::registerTrans();
34
35  //----------------------------------------------------------------
36
37  StdString CExtractDomainToAxis::GetName(void)    { return StdString("extract_domain_to_axis"); }
38  StdString CExtractDomainToAxis::GetDefName(void) { return StdString("extract_domain_to_axis"); }
39  ENodeType CExtractDomainToAxis::GetType(void)    { return eExtractDomainToAxis; }
40
41  void CExtractDomainToAxis::checkValid(CAxis* axisDst, CDomain* domainSrc)
42  {
43    if (CDomain::type_attr::unstructured == domainSrc->type)
44      ERROR("CExtractDomainToAxis::checkValid(CAxis* axisDst, CDomain* domainSrc)",
45       << "Domain reduction is only supported for rectilinear or curvillinear grid."
46       << "Domain source " <<domainSrc->getId() << std::endl
47       << "Axis destination " << axisDst->getId());
48
49    int axis_n_glo = axisDst->n_glo;
50    int domain_ni_glo = domainSrc->ni_glo;
51    int domain_nj_glo = domainSrc->nj_glo;
52
53    StdString dirLists[]= {"i","j"};
54    std::set<StdString> dirString(dirLists, dirLists + sizeof(dirLists)/sizeof(dirLists[0]));
55
56    if (this->direction.isEmpty())
57      ERROR("CExtractDomainToAxis::checkValid(CAxis* axisDst, CDomain* domainSrc)",
58             << "A direction to apply the operation must be defined. It should be: 'i' or 'j'"
59             << "Domain source " <<domainSrc->getId() << std::endl
60             << "Axis destination " << axisDst->getId());
61
62    StdString direction = this->direction;
63    if (dirString.end() == dirString.find(direction))
64    {
65      ERROR("CExtractDomainToAxis::checkValid(CAxis* axisDst, CDomain* domainSrc)",
66       << "Direction '" << direction << " is undefined. Please make sure to use a supported one: i or j"
67       << "Domain source " <<domainSrc->getId() << std::endl
68       << "Axis destination " << axisDst->getId());
69    }
70    else
71    {
72      if (0 == direction.compare("j"))
73      {
74        if (axis_n_glo != domain_ni_glo)
75         ERROR("CExtractDomainToAxis::checkValid(CAxis* axisDst, CDomain* domainSrc)",
76           << "Extract domain along j, axis destination should have n_glo equal to ni_glo of domain source"
77           << "Domain source " <<domainSrc->getId() << " has nj_glo " << domain_ni_glo << std::endl
78           << "Axis destination " << axisDst->getId() << " has n_glo " << axis_n_glo);
79      }
80      if (0 == direction.compare("i"))
81      {
82        if (axis_n_glo != domain_nj_glo)
83         ERROR("CExtractDomainToAxis::checkValid(CAxis* axisDst, CDomain* domainSrc)",
84           << "Extract domain along i, axis destination should have n_glo equal to nj_glo of domain source"
85           << "Domain source " <<domainSrc->getId() << " has nj_glo " << domain_nj_glo << std::endl
86           << "Axis destination " << axisDst->getId() << " has n_glo " << axis_n_glo);
87      }
88    }
89
90    int position = this->position;
91    if (0 == direction.compare("j"))
92    {
93      if ((position < 0) || (position > domain_ni_glo))
94        ERROR("CExtractDomainToAxis::checkValid(CAxis* axisDst, CDomain* domainSrc)",
95          << "Extract domain along j, position should be inside 0 and ni_glo of domain source"
96          << "Domain source " <<domainSrc->getId() << " has nj_glo " << domain_ni_glo << std::endl
97          << "Axis destination " << axisDst->getId() << std::endl
98          << "Position " << position);
99    }
100    if (0 == direction.compare("i"))
101    {
102      if ((position < 0) || (position > domain_nj_glo))
103        ERROR("CExtractDomainToAxis::checkValid(CAxis* axisDst, CDomain* domainSrc)",
104          << "Extract domain along i, position should be inside 0 and nj_glo of domain source"
105          << "Domain source " <<domainSrc->getId() << " has nj_glo " << domain_ni_glo << std::endl
106          << "Axis destination " << axisDst->getId() << std::endl
107          << "Position " << position);
108    }
109
110  }
111
112}
Note: See TracBrowser for help on using the repository browser.