23 PetscInt particles_per_rank = -1;
24 PetscInt remainder = -1;
26 PetscFunctionBeginUser;
28 PetscCall(
PicurvAssertIntEqual(4, particles_per_rank,
"rank 0 should receive one remainder particle"));
32 PetscCall(
PicurvAssertIntEqual(3, particles_per_rank,
"last rank should receive base particle count"));
34 PetscFunctionReturn(0);
45 PetscFunctionBeginUser;
46 PetscCall(PetscMemzero(&bbox,
sizeof(bbox)));
47 PetscCall(PetscMemzero(&particle,
sizeof(particle)));
56 particle.
loc.
x = 0.25;
63 PetscFunctionReturn(0);
72 PetscReal distances[
NUM_FACES] = {1.0, 3.0, 2.0, 2.0, 4.0, 1.0};
73 PetscReal clamped[
NUM_FACES] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
75 PetscFunctionBeginUser;
76 PetscCall(PetscMemzero(&particle,
sizeof(particle)));
86 PetscFunctionReturn(0);
98 PetscFunctionBeginUser;
102 PetscCall(PetscMemzero(&particle,
sizeof(particle)));
103 particle.
loc.
x = 1.0;
104 particle.
loc.
y = -2.0;
105 particle.
loc.
z = 3.0;
106 particle.
vel.
x = 0.5;
107 particle.
vel.
y = -1.0;
108 particle.
vel.
z = 2.0;
120 PetscFunctionReturn(0);
129 const PetscReal dt = 0.5;
130 const PetscReal diffusivity = 0.2;
131 const PetscReal mean_val = 3.0;
132 const PetscReal cell_vol = 8.0;
133 const PetscReal c_model = 2.0;
134 PetscReal unchanged = 7.0;
136 PetscFunctionBeginUser;
139 mean_val + (1.0 - mean_val) * PetscExpReal(-(c_model * diffusivity / PetscPowReal(cell_vol, 0.6666667)) * dt),
142 "IEM update should match analytical relaxation"));
144 PetscCall(
UpdateParticleField(
"UnrelatedField", dt, &unchanged, diffusivity, mean_val, cell_vol, c_model));
145 PetscCall(
PicurvAssertRealNear(7.0, unchanged, 1.0e-12,
"unknown field should remain unchanged"));
146 PetscFunctionReturn(0);
157 PetscFunctionBeginUser;
159 PetscCall(VecSet(user->
Ucont, 7.0));
165 PetscFunctionReturn(0);
177 PetscFunctionBeginUser;
185 PetscCall(VecSet(user->
Ucont, 0.0));
188 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
189 PetscCall(
PicurvAssertRealNear(0.0, ucont[1][1][1].x, 1.0e-12,
"x contravariant component remains zero"));
190 PetscCall(
PicurvAssertRealNear(0.0, ucont[1][1][1].y, 1.0e-12,
"y contravariant component remains zero"));
191 PetscCall(
PicurvAssertRealNear(2.0, ucont[1][1][1].z, 1.0e-12,
"z contravariant component should match constant inlet magnitude"));
192 PetscCall(
PicurvAssertRealNear(0.0, ucont[0][1][1].z, 1.0e-12,
"boundary/ghost cell should remain unchanged"));
193 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
196 PetscFunctionReturn(0);
204 Cmpnts wall_velocity = {0.0, 0.0, 0.0};
205 Cmpnts reference_velocity = {2.0, 4.0, 6.0};
206 Cmpnts boundary_velocity = {0.0, 0.0, 0.0};
207 Cmpnts free_slip_reference = {2.0, 3.0, 4.0};
209 PetscFunctionBeginUser;
210 noslip(NULL, 2.0, 1.0, wall_velocity, reference_velocity, &boundary_velocity, 1.0, 0.0, 0.0);
215 freeslip(NULL, 2.0, 1.0, wall_velocity, free_slip_reference, &boundary_velocity, 1.0, 0.0, 0.0);
216 PetscCall(
PicurvAssertRealNear(1.0, boundary_velocity.
x, 1.0e-12,
"free-slip interpolated normal component"));
217 PetscCall(
PicurvAssertRealNear(3.0, boundary_velocity.
y, 1.0e-12,
"free-slip tangential y preserved"));
218 PetscCall(
PicurvAssertRealNear(4.0, boundary_velocity.
z, 1.0e-12,
"free-slip tangential z preserved"));
219 PetscFunctionReturn(0);
227 const PetscReal expected_smooth_e = PetscExpReal(0.41 * 5.5);
228 PetscReal e_coeff = 0.0;
229 PetscReal utau = 0.0;
230 PetscReal residual = 0.0;
232 PetscFunctionBeginUser;
233 e_coeff =
E_coeff(0.1, 0.0, 1.0e-3);
234 PetscCall(
PicurvAssertRealNear(expected_smooth_e, e_coeff, 1.0e-10,
"smooth-wall E coefficient"));
237 PetscCall(
PicurvAssertBool((PetscBool)(utau > 0.0),
"friction velocity should remain positive"));
238 residual =
f_hydset(1.0e-3, 1.0, 1.0e-2, utau, 0.0);
239 PetscCall(
PicurvAssertBool((PetscBool)(PetscAbsReal(residual) < 1.0e-5),
"Newton solve residual should be small"));
243 PetscFunctionReturn(0);
254 PetscFunctionBeginUser;
258 PetscFunctionReturn(0);
269 PetscFunctionBeginUser;
271 PetscCall(DMCreateGlobalVector(user->
da, &user->
CS));
281 PetscFunctionReturn(0);
292 PetscFunctionBeginUser;
295 PetscCall(DMCreateGlobalVector(user->
fda, &user->
Ucont_o));
296 PetscCall(DMCreateGlobalVector(user->
fda, &user->
Ucont_rm1));
297 PetscCall(DMCreateLocalVector(user->
fda, &user->
lUcont_o));
298 PetscCall(DMCreateLocalVector(user->
fda, &user->
lUcont_rm1));
299 PetscCall(DMCreateGlobalVector(user->
fda, &user->
Ucat_o));
300 PetscCall(DMCreateGlobalVector(user->
da, &user->
P_o));
302 PetscCall(VecSet(user->
Ucont, 11.0));
303 PetscCall(VecSet(user->
Ucont_o, 7.0));
305 PetscCall(VecSet(user->
Ucat, 5.0));
306 PetscCall(VecSet(user->
Ucat_o, -1.0));
307 PetscCall(VecSet(user->
P, 9.0));
308 PetscCall(VecSet(user->
P_o, -2.0));
320 PetscFunctionReturn(0);
330 PetscInt xs = -1, ys = -1, zs = -1;
331 PetscInt xm = -1, ym = -1, zm = -1;
333 PetscFunctionBeginUser;
348 PetscFunctionReturn(0);
359 PetscFunctionBeginUser;
371 PetscFunctionReturn(0);
397 ierr = PetscInitialize(&argc, &argv, NULL,
"PICurv runtime-kernel tests");
402 ierr =
PicurvRunTests(
"unit-runtime", cases,
sizeof(cases) /
sizeof(cases[0]));
408 ierr = PetscFinalize();
PetscErrorCode Validate_DrivenFlowConfiguration(UserCtx *user)
(Private) Validates all consistency rules for a driven flow (channel/pipe) setup.
Header file for Particle Motion and migration related functions.
PetscErrorCode UpdateParticlePosition(UserCtx *user, Particle *particle)
Updates a particle's position based on its velocity and the timestep dt (stored in user->dt).
Header file for Particle related physics modules.
PetscErrorCode UpdateParticleField(const char *fieldName, PetscReal dt, PetscReal *psi_io, PetscReal diffusivity, PetscReal mean_val, PetscReal cell_vol, PetscReal C_model)
Updates a single particle's field based on its state and physics model.
Header file for Particle Swarm management functions.
PetscErrorCode UpdateParticleWeights(PetscReal *d, Particle *particle)
Updates a particle's interpolation weights based on distances to cell faces.
PetscErrorCode DistributeParticles(PetscInt numParticles, PetscMPIInt rank, PetscMPIInt size, PetscInt *particlesPerProcess, PetscInt *remainder)
Distributes particles evenly across MPI processes, handling any remainders.
PetscBool IsParticleInsideBoundingBox(const BoundingBox *bbox, const Particle *particle)
Checks if a particle's location is within a specified bounding box.
PetscErrorCode SetInitialInteriorField(UserCtx *user, const char *fieldName)
Sets the initial values for the INTERIOR of a specified Eulerian field.
PetscErrorCode ComputeSmagorinskyConstant(UserCtx *user)
Computes the dynamic Smagorinsky constant (Cs) for the LES model.
PetscErrorCode UpdateSolverHistoryVectors(UserCtx *user)
Copies the current time step's solution fields into history vectors (e.g., U(t_n) -> U_o,...
PetscErrorCode GetOwnedCellRange(const DMDALocalInfo *info_nodes, PetscInt dim, PetscInt *xs_cell_global_out, PetscInt *xm_cell_local_out)
Determines the global starting index and number of CELLS owned by the current processor in a specifie...
PetscErrorCode ComputeAndStoreNeighborRanks(UserCtx *user)
Computes and stores the Cartesian neighbor ranks for the DMDA decomposition.
static PetscErrorCode TestUpdateParticleFieldIEMRelaxation(void)
Test-local routine.
static PetscErrorCode TestSetInitialInteriorFieldConstantProfileOnZInlet(void)
Test-local routine.
static PetscErrorCode TestSetInitialInteriorFieldIgnoresNonUcontRequest(void)
Test-local routine.
int main(int argc, char **argv)
Entry point for this unit-test binary.
static PetscErrorCode TestDistributeParticlesRemainderHandling(void)
Test-local routine.
static PetscErrorCode TestGetOwnedCellRangeSingleRankAccounting(void)
Test-local routine.
static PetscErrorCode TestUpdateParticlePositionWithoutBrownianContribution(void)
Test-local routine.
static PetscErrorCode TestComputeAndStoreNeighborRanksSingleRank(void)
Test-local routine.
static PetscErrorCode TestValidateDrivenFlowConfigurationNoDrivenHandlers(void)
Test-local routine.
static PetscErrorCode TestWallNoSlipAndFreeSlipHelpers(void)
Test-local routine.
static PetscErrorCode TestComputeSmagorinskyConstantConstantModel(void)
Test-local routine.
static PetscErrorCode TestUpdateSolverHistoryVectorsShiftsStates(void)
Test-local routine.
static PetscErrorCode TestUpdateParticleWeightsComputesExpectedRatios(void)
Test-local routine.
static PetscErrorCode TestIsParticleInsideBoundingBoxBasicCases(void)
Test-local routine.
static PetscErrorCode TestWallModelScalarHelpers(void)
Test-local routine.
PetscErrorCode PicurvCreateMinimalContexts(SimCtx **simCtx_out, UserCtx **user_out, PetscInt mx, PetscInt my, PetscInt mz)
Shared test-support routine.
PetscErrorCode PicurvAssertRealNear(PetscReal expected, PetscReal actual, PetscReal tol, const char *context)
Shared test-support routine.
PetscErrorCode PicurvDestroyMinimalContexts(SimCtx **simCtx_ptr, UserCtx **user_ptr)
Shared test-support routine.
PetscErrorCode PicurvRunTests(const char *suite_name, const PicurvTestCase *cases, size_t case_count)
Shared test-support routine.
PetscErrorCode PicurvAssertVecConstant(Vec vec, PetscScalar expected, PetscReal tol, const char *context)
Shared test-support routine.
PetscErrorCode PicurvAssertIntEqual(PetscInt expected, PetscInt actual, const char *context)
Shared test-support routine.
PetscErrorCode PicurvAssertBool(PetscBool value, const char *context)
Shared test-support routine.
C test module for PICurv.
Named test case descriptor consumed by PicurvRunTests.
BCFace identifiedInletBCFace
PetscInt FieldInitialization
Cmpnts max_coords
Maximum x, y, z coordinates of the bounding box.
Cmpnts diffusivitygradient
Cmpnts min_coords
Minimum x, y, z coordinates of the bounding box.
Cmpnts InitialConstantContra
Defines a 3D axis-aligned bounding box.
A 3D point or vector with PetscScalar components.
Defines a particle's core properties for Lagrangian tracking.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.
double find_utau_hydset(double kinematic_viscosity, double known_velocity, double wall_distance, double initial_guess, double roughness_height)
Solves for friction velocity using Newton-Raphson iteration.
void noslip(UserCtx *user, double distance_reference, double distance_boundary, Cmpnts velocity_wall, Cmpnts velocity_reference, Cmpnts *velocity_boundary, double normal_x, double normal_y, double normal_z)
Applies no-slip wall boundary condition with linear interpolation.
double integrate_1(double kinematic_viscosity, double wall_distance, double friction_velocity, int integration_mode)
Integrates eddy viscosity profile from wall to distance y.
double f_hydset(double kinematic_viscosity, double known_velocity, double wall_distance, double friction_velocity_guess, double roughness_height)
Residual function for friction velocity equation (log-law with roughness)
double E_coeff(double friction_velocity, double roughness_height, double kinematic_viscosity)
Computes roughness-modified log-law coefficient E.
double nu_t(double yplus)
Computes turbulent eddy viscosity ratio (ν_t / ν)
void freeslip(UserCtx *user, double distance_reference, double distance_boundary, Cmpnts velocity_wall, Cmpnts velocity_reference, Cmpnts *velocity_boundary, double normal_x, double normal_y, double normal_z)
Applies free-slip wall boundary condition.