forked from AMReX-Codes/amrex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAMReX_Mask.cpp
103 lines (86 loc) · 2.11 KB
/
AMReX_Mask.cpp
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
#include <AMReX_Mask.H>
#include <AMReX_Utility.H>
#include <cstdlib>
namespace amrex {
Mask::Mask () noexcept
: BaseFab<int>() {}
Mask::Mask (Arena* ar) noexcept
: BaseFab<int>(ar) {}
Mask::Mask (const Box& bx, int nc, Arena* ar)
: BaseFab<int>(bx,nc,ar) {}
Mask::Mask (const Box& bx, int nc, bool alloc, bool shared, Arena* ar)
: BaseFab<int>(bx,nc,alloc,shared,ar) {}
Mask::Mask (Mask const& rhs, MakeType make_type, int scomp, int ncomp)
:
BaseFab<int>(rhs,make_type,scomp,ncomp) {}
Mask::Mask (std::istream& is)
{
readFrom(is);
}
std::ostream&
operator<< (std::ostream& os,
const Mask& m)
{
int ncomp = m.nComp();
os << "(Mask: " << m.box() << " " << ncomp << "\n";
IntVect sm = m.box().smallEnd();
IntVect bg = m.box().bigEnd();
for (IntVect p = sm; p <= bg; m.box().next(p))
{
os << p;
for (int k = 0; k < ncomp; k++)
os << " " << m(p,k);
os << "\n";
}
os << ")\n";
BL_ASSERT(os.good());
return os;
}
std::istream&
operator>> (std::istream& is,
Mask& m)
{
is.ignore(BL_IGNORE_MAX,':');
Box b;
int ncomp;
is >> b >> ncomp;
is.ignore(BL_IGNORE_MAX, '\n');
m.resize(b,ncomp);
IntVect sm = b.smallEnd();
IntVect bg = b.bigEnd();
IntVect q;
for (IntVect p = sm; p <= bg; b.next(p))
{
is >> q;
BL_ASSERT( p == q);
for( int k=0; k<ncomp; k++ ) is >> m(p,k);
is.ignore(BL_IGNORE_MAX, '\n');
}
is.ignore(BL_IGNORE_MAX,'\n');
BL_ASSERT(is.good());
return is;
}
void
Mask::writeOn (std::ostream& os) const
{
os << "(Mask: " << domain << " " << nvar << "\n";
const int* ptr = dataPtr();
int len = domain.numPts();
os.write( (char*) ptr, len*sizeof(int) );
os << ")\n";
}
void
Mask::readFrom (std::istream& is)
{
is.ignore(BL_IGNORE_MAX,':');
Box b;
int ncomp;
is >> b >> ncomp;
is.ignore(BL_IGNORE_MAX, '\n');
resize(b,ncomp);
int *ptr = dataPtr();
int len = domain.numPts();
is.read( (char*) ptr, len*sizeof(int) );
is.ignore(BL_IGNORE_MAX, '\n');
}
}