Ignore:
Timestamp:
12/16/14 12:55:53 (10 years ago)
Author:
mhnguyen
Message:

Reorganizing structure of grid

+) Grid doesn't have domain_ref and axis_ref anymore.
All domain and axis of a grid must be inside grid (These domain and axis can be defined or refer to others)
+) Grid contains list of domain and axis
+) Reorder some functions to make sure new functionlities work

Test
+) On Curie
+) Mode attached and detached
+) Only test_new_features
+) Passed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/node/field.cpp

    r538 r540  
    288288   //---------------------------------------------------------------- 
    289289 
    290    /*! 
    291    \brief Get pointer to direct field to which the current field refers. 
    292    */ 
    293    CField* CField::getDirectFieldReference(void) const 
    294    { 
    295       if (this->field_ref.isEmpty()) 
    296          return (this->getBaseFieldReference()); 
    297  
    298       if (! CField::has(this->field_ref.getValue())) 
    299          ERROR("CField::getDirectFieldReference(void)", 
    300                << "[ ref_name = " << this->field_ref.getValue() << "]" 
    301                << " invalid field name !"); 
    302  
    303       return (CField::get(this->field_ref.getValue())); 
    304    } 
    305  
    306    //---------------------------------------------------------------- 
    307  
    308    CField* CField::getBaseFieldReference(void) const 
    309    { 
    310       return (baseRefObject); 
    311    } 
    312  
    313    //---------------------------------------------------------------- 
    314  
    315    const std::vector<CField*>& CField::getAllReference(void) const 
    316    { 
    317       return (refObject); 
    318    } 
    319  
    320    //---------------------------------------------------------------- 
    321  
    322    const StdString & CField::getBaseFieldId(void) const 
    323    { 
    324       return (this->getBaseFieldReference()->getId()); 
    325    } 
    326  
    327    //---------------------------------------------------------------- 
    328  
    329290   const CDuration & CField::getFreqOperation(void) const 
    330291   { 
     
    345306   } 
    346307 
    347    //---------------------------------------------------------------- 
    348  
    349    bool CField::hasDirectFieldReference(void) const 
    350    { 
    351      return (!this->field_ref.isEmpty()); 
    352    } 
    353308 
    354309   bool CField::isActive(void) const 
     
    431386       active=true; 
    432387     } 
    433    } 
    434  
    435    /*! 
    436    \brief Searching for all reference of a field 
    437    If a field refers to (an)other field(s), we will search for all its referenced parents. 
    438    Moreover, if any father, direct or indirect (e.g: two levels up), has non-empty attributes, 
    439    all its attributes will be added to the current field 
    440    \param [in] apply Flag to specify whether current field uses attributes of its father 
    441                in case the attribute is empty (true) or its attributes are replaced by ones of its father (false) 
    442    */ 
    443    void CField::solveRefInheritance(bool apply) 
    444    { 
    445       std::set<CField *> sset; 
    446       CField* refer_sptr; 
    447       CField * refer_ptr = this; 
    448  
    449       while (refer_ptr->hasDirectFieldReference()) 
    450       { 
    451          refer_sptr = refer_ptr->getDirectFieldReference(); 
    452          refer_ptr  = refer_sptr; 
    453  
    454          if(sset.end() != sset.find(refer_ptr)) 
    455          { 
    456             DEBUG (<< "Circular dependency stopped for field object on " 
    457                    << "\"" + refer_ptr->getId() + "\" !"); 
    458             break; 
    459          } 
    460  
    461          SuperClassAttribute::setAttributes(refer_ptr, apply); 
    462          sset.insert(refer_ptr); 
    463       } 
    464    } 
    465  
    466  
    467    /*! 
    468    \brief Only on SERVER side. Remove all field_ref from current field 
    469    On creating a new field on server side, redundant "field_ref" is still kept in the attribute list 
    470    of the current field. This function removes this from current field 
    471    */ 
    472    void CField::removeRefInheritance() 
    473    { 
    474      if (this->field_ref.isEmpty()) return; 
    475      this->clearAttribute("field_ref"); 
    476    } 
    477  
    478    void CField::solveBaseReference(void) 
    479    { 
    480       std::set<CField *> sset; 
    481       CField* refer_sptr; 
    482       CField * refer_ptr = this; 
    483  
    484       if (this->hasDirectFieldReference())  baseRefObject = getDirectFieldReference(); 
    485       else  baseRefObject = CField::get(this); 
    486  
    487       while (refer_ptr->hasDirectFieldReference()) 
    488       { 
    489          refer_sptr = refer_ptr->getDirectFieldReference(); 
    490          refer_ptr  = refer_sptr; 
    491  
    492          if(sset.end() != sset.find(refer_ptr)) 
    493          { 
    494             DEBUG (<< "Circular dependency stopped for field object on " 
    495                    << "\"" + refer_ptr->getId() + "\" !"); 
    496             break; 
    497          } 
    498  
    499          sset.insert(refer_ptr); 
    500       } 
    501  
    502       if (hasDirectFieldReference()) baseRefObject->addReference(this) ; 
    503388   } 
    504389 
     
    652537      } 
    653538 
    654       if (grid_ref.isEmpty() &&  domain_ref.isEmpty()) 
     539      if (grid_ref.isEmpty() &&  domain_ref.isEmpty() && axis_ref.isEmpty()) 
    655540      { 
    656541            ERROR("CField::solveGridReference(void)", 
    657                   << "The horizontal domain for this field is not defined"); 
    658  
     542                  << "At least one dimension must be defined for this field."); 
     543      } 
     544 
     545//     if (!grid_ref.isEmpty()) 
     546//     { 
     547//       domain = grid->domain; 
     548//       axis = grid->axis; 
     549//     } 
     550 
     551//     CType<string> goodDomain ; 
     552//     CType<string> goodAxis ; 
     553//     if (!grid_ref.isEmpty()) 
     554//     { 
     555//       if (!grid->domain_ref.isEmpty()) goodDomain=grid->domain_ref ; 
     556//       if (!grid->axis_ref.isEmpty()) goodAxis=grid->axis_ref ; 
     557//     } 
     558//     if (!domain_ref.isEmpty()) goodDomain=domain_ref ; 
     559//     if (!axis_ref.isEmpty()) goodAxis=axis_ref ; 
     560 
     561//     CArray<std::string,1> domListTmp = grid->domainList.getValue(); 
     562//     CArray<std::string,1> axisListTmp = grid->axisList.getValue(); 
     563 
     564     std::vector<std::string> domList, axisList; 
     565     if (0 != grid) 
     566     { 
     567       domList = grid->getDomainList(); 
     568       axisList = grid->getAxisList(); 
    659569     } 
    660570 
    661      CType<string> goodDomain ; 
    662      CType<string> goodAxis ; 
    663      if (!grid_ref.isEmpty()) 
     571     if (domList.empty() && axisList.empty()) 
    664572     { 
    665        if (!grid->domain_ref.isEmpty()) goodDomain=grid->domain_ref ; 
    666        if (!grid->axis_ref.isEmpty()) goodAxis=grid->axis_ref ; 
     573       std::vector<CDomain*> vecDom; 
     574       if (0 != domain) vecDom.push_back(domain); 
     575       std::vector<CAxis*> vecAxis; 
     576       if (0 != axis) vecAxis.push_back(axis); 
     577       this->grid = CGrid::createGrid(vecDom, vecAxis); 
    667578     } 
    668      if (!domain_ref.isEmpty()) goodDomain=domain_ref ; 
    669      if (!axis_ref.isEmpty()) goodAxis=axis_ref ; 
    670  
    671  
    672      if (goodDomain.isEmpty()) 
    673      { 
    674        ERROR("CField::solveGridReference(void)", << "The horizontal domain for this field is not defined"); 
    675      } 
    676      else 
    677      { 
    678        if (CDomain::has(goodDomain)) domain = CDomain::get(goodDomain) ; 
    679        else ERROR("CField::solveGridReference(void)",<< "Reference to the domain \'"<<goodDomain.get() << "\' is wrong") ; 
    680      } 
    681  
    682      if (!goodAxis.isEmpty()) 
    683      { 
    684        if (CAxis::has(goodAxis))  axis = CAxis::get(goodAxis) ; 
    685        else  ERROR("CField::solveGridReference(void)", << "Reference to the axis \'" 
    686                   << goodAxis.get() <<"\' is wrong") ; 
    687      } 
    688  
    689      bool nothingToDo=false ; 
    690  
    691      if (!grid_ref.isEmpty()) 
    692      { 
    693        if (!grid->domain_ref.isEmpty() && goodDomain.get() == grid->domain_ref.get()) 
    694          if (goodAxis.isEmpty()) nothingToDo=true ; 
    695          else if (!grid->axis_ref.isEmpty()) 
    696                  if (grid->axis_ref.get()==goodAxis.get()) nothingToDo=true ; 
    697      } 
    698  
    699      if (!nothingToDo) 
    700      { 
    701        if (!goodAxis.isEmpty()) 
    702        { 
    703          this->grid = CGrid::createGrid(domain, axis) ; 
    704          this->grid_ref.setValue(this->grid->getId()); 
    705        } 
    706        else 
    707        { 
    708          this->grid = CGrid::createGrid(domain) ; 
    709          this->grid_ref.setValue(this->grid->getId()); 
    710        } 
    711      } 
     579 
     580//     std::string goodDomain = domListTmp[0]; 
     581//     std::string goodAxis = axisListTmp[0]; 
     582 
     583//     if (goodDomain.isEmpty()) 
     584//     if (goodDomain.empty()) 
     585//     { 
     586//       ERROR("CField::solveGridReference(void)", << "The horizontal domain for this field is not defined"); 
     587//     } 
     588//     else 
     589//     { 
     590//       if (CDomain::has(goodDomain)) domain = CDomain::get(goodDomain) ; 
     591//       else ERROR("CField::solveGridReference(void)",<< "Reference to the domain \'" 
     592//                  <<goodDomain << "\' is wrong") ; 
     593////                  <<goodDomain.get() << "\' is wrong") ; 
     594//     } 
     595// 
     596////     if (!goodAxis.isEmpty()) 
     597//     if (!goodAxis.empty()) 
     598//     { 
     599//       if (CAxis::has(goodAxis))  axis = CAxis::get(goodAxis) ; 
     600//       else  ERROR("CField::solveGridReference(void)", << "Reference to the axis \'" 
     601//                  << goodAxis <<"\' is wrong") ; 
     602//                  << goodAxis.get() <<"\' is wrong") ; 
     603//     } 
     604 
     605//     bool nothingToDo=false ; 
     606// 
     607//     if (!grid_ref.isEmpty()) 
     608//     { 
     609//       if (!grid->domain_ref.isEmpty() && goodDomain.get() == grid->domain_ref.get()) 
     610//         if (goodAxis.isEmpty()) nothingToDo=true ; 
     611//         else if (!grid->axis_ref.isEmpty()) 
     612//                 if (grid->axis_ref.get()==goodAxis.get()) nothingToDo=true ; 
     613//     } 
     614// 
     615//     nothingToDo = true; 
     616//     if (!nothingToDo) 
     617//     { 
     618//       if (!goodAxis.isEmpty()) 
     619//       { 
     620//         this->grid = CGrid::createGrid(domain, axis) ; 
     621//         this->grid_ref.setValue(this->grid->getId()); 
     622//       } 
     623//       else 
     624//       { 
     625//         this->grid = CGrid::createGrid(domain) ; 
     626//         this->grid_ref.setValue(this->grid->getId()); 
     627//       } 
     628//     } 
    712629 
    713630//     grid->solveReference() ; 
     
    803720    } 
    804721    return &instantData ; 
    805   } 
    806  
    807   void CField::addReference(CField* field) 
    808   { 
    809     refObject.push_back(field) ; 
    810722  } 
    811723 
     
    1047959   } 
    1048960 
    1049  
    1050  
     961   DEFINE_REF_FUNC(Field,field) 
     962 
     963//  void CField::addReference(CField* field) 
     964//  { 
     965//    refObject.push_back(field) ; 
     966//  } 
     967// 
     968//   //---------------------------------------------------------------- 
     969// 
     970//   bool CField::hasDirectFieldReference(void) const 
     971//   { 
     972//     return (!this->field_ref.isEmpty()); 
     973//   } 
     974// 
     975//   //---------------------------------------------------------------- 
     976// 
     977//   const StdString & CField::getBaseFieldId(void) const 
     978//   { 
     979//      return (this->getBaseFieldReference()->getId()); 
     980//   } 
     981// 
     982// 
     983//   //---------------------------------------------------------------- 
     984// 
     985//   /*! 
     986//   \brief Get pointer to direct field to which the current field refers. 
     987//   */ 
     988//   CField* CField::getDirectFieldReference(void) const 
     989//   { 
     990//      if (this->field_ref.isEmpty()) 
     991//         return (this->getBaseFieldReference()); 
     992// 
     993//      if (! CField::has(this->field_ref.getValue())) 
     994//         ERROR("CField::getDirectFieldReference(void)", 
     995//               << "[ ref_name = " << this->field_ref.getValue() << "]" 
     996//               << " invalid field name !"); 
     997// 
     998//      return (CField::get(this->field_ref.getValue())); 
     999//   } 
     1000// 
     1001//   //---------------------------------------------------------------- 
     1002// 
     1003//   CField* CField::getBaseFieldReference(void) const 
     1004//   { 
     1005//      return (baseRefObject); 
     1006//   } 
     1007// 
     1008//   //---------------------------------------------------------------- 
     1009// 
     1010//   const std::vector<CField*>& CField::getAllReference(void) const 
     1011//   { 
     1012//      return (refObject); 
     1013//   } 
     1014// 
     1015// 
     1016//   /*! 
     1017//   \brief Searching for all reference of a field 
     1018//   If a field refers to (an)other field(s), we will search for all its referenced parents. 
     1019//   Moreover, if any father, direct or indirect (e.g: two levels up), has non-empty attributes, 
     1020//   all its attributes will be added to the current field 
     1021//   \param [in] apply Flag to specify whether current field uses attributes of its father 
     1022//               in case the attribute is empty (true) or its attributes are replaced by ones of its father (false) 
     1023//   */ 
     1024//   void CField::solveRefInheritance(bool apply) 
     1025//   { 
     1026//      std::set<CField *> sset; 
     1027//      CField* refer_sptr; 
     1028//      CField * refer_ptr = this; 
     1029// 
     1030//      while (refer_ptr->hasDirectFieldReference()) 
     1031//      { 
     1032//         refer_sptr = refer_ptr->getDirectFieldReference(); 
     1033//         refer_ptr  = refer_sptr; 
     1034// 
     1035//         if(sset.end() != sset.find(refer_ptr)) 
     1036//         { 
     1037//            DEBUG (<< "Circular dependency stopped for field object on " 
     1038//                   << "\"" + refer_ptr->getId() + "\" !"); 
     1039//            break; 
     1040//         } 
     1041// 
     1042//         SuperClassAttribute::setAttributes(refer_ptr, apply); 
     1043//         sset.insert(refer_ptr); 
     1044//      } 
     1045//   } 
     1046// 
     1047//   /*! 
     1048//   \brief Only on SERVER side. Remove all field_ref from current field 
     1049//   On creating a new field on server side, redundant "field_ref" is still kept in the attribute list 
     1050//   of the current field. This function removes this from current field 
     1051//   */ 
     1052//   void CField::removeRefInheritance() 
     1053//   { 
     1054//     if (this->field_ref.isEmpty()) return; 
     1055//     this->clearAttribute("field_ref"); 
     1056//   } 
     1057// 
     1058//   void CField::solveBaseReference(void) 
     1059//   { 
     1060//      std::set<CField *> sset; 
     1061//      CField* refer_sptr; 
     1062//      CField * refer_ptr = this; 
     1063// 
     1064//      if (this->hasDirectFieldReference())  baseRefObject = getDirectFieldReference(); 
     1065//      else  baseRefObject = CField::get(this); 
     1066// 
     1067//      while (refer_ptr->hasDirectFieldReference()) 
     1068//      { 
     1069//         refer_sptr = refer_ptr->getDirectFieldReference(); 
     1070//         refer_ptr  = refer_sptr; 
     1071// 
     1072//         if(sset.end() != sset.find(refer_ptr)) 
     1073//         { 
     1074//            DEBUG (<< "Circular dependency stopped for field object on " 
     1075//                   << "\"" + refer_ptr->getId() + "\" !"); 
     1076//            break; 
     1077//         } 
     1078// 
     1079//         sset.insert(refer_ptr); 
     1080//      } 
     1081// 
     1082//      if (hasDirectFieldReference()) baseRefObject->addReference(this) ; 
     1083//   } 
     1084// 
    10511085 
    10521086} // namespace xios 
Note: See TracChangeset for help on using the changeset viewer.