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 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919
|
/*
** (c) 1996-2000 The Regents of the University of California (through
** E.O. Lawrence Berkeley National Laboratory), subject to approval by
** the U.S. Department of Energy. Your use of this software is under
** license -- the license agreement is attached and included in the
** directory as license.txt or you may contact Berkeley Lab's Technology
** Transfer Department at TTD@lbl.gov. NOTICE OF U.S. GOVERNMENT RIGHTS.
** The Software was developed under funding from the U.S. Government
** which consequently retains certain rights as follows: the
** U.S. Government has been granted for itself and others acting on its
** behalf a paid-up, nonexclusive, irrevocable, worldwide license in the
** Software to reproduce, prepare derivative works, and perform publicly
** and display publicly. Beginning five (5) years after the date
** permission to assert copyright is obtained from the U.S. Department of
** Energy, and subject to any subsequent five (5) year renewals, the
** U.S. Government is granted for itself and others acting on its behalf
** a paid-up, nonexclusive, irrevocable, worldwide license in the
** Software to reproduce, prepare derivative works, distribute copies to
** the public, perform publicly and display publicly, and to permit
** others to do so.
*/
//
// $Id: VisMF.cpp,v 1.92 2002/04/17 22:22:19 vince Exp $
//
#include <winstd.H>
#include <cstdio>
#include <fstream>
//
// This MUST be defined if don't have pubsetbuf() in I/O Streams Library.
//
#ifdef BL_USE_SETBUF
#define pubsetbuf setbuf
#endif
#include <ccse-mpi.H>
#include <Utility.H>
#include <VisMF.H>
const std::string VisMF::FabFileSuffix("_D_");
const std::string VisMF::MultiFabHdrFileSuffix("_H");
const std::string VisMF::FabOnDisk::Prefix("FabOnDisk:");
std::ostream&
operator<< (std::ostream& os,
const VisMF::FabOnDisk& fod)
{
os << VisMF::FabOnDisk::Prefix << ' ' << fod.m_name << ' ' << fod.m_head;
if (!os.good())
BoxLib::Error("Write of VisMF::FabOnDisk failed");
return os;
}
std::istream&
operator>> (std::istream& is,
VisMF::FabOnDisk& fod)
{
std::string str;
is >> str;
BL_ASSERT(str == VisMF::FabOnDisk::Prefix);
is >> fod.m_name;
is >> fod.m_head;
if (!is.good())
BoxLib::Error("Read of VisMF::FabOnDisk failed");
return is;
}
std::ostream&
operator<< (std::ostream& os,
const Array<VisMF::FabOnDisk>& fa)
{
long i = 0, N = fa.size();
os << N << '\n';
for ( ; i < N; i++)
{
os << fa[i] << '\n';
}
if (!os.good())
BoxLib::Error("Write of Array<VisMF::FabOnDisk> failed");
return os;
}
std::istream&
operator>> (std::istream& is,
Array<VisMF::FabOnDisk>& fa)
{
long i = 0, N;
is >> N;
BL_ASSERT(N >= 0);
fa.resize(N);
for ( ; i < N; i++)
{
is >> fa[i];
}
if (!is.good())
BoxLib::Error("Read of Array<VisMF::FabOnDisk> failed");
return is;
}
static
std::ostream&
operator<< (std::ostream& os,
const Array< Array<Real> >& ar)
{
long i = 0, N = ar.size(), M = (N == 0) ? 0 : ar[0].size();
os << N << ',' << M << '\n';
for ( ; i < N; i++)
{
BL_ASSERT(ar[i].size() == M);
for (long j = 0; j < M; j++)
{
os << ar[i][j] << ',';
}
os << '\n';
}
if (!os.good())
BoxLib::Error("Write of Array<Array<Real>> failed");
return os;
}
static
std::istream&
operator>> (std::istream& is,
Array< Array<Real> >& ar)
{
char ch;
long i = 0, N, M;
is >> N >> ch >> M;
BL_ASSERT(N >= 0);
BL_ASSERT(ch == ',');
BL_ASSERT(M >= 0);
ar.resize(N);
for ( ; i < N; i++)
{
ar[i].resize(M);
for (long j = 0; j < M; j++)
{
is >> ar[i][j] >> ch;
BL_ASSERT(ch == ',');
}
}
if (!is.good())
BoxLib::Error("Read of Array<Array<Real>> failed");
return is;
}
std::ostream&
operator<< (std::ostream& os,
const VisMF::Header& hd)
{
//
// Up the precision for the Reals in m_min and m_max.
//
int old_prec = os.precision(15);
os << hd.m_vers << '\n';
os << int(hd.m_how) << '\n';
os << hd.m_ncomp << '\n';
os << hd.m_ngrow << '\n';
hd.m_ba.writeOn(os); os << '\n';
os << hd.m_fod << '\n';
os << hd.m_min << '\n';
os << hd.m_max << '\n';
os.precision(old_prec);
if (!os.good())
BoxLib::Error("Write of VisMF::Header failed");
return os;
}
std::istream&
operator>> (std::istream& is,
VisMF::Header& hd)
{
is >> hd.m_vers;
BL_ASSERT(hd.m_vers == VisMF::Header::Version);
int how;
is >> how;
switch (how)
{
case VisMF::OneFilePerCPU:
hd.m_how = VisMF::OneFilePerCPU; break;
default:
BoxLib::Error("Bad case in switch");
}
is >> hd.m_ncomp;
BL_ASSERT(hd.m_ncomp >= 0);
is >> hd.m_ngrow;
BL_ASSERT(hd.m_ngrow >= 0);
hd.m_ba.readFrom(is);
is >> hd.m_fod;
BL_ASSERT(hd.m_ba.size() == hd.m_fod.size());
is >> hd.m_min;
is >> hd.m_max;
BL_ASSERT(hd.m_ba.size() == hd.m_min.size());
BL_ASSERT(hd.m_ba.size() == hd.m_max.size());
if (!is.good())
BoxLib::Error("Read of VisMF::Header failed");
return is;
}
VisMF::FabOnDisk::FabOnDisk () {}
VisMF::FabOnDisk::FabOnDisk (const std::string& name, long offset)
:
m_name(name),
m_head(offset)
{}
int
VisMF::nComp () const
{
return m_hdr.m_ncomp;
}
int
VisMF::nGrow () const
{
return m_hdr.m_ngrow;
}
int
VisMF::size () const
{
return m_hdr.m_ba.size();
}
const BoxArray&
VisMF::boxArray () const
{
return m_hdr.m_ba;
}
Real
VisMF::min (int fabIndex,
int nComp) const
{
BL_ASSERT(0 <= fabIndex && fabIndex < m_hdr.m_ba.size());
BL_ASSERT(0 <= nComp && nComp < m_hdr.m_ncomp);
return m_hdr.m_min[fabIndex][nComp];
}
Real
VisMF::max (int fabIndex,
int nComp) const
{
BL_ASSERT(0 <= fabIndex && fabIndex < m_hdr.m_ba.size());
BL_ASSERT(0 <= nComp && nComp < m_hdr.m_ncomp);
return m_hdr.m_max[fabIndex][nComp];
}
const FArrayBox&
VisMF::GetFab (int fabIndex,
int ncomp) const
{
if (m_pa[ncomp][fabIndex] == 0)
{
m_pa[ncomp][fabIndex] = VisMF::readFAB(fabIndex,m_mfname,m_hdr,ncomp);
}
return *m_pa[ncomp][fabIndex];
}
void
VisMF::clear (int fabIndex,
int compIndex)
{
delete m_pa[compIndex][fabIndex];
}
long
VisMF::FileOffset (std::ostream& os)
{
return
#if defined(__KCC)
#if ((BL_KCC_MAJOR_VERSION >= 4) || (BL_KCC_MAJOR_VERSION == 3 && BL_KCC_MINOR_VERSION > 3) || (BL_KCC_MAJOR_VERSION == 0))
os.tellp();
#else
os.tellp().offset();
#endif
#else
os.tellp();
#endif
}
FArrayBox*
VisMF::readFAB (int idx,
const std::string& mf_name)
{
return VisMF::readFAB(idx,mf_name,m_hdr,-1);
}
FArrayBox*
VisMF::readFAB (int idx,
int ncomp)
{
return VisMF::readFAB(idx,m_mfname,m_hdr,ncomp);
}
std::string
VisMF::BaseName (const std::string& filename)
{
BL_ASSERT(filename[filename.length() - 1] != '/');
if (const char* slash = strrchr(filename.c_str(), '/'))
{
//
// Got at least one slash -- give'm the following tail.
//
return std::string(slash + 1);
}
else
{
//
// No leading directory portion to name.
//
return filename;
}
}
std::string
VisMF::DirName (const std::string& filename)
{
BL_ASSERT(filename[filename.length() - 1] != '/');
static const std::string TheNullString("");
const char* str = filename.c_str();
if (const char* slash = strrchr(str, '/'))
{
//
// Got at least one slash -- give'm the dirname including last slash.
//
int len = (slash - str) + 1;
char* buf = new char[len+1];
strncpy(buf, str, len);
buf[len] = 0; // Stringify
std::string dirname = buf;
delete [] buf;
return dirname;
}
else
{
//
// No directory name here.
//
return TheNullString;
}
}
VisMF::FabOnDisk
VisMF::Write (const FArrayBox& fab,
const std::string& filename,
std::ostream& os,
long& bytes)
{
VisMF::FabOnDisk fab_on_disk(filename, VisMF::FileOffset(os));
fab.writeOn(os);
//
// Add in the number of bytes in the FAB including the FAB header.
//
bytes += (VisMF::FileOffset(os) - fab_on_disk.m_head);
return fab_on_disk;
}
//
// This does not build a valid header.
//
VisMF::Header::Header ()
:
m_vers(0)
{}
//
// The more-or-less complete header only exists at IOProcessor().
//
VisMF::Header::Header (const MultiFab& mf,
VisMF::How how)
:
m_vers(VisMF::Header::Version),
m_how(how),
m_ncomp(mf.nComp()),
m_ngrow(mf.nGrow()),
m_ba(mf.boxArray()),
m_fod(m_ba.size()),
m_min(m_ba.size()),
m_max(m_ba.size())
{
#ifdef BL_USE_MPI
//
// Note that m_min and m_max are only calculated on CPU owning the fab.
// We pass this data back to IOProcessor() so it sees the whole Header.
//
const int SeqNo = ParallelDescriptor::SeqNum();
const int NProcs = ParallelDescriptor::NProcs();
const int IOProc = ParallelDescriptor::IOProcessorNumber();
int nFabs = 0;
for (MFIter mfi(mf); mfi.isValid(); ++mfi)
{
nFabs++;
const int idx = mfi.index();
m_min[idx].resize(m_ncomp);
m_max[idx].resize(m_ncomp);
BL_ASSERT(mf[mfi].box().contains(m_ba[idx]));
for (long j = 0; j < m_ncomp; j++)
{
m_min[idx][j] = mf[mfi].min(m_ba[idx],j);
m_max[idx][j] = mf[mfi].max(m_ba[idx],j);
}
}
if (!ParallelDescriptor::IOProcessor())
{
if (nFabs)
{
Array<Real> senddata(2*m_ncomp*nFabs);
int offset = 0;
for (MFIter mfi(mf); mfi.isValid(); ++mfi)
{
const int idx = mfi.index();
for (int i = 0; i < m_ncomp; i++)
{
senddata[offset+i] = m_min[idx][i];
senddata[offset+m_ncomp+i] = m_max[idx][i];
}
offset += 2*m_ncomp;
}
BL_ASSERT(offset == 2*m_ncomp*nFabs);
BL_MPI_REQUIRE( MPI_Send(senddata.dataPtr(),
2*m_ncomp*nFabs,
ParallelDescriptor::Mpi_typemap<Real>::type(),
IOProc,
SeqNo,
ParallelDescriptor::Communicator()) );
BL_ASSERT(offset == 2*m_ncomp*nFabs);
}
}
else
{
const Array<int>& procmap = mf.DistributionMap().ProcessorMap();
Array<int> fabs(NProcs,0);
Array<int> indx(NProcs);
Array<MPI_Request> reqs(NProcs,MPI_REQUEST_NULL);
Array<MPI_Status> status(NProcs);
Array< Array<Real> > data(NProcs);
for (int i = 0, N = procmap.size(); i < N; i++)
fabs[procmap[i]]++;
fabs[IOProc] = 0;
int NWaits = 0;
for (int i = 0; i < NProcs; i++)
{
if (fabs[i])
{
NWaits++;
data[i].resize(2*m_ncomp*fabs[i]);
BL_MPI_REQUIRE( MPI_Irecv(data[i].dataPtr(),
2*m_ncomp*fabs[i],
ParallelDescriptor::Mpi_typemap<Real>::type(),
i,
SeqNo,
ParallelDescriptor::Communicator(),
&reqs[i]) );
}
}
for (int completed; NWaits > 0; NWaits -= completed)
{
BL_MPI_REQUIRE( MPI_Waitsome(NProcs,
reqs.dataPtr(),
&completed,
indx.dataPtr(),
status.dataPtr()) );
for (int k = 0; k < completed; k++)
{
int Ncpu = indx[k], offset = 0;
for (int idx = 0, N = procmap.size(); idx < N; idx++)
{
if (procmap[idx] == Ncpu)
{
m_min[idx].resize(m_ncomp);
m_max[idx].resize(m_ncomp);
for (int i = 0; i < m_ncomp; i++)
{
m_min[idx][i] = data[Ncpu][offset+i];
m_max[idx][i] = data[Ncpu][offset+m_ncomp+i];
}
offset += 2*m_ncomp;
}
}
BL_ASSERT(offset == 2*m_ncomp*fabs[Ncpu]);
}
}
}
#else
for (MFIter mfi(mf); mfi.isValid(); ++mfi)
{
const int idx = mfi.index();
m_min[idx].resize(m_ncomp);
m_max[idx].resize(m_ncomp);
BL_ASSERT(mf[mfi].box().contains(m_ba[idx]));
for (long j = 0; j < m_ncomp; j++)
{
m_min[idx][j] = mf[mfi].min(m_ba[idx],j);
m_max[idx][j] = mf[mfi].max(m_ba[idx],j);
}
}
#endif /*BL_USE_MPI*/
}
long
VisMF::WriteHeader (const std::string& mf_name,
VisMF::Header& hdr)
{
long bytes = 0;
//
// When running in parallel only one processor should do this I/O.
//
if (ParallelDescriptor::IOProcessor())
{
std::string MFHdrFileName = mf_name;
MFHdrFileName += VisMF::MultiFabHdrFileSuffix;
VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size);
std::ofstream MFHdrFile;
MFHdrFile.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
MFHdrFile.open(MFHdrFileName.c_str(), std::ios::out|std::ios::trunc);
if (!MFHdrFile.good())
BoxLib::FileOpenFailed(MFHdrFileName);
MFHdrFile << hdr;
//
// Add in the number of bytes written out in the Header.
//
bytes += VisMF::FileOffset(MFHdrFile);
}
return bytes;
}
long
VisMF::Write (const MultiFab& mf,
const std::string& mf_name,
VisMF::How how,
bool set_ghost)
{
BL_ASSERT(mf_name[mf_name.length() - 1] != '/');
const int MyProc = ParallelDescriptor::MyProc();
long bytes = 0;
VisMF::Header hdr(mf, how);
if (set_ghost)
{
MultiFab* the_mf = const_cast<MultiFab*>(&mf);
BL_ASSERT(!(the_mf == 0));
BL_ASSERT(hdr.m_ba == mf.boxArray());
BL_ASSERT(hdr.m_ncomp == mf.nComp());
for (MFIter mfi(*the_mf); mfi.isValid(); ++mfi)
{
const int idx = mfi.index();
for (int j = 0; j < hdr.m_ncomp; j++)
{
const Real val = (hdr.m_min[idx][j] + hdr.m_max[idx][j]) / 2;
the_mf->get(mfi).setComplement(val, hdr.m_ba[idx], j, 1);
}
}
}
char buf[sizeof(int) + 1];
VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size);
std::string FullFileName = mf_name;
FullFileName += VisMF::FabFileSuffix;
sprintf(buf, "%04d", MyProc);
FullFileName += buf;
std::ofstream FabFile;
FabFile.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
FabFile.open(FullFileName.c_str(), std::ios::out|std::ios::trunc|std::ios::binary);
if (!FabFile.good())
BoxLib::FileOpenFailed(FullFileName);
std::string basename = VisMF::BaseName(FullFileName);
for (MFIter mfi(mf); mfi.isValid(); ++mfi)
hdr.m_fod[mfi.index()] = VisMF::Write(mf[mfi],basename,FabFile,bytes);
#ifdef BL_USE_MPI
const int SeqNo = ParallelDescriptor::SeqNum();
const int NProcs = ParallelDescriptor::NProcs();
const int IOProc = ParallelDescriptor::IOProcessorNumber();
if (!ParallelDescriptor::IOProcessor())
{
int nFabs = 0, idx = 0;
for (MFIter mfi(mf); mfi.isValid(); ++mfi)
nFabs++;
if (nFabs)
{
Array<long> senddata(nFabs);
for (MFIter mfi(mf); mfi.isValid(); ++mfi)
senddata[idx++] = hdr.m_fod[mfi.index()].m_head;
BL_MPI_REQUIRE( MPI_Send(senddata.dataPtr(),
nFabs,
MPI_LONG,
IOProc,
SeqNo,
ParallelDescriptor::Communicator()));
}
BL_ASSERT(idx == nFabs);
}
else
{
const Array<int>& procmap = mf.DistributionMap().ProcessorMap();
Array<int> fabs(NProcs,0);
Array<int> indx(NProcs);
Array<MPI_Request> reqs(NProcs,MPI_REQUEST_NULL);
Array<MPI_Status> status(NProcs);
Array< Array<long> > data(NProcs);
for (int i = 0, N = procmap.size(); i < N; i++)
fabs[procmap[i]]++;
fabs[IOProc] = 0;
int NWaits = 0;
for (int i = 0; i < NProcs; i++)
{
if (fabs[i])
{
NWaits++;
data[i].resize(fabs[i]);
BL_MPI_REQUIRE( MPI_Irecv(data[i].dataPtr(),
fabs[i],
MPI_LONG,
i,
SeqNo,
ParallelDescriptor::Communicator(),
&reqs[i]));
}
}
for (int completed; NWaits > 0; NWaits -= completed)
{
BL_MPI_REQUIRE( MPI_Waitsome(NProcs,
reqs.dataPtr(),
&completed,
indx.dataPtr(),
status.dataPtr()));
for (int k = 0; k < completed; k++)
{
int Ncpu = indx[k], offset = 0;
for (int idx = 0, N = procmap.size(); idx < N; idx++)
{
if (procmap[idx] == Ncpu)
{
hdr.m_fod[idx].m_head = data[Ncpu][offset++];
std::string name = mf_name;
name += VisMF::FabFileSuffix;
sprintf(buf, "%04d", Ncpu);
name += buf;
hdr.m_fod[idx].m_name = VisMF::BaseName(name);
}
}
BL_ASSERT(offset == fabs[Ncpu]);
}
}
}
#endif /*BL_USE_MPI*/
if (VisMF::FileOffset(FabFile) <= 0)
BoxLib::UnlinkFile(FullFileName);
bytes += VisMF::WriteHeader(mf_name, hdr);
return bytes;
}
VisMF::VisMF (const std::string& mf_name)
:
m_mfname(mf_name)
{
std::string FullHdrFileName = m_mfname;
FullHdrFileName += VisMF::MultiFabHdrFileSuffix;
VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size);
std::ifstream ifs;
ifs.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
ifs.open(FullHdrFileName.c_str(), std::ios::in);
if (!ifs.good())
BoxLib::FileOpenFailed(FullHdrFileName);
ifs >> m_hdr;
m_pa.resize(m_hdr.m_ncomp);
for (int nComp = 0; nComp < m_pa.size(); ++nComp)
{
m_pa[nComp].resize(m_hdr.m_ba.size());
for (int ii = 0; ii < m_pa[nComp].size(); ++ii)
{
m_pa[nComp][ii] = 0;
}
}
}
FArrayBox*
VisMF::readFAB (int idx,
const std::string& mf_name,
const VisMF::Header& hdr,
int ncomp)
{
Box fab_box = hdr.m_ba[idx];
if (hdr.m_ngrow)
fab_box.grow(hdr.m_ngrow);
FArrayBox* fab = new FArrayBox(fab_box, ncomp == -1 ? hdr.m_ncomp : 1);
std::string FullFileName = VisMF::DirName(mf_name);
FullFileName += hdr.m_fod[idx].m_name;
VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size);
std::ifstream ifs;
ifs.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
ifs.open(FullFileName.c_str(), std::ios::in|std::ios::binary);
if (!ifs.good())
BoxLib::FileOpenFailed(FullFileName);
if (hdr.m_fod[idx].m_head)
ifs.seekg(hdr.m_fod[idx].m_head, std::ios::beg);
if (ncomp == -1)
{
fab->readFrom(ifs);
}
else
{
fab->readFrom(ifs, ncomp);
}
return fab;
}
void
VisMF::Read (MultiFab& mf,
const std::string& mf_name)
{
VisMF::Header hdr;
std::string FullHdrFileName = mf_name;
FullHdrFileName += VisMF::MultiFabHdrFileSuffix;
{
VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size);
std::ifstream ifs;
ifs.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
ifs.open(FullHdrFileName.c_str(), std::ios::in);
if (!ifs.good())
BoxLib::FileOpenFailed(FullHdrFileName);
ifs >> hdr;
}
mf.define(hdr.m_ba, hdr.m_ncomp, hdr.m_ngrow, Fab_noallocate);
for (MFIter mfi(mf); mfi.isValid(); ++mfi)
{
mf.setFab(mfi.index(), VisMF::readFAB(mfi.index(), mf_name, hdr));
}
BL_ASSERT(mf.ok());
}
void
VisMF::clear (int fabIndex)
{
for (int ncomp = 0; ncomp < m_pa.size(); ++ncomp)
{
clear(ncomp, fabIndex);
}
}
void
VisMF::clear ()
{
for (int ncomp = 0; ncomp < m_pa.size(); ++ncomp)
{
for (int fabIndex = 0; fabIndex < m_pa[ncomp].size(); ++fabIndex)
{
clear(ncomp, fabIndex);
}
}
}
|