Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data encapsulation and access functions #69

Merged
merged 11 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Checks: 'bugprone-*,
-readability-avoid-const-params-in-decls,
-readability-identifier-length,
-readability-convert-member-functions-to-static,
-readability-function-cognitive-complexity'
-readability-function-cognitive-complexity,
-readability-make-member-function-const'
WarningsAsErrors: ''
HeaderFilterRegex: '.*'
HeaderFileExtensions: ['', "H", 'h', 'hh', 'hpp', 'hxx']
Expand Down
19 changes: 10 additions & 9 deletions src/CartBlock.C
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,19 @@
{
int nfrac;
for (int n = 0; n < 3; n++) {
xlo[n] = cg->xlo[(3 * global_id) + n];
xlo[n] = cg->get_xlo((3 * global_id) + n);
}
for (int n = 0; n < 3; n++) {
dx[n] = cg->dx[(3 * global_id) + n];
dx[n] = cg->get_dx((3 * global_id) + n);
}
dims[0] = cg->ihi[static_cast<ptrdiff_t>(3 * global_id)] -
cg->ilo[static_cast<ptrdiff_t>(3 * global_id)] + 1;
dims[1] = cg->ihi[(3 * global_id) + 1] - cg->ilo[(3 * global_id) + 1] + 1;
dims[2] = cg->ihi[(3 * global_id) + 2] - cg->ilo[(3 * global_id) + 2] + 1;
nf = cg->nf;
myid = cg->myid;
donor_frac = cg->donor_frac;
dims[0] = cg->get_ihi((3 * global_id)) - cg->get_ilo((3 * global_id)) + 1;
dims[1] =
cg->get_ihi((3 * global_id) + 1) - cg->get_ilo((3 * global_id) + 1) + 1;
dims[2] =
cg->get_ihi((3 * global_id) + 2) - cg->get_ilo((3 * global_id) + 2) + 1;
nf = cg->get_nf();
myid = cg->get_myid();
donor_frac = cg->get_donor_frac();
ncell = dims[0] * dims[1] * dims[2];
ncell_nf = (dims[0] + 2 * nf) * (dims[1] + 2 * nf) * (dims[2] + 2 * nf);
nnode = (dims[0] + 1) * (dims[1] + 1) * (dims[2] + 1);
Expand All @@ -201,7 +202,7 @@
deallocateLinkList(donorList[i]);
donorList[i] = nullptr;
}
TIOGA_FREE(donorList);

Check warning on line 205 in src/CartBlock.C

View workflow job for this annotation

GitHub Actions / Lint-clang-tidy

multilevel pointer conversion from 'DONORLIST **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
}
deallocateLinkList4(interpList);
interpList = nullptr;
Expand Down
21 changes: 19 additions & 2 deletions src/CartGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ class CartGrid
bool own_data_ptrs{true};
bool own_amr_mesh_info{false};

public:
TIOGA::AMRMeshInfo* m_info{nullptr};
TIOGA::AMRMeshInfo* m_info_device{nullptr};

int* global_id{nullptr};
int* level_num{nullptr};
int* proc_id{nullptr};
int* local_id{nullptr};
int myid{0};
int* ilo{nullptr};
int* ihi{nullptr};
int* dims{nullptr};
int myid{0};
int nf{0};
double* xlo{nullptr};
double* dx{nullptr};
int ngrids{0};
void (*donor_frac)(int*, double*, int*, double*) = nullptr;

public:
CartGrid() = default;
~CartGrid();

Expand All @@ -70,6 +70,23 @@ class CartGrid
}

void create_mesh_info();

TIOGA::AMRMeshInfo* get_mesh_info() { return m_info; }
int get_proc_id(int index) { return proc_id[index]; }
int get_local_id(int index) { return local_id[index]; }
void set_myid(int rank_id) { myid = rank_id; }
int get_myid() { return myid; }
int get_ilo(int index) { return ilo[index]; }
int get_ihi(int index) { return ihi[index]; }
int get_dims(int index) { return dims[index]; }
int get_nf() { return nf; }
double get_xlo(int index) { return xlo[index]; }
double get_dx(int index) { return dx[index]; }
int get_ngrids() { return ngrids; }
void (*get_donor_frac())(int*, double*, int*, double*)
{
return donor_frac;
}
};

#endif /* CARTGRID_H */
29 changes: 17 additions & 12 deletions src/exchangeAMRDonors.C
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ void tioga::exchangeAMRDonors()
// since the receiver side is unknown
//
pc_cart->getMap(&nsend_sav, &nrecv_sav, &sndMap, &rcvMap);
sndMapAll = (int*)malloc(sizeof(int) * pc_cart->numprocs);
rcvMapAll = (int*)malloc(sizeof(int) * pc_cart->numprocs);
nsend = nrecv = pc_cart->numprocs;
imap = (int*)malloc(sizeof(int) * pc_cart->numprocs);
icount = (int*)malloc(sizeof(int) * pc_cart->numprocs);
for (i = 0; i < pc_cart->numprocs; i++) {
const int cart_comm_size = pc_cart->get_comm_size();
sndMapAll = (int*)malloc(sizeof(int) * cart_comm_size);
rcvMapAll = (int*)malloc(sizeof(int) * cart_comm_size);
nsend = nrecv = cart_comm_size;
imap = (int*)malloc(sizeof(int) * cart_comm_size);
icount = (int*)malloc(sizeof(int) * cart_comm_size);
for (i = 0; i < cart_comm_size; i++) {
sndMapAll[i] = rcvMapAll[i] = imap[i] = i;
icount[i] = 0;
}
Expand Down Expand Up @@ -86,8 +87,10 @@ void tioga::exchangeAMRDonors()
for (i = 0; i < mb->ntotalPointsCart; i++) {
if (mb->donorIdCart[i] != -1) {
gid = mb->donorIdCart[i];
assert((cg->proc_id[gid] < nsend && cg->proc_id[gid] >= 0));
obdonors[imap[cg->proc_id[gid]]]++;
assert(
(cg->get_proc_id(gid) < nsend &&
cg->get_proc_id(gid) >= 0));
obdonors[imap[cg->get_proc_id(gid)]]++;
}
}
for (i = 0; i < mb->nsearch; i++) {
Expand Down Expand Up @@ -127,8 +130,8 @@ void tioga::exchangeAMRDonors()
for (i = 0; i < mb->ntotalPointsCart; i++) {
if (mb->donorIdCart[i] != -1) {
gid = mb->donorIdCart[i];
procid = imap[cg->proc_id[gid]];
localid = cg->local_id[gid];
procid = imap[cg->get_proc_id(gid)];
localid = cg->get_local_id(gid);
sndPack[procid].intData[intcount[procid]++] = localid;
sndPack[procid].intData[intcount[procid]++] =
mb->receptorIdCart[i];
Expand Down Expand Up @@ -319,10 +322,12 @@ void tioga::checkComm()
int *sndMap, *rcvMap;
PACKET *sndPack, *rcvPack;

nsend = nrecv = pc_cart->numprocs;
const int cart_comm_size = pc_cart->get_comm_size();
nsend = cart_comm_size;
nrecv = cart_comm_size;
sndMap = (int*)malloc(sizeof(int) * nsend);
rcvMap = (int*)malloc(sizeof(int) * nrecv);
for (i = 0; i < pc_cart->numprocs; i++) {
for (i = 0; i < cart_comm_size; i++) {
sndMap[i] = rcvMap[i] = i;
}
pc_cart->setMap(nsend, nrecv, sndMap, rcvMap);
Expand Down
61 changes: 32 additions & 29 deletions src/getCartReceptors.C
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ void MeshBlock::getCartReceptors(CartGrid* cg, parallelComm* pc)
//
// limit case we communicate to everybody
//
int* pmap = (int*)malloc(sizeof(int) * pc->numprocs);
for (int i = 0; i < pc->numprocs; i++) {
const int comm_size = pc->get_comm_size();
int* pmap = (int*)malloc(sizeof(int) * comm_size);
for (int i = 0; i < comm_size; i++) {
pmap[i] = 0;
}
//
Expand All @@ -60,17 +61,18 @@ void MeshBlock::getCartReceptors(CartGrid* cg, parallelComm* pc)
//
nsearch = 0;
//
for (int c = 0; c < cg->ngrids; c++) {
int const cell_count = (cg->dims[3 * c] + 2 * cg->nf) *
(cg->dims[3 * c + 1] + 2 * cg->nf) *
(cg->dims[3 * c + 2] + 2 * cg->nf);
for (int c = 0; c < cg->get_ngrids(); c++) {
int const cell_count = (cg->get_dims(3 * c) + 2 * cg->get_nf()) *
(cg->get_dims(3 * c + 1) + 2 * cg->get_nf()) *
(cg->get_dims(3 * c + 2) + 2 * cg->get_nf());

int const vol = static_cast<int>(
cg->dx[3 * c] * cg->dx[3 * c + 1] * cg->dx[3 * c + 2]);
cg->get_dx(3 * c) * cg->get_dx(3 * c + 1) * cg->get_dx(3 * c + 2));

for (int n = 0; n < 3; n++) {
obcart->dxc[n] = cg->dx[3 * c + n] * (cg->dims[3 * c + n]) * 0.5;
obcart->xc[n] = cg->xlo[3 * c + n] + obcart->dxc[n];
obcart->dxc[n] =
cg->get_dx(3 * c + n) * (cg->get_dims(3 * c + n)) * 0.5;
obcart->xc[n] = cg->get_xlo(3 * c + n) + obcart->dxc[n];
}

int intersectCount = 0;
Expand All @@ -84,19 +86,19 @@ void MeshBlock::getCartReceptors(CartGrid* cg, parallelComm* pc)

auto* xtm = (double*)malloc(sizeof(double) * 3);

for (int j = 0; j < cg->dims[3 * c]; j++) {
for (int k = 0; k < cg->dims[3 * c + 1]; k++) {
for (int l = 0; l < cg->dims[3 * c + 2]; l++) {
for (int j = 0; j < cg->get_dims(3 * c); j++) {
for (int k = 0; k < cg->get_dims(3 * c + 1); k++) {
for (int l = 0; l < cg->get_dims(3 * c + 2); l++) {
fillReceptorDataPtr(
cg, cell_count, c, j, k, l, pmap, vol, xtm, false,
dataPtr);
}
}
}

for (int j = 0; j < cg->dims[3 * c] + 1; j++) {
for (int k = 0; k < cg->dims[3 * c + 1] + 1; k++) {
for (int l = 0; l < cg->dims[3 * c + 2] + 1; l++) {
for (int j = 0; j < cg->get_dims(3 * c) + 1; j++) {
for (int k = 0; k < cg->get_dims(3 * c + 1) + 1; k++) {
for (int l = 0; l < cg->get_dims(3 * c + 2) + 1; l++) {
fillReceptorDataPtr(
cg, cell_count, c, j, k, l, pmap, vol, xtm, true,
dataPtr);
Expand All @@ -111,7 +113,7 @@ void MeshBlock::getCartReceptors(CartGrid* cg, parallelComm* pc)
// create the communication map
//
int nsend = 0;
for (int i = 0; i < pc->numprocs; i++) {
for (int i = 0; i < comm_size; i++) {
if (pmap[i] == 1) {
nsend++;
}
Expand All @@ -120,7 +122,7 @@ void MeshBlock::getCartReceptors(CartGrid* cg, parallelComm* pc)
int* sndMap = (int*)malloc(sizeof(int) * nsend);
int* rcvMap = (int*)malloc(sizeof(int) * nrecv);
int m = 0;
for (int i = 0; i < pc->numprocs; i++) {
for (int i = 0; i < comm_size; i++) {
if (pmap[i] == 1) {
sndMap[m] = rcvMap[m] = i;
m++;
Expand Down Expand Up @@ -185,19 +187,20 @@ void MeshBlock::fillReceptorDataPtr(
int itm = -1;
if (isNodal) {
itm = cart_utils::get_concatenated_node_index(
cg->dims[3 * c], cg->dims[3 * c + 1], cg->dims[3 * c + 2], cg->nf,
j, k, l);
cg->get_dims(3 * c), cg->get_dims(3 * c + 1),
cg->get_dims(3 * c + 2), cg->get_nf(), j, k, l);

xtm[0] = cg->xlo[3 * c] + j * cg->dx[3 * c];
xtm[1] = cg->xlo[3 * c + 1] + k * cg->dx[3 * c + 1];
xtm[2] = cg->xlo[3 * c + 2] + l * cg->dx[3 * c + 2];
xtm[0] = cg->get_xlo(3 * c) + j * cg->get_dx(3 * c);
xtm[1] = cg->get_xlo(3 * c + 1) + k * cg->get_dx(3 * c + 1);
xtm[2] = cg->get_xlo(3 * c + 2) + l * cg->get_dx(3 * c + 2);
} else {
itm = cart_utils::get_cell_index(
cg->dims[3 * c], cg->dims[3 * c + 1], cg->nf, j, k, l);
cg->get_dims(3 * c), cg->get_dims(3 * c + 1), cg->get_nf(), j, k,
l);

xtm[0] = cg->xlo[3 * c] + (j + 0.5) * cg->dx[3 * c];
xtm[1] = cg->xlo[3 * c + 1] + (k + 0.5) * cg->dx[3 * c + 1];
xtm[2] = cg->xlo[3 * c + 2] + (l + 0.5) * cg->dx[3 * c + 2];
xtm[0] = cg->get_xlo(3 * c) + (j + 0.5) * cg->get_dx(3 * c);
xtm[1] = cg->get_xlo(3 * c + 1) + (k + 0.5) * cg->get_dx(3 * c + 1);
xtm[2] = cg->get_xlo(3 * c + 2) + (l + 0.5) * cg->get_dx(3 * c + 2);
}

double xd[3];
Expand All @@ -217,16 +220,16 @@ void MeshBlock::fillReceptorDataPtr(
}

if (iflag > 0) {
pmap[cg->proc_id[c]] = 1;
pmap[cg->get_proc_id(c)] = 1;
dataPtr->next = (INTEGERLIST2*)malloc(sizeof(INTEGERLIST2));
dataPtr = dataPtr->next;
dataPtr->intDataSize = 4;
dataPtr->realDataSize = 4;
dataPtr->realData =
(double*)malloc(sizeof(double) * dataPtr->realDataSize);
dataPtr->intData = (int*)malloc(sizeof(int) * dataPtr->intDataSize);
dataPtr->intData[0] = cg->proc_id[c];
dataPtr->intData[1] = cg->local_id[c];
dataPtr->intData[0] = cg->get_proc_id(c);
dataPtr->intData[1] = cg->get_local_id(c);
dataPtr->intData[2] = itm;
dataPtr->intData[3] = 0;
nsearch += 1;
Expand Down
12 changes: 12 additions & 0 deletions src/parallelComm.C
Original file line number Diff line number Diff line change
Expand Up @@ -439,3 +439,15 @@ void parallelComm::initPackets(PACKET* sndPack, PACKET* rcvPack) const
}
//
}

void parallelComm::set_comm_size(int nprocs) { numprocs = nprocs; }

int parallelComm::get_comm_size() { return numprocs; }

void parallelComm::set_rank(int procid) { myid = procid; }

int parallelComm::get_rank() { return myid; }

void parallelComm::set_comm(MPI_Comm comm) { scomm = comm; }

MPI_Comm parallelComm::get_comm() { return scomm; }
15 changes: 13 additions & 2 deletions src/parallelComm.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ class parallelComm
int nrecv;
int* sndMap;
int* rcvMap;

public:
int myid;
int numprocs;
MPI_Comm scomm;

public:
parallelComm()
{
sndMap = nullptr;
Expand Down Expand Up @@ -74,6 +73,18 @@ class parallelComm
void initPackets(PACKET* sndPack, PACKET* rcvPack) const;

void clearPackets(PACKET* sndPack, PACKET* rcvPack) const;

void set_comm_size(int nprocs);

int get_comm_size();

void set_rank(int procid);

int get_rank();

void set_comm(MPI_Comm comm);

MPI_Comm get_comm();
};

#endif /* PARALLELCOMM_H */
Loading
Loading