source: XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/grid_algorithm_generic.cpp @ 2291

Last change on this file since 2291 was 2291, checked in by ymipsl, 2 years ago

Improve reduction transformation

  • make the difference between reduction over geometry or reduction between process.
  • geometrical reduction :

domain -> axis
axis -> scalar
domain -> scalar

  • reduction across processes for redondant geometrical cell :

axis -> axis
scalar -> scalar

Reduction can be local (only for the geometrical cell owned by current process) or global, using the "local" attribute (bool) over the reduction.

YM

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 2.9 KB
Line 
1#include "grid_algorithm_generic.hpp"
2#include "grid_elements.hpp"
3#include "grid_local_view.hpp"
4#include "grid.hpp"
5#include "algo_types.hpp"
6#include "context.hpp"
7#include "transform_filter.hpp"
8
9namespace xios
10{
11
12  CGridAlgorithmGeneric::CGridAlgorithmGeneric(CGrid* gridSrc, CGrid* gridDst, int pos,  shared_ptr<CGenericAlgorithmTransformation> algo)
13  : CGridAlgorithm(algo), gridSrc_(gridSrc), gridDst_(gridDst), pos_(pos)
14  {
15  }
16
17  void CGridAlgorithmGeneric::computeAlgorithm(bool eliminateRedondant)
18  {
19    shared_ptr<CGridLocalElements> gridSrcElements = gridSrc_->getGridLocalElements() ;
20    shared_ptr<CGridLocalElements> gridDstElements = gridDst_->getGridLocalElements() ;
21   
22    shared_ptr<CGridLocalView> srcView = gridSrcElements->getView(CElementView::WORKFLOW) ;
23    shared_ptr<CGridLocalView> dstView = gridDstElements->getView(CElementView::WORKFLOW) ;
24    MPI_Comm comm = CContext::getCurrent()->getIntraComm() ;
25    int commSize = CContext::getCurrent()->getIntraCommSize() ;
26    int commRank = CContext::getCurrent()->getIntraCommRank() ;
27   
28    auto& elements =  gridSrcElements->getElements() ;
29    int nElements = elements.size() ;
30    vector<shared_ptr<CLocalElement>> remoteElements(nElements) ;
31    vector<shared_ptr<CLocalView>> remoteViews(nElements) ;
32    for(int i=0;i<nElements;i++)
33    {
34      if (i==pos_) remoteElements[i] = algorithm_->getRecvElement() ;
35      else
36      { 
37        CArray<size_t,1> globalIndexView ;
38        srcView->getView(i)->getGlobalIndexView(globalIndexView) ;
39        remoteElements[i] = make_shared<CLocalElement>(commRank, srcView->getView(i)->getGlobalSize(),globalIndexView) ;
40        remoteElements[i]->addFullView() ;
41        if (i>pos_) dimBefore_ *= srcView->getView(i)->getSize() ;
42        else dimAfter_ *= srcView->getView(i)->getSize() ;
43         
44      }
45      remoteViews[i] = remoteElements[i] -> getView(CElementView::FULL);
46    }
47
48    gridTransformConnector_ = make_shared<CGridTransformConnector>(srcView->getViews(), remoteViews, comm ) ;
49    gridTransformConnector_->computeConnector(eliminateRedondant) ;
50 
51  }
52
53  void CGridAlgorithmGeneric::apply(const CArray<double,1>& dataIn, CArray<double,1>& dataOut)
54  {
55    CArray<double,1> dataOutTmp ;
56    gridTransformConnector_->transfer(dataIn, dataOutTmp) ;
57    algorithm_->apply(dimBefore_, dimAfter_, dataOutTmp, dataOut) ;
58  }
59
60  void CGridAlgorithmGeneric::apply(const CArray<double,1>& dataIn, const vector<CArray<double,1>>& auxData, CArray<double,1>& dataOut)
61  {
62    CArray<double,1> dataOutTmp ;
63    vector<CArray<double,1>> auxDataOutTmp(auxData.size()) ;
64
65    gridTransformConnector_->transfer(dataIn, dataOutTmp) ;
66    for (int i=0; i<auxData.size();i++) 
67    {
68      if (algorithm_->transformAuxField(i)) gridTransformConnector_->transfer(auxData[i], auxDataOutTmp[i]) ;
69      else auxDataOutTmp[i].reference(auxData[i]) ;
70    }
71
72    algorithm_->apply(dimBefore_, dimAfter_, dataOutTmp, auxDataOutTmp, dataOut) ;
73  }
74 
75
76}
Note: See TracBrowser for help on using the repository browser.