Feature/poststep hook#129
Merged
Merged
Conversation
PostStepHook is a new type-bound procedure on the abstract Model type (default no-op) invoked by every time integrator (Euler, low-storage RK2/RK3/RK4) once immediately after each completed step, i.e. after this%t advances by this%dt. Motivation: per-step work such as recording off-grid receiver samples from a device-resident solution should run inside the native stepping loop. The alternative -- driving the integrator one step at a time from the host via ForwardStep -- forces the entropy/diagnostic and WriteModel device-to-host copies every step, which is unnecessary and slow for a GPU-resident model. Overriding PostStepHook lets a derived model perform that work without touching the integrators or paying the ForwardStep diagnostic overhead. The default implementation is a no-op, so existing models are unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…hooks Introduce a PreStepHook (default no-op) invoked once per time step before the Runge-Kutta stages, symmetric with the existing PostStepHook. Rename the PreTendency hook to PreTendencyHook so all three overridable model hooks share a consistent "Hook" suffix for discoverability in model extensions. - PreStepHook / PostStepHook fire once per step (start / end) in all four integrators (euler, rk2, rk3, rk4). - PreTendencyHook fires once per tendency evaluation (RK stage), unchanged in behavior aside from the rename. - Add docs/Models/model-hooks.md describing the hooks, their cadence, and the type-extension override pattern; add it to the Models nav. - Drop the polyfill.io script from mkdocs (sold domain that served malware in a 2024 supply-chain incident; MathJax 3 needs no es6 polyfill on supported browsers). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds three overridable, type-bound model hooks to the abstract
Modeltype so derived models can run per-step / per-stage work inside the native time-stepping loop without modifying the integrators. All hooks default to no-ops, so existing models are unaffected.PreStepHookPreTendencyHookPostStepHookthis%tadvances bythis%dtPreStepHookandPostStepHookfire in all four integrators (euler, low-storagerk2,rk3,rk4).PreTendencyHookis the formerPreTendencyhook, renamed for a consistentHooksuffix across all three (unchanged in behavior otherwise).Motivation
Per-step work — e.g. recording off-grid receiver samples from a device-resident solution — should run inside the native stepping loop. The alternative, driving the integrator one step at a time from the host via
ForwardStep, forces the entropy/diagnostic andWriteModeldevice-to-host copies every step, which is unnecessary and slow for a GPU-resident model. OverridingPostStepHooklets a derived model do that work without touching the integrators or paying theForwardStepdiagnostic overhead.Changes
src/SELF_Model.f90: addPreStepHook/PostStepHook, renamePreTendency→PreTendencyHook, wire all three into the integrators.PreTendency→PreTendencyHookrename through the DG / ECDG / ESAtmo model types (1D/2D/3D, CPU and GPU) and the Null models.docs/Models/model-hooks.md: new page documenting the hooks, their cadence, and the type-extension override pattern; added to the Models nav.mkdocs.yml: drop thepolyfill.ioscript (sold domain that served malware in the 2024 supply-chain incident; MathJax 3 needs no es6 polyfill on supported browsers).Compatibility
The rename of
PreTendency→PreTendencyHookchanges a public type-bound procedure name. Models that overridePreTendencymust update to the new name; all in-tree models are updated in this PR.