1 | /*! |
---|
2 | \file axis_algorithm_extract.cpp |
---|
3 | \brief Algorithm for extracting an axis. |
---|
4 | */ |
---|
5 | #include "axis_algorithm_extract.hpp" |
---|
6 | #include "axis.hpp" |
---|
7 | #include "grid.hpp" |
---|
8 | #include "grid_transformation_factory_impl.hpp" |
---|
9 | #include "extract_axis.hpp" |
---|
10 | |
---|
11 | namespace xios { |
---|
12 | CGenericAlgorithmTransformation* CAxisAlgorithmExtract::create(CGrid* gridDst, CGrid* gridSrc, |
---|
13 | CTransformation<CAxis>* 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) |
---|
21 | TRY |
---|
22 | { |
---|
23 | std::vector<CAxis*> axisListDestP = gridDst->getAxis(); |
---|
24 | std::vector<CAxis*> axisListSrcP = gridSrc->getAxis(); |
---|
25 | |
---|
26 | CExtractAxis* extractAxis = dynamic_cast<CExtractAxis*> (transformation); |
---|
27 | int axisDstIndex = elementPositionInGridDst2AxisPosition[elementPositionInGrid]; |
---|
28 | int axisSrcIndex = elementPositionInGridSrc2AxisPosition[elementPositionInGrid]; |
---|
29 | |
---|
30 | return (new CAxisAlgorithmExtract(axisListDestP[axisDstIndex], axisListSrcP[axisSrcIndex], extractAxis)); |
---|
31 | } |
---|
32 | CATCH |
---|
33 | |
---|
34 | bool CAxisAlgorithmExtract::registerTrans() |
---|
35 | TRY |
---|
36 | { |
---|
37 | return CGridTransformationFactory<CAxis>::registerTransformation(TRANS_EXTRACT_AXIS, create); |
---|
38 | } |
---|
39 | CATCH |
---|
40 | |
---|
41 | CAxisAlgorithmExtract::CAxisAlgorithmExtract(CAxis* axisDestination, CAxis* axisSource, CExtractAxis* extractAxis) |
---|
42 | : CAxisAlgorithmTransformation(axisDestination, axisSource) |
---|
43 | TRY |
---|
44 | { |
---|
45 | extractAxis->checkValid(axisSource); |
---|
46 | extractBegin_ = extractAxis->begin.getValue(); |
---|
47 | extractN_ = extractAxis->n.getValue(); |
---|
48 | extractEnd_ = extractBegin_ + extractN_ - 1; |
---|
49 | |
---|
50 | if (extractN_ > axisSource->n_glo.getValue()) |
---|
51 | { |
---|
52 | ERROR("CAxisAlgorithmExtract::CAxisAlgorithmExtract(CAxis* axisDestination, CAxis* axisSource, CExtractAxis* extractAxis)", |
---|
53 | << "Extract size is greater than global size of source axis" |
---|
54 | << "Global size of source axis " <<axisSource->getId() << " is " << axisSource->n_glo.getValue() << std::endl |
---|
55 | << "Extract size is " << extractN_ ); |
---|
56 | } |
---|
57 | |
---|
58 | int idxSrc, nDest = 0, beginDestLoc, beginDestGlo = 0 ; |
---|
59 | int indGloDest, indGloSrc, iSrc; |
---|
60 | for (int i = 0; i < axisSrc_->n.getValue(); i++) |
---|
61 | { |
---|
62 | idxSrc = axisSrc_->index(i); |
---|
63 | if ((idxSrc >= extractBegin_) && (idxSrc <= extractEnd_)) |
---|
64 | { |
---|
65 | if (nDest == 0) beginDestLoc = i; |
---|
66 | ++nDest; |
---|
67 | } |
---|
68 | } |
---|
69 | beginDestGlo = beginDestLoc + axisSrc_->begin - extractBegin_; |
---|
70 | axisDest_->n_glo.setValue(extractN_); |
---|
71 | axisDest_->n.setValue(nDest); |
---|
72 | axisDest_->begin.setValue(beginDestGlo); |
---|
73 | axisDest_->index.resize(nDest); |
---|
74 | |
---|
75 | axisDest_->data_n.setValue(nDest); |
---|
76 | axisDest_->data_begin.setValue(0); |
---|
77 | axisDest_->data_index.resize(nDest); |
---|
78 | |
---|
79 | axisDest_->mask.resize(nDest); |
---|
80 | if (axisSrc_->hasValue) axisDest_->value.resize(nDest); |
---|
81 | if (axisSrc_->hasLabel) axisDest_->label.resize(nDest); |
---|
82 | if (axisSrc_->hasBounds) axisDest_->bounds.resize(2,nDest); |
---|
83 | |
---|
84 | this->transformationMapping_.resize(1); |
---|
85 | this->transformationWeight_.resize(1); |
---|
86 | TransformationIndexMap& transMap = this->transformationMapping_[0]; |
---|
87 | TransformationWeightMap& transWeight = this->transformationWeight_[0]; |
---|
88 | |
---|
89 | for (int iDest = 0; iDest < nDest; iDest++) |
---|
90 | { |
---|
91 | iSrc = iDest + beginDestLoc; |
---|
92 | axisDest_->index(iDest) = iDest + beginDestGlo; |
---|
93 | axisDest_->data_index(iDest) = axisSrc_->data_index(iSrc) - beginDestLoc; |
---|
94 | axisDest_->mask(iDest) = axisSrc_->mask(iSrc); |
---|
95 | |
---|
96 | if (axisSrc_->hasValue) |
---|
97 | axisDest_->value(iDest) = axisSrc_->value(iSrc); |
---|
98 | if (axisSrc_->hasLabel) |
---|
99 | axisDest_->label(iDest) = axisSrc_->label(iSrc); |
---|
100 | if (axisSrc_->hasBounds) |
---|
101 | { |
---|
102 | axisDest_->bounds(0,iDest) = axisSrc_->bounds(0,iSrc); |
---|
103 | axisDest_->bounds(1,iDest) = axisSrc_->bounds(1,iSrc); |
---|
104 | } |
---|
105 | indGloDest = axisDest_->index(iDest); |
---|
106 | indGloSrc = axisSrc_->index(iSrc); |
---|
107 | transMap[indGloDest].push_back(indGloSrc); |
---|
108 | transWeight[indGloDest].push_back(1.0); |
---|
109 | |
---|
110 | } |
---|
111 | } |
---|
112 | CATCH |
---|
113 | |
---|
114 | /*! |
---|
115 | Compute the index mapping between domain on grid source and one on grid destination |
---|
116 | */ |
---|
117 | void CAxisAlgorithmExtract::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) |
---|
118 | { |
---|
119 | } |
---|
120 | |
---|
121 | } |
---|