tlm_adjoint.adjoint

Module Contents

class tlm_adjoint.adjoint.AdjointRHS(x)

The right-hand-side of an adjoint equation, for an adjoint variable associated with an equation solving for a forward variable x.

Parameters:

x – The forward variable.

b(*, copy=False)

Return the right-hand-side, as a variable.

Parameters:

copy – If True then a copy of the internal variable storing the right-hand-side value is returned. If False the internal variable itself is returned.

Returns:

A variable storing the right-hand-side value.

initialize()

Allocate an internal variable to store the right-hand-side. Typically need not be called manually.

sub(b)

Subtract a term from the right-hand-side.

Parameters:

b – The term to subtract. subtract_adjoint_derivative_action() is used to subtract the term.

is_empty()

Return whether the right-hand-side is ‘empty’, meaning that the AdjointRHS.initialize() method has not been called.

Returns:

True if the AdjointRHS.initialize() method has not been called, and False otherwise.

class tlm_adjoint.adjoint.AdjointEquationRHS(eq)

The right-hand-side of an adjoint equation, for adjoint variables associated with an equation solving for multiple forward variables X.

Multiple AdjointRHS objects. The AdjointRHS objects may be accessed by index, e.g.

adj_eq_rhs = AdjointEquationRHS(eq)
adj_rhs = adj_eq_rhs[m]
Parameters:

eq – An Equation. eq.X() defines the forward variables.

b(*, copy=False)

For the case where there is a single forward variable, return a variable associated with the right-hand-side.

Parameters:

copy – If True then a copy of the internal variable storing the right-hand-side value is returned. If False the internal variable itself is returned.

Returns:

A variable storing the right-hand-side value.

B(*, copy=False)

Return variables associated with the right-hand-sides.

Parameters:

copy – If True then copies of the internal variables storing the right-hand-side values are returned. If False the internal variables themselves are returned.

Returns:

A tuple of variables storing the right-hand-side values.

is_empty()

Return whether all of the AdjointRHS objects are ‘empty’, meaning that the AdjointRHS.initialize() method has not been called for any AdjointRHS.

Returns:

True if the AdjointRHS.initialize() method has not been called for any AdjointRHS, and False otherwise.

class tlm_adjoint.adjoint.AdjointBlockRHS(block)

The right-hand-side of multiple adjoint equations.

Multiple AdjointEquationRHS objects. The AdjointEquationRHS objects may be accessed by index, e.g.

adj_block_rhs = AdjointBlockRHS(block)
adj_eq_rhs = adj_block_rhs[k]
Parameters:

block – A Sequence of Equation objects.

pop()

Remove and return the last AdjointEquationRHS in the AdjointBlockRHS.

Returns:

A tuple (n, B). B is the removed AdjointEquationRHS, associated with block n.

is_empty()

Return whether there are no AdjointEquationRHS objects in the AdjointBlockRHS.

Returns:

True if there are no AdjointEquationRHS objects in the AdjointBlockRHS, and False otherwise.

class tlm_adjoint.adjoint.AdjointModelRHS(blocks)

The right-hand-side of multiple blocks of adjoint equations.

Multiple AdjointBlockRHS objects. The AdjointBlockRHS objects may be accessed by index, e.g.

adj_model_rhs = AdjointModelRHS(block)
adj_block_rhs = adj_block_rhs[p]

If the last block of adjoint equations contains no equations then it is automatically removed from the AdjointModelRHS.

Parameters:

blocks – A Sequence of Sequence objects each containing Equation objects, or a Mapping with items (index, block) where index is an int and block a Sequence of Equation objects. In the latter case blocks are ordered by index.

pop()

Remove and return the last AdjointEquationRHS in the last AdjointBlockRHS in the AdjointModelRHS.

Returns:

A tuple ((n, i), B). B is the removed AdjointEquationRHS, associated with equation i in block n.

is_empty()

Return whether there are no AdjointBlockRHS objects in the AdjointModelRHS.

Returns:

True if there are no AdjointBlockRHS objects in the AdjointModelRHS, and False otherwise.