10#define FIELD_ENTRY(field_id_, name_, alias1_, alias2_, dof_, dm_, layout_, sync_, availability_, capabilities_, global_member_, local_member_, dimension_) \
12 field_id_, name_, alias1_, alias2_, dof_, dm_, layout_, sync_, availability_, capabilities_, \
13 offsetof(UserCtx, global_member_), offsetof(UserCtx, local_member_), dimension_ \
75 Wall_Stress, lWall_Stress,
277 "Field catalog must contain one entry per FieldId.");
287 PetscFunctionBeginUser;
289 PetscCheck(descriptor != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
290 "Field descriptor output cannot be NULL.");
291 PetscCheck(field_id >= 0 && field_id <
FIELD_ID_COUNT, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
292 "Invalid FieldId value %d.", (
int)field_id);
293 PetscCheck(
gFieldCatalog[field_id].
id == field_id, PETSC_COMM_SELF, PETSC_ERR_PLIB,
294 "Field catalog entry %d is not initialized consistently.", (
int)field_id);
298 PetscFunctionReturn(0);
309 PetscBool found = PETSC_FALSE;
311 PetscFunctionBeginUser;
314 PetscCheck(found, PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE,
315 "Field name '%s' is not registered in the Eulerian field catalog.", field_name);
317 PetscFunctionReturn(0);
326 PetscFunctionBeginUser;
328 PetscCheck(field_name != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
329 "Field name cannot be NULL.");
330 PetscCheck(field_id != NULL && found != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
331 "FieldId and found outputs cannot be NULL.");
334 *found = PETSC_FALSE;
337 PetscBool match = PETSC_FALSE;
339 PetscCall(PetscStrcasecmp(field_name, descriptor->
canonical_name, &match));
340 if (!match && descriptor->
alias_1) PetscCall(PetscStrcasecmp(field_name, descriptor->
alias_1, &match));
341 if (!match && descriptor->
alias_2) PetscCall(PetscStrcasecmp(field_name, descriptor->
alias_2, &match));
343 *field_id = descriptor->
id;
349 PetscFunctionReturn(0);
359 PetscFunctionBeginUser;
361 PetscCheck(scaling != NULL && scale != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
362 "Scaling context and scale output cannot be NULL.");
364 "Only a field with a fixed physical dimension has a reference scale.");
365 *scale = PetscPowRealInt(scaling->
L_ref, dimension.
length) *
369 PetscFunctionReturn(0);
378 const char *symbols[3] = {
"L",
"U",
"rho"};
382 PetscFunctionBeginUser;
384 PetscCheck(label != NULL && length > 0, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
385 "Dimension label buffer cannot be NULL or empty.");
388 PetscCall(PetscStrncpy(label,
"not a physical quantity", length));
390 PetscFunctionReturn(0);
393 PetscCall(PetscStrncpy(label,
"dimension of its source field", length));
395 PetscFunctionReturn(0);
397 for (
int index = 0; index < 3; ++index) {
398 if (!exponents[index])
continue;
399 if (exponents[index] == 1) {
400 PetscCall(PetscSNPrintf(label + used, length - used,
"%s%s", used ?
" " :
"", symbols[index]));
402 PetscCall(PetscSNPrintf(label + used, length - used,
"%s%s^%d", used ?
" " :
"",
403 symbols[index], exponents[index]));
405 PetscCall(PetscStrlen(label, &used));
407 if (!used) PetscCall(PetscStrncpy(label,
"dimensionless", length));
409 PetscFunctionReturn(0);
441 default: name =
"Invalid-Layout";
break;
457 PetscFunctionBeginUser;
459 PetscCheck(user != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
460 "UserCtx cannot be NULL when resolving a field view.");
461 PetscCheck(view != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
462 "Field view output cannot be NULL.");
475 view->
dm = user->
fda;
478 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_PLIB,
479 "Field '%s' has an invalid DM selector.", descriptor->
canonical_name);
485 PetscCheck(view->
dm != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
486 "DM for field '%s' is unavailable in this UserCtx.", descriptor->
canonical_name);
487 PetscCheck(view->
global_vec != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
488 "Global vector for field '%s' is unavailable in this UserCtx.", descriptor->
canonical_name);
489 PetscCheck(view->
local_vec != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
490 "Local vector for field '%s' is unavailable in this UserCtx.", descriptor->
canonical_name);
493 PetscFunctionReturn(0);
PetscErrorCode FieldIdFromName(const char *field_name, FieldId *field_id)
Resolves a canonical field name or registered alias to a typed identity.
PetscErrorCode FieldDimensionReferenceScale(const ScalingCtx *scaling, FieldDimension dimension, PetscReal *scale)
Multiplies the reference scales raised to the dimension's exponents.
#define FIELD_ENTRY(field_id_, name_, alias1_, alias2_, dof_, dm_, layout_, sync_, availability_, capabilities_, global_member_, local_member_, dimension_)
static const FieldDescriptor gFieldCatalog[FIELD_ID_COUNT]
const char * FieldCanonicalName(FieldId field_id)
Returns catalog-owned printable text for a field identity.
PetscErrorCode FieldGetView(UserCtx *user, FieldId field_id, FieldView *view)
Binds one descriptor to the PETSc objects already owned by a UserCtx.
PetscErrorCode FieldTryIdFromName(const char *field_name, FieldId *field_id, PetscBool *found)
Searches canonical names and aliases, reporting a miss instead of failing.
const char * FieldLayoutName(FieldLayout layout)
Converts layout metadata to the stable diagnostic label used by field loggers.
PetscErrorCode FieldDimensionLabel(FieldDimension dimension, char *label, size_t length)
Formats the nonzero exponents, or names the non-fixed kinds.
PetscErrorCode FieldGetDescriptor(FieldId field_id, const FieldDescriptor **descriptor)
Returns the immutable catalog descriptor for one typed field identity.
Authoritative identities and storage metadata for persistent Eulerian fields.
#define FIELD_DIM_VELOCITY_SQUARED
#define FIELD_DIM_INVERSE_VOLUME
@ FIELD_DIMENSION_FROM_SOURCE
Staging storage: carries whatever was written into it.
@ FIELD_DIMENSION_NOT_A_QUANTITY
Integer bookkeeping: identities, flags, ranks.
@ FIELD_DIMENSION_FIXED
The exponents are the field's dimension.
#define FIELD_DIM_DIFFUSIVITY
@ FIELD_CAPABILITY_CHECKPOINT
@ FIELD_CAPABILITY_PARTICLE_SAMPLED
Defined only where a cell holds particles; elsewhere the stored value is a placeholder,...
@ FIELD_CAPABILITY_GHOST_UPDATE
@ FIELD_CAPABILITY_PERIODIC_GEOMETRY_SHIFT
@ FIELD_CAPABILITY_PERIODIC_CELL_SYNC
@ FIELD_CAPABILITY_PERIODIC_FACE_SYNC
@ FIELD_CAPABILITY_PERIODIC_STAGGERED_SYNC
@ FIELD_AVAILABILITY_WALL_MODEL
@ FIELD_AVAILABILITY_FINEST_LEVEL
@ FIELD_AVAILABILITY_PARTICLES
@ FIELD_AVAILABILITY_TURBULENCE
@ FIELD_AVAILABILITY_LES_DYNAMIC
@ FIELD_AVAILABILITY_ALWAYS
@ FIELD_AVAILABILITY_INFLOW_FLUCTUATION
@ FIELD_SYNC_COMPONENT_STAGGERED
#define FIELD_DIM_INVERSE_TIME_SQUARED
const FieldDescriptor * descriptor
#define FIELD_DIM_DIMENSIONLESS
#define FIELD_DIM_FROM_SOURCE
FieldLayout
Logical storage topology of a field.
@ FIELD_LAYOUT_CELL_CENTERED
@ FIELD_LAYOUT_COMPONENT_STAGGERED
@ FIELD_LAYOUT_NODE_CENTERED
const char * canonical_name
#define FIELD_DIM_PRESSURE
#define FIELD_DIM_VOLUME_FLUX
#define FIELD_DIM_VELOCITY
FieldId
Compile-time identity for a catalogued Eulerian field.
@ FIELD_ID_DUAL_PLANE_CENTROID_I
@ FIELD_ID_PLANE_NORMAL_J
@ FIELD_ID_PLANE_CENTROID_I
@ FIELD_ID_CELL_SCALAR_AT_CORNER
@ FIELD_ID_PLANE_NORMAL_K
@ FIELD_ID_PLANE_CENTROID_K
@ FIELD_ID_PLANE_NORMAL_I
@ FIELD_ID_CELL_VECTOR_AT_CORNER
@ FIELD_ID_DUAL_PLANE_CENTROID_J
@ FIELD_ID_INFLOW_FLUCTUATION
@ FIELD_ID_DUAL_PLANE_CENTROID_K
@ FIELD_ID_DIFFUSIVITY_GRADIENT
@ FIELD_ID_PLANE_CENTROID_J
@ FIELD_ID_DUAL_PLANE_NORMAL_I
@ FIELD_ID_DUAL_PLANE_NORMAL_J
@ FIELD_ID_DUAL_PLANE_NORMAL_K
@ FIELD_ID_PARTICLE_COUNT
@ FIELD_ID_SEARCH_CELL_SIZE
Immutable metadata for one field identity.
Physical dimension as exponents of the reference length, velocity, and density.
Non-owning runtime objects resolved for one field and UserCtx.
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.
User-defined context containing data specific to a single computational grid level.