#include <petscpf.h>#include <petscdmswarm.h>#include <stdlib.h>#include <time.h>#include <math.h>#include <petsctime.h>#include <petscsys.h>#include <petscdmcomposite.h>#include <petscsystypes.h>#include "variables.h"#include "field_catalog.h"#include "ParticleSwarm.h"#include "walkingsearch.h"#include "grid.h"#include "logging.h"#include "io.h"#include "interpolation.h"#include "ParticleMotion.h"#include "BC_Handlers.h"#include "wallfunction.h"Go to the source code of this file.
Enumerations | |
| enum | MomentumRowType { MOM_ROW_PHYSICAL = 0 , MOM_ROW_FIXED_CONDITIONED , MOM_ROW_FIXED_HOMOGENEOUS , MOM_ROW_PERIODIC_DUPLICATE } |
| Classification of one staggered momentum row (location + component). More... | |
Functions | |
| PetscErrorCode | BoundarySystem_Validate (UserCtx *user) |
| (Public) Validates the consistency and compatibility of the parsed boundary condition system. | |
| PetscErrorCode | BoundaryCondition_Create (BCHandlerType handler_type, BoundaryCondition **new_bc_ptr) |
| (Private) Creates and configures a specific BoundaryCondition handler object. | |
| PetscErrorCode | BoundarySystem_Initialize (UserCtx *user, const char *bcs_filename) |
| Initializes the entire boundary system. | |
| PetscErrorCode | PropagateBoundaryConfigToCoarserLevels (SimCtx *simCtx) |
| Propagates boundary condition configuration from finest to all coarser multigrid levels. | |
| PetscErrorCode | BoundarySystem_ExecuteStep (UserCtx *user) |
| Executes one full boundary condition update cycle for a time step. | |
| PetscErrorCode | BoundarySystem_RefreshUbcs (UserCtx *user) |
| (Private) A lightweight execution engine that calls the UpdateUbcs() method on all relevant handlers. | |
| PetscErrorCode | BoundarySystem_Destroy (UserCtx *user) |
| Cleans up and destroys all boundary system resources. | |
| PetscErrorCode | CanRankServiceFace (const DMDALocalInfo *info, PetscInt IM_nodes_global, PetscInt JM_nodes_global, PetscInt KM_nodes_global, BCFace face_id, PetscBool *can_service_out) |
| Determines if the current MPI rank owns any part of a specified global face. | |
| PetscErrorCode | GetBoundaryFaceElements (UserCtx *user, BCFace face_id, BoundaryFaceElements *elements) |
| The elements of a boundary face this rank owns, as index ranges. | |
| PetscBool | BoundaryFaceHasWallShear (const BoundaryFaceConfig *face) |
| Reports whether a boundary face is a wall that exerts shear on the flow. | |
| static PetscBool | BoundaryFaceIsFreeSlipWall (const BoundaryFaceConfig *face) |
| Reports whether a boundary face is a free-slip wall: impenetrable, exerting no shear, and a plane across which the flow mirrors. | |
| MomentumRowType | ClassifyMomentumRow (UserCtx *user, PetscInt i, PetscInt j, PetscInt k, PetscInt component, PetscInt *ri, PetscInt *rj, PetscInt *rk) |
| Single source of truth for "which staggered momentum rows are unknowns". | |
| PetscBool | MomentumRowIsSolidMasked (const PetscReal ***nvert, PetscInt i, PetscInt j, PetscInt k, PetscInt component) |
| Reports whether a momentum row is masked out by the solid-cell field. | |
| PetscErrorCode | EnforceRHSBoundaryConditions (UserCtx *user) |
| Zeroes every momentum RHS row that does not carry an independent unknown. | |
| PetscErrorCode | SynchronizePeriodicCellFields (UserCtx *user, PetscInt num_fields, const FieldId field_ids[]) |
| Synchronizes periodic endpoint cells for a list of cell-centered fields. | |
| PetscErrorCode | SynchronizePeriodicFaceFields (UserCtx *user, char face_direction, PetscInt num_fields, const FieldId field_ids[]) |
| Synchronizes persistent fields belonging to one face family. | |
| PetscErrorCode | SynchronizePeriodicStaggeredFields (UserCtx *user, PetscInt num_fields, const FieldId field_ids[]) |
| Synchronizes persistent component-staggered vector fields. | |
| PetscErrorCode | PreparePeriodicQuickStencilFields (UserCtx *user, Vec local_vector_field, Vec local_scalar_field) |
| Repairs the outer adjacent periodic ghosts used by QUICK cell stencils. | |
| PetscErrorCode | SynchronizePeriodicLocalStaggeredField (UserCtx *user, Vec local_field) |
| Synchronizes one local-only component-staggered periodic work field. | |
| PetscErrorCode | ApplyMetricsPeriodicBCs (UserCtx *user) |
| (Orchestrator) Updates all metric-related fields in the local ghost cell regions for periodic boundaries. | |
| PetscErrorCode | ApplyPeriodicBCs (UserCtx *user, PetscBool final_cell_update) |
| Applies periodic boundary conditions by copying data across domain boundaries for all relevant fields. | |
| PetscErrorCode | UpdateDummyCells (UserCtx *user, FieldId field_id) |
| Fills the dummy cells on the non-periodic faces of one cell-centred field. | |
| PetscErrorCode | UpdateCornerNodes (UserCtx *user, FieldId field_id) |
| Fills the edge and corner dummy cells of one cell-centred field. | |
| PetscErrorCode | ApplyWallFunction (UserCtx *user) |
| Evaluates the selected wall law on every wall-face element and stores the wall stress. | |
| PetscErrorCode | LogWallModelDiagnostics (UserCtx *user) |
Appends one row of near-wall statistics to <run.analysis.metrics>/wall_model.csv. | |
| PetscErrorCode | LogBoundaryPressureDiagnostics (UserCtx *user) |
| Records each INLET and OUTLET face's area-weighted mean pressure this step. | |
| PetscErrorCode | FinalizePostProjectionCellFields (UserCtx *user) |
| Finalizes cell-centered fields after the projection step. | |
| PetscErrorCode | FinalizeCellFieldsFromBoundaryValues (UserCtx *user) |
Brings Ucat's and P's dummy cells, periodic endpoints, corners and ghosts in line with their interior values and the boundary values already in Ubcs. | |
| PetscErrorCode | ApplyBoundaryConditions (UserCtx *user) |
| Main boundary-condition orchestrator executed during solver timestepping. | |
| enum MomentumRowType |
Classification of one staggered momentum row (location + component).
| Enumerator | |
|---|---|
| MOM_ROW_PHYSICAL | Independent unknown governed by the momentum equation. |
| MOM_ROW_FIXED_CONDITIONED | Strong Dirichlet row; the value comes from ApplyBoundaryConditions(). |
| MOM_ROW_FIXED_HOMOGENEOUS | Dummy/tangential row carrying no unknown at all. |
| MOM_ROW_PERIODIC_DUPLICATE | Duplicate of a wrapped representative row (see |
Definition at line 191 of file Boundaries.h.
| PetscErrorCode BoundarySystem_Validate | ( | UserCtx * | user | ) |
(Public) Validates the consistency and compatibility of the parsed boundary condition system.
This function is the main entry point for all boundary condition validation. It should be called from the main setup sequence AFTER the configuration file has been parsed by ParseAllBoundaryConditions but BEFORE any BoundaryCondition handler objects are created.
It acts as a dispatcher, calling specialized private sub-validators for different complex BC setups (like driven flow) to ensure the combination of mathematical_type and handler_type across all six faces is physically and numerically valid. This provides a "fail-fast" mechanism to prevent users from running improperly configured simulations.
| user | The UserCtx for a single block, containing the populated boundary_faces configuration. |
(Public) Validates the consistency and compatibility of the parsed boundary condition system.
Definition at line 352 of file Boundaries.c.
| PetscErrorCode BoundaryCondition_Create | ( | BCHandlerType | handler_type, |
| BoundaryCondition ** | new_bc_ptr | ||
| ) |
(Private) Creates and configures a specific BoundaryCondition handler object.
This function acts as a factory. Based on the requested handler_type, it allocates a BoundaryCondition object and populates it with the correct set of function pointers corresponding to that specific behavior.
| handler_type | The specific handler to create (e.g., BC_HANDLER_WALL_NOSLIP). | |
| [out] | new_bc_ptr | A pointer to where the newly created BoundaryCondition object's address will be stored. |
(Private) Creates and configures a specific BoundaryCondition handler object.
Definition at line 265 of file Boundaries.c.
| PetscErrorCode BoundarySystem_Initialize | ( | UserCtx * | user, |
| const char * | bcs_filename | ||
| ) |
Initializes the entire boundary system.
| [in,out] | user | Finest-level block context receiving parsed face configuration. |
| bcs_filename | Path to the generated boundary-condition definition file. |
Initializes the entire boundary system.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Boundaries.h.
Definition at line 412 of file Boundaries.c.
| PetscErrorCode PropagateBoundaryConfigToCoarserLevels | ( | SimCtx * | simCtx | ) |
Propagates boundary condition configuration from finest to all coarser multigrid levels.
Coarser levels need BC type information for geometric operations (e.g., periodic corrections) but do NOT need full handler objects since timestepping only occurs at the finest level. This function copies the boundary_faces configuration down the hierarchy.
| simCtx | The master SimCtx containing the multigrid hierarchy |
Propagates boundary condition configuration from finest to all coarser multigrid levels.
Definition at line 530 of file Boundaries.c.
| PetscErrorCode BoundarySystem_ExecuteStep | ( | UserCtx * | user | ) |
Executes one full boundary condition update cycle for a time step.
| [in,out] | user | Block context whose boundary handlers update target values and fluxes. |
Executes one full boundary condition update cycle for a time step.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Boundaries.h.
Definition at line 600 of file Boundaries.c.
| PetscErrorCode BoundarySystem_RefreshUbcs | ( | UserCtx * | user | ) |
(Private) A lightweight execution engine that calls the UpdateUbcs() method on all relevant handlers.
This function's sole purpose is to re-evaluate the target boundary values (ubcs) for flow-dependent boundary conditions (e.g., Symmetry, Outlets) after the interior velocity field has changed, such as after the projection step.
It operates based on a "pull" model: it iterates through all boundary handlers and executes their UpdateUbcs method only if the handler has provided one. This makes the system extensible, as new flow-dependent handlers can be added without changing this engine. Handlers for fixed boundary conditions (e.g., a wall with a constant velocity) will have their UpdateUbcs pointer set to NULL and will be skipped automatically.
ucont and does NOT perform flux balancing.| user | The main UserCtx struct. |
(Private) A lightweight execution engine that calls the UpdateUbcs() method on all relevant handlers.
Definition at line 1020 of file Boundaries.c.
| PetscErrorCode BoundarySystem_Destroy | ( | UserCtx * | user | ) |
Cleans up and destroys all boundary system resources.
| [in,out] | user | Block context whose boundary handlers and temporary state are released. |
Cleans up and destroys all boundary system resources.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Boundaries.h.
Definition at line 1070 of file Boundaries.c.
| PetscErrorCode CanRankServiceFace | ( | const DMDALocalInfo * | info, |
| PetscInt | IM_nodes_global, | ||
| PetscInt | JM_nodes_global, | ||
| PetscInt | KM_nodes_global, | ||
| BCFace | face_id, | ||
| PetscBool * | can_service_out | ||
| ) |
Determines if the current MPI rank owns any part of a specified global face.
This function is a general utility for parallel boundary operations. It checks if the local domain of the current MPI rank is adjacent to a specified global boundary face. A rank "services" a face if it owns the cells adjacent to that global boundary and has a non-zero extent (i.e., owns at least one cell) in the tangential dimensions of that face.
| info | Pointer to the DMDALocalInfo for the current rank's DA. | |
| IM_nodes_global | Global number of nodes in the I-direction (e.g., user->IM + 1 if user->IM is cell count). | |
| JM_nodes_global | Global number of nodes in the J-direction. | |
| KM_nodes_global | Global number of nodes in the K-direction. | |
| face_id | The specific global face (e.g., BC_FACE_NEG_Z) to check. | |
| [out] | can_service_out | Pointer to a PetscBool; set to PETSC_TRUE if the rank services the face, PETSC_FALSE otherwise. |
Determines if the current MPI rank owns any part of a specified global face.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Boundaries.h.
Definition at line 22 of file Boundaries.c.
| PetscErrorCode GetBoundaryFaceElements | ( | UserCtx * | user, |
| BCFace | face_id, | ||
| BoundaryFaceElements * | elements | ||
| ) |
The elements of a boundary face this rank owns, as index ranges.
Purely local: it reads the block's decomposition through CanRankServiceFace() and GetOwnedInteriorCellBounds(), allocates nothing and communicates nothing, so a per-pass loop over a face's elements may call it freely. Edge and corner elements of the face are those of the interior cells beside it; the dummy rows of the other faces are not included.
| [in] | user | Block context. |
| [in] | face_id | Face. |
| [out] | elements | Axes, the face's metric/flux layer, and the owned tangential ranges; n is zero along both axes when this rank does not serve the face. |
The elements of a boundary face this rank owns, as index ranges.
Definition at line 105 of file Boundaries.c.
| PetscBool BoundaryFaceHasWallShear | ( | const BoundaryFaceConfig * | face | ) |
Reports whether a boundary face is a wall that exerts shear on the flow.
Every WALL face is impenetrable, and code that needs only that tests the type. A free-slip wall exerts no shear, so the wall model, its eddy viscosity on the wall face, and the cells it writes belong only to the walls this reports: a free-slip face uses the interior face average there instead, as a symmetry plane does.
| face | Boundary face configuration. |
Reports whether a boundary face is a wall that exerts shear on the flow.
Definition at line 9 of file Boundaries.c.
|
inlinestatic |
Reports whether a boundary face is a free-slip wall: impenetrable, exerting no shear, and a plane across which the flow mirrors.
| face | Boundary face configuration. |
Definition at line 180 of file Boundaries.h.
| MomentumRowType ClassifyMomentumRow | ( | UserCtx * | user, |
| PetscInt | i, | ||
| PetscInt | j, | ||
| PetscInt | k, | ||
| PetscInt | component, | ||
| PetscInt * | ri, | ||
| PetscInt * | rj, | ||
| PetscInt * | rk | ||
| ) |
Single source of truth for "which staggered momentum rows are unknowns".
Every consumer of the momentum system must agree on which rows the solver is responsible for, and every consumer must derive that answer from this function rather than restating the index arithmetic locally. Three independent restatements previously disagreed, and the disagreement was silent: the residual assembly skipped the periodic duplicate column at index 0 while nothing zeroed it, so ComputeTotalResidual()'s BDF term accumulated there without bound and the reported residual norm stopped describing the state.
The classification depends only on user->info, the configured boundary types, and the queried index; it reads no field data and performs no communication, so it is safe to call inside assembly loops.
Periodicity of an axis is taken from that axis's NEGATIVE face, matching ComputeRHS() and TransferPeriodicStaggeredFieldByDirection(). A periodic axis is expected to carry PERIODIC on both of its faces.
Callers act on the classification differently, and both actions are correct:
EnforceRHSBoundaryConditions()) zero every non-physical row, because the value there is imposed immediately afterwards by the boundary sweep or the periodic synchronisation;F = X - U_conditioned, F = X, F = X_dup - X_rep), because a zeroed row would leave a zero Jacobian row.| [in] | user | Block context supplying info and boundary_faces. |
| [in] | i | Location index along xi. |
| [in] | j | Location index along eta. |
| [in] | k | Location index along zeta. |
| [in] | component | Staggered component of the row (0 = xi, 1 = eta, 2 = zeta). |
| [out] | ri | Representative xi index; equals i unless the row wraps. |
| [out] | rj | Representative eta index; equals j unless the row wraps. |
| [out] | rk | Representative zeta index; equals k unless the row wraps. |
Single source of truth for "which staggered momentum rows are unknowns".
Pure index/boundary-type arithmetic: no field reads, no communication. Precedence matters. A conditioned row is reported first because its explicit Dirichlet value is more specific than the homogeneous fallback, and a periodic duplicate is reported before the homogeneous case because the Newton path needs its representative index to build F = X_dup - X_rep.
Definition at line 139 of file Boundaries.c.
| PetscBool MomentumRowIsSolidMasked | ( | const PetscReal *** | nvert, |
| PetscInt | i, | ||
| PetscInt | j, | ||
| PetscInt | k, | ||
| PetscInt | component | ||
| ) |
Reports whether a momentum row is masked out by the solid-cell field.
ComputeRHS() zeroes the residual at a solid cell and at the staggered rows whose downstream neighbour is solid, so those rows carry no equation. A solver that only marches on the residual needs nothing more: a zero residual means no update. A solver that assembles a matrix and solves F(X) = 0 does, because such a row has a zero Jacobian row and a zero column, leaving the unknown undetermined. Those rows must be constrained like any other row that carries no unknown.
The condition mirrors the residual's own masking exactly. If one changes, so must the other, or the assembled operator stops matching the residual it preconditions.
| [in] | nvert | Ghosted solid-cell field, or NULL to apply no masking. |
| [in] | i | Location index along xi. |
| [in] | j | Location index along eta. |
| [in] | k | Location index along zeta. |
| [in] | component | Staggered component of the row (0 = xi, 1 = eta, 2 = zeta). |
PETSC_TRUE when the row is masked and therefore carries no unknown.Reports whether a momentum row is masked out by the solid-cell field.
Full API contract is documented with the header declaration in include/Boundaries.h.
Definition at line 193 of file Boundaries.c.
| PetscErrorCode EnforceRHSBoundaryConditions | ( | UserCtx * | user | ) |
Zeroes every momentum RHS row that does not carry an independent unknown.
The set of such rows is not restated here: each owned location and component is asked of ClassifyMomentumRow(), and anything other than MOM_ROW_PHYSICAL is zeroed. That covers, without enumerating them,
ApplyBoundaryConditions() has just set;SynchronizePeriodicStaggeredFields() copies from the wrapped master.The last case is the one that must not be skipped. ComputeRHS() leaves the transverse components of a periodic duplicate column untouched, so a row left unzeroed here retains its previous contents while ComputeTotalResidual() adds the BDF term on top of them on every call. The residual norm then grows by |dU|/dt per evaluation regardless of the state, and no pseudo-time iteration can reduce it.
Call immediately after the RHS vector is fully assembled (spatial + temporal terms) and before it is used in a time-stepping update.
| user | The UserCtx for the specific block being computed. |
Zeroes every momentum RHS row that does not carry an independent unknown.
The sweep is deliberately expressed over every owned location rather than over the six boundary slabs: restating "which indices can be non-physical" here is exactly the duplication that let the periodic duplicate column go unzeroed. ClassifyMomentumRow() is a handful of integer comparisons and the walk is a single pass with no stencil access, which is negligible next to the several ghosted stencil passes ComputeRHS() has already made over the same range. MomentumNewtonKrylov_ApplyConstraints() walks the same range the same way.
Definition at line 224 of file Boundaries.c.
| PetscErrorCode SynchronizePeriodicCellFields | ( | UserCtx * | user, |
| PetscInt | num_fields, | ||
| const FieldId | field_ids[] | ||
| ) |
Synchronizes periodic endpoint cells for a list of cell-centered fields.
The fields are first communicated from global to local storage. Each periodic direction is then transferred in i-j-k order, with an intermediate ghost refresh after every active direction so periodic edges and corners inherit the values established by earlier directions. Only global duplicate planes in active periodic directions are repaired; non-periodic directions are untouched. The routine is a no-op, including no local refresh, when every direction is nonperiodic. During active periodic synchronization it internally refreshes the local vectors, but it is not a general replacement for UpdateLocalGhosts().
Supported fields are selected by FIELD_CAPABILITY_PERIODIC_CELL_SYNC in the field catalog.
| user | The main UserCtx struct. |
| num_fields | The number of entries in field_ids. |
| field_ids | The cell-centered fields to synchronize. |
Synchronizes periodic endpoint cells for a list of cell-centered fields.
Full API contract is documented with the header declaration in include/Boundaries.h.
Definition at line 1474 of file Boundaries.c.
| PetscErrorCode SynchronizePeriodicFaceFields | ( | UserCtx * | user, |
| char | face_direction, | ||
| PetscInt | num_fields, | ||
| const FieldId | field_ids[] | ||
| ) |
Synchronizes persistent fields belonging to one face family.
The function performs deterministic I/J/K directional passes with an intermediate ghost refresh after each active periodic direction. It updates persistent global seam/dummy values only; face-specific local stencil repair remains a separate operation.
| user | The main UserCtx struct. | |
| face_direction | Face family shared by every field (‘'i’,'j', or'k'`). | |
| [in] | num_fields | Count of registered face fields. |
| field_ids | Registered persistent face-field identities. |
Definition at line 1658 of file Boundaries.c.
| PetscErrorCode SynchronizePeriodicStaggeredFields | ( | UserCtx * | user, |
| PetscInt | num_fields, | ||
| const FieldId | field_ids[] | ||
| ) |
Synchronizes persistent component-staggered vector fields.
The function performs deterministic I/J/K endpoint transfers with an intermediate ghost refresh after every active periodic direction. Currently Ucont is the only registered component-staggered field.
| user | The main UserCtx struct. |
| num_fields | Number of entries in field_ids. |
| field_ids | Registered component-staggered field identities. |
Synchronizes persistent component-staggered vector fields.
Definition at line 1850 of file Boundaries.c.
| PetscErrorCode PreparePeriodicQuickStencilFields | ( | UserCtx * | user, |
| Vec | local_vector_field, | ||
| Vec | local_scalar_field | ||
| ) |
Repairs the outer adjacent periodic ghosts used by QUICK cell stencils.
The supplied local vectors must already contain a current PETSc periodic ghost exchange. The vector and scalar fields are repaired two logical cells across each active periodic seam so QUICK's i-1/i+2 equivalents are valid.
| user | Main block context containing periodic boundary metadata. |
| local_vector_field | Ghosted three-component cell-centered field. |
| local_scalar_field | Ghosted scalar cell-centered field. |
Repairs the outer adjacent periodic ghosts used by QUICK cell stencils.
Definition at line 1865 of file Boundaries.c.
| PetscErrorCode SynchronizePeriodicLocalStaggeredField | ( | UserCtx * | user, |
| Vec | local_field | ||
| ) |
Synchronizes one local-only component-staggered periodic work field.
This helper communicates locally computed owned entries, establishes the normal-component periodic endpoint values, and communicates once more.
| user | Main block context containing periodic boundary metadata. |
| local_field | Ghosted local component-staggered vector. |
Synchronizes one local-only component-staggered periodic work field.
Definition at line 1931 of file Boundaries.c.
| PetscErrorCode ApplyMetricsPeriodicBCs | ( | UserCtx * | user | ) |
(Orchestrator) Updates all metric-related fields in the local ghost cell regions for periodic boundaries.
This function synchronizes cell-centered Aj and the persistent I/J/K metric face families through the canonical MPI-safe synchronizers.
| user | The main UserCtx struct. |
(Orchestrator) Updates all metric-related fields in the local ghost cell regions for periodic boundaries.
Definition at line 1971 of file Boundaries.c.
| PetscErrorCode ApplyPeriodicBCs | ( | UserCtx * | user, |
| PetscBool | final_cell_update | ||
| ) |
Applies periodic boundary conditions by copying data across domain boundaries for all relevant fields.
This is the canonical periodic orchestrator for geometric consistency. It updates Ucat, P, and Nvert through the generic cell synchronizer and updates staggered Ucont through the component-staggered synchronizer.
Future extension rule: add new periodic variables by extending the existing field string dispatchers and invoking them from this orchestrator.
| user | The main UserCtx struct. |
| final_cell_update | PETSC_FALSE leaves the cell fields' last ghost update to the caller, which must update Ucat, P and Nvert before anything reads their local vectors; PETSC_TRUE leaves them current. |
Applies periodic boundary conditions by copying data across domain boundaries for all relevant fields.
Definition at line 1998 of file Boundaries.c.
Fills the dummy cells on the non-periodic faces of one cell-centred field.
A cell-centred field stores cell c at index c+1; index 0 and the last index along each axis are dummy cells outside the domain. Stencils and node averages that reach across a boundary read them, so their value is the field's boundary condition:
| Field | Dummy value | Condition it encodes |
|---|---|---|
Ucat | 2 Ubcs - interior | face average equals the handler's boundary velocity |
P | the adjacent interior cell | zero normal gradient |
Psi | the adjacent interior cell | zero normal gradient (no scalar flux) |
Any other field is refused: its condition must be chosen for the quantity before its dummy cells are filled (see 11. Derived Statistics At Non-Periodic Boundaries for why no default serves every quantity).
Pressure. Zero gradient is the condition the pressure solve already implies on every non-periodic face: the Poisson operator drops each boundary face's term, the dummy rows are identities with a zero right-hand side, and the projection corrects interior faces only. Nothing in the solve reads these values; filling them makes P_nodal and near-wall pressure gradients (the Cabot wall model) consistent with that condition, instead of averaging in a dummy value that stays at its initial zero. A pressure boundary condition (a far field, or a pressure outlet) will set its dummy value here as well, but that alone changes nothing the solve sees; see 6b. Pressure Boundary Conditions for what has to change with it.
Eddy viscosity. Mirrored, zero gradient, across a free-slip wall only. The flow mirrors there, so the face value the viscous flux averages must be the interior one, as on the corresponding interior face of the full, unmirrored domain. A wall that exerts shear replaces the face value outright (the wall model's, or zero), and the eddy viscosity's dummy cells on every other face are not written here.
Periodic faces are skipped: the periodic synchronizers own them. Only the flat part of each face is written (shrunken loop ranges); edges and corners are filled afterwards by UpdateCornerNodes from these values.
| user | Block context supplying the layout, face types, and Ubcs. |
| field_id | Cell-centred field to fill: FIELD_ID_UCAT, FIELD_ID_P, FIELD_ID_PSI, or FIELD_ID_NU_T. |
PETSC_ERR_ARG_WRONG for a field that is not cell-centred, PETSC_ERR_SUP for one with no boundary rule.Fills the dummy cells on the non-periodic faces of one cell-centred field.
Full API contract is documented with the header declaration in include/Boundaries.h.
Definition at line 2037 of file Boundaries.c.
Fills the edge and corner dummy cells of one cell-centred field.
Call after the face dummy cells are final, both periodic (the periodic synchronizers) and non-periodic (UpdateDummyCells). Each edge dummy cell becomes the mean of its two face-adjacent dummy cells; the edges along the Z faces are done first, so the corners the remaining edges pass through are filled from finished edges. Across a free-slip wall the flow is the mirror image of the flow inside, so an edge cell beside one is instead the mirror image of its neighbour across that wall: a scalar copied, a velocity with its component along the wall's metric reversed. That keeps a free-slip wall exactly a plane of symmetry up to its edges.
| user | Block context supplying the layout. |
| field_id | Cell-centred field whose edges and corners are filled. |
PETSC_ERR_ARG_WRONG for a field that is not cell-centred.Fills the edge and corner dummy cells of one cell-centred field.
Full API contract is documented with the header declaration in include/Boundaries.h.
Definition at line 2183 of file Boundaries.c.
| PetscErrorCode ApplyWallFunction | ( | UserCtx * | user | ) |
Evaluates the selected wall law on every wall-face element and stores the wall stress.
For each element of a face whose boundary exerts shear (no-slip or moving wall; free-slip exerts none), the law is evaluated from the resolved velocity of the reference cell - the second cell from the wall - relative to the wall's velocity, at that cell's wall distance, and gives a friction velocity u_tau. The kinematic wall shear stress u_tau^2, directed against the reference cell's wall-parallel motion, is written to Wall_Stress in the face's own dummy cell, oriented as that face's viscous flux per unit area; ComputeViscous() applies it on the wall face in place of a gradient flux. The wall-normal flux through the face is set to zero.
The resolved velocity is never modified, so the momentum equation, the subgrid closure, the dummy cells and every other boundary condition read the same near-wall velocity. A cell beside two walls has one element on each, with its own reference cell and stress. Friction_Velocity holds, per first cell, the RMS of u_tau over its wall faces, and LogWallModelDiagnostics reduces per-element statistics.
Distances come from the cell Jacobians and the wall-face area: half the first cell's thickness, and the first cell's full thickness plus half the second's. A rank must own at least three nodes normal to each wall it serves, so the reference cell is in its block; a layout that violates this is refused.
Cabot may return a negative friction velocity when an adverse pressure gradient reverses its wall-layer balance; the stress then acts along the reference flow.
| user | Block context whose Ucat is the current pass's reconstruction. |
PETSC_ERR_ARG_OUTOFRANGE for a layout that does not reach the reference cell; PETSC_ERR_FP for a non-finite friction velocity.Evaluates the selected wall law on every wall-face element and stores the wall stress.
Definition at line 2314 of file Boundaries.c.
| PetscErrorCode LogWallModelDiagnostics | ( | UserCtx * | user | ) |
Appends one row of near-wall statistics to <run.analysis.metrics>/wall_model.csv.
Reduces the state ApplyWallFunction accumulated over the wall faces this rank owns and writes the run-wide row from rank 0. y+ is the column that matters: it says whether the first cell sits where the selected law is valid, and no stored field can answer that after the fact.
A no-op when no wall model is active. When a wall model is active but no cell was corrected - wall functions enabled on a case with no WALL face - it warns and writes nothing rather than emitting a row of zeros.
Collective on the block's communicator; call it on every rank, once per step, after ApplyWallFunction.
| [in] | user | Block context whose wall-model pass has already run this step. |
Appends one row of near-wall statistics to <run.analysis.metrics>/wall_model.csv.
Full API contract is documented with the header declaration in include/Boundaries.h.
Definition at line 2541 of file Boundaries.c.
| PetscErrorCode LogBoundaryPressureDiagnostics | ( | UserCtx * | user | ) |
Records each INLET and OUTLET face's area-weighted mean pressure this step.
Appends one row per such face to <analysis_dir>/boundary_pressure.csv: the step, the physical time, the face, its type, its open area, and the mean of the pressure in the first interior cells beside it, weighted by their face areas, in physical units. Edge and corner cells and cells blanked by an immersed body are left out, as in the outlet's flux sum. Pressure carries an arbitrary constant, so the difference between two faces' rows is the meaningful quantity: the pressure drop across the domain, the observable for a duct's friction factor and for the transient that enforces a change in an inflow-outflow domain's flow rate. A no-op when the block has no INLET or OUTLET face; in a multi-block run only the first block's faces are recorded, as in inlet_flow.csv.
Collective on PETSC_COMM_WORLD; call it on every rank, once per step, after the projection.
| [in] | user | Block context whose pressure is current for this step. |
Records each INLET and OUTLET face's area-weighted mean pressure this step.
Definition at line 2730 of file Boundaries.c.
| PetscErrorCode FinalizePostProjectionCellFields | ( | UserCtx * | user | ) |
Finalizes cell-centered fields after the projection step.
This function completes the cell-centered state derived from the final, divergence-free Ucont produced by Projection. It fills non-periodic Ucat dummy faces, synchronizes periodic Ucat and P endpoints, resolves edges and corners, and refreshes the corresponding local vectors.
This function is fundamentally different from ApplyBoundaryConditions: it does NOT modify Ucont, reapply wall functions, or rerun the full physical boundary-condition workflow.
WORKFLOW:
Ucat and any flow-dependent Ubcs targets.Ucat and P.| user | The main UserCtx struct, containing all simulation state. |
Finalizes cell-centered fields after the projection step.
Full API contract is documented with the header declaration in include/Boundaries.h.
Definition at line 2814 of file Boundaries.c.
| PetscErrorCode FinalizeCellFieldsFromBoundaryValues | ( | UserCtx * | user | ) |
Brings Ucat's and P's dummy cells, periodic endpoints, corners and ghosts in line with their interior values and the boundary values already in Ubcs.
The part of FinalizePostProjectionCellFields() that does not ask the handlers to refresh Ubcs, for a caller that sets the boundary values itself. Collective.
| [in,out] | user | Block whose global Ucat, P and Ubcs are current. |
Brings Ucat's and P's dummy cells, periodic endpoints, corners and ghosts in line with their interior values and the boundary values already in Ubcs.
Definition at line 2837 of file Boundaries.c.
| PetscErrorCode ApplyBoundaryConditions | ( | UserCtx * | user | ) |
Main boundary-condition orchestrator executed during solver timestepping.
This routine performs the full BC workflow for the current block, including dynamic boundary refresh, periodic transfer, dummy/corner updates, and optional wall-function corrections in the same order expected by the runtime solver. It may iterate boundary updates to enforce coupled boundary dependencies.
| user | The main UserCtx struct containing field vectors and boundary system state. |
Main boundary-condition orchestrator executed during solver timestepping.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Boundaries.h.
Definition at line 2992 of file Boundaries.c.