PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
rhs.h
Go to the documentation of this file.
1#ifndef RHS_H
2#define RHS_H
3
4#include "variables.h" // Provides definitions for UserCtx, SimCtx, IBMNodes, etc.
5#include "logging.h"
6#include "Metric.h"
7#include "BodyForces.h"
8#include "poisson.h" // POISSON_SOLID_THRESHOLD and the face gradient shared with the projection
9
10/** Cells whose `nvert` exceeds this are blanked inner-body cells, which convect as fluid. */
11#define RHS_INNER_BLANK 7.0
12
13/**
14 * @brief Whether a cell takes part in convection: fluid, or a blanked inner-body cell. A face
15 * next to any other cell takes ComputeConvection()'s one-sided QUICK stencil.
16 * @param[in] nvert The cell's solid field.
17 * @return PETSC_TRUE for `nvert < POISSON_SOLID_THRESHOLD` or `nvert > RHS_INNER_BLANK`.
18 */
19static inline PetscBool RHSConvectsAsFluid(PetscReal nvert)
20{
21 return (PetscBool)(nvert < POISSON_SOLID_THRESHOLD || nvert > RHS_INNER_BLANK);
22}
23
24/**
25 * @brief Whether a cell is a blanked solid cell, which ComputeViscous()'s transverse
26 * differences avoid with a one-sided stencil.
27 * @param[in] nvert The cell's solid field.
28 * @return PETSC_TRUE for `0.5 < nvert < RHS_INNER_BLANK`.
29 */
30static PICURV_ALWAYS_INLINE PetscBool RHSIsBlankedSolid(PetscReal nvert)
31{
32 return (PetscBool)(nvert > 0.5 && nvert < RHS_INNER_BLANK);
33}
34
35/**
36 * @brief Computes the viscous contribution to the contravariant momentum RHS.
37 *
38 * This routine evaluates diffusive fluxes on the curvilinear grid and writes the
39 * resulting term into `Visc`, which it zeroes first. The caller is responsible for
40 * providing compatible vectors and for assembling any additional source terms afterwards.
41 *
42 * @param[in] user Block-level solver context containing metrics and model parameters.
43 * @param[in] Ucat Ghosted Cartesian velocity field used for derivative evaluation.
44 * @param[out] Visc Output vector receiving the viscous RHS contribution.
45 * @return PetscErrorCode 0 on success.
46 */
47PetscErrorCode ComputeViscous(UserCtx *user, Vec Ucat, Vec Visc);
48
49/**
50 * @brief Computes the convective contribution to the contravariant momentum RHS.
51 *
52 * This routine evaluates the advection operator on the current velocity state and
53 * stores the contribution in `Conv`, which it zeroes first, for subsequent combination
54 * with viscous and body-force terms.
55 *
56 * @param[in] user Block-level solver context containing metrics and numerics settings.
57 * @param[in] Ucont Contravariant velocity field used in face-normal flux construction.
58 * @param[in] Ucat Cartesian velocity field used by the convective stencil.
59 * @param[out] Conv Output vector receiving the convection RHS contribution.
60 * @return PetscErrorCode 0 on success.
61 */
62PetscErrorCode ComputeConvection(UserCtx *user, Vec Ucont, Vec Ucat, Vec Conv);
63
64/**
65 * @brief General dispatcher for applying all active body forces (momentum sources).
66 *
67 * This function serves as a central hub for adding momentum source terms to the
68 * contravariant right-hand-side (Rct) of the momentum equations. It is called once per RHS
69 * evaluation (e.g., once per Runge-Kutta stage).
70 *
71 * It introspects the simulation configuration to determine which, if any, body
72 * forces are active and calls their specific implementation functions.
73 *
74 * @param user The UserCtx containing the simulation state for a single block.
75 * @param Rct The PETSc Vec for the contravariant RHS, modified in place.
76 * @return PetscErrorCode 0 on success.
77 */
78PetscErrorCode ComputeBodyForces(UserCtx *user, Vec Rct);
79
80/**
81 * @brief Computes the Right-Hand Side (RHS) of the momentum equations.
82 *
83 * This function calculates the contribution of the convective and diffusive terms.
84 * It is called by the momentum solvers (e.g., RungeKutta).
85 *
86 * @param user The UserCtx for a single block.
87 * @param Rhs The PETSc Vec where the RHS result will be stored.
88 * @return PetscErrorCode 0 on success.
89 */
90extern PetscErrorCode ComputeRHS(UserCtx *user, Vec Rhs);
91
92#endif // RHS_H
Momentum source terms added to the contravariant RHS.
Logging utilities and macros for PETSc-based applications.
Pressure-Poisson projection: the multigrid pressure-correction solve, the pressure update,...
PetscErrorCode ComputeBodyForces(UserCtx *user, Vec Rct)
General dispatcher for applying all active body forces (momentum sources).
Definition rhs.c:426
PetscErrorCode ComputeConvection(UserCtx *user, Vec Ucont, Vec Ucat, Vec Conv)
Computes the convective contribution to the contravariant momentum RHS.
Definition rhs.c:96
static PetscBool RHSIsBlankedSolid(PetscReal nvert)
Whether a cell is a blanked solid cell, which ComputeViscous()'s transverse differences avoid with a ...
Definition rhs.h:30
#define RHS_INNER_BLANK
Cells whose nvert exceeds this are blanked inner-body cells, which convect as fluid.
Definition rhs.h:11
PetscErrorCode ComputeViscous(UserCtx *user, Vec Ucat, Vec Visc)
Computes the viscous contribution to the contravariant momentum RHS.
Definition rhs.c:346
static PetscBool RHSConvectsAsFluid(PetscReal nvert)
Whether a cell takes part in convection: fluid, or a blanked inner-body cell.
Definition rhs.h:19
PetscErrorCode ComputeRHS(UserCtx *user, Vec Rhs)
Computes the Right-Hand Side (RHS) of the momentum equations.
Definition rhs.c:616
Main header file for a complex fluid dynamics solver.
#define PICURV_ALWAYS_INLINE
Forces inlining of a per-cell or per-face kernel whose size defeats the compiler's inlining heuristic...
Definition variables.h:65
User-defined context containing data specific to a single computational grid level.
Definition variables.h:1157