[1457] | 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 | |
---|
| 11 | namespace xios { |
---|
| 12 | CGenericAlgorithmTransformation* CDomainAlgorithmReorder::create(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) |
---|
[1612] | 21 | TRY |
---|
[1457] | 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 | } |
---|
[1612] | 32 | CATCH |
---|
[1457] | 33 | |
---|
| 34 | bool CDomainAlgorithmReorder::registerTrans() |
---|
[1612] | 35 | TRY |
---|
[1457] | 36 | { |
---|
| 37 | CGridTransformationFactory<CDomain>::registerTransformation(TRANS_REORDER_DOMAIN, create); |
---|
| 38 | } |
---|
[1612] | 39 | CATCH |
---|
[1457] | 40 | |
---|
| 41 | CDomainAlgorithmReorder::CDomainAlgorithmReorder(CDomain* domainDestination, CDomain* domainSource, CReorderDomain* reorderDomain) |
---|
| 42 | : CDomainAlgorithmTransformation(domainDestination, domainSource) |
---|
[1612] | 43 | TRY |
---|
[1457] | 44 | { |
---|
| 45 | reorderDomain->checkValid(domainSource); |
---|
| 46 | if (domainDestination->type != CDomain::type_attr::rectilinear) |
---|
| 47 | { |
---|
| 48 | ERROR("CDomainAlgorithmReorder::CDomainAlgorithmReorder(CDomain* domainDestination, CDomain* domainSource, CReorderDomain* reorderDomain)", |
---|
| 49 | << "Domain destination is not rectilinear. This filter work only for rectilinear domain and destination domain with < id = " |
---|
| 50 | <<domainDestination->getId() <<" > is of type "<<domainDestination->type<<std::endl); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | if (domainDestination == domainSource) |
---|
| 54 | { |
---|
| 55 | ERROR("CDomainAlgorithmReorder::CDomainAlgorithmReorder(CDomain* domainDestination, CDomain* domainSource, CReorderDomain* reorderDomain)", |
---|
| 56 | << "Domain source and domain destination are the same. Please make sure domain destination refers to domain source" << std::endl |
---|
| 57 | << "Domain source " <<domainSource->getId() << std::endl |
---|
| 58 | << "Domain destination " <<domainDestination->getId() << std::endl); |
---|
| 59 | } |
---|
| 60 | this->type_ = (ELEMENT_MODIFICATION_WITHOUT_DATA); |
---|
| 61 | |
---|
| 62 | if (!reorderDomain->invert_lat.isEmpty()) |
---|
| 63 | { |
---|
| 64 | CArray<int,1>& j_index=domainDestination->j_index ; |
---|
| 65 | int nglo = j_index.numElements() ; |
---|
| 66 | int nj_glo =domainDestination->nj_glo ; |
---|
| 67 | |
---|
| 68 | for (size_t i = 0; i < nglo ; ++i) |
---|
| 69 | { |
---|
| 70 | j_index(i)=(nj_glo-1)-j_index(i) ; |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | if (!reorderDomain->shift_lon_fraction.isEmpty()) |
---|
| 75 | { |
---|
| 76 | int ni_glo =domainDestination->ni_glo ; |
---|
| 77 | int offset = ni_glo*reorderDomain->shift_lon_fraction ; |
---|
| 78 | CArray<int,1>& i_index=domainDestination->i_index ; |
---|
| 79 | int nglo = i_index.numElements() ; |
---|
| 80 | |
---|
| 81 | for (size_t i = 0; i < nglo ; ++i) |
---|
| 82 | { |
---|
| 83 | i_index(i)= (i_index(i)+offset+ni_glo)%ni_glo ; |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | if (!reorderDomain->min_lon.isEmpty() && !reorderDomain->max_lon.isEmpty()) |
---|
| 88 | { |
---|
| 89 | double min_lon=reorderDomain->min_lon ; |
---|
| 90 | double max_lon=reorderDomain->max_lon ; |
---|
| 91 | double delta=max_lon-min_lon ; |
---|
| 92 | |
---|
| 93 | if (!domainDestination->lonvalue_1d.isEmpty() ) |
---|
| 94 | { |
---|
| 95 | CArray<double,1>& lon=domainDestination->lonvalue_1d ; |
---|
| 96 | for (int i=0;i<lon.numElements();++i) |
---|
| 97 | { |
---|
| 98 | while (lon(i) > max_lon) lon(i)=lon(i)-delta ; |
---|
| 99 | while (lon(i) < min_lon) lon(i)=lon(i)+delta ; |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | if (!domainDestination->bounds_lon_1d.isEmpty() ) |
---|
| 104 | { |
---|
| 105 | CArray<double,2>& bounds_lon=domainDestination->bounds_lon_1d ; |
---|
| 106 | for (int i=0;i<bounds_lon.extent(0);++i) |
---|
| 107 | { |
---|
| 108 | while (bounds_lon(0,i) > max_lon) bounds_lon(0,i)=bounds_lon(0,i)-delta ; |
---|
| 109 | while (bounds_lon(1,i) > max_lon) bounds_lon(1,i)=bounds_lon(1,i)-delta ; |
---|
| 110 | |
---|
| 111 | while (bounds_lon(0,i) < min_lon) bounds_lon(0,i)=bounds_lon(0,i)+delta ; |
---|
| 112 | while (bounds_lon(1,i) < min_lon) bounds_lon(1,i)=bounds_lon(1,i)+delta ; |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | } |
---|
[1612] | 117 | CATCH |
---|
[1457] | 118 | |
---|
| 119 | /*! |
---|
| 120 | Compute the index mapping between domain on grid source and one on grid destination |
---|
| 121 | */ |
---|
| 122 | void CDomainAlgorithmReorder::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) |
---|
| 123 | { |
---|
| 124 | /* |
---|
| 125 | this->transformationMapping_.resize(1); |
---|
| 126 | this->transformationWeight_.resize(1); |
---|
| 127 | |
---|
| 128 | TransformationIndexMap& transMap = this->transformationMapping_[0]; |
---|
| 129 | TransformationWeightMap& transWeight = this->transformationWeight_[0]; |
---|
| 130 | */ |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | } |
---|