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) |
Public wrapper: map (cell index, ξ,η,ζ) to (x,y,z). | |
PetscErrorCode | MetricGetCellVertices (UserCtx *user, const Cmpnts ***X, PetscInt i, PetscInt j, PetscInt k, Cmpnts V[8]) |
Extract the eight vertex coordinates of the hexahedral cell (i,j,k). | |
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) |
Compute Jacobian matrix and its determinant at (xi,eta,zta). | |
PetscErrorCode | MetricVelocityContravariant (const PetscReal J[3][3], PetscReal detJ, const PetscReal u[3], PetscReal uc[3]) |
Convert physical velocity (u,v,w) to contravariant components (u^xi, u^eta, u^zta). | |
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) |
Ensure a 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 | ||
) |
Public wrapper: map (cell index, ξ,η,ζ) to (x,y,z).
Definition at line 68 of file Metric.c.
PetscErrorCode MetricGetCellVertices | ( | UserCtx * | user, |
const Cmpnts *** | X, | ||
PetscInt | i, | ||
PetscInt | j, | ||
PetscInt | k, | ||
Cmpnts | V[8] | ||
) |
Extract the eight vertex coordinates of the hexahedral cell (i,j,k).
Vertices are returned in the standard trilinear ordering: bit 0 → x-corner, bit 1 → y-corner, bit 2 → z-corner. (000 = origin of the cell, 111 = far corner.)
Definition at line 24 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 | ||
) |
Compute Jacobian matrix and its determinant at (xi,eta,zta).
J = [ x_ξ x_η x_ζ ] [ y_ξ y_η y_ζ ] [ z_ξ z_η z_ζ ]
This is handy for converting physical velocities (u,v,w) into contravariant components and for volume weighting.
Definition at line 93 of file Metric.c.
PetscErrorCode MetricVelocityContravariant | ( | const PetscReal | J[3][3], |
PetscReal | detJ, | ||
const PetscReal | u[3], | ||
PetscReal | uc[3] | ||
) |
Convert physical velocity (u,v,w) to contravariant components (u^xi, u^eta, u^zta).
Definition at line 141 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. Definition at line 286 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
.
[in,out] | user | Pointer to the UserCtx structure. |
Definition at line 491 of file Metric.c.
PetscErrorCode CheckAndFixGridOrientation | ( | UserCtx * | user | ) |
Ensure a 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.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.Definition at line 195 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 . |
Definition at line 644 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. |
This function calculates the metric terms (ICsi
, IEta
, IZet
) and the inverse Jacobian (IAj
) located at the geometric center of each constant-i 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->Centx
vector.Centx
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->ICsi , user->IEta , user->IZet , and user->IAj vectors. |
Definition at line 739 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. |
Definition at line 942 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. |
This function calculates the metric terms (KCsi
, KEta
, KZet
) and the inverse Jacobian (KAj
) located at the geometric center of each constant-k 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. |
Definition at line 1145 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.
This function serves as a diagnostic tool to assess the quality of the grid metrics. It calculates the divergence of the face metrics (Csi, Eta, Zet) and scales it by the inverse of the cell Jacobian. The maximum divergence value is then located, and its grid coordinates are printed to the console, helping to pinpoint areas of potential grid quality issues.
user | The UserCtx, containing all necessary grid data. |
Definition at line 1416 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. |
Definition at line 1506 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.
Definition at line 1639 of file Metric.c.