PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
particle_field_catalog.c
Go to the documentation of this file.
1/**
2 * @file particle_field_catalog.c
3 * @brief Persistent solver-particle-field catalog implementation.
4 */
5
7#include "logging.h"
8
9#define PARTICLE_FIELD_ENTRY(field_id_, name_, alias1_, alias2_, components_, type_, registration_, capabilities_, default_, scatter_target_, dimension_) \
10 [field_id_] = { \
11 field_id_, name_, alias1_, alias2_, components_, type_, registration_, capabilities_, default_, scatter_target_, dimension_ \
12 }
13
15 PARTICLE_FIELD_ENTRY(PARTICLE_FIELD_ID_POSITION, "position", "ParticlePosition", NULL,
19 PARTICLE_FIELD_ENTRY(PARTICLE_FIELD_ID_VELOCITY, "velocity", "ParticleVelocity", NULL,
25 PARTICLE_FIELD_ENTRY(PARTICLE_FIELD_ID_CELL_ID, "DMSwarm_CellID", "CellID", NULL,
29 PARTICLE_FIELD_ENTRY(PARTICLE_FIELD_ID_WEIGHT, "weight", "ParticleWeight", NULL,
34 PARTICLE_FIELD_ENTRY(PARTICLE_FIELD_ID_DIFFUSIVITY, "Diffusivity", NULL, NULL,
38 PARTICLE_FIELD_ENTRY(PARTICLE_FIELD_ID_DIFFUSIVITY_GRADIENT, "DiffusivityGradient", NULL, NULL,
49 0.0, FIELD_ID_PSI,
51 PARTICLE_FIELD_ENTRY(PARTICLE_FIELD_ID_LOCATION_STATUS, "DMSwarm_location_status", "Migration Status", NULL,
55 PARTICLE_FIELD_ENTRY(PARTICLE_FIELD_ID_PID, "DMSwarm_pid", "pid", "Particle ID",
59 PARTICLE_FIELD_ENTRY(PARTICLE_FIELD_ID_RANK, "DMSwarm_rank", "rank", NULL,
63};
64
65_Static_assert(sizeof(gParticleFieldCatalog) / sizeof(gParticleFieldCatalog[0]) == PARTICLE_FIELD_ID_COUNT,
66 "Particle field catalog must contain one entry per ParticleFieldId.");
67
68/**
69 * @brief Validates and returns one immutable particle-field descriptor.
70 * @see ParticleFieldGetDescriptor()
71 */
73 const ParticleFieldDescriptor **descriptor)
74{
75 PetscFunctionBeginUser;
77 PetscCheck(descriptor != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
78 "Particle field descriptor output cannot be NULL.");
79 PetscCheck(field_id >= 0 && field_id < PARTICLE_FIELD_ID_COUNT,
80 PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
81 "Invalid ParticleFieldId value %d.", (int)field_id);
82 PetscCheck(gParticleFieldCatalog[field_id].id == field_id,
83 PETSC_COMM_SELF, PETSC_ERR_PLIB,
84 "Particle field catalog entry %d is not initialized consistently.", (int)field_id);
85
86 *descriptor = &gParticleFieldCatalog[field_id];
88 PetscFunctionReturn(0);
89}
90
91/**
92 * @brief Returns the particle field scattering to one Eulerian field.
93 * @see ParticleFieldIdFromScatterTarget()
94 */
96{
97 PetscFunctionBeginUser;
99 PetscCheck(field_id != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
100 "ParticleFieldId output cannot be NULL.");
101 for (PetscInt index = 0; index < PARTICLE_FIELD_ID_COUNT; ++index) {
103 gParticleFieldCatalog[index].eulerian_scatter_target == target) {
104 *field_id = (ParticleFieldId)index;
106 PetscFunctionReturn(0);
107 }
108 }
109 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
110 "No particle field scatters to Eulerian field '%s'.", FieldCanonicalName(target));
112}
113
114/**
115 * @brief Resolves particle field text once by searching canonical names and aliases.
116 * @see ParticleFieldIdFromName()
117 */
118PetscErrorCode ParticleFieldIdFromName(const char *field_name, ParticleFieldId *field_id)
119{
120 PetscBool found = PETSC_FALSE;
121
122 PetscFunctionBeginUser;
124 PetscCall(ParticleFieldTryIdFromName(field_name, field_id, &found));
125 PetscCheck(found, PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE,
126 "Particle field name '%s' is not registered in the persistent particle field catalog.",
127 field_name);
129 PetscFunctionReturn(0);
130}
131
132/**
133 * @brief Searches canonical names and aliases, reporting a miss instead of failing.
134 * @see ParticleFieldTryIdFromName()
135 */
136PetscErrorCode ParticleFieldTryIdFromName(const char *field_name, ParticleFieldId *field_id,
137 PetscBool *found)
138{
139 PetscFunctionBeginUser;
141 PetscCheck(field_name != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
142 "Particle field name cannot be NULL.");
143 PetscCheck(field_id != NULL && found != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
144 "ParticleFieldId and found outputs cannot be NULL.");
145
146 *field_id = PARTICLE_FIELD_ID_INVALID;
147 *found = PETSC_FALSE;
148 for (PetscInt index = 0; index < PARTICLE_FIELD_ID_COUNT; ++index) {
149 const ParticleFieldDescriptor *descriptor = &gParticleFieldCatalog[index];
150 PetscBool match = PETSC_FALSE;
151
152 PetscCall(PetscStrcasecmp(field_name, descriptor->canonical_name, &match));
153 if (!match && descriptor->alias_1) PetscCall(PetscStrcasecmp(field_name, descriptor->alias_1, &match));
154 if (!match && descriptor->alias_2) PetscCall(PetscStrcasecmp(field_name, descriptor->alias_2, &match));
155 if (match) {
156 *field_id = descriptor->id;
157 *found = PETSC_TRUE;
158 break;
159 }
160 }
162 PetscFunctionReturn(0);
163}
164
165/**
166 * @brief Returns the canonical PETSc name without performing name lookup.
167 * @see ParticleFieldName()
168 */
170{
172 if (field_id < 0 || field_id >= PARTICLE_FIELD_ID_COUNT) { PROFILE_HELPER_END; return "InvalidParticleField"; }
173 if (gParticleFieldCatalog[field_id].id != field_id) { PROFILE_HELPER_END; return "InvalidParticleField"; }
175 return gParticleFieldCatalog[field_id].canonical_name;
176}
177
178#undef PARTICLE_FIELD_ENTRY
#define FIELD_DIM_DIFFUSIVITY
const char * FieldCanonicalName(FieldId field_id)
Return the canonical printable name for an ID.
#define FIELD_DIM_DIMENSIONLESS
#define FIELD_DIM_NOT_A_QUANTITY
#define FIELD_DIM_LENGTH
#define FIELD_DIM_VELOCITY
FieldId
Compile-time identity for a catalogued Eulerian field.
@ FIELD_ID_PSI
@ FIELD_ID_UCAT
@ FIELD_ID_INVALID
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.
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
#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
const char * ParticleFieldName(ParticleFieldId field_id)
Returns the canonical PETSc name without performing name lookup.
PetscErrorCode ParticleFieldIdFromName(const char *field_name, ParticleFieldId *field_id)
Resolves particle field text once by searching canonical names and aliases.
#define PARTICLE_FIELD_ENTRY(field_id_, name_, alias1_, alias2_, components_, type_, registration_, capabilities_, default_, scatter_target_, dimension_)
static const ParticleFieldDescriptor gParticleFieldCatalog[PARTICLE_FIELD_ID_COUNT]
PetscErrorCode ParticleFieldIdFromScatterTarget(FieldId target, ParticleFieldId *field_id)
Returns the particle field scattering to one Eulerian field.
PetscErrorCode ParticleFieldGetDescriptor(ParticleFieldId field_id, const ParticleFieldDescriptor **descriptor)
Validates and returns one immutable particle-field descriptor.
PetscErrorCode ParticleFieldTryIdFromName(const char *field_name, ParticleFieldId *field_id, PetscBool *found)
Searches canonical names and aliases, reporting a miss instead of failing.
Typed identities and metadata for persistent solver-particle fields.
ParticleFieldId
Compile-time identity for a persistent solver-particle field.
@ PARTICLE_FIELD_ID_LOCATION_STATUS
@ PARTICLE_FIELD_ID_WEIGHT
@ PARTICLE_FIELD_ID_POSITION
@ PARTICLE_FIELD_ID_PID
@ PARTICLE_FIELD_ID_CELL_ID
@ PARTICLE_FIELD_ID_PSI
@ PARTICLE_FIELD_ID_RANK
@ PARTICLE_FIELD_ID_DIFFUSIVITY_GRADIENT
@ PARTICLE_FIELD_ID_COUNT
@ PARTICLE_FIELD_ID_DIFFUSIVITY
@ PARTICLE_FIELD_ID_INVALID
@ PARTICLE_FIELD_ID_VELOCITY
@ PARTICLE_FIELD_CAPABILITY_MODEL_UPDATE
@ PARTICLE_FIELD_CAPABILITY_USER_INITIALIZE
The particle carries the value, so a configured initial value survives: nothing re-derives it from th...
@ PARTICLE_FIELD_CAPABILITY_DEFAULT_INITIALIZE
@ PARTICLE_FIELD_CAPABILITY_CHECKPOINT
@ PARTICLE_FIELD_CAPABILITY_EULERIAN_SCATTER
@ PARTICLE_FIELD_CAPABILITY_NONE
@ PARTICLE_FIELD_REGISTRATION_PETSC
@ PARTICLE_FIELD_REGISTRATION_PICURV
Immutable metadata for one persistent particle field.