43 PetscFunctionBeginUser;
45 PetscCall(PetscNew(&field));
56 PetscBool varies = PETSC_FALSE;
57 for (PetscInt c = 0; c < field->
source.
count; ++c) {
71 PetscCall(DMCreateGlobalVector(user_finest[bi].fda, &field->
fraction[bi]));
72 PetscCall(DMCreateGlobalVector(user_finest[bi].fda, &field->
length[bi]));
74 for (PetscInt face = 0; face < 6; ++face) {
76 &field->
faces[bi][face]));
81 PetscFunctionReturn(0);
92 PetscFunctionBeginUser;
98 PetscCall(VecDestroy(&field->
fraction[bi]));
99 PetscCall(VecDestroy(&field->
length[bi]));
106 PetscFunctionReturn(0);
123 PetscReal physical_time)
128 PetscFunctionBeginUser;
130 PetscCall(DMDAVecGetArray(user->
fda, user->
Bcs.
Ubcs, &ubcs));
131 for (PetscInt face = 0; face < 6; ++face) {
133 for (PetscInt q = 0; q < slots->
elements.
n[1]; ++q)
134 for (PetscInt p = 0; p < slots->
elements.
n[0]; ++p) {
135 const PetscInt s = p + slots->
elements.
n[0] * q;
142 ubcs[f[2]][f[1]][f[0]].
x = field->
factor * v.
x / U_ref;
143 ubcs[f[2]][f[1]][f[0]].
y = field->
factor * v.
y / U_ref;
144 ubcs[f[2]][f[1]][f[0]].
z = field->
factor * v.
z / U_ref;
147 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Bcs.
Ubcs, &ubcs));
149 PetscFunctionReturn(0);
162 PetscReal physical_time;
164 PetscFunctionBeginUser;
170 for (PetscInt bi = 0; bi < simCtx->
block_number; ++bi) {
171 UserCtx *user = &user_finest[bi];
174 PetscCall(VecSet(user->
Ucat, 0.0));
177 PetscCall(VecSet(user->
Ucont, 0.0));
183 if (!field->
pressure) PetscCall(VecSet(user->
P, 0.0));
191 PetscFunctionReturn(0);
206 PetscFunctionBeginUser;
209 "The analytical field cannot be evaluated at a particle: it needs a Cartesian source in x, y, z and t.");
213 PetscCall(VecGetLocalSize(tempVec, &nLocal));
214 PetscCall(VecGetArray(tempVec, &data));
216 for (PetscInt i = 0; i < nLocal; i += 3) {
222 data[i] = v.
x / scaling->
U_ref;
223 data[i + 1] = v.
y / scaling->
U_ref;
224 data[i + 2] = v.
z / scaling->
U_ref;
226 PetscCall(VecRestoreArray(tempVec, &data));
228 PetscFunctionReturn(0);
PetscErrorCode AnalyticalFieldDestroy(SimCtx *simCtx)
Implementation of AnalyticalFieldDestroy().
PicurvVelocitySource source
static PetscErrorCode SetBoundaryVelocityFromSource(UserCtx *user, const struct AnalyticalField *field, PetscInt block, PetscReal physical_time)
Set Ubcs on every physical boundary face to the source at the face centre.
static PetscErrorCode AnalyticalFieldCreate(SimCtx *simCtx)
Read the source once, and work out what it depends on.
PetscErrorCode AnalyticalSolutionEngine(SimCtx *simCtx)
Implementation of AnalyticalSolutionEngine().
PetscBool AnalyticalFieldSupportsInterpolationError(const SimCtx *simCtx)
Implementation of AnalyticalFieldSupportsInterpolationError().
PetscErrorCode SetAnalyticalSolutionForParticles(Vec tempVec, SimCtx *simCtx)
Implementation of SetAnalyticalSolutionForParticles().
PicurvExpression * pressure
PicurvSourceFaceSlots(* faces)[6]
The prescribed field: the case's source, and what it reuses from step to step.
PetscErrorCode FinalizeCellFieldsFromBoundaryValues(UserCtx *user)
Brings Ucat's and P's dummy cells, periodic endpoints, corners and ghosts in line with their interior...
PetscErrorCode SynchronizePeriodicStaggeredFields(UserCtx *user, PetscInt num_fields, const FieldId field_ids[])
Synchronizes persistent component-staggered vector 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...
BoundaryFaceElements elements
The owned face elements the slots are.
PicurvExpression * bulk
Target mean speed [m/s] in t, or NULL.
PetscErrorCode PicurvExpressionDestroy(PicurvExpression **expression)
Free a compiled expression.
PetscBool bulk_time_dependent
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 PicurvVelocitySourceEvaluate(const PicurvVelocitySource *source, const PetscReal *values, const PicurvExpressionDrawKey *key, const Cmpnts edges[3], Cmpnts *value)
Evaluate a source at one point.
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...
@ PICURV_SOURCE_VAR_XI
Arc-length fraction along the xi grid line, 0 at the - face.
@ PICURV_SOURCE_VAR_T
Physical time [s].
@ PICURV_SOURCE_VAR_Y
Physical y [m].
@ PICURV_SOURCE_VAR_X
Physical x of the point [m].
@ PICURV_SOURCE_VAR_COUNT
@ PICURV_SOURCE_VAR_Z
Physical z [m].
PetscErrorCode PicurvExpressionUsesVariable(const PicurvExpression *expression, PetscInt index, PetscBool *uses)
Whether a compiled expression reads one of its variables.
PetscErrorCode PicurvVelocitySourceDestroy(PicurvVelocitySource *source)
Free a source's compiled expressions and bulk velocity.
PicurvExpression * component[3]
PetscBool time_dependent
Some component reads t or draws, so a face re-evaluates it each step.
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...
PetscErrorCode PicurvSourceFaceSlotsCreate(UserCtx *user, BCFace face_id, Vec fraction, Vec length, PicurvSourceFaceSlots *slots)
Gather each owned slot of a boundary face: face-centre position, the grid-line fractions and lengths ...
PetscReal(* values)[PICURV_SOURCE_VAR_COUNT]
Variables per slot; t is the caller's.
PetscErrorCode PicurvSourceFaceSlotsDestroy(PicurvSourceFaceSlots *slots)
Release what PicurvSourceFaceSlotsCreate() allocated.
Cmpnts(* edges)[3]
Directions per slot, for the curvilinear frame.
@ PICURV_SOURCE_FRAME_CARTESIAN
Three values: x, y, z velocity components.
@ PICURV_SOURCE_FRAME_CURVILINEAR
Three values along the unit xi, eta, zeta grid-line directions.
PetscInt count
1 for the normal frame, otherwise 3; 0 for staged data alone.
What a source reads at each boundary-face slot this rank owns, gathered once.
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.
PetscErrorCode PicurvPhysicalTime(const SimCtx *simCtx, PetscReal solver_time, PetscReal *physical)
Convert a solver time to physical seconds, t * L_ref / U_ref.
Logging utilities and macros for PETSc-based applications.
#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.
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled function: an always-on aggregate timer.
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.
struct AnalyticalField * analyticalField
The prescribed field's source, once read; see AnalyticalSolutionEngine().
SimCtx * simCtx
Back-pointer to the master simulation context.
PetscInt layer
Index along the normal of the face's metric and flux.
PetscInt normal
Logical axis of the face normal.
Vec Ubcs
Physical Cartesian velocity at boundary faces. Full 3D array but only boundary-face entries are meani...
PetscInt n[2]
Owned elements along a and b; 0 when this rank does not serve the face.
PetscInt lo[2]
First owned indices along a and b.
PetscInt b
The two tangential axes, a < b.
BCFace
Identifies the six logical faces of a structured computational block.
A 3D point or vector with PetscScalar components.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.