Applies a momentum source term to drive flow in a periodic channel or pipe.
Local to this translation unit.
15{
16 PetscErrorCode ierr;
18 PetscFunctionBeginUser;
19
20
21 char drivenDirection = ' ';
22 for (int i = 0; i < 6; i++) {
26 {
31 }
32 break;
33 }
34 }
35
36
37 if (drivenDirection == ' ') {
38 PetscFunctionReturn(0);
39 }
40
41
43 if (PetscAbsReal(bulkVelocityCorrection) < 1.0e-12) {
44 PetscFunctionReturn(0);
45 }
46
48 simCtx->
rank, user->
_this, drivenDirection);
50
51
52 DMDALocalInfo info = user->
info;
53 PetscInt i, j, k;
54 PetscInt lxs = (info.xs == 0) ? 1 : info.xs;
55 PetscInt lys = (info.ys == 0) ? 1 : info.ys;
56 PetscInt lzs = (info.zs == 0) ? 1 : info.zs;
57 PetscInt lxe = (info.xs + info.xm == info.mx) ? info.mx - 1 : info.xs + info.xm;
58 PetscInt lye = (info.ys + info.ym == info.my) ? info.my - 1 : info.ys + info.ym;
59 PetscInt lze = (info.zs + info.zm == info.mz) ? info.mz - 1 : info.zs + info.zm;
60
61 Cmpnts ***rct, ***csi, ***eta, ***zet;
62 PetscReal ***nvert;
63 ierr = DMDAVecGetArray(user->
fda, Rct, &rct); CHKERRQ(ierr);
64 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
65 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
66 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
67 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
68
69
70
72 PetscReal drivingForceMagnitude = (bulkVelocityCorrection / simCtx->
dt / 1.0 *
COEF_TIME_ACCURACY);
74
78
79 PetscBool hasLoggedApplication = PETSC_FALSE;
80
81 for (k = lzs; k < lze; k++) {
82 for (j = lys; j < lye; j++) {
83 for (i = lxs; i < lxe; i++) {
84 if (nvert[k][j][i] < 0.1) {
85 PetscReal faceArea = 0.0;
86 PetscReal momentumSource = 0.0;
87
88 switch (drivenDirection) {
89 case 'X':
90 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);
91 momentumSource = drivingForceMagnitude * forceScalingFactor * faceArea;
92 rct[k][j][i].
x += momentumSource;
93
94
95 if (!hasLoggedApplication) {
97 hasLoggedApplication = PETSC_TRUE;
98 }
99 break;
100 case 'Y':
101 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);
102 momentumSource = drivingForceMagnitude * forceScalingFactor * faceArea;
103 rct[k][j][i].
y += momentumSource;
104
105
106 if (!hasLoggedApplication) {
108 hasLoggedApplication = PETSC_TRUE;
109 }
110 break;
111 case 'Z':
112 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);
113 momentumSource = drivingForceMagnitude * forceScalingFactor * faceArea;
114 rct[k][j][i].
z += momentumSource;
115
116
117 if (!hasLoggedApplication) {
119 hasLoggedApplication = PETSC_TRUE;
120 }
121 break;
122 }
123 }
124 }
125 }
126 }
127
128
130
131
132 ierr = DMDAVecRestoreArray(user->
fda, Rct, &rct); CHKERRQ(ierr);
133 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
134 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
135 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
136 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
137
138 PetscFunctionReturn(0);
139}
#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.