tlm_adjoint.storage
Module Contents
- class tlm_adjoint.storage.Storage(x, key, *, save=False)
Used to save and load a forward solution value.
With save=True the first forward solve saves the value of x. With save=False, or on any subsequent forward solve, the value of the forward solution is loaded into x.
When processed by the
EquationManagerthis is equivalent to an assignment\[x = x_\text{value},\]where \(x_\text{value}\) is the value which is saved or loaded. The forward residual is defined
\[\mathcal{F} \left( x \right) = x - x_\text{value}.\]This is an abstract base class. Information required to save and load data is provided by overloading abstract methods. This class does not inherit from
abc.ABC, so that methods may be implemented as needed.- Parameters:
x – A variable defining the forward solution, whose value is saved or loaded.
key – A
strkey for the saved or loaded data.save – If True then the first forward solve saves the value of x. If False then the first forward solve loads the value of x.
- property key
The key associated with saved or loaded data.
- abstract is_saved()
Return whether a value can be loaded.
- Returns:
True if a value can be loaded, and False otherwise.
- abstract load(x)
Load data, storing the result in x.
- Parameters:
x – A variable in which the loaded data is stored.
- abstract save(x)
Save the value of x.
- Parameters:
x – A variable whose value should be saved.
- forward_solve(x, deps=None)
Compute the forward solution.
Can assume that the currently active
EquationManageris paused.- Parameters:
X – A variable or a
Sequenceof variables storing the solution. May define an initial guess, and should be set by this method.deps – A
tupleof variables, defining values for dependencies. Only the elements corresponding to X may be modified. self.dependencies() should be used if not supplied.
- adjoint_jacobian_solve(adj_x, nl_deps, b)
Compute an adjoint solution.
- Parameters:
adj_X – Either None, or a variable or
Sequenceof variables defining the initial guess for an iterative solve. May be modified or returned.nl_deps – A
Sequenceof variables defining values for non-linear dependencies. Should not be modified.B – The right-hand-side. A variable or
Sequenceof variables storing the value of the right-hand-side. May be modified or returned.
- Returns:
A variable or
Sequenceof variables storing the value of the adjoint solution. May return None to indicate a value of zero.
- tangent_linear(tlm_map)
Derive an
Equationcorresponding to a tangent-linear operation.- Parameters:
tlm_map – A
TangentLinearMapstoring values for tangent-linear variables.- Returns:
An
Equation, corresponding to the tangent-linear operation.
- class tlm_adjoint.storage.MemoryStorage(x, d, key, *, save=False)
A
Storagewhich stores the value in memory.- Parameters:
- is_saved()
Return whether a value can be loaded.
- Returns:
True if a value can be loaded, and False otherwise.
- load(x)
Load data, storing the result in x.
- Parameters:
x – A variable in which the loaded data is stored.
- save(x)
Save the value of x.
- Parameters:
x – A variable whose value should be saved.
- class tlm_adjoint.storage.HDF5Storage(x, h, key, *, save=False)
A
Storagewhich stores the value on disk using the h5py library.- Parameters:
- is_saved()
Return whether a value can be loaded.
- Returns:
True if a value can be loaded, and False otherwise.
- load(x)
Load data, storing the result in x.
- Parameters:
x – A variable in which the loaded data is stored.
- save(x)
Save the value of x.
- Parameters:
x – A variable whose value should be saved.