21 PetscFunctionBeginUser;
27 PetscFunctionReturn(0);
38 PetscFunctionBeginUser;
46 PetscFunctionReturn(0);
59 PetscReal physical_time, weight = 1.0, factor = 1.0;
62 PetscFunctionBeginUser;
66 PetscCall(VecSet(user->
Ucat, 0.0));
67 PetscCall(VecSet(user->
Ucont, 0.0));
69 PetscCall(PetscOptionsGetReal(NULL, NULL,
"-ic_source_field_weight", &weight, NULL));
71 if (weight != 1.0) PetscCall(VecScale(staged_flux ? user->
Ucont : user->
Ucat, weight));
75 if (source.
count > 0 || pressure) {
76 PetscCall(DMCreateGlobalVector(user->
fda, &fraction));
77 PetscCall(DMCreateGlobalVector(user->
fda, &length));
82 PetscCall(VecDestroy(&fraction));
83 PetscCall(VecDestroy(&length));
88 PetscFunctionReturn(0);
97 PetscFunctionBeginUser;
123 PetscFunctionReturn(0);
139 PetscFunctionBeginUser;
142 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
147 PetscCall(VecSet(user_finest[bi].Phi, 0.0));
150 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Initial velocity projected to be divergence-free (Poisson source imbalance %g).\n",
153 PetscFunctionReturn(0);
163 PetscFunctionBeginUser;
167 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
188 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
196 PetscBool project = PETSC_FALSE;
197 ierr = PetscOptionsGetBool(NULL, NULL,
"-ic_source_project", &project, NULL); CHKERRQ(ierr);
203 PetscFunctionReturn(0);
213 PetscFunctionBeginUser;
217 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
218 LOG_ALLOW(
LOCAL,
LOG_INFO,
"Rank %d, Block %" PetscInt_FMT
": Reading restart files for step %" PetscInt_FMT
".\n",
235 PetscFunctionReturn(0);
247 PetscFunctionBeginUser;
285 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
293 PetscFunctionReturn(0);
PetscErrorCode AnalyticalSolutionEngine(SimCtx *simCtx)
Sets the Eulerian fields from the case's source (-ic_source_*) at the step's time.
PetscErrorCode SynchronizePeriodicStaggeredFields(UserCtx *user, PetscInt num_fields, const FieldId field_ids[])
Synchronizes persistent component-staggered vector fields.
PetscErrorCode ApplyBoundaryConditions(UserCtx *user)
Main boundary-condition orchestrator executed during solver timestepping.
PetscErrorCode SynchronizePeriodicCellFields(UserCtx *user, PetscInt num_fields, const FieldId field_ids[])
Synchronizes periodic endpoint cells for a list of cell-centered fields.
PetscErrorCode ComputeGridLineFractions(UserCtx *user, Vec fraction, Vec length)
Arc-length position of every owned cell centre along its three grid lines.
The expression language shared by every configured field, the keyed hashes its random draws and other...
PicurvExpression * bulk
Target mean speed [m/s] in t, or NULL.
PetscErrorCode PicurvExpressionDestroy(PicurvExpression **expression)
Free a compiled expression.
PetscErrorCode PicurvSourceAddFluxes(UserCtx *user, const PicurvVelocitySource *source, Vec fraction, Vec length, PetscReal physical_time, PetscReal factor, PetscBool boundary_faces)
Add a source's flux to every owned face of Ucont, evaluating it at each face centre.
PetscErrorCode PicurvVelocitySourceCreate(const char *prefix, PetscBool on_face, PetscBool has_data, PetscBool allow_draws, PicurvVelocitySource *source)
Read and compile a velocity source from the options database.
PetscErrorCode PicurvSourceCellBulkFactor(UserCtx *user, const PicurvVelocitySource *source, Vec fraction, Vec length, PetscReal physical_time, PetscReal *factor)
Factor on a source's expressions that makes the volume mean of the whole field, along the source's ow...
PetscErrorCode PicurvVelocitySourceDestroy(PicurvVelocitySource *source)
Free a source's compiled expressions and bulk velocity.
PetscErrorCode PicurvSourcePressureCreate(const char *prefix, PetscBool allow_draws, PicurvExpression **pressure)
Read and compile a source's optional pressure, -<prefix>_pressure, an expression in Pa over the cell ...
PetscErrorCode PicurvSourceSetCellFields(UserCtx *user, const PicurvVelocitySource *velocity, PetscReal factor, const PicurvExpression *pressure, Vec fraction, Vec length, PetscReal physical_time)
Set a block's Ucat, its P, or both at every interior cell centre this rank owns, from a source evalua...
PetscInt count
1 for the normal frame, otherwise 3; 0 for staged data alone.
A prescribed velocity, for any target: one compiled expression per value, the frame they are in,...
FieldId
Compile-time identity for a catalogued Eulerian field.
static PetscErrorCode SetInitialFluidState_Load(SimCtx *simCtx)
Restore Eulerian fields from checkpoint files for a restart simulation.
static PetscErrorCode UcontFromInteriorUcat(UserCtx *user)
Derive Ucont from a Ucat whose interior cells are set: sync the periodic and ghost cells,...
static PetscErrorCode ProjectInitialVelocity(SimCtx *simCtx)
Make the fresh-start velocity divergence-free with the time step's own projection: solve the pressure...
static PetscErrorCode SetInitialFluidState_FreshStart(SimCtx *simCtx)
Initialize Eulerian fields for a new simulation without restart data.
static PetscErrorCode ReadStagedInitialField(UserCtx *user, const char *name, Vec target)
Read one staged initial field (ufield00000_0 or vfield00000_0) from the initial-condition directory i...
PetscErrorCode InitializeEulerianState(SimCtx *simCtx)
Implementation of InitializeEulerianState().
PetscErrorCode PopulateInitialUcont(UserCtx *user)
Implementation of PopulateInitialUcont().
static PetscErrorCode FinalizeBlockState(UserCtx *user)
Complete one initial-condition block after its interior values are assigned.
PetscErrorCode ReadSimulationFields(UserCtx *user, PetscInt ti)
Reads binary field data for velocity, pressure, and other required vectors.
PetscErrorCode ReadFieldData(UserCtx *user, const char *field_name, Vec field_vec, const char *ext)
Reads data for a specific field from a file into the provided vector.
PetscErrorCode RestoreFieldStatisticsState(SimCtx *simCtx, PetscInt ti)
Restores field-statistics window state and accumulators from a checkpoint.
PetscErrorCode PicurvPhysicalTime(const SimCtx *simCtx, PetscReal solver_time, PetscReal *physical)
Convert a solver time to physical seconds, t * L_ref / U_ref.
#define LOCAL
Logging scope definitions for controlling message output.
#define GLOBAL
Scope for global logging across all processes.
#define LOG_ALLOW(scope, level, fmt,...)
Logging macro that checks both the log level and whether the calling function is in the allowed-funct...
#define PROFILE_HELPER_BEGIN
Marks the beginning of a profiled helper: timed only when enabled by name.
#define PROFILE_HELPER_END
Alias of PROFILE_FUNCTION_END for a function that began with PROFILE_HELPER_BEGIN.
#define PROFILE_FUNCTION_END
Marks the end of a profiled code block.
@ LOG_TRACE
Very fine-grained tracing information for in-depth debugging.
@ LOG_INFO
Informational messages about program execution.
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled function: an always-on aggregate timer.
Pressure-Poisson projection: the multigrid pressure-correction solve, the pressure update,...
PetscErrorCode ProjectVelocity(UserCtx *user)
Corrects the contravariant flux with the gradient of Phi.
PetscErrorCode PoissonSolver_Multigrid(UserMG *usermg)
Solves the pressure-correction equation for every block with geometric multigrid.
PetscErrorCode UpdateSolverHistoryVectors(UserCtx *user, PetscBool preserve_previous_state)
Copies the current time step's solution fields into history vectors (e.g., U(t_n) -> U_o,...
PetscErrorCode Contra2Cart(UserCtx *user)
Reconstructs Cartesian velocity (Ucat) at cell centers from contravariant velocity (Ucont) defined on...
PetscErrorCode UpdateLocalGhosts(UserCtx *user, FieldId field_id)
Updates the local vector (including ghost points) from its corresponding global vector.
PetscErrorCode Cart2Contra(UserCtx *user)
Convert the ghosted Cartesian velocity field to contravariant face fluxes.
SimCtx * simCtx
Back-pointer to the master simulation context.
PetscReal poissonSourceImbalance
char * current_io_directory
char eulerianSource[PETSC_MAX_PATH_LEN]
char initialConditionDirectory[PETSC_MAX_PATH_LEN]
PetscBool initialConditionStaged
char _io_context_buffer[PETSC_MAX_PATH_LEN]
InitialConditionField initialConditionField
PetscBool restartHistoryAvailable
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.