source: XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/grid_algorithm.cpp @ 1999

Last change on this file since 1999 was 1999, checked in by ymipsl, 3 years ago

Adapt transformation algorithm to new infrastructure (on going...)

YM

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