Keeping parameter values valid and current in CADET-Core

Several bugs in how CADET-Core handles parameter values went unnoticed for a long time, because the simulation either crashed far from the cause or ran without an error and returned plausible but wrong results:

  • Crashes. Section-dependent inputs that were too short were read past their end; #28 stayed open from 2020 until #109 fixed it on 2026-12-03.
  • Silently wrong values. Readers ignore surplus entries and fill missing sections with the first section’s values, so a configuration written for the wrong number of components or sections runs without an error (#871).
  • Wrong documentation. The interface pages and the readers disagree; the Linear binding page, for example, gives the length of LIN_KA as one or the number of bound states, while the reader requires one value per component.
  • Wrong sensitivities. Quantities derived from a parameter are computed once during configuration and go stale when the parameter is changed, or lack the derivative when it is seeded for sensitivities (#810, fixed in #863; #888).
  • Unclear rules for developers. Checks live either in the parameter handler’s validateConfig, which runs once all declared parameters are read, or in the model’s configureImpl, and even in review it is not obvious where a check belongs (#876).

These are not isolated cases. Other issues of the same kind include sensitivity parameters that match nothing and are silently accepted (#761) or address the wrong entries (#875), interface documentation with missing or wrong lengths (#408, #350), and invalid initial states that are not reported (#881).

The first three concern the configuration and are what CADET-Specification #2 addresses: one source of truth for parameter names, types, shapes, units and descriptions, with validation derived from it. In Core, #874 prototypes the declarations in the existing <codegen> blocks; it generates no checks yet.

What has not been worked out is how Core derives its checks from these declarations, and when they run. The proposal is to generate them and run them not only when the file is read, but also when values change after configuration, through setParameter or by seeding sensitivities. That path has no rules today: values set later are not checked, and derived quantities are not updated. Generated checks would also settle where checks live.

This matters now because the setter is about to become the normal way to change a value. Today, setParameterValue is reachable only from C++, so almost every value enters through the configuration file and its checks. Section-wise control through the C-API (#634) would let callers such as CADET-Python run a simulation section by section and change parameters in between. Changing a value would then usually mean calling the setter instead of writing a new file, and every value changed that way would bypass the checks and leave derived quantities stale.

Example

The DG pore ratio is derived from the porosity during configure:

Nothing updates it afterwards: the section transition does nothing, and setParameter writes the new porosity and returns. Seeding a sensitivity for the porosity behaves the same way.

Proposed direction

The proposed requirement: whenever a model evaluates its equations, its parameters are valid and every derived quantity is current, however the values entered.

  1. Validate from the declarations of #874, when the file is read and after every setter, replacing the checks written by hand in validateConfig and configureImpl.
  2. Recompute derived quantities before the next evaluation, after any setter or sensitivity seed, with one rule for all models. So far each fix chose its own: #863 computes the DG element spacing from BED_LENGTH on every residual evaluation instead of storing it, and #888 recomputes the pore ratio at each section transition.

Concretely, as a sketch for discussion: each parameter becomes an object built from its declaration, holding its value, its declared dimensions and range, and its checks, which run when it is read and when it is set. setParameter and sensitivity seeding go through that object, and each model registers its derived quantities with one update hook that runs before the next evaluation. The same object can also give each parameter its sensitivity address from its declared indices, instead of fitting them into the fixed fields of ParameterId, where a wrong address silently selects a different entry today (#875). Whether these objects are generated or written by hand is open.

The smallest alternative is to document that setters are unchecked and that derived quantities do not follow them, and to keep fixing sensitivity defects one by one.

Details to keep in mind

These follow once the direction is agreed and need not be settled now:

  • Rules between parameters, such as PAR_CORERADIUS <= PAR_RADIUS, can only be checked after a group of updates, so that the order of setters does not matter.
  • How derived quantities are recomputed: one update function per model, computing them on every evaluation instead of storing them, or tracking dependencies; each trades recomputation against bookkeeping.
  • Multiplexed inputs, one value given for several components, sections or particle types, are recognized by their length; any multiple of the number of components counts as section-dependent, so a generated length check cannot tell a wrong array from a section-dependent one without explicit flags.
  • External functions and parameter dependences (*_DEP) could become one way of defining a parameter’s value: a constant, per section, a profile in time and space, or a relation to another quantity, whose own parameters (such as FILM_DIFFUSION_DEP_EXPONENT) are declared and checked like any other. That would remove the separate EXT_ model variants, and with them the main reason for generated parameter handlers; it is a public change and not part of this proposal.
  • Compatibility: existing valid input files keep their meaning, and parameters that set the size of the state vector stay fixed after configuration.

Wanted from the discussion: agreement or disagreement with the requirement and the two steps, and first reactions to the sketch.