Ignore:
Timestamp:
03/21/22 15:27:07 (2 years ago)
Author:
ymipsl
Message:

Take into account detect_missing_value and renormalize attribute for interpolate class transformation.

YM

Location:
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/weight_transform_connector.cpp

    r2267 r2313  
    55 
    66  CWeightTransformConnector::CWeightTransformConnector(shared_ptr<CLocalView> srcView, shared_ptr<CLocalView> dstView, unordered_map<int, std::vector<int>>& indexMap,  
    7                                                    unordered_map<int, std::vector<double>>& weightMap) : srcView_(srcView), dstView_(dstView) 
     7                                                       unordered_map<int, std::vector<double>>& weightMap,  bool detectMissingValue, bool renormalize) :  
     8                                                       srcView_(srcView), dstView_(dstView), detectMissingValue_(detectMissingValue), renormalize_(renormalize) 
    89  { 
    910    computeConnector(indexMap, weightMap) ; 
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/weight_transform_connector.hpp

    r2267 r2313  
    2323      int srcSize_ ; 
    2424      int dstSize_ ; 
     25      bool detectMissingValue_ ; 
     26      bool renormalize_ ; 
    2527 
    2628     void computeConnector(unordered_map<int, std::vector<int>>& indexMap, unordered_map<int, std::vector<double>>& weightMap) ; 
     
    2931 
    3032    CWeightTransformConnector(shared_ptr<CLocalView> srcView, shared_ptr<CLocalView> dstView, unordered_map<int, std::vector<int>>& indexMap,  
    31                               unordered_map<int, std::vector<double>>& weightMap) ; 
     33                              unordered_map<int, std::vector<double>>& weightMap, bool detectMissingValue, bool renormalize) ; 
    3234  
    3335    void transfer(int repeat, int sizeT, const CArray<double,1>& dataIn, CArray<double,1>& dataOut) 
     
    3638      int srcSlice = srcSize_*sizeT ; 
    3739      dataOut.resize(repeat* dstSlice) ; 
    38       dataOut=0 ; // what to do about missing value => next step ? 
    39  
     40      double defaultValue = std::numeric_limits<double>::quiet_NaN(); 
     41      dataOut = defaultValue ; // what to do about missing value => next step ? 
    4042      const double* input = dataIn.dataFirst()  ; 
    4143      double* output = dataOut.dataFirst()  ; 
     44      vector<bool> isFirst(dstSlice) ; 
     45      size_t pos ; 
     46       
     47      if (renormalize_) 
     48      { 
     49        double inVal ; 
     50        vector<double> renormalizeFactor(repeat*dstSlice,1) ; 
     51        double* renorm = renormalizeFactor.data() ; 
     52        for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice, renorm+=dstSlice) 
     53        { 
     54          const double* in = input; 
     55          double* out = output ; 
     56          double* ren = renorm ; 
     57          isFirst.assign(dstSlice,true) ; 
     58          pos=0 ; 
     59          int k=0 ; 
     60          for(int i=0; i<dstSize_; i++, out+=sizeT, pos+=sizeT, ren+=sizeT) 
     61            for(int j=0 ; j<nWeights_[i] ; j++,k++) 
     62              for(int l=0; l<sizeT; l++) 
     63              { 
     64                inVal=in[connector_[k]*sizeT+l] ; 
     65                if (!std::isnan(inVal)) 
     66                { 
     67                  if (isFirst[pos+l])  { out[l] = inVal*weights_[k] ; isFirst[pos+l]=false ;} 
     68                  else out[l] += inVal*weights_[k] ; 
     69                } 
     70                else  ren[l] -= weights_[k] ; 
     71              } 
     72          for(int i=0; i<dstSlice; i++) output[i] /= renorm[i] ;  
     73        } 
     74      } 
     75      else if (detectMissingValue_) 
     76      { 
     77        double inVal ; 
     78        for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice) 
     79        { 
     80          const double* in = input; 
     81          double* out = output ; 
     82          isFirst.assign(dstSlice,true) ; 
     83          pos=0 ; 
     84          int k=0 ; 
     85          for(int i=0; i<dstSize_; i++, out+=sizeT, pos+=sizeT) 
     86            for(int j=0 ; j<nWeights_[i] ; j++,k++) 
     87              for(int l=0; l<sizeT; l++) 
     88              { 
     89                inVal=in[connector_[k]*sizeT+l] ; 
     90                if (!std::isnan(inVal)) 
     91                { 
     92                  if (isFirst[pos+l])  { out[l] = inVal*weights_[k] ; isFirst[pos+l]=false ;} 
     93                  else out[l] += inVal*weights_[k] ; 
     94                } 
     95              } 
     96        } 
    4297 
    43       for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice) 
     98      } 
     99      else 
    44100      { 
    45         const double* in = input; 
    46         double* out = output ; 
    47         int k=0 ; 
    48         for(int i=0; i<dstSize_; i++, out+=sizeT) 
    49           for(int j=0 ; j<nWeights_[i] ; j++,k++) 
    50             for(int l=0; l<sizeT; l++) out[l] += in[connector_[k]*sizeT+l]*weights_[k] ; 
     101        for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice) 
     102        { 
     103          const double* in = input; 
     104          double* out = output ; 
     105          isFirst.assign(dstSlice,true) ; 
     106          pos=0 ; 
     107          int k=0 ; 
     108          for(int i=0; i<dstSize_; i++, out+=sizeT, pos+=sizeT) 
     109            for(int j=0 ; j<nWeights_[i] ; j++,k++) 
     110              for(int l=0; l<sizeT; l++)  
     111                if (isFirst[pos+l])  { out[l] = in[connector_[k]*sizeT+l]*weights_[k] ; isFirst[pos+l]=false ;} 
     112                else out[l] += in[connector_[k]*sizeT+l]*weights_[k] ; 
     113        } 
    51114      } 
    52115    } 
Note: See TracChangeset for help on using the changeset viewer.