This class wraps any IGradientType implementation and provides caching functionality using the Decorator pattern. When set_field is called, it pre-computes gradients for all nodes and stores them in memory for fast O(1) retrieval. This trades memory for speed when gradients are accessed multiple times for the same scalar field.
The class takes ownership of the wrapped gradient object via move semantics and provides the same interface as any other gradient implementation. This allows it to be used transparently in place of the original gradient object.
Usage pattern:
- Create a base gradient implementation (e.g., LeastSquaresGradientType)
- Wrap it with CachedGradientType using the constructor
- Call set_field() once to pre-compute all gradients
- Call get() multiple times for fast cached lookups
- Note
- The wrapped gradient object is moved (not copied) during construction for efficient memory management.
Definition at line 33 of file CachedGradient.f90.