#include "momentumsolvers.h"Go to the source code of this file.
Data Structures | |
| struct | MomentumNewtonJacobian |
| struct | MomentumPreconditionerDescription |
| struct | MomentumPreconditionerModelOps |
| struct | MomentumPreconditionerEngine |
| struct | MomentumNewtonKrylovContext |
Macros | |
| #define | __FUNCT__ "MomentumNewtonKrylov_Validate" |
| #define | __FUNCT__ "MomentumNewtonKrylov_ReadLinearizationConfig" |
| #define | __FUNCT__ "FrozenMomentumJacobian_DescribePointBlock" |
| #define | __FUNCT__ "FrozenMomentumJacobian_AssemblePointBlocks" |
| #define | __FUNCT__ "MomentumPreconditionerEngine_ApplyConstraintRows" |
| #define | __FUNCT__ "MomentumNewtonJacobian_Create" |
| #define | __FUNCT__ "MomentumPreconditionerEngine_Create" |
| #define | __FUNCT__ "MomentumPreconditionerEngine_Assemble" |
| #define | __FUNCT__ "MomentumNewtonKrylov_FormJacobian" |
| #define | __FUNCT__ "MomentumPreconditionerEngine_CreateExactPointBlockMatrix" |
| #define | __FUNCT__ "MomentumNewtonKrylov_ApplyConstraints" |
| #define | __FUNCT__ "MomentumNewtonKrylov_FormResidual" |
| #define | __FUNCT__ "MomentumSolver_NewtonKrylov" |
Functions | |
| static PetscErrorCode | MomentumNewtonKrylov_Validate (UserCtx *user) |
| Rejects configurations outside the audited version-one feature set. | |
| static PetscErrorCode | MomentumNewtonKrylov_FormResidual (SNES snes, Vec X, Vec F, void *vctx) |
| Adapts a PETSc trial vector to the existing momentum residual path. | |
| static PetscErrorCode | MomentumNewtonKrylov_Monitor (SNES snes, PetscInt iteration, PetscReal norm, void *vctx) |
| Captures SNES iteration norms and optionally writes PICurv history rows. | |
| static PetscErrorCode | MomentumNewtonKrylov_LinearMonitor (KSP ksp, PetscInt iteration, PetscReal norm, void *vctx) |
| Writes the effective KSP tolerance and PETSc-reported norm for each inner iteration. | |
| static void | MomentumNewtonKrylov_OpenHistory (MomentumNewtonKrylovContext *ctx) |
| Opens the optional rank-zero Newton iteration-history file. | |
| static void | MomentumNewtonKrylov_WriteSummary (const MomentumNewtonKrylovContext *ctx, SNESConvergedReason reason, PetscInt nonlinear_its, PetscInt function_evals, PetscInt linear_its, PetscReal final_norm, PetscBool committed) |
| Appends one rank-zero structured Newton result for a physical step. | |
| static PetscErrorCode | MomentumNewtonKrylov_ApplyConstraints (MomentumNewtonKrylovContext *ctx, Vec X, Vec F) |
| Replaces every non-independent residual row with an explicit equation. | |
| static PetscErrorCode | MomentumNewtonKrylov_ReadLinearizationConfig (MomentumNewtonJacobian *jacobian, MomentumPreconditionerDescription *description) |
| Reads application-owned Jacobian and preconditioner mathematics. | |
| static PetscErrorCode | MomentumNewtonKrylov_FormJacobian (SNES snes, Vec current_solution, Mat jacobian_operator, Mat preconditioning_matrix, void *vctx) |
| Updates the Jacobian and then assembles any separate preconditioning matrix. | |
| static PetscErrorCode | FrozenMomentumJacobian_AssemblePointBlocks (UserCtx *user, Vec current_solution, Mat preconditioning_matrix) |
| Inserts only the audited interior frozen-momentum point blocks. | |
| static PetscErrorCode | MomentumPreconditionerEngine_CreateExactPointBlockMatrix (UserCtx *user, Mat *preconditioning_matrix) |
| Creates the frozen point-block P matrix with its exact scalar pattern. | |
| static MomentumRowType | MomentumNewtonKrylov_ClassifyRow (UserCtx *user, const PetscReal ***nvert, PetscInt i, PetscInt j, PetscInt k, PetscInt component, PetscInt *ri, PetscInt *rj, PetscInt *rk) |
| Row classification with solid-cell masking folded in. | |
| static PetscReal | FrozenMomentumJacobian_MetricNormSquared (Cmpnts metric) |
| Returns the squared Euclidean norm of one metric vector. | |
| static PetscReal | FrozenMomentumJacobian_FaceEddyViscosity (const UserCtx *user, const PetscReal ***nu_t, PetscInt axis, PetscInt i, PetscInt j, PetscInt k) |
| Returns the face-averaged eddy viscosity the residual uses on one face. | |
| static void | FrozenMomentumJacobian_PointBlock (const UserCtx *user, const Cmpnts ***ucont, const Cmpnts ***csi, const Cmpnts ***eta, const Cmpnts ***zet, const PetscReal ***aj, const PetscReal ***nu_t, PetscInt i, PetscInt j, PetscInt k, PetscScalar block[9]) |
| Returns the frozen-momentum point block for the current residual convention. | |
| static PetscErrorCode | FrozenMomentumJacobian_DescribePointBlock (UserCtx *user, MomentumPreconditionerDescription *description) |
| Describes the audited frozen-coefficient point-block model. | |
| static PetscErrorCode | MomentumPreconditionerEngine_ApplyConstraintRows (UserCtx *user, Mat preconditioning_matrix) |
| Inserts all common fixed, homogeneous, and periodic-duplicate rows. | |
| static PetscErrorCode | MomentumNewtonJacobian_Create (SNES snes, MomentumNewtonJacobian *jacobian) |
| Creates the selected Jacobian operator; currently PETSc MFFD only. | |
| static PetscErrorCode | MomentumNewtonJacobian_Update (SNES snes, Vec current_solution, MomentumNewtonJacobian *jacobian) |
| Updates the matrix-free finite-difference operator base. | |
| static PetscErrorCode | MomentumNewtonJacobian_Register (SNES snes, MomentumNewtonJacobian *jacobian, MomentumPreconditionerEngine *engine, MomentumNewtonKrylovContext *ctx) |
| Registers the application orchestration callback and both SNES matrices. | |
| static PetscErrorCode | MomentumNewtonJacobian_Destroy (MomentumNewtonJacobian *jacobian) |
| Destroys a partially or fully created Jacobian operator. | |
| static PetscErrorCode | MomentumPreconditionerEngine_Create (UserCtx *user, Mat jacobian_operator, const MomentumPreconditionerDescription *requested, MomentumPreconditionerEngine *engine) |
| Validates a model/structure and creates or aliases its matrix. | |
| static PetscErrorCode | MomentumPreconditionerEngine_Assemble (MomentumPreconditionerEngine *engine, UserCtx *user, Vec current_solution) |
| Runs model insertion, common row handling, and final assembly. | |
| static PetscErrorCode | MomentumPreconditionerEngine_ConfigurePetscPC (MomentumPreconditionerEngine *engine, PC pc) |
| Applies the validated model/structure-to-PETSc-PC mapping. | |
| static PetscErrorCode | MomentumPreconditionerEngine_ValidatePetscPC (MomentumPreconditionerEngine *engine, PC pc) |
| Rejects raw options that select an unvalidated PETSc PC backend. | |
| static PetscErrorCode | MomentumPreconditionerEngine_Destroy (MomentumPreconditionerEngine *engine) |
| Destroys only a separately owned preconditioning matrix. | |
| PetscErrorCode | MomentumSolver_NewtonKrylov (UserCtx *user, IBMNodes *ibm, FSInfo *fsi) |
| Solves one physical momentum step with matrix-free Newton–Krylov. | |
Variables | |
| static const MomentumPreconditionerModelOps | frozen_momentum_point_block_ops |
| struct MomentumNewtonJacobian |
Definition at line 11 of file momentum_newton_krylov.c.
| Data Fields | ||
|---|---|---|
| MomentumNewtonJacobianType | type | |
| MomentumNewtonFiniteDifferenceMode | finite_difference_mode | |
| Mat | jacobian_operator | |
| struct MomentumPreconditionerDescription |
Definition at line 27 of file momentum_newton_krylov.c.
| Data Fields | ||
|---|---|---|
| MomentumPreconditionerModel | model | |
| MomentumPreconditionerStructure | structure | |
| PetscInt | block_size | |
| PetscInt | stencil_width | |
| struct MomentumPreconditionerEngine |
Definition at line 39 of file momentum_newton_krylov.c.
| Data Fields | ||
|---|---|---|
| MomentumPreconditionerDescription | description | |
| const MomentumPreconditionerModelOps * | model_ops | |
| Mat | preconditioning_matrix | |
| PetscBool | aliases_jacobian_operator | |
| PetscBool | owns_preconditioning_matrix | |
| const char * | petsc_pc_type | |
| struct MomentumNewtonKrylovContext |
Definition at line 48 of file momentum_newton_krylov.c.
| Data Fields | ||
|---|---|---|
| UserCtx * | user | |
| SNES | snes | |
| FILE * | history_file | |
| FILE * | linear_history_file | |
| PetscBool | have_initial_norm | |
| PetscReal | initial_norm | |
| MomentumNewtonJacobian | jacobian | |
| MomentumPreconditionerEngine | preconditioning_engine | |
| #define __FUNCT__ "MomentumNewtonKrylov_Validate" |
Definition at line 240 of file momentum_newton_krylov.c.
| #define __FUNCT__ "MomentumNewtonKrylov_ReadLinearizationConfig" |
Definition at line 240 of file momentum_newton_krylov.c.
| #define __FUNCT__ "FrozenMomentumJacobian_DescribePointBlock" |
Definition at line 240 of file momentum_newton_krylov.c.
| #define __FUNCT__ "FrozenMomentumJacobian_AssemblePointBlocks" |
Definition at line 240 of file momentum_newton_krylov.c.
| #define __FUNCT__ "MomentumPreconditionerEngine_ApplyConstraintRows" |
Definition at line 240 of file momentum_newton_krylov.c.
| #define __FUNCT__ "MomentumNewtonJacobian_Create" |
Definition at line 240 of file momentum_newton_krylov.c.
| #define __FUNCT__ "MomentumPreconditionerEngine_Create" |
Definition at line 240 of file momentum_newton_krylov.c.
| #define __FUNCT__ "MomentumPreconditionerEngine_Assemble" |
Definition at line 240 of file momentum_newton_krylov.c.
| #define __FUNCT__ "MomentumNewtonKrylov_FormJacobian" |
Definition at line 240 of file momentum_newton_krylov.c.
| #define __FUNCT__ "MomentumPreconditionerEngine_CreateExactPointBlockMatrix" |
Definition at line 240 of file momentum_newton_krylov.c.
| #define __FUNCT__ "MomentumNewtonKrylov_ApplyConstraints" |
Definition at line 240 of file momentum_newton_krylov.c.
| #define __FUNCT__ "MomentumNewtonKrylov_FormResidual" |
Definition at line 240 of file momentum_newton_krylov.c.
| #define __FUNCT__ "MomentumSolver_NewtonKrylov" |
Definition at line 240 of file momentum_newton_krylov.c.
| Enumerator | |
|---|---|
| MOM_NK_JACOBIAN_FINITE_DIFFERENCE | |
Definition at line 3 of file momentum_newton_krylov.c.
| Enumerator | |
|---|---|
| MOM_NK_FD_MODE_MATRIX_FREE | |
Definition at line 7 of file momentum_newton_krylov.c.
| Enumerator | |
|---|---|
| MOM_NK_PC_MODEL_NONE | |
| MOM_NK_PC_MODEL_FROZEN_MOMENTUM_JACOBIAN | |
Definition at line 17 of file momentum_newton_krylov.c.
| Enumerator | |
|---|---|
| MOM_NK_PC_STRUCTURE_NONE | |
| MOM_NK_PC_STRUCTURE_POINT_BLOCK | |
Definition at line 22 of file momentum_newton_krylov.c.
|
static |
Rejects configurations outside the audited version-one feature set.
| user | Single-block momentum context to validate. |
Definition at line 246 of file momentum_newton_krylov.c.
|
static |
Adapts a PETSc trial vector to the existing momentum residual path.
A matrix-free SNES residual must be a deterministic function of the trial vector X alone: F(X) may not depend on any state left by a previous residual or MFFD evaluation, or finite-difference Jacobian actions become inconsistent. To honor that contract this callback fully derives the Cartesian velocity state (Ucat/lUcat) from X before the first boundary sweep – see the inline comment below for why ApplyBoundaryConditions()'s own internal reconstruction is not sufficient for the first outlet pass.
State invariants:
Side effects: overwrites user->Ucont/lUcont, user->Ucat/lUcat, user->Rhs, the boundary Ubcs targets, and boundary flux/area diagnostics; writes F.
| snes | Calling nonlinear solver. |
| X | Trial solution (read-only). |
| F | Residual output. |
| vctx | Pointer to MomentumNewtonKrylovContext. |
Definition at line 1130 of file momentum_newton_krylov.c.
|
static |
Captures SNES iteration norms and optionally writes PICurv history rows.
SNES supplies the already-computed norm, so this monitor never causes an additional nonlinear residual evaluation. PETSc monitors selected through -mom_nk_snes_monitor remain independent and may run alongside this callback.
Definition at line 92 of file momentum_newton_krylov.c.
|
static |
Writes the effective KSP tolerance and PETSc-reported norm for each inner iteration.
The tolerance is queried after SNES has applied any inexact-Newton forcing update, so the log distinguishes changing Eisenstat–Walker requests from changing linear convergence behavior.
Definition at line 120 of file momentum_newton_krylov.c.
|
static |
Opens the optional rank-zero Newton iteration-history file.
Definition at line 142 of file momentum_newton_krylov.c.
|
static |
Appends one rank-zero structured Newton result for a physical step.
File failures are deliberately diagnostic-only: rollback and PETSc cleanup must retain their original error behavior.
Definition at line 187 of file momentum_newton_krylov.c.
|
static |
Replaces every non-independent residual row with an explicit equation.
Which rows are non-independent is decided by ClassifyMomentumRow(), shared with the residual path; only the action taken differs. Conditioned face-normal rows use F=X-Uconditioned, unconditioned legacy dummy/tangential rows use F=X, and periodic duplicates use Fdup=Xdup-Xrep. These equations prevent the zero Jacobian rows that EnforceRHSBoundaryConditions()'s zeroing would produce in a matrix-free Newton operator. Immersed, masked, TwoD, and interface rows are rejected before this callback is installed.
| ctx | Active solve context. |
| X | Unconditioned PETSc trial state. |
| F | Residual vector to update in place. |
Definition at line 1050 of file momentum_newton_krylov.c.
|
static |
Reads application-owned Jacobian and preconditioner mathematics.
Definition at line 335 of file momentum_newton_krylov.c.
|
static |
Updates the Jacobian and then assembles any separate preconditioning matrix.
Definition at line 863 of file momentum_newton_krylov.c.
|
static |
Inserts only the audited interior frozen-momentum point blocks.
Definition at line 600 of file momentum_newton_krylov.c.
|
static |
Creates the frozen point-block P matrix with its exact scalar pattern.
Row and column ownership follows the velocity DMDA global vector. Physical rows reserve the three same-point components, fixed rows reserve only their diagonal, and periodic duplicate rows additionally reserve their wrapped representative. DMDA AO, local mapping, and stencil metadata are retained so the existing insertion paths keep their exact ordering.
Definition at line 886 of file momentum_newton_krylov.c.
|
static |
Row classification with solid-cell masking folded in.
A masked row's residual is identically zero for every X, so it has a zero Jacobian row and a zero column and its unknown is undetermined. It therefore needs the same identity treatment as any other row carrying no unknown. Checked after the boundary classification so a periodic duplicate keeps its representative column.
Definition at line 402 of file momentum_newton_krylov.c.
|
static |
Returns the squared Euclidean norm of one metric vector.
Definition at line 414 of file momentum_newton_krylov.c.
|
static |
Returns the face-averaged eddy viscosity the residual uses on one face.
The preconditioner has to reproduce the operator it preconditions, so the interior face average here tracks Viscous().
The WALL branch below does not, and is retained only because it cannot currently change an assembled entry. It is unreachable by construction, not by configuration: FrozenMomentumJacobian_PointBlock() puts the eddy viscosity only on the three diagonal entries, and the row-at-a-time insertion in FrozenMomentumJacobian_AssemblePointBlocks() means row c carries only axis == c. The two coordinates that trigger the branch are exactly those ClassifyMomentumRow() reports as non-MOM_ROW_PHYSICAL, and only physical rows assemble a block; the WALL-on-a-periodic-axis loophole is closed by the pairing check in BoundarySystem_Validate(). Both rules state the same boundary fact: the wall-normal flux at a no-slip wall is not an unknown.
Viscous() substitutes the wall-model eddy viscosity lnu_wall on a wall face and falls back to zero only when simCtx->wallfunction is unset, so this branch is already wrong for a wall-modelled run – it simply has no way to express that yet. Widening the stencil makes it reachable and therefore wrong in effect: an interior row would need the eddy viscosity on the wall face for its off-diagonal. Fix this to read lNu_Wall before adding any preconditioner with stencil_width >= 1, or any row classification that makes wall-normal DOFs solvable. Tracked as issue #8.
Definition at line 444 of file momentum_newton_krylov.c.
|
static |
Returns the frozen-momentum point block for the current residual convention.
Definition at line 466 of file momentum_newton_krylov.c.
|
static |
Describes the audited frozen-coefficient point-block model.
Definition at line 583 of file momentum_newton_krylov.c.
|
static |
Inserts all common fixed, homogeneous, and periodic-duplicate rows.
Definition at line 679 of file momentum_newton_krylov.c.
|
static |
Creates the selected Jacobian operator; currently PETSc MFFD only.
Definition at line 724 of file momentum_newton_krylov.c.
|
static |
Updates the matrix-free finite-difference operator base.
Definition at line 740 of file momentum_newton_krylov.c.
|
static |
Registers the application orchestration callback and both SNES matrices.
Definition at line 750 of file momentum_newton_krylov.c.
|
static |
Destroys a partially or fully created Jacobian operator.
Definition at line 762 of file momentum_newton_krylov.c.
|
static |
Validates a model/structure and creates or aliases its matrix.
Definition at line 772 of file momentum_newton_krylov.c.
|
static |
Runs model insertion, common row handling, and final assembly.
Definition at line 807 of file momentum_newton_krylov.c.
|
static |
Applies the validated model/structure-to-PETSc-PC mapping.
Definition at line 823 of file momentum_newton_krylov.c.
|
static |
Rejects raw options that select an unvalidated PETSc PC backend.
Definition at line 832 of file momentum_newton_krylov.c.
|
static |
Destroys only a separately owned preconditioning matrix.
Definition at line 849 of file momentum_newton_krylov.c.
Solves one physical momentum step with matrix-free Newton–Krylov.
The Jacobian operator is the finite-difference, matrix-free operator of the complete deterministic residual. With no mathematical preconditioner its matrix is also passed to PETSc's preconditioning slot and PCNONE is derived. The optional provisional frozen-momentum, point-block model approximates same-cell frozen coupling, owns a separate matrix, and derives a block-Jacobi PETSc backend. It does not relax the version-one physics or boundary-condition restrictions. All PETSc solver objects are local to this call. Rows removed by legacy boundary residual enforcement are made explicit: conditioned normal rows use X-Uconditioned, untouched dummy/tangential rows use X, and periodic duplicates use Xdup-Xrepresentative. Unsupported masked, interface, and component-disabled rows are rejected before setup.
| user | Single-block momentum context. |
| ibm | Must be NULL; immersed boundaries are not supported in version one. |
| fsi | Must be NULL; moving-body coupling is not supported in version one. |
Definition at line 1195 of file momentum_newton_krylov.c.
|
static |
Definition at line 716 of file momentum_newton_krylov.c.