- Timestamp:
- 03/21/22 15:27:07 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/weight_transform_connector.hpp
r2267 r2313 23 23 int srcSize_ ; 24 24 int dstSize_ ; 25 bool detectMissingValue_ ; 26 bool renormalize_ ; 25 27 26 28 void computeConnector(unordered_map<int, std::vector<int>>& indexMap, unordered_map<int, std::vector<double>>& weightMap) ; … … 29 31 30 32 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) ; 32 34 33 35 void transfer(int repeat, int sizeT, const CArray<double,1>& dataIn, CArray<double,1>& dataOut) … … 36 38 int srcSlice = srcSize_*sizeT ; 37 39 dataOut.resize(repeat* dstSlice) ; 38 d ataOut=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 ? 40 42 const double* input = dataIn.dataFirst() ; 41 43 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 } 42 97 43 for(int r=0;r<repeat;r++, input+=srcSlice, output+=dstSlice) 98 } 99 else 44 100 { 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 } 51 114 } 52 115 }
Note: See TracChangeset
for help on using the changeset viewer.