PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
Loading...
Searching...
No Matches
Functions
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)
 Configures a BoundaryCondition object for a parabolic inlet profile.
 
PetscErrorCode Create_OutletConservation (BoundaryCondition *bc)
 Configures a BoundaryCondition object for conservative outlet treatment.
 
PetscErrorCode Create_PeriodicGeometric (BoundaryCondition *bc)
 Configures a BoundaryCondition object for geometric periodic coupling.
 
PetscErrorCode Create_PeriodicDrivenConstant (BoundaryCondition *bc)
 Configures a BoundaryCondition object for periodic driven-flow forcing.
 

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.

(Private) Validates all consistency rules for a driven flow (channel/pipe) setup.

Local to this translation unit.

Definition at line 15 of file BC_Handlers.c.

16{
17 PetscFunctionBeginUser;
18
19 // --- CHECK 1: Detect if a driven flow is active. ---
20 PetscBool is_driven_flow_active = PETSC_FALSE;
21 char driven_direction = ' ';
22 const char* first_driven_face_name = "";
23
24 for (int i = 0; i < 6; i++) {
25 BCHandlerType handler_type = user->boundary_faces[i].handler_type;
26 if (handler_type == BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX ||
28 {
29 is_driven_flow_active = PETSC_TRUE;
30 first_driven_face_name = BCFaceToString((BCFace)i);
31
32 if (i <= 1) driven_direction = 'X';
33 else if (i <= 3) driven_direction = 'Y';
34 else driven_direction = 'Z';
35
36 break; // Exit loop once we've confirmed it's active and found the direction.
37 }
38 }
39
40 // If no driven flow handler is found, validation for this rule set is complete.
41 if (!is_driven_flow_active) {
42 PetscFunctionReturn(0);
43 }
44
45 LOG_ALLOW(GLOBAL, LOG_DEBUG, " - Driven Flow Handler detected on face %s. Applying driven flow validation rules...\n", first_driven_face_name);
46
47 // --- CHECK 2: Ensure no conflicting BCs (Inlet/Outlet/Far-field) are present. ---
48 LOG_ALLOW(GLOBAL, LOG_DEBUG, " - Checking for incompatible Inlet/Outlet/Far-field BCs...\n");
49 for (int i = 0; i < 6; i++) {
50 BCType math_type = user->boundary_faces[i].mathematical_type;
51 if (math_type == INLET || math_type == OUTLET || math_type == FARFIELD) {
52 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
53 "Configuration Error: A DRIVEN flow handler is active, which is incompatible with the %s boundary condition found on face %s.",
54 BCTypeToString(math_type), BCFaceToString((BCFace)i));
55 }
56 }
57 LOG_ALLOW(GLOBAL, LOG_DEBUG, " ... No conflicting BC types found. OK.\n");
58
59 // --- CHECK 3: Ensure both ends of the driven direction have identical, valid setups. ---
60 LOG_ALLOW(GLOBAL, LOG_DEBUG, " - Validating symmetry and mathematical types for the '%c' direction...\n", driven_direction);
61
62 PetscInt neg_face_idx = 0, pos_face_idx = 0;
63 if (driven_direction == 'X') {
64 neg_face_idx = BC_FACE_NEG_X; pos_face_idx = BC_FACE_POS_X;
65 } else if (driven_direction == 'Y') {
66 neg_face_idx = BC_FACE_NEG_Y; pos_face_idx = BC_FACE_POS_Y;
67 } else { // 'Z'
68 neg_face_idx = BC_FACE_NEG_Z; pos_face_idx = BC_FACE_POS_Z;
69 }
70
71 BoundaryFaceConfig *neg_face_cfg = &user->boundary_faces[neg_face_idx];
72 BoundaryFaceConfig *pos_face_cfg = &user->boundary_faces[pos_face_idx];
73
74 // Rule 3a: Both faces must be PERIODIC.
75 if (neg_face_cfg->mathematical_type != PERIODIC || pos_face_cfg->mathematical_type != PERIODIC) {
76 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
77 "Configuration Error: For a driven flow in the '%c' direction, both the %s and %s faces must be of mathematical_type PERIODIC.",
78 driven_direction, BCFaceToString((BCFace)neg_face_idx), BCFaceToString((BCFace)pos_face_idx));
79 }
80
81 // Rule 3b: Both faces must use the exact same handler type.
82 if (neg_face_cfg->handler_type != pos_face_cfg->handler_type) {
83 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
84 "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).",
85 BCFaceToString((BCFace)neg_face_idx), BCFaceToString((BCFace)pos_face_idx), driven_direction);
86 }
87
88 LOG_ALLOW(GLOBAL, LOG_DEBUG, " ... Symmetry and mathematical types are valid. OK.\n");
89
90 PetscFunctionReturn(0);
91}
#define GLOBAL
Scope for global logging across all processes.
Definition logging.h:45
const char * BCFaceToString(BCFace face)
Helper function to convert BCFace enum to a string representation.
Definition logging.c:669
#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:199
const char * BCTypeToString(BCType type)
Helper function to convert BCType enum to a string representation.
Definition logging.c:751
@ LOG_DEBUG
Detailed debugging information.
Definition logging.h:31
BCType
Defines the general mathematical/physical Category of a boundary.
Definition variables.h:251
@ INLET
Definition variables.h:258
@ FARFIELD
Definition variables.h:259
@ OUTLET
Definition variables.h:257
@ PERIODIC
Definition variables.h:260
BoundaryFaceConfig boundary_faces[6]
Definition variables.h:829
BCHandlerType
Defines the specific computational "strategy" for a boundary handler.
Definition variables.h:271
@ BC_HANDLER_PERIODIC_DRIVEN_INITIAL_FLUX
Definition variables.h:287
@ BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX
Definition variables.h:286
BCHandlerType handler_type
Definition variables.h:337
BCType mathematical_type
Definition variables.h:336
BCFace
Identifies the six logical faces of a structured computational block.
Definition variables.h:244
@ BC_FACE_NEG_X
Definition variables.h:245
@ BC_FACE_POS_Z
Definition variables.h:247
@ BC_FACE_POS_Y
Definition variables.h:246
@ BC_FACE_NEG_Z
Definition variables.h:247
@ BC_FACE_POS_X
Definition variables.h:245
@ BC_FACE_NEG_Y
Definition variables.h:246
Holds the complete configuration for one of the six boundary faces.
Definition variables.h:334
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
Returns
PetscErrorCode 0 on success.

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

Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/BC_Handlers.h.

See also
Create_WallNoSlip()

Definition at line 114 of file BC_Handlers.c.

115{
116 PetscFunctionBeginUser;
117
118 if (!bc) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
119 "Input BoundaryCondition object is NULL in Create_WallNoSlip");
120
121 // ✅ Set priority
123
124 // Assign function pointers
125 bc->Initialize = NULL;
126 bc->PreStep = NULL;
128 bc->PostStep = NULL;
129 bc->UpdateUbcs = NULL;
130 bc->Destroy = NULL;
131
132 // No private data needed for this simple handler
133 bc->data = NULL;
134
135 PetscFunctionReturn(0);
136}
static PetscErrorCode Apply_WallNoSlip(BoundaryCondition *self, BCContext *ctx)
Internal helper implementation: Apply_WallNoSlip().
PetscErrorCode(* PostStep)(BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow, PetscReal *local_outflow)
Definition variables.h:328
PetscErrorCode(* PreStep)(BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow, PetscReal *local_outflow)
Definition variables.h:326
PetscErrorCode(* Destroy)(BoundaryCondition *self)
Definition variables.h:330
PetscErrorCode(* Initialize)(BoundaryCondition *self, BCContext *ctx)
Definition variables.h:325
PetscErrorCode(* UpdateUbcs)(BoundaryCondition *self, BCContext *ctx)
Definition variables.h:329
PetscErrorCode(* Apply)(BoundaryCondition *self, BCContext *ctx)
Definition variables.h:327
BCPriorityType priority
Definition variables.h:323
@ BC_PRIORITY_WALL
Definition variables.h:295
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.

Parameters
bcParameter bc passed to Create_InletConstantVelocity().
Returns
PetscErrorCode 0 on success.

Configures a BoundaryCondition object to behave as a constant velocity inlet.

Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/BC_Handlers.h.

See also
Create_InletConstantVelocity()

Definition at line 323 of file BC_Handlers.c.

324{
325 PetscErrorCode ierr;
326 PetscFunctionBeginUser;
327
328 if (!bc) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "BoundaryCondition is NULL");
329
330 InletConstantData *data = NULL;
331 ierr = PetscMalloc1(1, &data); CHKERRQ(ierr);
332 bc->data = (void*)data;
333
339 bc->UpdateUbcs = NULL;
341
342 PetscFunctionReturn(0);
343}
static PetscErrorCode PreStep_InletConstantVelocity(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Internal helper implementation: PreStep_InletConstantVelocity().
static PetscErrorCode Apply_InletConstantVelocity(BoundaryCondition *self, BCContext *ctx)
Internal helper implementation: Apply_InletConstantVelocity().
static PetscErrorCode Destroy_InletConstantVelocity(BoundaryCondition *self)
Internal helper implementation: Destroy_InletConstantVelocity().
static PetscErrorCode Initialize_InletConstantVelocity(BoundaryCondition *self, BCContext *ctx)
Internal helper implementation: Initialize_InletConstantVelocity().
static PetscErrorCode PostStep_InletConstantVelocity(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Internal helper implementation: PostStep_InletConstantVelocity().
Private data structure for the Constant Velocity Inlet handler.
@ BC_PRIORITY_INLET
Definition variables.h:293
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Create_InletParabolicProfile()

PetscErrorCode Create_InletParabolicProfile ( BoundaryCondition bc)

Configures a BoundaryCondition object for a parabolic inlet profile.

The constructed handler computes inlet velocity as a profile function of transverse coordinates, typically used for laminar channel/pipe initialization.

Parameters
bcA pointer to the generic BoundaryCondition object to be configured.
Returns
PetscErrorCode 0 on success.

Configures a BoundaryCondition object for a parabolic inlet profile.

Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/BC_Handlers.h.

See also
Create_InletParabolicProfile()

Definition at line 721 of file BC_Handlers.c.

722{
723 PetscErrorCode ierr;
724 PetscFunctionBeginUser;
725
726 if (!bc) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "BoundaryCondition is NULL");
727
728 InletParabolicData *data = NULL;
729 ierr = PetscMalloc1(1, &data); CHKERRQ(ierr);
730 bc->data = (void*)data;
731
737 bc->UpdateUbcs = NULL;
739
740 PetscFunctionReturn(0);
741}
static PetscErrorCode Initialize_InletParabolicProfile(BoundaryCondition *self, BCContext *ctx)
Internal helper implementation: Initialize_InletParabolicProfile().
static PetscErrorCode Apply_InletParabolicProfile(BoundaryCondition *self, BCContext *ctx)
Internal helper implementation: Apply_InletParabolicProfile().
static PetscErrorCode PostStep_InletParabolicProfile(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Internal helper implementation: PostStep_InletParabolicProfile().
static PetscErrorCode PreStep_InletParabolicProfile(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Internal helper implementation: PreStep_InletParabolicProfile().
static PetscErrorCode Destroy_InletParabolicProfile(BoundaryCondition *self)
Internal helper implementation: Destroy_InletParabolicProfile().
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)

Configures a BoundaryCondition object for conservative outlet treatment.

The constructed handler applies outlet updates that preserve the solver's global mass/flux consistency assumptions.

Parameters
bcA pointer to the generic BoundaryCondition object to be configured.
Returns
PetscErrorCode 0 on success.

Configures a BoundaryCondition object for conservative outlet treatment.

Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/BC_Handlers.h.

See also
Create_OutletConservation()

Definition at line 1129 of file BC_Handlers.c.

1130{
1131 PetscFunctionBeginUser;
1132
1133 if (!bc) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Input BoundaryCondition is NULL");
1134
1135 // This handler has the highest priority to ensure it runs after
1136 // all inflow fluxes have been calculated.
1138
1139 // Assign function pointers
1140 bc->Initialize = NULL; // No initialization needed
1144 bc->UpdateUbcs = NULL;
1145 bc->Destroy = NULL; // No private data to destroy
1146
1147 bc->data = NULL;
1148
1149 PetscFunctionReturn(0);
1150}
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)
Internal helper implementation: PostStep_OutletConservation().
static PetscErrorCode PreStep_OutletConservation(BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow_contribution, PetscReal *local_outflow_contribution)
Internal helper implementation: PreStep_OutletConservation().
@ BC_PRIORITY_OUTLET
Definition variables.h:296
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Create_PeriodicGeometric()

PetscErrorCode Create_PeriodicGeometric ( BoundaryCondition bc)

Configures a BoundaryCondition object for geometric periodic coupling.

This constructor wires periodic boundary callbacks that exchange values across opposite faces according to the configured periodic directions.

Parameters
bcA pointer to the generic BoundaryCondition object to be configured.
Returns
PetscErrorCode 0 on success.

Configures a BoundaryCondition object for geometric periodic coupling.

Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/BC_Handlers.h.

See also
Create_PeriodicGeometric()

Definition at line 1646 of file BC_Handlers.c.

1646 {
1647 PetscFunctionBeginUser;
1648
1649 if (!bc) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Input BoundaryCondition is NULL");
1651
1652 // Assign function pointers
1653 bc->Initialize = NULL; // No initialization needed
1654 bc->PreStep = NULL;
1655 bc->Apply = NULL;
1656 bc->PostStep = NULL;
1657 bc->UpdateUbcs = NULL;
1658 bc->Destroy = NULL; // No private data to destroy
1659
1660 bc->data = NULL;
1661
1662 PetscFunctionReturn(0);
1663}
Here is the caller graph for this function:

◆ Create_PeriodicDrivenConstant()

PetscErrorCode Create_PeriodicDrivenConstant ( BoundaryCondition bc)

Configures a BoundaryCondition object for periodic driven-flow forcing.

This constructor wires the periodic callbacks that enforce a prescribed driving strategy (for example constant target flux) on a periodic direction pair.

Parameters
bcA pointer to the generic BoundaryCondition object to be configured.
Returns
PetscErrorCode 0 on success.

Configures a BoundaryCondition object for periodic driven-flow forcing.

Local to this translation unit.

Definition at line 1699 of file BC_Handlers.c.

1700{
1701 PetscErrorCode ierr;
1702 PetscFunctionBeginUser;
1703
1704 if (!bc) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "Input BoundaryCondition object is NULL in Create_PeriodicDrivenConstantFlux");
1705
1706 // --- Allocate the private data structure ---
1707 DrivenConstantData *data = NULL;
1708 ierr = PetscNew(&data); CHKERRQ(ierr);
1709 // Initialize fields to safe default values
1710 data->direction = ' ';
1711 data->targetVolumetricFlux = 0.0;
1712 data->boundaryVelocityCorrection = 0.0;
1713 data->isMasterController = PETSC_FALSE;
1714 data->applyBoundaryTrim = PETSC_FALSE;
1715
1716 // Attach the private data to the generic handler object
1717 bc->data = (void*)data;
1718
1719 // --- Configure the handler's properties and methods ---
1720
1721 // Set priority: Using BC_PRIORITY_INLET ensures this handler's PreStep runs
1722 // before other handlers (like outlets) that might depend on its calculations.
1723 // It is the caller's responsibility that there are no Inlets called along with driven periodic to avoid clash.
1725
1726 // Assign the function pointers to the implementations in this file.
1730 bc->PostStep = NULL; // This handler has no action after the main solver step.
1731 bc->UpdateUbcs = NULL; // The boundary value is not flow-dependent (it's periodic).
1733
1734 PetscFunctionReturn(0);
1735}
PetscBool applyBoundaryTrim
PetscReal targetVolumetricFlux
PetscBool isMasterController
static PetscErrorCode Apply_PeriodicDrivenConstant(BoundaryCondition *self, BCContext *ctx)
Internal helper implementation: Apply_PeriodicDrivenConstant().
static PetscErrorCode Initialize_PeriodicDrivenConstant(BoundaryCondition *self, BCContext *ctx)
Internal helper implementation: Initialize_PeriodicDrivenConstant().
static PetscErrorCode Destroy_PeriodicDrivenConstant(BoundaryCondition *self)
Internal helper implementation: Destroy_PeriodicDrivenConstant().
static PetscErrorCode PreStep_PeriodicDrivenConstant(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Internal helper implementation: PreStep_PeriodicDrivenConstant().
PetscReal boundaryVelocityCorrection
Private data structure for the handler.
Here is the call graph for this function:
Here is the caller graph for this function: