33 PetscFunctionBeginUser;
36 char drivenDirection =
' ';
37 for (
int i = 0; i < 6; i++) {
52 if (drivenDirection ==
' ') {
53 PetscFunctionReturn(0);
58 if (PetscAbsReal(bulkVelocityCorrection) < 1.0e-12) {
59 PetscFunctionReturn(0);
63 simCtx->
rank, user->
_this, drivenDirection);
67 DMDALocalInfo info = user->
info;
69 PetscInt lxs = (info.xs == 0) ? 1 : info.xs;
70 PetscInt lys = (info.ys == 0) ? 1 : info.ys;
71 PetscInt lzs = (info.zs == 0) ? 1 : info.zs;
72 PetscInt lxe = (info.xs + info.xm == info.mx) ? info.mx - 1 : info.xs + info.xm;
73 PetscInt lye = (info.ys + info.ym == info.my) ? info.my - 1 : info.ys + info.ym;
74 PetscInt lze = (info.zs + info.zm == info.mz) ? info.mz - 1 : info.zs + info.zm;
76 Cmpnts ***rct, ***csi, ***eta, ***zet;
78 ierr = DMDAVecGetArray(user->
fda, Rct, &rct); CHKERRQ(ierr);
79 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
80 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
81 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
82 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
87 PetscReal drivingForceMagnitude = (bulkVelocityCorrection / simCtx->
dt / 1.0 *
COEF_TIME_ACCURACY);
94 PetscBool hasLoggedApplication = PETSC_FALSE;
96 for (k = lzs; k < lze; k++) {
97 for (j = lys; j < lye; j++) {
98 for (i = lxs; i < lxe; i++) {
99 if (nvert[k][j][i] < 0.1) {
100 PetscReal faceArea = 0.0;
101 PetscReal momentumSource = 0.0;
103 switch (drivenDirection) {
105 faceArea = sqrt(csi[k][j][i].x * csi[k][j][i].x + csi[k][j][i].y * csi[k][j][i].y + csi[k][j][i].z * csi[k][j][i].z);
106 momentumSource = drivingForceMagnitude * forceScalingFactor * faceArea;
107 rct[k][j][i].
x += momentumSource;
110 if (!hasLoggedApplication) {
112 hasLoggedApplication = PETSC_TRUE;
116 faceArea = sqrt(eta[k][j][i].x * eta[k][j][i].x + eta[k][j][i].y * eta[k][j][i].y + eta[k][j][i].z * eta[k][j][i].z);
117 momentumSource = drivingForceMagnitude * forceScalingFactor * faceArea;
118 rct[k][j][i].
y += momentumSource;
121 if (!hasLoggedApplication) {
123 hasLoggedApplication = PETSC_TRUE;
127 faceArea = sqrt(zet[k][j][i].x * zet[k][j][i].x + zet[k][j][i].y * zet[k][j][i].y + zet[k][j][i].z * zet[k][j][i].z);
128 momentumSource = drivingForceMagnitude * forceScalingFactor * faceArea;
129 rct[k][j][i].
z += momentumSource;
132 if (!hasLoggedApplication) {
134 hasLoggedApplication = PETSC_TRUE;
147 ierr = DMDAVecRestoreArray(user->
fda, Rct, &rct); CHKERRQ(ierr);
148 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
149 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
150 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
151 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
153 PetscFunctionReturn(0);
PetscErrorCode ComputeDrivenChannelFlowSource(UserCtx *user, Vec Rct)
Applies a momentum source term to drive flow in a periodic channel or pipe.