[623] | 1 | /*! |
---|
| 2 | \file grid_transformation.cpp |
---|
| 3 | \author Ha NGUYEN |
---|
| 4 | \since 14 May 2015 |
---|
[630] | 5 | \date 02 Jul 2015 |
---|
[623] | 6 | |
---|
| 7 | \brief Interface for all transformations. |
---|
| 8 | */ |
---|
[620] | 9 | #include "grid_transformation.hpp" |
---|
[623] | 10 | #include "axis_algorithm_inverse.hpp" |
---|
| 11 | #include "axis_algorithm_zoom.hpp" |
---|
[630] | 12 | #include "axis_algorithm_interpolate.hpp" |
---|
[631] | 13 | #include "domain_algorithm_zoom.hpp" |
---|
[689] | 14 | #include "domain_algorithm_interpolate.hpp" |
---|
[622] | 15 | #include "context.hpp" |
---|
| 16 | #include "context_client.hpp" |
---|
[620] | 17 | #include "transformation_mapping.hpp" |
---|
[621] | 18 | #include "axis_algorithm_transformation.hpp" |
---|
[660] | 19 | #include "distribution_client.hpp" |
---|
[821] | 20 | #include "mpi_tag.hpp" |
---|
[829] | 21 | #include <boost/unordered_map.hpp> |
---|
[620] | 22 | |
---|
| 23 | namespace xios { |
---|
| 24 | CGridTransformation::CGridTransformation(CGrid* destination, CGrid* source) |
---|
[622] | 25 | : gridSource_(source), gridDestination_(destination), originalGridSource_(source), |
---|
[827] | 26 | algoTypes_(), nbAlgos_(0), currentGridIndexToOriginalGridIndex_(), tempGrids_(), |
---|
[832] | 27 | auxInputs_(), dynamicalTransformation_(false), timeStamp_() |
---|
[821] | 28 | |
---|
[620] | 29 | { |
---|
| 30 | //Verify the compatibity between two grids |
---|
| 31 | int numElement = gridDestination_->axis_domain_order.numElements(); |
---|
| 32 | if (numElement != gridSource_->axis_domain_order.numElements()) |
---|
| 33 | ERROR("CGridTransformation::CGridTransformation(CGrid* destination, CGrid* source)", |
---|
| 34 | << "Two grids have different number of elements" |
---|
| 35 | << "Number of elements of grid source " <<gridSource_->getId() << " is " << gridSource_->axis_domain_order.numElements() << std::endl |
---|
| 36 | << "Number of elements of grid destination " <<gridDestination_->getId() << " is " << numElement); |
---|
| 37 | |
---|
| 38 | for (int i = 0; i < numElement; ++i) |
---|
| 39 | { |
---|
| 40 | if (gridDestination_->axis_domain_order(i) != gridSource_->axis_domain_order(i)) |
---|
| 41 | ERROR("CGridTransformation::CGridTransformation(CGrid* destination, CGrid* source)", |
---|
| 42 | << "Transformed grid and its grid source have incompatible elements" |
---|
| 43 | << "Grid source " <<gridSource_->getId() << std::endl |
---|
| 44 | << "Grid destination " <<gridDestination_->getId()); |
---|
| 45 | } |
---|
| 46 | |
---|
[622] | 47 | initializeMappingOfOriginalGridSource(); |
---|
[620] | 48 | } |
---|
| 49 | |
---|
[624] | 50 | /*! |
---|
| 51 | Initialize the mapping between the first grid source and the original one |
---|
| 52 | In a series of transformation, for each step, there is a need to "create" a new grid that plays a role of "temporary" source. |
---|
| 53 | Because at the end of the series, we need to know about the index mapping between the final grid destination and original grid source, |
---|
| 54 | for each transformation, we need to make sure that the current "temporary source" maps its global index correctly to the original one. |
---|
| 55 | */ |
---|
[622] | 56 | void CGridTransformation::initializeMappingOfOriginalGridSource() |
---|
| 57 | { |
---|
| 58 | CContext* context = CContext::getCurrent(); |
---|
[653] | 59 | CContextClient* client = context->client; |
---|
[622] | 60 | |
---|
[821] | 61 | // Initialize algorithms |
---|
| 62 | initializeAlgorithms(); |
---|
[622] | 63 | |
---|
[821] | 64 | ListAlgoType::const_iterator itb = listAlgos_.begin(), |
---|
| 65 | ite = listAlgos_.end(), it; |
---|
| 66 | |
---|
| 67 | for (it = itb; it != ite; ++it) |
---|
| 68 | { |
---|
| 69 | ETranformationType transType = (it->second).first; |
---|
| 70 | if (!isSpecialTransformation(transType)) ++nbAlgos_; |
---|
| 71 | } |
---|
[622] | 72 | } |
---|
| 73 | |
---|
[620] | 74 | CGridTransformation::~CGridTransformation() |
---|
| 75 | { |
---|
[827] | 76 | std::vector<CGenericAlgorithmTransformation*>::const_iterator itb = algoTransformation_.begin(), it, |
---|
| 77 | ite = algoTransformation_.end(); |
---|
[622] | 78 | for (it = itb; it != ite; ++it) delete (*it); |
---|
[620] | 79 | } |
---|
| 80 | |
---|
[624] | 81 | /*! |
---|
| 82 | Initialize the algorithms (transformations) |
---|
| 83 | */ |
---|
[620] | 84 | void CGridTransformation::initializeAlgorithms() |
---|
| 85 | { |
---|
[631] | 86 | std::vector<int> axisPositionInGrid; |
---|
| 87 | std::vector<int> domPositionInGrid; |
---|
| 88 | std::vector<CAxis*> axisListDestP = gridDestination_->getAxis(); |
---|
| 89 | std::vector<CDomain*> domListDestP = gridDestination_->getDomains(); |
---|
| 90 | |
---|
| 91 | int idx = 0; |
---|
| 92 | for (int i = 0; i < gridDestination_->axis_domain_order.numElements(); ++i) |
---|
| 93 | { |
---|
| 94 | if (false == (gridDestination_->axis_domain_order)(i)) |
---|
| 95 | { |
---|
| 96 | axisPositionInGrid.push_back(idx); |
---|
| 97 | ++idx; |
---|
| 98 | } |
---|
| 99 | else |
---|
| 100 | { |
---|
| 101 | ++idx; |
---|
| 102 | domPositionInGrid.push_back(idx); |
---|
| 103 | ++idx; |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | for (int i = 0; i < axisListDestP.size(); ++i) |
---|
| 108 | { |
---|
| 109 | elementPosition2AxisPositionInGrid_[axisPositionInGrid[i]] = i; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | for (int i = 0; i < domListDestP.size(); ++i) |
---|
| 113 | { |
---|
| 114 | elementPosition2DomainPositionInGrid_[domPositionInGrid[i]] = i; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | idx = 0; |
---|
| 118 | for (int i = 0; i < gridDestination_->axis_domain_order.numElements(); ++i) |
---|
| 119 | { |
---|
| 120 | if (false == (gridDestination_->axis_domain_order)(i)) |
---|
| 121 | { |
---|
| 122 | initializeAxisAlgorithms(idx); |
---|
| 123 | ++idx; |
---|
| 124 | } |
---|
| 125 | else |
---|
| 126 | { |
---|
| 127 | ++idx; |
---|
| 128 | initializeDomainAlgorithms(idx); |
---|
| 129 | ++idx; |
---|
| 130 | } |
---|
| 131 | } |
---|
[620] | 132 | } |
---|
| 133 | |
---|
| 134 | /*! |
---|
| 135 | Initialize the algorithms corresponding to transformation info contained in each axis. |
---|
| 136 | If an axis has transformations, these transformations will be represented in form of vector of CTransformation pointers |
---|
| 137 | In general, each axis can have several transformations performed on itself. However, should they be done seperately or combinely (of course in order)? |
---|
| 138 | For now, one approach is to do these combinely but maybe this needs changing. |
---|
[631] | 139 | \param [in] axisPositionInGrid position of an axis in grid. (for example: a grid with one domain and one axis, position of domain is 1, position of axis is 2) |
---|
[620] | 140 | */ |
---|
[631] | 141 | void CGridTransformation::initializeAxisAlgorithms(int axisPositionInGrid) |
---|
[620] | 142 | { |
---|
| 143 | std::vector<CAxis*> axisListDestP = gridDestination_->getAxis(); |
---|
| 144 | if (!axisListDestP.empty()) |
---|
| 145 | { |
---|
[631] | 146 | if (axisListDestP[elementPosition2AxisPositionInGrid_[axisPositionInGrid]]->hasTransformation()) |
---|
[620] | 147 | { |
---|
[631] | 148 | CAxis::TransMapTypes trans = axisListDestP[elementPosition2AxisPositionInGrid_[axisPositionInGrid]]->getAllTransformations(); |
---|
| 149 | CAxis::TransMapTypes::const_iterator itb = trans.begin(), it, |
---|
| 150 | ite = trans.end(); |
---|
| 151 | int transformationOrder = 0; |
---|
| 152 | for (it = itb; it != ite; ++it) |
---|
[620] | 153 | { |
---|
[631] | 154 | listAlgos_.push_back(std::make_pair(axisPositionInGrid, std::make_pair(it->first, transformationOrder))); |
---|
| 155 | algoTypes_.push_back(false); |
---|
| 156 | ++transformationOrder; |
---|
[827] | 157 | std::vector<StdString> auxInput = (it->second)->checkAuxInputs(); |
---|
| 158 | for (int idx = 0; idx < auxInput.size(); ++idx) auxInputs_.push_back(auxInput[idx]); |
---|
[620] | 159 | } |
---|
| 160 | } |
---|
[631] | 161 | } |
---|
| 162 | } |
---|
[620] | 163 | |
---|
[631] | 164 | /*! |
---|
| 165 | Initialize the algorithms corresponding to transformation info contained in each domain. |
---|
| 166 | If a domain has transformations, they will be represented in form of vector of CTransformation pointers |
---|
| 167 | In general, each domain can have several transformations performed on itself. |
---|
| 168 | \param [in] domPositionInGrid position of a domain in grid. (for example: a grid with one domain and one axis, position of domain is 1, position of axis is 2) |
---|
| 169 | */ |
---|
| 170 | void CGridTransformation::initializeDomainAlgorithms(int domPositionInGrid) |
---|
| 171 | { |
---|
| 172 | std::vector<CDomain*> domListDestP = gridDestination_->getDomains(); |
---|
| 173 | if (!domListDestP.empty()) |
---|
| 174 | { |
---|
| 175 | if (domListDestP[elementPosition2DomainPositionInGrid_[domPositionInGrid]]->hasTransformation()) |
---|
[620] | 176 | { |
---|
[631] | 177 | CDomain::TransMapTypes trans = domListDestP[elementPosition2DomainPositionInGrid_[domPositionInGrid]]->getAllTransformations(); |
---|
| 178 | CDomain::TransMapTypes::const_iterator itb = trans.begin(), it, |
---|
| 179 | ite = trans.end(); |
---|
| 180 | int transformationOrder = 0; |
---|
| 181 | for (it = itb; it != ite; ++it) |
---|
[620] | 182 | { |
---|
[631] | 183 | listAlgos_.push_back(std::make_pair(domPositionInGrid, std::make_pair(it->first, transformationOrder))); |
---|
| 184 | algoTypes_.push_back(true); |
---|
| 185 | ++transformationOrder; |
---|
[827] | 186 | std::vector<StdString> auxInput = (it->second)->checkAuxInputs(); |
---|
| 187 | for (int idx = 0; idx < auxInput.size(); ++idx) auxInputs_.push_back(auxInput[idx]); |
---|
[620] | 188 | } |
---|
| 189 | } |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | } |
---|
| 193 | |
---|
[624] | 194 | /*! |
---|
| 195 | Select algorithm correspoding to its transformation type and its position in each element |
---|
| 196 | \param [in] elementPositionInGrid position of element in grid. e.g: a grid has 1 domain and 1 axis, then position of domain is 1 (because it contains 2 basic elements) |
---|
| 197 | and position of axis is 2 |
---|
| 198 | \param [in] transType transformation type, for now we have Zoom_axis, inverse_axis |
---|
| 199 | \param [in] transformationOrder position of the transformation in an element (an element can have several transformation) |
---|
[631] | 200 | \param [in] isDomainAlgo flag to specify type of algorithm (for domain or axis) |
---|
[624] | 201 | */ |
---|
[631] | 202 | void CGridTransformation::selectAlgo(int elementPositionInGrid, ETranformationType transType, int transformationOrder, bool isDomainAlgo) |
---|
[622] | 203 | { |
---|
[631] | 204 | if (isDomainAlgo) selectDomainAlgo(elementPositionInGrid, transType, transformationOrder); |
---|
| 205 | else selectAxisAlgo(elementPositionInGrid, transType, transformationOrder); |
---|
[622] | 206 | } |
---|
| 207 | |
---|
[624] | 208 | /*! |
---|
| 209 | Select algorithm of an axis correspoding to its transformation type and its position in each element |
---|
| 210 | \param [in] elementPositionInGrid position of element in grid. e.g: a grid has 1 domain and 1 axis, then position of domain is 1 (because it contains 2 basic elements) |
---|
| 211 | and position of axis is 2 |
---|
| 212 | \param [in] transType transformation type, for now we have Zoom_axis, inverse_axis |
---|
| 213 | \param [in] transformationOrder position of the transformation in an element (an element can have several transformation) |
---|
| 214 | */ |
---|
[622] | 215 | void CGridTransformation::selectAxisAlgo(int elementPositionInGrid, ETranformationType transType, int transformationOrder) |
---|
| 216 | { |
---|
| 217 | std::vector<CAxis*> axisListDestP = gridDestination_->getAxis(); |
---|
| 218 | std::vector<CAxis*> axisListSrcP = gridSource_->getAxis(); |
---|
| 219 | |
---|
| 220 | int axisIndex = elementPosition2AxisPositionInGrid_[elementPositionInGrid]; |
---|
| 221 | CAxis::TransMapTypes trans = axisListDestP[axisIndex]->getAllTransformations(); |
---|
| 222 | CAxis::TransMapTypes::const_iterator it = trans.begin(); |
---|
| 223 | |
---|
| 224 | for (int i = 0; i < transformationOrder; ++i, ++it) {} // Find the correct transformation |
---|
| 225 | |
---|
| 226 | CZoomAxis* zoomAxis = 0; |
---|
[630] | 227 | CInterpolateAxis* interpAxis = 0; |
---|
[622] | 228 | CGenericAlgorithmTransformation* algo = 0; |
---|
| 229 | switch (transType) |
---|
| 230 | { |
---|
[630] | 231 | case TRANS_INTERPOLATE_AXIS: |
---|
| 232 | interpAxis = dynamic_cast<CInterpolateAxis*> (it->second); |
---|
| 233 | algo = new CAxisAlgorithmInterpolate(axisListDestP[axisIndex], axisListSrcP[axisIndex], interpAxis); |
---|
| 234 | break; |
---|
[622] | 235 | case TRANS_ZOOM_AXIS: |
---|
| 236 | zoomAxis = dynamic_cast<CZoomAxis*> (it->second); |
---|
[623] | 237 | algo = new CAxisAlgorithmZoom(axisListDestP[axisIndex], axisListSrcP[axisIndex], zoomAxis); |
---|
[622] | 238 | break; |
---|
| 239 | case TRANS_INVERSE_AXIS: |
---|
[623] | 240 | algo = new CAxisAlgorithmInverse(axisListDestP[axisIndex], axisListSrcP[axisIndex]); |
---|
[622] | 241 | break; |
---|
| 242 | default: |
---|
| 243 | break; |
---|
| 244 | } |
---|
| 245 | algoTransformation_.push_back(algo); |
---|
| 246 | |
---|
| 247 | } |
---|
| 248 | |
---|
[624] | 249 | /*! |
---|
| 250 | Select algorithm of a domain correspoding to its transformation type and its position in each element |
---|
| 251 | \param [in] elementPositionInGrid position of element in grid. e.g: a grid has 1 domain and 1 axis, then position of domain is 1 (because it contains 2 basic elements) |
---|
| 252 | and position of axis is 2 |
---|
| 253 | \param [in] transType transformation type, for now we have Zoom_axis, inverse_axis |
---|
| 254 | \param [in] transformationOrder position of the transformation in an element (an element can have several transformation) |
---|
| 255 | */ |
---|
[622] | 256 | void CGridTransformation::selectDomainAlgo(int elementPositionInGrid, ETranformationType transType, int transformationOrder) |
---|
| 257 | { |
---|
[631] | 258 | std::vector<CDomain*> domainListDestP = gridDestination_->getDomains(); |
---|
| 259 | std::vector<CDomain*> domainListSrcP = gridSource_->getDomains(); |
---|
| 260 | |
---|
| 261 | int domainIndex = elementPosition2DomainPositionInGrid_[elementPositionInGrid]; |
---|
| 262 | CDomain::TransMapTypes trans = domainListDestP[domainIndex]->getAllTransformations(); |
---|
| 263 | CDomain::TransMapTypes::const_iterator it = trans.begin(); |
---|
| 264 | |
---|
| 265 | for (int i = 0; i < transformationOrder; ++i, ++it) {} // Find the correct transformation |
---|
| 266 | |
---|
| 267 | CZoomDomain* zoomDomain = 0; |
---|
[689] | 268 | CInterpolateDomain* interpFileDomain = 0; |
---|
[631] | 269 | CGenericAlgorithmTransformation* algo = 0; |
---|
| 270 | switch (transType) |
---|
| 271 | { |
---|
[689] | 272 | case TRANS_INTERPOLATE_DOMAIN: |
---|
| 273 | interpFileDomain = dynamic_cast<CInterpolateDomain*> (it->second); |
---|
| 274 | algo = new CDomainAlgorithmInterpolate(domainListDestP[domainIndex], domainListSrcP[domainIndex],interpFileDomain); |
---|
[657] | 275 | break; |
---|
[631] | 276 | case TRANS_ZOOM_DOMAIN: |
---|
| 277 | zoomDomain = dynamic_cast<CZoomDomain*> (it->second); |
---|
| 278 | algo = new CDomainAlgorithmZoom(domainListDestP[domainIndex], domainListSrcP[domainIndex], zoomDomain); |
---|
| 279 | break; |
---|
| 280 | default: |
---|
| 281 | break; |
---|
| 282 | } |
---|
| 283 | algoTransformation_.push_back(algo); |
---|
[622] | 284 | } |
---|
| 285 | |
---|
[624] | 286 | /*! |
---|
| 287 | Assign the current grid destination to the grid source in the new transformation. |
---|
| 288 | The current grid destination plays the role of grid source in next transformation (if any). |
---|
| 289 | Only element on which the transformation is performed is modified |
---|
| 290 | \param [in] elementPositionInGrid position of element in grid |
---|
| 291 | \param [in] transType transformation type |
---|
| 292 | */ |
---|
[827] | 293 | void CGridTransformation::setUpGrid(int elementPositionInGrid, ETranformationType transType, int nbTransformation) |
---|
[622] | 294 | { |
---|
[827] | 295 | if (!tempGrids_.empty() && (getNbAlgo()-1) == tempGrids_.size()) |
---|
| 296 | { |
---|
| 297 | gridSource_ = tempGrids_[nbTransformation]; |
---|
| 298 | return; |
---|
| 299 | } |
---|
| 300 | |
---|
[622] | 301 | std::vector<CAxis*> axisListDestP = gridDestination_->getAxis(); |
---|
[827] | 302 | std::vector<CAxis*> axisListSrcP = gridSource_->getAxis(), axisSrc; |
---|
[622] | 303 | |
---|
[631] | 304 | std::vector<CDomain*> domListDestP = gridDestination_->getDomains(); |
---|
[827] | 305 | std::vector<CDomain*> domListSrcP = gridSource_->getDomains(), domainSrc; |
---|
[631] | 306 | |
---|
[827] | 307 | int axisIndex = -1, domainIndex = -1; |
---|
[622] | 308 | switch (transType) |
---|
| 309 | { |
---|
[689] | 310 | case TRANS_INTERPOLATE_DOMAIN: |
---|
[631] | 311 | case TRANS_ZOOM_DOMAIN: |
---|
| 312 | domainIndex = elementPosition2DomainPositionInGrid_[elementPositionInGrid]; |
---|
| 313 | break; |
---|
| 314 | |
---|
[630] | 315 | case TRANS_INTERPOLATE_AXIS: |
---|
[622] | 316 | case TRANS_ZOOM_AXIS: |
---|
| 317 | case TRANS_INVERSE_AXIS: |
---|
| 318 | axisIndex = elementPosition2AxisPositionInGrid_[elementPositionInGrid]; |
---|
| 319 | break; |
---|
| 320 | default: |
---|
| 321 | break; |
---|
| 322 | } |
---|
[827] | 323 | |
---|
| 324 | for (int idx = 0; idx < axisListSrcP.size(); ++idx) |
---|
| 325 | { |
---|
| 326 | CAxis* axis = CAxis::createAxis(); |
---|
| 327 | if (axisIndex != idx) axis->axis_ref.setValue(axisListSrcP[idx]->getId()); |
---|
| 328 | else axis->axis_ref.setValue(axisListDestP[idx]->getId()); |
---|
| 329 | axis->solveRefInheritance(true); |
---|
| 330 | axis->checkAttributesOnClient(); |
---|
| 331 | axisSrc.push_back(axis); |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | for (int idx = 0; idx < domListSrcP.size(); ++idx) |
---|
| 335 | { |
---|
| 336 | CDomain* domain = CDomain::createDomain(); |
---|
| 337 | if (domainIndex != idx) domain->domain_ref.setValue(domListSrcP[idx]->getId()); |
---|
| 338 | else domain->domain_ref.setValue(domListDestP[idx]->getId()); |
---|
| 339 | domain->solveRefInheritance(true); |
---|
| 340 | domain->checkAttributesOnClient(); |
---|
| 341 | domainSrc.push_back(domain); |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | gridSource_ = CGrid::createGrid(domainSrc, axisSrc, gridDestination_->axis_domain_order); |
---|
| 345 | gridSource_->computeGridGlobalDimension(domainSrc, axisSrc, gridDestination_->axis_domain_order); |
---|
| 346 | |
---|
| 347 | tempGrids_.push_back(gridSource_); |
---|
[622] | 348 | } |
---|
| 349 | |
---|
[624] | 350 | /*! |
---|
| 351 | Perform all transformations |
---|
| 352 | For each transformation, there are some things to do: |
---|
| 353 | -) Chose the correct algorithm by transformation type and position of element |
---|
| 354 | -) Calculate the mapping of global index between the current grid source and grid destination |
---|
| 355 | -) Calculate the mapping of global index between current grid DESTINATION and ORIGINAL grid SOURCE |
---|
| 356 | -) Make current grid destination become grid source in the next transformation |
---|
| 357 | */ |
---|
[832] | 358 | void CGridTransformation::computeAll(const std::vector<CArray<double,1>* >& dataAuxInputs, Time timeStamp) |
---|
[622] | 359 | { |
---|
[824] | 360 | if (nbAlgos_ < 1) return; |
---|
[827] | 361 | if (!auxInputs_.empty() && !dynamicalTransformation_) { dynamicalTransformation_ = true; return; } |
---|
[832] | 362 | if (dynamicalTransformation_) |
---|
| 363 | { |
---|
| 364 | if (timeStamp_.insert(timeStamp).second) |
---|
| 365 | DestinationIndexMap().swap(currentGridIndexToOriginalGridIndex_); // Reset map |
---|
| 366 | else |
---|
| 367 | return; |
---|
| 368 | } |
---|
[824] | 369 | |
---|
[622] | 370 | CContext* context = CContext::getCurrent(); |
---|
[653] | 371 | CContextClient* client = context->client; |
---|
[622] | 372 | |
---|
| 373 | ListAlgoType::const_iterator itb = listAlgos_.begin(), |
---|
| 374 | ite = listAlgos_.end(), it; |
---|
[821] | 375 | |
---|
[622] | 376 | CGenericAlgorithmTransformation* algo = 0; |
---|
[687] | 377 | int nbAgloTransformation = 0; // Only count for executed transformation. Generate domain is a special one, not executed in the list |
---|
[622] | 378 | for (it = itb; it != ite; ++it) |
---|
| 379 | { |
---|
| 380 | int elementPositionInGrid = it->first; |
---|
| 381 | ETranformationType transType = (it->second).first; |
---|
| 382 | int transformationOrder = (it->second).second; |
---|
[829] | 383 | DestinationIndexMap globaIndexWeightFromDestToSource; |
---|
[622] | 384 | |
---|
| 385 | // First of all, select an algorithm |
---|
[827] | 386 | if (!dynamicalTransformation_ || (algoTransformation_.size() < listAlgos_.size())) |
---|
| 387 | { |
---|
| 388 | selectAlgo(elementPositionInGrid, transType, transformationOrder, algoTypes_[std::distance(itb, it)]); |
---|
| 389 | algo = algoTransformation_.back(); |
---|
| 390 | } |
---|
| 391 | else |
---|
| 392 | algo = algoTransformation_[std::distance(itb, it)]; |
---|
[622] | 393 | |
---|
[687] | 394 | if (0 != algo) // Only registered transformation can be executed |
---|
| 395 | { |
---|
[827] | 396 | algo->computeIndexSourceMapping(dataAuxInputs); |
---|
| 397 | |
---|
[687] | 398 | // Recalculate the distribution of grid destination |
---|
| 399 | CDistributionClient distributionClientDest(client->clientRank, gridDestination_); |
---|
[831] | 400 | const CDistributionClient::GlobalLocalDataMap& globalLocalIndexGridDestSendToServer = distributionClientDest.getGlobalLocalDataSendToServer(); |
---|
[622] | 401 | |
---|
[687] | 402 | // ComputeTransformation of global index of each element |
---|
| 403 | std::vector<int> gridDestinationDimensionSize = gridDestination_->getGlobalDimension(); |
---|
| 404 | std::vector<int> gridSrcDimensionSize = gridSource_->getGlobalDimension(); |
---|
| 405 | int elementPosition = it->first; |
---|
| 406 | algo->computeGlobalSourceIndex(elementPosition, |
---|
| 407 | gridDestinationDimensionSize, |
---|
| 408 | gridSrcDimensionSize, |
---|
[831] | 409 | globalLocalIndexGridDestSendToServer, |
---|
[687] | 410 | globaIndexWeightFromDestToSource); |
---|
[622] | 411 | |
---|
[841] | 412 | // Compute transformation of global indexes among grids |
---|
| 413 | computeTransformationMapping(globaIndexWeightFromDestToSource); |
---|
| 414 | |
---|
[821] | 415 | if (1 < nbAlgos_) |
---|
| 416 | { |
---|
| 417 | // Now grid destination becomes grid source in a new transformation |
---|
[827] | 418 | if (nbAgloTransformation != (nbAlgos_-1)) setUpGrid(elementPositionInGrid, transType, nbAgloTransformation); |
---|
[821] | 419 | } |
---|
[687] | 420 | ++nbAgloTransformation; |
---|
| 421 | } |
---|
[622] | 422 | } |
---|
| 423 | } |
---|
| 424 | |
---|
[621] | 425 | /*! |
---|
[841] | 426 | Compute exchange index between grid source and grid destination |
---|
| 427 | \param [in] globalIndexWeightFromDestToSource global index mapping between grid destination and grid source |
---|
[621] | 428 | */ |
---|
[841] | 429 | void CGridTransformation::computeTransformationMapping(const DestinationIndexMap& globalIndexWeightFromDestToSource) |
---|
[620] | 430 | { |
---|
[623] | 431 | CContext* context = CContext::getCurrent(); |
---|
[653] | 432 | CContextClient* client = context->client; |
---|
[623] | 433 | |
---|
[622] | 434 | CTransformationMapping transformationMap(gridDestination_, gridSource_); |
---|
| 435 | |
---|
[841] | 436 | transformationMap.computeTransformationMapping(globalIndexWeightFromDestToSource); |
---|
[622] | 437 | |
---|
[829] | 438 | const CTransformationMapping::ReceivedIndexMap& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping(); |
---|
| 439 | CTransformationMapping::ReceivedIndexMap::const_iterator itbMapRecv, itMapRecv, iteMapRecv; |
---|
[620] | 440 | itbMapRecv = globalIndexToReceive.begin(); |
---|
| 441 | iteMapRecv = globalIndexToReceive.end(); |
---|
[841] | 442 | nbLocalIndexOnGridDest_.push_back(globalIndexWeightFromDestToSource.size()); |
---|
| 443 | localIndexToReceiveOnGridDest_.push_back(RecvIndexGridDestinationMap()); |
---|
| 444 | RecvIndexGridDestinationMap& recvTmp = localIndexToReceiveOnGridDest_.back(); |
---|
[620] | 445 | for (itMapRecv = itbMapRecv; itMapRecv != iteMapRecv; ++itMapRecv) |
---|
| 446 | { |
---|
| 447 | int sourceRank = itMapRecv->first; |
---|
| 448 | int numGlobalIndex = (itMapRecv->second).size(); |
---|
[841] | 449 | recvTmp[sourceRank].resize(numGlobalIndex); |
---|
[620] | 450 | for (int i = 0; i < numGlobalIndex; ++i) |
---|
| 451 | { |
---|
| 452 | int vecSize = ((itMapRecv->second)[i]).size(); |
---|
| 453 | for (int idx = 0; idx < vecSize; ++idx) |
---|
| 454 | { |
---|
[829] | 455 | const std::pair<int, std::pair<size_t,double> >& tmpPair = (itMapRecv->second)[i][idx]; |
---|
[841] | 456 | recvTmp[sourceRank][i].push_back(make_pair(tmpPair.first, tmpPair.second.second)); |
---|
[620] | 457 | } |
---|
| 458 | } |
---|
| 459 | } |
---|
| 460 | |
---|
[630] | 461 | // Find out local index on grid source (to send) |
---|
[831] | 462 | const CTransformationMapping::SentIndexMap& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping(); |
---|
[829] | 463 | CTransformationMapping::SentIndexMap::const_iterator itbMap, itMap, iteMap; |
---|
[620] | 464 | itbMap = globalIndexToSend.begin(); |
---|
| 465 | iteMap = globalIndexToSend.end(); |
---|
[841] | 466 | localIndexToSendFromGridSource_.push_back(SendingIndexGridSourceMap()); |
---|
| 467 | SendingIndexGridSourceMap& tmpSend = localIndexToSendFromGridSource_.back(); |
---|
[620] | 468 | for (itMap = itbMap; itMap != iteMap; ++itMap) |
---|
| 469 | { |
---|
[621] | 470 | int destRank = itMap->first; |
---|
[653] | 471 | int vecSize = itMap->second.size(); |
---|
[841] | 472 | tmpSend[destRank].resize(vecSize); |
---|
[620] | 473 | for (int idx = 0; idx < vecSize; ++idx) |
---|
| 474 | { |
---|
[841] | 475 | tmpSend[destRank](idx) = itMap->second[idx].first; |
---|
[620] | 476 | } |
---|
| 477 | } |
---|
| 478 | } |
---|
| 479 | |
---|
[821] | 480 | bool CGridTransformation::isSpecialTransformation(ETranformationType transType) |
---|
| 481 | { |
---|
| 482 | bool res; |
---|
| 483 | switch (transType) |
---|
| 484 | { |
---|
| 485 | case TRANS_GENERATE_RECTILINEAR_DOMAIN: |
---|
| 486 | res = true; |
---|
| 487 | break; |
---|
| 488 | default: |
---|
| 489 | res = false; |
---|
| 490 | break; |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | return res; |
---|
| 494 | } |
---|
| 495 | |
---|
[621] | 496 | /*! |
---|
| 497 | Local index of data which need sending from the grid source |
---|
| 498 | \return local index of data |
---|
| 499 | */ |
---|
[841] | 500 | const std::list<CGridTransformation::SendingIndexGridSourceMap>& CGridTransformation::getLocalIndexToSendFromGridSource() const |
---|
[620] | 501 | { |
---|
| 502 | return localIndexToSendFromGridSource_; |
---|
| 503 | } |
---|
| 504 | |
---|
[621] | 505 | /*! |
---|
| 506 | Local index of data which will be received on the grid destination |
---|
| 507 | \return local index of data |
---|
| 508 | */ |
---|
[841] | 509 | const std::list<CGridTransformation::RecvIndexGridDestinationMap>& CGridTransformation::getLocalIndexToReceiveOnGridDest() const |
---|
[620] | 510 | { |
---|
| 511 | return localIndexToReceiveOnGridDest_; |
---|
| 512 | } |
---|
| 513 | |
---|
[841] | 514 | const std::list<size_t>& CGridTransformation::getNbLocalIndexToReceiveOnGridDest() const |
---|
| 515 | { |
---|
| 516 | return nbLocalIndexOnGridDest_; |
---|
[620] | 517 | } |
---|
[841] | 518 | |
---|
| 519 | } |
---|