[1985] | 1 | /*! |
---|
| 2 | \file axis_algorithm_reduce_domain.cpp |
---|
| 3 | \author Ha NGUYEN |
---|
| 4 | \since 23 June 2016 |
---|
| 5 | \date 23 June 2016 |
---|
| 6 | |
---|
| 7 | \brief Algorithm for extract a domain to an axis |
---|
| 8 | */ |
---|
| 9 | #include "axis_algorithm_extract_domain.hpp" |
---|
| 10 | #include "extract_domain_to_axis.hpp" |
---|
| 11 | #include "axis.hpp" |
---|
| 12 | #include "domain.hpp" |
---|
| 13 | #include "grid.hpp" |
---|
| 14 | #include "grid_transformation_factory_impl.hpp" |
---|
| 15 | #include "reduction.hpp" |
---|
| 16 | |
---|
[2270] | 17 | namespace xios |
---|
| 18 | { |
---|
| 19 | |
---|
| 20 | shared_ptr<CGenericAlgorithmTransformation> CAxisAlgorithmExtractDomain::create(bool isSource, CGrid* gridDst, CGrid* gridSrc, |
---|
[1985] | 21 | CTransformation<CAxis>* transformation, |
---|
| 22 | int elementPositionInGrid, |
---|
| 23 | std::map<int, int>& elementPositionInGridSrc2ScalarPosition, |
---|
| 24 | std::map<int, int>& elementPositionInGridSrc2AxisPosition, |
---|
| 25 | std::map<int, int>& elementPositionInGridSrc2DomainPosition, |
---|
| 26 | std::map<int, int>& elementPositionInGridDst2ScalarPosition, |
---|
| 27 | std::map<int, int>& elementPositionInGridDst2AxisPosition, |
---|
| 28 | std::map<int, int>& elementPositionInGridDst2DomainPosition) |
---|
| 29 | TRY |
---|
| 30 | { |
---|
| 31 | std::vector<CAxis*> axisListDestP = gridDst->getAxis(); |
---|
| 32 | std::vector<CDomain*> domainListSrcP = gridSrc->getDomains(); |
---|
| 33 | |
---|
| 34 | CExtractDomainToAxis* extractDomain = dynamic_cast<CExtractDomainToAxis*> (transformation); |
---|
| 35 | int axisDstIndex = elementPositionInGridDst2AxisPosition[elementPositionInGrid]; |
---|
| 36 | int domainSrcIndex = elementPositionInGridSrc2DomainPosition[elementPositionInGrid]; |
---|
| 37 | |
---|
[2270] | 38 | return make_shared<CAxisAlgorithmExtractDomain>(isSource, axisListDestP[axisDstIndex], domainListSrcP[domainSrcIndex], extractDomain); |
---|
[1985] | 39 | } |
---|
| 40 | CATCH |
---|
| 41 | |
---|
| 42 | bool CAxisAlgorithmExtractDomain::dummyRegistered_ = CAxisAlgorithmExtractDomain::registerTrans(); |
---|
| 43 | bool CAxisAlgorithmExtractDomain::registerTrans() |
---|
| 44 | TRY |
---|
| 45 | { |
---|
| 46 | return CGridTransformationFactory<CAxis>::registerTransformation(TRANS_EXTRACT_DOMAIN_TO_AXIS, create); |
---|
| 47 | } |
---|
| 48 | CATCH |
---|
| 49 | |
---|
| 50 | |
---|
[1988] | 51 | CAxisAlgorithmExtractDomain::CAxisAlgorithmExtractDomain(bool isSource, CAxis* axisDestination, CDomain* domainSource, CExtractDomainToAxis* algo) |
---|
[1999] | 52 | : CAlgorithmTransformationTransfer(isSource), pos_(-1), axisDest_(axisDestination), domainSrc_(domainSource) |
---|
[1985] | 53 | TRY |
---|
| 54 | { |
---|
[2255] | 55 | axisDestination->axis_type.reset(); |
---|
| 56 | axisDestination->n_glo.reset(); |
---|
| 57 | axisDestination->index.reset(); |
---|
| 58 | axisDestination->n.reset(); |
---|
| 59 | axisDestination->begin.reset(); |
---|
| 60 | |
---|
| 61 | axisDestination->mask.reset(); |
---|
| 62 | axisDestination->data_index.reset(); |
---|
| 63 | axisDestination->data_n.reset(); |
---|
| 64 | axisDestination->data_begin.reset(); |
---|
| 65 | |
---|
| 66 | axisDestination->value.reset(); |
---|
| 67 | axisDestination->label.reset(); |
---|
| 68 | axisDestination->bounds.reset(); |
---|
| 69 | |
---|
[1985] | 70 | algo->checkValid(axisDestination, domainSource); |
---|
| 71 | StdString op = "extract"; |
---|
| 72 | |
---|
[2255] | 73 | int nglo,nloc; |
---|
[1985] | 74 | switch (algo->direction) |
---|
| 75 | { |
---|
| 76 | case CExtractDomainToAxis::direction_attr::jDir: |
---|
| 77 | dir_ = jDir; |
---|
[2255] | 78 | nglo = domainSource->nj_glo.getValue(); |
---|
| 79 | nloc = domainSource->nj.getValue(); |
---|
[1985] | 80 | break; |
---|
| 81 | case CExtractDomainToAxis::direction_attr::iDir: |
---|
| 82 | dir_ = iDir; |
---|
[2255] | 83 | nglo = domainSource->ni_glo.getValue(); |
---|
| 84 | nloc = domainSource->ni.getValue(); |
---|
[1985] | 85 | break; |
---|
| 86 | default: |
---|
| 87 | break; |
---|
| 88 | } |
---|
[2255] | 89 | |
---|
| 90 | axisDestination->n_glo.setValue( nglo ); |
---|
| 91 | axisDestination->index.resize( nloc ); |
---|
| 92 | axisDestination->data_index.resize( nloc ); |
---|
| 93 | axisDestination->data_index = -1; |
---|
[1985] | 94 | |
---|
[2255] | 95 | if ( axisDestination->index.isEmpty() ) |
---|
| 96 | { |
---|
| 97 | axisDestination->n.setValue( 0 ); |
---|
| 98 | axisDestination->begin.setValue( 0 ); |
---|
| 99 | } |
---|
| 100 | |
---|
[1985] | 101 | pos_ = algo->position; |
---|
| 102 | |
---|
[1999] | 103 | auto& transMap = this->transformationMapping_; |
---|
[2255] | 104 | |
---|
| 105 | CArray<size_t,1> sourceGlobalIdx = domainSource->getLocalElement()->getGlobalIndex(); |
---|
| 106 | int indexSize = sourceGlobalIdx.numElements(); |
---|
[1985] | 107 | |
---|
[2255] | 108 | CArray<int,1> sourceWorkflowIdx = domainSource->getLocalView(CElementView::WORKFLOW)->getIndex(); |
---|
| 109 | int srcWorkflowSize = sourceWorkflowIdx.numElements(); |
---|
| 110 | |
---|
| 111 | int iIdxSrcMin = INT_MAX; |
---|
| 112 | int jIdxSrcMin = INT_MAX; |
---|
| 113 | int IdxMin = INT_MAX; |
---|
| 114 | for (int countSrc = 0; countSrc < indexSize ; ++countSrc) |
---|
| 115 | { |
---|
| 116 | if ( sourceGlobalIdx(countSrc)%domainSource->ni_glo < iIdxSrcMin ) |
---|
| 117 | iIdxSrcMin = sourceGlobalIdx(countSrc)%domainSource->ni_glo; |
---|
| 118 | if ( sourceGlobalIdx(countSrc)/domainSource->ni_glo < jIdxSrcMin ) |
---|
| 119 | jIdxSrcMin = sourceGlobalIdx(countSrc)/domainSource->ni_glo; |
---|
| 120 | if ( sourceGlobalIdx(countSrc) < IdxMin ) |
---|
| 121 | IdxMin = sourceGlobalIdx(countSrc); |
---|
| 122 | } |
---|
| 123 | |
---|
[1985] | 124 | if (jDir == dir_) |
---|
| 125 | { |
---|
[2255] | 126 | int countDest(0); |
---|
| 127 | for (int countSrc = 0; countSrc < indexSize ; ++countSrc) |
---|
[1985] | 128 | { |
---|
[2255] | 129 | if ( sourceGlobalIdx(countSrc)%domainSource->ni_glo == pos_ ) |
---|
| 130 | { |
---|
| 131 | axisDest_->index(countDest) = sourceGlobalIdx(countSrc)/domainSource->ni_glo; |
---|
| 132 | int iIdxSrc2 = (countSrc+IdxMin)%domainSource->ni_glo; |
---|
| 133 | int jIdxSrc2 = (countSrc+IdxMin)/domainSource->ni_glo; |
---|
| 134 | int convert_locally_global_idx = (jIdxSrc2-jIdxSrcMin)*domainSource->ni + (iIdxSrc2-iIdxSrcMin) ; |
---|
| 135 | bool concerned_by_WF(false); |
---|
| 136 | for ( int i = 0 ; i<sourceWorkflowIdx.numElements() ; ++i ) |
---|
| 137 | { |
---|
| 138 | if (sourceWorkflowIdx(i)==convert_locally_global_idx) |
---|
| 139 | { |
---|
| 140 | concerned_by_WF = true; |
---|
| 141 | break; |
---|
| 142 | } |
---|
| 143 | } |
---|
| 144 | if (concerned_by_WF) |
---|
| 145 | { |
---|
| 146 | axisDest_->data_index(countDest) = countDest; |
---|
| 147 | transMap[axisDest_->index(countDest)] = sourceGlobalIdx(countSrc); |
---|
| 148 | } |
---|
| 149 | countDest++; |
---|
| 150 | } |
---|
[1985] | 151 | } |
---|
| 152 | } |
---|
| 153 | else if (iDir == dir_) |
---|
| 154 | { |
---|
[2255] | 155 | int countDest(0); |
---|
| 156 | for (int countSrc = 0; countSrc < indexSize ; ++countSrc) |
---|
[1985] | 157 | { |
---|
[2255] | 158 | if ( sourceGlobalIdx(countSrc)/domainSource->ni_glo == pos_ ) |
---|
| 159 | { |
---|
| 160 | axisDest_->index(countDest) = sourceGlobalIdx(countSrc)%domainSource->ni_glo; |
---|
| 161 | int iIdxSrc2 = (countSrc+IdxMin)%domainSource->ni_glo; |
---|
| 162 | int jIdxSrc2 = (countSrc+IdxMin)/domainSource->ni_glo; |
---|
| 163 | int convert_locally_global_idx = (jIdxSrc2-jIdxSrcMin)*domainSource->ni + (iIdxSrc2-iIdxSrcMin) ; |
---|
| 164 | bool concerned_by_WF(false); |
---|
| 165 | for ( int i = 0 ; i<sourceWorkflowIdx.numElements() ; ++i ) |
---|
| 166 | { |
---|
| 167 | if (sourceWorkflowIdx(i)==convert_locally_global_idx) |
---|
| 168 | { |
---|
| 169 | concerned_by_WF = true; |
---|
| 170 | break; |
---|
| 171 | } |
---|
| 172 | } |
---|
| 173 | if (concerned_by_WF) |
---|
| 174 | { |
---|
| 175 | axisDest_->data_index(countDest) = countDest; |
---|
| 176 | transMap[axisDest_->index(countDest)] = sourceGlobalIdx(countSrc); |
---|
| 177 | } |
---|
| 178 | countDest++; |
---|
| 179 | } |
---|
[1985] | 180 | } |
---|
| 181 | } |
---|
| 182 | else |
---|
| 183 | {} |
---|
[1999] | 184 | |
---|
| 185 | axisDestination->checkAttributes() ; |
---|
| 186 | this->computeAlgorithm(domainSource->getLocalView(CElementView::WORKFLOW), axisDestination->getLocalView(CElementView::WORKFLOW)) ; |
---|
[1985] | 187 | } |
---|
| 188 | CATCH |
---|
[1999] | 189 | |
---|
| 190 | |
---|
| 191 | CAxisAlgorithmExtractDomain::~CAxisAlgorithmExtractDomain() |
---|
| 192 | TRY |
---|
| 193 | { |
---|
[1985] | 194 | } |
---|
[1999] | 195 | CATCH |
---|
| 196 | |
---|
| 197 | } |
---|