source: XIOS/dev/dev_trunk_graph/src/transformation/domain_algorithm/domain_algorithm_reorder.cpp @ 2019

Last change on this file since 2019 was 2019, checked in by yushan, 6 months ago

Graph intermedia commit to a tmp branch

  • Property svn:executable set to *
File size: 5.0 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(isSource, 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(bool isSource, CDomain* domainDestination, CDomain* domainSource, CReorderDomain* reorderDomain)
43: CAlgorithmTransformationNoDataModification(isSource)
44TRY
45{
46  reorderDomain->checkValid(domainSource);
47  domainDestination->checkAttributes() ; // for now but maybe use domainSource as template for domain destination
48
49  if (domainDestination->type !=  CDomain::type_attr::rectilinear)
50  {
51      ERROR("CDomainAlgorithmReorder::CDomainAlgorithmReorder(CDomain* domainDestination, CDomain* domainSource, CReorderDomain* reorderDomain)",
52           << "Domain destination is not rectilinear. This filter work only for rectilinear domain and destination domain with < id = "
53           <<domainDestination->getId() <<" > is of type "<<domainDestination->type<<std::endl);
54  }
55 
56  if (domainDestination == domainSource)
57  {
58    ERROR("CDomainAlgorithmReorder::CDomainAlgorithmReorder(CDomain* domainDestination, CDomain* domainSource, CReorderDomain* reorderDomain)",
59           << "Domain source and domain destination are the same. Please make sure domain destination refers to domain source" << std::endl
60           << "Domain source " <<domainSource->getId() << std::endl
61           << "Domain destination " <<domainDestination->getId() << std::endl);
62  }
63 
64  if (!reorderDomain->invert_lat.isEmpty())
65  {
66    CArray<int,1>& j_index=domainDestination->j_index ;
67    int nglo = j_index.numElements() ;
68    int nj_glo =domainDestination->nj_glo ;
69   
70    for (size_t i = 0; i < nglo ; ++i)
71    {
72      j_index(i)=(nj_glo-1)-j_index(i) ;
73    }
74  }
75
76  if (!reorderDomain->shift_lon_fraction.isEmpty())
77  {
78    int ni_glo =domainDestination->ni_glo ;
79    int  offset = ni_glo*reorderDomain->shift_lon_fraction ;
80    CArray<int,1>& i_index=domainDestination->i_index ;
81    int nglo = i_index.numElements() ;
82   
83    for (size_t i = 0; i < nglo ; ++i)
84    {
85      i_index(i)=  (i_index(i)+offset+ni_glo)%ni_glo ;
86    }
87  }
88
89  if (!reorderDomain->min_lon.isEmpty() && !reorderDomain->max_lon.isEmpty())
90  {
91    double min_lon=reorderDomain->min_lon ;
92    double max_lon=reorderDomain->max_lon ;
93    double delta=max_lon-min_lon ;
94   
95    if (!domainDestination->lonvalue_1d.isEmpty() )
96    {
97      CArray<double,1>& lon=domainDestination->lonvalue_1d ;
98      for (int i=0;i<lon.numElements();++i)
99      {
100        while  (lon(i) > max_lon) lon(i)=lon(i)-delta ;
101        while  (lon(i) < min_lon) lon(i)=lon(i)+delta ;
102      }
103    }
104
105    if (!domainDestination->bounds_lon_1d.isEmpty() )
106    {
107      CArray<double,2>& bounds_lon=domainDestination->bounds_lon_1d ;
108      for (int i=0;i<bounds_lon.extent(0);++i)
109      {
110        while  (bounds_lon(0,i) > max_lon) bounds_lon(0,i)=bounds_lon(0,i)-delta ;
111        while  (bounds_lon(1,i) > max_lon) bounds_lon(1,i)=bounds_lon(1,i)-delta ;
112
113        while  (bounds_lon(0,i) < min_lon) bounds_lon(0,i)=bounds_lon(0,i)+delta ;
114        while  (bounds_lon(1,i) < min_lon) bounds_lon(1,i)=bounds_lon(1,i)+delta ;
115      }
116    }
117  }
118
119  domainDestination->checkAttributes() ;
120}
121CATCH
122
123
124}
Note: See TracBrowser for help on using the repository browser.