PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
Functions
AnalyticalSolutions.h File Reference
#include "variables.h"
Include dependency graph for AnalyticalSolutions.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

PetscErrorCode AnalyticalSolutionEngine (SimCtx *simCtx)
 Sets the Eulerian fields from the case's source (-ic_source_*) at the step's time.
 
PetscErrorCode AnalyticalFieldDestroy (SimCtx *simCtx)
 Release what AnalyticalSolutionEngine() keeps from step to step, if anything.
 
PetscBool AnalyticalFieldSupportsInterpolationError (const SimCtx *simCtx)
 Reports whether the analytical field can be compared with interpolated particle velocities.
 
PetscErrorCode SetAnalyticalSolutionForParticles (Vec tempVec, SimCtx *simCtx)
 Evaluates the analytical velocity at particle positions.
 

Function Documentation

◆ AnalyticalSolutionEngine()

PetscErrorCode AnalyticalSolutionEngine ( SimCtx *  simCtx)

Sets the Eulerian fields from the case's source (-ic_source_*) at the step's time.

Sets the fluxes on every face, Ubcs on every boundary face, and Ucat and P at the cell centres. A source that does not read t is evaluated once. Collective.

Parameters
simCtxThe main simulation context, containing configuration and state.
Returns
PetscErrorCode 0 on success.

Sets the Eulerian fields from the case's source (-ic_source_*) at the step's time.

The field is the case's source, evaluated at the step's time. As on an inlet, a source that does not read t is evaluated once.

See also
AnalyticalSolutionEngine()

Definition at line 158 of file AnalyticalSolutions.c.

159{
160 UserCtx *user_finest = simCtx->usermg.mgctx[simCtx->usermg.mglevels - 1].user;
161 struct AnalyticalField *field;
162 PetscReal physical_time;
163
164 PetscFunctionBeginUser;
166 if (!simCtx->analyticalField) PetscCall(AnalyticalFieldCreate(simCtx));
167 field = simCtx->analyticalField;
168 if (field->evaluated && !field->time_dependent) { PROFILE_FUNCTION_END; PetscFunctionReturn(0); }
169 PetscCall(PicurvPhysicalTime(simCtx, simCtx->ti, &physical_time));
170 for (PetscInt bi = 0; bi < simCtx->block_number; ++bi) {
171 UserCtx *user = &user_finest[bi];
172 const FieldId staggered_fields[] = {FIELD_ID_UCONT};
173 if (field->source.bulk) {
174 PetscCall(VecSet(user->Ucat, 0.0));
175 PetscCall(PicurvSourceCellBulkFactor(user, &field->source, field->fraction[bi], field->length[bi], physical_time, &field->factor));
176 }
177 PetscCall(VecSet(user->Ucont, 0.0));
178 PetscCall(PicurvSourceAddFluxes(user, &field->source, field->fraction[bi], field->length[bi], physical_time, field->factor, PETSC_TRUE));
179 PetscCall(SetBoundaryVelocityFromSource(user, field, bi, physical_time));
180 /* A curvilinear source's Ucat follows from its fluxes, below. */
181 PetscCall(PicurvSourceSetCellFields(user, (field->source.frame != PICURV_SOURCE_FRAME_CURVILINEAR) ? &field->source : NULL,
182 field->factor, field->pressure, field->fraction[bi], field->length[bi], physical_time));
183 if (!field->pressure) PetscCall(VecSet(user->P, 0.0));
184 PetscCall(SynchronizePeriodicStaggeredFields(user, 1, staggered_fields));
185 PetscCall(UpdateLocalGhosts(user, FIELD_ID_UCONT));
186 if (field->source.frame == PICURV_SOURCE_FRAME_CURVILINEAR) PetscCall(Contra2Cart(user));
188 }
189 field->evaluated = PETSC_TRUE;
191 PetscFunctionReturn(0);
192}
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.
PicurvExpression * pressure
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.
PicurvExpression * bulk
Target mean speed [m/s] in t, or NULL.
Definition expression.h:192
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 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 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...
PicurvSourceFrame frame
Definition expression.h:188
@ PICURV_SOURCE_FRAME_CURVILINEAR
Three values along the unit xi, eta, zeta grid-line directions.
Definition expression.h:177
FieldId
Compile-time identity for a catalogued Eulerian field.
@ FIELD_ID_UCONT
PetscErrorCode PicurvPhysicalTime(const SimCtx *simCtx, PetscReal solver_time, PetscReal *physical)
Convert a solver time to physical seconds, t * L_ref / U_ref.
Definition io.c:2986
#define PROFILE_FUNCTION_END
Marks the end of a profiled code block.
Definition logging.h:1029
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled function: an always-on aggregate timer.
Definition logging.h:1000
PetscErrorCode Contra2Cart(UserCtx *user)
Reconstructs Cartesian velocity (Ucat) at cell centers from contravariant velocity (Ucont) defined on...
Definition setup.c:3313
PetscErrorCode UpdateLocalGhosts(UserCtx *user, FieldId field_id)
Updates the local vector (including ghost points) from its corresponding global vector.
Definition setup.c:2593
UserCtx * user
Definition variables.h:768
struct AnalyticalField * analyticalField
The prescribed field's source, once read; see AnalyticalSolutionEngine().
Definition variables.h:952
PetscInt block_number
Definition variables.h:1009
UserMG usermg
Definition variables.h:1082
Vec Ucont
Definition variables.h:1197
PetscInt mglevels
Definition variables.h:775
MGCtx * mgctx
Definition variables.h:778
PetscReal ti
Definition variables.h:925
User-defined context containing data specific to a single computational grid level.
Definition variables.h:1157
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AnalyticalFieldDestroy()

PetscErrorCode AnalyticalFieldDestroy ( SimCtx *  simCtx)

Release what AnalyticalSolutionEngine() keeps from step to step, if anything.

Parameters
simCtxSimulation context.
Returns
PetscErrorCode 0 on success.

Release what AnalyticalSolutionEngine() keeps from step to step, if anything.

See also
AnalyticalFieldDestroy()

Definition at line 88 of file AnalyticalSolutions.c.

89{
90 struct AnalyticalField *field = simCtx->analyticalField;
91
92 PetscFunctionBeginUser;
94 if (field) {
95 PetscCall(PicurvVelocitySourceDestroy(&field->source));
96 PetscCall(PicurvExpressionDestroy(&field->pressure));
97 for (PetscInt bi = 0; bi < simCtx->block_number; ++bi) {
98 PetscCall(VecDestroy(&field->fraction[bi]));
99 PetscCall(VecDestroy(&field->length[bi]));
100 for (PetscInt face = 0; face < 6; ++face) PetscCall(PicurvSourceFaceSlotsDestroy(&field->faces[bi][face]));
101 }
102 PetscCall(PetscFree3(field->fraction, field->length, field->faces));
103 PetscCall(PetscFree(simCtx->analyticalField));
104 }
106 PetscFunctionReturn(0);
107}
PicurvSourceFaceSlots(* faces)[6]
PetscErrorCode PicurvExpressionDestroy(PicurvExpression **expression)
Free a compiled expression.
Definition expression.c:818
PetscErrorCode PicurvVelocitySourceDestroy(PicurvVelocitySource *source)
Free a source's compiled expressions and bulk velocity.
PetscErrorCode PicurvSourceFaceSlotsDestroy(PicurvSourceFaceSlots *slots)
Release what PicurvSourceFaceSlotsCreate() allocated.
#define PROFILE_HELPER_BEGIN
Marks the beginning of a profiled helper: timed only when enabled by name.
Definition logging.h:1014
#define PROFILE_HELPER_END
Alias of PROFILE_FUNCTION_END for a function that began with PROFILE_HELPER_BEGIN.
Definition logging.h:1033
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AnalyticalFieldSupportsInterpolationError()

PetscBool AnalyticalFieldSupportsInterpolationError ( const SimCtx *  simCtx)

Reports whether the analytical field can be compared with interpolated particle velocities.

It must be evaluable at any point, a Cartesian source reading only x, y, z and t, and must vary in space: interpolating a uniform field has no error to measure.

Parameters
simCtxSimulation context, after AnalyticalSolutionEngine().
Returns
PETSC_TRUE if interpolation error is meaningful, PETSC_FALSE otherwise.

Reports whether the analytical field can be compared with interpolated particle velocities.

See also
AnalyticalFieldSupportsInterpolationError()

Definition at line 113 of file AnalyticalSolutions.c.

114{
116 const PetscBool pointwise = (simCtx && simCtx->analyticalField) ? simCtx->analyticalField->pointwise : PETSC_FALSE;
118 return pointwise;
119}
Here is the caller graph for this function:

◆ SetAnalyticalSolutionForParticles()

PetscErrorCode SetAnalyticalSolutionForParticles ( Vec  tempVec,
SimCtx *  simCtx 
)

Evaluates the analytical velocity at particle positions.

Parameters
tempVecThe PETSc Vec containing particle positions, replaced by the velocities.
simCtxThe simulation context.
Returns
PetscErrorCode Returns 0 on success.

Evaluates the analytical velocity at particle positions.

Only a pointwise source reaches here; see AnalyticalFieldSupportsInterpolationError().

See also
SetAnalyticalSolutionForParticles()

Definition at line 199 of file AnalyticalSolutions.c.

200{
201 const struct AnalyticalField *field = simCtx->analyticalField;
202 const ScalingCtx *scaling = &simCtx->scaling;
203 PetscInt nLocal;
204 PetscReal *data, values[PICURV_SOURCE_VAR_COUNT], physical_time;
205
206 PetscFunctionBeginUser;
208 PetscCheck(AnalyticalFieldSupportsInterpolationError(simCtx), PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
209 "The analytical field cannot be evaluated at a particle: it needs a Cartesian source in x, y, z and t.");
210 PetscCall(PetscArrayzero(values, PICURV_SOURCE_VAR_COUNT));
211 PetscCall(PicurvPhysicalTime(simCtx, simCtx->ti, &physical_time));
212 values[PICURV_SOURCE_VAR_T] = physical_time;
213 PetscCall(VecGetLocalSize(tempVec, &nLocal));
214 PetscCall(VecGetArray(tempVec, &data));
215 /* Interleaved [x0,y0,z0, x1,y1,z1, ...], replaced by the velocity there. */
216 for (PetscInt i = 0; i < nLocal; i += 3) {
217 Cmpnts v;
218 values[PICURV_SOURCE_VAR_X] = data[i] * scaling->L_ref;
219 values[PICURV_SOURCE_VAR_Y] = data[i + 1] * scaling->L_ref;
220 values[PICURV_SOURCE_VAR_Z] = data[i + 2] * scaling->L_ref;
221 PetscCall(PicurvVelocitySourceEvaluate(&field->source, values, NULL, NULL, &v));
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;
225 }
226 PetscCall(VecRestoreArray(tempVec, &data));
228 PetscFunctionReturn(0);
229}
PetscBool AnalyticalFieldSupportsInterpolationError(const SimCtx *simCtx)
Implementation of AnalyticalFieldSupportsInterpolationError().
PetscErrorCode PicurvVelocitySourceEvaluate(const PicurvVelocitySource *source, const PetscReal *values, const PicurvExpressionDrawKey *key, const Cmpnts edges[3], Cmpnts *value)
Evaluate a source at one point.
Definition expression.c:993
@ PICURV_SOURCE_VAR_T
Physical time [s].
Definition expression.h:162
@ PICURV_SOURCE_VAR_Y
Physical y [m].
Definition expression.h:160
@ PICURV_SOURCE_VAR_X
Physical x of the point [m].
Definition expression.h:159
@ PICURV_SOURCE_VAR_COUNT
Definition expression.h:171
@ PICURV_SOURCE_VAR_Z
Physical z [m].
Definition expression.h:161
PetscReal L_ref
Definition variables.h:898
PetscScalar x
Definition variables.h:145
PetscScalar z
Definition variables.h:145
ScalingCtx scaling
Definition variables.h:1003
PetscScalar y
Definition variables.h:145
PetscReal U_ref
Definition variables.h:899
A 3D point or vector with PetscScalar components.
Definition variables.h:144
Here is the call graph for this function:
Here is the caller graph for this function: