Changeset 1004


Ignore:
Timestamp:
11/25/16 14:12:15 (7 years ago)
Author:
mhnguyen
Message:

Some modifications of reading/writing interpolation weight from/into a file
There are 3 attributes concerning read/write weights from/into a file

  • write_weight: true/false. Default value: false
  • weight_filename.
  • mode: Default value: compute + read: read from file whose name is weight_filename + compute: compute weights + read_or_compute: if weight_filename already exists, the weights will be read from it; otherwise the weights will be computed

In mode compute and read_or_compute, if there is no weight_filename, a filename whose format
xios_interpolation_weight_nameOfContext_nameOfDomainSource_nameOfDomainDestination.nc will be used for read/write.

Test
+) On Curie
+) Work

Location:
XIOS/trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/config/interpolate_domain_attribute.conf

    r982 r1004  
    55 
    66/* Write interpolation weights into file */ 
    7 DECLARE_ENUM2(mode,write,read) 
     7DECLARE_ENUM3(mode,compute,read,read_or_compute) 
     8DECLARE_ATTRIBUTE(StdString, weight_filename) 
     9DECLARE_ATTRIBUTE(bool, write_weight) 
  • XIOS/trunk/src/node/interpolate_domain.cpp

    r982 r1004  
    4848    } 
    4949 
    50     StdString weightFile = "interpolation_weights_" + domainSrc->getDomainOutputName(); 
     50    if (this->mode.isEmpty()) this->mode.setValue(mode_attr::compute); 
     51    if (this->write_weight.isEmpty()) this->write_weight.setValue(false); 
    5152 
    52     if (!this->mode.isEmpty()) 
    53     {  
    54       if (mode_attr::read == this->mode) 
    55       { 
    56          if (this->file.isEmpty()) 
    57          { 
     53    StdString weightFile; 
     54    switch (this->mode) 
     55    { 
     56      case mode_attr::read: 
     57        if (this->file.isEmpty()) 
     58        { 
     59          if (!this->write_weight) 
    5860            ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)", 
    5961                 << "Read mode is activated but there is no file specified." << std::endl 
    6062                 << "Please define a correct file containing interpolation weights with option 'file'. "); 
    61          } 
    62          else 
    63          { 
    64            weightFile = this->file; 
    65            ifstream f(weightFile.c_str()); 
    66            if (!f.good()) 
    67              ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)", 
    68                    << "Read mode is activated but file "  << weightFile << " doesn't exist." << std::endl 
    69                    << "Please check this file "); 
    70          } 
    71       } 
    72       else 
    73       { 
    74         if (file.isEmpty()) 
    75           this->file.setValue(weightFile); 
    76       }    
    77     } 
    78     else 
    79     { 
    80       if (!file.isEmpty()) // set mode read 
    81       { 
    82          weightFile = this->file; 
    83          ifstream f(weightFile.c_str()); 
    84          if (!f.good()) // file doesn't exist 
    85            this->mode.setValue(mode_attr::write); 
    86          else 
    87            this->mode.setValue(mode_attr::read); 
    88       } 
    89       else // only calculate weights() Mode set write but there is no file) 
    90       { 
    91         this->mode.setValue(mode_attr::write); 
    92       } 
     63        } 
     64        else 
     65        { 
     66          weightFile = this->file; 
     67          ifstream f(weightFile.c_str()); 
     68          if (!f.good()) 
     69            ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)", 
     70                  << "Read mode is activated but file "  << weightFile << " doesn't exist." << std::endl 
     71                  << "Please check this file "); 
     72        } 
     73        break; 
     74      case mode_attr::compute: 
     75        break; 
     76      case mode_attr::read_or_compute: 
     77        if (!this->file.isEmpty() && !this->write_weight) 
     78        { 
     79          weightFile = this->file; 
     80          ifstream f(weightFile.c_str()); 
     81          if (!f.good()) 
     82            ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)", 
     83                  << "read_or_compute mode is activated but file "  << weightFile << " doesn't exist." << std::endl 
     84                  << "Please check this file "); 
     85        } 
     86        break; 
     87      default: 
     88        break; 
    9389    } 
    9490 
  • XIOS/trunk/src/node/interpolate_domain.hpp

    r836 r1004  
    5050      virtual ~CInterpolateDomain(void); 
    5151 
    52       virtual void checkValid(CDomain* axisDest); 
     52      virtual void checkValid(CDomain* domainSource); 
    5353 
    5454      /// Accesseurs statiques /// 
  • XIOS/trunk/src/transformation/domain_algorithm_interpolate.cpp

    r982 r1004  
    4848 
    4949CDomainAlgorithmInterpolate::CDomainAlgorithmInterpolate(CDomain* domainDestination, CDomain* domainSource, CInterpolateDomain* interpDomain) 
    50 : CDomainAlgorithmTransformation(domainDestination, domainSource), interpDomain_(interpDomain), writeToFile_(false) 
    51 { 
     50: CDomainAlgorithmTransformation(domainDestination, domainSource), interpDomain_(interpDomain), writeToFile_(false), readFromFile_(false) 
     51{ 
     52  CContext* context = CContext::getCurrent(); 
    5253  interpDomain_->checkValid(domainSource); 
    53   if ((CInterpolateDomain::mode_attr::write == interpDomain_->mode) && 
    54       (!interpDomain_->file.isEmpty())) 
    55     writeToFile_ = true; 
     54  fileToReadWrite_ = "xios_interpolation_weights_"; 
     55 
     56  if (interpDomain_->weight_filename.isEmpty()) 
     57  { 
     58    fileToReadWrite_ += context->getId() + "_" +  
     59                    domainSource->getDomainOutputName() + "_" +  
     60                    domainDestination->getDomainOutputName() + ".nc";     
     61  } 
     62  else  
     63    fileToReadWrite_ = interpDomain_->weight_filename; 
     64 
     65  ifstream f(fileToReadWrite_.c_str());   
     66  switch (interpDomain_->mode) 
     67  { 
     68    case CInterpolateDomain::mode_attr::read: 
     69      readFromFile_ = true;       
     70      break; 
     71    case CInterpolateDomain::mode_attr::compute: 
     72      readFromFile_ = false; 
     73      break; 
     74    case CInterpolateDomain::mode_attr::read_or_compute:       
     75      if (!f.good()) 
     76        readFromFile_ = false; 
     77      else 
     78        readFromFile_ = true; 
     79      break; 
     80    default: 
     81      break; 
     82  }  
     83 
     84  writeToFile_ = interpDomain_->write_weight;   
     85     
    5686} 
    5787 
     
    354384  } 
    355385 
    356   if (writeToFile_) 
     386  if (writeToFile_ && !readFromFile_) 
    357387     writeRemapInfo(interpMapValue); 
    358388  exchangeRemapInfo(interpMapValue); 
     
    439469void CDomainAlgorithmInterpolate::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) 
    440470{ 
    441   if (CInterpolateDomain::mode_attr::read == interpDomain_->mode 
     471  if (readFromFile_ && !writeToFile_ 
    442472    readRemapInfo(); 
    443473  else 
     
    448478 
    449479void CDomainAlgorithmInterpolate::writeRemapInfo(std::map<int,std::vector<std::pair<int,double> > >& interpMapValue) 
    450 { 
    451   std::string filename = interpDomain_->file.getValue(); 
    452   writeInterpolationInfo(filename, interpMapValue); 
     480 
     481  writeInterpolationInfo(fileToReadWrite_, interpMapValue); 
    453482} 
    454483 
    455484void CDomainAlgorithmInterpolate::readRemapInfo() 
    456 { 
    457   std::string filename = interpDomain_->file.getValue(); 
     485 
    458486  std::map<int,std::vector<std::pair<int,double> > > interpMapValue; 
    459   readInterpolationInfo(filename, interpMapValue); 
     487  readInterpolationInfo(fileToReadWrite_, interpMapValue); 
    460488 
    461489  exchangeRemapInfo(interpMapValue); 
  • XIOS/trunk/src/transformation/domain_algorithm_interpolate.hpp

    r982 r1004  
    4848  CInterpolateDomain* interpDomain_; 
    4949  bool writeToFile_; 
     50  bool readFromFile_; 
     51  StdString fileToReadWrite_; 
    5052 
    5153  // class WriteNetCdf; 
Note: See TracChangeset for help on using the changeset viewer.