Changeset 982
- Timestamp:
- 10/27/16 18:14:46 (8 years ago)
- Location:
- XIOS/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/inputs/REMAP/iodef.xml
r978 r982 109 109 <domain_group id="domain_dst"> 110 110 <domain id="dst_domain"> 111 <interpolate_domain />111 <interpolate_domain file="weight.nc" /> 112 112 </domain> 113 113 <domain id="dst_domain_regular_pole" ni_glo="90" nj_glo="45" type="rectilinear"> -
XIOS/trunk/src/config/interpolate_domain_attribute.conf
r846 r982 3 3 DECLARE_ATTRIBUTE(int, order) 4 4 DECLARE_ATTRIBUTE(bool, renormalize) 5 6 /* Write interpolation weights into file */ 7 DECLARE_ENUM2(mode,write,read) -
XIOS/trunk/src/node/interpolate_domain.cpp
r836 r982 47 47 << "Please define a correct one") ; 48 48 } 49 50 StdString weightFile = "interpolation_weights_" + domainSrc->getDomainOutputName(); 51 52 if (!this->mode.isEmpty()) 53 { 54 if (mode_attr::read == this->mode) 55 { 56 if (this->file.isEmpty()) 57 { 58 ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)", 59 << "Read mode is activated but there is no file specified." << std::endl 60 << "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 } 93 } 94 49 95 } 50 96 -
XIOS/trunk/src/transformation/domain_algorithm_interpolate.cpp
r978 r982 48 48 49 49 CDomainAlgorithmInterpolate::CDomainAlgorithmInterpolate(CDomain* domainDestination, CDomain* domainSource, CInterpolateDomain* interpDomain) 50 : CDomainAlgorithmTransformation(domainDestination, domainSource), interpDomain_(interpDomain) 50 : CDomainAlgorithmTransformation(domainDestination, domainSource), interpDomain_(interpDomain), writeToFile_(false) 51 51 { 52 52 interpDomain_->checkValid(domainSource); 53 if ((CInterpolateDomain::mode_attr::write == interpDomain_->mode) && 54 (!interpDomain_->file.isEmpty())) 55 writeToFile_ = true; 53 56 } 54 57 … … 351 354 } 352 355 356 if (writeToFile_) 357 writeRemapInfo(interpMapValue); 353 358 exchangeRemapInfo(interpMapValue); 354 359 … … 434 439 void CDomainAlgorithmInterpolate::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) 435 440 { 436 if ( !interpDomain_->file.isEmpty())441 if (CInterpolateDomain::mode_attr::read == interpDomain_->mode) 437 442 readRemapInfo(); 438 443 else 439 computeRemap(); 444 { 445 computeRemap(); 446 } 447 } 448 449 void CDomainAlgorithmInterpolate::writeRemapInfo(std::map<int,std::vector<std::pair<int,double> > >& interpMapValue) 450 { 451 std::string filename = interpDomain_->file.getValue(); 452 writeInterpolationInfo(filename, interpMapValue); 440 453 } 441 454 442 455 void CDomainAlgorithmInterpolate::readRemapInfo() 443 456 { 444 CContext* context = CContext::getCurrent();445 CContextClient* client=context->client;446 int clientRank = client->clientRank;447 448 457 std::string filename = interpDomain_->file.getValue(); 449 458 std::map<int,std::vector<std::pair<int,double> > > interpMapValue; … … 637 646 delete [] recvBuff; 638 647 } 648 649 /*! Redefined some functions of CONetCDF4 to make use of them */ 650 CDomainAlgorithmInterpolate::WriteNetCdf::WriteNetCdf(const StdString& filename, const MPI_Comm comm) 651 : CNc4DataOutput(filename, false, false, true, comm, false, true) {} 652 int CDomainAlgorithmInterpolate::WriteNetCdf::addDimensionWrite(const StdString& name, 653 const StdSize size) 654 { 655 CONetCDF4::addDimension(name, size); 656 } 657 658 int CDomainAlgorithmInterpolate::WriteNetCdf::addVariableWrite(const StdString& name, nc_type type, 659 const std::vector<StdString>& dim) 660 { 661 CONetCDF4::addVariable(name, type, dim); 662 } 663 664 void CDomainAlgorithmInterpolate::WriteNetCdf::writeDataIndex(const CArray<int,1>& data, const StdString& name, 665 bool collective, StdSize record, 666 const std::vector<StdSize>* start, 667 const std::vector<StdSize>* count) 668 { 669 CONetCDF4::writeData<int,1>(data, name, collective, record, start, count); 670 } 671 672 void CDomainAlgorithmInterpolate::WriteNetCdf::writeDataIndex(const CArray<double,1>& data, const StdString& name, 673 bool collective, StdSize record, 674 const std::vector<StdSize>* start, 675 const std::vector<StdSize>* count) 676 { 677 CONetCDF4::writeData<double,1>(data, name, collective, record, start, count); 678 } 679 680 /* 681 Write interpolation weights into a file 682 \param [in] filename name of output file 683 \param interpMapValue mapping of global index of domain destination and domain source as well as the corresponding weight 684 */ 685 void CDomainAlgorithmInterpolate::writeInterpolationInfo(std::string& filename, 686 std::map<int,std::vector<std::pair<int,double> > >& interpMapValue) 687 { 688 CContext* context = CContext::getCurrent(); 689 CContextClient* client=context->client; 690 691 size_t n_src = domainSrc_->ni_glo * domainSrc_->nj_glo; 692 size_t n_dst = domainDest_->ni_glo * domainDest_->nj_glo; 693 694 long localNbWeight = 0; 695 long globalNbWeight; 696 long startIndex; 697 typedef std::map<int,std::vector<std::pair<int,double> > > IndexRemap; 698 IndexRemap::iterator itb = interpMapValue.begin(), it, 699 ite = interpMapValue.end(); 700 for (it = itb; it!=ite; ++it) 701 { 702 localNbWeight += (it->second).size(); 703 } 704 705 CArray<int,1> src_idx(localNbWeight); 706 CArray<int,1> dst_idx(localNbWeight); 707 CArray<double,1> weights(localNbWeight); 708 709 int index = 0; 710 for (it = itb; it !=ite; ++it) 711 { 712 std::vector<std::pair<int,double> >& tmp = it->second; 713 for (int idx = 0; idx < tmp.size(); ++idx) 714 { 715 dst_idx(index) = it->first + 1; 716 src_idx(index) = tmp[idx].first + 1; 717 weights(index) = tmp[idx].second; 718 ++index; 719 } 720 } 721 722 MPI_Allreduce(&localNbWeight, &globalNbWeight, 1, MPI_LONG, MPI_SUM, client->intraComm); 723 MPI_Scan(&localNbWeight, &startIndex, 1, MPI_LONG, MPI_SUM, client->intraComm); 724 725 std::vector<StdSize> start(1, startIndex - localNbWeight); 726 std::vector<StdSize> count(1, localNbWeight); 727 728 WriteNetCdf netCdfWriter(filename, client->intraComm); 729 730 // netCdfWriter = CONetCDF4(filename, false, false, true, client->intraComm, false); 731 732 // Define some dimensions 733 netCdfWriter.addDimensionWrite("n_src", n_src); 734 netCdfWriter.addDimensionWrite("n_dst", n_dst); 735 netCdfWriter.addDimensionWrite("n_weight", globalNbWeight); 736 737 std::vector<StdString> dims(1,"n_weight"); 738 739 // Add some variables 740 netCdfWriter.addVariableWrite("src_idx", NC_INT, dims); 741 netCdfWriter.addVariableWrite("dst_idx", NC_INT, dims); 742 netCdfWriter.addVariableWrite("weight", NC_DOUBLE, dims); 743 744 // // Write variables 745 netCdfWriter.writeDataIndex(src_idx, "src_idx", true, 0, &start, &count); 746 netCdfWriter.writeDataIndex(dst_idx, "dst_idx", true, 0, &start, &count); 747 netCdfWriter.writeDataIndex(weights, "weight", true, 0, &start, &count); 748 749 netCdfWriter.closeFile(); 750 } 639 751 640 752 /*! -
XIOS/trunk/src/transformation/domain_algorithm_interpolate.hpp
r933 r982 12 12 #include "domain_algorithm_transformation.hpp" 13 13 #include "transformation.hpp" 14 #include "nc4_data_output.hpp" 14 15 15 16 namespace xios { … … 17 18 class CDomain; 18 19 class CInterpolateDomain; 20 19 21 20 22 /*! … … 35 37 private: 36 38 void readInterpolationInfo(std::string& filename, std::map<int,std::vector<std::pair<int,double> > >& interpMapValue); 39 void writeInterpolationInfo(std::string& filename, std::map<int,std::vector<std::pair<int,double> > >& interpMapValue); 37 40 void processPole(std::map<int,std::vector<std::pair<int,double> > >& interMapValuePole, 38 41 int nbGlobalPointOnPole); 39 42 void computeRemap(); 40 43 void readRemapInfo(); 44 void writeRemapInfo(std::map<int,std::vector<std::pair<int,double> > >&); 41 45 void exchangeRemapInfo(std::map<int,std::vector<std::pair<int,double> > >& interpMapValue); 46 42 47 private: 43 48 CInterpolateDomain* interpDomain_; 49 bool writeToFile_; 50 51 // class WriteNetCdf; 52 class WriteNetCdf : public CNc4DataOutput 53 { 54 public: 55 WriteNetCdf(const StdString& filename, const MPI_Comm comm); 56 int addDimensionWrite(const StdString& name, const StdSize size = UNLIMITED_DIM); 57 int addVariableWrite(const StdString& name, nc_type type, 58 const std::vector<StdString>& dim); 59 void writeDataIndex(const CArray<int,1>& data, const StdString& name, 60 bool collective, StdSize record, 61 const std::vector<StdSize>* start = NULL, 62 const std::vector<StdSize>* count = NULL); 63 void writeDataIndex(const CArray<double,1>& data, const StdString& name, 64 bool collective, StdSize record, 65 const std::vector<StdSize>* start = NULL, 66 const std::vector<StdSize>* count = NULL); 67 }; 68 44 69 45 70 private:
Note: See TracChangeset
for help on using the changeset viewer.