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

branch_openmp merged with XIOS_DEV_CMIP6@1459

Location:
XIOS/dev/branch_openmp/src/filter
Files:
2 added
15 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/branch_openmp/src/filter/file_writer_filter.cpp

    r1328 r1460  
    3737  } 
    3838 
     39  bool CFileWriterFilter::mustAutoTrigger() const 
     40  { 
     41    return true; 
     42  } 
     43 
    3944  bool CFileWriterFilter::isDataExpected(const CDate& date) const 
    4045  { 
  • XIOS/dev/branch_openmp/src/filter/file_writer_filter.hpp

    r1119 r1460  
    2424 
    2525      /*! 
     26       * Tests if the filter must auto-trigger. 
     27       * 
     28       * \return true if the filter must auto-trigger 
     29       */ 
     30      bool virtual mustAutoTrigger() const; 
     31 
     32      /*! 
    2633       * Tests whether data is expected for the specified date. 
    2734       * 
  • XIOS/dev/branch_openmp/src/filter/filter.cpp

    r1119 r1460  
    4141  } 
    4242 
     43  bool CFilter::mustAutoTrigger() const 
     44  { 
     45    return COutputPin::mustAutoTrigger(); 
     46  } 
     47 
    4348  bool CFilter::isDataExpected(const CDate& date) const 
    4449  { 
  • XIOS/dev/branch_openmp/src/filter/filter.hpp

    r1119 r1460  
    4949 
    5050      /*! 
     51       * Tests if the filter must auto-trigger. 
     52       * 
     53       * \return true if the filter must auto-trigger 
     54       */ 
     55      bool virtual mustAutoTrigger() const; 
     56 
     57      /*! 
    5158       * Tests whether data is expected for the specified date. 
    5259       * 
  • XIOS/dev/branch_openmp/src/filter/input_pin.hpp

    r1119 r1460  
    6060 
    6161      /*! 
     62       * Tests if the pin must auto-trigger. 
     63       * 
     64       * \return true if the pin must auto-trigger 
     65       */ 
     66      bool virtual mustAutoTrigger() const = 0; 
     67 
     68      /*! 
    6269       * Tests whether data is expected for the specified date. 
    6370       * 
  • XIOS/dev/branch_openmp/src/filter/output_pin.cpp

    r1119 r1460  
    6666  } 
    6767 
     68  bool COutputPin::mustAutoTrigger() const 
     69  { 
     70    std::vector<std::pair<boost::shared_ptr<CInputPin>, size_t> >::const_iterator it, itEnd; 
     71    for (it = outputs.begin(), itEnd = outputs.end(); it != itEnd; ++it) 
     72    { 
     73      if (it->first->mustAutoTrigger()) 
     74        return true; 
     75    } 
     76 
     77    return false; 
     78  } 
     79 
    6880  void COutputPin::setOutputTriggers() 
    6981  { 
  • XIOS/dev/branch_openmp/src/filter/output_pin.hpp

    r1119 r1460  
    4444       */ 
    4545      bool virtual canBeTriggered() const; 
     46 
     47      /*! 
     48       * Tests if the pin must auto-trigger. 
     49       * 
     50       * \return true if the pin must auto-trigger 
     51       */ 
     52      bool virtual mustAutoTrigger() const; 
    4653 
    4754      /*! 
  • XIOS/dev/branch_openmp/src/filter/source_filter.cpp

    r1328 r1460  
    77namespace xios 
    88{ 
    9   CSourceFilter::CSourceFilter(CGarbageCollector& gc, CGrid* grid, 
     9  CSourceFilter::CSourceFilter(CGarbageCollector& gc, CGrid* grid, bool compression,  
    1010                               const CDuration offset /*= NoneDu*/, bool manualTrigger /*= false*/, 
    1111                               bool hasMissingValue /*= false*/, 
     
    1313    : COutputPin(gc, manualTrigger) 
    1414    , grid(grid) 
     15    , compression(compression) 
    1516    , offset(offset) 
    1617    , hasMissingValue(hasMissingValue), defaultValue(defaultValue) 
     
    3132    packet->status = CDataPacket::NO_ERROR; 
    3233 
    33     packet->data.resize(grid->storeIndex_client.numElements()); 
    34     grid->inputField(data, packet->data); 
     34    packet->data.resize(grid->storeIndex_client.numElements());     
     35     
     36    if (compression) 
     37    { 
     38      packet->data = defaultValue; 
     39      grid->uncompressField(data, packet->data);     
     40    } 
     41    else 
     42      grid->inputField(data, packet->data); 
    3543 
     44     
     45     
     46    // if (compression) grid->inputField(data, packet->data) ; 
     47    // else 
     48    // { 
     49    //   // just make a flat copy 
     50    //   CArray<double, N> data_tmp(data.copy()) ; // supress const attribute 
     51    //   CArray<double,1> dataTmp2(data_tmp.dataFirst(),shape(data.numElements()),neverDeleteData) ; 
     52    //   packet->data = dataTmp2 ; 
     53    // } 
    3654    // Convert missing values to NaN 
    3755    if (hasMissingValue) 
     
    6583    packet->timestamp = date; 
    6684    packet->status = CDataPacket::NO_ERROR; 
    67  
    68     // if (data.size() != grid->storeIndex_toSrv.size()) 
     85     
    6986    if (data.size() != grid->storeIndex_fromSrv.size()) 
    7087      ERROR("CSourceFilter::streamDataFromServer(CDate date, const std::map<int, CArray<double, 1> >& data)", 
     
    7592    std::map<int, CArray<double, 1> >::const_iterator it, itEnd = data.end(); 
    7693    for (it = data.begin(); it != itEnd; it++) 
    77     { 
    78       // CArray<int,1>& index = grid->storeIndex_toSrv[it->first]; 
     94    {       
    7995      CArray<int,1>& index = grid->storeIndex_fromSrv[it->first]; 
    8096      for (int n = 0; n < index.numElements(); n++) 
  • XIOS/dev/branch_openmp/src/filter/source_filter.hpp

    r1205 r1460  
    2727       */ 
    2828      CSourceFilter(CGarbageCollector& gc, CGrid* grid, 
     29                    bool compression=true, 
    2930                    const CDuration offset = NoneDu, bool manualTrigger = false, 
    3031                    bool hasMissingValue = false, 
     
    6465      const bool hasMissingValue; 
    6566      const double defaultValue; 
     67      const bool compression ; //!< indicate if the data need to be compressed : on client size : true, on server side : false 
    6668  }; // class CSourceFilter 
    6769} // namespace xios 
  • XIOS/dev/branch_openmp/src/filter/spatial_transform_filter.cpp

    r1328 r1460  
    44#include "context.hpp" 
    55#include "context_client.hpp" 
     6#include "timer.hpp" 
    67using namespace ep_lib; 
    78 
     
    2930      size_t inputCount = 1 + (auxInputs.empty() ? 0 : auxInputs.size()); 
    3031      double defaultValue  = (hasMissingValue) ? std::numeric_limits<double>::quiet_NaN() : 0.0; 
    31       boost::shared_ptr<CSpatialTransformFilter> filter(new CSpatialTransformFilter(gc, engine, defaultValue, inputCount)); 
    32  
     32 
     33 
     34      const CGridTransformationSelector::ListAlgoType& algoList = gridTransformation->getAlgoList() ; 
     35      CGridTransformationSelector::ListAlgoType::const_iterator it  ; 
     36 
     37      bool isSpatialTemporal=false ; 
     38      for (it=algoList.begin();it!=algoList.end();++it)  if (it->second.first == TRANS_TEMPORAL_SPLITTING) isSpatialTemporal=true ; 
     39 
     40      boost::shared_ptr<CSpatialTransformFilter> filter ; 
     41      if( isSpatialTemporal) filter = boost::shared_ptr<CSpatialTransformFilter>(new CSpatialTemporalFilter(gc, engine, gridTransformation, defaultValue, inputCount)); 
     42      else filter = boost::shared_ptr<CSpatialTransformFilter>(new CSpatialTransformFilter(gc, engine, defaultValue, inputCount)); 
     43 
     44       
    3345      if (!lastFilter) 
    3446        lastFilter = filter; 
     
    5870      onOutputReady(outputPacket); 
    5971  } 
     72 
     73 
     74 
     75 
     76 
     77  CSpatialTemporalFilter::CSpatialTemporalFilter(CGarbageCollector& gc, CSpatialTransformFilterEngine* engine, CGridTransformation* gridTransformation, double outputValue, size_t inputSlotsCount) 
     78    : CSpatialTransformFilter(gc, engine, outputValue, inputSlotsCount), record(0) 
     79  { 
     80      const CGridTransformationSelector::ListAlgoType& algoList = gridTransformation->getAlgoList() ; 
     81      CGridTransformationSelector::ListAlgoType::const_iterator it  ; 
     82 
     83      int pos ; 
     84      for (it=algoList.begin();it!=algoList.end();++it)  
     85        if (it->second.first == TRANS_TEMPORAL_SPLITTING) 
     86        { 
     87          pos=it->first ; 
     88          if (pos < algoList.size()-1) 
     89            ERROR("SpatialTemporalFilter::CSpatialTemporalFilter(CGarbageCollector& gc, CSpatialTransformFilterEngine* engine, CGridTransformation* gridTransformation, double outputValue, size_t inputSlotsCount))", 
     90                  "temporal splitting operation must be the last of whole transformation on same grid") ; 
     91        } 
     92           
     93      CGrid* grid=gridTransformation->getGridDestination() ; 
     94 
     95      CAxis* axis = grid->getAxis(gridTransformation->getElementPositionInGridDst2AxisPosition().find(pos)->second) ; 
     96 
     97      nrecords = axis->index.numElements() ; 
     98  } 
     99 
     100 
     101  void CSpatialTemporalFilter::onInputReady(std::vector<CDataPacketPtr> data) 
     102  { 
     103    CSpatialTransformFilterEngine* spaceFilter = static_cast<CSpatialTransformFilterEngine*>(engine); 
     104    CDataPacketPtr outputPacket = spaceFilter->applyFilter(data, outputDefaultValue); 
     105 
     106    if (outputPacket) 
     107    { 
     108      size_t nelements=outputPacket->data.numElements() ; 
     109      if (!tmpData.numElements()) 
     110      { 
     111        tmpData.resize(nelements); 
     112        tmpData=outputDefaultValue ; 
     113      } 
     114 
     115      nelements/=nrecords ; 
     116      size_t offset=nelements*record ; 
     117      for(size_t i=0;i<nelements;++i)  tmpData(i+offset) = outputPacket->data(i) ; 
     118     
     119      record ++ ; 
     120      if (record==nrecords) 
     121      { 
     122        record=0 ; 
     123        CDataPacketPtr packet = CDataPacketPtr(new CDataPacket); 
     124        packet->date = data[0]->date; 
     125        packet->timestamp = data[0]->timestamp; 
     126        packet->status = data[0]->status; 
     127        packet->data.resize(tmpData.numElements()); 
     128        packet->data = tmpData; 
     129        onOutputReady(packet); 
     130        tmpData.resize(0) ; 
     131      } 
     132    } 
     133  } 
     134 
    60135 
    61136  CSpatialTransformFilterEngine::CSpatialTransformFilterEngine(CGridTransformation* gridTransformation) 
     
    122197  void CSpatialTransformFilterEngine::apply(const CArray<double, 1>& dataSrc, CArray<double,1>& dataDest) 
    123198  { 
     199    CTimer::get("CSpatialTransformFilterEngine::apply").resume();  
     200     
    124201    CContextClient* client = CContext::getCurrent()->client; 
    125202 
     
    235312 
    236313    dataDest = dataCurrentDest; 
     314 
     315    CTimer::get("CSpatialTransformFilterEngine::apply").suspend() ; 
    237316  } 
    238317} // namespace xios 
  • XIOS/dev/branch_openmp/src/filter/spatial_transform_filter.hpp

    r1334 r1460  
    33 
    44#include "filter.hpp" 
     5 
    56namespace xios 
    67{ 
     
    4849      double outputDefaultValue; 
    4950  }; // class CSpatialTransformFilter 
     51 
     52 
     53 /*! 
     54   * A specific spatial filter for the temporal_splitting transformation scalar -> axis. An incoming flux will be stored in an aditional dimension given by the destination axis. 
     55   * At each flux received, the storing index (record) is increased. When it reach the size of the axis (nrecords) a new flux is generated and the record is reset to 0 
     56   */ 
     57 
     58 class CSpatialTemporalFilter : public CSpatialTransformFilter 
     59  { 
     60    public: 
     61      /*! 
     62       * Constructs a filter wrapping the specified spatial transformation. 
     63       * 
     64       * \param gc the associated garbage collector 
     65       * \param engine the engine defining the spatial transformation 
     66       * \param [in] gridTransformation the associated transformations 
     67       * \param outputValue default value of output pin 
     68       * \param [in] inputSlotsCount number of input, by default there is only one for field src 
     69       */ 
     70      CSpatialTemporalFilter(CGarbageCollector& gc, CSpatialTransformFilterEngine* engine, CGridTransformation* gridTransformation, double outputValue, size_t inputSlotsCount = 1); 
     71 
     72 
     73    protected: 
     74      /*! 
     75        Overriding this function to process transformations with auxillary inputs 
     76      */ 
     77      void virtual onInputReady(std::vector<CDataPacketPtr> data); 
     78      //! Current record in the filter 
     79      int record ; 
     80      //! Maximum number of records 
     81      int nrecords; 
     82      //! Temporary storage for output flux 
     83      CArray<double, 1> tmpData;  
     84 
     85 
     86  }; // class CSpatialTemporalFilter 
     87 
    5088 
    5189  /*! 
  • XIOS/dev/branch_openmp/src/filter/store_filter.cpp

    r1328 r1460  
    111111  } 
    112112 
     113  bool CStoreFilter::mustAutoTrigger() const 
     114  { 
     115    return false; 
     116  } 
     117 
    113118  bool CStoreFilter::isDataExpected(const CDate& date) const 
    114119  { 
  • XIOS/dev/branch_openmp/src/filter/store_filter.hpp

    r1205 r1460  
    5353 
    5454      /*! 
     55       * Tests if the filter must auto-trigger. 
     56       * 
     57       * \return true if the filter must auto-trigger 
     58       */ 
     59      bool virtual mustAutoTrigger() const; 
     60 
     61      /*! 
    5562       * Tests whether data is expected for the specified date. 
    5663       * 
  • XIOS/dev/branch_openmp/src/filter/temporal_filter.cpp

    r1328 r1460  
    55namespace xios 
    66{ 
    7   static func::CFunctor* createFunctor(const std::string& opId, bool ignoreMissingValue, double missingValue, CArray<double, 1>& tmpData); 
     7  static func::CFunctor* createFunctor(const std::string& opId, bool ignoreMissingValue, CArray<double, 1>& tmpData); 
    88 
    99  CTemporalFilter::CTemporalFilter(CGarbageCollector& gc, const std::string& opId, 
    1010                                   const CDate& initDate, const CDuration samplingFreq, const CDuration samplingOffset, const CDuration opFreq, 
    11                                    bool ignoreMissingValue /*= false*/, double missingValue /*= 0.0*/) 
     11                                   bool ignoreMissingValue /*= false*/) 
    1212    : CFilter(gc, 1, this) 
    13     , functor(createFunctor(opId, ignoreMissingValue, missingValue, tmpData)) 
     13    , functor(createFunctor(opId, ignoreMissingValue, tmpData)) 
    1414    , isOnceOperation(functor->timeType() == func::CFunctor::once) 
    1515    , isInstantOperation(functor->timeType() == func::CFunctor::instant) 
     
    1717    , samplingOffset(samplingOffset) 
    1818    , opFreq(opFreq) 
    19     , nextSamplingDate(initDate + this->samplingOffset + initDate.getRelCalendar().getTimeStep()) 
    20     , nextOperationDate(initDate + this->samplingOffset + opFreq) 
     19    , offsetMonth({0, this->samplingOffset.month, 0, 0, 0, 0, 0}) 
     20    , offsetAllButMonth({this->samplingOffset.year, 0 , this->samplingOffset.day, 
     21                       this->samplingOffset.hour, this->samplingOffset.minute, 
     22                       this->samplingOffset.second, this->samplingOffset.timestep}) 
     23    , initDate(initDate) 
     24    , nextSamplingDate(initDate + (this->samplingOffset + initDate.getRelCalendar().getTimeStep())) 
     25    , nbOperationDates(1) 
     26//    , nextOperationDate(initDate + opFreq + this->samplingOffset) 
    2127    , isFirstOperation(true) 
    2228  { 
     
    3541      { 
    3642        usePacket = (data[0]->date >= nextSamplingDate); 
    37         outputResult = (data[0]->date + samplingFreq > nextOperationDate); 
     43//        outputResult = (data[0]->date + samplingFreq > nextOperationDate); 
     44        outputResult = (data[0]->date  > initDate + nbOperationDates*opFreq - samplingFreq + offsetMonth + offsetAllButMonth); 
    3845        copyLess = (isInstantOperation && usePacket && outputResult); 
    3946      } 
     
    5461      if (outputResult) 
    5562      { 
     63        nbOperationDates ++; 
    5664        if (!copyLess) 
    5765        { 
     
    6977 
    7078        isFirstOperation = false; 
    71         nextOperationDate = nextOperationDate + samplingFreq + opFreq - samplingFreq; 
     79//        nextOperationDate = initDate + samplingFreq + nbOperationDates*opFreq - samplingFreq + offsetMonth + offsetAllButMonth; 
    7280      } 
    7381    } 
     
    7684  } 
    7785 
     86  bool CTemporalFilter::mustAutoTrigger() const 
     87  { 
     88    return true; 
     89  } 
     90 
    7891  bool CTemporalFilter::isDataExpected(const CDate& date) const 
    7992  { 
    80     return isOnceOperation ? isFirstOperation : (date >= nextSamplingDate || date + samplingFreq > nextOperationDate); 
     93//    return isOnceOperation ? isFirstOperation : (date >= nextSamplingDate || date + samplingFreq > nextOperationDate); 
     94    return isOnceOperation ? isFirstOperation : (date >= nextSamplingDate || date > initDate + nbOperationDates*opFreq - samplingFreq + offsetMonth + offsetAllButMonth); 
    8195  } 
    8296 
    83   static func::CFunctor* createFunctor(const std::string& opId, bool ignoreMissingValue, double missingValue, CArray<double, 1>& tmpData) 
     97  static func::CFunctor* createFunctor(const std::string& opId, bool ignoreMissingValue, CArray<double, 1>& tmpData) 
    8498  { 
    8599    func::CFunctor* functor = NULL; 
    86100 
    87     double defaultValue = ignoreMissingValue ? std::numeric_limits<double>::quiet_NaN() : missingValue; 
     101    double defaultValue = std::numeric_limits<double>::quiet_NaN(); 
    88102 
    89103#define DECLARE_FUNCTOR(MType, mtype) \ 
  • XIOS/dev/branch_openmp/src/filter/temporal_filter.hpp

    r1205 r1460  
    2626       * \param ignoreMissingValue true if and only if the missing value must be ignored 
    2727                                   when doing the operation 
    28        * \param missingValue the missing value 
    2928       */ 
    3029      CTemporalFilter(CGarbageCollector& gc, const std::string& opId, 
    3130                      const CDate& initDate, const CDuration samplingFreq, const CDuration samplingOffset, const CDuration opFreq, 
    32                       bool ignoreMissingValue = false, double missingValue = 0.0); 
     31                      bool ignoreMissingValue = false); 
    3332 
    3433      /*! 
     
    3938       */ 
    4039      CDataPacketPtr virtual apply(std::vector<CDataPacketPtr> data); 
     40 
     41      /*! 
     42       * Tests if the filter must auto-trigger. 
     43       * 
     44       * \return true if the filter must auto-trigger 
     45       */ 
     46      bool virtual mustAutoTrigger() const; 
    4147 
    4248      /*! 
     
    5662      const CDuration samplingOffset; //!< The sampling offset, i.e. the offset after which the input data will be used 
    5763      const CDuration opFreq; //!< The operation frequency, i.e. the frequency at which the output data will be computed 
     64      const CDuration offsetMonth; //!< The month duration of samplingOffset 
     65      CDuration offsetAllButMonth; //!< All but the month duration of samplingOffset 
     66      const CDate initDate; 
    5867      CDate nextSamplingDate; //!< The date of the next sampling 
    59       CDate nextOperationDate; //!< The date of the next operation 
     68      int nbOperationDates; //!< The number of times an operation is performed 
     69//      CDate nextOperationDate; //!< The date of the next operation 
    6070      bool isFirstOperation; //!< True before the first operation was been computed 
    6171  }; // class CTemporalFilter 
Note: See TracChangeset for help on using the changeset viewer.