35 PetscFunctionBeginUser;
44 if (strcmp(fieldName,
"Ucont") != 0) {
49 PetscFunctionReturn(0);
53 DM fieldDM = user->
fda;
54 Vec fieldVec = user->
Ucont;
56 ierr = DMDAGetLocalInfo(fieldDM, &info); CHKERRQ(ierr);
60 ierr = DMGetCoordinatesLocal(user->
da, &localCoor); CHKERRQ(ierr);
61 ierr = DMDAVecGetArrayRead(user->
fda, localCoor, &coor_arr); CHKERRQ(ierr);
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);
68 const PetscInt im_phys = info.mx - 1;
69 const PetscInt jm_phys = info.my - 1;
70 const PetscInt km_phys = info.mz - 1;
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;
82 if (xm_cell > 0 && ym_cell > 0 && zm_cell > 0) {
83 ierr =
Allocate3DArray(¢_coor, zm_cell, ym_cell, xm_cell); CHKERRQ(ierr);
91 ierr = DMDAVecGetArray(fieldDM, fieldVec, &ucont_arr); CHKERRQ(ierr);
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;
103 LOG_ALLOW(
GLOBAL,
LOG_DEBUG,
"Initial Constant Flux (Contravariant) = (%.3f, %.3f, %.3f)\n",(
double)uin.
x, (
double)uin.
y, (
double)uin.
z);
107 for (k = zs; k < ze; k++) {
108 for (j = ys; j < ye; j++) {
109 for (i = xs; i < xe; i++) {
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);
117 Cmpnts ucont_val = {0.0, 0.0, 0.0};
118 PetscReal normal_velocity_mag = 0.0;
123 normal_velocity_mag = 0.0;
128 normal_velocity_mag = uin.
x;
130 normal_velocity_mag = uin.
y;
132 normal_velocity_mag = uin.
z;
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;
152 const PetscReal i_norm = (i - i_center) / (i_width / 2.0);
153 const PetscReal j_norm = (j - j_center) / (j_width / 2.0);
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;
162 if (normal_velocity_mag < 0.0) {
163 normal_velocity_mag = 0.0;
194 normal_velocity_mag = 0.0;
200 if (normal_velocity_mag != 0.0) {
201 const PetscReal signed_normal_vel = normal_velocity_mag * flow_direction_sign*user->
GridOrientation;
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);
206 ucont_val.
x = signed_normal_vel * area_i;
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);
213 ucont_val.
y = signed_normal_vel * area_j;
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);
220 ucont_val.
z = signed_normal_vel * area_k;
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);
225 ucont_arr[k][j][i] = ucont_val;
230 ierr = DMDAVecRestoreArray(fieldDM, fieldVec, &ucont_arr); CHKERRQ(ierr);
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);
244 PetscFunctionReturn(0);