Sets the initial values for the INTERIOR of a specified Eulerian field.
Local to this translation unit.
15{
16 PetscErrorCode ierr;
17 PetscFunctionBeginUser;
18
20
22
24
25
26 if (strcmp(fieldName, "Ucont") != 0) {
28
30
31 PetscFunctionReturn(0);
32 }
33
34
35 DM fieldDM = user->
fda;
36 Vec fieldVec = user->
Ucont;
37 DMDALocalInfo info;
38 ierr = DMDAGetLocalInfo(fieldDM, &info); CHKERRQ(ierr);
39
40 Vec localCoor;
42 ierr = DMGetCoordinatesLocal(user->
da, &localCoor); CHKERRQ(ierr);
43 ierr = DMDAVecGetArrayRead(user->
fda, localCoor, &coor_arr); CHKERRQ(ierr);
44
45 Cmpnts ***csi_arr, ***eta_arr, ***zet_arr;
46 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, &csi_arr); CHKERRQ(ierr);
47 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, &eta_arr); CHKERRQ(ierr);
48 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, &zet_arr); CHKERRQ(ierr);
49
50 const PetscInt im_phys = info.mx - 1;
51 const PetscInt jm_phys = info.my - 1;
52 const PetscInt km_phys = info.mz - 1;
53
54
55 Cmpnts ***cent_coor = NULL;
56 PetscInt xs_cell=0, xm_cell=0, ys_cell=0, ym_cell=0, zs_cell=0, zm_cell=0;
57
59
63
64 if (xm_cell > 0 && ym_cell > 0 && zm_cell > 0) {
65 ierr =
Allocate3DArray(¢_coor, zm_cell, ym_cell, xm_cell); CHKERRQ(ierr);
68 }
69 }
70
71
73 ierr = DMDAVecGetArray(fieldDM, fieldVec, &ucont_arr); CHKERRQ(ierr);
74
75 PetscInt i, j, k;
76 const PetscInt xs = info.xs, xe = info.xs + info.xm;
77 const PetscInt ys = info.ys, ye = info.ys + info.ym;
78 const PetscInt zs = info.zs, ze = info.zs + info.zm;
79
81
82
83
84 LOG_ALLOW(
GLOBAL,
LOG_DEBUG,
"Initial Constant Flux (Contravariant) = (%.3f, %.3f, %.3f)\n",(
double)uin.
x, (
double)uin.
y, (
double)uin.
z);
85
87
88 for (k = zs; k < ze; k++) {
89 for (j = ys; j < ye; j++) {
90 for (i = xs; i < xe; i++) {
91
92
93
94
95
96
97
98
99
100
101
102
103 const PetscBool is_interior = (i > 0 && i < im_phys &&
104 j > 0 && j < jm_phys &&
105 k > 0 && k < km_phys);
106
107 if (is_interior) {
108 Cmpnts ucont_val = {0.0, 0.0, 0.0};
109 PetscReal normal_velocity_mag = 0.0;
110
111
113 case 0:
114 normal_velocity_mag = 0.0;
115 break;
116 case 1:
119 normal_velocity_mag = uin.
x;
121 normal_velocity_mag = uin.
y;
122 } else {
123 normal_velocity_mag = uin.
z;
124 }
125 break;
126 case 2:
127 {
128
129
130 PetscReal u0 = 0.0;
134
135
136
137 const PetscReal i_width = (PetscReal)(im_phys - 2);
138 const PetscReal j_width = (PetscReal)(jm_phys - 2);
139 const PetscReal i_center = 1.0 + i_width / 2.0;
140 const PetscReal j_center = 1.0 + j_width / 2.0;
141
142
143 const PetscReal i_norm = (i - i_center) / (i_width / 2.0);
144 const PetscReal j_norm = (j - j_center) / (j_width / 2.0);
145
146
147
148 const PetscReal profile_i = 1.0 - i_norm * i_norm;
149 const PetscReal profile_j = 1.0 - j_norm * j_norm;
150 normal_velocity_mag = u0 * profile_i * profile_j;
151
152
153 if (normal_velocity_mag < 0.0) {
154 normal_velocity_mag = 0.0;
155 }
156 }
157 break;
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183 default:
185 normal_velocity_mag = 0.0;
186 break;
187 }
188
189
190
191 if (normal_velocity_mag != 0.0) {
192 const PetscReal signed_normal_vel = normal_velocity_mag * flow_direction_sign*user->
GridOrientation;
193
195 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);
196
197 ucont_val.
x = signed_normal_vel * area_i;
198
200 }
202 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);
203
204 ucont_val.
y = signed_normal_vel * area_j;
205
207 }
208 else {
209 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);
210
211 ucont_val.
z = signed_normal_vel * area_k;
212
213 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);
214 }
215 }
216 ucont_arr[k][j][i] = ucont_val;
217 }
218 }
219 }
220 }
221 ierr = DMDAVecRestoreArray(fieldDM, fieldVec, &ucont_arr); CHKERRQ(ierr);
222
223
224 ierr = DMDAVecRestoreArrayRead(user->
fda, localCoor, &coor_arr); CHKERRQ(ierr);
225 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, &csi_arr); CHKERRQ(ierr);
226 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, &eta_arr); CHKERRQ(ierr);
227 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, &zet_arr); CHKERRQ(ierr);
228
229 if (cent_coor) {
231 }
232
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...
#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)
PetscErrorCode GetOwnedCellRange(const DMDALocalInfo *info_nodes, PetscInt dim, PetscInt *xs_cell_global_out, PetscInt *xm_cell_local_out)
Determines the global starting index and number of CELLS owned by the current processor in a specifie...
#define Deallocate3DArray(array, nz, ny)
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.