MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
cachedgradientmodule::cachedgradienttype Interface Referenceabstract

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

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

Public Member Functions

procedure get (this, n)
procedure set_field (this, phi)
final destructor (this)
type(cachedgradienttype) function constructor (gradient, dis)
procedure(get_if), deferred get (this, n)
procedure(set_field_if), deferred set_field (this, phi)

Public Attributes

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

Private Attributes

class(disbasetype), pointer dis

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.

Constructor & Destructor Documentation

◆ destructor()

final cachedgradientmodule::cachedgradienttype::destructor ( type(cachedgradienttype), intent(inout) this)
final

Definition at line 41 of file CachedGradient.f90.

Here is the call graph for this function:

Member Function/Subroutine Documentation

◆ constructor()

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

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

◆ get() [1/2]

procedure cachedgradientmodule::cachedgradienttype::get ( class(cachedgradienttype), target this,
integer(i4b), intent(in) n )

Definition at line 39 of file CachedGradient.f90.

◆ get() [2/2]

procedure(get_if), deferred igradient::igradienttype::get ( class(igradienttype), target this,
integer(i4b), intent(in) n )
pure virtualinherited

Definition at line 17 of file IGradient.f90.

◆ set_field() [1/2]

procedure cachedgradientmodule::cachedgradienttype::set_field ( class(cachedgradienttype), target this,
real(dp), dimension(:), intent(in), pointer phi )

Definition at line 40 of file CachedGradient.f90.

◆ set_field() [2/2]

procedure(set_field_if), deferred igradient::igradienttype::set_field ( class(igradienttype), target this,
real(dp), dimension(:), intent(in), pointer phi )
pure virtualinherited

Definition at line 18 of file IGradient.f90.

Member Data Documentation

◆ cached_gradients

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

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

Definition at line 36 of file CachedGradient.f90.

36 class(IGradientType), allocatable :: gradient

The documentation for this interface was generated from the following file:
  • /home/runner/work/modflow6/modflow6/src/Model/TransportModel/Gradient/CachedGradient.f90