Changeset 823 for XIOS


Ignore:
Timestamp:
02/16/16 10:14:23 (8 years ago)
Author:
mhnguyen
Message:

Implementing grid destination clone in case of two grid source

+) Clone attributes of grid destination as well as its transformation
+) Clean some redundant codes

Test
+) All tests pass

Location:
XIOS/trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/inputs/REMAP/iodef.xml

    r821 r823  
    1414     <field id="dst_field_regular" operation="instant" field_ref="tmp_field_2" grid_ref="dst_grid_regular" read_access="true"/> 
    1515     <field id="dst_field_regular_pole" operation="instant" field_ref="src_field" domain_ref="dst_domain_regular_pole"/> 
     16     <field id="dst_field_regular_pole_1" operation="instant" field_ref="tmp_field" domain_ref="dst_domain_regular_pole"/> 
    1617   </field_definition> 
    1718 
     
    2728        <field field_ref="dst_field_regular_pole" name="field" /> 
    2829     </file> 
     30     <file id="out_dst_regular_pole_1" name="out_dst_regular_pole_1" type="one_file"> 
     31        <field field_ref="dst_field_regular_pole_1" name="field" /> 
     32     </file> 
    2933     <file id="output_dst_regular" name="output_dst_regular" type="one_file"> 
    3034        <field field_ref="dst_field_regular" name="field" /> 
     
    3943        <field id="src_field_regular_tmp" name="field" domain_ref="src_domain_regular_tmp" operation="instant"/> 
    4044     </file> 
    41  
    4245     <file id="output_src_curvilinear" name="output_src_curvilinear" mode="read" type="one_file"> 
    4346        <field id="src_field_curvilinear" name="field_A" grid_ref="src_grid_curvilinear" operation="instant"/> 
  • XIOS/trunk/src/node/axis.cpp

    r821 r823  
    911911  } 
    912912 
     913  void CAxis::duplicateTransformation(CAxis* src) 
     914  { 
     915    if (src->hasTransformation()) 
     916    { 
     917      this->setTransformations(src->getAllTransformations()); 
     918    } 
     919  } 
     920 
    913921  /*! 
    914922   * Go through the hierarchy to find the axis from which the transformations must be inherited 
  • XIOS/trunk/src/node/axis.hpp

    r821 r823  
    113113         TransMapTypes getAllTransformations(); 
    114114         void fillInValues(const CArray<double,1>& values); 
     115         void duplicateTransformation(CAxis*);                   \ 
    115116 
    116117      public: 
  • XIOS/trunk/src/node/context.cpp

    r806 r823  
    451451      for (unsigned int i = 0; i < this->enabledReadModeFiles.size(); ++i) 
    452452        (void)this->enabledReadModeFiles[i]->readAttributesOfEnabledFieldsInReadMode(); 
     453   } 
     454 
     455   void CContext::solveOnlyRefOfEnabledFields(bool sendToServer) 
     456   { 
     457     int size = this->enabledFiles.size(); 
     458     for (int i = 0; i < size; ++i) 
     459     { 
     460       this->enabledFiles[i]->solveOnlyRefOfEnabledFields(sendToServer); 
     461     } 
     462 
     463     for (int i = 0; i < size; ++i) 
     464     { 
     465       this->enabledFiles[i]->generateNewTransformationGridDest(); 
     466     } 
    453467   } 
    454468 
     
    804818      this->readAttributesOfEnabledFieldsInReadModeFiles(); 
    805819     } 
     820 
     821      // Only search and rebuild all reference objects of enable fields, don't transform 
     822      this->solveOnlyRefOfEnabledFields(false); 
     823 
    806824      // Search and rebuild all reference object of enabled fields 
    807825      this->solveAllRefOfEnabledFields(false); 
  • XIOS/trunk/src/node/context.hpp

    r775 r823  
    113113         void checkAxisDomainsGridsEligibilityForCompressedOutput(); 
    114114         void prepareTimeseries(void); 
     115         void solveOnlyRefOfEnabledFields(bool sendToServer); 
    115116         void solveAllRefOfEnabledFields(bool sendToServer); 
    116117         void buildFilterGraphOfEnabledFields(); 
  • XIOS/trunk/src/node/domain.cpp

    r821 r823  
    19471947  } 
    19481948 
     1949  void CDomain::duplicateTransformation(CDomain* src) 
     1950  { 
     1951    if (src->hasTransformation()) 
     1952    { 
     1953      this->setTransformations(src->getAllTransformations()); 
     1954    } 
     1955  } 
     1956 
    19491957  /*! 
    19501958   * Go through the hierarchy to find the domain from which the transformations must be inherited 
  • XIOS/trunk/src/node/domain.hpp

    r821 r823  
    7878         TransMapTypes getAllTransformations(); 
    7979         void redistribute(int nbLocalDomain); 
     80         void duplicateTransformation(CDomain*); 
    8081 
    8182      public: 
  • XIOS/trunk/src/node/field.cpp

    r790 r823  
    3434      , nstep(0), nstepMax(0) 
    3535      , hasOutputFile(false) 
    36       , domAxisIds_("", ""), areAllReferenceSolved(false) 
     36      , domAxisIds_("", ""), areAllReferenceSolved(false), isReferenceSolved(false) 
    3737      , useCompressedOutput(false) 
    3838      , isReadDataRequestPending(false) 
     
    4545      , nstep(0), nstepMax(0) 
    4646      , hasOutputFile(false) 
    47       , domAxisIds_("", ""), areAllReferenceSolved(false) 
     47      , domAxisIds_("", ""), areAllReferenceSolved(false), isReferenceSolved(false) 
    4848      , useCompressedOutput(false) 
    4949      , isReadDataRequestPending(false) 
     
    492492   //---------------------------------------------------------------- 
    493493 
    494    void CField::solveAllReferenceEnabledField(bool doSending2Sever) 
     494   void CField::solveOnlyReferenceEnabledField(bool doSending2Server) 
    495495   { 
    496496     CContext* context = CContext::getCurrent(); 
     497     if (!isReferenceSolved) 
     498     { 
     499        isReferenceSolved = true; 
     500 
     501        if (context->hasClient) 
     502        { 
     503          solveRefInheritance(true); 
     504          if (hasDirectFieldReference()) getDirectFieldReference()->solveOnlyReferenceEnabledField(false); 
     505        } 
     506        else if (context->hasServer) 
     507          solveServerOperation(); 
     508 
     509        solveGridReference(); 
     510 
     511       if (context->hasClient) 
     512       { 
     513         solveGenerateGrid(); 
     514         buildGridTransformationGraph(); 
     515       } 
     516     } 
     517   } 
     518 
     519   /*! 
     520     Build up graph of grids which plays role of destination and source in grid transformation 
     521     This function should be called before \func solveGridReference() 
     522   */ 
     523   void CField::buildGridTransformationGraph() 
     524   { 
     525     CContext* context = CContext::getCurrent(); 
     526     if (context->hasClient) 
     527     { 
     528       if (grid && !grid->isTransformed() && hasDirectFieldReference() && grid != getDirectFieldReference()->grid) 
     529       { 
     530         grid->addTransGridSource(getDirectFieldReference()->grid); 
     531       } 
     532     } 
     533   } 
     534 
     535   /*! 
     536     Generate a new grid destination if there are more than one grid source pointing to a same grid destination 
     537   */ 
     538   void CField::generateNewTransformationGridDest() 
     539   { 
     540     CContext* context = CContext::getCurrent(); 
     541     if (context->hasClient) 
     542     { 
     543       std::map<CGrid*,std::pair<bool,StdString> >& gridSrcMap = grid->getTransGridSource(); 
     544       if (1 < gridSrcMap.size()) 
     545       { 
     546         // Search for grid source 
     547         CGrid* gridSrc = grid; 
     548         CField* currField = this; 
     549         std::vector<CField*> hieraField; 
     550 
     551         while (currField->hasDirectFieldReference() && (gridSrc == grid)) 
     552         { 
     553           hieraField.push_back(currField); 
     554           CField* tmp = currField->getDirectFieldReference(); 
     555           currField = tmp; 
     556           gridSrc = currField->grid; 
     557         } 
     558 
     559         if (gridSrcMap.end() != gridSrcMap.find(gridSrc)) 
     560         { 
     561           CGrid* gridTmp; 
     562           std::pair<bool,StdString> newGridDest = gridSrcMap[gridSrc]; 
     563           if (newGridDest.first) 
     564           { 
     565             StdString newIdGridDest = newGridDest.second; 
     566             if (!CGrid::has(newIdGridDest)) 
     567             { 
     568                ERROR("CGrid* CGrid::generateNewTransformationGridDest()", 
     569                  << " Something wrong happened! Grid whose id " << newIdGridDest 
     570                  << "should exist "); 
     571             } 
     572             gridTmp = CGrid::get(newIdGridDest); 
     573           } 
     574           else 
     575           { 
     576             StdString newIdGridDest = CGrid::generateId(gridSrc, grid); 
     577             gridTmp = CGrid::cloneGrid(newIdGridDest, grid); 
     578 
     579             (gridSrcMap[gridSrc]).first = true; 
     580             (gridSrcMap[gridSrc]).second = newIdGridDest; 
     581           } 
     582 
     583           // Update all descendants 
     584           for (std::vector<CField*>::iterator it = hieraField.begin(); it != hieraField.end(); ++it) 
     585           { 
     586             (*it)->grid = gridTmp; 
     587             (*it)->updateRef((*it)->grid); 
     588           } 
     589         } 
     590       } 
     591     } 
     592   } 
     593 
     594   void CField::updateRef(CGrid* grid) 
     595   { 
     596     if (!grid_ref.isEmpty()) grid_ref.setValue(grid->getId()); 
     597     else 
     598     { 
     599       std::vector<CAxis*> axisTmp = grid->getAxis(); 
     600       std::vector<CDomain*> domainTmp = grid->getDomains(); 
     601       if ((1<axisTmp.size()) || (1<domainTmp.size())) 
     602         ERROR("void CField::updateRef(CGrid* grid)", 
     603           << "More than one domain or axis is available for domain_ref/axis_ref of field " << this->getId()); 
     604 
     605       if ((!domain_ref.isEmpty()) && (domainTmp.empty())) 
     606         ERROR("void CField::updateRef(CGrid* grid)", 
     607           << "Incoherent between available domain and domain_ref of field " << this->getId()); 
     608       if ((!axis_ref.isEmpty()) && (axisTmp.empty())) 
     609         ERROR("void CField::updateRef(CGrid* grid)", 
     610           << "Incoherent between available axis and axis_ref of field " << this->getId()); 
     611 
     612       if (!domain_ref.isEmpty()) domain_ref.setValue(domainTmp[0]->getId()); 
     613       if (!axis_ref.isEmpty()) axis_ref.setValue(axisTmp[0]->getId()); 
     614     } 
     615   } 
     616 
     617   void CField::solveAllReferenceEnabledField(bool doSending2Server) 
     618   { 
     619     CContext* context = CContext::getCurrent(); 
     620     solveOnlyReferenceEnabledField(doSending2Server); 
     621 
    497622     if (!areAllReferenceSolved) 
    498623     { 
     
    509634        solveGridReference(); 
    510635     } 
    511      if (context->hasClient) 
    512      { 
    513        solveGenerateGrid(); 
    514      } 
    515  
    516      solveGridDomainAxisRef(doSending2Sever); 
     636 
     637     solveGridDomainAxisRef(doSending2Server); 
    517638 
    518639     if (context->hasClient) 
     
    521642     } 
    522643 
    523      solveCheckMaskIndex(doSending2Sever); 
     644     solveCheckMaskIndex(doSending2Server); 
    524645   } 
    525646 
     
    773894        if (!domain_ref.isEmpty()) 
    774895        { 
     896          StdString tmp = domain_ref.getValue(); 
    775897          if (CDomain::has(domain_ref)) 
    776898            vecDom.push_back(CDomain::get(domain_ref)); 
  • XIOS/trunk/src/node/field.hpp

    r775 r823  
    110110         void solveServerOperation(void); 
    111111         void solveCheckMaskIndex(bool doSendingIndex); 
    112          void solveAllReferenceEnabledField(bool doSending2Sever); 
     112         void solveAllReferenceEnabledField(bool doSending2Server); 
     113         void solveOnlyReferenceEnabledField(bool doSending2Server); 
     114         void generateNewTransformationGridDest(); 
     115         void updateRef(CGrid* grid); 
     116         void buildGridTransformationGraph(); 
    113117         void solveGridDomainAxisRef(bool checkAtt); 
    114118         void solveTransformedGrid(); 
     
    196200 
    197201         bool areAllReferenceSolved; 
     202         bool isReferenceSolved; 
    198203         std::pair<StdString,StdString> domAxisIds_; 
    199204         bool isReadDataRequestPending; 
  • XIOS/trunk/src/node/file.cpp

    r811 r823  
    647647   \param [in] sendToServer: Send all info to server (true) or only a part of it (false) 
    648648   */ 
     649   void CFile::solveOnlyRefOfEnabledFields(bool sendToServer) 
     650   { 
     651     int size = this->enabledFields.size(); 
     652     for (int i = 0; i < size; ++i) 
     653     { 
     654       this->enabledFields[i]->solveOnlyReferenceEnabledField(sendToServer); 
     655//       this->enabledFields[i]->buildGridTransformationGraph(); 
     656     } 
     657   } 
     658 
     659   void CFile::generateNewTransformationGridDest() 
     660   { 
     661     int size = this->enabledFields.size(); 
     662     for (int i = 0; i < size; ++i) 
     663     { 
     664       this->enabledFields[i]->generateNewTransformationGridDest(); 
     665     } 
     666   } 
     667 
     668   /*! 
     669   \brief Resolve all reference of active fields. 
     670      In order to know exactly which data each active field has, a search for all its 
     671   reference to find its parents or/and its base reference object must be done. Moreover 
     672   during this search, there are some information that can only be sent to server AFTER 
     673   all information of active fields are created on server side, e.g: checking mask or index 
     674   \param [in] sendToServer: Send all info to server (true) or only a part of it (false) 
     675   */ 
    649676   void CFile::solveAllRefOfEnabledFields(bool sendToServer) 
    650677   { 
  • XIOS/trunk/src/node/file.hpp

    r775 r823  
    106106         void solveFieldRefInheritance(bool apply); 
    107107         void processEnabledFile(void); 
     108         void solveOnlyRefOfEnabledFields(bool sendToServer); 
     109         void generateNewTransformationGridDest(); 
    108110         void solveAllRefOfEnabledFields(bool sendToServer); 
    109111         void buildFilterGraphOfEnabledFields(CGarbageCollector& gc); 
  • XIOS/trunk/src/node/grid.cpp

    r821 r823  
    3232      , transformations_(0), isTransformed_(false) 
    3333      , axisPositionInGrid_(), positionDimensionDistributed_(1), hasDomainAxisBaseRef_(false) 
     34      , gridSrc_() 
    3435   { 
    3536     setVirtualDomainGroup(); 
     
    4647      , transformations_(0), isTransformed_(false) 
    4748      , axisPositionInGrid_(), positionDimensionDistributed_(1), hasDomainAxisBaseRef_(false) 
     49      , gridSrc_() 
    4850   { 
    4951     setVirtualDomainGroup(); 
     
    551553   } 
    552554 
     555   CGrid* CGrid::cloneGrid(const StdString& idNewGrid, CGrid* gridSrc) 
     556   { 
     557     std::vector<CAxis*> axisSrcTmp = gridSrc->getAxis(), axisSrc; 
     558     std::vector<CDomain*> domainSrcTmp = gridSrc->getDomains(), domainSrc; 
     559     for (int idx = 0; idx < axisSrcTmp.size(); ++idx) 
     560     { 
     561       CAxis* axis = CAxis::createAxis(); 
     562       axis->duplicateAttributes(axisSrcTmp[idx]); 
     563       axis->duplicateTransformation(axisSrcTmp[idx]); 
     564       axis->solveRefInheritance(true); 
     565       axis->solveInheritanceTransformation(); 
     566       axisSrc.push_back(axis); 
     567     } 
     568 
     569     for (int idx = 0; idx < domainSrcTmp.size(); ++idx) 
     570     { 
     571       CDomain* domain = CDomain::createDomain(); 
     572       domain->duplicateAttributes(domainSrcTmp[idx]); 
     573       domain->duplicateTransformation(domainSrcTmp[idx]); 
     574       domain->solveRefInheritance(true); 
     575       domain->solveInheritanceTransformation(); 
     576       domainSrc.push_back(domain); 
     577     } 
     578 
     579      CGrid* grid = CGrid::createGrid(idNewGrid, domainSrc, axisSrc, gridSrc->axis_domain_order); 
     580 
     581      return grid; 
     582   } 
     583 
    553584   StdString CGrid::generateId(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, 
    554585                               const CArray<bool,1>& axisDomainOrder) 
     
    588619 
    589620      return id.str(); 
     621   } 
     622 
     623   StdString CGrid::generateId(const CGrid* gridSrc, const CGrid* gridDest) 
     624   { 
     625     StdString idSrc  = gridSrc->getId(); 
     626     StdString idDest = gridDest->getId(); 
     627 
     628     std::ostringstream id; 
     629     id << idSrc << "__" << idDest; 
     630 
     631     return id.str(); 
    590632   } 
    591633 
     
    12981340  } 
    12991341 
     1342  void CGrid::addTransGridSource(CGrid* gridSrc) 
     1343  { 
     1344    if (gridSrc_.end() == gridSrc_.find(gridSrc)) 
     1345      gridSrc_.insert(make_pair(gridSrc,make_pair(false,""))); 
     1346  } 
     1347 
     1348  std::map<CGrid*,std::pair<bool,StdString> >& CGrid::getTransGridSource() 
     1349  { 
     1350    return gridSrc_; 
     1351  } 
     1352 
    13001353  /*! 
    13011354     Complete all the necessary (and lacking) attributes of a grid 
  • XIOS/trunk/src/node/grid.hpp

    r821 r823  
    127127         static StdString generateId(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, 
    128128                                     const CArray<bool,1>& axisDomainOrder = CArray<bool,1>()); 
     129         static StdString generateId(const CGrid* gridSrc, const CGrid* gridDest); 
     130         static CGrid* cloneGrid(const StdString& idNewGrid, CGrid* gridSrc); 
    129131 
    130132      public: 
     
    191193         bool isTransformed(); 
    192194         void setTransformed(); 
     195         void addTransGridSource(CGrid* gridSrc); 
     196         std::map<CGrid*, std::pair<bool,StdString> >& getTransGridSource(); 
    193197 
    194198      public: 
     
    242246        void setTransformationAlgorithms(); 
    243247 
    244         std::vector<int> globalDim_; 
     248 
    245249 
    246250      private: 
     
    267271        CGridTransformation* transformations_; 
    268272        bool hasDomainAxisBaseRef_; 
     273        std::vector<int> globalDim_; 
     274        std::map<CGrid*, std::pair<bool,StdString> > gridSrc_; 
    269275   }; // class CGrid 
    270276 
  • XIOS/trunk/src/transformation/grid_transformation.cpp

    r821 r823  
    4343  } 
    4444 
    45 //  std::vector<CAxis*> axisSrcTmp = gridSource_->getAxis(), axisSrc; 
    46 //  std::vector<CDomain*> domainSrcTmp = gridSource_->getDomains(), domainSrc; 
    47 //  for (int idx = 0; idx < axisSrcTmp.size(); ++idx) 
    48 //  { 
    49 //    CAxis* axis = CAxis::createAxis(); 
    50 //    axis->axis_ref.setValue(axisSrcTmp[idx]->getId()); 
    51 //    axis->solveRefInheritance(true); 
    52 //    axis->solveInheritanceTransformation(); 
    53 //    axis->checkAttributesOnClient(); 
    54 //    axisSrc.push_back(axis); 
    55 //  } 
    56 // 
    57 //  for (int idx = 0; idx < domainSrcTmp.size(); ++idx) 
    58 //  { 
    59 //    CDomain* domain = CDomain::createDomain(); 
    60 //    domain->domain_ref.setValue(domainSrcTmp[idx]->getId()); 
    61 //    domain->solveRefInheritance(true); 
    62 //    domain->solveInheritanceTransformation(); 
    63 //    domain->checkAttributesOnClient(); 
    64 //    domainSrc.push_back(domain); 
    65 //  } 
    66 // 
    67 //  gridSource_ = CGrid::createGrid(domainSrc, axisSrc, gridDestination_->axis_domain_order); 
    68 //  gridSource_->computeGridGlobalDimension(domainSrc, axisSrc, gridDestination_->axis_domain_order); 
    69  
    7045  initializeMappingOfOriginalGridSource(); 
    71 //  initializeAlgorithms(); 
    7246} 
    7347 
Note: See TracChangeset for help on using the changeset viewer.