33 PetscFunctionBeginUser;
40 if (strcmp(fieldName,
"Ucont") != 0) {
42 PetscFunctionReturn(0);
46 DM fieldDM = user->
fda;
47 Vec fieldVec = user->
Ucont;
49 ierr = DMDAGetLocalInfo(fieldDM, &info); CHKERRQ(ierr);
53 ierr = DMGetCoordinatesLocal(user->
da, &localCoor); CHKERRQ(ierr);
54 ierr = DMDAVecGetArrayRead(user->
fda, localCoor, &coor_arr); CHKERRQ(ierr);
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);
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;
75 if (xm_cell > 0 && ym_cell > 0 && zm_cell > 0) {
76 ierr =
Allocate3DArray(¢_coor, zm_cell, ym_cell, xm_cell); CHKERRQ(ierr);
84 ierr = DMDAVecGetArray(fieldDM, fieldVec, &ucont_arr); CHKERRQ(ierr);
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;
100 for (k = zs; k < ze; k++) {
101 for (j = ys; j < ye; j++) {
102 for (i = xs; i < xe; i++) {
105 const PetscBool is_interior = (i > 0 && i < mx - 1 &&
106 j > 0 && j < my - 1 &&
107 k > 0 && k < mz - 1);
110 Cmpnts ucont_val = {0.0, 0.0, 0.0};
111 PetscReal normal_velocity_mag = 0.0;
116 normal_velocity_mag = 0.0;
121 normal_velocity_mag = uin.
x;
123 normal_velocity_mag = uin.
y;
125 normal_velocity_mag = uin.
z;
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;
145 const PetscReal i_norm = (i - i_center) / (i_width / 2.0);
146 const PetscReal j_norm = (j - j_center) / (j_width / 2.0);
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;
155 if (normal_velocity_mag < 0.0) {
156 normal_velocity_mag = 0.0;
187 normal_velocity_mag = 0.0;
193 if (normal_velocity_mag != 0.0) {
194 const PetscReal signed_normal_vel = normal_velocity_mag * flow_direction_sign*user->
GridOrientation;
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);
199 ucont_val.
x = signed_normal_vel * area_i;
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);
206 ucont_val.
y = signed_normal_vel * area_j;
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);
213 ucont_val.
z = signed_normal_vel * area_k;
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);
218 ucont_arr[k][j][i] = ucont_val;
223 ierr = DMDAVecRestoreArray(fieldDM, fieldVec, &ucont_arr); CHKERRQ(ierr);
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);
235 PetscFunctionReturn(0);