42 PetscFunctionBeginUser;
49 if (drivenDirection ==
' ') {
51 PetscFunctionReturn(0);
56 if (PetscAbsReal(bulkVelocityCorrection) < 1.0e-12) {
58 PetscFunctionReturn(0);
61 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Rank %d, Block %" PetscInt_FMT
": Applying driven flow momentum source in '%c' direction.\n",
62 simCtx->
rank, user->
_this, drivenDirection);
66 DMDALocalInfo info = user->
info;
68 PetscInt lo[3], hi[3];
70 PetscInt lxs = lo[0], lys = lo[1], lzs = lo[2], lxe = hi[0], lye = hi[1], lze = hi[2];
72 Cmpnts ***rct, ***csi, ***eta, ***zet;
74 ierr = DMDAVecGetArray(user->
fda, Rct, &rct); CHKERRQ(ierr);
75 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
76 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
77 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
78 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
94 PetscReal drivingForceMagnitude;
109 PetscBool hasLoggedApplication = PETSC_FALSE;
111 for (k = lzs; k < lze; k++) {
112 for (j = lys; j < lye; j++) {
113 for (i = lxs; i < lxe; i++) {
114 if (nvert[k][j][i] < 0.1) {
115 PetscReal faceArea = 0.0;
116 PetscReal momentumSource = 0.0;
118 switch (drivenDirection) {
120 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);
121 momentumSource = drivingForceMagnitude * forceScalingFactor * faceArea;
122 rct[k][j][i].
x += momentumSource;
125 if (!hasLoggedApplication) {
126 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Body Force %le added at (%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
")\n",momentumSource, k, j, i);
127 hasLoggedApplication = PETSC_TRUE;
131 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);
132 momentumSource = drivingForceMagnitude * forceScalingFactor * faceArea;
133 rct[k][j][i].
y += momentumSource;
136 if (!hasLoggedApplication) {
137 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Body Force %le added at (%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
")\n",momentumSource, k, j, i);
138 hasLoggedApplication = PETSC_TRUE;
142 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);
143 momentumSource = drivingForceMagnitude * forceScalingFactor * faceArea;
144 rct[k][j][i].
z += momentumSource;
147 if (!hasLoggedApplication) {
148 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Body Force %le added at (%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
")\n",momentumSource, k, j, i);
149 hasLoggedApplication = PETSC_TRUE;
159 ierr = DMDAVecRestoreArray(user->
fda, Rct, &rct); CHKERRQ(ierr);
160 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
161 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
162 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
163 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
166 PetscFunctionReturn(0);
PetscErrorCode LogDrivenFlowDiagnostics(UserCtx *user)
Implementation of LogDrivenFlowDiagnostics().
PetscErrorCode ComputeDrivenChannelFlowSource(UserCtx *user, Vec Rct)
Internal helper implementation: ComputeDrivenChannelFlowSource().
static char DrivenFlowDirection(const UserCtx *user)
The axis a driven periodic handler drives, or ' ' when none is configured.
Momentum source terms added to the contravariant RHS.