[266] | 1 | |
---|
[219] | 2 | #include "grid.hpp" |
---|
| 3 | |
---|
[352] | 4 | #include "attribute_template.hpp" |
---|
| 5 | #include "object_template.hpp" |
---|
| 6 | #include "group_template.hpp" |
---|
| 7 | #include "message.hpp" |
---|
[286] | 8 | #include <iostream> |
---|
[352] | 9 | #include "xmlioserver_spl.hpp" |
---|
| 10 | #include "type.hpp" |
---|
| 11 | #include "context.hpp" |
---|
| 12 | #include "context_client.hpp" |
---|
[552] | 13 | #include "context_server.hpp" |
---|
[369] | 14 | #include "array_new.hpp" |
---|
[568] | 15 | #include "client_server_mapping_distributed.hpp" |
---|
[219] | 16 | |
---|
[335] | 17 | namespace xios { |
---|
[219] | 18 | |
---|
| 19 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 20 | |
---|
| 21 | CGrid::CGrid(void) |
---|
| 22 | : CObjectTemplate<CGrid>(), CGridAttributes() |
---|
[567] | 23 | , isChecked(false), isDomainAxisChecked(false), storeIndex(1) |
---|
[551] | 24 | , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) |
---|
[568] | 25 | , serverDistribution_(0), serverDistributionDescription_(0), clientServerMap_(0), writtenDataSize_(0), globalDim_() |
---|
[540] | 26 | { |
---|
| 27 | setVirtualDomainGroup(); |
---|
| 28 | setVirtualAxisGroup(); |
---|
| 29 | } |
---|
[219] | 30 | |
---|
| 31 | CGrid::CGrid(const StdString & id) |
---|
| 32 | : CObjectTemplate<CGrid>(id), CGridAttributes() |
---|
[567] | 33 | , isChecked(false), isDomainAxisChecked(false), storeIndex(1) |
---|
[551] | 34 | , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) |
---|
[568] | 35 | , serverDistribution_(0), serverDistributionDescription_(0), clientServerMap_(0), writtenDataSize_(0), globalDim_() |
---|
[540] | 36 | { |
---|
| 37 | setVirtualDomainGroup(); |
---|
| 38 | setVirtualAxisGroup(); |
---|
| 39 | } |
---|
[219] | 40 | |
---|
| 41 | CGrid::~CGrid(void) |
---|
[509] | 42 | { |
---|
[369] | 43 | deque< CArray<int, 1>* >::iterator it ; |
---|
[509] | 44 | |
---|
[369] | 45 | for(deque< CArray<int,1>* >::iterator it=storeIndex.begin(); it!=storeIndex.end();it++) delete *it ; |
---|
[551] | 46 | for(map<int,CArray<size_t,1>* >::iterator it=outIndexFromClient.begin();it!=outIndexFromClient.end();++it) delete (it->second); |
---|
| 47 | |
---|
| 48 | if (0 != clientDistribution_) delete clientDistribution_; |
---|
[552] | 49 | if (0 != serverDistribution_) delete serverDistribution_; |
---|
[553] | 50 | if (0 != serverDistributionDescription_) delete serverDistributionDescription_; |
---|
[219] | 51 | } |
---|
| 52 | |
---|
| 53 | ///--------------------------------------------------------------- |
---|
| 54 | |
---|
| 55 | StdString CGrid::GetName(void) { return (StdString("grid")); } |
---|
| 56 | StdString CGrid::GetDefName(void) { return (CGrid::GetName()); } |
---|
| 57 | ENodeType CGrid::GetType(void) { return (eGrid); } |
---|
| 58 | |
---|
| 59 | //---------------------------------------------------------------- |
---|
| 60 | |
---|
[369] | 61 | const std::deque< CArray<int,1>* > & CGrid::getStoreIndex(void) const |
---|
[509] | 62 | { |
---|
[219] | 63 | return (this->storeIndex ); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | //--------------------------------------------------------------- |
---|
[567] | 67 | // |
---|
| 68 | // const std::deque< CArray<int,1>* > & CGrid::getOutIIndex(void) const |
---|
| 69 | // { |
---|
| 70 | // return (this->out_i_index ); |
---|
| 71 | // } |
---|
| 72 | // |
---|
| 73 | // //--------------------------------------------------------------- |
---|
| 74 | // |
---|
| 75 | // const std::deque< CArray<int,1>* > & CGrid::getOutJIndex(void) const |
---|
| 76 | // { |
---|
| 77 | // return (this->out_j_index ); |
---|
| 78 | // } |
---|
| 79 | // |
---|
| 80 | // //--------------------------------------------------------------- |
---|
| 81 | // |
---|
| 82 | // const std::deque< CArray<int,1>* > & CGrid::getOutLIndex(void) const |
---|
| 83 | // { |
---|
| 84 | // return (this->out_l_index ); |
---|
| 85 | // } |
---|
| 86 | // |
---|
| 87 | // //--------------------------------------------------------------- |
---|
| 88 | // |
---|
| 89 | // const CAxis* CGrid::getRelAxis (void) const |
---|
| 90 | // { |
---|
| 91 | // return (this->axis ); |
---|
| 92 | // } |
---|
[219] | 93 | |
---|
[567] | 94 | // //--------------------------------------------------------------- |
---|
| 95 | // |
---|
| 96 | // const CDomain* CGrid::getRelDomain(void) const |
---|
| 97 | // { |
---|
| 98 | // return (this->domain ); |
---|
| 99 | // } |
---|
[219] | 100 | |
---|
| 101 | //--------------------------------------------------------------- |
---|
| 102 | |
---|
[567] | 103 | // bool CGrid::hasAxis(void) const |
---|
| 104 | // { |
---|
| 105 | // return (this->withAxis); |
---|
| 106 | // } |
---|
[219] | 107 | |
---|
| 108 | //--------------------------------------------------------------- |
---|
| 109 | |
---|
| 110 | StdSize CGrid::getDimension(void) const |
---|
| 111 | { |
---|
[567] | 112 | return (globalDim_.size()); |
---|
[219] | 113 | } |
---|
| 114 | |
---|
| 115 | //--------------------------------------------------------------- |
---|
| 116 | |
---|
[351] | 117 | /* |
---|
[266] | 118 | std::vector<StdSize> CGrid::getLocalShape(void) const |
---|
[219] | 119 | { |
---|
| 120 | std::vector<StdSize> retvalue; |
---|
[266] | 121 | retvalue.push_back(domain->zoom_ni_loc.getValue()); |
---|
| 122 | retvalue.push_back(domain->zoom_nj_loc.getValue()); |
---|
[219] | 123 | if (this->withAxis) |
---|
[351] | 124 | retvalue.push_back(this->axis->zoom_size.getValue()); |
---|
[219] | 125 | return (retvalue); |
---|
| 126 | } |
---|
[351] | 127 | */ |
---|
[219] | 128 | //--------------------------------------------------------------- |
---|
[509] | 129 | |
---|
[351] | 130 | /* |
---|
[266] | 131 | StdSize CGrid::getLocalSize(void) const |
---|
[219] | 132 | { |
---|
| 133 | StdSize retvalue = 1; |
---|
[266] | 134 | std::vector<StdSize> shape_ = this->getLocalShape(); |
---|
[219] | 135 | for (StdSize s = 0; s < shape_.size(); s++) |
---|
| 136 | retvalue *= shape_[s]; |
---|
| 137 | return (retvalue); |
---|
| 138 | } |
---|
[351] | 139 | */ |
---|
[266] | 140 | //--------------------------------------------------------------- |
---|
[351] | 141 | /* |
---|
[266] | 142 | std::vector<StdSize> CGrid::getGlobalShape(void) const |
---|
| 143 | { |
---|
| 144 | std::vector<StdSize> retvalue; |
---|
| 145 | retvalue.push_back(domain->ni.getValue()); |
---|
| 146 | retvalue.push_back(domain->nj.getValue()); |
---|
| 147 | if (this->withAxis) |
---|
| 148 | retvalue.push_back(this->axis->size.getValue()); |
---|
| 149 | return (retvalue); |
---|
| 150 | } |
---|
[351] | 151 | */ |
---|
[219] | 152 | //--------------------------------------------------------------- |
---|
[351] | 153 | |
---|
[509] | 154 | /* |
---|
[266] | 155 | StdSize CGrid::getGlobalSize(void) const |
---|
| 156 | { |
---|
| 157 | StdSize retvalue = 1; |
---|
| 158 | std::vector<StdSize> shape_ = this->getGlobalShape(); |
---|
| 159 | for (StdSize s = 0; s < shape_.size(); s++) |
---|
| 160 | retvalue *= shape_[s]; |
---|
| 161 | return (retvalue); |
---|
| 162 | } |
---|
[351] | 163 | */ |
---|
[286] | 164 | StdSize CGrid::getDataSize(void) const |
---|
| 165 | { |
---|
[567] | 166 | std::vector<int> dataNindex = clientDistribution_->getDataNIndex(); |
---|
| 167 | StdSize retvalue = 1; |
---|
| 168 | for (int i = 0; i < dataNindex.size(); ++i) retvalue *= dataNindex[i]; |
---|
[286] | 169 | return (retvalue); |
---|
| 170 | } |
---|
| 171 | |
---|
[509] | 172 | std::map<int, StdSize> CGrid::getConnectedServerDataSize() |
---|
| 173 | { |
---|
[551] | 174 | double secureFactor = 2.5 * sizeof(double) * CXios::bufferServerFactorSize; |
---|
| 175 | StdSize retVal; |
---|
[509] | 176 | std::map<int, StdSize> ret; |
---|
[568] | 177 | const std::map<int, std::vector<int> >& distribution = clientServerMap_->getLocalIndexSendToServer(); |
---|
[551] | 178 | std::map<int, std::vector<int> >::const_iterator it = distribution.begin(), itE = distribution.end(); |
---|
| 179 | for (; it != itE; ++it) |
---|
[509] | 180 | { |
---|
[551] | 181 | retVal = it->second.size(); |
---|
| 182 | retVal *= secureFactor; |
---|
| 183 | ret.insert(std::make_pair<int,StdSize>(it->first, retVal)); |
---|
[509] | 184 | } |
---|
[551] | 185 | |
---|
[509] | 186 | return ret; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | |
---|
| 190 | void CGrid::solveDomainAxisRef(bool areAttributesChecked) |
---|
[219] | 191 | { |
---|
[509] | 192 | if (this->isDomainAxisChecked) return; |
---|
[369] | 193 | |
---|
[509] | 194 | this->solveDomainRef(areAttributesChecked); |
---|
| 195 | this->solveAxisRef(areAttributesChecked); |
---|
| 196 | |
---|
| 197 | this->isDomainAxisChecked = areAttributesChecked; |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | void CGrid::checkMaskIndex(bool doSendingIndex) |
---|
| 201 | { |
---|
| 202 | CContext* context = CContext::getCurrent() ; |
---|
| 203 | CContextClient* client=context->client ; |
---|
| 204 | |
---|
| 205 | if (context->hasClient) |
---|
[551] | 206 | if (this->isChecked && doSendingIndex && !isIndexSent) { sendIndex(); this->isIndexSent = true; } |
---|
[509] | 207 | |
---|
| 208 | if (this->isChecked) return; |
---|
| 209 | |
---|
| 210 | if (context->hasClient) |
---|
| 211 | { |
---|
| 212 | checkMask() ; |
---|
| 213 | this->computeIndex() ; |
---|
| 214 | this->storeIndex.push_front(new CArray<int,1>() ); |
---|
| 215 | } |
---|
| 216 | this->isChecked = true; |
---|
[219] | 217 | } |
---|
| 218 | |
---|
[415] | 219 | void CGrid::checkMask(void) |
---|
| 220 | { |
---|
| 221 | using namespace std; |
---|
[567] | 222 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
| 223 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
| 224 | int dim = domainP.size() * 2 + axisP.size(); |
---|
[415] | 225 | |
---|
[567] | 226 | std::vector<CArray<bool,2>* > domainMasks(domainP.size()); |
---|
| 227 | for (int i = 0; i < domainMasks.size(); ++i) domainMasks[i] = &(domainP[i]->mask); |
---|
| 228 | std::vector<CArray<bool,1>* > axisMasks(axisP.size()); |
---|
| 229 | for (int i = 0; i < axisMasks.size(); ++i) axisMasks[i] = &(axisP[i]->mask); |
---|
[415] | 230 | |
---|
[567] | 231 | switch (dim) { |
---|
| 232 | case 1: |
---|
| 233 | checkGridMask(mask1, domainMasks, axisMasks, axisDomainOrder); |
---|
| 234 | break; |
---|
| 235 | case 2: |
---|
| 236 | checkGridMask(mask2, domainMasks, axisMasks, axisDomainOrder); |
---|
| 237 | break; |
---|
| 238 | case 3: |
---|
| 239 | checkGridMask(mask3, domainMasks, axisMasks, axisDomainOrder); |
---|
| 240 | break; |
---|
| 241 | // case 4: |
---|
| 242 | // checkGridMask(mask4, domainMasks, axisMasks, axisDomainOrder); |
---|
| 243 | // break; |
---|
| 244 | // case 5: |
---|
| 245 | // checkGridMask(mask5, domainMasks, axisMasks, axisDomainOrder); |
---|
| 246 | // break; |
---|
| 247 | // case 6: |
---|
| 248 | // checkGridMask(mask6, domainMasks, axisMasks, axisDomainOrder); |
---|
| 249 | // break; |
---|
| 250 | // case 7: |
---|
| 251 | // checkGridMask(mask7, domainMasks, axisMasks, axisDomainOrder); |
---|
| 252 | // break; |
---|
| 253 | default: |
---|
| 254 | break; |
---|
[415] | 255 | } |
---|
| 256 | } |
---|
[219] | 257 | //--------------------------------------------------------------- |
---|
| 258 | |
---|
[509] | 259 | void CGrid::solveDomainRef(bool sendAtt) |
---|
[219] | 260 | { |
---|
[540] | 261 | setDomainList(); |
---|
[567] | 262 | std::vector<CDomain*> domListP = this->getDomains(); |
---|
| 263 | if (!domListP.empty()) |
---|
[219] | 264 | { |
---|
[567] | 265 | computeGridGlobalDimension(getDomains(), getAxis(), axisDomainOrder); |
---|
| 266 | for (int i = 0; i < domListP.size(); ++i) |
---|
| 267 | { |
---|
| 268 | if (sendAtt) domListP[i]->sendCheckedAttributes(); |
---|
| 269 | else domListP[i]->checkAttributesOnClient(); |
---|
| 270 | } |
---|
[219] | 271 | } |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | //--------------------------------------------------------------- |
---|
| 275 | |
---|
[567] | 276 | void CGrid::solveAxisRef(bool sendAtt) |
---|
[219] | 277 | { |
---|
[540] | 278 | setAxisList(); |
---|
[567] | 279 | std::vector<CAxis*> axisListP = this->getAxis(); |
---|
| 280 | if (!axisListP.empty()) |
---|
[219] | 281 | { |
---|
[567] | 282 | int idx = 0; |
---|
[568] | 283 | std::vector<int> axisPositionMap; |
---|
| 284 | for (int i = 0; i < axisDomainOrder.numElements(); ++i) |
---|
| 285 | { |
---|
| 286 | if (false == axisDomainOrder(i)) |
---|
| 287 | { |
---|
| 288 | axisPositionMap.push_back(idx); |
---|
| 289 | ++idx; |
---|
| 290 | } |
---|
| 291 | else idx += 2; |
---|
| 292 | } |
---|
| 293 | |
---|
[567] | 294 | computeGridGlobalDimension(getDomains(), getAxis(), axisDomainOrder); |
---|
| 295 | for (int i = 0; i < axisListP.size(); ++i) |
---|
[540] | 296 | { |
---|
[567] | 297 | if (sendAtt) |
---|
[568] | 298 | axisListP[i]->sendCheckedAttributes(globalDim_,axisPositionMap[i]); |
---|
[567] | 299 | else |
---|
[568] | 300 | axisListP[i]->checkAttributesOnClient(globalDim_,axisPositionMap[i]); |
---|
[567] | 301 | ++idx; |
---|
[540] | 302 | } |
---|
| 303 | |
---|
[219] | 304 | } |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | //--------------------------------------------------------------- |
---|
| 308 | |
---|
| 309 | void CGrid::computeIndex(void) |
---|
[509] | 310 | { |
---|
[551] | 311 | CContext* context = CContext::getCurrent() ; |
---|
| 312 | CContextClient* client=context->client ; |
---|
[553] | 313 | |
---|
| 314 | // First of all, compute distribution on client side |
---|
[551] | 315 | clientDistribution_ = new CDistributionClient(client->clientRank, this); |
---|
[568] | 316 | size_t globalSizeIndex = 1, indexBegin, indexEnd; |
---|
| 317 | int range, clientSize = client->clientSize; |
---|
| 318 | for (int i = 0; i < globalDim_.size(); ++i) globalSizeIndex *= globalDim_[i]; |
---|
| 319 | indexBegin = 0; |
---|
| 320 | for (int i = 0; i < clientSize; ++i) |
---|
| 321 | { |
---|
| 322 | range = globalSizeIndex / clientSize; |
---|
| 323 | if (i < (globalSizeIndex%clientSize)) ++range; |
---|
| 324 | if (i == client->clientRank) break; |
---|
| 325 | indexBegin += range; |
---|
| 326 | } |
---|
| 327 | indexEnd = indexBegin + range - 1; |
---|
[509] | 328 | |
---|
[553] | 329 | // Then compute distribution on server side |
---|
| 330 | serverDistributionDescription_ = new CServerDistributionDescription(clientDistribution_->getNGlob()); |
---|
| 331 | serverDistributionDescription_->computeServerDistribution(client->serverSize, true); |
---|
[568] | 332 | serverDistributionDescription_->computeServerGlobalIndexInRange(client->serverSize, |
---|
| 333 | std::make_pair<size_t,size_t>(indexBegin, indexEnd)); |
---|
[553] | 334 | |
---|
| 335 | // Finally, compute index mapping between client(s) and server(s) |
---|
[568] | 336 | clientServerMap_ = new CClientServerMappingDistributed(serverDistributionDescription_->getGlobalIndexRange(), |
---|
| 337 | client->intraComm); |
---|
| 338 | |
---|
| 339 | clientServerMap_->computeServerIndexMapping(clientDistribution_->getGlobalIndex(), |
---|
| 340 | clientDistribution_->getLocalDataIndexSendToServerOnClient()); |
---|
| 341 | |
---|
| 342 | // clientServerMap_->computeServerIndexMapping(clientDistribution_->getGlobalIndex(), |
---|
| 343 | // clientDistribution_->getLocalDataIndexSendToServerOnClient(), |
---|
| 344 | // serverDistributionDescription_->getGlobalIndex()); |
---|
| 345 | const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientServerMap_->getGlobalIndexOnServer(); |
---|
[553] | 346 | std::vector<int> connectedServerRank; |
---|
| 347 | for (std::map<int, std::vector<size_t> >::const_iterator it = globalIndexOnServer.begin(); it != globalIndexOnServer.end(); ++it) { |
---|
| 348 | connectedServerRank.push_back(it->first); |
---|
| 349 | } |
---|
[568] | 350 | nbSenders = clientServerMap_->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank); |
---|
[553] | 351 | |
---|
| 352 | // Get local data index on client |
---|
[551] | 353 | storeIndex_client.resize(clientDistribution_->getLocalDataIndexOnClient().numElements()); |
---|
| 354 | storeIndex_client = (clientDistribution_->getLocalDataIndexOnClient()); |
---|
| 355 | |
---|
[219] | 356 | } |
---|
| 357 | |
---|
| 358 | //---------------------------------------------------------------- |
---|
| 359 | |
---|
[347] | 360 | CGrid* CGrid::createGrid(CDomain* domain) |
---|
[219] | 361 | { |
---|
[567] | 362 | std::vector<CDomain*> vecDom(1,domain); |
---|
| 363 | std::vector<CAxis*> vecAxis; |
---|
[540] | 364 | |
---|
[567] | 365 | CGrid* grid = createGrid(vecDom, vecAxis); |
---|
| 366 | |
---|
[219] | 367 | return (grid); |
---|
| 368 | } |
---|
| 369 | |
---|
[347] | 370 | CGrid* CGrid::createGrid(CDomain* domain, CAxis* axis) |
---|
[219] | 371 | { |
---|
[540] | 372 | std::vector<CDomain*> vecDom(1,domain); |
---|
| 373 | std::vector<CAxis*> vecAxis(1,axis); |
---|
[567] | 374 | CGrid* grid = createGrid(vecDom, vecAxis); |
---|
| 375 | |
---|
[219] | 376 | return (grid); |
---|
| 377 | } |
---|
| 378 | |
---|
[540] | 379 | CGrid* CGrid::createGrid(std::vector<CDomain*> domains, std::vector<CAxis*> axis) |
---|
| 380 | { |
---|
| 381 | StdString new_id = StdString("__"); |
---|
| 382 | if (!domains.empty()) for (int i = 0; i < domains.size(); ++i) new_id += domains[i]->getId() + StdString("_"); |
---|
| 383 | if (!axis.empty()) for (int i = 0; i < axis.size(); ++i) new_id += axis[i]->getId() + StdString("_") ; |
---|
| 384 | new_id += StdString("_"); |
---|
| 385 | |
---|
| 386 | CGrid* grid = CGridGroup::get("grid_definition")->createChild(new_id) ; |
---|
| 387 | grid->setDomainList(domains); |
---|
| 388 | grid->setAxisList(axis); |
---|
[551] | 389 | |
---|
| 390 | //By default, domains are always the first ones of a grid |
---|
| 391 | if (grid->axisDomainOrder.isEmpty()) |
---|
| 392 | { |
---|
| 393 | int size = domains.size()+axis.size(); |
---|
| 394 | grid->axisDomainOrder.resize(size); |
---|
| 395 | for (int i = 0; i < size; ++i) |
---|
| 396 | { |
---|
| 397 | if (i < domains.size()) grid->axisDomainOrder(i) = true; |
---|
| 398 | else grid->axisDomainOrder(i) = false; |
---|
| 399 | } |
---|
| 400 | } |
---|
| 401 | |
---|
[567] | 402 | grid->computeGridGlobalDimension(domains, axis, grid->axisDomainOrder); |
---|
| 403 | |
---|
[540] | 404 | return (grid); |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | CDomainGroup* CGrid::getVirtualDomainGroup() const |
---|
| 408 | { |
---|
| 409 | return (this->vDomainGroup_); |
---|
| 410 | } |
---|
| 411 | |
---|
| 412 | CAxisGroup* CGrid::getVirtualAxisGroup() const |
---|
| 413 | { |
---|
| 414 | return (this->vAxisGroup_); |
---|
| 415 | } |
---|
| 416 | |
---|
[551] | 417 | void CGrid::outputField(int rank, const CArray<double, 1>& stored, double* field) |
---|
| 418 | { |
---|
| 419 | CArray<size_t,1>& out_i=*outIndexFromClient[rank]; |
---|
| 420 | StdSize numElements = stored.numElements(); |
---|
| 421 | for (StdSize n = 0; n < numElements; ++n) |
---|
| 422 | { |
---|
| 423 | *(field+out_i(n)) = stored(n); |
---|
| 424 | } |
---|
| 425 | } |
---|
| 426 | |
---|
[219] | 427 | //---------------------------------------------------------------- |
---|
| 428 | |
---|
[509] | 429 | |
---|
[219] | 430 | void CGrid::storeField_arr |
---|
[369] | 431 | (const double * const data, CArray<double, 1>& stored) const |
---|
[219] | 432 | { |
---|
[369] | 433 | const StdSize size = storeIndex_client.numElements() ; |
---|
[300] | 434 | |
---|
[369] | 435 | stored.resize(size) ; |
---|
| 436 | for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)] ; |
---|
[219] | 437 | } |
---|
[509] | 438 | |
---|
[300] | 439 | void CGrid::sendIndex(void) |
---|
| 440 | { |
---|
[347] | 441 | CContext* context = CContext::getCurrent() ; |
---|
[300] | 442 | CContextClient* client=context->client ; |
---|
[509] | 443 | |
---|
[300] | 444 | CEventClient event(getType(),EVENT_ID_INDEX) ; |
---|
| 445 | int rank ; |
---|
| 446 | list<shared_ptr<CMessage> > list_msg ; |
---|
[551] | 447 | list< CArray<size_t,1>* > listOutIndex; |
---|
[568] | 448 | const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientServerMap_->getGlobalIndexOnServer(); |
---|
| 449 | const std::map<int, std::vector<int> >& localIndexSendToServer = clientServerMap_->getLocalIndexSendToServer(); |
---|
[509] | 450 | |
---|
[551] | 451 | std::map<int, std::vector<size_t> >::const_iterator iteMap, itbMap, itGlobal; |
---|
| 452 | std::map<int, std::vector<int> >::const_iterator itLocal; |
---|
| 453 | itbMap = itGlobal = globalIndexOnServer.begin(); |
---|
| 454 | iteMap = globalIndexOnServer.end(); |
---|
| 455 | itLocal = localIndexSendToServer.begin(); |
---|
| 456 | |
---|
[567] | 457 | if (!doGridHaveDataDistributed()) |
---|
[551] | 458 | { |
---|
[567] | 459 | if (0 == client->getClientRank()) |
---|
[551] | 460 | { |
---|
[567] | 461 | for (int ns = 0; itGlobal != iteMap; ++itGlobal, ++itLocal, ++ns) |
---|
| 462 | { |
---|
| 463 | rank = itGlobal->first; |
---|
| 464 | int nb = (itGlobal->second).size(); |
---|
[551] | 465 | |
---|
[567] | 466 | CArray<size_t, 1> outGlobalIndexOnServer(nb); |
---|
| 467 | CArray<int, 1> outLocalIndexToServer(nb); |
---|
| 468 | for (int k = 0; k < nb; ++k) |
---|
| 469 | { |
---|
| 470 | outGlobalIndexOnServer(k) = itGlobal->second.at(k); |
---|
| 471 | outLocalIndexToServer(k) = itLocal->second.at(k); |
---|
| 472 | } |
---|
[551] | 473 | |
---|
[567] | 474 | storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(outLocalIndexToServer) )); |
---|
| 475 | listOutIndex.push_back(new CArray<size_t,1>(outGlobalIndexOnServer)); |
---|
| 476 | |
---|
| 477 | list_msg.push_back(shared_ptr<CMessage>(new CMessage)); |
---|
| 478 | *list_msg.back()<<getId()<<*listOutIndex.back(); |
---|
| 479 | event.push(rank, 1, *list_msg.back()); |
---|
| 480 | } |
---|
| 481 | client->sendEvent(event); |
---|
| 482 | } else client->sendEvent(event); |
---|
[551] | 483 | } |
---|
[567] | 484 | else |
---|
[300] | 485 | { |
---|
[567] | 486 | for (int ns = 0; itGlobal != iteMap; ++itGlobal, ++itLocal, ++ns) |
---|
| 487 | { |
---|
| 488 | rank = itGlobal->first; |
---|
| 489 | int nb = (itGlobal->second).size(); |
---|
[509] | 490 | |
---|
[567] | 491 | CArray<size_t, 1> outGlobalIndexOnServer(nb); |
---|
| 492 | CArray<int, 1> outLocalIndexToServer(nb); |
---|
| 493 | for (int k = 0; k < nb; ++k) |
---|
| 494 | { |
---|
| 495 | outGlobalIndexOnServer(k) = itGlobal->second.at(k); |
---|
| 496 | outLocalIndexToServer(k) = itLocal->second.at(k); |
---|
| 497 | } |
---|
[509] | 498 | |
---|
[567] | 499 | storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(outLocalIndexToServer) )); |
---|
| 500 | listOutIndex.push_back(new CArray<size_t,1>(outGlobalIndexOnServer)); |
---|
[509] | 501 | |
---|
[567] | 502 | list_msg.push_back(shared_ptr<CMessage>(new CMessage)); |
---|
| 503 | *list_msg.back()<<getId()<<*listOutIndex.back(); |
---|
| 504 | event.push(rank, nbSenders[rank], *list_msg.back()); |
---|
| 505 | } |
---|
| 506 | client->sendEvent(event); |
---|
[300] | 507 | } |
---|
[369] | 508 | |
---|
[567] | 509 | for(list<CArray<size_t,1>* >::iterator it=listOutIndex.begin();it!=listOutIndex.end();++it) delete *it ; |
---|
[300] | 510 | } |
---|
[509] | 511 | |
---|
[300] | 512 | void CGrid::recvIndex(CEventServer& event) |
---|
| 513 | { |
---|
| 514 | list<CEventServer::SSubEvent>::iterator it ; |
---|
| 515 | for (it=event.subEvents.begin();it!=event.subEvents.end();++it) |
---|
| 516 | { |
---|
| 517 | int rank=it->rank; |
---|
| 518 | CBufferIn* buffer=it->buffer; |
---|
[551] | 519 | string gridId ; |
---|
| 520 | *buffer>>gridId ; |
---|
| 521 | get(gridId)->recvIndex(rank,*buffer) ; |
---|
[300] | 522 | } |
---|
| 523 | } |
---|
[509] | 524 | |
---|
[567] | 525 | void CGrid::computeGridGlobalDimension(const std::vector<CDomain*>& domains, |
---|
| 526 | const std::vector<CAxis*>& axis, |
---|
| 527 | const CArray<bool,1>& axisDomainOrder) |
---|
| 528 | { |
---|
| 529 | globalDim_.resize(domains.size()*2+axis.size()); |
---|
| 530 | int idx = 0, idxDomain = 0, idxAxis = 0; |
---|
| 531 | for (int i = 0; i < axisDomainOrder.numElements(); ++i) |
---|
| 532 | { |
---|
| 533 | if (axisDomainOrder(i)) |
---|
| 534 | { |
---|
| 535 | globalDim_[idx] = domains[idxDomain]->ni_glo.getValue(); |
---|
| 536 | globalDim_[idx+1] = domains[idxDomain]->nj_glo.getValue(); |
---|
| 537 | ++idxDomain; |
---|
| 538 | idx += 2; |
---|
| 539 | } |
---|
| 540 | else |
---|
| 541 | { |
---|
| 542 | globalDim_[idx] = axis[idxAxis]->size.getValue(); |
---|
| 543 | ++idxAxis; |
---|
| 544 | ++idx; |
---|
| 545 | } |
---|
| 546 | } |
---|
| 547 | } |
---|
| 548 | |
---|
| 549 | std::vector<int> CGrid::getGlobalDimension() |
---|
| 550 | { |
---|
| 551 | return globalDim_; |
---|
| 552 | } |
---|
| 553 | |
---|
| 554 | /*! |
---|
| 555 | Verify whether one server need to write data |
---|
| 556 | There are some cases on which one server has nodata to write. For example, when we |
---|
| 557 | just only want to zoom on a domain. |
---|
| 558 | */ |
---|
| 559 | bool CGrid::doGridHaveDataToWrite() |
---|
| 560 | { |
---|
| 561 | return (0 != serverDistribution_); |
---|
| 562 | } |
---|
| 563 | |
---|
| 564 | /*! |
---|
| 565 | Return size of data which is written on each server |
---|
| 566 | Whatever dimension of a grid, data which are written on server must be presented as |
---|
| 567 | an one dimension array. |
---|
| 568 | \return size of data written on server |
---|
| 569 | */ |
---|
| 570 | size_t CGrid::getWrittenDataSize() const |
---|
| 571 | { |
---|
| 572 | return writtenDataSize_; |
---|
| 573 | } |
---|
| 574 | |
---|
| 575 | |
---|
| 576 | const CDistributionServer* CGrid::getDistributionServer() const |
---|
| 577 | { |
---|
| 578 | return serverDistribution_; |
---|
| 579 | } |
---|
| 580 | |
---|
| 581 | bool CGrid::doGridHaveDataDistributed() |
---|
| 582 | { |
---|
| 583 | return clientDistribution_->isDataDistributed(); |
---|
| 584 | } |
---|
| 585 | |
---|
[300] | 586 | void CGrid::recvIndex(int rank, CBufferIn& buffer) |
---|
| 587 | { |
---|
[552] | 588 | if (0 == serverDistribution_) |
---|
| 589 | { |
---|
| 590 | CContext* context = CContext::getCurrent() ; |
---|
| 591 | CContextServer* server=context->server ; |
---|
| 592 | int idx = 0, numElement = axisDomainOrder.numElements(); |
---|
| 593 | int ssize = numElement; |
---|
| 594 | std::vector<int> indexMap(numElement); |
---|
| 595 | for (int i = 0; i < numElement; ++i) |
---|
| 596 | { |
---|
| 597 | indexMap[i] = idx; |
---|
| 598 | if (true == axisDomainOrder(i)) |
---|
[567] | 599 | { |
---|
| 600 | ++ssize; |
---|
| 601 | idx += 2; |
---|
| 602 | } |
---|
| 603 | else |
---|
| 604 | ++idx; |
---|
[552] | 605 | } |
---|
| 606 | |
---|
| 607 | int axisId = 0, domainId = 0; |
---|
| 608 | std::vector<CDomain*> domainList = getDomains(); |
---|
| 609 | std::vector<CAxis*> axisList = getAxis(); |
---|
[567] | 610 | std::vector<int> nZoomBegin(ssize), nZoomSize(ssize), nGlob(ssize), nZoomBeginGlobal(ssize); |
---|
[552] | 611 | for (int i = 0; i < numElement; ++i) |
---|
| 612 | { |
---|
| 613 | if (axisDomainOrder(i)) |
---|
| 614 | { |
---|
| 615 | nZoomBegin[indexMap[i]] = domainList[domainId]->zoom_ibegin_srv; |
---|
| 616 | nZoomSize[indexMap[i]] = domainList[domainId]->zoom_ni_srv; |
---|
[567] | 617 | nZoomBeginGlobal[indexMap[i]] = domainList[domainId]->zoom_ibegin; |
---|
[552] | 618 | nGlob[indexMap[i]] = domainList[domainId]->ni_glo; |
---|
| 619 | |
---|
| 620 | nZoomBegin[indexMap[i]+1] = domainList[domainId]->zoom_jbegin_srv; |
---|
| 621 | nZoomSize[indexMap[i]+1] = domainList[domainId]->zoom_nj_srv; |
---|
[567] | 622 | nZoomBeginGlobal[indexMap[i]+1] = domainList[domainId]->zoom_jbegin; |
---|
[552] | 623 | nGlob[indexMap[i]+1] = domainList[domainId]->nj_glo; |
---|
| 624 | ++domainId; |
---|
| 625 | } |
---|
| 626 | else |
---|
| 627 | { |
---|
[567] | 628 | nZoomBegin[indexMap[i]] = axisList[axisId]->zoom_begin_srv; |
---|
| 629 | nZoomSize[indexMap[i]] = axisList[axisId]->zoom_size_srv; |
---|
| 630 | nZoomBeginGlobal[indexMap[i]] = axisList[axisId]->zoom_begin; |
---|
[552] | 631 | nGlob[indexMap[i]] = axisList[axisId]->size; |
---|
| 632 | ++axisId; |
---|
| 633 | } |
---|
| 634 | } |
---|
[567] | 635 | writtenDataSize_ = 1; |
---|
| 636 | for (int i = 0; i < nZoomSize.size(); ++i) |
---|
| 637 | writtenDataSize_ *= nZoomSize[i]; |
---|
| 638 | |
---|
| 639 | serverDistribution_ = new CDistributionServer(server->intraCommRank, nZoomBegin, nZoomSize, |
---|
| 640 | nZoomBeginGlobal, nGlob); |
---|
[552] | 641 | } |
---|
| 642 | |
---|
[551] | 643 | CArray<size_t,1> outIndex; |
---|
| 644 | buffer>>outIndex; |
---|
[552] | 645 | serverDistribution_->computeLocalIndex(outIndex); |
---|
[551] | 646 | outIndexFromClient.insert(std::pair<int, CArray<size_t,1>* >(rank, new CArray<size_t,1>(outIndex))); |
---|
[300] | 647 | } |
---|
| 648 | |
---|
[540] | 649 | /*! |
---|
| 650 | \brief Dispatch event received from client |
---|
| 651 | Whenever a message is received in buffer of server, it will be processed depending on |
---|
| 652 | its event type. A new event type should be added in the switch list to make sure |
---|
| 653 | it processed on server side. |
---|
| 654 | \param [in] event: Received message |
---|
| 655 | */ |
---|
[300] | 656 | bool CGrid::dispatchEvent(CEventServer& event) |
---|
| 657 | { |
---|
[509] | 658 | |
---|
[300] | 659 | if (SuperClass::dispatchEvent(event)) return true ; |
---|
| 660 | else |
---|
| 661 | { |
---|
| 662 | switch(event.type) |
---|
| 663 | { |
---|
| 664 | case EVENT_ID_INDEX : |
---|
| 665 | recvIndex(event) ; |
---|
| 666 | return true ; |
---|
| 667 | break ; |
---|
[509] | 668 | |
---|
[540] | 669 | case EVENT_ID_ADD_DOMAIN : |
---|
| 670 | recvAddDomain(event) ; |
---|
| 671 | return true ; |
---|
| 672 | break ; |
---|
| 673 | |
---|
| 674 | case EVENT_ID_ADD_AXIS : |
---|
| 675 | recvAddAxis(event) ; |
---|
| 676 | return true ; |
---|
| 677 | break ; |
---|
[300] | 678 | default : |
---|
| 679 | ERROR("bool CDomain::dispatchEvent(CEventServer& event)", |
---|
| 680 | <<"Unknown Event") ; |
---|
| 681 | return false ; |
---|
| 682 | } |
---|
| 683 | } |
---|
| 684 | } |
---|
| 685 | |
---|
[369] | 686 | void CGrid::inputFieldServer(const std::deque< CArray<double, 1>* > storedClient, CArray<double, 1>& storedServer) const |
---|
[219] | 687 | { |
---|
| 688 | if ((this->storeIndex.size()-1 ) != storedClient.size()) |
---|
[369] | 689 | ERROR("void CGrid::inputFieldServer(const std::deque< CArray<double, 1>* > storedClient, CArray<double, 1>& storedServer) const", |
---|
[421] | 690 | << "[ Expected received field = " << (this->storeIndex.size()-1) << ", " |
---|
| 691 | << "[ received fiedl = " << storedClient.size() << "] " |
---|
| 692 | << "Data from clients are missing!") ; |
---|
[369] | 693 | storedServer.resize(storeIndex[0]->numElements()); |
---|
[509] | 694 | |
---|
[219] | 695 | for (StdSize i = 0, n = 0; i < storedClient.size(); i++) |
---|
[369] | 696 | for (StdSize j = 0; j < storedClient[i]->numElements(); j++) |
---|
| 697 | storedServer(n++) = (*storedClient[i])(j); |
---|
[219] | 698 | } |
---|
| 699 | |
---|
[369] | 700 | void CGrid::outputFieldToServer(CArray<double,1>& fieldIn, int rank, CArray<double,1>& fieldOut) |
---|
[300] | 701 | { |
---|
[369] | 702 | CArray<int,1>& index = *storeIndex_toSrv[rank] ; |
---|
| 703 | int nb=index.numElements() ; |
---|
| 704 | fieldOut.resize(nb) ; |
---|
[509] | 705 | |
---|
[369] | 706 | for(int k=0;k<nb;k++) fieldOut(k)=fieldIn(index(k)) ; |
---|
[300] | 707 | } |
---|
[219] | 708 | ///--------------------------------------------------------------- |
---|
| 709 | |
---|
[540] | 710 | CDomain* CGrid::addDomain(const std::string& id) |
---|
| 711 | { |
---|
| 712 | return vDomainGroup_->createChild(id) ; |
---|
| 713 | } |
---|
| 714 | |
---|
| 715 | CAxis* CGrid::addAxis(const std::string& id) |
---|
| 716 | { |
---|
| 717 | return vAxisGroup_->createChild(id) ; |
---|
| 718 | } |
---|
| 719 | |
---|
| 720 | //! Change virtual field group to a new one |
---|
| 721 | void CGrid::setVirtualDomainGroup(CDomainGroup* newVDomainGroup) |
---|
| 722 | { |
---|
| 723 | this->vDomainGroup_ = newVDomainGroup; |
---|
| 724 | } |
---|
| 725 | |
---|
| 726 | //! Change virtual variable group to new one |
---|
| 727 | void CGrid::setVirtualAxisGroup(CAxisGroup* newVAxisGroup) |
---|
| 728 | { |
---|
| 729 | this->vAxisGroup_ = newVAxisGroup; |
---|
| 730 | } |
---|
| 731 | |
---|
| 732 | //---------------------------------------------------------------- |
---|
| 733 | //! Create virtual field group, which is done normally on initializing file |
---|
| 734 | void CGrid::setVirtualDomainGroup(void) |
---|
| 735 | { |
---|
| 736 | this->setVirtualDomainGroup(CDomainGroup::create()); |
---|
| 737 | } |
---|
| 738 | |
---|
| 739 | //! Create virtual variable group, which is done normally on initializing file |
---|
| 740 | void CGrid::setVirtualAxisGroup(void) |
---|
| 741 | { |
---|
| 742 | this->setVirtualAxisGroup(CAxisGroup::create()); |
---|
| 743 | } |
---|
| 744 | |
---|
| 745 | /*! |
---|
| 746 | \brief Send a message to create a domain on server side |
---|
| 747 | \param[in] id String identity of domain that will be created on server |
---|
| 748 | */ |
---|
| 749 | void CGrid::sendAddDomain(const string& id) |
---|
| 750 | { |
---|
| 751 | CContext* context=CContext::getCurrent() ; |
---|
| 752 | |
---|
| 753 | if (! context->hasServer ) |
---|
| 754 | { |
---|
| 755 | CContextClient* client=context->client ; |
---|
| 756 | |
---|
| 757 | CEventClient event(this->getType(),EVENT_ID_ADD_DOMAIN) ; |
---|
| 758 | if (client->isServerLeader()) |
---|
| 759 | { |
---|
| 760 | CMessage msg ; |
---|
| 761 | msg<<this->getId() ; |
---|
| 762 | msg<<id ; |
---|
| 763 | event.push(client->getServerLeader(),1,msg) ; |
---|
| 764 | client->sendEvent(event) ; |
---|
| 765 | } |
---|
| 766 | else client->sendEvent(event) ; |
---|
| 767 | } |
---|
| 768 | } |
---|
| 769 | |
---|
| 770 | /*! |
---|
| 771 | \brief Send a message to create an axis on server side |
---|
| 772 | \param[in] id String identity of axis that will be created on server |
---|
| 773 | */ |
---|
| 774 | void CGrid::sendAddAxis(const string& id) |
---|
| 775 | { |
---|
| 776 | CContext* context=CContext::getCurrent() ; |
---|
| 777 | |
---|
| 778 | if (! context->hasServer ) |
---|
| 779 | { |
---|
| 780 | CContextClient* client=context->client ; |
---|
| 781 | |
---|
| 782 | CEventClient event(this->getType(),EVENT_ID_ADD_AXIS) ; |
---|
| 783 | if (client->isServerLeader()) |
---|
| 784 | { |
---|
| 785 | CMessage msg ; |
---|
| 786 | msg<<this->getId() ; |
---|
| 787 | msg<<id ; |
---|
| 788 | event.push(client->getServerLeader(),1,msg) ; |
---|
| 789 | client->sendEvent(event) ; |
---|
| 790 | } |
---|
| 791 | else client->sendEvent(event) ; |
---|
| 792 | } |
---|
| 793 | } |
---|
| 794 | |
---|
| 795 | /*! |
---|
| 796 | \brief Receive a message annoucing the creation of a domain on server side |
---|
| 797 | \param[in] event Received event |
---|
| 798 | */ |
---|
| 799 | void CGrid::recvAddDomain(CEventServer& event) |
---|
| 800 | { |
---|
| 801 | |
---|
| 802 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 803 | string id; |
---|
| 804 | *buffer>>id ; |
---|
| 805 | get(id)->recvAddDomain(*buffer) ; |
---|
| 806 | } |
---|
| 807 | |
---|
| 808 | /*! |
---|
| 809 | \brief Receive a message annoucing the creation of a domain on server side |
---|
| 810 | \param[in] buffer Buffer containing message |
---|
| 811 | */ |
---|
| 812 | void CGrid::recvAddDomain(CBufferIn& buffer) |
---|
| 813 | { |
---|
| 814 | string id ; |
---|
| 815 | buffer>>id ; |
---|
| 816 | addDomain(id) ; |
---|
| 817 | } |
---|
| 818 | |
---|
| 819 | /*! |
---|
| 820 | \brief Receive a message annoucing the creation of an axis on server side |
---|
| 821 | \param[in] event Received event |
---|
| 822 | */ |
---|
| 823 | void CGrid::recvAddAxis(CEventServer& event) |
---|
| 824 | { |
---|
| 825 | |
---|
| 826 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
| 827 | string id; |
---|
| 828 | *buffer>>id ; |
---|
| 829 | get(id)->recvAddAxis(*buffer) ; |
---|
| 830 | } |
---|
| 831 | |
---|
| 832 | /*! |
---|
| 833 | \brief Receive a message annoucing the creation of an axis on server side |
---|
| 834 | \param[in] buffer Buffer containing message |
---|
| 835 | */ |
---|
| 836 | void CGrid::recvAddAxis(CBufferIn& buffer) |
---|
| 837 | { |
---|
| 838 | string id ; |
---|
| 839 | buffer>>id ; |
---|
| 840 | addAxis(id) ; |
---|
| 841 | } |
---|
| 842 | |
---|
[551] | 843 | /*! |
---|
| 844 | \brief Solve domain and axis references |
---|
| 845 | As field, domain and axis can refer to other domains or axis. In order to inherit correctly |
---|
| 846 | all attributes from their parents, they should be processed with this function |
---|
| 847 | \param[in] apply inherit all attributes of parents (true) |
---|
| 848 | */ |
---|
[540] | 849 | void CGrid::solveDomainAxisRefInheritance(bool apply) |
---|
| 850 | { |
---|
| 851 | CContext* context = CContext::getCurrent(); |
---|
| 852 | unsigned int vecSize, i; |
---|
| 853 | std::vector<StdString>::iterator it, itE; |
---|
| 854 | setDomainList(); |
---|
| 855 | it = domList_.begin(); itE = domList_.end(); |
---|
| 856 | for (; it != itE; ++it) |
---|
| 857 | { |
---|
| 858 | CDomain* pDom = CDomain::get(*it); |
---|
| 859 | if (context->hasClient) |
---|
| 860 | { |
---|
| 861 | pDom->solveRefInheritance(apply); |
---|
| 862 | pDom->solveBaseReference(); |
---|
| 863 | if ((!pDom->domain_ref.isEmpty()) && (pDom->name.isEmpty())) |
---|
| 864 | pDom->name.setValue(pDom->getBaseDomainReference()->getId()); |
---|
| 865 | } |
---|
| 866 | } |
---|
| 867 | |
---|
| 868 | setAxisList(); |
---|
| 869 | it = axisList_.begin(); itE = axisList_.end(); |
---|
| 870 | for (; it != itE; ++it) |
---|
| 871 | { |
---|
| 872 | CAxis* pAxis = CAxis::get(*it); |
---|
| 873 | if (context->hasClient) |
---|
| 874 | { |
---|
| 875 | pAxis->solveRefInheritance(apply); |
---|
| 876 | pAxis->solveBaseReference(); |
---|
| 877 | if ((!pAxis->axis_ref.isEmpty()) && (pAxis->name.isEmpty())) |
---|
| 878 | pAxis->name.setValue(pAxis->getBaseAxisReference()->getId()); |
---|
| 879 | } |
---|
| 880 | } |
---|
| 881 | } |
---|
| 882 | |
---|
[551] | 883 | /*! |
---|
| 884 | \brief Get the list of domain pointers |
---|
| 885 | \return list of domain pointers |
---|
| 886 | */ |
---|
[540] | 887 | std::vector<CDomain*> CGrid::getDomains() |
---|
| 888 | { |
---|
| 889 | std::vector<CDomain*> domList; |
---|
| 890 | if (!domList_.empty()) |
---|
| 891 | { |
---|
| 892 | for (int i = 0; i < domList_.size(); ++i) domList.push_back(CDomain::get(domList_[i])); |
---|
| 893 | } |
---|
| 894 | return domList; |
---|
| 895 | } |
---|
| 896 | |
---|
[551] | 897 | /*! |
---|
| 898 | \brief Get the list of axis pointers |
---|
| 899 | \return list of axis pointers |
---|
| 900 | */ |
---|
[540] | 901 | std::vector<CAxis*> CGrid::getAxis() |
---|
| 902 | { |
---|
| 903 | std::vector<CAxis*> aList; |
---|
| 904 | if (!axisList_.empty()) |
---|
| 905 | for (int i =0; i < axisList_.size(); ++i) aList.push_back(CAxis::get(axisList_[i])); |
---|
| 906 | |
---|
| 907 | return aList; |
---|
| 908 | } |
---|
| 909 | |
---|
[551] | 910 | /*! |
---|
| 911 | \brief Set domain(s) of a grid from a list |
---|
| 912 | \param[in] domains list of domains |
---|
| 913 | */ |
---|
[540] | 914 | void CGrid::setDomainList(const std::vector<CDomain*> domains) |
---|
| 915 | { |
---|
| 916 | if (isDomListSet) return; |
---|
| 917 | std::vector<CDomain*> domList = this->getVirtualDomainGroup()->getAllChildren(); |
---|
| 918 | if (!domains.empty() && domList.empty()) domList = domains; |
---|
| 919 | if (!domList.empty()) |
---|
| 920 | { |
---|
| 921 | int sizeDom = domList.size(); |
---|
| 922 | domList_.resize(sizeDom); |
---|
| 923 | for (int i = 0 ; i < sizeDom; ++i) |
---|
| 924 | { |
---|
| 925 | domList_[i] = domList[i]->getId(); |
---|
| 926 | } |
---|
| 927 | isDomListSet = true; |
---|
| 928 | } |
---|
| 929 | |
---|
| 930 | } |
---|
| 931 | |
---|
[551] | 932 | /*! |
---|
| 933 | \brief Set axis(s) of a grid from a list |
---|
| 934 | \param[in] axis list of axis |
---|
| 935 | */ |
---|
[540] | 936 | void CGrid::setAxisList(const std::vector<CAxis*> axis) |
---|
| 937 | { |
---|
| 938 | if (isAxisListSet) return; |
---|
| 939 | std::vector<CAxis*> aList = this->getVirtualAxisGroup()->getAllChildren(); |
---|
| 940 | if (!axis.empty() && aList.empty()) aList = axis; |
---|
| 941 | if (!aList.empty()) |
---|
| 942 | { |
---|
| 943 | int sizeAxis = aList.size(); |
---|
| 944 | axisList_.resize(sizeAxis); |
---|
| 945 | for (int i = 0; i < sizeAxis; ++i) |
---|
| 946 | { |
---|
| 947 | axisList_[i] = aList[i]->getId(); |
---|
| 948 | } |
---|
| 949 | isAxisListSet = true; |
---|
| 950 | } |
---|
| 951 | } |
---|
| 952 | |
---|
[551] | 953 | /*! |
---|
| 954 | \brief Get list of id of domains |
---|
| 955 | \return id list of domains |
---|
| 956 | */ |
---|
[540] | 957 | std::vector<StdString> CGrid::getDomainList() |
---|
| 958 | { |
---|
| 959 | setDomainList(); |
---|
| 960 | return domList_; |
---|
| 961 | } |
---|
| 962 | |
---|
[551] | 963 | /*! |
---|
| 964 | \brief Get list of id of axis |
---|
| 965 | \return id list of axis |
---|
| 966 | */ |
---|
[540] | 967 | std::vector<StdString> CGrid::getAxisList() |
---|
| 968 | { |
---|
| 969 | setAxisList(); |
---|
| 970 | return axisList_; |
---|
| 971 | } |
---|
| 972 | |
---|
| 973 | void CGrid::sendAllDomains() |
---|
| 974 | { |
---|
| 975 | std::vector<CDomain*> domList = this->getVirtualDomainGroup()->getAllChildren(); |
---|
| 976 | int dSize = domList.size(); |
---|
| 977 | for (int i = 0; i < dSize; ++i) |
---|
| 978 | { |
---|
| 979 | sendAddDomain(domList[i]->getId()); |
---|
| 980 | domList[i]->sendAllAttributesToServer(); |
---|
| 981 | } |
---|
| 982 | } |
---|
| 983 | |
---|
| 984 | void CGrid::sendAllAxis() |
---|
| 985 | { |
---|
| 986 | std::vector<CAxis*> aList = this->getVirtualAxisGroup()->getAllChildren(); |
---|
| 987 | int aSize = aList.size(); |
---|
| 988 | |
---|
| 989 | for (int i = 0; i < aSize; ++i) |
---|
| 990 | { |
---|
| 991 | sendAddAxis(aList[i]->getId()); |
---|
| 992 | aList[i]->sendAllAttributesToServer(); |
---|
| 993 | } |
---|
| 994 | } |
---|
| 995 | |
---|
| 996 | void CGrid::parse(xml::CXMLNode & node) |
---|
| 997 | { |
---|
| 998 | SuperClass::parse(node); |
---|
[567] | 999 | |
---|
[551] | 1000 | // List order of axis and domain in a grid, if there is a domain, it will take value 1 (true), axis 0 (false) |
---|
| 1001 | std::vector<bool> order; |
---|
[540] | 1002 | |
---|
| 1003 | if (node.goToChildElement()) |
---|
| 1004 | { |
---|
| 1005 | StdString domainName("domain"); |
---|
| 1006 | StdString axisName("axis"); |
---|
| 1007 | do |
---|
| 1008 | { |
---|
| 1009 | if (node.getElementName() == domainName) { |
---|
[551] | 1010 | order.push_back(true); |
---|
[540] | 1011 | this->getVirtualDomainGroup()->parseChild(node); |
---|
| 1012 | } |
---|
| 1013 | if (node.getElementName() == axisName) { |
---|
[551] | 1014 | order.push_back(false); |
---|
[540] | 1015 | this->getVirtualAxisGroup()->parseChild(node); |
---|
| 1016 | } |
---|
| 1017 | } while (node.goToNextElement()) ; |
---|
| 1018 | node.goToParentElement(); |
---|
| 1019 | } |
---|
| 1020 | |
---|
[551] | 1021 | if (!order.empty()) |
---|
[540] | 1022 | { |
---|
[551] | 1023 | int sizeOrd = order.size(); |
---|
| 1024 | axisDomainOrder.resize(sizeOrd); |
---|
[540] | 1025 | for (int i = 0; i < sizeOrd; ++i) |
---|
| 1026 | { |
---|
[551] | 1027 | axisDomainOrder(i) = order[i]; |
---|
[540] | 1028 | } |
---|
| 1029 | } |
---|
| 1030 | |
---|
| 1031 | setDomainList(); |
---|
| 1032 | setAxisList(); |
---|
| 1033 | } |
---|
| 1034 | |
---|
[335] | 1035 | } // namespace xios |
---|