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.
33{
34 PetscErrorCode ierr;
35 PetscFunctionBeginUser;
36
38
40
42
43
44 if (strcmp(fieldName, "Ucont") != 0) {
46
48
49 PetscFunctionReturn(0);
50 }
51
52
53 DM fieldDM = user->
fda;
54 Vec fieldVec = user->
Ucont;
55 DMDALocalInfo info;
56 ierr = DMDAGetLocalInfo(fieldDM, &info); CHKERRQ(ierr);
57
58 Vec localCoor;
60 ierr = DMGetCoordinatesLocal(user->
da, &localCoor); CHKERRQ(ierr);
61 ierr = DMDAVecGetArrayRead(user->
fda, localCoor, &coor_arr); CHKERRQ(ierr);
62
63 Cmpnts ***csi_arr, ***eta_arr, ***zet_arr;
64 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, &csi_arr); CHKERRQ(ierr);
65 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, &eta_arr); CHKERRQ(ierr);
66 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, &zet_arr); CHKERRQ(ierr);
67
68 const PetscInt im_phys = info.mx - 1;
69 const PetscInt jm_phys = info.my - 1;
70 const PetscInt km_phys = info.mz - 1;
71
72
73 Cmpnts ***cent_coor = NULL;
74 PetscInt xs_cell=0, xm_cell=0, ys_cell=0, ym_cell=0, zs_cell=0, zm_cell=0;
75
77
81
82 if (xm_cell > 0 && ym_cell > 0 && zm_cell > 0) {
83 ierr =
Allocate3DArray(¢_coor, zm_cell, ym_cell, xm_cell); CHKERRQ(ierr);
86 }
87 }
88
89
91 ierr = DMDAVecGetArray(fieldDM, fieldVec, &ucont_arr); CHKERRQ(ierr);
92
93 PetscInt i, j, k;
94 const PetscInt mx = info.mx, my = info.my, mz = info.mz;
95 const PetscInt xs = info.xs, xe = info.xs + info.xm;
96 const PetscInt ys = info.ys, ye = info.ys + info.ym;
97 const PetscInt zs = info.zs, ze = info.zs + info.zm;
98
100
101
102
103 LOG_ALLOW(
GLOBAL,
LOG_DEBUG,
"Initial Constant Flux (Contravariant) = (%.3f, %.3f, %.3f)\n",(
double)uin.
x, (
double)uin.
y, (
double)uin.
z);
104
106
107 for (k = zs; k < ze; k++) {
108 for (j = ys; j < ye; j++) {
109 for (i = xs; i < xe; i++) {
110
111
112 const PetscBool is_interior = (i > 0 && i < im_phys - 1 &&
113 j > 0 && j < jm_phys - 1 &&
114 k > 0 && k < km_phys - 1);
115
116 if (is_interior) {
117 Cmpnts ucont_val = {0.0, 0.0, 0.0};
118 PetscReal normal_velocity_mag = 0.0;
119
120
122 case 0:
123 normal_velocity_mag = 0.0;
124 break;
125 case 1:
128 normal_velocity_mag = uin.
x;
130 normal_velocity_mag = uin.
y;
131 } else {
132 normal_velocity_mag = uin.
z;
133 }
134 break;
135 case 2:
136 {
137
138
139 PetscReal u0 = 0.0;
143
144
145
146 const PetscReal i_width = (PetscReal)(im_phys - 2);
147 const PetscReal j_width = (PetscReal)(jm_phys - 2);
148 const PetscReal i_center = 1.0 + i_width / 2.0;
149 const PetscReal j_center = 1.0 + j_width / 2.0;
150
151
152 const PetscReal i_norm = (i - i_center) / (i_width / 2.0);
153 const PetscReal j_norm = (j - j_center) / (j_width / 2.0);
154
155
156
157 const PetscReal profile_i = 1.0 - i_norm * i_norm;
158 const PetscReal profile_j = 1.0 - j_norm * j_norm;
159 normal_velocity_mag = u0 * profile_i * profile_j;
160
161
162 if (normal_velocity_mag < 0.0) {
163 normal_velocity_mag = 0.0;
164 }
165 }
166 break;
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192 default:
194 normal_velocity_mag = 0.0;
195 break;
196 }
197
198
199
200 if (normal_velocity_mag != 0.0) {
201 const PetscReal signed_normal_vel = normal_velocity_mag * flow_direction_sign*user->
GridOrientation;
202
204 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);
205
206 ucont_val.
x = signed_normal_vel * area_i;
207
209 }
211 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);
212
213 ucont_val.
y = signed_normal_vel * area_j;
214
216 }
217 else {
218 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);
219
220 ucont_val.
z = signed_normal_vel * area_k;
221
222 LOG_LOOP_ALLOW(
GLOBAL,
LOG_VERBOSE,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);
223 }
224 }
225 ucont_arr[k][j][i] = ucont_val;
226 }
227 }
228 }
229 }
230 ierr = DMDAVecRestoreArray(fieldDM, fieldVec, &ucont_arr); CHKERRQ(ierr);
231
232
233 ierr = DMDAVecRestoreArrayRead(user->
fda, localCoor, &coor_arr); CHKERRQ(ierr);
234 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, &csi_arr); CHKERRQ(ierr);
235 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, &eta_arr); CHKERRQ(ierr);
236 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, &zet_arr); CHKERRQ(ierr);
237
238 if (cent_coor) {
240 }
241
243
244 PetscFunctionReturn(0);
245}
#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...
#define PROFILE_FUNCTION_END
Marks the end of a profiled code block.
@ LOG_INFO
Informational messages about program execution.
@ LOG_WARNING
Non-critical issues that warrant attention.
@ LOG_DEBUG
Detailed debugging information.
@ LOG_VERBOSE
Extremely detailed logs, typically for development use only.
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled code block (typically a function).
#define Allocate3DArray(array, nz, ny, nx)
#define Deallocate3DArray(array, nz, ny)
PetscErrorCode GetOwnedCellRange(const DMDALocalInfo *info_nodes, PetscInt dim, PetscInt *xs_cell_global, PetscInt *xm_cell_local)
Determines the global starting index and number of CELLS owned by the current processor in a specifie...
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.