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
71
72
73
74
75
76
77
78
79
80
81
83 PetscReal drivingForceMagnitude;
84
90 } else {
92 }
93
97
98 PetscBool hasLoggedApplication = PETSC_FALSE;
99
100 for (k = lzs; k < lze; k++) {
101 for (j = lys; j < lye; j++) {
102 for (i = lxs; i < lxe; i++) {
103 if (nvert[k][j][i] < 0.1) {
104 PetscReal faceArea = 0.0;
105 PetscReal momentumSource = 0.0;
106
107 switch (drivenDirection) {
108 case 'X':
109 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);
110 momentumSource = drivingForceMagnitude * forceScalingFactor * faceArea;
111 rct[k][j][i].
x += momentumSource;
112
113
114 if (!hasLoggedApplication) {
116 hasLoggedApplication = PETSC_TRUE;
117 }
118 break;
119 case 'Y':
120 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);
121 momentumSource = drivingForceMagnitude * forceScalingFactor * faceArea;
122 rct[k][j][i].
y += momentumSource;
123
124
125 if (!hasLoggedApplication) {
127 hasLoggedApplication = PETSC_TRUE;
128 }
129 break;
130 case 'Z':
131 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);
132 momentumSource = drivingForceMagnitude * forceScalingFactor * faceArea;
133 rct[k][j][i].
z += momentumSource;
134
135
136 if (!hasLoggedApplication) {
138 hasLoggedApplication = PETSC_TRUE;
139 }
140 break;
141 }
142 }
143 }
144 }
145 }
146
147
148 ierr = DMDAVecRestoreArray(user->
fda, Rct, &rct); CHKERRQ(ierr);
149 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
150 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
151 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
152 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
153
154 PetscFunctionReturn(0);
155}
#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
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.