Changeset 1930 for XIOS/dev/dev_ym/XIOS_COUPLING/src/node/grid.cpp
- Timestamp:
- 09/10/20 13:51:02 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/grid.cpp
r1918 r1930 19 19 #include "grid_generate.hpp" 20 20 #include "server.hpp" 21 #include "distribution_type.hpp" 22 #include "grid_remote_connector.hpp" 23 #include "grid_elements.hpp" 24 #include "grid_local_view.hpp" 25 21 26 22 27 namespace xios { … … 79 84 StdString CGrid::GetDefName(void) { return CGrid::GetName(); } 80 85 ENodeType CGrid::GetType(void) { return eGrid; } 86 87 88 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 89 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 90 ///////// MEMBER FUNCTION RELATED TO GRID CONSTRUCTION by ELEMNTS AND MANAGEMENT ///// 91 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 92 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 93 94 95 CGrid* CGrid::createGrid(CDomain* domain) 96 TRY 97 { 98 std::vector<CDomain*> vecDom(1, domain); 99 std::vector<CAxis*> vecAxis; 100 return createGrid(vecDom, vecAxis); 101 } 102 CATCH 103 104 CGrid* CGrid::createGrid(CDomain* domain, CAxis* axis) 105 TRY 106 { 107 std::vector<CDomain*> vecDom(1, domain); 108 std::vector<CAxis*> vecAxis(1, axis); 109 110 return createGrid(vecDom, vecAxis); 111 } 112 CATCH 113 114 CGrid* CGrid::createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, 115 const CArray<int,1>& axisDomainOrder) 116 TRY 117 { 118 std::vector<CScalar*> vecScalar; 119 return createGrid(generateId(domains, axis, vecScalar, axisDomainOrder), domains, axis, vecScalar, axisDomainOrder); 120 } 121 CATCH 122 123 CGrid* CGrid::createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, 124 const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder) 125 TRY 126 { 127 return createGrid(generateId(domains, axis, scalars, axisDomainOrder), domains, axis, scalars, axisDomainOrder); 128 } 129 CATCH 130 131 CGrid* CGrid::createGrid(StdString id, const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, 132 const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder) 133 TRY 134 { 135 if (axisDomainOrder.numElements() > 0 && axisDomainOrder.numElements() != (domains.size() + axis.size() + scalars.size())) 136 ERROR("CGrid* CGrid::createGrid(...)", 137 << "The size of axisDomainOrder (" << axisDomainOrder.numElements() 138 << ") is not coherent with the number of elements (" << domains.size() + axis.size() <<")."); 139 140 CGrid* grid = CGridGroup::get("grid_definition")->createChild(id); 141 grid->setDomainList(domains); 142 grid->setAxisList(axis); 143 grid->setScalarList(scalars); 144 145 // By default, domains are always the first elements of a grid 146 if (0 == axisDomainOrder.numElements()) 147 { 148 int size = domains.size() + axis.size() + scalars.size(); 149 int nb = 0; 150 grid->axis_domain_order.resize(size); 151 for (int i = 0; i < size; ++i) 152 { 153 if (i < domains.size()) { 154 grid->axis_domain_order(i) = 2; 155 156 } 157 else if ((scalars.size() < (size-nb)) < size) { 158 grid->axis_domain_order(i) = 1; 159 } 160 else 161 grid->axis_domain_order(i) = 0; 162 ++nb; 163 } 164 } 165 else 166 { 167 grid->axis_domain_order.resize(axisDomainOrder.numElements()); 168 grid->axis_domain_order = axisDomainOrder; 169 } 170 171 // grid->solveElementsRefInheritance(true); 172 173 return grid; 174 } 175 CATCH 176 177 //---------------------------------------------------------------- 178 179 //! Change virtual field group to a new one 180 void CGrid::setVirtualDomainGroup(CDomainGroup* newVDomainGroup) 181 TRY 182 { 183 this->vDomainGroup_ = newVDomainGroup; 184 } 185 CATCH_DUMP_ATTR 186 187 //! Change virtual variable group to new one 188 void CGrid::setVirtualAxisGroup(CAxisGroup* newVAxisGroup) 189 TRY 190 { 191 this->vAxisGroup_ = newVAxisGroup; 192 } 193 CATCH_DUMP_ATTR 194 195 //! Change virtual variable group to new one 196 void CGrid::setVirtualScalarGroup(CScalarGroup* newVScalarGroup) 197 TRY 198 { 199 this->vScalarGroup_ = newVScalarGroup; 200 } 201 CATCH_DUMP_ATTR 202 203 //---------------------------------------------------------------- 204 205 CDomainGroup* CGrid::getVirtualDomainGroup() const 206 TRY 207 { 208 return this->vDomainGroup_; 209 } 210 CATCH 211 212 CAxisGroup* CGrid::getVirtualAxisGroup() const 213 TRY 214 { 215 return this->vAxisGroup_; 216 } 217 CATCH 218 219 CScalarGroup* CGrid::getVirtualScalarGroup() const 220 TRY 221 { 222 return this->vScalarGroup_; 223 } 224 CATCH 225 226 ///--------------------------------------------------------------- 227 228 CDomain* CGrid::addDomain(const std::string& id) 229 TRY 230 { 231 order_.push_back(2); 232 axis_domain_order.resize(order_.size()); 233 for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; 234 return vDomainGroup_->createChild(id); 235 } 236 CATCH_DUMP_ATTR 237 238 CAxis* CGrid::addAxis(const std::string& id) 239 TRY 240 { 241 order_.push_back(1); 242 axis_domain_order.resize(order_.size()); 243 for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; 244 return vAxisGroup_->createChild(id); 245 } 246 CATCH_DUMP_ATTR 247 248 CScalar* CGrid::addScalar(const std::string& id) 249 TRY 250 { 251 order_.push_back(0); 252 axis_domain_order.resize(order_.size()); 253 for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; 254 return vScalarGroup_->createChild(id); 255 } 256 CATCH_DUMP_ATTR 257 258 259 260 261 /*! 262 \brief Get the list of domain pointers 263 \return list of domain pointers 264 */ 265 std::vector<CDomain*> CGrid::getDomains() 266 TRY 267 { 268 std::vector<CDomain*> domList; 269 if (!domList_.empty()) 270 { 271 for (int i = 0; i < domList_.size(); ++i) domList.push_back(CDomain::get(domList_[i])); 272 } 273 return domList; 274 } 275 CATCH_DUMP_ATTR 276 277 /*! 278 \brief Get the list of axis pointers 279 \return list of axis pointers 280 */ 281 std::vector<CAxis*> CGrid::getAxis() 282 TRY 283 { 284 std::vector<CAxis*> aList; 285 if (!axisList_.empty()) 286 for (int i =0; i < axisList_.size(); ++i) aList.push_back(CAxis::get(axisList_[i])); 287 288 return aList; 289 } 290 CATCH_DUMP_ATTR 291 292 /*! 293 \brief Get the list of axis pointers 294 \return list of axis pointers 295 */ 296 std::vector<CScalar*> CGrid::getScalars() 297 TRY 298 { 299 std::vector<CScalar*> sList; 300 if (!scalarList_.empty()) 301 for (int i =0; i < scalarList_.size(); ++i) sList.push_back(CScalar::get(scalarList_[i])); 302 303 return sList; 304 } 305 CATCH_DUMP_ATTR 306 307 /*! 308 \brief Get domain pointer with index 309 \return domain pointer 310 */ 311 CDomain* CGrid::getDomain(int domainIndex) 312 TRY 313 { 314 std::vector<CDomain*> domainListP = this->getDomains(); 315 if (domainListP.empty()) 316 { 317 ERROR("CGrid::getDomain(int domainIndex)", 318 << "No domain associated to this grid. " << std::endl 319 << "Grid id = " << this->getId()); 320 } 321 322 if (domainIndex >= domainListP.size() || (domainIndex < 0)) 323 ERROR("CGrid::getDomain(int domainIndex)", 324 << "Domain with the index doesn't exist " << std::endl 325 << "Grid id = " << this->getId() << std::endl 326 << "Grid has only " << domainListP.size() << " domain but domain index required is " << domainIndex << std::endl); 327 328 return domainListP[domainIndex]; 329 } 330 CATCH_DUMP_ATTR 331 332 /*! 333 \brief Get the axis pointer with index 334 \return axis pointer 335 */ 336 CAxis* CGrid::getAxis(int axisIndex) 337 TRY 338 { 339 std::vector<CAxis*> axisListP = this->getAxis(); 340 if (axisListP.empty()) 341 { 342 ERROR("CGrid::getDomain(int axisIndex)", 343 << "No axis associated to this grid. " << std::endl 344 << "Grid id = " << this->getId()); 345 } 346 347 if (axisIndex >= axisListP.size() || (axisIndex < 0)) 348 ERROR("CGrid::getDomain(int axisIndex)", 349 << "Domain with the index doesn't exist " << std::endl 350 << "Grid id = " << this->getId() << std::endl 351 << "Grid has only " << axisListP.size() << " axis but axis index required is " << axisIndex << std::endl); 352 353 return axisListP[axisIndex]; 354 } 355 CATCH_DUMP_ATTR 356 357 /*! 358 \brief Get the a scalar pointer 359 \return scalar pointer 360 */ 361 CScalar* CGrid::getScalar(int scalarIndex) 362 TRY 363 { 364 std::vector<CScalar*> scalarListP = this->getScalars(); 365 if (scalarListP.empty()) 366 { 367 ERROR("CGrid::getScalar(int scalarIndex)", 368 << "No scalar associated to this grid. " << std::endl 369 << "Grid id = " << this->getId()); 370 } 371 372 if (scalarIndex >= scalarListP.size() || (scalarIndex < 0)) 373 ERROR("CGrid::getScalar(int scalarIndex)", 374 << "Scalar with the index doesn't exist " << std::endl 375 << "Grid id = " << this->getId() << std::endl 376 << "Grid has only " << scalarListP.size() << " scalar but scalar index required is " << scalarIndex << std::endl); 377 378 return scalarListP[scalarIndex]; 379 } 380 CATCH_DUMP_ATTR 381 382 /*! 383 \brief Set domain(s) of a grid from a list 384 \param[in] domains list of domains 385 */ 386 void CGrid::setDomainList(const std::vector<CDomain*> domains) 387 TRY 388 { 389 if (isDomListSet) return; 390 std::vector<CDomain*> domList = this->getVirtualDomainGroup()->getAllChildren(); 391 if (!domains.empty() && domList.empty()) 392 { 393 for (int i = 0; i < domains.size(); ++i) 394 this->getVirtualDomainGroup()->addChild(domains[i]); 395 domList = this->getVirtualDomainGroup()->getAllChildren(); 396 } 397 398 if (!domList.empty()) 399 { 400 int sizeDom = domList.size(); 401 domList_.resize(sizeDom); 402 for (int i = 0; i < sizeDom; ++i) 403 { 404 domList_[i] = domList[i]->getId(); 405 } 406 isDomListSet = true; 407 } 408 } 409 CATCH_DUMP_ATTR 410 411 /*! 412 \brief Set axis(s) of a grid from a list 413 \param[in] axis list of axis 414 */ 415 void CGrid::setAxisList(const std::vector<CAxis*> axis) 416 TRY 417 { 418 if (isAxisListSet) return; 419 std::vector<CAxis*> aList = this->getVirtualAxisGroup()->getAllChildren(); 420 if (!axis.empty() && aList.empty()) 421 { 422 for (int i = 0; i < axis.size(); ++i) 423 this->getVirtualAxisGroup()->addChild(axis[i]); 424 aList = this->getVirtualAxisGroup()->getAllChildren(); 425 } 426 427 if (!aList.empty()) 428 { 429 int sizeAxis = aList.size(); 430 axisList_.resize(sizeAxis); 431 for (int i = 0; i < sizeAxis; ++i) 432 { 433 axisList_[i] = aList[i]->getId(); 434 } 435 isAxisListSet = true; 436 } 437 } 438 CATCH_DUMP_ATTR 439 440 /*! 441 \brief Set scalar(s) of a grid from a list 442 \param[in] scalars list of scalars 443 */ 444 void CGrid::setScalarList(const std::vector<CScalar*> scalars) 445 TRY 446 { 447 if (isScalarListSet) return; 448 std::vector<CScalar*> sList = this->getVirtualScalarGroup()->getAllChildren(); 449 if (!scalars.empty() && sList.empty()) 450 { 451 for (int i = 0; i < scalars.size(); ++i) 452 this->getVirtualScalarGroup()->addChild(scalars[i]); 453 sList = this->getVirtualScalarGroup()->getAllChildren(); 454 } 455 456 if (!sList.empty()) 457 { 458 int sizeScalar = sList.size(); 459 scalarList_.resize(sizeScalar); 460 for (int i = 0; i < sizeScalar; ++i) 461 { 462 scalarList_[i] = sList[i]->getId(); 463 } 464 isScalarListSet = true; 465 } 466 } 467 CATCH_DUMP_ATTR 468 469 /*! 470 \brief Get list of id of domains 471 \return id list of domains 472 */ 473 std::vector<StdString> CGrid::getDomainList() 474 TRY 475 { 476 setDomainList(); 477 return domList_; 478 } 479 CATCH 480 481 /*! 482 \brief Get list of id of axis 483 \return id list of axis 484 */ 485 std::vector<StdString> CGrid::getAxisList() 486 TRY 487 { 488 setAxisList(); 489 return axisList_; 490 } 491 CATCH 492 493 /*! 494 \brief Get list of id of scalar 495 \return id list of scalar 496 */ 497 std::vector<StdString> CGrid::getScalarList() 498 TRY 499 { 500 setScalarList(); 501 return scalarList_; 502 } 503 CATCH 504 505 506 void CGrid::computeElements(void) 507 { 508 const auto& domains = getDomains() ; 509 const auto& axis = getAxis() ; 510 const auto& scalars = getScalars() ; 511 int idxDomain = 0, idxAxis=0 , idxScalar=0 ; 512 513 for(auto type : order_) 514 { 515 if (type == 0) { elements_.push_back({scalars[idxScalar], TYPE_SCALAR, scalars[idxScalar], nullptr, nullptr } ) ; idxScalar++;} 516 else if (type == 1) { elements_.push_back({axis[idxAxis], TYPE_AXIS, nullptr, axis[idxAxis], nullptr}) ; idxAxis++;} 517 else if (type == 2) { elements_.push_back({domains[idxDomain], TYPE_DOMAIN, nullptr, nullptr, domains[idxDomain] }) ; idxDomain++;} 518 } 519 elementsComputed_ = true ; 520 } 521 522 523 /*! 524 Parse a grid, for now, it contains only domain, axis and scalar 525 */ 526 void CGrid::parse(xml::CXMLNode& node) 527 TRY 528 { 529 SuperClass::parse(node); 530 531 if (node.goToChildElement()) 532 { 533 StdString domainName("domain"); 534 StdString axisName("axis"); 535 StdString scalarName("scalar"); 536 do 537 { 538 if (node.getElementName() == domainName) { 539 order_.push_back(2); 540 this->getVirtualDomainGroup()->parseChild(node); 541 } 542 if (node.getElementName() == axisName) { 543 order_.push_back(1); 544 this->getVirtualAxisGroup()->parseChild(node); 545 } 546 if (node.getElementName() == scalarName) { 547 order_.push_back(0); 548 this->getVirtualScalarGroup()->parseChild(node); 549 } 550 } while (node.goToNextElement()); 551 node.goToParentElement(); 552 } 553 554 if (!order_.empty()) 555 { 556 int sizeOrd = order_.size(); 557 axis_domain_order.resize(sizeOrd); 558 for (int i = 0; i < sizeOrd; ++i) 559 { 560 axis_domain_order(i) = order_[i]; 561 } 562 } 563 564 setDomainList(); 565 setAxisList(); 566 setScalarList(); 567 } 568 CATCH_DUMP_ATTR 569 570 571 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 572 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 573 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 574 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 575 81 576 82 577 … … 1169 1664 //---------------------------------------------------------------- 1170 1665 1171 CGrid* CGrid::createGrid(CDomain* domain) 1172 TRY 1173 { 1174 std::vector<CDomain*> vecDom(1, domain); 1175 std::vector<CAxis*> vecAxis; 1176 1177 return createGrid(vecDom, vecAxis); 1178 } 1179 CATCH 1180 1181 CGrid* CGrid::createGrid(CDomain* domain, CAxis* axis) 1182 TRY 1183 { 1184 std::vector<CDomain*> vecDom(1, domain); 1185 std::vector<CAxis*> vecAxis(1, axis); 1186 1187 return createGrid(vecDom, vecAxis); 1188 } 1189 CATCH 1190 1191 CGrid* CGrid::createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, 1192 const CArray<int,1>& axisDomainOrder) 1193 TRY 1194 { 1195 std::vector<CScalar*> vecScalar; 1196 return createGrid(generateId(domains, axis, vecScalar, axisDomainOrder), domains, axis, vecScalar, axisDomainOrder); 1197 } 1198 CATCH 1199 1200 CGrid* CGrid::createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, 1201 const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder) 1202 TRY 1203 { 1204 return createGrid(generateId(domains, axis, scalars, axisDomainOrder), domains, axis, scalars, axisDomainOrder); 1205 } 1206 CATCH 1207 1208 CGrid* CGrid::createGrid(StdString id, const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, 1209 const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder) 1210 TRY 1211 { 1212 if (axisDomainOrder.numElements() > 0 && axisDomainOrder.numElements() != (domains.size() + axis.size() + scalars.size())) 1213 ERROR("CGrid* CGrid::createGrid(...)", 1214 << "The size of axisDomainOrder (" << axisDomainOrder.numElements() 1215 << ") is not coherent with the number of elements (" << domains.size() + axis.size() <<")."); 1216 1217 CGrid* grid = CGridGroup::get("grid_definition")->createChild(id); 1218 grid->setDomainList(domains); 1219 grid->setAxisList(axis); 1220 grid->setScalarList(scalars); 1221 1222 // By default, domains are always the first elements of a grid 1223 if (0 == axisDomainOrder.numElements()) 1224 { 1225 int size = domains.size() + axis.size() + scalars.size(); 1226 int nb = 0; 1227 grid->axis_domain_order.resize(size); 1228 for (int i = 0; i < size; ++i) 1229 { 1230 if (i < domains.size()) { 1231 grid->axis_domain_order(i) = 2; 1232 1233 } 1234 else if ((scalars.size() < (size-nb)) < size) { 1235 grid->axis_domain_order(i) = 1; 1236 } 1237 else 1238 grid->axis_domain_order(i) = 0; 1239 ++nb; 1240 } 1241 } 1242 else 1243 { 1244 grid->axis_domain_order.resize(axisDomainOrder.numElements()); 1245 grid->axis_domain_order = axisDomainOrder; 1246 } 1247 1248 // grid->solveElementsRefInheritance(true); 1249 1250 return grid; 1251 } 1252 CATCH 1666 1253 1667 1254 1668 CGrid* CGrid::cloneGrid(const StdString& idNewGrid, CGrid* gridSrc) … … 1353 1767 CATCH 1354 1768 1355 //----------------------------------------------------------------1356 1357 CDomainGroup* CGrid::getVirtualDomainGroup() const1358 TRY1359 {1360 return this->vDomainGroup_;1361 }1362 CATCH1363 1364 CAxisGroup* CGrid::getVirtualAxisGroup() const1365 TRY1366 {1367 return this->vAxisGroup_;1368 }1369 CATCH1370 1371 CScalarGroup* CGrid::getVirtualScalarGroup() const1372 TRY1373 {1374 return this->vScalarGroup_;1375 }1376 CATCH1377 1769 1378 1770 //---------------------------------------------------------------- … … 2086 2478 TRY 2087 2479 { 2088 return (0 != get WrittenDataSize());2480 return (0 != getGridLocalElements()->getView(CElementView::FULL)->getSize()); 2089 2481 } 2090 2482 CATCH_DUMP_ATTR … … 2099 2491 TRY 2100 2492 { 2101 return get ServerDistribution()->getGridSize();2493 return getGridLocalElements()->getView(CElementView::FULL)->getSize() ; 2102 2494 } 2103 2495 CATCH … … 2205 2597 CATCH 2206 2598 2207 ///--------------------------------------------------------------- 2208 2209 CDomain* CGrid::addDomain(const std::string& id) 2210 TRY 2211 { 2212 order_.push_back(2); 2213 axis_domain_order.resize(order_.size()); 2214 for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; 2215 return vDomainGroup_->createChild(id); 2216 } 2217 CATCH_DUMP_ATTR 2218 2219 CAxis* CGrid::addAxis(const std::string& id) 2220 TRY 2221 { 2222 order_.push_back(1); 2223 axis_domain_order.resize(order_.size()); 2224 for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; 2225 return vAxisGroup_->createChild(id); 2226 } 2227 CATCH_DUMP_ATTR 2228 2229 CScalar* CGrid::addScalar(const std::string& id) 2230 TRY 2231 { 2232 order_.push_back(0); 2233 axis_domain_order.resize(order_.size()); 2234 for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; 2235 return vScalarGroup_->createChild(id); 2236 } 2237 CATCH_DUMP_ATTR 2238 2239 //! Change virtual field group to a new one 2240 void CGrid::setVirtualDomainGroup(CDomainGroup* newVDomainGroup) 2241 TRY 2242 { 2243 this->vDomainGroup_ = newVDomainGroup; 2244 } 2245 CATCH_DUMP_ATTR 2246 2247 //! Change virtual variable group to new one 2248 void CGrid::setVirtualAxisGroup(CAxisGroup* newVAxisGroup) 2249 TRY 2250 { 2251 this->vAxisGroup_ = newVAxisGroup; 2252 } 2253 CATCH_DUMP_ATTR 2254 2255 //! Change virtual variable group to new one 2256 void CGrid::setVirtualScalarGroup(CScalarGroup* newVScalarGroup) 2257 TRY 2258 { 2259 this->vScalarGroup_ = newVScalarGroup; 2260 } 2261 CATCH_DUMP_ATTR 2262 2599 2263 2600 2264 2601 void CGrid::sendGridToFileServer(CContextClient* client) … … 2271 2608 gridPtr->sendCreateChild(this->getId(),client); 2272 2609 this->sendAllAttributesToServer(client); 2273 if (isScalarGrid()) sendIndexScalarGrid(client); 2274 else sendIndex(client); 2275 this->sendAllDomains(client); 2276 this->sendAllAxis(client); 2277 this->sendAllScalars(client); 2278 } 2610 //if (isScalarGrid()) sendIndexScalarGrid(client); 2611 //else sendIndex(client); 2612 //this->sendAllDomains(client); 2613 //this->sendAllAxis(client); 2614 //this->sendAllScalars(client); 2615 2616 distributeGridToFileServer(client) ; 2617 } 2618 2619 2620 void CGrid::distributeGridToFileServer(CContextClient* client) 2621 { 2622 CContext* context = CContext::getCurrent(); 2623 // simple Distribution for now 2624 // distribute over the fisrt element except if it is a scalar 2625 auto& elements = getElements() ; 2626 int posDistributed = 0 ; 2627 for(auto& element : elements) 2628 { 2629 if (element.type==TYPE_DOMAIN) break ; 2630 else if (element.type==TYPE_AXIS) break ; 2631 else if (element.type==TYPE_SCALAR) posDistributed++ ; 2632 } 2633 2634 vector<CLocalView*> localViews ; 2635 vector<CDistributedView*> remoteViews ; 2636 2637 for(int i=0 ; i<elements.size() ; i++) 2638 { 2639 if (elements[i].type==TYPE_DOMAIN) 2640 { 2641 CDomain* domain = (CDomain*) elements[i].ptr ; 2642 domain->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; 2643 remoteViews.push_back(domain->getRemoteElement(client)->getView(CElementView::FULL)) ; 2644 localViews.push_back(domain->getLocalView(CElementView::FULL)) ; 2645 } 2646 else if (elements[i].type==TYPE_AXIS) 2647 { 2648 CAxis* axis = (CAxis*) elements[i].ptr ; 2649 axis->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; 2650 remoteViews.push_back(axis->getRemoteElement(client)->getView(CElementView::FULL)) ; 2651 localViews.push_back(axis->getLocalView(CElementView::FULL)) ; 2652 } 2653 else if (elements[i].type==TYPE_SCALAR) 2654 { 2655 CScalar* scalar = (CScalar*) elements[i].ptr ; 2656 scalar->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; 2657 remoteViews.push_back(scalar->getRemoteElement(client)->getView(CElementView::FULL)) ; 2658 localViews.push_back(scalar->getLocalView(CElementView::FULL)) ; 2659 } 2660 } 2661 CGridRemoteConnector gridRemoteConnector(localViews, remoteViews, context->getIntraComm()) ; 2662 gridRemoteConnector.computeConnector() ; 2663 2664 vector<CScattererConnector*> clientToServerConnectors ; 2665 for(int i=0 ; i<elements.size() ; i++) 2666 { 2667 if (elements[i].type==TYPE_DOMAIN) 2668 { 2669 CDomain* domain = (CDomain*) elements[i].ptr ; 2670 sendAddDomain(domain->getId(),client) ; 2671 domain->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; 2672 clientToServerConnectors.push_back(domain->getClientToServerConnector(client)) ; 2673 } 2674 else if (elements[i].type==TYPE_AXIS) 2675 { 2676 CAxis* axis = (CAxis*) elements[i].ptr ; 2677 sendAddAxis(axis->getId(),client) ; 2678 axis->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; 2679 clientToServerConnectors.push_back(axis->getClientToServerConnector(client)) ; 2680 } 2681 else if (elements[i].type==TYPE_SCALAR) 2682 { 2683 CScalar* scalar = (CScalar*) elements[i].ptr ; 2684 sendAddScalar(scalar->getId(),client) ; 2685 scalar->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; 2686 clientToServerConnectors.push_back(scalar->getClientToServerConnector(client)) ; 2687 } 2688 } 2689 2690 // compute the grid clientToServerConnector to send flux from client to servers 2691 clientToServerConnector_[client] = new CGridScattererConnector(clientToServerConnectors) ; 2692 2693 } 2694 2279 2695 2280 2696 void CGrid::sendGridToCouplerOut(CContextClient* client, const string& fieldId) … … 2282 2698 if (sendGridToCouplerOut_done_.count(client)!=0) return ; 2283 2699 else sendGridToCouplerOut_done_.insert(client) ; 2284 string gridId="_grid_of_"+fieldId ; 2285 this->sendAllAttributesToServer(client, gridId); 2700 2701 CContext* context = CContext::getCurrent(); 2702 // simple Distribution for now 2703 // distribute over the fisrt element except if it is a scalar 2704 auto& elements = getElements() ; 2705 int posDistributed = 0 ; 2706 for(auto& element : elements) 2707 { 2708 if (element.type==TYPE_DOMAIN) break ; 2709 else if (element.type==TYPE_AXIS) break ; 2710 else if (element.type==TYPE_SCALAR) posDistributed++ ; 2711 } 2286 2712 2287 if (isScalarGrid()) sendIndexScalarGrid(client, gridId); 2288 else sendIndex(client, gridId); 2289 2290 const auto& domVect = getDomains() ; 2291 for (int pos=0; pos<domVect.size();pos++) domVect[pos]->sendDomainToCouplerOut(client, fieldId, pos); 2292 2293 const auto& axisVect=getAxis() ; 2294 for (int pos=0; pos<axisVect.size();pos++) axisVect[pos]->sendAxisToCouplerOut(client, getGlobalDimension(), getAxisPositionInGrid()[pos], fieldId, pos); 2295 2296 const auto& scalVect=getScalars() ; 2297 for (int pos=0; pos<scalVect.size();pos++) scalVect[pos]->sendScalarToCouplerOut(client, fieldId, pos); 2713 vector<CLocalView*> localViews ; 2714 vector<CDistributedView*> remoteViews ; 2715 2716 for(int i=0 ; i<elements.size() ; i++) 2717 { 2718 if (elements[i].type==TYPE_DOMAIN) 2719 { 2720 CDomain* domain = (CDomain*) elements[i].ptr ; 2721 domain->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; 2722 remoteViews.push_back(domain->getRemoteElement(client)->getView(CElementView::FULL)) ; 2723 localViews.push_back(domain->getLocalView(CElementView::FULL)) ; 2724 } 2725 else if (elements[i].type==TYPE_AXIS) 2726 { 2727 CAxis* axis = (CAxis*) elements[i].ptr ; 2728 axis->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; 2729 remoteViews.push_back(axis->getRemoteElement(client)->getView(CElementView::FULL)) ; 2730 localViews.push_back(axis->getLocalView(CElementView::FULL)) ; 2731 } 2732 else if (elements[i].type==TYPE_SCALAR) 2733 { 2734 CScalar* scalar = (CScalar*) elements[i].ptr ; 2735 scalar->computeRemoteElement(client, posDistributed==i ? EDistributionType::BANDS : EDistributionType::NONE) ; 2736 remoteViews.push_back(scalar->getRemoteElement(client)->getView(CElementView::FULL)) ; 2737 localViews.push_back(scalar->getLocalView(CElementView::FULL)) ; 2738 } 2739 } 2740 CGridRemoteConnector gridRemoteConnector(localViews, remoteViews, context->getIntraComm()) ; 2741 gridRemoteConnector.computeConnector() ; 2742 2743 vector<CScattererConnector*> clientToClientConnectors ; 2744 for(int i=0 ; i<elements.size() ; i++) 2745 { 2746 if (elements[i].type==TYPE_DOMAIN) 2747 { 2748 CDomain* domain = (CDomain*) elements[i].ptr ; 2749 sendAddDomain(domain->getId(),client) ; 2750 domain->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; 2751 clientToClientConnectors.push_back(domain->getClientToServerConnector(client)) ; 2752 } 2753 else if (elements[i].type==TYPE_AXIS) 2754 { 2755 CAxis* axis = (CAxis*) elements[i].ptr ; 2756 sendAddAxis(axis->getId(),client) ; 2757 axis->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; 2758 clientToClientConnectors.push_back(axis->getClientToServerConnector(client)) ; 2759 } 2760 else if (elements[i].type==TYPE_SCALAR) 2761 { 2762 CScalar* scalar = (CScalar*) elements[i].ptr ; 2763 sendAddScalar(scalar->getId(),client) ; 2764 scalar->distributeToServer(client, gridRemoteConnector.getDistributedGlobalIndex(i)) ; 2765 clientToClientConnectors.push_back(scalar->getClientToServerConnector(client)) ; 2766 } 2767 } 2768 2769 // compute the grid clientToServerConnector to send flux from client to servers 2770 clientToClientConnector_[client] = new CGridScattererConnector(clientToClientConnectors) ; 2298 2771 } 2299 2772 … … 2710 3183 CATCH_DUMP_ATTR 2711 3184 2712 /*! 2713 \brief Get the list of domain pointers 2714 \return list of domain pointers 2715 */ 2716 std::vector<CDomain*> CGrid::getDomains() 2717 TRY 2718 { 2719 std::vector<CDomain*> domList; 2720 if (!domList_.empty()) 2721 { 2722 for (int i = 0; i < domList_.size(); ++i) domList.push_back(CDomain::get(domList_[i])); 2723 } 2724 return domList; 2725 } 2726 CATCH_DUMP_ATTR 2727 2728 /*! 2729 \brief Get the list of axis pointers 2730 \return list of axis pointers 2731 */ 2732 std::vector<CAxis*> CGrid::getAxis() 2733 TRY 2734 { 2735 std::vector<CAxis*> aList; 2736 if (!axisList_.empty()) 2737 for (int i =0; i < axisList_.size(); ++i) aList.push_back(CAxis::get(axisList_[i])); 2738 2739 return aList; 2740 } 2741 CATCH_DUMP_ATTR 2742 2743 /*! 2744 \brief Get the list of axis pointers 2745 \return list of axis pointers 2746 */ 2747 std::vector<CScalar*> CGrid::getScalars() 2748 TRY 2749 { 2750 std::vector<CScalar*> sList; 2751 if (!scalarList_.empty()) 2752 for (int i =0; i < scalarList_.size(); ++i) sList.push_back(CScalar::get(scalarList_[i])); 2753 2754 return sList; 2755 } 2756 CATCH_DUMP_ATTR 2757 2758 /*! 2759 \brief Get domain pointer with index 2760 \return domain pointer 2761 */ 2762 CDomain* CGrid::getDomain(int domainIndex) 2763 TRY 2764 { 2765 std::vector<CDomain*> domainListP = this->getDomains(); 2766 if (domainListP.empty()) 2767 { 2768 ERROR("CGrid::getDomain(int domainIndex)", 2769 << "No domain associated to this grid. " << std::endl 2770 << "Grid id = " << this->getId()); 2771 } 2772 2773 if (domainIndex >= domainListP.size() || (domainIndex < 0)) 2774 ERROR("CGrid::getDomain(int domainIndex)", 2775 << "Domain with the index doesn't exist " << std::endl 2776 << "Grid id = " << this->getId() << std::endl 2777 << "Grid has only " << domainListP.size() << " domain but domain index required is " << domainIndex << std::endl); 2778 2779 return domainListP[domainIndex]; 2780 } 2781 CATCH_DUMP_ATTR 2782 2783 /*! 2784 \brief Get the axis pointer with index 2785 \return axis pointer 2786 */ 2787 CAxis* CGrid::getAxis(int axisIndex) 2788 TRY 2789 { 2790 std::vector<CAxis*> axisListP = this->getAxis(); 2791 if (axisListP.empty()) 2792 { 2793 ERROR("CGrid::getDomain(int axisIndex)", 2794 << "No axis associated to this grid. " << std::endl 2795 << "Grid id = " << this->getId()); 2796 } 2797 2798 if (axisIndex >= axisListP.size() || (axisIndex < 0)) 2799 ERROR("CGrid::getDomain(int axisIndex)", 2800 << "Domain with the index doesn't exist " << std::endl 2801 << "Grid id = " << this->getId() << std::endl 2802 << "Grid has only " << axisListP.size() << " axis but axis index required is " << axisIndex << std::endl); 2803 2804 return axisListP[axisIndex]; 2805 } 2806 CATCH_DUMP_ATTR 2807 2808 /*! 2809 \brief Get the a scalar pointer 2810 \return scalar pointer 2811 */ 2812 CScalar* CGrid::getScalar(int scalarIndex) 2813 TRY 2814 { 2815 std::vector<CScalar*> scalarListP = this->getScalars(); 2816 if (scalarListP.empty()) 2817 { 2818 ERROR("CGrid::getScalar(int scalarIndex)", 2819 << "No scalar associated to this grid. " << std::endl 2820 << "Grid id = " << this->getId()); 2821 } 2822 2823 if (scalarIndex >= scalarListP.size() || (scalarIndex < 0)) 2824 ERROR("CGrid::getScalar(int scalarIndex)", 2825 << "Scalar with the index doesn't exist " << std::endl 2826 << "Grid id = " << this->getId() << std::endl 2827 << "Grid has only " << scalarListP.size() << " scalar but scalar index required is " << scalarIndex << std::endl); 2828 2829 return scalarListP[scalarIndex]; 2830 } 2831 CATCH_DUMP_ATTR 2832 2833 /*! 2834 \brief Set domain(s) of a grid from a list 2835 \param[in] domains list of domains 2836 */ 2837 void CGrid::setDomainList(const std::vector<CDomain*> domains) 2838 TRY 2839 { 2840 if (isDomListSet) return; 2841 std::vector<CDomain*> domList = this->getVirtualDomainGroup()->getAllChildren(); 2842 if (!domains.empty() && domList.empty()) 2843 { 2844 for (int i = 0; i < domains.size(); ++i) 2845 this->getVirtualDomainGroup()->addChild(domains[i]); 2846 domList = this->getVirtualDomainGroup()->getAllChildren(); 2847 } 2848 2849 if (!domList.empty()) 2850 { 2851 int sizeDom = domList.size(); 2852 domList_.resize(sizeDom); 2853 for (int i = 0; i < sizeDom; ++i) 2854 { 2855 domList_[i] = domList[i]->getId(); 2856 } 2857 isDomListSet = true; 2858 } 2859 } 2860 CATCH_DUMP_ATTR 2861 2862 /*! 2863 \brief Set axis(s) of a grid from a list 2864 \param[in] axis list of axis 2865 */ 2866 void CGrid::setAxisList(const std::vector<CAxis*> axis) 2867 TRY 2868 { 2869 if (isAxisListSet) return; 2870 std::vector<CAxis*> aList = this->getVirtualAxisGroup()->getAllChildren(); 2871 if (!axis.empty() && aList.empty()) 2872 { 2873 for (int i = 0; i < axis.size(); ++i) 2874 this->getVirtualAxisGroup()->addChild(axis[i]); 2875 aList = this->getVirtualAxisGroup()->getAllChildren(); 2876 } 2877 2878 if (!aList.empty()) 2879 { 2880 int sizeAxis = aList.size(); 2881 axisList_.resize(sizeAxis); 2882 for (int i = 0; i < sizeAxis; ++i) 2883 { 2884 axisList_[i] = aList[i]->getId(); 2885 } 2886 isAxisListSet = true; 2887 } 2888 } 2889 CATCH_DUMP_ATTR 2890 2891 /*! 2892 \brief Set scalar(s) of a grid from a list 2893 \param[in] scalars list of scalars 2894 */ 2895 void CGrid::setScalarList(const std::vector<CScalar*> scalars) 2896 TRY 2897 { 2898 if (isScalarListSet) return; 2899 std::vector<CScalar*> sList = this->getVirtualScalarGroup()->getAllChildren(); 2900 if (!scalars.empty() && sList.empty()) 2901 { 2902 for (int i = 0; i < scalars.size(); ++i) 2903 this->getVirtualScalarGroup()->addChild(scalars[i]); 2904 sList = this->getVirtualScalarGroup()->getAllChildren(); 2905 } 2906 2907 if (!sList.empty()) 2908 { 2909 int sizeScalar = sList.size(); 2910 scalarList_.resize(sizeScalar); 2911 for (int i = 0; i < sizeScalar; ++i) 2912 { 2913 scalarList_[i] = sList[i]->getId(); 2914 } 2915 isScalarListSet = true; 2916 } 2917 } 2918 CATCH_DUMP_ATTR 2919 2920 /*! 2921 \brief Get list of id of domains 2922 \return id list of domains 2923 */ 2924 std::vector<StdString> CGrid::getDomainList() 2925 TRY 2926 { 2927 setDomainList(); 2928 return domList_; 2929 } 2930 CATCH 2931 2932 /*! 2933 \brief Get list of id of axis 2934 \return id list of axis 2935 */ 2936 std::vector<StdString> CGrid::getAxisList() 2937 TRY 2938 { 2939 setAxisList(); 2940 return axisList_; 2941 } 2942 CATCH 2943 2944 /*! 2945 \brief Get list of id of scalar 2946 \return id list of scalar 2947 */ 2948 std::vector<StdString> CGrid::getScalarList() 2949 TRY 2950 { 2951 setScalarList(); 2952 return scalarList_; 2953 } 2954 CATCH 3185 2955 3186 2956 3187 /*! … … 3014 3245 CATCH_DUMP_ATTR 3015 3246 3016 /*! 3017 Parse a grid, for now, it contains only domain, axis and scalar 3018 */ 3019 void CGrid::parse(xml::CXMLNode& node) 3020 TRY 3021 { 3022 SuperClass::parse(node); 3023 3024 if (node.goToChildElement()) 3025 { 3026 StdString domainName("domain"); 3027 StdString axisName("axis"); 3028 StdString scalarName("scalar"); 3029 do 3030 { 3031 if (node.getElementName() == domainName) { 3032 order_.push_back(2); 3033 this->getVirtualDomainGroup()->parseChild(node); 3034 } 3035 if (node.getElementName() == axisName) { 3036 order_.push_back(1); 3037 this->getVirtualAxisGroup()->parseChild(node); 3038 } 3039 if (node.getElementName() == scalarName) { 3040 order_.push_back(0); 3041 this->getVirtualScalarGroup()->parseChild(node); 3042 } 3043 } while (node.goToNextElement()); 3044 node.goToParentElement(); 3045 } 3046 3047 if (!order_.empty()) 3048 { 3049 int sizeOrd = order_.size(); 3050 axis_domain_order.resize(sizeOrd); 3051 for (int i = 0; i < sizeOrd; ++i) 3052 { 3053 axis_domain_order(i) = order_[i]; 3054 } 3055 } 3056 3057 setDomainList(); 3058 setAxisList(); 3059 setScalarList(); 3060 } 3061 CATCH_DUMP_ATTR 3062 3063 3247 3064 3248 void CGrid::computeGridLocalElements() 3065 3249 { … … 3097 3281 modelToWorkflowConnector_ = getGridLocalElements()->getConnector(CElementView::MODEL,CElementView::WORKFLOW) ; 3098 3282 } 3283 3284 void CGrid::computeWorkflowToFullConnector(void) 3285 { 3286 workflowToFullConnector_ = getGridLocalElements()->getConnector(CElementView::WORKFLOW,CElementView::FULL) ; 3287 } 3288 3289 void CGrid::computeWorkflowToModelConnector(void) 3290 { 3291 workflowToModelConnector_ = getGridLocalElements()->getConnector(CElementView::WORKFLOW,CElementView::MODEL) ; 3292 } 3293 3294 void CGrid::computeFullToWorkflowConnector(void) 3295 { 3296 fullToWorkflowConnector_ = getGridLocalElements()->getConnector(CElementView::FULL,CElementView::WORKFLOW) ; 3297 } 3298 3299 void CGrid::computeServerFromClientConnector(void) 3300 { 3301 vector<CGathererConnector*> connectors ; 3302 for(auto& element : getElements()) 3303 { 3304 if (element.type==TYPE_DOMAIN) connectors.push_back(element.domain->getServerFromClientConnector()) ; 3305 else if (element.type==TYPE_AXIS) connectors.push_back(element.axis->getServerFromClientConnector()) ; 3306 else if (element.type==TYPE_SCALAR) connectors.push_back(element.scalar->getServerFromClientConnector()) ; 3307 } 3308 serverFromClientConnector_ = new CGridGathererConnector(connectors) ; 3309 } 3310 3311 void CGrid::computeClientFromClientConnector(void) 3312 { 3313 vector<CGathererConnector*> connectors ; 3314 for(auto& element : getElements()) 3315 { 3316 if (element.type==TYPE_DOMAIN) connectors.push_back(element.domain->getServerFromClientConnector()) ; 3317 else if (element.type==TYPE_AXIS) connectors.push_back(element.axis->getServerFromClientConnector()) ; 3318 else if (element.type==TYPE_SCALAR) connectors.push_back(element.scalar->getServerFromClientConnector()) ; 3319 } 3320 clientFromClientConnector_ = new CGridGathererConnector(connectors) ; 3321 } 3099 3322 } // namespace xios
Note: See TracChangeset
for help on using the changeset viewer.