forked from BoxLib-Codes/BoxLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
89 lines (70 loc) · 2.24 KB
/
Copy pathmain.cpp
File metadata and controls
89 lines (70 loc) · 2.24 KB
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
#include <Geometry.H>
#include <PArray.H>
#include <MultiFab.H>
//***********************************************
// This can be moved into a C++ header file and #included here instead
#include <BLFort.H>
extern "C"
{
void work_on_data(Real* data, const int* ng, const int* nc,
const int* lo, const int* hi);
}
//***********************************************
void main_main ()
{
// define a box with bounds (0,0) to (15,15) in 2D
// or a box with bounds (0,0,0) to (15,15,15) in 3D
#if (BL_SPACEDIM == 2)
IntVect lo(0,0), hi(15,15);
#elif (BL_SPACEDIM == 3)
IntVect lo(0,0,0), hi(15,15,15);
#endif
Box bx(lo,hi);
BoxArray ba(bx); // ba has one 16^2 box
ba.maxSize(8); // ba now has four 8^2 boxes
// This stores the physical coordinates of the problem domain
RealBox real_box;
for (int n = 0; n < BL_SPACEDIM; n++)
{
real_box.setLo(n,-1.0);
real_box.setHi(n, 1.0);
}
// This says we are using Cartesian coordinates
int coord = 0;
// This says the domain is periodic in each direction
int is_per[BL_SPACEDIM];
for (int i = 0; i < BL_SPACEDIM; i++)
{
is_per[i] = 1;
}
// Define a Geometry object to store problem domain physical coordinates,
// incides, coordinate system, and periodicity
Geometry geom;
geom.define(bx, &real_box, coord, is_per);
// define a multifab with 2 components and 6 ghost cells
// We use the PArray class to help manage the memory
// (auto deallocation to prevent memory leaks)
int Ncomp = 2 , Nghost = 6;
// the "1" means only 1 MultiFab; you can declare more if needed
PArray <MultiFab> data(1,PArrayManage);
// build the "0th" MultiFab in the PArray
data.set(0, new MultiFab(ba, Ncomp, Nghost));
// MFIter is a "MultiFab Iterator" that loops over
// the grids in the MultiFab
for ( MFIter mfi(data[0]); mfi.isValid(); ++mfi)
{
// get the box associated with the current grid
const Box& bx = mfi.validbox();
work_on_data((data[0])[mfi].dataPtr(), &Nghost, &Ncomp,
bx.loVect(), bx.hiVect());
}
// fill periodic domain boundary and neighboring grid ghost cells
data[0].FillBoundary(geom.periodicity());
}
int main (int argc, char* argv[])
{
BoxLib::Initialize(argc,argv);
main_main();
BoxLib::Finalize();
return 0;
}