244 const PetscReal V0 = 1.0;
245 const PetscReal rho = 1.0;
246 const PetscReal p0 = 0.0;
249 const PetscReal nu = (simCtx->
ren > 0) ? (1.0 / simCtx->
ren) : 0.0;
251 const PetscReal k = 1.0;
252 const PetscReal t = simCtx->
ti;
254 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);
256 const PetscReal vel_decay = exp(-2.0 * nu * k * k * t);
257 const PetscReal prs_decay = exp(-4.0 * nu * k * k * t);
259 PetscFunctionBeginUser;
261 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
262 UserCtx* user = &user_finest[bi];
263 DMDALocalInfo info = user->
info;
264 PetscInt xs = info.xs, xe = info.xs + info.xm;
265 PetscInt ys = info.ys, ye = info.ys + info.ym;
266 PetscInt zs = info.zs, ze = info.zs + info.zm;
267 PetscInt mx = info.mx, my = info.my, mz = info.mz;
270 const Cmpnts ***cent, ***cent_x, ***cent_y, ***cent_z;
274 PetscInt lxs = (xs == 0) ? xs + 1 : xs, lxe = (xe == mx) ? xe - 1 : xe;
275 PetscInt lys = (ys == 0) ? ys + 1 : ys, lye = (ye == my) ? ye - 1 : ye;
276 PetscInt lzs = (zs == 0) ? zs + 1 : zs, lze = (ze == mz) ? ze - 1 : ze;
279 ierr = DMDAVecGetArray(user->
fda, user->
Ucat, &ucat); CHKERRQ(ierr);
280 ierr = DMDAVecGetArray(user->
da, user->
P, &p); CHKERRQ(ierr);
281 ierr = DMDAVecGetArray(user->
fda, user->
Bcs.
Ubcs, &ubcs); CHKERRQ(ierr);
282 ierr = DMDAVecGetArrayRead(user->
fda, user->
Cent, ¢); CHKERRQ(ierr);
283 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCentx, ¢_x); CHKERRQ(ierr);
284 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCenty, ¢_y); CHKERRQ(ierr);
285 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCentz, ¢_z); CHKERRQ(ierr);
288 for (PetscInt k_cell = lzs; k_cell < lze; k_cell++) {
289 for (PetscInt j_cell = lys; j_cell < lye; j_cell++) {
290 for (PetscInt i_cell = lxs; i_cell < lxe; i_cell++) {
291 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;
292 ucat[k_cell][j_cell][i_cell].
x = V0 * sin(k*cx) * cos(k*cy) * cos(k*cz) * vel_decay;
293 ucat[k_cell][j_cell][i_cell].
y = -V0 * cos(k*cx) * sin(k*cy) * cos(k*cz) * vel_decay;
294 ucat[k_cell][j_cell][i_cell].
z = 0.0;
301 for (PetscInt k_cell = lzs; k_cell < lze; k_cell++) {
302 for (PetscInt j_cell = lys; j_cell < lye; j_cell++) {
303 for (PetscInt i_cell = lxs; i_cell < lxe; i_cell++) {
304 const PetscReal cx = cent[k_cell][j_cell][i_cell].
x, cy = cent[k_cell][j_cell][i_cell].
y;
305 p[k_cell][j_cell][i_cell] = p0 + (rho * V0 * V0 / 4.0) * (cos(2*k*cx) + cos(2*k*cy)) * prs_decay;
312 if (xs == 0)
for (PetscInt k=zs; k<ze; k++)
for (PetscInt j=ys; j<ye; j++) {
313 const PetscReal fcx=cent_x[k][j][xs].
x, fcy=cent_x[k][j][xs].
y, fcz=cent_x[k][j][xs].
z;
314 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;
316 if (xe == mx)
for (PetscInt k=zs; k<ze; k++)
for (PetscInt j=ys; j<ye; j++) {
317 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;
318 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;
320 if (ys == 0)
for (PetscInt k=zs; k<ze; k++)
for (PetscInt i=xs; i<xe; i++) {
321 const PetscReal fcx=cent_y[k][ys][i].
x, fcy=cent_y[k][ys][i].
y, fcz=cent_y[k][ys][i].
z;
322 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;
324 if (ye == my)
for (PetscInt k=zs; k<ze; k++)
for (PetscInt i=xs; i<xe; i++) {
325 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;
326 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;
328 if (zs == 0)
for (PetscInt j=ys; j<ye; j++)
for (PetscInt i=xs; i<xe; i++) {
329 const PetscReal fcx=cent_z[zs][j][i].
x, fcy=cent_z[zs][j][i].
y, fcz=cent_z[zs][j][i].
z;
330 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;
332 if (ze == mz)
for (PetscInt j=ys; j<ye; j++)
for (PetscInt i=xs; i<xe; i++) {
333 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;
334 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;
338 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];
339 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];
341 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];
342 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];
344 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];
345 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];
348 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucat, &ucat); CHKERRQ(ierr);
349 ierr = DMDAVecRestoreArray(user->
da, user->
P, &p); CHKERRQ(ierr);
350 ierr = DMDAVecRestoreArray(user->
fda, user->
Bcs.
Ubcs, &ubcs); CHKERRQ(ierr);
351 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
Cent, ¢); CHKERRQ(ierr);
352 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCentx, ¢_x); CHKERRQ(ierr);
353 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCenty, ¢_y); CHKERRQ(ierr);
354 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCentz, ¢_z); CHKERRQ(ierr);
370 PetscFunctionReturn(0);
414 const PetscReal u = uniform_velocity.
x;
415 const PetscReal v = uniform_velocity.
y;
416 const PetscReal w = uniform_velocity.
z;
418 PetscFunctionBeginUser;
420 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
421 UserCtx *user = &user_finest[bi];
422 DMDALocalInfo info = user->
info;
423 PetscInt xs = info.xs, xe = info.xs + info.xm;
424 PetscInt ys = info.ys, ye = info.ys + info.ym;
425 PetscInt zs = info.zs, ze = info.zs + info.zm;
426 PetscInt mx = info.mx, my = info.my, mz = info.mz;
433 ierr = DMDAVecGetArray(user->
fda, user->
Bcs.
Ubcs, &ubcs); CHKERRQ(ierr);
434 if (xs == 0)
for (PetscInt k = zs; k < ze; k++)
for (PetscInt j = ys; j < ye; j++) ubcs[k][j][xs] = uniform_velocity;
435 if (xe == mx)
for (PetscInt k = zs; k < ze; k++)
for (PetscInt j = ys; j < ye; j++) ubcs[k][j][xe - 1] = uniform_velocity;
436 if (ys == 0)
for (PetscInt k = zs; k < ze; k++)
for (PetscInt i = xs; i < xe; i++) ubcs[k][ys][i] = uniform_velocity;
437 if (ye == my)
for (PetscInt k = zs; k < ze; k++)
for (PetscInt i = xs; i < xe; i++) ubcs[k][ye - 1][i] = uniform_velocity;
438 if (zs == 0)
for (PetscInt j = ys; j < ye; j++)
for (PetscInt i = xs; i < xe; i++) ubcs[zs][j][i] = uniform_velocity;
439 if (ze == mz)
for (PetscInt j = ys; j < ye; j++)
for (PetscInt i = xs; i < xe; i++) ubcs[ze - 1][j][i] = uniform_velocity;
440 ierr = DMDAVecRestoreArray(user->
fda, user->
Bcs.
Ubcs, &ubcs); CHKERRQ(ierr);
443 ierr = VecZeroEntries(user->
P); CHKERRQ(ierr);
457 PetscFunctionReturn(0);
629 PetscReal *positions = NULL;
630 PetscReal *scalar_values = NULL;
632 const char *swarm_field_name = NULL;
634 PetscFunctionBeginUser;
635 if (!user) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"UserCtx cannot be NULL.");
636 if (!user->
swarm) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
"UserCtx->swarm is NULL.");
640 PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP,
641 "Analytical scalar assignment requires a one-component PETSC_REAL particle field; '%s' has %d components and type %s.",
645 ierr = DMSwarmGetLocalSize(user->
swarm, &nlocal); CHKERRQ(ierr);
646 if (nlocal == 0) PetscFunctionReturn(0);
649 ierr = DMSwarmGetField(user->
swarm, swarm_field_name, NULL, NULL, (
void **)&scalar_values); CHKERRQ(ierr);
651 for (PetscInt p = 0; p < nlocal; ++p) {
652 PetscReal value = 0.0;
654 positions[3 * p + 0],
655 positions[3 * p + 1],
656 positions[3 * p + 2],
658 &value); CHKERRQ(ierr);
659 scalar_values[p] = value;
662 ierr = DMSwarmRestoreField(user->
swarm, swarm_field_name, NULL, NULL, (
void **)&scalar_values); CHKERRQ(ierr);
664 PetscFunctionReturn(0);
678 PetscReal ***target = NULL;
679 const Cmpnts ***cent = NULL;
681 PetscInt xs, xe, ys, ye, zs, ze, mx, my, mz;
682 PetscInt lxs, lxe, lys, lye, lzs, lze;
684 PetscFunctionBeginUser;
685 if (!user) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"UserCtx cannot be NULL.");
686 if (!targetVec) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"targetVec cannot be NULL.");
689 xs = info.xs; xe = info.xs + info.xm;
690 ys = info.ys; ye = info.ys + info.ym;
691 zs = info.zs; ze = info.zs + info.zm;
692 mx = info.mx; my = info.my; mz = info.mz;
693 lxs = (xs == 0) ? xs + 1 : xs; lxe = (xe == mx) ? xe - 1 : xe;
694 lys = (ys == 0) ? ys + 1 : ys; lye = (ye == my) ? ye - 1 : ye;
695 lzs = (zs == 0) ? zs + 1 : zs; lze = (ze == mz) ? ze - 1 : ze;
697 ierr = VecSet(targetVec, 0.0); CHKERRQ(ierr);
698 ierr = DMDAVecGetArray(user->
da, targetVec, &target); CHKERRQ(ierr);
699 ierr = DMDAVecGetArrayRead(user->
fda, user->
Cent, ¢); CHKERRQ(ierr);
701 for (PetscInt k = lzs; k < lze; ++k) {
702 for (PetscInt j = lys; j < lye; ++j) {
703 for (PetscInt i = lxs; i < lxe; ++i) {
704 PetscReal value = 0.0;
710 &value); CHKERRQ(ierr);
711 target[k][j][i] = value;
716 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
Cent, ¢); CHKERRQ(ierr);
717 ierr = DMDAVecRestoreArray(user->
da, targetVec, &target); CHKERRQ(ierr);
718 PetscFunctionReturn(0);
PetscErrorCode ParticleFieldGetDescriptor(ParticleFieldId field_id, const ParticleFieldDescriptor **descriptor)
Return immutable metadata for a valid particle field ID.