[895] | 1 | #include "reduce_domain_to_axis.hpp" |
---|
| 2 | #include "type.hpp" |
---|
| 3 | #include "axis.hpp" |
---|
| 4 | #include "domain.hpp" |
---|
| 5 | |
---|
| 6 | namespace xios { |
---|
| 7 | |
---|
| 8 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 9 | |
---|
| 10 | CReduceDomainToAxis::CReduceDomainToAxis(void) |
---|
| 11 | : CObjectTemplate<CReduceDomainToAxis>(), CReduceDomainToAxisAttributes(), CTransformation<CAxis>() |
---|
| 12 | { /* Ne rien faire de plus */ } |
---|
| 13 | |
---|
| 14 | CReduceDomainToAxis::CReduceDomainToAxis(const StdString & id) |
---|
| 15 | : CObjectTemplate<CReduceDomainToAxis>(id), CReduceDomainToAxisAttributes(), CTransformation<CAxis>() |
---|
| 16 | { /* Ne rien faire de plus */ } |
---|
| 17 | |
---|
| 18 | CReduceDomainToAxis::~CReduceDomainToAxis(void) |
---|
| 19 | {} |
---|
| 20 | |
---|
| 21 | CTransformation<CAxis>* CReduceDomainToAxis::create(const StdString& id, xml::CXMLNode* node) |
---|
| 22 | { |
---|
| 23 | CReduceDomainToAxis* reduceDomain = CReduceDomainToAxisGroup::get("reduce_domain_to_axis_definition")->createChild(id); |
---|
| 24 | if (node) reduceDomain->parse(*node); |
---|
| 25 | return static_cast<CTransformation<CAxis>*>(reduceDomain); |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | bool CReduceDomainToAxis::registerTrans() |
---|
| 29 | { |
---|
| 30 | return registerTransformation(TRANS_REDUCE_DOMAIN_TO_AXIS, CReduceDomainToAxis::create); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | bool CReduceDomainToAxis::_dummyRegistered = CReduceDomainToAxis::registerTrans(); |
---|
| 34 | |
---|
| 35 | //---------------------------------------------------------------- |
---|
| 36 | |
---|
| 37 | StdString CReduceDomainToAxis::GetName(void) { return StdString("reduce_domain_to_axis"); } |
---|
| 38 | StdString CReduceDomainToAxis::GetDefName(void) { return StdString("reduce_domain_to_axis"); } |
---|
| 39 | ENodeType CReduceDomainToAxis::GetType(void) { return eReduceDomainToAxis; } |
---|
| 40 | |
---|
| 41 | void CReduceDomainToAxis::checkValid(CAxis* axisDst, CDomain* domainSrc) |
---|
| 42 | { |
---|
| 43 | if (CDomain::type_attr::unstructured == domainSrc->type) |
---|
| 44 | ERROR("CReduceDomainToAxis::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 opLists[]= {"sum","min","max"}; |
---|
| 54 | std::set<StdString> opString(opLists, opLists + sizeof(opLists)/sizeof(opLists[0])); |
---|
| 55 | |
---|
| 56 | StdString dirLists[]= {"i","j"}; |
---|
| 57 | std::set<StdString> dirString(dirLists, dirLists + sizeof(dirLists)/sizeof(dirLists[0])); |
---|
| 58 | |
---|
| 59 | if (this->operation.isEmpty()) |
---|
| 60 | ERROR("CReduceDomainToAxis::checkValid(CAxis* axisDst, CDomain* domainSrc)", |
---|
| 61 | << "An operation must be defined." |
---|
| 62 | << "Domain source " <<domainSrc->getId() << std::endl |
---|
| 63 | << "Axis destination " << axisDst->getId()); |
---|
| 64 | |
---|
| 65 | StdString op = this->operation; |
---|
| 66 | if (opString.end() == opString.find(op)) |
---|
| 67 | ERROR("CReduceDomainToAxis::checkValid(CAxis* axisDst, CDomain* domainSrc)", |
---|
| 68 | << "Operation '" << op << "' not found. Please make sure to use a supported one" |
---|
| 69 | << "Domain source " <<domainSrc->getId() << std::endl |
---|
| 70 | << "Axis destination " << axisDst->getId()); |
---|
| 71 | |
---|
| 72 | if (this->direction.isEmpty()) |
---|
| 73 | ERROR("CReduceDomainToAxis::checkValid(CAxis* axisDst, CDomain* domainSrc)", |
---|
| 74 | << "A direction to apply the operation must be defined. It should be: 'i' or 'j'" |
---|
| 75 | << "Domain source " <<domainSrc->getId() << std::endl |
---|
| 76 | << "Axis destination " << axisDst->getId()); |
---|
| 77 | |
---|
| 78 | StdString direction = this->direction; |
---|
| 79 | if (dirString.end() == dirString.find(direction)) |
---|
| 80 | { |
---|
| 81 | ERROR("CReduceDomainToAxis::checkValid(CAxis* axisDst, CDomain* domainSrc)", |
---|
| 82 | << "Direction '" << direction << " is undefined. Please make sure to use a supported one: i or j" |
---|
| 83 | << "Domain source " <<domainSrc->getId() << std::endl |
---|
| 84 | << "Axis destination " << axisDst->getId()); |
---|
| 85 | } |
---|
| 86 | else |
---|
| 87 | { |
---|
| 88 | if (0 == direction.compare("j")) |
---|
| 89 | { |
---|
| 90 | if (axis_n_glo != domain_ni_glo) |
---|
| 91 | ERROR("CReduceDomainToAxis::checkValid(CAxis* axisDst, CDomain* domainSrc)", |
---|
| 92 | << "Reduce domain along j, axis destination should have n_glo equal to ni_glo of domain source" |
---|
| 93 | << "Domain source " <<domainSrc->getId() << " has nj_glo " << domain_ni_glo << std::endl |
---|
| 94 | << "Axis destination " << axisDst->getId() << " has n_glo " << axis_n_glo); |
---|
| 95 | } |
---|
| 96 | if (0 == direction.compare("i")) |
---|
| 97 | { |
---|
| 98 | if (axis_n_glo != domain_nj_glo) |
---|
| 99 | ERROR("CReduceDomainToAxis::checkValid(CAxis* axisDst, CDomain* domainSrc)", |
---|
| 100 | << "Reduce domain along i, axis destination should have n_glo equal to nj_glo of domain source" |
---|
| 101 | << "Domain source " <<domainSrc->getId() << " has nj_glo " << domain_nj_glo << std::endl |
---|
| 102 | << "Axis destination " << axisDst->getId() << " has n_glo " << axis_n_glo); |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | } |
---|