|
PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
|
#include <petsc.h>#include "variables.h"#include "logging.h"#include <stdlib.h>#include "io.h"#include "setup.h"Go to the source code of this file.
Functions | |
| PetscErrorCode | MetricLogicalToPhysical (UserCtx *user, const Cmpnts ***X, PetscInt i, PetscInt j, PetscInt k, PetscReal xi, PetscReal eta, PetscReal zta, Cmpnts *Xp) |
| Maps a logical point inside one hexahedral cell to physical space. | |
| PetscErrorCode | MetricGetCellVertices (UserCtx *user, const Cmpnts ***X, PetscInt i, PetscInt j, PetscInt k, Cmpnts V[8]) |
| Collects the eight node coordinates of one logical hexahedral cell. | |
| PetscErrorCode | MetricJacobian (UserCtx *user, const Cmpnts ***X, PetscInt i, PetscInt j, PetscInt k, PetscReal xi, PetscReal eta, PetscReal zta, PetscReal J[3][3], PetscReal *detJ) |
| Evaluates the trilinear mapping Jacobian and its determinant in one cell. | |
| PetscErrorCode | MetricVelocityContravariant (const PetscReal J[3][3], PetscReal detJ, const PetscReal u[3], PetscReal uc[3]) |
| Converts a Cartesian velocity vector to contravariant logical components. | |
| PetscErrorCode | CalculateFaceNormalAndArea (Cmpnts csi, Cmpnts eta, Cmpnts zet, double ni[3], double nj[3], double nk[3], double *Ai, double *Aj, double *Ak) |
| Computes the unit normal vectors and areas of the three faces of a computational cell. | |
| PetscErrorCode | InvertCovariantMetricTensor (double covariantTensor[3][3], double contravariantTensor[3][3]) |
| Inverts the 3x3 covariant metric tensor to obtain the contravariant metric tensor. | |
| PetscErrorCode | ComputeCellCharacteristicLengthScale (PetscReal ajc, Cmpnts csi, Cmpnts eta, Cmpnts zet, double *dx, double *dy, double *dz) |
| Computes characteristic length scales (dx, dy, dz) for a curvilinear cell. | |
| PetscErrorCode | ApplyPeriodicCorrectionsToCellCentersAndSpacing (UserCtx *user) |
| Builds translated periodic images for cell centers and grid spacing. | |
| PetscErrorCode | ApplyPeriodicCorrectionsToIFaceCenter (UserCtx *user) |
| Builds translated periodic images for i-face centers (Centx). | |
| PetscErrorCode | ApplyPeriodicCorrectionsToJFaceCenter (UserCtx *user) |
| Builds translated periodic images for j-face centers (Centy). | |
| PetscErrorCode | ApplyPeriodicCorrectionsToKFaceCenter (UserCtx *user) |
| Builds translated periodic images for k-face centers (Centz). | |
| PetscErrorCode | ComputeFaceMetrics (UserCtx *user) |
| Computes the primary face metric components (Csi, Eta, Zet), including boundary extrapolation, and stores them in the corresponding global Vec members of the UserCtx structure (user->Csi, user->Eta, user->Zet). | |
| PetscErrorCode | ComputeCellCenteredJacobianInverse (UserCtx *user) |
Calculates the cell-centered inverse Jacobian determinant (1/J) for INTERIOR cells and stores it in user->Aj. | |
| PetscErrorCode | CheckAndFixGridOrientation (UserCtx *user) |
Verify and, when consistently inverted, repair the right-handed metric basis (Csi, Eta, Zet) and a positive Jacobian (Aj) over the whole domain. | |
| PetscErrorCode | ComputeCellCentersAndSpacing (UserCtx *user) |
| Computes the physical location of cell centers and the spacing between them. | |
| PetscErrorCode | ComputeIFaceMetrics (UserCtx *user) |
| Computes metrics centered on constant-i faces (i-faces). | |
| PetscErrorCode | ComputeJFaceMetrics (UserCtx *user) |
| Computes metrics centered on constant-j faces (j-faces). | |
| PetscErrorCode | ComputeKFaceMetrics (UserCtx *user) |
| Computes metrics centered on constant-k faces (k-faces). | |
| PetscErrorCode | ComputeMetricsDivergence (UserCtx *user) |
| Performs a diagnostic check on the divergence of the face area metric vectors. | |
| PetscErrorCode | ComputeMetricNorms (UserCtx *user) |
| Computes the max-min values of the grid metrics. | |
| PetscErrorCode | CalculateAllGridMetrics (SimCtx *simCtx) |
| Orchestrates the calculation of all grid metrics. | |
| PetscErrorCode MetricLogicalToPhysical | ( | UserCtx * | user, |
| const Cmpnts *** | X, | ||
| PetscInt | i, | ||
| PetscInt | j, | ||
| PetscInt | k, | ||
| PetscReal | xi, | ||
| PetscReal | eta, | ||
| PetscReal | zta, | ||
| Cmpnts * | Xp | ||
| ) |
Maps a logical point inside one hexahedral cell to physical space.
Uses trilinear interpolation of the eight cell vertices. Logical coordinates are measured from the cell's lower logical corner and normally lie in [0, 1].
| user | Grid context used for cell indexing. | |
| X | Ghosted node-coordinate array for the block. | |
| i | Cell index in the xi direction. | |
| j | Cell index in the eta direction. | |
| k | Cell index in the zeta direction. | |
| xi | Local xi coordinate within the cell. | |
| eta | Local eta coordinate within the cell. | |
| zta | Local zeta coordinate within the cell. | |
| [out] | Xp | Physical Cartesian position evaluated at the logical point. |
Maps a logical point inside one hexahedral cell to physical space.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Metric.h.
Definition at line 76 of file Metric.c.
| PetscErrorCode MetricGetCellVertices | ( | UserCtx * | user, |
| const Cmpnts *** | X, | ||
| PetscInt | i, | ||
| PetscInt | j, | ||
| PetscInt | k, | ||
| Cmpnts | V[8] | ||
| ) |
Collects the eight node coordinates of one logical hexahedral cell.
Vertex ordering matches the trilinear metric kernels in this module.
| user | Grid context used for cell indexing. | |
| X | Ghosted node-coordinate array for the block. | |
| i | Cell index in the xi direction. | |
| j | Cell index in the eta direction. | |
| k | Cell index in the zeta direction. | |
| [out] | V | Eight physical vertex coordinates in metric-kernel order. |
Collects the eight node coordinates of one logical hexahedral cell.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Metric.h.
Definition at line 26 of file Metric.c.
| PetscErrorCode MetricJacobian | ( | UserCtx * | user, |
| const Cmpnts *** | X, | ||
| PetscInt | i, | ||
| PetscInt | j, | ||
| PetscInt | k, | ||
| PetscReal | xi, | ||
| PetscReal | eta, | ||
| PetscReal | zta, | ||
| PetscReal | J[3][3], | ||
| PetscReal * | detJ | ||
| ) |
Evaluates the trilinear mapping Jacobian and its determinant in one cell.
The returned matrix is \(\partial(x,y,z)/\partial(\xi,\eta,\zeta)\); callers use its determinant to reject degenerate or inverted cells.
| user | Grid context used for cell indexing. | |
| X | Ghosted node-coordinate array for the block. | |
| i | Cell index in the xi direction. | |
| j | Cell index in the eta direction. | |
| k | Cell index in the zeta direction. | |
| xi | Local xi coordinate within the cell. | |
| eta | Local eta coordinate within the cell. | |
| zta | Local zeta coordinate within the cell. | |
| [out] | J | Mapping Jacobian in row-major Cartesian/logical form. |
| [out] | detJ | Determinant of J. |
Evaluates the trilinear mapping Jacobian and its determinant in one cell.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Metric.h.
Definition at line 105 of file Metric.c.
| PetscErrorCode MetricVelocityContravariant | ( | const PetscReal | J[3][3], |
| PetscReal | detJ, | ||
| const PetscReal | u[3], | ||
| PetscReal | uc[3] | ||
| ) |
Converts a Cartesian velocity vector to contravariant logical components.
Uses the inverse of the physical-to-logical Jacobian; detJ must describe the same mapping as J and must be nonzero.
| J | Mapping Jacobian at the evaluation point. | |
| detJ | Determinant of J. | |
| u | Cartesian velocity components. | |
| [out] | uc | Contravariant xi/eta/zeta velocity components. |
Converts a Cartesian velocity vector to contravariant logical components.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Metric.h.
Definition at line 165 of file Metric.c.
| PetscErrorCode CalculateFaceNormalAndArea | ( | Cmpnts | csi, |
| Cmpnts | eta, | ||
| Cmpnts | zet, | ||
| double | ni[3], | ||
| double | nj[3], | ||
| double | nk[3], | ||
| double * | Ai, | ||
| double * | Aj, | ||
| double * | Ak | ||
| ) |
Computes the unit normal vectors and areas of the three faces of a computational cell.
Given the metric vectors (csi, eta, zet), this function calculates the geometric properties of the cell faces aligned with the i, j, and k directions.
| csi | Covariant xi metric vector. | |
| eta | Covariant eta metric vector. | |
| zet | Covariant zeta metric vector. | |
| [out] | ni | Unit normal of the xi-normal face. |
| [out] | nj | Unit normal of the eta-normal face. |
| [out] | nk | Unit normal of the zeta-normal face. |
| [out] | Ai | Area of the xi-normal face. |
| [out] | Aj | Area of the eta-normal face. |
| [out] | Ak | Area of the zeta-normal face. |
Computes the unit normal vectors and areas of the three faces of a computational cell.
Local to this translation unit.
Definition at line 236 of file Metric.c.
| PetscErrorCode InvertCovariantMetricTensor | ( | double | covariantTensor[3][3], |
| double | contravariantTensor[3][3] | ||
| ) |
Inverts the 3x3 covariant metric tensor to obtain the contravariant metric tensor.
In curvilinear coordinates, the input matrix g contains the dot products of the covariant basis vectors (e.g., g_ij = e_i . e_j). Its inverse, G, is the contravariant metric tensor, which is essential for transforming vectors and tensors between coordinate systems.
| covariantTensor | Input: A 3x3 matrix representing the covariant metric tensor. | |
| [out] | contravariantTensor | Inverse metric tensor written in place. |
Inverts the 3x3 covariant metric tensor to obtain the contravariant metric tensor.
Local to this translation unit.
Definition at line 202 of file Metric.c.
| PetscErrorCode ComputeCellCharacteristicLengthScale | ( | PetscReal | ajc, |
| Cmpnts | csi, | ||
| Cmpnts | eta, | ||
| Cmpnts | zet, | ||
| double * | dx, | ||
| double * | dy, | ||
| double * | dz | ||
| ) |
Computes characteristic length scales (dx, dy, dz) for a curvilinear cell.
For a non-uniform, non-orthogonal cell, there is no single "dx". This function computes an effective length scale in each Cartesian direction based on the cell volume and the areas of its faces.
| ajc | Cell Jacobian/volume metric at the cell center. | |
| csi | Covariant xi metric vector. | |
| eta | Covariant eta metric vector. | |
| zet | Covariant zeta metric vector. | |
| [out] | dx | Effective physical length associated with xi variation. |
| [out] | dy | Effective physical length associated with eta variation. |
| [out] | dz | Effective physical length associated with zeta variation. |
Computes characteristic length scales (dx, dy, dz) for a curvilinear cell.
Local to this translation unit.
Definition at line 282 of file Metric.c.
| PetscErrorCode ApplyPeriodicCorrectionsToCellCentersAndSpacing | ( | UserCtx * | user | ) |
Builds translated periodic images for cell centers and grid spacing.
PETSc wraps field indices but does not translate coordinates. This routine applies the validated per-axis geometric translation to wrapped center coordinates and refreshes the associated local grid spacing.
| user | The UserCtx containing grid and field data. |
Builds translated periodic images for cell centers and grid spacing.
Local to this translation unit.
Definition at line 391 of file Metric.c.
| PetscErrorCode ApplyPeriodicCorrectionsToIFaceCenter | ( | UserCtx * | user | ) |
Builds translated periodic images for i-face centers (Centx).
Every active periodic axis can affect the ghost images of Centx. This must be called after Centx is computed and before it is used for metric calculations.
| user | The UserCtx containing grid and field data. |
Builds translated periodic images for i-face centers (Centx).
Local to this translation unit.
Definition at line 590 of file Metric.c.
| PetscErrorCode ApplyPeriodicCorrectionsToJFaceCenter | ( | UserCtx * | user | ) |
Builds translated periodic images for j-face centers (Centy).
Every active periodic axis can affect the ghost images of Centy. This must be called after Centy is computed and before it is used for metric calculations.
| user | The UserCtx containing grid and field data. |
Builds translated periodic images for j-face centers (Centy).
Local to this translation unit.
Definition at line 606 of file Metric.c.
| PetscErrorCode ApplyPeriodicCorrectionsToKFaceCenter | ( | UserCtx * | user | ) |
Builds translated periodic images for k-face centers (Centz).
Every active periodic axis can affect the ghost images of Centz. This must be called after Centz is computed and before it is used for metric calculations.
| user | The UserCtx containing grid and field data. |
Builds translated periodic images for k-face centers (Centz).
Local to this translation unit.
Definition at line 622 of file Metric.c.
| PetscErrorCode ComputeFaceMetrics | ( | UserCtx * | user | ) |
Computes the primary face metric components (Csi, Eta, Zet), including boundary extrapolation, and stores them in the corresponding global Vec members of the UserCtx structure (user->Csi, user->Eta, user->Zet).
This is a self-contained routine that performs the following steps:
user->Csi, user->Eta, user->Zet Vecs.user->lCsi, user->lEta, user->lZet Vecs.| [in,out] | user | Pointer to the UserCtx structure. |
VecZeroEntries on user->Csi, Eta, Zet before this if they might contain old data.Computes the primary face metric components (Csi, Eta, Zet), including boundary extrapolation, and stores them in the corresponding global Vec members of the UserCtx structure (user->Csi, user->Eta, user->Zet).
Local to this translation unit.
Definition at line 637 of file Metric.c.
| PetscErrorCode ComputeCellCenteredJacobianInverse | ( | UserCtx * | user | ) |
Calculates the cell-centered inverse Jacobian determinant (1/J) for INTERIOR cells and stores it in user->Aj.
This version includes boundary extrapolation.
Nodal coordinates are obtained internally. Refer to previous Doxygen comments for details on physical locations and storage convention (aj_arr[k_n][j_n][i_n] for cell C(i_n-1,j_n-1,k_n-1)).
| [in,out] | user | Pointer to the UserCtx structure. |
Calculates the cell-centered inverse Jacobian determinant (1/J) for INTERIOR cells and stores it in user->Aj.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/Metric.h.
Definition at line 849 of file Metric.c.
| PetscErrorCode CheckAndFixGridOrientation | ( | UserCtx * | user | ) |
Verify and, when consistently inverted, repair the right-handed metric basis (Csi, Eta, Zet) and a positive Jacobian (Aj) over the whole domain.
The metric-generation kernels are completely algebraic, so they will happily deliver a left-handed basis if the mesh file enumerates nodes in the opposite ζ-direction.
This routine makes the orientation explicit and—if needed—repairs it once per run:
| Step | Action |
|---|---|
| 1 | Compute global Aj_min, Aj_max. |
| 2 | Mixed signs (Aj_min < 0 && Aj_max > 0) → abort: the mesh is topologically inconsistent. |
| 3 | All negative (Aj_max < 0) → flip Csi, Eta, Zet, Aj & update local ghosts. |
| 4 | Store user->orientation = ±1 so BC / IC routines can apply sign-aware logic if they care about inlet direction. |
| [in,out] | user | Fully initialised UserCtx that already contains Csi, Eta, Zet, Aj, their local ghosts, and valid distributed DMs. |
0 on success or a PETSc error code on failure.ComputeCellCenteredJacobianInverse() and before any routine that differentiates or applies BCs.Verify and, when consistently inverted, repair the right-handed metric basis (Csi, Eta, Zet) and a positive Jacobian (Aj) over the whole domain.
Local to this translation unit.
Definition at line 313 of file Metric.c.
| PetscErrorCode ComputeCellCentersAndSpacing | ( | UserCtx * | user | ) |
Computes the physical location of cell centers and the spacing between them.
This function calculates two key geometric properties from the nodal coordinates:
Cent: A vector field storing the (x,y,z) coordinates of the center of each grid cell.GridSpace: A vector field storing the physical distance between adjacent cell centers in the i, j, and k computational directions.It is a direct adaptation of the corresponding logic from the legacy FormMetrics.
| user | The UserCtx for a specific grid level. The function populates user->Cent and user->GridSpace. |
Computes the physical location of cell centers and the spacing between them.
Local to this translation unit.
Definition at line 993 of file Metric.c.
| PetscErrorCode ComputeIFaceMetrics | ( | UserCtx * | user | ) |
Computes metrics centered on constant-i faces (i-faces).
This function calculates the metric terms (ICsi, IEta, IZet) and the inverse Jacobian (IAj) located at the center of each i-face. The stencils use i-face-centered coordinates (Centx) which must be computed first. The logic is a direct adaptation of the legacy FormMetrics function.
| user | The UserCtx for a specific grid level. Populates user->ICsi, etc. |
Computes metrics centered on constant-i faces (i-faces).
Local to this translation unit.
Definition at line 1096 of file Metric.c.
| PetscErrorCode ComputeJFaceMetrics | ( | UserCtx * | user | ) |
Computes metrics centered on constant-j faces (j-faces).
This function calculates the metric terms (JCsi, JEta, JZet) and the inverse Jacobian (JAj) located at the geometric center of each constant-j face. This is a critical step for staggered-grid finite difference schemes.
The process is a direct and faithful refactoring of the corresponding logic from the legacy FormMetrics function:
user->Centy vector.Centy field to compute the derivatives (e.g., d(x)/d(csi)).Vec objects.| user | The UserCtx for a specific grid level. This function populates the user->JCsi, user->JEta, user->JZet, and user->JAj vectors. |
Computes metrics centered on constant-j faces (j-faces).
Local to this translation unit.
Definition at line 1307 of file Metric.c.
| PetscErrorCode ComputeKFaceMetrics | ( | UserCtx * | user | ) |
Computes metrics centered on constant-k faces (k-faces).
This function calculates the metric terms (KCsi, KEta, KZet) and the inverse Jacobian (KAj) located at the geometric center of each constant-j face. This is a critical step for staggered-grid finite difference schemes.
The process is a direct and faithful refactoring of the corresponding logic from the legacy FormMetrics function:
user->Centz vector.Centz field to compute the derivatives (e.g., d(x)/d(csi)).Vec objects.| user | The UserCtx for a specific grid level. This function populates the user->KCsi, user->KEta, user->KZet, and user->KAj vectors. |
Computes metrics centered on constant-k faces (k-faces).
Local to this translation unit.
Definition at line 1502 of file Metric.c.
| PetscErrorCode ComputeMetricsDivergence | ( | UserCtx * | user | ) |
Performs a diagnostic check on the divergence of the face area metric vectors.
For a closed cell, the sum of the face area vectors should be zero (Gauss's divergence theorem). This function computes a measure of this divergence and reports the maximum value over the domain. A small value indicates a well-formed grid. This is a direct adaptation of the legacy function.
| user | The UserCtx for a specific grid level (typically the finest). |
Performs a diagnostic check on the divergence of the face area metric vectors.
Local to this translation unit.
Definition at line 1716 of file Metric.c.
| PetscErrorCode ComputeMetricNorms | ( | UserCtx * | user | ) |
Computes the max-min values of the grid metrics.
This function serves as a diagnostic tool to assess the quality of the grid metrics. It calculates the bounds of the face metrics (Csi, Eta, Zet).
| user | The UserCtx, containing all necessary grid data. |
Computes the max-min values of the grid metrics.
Local to this translation unit.
Definition at line 1808 of file Metric.c.
| PetscErrorCode CalculateAllGridMetrics | ( | SimCtx * | simCtx | ) |
Orchestrates the calculation of all grid metrics.
This function iterates through every UserCtx in the multigrid and multi-block hierarchy. For each context, it calls a series of modern, modular helper functions to compute the face metrics (Csi, Eta, Zet), the cell-centered inverse Jacobian (Aj), and to validate the grid's orientation.
Orchestrates the calculation of all grid metrics.
Local to this translation unit.
Definition at line 1940 of file Metric.c.