|
PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
|
#include "BC_Handlers.h"Go to the source code of this file.
Data Structures | |
| struct | InletConstantData |
| Private data structure for the Constant Velocity Inlet handler. More... | |
| struct | InletParabolicData |
| Private data structure for the Parabolic Velocity Inlet handler. More... | |
| struct | DrivenConstantData |
| Private data structure for the handler. More... | |
Macros | |
| #define | __FUNCT__ "Validate_DrivenFlowConfiguration" |
| #define | __FUNCT__ "Create_WallNoSlip" |
| #define | __FUNCT__ "Apply_WallNoSlip" |
| #define | __FUNCT__ "Create_InletConstantVelocity" |
| #define | __FUNCT__ "Initialize_InletConstantVelocity" |
| #define | __FUNCT__ "PreStep_InletConstantVelocity" |
| #define | __FUNCT__ "Apply_InletConstantVelocity" |
| #define | __FUNCT__ "PostStep_InletConstantVelocity" |
| #define | __FUNCT__ "Destroy_InletConstantVelocity" |
| #define | __FUNCT__ "Create_InletParabolicProfile" |
| #define | __FUNCT__ "Initialize_InletParabolicProfile" |
| #define | __FUNCT__ "PreStep_InletParabolicProfile" |
| #define | __FUNCT__ "Apply_InletParabolicProfile" |
| #define | __FUNCT__ "PostStep_InletParabolicProfile" |
| #define | __FUNCT__ "Destroy_InletParabolicProfile" |
| #define | __FUNCT__ "Create_OutletConservation" |
| #define | __FUNCT__ "PreStep_OutletConservation" |
| #define | __FUNCT__ "Apply_OutletConservation" |
| #define | __FUNCT__ "PostStep_OutletConservation" |
| #define | __FUNCT__ "Create_PeriodicDrivenConstant" |
| #define | __FUNCT__ "Initialize_PeriodicDrivenConstant" |
| #define | __FUNCT__ "PreStep_PeriodicDrivenConstant" |
| #define | __FUNCT__ "Apply_PeriodicDrivenConstant" |
| #define | __FUNCT__ "Destroy_PeriodicDrivenConstant" |
Functions | |
| PetscErrorCode | Validate_DrivenFlowConfiguration (UserCtx *user) |
| (Private) Validates all consistency rules for a driven flow (channel/pipe) setup. | |
| static PetscErrorCode | Apply_WallNoSlip (BoundaryCondition *self, BCContext *ctx) |
| (Handler Action) Applies the no-slip wall condition to a specified face. | |
| PetscErrorCode | Create_WallNoSlip (BoundaryCondition *bc) |
| (Handler Constructor) Populates a BoundaryCondition object with No-Slip Wall behavior. | |
| static PetscErrorCode | Initialize_InletConstantVelocity (BoundaryCondition *self, BCContext *ctx) |
| (Handler Action) Initializes the constant velocity inlet handler. | |
| static PetscErrorCode | PreStep_InletConstantVelocity (BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow_contribution, PetscReal *local_outflow_contribution) |
| (Handler PreStep) No preparation needed for constant velocity inlet. | |
| static PetscErrorCode | Apply_InletConstantVelocity (BoundaryCondition *self, BCContext *ctx) |
| (Handler Action) Applies the constant velocity inlet condition. | |
| static PetscErrorCode | PostStep_InletConstantVelocity (BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow_contribution, PetscReal *local_outflow_contribution) |
| (Handler PostStep) Measures actual inflow flux through the constant velocity inlet face. | |
| static PetscErrorCode | Destroy_InletConstantVelocity (BoundaryCondition *self) |
| (Handler Destructor) Frees memory for the Constant Velocity Inlet. | |
| PetscErrorCode | Create_InletConstantVelocity (BoundaryCondition *bc) |
| Configures a BoundaryCondition object to behave as a constant velocity inlet. | |
| static PetscErrorCode | Initialize_InletParabolicProfile (BoundaryCondition *self, BCContext *ctx) |
| (Handler Action) Initializes the parabolic inlet handler. | |
| static PetscErrorCode | PreStep_InletParabolicProfile (BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow_contribution, PetscReal *local_outflow_contribution) |
| (Handler PreStep) No preparation needed for parabolic inlet. | |
| static PetscErrorCode | Apply_InletParabolicProfile (BoundaryCondition *self, BCContext *ctx) |
| (Handler Action) Applies the parabolic velocity inlet condition. | |
| static PetscErrorCode | PostStep_InletParabolicProfile (BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow_contribution, PetscReal *local_outflow_contribution) |
| (Handler PostStep) Measures actual inflow flux through the parabolic inlet face. | |
| static PetscErrorCode | Destroy_InletParabolicProfile (BoundaryCondition *self) |
| (Handler Destructor) Frees memory for the Parabolic Velocity Inlet. | |
| PetscErrorCode | Create_InletParabolicProfile (BoundaryCondition *bc) |
| (Handler Constructor) Populates a BoundaryCondition object with Parabolic Inlet behavior. | |
| static PetscErrorCode | PreStep_OutletConservation (BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow_contribution, PetscReal *local_outflow_contribution) |
| (Handler Action) Measures the current, uncorrected flux passing through a SINGLE outlet face. | |
| static PetscErrorCode | Apply_OutletConservation (BoundaryCondition *self, BCContext *ctx) |
| (Handler Action) Applies mass conservation correction to the outlet face. | |
| static PetscErrorCode | PostStep_OutletConservation (BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow_contribution, PetscReal *local_outflow_contribution) |
| (Handler PostStep) Measures corrected outflow flux for verification. | |
| PetscErrorCode | Create_OutletConservation (BoundaryCondition *bc) |
| (Handler Constructor) Populates a BoundaryCondition object with Outlet Conservation behavior. | |
| PetscErrorCode | Create_PeriodicGeometric (BoundaryCondition *bc) |
| static PetscErrorCode | Initialize_PeriodicDrivenConstant (BoundaryCondition *self, BCContext *ctx) |
| (Handler Initialize) Initializes the handler by validating its configuration and parsing parameters. | |
| static PetscErrorCode | PreStep_PeriodicDrivenConstant (BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow_contribution, PetscReal *local_outflow_contribution) |
| (Handler PreStep) Measures current fluxes and calculates the correction terms for the timestep. | |
| static PetscErrorCode | Apply_PeriodicDrivenConstant (BoundaryCondition *self, BCContext *ctx) |
| (Handler Apply) Applies the immediate "Boundary Trim" velocity correction to the periodic face. | |
| static PetscErrorCode | Destroy_PeriodicDrivenConstant (BoundaryCondition *self) |
| (Handler Destructor) Frees the memory allocated for the handler's private data. | |
| PetscErrorCode | Create_PeriodicDrivenConstant (BoundaryCondition *bc) |
| (Handler Constructor) Creates and configures a BoundaryCondition object for a driven periodic flow with a constant, user-defined target flux. | |
| struct InletConstantData |
Private data structure for the Constant Velocity Inlet handler.
Definition at line 339 of file BC_Handlers.c.
| Data Fields | ||
|---|---|---|
| PetscReal | normal_velocity | |
| struct InletParabolicData |
Private data structure for the Parabolic Velocity Inlet handler.
Stores the peak velocity and pre-computed cross-stream geometry needed to evaluate the parabolic profile at each boundary node.
Definition at line 743 of file BC_Handlers.c.
| struct DrivenConstantData |
Private data structure for the handler.
Definition at line 1769 of file BC_Handlers.c.
| Data Fields | ||
|---|---|---|
| char | direction | |
| PetscReal | targetVolumetricFlux | |
| PetscReal | boundaryVelocityCorrection | |
| PetscBool | isMasterController | |
| PetscBool | applyBoundaryTrim | |
| #define __FUNCT__ "Validate_DrivenFlowConfiguration" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "Create_WallNoSlip" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "Apply_WallNoSlip" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "Create_InletConstantVelocity" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "Initialize_InletConstantVelocity" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "PreStep_InletConstantVelocity" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "Apply_InletConstantVelocity" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "PostStep_InletConstantVelocity" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "Destroy_InletConstantVelocity" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "Create_InletParabolicProfile" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "Initialize_InletParabolicProfile" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "PreStep_InletParabolicProfile" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "Apply_InletParabolicProfile" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "PostStep_InletParabolicProfile" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "Destroy_InletParabolicProfile" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "Create_OutletConservation" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "PreStep_OutletConservation" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "Apply_OutletConservation" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "PostStep_OutletConservation" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "Create_PeriodicDrivenConstant" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "Initialize_PeriodicDrivenConstant" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "PreStep_PeriodicDrivenConstant" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "Apply_PeriodicDrivenConstant" |
Definition at line 10 of file BC_Handlers.c.
| #define __FUNCT__ "Destroy_PeriodicDrivenConstant" |
Definition at line 10 of file BC_Handlers.c.
| PetscErrorCode Validate_DrivenFlowConfiguration | ( | UserCtx * | user | ) |
(Private) Validates all consistency rules for a driven flow (channel/pipe) setup.
This function enforces a strict set of rules to ensure a driven flow simulation is configured correctly. It is called by the main BoundarySystem_Validate dispatcher.
The validation rules are checked in a specific order:
DRIVEN_ handler is active. If not, the function returns immediately.INLET, OUTLET, or FARFIELD boundary conditions exist anywhere in the domain, as they are physically incompatible with a pressure-driven flow model.mathematical_type PERIODIC.DRIVEN_ handler type.| user | The UserCtx for a single block. |
Definition at line 27 of file BC_Handlers.c.
|
static |
(Handler Action) Applies the no-slip wall condition to a specified face.
This function enforces zero velocity at the wall by:
NOTE: Unlike the legacy code, this does NOT set ucat[ghost]. The orchestrator's UpdateDummyCells function handles ghost cell extrapolation uniformly for all BC types.
| self | The BoundaryCondition object (unused for this simple handler) |
| ctx | BCContext containing UserCtx and face_id |
Definition at line 172 of file BC_Handlers.c.
| PetscErrorCode Create_WallNoSlip | ( | BoundaryCondition * | bc | ) |
(Handler Constructor) Populates a BoundaryCondition object with No-Slip Wall behavior.
Configures a BoundaryCondition object to behave as a no-slip, stationary wall.
A no-slip wall is simple and requires only the Apply method:
Initialize is NULL)PreStep and PostStep are NULL)Apply)Destroy is NULL)| bc | A pointer to the generic BoundaryCondition object to be configured. |
Definition at line 132 of file BC_Handlers.c.
|
static |
(Handler Action) Initializes the constant velocity inlet handler.
Parses the appropriate velocity component ('vx', 'vy', or 'vz') from bcs.dat based on the face orientation and sets the initial state on the boundary face by calling the Apply function.
Definition at line 380 of file BC_Handlers.c.
|
static |
(Handler PreStep) No preparation needed for constant velocity inlet.
For constant velocity inlets, all parameters are parsed during Initialize and stored in the handler's private data. There is nothing to prepare before Apply, so this function is a no-op.
NOTE: Other inlet types (parabolic, time-varying, file-based) DO use PreStep for profile calculation, file I/O, or data preparation.
Definition at line 436 of file BC_Handlers.c.
|
static |
(Handler Action) Applies the constant velocity inlet condition.
This function enforces a constant normal velocity on its assigned face by:
Definition at line 465 of file BC_Handlers.c.
|
static |
(Handler PostStep) Measures actual inflow flux through the constant velocity inlet face.
Definition at line 600 of file BC_Handlers.c.
|
static |
(Handler Destructor) Frees memory for the Constant Velocity Inlet.
Definition at line 694 of file BC_Handlers.c.
| PetscErrorCode Create_InletConstantVelocity | ( | BoundaryCondition * | bc | ) |
Configures a BoundaryCondition object to behave as a constant velocity inlet.
Definition at line 348 of file BC_Handlers.c.
|
static |
(Handler Action) Initializes the parabolic inlet handler.
Parses 'v_max' (peak centerline velocity) from the boundary condition parameters, determines the two cross-stream directions based on face orientation, and pre-computes the center and half-width in index space for each cross-stream direction.
Cross-stream direction mapping:
The interior node width in each cross-stream direction is (dim - 2), since indices 0 and (dim-1) are ghost/boundary layers. The parabolic profile spans from index 1 to (dim-2), centered at 1.0 + (dim-2)/2.0.
Definition at line 803 of file BC_Handlers.c.
|
static |
(Handler PreStep) No preparation needed for parabolic inlet.
The parabolic profile is time-invariant. All geometry and parameters are computed once during Initialize and stored in the handler's private data.
Definition at line 871 of file BC_Handlers.c.
|
static |
(Handler Action) Applies the parabolic velocity inlet condition.
Enforces a Poiseuille (parabolic) velocity profile on the assigned inlet face:
The profile evaluates to v_max at the face center and zero at the walls, matching a fully-developed rectangular channel Poiseuille solution.
Definition at line 902 of file BC_Handlers.c.
|
static |
(Handler PostStep) Measures actual inflow flux through the parabolic inlet face.
Sums the contravariant velocity (ucont) over all owned nodes on the inlet face to compute the volumetric flux contribution from this MPI rank. This is identical to the constant velocity inlet's PostStep, since flux measurement is independent of how the velocity was set.
Definition at line 1064 of file BC_Handlers.c.
|
static |
(Handler Destructor) Frees memory for the Parabolic Velocity Inlet.
Definition at line 1157 of file BC_Handlers.c.
| PetscErrorCode Create_InletParabolicProfile | ( | BoundaryCondition * | bc | ) |
(Handler Constructor) Populates a BoundaryCondition object with Parabolic Inlet behavior.
Allocates the private data structure and wires all lifecycle function pointers. Actual parameter parsing and geometry computation are deferred to Initialize.
| bc | The BoundaryCondition object to populate. |
Definition at line 762 of file BC_Handlers.c.
|
static |
(Handler Action) Measures the current, uncorrected flux passing through a SINGLE outlet face.
This function is called during the PreStep phase of the boundary condition cycle. It is a direct, high-fidelity port of the flux measurement logic from the legacy function for outlet-type boundaries.
Its primary responsibility is to calculate the total volumetric flux that is currently passing out of the domain through the specified outlet face, before any mass-conservation corrections are applied.
The calculation is performed by taking the dot product of the interior cell-centered Cartesian velocity (ucat) with the corresponding face area vectors (csi, eta, or zet). To ensure bit-for-bit identical behavior with the legacy code, this function respects the convention of excluding domain corners and edges from the main face loops by using shrunk loop bounds (lxs, lxe, etc.).
The result from this rank's portion of the face is added to the local_outflow_contribution accumulator, which is later summed across all MPI ranks to obtain the global uncorrected outflow.
| self | A pointer to the BoundaryCondition object (unused in this specific handler). | |
| ctx | The context for this execution, providing access to the UserCtx and, critically, the face_id that this function call should operate on. | |
| local_inflow_contribution | Accumulator for inflow flux (unused by this handler). | |
| [out] | local_outflow_contribution | Accumulator for outflow flux. This function will ADD its calculated flux to this value. |
Definition at line 1248 of file BC_Handlers.c.
|
static |
(Handler Action) Applies mass conservation correction to the outlet face.
This function calculates a global correction factor based on the total inflow and outflow fluxes and applies it to the contravariant velocity (ucont) on the outlet face to ensure mass conservation.
Definition at line 1383 of file BC_Handlers.c.
|
static |
(Handler PostStep) Measures corrected outflow flux for verification.
After Apply has set the corrected ucont values, this function measures the actual flux passing through the outlet face by summing the ucont components. Only fluid cells (nvert < 0.1) are included in the sum.
Definition at line 1598 of file BC_Handlers.c.
| PetscErrorCode Create_OutletConservation | ( | BoundaryCondition * | bc | ) |
(Handler Constructor) Populates a BoundaryCondition object with Outlet Conservation behavior.
Definition at line 1195 of file BC_Handlers.c.
| PetscErrorCode Create_PeriodicGeometric | ( | BoundaryCondition * | bc | ) |
Definition at line 1733 of file BC_Handlers.c.
|
static |
(Handler Initialize) Initializes the handler by validating its configuration and parsing parameters.
This method is called once at simulation startup. It performs the following critical setup tasks:
mathematical_type = PERIODIC. If not, it halts the simulation with a clear error message.face_id it is attached to. It also designates the handler on the "negative" face (e.g., BC_FACE_NEG_X) as the "master controller". This ensures that computationally expensive, domain-wide calculations in the PreStep method are only executed once per direction.target_flux parameter from the boundary condition configuration file. It will halt with an error if this parameter is missing. The parsed value is stored in the handler's private data and also copied to a shared location in the UserCtx for other parts of the solver (like the "Enforcer" function) to access.| self | The BoundaryCondition object containing the handler's state. |
| ctx | The BCContext, providing access to the UserCtx and face_id. |
Definition at line 1863 of file BC_Handlers.c.
|
static |
(Handler PreStep) Measures current fluxes and calculates the correction terms for the timestep.
This method executes the main "Strategist" logic of the driven flow controller. It is called once per timestep during the PreStep phase of the boundary condition cycle.
The logic is executed only by the "master" handler (the one on the negative face) to ensure domain-wide calculations are performed just once per direction.
The function performs the following steps:
targetVolumetricFlux from the SimCtx.globalAveragePlanarVolumetricFlux by averaging the flux across all cross-sectional planes. This provides a stable, noise-filtered signal.globalCurrentBoundaryFlux at the single periodic boundary plane. This provides a fast, responsive signal.bulkVelocityCorrection using the stable, averaged flux and stores it in the SimCtx for the ApplyDrivenChannelFlowSource function to use.boundaryVelocityCorrection using the fast, boundary-specific flux and stores it in the handler's private data for its own Apply method to use for the "Boundary Trim".| self | The BoundaryCondition object containing the handler's state. |
| ctx | The BCContext, providing access to the UserCtx. |
| local_inflow_contribution | (Not used by this handler) |
| local_outflow_contribution | (Not used by this handler) |
Definition at line 1954 of file BC_Handlers.c.
|
static |
(Handler Apply) Applies the immediate "Boundary Trim" velocity correction to the periodic face.
This method executes the fast, tactical part of the control loop. It is called during the Apply phase of the boundary condition cycle for each of the two periodic faces that have this handler.
It reads the boundaryVelocityCorrection value (which was computed for the entire boundary by the master controller's PreStep method) from its private data. It then applies this correction directly to the contravariant velocity (ucont) field on the face it manages.
This action serves to immediately correct any flux deviation at the periodic "seam", preventing errors from propagating into the domain in the subsequent timestep. The correction value is also stored in the uch vector for diagnostic purposes.
| self | The BoundaryCondition object containing the handler's state. |
| ctx | The BCContext, providing access to the UserCtx and face_id. |
Definition at line 2151 of file BC_Handlers.c.
|
static |
(Handler Destructor) Frees the memory allocated for the handler's private data.
This method is called once at the end of the simulation by BoundarySystem_Destroy. Its only job is to free the DrivenConstantData struct that was allocated in the Create_PeriodicDrivenConstantFlux constructor.
This is a critical step to ensure there are no memory leaks.
| self | The BoundaryCondition object containing the private data to be freed. |
Definition at line 2263 of file BC_Handlers.c.
| PetscErrorCode Create_PeriodicDrivenConstant | ( | BoundaryCondition * | bc | ) |
(Handler Constructor) Creates and configures a BoundaryCondition object for a driven periodic flow with a constant, user-defined target flux.
This function acts as the factory entry point for the BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX type. It performs the following steps:
BoundaryCondition object (done by the factory caller).DrivenConstantData struct.BC_PRIORITY_INLET to ensure the controller's PreStep runs before other flux-measuring handlers.Initialize, PreStep, Apply, Destroy) to the specific static implementations defined in this file. Other methods are set to NULL as they are not needed by this handler.| bc | A pointer to the generic BoundaryCondition object to be configured. |
Definition at line 1799 of file BC_Handlers.c.