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_WallFreeSlip (BoundaryCondition *bc)
 Configures a BoundaryCondition object to behave as a free-slip wall.
 
PetscErrorCode Create_InletPrescribedVelocity (BoundaryCondition *bc)
 Configures a BoundaryCondition object as an inlet whose velocity is a configured source: expressions over position, time and grid-line fractions, in the Cartesian, curvilinear or face-normal frame, a PICSLICE file, or a file with expressions added to it, optionally rescaled to a bulk velocity or flow rate, with optional synthetic fluctuations.
 
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.
 
PetscErrorCode Create_PeriodicDrivenInitial (BoundaryCondition *bc)
 Configures a BoundaryCondition object for initial-flux periodic driving.
 
PetscErrorCode Create_WallMoving (BoundaryCondition *bc)
 Creates a wall moving along itself at a velocity source, the prescribed inlet's without its flux.
 
PetscErrorCode LogPrescribedFlowDiagnostics (UserCtx *user)
 Appends each prescribed-velocity inlet's flow rate and mean normal speed this step to inlet_flow.csv.
 

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.

See also
Validate_DrivenFlowConfiguration()

Definition at line 15 of file BC_Handlers.c.

16{
17 PetscFunctionBeginUser;
19
20 // --- CHECK 1: Detect if a driven flow is active. ---
21 PetscBool is_driven_flow_active = PETSC_FALSE;
22 char driven_direction = ' ';
23 const char* first_driven_face_name = "";
24
25 for (int i = 0; i < 6; i++) {
26 BCHandlerType handler_type = user->boundary_faces[i].handler_type;
27 if (handler_type == BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX ||
29 {
30 is_driven_flow_active = PETSC_TRUE;
31 first_driven_face_name = BCFaceToString((BCFace)i);
32
33 if (i <= 1) driven_direction = 'X';
34 else if (i <= 3) driven_direction = 'Y';
35 else driven_direction = 'Z';
36
37 break; // Exit loop once we've confirmed it's active and found the direction.
38 }
39 }
40
41 // If no driven flow handler is found, validation for this rule set is complete.
42 if (!is_driven_flow_active) {
44 PetscFunctionReturn(0);
45 }
46
47 LOG_ALLOW(GLOBAL, LOG_DEBUG, " - Driven Flow Handler detected on face %s. Applying driven flow validation rules...\n", first_driven_face_name);
48
49 // --- CHECK 2: Ensure no conflicting BCs (Inlet/Outlet/Far-field) are present. ---
50 LOG_ALLOW(GLOBAL, LOG_DEBUG, " - Checking for incompatible Inlet/Outlet/Far-field BCs...\n");
51 for (int i = 0; i < 6; i++) {
52 BCType math_type = user->boundary_faces[i].mathematical_type;
53 if (math_type == INLET || math_type == OUTLET || math_type == FARFIELD) {
54 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
55 "Configuration Error: A DRIVEN flow handler is active, which is incompatible with the %s boundary condition found on face %s.",
56 BCTypeToString(math_type), BCFaceToString((BCFace)i));
57 }
58 }
59 LOG_ALLOW(GLOBAL, LOG_DEBUG, " ... No conflicting BC types found. OK.\n");
60
61 // --- CHECK 3: Ensure both ends of the driven direction have identical, valid setups. ---
62 LOG_ALLOW(GLOBAL, LOG_DEBUG, " - Validating symmetry and mathematical types for the '%c' direction...\n", driven_direction);
63
64 PetscInt neg_face_idx = 0, pos_face_idx = 0;
65 if (driven_direction == 'X') {
66 neg_face_idx = BC_FACE_NEG_X; pos_face_idx = BC_FACE_POS_X;
67 } else if (driven_direction == 'Y') {
68 neg_face_idx = BC_FACE_NEG_Y; pos_face_idx = BC_FACE_POS_Y;
69 } else { // 'Z'
70 neg_face_idx = BC_FACE_NEG_Z; pos_face_idx = BC_FACE_POS_Z;
71 }
72
73 BoundaryFaceConfig *neg_face_cfg = &user->boundary_faces[neg_face_idx];
74 BoundaryFaceConfig *pos_face_cfg = &user->boundary_faces[pos_face_idx];
75
76 // Rule 3a: Both faces must be PERIODIC.
77 if (neg_face_cfg->mathematical_type != PERIODIC || pos_face_cfg->mathematical_type != PERIODIC) {
78 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
79 "Configuration Error: For a driven flow in the '%c' direction, both the %s and %s faces must be of mathematical_type PERIODIC.",
80 driven_direction, BCFaceToString((BCFace)neg_face_idx), BCFaceToString((BCFace)pos_face_idx));
81 }
82
83 // Rule 3b: Both faces must use the exact same handler type.
84 if (neg_face_cfg->handler_type != pos_face_cfg->handler_type) {
85 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
86 "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).",
87 BCFaceToString((BCFace)neg_face_idx), BCFaceToString((BCFace)pos_face_idx), driven_direction);
88 }
89
90 LOG_ALLOW(GLOBAL, LOG_DEBUG, " ... Symmetry and mathematical types are valid. OK.\n");
91
93 PetscFunctionReturn(0);
94}
#define GLOBAL
Scope for global logging across all processes.
Definition logging.h:46
const char * BCFaceToString(BCFace face)
Returns the canonical log token for a boundary-face enum value.
Definition logging.c:640
#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:214
#define PROFILE_FUNCTION_END
Marks the end of a profiled code block.
Definition logging.h:1029
const char * BCTypeToString(BCType type)
Returns the canonical log token for a boundary mathematical type.
Definition logging.c:828
@ LOG_DEBUG
Detailed debugging information.
Definition logging.h:32
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled function: an always-on aggregate timer.
Definition logging.h:1000
BCType
Defines the general mathematical/physical Category of a boundary.
Definition variables.h:316
@ INLET
Definition variables.h:323
@ FARFIELD
Definition variables.h:324
@ OUTLET
Definition variables.h:322
@ PERIODIC
Definition variables.h:325
BoundaryFaceConfig boundary_faces[6]
Definition variables.h:1182
BCHandlerType
Defines the specific computational "strategy" for a boundary handler.
Definition variables.h:343
@ BC_HANDLER_PERIODIC_DRIVEN_INITIAL_FLUX
Definition variables.h:355
@ BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX
Definition variables.h:354
BCHandlerType handler_type
Definition variables.h:427
BCType mathematical_type
Definition variables.h:426
BCFace
Identifies the six logical faces of a structured computational block.
Definition variables.h:308
@ BC_FACE_NEG_X
Definition variables.h:309
@ BC_FACE_POS_Z
Definition variables.h:311
@ BC_FACE_POS_Y
Definition variables.h:310
@ BC_FACE_NEG_Z
Definition variables.h:311
@ BC_FACE_POS_X
Definition variables.h:309
@ BC_FACE_NEG_Y
Definition variables.h:310
Holds the complete configuration for one of the six boundary faces.
Definition variables.h:424
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
[in,out]bcBoundary object whose callbacks and handler metadata are installed.
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 123 of file BC_Handlers.c.

124{
125 PetscFunctionBeginUser;
127
128 PetscCheck(bc, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "BoundaryCondition is NULL");
129
130 // ✅ Set priority
132
133 // Assign function pointers
134 bc->Initialize = NULL;
135 bc->PreStep = NULL;
137 bc->PostStep = NULL;
138 bc->UpdateUbcs = NULL;
139 bc->Destroy = NULL;
140
141 // No private data needed for this simple handler
142 bc->data = NULL;
143
145 PetscFunctionReturn(0);
146}
static PetscErrorCode Apply_WallNoSlip(BoundaryCondition *self, BCContext *ctx)
Apply no-slip velocity values to wall-adjacent cells for this boundary condition.
PetscErrorCode(* PostStep)(BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow, PetscReal *local_outflow)
Definition variables.h:396
PetscErrorCode(* PreStep)(BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow, PetscReal *local_outflow)
Definition variables.h:394
PetscErrorCode(* Destroy)(BoundaryCondition *self)
Definition variables.h:398
PetscErrorCode(* Initialize)(BoundaryCondition *self, BCContext *ctx)
Definition variables.h:393
PetscErrorCode(* UpdateUbcs)(BoundaryCondition *self, BCContext *ctx)
Definition variables.h:397
PetscErrorCode(* Apply)(BoundaryCondition *self, BCContext *ctx)
Definition variables.h:395
BCPriorityType priority
Definition variables.h:391
@ BC_PRIORITY_WALL
Definition variables.h:363
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Create_WallFreeSlip()

PetscErrorCode Create_WallFreeSlip ( BoundaryCondition *  bc)

Configures a BoundaryCondition object to behave as a free-slip wall.

The wall is impenetrable and exerts no shear: the normal velocity vanishes and the tangential velocity has zero normal gradient, which is also the condition at a plane of symmetry. The boundary value follows the adjacent velocity, so the handler also provides UpdateUbcs.

Parameters
[in,out]bcBoundary object whose callbacks and handler metadata are installed.
Returns
PetscErrorCode 0 on success.

Configures a BoundaryCondition object to behave as a free-slip wall.

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

See also
Create_WallFreeSlip()

Definition at line 197 of file BC_Handlers.c.

198{
199 PetscFunctionBeginUser;
201 PetscCheck(bc, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "BoundaryCondition is NULL");
203 bc->Initialize = NULL;
204 bc->PreStep = NULL;
206 bc->PostStep = NULL;
207 /* The boundary value follows the adjacent velocity, so it is refreshed whenever
208 * the velocity is: on every boundary pass and after each projection. */
210 bc->needs_repeat_pass = PETSC_TRUE; // Copies the adjacent Ucat, which the pass refreshes after it
211 bc->Destroy = NULL;
212 bc->data = NULL;
214 PetscFunctionReturn(0);
215}
static PetscErrorCode Apply_WallFreeSlip(BoundaryCondition *self, BCContext *ctx)
Apply free-slip boundary values to wall-adjacent cells for this boundary condition.
PetscBool needs_repeat_pass
Apply() reads state its own boundary pass changes after it runs (the interior Ucat that Contra2Cart r...
Definition variables.h:402
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Create_InletPrescribedVelocity()

PetscErrorCode Create_InletPrescribedVelocity ( BoundaryCondition *  bc)

Configures a BoundaryCondition object as an inlet whose velocity is a configured source: expressions over position, time and grid-line fractions, in the Cartesian, curvilinear or face-normal frame, a PICSLICE file, or a file with expressions added to it, optionally rescaled to a bulk velocity or flow rate, with optional synthetic fluctuations.

The face's source_id parameter names the options -face_source_<id>_* that hold the source (see PicurvVelocitySourceCreate()) and its optional _bulk_velocity or _flow_rate target. A source_file parameter names a staged PICSLICE file of solver-unit values, one per interior face slot: a normal speed, or a Cartesian velocity with three components, in one frame or in several frames interpolated in time. Expressions in the file's frame, when given, are added to it, and the target then rescales the expressions alone. The -face_source_<id>_fluct* options add digital-filter fluctuations after the rescaling.

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

Configures a BoundaryCondition object as an inlet whose velocity is a configured source: expressions over position, time and grid-line fractions, in the Cartesian, curvilinear or face-normal frame, a PICSLICE file, or a file with expressions added to it, optionally rescaled to a bulk velocity or flow rate, with optional synthetic fluctuations.

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

See also
Create_InletPrescribedVelocity()

Definition at line 323 of file BC_Handlers.c.

324{
325 InletPrescribedVelocityData *data = NULL;
326
327 PetscFunctionBeginUser;
329 PetscCheck(bc, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "BoundaryCondition is NULL");
330 PetscCall(PetscNew(&data));
331 bc->data = (void*)data;
337 bc->UpdateUbcs = NULL;
340 PetscFunctionReturn(0);
341}
static PetscErrorCode Apply_InletVelocity(BoundaryCondition *self, BCContext *ctx)
Applies the prescribed inlet velocity through the common face-layout path.
static PetscErrorCode Initialize_InletPrescribedVelocity(BoundaryCondition *self, BCContext *ctx)
Compile the source named by the face's source_id parameter, with its bulk velocity or flow rate if an...
static PetscErrorCode PostStep_InletFlux(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Adds the inlet face's applied flux, the sum of its normal Ucont, to the inflow.
static PetscErrorCode Destroy_InletPrescribedVelocity(BoundaryCondition *self)
Release the compiled source and the per-slot arrays.
static PetscErrorCode PreStep_InletPrescribedVelocity(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Refresh the inlet velocity once per step: gather the slots on the first call, then re-evaluate and re...
Private data of the prescribed-velocity inlet: a compiled source or a PICSLICE file,...
@ BC_PRIORITY_INLET
Definition variables.h:361
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 1414 of file BC_Handlers.c.

1415{
1416 PetscFunctionBeginUser;
1418
1419 PetscCheck(bc, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "BoundaryCondition is NULL");
1420
1421 // This handler has the highest priority to ensure it runs after
1422 // all inflow fluxes have been calculated.
1424
1425 // Assign function pointers
1426 bc->Initialize = NULL; // No initialization needed
1430 bc->UpdateUbcs = NULL;
1431 bc->needs_repeat_pass = PETSC_TRUE; // Reads the adjacent Ucat and the inlets' flux
1433
1434 OutletConservationData *data = NULL;
1435 PetscCall(PetscNew(&data));
1436 data->decisionStep = -1;
1437 bc->data = (void*)data;
1438
1440 PetscFunctionReturn(0);
1441}
static PetscErrorCode Destroy_OutletConservation(BoundaryCondition *self)
Release the outlet-conservation handler's clip state.
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)
Update outlet-conservation state after a completed solver step.
static PetscErrorCode PreStep_OutletConservation(BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow_contribution, PetscReal *local_outflow_contribution)
Prepare the outlet-conservation correction before advancing the solver.
Per-face state of the backflow clip; see the section comment above.
@ BC_PRIORITY_OUTLET
Definition variables.h:364
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 2115 of file BC_Handlers.c.

2115 {
2116 PetscFunctionBeginUser;
2118
2119 PetscCheck(bc, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "BoundaryCondition is NULL");
2121
2122 // Assign function pointers
2123 bc->Initialize = NULL; // No initialization needed
2124 bc->PreStep = NULL;
2125 bc->Apply = NULL;
2126 bc->PostStep = NULL;
2127 bc->UpdateUbcs = NULL;
2128 bc->Destroy = NULL; // No private data to destroy
2129
2130 bc->data = NULL;
2131
2133 PetscFunctionReturn(0);
2134}
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.

See also
Create_PeriodicDrivenConstant()

Definition at line 2278 of file BC_Handlers.c.

2279{
2280 PetscErrorCode ierr;
2281 PetscFunctionBeginUser;
2283
2284 PetscCheck(bc, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "BoundaryCondition is NULL");
2285
2286 // --- Allocate the private data structure ---
2287 DrivenFluxData *data = NULL;
2288 ierr = PetscNew(&data); CHKERRQ(ierr);
2289 // Initialize fields to safe default values
2290 data->direction = ' ';
2291 data->targetVolumetricFlux = 0.0;
2292 data->isMasterController = PETSC_FALSE;
2293 data->enforceSeamFlux = PETSC_FALSE;
2294 data->lastBulkCorrectionStep = -1;
2295
2296 // Attach the private data to the generic handler object
2297 bc->data = (void*)data;
2298
2299 // --- Configure the handler's properties and methods ---
2300
2301 // Set priority: Using BC_PRIORITY_INLET ensures this handler's PreStep runs
2302 // before other handlers (like outlets) that might depend on its calculations.
2303 // It is the caller's responsibility that there are no Inlets called along with driven periodic to avoid clash.
2305
2306 // Assign the function pointers to the implementations in this file.
2310 bc->PostStep = NULL; // This handler has no action after the main solver step.
2311 bc->UpdateUbcs = NULL; // The boundary value is not flow-dependent (it's periodic).
2313
2315 PetscFunctionReturn(0);
2316}
PetscBool enforceSeamFlux
PetscBool isMasterController
PetscInt lastBulkCorrectionStep
static PetscErrorCode Apply_PeriodicDrivenConstant(BoundaryCondition *self, BCContext *ctx)
Apply the configured constant driving term to the periodic boundary.
static PetscErrorCode Initialize_PeriodicDrivenConstant(BoundaryCondition *self, BCContext *ctx)
Initialize constant forcing data for a periodically driven boundary.
static PetscErrorCode Destroy_PeriodicDrivenConstant(BoundaryCondition *self)
Release resources owned by the constant periodic-driving boundary.
static PetscErrorCode PreStep_PeriodicDrivenConstant(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Prepare constant periodic-driving data before the solver step.
PetscReal targetVolumetricFlux
Private data structure shared by both periodic driven-flux handlers.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Create_PeriodicDrivenInitial()

PetscErrorCode Create_PeriodicDrivenInitial ( BoundaryCondition *  bc)

Configures a BoundaryCondition object for initial-flux periodic driving.

Wires the same periodic callbacks as Create_PeriodicDrivenConstant(), but the target flux is measured from the field the run starts with rather than read from the bcs file, so this handler takes no target_flux parameter. The latched target is checkpointed so a restart holds the original value.

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

Configures a BoundaryCondition object for initial-flux periodic driving.

See also
Create_PeriodicDrivenInitial()

Definition at line 2626 of file BC_Handlers.c.

2627{
2628 PetscErrorCode ierr;
2629 PetscFunctionBeginUser;
2631
2632 PetscCheck(bc, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "BoundaryCondition is NULL");
2633
2634 // --- Allocate the private data structure ---
2635 DrivenFluxData *data = NULL;
2636 ierr = PetscNew(&data); CHKERRQ(ierr);
2637 // Initialize fields to safe default values
2638 data->direction = ' ';
2639 data->targetVolumetricFlux = 0.0;
2640 data->isMasterController = PETSC_FALSE;
2641 data->enforceSeamFlux = PETSC_FALSE;
2642 data->lastBulkCorrectionStep = -1;
2643
2644 // Attach the private data to the generic handler object
2645 bc->data = (void*)data;
2646
2647 // --- Configure the handler's properties and methods ---
2648
2649 // Same priority reasoning as the constant-flux handler: PreStep must run
2650 // before any handler that depends on the controller's corrections.
2652
2655 bc->Apply = Apply_PeriodicDrivenConstant; // Boundary trim is target-agnostic.
2656 bc->PostStep = NULL; // This handler has no action after the main solver step.
2657 bc->UpdateUbcs = NULL; // The boundary value is not flow-dependent (it's periodic).
2658 bc->Destroy = Destroy_PeriodicDrivenConstant; // Same private data layout.
2659
2661 PetscFunctionReturn(0);
2662}
static PetscErrorCode Initialize_PeriodicDrivenInitial(BoundaryCondition *self, BCContext *ctx)
Initialize forcing data for a periodic boundary driven to its initial flux.
static PetscErrorCode PreStep_PeriodicDrivenInitial(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Latch the initial-state flux once, then drive to it like a constant target.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Create_WallMoving()

PetscErrorCode Create_WallMoving ( BoundaryCondition *  bc)

Creates a wall moving along itself at a velocity source, the prescribed inlet's without its flux.

Parameters
bcBoundary condition to fill.
Returns
PetscErrorCode 0 on success.

Creates a wall moving along itself at a velocity source, the prescribed inlet's without its flux.

See also
Create_WallMoving()

Definition at line 347 of file BC_Handlers.c.

348{
349 PetscFunctionBeginUser;
351 PetscCall(Create_InletPrescribedVelocity(bc));
354 bc->PostStep = NULL;
356 PetscFunctionReturn(0);
357}
static PetscErrorCode Apply_WallMoving(BoundaryCondition *self, BCContext *ctx)
Applies a moving wall's velocity through the path every prescribed face shares.
PetscErrorCode Create_InletPrescribedVelocity(BoundaryCondition *bc)
Implementation of Create_InletPrescribedVelocity().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LogPrescribedFlowDiagnostics()

PetscErrorCode LogPrescribedFlowDiagnostics ( UserCtx *  user)

Appends each prescribed-velocity inlet's flow rate and mean normal speed this step to inlet_flow.csv.

Collective.

Parameters
userBlock.
Returns
PetscErrorCode 0 on success.

Appends each prescribed-velocity inlet's flow rate and mean normal speed this step to inlet_flow.csv.

See also
LogPrescribedFlowDiagnostics()

Definition at line 1065 of file BC_Handlers.c.

1066{
1067 SimCtx *simCtx = user->simCtx;
1068
1069 PetscFunctionBeginUser;
1071 for (PetscInt face = 0; face < 6; ++face) {
1072 const BoundaryCondition *handler = user->boundary_faces[face].handler;
1073 PetscReal local[4], global[4], physical_time, flow_rate;
1074 FILE *file = NULL;
1075
1076 if (!handler || user->boundary_faces[face].handler_type != BC_HANDLER_INLET_PRESCRIBED_VELOCITY) continue;
1077 const InletPrescribedVelocityData *data = (const InletPrescribedVelocityData*)handler->data;
1078 if (!data->built) continue;
1079 PetscCall(PrescribedFaceSums(data, user, (BCFace)face, local));
1080 PetscCallMPI(MPI_Allreduce(local, global, 4, MPIU_REAL, MPI_SUM, PETSC_COMM_WORLD));
1081 if (simCtx->rank != 0 || user->_this != 0) continue;
1082 PetscCall(PicurvPhysicalTime(simCtx, simCtx->ti, &physical_time));
1083 flow_rate = data->factor * global[0] + global[1];
1084 PetscCall(PicurvOpenDiagnosticsCsv(simCtx, simCtx->analysis_dir, "inlet_flow.csv",
1085 "step,physical_time,face,area,flow_rate,mean_normal_speed,bulk_factor,"
1086 "fluctuation_flow_rate,applied_flow_rate",
1087 &file));
1088 /* flow_rate is the rescaled profile's, the one a bulk target controls; the synthetic
1089 fluctuations are added after the rescaling, so the flux the face actually admits is
1090 their sum. */
1091 fprintf(file, "%d,%.10e,%s,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e\n", (int)simCtx->step, (double)physical_time,
1092 BCFaceToString((BCFace)face), (double)global[2], (double)flow_rate,
1093 (double)(global[2] > 0.0 ? flow_rate / global[2] : 0.0), (double)data->factor,
1094 (double)global[3], (double)(flow_rate + global[3]));
1095 PetscCheck(fclose(file) == 0, PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE, "Unable to close the inlet-flow diagnostics file.");
1096 }
1098 PetscFunctionReturn(0);
1099}
static PetscErrorCode PrescribedFaceSums(const InletPrescribedVelocityData *data, UserCtx *user, BCFace face_id, PetscReal local[4])
This rank's area-weighted sums over the face, physical: the source's normal speed,...
PetscErrorCode PicurvPhysicalTime(const SimCtx *simCtx, PetscReal solver_time, PetscReal *physical)
Convert a solver time to physical seconds, t * L_ref / U_ref.
Definition io.c:2986
static PetscErrorCode PicurvOpenDiagnosticsCsv(SimCtx *simCtx, const char *dir, const char *filename, const char *header, FILE **file)
Opens a per-step diagnostics CSV: PicurvOpenRunCsv() with the common settings.
Definition logging.h:1197
#define PROFILE_HELPER_BEGIN
Marks the beginning of a profiled helper: timed only when enabled by name.
Definition logging.h:1014
#define PROFILE_HELPER_END
Alias of PROFILE_FUNCTION_END for a function that began with PROFILE_HELPER_BEGIN.
Definition logging.h:1033
The "virtual table" struct for a boundary condition handler object.
Definition variables.h:389
PetscMPIInt rank
Definition variables.h:919
SimCtx * simCtx
Back-pointer to the master simulation context.
Definition variables.h:1160
@ BC_HANDLER_INLET_PRESCRIBED_VELOCITY
Definition variables.h:348
PetscInt _this
Definition variables.h:1175
char analysis_dir[PETSC_MAX_PATH_LEN]
Definition variables.h:942
PetscInt step
Definition variables.h:924
PetscReal ti
Definition variables.h:925
BoundaryCondition * handler
Definition variables.h:430
The master context for the entire simulation.
Definition variables.h:916
Here is the call graph for this function:
Here is the caller graph for this function: