Sets the initial values for the INTERIOR of a specified Eulerian field.
The initialization is directional, aligned with the primary INLET face that was identified by the parser. This ensures the initial flow is physically meaningful.
31{
32 PetscErrorCode ierr;
33 PetscFunctionBeginUser;
34
36
38
39
40 if (strcmp(fieldName, "Ucont") != 0) {
42 PetscFunctionReturn(0);
43 }
44
45
46 DM fieldDM = user->
fda;
47 Vec fieldVec = user->
Ucont;
48 DMDALocalInfo info;
49 ierr = DMDAGetLocalInfo(fieldDM, &info); CHKERRQ(ierr);
50
51 Vec localCoor;
53 ierr = DMGetCoordinatesLocal(user->
da, &localCoor); CHKERRQ(ierr);
54 ierr = DMDAVecGetArrayRead(user->
fda, localCoor, &coor_arr); CHKERRQ(ierr);
55
56 Cmpnts ***csi_arr, ***eta_arr, ***zet_arr;
57 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, &csi_arr); CHKERRQ(ierr);
58 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, &eta_arr); CHKERRQ(ierr);
59 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, &zet_arr); CHKERRQ(ierr);
60
61
62 Cmpnts ***cent_coor = NULL;
63 PetscInt xs_cell=0, xm_cell=0, ys_cell=0, ym_cell=0, zs_cell=0, zm_cell=0;
64
66
67
68
69
70
74
75 if (xm_cell > 0 && ym_cell > 0 && zm_cell > 0) {
76 ierr =
Allocate3DArray(¢_coor, zm_cell, ym_cell, xm_cell); CHKERRQ(ierr);
79 }
80 }
81
82
84 ierr = DMDAVecGetArray(fieldDM, fieldVec, &ucont_arr); CHKERRQ(ierr);
85
86 PetscInt i, j, k;
87 const PetscInt mx = info.mx, my = info.my, mz = info.mz;
88 const PetscInt xs = info.xs, xe = info.xs + info.xm;
89 const PetscInt ys = info.ys, ye = info.ys + info.ym;
90 const PetscInt zs = info.zs, ze = info.zs + info.zm;
91
93
94
95
97
99
100 for (k = zs; k < ze; k++) {
101 for (j = ys; j < ye; j++) {
102 for (i = xs; i < xe; i++) {
103
104
105 const PetscBool is_interior = (i > 0 && i < mx - 1 &&
106 j > 0 && j < my - 1 &&
107 k > 0 && k < mz - 1);
108
109 if (is_interior) {
110 Cmpnts ucont_val = {0.0, 0.0, 0.0};
111 PetscReal normal_velocity_mag = 0.0;
112
113
115 case 0:
116 normal_velocity_mag = 0.0;
117 break;
118 case 1:
121 normal_velocity_mag = uin.
x;
123 normal_velocity_mag = uin.
y;
124 } else {
125 normal_velocity_mag = uin.
z;
126 }
127 break;
128 case 2:
129 {
130
131
132 PetscReal u0 = 0.0;
136
137
138
139 const PetscReal i_width = (PetscReal)(mx - 2);
140 const PetscReal j_width = (PetscReal)(my - 2);
141 const PetscReal i_center = 1.0 + i_width / 2.0;
142 const PetscReal j_center = 1.0 + j_width / 2.0;
143
144
145 const PetscReal i_norm = (i - i_center) / (i_width / 2.0);
146 const PetscReal j_norm = (j - j_center) / (j_width / 2.0);
147
148
149
150 const PetscReal profile_i = 1.0 - i_norm * i_norm;
151 const PetscReal profile_j = 1.0 - j_norm * j_norm;
152 normal_velocity_mag = u0 * profile_i * profile_j;
153
154
155 if (normal_velocity_mag < 0.0) {
156 normal_velocity_mag = 0.0;
157 }
158 }
159 break;
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185 default:
187 normal_velocity_mag = 0.0;
188 break;
189 }
190
191
192
193 if (normal_velocity_mag != 0.0) {
194 const PetscReal signed_normal_vel = normal_velocity_mag * flow_direction_sign*user->
GridOrientation;
195
197 const PetscReal area_i = sqrt(csi_arr[k][j][i].x * csi_arr[k][j][i].x + csi_arr[k][j][i].y * csi_arr[k][j][i].y + csi_arr[k][j][i].z * csi_arr[k][j][i].z);
198
199 ucont_val.
x = signed_normal_vel * area_i;
200
202 }
204 const PetscReal area_j = sqrt(eta_arr[k][j][i].x * eta_arr[k][j][i].x + eta_arr[k][j][i].y * eta_arr[k][j][i].y + eta_arr[k][j][i].z * eta_arr[k][j][i].z);
205
206 ucont_val.
y = signed_normal_vel * area_j;
207
209 }
210 else {
211 const PetscReal area_k = sqrt(zet_arr[k][j][i].x * zet_arr[k][j][i].x + zet_arr[k][j][i].y * zet_arr[k][j][i].y + zet_arr[k][j][i].z * zet_arr[k][j][i].z);
212
213 ucont_val.
z = signed_normal_vel * area_k;
214
215 LOG_LOOP_ALLOW(
GLOBAL,
LOG_DEBUG,k,50,
" i,j,k,ucont_val.z = %d, %d, %d, %.6f (signed_normal_vel=%.3f × area=%.4f)\n",i,j,k,ucont_val.
z, signed_normal_vel, area_k);
216 }
217 }
218 ucont_arr[k][j][i] = ucont_val;
219 }
220 }
221 }
222 }
223 ierr = DMDAVecRestoreArray(fieldDM, fieldVec, &ucont_arr); CHKERRQ(ierr);
224
225
226 ierr = DMDAVecRestoreArrayRead(user->
fda, localCoor, &coor_arr); CHKERRQ(ierr);
227 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, &csi_arr); CHKERRQ(ierr);
228 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, &eta_arr); CHKERRQ(ierr);
229 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, &zet_arr); CHKERRQ(ierr);
230
231 if (cent_coor) {
233 }
234
235 PetscFunctionReturn(0);
236}
#define InterpolateFieldFromCornerToCenter(field, centfield, user)
Generic macro to call the appropriate interpolation function based on the field type.
#define LOG_LOOP_ALLOW(scope, level, iterVar, interval, fmt,...)
Logs a message inside a loop, but only every interval iterations.
#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_INFO
Informational messages about program execution.
@ LOG_WARNING
Non-critical issues that warrant attention.
@ LOG_DEBUG
Detailed debugging information.
#define Allocate3DArray(array, nz, ny, nx)
#define Deallocate3DArray(array, nz, ny)
PetscErrorCode GetGhostedCellRange(const DMDALocalInfo *info_nodes, const RankNeighbors *neighbors, PetscInt dim, PetscInt *xs_cell_global_out, PetscInt *xm_cell_local_out)
Gets the global cell range for a rank, including boundary cells.
BCFace identifiedInletBCFace
SimCtx * simCtx
Back-pointer to the master simulation context.
PetscInt FieldInitialization
Cmpnts InitialConstantContra
A 3D point or vector with PetscScalar components.
The master context for the entire simulation.