MODFLOW 6  version 6.7.0.dev3
USGS Modular Hydrologic Model
cachedgradientmodule::cachedgradienttype Interface Reference

Decorator that adds caching to any gradient computation implementation. More...

Inheritance diagram for cachedgradientmodule::cachedgradienttype:
Inheritance graph
Collaboration diagram for cachedgradientmodule::cachedgradienttype:
Collaboration graph

Private Member Functions

procedure get
 
procedure set_field
 
final destructor
 
type(cachedgradienttype) function constructor (gradient, dis)
 

Private Attributes

class(disbasetype), pointer dis
 
class(igradienttype), allocatable gradient
 
real(dp), dimension(:, :), allocatable cached_gradients
 

Detailed Description

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:

  1. Create a base gradient implementation (e.g., LeastSquaresGradientType)
  2. Wrap it with CachedGradientType using the constructor
  3. Call set_field() once to pre-compute all gradients
  4. 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.

Member Function/Subroutine Documentation

◆ constructor()

type(cachedgradienttype) function cachedgradientmodule::cachedgradienttype::constructor ( class(igradienttype), intent(inout), allocatable  gradient,
class(disbasetype), intent(in), pointer  dis 
)
private

Definition at line 50 of file CachedGradient.f90.

51  ! --dummy
52  class(IGradientType), allocatable, intent(inout) :: gradient
53  class(DisBaseType), pointer, intent(in) :: dis
54  !-- return
55  type(CachedGradientType) :: cached_gradient
56 
57  cached_gradient%dis => dis
58 
59  call move_alloc(gradient, cached_gradient%gradient) ! Take ownership
60  allocate (cached_gradient%cached_gradients(dis%nodes, 3))
61 

◆ destructor()

final cachedgradientmodule::cachedgradienttype::destructor
finalprivate

Definition at line 41 of file CachedGradient.f90.

Here is the call graph for this function:

◆ get()

procedure cachedgradientmodule::cachedgradienttype::get
private

Definition at line 39 of file CachedGradient.f90.

◆ set_field()

procedure cachedgradientmodule::cachedgradienttype::set_field
private

Definition at line 40 of file CachedGradient.f90.

Member Data Documentation

◆ cached_gradients

real(dp), dimension(:, :), allocatable cachedgradientmodule::cachedgradienttype::cached_gradients
private

Definition at line 37 of file CachedGradient.f90.

37  real(DP), dimension(:, :), allocatable :: cached_gradients ! gradients at nodes

◆ dis

class(disbasetype), pointer cachedgradientmodule::cachedgradienttype::dis
private

Definition at line 35 of file CachedGradient.f90.

35  class(DisBaseType), pointer :: dis

◆ gradient

class(igradienttype), allocatable cachedgradientmodule::cachedgradienttype::gradient
private

Definition at line 36 of file CachedGradient.f90.

36  class(IGradientType), allocatable :: gradient

The documentation for this interface was generated from the following file: