8 #include <athena/bvals/bvals.hpp>
9 #include <athena/globals.hpp>
10 #include <athena/mesh/mesh.hpp>
11 #include <athena/stride_iterator.hpp>
14 #include <application/application.hpp>
15 #include <application/globals.hpp>
22 #include "../thermodynamics/thermodynamics.hpp"
26 : pmy_block_(pmb), has_top_neighbor(false), has_bot_neighbor(false) {
27 Application::Logger app(
"snap");
28 app->Log(
"Initialize Decomposition");
29 int nc1 = pmb->ncells1, nc2 = pmb->ncells2, nc3 = pmb->ncells3;
31 psf_.NewAthenaArray(nc3, nc2, nc1 + 1);
32 psv_.NewAthenaArray(nc3, nc2, nc1);
33 pres_.NewAthenaArray(nc3, nc2, nc1);
34 dens_.NewAthenaArray(nc3, nc2, nc1);
36 buffer_ =
new Real[3 * (NGHOST + 1) * nc3 * nc2];
42 brank_ =
new int[Globals::nranks];
43 color_ =
new int[Globals::nranks];
46 entropy_.NewAthenaArray(2, nc3, nc2);
47 gamma_.NewAthenaArray(nc3, nc2, nc1);
51 Application::Logger app(
"snap");
52 app->Log(
"Destroy Decomposition");
65 std::string str = std::to_string(recvid);
67 str += std::to_string(sendid);
69 str += std::to_string(phys);
78 for (
int n = 0; n < pmb->pbval->nneighbor; ++n) {
79 NeighborBlock &nb = pmb->pbval->neighbor[n];
80 if ((nb.ni.ox1 == -1) && (nb.ni.ox2 == 0) && (nb.ni.ox3 == 0)) {
84 if ((nb.ni.ox1 == 1) && (nb.ni.ox2 == 0) && (nb.ni.ox3 == 0)) {
100 MPI_Allgather(&
bblock.snb.rank, 1, MPI_INT,
brank_, 1, MPI_INT,
113 int ssize = (ju - jl + 1) * (ku - kl + 1) * (NGHOST + 1);
115 std::stringstream msg;
120 if (
tblock.snb.rank != Globals::my_rank) {
123 MPI_Recv(
buffer_, ssize, MPI_ATHENA_REAL,
tblock.snb.rank, tag,
124 MPI_COMM_WORLD, &status);
128 msg <<
"### FATAL ERROR in Decompositin::RecvFromTop" << std::endl
129 <<
"Local boundary not yet implemented" << std::endl;
133 for (
int k = kl; k <= ku; ++k)
134 for (
int j = jl;
j <= ju; ++
j)
135 for (
int i = 0; i <= NGHOST; ++i)
136 psf(k,
j, pmb->ie + i + 1) =
buffer_[
p++];
143 for (
int k = kl; k <= ku; ++k)
144 for (
int j = jl;
j <= ju; ++
j)
145 for (
int i = 0; i <= NGHOST; ++i)
146 buffer_[ssize++] = psf(k,
j, pmb->is + i);
148 if (
bblock.snb.rank != Globals::my_rank) {
151 MPI_Isend(
buffer_, ssize, MPI_ATHENA_REAL,
bblock.snb.rank, tag,
152 MPI_COMM_WORLD, &req_send_bot_);
156 std::memcpy(pbl->pimpl->pdec->buffer_,
buffer_, ssize *
sizeof(Real));
166 for (
int k = kl; k <= ku; ++k)
167 for (
int j = jl;
j <= ju; ++
j)
168 for (
int i = 0; i < NGHOST; ++i) {
172 if (
bblock.snb.rank != Globals::my_rank) {
176 MPI_COMM_WORLD, &req_send_sync_bot_);
179 MPI_COMM_WORLD, &req_recv_sync_bot_);
183 std::memcpy(pbl->pimpl->pdec->wrecv_top_,
wsend_bot_,
184 sbot *
sizeof(Real));
185 std::memcpy(
wrecv_bot_, pbl->pimpl->pdec->wsend_top_,
186 sbot *
sizeof(Real));
192 for (
int k = kl; k <= ku; ++k)
193 for (
int j = jl;
j <= ju; ++
j)
194 for (
int i = 0; i < NGHOST; ++i) {
198 if (
tblock.snb.rank != Globals::my_rank) {
202 MPI_COMM_WORLD, &req_send_sync_top_);
205 MPI_COMM_WORLD, &req_recv_sync_top_);
209 std::memcpy(pbl->pimpl->pdec->wrecv_bot_,
wsend_top_,
210 stop *
sizeof(Real));
211 std::memcpy(
wrecv_top_, pbl->pimpl->pdec->wsend_bot_,
212 stop *
sizeof(Real));
221 MPI_Wait(&req_send_bot_, &status);
224 MPI_Wait(&req_send_top_, &status);
234 MPI_Wait(&req_send_sync_bot_, &status);
235 MPI_Wait(&req_recv_sync_bot_, &status);
241 for (
int k = kl; k <= ku; ++k)
242 for (
int j = jl;
j <= ju; ++
j)
243 for (
int i = 1; i <= NGHOST; ++i) {
251 MPI_Wait(&req_send_sync_top_, &status);
252 MPI_Wait(&req_recv_sync_top_, &status);
258 for (
int k = kl; k <= ku; ++k)
259 for (
int j = jl;
j <= ju; ++
j)
260 for (
int i = 1; i <= NGHOST; ++i) {
271 int ju,
int il,
int iu, NeighborBlock nb) {
273 int ssize = (iu - il + 1) * (ju - jl + 1) * (ku - kl + 1);
275 std::stringstream msg;
280 if (nb.snb.rank != Globals::my_rank) {
283 MPI_Recv(
buffer_, ssize, MPI_ATHENA_REAL, nb.snb.rank, tag, MPI_COMM_WORLD,
288 msg <<
"### FATAL ERROR in Decompositin::RecvBuffer" << std::endl
289 <<
"Local boundary not yet implemented" << std::endl;
293 for (
int k = kl; k <= ku; ++k)
294 for (
int j = jl;
j <= ju; ++
j)
295 for (
int i = il; i <= iu; ++i) psf(k,
j, i) =
buffer_[
p++];
302 for (
int k = kl; k <= ku; ++k)
303 for (
int j = jl;
j <= ju; ++
j)
304 for (
int i = pmb->is; i <= pmb->is + NGHOST; ++i)
308 for (
int k = kl; k <= ku; ++k)
309 for (
int j = jl;
j <= ju; ++
j)
310 for (
int i = pmb->ie - NGHOST + 1; i <= pmb->ie + 1; ++i)
314 if (
bblock.snb.rank != Globals::my_rank) {
318 MPI_COMM_WORLD, &req_send_bot_);
322 std::memcpy(pbl->pimpl->pdec->buffer_,
send_buffer_, s1 *
sizeof(Real));
327 if (
tblock.snb.rank != Globals::my_rank) {
331 MPI_COMM_WORLD, &req_send_top_);
335 std::memcpy(pbl->pimpl->pdec->buffer_,
send_buffer_ + s1,
342 int ku,
int jl,
int ju) {
345 for (
int i = 0; i < Globals::nranks; ++i) {
352 int ssize = 2 * (ku - kl + 1) * (ju - jl + 1),
p = 0;
355 for (
int k = kl; k <= ku; ++k)
356 for (
int j = jl;
j <= ju; ++
j) {
357 Real gamma = pthermo->GetGamma(pmb, k,
j, pmb->is);
360 log(w(IPR, k,
j, pmb->is)) - gamma * log(w(IDN, k,
j, pmb->is));
375 MPI_Comm_split(MPI_COMM_WORLD,
color_[Globals::my_rank], Globals::my_rank,
378 MPI_Bcast(
buffer_, ssize, MPI_ATHENA_REAL, 0, comm_col);
379 MPI_Comm_free(&comm_col);
383 for (
int k = kl; k <= ku; ++k)
384 for (
int j = jl;
j <= ju; ++
j) {
void RecvBuffer(AthenaArray< Real > &psf, int kl, int ku, int jl, int ju, int il, int iu, NeighborBlock nb)
AthenaArray< Real > gamma_
AthenaArray< Real > pres_
AthenaArray< Real > dens_
void WaitToFinishSync(AthenaArray< Real > &w, int kl, int ku, int jl, int ju)
void RecvFromTop(AthenaArray< Real > &psf, int kl, int ku, int jl, int ju)
int CreateMPITag(int lid, int bufid, int phy)
void SyncNewVariables(AthenaArray< Real > const &w, int kl, int ku, int jl, int ju)
Decomposition(MeshBlock *pmb)
void SendBuffer(AthenaArray< Real > const &psf, int kl, int ku, int jl, int ju)
AthenaArray< Real > entropy_
void SendToBottom(AthenaArray< Real > const &psf, int kl, int ku, int jl, int ju)
void PopulateBotEntropy(AthenaArray< Real > const &w, int kl, int ku, int jl, int ju)
static Thermodynamics const * GetInstance()
Return a pointer to the one and only instance of Thermodynamics.