Applies a momentum source term to drive flow in a periodic channel or pipe.
Local to this translation unit.
38{
39 PetscErrorCode ierr;
41 PetscFunctionBeginUser;
42
43
45
46
47 if (drivenDirection == ' ') {
48 PetscFunctionReturn(0);
49 }
50
51
53 if (PetscAbsReal(bulkVelocityCorrection) < 1.0e-12) {
54 PetscFunctionReturn(0);
55 }
56
58 simCtx->
rank, user->
_this, drivenDirection);
60
61
62 DMDALocalInfo info = user->
info;
63 PetscInt i, j, k;
64 PetscInt lxs = (info.xs == 0) ? 1 : info.xs;
65 PetscInt lys = (info.ys == 0) ? 1 : info.ys;
66 PetscInt lzs = (info.zs == 0) ? 1 : info.zs;
67 PetscInt lxe = (info.xs + info.xm == info.mx) ? info.mx - 1 : info.xs + info.xm;
68 PetscInt lye = (info.ys + info.ym == info.my) ? info.my - 1 : info.ys + info.ym;
69 PetscInt lze = (info.zs + info.zm == info.mz) ? info.mz - 1 : info.zs + info.zm;
70
71 Cmpnts ***rct, ***csi, ***eta, ***zet;
72 PetscReal ***nvert;
73 ierr = DMDAVecGetArray(user->
fda, Rct, &rct); CHKERRQ(ierr);
74 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
75 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
76 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
77 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
78
79
80
81
82
83
84
85
86
87
88
89
90
91
93 PetscReal drivingForceMagnitude;
94
100 } else {
102 }
103
107
108 PetscBool hasLoggedApplication = PETSC_FALSE;
109
110 for (k = lzs; k < lze; k++) {
111 for (j = lys; j < lye; j++) {
112 for (i = lxs; i < lxe; i++) {
113 if (nvert[k][j][i] < 0.1) {
114 PetscReal faceArea = 0.0;
115 PetscReal momentumSource = 0.0;
116
117 switch (drivenDirection) {
118 case 'X':
119 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);
120 momentumSource = drivingForceMagnitude * forceScalingFactor * faceArea;
121 rct[k][j][i].
x += momentumSource;
122
123
124 if (!hasLoggedApplication) {
126 hasLoggedApplication = PETSC_TRUE;
127 }
128 break;
129 case 'Y':
130 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);
131 momentumSource = drivingForceMagnitude * forceScalingFactor * faceArea;
132 rct[k][j][i].
y += momentumSource;
133
134
135 if (!hasLoggedApplication) {
137 hasLoggedApplication = PETSC_TRUE;
138 }
139 break;
140 case 'Z':
141 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);
142 momentumSource = drivingForceMagnitude * forceScalingFactor * faceArea;
143 rct[k][j][i].
z += momentumSource;
144
145
146 if (!hasLoggedApplication) {
148 hasLoggedApplication = PETSC_TRUE;
149 }
150 break;
151 }
152 }
153 }
154 }
155 }
156
157
158 ierr = DMDAVecRestoreArray(user->
fda, Rct, &rct); CHKERRQ(ierr);
159 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
160 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
161 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
162 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
163
164 PetscFunctionReturn(0);
165}
static char DrivenFlowDirection(const UserCtx *user)
The axis a driven periodic handler drives, or ' ' when none is configured.
#define LOCAL
Logging scope definitions for controlling message output.
#define GLOBAL
Scope for global logging across all processes.
#define LOG_ALLOW(scope, level, fmt,...)
Logging macro that checks both the log level and whether the calling function is in the allowed-funct...
@ LOG_DEBUG
Detailed debugging information.
PetscReal forceScalingFactor
SimCtx * simCtx
Back-pointer to the master simulation context.
PetscReal bulkVelocityCorrection
PetscInt drivingForceStep
#define COEF_TIME_ACCURACY
Coefficient controlling the temporal accuracy scheme (e.g., 1.5 for 2nd Order Backward Difference).
PetscReal drivingForceMagnitude
A 3D point or vector with PetscScalar components.
The master context for the entire simulation.