Applies a momentum source term to drive flow in a periodic channel or pipe.
Local to this translation unit.
39{
40 PetscErrorCode ierr;
42 PetscFunctionBeginUser;
44
45
47
48
49 if (drivenDirection == ' ') {
51 PetscFunctionReturn(0);
52 }
53
54
56 if (PetscAbsReal(bulkVelocityCorrection) < 1.0e-12) {
58 PetscFunctionReturn(0);
59 }
60
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);
64
65
66 DMDALocalInfo info = user->
info;
67 PetscInt i, j, k;
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];
71
72 Cmpnts ***rct, ***csi, ***eta, ***zet;
73 PetscReal ***nvert;
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);
79
80
81
82
83
84
85
86
87
88
89
90
91
92
94 PetscReal drivingForceMagnitude;
95
101 } else {
103 }
104
108
109 PetscBool hasLoggedApplication = PETSC_FALSE;
110
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;
117
118 switch (drivenDirection) {
119 case 'X':
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;
123
124
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;
128 }
129 break;
130 case 'Y':
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;
134
135
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;
139 }
140 break;
141 case 'Z':
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;
145
146
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;
150 }
151 break;
152 }
153 }
154 }
155 }
156 }
157
158
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);
164
166 PetscFunctionReturn(0);
167}
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.
static void GetOwnedInteriorCellBounds(const DMDALocalInfo *info, PetscInt lo[3], PetscInt hi[3])
Index bounds of the interior cells this rank owns in the solver's cell-centred layout: the owned rang...
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.