PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
Loading...
Searching...
No Matches
BC_Handlers.h File Reference
#include "variables.h"
#include "logging.h"
Include dependency graph for BC_Handlers.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

PetscErrorCode Validate_DrivenFlowConfiguration (UserCtx *user)
 (Private) Validates all consistency rules for a driven flow (channel/pipe) setup.
 
PetscErrorCode Create_WallNoSlip (BoundaryCondition *bc)
 Configures a BoundaryCondition object to behave as a no-slip, stationary wall.
 
PetscErrorCode Create_InletConstantVelocity (BoundaryCondition *bc)
 Configures a BoundaryCondition object to behave as a constant velocity inlet.
 
PetscErrorCode Create_InletParabolicProfile (BoundaryCondition *bc)
 (Handler Constructor) Populates a BoundaryCondition object with Parabolic Inlet behavior.
 
PetscErrorCode Create_OutletConservation (BoundaryCondition *bc)
 (Handler Constructor) Populates a BoundaryCondition object with Outlet Conservation behavior.
 
PetscErrorCode Create_PeriodicGeometric (BoundaryCondition *bc)
 

Function Documentation

◆ Validate_DrivenFlowConfiguration()

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:

  1. Detect if any DRIVEN_ handler is active. If not, the function returns immediately.
  2. Ensure that no INLET, OUTLET, or FARFIELD boundary conditions exist anywhere in the domain, as they are physically incompatible with a pressure-driven flow model.
  3. Verify that both faces in the driven direction are of mathematical_type PERIODIC.
  4. Verify that both faces in the driven direction use the exact same DRIVEN_ handler type.
Parameters
userThe UserCtx for a single block.
Returns
PetscErrorCode 0 on success, non-zero PETSc error code on failure.

Definition at line 27 of file BC_Handlers.c.

28{
29 PetscFunctionBeginUser;
30
31 // --- CHECK 1: Detect if a driven flow is active. ---
32 PetscBool is_driven_flow_active = PETSC_FALSE;
33 char driven_direction = ' ';
34 const char* first_driven_face_name = "";
35
36 for (int i = 0; i < 6; i++) {
37 BCHandlerType handler_type = user->boundary_faces[i].handler_type;
38 if (handler_type == BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX ||
40 {
41 is_driven_flow_active = PETSC_TRUE;
42 first_driven_face_name = BCFaceToString((BCFace)i);
43
44 if (i <= 1) driven_direction = 'X';
45 else if (i <= 3) driven_direction = 'Y';
46 else driven_direction = 'Z';
47
48 break; // Exit loop once we've confirmed it's active and found the direction.
49 }
50 }
51
52 // If no driven flow handler is found, validation for this rule set is complete.
53 if (!is_driven_flow_active) {
54 PetscFunctionReturn(0);
55 }
56
57 LOG_ALLOW(GLOBAL, LOG_DEBUG, " - Driven Flow Handler detected on face %s. Applying driven flow validation rules...\n", first_driven_face_name);
58
59 // --- CHECK 2: Ensure no conflicting BCs (Inlet/Outlet/Far-field) are present. ---
60 LOG_ALLOW(GLOBAL, LOG_DEBUG, " - Checking for incompatible Inlet/Outlet/Far-field BCs...\n");
61 for (int i = 0; i < 6; i++) {
62 BCType math_type = user->boundary_faces[i].mathematical_type;
63 if (math_type == INLET || math_type == OUTLET || math_type == FARFIELD) {
64 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
65 "Configuration Error: A DRIVEN flow handler is active, which is incompatible with the %s boundary condition found on face %s.",
66 BCTypeToString(math_type), BCFaceToString((BCFace)i));
67 }
68 }
69 LOG_ALLOW(GLOBAL, LOG_DEBUG, " ... No conflicting BC types found. OK.\n");
70
71 // --- CHECK 3: Ensure both ends of the driven direction have identical, valid setups. ---
72 LOG_ALLOW(GLOBAL, LOG_DEBUG, " - Validating symmetry and mathematical types for the '%c' direction...\n", driven_direction);
73
74 PetscInt neg_face_idx = 0, pos_face_idx = 0;
75 if (driven_direction == 'X') {
76 neg_face_idx = BC_FACE_NEG_X; pos_face_idx = BC_FACE_POS_X;
77 } else if (driven_direction == 'Y') {
78 neg_face_idx = BC_FACE_NEG_Y; pos_face_idx = BC_FACE_POS_Y;
79 } else { // 'Z'
80 neg_face_idx = BC_FACE_NEG_Z; pos_face_idx = BC_FACE_POS_Z;
81 }
82
83 BoundaryFaceConfig *neg_face_cfg = &user->boundary_faces[neg_face_idx];
84 BoundaryFaceConfig *pos_face_cfg = &user->boundary_faces[pos_face_idx];
85
86 // Rule 3a: Both faces must be PERIODIC.
87 if (neg_face_cfg->mathematical_type != PERIODIC || pos_face_cfg->mathematical_type != PERIODIC) {
88 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
89 "Configuration Error: For a driven flow in the '%c' direction, both the %s and %s faces must be of mathematical_type PERIODIC.",
90 driven_direction, BCFaceToString((BCFace)neg_face_idx), BCFaceToString((BCFace)pos_face_idx));
91 }
92
93 // Rule 3b: Both faces must use the exact same handler type.
94 if (neg_face_cfg->handler_type != pos_face_cfg->handler_type) {
95 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
96 "Configuration Error: The DRIVEN handlers on the %s and %s faces of the '%c' direction do not match. Both must be the same type (e.g., both CONSTANT_FLUX).",
97 BCFaceToString((BCFace)neg_face_idx), BCFaceToString((BCFace)pos_face_idx), driven_direction);
98 }
99
100 LOG_ALLOW(GLOBAL, LOG_DEBUG, " ... Symmetry and mathematical types are valid. OK.\n");
101
102 PetscFunctionReturn(0);
103}
#define GLOBAL
Scope for global logging across all processes.
Definition logging.h:46
const char * BCFaceToString(BCFace face)
Helper function to convert BCFace enum to a string representation.
Definition logging.c:643
#define LOG_ALLOW(scope, level, fmt,...)
Logging macro that checks both the log level and whether the calling function is in the allowed-funct...
Definition logging.h:200
const char * BCTypeToString(BCType type)
Helper function to convert BCType enum to a string representation.
Definition logging.c:722
@ LOG_DEBUG
Detailed debugging information.
Definition logging.h:32
BCType
Defines the general mathematical/physical Category of a boundary.
Definition variables.h:210
@ INLET
Definition variables.h:217
@ FARFIELD
Definition variables.h:218
@ OUTLET
Definition variables.h:216
@ PERIODIC
Definition variables.h:219
BoundaryFaceConfig boundary_faces[6]
Definition variables.h:746
BCHandlerType
Defines the specific computational "strategy" for a boundary handler.
Definition variables.h:230
@ BC_HANDLER_PERIODIC_DRIVEN_INITIAL_FLUX
Definition variables.h:246
@ BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX
Definition variables.h:245
BCHandlerType handler_type
Definition variables.h:296
BCType mathematical_type
Definition variables.h:295
BCFace
Identifies the six logical faces of a structured computational block.
Definition variables.h:203
@ BC_FACE_NEG_X
Definition variables.h:204
@ BC_FACE_POS_Z
Definition variables.h:206
@ BC_FACE_POS_Y
Definition variables.h:205
@ BC_FACE_NEG_Z
Definition variables.h:206
@ BC_FACE_POS_X
Definition variables.h:204
@ BC_FACE_NEG_Y
Definition variables.h:205
Holds the complete configuration for one of the six boundary faces.
Definition variables.h:293
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Create_WallNoSlip()

PetscErrorCode Create_WallNoSlip ( BoundaryCondition bc)

Configures a BoundaryCondition object to behave as a no-slip, stationary wall.

Parameters
bcA pointer to the generic BoundaryCondition object to be configured.

Configures a BoundaryCondition object to behave as a no-slip, stationary wall.

A no-slip wall is simple and requires only the Apply method:

  • No special initialization needed (Initialize is NULL)
  • Does not contribute to global mass balance (PreStep and PostStep are NULL)
  • Enforces zero velocity at the wall (Apply)
  • Allocates no private data (Destroy is NULL)
Parameters
bcA pointer to the generic BoundaryCondition object to be configured.
Returns
PetscErrorCode 0 on success.

Definition at line 132 of file BC_Handlers.c.

133{
134 PetscFunctionBeginUser;
135
136 if (!bc) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
137 "Input BoundaryCondition object is NULL in Create_WallNoSlip");
138
139 // ✅ Set priority
141
142 // Assign function pointers
143 bc->Initialize = NULL;
144 bc->PreStep = NULL;
146 bc->PostStep = NULL;
147 bc->UpdateUbcs = NULL;
148 bc->Destroy = NULL;
149
150 // No private data needed for this simple handler
151 bc->data = NULL;
152
153 PetscFunctionReturn(0);
154}
static PetscErrorCode Apply_WallNoSlip(BoundaryCondition *self, BCContext *ctx)
(Handler Action) Applies the no-slip wall condition to a specified face.
PetscErrorCode(* PreStep)(BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow, PetscReal *local_outflow)
Definition variables.h:285
PetscErrorCode(* Destroy)(BoundaryCondition *self)
Definition variables.h:289
PetscErrorCode(* PostStep)(BoundaryCondition *self, BCContext *ctx,...)
Definition variables.h:287
PetscErrorCode(* Initialize)(BoundaryCondition *self, BCContext *ctx)
Definition variables.h:284
PetscErrorCode(* UpdateUbcs)(BoundaryCondition *self, BCContext *ctx)
Definition variables.h:288
PetscErrorCode(* Apply)(BoundaryCondition *self, BCContext *ctx)
Definition variables.h:286
BCPriorityType priority
Definition variables.h:282
@ BC_PRIORITY_WALL
Definition variables.h:254
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Create_InletConstantVelocity()

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.

349{
350 PetscErrorCode ierr;
351 PetscFunctionBeginUser;
352
353 if (!bc) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "BoundaryCondition is NULL");
354
355 InletConstantData *data = NULL;
356 ierr = PetscMalloc1(1, &data); CHKERRQ(ierr);
357 bc->data = (void*)data;
358
364 bc->UpdateUbcs = NULL;
366
367 PetscFunctionReturn(0);
368}
static PetscErrorCode PreStep_InletConstantVelocity(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
(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 Destroy_InletConstantVelocity(BoundaryCondition *self)
(Handler Destructor) Frees memory for the Constant Velocity Inlet.
static PetscErrorCode Initialize_InletConstantVelocity(BoundaryCondition *self, BCContext *ctx)
(Handler Action) Initializes the constant velocity inlet handler.
static PetscErrorCode PostStep_InletConstantVelocity(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
(Handler PostStep) Measures actual inflow flux through the constant velocity inlet face.
Private data structure for the Constant Velocity Inlet handler.
@ BC_PRIORITY_INLET
Definition variables.h:252
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Create_InletParabolicProfile()

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.

Parameters
bcThe BoundaryCondition object to populate.
Returns
PetscErrorCode 0 on success.

Definition at line 762 of file BC_Handlers.c.

763{
764 PetscErrorCode ierr;
765 PetscFunctionBeginUser;
766
767 if (!bc) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "BoundaryCondition is NULL");
768
769 InletParabolicData *data = NULL;
770 ierr = PetscMalloc1(1, &data); CHKERRQ(ierr);
771 bc->data = (void*)data;
772
778 bc->UpdateUbcs = NULL;
780
781 PetscFunctionReturn(0);
782}
static PetscErrorCode Initialize_InletParabolicProfile(BoundaryCondition *self, BCContext *ctx)
(Handler Action) Initializes the parabolic inlet handler.
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 *in, PetscReal *out)
(Handler PostStep) Measures actual inflow flux through the parabolic inlet face.
static PetscErrorCode PreStep_InletParabolicProfile(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
(Handler PreStep) No preparation needed for parabolic inlet.
static PetscErrorCode Destroy_InletParabolicProfile(BoundaryCondition *self)
(Handler Destructor) Frees memory for the Parabolic Velocity Inlet.
Private data structure for the Parabolic Velocity Inlet handler.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Create_OutletConservation()

PetscErrorCode Create_OutletConservation ( BoundaryCondition bc)

(Handler Constructor) Populates a BoundaryCondition object with Outlet Conservation behavior.

Definition at line 1195 of file BC_Handlers.c.

1196{
1197 PetscFunctionBeginUser;
1198
1199 if (!bc) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Input BoundaryCondition is NULL");
1200
1201 // This handler has the highest priority to ensure it runs after
1202 // all inflow fluxes have been calculated.
1204
1205 // Assign function pointers
1206 bc->Initialize = NULL; // No initialization needed
1210 bc->UpdateUbcs = NULL;
1211 bc->Destroy = NULL; // No private data to destroy
1212
1213 bc->data = NULL;
1214
1215 PetscFunctionReturn(0);
1216}
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 *in, PetscReal *out)
(Handler PostStep) Measures corrected outflow flux for verification.
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.
@ BC_PRIORITY_OUTLET
Definition variables.h:255
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Create_PeriodicGeometric()

PetscErrorCode Create_PeriodicGeometric ( BoundaryCondition bc)

Definition at line 1733 of file BC_Handlers.c.

1733 {
1734 PetscFunctionBeginUser;
1735
1736 if (!bc) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Input BoundaryCondition is NULL");
1738
1739 // Assign function pointers
1740 bc->Initialize = NULL; // No initialization needed
1741 bc->PreStep = NULL;
1742 bc->Apply = NULL;
1743 bc->PostStep = NULL;
1744 bc->UpdateUbcs = NULL;
1745 bc->Destroy = NULL; // No private data to destroy
1746
1747 bc->data = NULL;
1748
1749 PetscFunctionReturn(0);
1750}
Here is the caller graph for this function: