Applies a momentum source term to drive flow in a periodic channel or pipe.
This function is the "engine" of the driven flow control system. It operates by:
If no driven flow handler is found, this function does nothing.
30{
31 PetscErrorCode ierr;
33 PetscFunctionBeginUser;
34
35
36 char drivenDirection = ' ';
37 for (int i = 0; i < 6; i++) {
41 {
46 }
47 break;
48 }
49 }
50
51
52 if (drivenDirection == ' ') {
53 PetscFunctionReturn(0);
54 }
55
56
58 if (PetscAbsReal(bulkVelocityCorrection) < 1.0e-12) {
59 PetscFunctionReturn(0);
60 }
61
63 simCtx->
rank, user->
_this, drivenDirection);
65
66
67 DMDALocalInfo info = user->
info;
68 PetscInt i, j, k;
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;
75
76 Cmpnts ***rct, ***csi, ***eta, ***zet;
77 PetscReal ***nvert;
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);
83
84
85
87 PetscReal drivingForceMagnitude = (bulkVelocityCorrection / simCtx->
dt / 1.0 *
COEF_TIME_ACCURACY);
89
93
94 PetscBool hasLoggedApplication = PETSC_FALSE;
95
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;
102
103 switch (drivenDirection) {
104 case 'X':
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;
108
109
110 if (!hasLoggedApplication) {
112 hasLoggedApplication = PETSC_TRUE;
113 }
114 break;
115 case 'Y':
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;
119
120
121 if (!hasLoggedApplication) {
123 hasLoggedApplication = PETSC_TRUE;
124 }
125 break;
126 case 'Z':
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;
130
131
132 if (!hasLoggedApplication) {
134 hasLoggedApplication = PETSC_TRUE;
135 }
136 break;
137 }
138 }
139 }
140 }
141 }
142
143
145
146
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);
152
153 PetscFunctionReturn(0);
154}
#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.
BoundaryFaceConfig boundary_faces[6]
PetscReal forceScalingFactor
SimCtx * simCtx
Back-pointer to the master simulation context.
BCHandlerType
Defines the specific computational "strategy" for a boundary handler.
@ BC_HANDLER_PERIODIC_DRIVEN_INITIAL_FLUX
@ BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX
BCHandlerType handler_type
PetscReal bulkVelocityCorrection
#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.