Ignore:
Timestamp:
03/22/18 10:43:20 (6 years ago)
Author:
yushan
Message:

branch_openmp merged with XIOS_DEV_CMIP6@1459

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/branch_openmp/src/transformation/domain_algorithm_interpolate.cpp

    r1338 r1460  
    5353  CContext* context = CContext::getCurrent(); 
    5454  interpDomain_->checkValid(domainSource); 
     55 
     56  detectMissingValue = interpDomain_->detect_missing_value ; 
     57  renormalize = interpDomain_->renormalize ; 
     58  quantity = interpDomain_->quantity ; 
     59 
     60  if (interpDomain_->read_write_convention == CInterpolateDomain::read_write_convention_attr::fortran) fortranConvention=true ; 
     61  else fortranConvention=false ; 
     62   
    5563  fileToReadWrite_ = "xios_interpolation_weights_"; 
    5664 
     
    100108  std::vector<double> srcPole(3,0), dstPole(3,0); 
    101109  int orderInterp = interpDomain_->order.getValue(); 
    102   bool renormalize ; 
    103   bool quantity ; 
    104  
    105   if (interpDomain_->renormalize.isEmpty()) renormalize=true; 
    106   else renormalize = interpDomain_->renormalize; 
    107  
    108   if (interpDomain_->quantity.isEmpty()) quantity=false; 
    109   else quantity = interpDomain_->quantity; 
     110 
    110111 
    111112  const double poleValue = 90.0; 
     
    456457        recvTemp[recvSourceIndexBuff[idx]] += recvSourceWeightBuff[idx]/nbGlobalPointOnPole; 
    457458      else 
    458         recvTemp[recvSourceIndexBuff[idx]] = 0.0; 
     459        recvTemp[recvSourceIndexBuff[idx]] = recvSourceWeightBuff[idx]/nbGlobalPointOnPole; 
    459460    } 
    460461 
     
    476477void CDomainAlgorithmInterpolate::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) 
    477478{ 
    478   if (readFromFile_ && !writeToFile_ 
     479  if (readFromFile_ 
    479480    readRemapInfo(); 
    480481  else 
     
    566567  } 
    567568 
    568   domainIndexClientClientMapping.computeServerIndexMapping(globalIndexInterp); 
     569  domainIndexClientClientMapping.computeServerIndexMapping(globalIndexInterp, client->serverSize); 
    569570  const CClientServerMapping::GlobalIndexMap& globalIndexInterpSendToClient = domainIndexClientClientMapping.getGlobalIndexOnServer(); 
    570571 
     
    775776 
    776777  int index = 0; 
     778  int indexOffset=0 ; 
     779  if (fortranConvention) indexOffset=1 ; 
    777780  for (it = itb; it !=ite; ++it) 
    778781  { 
     
    780783    for (int idx = 0; idx < tmp.size(); ++idx) 
    781784    { 
    782       dst_idx(index) = it->first + 1; 
    783       src_idx(index) = tmp[idx].first + 1; 
     785      dst_idx(index) = it->first + indexOffset; 
     786      src_idx(index) = tmp[idx].first + indexOffset; 
    784787      weights(index) = tmp[idx].second; 
    785788      ++index; 
     
    843846  size_t nbWeightGlo ; 
    844847 
     848 
    845849  CContext* context = CContext::getCurrent(); 
    846850  CContextClient* client=context->client; 
     
    848852  int clientSize = client->clientSize; 
    849853 
     854 
     855  { 
     856    ifstream f(filename.c_str()); 
     857    if (!f.good()) ERROR("void CDomainAlgorithmInterpolate::readInterpolationInfo", 
     858                      << "Attempt to read file weight :"  << filename << " which doesn't seem to exist." << std::endl 
     859                      << "Please check this file "); 
     860  } 
     861                   
    850862  nc_open(filename.c_str(),NC_NOWRITE, &ncid) ; 
    851863  nc_inq_dimid(ncid,"n_weight",&weightDimId) ; 
     
    882894  nc_get_vara_long(ncid, dstIndexId, &start, &nbWeight, dstIndex) ; 
    883895 
    884   for(size_t ind=0; ind<nbWeight;++ind) 
    885     interpMapValue[dstIndex[ind]-1].push_back(make_pair(srcIndex[ind]-1,weight[ind])); 
    886 } 
    887  
    888 } 
     896  int indexOffset=0 ; 
     897  if (fortranConvention) indexOffset=1 ; 
     898    for(size_t ind=0; ind<nbWeight;++ind) 
     899      interpMapValue[dstIndex[ind]-indexOffset].push_back(make_pair(srcIndex[ind]-indexOffset,weight[ind])); 
     900 } 
     901 
     902void CDomainAlgorithmInterpolate::apply(const std::vector<std::pair<int,double> >& localIndex, 
     903                                            const double* dataInput, 
     904                                            CArray<double,1>& dataOut, 
     905                                            std::vector<bool>& flagInitial, 
     906                                            bool ignoreMissingValue, bool firstPass  ) 
     907{ 
     908  int nbLocalIndex = localIndex.size();    
     909  double defaultValue = std::numeric_limits<double>::quiet_NaN(); 
     910    
     911  if (detectMissingValue) 
     912  { 
     913     if (firstPass && renormalize) 
     914     { 
     915       renormalizationFactor.resize(dataOut.numElements()) ; 
     916       renormalizationFactor=1 ; 
     917     } 
     918 
     919    for (int idx = 0; idx < nbLocalIndex; ++idx) 
     920    { 
     921      if (NumTraits<double>::isnan(*(dataInput + idx))) 
     922      { 
     923        flagInitial[localIndex[idx].first] = false; 
     924        if (renormalize) renormalizationFactor(localIndex[idx].first)-=localIndex[idx].second ; 
     925      } 
     926      else 
     927      { 
     928        dataOut(localIndex[idx].first) += *(dataInput + idx) * localIndex[idx].second; 
     929        flagInitial[localIndex[idx].first] = true; // Reset flag to indicate not all data source are nan 
     930      } 
     931    } 
     932 
     933    // If all data source are nan then data destination must be nan 
     934    for (int idx = 0; idx < nbLocalIndex; ++idx) 
     935    { 
     936      if (!flagInitial[localIndex[idx].first]) 
     937        dataOut(localIndex[idx].first) = defaultValue; 
     938    } 
     939  } 
     940  else 
     941  { 
     942    for (int idx = 0; idx < nbLocalIndex; ++idx) 
     943    { 
     944      dataOut(localIndex[idx].first) += *(dataInput + idx) * localIndex[idx].second; 
     945    } 
     946  } 
     947} 
     948 
     949void CDomainAlgorithmInterpolate::updateData(CArray<double,1>& dataOut) 
     950{ 
     951  if (detectMissingValue && renormalize) 
     952  { 
     953    if (renormalizationFactor.numElements()>0) dataOut/=renormalizationFactor ; // In some case, process doesn't received any data for interpolation (mask) 
     954                                                                                // so renormalizationFactor is not initialized 
     955  } 
     956} 
     957 
     958} 
Note: See TracChangeset for help on using the changeset viewer.