9#define __FUNCT__ "SetInitialInteriorField"
17 PetscFunctionBeginUser;
26 if (strcmp(fieldName,
"Ucont") != 0) {
31 PetscFunctionReturn(0);
36 ierr = DMDAGetLocalInfo(user->
fda, &info); CHKERRQ(ierr);
38 const PetscInt im_phys = info.mx - 1;
39 const PetscInt jm_phys = info.my - 1;
40 const PetscInt km_phys = info.mz - 1;
47 (
double)u_cart, (
double)v_cart, (
double)w_cart,
54 PetscFunctionReturn(0);
58 const PetscBool needs_flow_dir = (PetscBool)(
62 PetscInt flow_axis = 0;
63 PetscReal flow_dir_sign = 1.0;
71 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_USER,
72 "Streamwise Constant and Poiseuille IC modes require either an INLET face or -flow_direction.");
73 flow_axis = (PetscInt)fd / 2;
74 flow_dir_sign = ((PetscInt)fd % 2 == 0) ? 1.0 : -1.0;
76 (
int)fd, (
int)flow_axis, (
double)flow_dir_sign);
80 Cmpnts ***csi_arr, ***eta_arr, ***zet_arr;
81 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, &csi_arr); CHKERRQ(ierr);
82 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, &eta_arr); CHKERRQ(ierr);
83 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, &zet_arr); CHKERRQ(ierr);
86 ierr = DMDAVecGetArray(user->
fda, user->
Ucont, &ucont_arr); CHKERRQ(ierr);
89 const PetscInt xs = info.xs, xe = info.xs + info.xm;
90 const PetscInt ys = info.ys, ye = info.ys + info.ym;
91 const PetscInt zs = info.zs, ze = info.zs + info.zm;
93 for (k = zs; k < ze; k++) {
94 for (j = ys; j < ye; j++) {
95 for (i = xs; i < xe; i++) {
108 const PetscBool is_interior = (i > 0 && i < im_phys &&
109 j > 0 && j < jm_phys &&
110 k > 0 && k < km_phys);
113 Cmpnts ucont_val = {0.0, 0.0, 0.0};
114 PetscReal normal_velocity_mag = 0.0;
124 PetscInt cs1, cs2, n1, n2;
125 if (flow_axis == 0) { cs1 = j; cs2 = k; n1 = jm_phys; n2 = km_phys; }
126 else if (flow_axis == 1) { cs1 = i; cs2 = k; n1 = im_phys; n2 = km_phys; }
127 else { cs1 = i; cs2 = j; n1 = im_phys; n2 = jm_phys; }
128 const PetscReal w1 = (PetscReal)(n1 - 2);
129 const PetscReal w2 = (PetscReal)(n2 - 2);
130 const PetscReal n1_norm = (cs1 - (1.0 + w1 / 2.0)) / (w1 / 2.0);
131 const PetscReal n2_norm = (cs2 - (1.0 + w2 / 2.0)) / (w2 / 2.0);
133 (1.0 - n1_norm * n1_norm) * (1.0 - n2_norm * n2_norm);
134 if (normal_velocity_mag < 0.0) normal_velocity_mag = 0.0;
143 if (normal_velocity_mag != 0.0) {
144 const PetscReal signed_vel = normal_velocity_mag * flow_dir_sign * user->
GridOrientation;
145 if (flow_axis == 0) {
146 const PetscReal area = sqrt(csi_arr[k][j][i].x * csi_arr[k][j][i].x +
147 csi_arr[k][j][i].y * csi_arr[k][j][i].y +
148 csi_arr[k][j][i].z * csi_arr[k][j][i].z);
149 ucont_val.
x = signed_vel * area;
150 }
else if (flow_axis == 1) {
151 const PetscReal area = sqrt(eta_arr[k][j][i].x * eta_arr[k][j][i].x +
152 eta_arr[k][j][i].y * eta_arr[k][j][i].y +
153 eta_arr[k][j][i].z * eta_arr[k][j][i].z);
154 ucont_val.
y = signed_vel * area;
156 const PetscReal area = sqrt(zet_arr[k][j][i].x * zet_arr[k][j][i].x +
157 zet_arr[k][j][i].y * zet_arr[k][j][i].y +
158 zet_arr[k][j][i].z * zet_arr[k][j][i].z);
159 ucont_val.
z = signed_vel * area;
162 ucont_arr[k][j][i] = ucont_val;
167 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucont, &ucont_arr); CHKERRQ(ierr);
170 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, &csi_arr); CHKERRQ(ierr);
171 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, &eta_arr); CHKERRQ(ierr);
172 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, &zet_arr); CHKERRQ(ierr);
176 PetscFunctionReturn(0);
180#define __FUNCT__ "LoadInitialUcont"
189 PetscFunctionBeginUser;
197 const char *cell_fields[] = {
"Ucat"};
205 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
206 "Unsupported file initial-condition field selector %d.",
211 PetscFunctionReturn(0);
215#define __FUNCT__ "PopulateInitialUcont"
224 PetscFunctionBeginUser;
230 PetscFunctionReturn(0);
234#define __FUNCT__ "FinalizeBlockState"
242 PetscFunctionBeginUser;
250 const char *staggered_fields[] = {
"Ucont"};
260 const char *cell_fields[] = {
"Ucat"};
268 PetscFunctionReturn(0);
273#define __FUNCT__ "SetInitialFluidState_FreshStart"
282 PetscFunctionBeginUser;
286 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
307 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
308 const char *staggered_fields[] = {
"Ucont"};
316 PetscFunctionReturn(0);
320#define __FUNCT__ "SetInitialFluidState_Load"
329 PetscFunctionBeginUser;
333 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
351 PetscFunctionReturn(0);
355#define __FUNCT__ "InitializeEulerianState"
365 PetscFunctionBeginUser;
390 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"FRESH START in ANALYTICAL mode. Initializing Analytical Solution type: %s (t=%.4f,step=%d).\n",
399 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
406 PetscFunctionReturn(0);
PetscErrorCode AnalyticalSolutionEngine(SimCtx *simCtx)
Dispatches to the appropriate analytical solution function based on simulation settings.
PetscErrorCode SynchronizePeriodicStaggeredFields(UserCtx *user, PetscInt num_fields, const char *field_names[])
Synchronizes persistent component-staggered vector fields.
PetscErrorCode ApplyBoundaryConditions(UserCtx *user)
Main boundary-condition orchestrator executed during solver timestepping.
PetscErrorCode SynchronizePeriodicCellFields(UserCtx *user, PetscInt num_fields, const char *field_names[])
Synchronizes periodic endpoint cells for a list of cell-centered fields.
static PetscErrorCode SetInitialFluidState_Load(SimCtx *simCtx)
Internal helper implementation: SetInitialFluidState_Load().
static PetscErrorCode SetInitialFluidState_FreshStart(SimCtx *simCtx)
Internal helper implementation: SetInitialFluidState_FreshStart().
PetscErrorCode SetInitialInteriorField(UserCtx *user, const char *fieldName)
Internal helper implementation: SetInitialInteriorField().
static PetscErrorCode LoadInitialUcont(UserCtx *user)
Load a staged file IC and return with Ucont populated.
PetscErrorCode InitializeEulerianState(SimCtx *simCtx)
Internal helper implementation: InitializeEulerianState().
PetscErrorCode PopulateInitialUcont(UserCtx *user)
Dispatch one fresh-start IC and return with Ucont populated.
static PetscErrorCode FinalizeBlockState(UserCtx *user)
Internal helper implementation: FinalizeBlockState().
PetscErrorCode ReadSimulationFields(UserCtx *user, PetscInt ti)
Reads binary field data for velocity, pressure, and other required vectors.
PetscErrorCode ReadFieldData(UserCtx *user, const char *field_name, Vec field_vec, PetscInt ti, const char *ext)
Reads data for a specific field from a file into the provided vector.
#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_TRACE
Very fine-grained tracing information for in-depth debugging.
@ LOG_INFO
Informational messages about program execution.
@ LOG_WARNING
Non-critical issues that warrant attention.
@ LOG_DEBUG
Detailed debugging information.
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled code block (typically a function).
PetscErrorCode UpdateSolverHistoryVectors(UserCtx *user)
Copies the current time step's solution fields into history vectors (e.g., U(t_n) -> U_o,...
PetscErrorCode UniformCart2Contra(UserCtx *user, PetscReal u, PetscReal v, PetscReal w)
Populate contravariant fluxes from one uniform Cartesian velocity.
PetscErrorCode Contra2Cart(UserCtx *user)
Reconstructs Cartesian velocity (Ucat) at cell centers from contravariant velocity (Ucont) defined on...
PetscErrorCode Cart2Contra(UserCtx *user)
Convert the ghosted Cartesian velocity field to contravariant face fluxes.
PetscErrorCode UpdateLocalGhosts(UserCtx *user, const char *fieldName)
Updates the local vector (including ghost points) from its corresponding global vector.
PetscReal icVelocityPhysical
PetscBool inletFaceDefined
BCFace identifiedInletBCFace
InitialConditionMode initialConditionMode
SimCtx * simCtx
Back-pointer to the master simulation context.
FlowDirection flowDirection
char * current_io_directory
char eulerianSource[PETSC_MAX_PATH_LEN]
FlowDirection
Primary flow direction for streamwise IC and Poiseuille modes.
char initialConditionDirectory[PETSC_MAX_PATH_LEN]
char AnalyticalSolutionType[PETSC_MAX_PATH_LEN]
@ IC_MODE_CONSTANT_CARTESIAN
@ IC_MODE_CONSTANT_STREAMWISE
Cmpnts InitialConstantContra
char _io_context_buffer[PETSC_MAX_PATH_LEN]
InitialConditionField initialConditionField
A 3D point or vector with PetscScalar components.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.