/usr/include/palabos/multiBlock/multiDataField2D.hh is in libplb-dev 1.5~r1+repack1-2build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 | /* This file is part of the Palabos library.
*
* Copyright (C) 2011-2015 FlowKit Sarl
* Route d'Oron 2
* 1010 Lausanne, Switzerland
* E-mail contact: contact@flowkit.com
*
* The most recent release of Palabos can be downloaded at
* <http://www.palabos.org/>
*
* The library Palabos is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* The library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
* Scalar, vector and tensor fields for 2D data fields -- generic implementation.
*/
#ifndef MULTI_DATA_FIELD_2D_HH
#define MULTI_DATA_FIELD_2D_HH
#include "multiBlock/multiDataField2D.h"
#include "multiBlock/multiBlockManagement2D.h"
#include "multiBlock/defaultMultiBlockPolicy2D.h"
#include "multiBlock/nonLocalTransfer2D.h"
#include "multiBlock/multiBlockGenerator2D.h"
#include "core/plbTypenames.h"
#include "core/multiBlockIdentifiers2D.h"
#include <vector>
#include <algorithm>
#include <limits>
#include <sstream>
namespace plb {
/////// Class MultiScalarField2D //////////////////////////////////
template<typename T>
const int MultiScalarField2D<T>::staticId =
meta::registerMultiBlock2D ( MultiScalarField2D<T>::basicType(),
"NA",
MultiScalarField2D<T>::blockName(),
defaultGenerateMultiScalarField2D<T> );
template<typename T>
MultiScalarField2D<T>::MultiScalarField2D (
MultiBlockManagement2D const& multiBlockManagement_,
BlockCommunicator2D* blockCommunicator_,
CombinedStatistics* combinedStatistics_,
MultiScalarAccess2D<T>* multiScalarAccess_,
T iniVal )
: MultiBlock2D(multiBlockManagement_, blockCommunicator_, combinedStatistics_ ),
multiScalarAccess(multiScalarAccess_)
{
allocateFields(iniVal);
}
template<typename T>
MultiScalarField2D<T>::MultiScalarField2D(plint nx, plint ny, T iniVal)
// Envelope-width defaults to 1.
: MultiBlock2D(nx,ny,1),
multiScalarAccess(defaultMultiBlockPolicy2D().getMultiScalarAccess<T>())
{
allocateFields(iniVal);
}
template<typename T>
MultiScalarField2D<T>::~MultiScalarField2D() {
deAllocateFields();
delete multiScalarAccess;
}
template<typename T>
MultiScalarField2D<T>::MultiScalarField2D(MultiScalarField2D<T> const& rhs)
: ScalarFieldBase2D<T>(rhs),
MultiBlock2D(rhs),
multiScalarAccess(rhs.multiScalarAccess->clone())
{
allocateFields();
typename BlockMap::iterator it = fields.begin();
typename BlockMap::const_iterator rhsIt = rhs.fields.begin();
for (; it != fields.end(); ++it, ++rhsIt) {
*(it->second) = *(rhsIt->second);
}
}
template<typename T>
MultiScalarField2D<T>::MultiScalarField2D(MultiBlock2D const& rhs)
// Use MultiBlock's sub-domain constructor to avoid that the data-processors are copied
: MultiBlock2D(rhs, rhs.getBoundingBox(), false),
multiScalarAccess(defaultMultiBlockPolicy2D().getMultiScalarAccess<T>())
{
allocateFields();
}
template<typename T>
MultiScalarField2D<T>::MultiScalarField2D(MultiBlock2D const& rhs, Box2D subDomain, bool crop)
: MultiBlock2D(rhs, subDomain, crop),
multiScalarAccess(defaultMultiBlockPolicy2D().getMultiScalarAccess<T>())
{
allocateFields();
}
template<typename T>
MultiScalarField2D<T>& MultiScalarField2D<T>::operator=(MultiScalarField2D<T> const& rhs) {
MultiScalarField2D<T> tmp(rhs);
swap(tmp);
return *this;
}
template<typename T>
MultiScalarField2D<T>* MultiScalarField2D<T>::clone() const {
return new MultiScalarField2D<T>(*this);
}
template<typename T>
MultiScalarField2D<T>* MultiScalarField2D<T>::clone(MultiBlockManagement2D const& newManagement) const
{
MultiScalarField2D<T>* newField = new MultiScalarField2D<T> (
newManagement,
this->getBlockCommunicator().clone(),
this->getCombinedStatistics().clone(),
multiScalarAccess->clone(), T() );
copy(*this, this->getBoundingBox(), *newField, newField->getBoundingBox());
return newField;
}
template<typename T>
void MultiScalarField2D<T>::swap(MultiScalarField2D<T>& rhs) {
MultiBlock2D::swap(rhs);
fields.swap(rhs.fields);
std::swap(multiScalarAccess, rhs.multiScalarAccess);
}
template<typename T>
void MultiScalarField2D<T>::reset() {
for ( typename BlockMap::iterator it = fields.begin();
it != fields.end(); ++it)
{
it->second->reset();
}
}
template<typename T>
void MultiScalarField2D<T>::allocateFields(T iniVal)
{
for (pluint iBlock=0; iBlock<this->getLocalInfo().getBlocks().size(); ++iBlock) {
plint blockId = this->getLocalInfo().getBlocks()[iBlock];
SmartBulk2D bulk(this->getMultiBlockManagement(), blockId);
Box2D envelope = bulk.computeEnvelope();
ScalarField2D<T>* newField =
new ScalarField2D<T> (
envelope.getNx(), envelope.getNy(), iniVal );
newField -> setLocation(Dot2D(envelope.x0, envelope.y0));
fields[blockId] = newField;
}
}
template<typename T>
void MultiScalarField2D<T>::deAllocateFields()
{
for ( typename BlockMap::iterator it = fields.begin();
it != fields.end(); ++it)
{
delete it->second;
}
}
template<typename T>
inline T& MultiScalarField2D<T>::get(plint iX, plint iY) {
PLB_PRECONDITION(iX>=0 && iX<this->getNx());
PLB_PRECONDITION(iY>=0 && iY<this->getNy());
return multiScalarAccess->getDistributedScalar(iX,iY, this->getMultiBlockManagement(), fields);
}
template<typename T>
inline T const& MultiScalarField2D<T>::get(plint iX, plint iY) const {
PLB_PRECONDITION(iX>=0 && iX<this->getNx());
PLB_PRECONDITION(iY>=0 && iY<this->getNy());
return multiScalarAccess->getDistributedScalar(iX,iY, this->getMultiBlockManagement(), fields);
}
template<typename T>
ScalarField2D<T>& MultiScalarField2D<T>::getComponent(plint blockId) {
typename BlockMap::iterator it = fields.find(blockId);
PLB_ASSERT (it != fields.end());
return *it->second;
}
template<typename T>
ScalarField2D<T> const& MultiScalarField2D<T>::getComponent(plint blockId) const {
typename BlockMap::const_iterator it = fields.find(blockId);
PLB_ASSERT (it != fields.end());
return *it->second;
}
template<typename T>
plint MultiScalarField2D<T>::sizeOfCell() const {
return sizeof(T);
}
template<typename T>
plint MultiScalarField2D<T>::getCellDim() const {
return 1;
}
template<typename T>
int MultiScalarField2D<T>::getStaticId() const {
return staticId;
}
template<typename T>
void MultiScalarField2D<T>::copyReceive (
MultiBlock2D const& fromBlock, Box2D const& fromDomain,
Box2D const& toDomain, modif::ModifT whichData )
{
MultiScalarField2D<T> const* fromField =
dynamic_cast<MultiScalarField2D<T> const* >(&fromBlock);
PLB_ASSERT( fromField );
copy(*fromField, fromDomain, *this, toDomain);
}
template<typename T>
std::string MultiScalarField2D<T>::getBlockName() const {
return blockName();
}
template<typename T>
std::vector<std::string> MultiScalarField2D<T>::getTypeInfo() const {
std::vector<std::string> info;
info.push_back(basicType());
return info;
}
template<typename T>
std::string MultiScalarField2D<T>::blockName() {
return std::string("ScalarField2D");
}
template<typename T>
std::string MultiScalarField2D<T>::basicType() {
return NativeType<T>::getName();
}
template<typename T>
MultiScalarField2D<T>& findMultiScalarField2D(id_t id) {
MultiBlock2D* multiBlock = multiBlockRegistration2D().find(id);
if (!multiBlock || multiBlock->getStaticId() != MultiScalarField2D<T>::staticId) {
throw PlbLogicException("Trying to access a multi scalar field that is not registered.");
}
return (MultiScalarField2D<T>&)(*multiBlock);
}
//////// Class MultiTensorField2D //////////////////////////////////
template<typename T, int nDim>
const int MultiTensorField2D<T,nDim>::staticId =
meta::registerMultiBlock2D ( MultiTensorField2D<T,nDim>::basicType(),
"NA",
MultiTensorField2D<T,nDim>::blockName(),
defaultGenerateMultiTensorField2D<T,nDim> );
template<typename T, int nDim>
MultiTensorField2D<T,nDim>::MultiTensorField2D (
MultiBlockManagement2D const& multiBlockManagement_,
BlockCommunicator2D* blockCommunicator_,
CombinedStatistics* combinedStatistics_,
MultiTensorAccess2D<T,nDim>* multiTensorAccess_ )
: MultiBlock2D(multiBlockManagement_, blockCommunicator_, combinedStatistics_ ),
multiTensorAccess(multiTensorAccess_)
{
allocateFields();
}
template<typename T, int nDim>
MultiTensorField2D<T,nDim>::MultiTensorField2D (
MultiBlockManagement2D const& multiBlockManagement_,
BlockCommunicator2D* blockCommunicator_,
CombinedStatistics* combinedStatistics_,
MultiTensorAccess2D<T,nDim>* multiTensorAccess_,
Array<T,nDim> const& iniVal )
: MultiBlock2D(multiBlockManagement_, blockCommunicator_, combinedStatistics_ ),
multiTensorAccess(multiTensorAccess_)
{
allocateFields(iniVal);
}
template<typename T, int nDim>
MultiTensorField2D<T,nDim>::MultiTensorField2D(plint nx, plint ny)
// Envelope-width defaults to 1.
: MultiBlock2D(nx,ny,1),
multiTensorAccess(defaultMultiBlockPolicy2D().getMultiTensorAccess<T,nDim>())
{
allocateFields();
}
template<typename T, int nDim>
MultiTensorField2D<T,nDim>::MultiTensorField2D( plint nx, plint ny,
Array<T,nDim> const& iniVal )
// Envelope-width defaults to 1.
: MultiBlock2D(nx,ny,1),
multiTensorAccess(defaultMultiBlockPolicy2D().getMultiTensorAccess<T,nDim>())
{
allocateFields(iniVal);
}
template<typename T, int nDim>
MultiTensorField2D<T,nDim>::~MultiTensorField2D() {
deAllocateFields();
delete multiTensorAccess;
}
template<typename T, int nDim>
MultiTensorField2D<T,nDim>::MultiTensorField2D(MultiTensorField2D<T,nDim> const& rhs)
: TensorFieldBase2D<T,nDim>(rhs),
MultiBlock2D(rhs),
multiTensorAccess(rhs.multiTensorAccess->clone())
{
allocateFields();
typename BlockMap::iterator it = fields.begin();
typename BlockMap::const_iterator rhsIt = rhs.fields.begin();
for (; it != fields.end(); ++it, ++rhsIt) {
*(it->second) = *(rhsIt->second);
}
}
template<typename T, int nDim>
MultiTensorField2D<T,nDim>::MultiTensorField2D(MultiBlock2D const& rhs)
// Use MultiBlock's sub-domain constructor to avoid that the data-processors are copied
: MultiBlock2D(rhs, rhs.getBoundingBox(), false),
multiTensorAccess(defaultMultiBlockPolicy2D().getMultiTensorAccess<T,nDim>())
{
allocateFields();
}
template<typename T, int nDim>
MultiTensorField2D<T,nDim>::MultiTensorField2D(MultiBlock2D const& rhs, Box2D subDomain, bool crop)
: MultiBlock2D(rhs, subDomain, crop),
multiTensorAccess(defaultMultiBlockPolicy2D().getMultiTensorAccess<T,nDim>())
{
allocateFields();
}
template<typename T, int nDim>
MultiTensorField2D<T,nDim>& MultiTensorField2D<T,nDim>::operator=(MultiTensorField2D<T,nDim> const& rhs) {
MultiTensorField2D<T,nDim> tmp(rhs);
swap(tmp);
return *this;
}
template<typename T, int nDim>
MultiTensorField2D<T,nDim>* MultiTensorField2D<T,nDim>::clone() const {
return new MultiTensorField2D<T,nDim>(*this);
}
template<typename T, int nDim>
MultiTensorField2D<T,nDim>* MultiTensorField2D<T,nDim>::clone(MultiBlockManagement2D const& newManagement) const
{
Array<T,nDim> iniVal; iniVal.resetToZero();
MultiTensorField2D<T,nDim>* newField = new MultiTensorField2D<T,nDim> (
newManagement,
this->getBlockCommunicator().clone(),
this->getCombinedStatistics().clone(),
multiTensorAccess->clone(), iniVal );
copy(*this, this->getBoundingBox(), *newField, newField->getBoundingBox());
return newField;
}
template<typename T, int nDim>
void MultiTensorField2D<T,nDim>::swap(MultiTensorField2D<T,nDim>& rhs) {
MultiBlock2D::swap(rhs);
fields.swap(rhs.fields);
std::swap(multiTensorAccess, rhs.multiTensorAccess);
}
template<typename T, int nDim>
void MultiTensorField2D<T,nDim>::reset() {
for ( typename BlockMap::iterator it = fields.begin();
it != fields.end(); ++it)
{
it->second -> reset();
}
}
template<typename T, int nDim>
void MultiTensorField2D<T,nDim>::allocateFields()
{
Array<T,nDim> iniVal;
iniVal.resetToZero();
allocateFields(iniVal);
}
template<typename T, int nDim>
void MultiTensorField2D<T,nDim>::allocateFields(Array<T,nDim> const& iniVal)
{
for (pluint iBlock=0; iBlock<this->getLocalInfo().getBlocks().size(); ++iBlock) {
plint blockId = this->getLocalInfo().getBlocks()[iBlock];
SmartBulk2D bulk(this->getMultiBlockManagement(), blockId);
Box2D envelope = bulk.computeEnvelope();
TensorField2D<T,nDim>* newField =
new TensorField2D<T,nDim> (
envelope.getNx(), envelope.getNy(), iniVal );
newField -> setLocation(Dot2D(envelope.x0, envelope.y0));
fields[blockId] = newField;
}
}
template<typename T, int nDim>
void MultiTensorField2D<T,nDim>::deAllocateFields()
{
for ( typename BlockMap::iterator it = fields.begin();
it != fields.end(); ++it)
{
delete it->second;
}
}
template<typename T, int nDim>
inline Array<T,nDim>&
MultiTensorField2D<T,nDim>::get(plint iX, plint iY) {
PLB_PRECONDITION(iX>=0 && iX<this->getNx());
PLB_PRECONDITION(iY>=0 && iY<this->getNy());
return multiTensorAccess->getDistributedTensor(iX,iY, this->getMultiBlockManagement(), fields);
}
template<typename T, int nDim>
inline Array<T,nDim> const&
MultiTensorField2D<T,nDim>::get(plint iX, plint iY) const {
PLB_PRECONDITION(iX>=0 && iX<this->getNx());
PLB_PRECONDITION(iY>=0 && iY<this->getNy());
return multiTensorAccess->getDistributedTensor(iX,iY, this->getMultiBlockManagement(), fields);
}
template<typename T, int nDim>
TensorField2D<T,nDim>& MultiTensorField2D<T,nDim>::getComponent(plint blockId) {
typename BlockMap::iterator it = fields.find(blockId);
PLB_ASSERT (it != fields.end());
return *it->second;
}
template<typename T, int nDim>
TensorField2D<T,nDim> const& MultiTensorField2D<T,nDim>::getComponent(plint blockId) const {
typename BlockMap::const_iterator it = fields.find(blockId);
PLB_ASSERT (it != fields.end());
return *it->second;
}
template<typename T, int nDim>
plint MultiTensorField2D<T,nDim>::sizeOfCell() const {
return nDim*sizeof(T);
}
template<typename T, int nDim>
plint MultiTensorField2D<T,nDim>::getCellDim() const {
return nDim;
}
template<typename T, int nDim>
int MultiTensorField2D<T,nDim>::getStaticId() const {
return staticId;
}
template<typename T, int nDim>
void MultiTensorField2D<T,nDim>::copyReceive (
MultiBlock2D const& fromBlock, Box2D const& fromDomain,
Box2D const& toDomain, modif::ModifT whichData )
{
MultiTensorField2D<T,nDim> const* fromField =
dynamic_cast<MultiTensorField2D<T,nDim> const* >(&fromBlock);
PLB_ASSERT( fromField );
copy(*fromField, fromDomain, *this, toDomain);
}
template<typename T, int nDim>
std::string MultiTensorField2D<T,nDim>::getBlockName() const {
return blockName();
}
template<typename T, int nDim>
std::vector<std::string> MultiTensorField2D<T,nDim>::getTypeInfo() const {
std::vector<std::string> info;
info.push_back(basicType());
return info;
}
template<typename T, int nDim>
std::string MultiTensorField2D<T,nDim>::blockName() {
return std::string("TensorField2D");
}
template<typename T, int nDim>
std::string MultiTensorField2D<T,nDim>::basicType() {
return NativeType<T>::getName();
}
template<typename T, int nDim>
MultiTensorField2D<T,nDim>& findMultiTensorField2D(id_t id) {
MultiBlock2D* multiBlock = multiBlockRegistration2D().find(id);
if (!multiBlock || multiBlock->getStaticId() != MultiTensorField2D<T,nDim>::staticId) {
throw PlbLogicException("Trying to access a multi scalar field that is not registered.");
}
return (MultiTensorField2D<T,nDim>&)(*multiBlock);
}
//////// Class MultiNTensorField2D //////////////////////////////////
template<typename T>
const int MultiNTensorField2D<T>::staticId =
meta::registerMultiBlock2D ( MultiNTensorField2D<T>::basicType(),
"NA",
MultiNTensorField2D<T>::blockName(),
defaultGenerateMultiNTensorField2D<T> );
template<typename T>
MultiNTensorField2D<T>::MultiNTensorField2D (
plint ndim,
MultiBlockManagement2D const& multiBlockManagement_,
BlockCommunicator2D* blockCommunicator_,
CombinedStatistics* combinedStatistics_,
MultiNTensorAccess2D<T>* multiNTensorAccess_ )
: NTensorFieldBase2D<T>(ndim),
MultiBlock2D(multiBlockManagement_, blockCommunicator_, combinedStatistics_ ),
multiNTensorAccess(multiNTensorAccess_)
{
allocateFields();
}
template<typename T>
MultiNTensorField2D<T>::MultiNTensorField2D (
plint ndim, T const* iniVal,
MultiBlockManagement2D const& multiBlockManagement_,
BlockCommunicator2D* blockCommunicator_,
CombinedStatistics* combinedStatistics_,
MultiNTensorAccess2D<T>* multiNTensorAccess_ )
: NTensorFieldBase2D<T>(ndim),
MultiBlock2D(multiBlockManagement_, blockCommunicator_, combinedStatistics_ ),
multiNTensorAccess(multiNTensorAccess_)
{
allocateFields(iniVal);
}
template<typename T>
MultiNTensorField2D<T>::MultiNTensorField2D(plint nx, plint ny, plint ndim)
: NTensorFieldBase2D<T>(ndim),
// Envelope-width defaults to 1.
MultiBlock2D(nx,ny,1),
multiNTensorAccess(defaultMultiBlockPolicy2D().getMultiNTensorAccess<T>())
{
allocateFields();
}
template<typename T>
MultiNTensorField2D<T>::MultiNTensorField2D(plint nx, plint ny, plint ndim, T const* iniVal)
: NTensorFieldBase2D<T>(ndim),
// Envelope-width defaults to 1.
MultiBlock2D(nx,ny,1),
multiNTensorAccess(defaultMultiBlockPolicy2D().getMultiNTensorAccess<T>())
{
allocateFields(iniVal);
}
template<typename T>
MultiNTensorField2D<T>::~MultiNTensorField2D() {
deAllocateFields();
delete multiNTensorAccess;
}
template<typename T>
MultiNTensorField2D<T>::MultiNTensorField2D(MultiNTensorField2D<T> const& rhs)
: NTensorFieldBase2D<T>(rhs),
// Use MultiBlock's sub-domain constructor to avoid that the data-processors are copied
MultiBlock2D(rhs, rhs.getBoundingBox(), false),
multiNTensorAccess(rhs.multiNTensorAccess->clone())
{
allocateFields();
typename BlockMap::iterator it = fields.begin();
typename BlockMap::const_iterator rhsIt = rhs.fields.begin();
for (; it != fields.end(); ++it, ++rhsIt) {
*(it->second) = *(rhsIt->second);
}
}
template<typename T>
MultiNTensorField2D<T>::MultiNTensorField2D(plint ndim, MultiBlock2D const& rhs)
: NTensorFieldBase2D<T>(ndim),
MultiBlock2D(rhs),
multiNTensorAccess(defaultMultiBlockPolicy2D().getMultiNTensorAccess<T>())
{
allocateFields();
}
template<typename T>
MultiNTensorField2D<T>::MultiNTensorField2D(plint ndim, MultiBlock2D const& rhs, Box2D subDomain, bool crop)
: NTensorFieldBase2D<T>(ndim),
MultiBlock2D(rhs, subDomain, crop),
multiNTensorAccess(defaultMultiBlockPolicy2D().getMultiNTensorAccess<T>())
{
allocateFields();
}
template<typename T>
MultiNTensorField2D<T>& MultiNTensorField2D<T>::operator=(MultiNTensorField2D<T> const& rhs) {
MultiNTensorField2D<T> tmp(rhs);
swap(tmp);
return *this;
}
template<typename T>
MultiNTensorField2D<T>* MultiNTensorField2D<T>::clone() const {
return new MultiNTensorField2D<T>(*this);
}
template<typename T>
MultiNTensorField2D<T>* MultiNTensorField2D<T>::clone(MultiBlockManagement2D const& newManagement) const
{
MultiNTensorField2D<T>* newField = new MultiNTensorField2D<T> (
this->getNdim(),
newManagement,
this->getBlockCommunicator().clone(),
this->getCombinedStatistics().clone(),
multiNTensorAccess->clone() );
copy(*this, this->getBoundingBox(), *newField, newField->getBoundingBox());
return newField;
}
template<typename T>
void MultiNTensorField2D<T>::swap(MultiNTensorField2D<T>& rhs) {
NTensorFieldBase2D<T>::swap(rhs);
MultiBlock2D::swap(rhs);
fields.swap(rhs.fields);
std::swap(multiNTensorAccess, rhs.multiNTensorAccess);
}
template<typename T>
void MultiNTensorField2D<T>::reset() {
for ( typename BlockMap::iterator it = fields.begin();
it != fields.end(); ++it)
{
it->second->reset();
}
}
template<typename T>
void MultiNTensorField2D<T>::allocateFields() {
std::vector<T> iniVal(this->getNdim());
std::fill(iniVal.begin(), iniVal.end(), T());
allocateFields(&iniVal[0]);
}
template<typename T>
void MultiNTensorField2D<T>::allocateFields(T const* iniVal)
{
for (pluint iBlock=0; iBlock<this->getLocalInfo().getBlocks().size(); ++iBlock) {
plint blockId = this->getLocalInfo().getBlocks()[iBlock];
SmartBulk2D bulk(this->getMultiBlockManagement(), blockId );
Box2D envelope = bulk.computeEnvelope();
NTensorField2D<T>* newField =
new NTensorField2D<T> (
envelope.getNx(), envelope.getNy(), this->getNdim(), iniVal );
newField -> setLocation(Dot2D(envelope.x0, envelope.y0));
fields[blockId] = newField;
}
}
template<typename T>
void MultiNTensorField2D<T>::deAllocateFields()
{
for ( typename BlockMap::iterator it = fields.begin();
it != fields.end(); ++it)
{
delete it->second;
}
}
template<typename T>
inline T*
MultiNTensorField2D<T>::get(plint iX, plint iY) {
PLB_PRECONDITION(iX>=0 && iX<this->getNx());
PLB_PRECONDITION(iY>=0 && iY<this->getNy());
return multiNTensorAccess->getDistributedNTensor(iX,iY, this->getMultiBlockManagement(), fields);
}
template<typename T>
inline T const*
MultiNTensorField2D<T>::get(plint iX, plint iY) const {
PLB_PRECONDITION(iX>=0 && iX<this->getNx());
PLB_PRECONDITION(iY>=0 && iY<this->getNy());
return multiNTensorAccess->getDistributedNTensor(iX,iY, this->getMultiBlockManagement(), fields);
}
template<typename T>
NTensorField2D<T>& MultiNTensorField2D<T>::getComponent(plint blockId) {
typename BlockMap::iterator it = fields.find(blockId);
PLB_ASSERT (it != fields.end());
return *it->second;
}
template<typename T>
NTensorField2D<T> const& MultiNTensorField2D<T>::getComponent(plint blockId) const {
typename BlockMap::const_iterator it = fields.find(blockId);
PLB_ASSERT (it != fields.end());
return *it->second;
}
template<typename T>
plint MultiNTensorField2D<T>::sizeOfCell() const {
return this->getNdim()*sizeof(T);
}
template<typename T>
plint MultiNTensorField2D<T>::getCellDim() const {
return this->getNdim();
}
template<typename T>
int MultiNTensorField2D<T>::getStaticId() const {
return staticId;
}
template<typename T>
void MultiNTensorField2D<T>::copyReceive (
MultiBlock2D const& fromBlock, Box2D const& fromDomain,
Box2D const& toDomain, modif::ModifT whichData )
{
MultiNTensorField2D<T> const* fromField =
dynamic_cast<MultiNTensorField2D<T> const* >(&fromBlock);
PLB_ASSERT( fromField );
copy(*fromField, fromDomain, *this, toDomain);
}
template<typename T>
std::string MultiNTensorField2D<T>::getBlockName() const {
return blockName();
}
template<typename T>
std::vector<std::string> MultiNTensorField2D<T>::getTypeInfo() const {
std::vector<std::string> info;
info.push_back(basicType());
return info;
}
template<typename T>
std::string MultiNTensorField2D<T>::blockName() {
return std::string("NTensorField2D");
}
template<typename T>
std::string MultiNTensorField2D<T>::basicType() {
return NativeType<T>::getName();
}
template<typename T>
MultiNTensorField2D<T>& findMultiNTensorField2D(id_t id) {
MultiBlock2D* multiBlock = multiBlockRegistration2D().find(id);
if (!multiBlock || multiBlock->getStaticId() != MultiNTensorField2D<T>::staticId) {
throw PlbLogicException("Trying to access a multi scalar field that is not registered.");
}
return (MultiNTensorField2D<T>&)(*multiBlock);
}
} // namespace plb
#endif // MULTI_DATA_FIELD_2D_HH
|