20 PetscFunctionBeginUser;
21 PetscCall(PetscOptionsClear(NULL));
22 PetscFunctionReturn(0);
26static PetscErrorCode
SetOption(
const char *name,
const char *value)
28 PetscFunctionBeginUser;
29 PetscCall(PetscOptionsSetValue(NULL, name, value));
30 PetscFunctionReturn(0);
36 PetscFunctionBeginUser;
38 PetscCall(
SetOption(
"-field_statistics_enabled",
"true"));
39 PetscCall(
SetOption(
"-field_statistics_window_count",
"1"));
40 PetscCall(
SetOption(
"-field_statistics_window_0_name",
"production"));
41 PetscCall(
SetOption(
"-field_statistics_window_0_start_time",
"50.0"));
42 PetscCall(
SetOption(
"-field_statistics_window_0_end_time",
"250.0"));
43 PetscCall(
SetOption(
"-field_statistics_window_0_weighting",
"physical_time"));
44 PetscCall(
SetOption(
"-field_statistics_window_0_step_cadence",
"5"));
45 PetscCall(
SetOption(
"-field_statistics_window_0_field_count",
"2"));
46 PetscCall(
SetOption(
"-field_statistics_window_0_field_0_name",
"Ucat"));
47 PetscCall(
SetOption(
"-field_statistics_window_0_field_0_moments",
"first,second"));
48 PetscCall(
SetOption(
"-field_statistics_window_0_field_1_name",
"P"));
49 PetscCall(
SetOption(
"-field_statistics_window_0_field_1_moments",
"first"));
50 PetscCall(
SetOption(
"-field_statistics_window_0_covariance_count",
"1"));
51 PetscCall(
SetOption(
"-field_statistics_window_0_covariance_0",
"Ucat,P"));
52 PetscFunctionReturn(0);
58 PetscFunctionBeginUser;
59 PetscCall(PetscMemzero(simCtx,
sizeof(*simCtx)));
60 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
62 PetscCall(PetscPopErrorHandler());
63 PetscFunctionReturn(0);
70 PetscBool name_matches = PETSC_FALSE;
72 PetscFunctionBeginUser;
74 PetscCall(PetscMemzero(&simCtx,
sizeof(simCtx)));
82 PetscCall(PetscStrcmp(d->
name,
"production", &name_matches));
88 "the weighting is read"));
90 "a step cadence selects the step schedule"));
94 "field names resolve through the typed catalog"));
98 "a field asking only for the first moment keeps no product"));
105 "a resolved window begins pending"));
110 PetscFunctionReturn(0);
118 PetscFunctionBeginUser;
120 PetscCall(PetscOptionsClearValue(NULL,
"-field_statistics_window_0_end_time"));
121 PetscCall(PetscMemzero(&simCtx,
sizeof(simCtx)));
125 "an absent end time leaves the window open ended"));
128 PetscFunctionReturn(0);
136 PetscFunctionBeginUser;
138 PetscCall(
SetOption(
"-field_statistics_enabled",
"false"));
139 PetscCall(PetscMemzero(&simCtx,
sizeof(simCtx)));
143 "a disabled subsystem resolves no window"));
145 "a disabled subsystem allocates nothing"));
149 PetscCall(PetscMemzero(&simCtx,
sizeof(simCtx)));
152 "an absent configuration resolves no window"));
154 PetscFunctionReturn(0);
162 PetscFunctionBeginUser;
164 PetscCall(
SetOption(
"-statistics_console_output_freq",
"25"));
165 PetscCall(PetscMemzero(&simCtx,
sizeof(simCtx)));
170 "the console cadence is read without any window"));
172 PetscFunctionReturn(0);
179 PetscErrorCode bad = 0;
181 PetscFunctionBeginUser;
185 PetscCall(
SetOption(
"-field_statistics_enabled",
"true"));
187 PetscCall(
PicurvAssertIntEqual(PETSC_ERR_ARG_WRONG, bad,
"enabled with no window is rejected"));
191 PetscCall(
SetOption(
"-field_statistics_window_0_time_cadence",
"0.5"));
197 PetscCall(PetscOptionsClearValue(NULL,
"-field_statistics_window_0_step_cadence"));
203 PetscCall(
SetOption(
"-field_statistics_window_0_weighting",
"inverse_variance"));
209 PetscCall(
SetOption(
"-field_statistics_window_0_field_0_moments",
"first,third"));
215 PetscCall(
SetOption(
"-field_statistics_window_0_covariance_0",
"Ucat,Nvert"));
218 "a covariance member outside the field list is rejected"));
222 PetscCall(
SetOption(
"-field_statistics_window_0_covariance_0",
"Ucat,Ucat"));
224 PetscCall(
PicurvAssertIntEqual(PETSC_ERR_ARG_WRONG, bad,
"a self-pairing covariance is rejected"));
228 PetscCall(
SetOption(
"-field_statistics_window_count",
"2"));
229 PetscCall(
SetOption(
"-field_statistics_window_1_name",
"production"));
230 PetscCall(
SetOption(
"-field_statistics_window_1_start_time",
"0.0"));
231 PetscCall(
SetOption(
"-field_statistics_window_1_weighting",
"sample"));
232 PetscCall(
SetOption(
"-field_statistics_window_1_step_cadence",
"1"));
233 PetscCall(
SetOption(
"-field_statistics_window_1_field_count",
"1"));
234 PetscCall(
SetOption(
"-field_statistics_window_1_field_0_name",
"P"));
235 PetscCall(
SetOption(
"-field_statistics_window_1_field_0_moments",
"first"));
237 PetscCall(
PicurvAssertIntEqual(PETSC_ERR_ARG_WRONG, bad,
"a duplicate window name is rejected"));
241 PetscCall(
SetOption(
"-field_statistics_window_0_end_time",
"10.0"));
244 "an end before the start is rejected by window validation"));
247 PetscFunctionReturn(0);
264 ierr = PetscInitialize(&argc, &argv, NULL,
"PICurv statistics configuration tests");
265 if (ierr)
return (
int)ierr;
266 ierr =
PicurvRunTests(
"unit-statistics-config", cases,
sizeof(cases) /
sizeof(cases[0]));
267 if (ierr) { PetscFinalize();
return (
int)ierr; }
268 ierr = PetscFinalize();
Authoritative identities and storage metadata for persistent Eulerian fields.
Control ingress for the field-statistics pipeline.
PetscErrorCode DestroyFieldStatisticsConfig(SimCtx *simCtx)
Releases the window definitions resolved by ParseFieldStatisticsConfig().
PetscErrorCode ParseFieldStatisticsConfig(SimCtx *simCtx)
Resolves field-statistics configuration from the control file.
Window lifecycle, scheduling, and weighting for the field-statistics pipeline.
PetscInt first
First member; must also appear in the field list.
PicurvWindowFieldRequest fields[16]
PetscReal end_time
Requested end; ignored when bounded is false.
PicurvCadenceKind cadence_kind
PetscInt step_cadence
Used when cadence_kind is step; must be positive.
@ PICURV_WINDOW_PENDING
Requested start not yet reached.
PetscBool want_second
Also keep the centered second moment.
PetscInt second
Second member; must also appear in the field list.
PicurvWindowCovarianceRequest covariances[16]
PetscBool bounded
False for an open-ended window.
PicurvWindowDefinition definition
PetscReal start_time
Requested start.
PetscInt covariance_count
PetscInt field_id
Catalogued Eulerian field identity.
@ PICURV_WEIGHTING_PHYSICAL_TIME
Weight is the represented interval.
@ PICURV_CADENCE_STEP
Every n completed steps from activation.
PicurvWeighting weighting
The scientifically immutable definition of one window.
static PetscErrorCode TestDisabledResolvesNothing(void)
A disabled subsystem resolves nothing and allocates nothing.
int main(int argc, char **argv)
Entry point for the statistics configuration suite.
static PetscErrorCode TestMalformedConfigurationRejected(void)
Malformed configuration is rejected rather than silently partially applied.
static PetscErrorCode ParseIntoFreshContext(SimCtx *simCtx, PetscErrorCode *result)
Runs the parse site against a zeroed context and reports the error code.
static PetscErrorCode TestResolvesCompleteWindow(void)
A complete configuration resolves into the definition the pipeline consumes.
static PetscErrorCode TestOmittedEndTimeLeavesWindowOpen(void)
An omitted end time leaves the window open rather than defaulting one.
static PetscErrorCode SetOption(const char *name, const char *value)
Installs one option as the control file would.
static PetscErrorCode SetValidWindow(void)
Installs a complete, valid single-window configuration.
static PetscErrorCode ClearStatisticsOptions(void)
Clears any statistics options left by a previous case.
static PetscErrorCode TestConsoleCadenceIsIndependent(void)
The console cadence rides the same chain and is independent of the windows.
PetscErrorCode PicurvAssertRealNear(PetscReal expected, PetscReal actual, PetscReal tol, const char *context)
Asserts that two real values agree within tolerance.
PetscErrorCode PicurvRunTests(const char *suite_name, const PicurvTestCase *cases, size_t case_count)
Runs a named C test suite and prints pass/fail progress markers.
PetscErrorCode PicurvAssertIntEqual(PetscInt expected, PetscInt actual, const char *context)
Asserts that two integer values are equal.
PetscErrorCode PicurvAssertBool(PetscBool value, const char *context)
Asserts that one boolean condition is true.
Shared declarations for the PICurv C test fixture and assertion layer.
Named test case descriptor consumed by PicurvRunTests.
PetscInt fieldStatisticsWindowCount
PetscInt statisticsConsoleOutputFreq
PetscBool fieldStatisticsEnabled
struct PicurvWindow * fieldStatisticsWindows
The master context for the entire simulation.