FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

avoid the use of old C arrays and use std::vector instead · idefix-code/idefix@9ba95b4 · GitHub

Repository navigation

Commit 9ba95b4

Browse files
committed
avoid the use of old C arrays and use std::vector instead
1 parent 3b8e491 commit 9ba95b4

13 files changed

Lines changed: 174 additions & 139 deletions

File tree

‎src/dataBlock/dataBlock.cpp‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ void DataBlock::InitFromGrid(Grid &grid, Input &input) {
2424
GridHost gridHost(grid);
2525
gridHost.SyncFromDevice();
2626

27+
nghost = std::vector<int>(3);
28+
np_int = std::vector<int>(3);
29+
np_tot = std::vector<int>(3);
30+
lbound = std::vector<BoundaryType>(3);
31+
rbound = std::vector<BoundaryType>(3);
32+
beg = std::vector<int>(3);
33+
end = std::vector<int>(3);
34+
gbeg = std::vector<int>(3);
35+
gend = std::vector<int>(3);
36+
37+
xbeg = std::vector<real>(3);
38+
xend = std::vector<real>(3);
39+
2740
// Get the number of points from the parent grid object
2841
for(int dir = 0 ; dir < 3 ; dir++) {
2942
nghost[dir] = grid.nghost[dir];
@@ -62,14 +75,14 @@ void DataBlock::InitFromGrid(Grid &grid, Input &input) {
6275

6376
// Allocate the required fields
6477
for(int dir = 0 ; dir < 3 ; dir++) {
65-
x[dir] = IdefixArray1D<real>("DataBlock_x",np_tot[dir]);
66-
xr[dir] = IdefixArray1D<real>("DataBlock_xr",np_tot[dir]);
67-
xl[dir] = IdefixArray1D<real>("DataBlock_xl",np_tot[dir]);
68-
dx[dir] = IdefixArray1D<real>("DataBlock_dx",np_tot[dir]);
69-
xgc[dir] = IdefixArray1D<real>("DataBlock_xgc",np_tot[dir]);
70-
71-
A[dir] = IdefixArray3D<real>("DataBlock_A",
72-
np_tot[KDIR]+KOFFSET, np_tot[JDIR]+JOFFSET, np_tot[IDIR]+IOFFSET);
78+
x.push_back(IdefixArray1D<real>("DataBlock_x",np_tot[dir]));
79+
xr.push_back(IdefixArray1D<real>("DataBlock_xr",np_tot[dir]));
80+
xl.push_back(IdefixArray1D<real>("DataBlock_xl",np_tot[dir]));
81+
dx.push_back(IdefixArray1D<real>("DataBlock_dx",np_tot[dir]));
82+
xgc.push_back(IdefixArray1D<real>("DataBlock_xgc",np_tot[dir]));
83+
84+
A.push_back(IdefixArray3D<real>("DataBlock_A",
85+
np_tot[KDIR]+KOFFSET, np_tot[JDIR]+JOFFSET, np_tot[IDIR]+IOFFSET));
7386
}
7487

7588
dV = IdefixArray3D<real>("DataBlock_dV",np_tot[KDIR],np_tot[JDIR],np_tot[IDIR]);

‎src/dataBlock/dataBlock.hpp‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
class DataBlock {
2424
public:
2525
// Local grid information
26-
IdefixArray1D<real> x[3]; ///< geometrical central points
27-
IdefixArray1D<real> xr[3]; ///< cell right interface
28-
IdefixArray1D<real> xl[3]; ///< cell left interface
29-
IdefixArray1D<real> dx[3]; ///< cell width
30-
IdefixArray1D<real> xgc[3]; ///< cell geometrical cell center
26+
std::vector<IdefixArray1D<real>> x; ///< geometrical central points
27+
std::vector<IdefixArray1D<real>> xr; ///< cell right interface
28+
std::vector<IdefixArray1D<real>> xl; ///< cell left interface
29+
std::vector<IdefixArray1D<real>> dx; ///< cell width
30+
std::vector<IdefixArray1D<real>> xgc; ///< cell geometrical cell center
3131
IdefixArray1D<real> rt; ///< In spherical coordinates, gives $\tilde{r}$
3232
IdefixArray1D<real> sinx2m; ///< In spherical coordinates,
3333
///< gives sin(th) at a j-1/2 interface
@@ -38,27 +38,27 @@ class DataBlock {
3838
IdefixArray1D<real> dmu; ///< In spherical coordinates,
3939
///< gives the $\theta$ volume = fabs(cos(th_m) - cos(th_p))
4040

41-
real xbeg[3]; ///< Beginning of active domain in datablock
42-
real xend[3]; ///< End of active domain in datablock
41+
std::vector<real> xbeg; ///< Beginning of active domain in datablock
42+
std::vector<real> xend; ///< End of active domain in datablock
4343

44-
IdefixArray3D<real> dV; ///< cell volume
45-
IdefixArray3D<real> A[3]; ///< cell right interface area
44+
IdefixArray3D<real> dV; ///< cell volume
45+
std::vector<IdefixArray3D<real>> A; ///< cell right interface area
4646

47-
int np_tot[3]; ///< total number of grid points in datablock
48-
int np_int[3]; ///< active number of grid points in datablock (excl. ghost cells)
47+
std::vector<int> np_tot; ///< total number of grid points in datablock
48+
std::vector<int> np_int; ///< active number of grid points in datablock (excl. ghost cells)
4949

50-
int nghost[3]; ///< number of ghost cells at each boundary
51-
BoundaryType lbound[3]; ///< Boundary condition to the left
52-
BoundaryType rbound[3]; ///< Boundary condition to the right
50+
std::vector<int> nghost; ///< number of ghost cells at each boundary
51+
std::vector<BoundaryType> lbound; ///< Boundary condition to the left
52+
std::vector<BoundaryType> rbound; ///< Boundary condition to the right
5353

54-
bool haveAxis = false; ///< DataBlock contains points on the axis and a special treatment
55-
///< has been required for these.
54+
bool haveAxis{false}; ///< DataBlock contains points on the axis and a special treatment
55+
///< has been required for these.
5656

57-
int beg[3]; ///< First local index of the active domain
58-
int end[3]; ///< Last local index of the active domain+1
57+
std::vector<int> beg; ///< First local index of the active domain
58+
std::vector<int> end; ///< Last local index of the active domain+1
5959

60-
int gbeg[3]; ///< First global index of the active domain of this datablock
61-
int gend[3]; ///< Last global index of the active domain of this datablock
60+
std::vector<int> gbeg; ///< First global index of the active domain of this datablock
61+
std::vector<int> gend; ///< Last global index of the active domain of this datablock
6262

6363
real dt; ///< Current timestep
6464
real t; ///< Current time

‎src/dataBlock/dataBlockHost.cpp‎

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,27 @@ DataBlockHost::DataBlockHost(DataBlock& datain) {
2323

2424
// Create mirrors (should be mirror_view)
2525
for(int dir = 0 ; dir < 3 ; dir++) {
26-
x[dir] = Kokkos::create_mirror_view(data->x[dir]);
27-
xr[dir] = Kokkos::create_mirror_view(data->xr[dir]);
28-
xl[dir] = Kokkos::create_mirror_view(data->xl[dir]);
29-
dx[dir] = Kokkos::create_mirror_view(data->dx[dir]);
30-
A[dir] = Kokkos::create_mirror_view(data->A[dir]);
31-
np_tot[dir] = data->np_tot[dir];
32-
np_int[dir] = data->np_int[dir];
33-
nghost[dir] = data->nghost[dir];
34-
35-
xbeg[dir] = data->xbeg[dir];
36-
xend[dir] = data->xend[dir];
37-
beg[dir] = data->beg[dir];
38-
end[dir] = data->end[dir];
39-
gbeg[dir] = data->gbeg[dir];
40-
gend[dir] = data->gend[dir];
26+
x.push_back(Kokkos::create_mirror_view(data->x[dir]));
27+
xr.push_back(Kokkos::create_mirror_view(data->xr[dir]));
28+
xl.push_back(Kokkos::create_mirror_view(data->xl[dir]));
29+
dx.push_back(Kokkos::create_mirror_view(data->dx[dir]));
30+
A.push_back(Kokkos::create_mirror_view(data->A[dir]));
31+
}
32+
33+
np_tot = data->np_tot;
34+
np_int = data->np_int;
35+
np_tot = data->np_tot;
36+
37+
nghost = data->nghost;
38+
39+
xbeg = data->xbeg;
40+
xend = data->xend;
41+
beg = data->beg;
42+
end = data->end;
43+
gbeg = data->gbeg;
44+
gend = data->gend;
4145

4246
// TO BE COMPLETED...
43-
}
4447

4548
dV = Kokkos::create_mirror_view(data->dV);
4649
Vc = Kokkos::create_mirror_view(data->hydro.Vc);

‎src/dataBlock/dataBlockHost.hpp‎

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,44 @@
1414
class DataBlockHost {
1515
public:
1616
// Local grid information
17-
IdefixArray1D<real>::HostMirror x[3]; // geometrical central points
18-
IdefixArray1D<real>::HostMirror xr[3]; // cell right interface
19-
IdefixArray1D<real>::HostMirror xl[3]; // cell left interface
20-
IdefixArray1D<real>::HostMirror dx[3]; // cell width
17+
std::vector<IdefixArray1D<real>::HostMirror> x; ///> geometrical central points
18+
std::vector<IdefixArray1D<real>::HostMirror> xr; ///> cell right interface
19+
std::vector<IdefixArray1D<real>::HostMirror> xl; ///> cell left interface
20+
std::vector<IdefixArray1D<real>::HostMirror> dx; ///> cell width
2121

22-
IdefixArray3D<real>::HostMirror dV; // cell volume
23-
IdefixArray3D<real>::HostMirror A[3]; // cell right interface area
22+
IdefixArray3D<real>::HostMirror dV; ///> cell volume
23+
std::vector<IdefixArray3D<real>::HostMirror> A; ///> cell right interface area
2424

25-
IdefixArray4D<real>::HostMirror Vc; // Main cell-centered primitive variables index
25+
IdefixArray4D<real>::HostMirror Vc; ///> Main cell-centered primitive variables index
2626
#if MHD == YES
27-
IdefixArray4D<real>::HostMirror Vs; // Main face-centered primitive variables index
28-
IdefixArray4D<real>::HostMirror Ve; // Main edge-centered primitive variables index
29-
IdefixArray4D<real>::HostMirror J; // Current (only when haveCurrent is enabled)
27+
IdefixArray4D<real>::HostMirror Vs; ///> Main face-centered primitive variables index
28+
IdefixArray4D<real>::HostMirror Ve; ///> Main edge-centered primitive variables index
29+
IdefixArray4D<real>::HostMirror J; ///> Current (only when haveCurrent is enabled)
3030
#endif
31-
IdefixArray4D<real>::HostMirror Uc; // Main cell-centered conservative variables
31+
IdefixArray4D<real>::HostMirror Uc; ///> Main cell-centered conservative variables
3232
IdefixArray3D<real>::HostMirror InvDt;
3333

34-
IdefixArray3D<real>::HostMirror Ex1; // x1 electric field
35-
IdefixArray3D<real>::HostMirror Ex2; // x2 electric field
36-
IdefixArray3D<real>::HostMirror Ex3; // x3 electric field
34+
IdefixArray3D<real>::HostMirror Ex1; ///> x1 electric field
35+
IdefixArray3D<real>::HostMirror Ex2; ///> x2 electric field
36+
IdefixArray3D<real>::HostMirror Ex3; ///> x3 electric field
3737

3838

39-
real xbeg[3]; // Beginning of dataBlock
40-
real xend[3]; // End of dataBlock
39+
std::vector<real> xbeg; ///> Beginning of dataBlock
40+
std::vector<real> xend; ///> End of dataBlock
4141

42-
int np_tot[3]; // total number of grid points
43-
int np_int[3]; // internal number of grid points
42+
std::vector<int> np_tot; ///> total number of grid points
43+
std::vector<int> np_int; ///> internal number of grid points
4444

45-
int nghost[3]; // number of ghost cells
45+
std::vector<int> nghost; ///> number of ghost cells
4646

47-
BoundaryType lbound[3]; // Boundary condition to the left
48-
BoundaryType rbound[3]; // Boundary condition to the right
47+
std::vector<BoundaryType> lbound; ///> Boundary condition to the left
48+
std::vector<BoundaryType> rbound; ///> Boundary condition to the right
4949

50-
int beg[3]; // Begining of internal indices
51-
int end[3]; // End of internal indices
50+
std::vector<int> beg; ///> Begining of internal indices
51+
std::vector<int> end; ///> End of internal indices
5252

53-
int gbeg[3]; // Begining of local block in the grid (internal)
54-
int gend[3]; // End of local block in the grid (internal)
53+
std::vector<int> gbeg; ///> Begining of local block in the grid (internal)
54+
std::vector<int> gend; ///> End of local block in the grid (internal)
5555

5656
// Constructor
5757
explicit DataBlockHost(DataBlock &);

‎src/dataBlock/fargo.cpp‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,9 @@ void Fargo::Init(Input &input, DataBlock *data) {
133133
this->hydro = &(data->hydro);
134134

135135
// A bit of arithmetic to get the sizes of the working array
136-
for(int dir = 0 ; dir < 3 ; dir++) {
137-
this->nghost[dir] = data->nghost[dir];
138-
this->beg[dir] = data->beg[dir];
139-
this->end[dir] = data->end[dir];
140-
}
136+
this->nghost = data->nghost;
137+
this->beg = data->beg;
138+
this->end = data->end;
141139

142140
if(input.CheckBlock("Fargo")) {
143141
std::string opType = input.Get<std::string>("Fargo","velocity",0);
@@ -235,9 +233,9 @@ void Fargo::Init(Input &input, DataBlock *data) {
235233
vars.push_back(i);
236234
}
237235
#if MHD == YES
238-
this->mpi.Init(data->mygrid, vars, this->nghost, data->np_int, true);
236+
this->mpi.Init(data->mygrid, vars, this->nghost.data(), data->np_int.data(), true);
239237
#else
240-
this->mpi.Init(data->mygrid, vars, this->nghost, data->np_int);
238+
this->mpi.Init(data->mygrid, vars, this->nghost.data(), data->np_int.data());
241239
#endif
242240
}
243241
#endif

‎src/dataBlock/fargo.hpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ class Fargo {
4242
Mpi mpi; // Fargo-specific MPI layer
4343
#endif
4444

45-
int beg[3];
46-
int end[3];
47-
int nghost[3];
45+
std::vector<int> beg;
46+
std::vector<int> end;
47+
std::vector<int> nghost;
4848
int maxShift; //< maximum number of cells along which we plan to shift.
4949
real dtMax{0}; //< Maximum allowable dt for a given Fargo velocity
5050
//< when domain decomposition is enabled

‎src/grid.cpp‎

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ Grid::Grid() {
1818
Grid::Grid(Input &input) {
1919
idfx::pushRegion("Grid::Grid(Input)");
2020

21+
xbeg = std::vector<real>(3);
22+
xend = std::vector<real>(3);
23+
24+
nghost = std::vector<int>(3);
25+
2126
// Get grid size from input file, block [Grid]
2227
int npoints[3];
2328
for(int dir = 0 ; dir < 3 ; dir++) {
@@ -39,6 +44,10 @@ Grid::Grid(Input &input) {
3944
}
4045
}
4146

47+
np_tot = std::vector<int>(3);
48+
np_int = std::vector<int>(3);
49+
lbound = std::vector<BoundaryType>(3);
50+
rbound = std::vector<BoundaryType>(3);
4251

4352
for(int dir = 0 ; dir < 3 ; dir++) {
4453
np_tot[dir] = npoints[dir] + 2*nghost[dir];
@@ -99,7 +108,10 @@ Grid::Grid(Input &input) {
99108
}
100109

101110
// Allocate the grid structure on device. Initialisation will come from GridHost
102-
111+
x = std::vector<IdefixArray1D<real>>(3);
112+
xr = std::vector<IdefixArray1D<real>>(3);
113+
xl = std::vector<IdefixArray1D<real>>(3);
114+
dx = std::vector<IdefixArray1D<real>>(3);
103115
for(int dir = 0 ; dir < 3 ; dir++) {
104116
x[dir] = IdefixArray1D<real>("Grid_x",np_tot[dir]);
105117
xr[dir] = IdefixArray1D<real>("Grid_xr",np_tot[dir]);
@@ -108,6 +120,8 @@ Grid::Grid(Input &input) {
108120
}
109121

110122
// Allocate proc structure (by default: one proc in each direction, size one)
123+
nproc = std::vector<int> (3);
124+
xproc = std::vector<int> (3);
111125
for(int i=0 ; i < 3; i++) {
112126
nproc[i] = 1;
113127
xproc[i] = 0;
@@ -168,17 +182,11 @@ Grid::Grid(Input &input) {
168182
}
169183

170184
// Create cartesian communicator along with cartesian coordinates.
171-
MPI_Cart_create(MPI_COMM_WORLD, 3, nproc, period, 0, &CartComm);
172-
MPI_Cart_coords(CartComm, idfx::prank, 3, xproc);
185+
MPI_Cart_create(MPI_COMM_WORLD, 3, nproc.data(), period, 0, &CartComm);
186+
MPI_Cart_coords(CartComm, idfx::prank, 3, xproc.data());
173187

174188
MPI_Barrier(MPI_COMM_WORLD);
175-
idfx::cout << "Grid::Grid: Current MPI proc coordinates (";
176-
177-
for(int dir = 0; dir < 3; dir++) {
178-
idfx::cout << xproc[dir];
179-
if(dir < 2) idfx::cout << ", ";
180-
}
181-
idfx::cout << ")" << std::endl;
189+
182190

183191
if(haveAxis) {
184192
// create axis communicator to be able to exchange data over the axis
@@ -229,12 +237,6 @@ void Grid::makeDomainDecomposition() {
229237
nproc[dirmax]=nproc[dirmax]*2;
230238
nleft=nleft/2;
231239
}
232-
233-
idfx::cout << "Grid::makeDomainDecomposition: grid is (";
234-
for(int dir = 0 ; dir < DIMENSIONS ; dir++) {
235-
idfx::cout << " " << nproc[dir] << " ";
236-
}
237-
idfx::cout << ")" << std::endl;
238240
}
239241
/*
240242
Grid& Grid::operator=(const Grid& grid) {
@@ -257,6 +259,7 @@ Grid& Grid::operator=(const Grid& grid) {
257259
*/
258260

259261
void Grid::ShowConfig() {
262+
260263
for(int dir = 0 ; dir < DIMENSIONS ; dir++) {
261264
idfx::cout << "Grid: ";
262265
std::string lboundString, rboundString;
@@ -315,4 +318,18 @@ void Grid::ShowConfig() {
315318
<< "...." << np_int[dir] << "...." << xend[dir] << "\t" << rboundString
316319
<< std::endl;
317320
}
321+
#ifdef WITH_MPI
322+
idfx::cout << "Grid: MPI domain decomposition is (";
323+
for(int dir = 0 ; dir < DIMENSIONS ; dir++) {
324+
idfx::cout << " " << nproc[dir] << " ";
325+
}
326+
idfx::cout << ")" << std::endl;
327+
idfx::cout << "Grid: Current MPI proc coordinates (";
328+
329+
for(int dir = 0; dir < 3; dir++) {
330+
idfx::cout << xproc[dir];
331+
if(dir < 2) idfx::cout << ", ";
332+
}
333+
idfx::cout << ")" << std::endl;
334+
#endif
318335
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL