source: XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/domain_algorithm/domain_algorithm_reorder.cpp @ 1985

Last change on this file since 1985 was 1985, checked in by ymipsl, 4 years ago

intermediate commit for new tranformation engine?
YM

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.3 KB
Line 
1/*!
2   \file domain_algorithm_reorder.cpp
3   \brief Algorithm for reorder a domain.
4 */
5#include "domain_algorithm_reorder.hpp"
6#include "reorder_domain.hpp"
7#include "domain.hpp"
8#include "grid.hpp"
9#include "grid_transformation_factory_impl.hpp"
10
11namespace xios {
12CGenericAlgorithmTransformation* CDomainAlgorithmReorder::create(bool isSource, CGrid* gridDst, CGrid* gridSrc,
13                                                             CTransformation<CDomain>* transformation,
14                                                             int elementPositionInGrid,
15                                                             std::map<int, int>& elementPositionInGridSrc2ScalarPosition,
16                                                             std::map<int, int>& elementPositionInGridSrc2AxisPosition,
17                                                             std::map<int, int>& elementPositionInGridSrc2DomainPosition,
18                                                             std::map<int, int>& elementPositionInGridDst2ScalarPosition,
19                                                             std::map<int, int>& elementPositionInGridDst2AxisPosition,
20                                                             std::map<int, int>& elementPositionInGridDst2DomainPosition)
21TRY
22{
23  std::vector<CDomain*> domainListDestP = gridDst->getDomains();
24  std::vector<CDomain*> domainListSrcP  = gridSrc->getDomains();
25
26  CReorderDomain* reorderDomain = dynamic_cast<CReorderDomain*> (transformation);
27  int domainDstIndex = elementPositionInGridDst2DomainPosition[elementPositionInGrid];
28  int domainSrcIndex = elementPositionInGridSrc2DomainPosition[elementPositionInGrid];
29
30  return (new CDomainAlgorithmReorder(domainListDestP[domainDstIndex], domainListSrcP[domainSrcIndex], reorderDomain));
31}
32CATCH
33
34bool CDomainAlgorithmReorder::dummyRegistered_ = CDomainAlgorithmReorder::registerTrans();
35bool CDomainAlgorithmReorder::registerTrans()
36TRY
37{
38  return CGridTransformationFactory<CDomain>::registerTransformation(TRANS_REORDER_DOMAIN, create);
39}
40CATCH
41
42CDomainAlgorithmReorder::CDomainAlgorithmReorder(CDomain* domainDestination, CDomain* domainSource, CReorderDomain* reorderDomain)
43: CDomainAlgorithmTransformation(domainDestination, domainSource)
44TRY
45{
46  reorderDomain->checkValid(domainSource);
47  if (domainDestination->type !=  CDomain::type_attr::rectilinear)
48  {
49      ERROR("CDomainAlgorithmReorder::CDomainAlgorithmReorder(CDomain* domainDestination, CDomain* domainSource, CReorderDomain* reorderDomain)",
50           << "Domain destination is not rectilinear. This filter work only for rectilinear domain and destination domain with < id = "
51           <<domainDestination->getId() <<" > is of type "<<domainDestination->type<<std::endl);
52  }
53 
54  if (domainDestination == domainSource)
55  {
56    ERROR("CDomainAlgorithmReorder::CDomainAlgorithmReorder(CDomain* domainDestination, CDomain* domainSource, CReorderDomain* reorderDomain)",
57           << "Domain source and domain destination are the same. Please make sure domain destination refers to domain source" << std::endl
58           << "Domain source " <<domainSource->getId() << std::endl
59           << "Domain destination " <<domainDestination->getId() << std::endl);
60  }
61  this->type_ = (ELEMENT_MODIFICATION_WITHOUT_DATA);
62
63  if (!reorderDomain->invert_lat.isEmpty())
64  {
65    CArray<int,1>& j_index=domainDestination->j_index ;
66    int nglo = j_index.numElements() ;
67    int nj_glo =domainDestination->nj_glo ;
68   
69    for (size_t i = 0; i < nglo ; ++i)
70    {
71      j_index(i)=(nj_glo-1)-j_index(i) ;
72    }
73  }
74
75  if (!reorderDomain->shift_lon_fraction.isEmpty())
76  {
77    int ni_glo =domainDestination->ni_glo ;
78    int  offset = ni_glo*reorderDomain->shift_lon_fraction ;
79    CArray<int,1>& i_index=domainDestination->i_index ;
80    int nglo = i_index.numElements() ;
81   
82    for (size_t i = 0; i < nglo ; ++i)
83    {
84      i_index(i)=  (i_index(i)+offset+ni_glo)%ni_glo ;
85    }
86  }
87
88  if (!reorderDomain->min_lon.isEmpty() && !reorderDomain->max_lon.isEmpty())
89  {
90    double min_lon=reorderDomain->min_lon ;
91    double max_lon=reorderDomain->max_lon ;
92    double delta=max_lon-min_lon ;
93   
94    if (!domainDestination->lonvalue_1d.isEmpty() )
95    {
96      CArray<double,1>& lon=domainDestination->lonvalue_1d ;
97      for (int i=0;i<lon.numElements();++i)
98      {
99        while  (lon(i) > max_lon) lon(i)=lon(i)-delta ;
100        while  (lon(i) < min_lon) lon(i)=lon(i)+delta ;
101      }
102    }
103
104    if (!domainDestination->bounds_lon_1d.isEmpty() )
105    {
106      CArray<double,2>& bounds_lon=domainDestination->bounds_lon_1d ;
107      for (int i=0;i<bounds_lon.extent(0);++i)
108      {
109        while  (bounds_lon(0,i) > max_lon) bounds_lon(0,i)=bounds_lon(0,i)-delta ;
110        while  (bounds_lon(1,i) > max_lon) bounds_lon(1,i)=bounds_lon(1,i)-delta ;
111
112        while  (bounds_lon(0,i) < min_lon) bounds_lon(0,i)=bounds_lon(0,i)+delta ;
113        while  (bounds_lon(1,i) < min_lon) bounds_lon(1,i)=bounds_lon(1,i)+delta ;
114      }
115    }
116  }
117}
118CATCH
119
120/*!
121  Compute the index mapping between domain on grid source and one on grid destination
122*/
123void CDomainAlgorithmReorder::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
124{
125/*
126  this->transformationMapping_.resize(1);
127  this->transformationWeight_.resize(1);
128
129  TransformationIndexMap& transMap = this->transformationMapping_[0];
130  TransformationWeightMap& transWeight = this->transformationWeight_[0];
131*/
132}
133
134
135}
Note: See TracBrowser for help on using the repository browser.