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