245 const PetscReal V0 = 1.0;
246 const PetscReal rho = 1.0;
247 const PetscReal p0 = 0.0;
250 const PetscReal nu = (simCtx->
ren > 0) ? (1.0 / simCtx->
ren) : 0.0;
252 const PetscReal k = 1.0;
253 const PetscReal t = simCtx->
ti;
255 LOG_ALLOW(
GLOBAL,
LOG_TRACE,
"TGV Setup: t = %.4f, V0* = %.4f, rho* = %.4f, k = %.4f, p0* = %4.f, nu = %.6f.\n",simCtx->
ti,V0,rho,k,p0,nu);
257 const PetscReal vel_decay = exp(-2.0 * nu * k * k * t);
258 const PetscReal prs_decay = exp(-4.0 * nu * k * k * t);
260 PetscFunctionBeginUser;
262 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
263 UserCtx* user = &user_finest[bi];
264 DMDALocalInfo info = user->
info;
265 PetscInt xs = info.xs, xe = info.xs + info.xm;
266 PetscInt ys = info.ys, ye = info.ys + info.ym;
267 PetscInt zs = info.zs, ze = info.zs + info.zm;
268 PetscInt mx = info.mx, my = info.my, mz = info.mz;
271 const Cmpnts ***cent, ***cent_x, ***cent_y, ***cent_z;
275 PetscInt lxs = (xs == 0) ? xs + 1 : xs, lxe = (xe == mx) ? xe - 1 : xe;
276 PetscInt lys = (ys == 0) ? ys + 1 : ys, lye = (ye == my) ? ye - 1 : ye;
277 PetscInt lzs = (zs == 0) ? zs + 1 : zs, lze = (ze == mz) ? ze - 1 : ze;
280 ierr = DMDAVecGetArray(user->
fda, user->
Ucat, &ucat); CHKERRQ(ierr);
281 ierr = DMDAVecGetArray(user->
da, user->
P, &p); CHKERRQ(ierr);
282 ierr = DMDAVecGetArray(user->
fda, user->
Bcs.
Ubcs, &ubcs); CHKERRQ(ierr);
283 ierr = DMDAVecGetArrayRead(user->
fda, user->
Cent, ¢); CHKERRQ(ierr);
284 ierr = DMDAVecGetArrayRead(user->
fda, user->
Centx, ¢_x); CHKERRQ(ierr);
285 ierr = DMDAVecGetArrayRead(user->
fda, user->
Centy, ¢_y); CHKERRQ(ierr);
286 ierr = DMDAVecGetArrayRead(user->
fda, user->
Centz, ¢_z); CHKERRQ(ierr);
289 for (PetscInt k_cell = lzs; k_cell < lze; k_cell++) {
290 for (PetscInt j_cell = lys; j_cell < lye; j_cell++) {
291 for (PetscInt i_cell = lxs; i_cell < lxe; i_cell++) {
292 const PetscReal cx = cent[k_cell][j_cell][i_cell].
x, cy = cent[k_cell][j_cell][i_cell].
y, cz = cent[k_cell][j_cell][i_cell].
z;
293 ucat[k_cell][j_cell][i_cell].
x = V0 * sin(k*cx) * cos(k*cy) * cos(k*cz) * vel_decay;
294 ucat[k_cell][j_cell][i_cell].
y = -V0 * cos(k*cx) * sin(k*cy) * cos(k*cz) * vel_decay;
295 ucat[k_cell][j_cell][i_cell].
z = 0.0;
302 for (PetscInt k_cell = lzs; k_cell < lze; k_cell++) {
303 for (PetscInt j_cell = lys; j_cell < lye; j_cell++) {
304 for (PetscInt i_cell = lxs; i_cell < lxe; i_cell++) {
305 const PetscReal cx = cent[k_cell][j_cell][i_cell].
x, cy = cent[k_cell][j_cell][i_cell].
y;
306 p[k_cell][j_cell][i_cell] = p0 + (rho * V0 * V0 / 4.0) * (cos(2*k*cx) + cos(2*k*cy)) * prs_decay;
313 if (xs == 0)
for (PetscInt k=zs; k<ze; k++)
for (PetscInt j=ys; j<ye; j++) {
314 const PetscReal fcx=cent_x[k][j][xs].
x, fcy=cent_x[k][j][xs].
y, fcz=cent_x[k][j][xs].
z;
315 ubcs[k][j][xs].
x = V0*sin(k*fcx)*cos(k*fcy)*cos(k*fcz)*vel_decay; ubcs[k][j][xs].
y = -V0*cos(k*fcx)*sin(k*fcy)*cos(k*fcz)*vel_decay; ubcs[k][j][xs].
z = 0.0;
317 if (xe == mx)
for (PetscInt k=zs; k<ze; k++)
for (PetscInt j=ys; j<ye; j++) {
318 const PetscReal fcx=cent_x[k][j][xe-1].
x, fcy=cent_x[k][j][xe-1].
y, fcz=cent_x[k][j][xe-1].
z;
319 ubcs[k][j][xe-1].
x = V0*sin(k*fcx)*cos(k*fcy)*cos(k*fcz)*vel_decay; ubcs[k][j][xe-1].
y = -V0*cos(k*fcx)*sin(k*fcy)*cos(k*fcz)*vel_decay; ubcs[k][j][xe-1].
z = 0.0;
321 if (ys == 0)
for (PetscInt k=zs; k<ze; k++)
for (PetscInt i=xs; i<xe; i++) {
322 const PetscReal fcx=cent_y[k][ys][i].
x, fcy=cent_y[k][ys][i].
y, fcz=cent_y[k][ys][i].
z;
323 ubcs[k][ys][i].
x = V0*sin(k*fcx)*cos(k*fcy)*cos(k*fcz)*vel_decay; ubcs[k][ys][i].
y = -V0*cos(k*fcx)*sin(k*fcy)*cos(k*fcz)*vel_decay; ubcs[k][ys][i].
z = 0.0;
325 if (ye == my)
for (PetscInt k=zs; k<ze; k++)
for (PetscInt i=xs; i<xe; i++) {
326 const PetscReal fcx=cent_y[k][ye-1][i].
x, fcy=cent_y[k][ye-1][i].
y, fcz=cent_y[k][ye-1][i].
z;
327 ubcs[k][ye-1][i].
x = V0*sin(k*fcx)*cos(k*fcy)*cos(k*fcz)*vel_decay; ubcs[k][ye-1][i].
y = -V0*cos(k*fcx)*sin(k*fcy)*cos(k*fcz)*vel_decay; ubcs[k][ye-1][i].
z = 0.0;
329 if (zs == 0)
for (PetscInt j=ys; j<ye; j++)
for (PetscInt i=xs; i<xe; i++) {
330 const PetscReal fcx=cent_z[zs][j][i].
x, fcy=cent_z[zs][j][i].
y, fcz=cent_z[zs][j][i].
z;
331 ubcs[zs][j][i].
x = V0*sin(k*fcx)*cos(k*fcy)*cos(k*fcz)*vel_decay; ubcs[zs][j][i].
y = -V0*cos(k*fcx)*sin(k*fcy)*cos(k*fcz)*vel_decay; ubcs[zs][j][i].
z = 0.0;
333 if (ze == mz)
for (PetscInt j=ys; j<ye; j++)
for (PetscInt i=xs; i<xe; i++) {
334 const PetscReal fcx=cent_z[ze-1][j][i].
x, fcy=cent_z[ze-1][j][i].
y, fcz=cent_z[ze-1][j][i].
z;
335 ubcs[ze-1][j][i].
x = V0*sin(k*fcx)*cos(k*fcy)*cos(k*fcz)*vel_decay; ubcs[ze-1][j][i].
y = -V0*cos(k*fcx)*sin(k*fcy)*cos(k*fcz)*vel_decay; ubcs[ze-1][j][i].
z = 0.0;
339 if (xs == 0)
for (PetscInt k=lzs; k<lze; k++)
for (PetscInt j=lys; j<lye; j++) p[k][j][xs] = p[k][j][xs+1];
340 if (xe == mx)
for (PetscInt k=lzs; k<lze; k++)
for (PetscInt j=lys; j<lye; j++) p[k][j][xe-1] = p[k][j][xe-2];
342 if (ys == 0)
for (PetscInt k=lzs; k<lze; k++)
for (PetscInt i=lxs; i<lxe; i++) p[k][ys][i] = p[k][ys+1][i];
343 if (ye == my)
for (PetscInt k=lzs; k<lze; k++)
for (PetscInt i=lxs; i<lxe; i++) p[k][ye-1][i] = p[k][ye-2][i];
345 if (zs == 0)
for (PetscInt j=lys; j<lye; j++)
for (PetscInt i=lxs; i<lxe; i++) p[zs][j][i] = p[zs+1][j][i];
346 if (ze == mz)
for (PetscInt j=lys; j<lye; j++)
for (PetscInt i=lxs; i<lxe; i++) p[ze-1][j][i] = p[ze-2][j][i];
349 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucat, &ucat); CHKERRQ(ierr);
350 ierr = DMDAVecRestoreArray(user->
da, user->
P, &p); CHKERRQ(ierr);
351 ierr = DMDAVecRestoreArray(user->
fda, user->
Bcs.
Ubcs, &ubcs); CHKERRQ(ierr);
352 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
Cent, ¢); CHKERRQ(ierr);
353 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
Centx, ¢_x); CHKERRQ(ierr);
354 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
Centy, ¢_y); CHKERRQ(ierr);
355 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
Centz, ¢_z); CHKERRQ(ierr);
371 PetscFunctionReturn(0);
417 const PetscReal u = uniform_velocity.
x;
418 const PetscReal v = uniform_velocity.
y;
419 const PetscReal w = uniform_velocity.
z;
421 PetscFunctionBeginUser;
423 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
424 UserCtx *user = &user_finest[bi];
425 DMDALocalInfo info = user->
info;
426 PetscInt xs = info.xs, xe = info.xs + info.xm;
427 PetscInt ys = info.ys, ye = info.ys + info.ym;
428 PetscInt zs = info.zs, ze = info.zs + info.zm;
429 PetscInt mx = info.mx, my = info.my, mz = info.mz;
437 const Cmpnts ***csi, ***eta, ***zet;
439 ierr = DMDAVecGetArray(user->
fda, user->
Ucont, &ucont); CHKERRQ(ierr);
440 ierr = DMDAVecGetArray(user->
fda, user->
Bcs.
Ubcs, &ubcs); CHKERRQ(ierr);
441 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, &csi); CHKERRQ(ierr);
442 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, &eta); CHKERRQ(ierr);
443 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, &zet); CHKERRQ(ierr);
445 for (PetscInt k = zs; k < ze; k++) {
446 for (PetscInt j = ys; j < ye; j++) {
447 for (PetscInt i = xs; i < xe; i++) {
448 ucont[k][j][i].
x = csi[k][j][i].
x * u + csi[k][j][i].
y * v + csi[k][j][i].
z * w;
449 ucont[k][j][i].
y = eta[k][j][i].
x * u + eta[k][j][i].
y * v + eta[k][j][i].
z * w;
450 ucont[k][j][i].
z = zet[k][j][i].
x * u + zet[k][j][i].
y * v + zet[k][j][i].
z * w;
456 if (xs == 0)
for (PetscInt k = zs; k < ze; k++)
for (PetscInt j = ys; j < ye; j++) ubcs[k][j][xs] = uniform_velocity;
457 if (xe == mx)
for (PetscInt k = zs; k < ze; k++)
for (PetscInt j = ys; j < ye; j++) ubcs[k][j][xe - 1] = uniform_velocity;
458 if (ys == 0)
for (PetscInt k = zs; k < ze; k++)
for (PetscInt i = xs; i < xe; i++) ubcs[k][ys][i] = uniform_velocity;
459 if (ye == my)
for (PetscInt k = zs; k < ze; k++)
for (PetscInt i = xs; i < xe; i++) ubcs[k][ye - 1][i] = uniform_velocity;
460 if (zs == 0)
for (PetscInt j = ys; j < ye; j++)
for (PetscInt i = xs; i < xe; i++) ubcs[zs][j][i] = uniform_velocity;
461 if (ze == mz)
for (PetscInt j = ys; j < ye; j++)
for (PetscInt i = xs; i < xe; i++) ubcs[ze - 1][j][i] = uniform_velocity;
463 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, &zet); CHKERRQ(ierr);
464 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, &eta); CHKERRQ(ierr);
465 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, &csi); CHKERRQ(ierr);
466 ierr = DMDAVecRestoreArray(user->
fda, user->
Bcs.
Ubcs, &ubcs); CHKERRQ(ierr);
467 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucont, &ucont); CHKERRQ(ierr);
470 ierr = VecZeroEntries(user->
P); CHKERRQ(ierr);
483 PetscFunctionReturn(0);
657 PetscReal *positions = NULL;
658 PetscReal *scalar_values = NULL;
660 PetscFunctionBeginUser;
661 if (!user) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"UserCtx cannot be NULL.");
662 if (!user->
swarm) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
"UserCtx->swarm is NULL.");
663 if (!swarm_field_name) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"swarm_field_name cannot be NULL.");
665 ierr = DMSwarmGetLocalSize(user->
swarm, &nlocal); CHKERRQ(ierr);
666 if (nlocal == 0) PetscFunctionReturn(0);
668 ierr = DMSwarmGetField(user->
swarm,
"position", NULL, NULL, (
void **)&positions); CHKERRQ(ierr);
669 ierr = DMSwarmGetField(user->
swarm, swarm_field_name, NULL, NULL, (
void **)&scalar_values); CHKERRQ(ierr);
671 for (PetscInt p = 0; p < nlocal; ++p) {
672 PetscReal value = 0.0;
674 positions[3 * p + 0],
675 positions[3 * p + 1],
676 positions[3 * p + 2],
678 &value); CHKERRQ(ierr);
679 scalar_values[p] = value;
682 ierr = DMSwarmRestoreField(user->
swarm, swarm_field_name, NULL, NULL, (
void **)&scalar_values); CHKERRQ(ierr);
683 ierr = DMSwarmRestoreField(user->
swarm,
"position", NULL, NULL, (
void **)&positions); CHKERRQ(ierr);
684 PetscFunctionReturn(0);
698 PetscReal ***target = NULL;
699 const Cmpnts ***cent = NULL;
701 PetscInt xs, xe, ys, ye, zs, ze, mx, my, mz;
702 PetscInt lxs, lxe, lys, lye, lzs, lze;
704 PetscFunctionBeginUser;
705 if (!user) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"UserCtx cannot be NULL.");
706 if (!targetVec) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"targetVec cannot be NULL.");
709 xs = info.xs; xe = info.xs + info.xm;
710 ys = info.ys; ye = info.ys + info.ym;
711 zs = info.zs; ze = info.zs + info.zm;
712 mx = info.mx; my = info.my; mz = info.mz;
713 lxs = (xs == 0) ? xs + 1 : xs; lxe = (xe == mx) ? xe - 1 : xe;
714 lys = (ys == 0) ? ys + 1 : ys; lye = (ye == my) ? ye - 1 : ye;
715 lzs = (zs == 0) ? zs + 1 : zs; lze = (ze == mz) ? ze - 1 : ze;
717 ierr = VecSet(targetVec, 0.0); CHKERRQ(ierr);
718 ierr = DMDAVecGetArray(user->
da, targetVec, &target); CHKERRQ(ierr);
719 ierr = DMDAVecGetArrayRead(user->
fda, user->
Cent, ¢); CHKERRQ(ierr);
721 for (PetscInt k = lzs; k < lze; ++k) {
722 for (PetscInt j = lys; j < lye; ++j) {
723 for (PetscInt i = lxs; i < lxe; ++i) {
724 PetscReal value = 0.0;
730 &value); CHKERRQ(ierr);
731 target[k][j][i] = value;
736 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
Cent, ¢); CHKERRQ(ierr);
737 ierr = DMDAVecRestoreArray(user->
da, targetVec, &target); CHKERRQ(ierr);
738 PetscFunctionReturn(0);